/***************************************************************************
Regular expression declartion.
Function Name: fnCleartxt, fnCheckEmail
Purpose: To validate Emailid in Choose Newsletter section.
Written By: Blesy Paul
Written On: 8/13/2009 14:00 PM
***************************************************************************/
function fnCleartxt()
{
	return document.frmPost.txtEmailid.value = "";
}
function fnCheckEmail()
{
	var txtEmail = document.frmPost.txtEmailid.value;
	if(txtEmail!=_YOUR_EMAIL_)
	{
		if(txtEmail!="")
		{
			var res = IsEmail(txtEmail);
			if(res == false)
			{
				document.getElementById('message').innerHTML="<font color='red'>"+_INVALID_EMAIL_+"</font>";
				document.getElementById('message').style.display="block";
				document.frmPost.txtEmailid.focus();
				return false;
			}
			else
			{
				var flagurl = _SITEURL_+"user/chkemailid.php?emailId="+encodeURIComponent(document.frmPost.txtEmailid.value);
				var myRandom = parseInt(Math.random()*99999999);  // cache buster	
				flagurl=flagurl + "&rand=" + myRandom;
				http.open("GET", flagurl, false);
				http.send(null);			
				var chval=http.responseText;

				if(chval == '0')
				{
					var flagurl = _SITEURL_+"user/emailadd.php?emailId="+encodeURIComponent(document.frmPost.txtEmailid.value);
					var myRandom = parseInt(Math.random()*99999999);  // cache buster	
					flagurl=flagurl + "&rand=" + myRandom;
					http.open("GET", flagurl, false);
					http.send(null);			
					var chval=http.responseText;
					if(chval == '1')
					{
						document.getElementById('message').innerHTML="<font color='green'>"+_SUBSCRIBED_SUCCESS_+"</font>";
						document.getElementById('message').style.display="block";
						document.frmPost.txtEmailid.value=_YOUR_EMAIL_;
						return false;
					}
				}
				else
				{
					document.getElementById('message').innerHTML="<font color='red'>"+_YOU_ALREADY_SUBSCRIBED_+"</font>";
					document.getElementById('message').style.display="block";
					return false;
				}			
			}
		}
		else
		{
			document.getElementById('message').innerHTML="<font color='red'>"+_ENTER_EMAIL_+"</font>";
			document.getElementById('message').style.display="block";
			return false;
		}
	}	
	return false;
}
/* ##################################################################### */


/***************************************************************************
Function Name: fnTrimVal, fnValidateContactUs, fnResetContactUs
Purpose: To Send Mail in Contact Us page.
Written By: Blesy Paul
Written On: 8/14/2009 3:00 PM
****************************************************************************/
function fnTrimVal()
{
	var txname=Trim(document.getElementById('txtName').value);
	var txmail=Trim(document.getElementById('txtEmail').value);
	var txphoneno=Trim(document.getElementById('txtPhoneNo').value);
	var txdesc=Trim(document.getElementById('txaDescptn').value);
	document.getElementById('txtName').value=txname;
	document.getElementById('txtEmail').value=txmail;
	document.getElementById('txtPhoneNo').value=txphoneno;
	document.getElementById('txaDescptn').value=txdesc;
}
function fnValidateContactUs()
{
	var name = document.frmPost.txtName.value;
	var email = document.frmPost.txtEmail.value;
	var phone = document.frmPost.txtPhoneNo.value;
	var desc = document.frmPost.txaDescptn.value;
	var Output = "";

	if(get = jsIsNull(document.getElementById('txtName'),_ENTER_NAME_))
		Output = "<font color='red'>" + Output + "<br/>" + get + "</font>";
	if(get = jsIsNull(document.getElementById('txtEmail'),'Enter Email'))
		Output = "<font color='red'>" + Output + "<br/>" + get + "</font>";
	else if(! IsEmail(document.getElementById('txtEmail').value))
		Output = "<font color='red'>" + Output + "<br/>" + display('INVALID_INPUT',_EMAIL_) + "</font>";
	if(phone != "")
	{
		if(get = jsValidatePhoneFax(document.getElementById('txtPhoneNo'),_CONTACT_PHONE_))
			Output = "<font color='red'>" + Output + "<br/>" + get + "</font>";	
	}		
	if(get = jsIsNull(document.getElementById('txaDescptn'),'Enter Comment / Suggestion'))
		Output = "<font color='red'>" + Output + "<br/>" + get + "</font>";	

	if(Output.length > 0)
	{
		document.getElementById('err_msg').innerHTML = Output;
		return false;
	}
	else
	{
		var flagurl = "user/SendContactUs.php?name="+encodeURIComponent(name)+"&email="+encodeURIComponent(email)+"&phone="+encodeURIComponent(phone)+"&desc="+encodeURIComponent(desc);
		var myRandom = parseInt(Math.random()*99999999);  // cache buster	
		flagurl=flagurl + "&rand=" + myRandom;
		http.open("GET", flagurl, false);
		http.send(null);			
		var chval=http.responseText;
		//alert(chval);
		//return false;
		if(chval == 1)
		{
			Output = "<font color='green'>"+_COMMENT_SUCCESS_+"</font><br/><br/>";
			document.getElementById('err_msg').innerHTML = Output;
			document.frmPost.txtName.value = "";
			document.frmPost.txtEmail.value = "";
			document.frmPost.txtPhoneNo.value = "";
			document.frmPost.txaDescptn.value = "";
			return true;
		}
		else
		{
			Output = "<font color='red'>"+_COMMENT_FAILED_+"</font><br/><br/>";
			document.getElementById('err_msg').innerHTML = Output;
			document.frmPost.txtName.value = "";
			document.frmPost.txtEmail.value = "";
			document.frmPost.txtPhoneNo.value = "";
			document.frmPost.txaDescptn.value = "";
			return false;
		}		
	}	
}
function fnResetContactUs()
{
	document.getElementById('err_msg').innerHTML = "";
}
/* ##################################################################### */

