
function trim( instr ) {
    	var reFirst = /\S/;		// regular expression for first non-white char
    	var reLast = /\s+$/;	// regular expression for first white char after last non-white char
    	var firstChar = instr.search(reFirst);
    	var lastChar = instr.search(reLast);
    	
    	if( lastChar == -1 ) 
			lastChar = instr.length;    	
    	outstr = instr.substring( firstChar, lastChar );
    	return outstr;
}


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("Please make sure the Email Address you enter is correct!")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Please make sure the Email Address you enter is correct!")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Please make sure the Email Address you enter is correct!")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Please make sure the Email Address you enter is correct!")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Please make sure the Email Address you enter is correct!")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Please make sure the Email Address you enter is correct!")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Please make sure the Email Address you enter is correct!")
		    return false
		 }

 		 return true					
	}



function valcontactfrm(contactfrm)
	{
	if(trim((contactfrm.txt_name.value))=="")
	{
		alert("Name cannot be empty");
		contactfrm.txt_name.focus();
		return false;
	}
	else if(trim((contactfrm.txt_address.value))=="")
	{
		alert("Address cannot be empty");
		contactfrm.txt_address.focus();
		return false;
	}
	else if(trim((contactfrm.txt_zip.value))=="")
	{
		alert("Zip cannot be empty");
		contactfrm.txt_zip.focus();
		return false;
	}
	else if(trim((contactfrm.txt_phone.value))=="")
	{
		alert("Phone cannot be empty");
		contactfrm.txt_phone.focus();
		return false;
	}
	else if(trim((contactfrm.txt_email.value))=="")
	{
		alert("Email Address cannot be empty");
		contactfrm.txt_email.focus();
		return false;
	}
	else if (echeck(contactfrm.txt_email.value)==false)
	{
		contactfrm.txt_email.focus();
		return false;
	}
	else if(trim((contactfrm.txt_comment.value))=="")
	{
		alert("Comments cannot be empty");
		contactfrm.txt_comment.focus();
		return false;
	}
	else
	{
		return true;
	}
	}



