function emailcheck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var lstr1=str.length-1
		var ldot=str.indexOf(dot)
		var strchr=str.substr(lstr-1,1)
		if (lstr < 5 ){
		 //  alert("Invalid E-mail ID")
		   return false
		}
		if (strchr == dot ){
		 //  alert("Invalid E-mail ID")
		   return false
		}
		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)==lstr1){
		  //  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 Trim(TRIM_VALUE){
if(TRIM_VALUE.length < 1){
return"";
}
TRIM_VALUE = RTrim(TRIM_VALUE);
TRIM_VALUE = LTrim(TRIM_VALUE);
if(TRIM_VALUE==""){
return "";
}
else{
return TRIM_VALUE;
}
} //End Function

function RTrim(VALUE){
var w_space = String.fromCharCode(32);
var v_length = VALUE.length;
var strTemp = "";
if(v_length < 0){
return"";
}
var iTemp = v_length -1;

while(iTemp > -1){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(0,iTemp +1);
break;
}
iTemp = iTemp-1;

} //End While
return strTemp;

} //End Function

function LTrim(VALUE){
var w_space = String.fromCharCode(32);
if(v_length < 1){
return"";
}
var v_length = VALUE.length;
var strTemp = "";

var iTemp = 0;

while(iTemp < v_length){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(iTemp,v_length);
break;
}
iTemp = iTemp + 1;
} //End While
return strTemp;
} //End Function

function checkForm(testForm){

 	if (Trim(testForm.firstName.value) ==""){
	alert("Please fill in your First Name.")
	testForm.firstName.select()
	return false;
	}	

	if (Trim(testForm.lastName.value) ==""){
	alert("Please fill in your Last Name.")
	testForm.lastName.select()
	return false;
	}	 
	
	if((testForm.gender[0].checked==false) && (testForm.gender[1].checked==false)){
 	alert("Please select your Gender.")
	 return false;
	}

	if (Trim(testForm.age.value) ==""){
	//alert("Please fill in your Age.")
    //testForm.age.select()
	//return false;
	}	
	
	
	if (Trim(testForm.address.value) ==""){
	alert("Please fill in your Address.")
	testForm.address.select()
	return false;
	}
	
	if (testForm.country.value =="NIL"){
	alert("Please select your Country.")
	testForm.country.focus()
	return false;
	}
	
	if (Trim(testForm.state.value) ==""){
	alert("Please fill in your State.")
	testForm.state.select()
	return false;
	}
	
	if (Trim(testForm.postal.value) ==""){
	alert("Please fill in your Postal Code.")
	testForm.postal.select()
	return false;
	}
	
	if (Trim(testForm.Email.value) ==""){
	alert("Please fill in your Email.")
	testForm.Email.select()
	return false;
	}else{
	 if (emailcheck(testForm.Email.value) == false){
     alert("Email is not valid. Please check your email address.")
	 testForm.Email.focus()
	 return false;
	 }
	}
	

	if (testForm.subject.value =="NIL"){
	alert("Please select the Subject.")
	testForm.subject.focus()
	return false;
	}
	
}

 
