function trim(str)
{
    if(!str || typeof str != 'string')
	{
        return "";
		}

    return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}
function validate(theForm){
	if (trim(theForm.txtFName.value)== ""){
		alert("Please fill in your name");
		theForm.txtFName.value="";
		theForm.txtFName.focus();
		return false;
	}
	if (trim(theForm.txtAddress1.value) == ""){
		alert("Please fill in your Address");
		theForm.txtAddress1.value="";
		theForm.txtAddress1.focus();
		return false;
	}
    if (trim(theForm.txtCountry.value) == ""){
		alert("Please fill in your Country");
		theForm.txtCountry.value="";
		theForm.txtCountry.focus();
		return false;
	}
	
    if (trim(theForm.txtPCode.value) == ""){
		alert("Please fill in your Postal Code.");
		theForm.txtPCode.value="";
		theForm.txtPCode.focus();
		return false;
	}
    if (trim(theForm.txtEmail.value) == ""){
		alert("Please fill in your Email Id");
		theForm.txtEmail.value="";
		theForm.txtEmail.focus();
		return false;
	}
	
 var emailID=document.theForm.txtEmail
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
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					
	}

}
//-->

