/*
This javascript is for validating feedback form 
Created By :Jijo Joseph
Created Date:22-04-2010
Code Review By: Ramesh
*/

function validateFeedBack()
{
	var feedBackEmail = document.getElementById('txtEmail').value;
	var feedBackComments = document.getElementById('Comments').value;
	var feedBackFname= document.getElementById('txtFirstName').value;
	var feedBackSubject = document.getElementById('txtSubject').value;
	var errMess='';	
	var validation = true;
	
	if(feedBackEmail == '')
	{
		errMess = 'Enter a valid Email Address';
		validation = false;
	}	
	if (feedBackComments == '')
	{
		errMess = 'Please Enter Comments';
		validation = false;
	}
	if (feedBackSubject == '')
	{
		errMess = 'Please Enter Subject';
		validation = false;
	}
	if (feedBackFname == '')
	{
		errMess = 'Please Enter Name';
		validation = false;
	}
	
	if (validation == false)
	{
		var objDiv=document.getElementById('errorDiv');
		objDiv.style.visibility="visible";
		objDiv.innerHTML=errMess;
		return false;
	}
	var emailPattern = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(emailPattern.test(feedBackEmail) == false) {
		var objDiv=document.getElementById('errorDiv');
		objDiv.style.visibility="visible";
		objDiv.innerHTML='Enter a valid Email Address';   
		return false;  
	}
	submitFeedBackForm();
}
function submitFeedBackForm()
{
	var url = "email=1";
	var serverLocation = top.location.host;
	url = url + "&txtEmail="+document.getElementById('txtEmail').value;
	url = url + "&txtSubject="+document.getElementById('txtSubject').value;
	url = url + "&txtFirstName="+document.getElementById('txtFirstName').value;
	url = url + "&Comments="+document.getElementById('Comments').value;
	url = url + "&feedbackSite="+document.getElementById('feedbackSite').value;
	var d = new Date();
	var locationString = "http://"+ serverLocation + "/com/assets/feedback/feedback.cfm?"+url+"&_="+d.getTime();
	$.get(locationString,{},successFeedbackReturn);
}
function successFeedbackReturn(response, operationStatus)
{
	var resp = jQuery.trim(response);
	$('#feedContentId').html(resp);
}
function closeWindow()
{
	$('#feedContentId').html('');
	$.unblockUI();
}
function openFeedbackWindow(siteUrlFeedback)
{
	url = "siteUrlFeedback="+siteUrlFeedback;
	var serverLocation = top.location.host;
	var d = new Date();
	var locationString = "http://"+ serverLocation + "/com/assets/feedback/feedback.cfm?"+url+"&_="+d.getTime();
	$.get(locationString,{},successFeedbackReturn);
	$.blockUI({ message: $('#popupContact'), css:{cursor:'auto',top:'25%',border:'0px',background:'transparent' } });
}

var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
	if(browserString.search("Microsoft") != -1 && browserVersion.search("MSIE 6") != -1)
	{
		if(document.getElementById("AllSubjects"))
			document.getElementById("AllSubjects").style.visibility= 'visible';
		if(document.getElementById("User_Qualification"))
			document.getElementById("User_Qualification").style.visibility = 'visible';
		if(document.getElementById("User_GraduationYear"))
			document.getElementById("User_GraduationYear").style.visibility = 'visible';
		if(document.getElementById("_category"))
			document.getElementById("_category").style.visibility = 'visible';
		if(document.getElementById("_degree"))
			document.getElementById("_degree").style.visibility = 'visible';
		if(document.getElementById("User_MainCategory"))
			document.getElementById("User_MainCategory").style.visibility = 'visible';
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	if (windowHeight > 500)
	{
		heightCal = windowHeight/2-popupHeight/2;
		if(heightCal > 200)
			heightCal = 150;
		//centering
		$("#popupContact").css({
			"top": heightCal,
			"left": windowWidth/2-popupWidth/2
		});
	}
	else
	{
		$("#popupContact").css({
			"top": 150,
			"left": 300
		});
	}
	browserString = navigator.appName;
	browserVersion = navigator.appVersion;
	if(browserString.search("Microsoft") != -1 && browserVersion.search("MSIE 6") != -1)
	{
		$("#backgroundPopup").css({
			"height": 1300
		});
		if(document.getElementById("AllSubjects"))
			document.getElementById("AllSubjects").style.visibility= 'hidden';
		if(document.getElementById("User_Qualification"))
			document.getElementById("User_Qualification").style.visibility = 'hidden';
		if(document.getElementById("User_GraduationYear"))
			document.getElementById("User_GraduationYear").style.visibility = 'hidden';
		if(document.getElementById("_category"))
			document.getElementById("_category").style.visibility = 'hidden';
		if(document.getElementById("_degree"))
			document.getElementById("_degree").style.visibility = 'hidden';
		if(document.getElementById("User_MainCategory"))
			document.getElementById("User_MainCategory").style.visibility = 'hidden';
	}
	else
	{	
		//only need force for IE6		
		$("#backgroundPopup").css({
			"height": document.documentElement.clientHeight
		});
	}
	if (windowHeight < 500)
	{
		$("#backgroundPopup").css({
			"height": 1300
		});
	}
			

}
function nextFocus1()
{
	return;
}
function showPopup()
{
	//centering with css
	centerPopup();
	//load popup
	loadPopup();
}