//FUNCTION - validateForm
function validateForm(RegForm) { 
//START VALIDATION
	if (RegForm.M_title.value == "") { 
	alert("Please choose a title."); 		   
	RegForm.M_title.focus( ); 
	return false; 
	}
	else if
	(valbutton(RegForm)==false) { 
   return false; 
	}	
	else if
   (RegForm.name.value == "") { 
   alert("The name field is empty."); 
   RegForm.name.focus( ); 
   return false; 
	}
	else if
   (RegForm.M_affiliation.value == "") { 
   alert("The affiliation field is empty."); 
   RegForm.M_affiliation.focus( ); 
   return false; 
	}
	else if
   (RegForm.address.value == "") { 
   alert("The address field is empty."); 
   RegForm.address.focus( ); 
   return false; 
	}
	else if
   (RegForm.country.value == "") { 
   alert("The country field is empty."); 
   RegForm.country.focus( ); 
   return false; 
	}
	else if
   (RegForm.postcode.value == "") { 
   alert("The postcode field is empty."); 
   RegForm.postcode.focus( ); 
   return false; 
	}
	else if
   (RegForm.tel.value == "") { 
   alert("The phone field is empty."); 
   RegForm.tel.focus( ); 
   return false; 
	}
	else if
   (RegForm.fax.value == "") { 
   alert("The fax field is empty."); 
   RegForm.fax.focus( ); 
   return false; 
	}	
	else if (RegForm.email.value == ""){
   alert("The email field is empty."); 
   RegForm.email.focus( ); 
   return false; 
   }
	else if (RegForm.email.value != "" && echeck(RegForm.email.value)==false){
	RegForm.email.value=""
	RegForm.email.focus()
	return false
	}
	else if (RegForm.amount.value == 0){
   alert("You have not selected any items to purchase."); 
   return false; 
   }	
}


//email validation function, called from within above validateForm function
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 E-mail that you have entered is not valid")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("The E-mail that you have entered is not valid")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("The E-mail that you have entered is not valid")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("The E-mail that you have entered is not valid")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("The E-mail that you have entered is not valid")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("The E-mail that you have entered is not valid")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("The E-mail that you have entered is not valid")
		    return false
		 }
 		 return true					
}
function valbutton(thisform) {
// place any other field validations that you require here
// validate myradiobuttons
myOption = -1;
for (i=0; i<thisform.M_sex.length; i++) {
	if (thisform.M_sex[i].checked) {
	myOption = i;
	}
}
	if (myOption == -1) {
	alert("Please let us know what sex you are");
	thisform.M_sex[1].focus;
	return false;
	}
}
