
	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("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 valfrm(userfrm)
{
if(trim((userfrm.txt_email.value))=="")
{
alert("Email / Login Name cannot be empty");
userfrm.txt_email.focus();
return false;
}
else if (echeck(userfrm.txt_email.value)==false)
{
userfrm.txt_email.focus();
return false;
}
else if(trim((userfrm.txt_password.value))=="")
{
alert("Password cannot be empty");
userfrm.txt_password.focus();
return false;
}
else if(trim((userfrm.txt_password2.value))=="")
{
alert("Confirm Password");
userfrm.txt_password2.focus();
return false;
}
else if(trim((userfrm.txt_password.value))!=(userfrm.txt_password2.value))
{
alert("Password mismatch");
userfrm.txt_password2.focus();
return false;
}	
else if(trim((userfrm.txt_institutename.value))=="")
{
alert("Institute Name cannot be empty");
userfrm.txt_institutename.focus();
return false;
}
else if(trim((userfrm.txt_contactname.value))=="")
{
alert("Contact Name cannot be empty");
userfrm.txt_contactname.focus();
return false;
}
else if(trim((userfrm.txt_phone.value))=="")
{
alert("Phone Number cannot be empty");
userfrm.txt_phone.focus();
return false;
}
else if(trim((userfrm.txt_city.value))=="")
{
alert("City Cannot be empty");
userfrm.txt_city.focus();
return false;
}
else if(trim((userfrm.txt_province.value))=="")
{
alert("Province (State) Cannot be empty");
userfrm.txt_province.focus();
return false;
}
else if(trim((userfrm.txt_zip.value))=="")
{
alert("Zip Code Cannot be empty");
userfrm.txt_zip.focus();
return false;
}

else
{
return true;
}
}

	
