//DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
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("The email address you entered is not valid, please try again")
	   return false
	}
	
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("The email address you entered is not valid, please try again")
	   return false
	}
	
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	   alert("The email address you entered is not valid, please try again")
		return false
	}
	
	 if (str.indexOf(at,(lat+1))!=-1){
	   alert("The email address you entered is not valid, please try again")
		return false
	 }
	
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	   alert("The email address you entered is not valid, please try again")
		return false
	 }
	
	 if (str.indexOf(dot,(lat+2))==-1){
	   alert("The email address you entered is not valid, please try again")
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
	   alert("The email address you entered is not valid, please try again")
		return false
	 }
	
	 return true					
}

// Validates the form client side
function validateThisForm() {
	
	// Initializes the variables used during validation
	if( document.getElementById ) {
		name = document.getElementById( 'name' );
		email = document.getElementById( 'email' );
		phone = document.getElementById( 'phone' );
	} else if ( document.all ) {
		name = document.all['name'];
		email = document.all['email'];
		phone = document.all['phone'];
	} else if ( document.layers ) {
		name = document.layers['name'];
		email = document.layers['email'];
		phone = document.layers['phone'];
	}
		
	// Validates the first name field
	if((name.value.length == 0) || (name.value == null)) {
		alert("Please enter your name in the selected field.");
		name.focus();
		return false;
	}
	
	if (echeck(email.value)==false){
		email.value=""
		email.focus()
		return false
	}
	
	// Validates the last name field
	if((phone.value.length == 0) || (phone.value == null)) {
		alert("Please enter your phone number in the selected field.");
		phone.focus();
		return false;
	}
}