/***************************************************************************
Function Name: fnChangeLan
Purpose: To set the Language Id.
Written By: Blesy Paul
Written On: 8/17/2009 
****************************************************************************/
function fnChangeLan(lang)
{
	if(lang != "")
	{
		document.frmPost.hdnlang.value = lang;
		document.frmPost.action=_SITEURL_+"ChooseeHome";
		document.frmPost.submit();
		return true;
	}
}
/* ##################################################################### */
function fnPostPoll(comts)
{
	var coments = comts;
	var SesId = document.frmPost.hdnSessId.value;
	var pollId = document.frmPost.hdnPollId.value;
	
	var flagurl = _SITEURL_+"user/PollComment.php?SesId="+SesId+"&coments="+coments+"&pollId="+pollId;
	var myRandom = parseInt(Math.random()*99999999);  // cache buster	
	flagurl=flagurl + "&rand=" + myRandom;
	http.open("GET", flagurl, false);
	http.send(null);			
	var chval=http.responseText;
	//alert(chval);
	//return false;
	//document.frmPost.hdnRate.value = chval;
	document.getElementById('rate_msg').innerHTML = chval;
	document.getElementById('yesno').innerHTML = "";
	//document.frmPost.submit();
	return true;	
}
function fnGetPercent()
{
	var questionId=document.getElementById('hdnQuestion').value;
	var percentdiv=document.getElementById('rate_msg').innerHTML;
}
function fnGetSearchResult(urllink,searchId)
{
	var keyvalue=document.getElementById(searchId).value;
	if(keyvalue!='' && keyvalue!=_ENTER_KEY_WORD_)
	{
		if(fnChkSplCharsName(document.getElementById(searchId),'Search Key'))
		{
			alert(_ENTER_VALID_DATA_);
			return false;
		}
		else
		{
			document.frmPost.action=_SITEURL_+"SearchResult";
			document.frmPost.submit();
		}
	}
	else
	{
		alert(_ENTER_KEY_WORD_);
		return false;
	}
}
function fngetBackPageresult(skey,divid)
{
	document.getElementById(divid).value=skey;
	document.frmPost.action=_SITEURL_+"SearchResult";
	document.frmPost.submit();
}
function fnEmpty(obj)
{
	obj.value="";
}
function fnGetDetailResult(searchval,section,fld,tbl)
{
	document.getElementById('search').value=searchval;
	document.getElementById('hdnQryTxt').value=section;
	document.getElementById('hdnfld').value=fld;
	document.getElementById('hdntbl').value=tbl;
	document.frmPost.action=_SITEURL_+"SearchResult?pgact=detail";
	document.frmPost.submit();
}
/***************************************************************************
Function Name: fnValidateIdea
Purpose: Used for Your ideas Page.
Written By: Firoja Kachhi
Written On: 9/11/2009
****************************************************************************/
function fnValidateIdea()
{
	var name = document.frmPost.txtName.value;
	var email = document.frmPost.txtEmail.value;
	var phone = document.frmPost.txtPhoneNo.value;
	var desc = document.frmPost.txaDescptn.value;
	var Output = "";
	if(get = jsIsNull(document.getElementById('txtName'),_ENTER_NAME_))
		Output = "<font color='red'>" + Output + "<br/>" + get + "</font>";
	if(get = jsIsNull(document.getElementById('txtEmail'),'Enter Email'))
		Output = "<font color='red'>" + Output + "<br/>" + get + "</font>";
	else if(! IsEmail(document.getElementById('txtEmail').value))
		Output = "<font color='red'>" + Output + "<br/>" + display('INVALID_INPUT',_EMAIL_) + "</font>";
	if(phone != "")
	{
		if(get = jsValidatePhoneFax(document.getElementById('txtPhoneNo'),_CONTACT_PHONE_))
			Output = "<font color='red'>" + Output + "<br/>" + get + "</font>";	
	}
	if(get = jsIsNull(document.getElementById('txaDescptn'),'Ideas/Recipe'))
		Output = "<font color='red'>" + Output + "<br/>" + get + "</font>";
	if(Output.length > 0)
	{
		document.getElementById('err_msg').innerHTML = Output;
		return false;
	}
	else
	{
		var flagurl = _SITEURL_+"user/SendRecipeProposal.php?name="+encodeURIComponent(name)+"&email="+encodeURIComponent(email)+"&phone="+encodeURIComponent(phone)+"&desc="+encodeURIComponent(desc);
		var myRandom = parseInt(Math.random()*99999999);  // cache buster	
		flagurl=flagurl + "&rand=" + myRandom;
		http.open("GET", flagurl, false);
		http.send(null);			
		var chval=http.responseText;
		//alert(chval);
		//return false;
		if(chval == 1)
		{
			Output = "<font color='green'>"+_PROPOSAL_SUCC_+"</font><br/><br/>";
			document.getElementById('err_msg').innerHTML = Output;
			document.getElementById('err_msg').display="block";
			document.frmPost.txtName.value = "";
			document.frmPost.txtEmail.value = "";
			document.frmPost.txtPhoneNo.value = "";
			document.frmPost.txaDescptn.value = "";
			//return true;
		}
		else
		{
			Output = "<font color='red'>"+_PROPOSAL_FAILED_+"</font><br/><br/>";
			document.getElementById('err_msg').innerHTML = Output;
			document.frmPost.txtName.value = "";
			document.frmPost.txtEmail.value = "";
			document.frmPost.txtPhoneNo.value = "";
			document.frmPost.txaDescptn.value = "";
			return false;
		}		
	}	
}
