function Trim(strVal) {
    var strMatch = strVal.match(/^\s*(\S+(\s+\S+)*)\s*$/);
    result = (strMatch == null) ? "" : strMatch[1];
    return result;
}
function isEmail(objObject){
	var regEmail, strValue;	
	regEmail = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
	strValue = objObject.value;
	if (objObject.value == "") return true;
	if(! regEmail.test(strValue)){
		return false;
	}
	return true;
}

function doOVERLAPBACKGROUND(func){	
	if(func == "load"){
		var windowWidth = document.documentElement.clientWidth;
		var windowHeight = document.documentElement.clientHeight;
		$("#backgroundPopup").css({
			"height": windowHeight ,
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn(300);
	}else{
		$("#backgroundPopup").fadeOut(300);
	}
}
function doAJAXLOADER(func){
	if(func == "load"){
		var windowWidth = document.documentElement.clientWidth;
		var windowHeight = document.documentElement.clientHeight;
		var popupHeight = $("#ajaxLoader").height();
		var popupWidth = $("#ajaxLoader").width();
		$("#ajaxLoader").css({
			"position": "absolute",		
			"top": windowHeight/2-popupHeight/2,
			"left": windowWidth/2-popupWidth/2
		});
		$("#ajaxLoader").fadeIn(300);
	}else{
		$("#ajaxLoader").fadeOut(300);
	}
}

$(function(){	
	$('.nwsm1').each(function(){
		$(this).parent().eq(0).hover(function(){
			$('.nwsm1:eq(0)', this).fadeIn(300);
		}, function(){
			$('.nwsm1:eq(0)', this).fadeOut(300);
		});		
	});
	$('.nwsm2').each(function(){
		$(this).parent().eq(0).hover(function(){
			$('.nwsm2:eq(0)', this).fadeIn(300);
		}, function(){
			$('.nwsm2:eq(0)', this).fadeOut(300);
		});
	});
	
	$('#flash-banner').flash({ 
		src: RelativeRootPath + 'images/banner.swf',
		width: 740,
		height: 284,
		menu: "false",
		wmode: "transparent",
		flashvars: {}
	},
		{ version: 8 }
    );
	
	$("#btnSUBMITFEEDBACK").click(function(){
		var submitURL_1 = "formaction.php?action=submitfeedback&vid=" + vid.toString() + "&vip=" + vip.toString();
		$("#frmFEEDBACKFORM").ajaxForm({ beforeSubmit: doVALIDATEFEEDBACKFORM, success: doSHOWRESPONSEFEEDBACKFORM, url: submitURL_1, clearForm: false });
	});
});

function doVALIDATEFEEDBACKFORM(){	
	var theForm = document.frmFEEDBACKFORM;
	if(Trim(theForm.txtYOURNAME.value).length == 0){
		alert("Please enter your name.");
		theForm.txtYOURNAME.focus();
		return false;
	}	
	if(Trim(theForm.txtYOURPHONE.value).length == 0){
		alert("Please enter your phone no.");
		theForm.txtYOURPHONE.focus();
		return false;
	}
	if(Trim(theForm.txtYOUREMAILID.value).length == 0){
		alert("Please enter your email id.");
		theForm.txtYOUREMAILID.focus();
		return false;
	}
	if(isEmail(theForm.txtYOUREMAILID) == false) {
		alert("Please enter your valid email id.\nFor Example: xyz@xyz.com");
		theForm.txtYOUREMAILID.focus();
		return false;
	}
	if(theForm.cmbREGARDING.selectedIndex == 0){
		alert("Please enter regarding information.");
		theForm.cmbREGARDING.focus();
		return false;
	}
	if(Trim(theForm.txaYOURMESSAGE.value).length == 0){
		alert("Please enter your message.");
		theForm.txaYOURMESSAGE.focus();
		return false;
	}
	if(Trim(theForm.txaYOURMESSAGE.value).length > 2000){
		alert("Please enter maximum 2000 characters in your message.");
		theForm.txaYOURMESSAGE.focus();
		return false;
	}
	doAJAXLOADER('load');
	doOVERLAPBACKGROUND('load');
}
function doSHOWRESPONSEFEEDBACKFORM(responseText){	
	var theForm = document.frmFEEDBACKFORM;		
	doAJAXLOADER('unload');
	doOVERLAPBACKGROUND('unload');
	if(Trim(responseText).length > 0){
		var retVal = responseText.split("|");
		if(retVal[0].toString() == "true"){
			theForm.txtYOURNAME.value = "";
			theForm.txtYOURADDRESS.value = "";			
			theForm.txtYOURPHONE.value = "";
			theForm.txtYOUREMAILID.value = "";
			theForm.cmbREGARDING.value = "";
			theForm.txaYOURMESSAGE.value = "";			
			alert("Thank you very much for your feedback.\nWe will revert back to you with our response shortly.");
			return false;
		}else{
			alert(retVal[1].toString());
			return false;	
		}
	}else{
		alert("An error occured while processing.");
		return false;
	}
}
