function trim(str, chars) 
{ 
return ltrim(rtrim(str, chars), chars);
} 
function ltrim(str, chars) 
{ 
chars = chars || "\\s"; return str.replace(new RegExp("^[" + chars + "]+", "g"), ""); 
} 
function rtrim(str, chars) 
{ 
chars = chars || "\\s"; 
return str.replace(new RegExp("[" + chars + "]+$", "g"), ""); 
}
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}


function validate_ques()
{
if(trim(ltrim(rtrim(document.getElementById('question').value)))=='')
{
	alert('Please enter question.');
	document.getElementById('question').focus();
	return false;
}
for(i=1;i<=4;i++)
{
	if(trim(ltrim(rtrim(document.getElementById('answer'+i).value)))=='')
	{
		alert('Please enter option'+i+'.');
		document.getElementById('answer'+i).focus();
		return false;
	}
}
return true;
}

function showans(str)
{
window.location.href="sel_ans.php?quesid="+str;
}
function open_popup(str)
{
 window.open ("view_result.php?view="+str,"","menubar=1,resizable=1,width=550,height=300");
}

function validate_signup()
{
	if(trim(ltrim(rtrim(document.getElementById('fname').value)))=='')
	{
		alert('Please enter first name.');
		document.getElementById('fname').focus();
		return false;
	}
	
	if(trim(ltrim(rtrim(document.getElementById('address1').value)))=='')
	{
		alert('Please enter address1.');
		document.getElementById('address1').focus();
		return false;
	}
	
	if(trim(ltrim(rtrim(document.getElementById('city').value)))=='')
	{
		alert('Please enter city.');
		document.getElementById('city').focus();
		return false;
	}
	if(trim(ltrim(rtrim(document.getElementById('state').value)))=='')
	{
		alert('Please enter state.');
		document.getElementById('state').focus();
		return false;
	}
	if(trim(ltrim(rtrim(document.getElementById('zip').value)))=='')
	{
		alert('Please enter zip.');
		document.getElementById('zip').focus();
		return false;
	}
	var emailID=document.getElementById('email')
	
	if ((trim(ltrim(rtrim(emailID.value)))==null)||(trim(ltrim(rtrim(emailID.value)))=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true;
}
function validate_newsletter()
{
	if(trim(ltrim(rtrim(document.getElementById('subject').value)))=='')
	{
		alert('Please enter subject.');
		document.getElementById('subject').focus();
		return false;
	}
	
	return true;
}
