/*This javascript file validates the following forms:
			1. Contact Us
			2. Register
			3. High Intensity - Consult Us
*/			


function validate_consult_us(form)
{
//Start validating name, subject, message all from the Contact Us form
  	if(form.enquiry_name.value ==""){
		alert("You must enter your contact name");
		form.enquiry_name.focus();
		
		return false;
	}
	
	if(form.enquiry_telephone.value ==""){
		alert("You must enter a contact telephone number");
		form.enquiry_telephone.focus();
		return false;
	}
	
	if(form.enquiry_details.value ==""){
		alert("Please enter an enquiry");
		form.enquiry_telephone.focus();
		return false;
	}
	
	return checkMail(form);

	return true;
}
//--------------------------------------------------------------------------------------------------

function validate_contactUs(form)
{
//Start validating name, subject, location message all from the Contact Us form
  	if(form.contactName.value ==""){
		alert("You must enter your contact name");
		form.contactName.focus();
		
		return false;
	}
	
	if(form.check_subject.value ==""){
		alert("You must enter a subject");
		form.check_subject.focus();
		return false;
	}
	
	if(form.message.value ==""){
		alert("Please enter a message");
		form.message.focus();
		return false;
	}
	
	if(form.location.value =="0"){
		alert("Please select a location");
		form.location.focus();
		return false;
	}
	
	return checkMail(form)
	
	return true;
	
}
//--------------------------------------------------------------------------------------------------

//start validating email
function checkMail(form)
{
	//Start validating email
	if (form.check_email.value.length==0) {
		alert("You must enter your email address");
      	form.check_email.focus();
      	return false;
 	}

	 var ix1=form.check_email.value.indexOf("@")
	 if (ix1 == -1) {
		 alert ("Your email address does not appear to be valid. Expecting name@domain.com")
		 form.check_email.focus();
		 return false;
	 }
  
	 var temp=form.check_email.value.split(ix1)
	 ix2 =  form.check_email.value.indexOf(".")
	 if (ix2 == -1) {
		 alert ("Your email address does not appear to be valid. Expecting name@domain.com")
		 form.check_email.focus();
		 return false;
  	}
  
	// at least one @ must be present and not before position 2
	// @yellow.com : NOT valid
	// x@yellow.com : VALID

	var myAtSymbolAt = form.check_email.value.indexOf("@");
	if (myAtSymbolAt < 1 ) 
 	{
    	alert ("At least one @ must be present after the username");
     	form.check_email.focus();
     	return false;		
	}

	// at least one . (dot) afer the @ is required
	// x@yellow : NOT valid
	// x.y@yellow : NOT valid
	// x@yellow.org : VALID
	
	var myLastDotAt = form.check_email.value.lastIndexOf(".");
	if (myLastDotAt < myAtSymbolAt) 
 	{
    	alert ("At least one . (dot) afer the @ is required");
     	form.check_email.focus();
     	return false;		
	}

	// at least two characters [com, uk, fr, ...] must occur after the last . (dot)
	// x.y@yellow. : NOT valid
	// x.y@yellow.a : NOT valid
	// x.y@yellow.ca : VALID

	var myLength = form.check_email.value.length;
	if (myLength - myLastDotAt <= 2) 
 	{
    	alert ("At least two characters [e.g. com, uk, fr, ...] must occur after the last . (dot)");
     	form.check_email.focus();
     	return false;		
	}

	// no empty space " " is permitted (one may trim the email)
	// x.y@yell ow.com : NOT valid
	
	var mySpaceAt = form.check_email.value.indexOf(" ");
	if (mySpaceAt != -1) 
 	{
    	alert ("No empty space [e.g. x.y@yell ow.com] is permitted");
     	form.check_email.focus();
     	return false;		
	}
	return true;
}	
//End validating email
//--------------------------------------------------------------------------------------------------

//start validating register form page. 
function validate_register(form)
{
	//Start validating stuff from the Register form
	
	if(form.surname.value ==""){
		alert("You must enter your surname");
		form.surname.focus();
		return false;
	}
	
	if(form.first_name.value ==""){
		alert("You must enter your first name");
		form.first_name.focus();
		return false;
	}

	if(form.street_address.value ==""){
		alert("You must enter your street");
		form.street_address.focus();
		return false;
	}
	
	if(form.city.value ==""){
		alert("You must enter your city");
		form.city.focus();
		return false;
	}

	if(form.postcode.value==""){
		alert("You must enter your postcode");
		form.postcode.focus();
		return false;
	}
	
	if (isNaN(form.postcode.value)){	
		alert("Please enter a valid postcode");
		form.postcode.value='';
		form.postcode.focus();
		return false;
	}
	
	if(form.get_state.value ==""){
		alert("You must enter your state");
		form.get_state.focus();
		return false;
	}
	
	if(form.private_password.value==""){
		alert("You must enter a password");
		form.private_password.focus();
		return false;
	}
	
	if(form.private_password.value != form.check_password.value){
		alert("Your passwords are not the same, please enter the same passwords");
		form.private_password.value='';
		form.check_password.value='';
		form.private_password.focus();
		return false;
	}
	

	if(form.get_country.selectedIndex==0){
		alert("Please select a country");
		form.get_country.focus();
		return false;
	}

	return checkMail(form);
		
	return true;
}
//End validating surname,firstname,street,suburb,postcode,country, mail from the register form
//--------------------------------------------------------------------------------------------------

//start validating password on my_account_password.asp
function validate_password(form)
{
		if(form.old_private_password.value==""){
		alert("You must your old password");
		form.old_private_password.focus();
		return false;
	}
	
	if(form.new_private_password.value==""){
		alert("You must enter a new password");
		form.new_private_password.focus();
		return false;
	}
	
	if(form.check_password.value==""){
		alert("You must confirm your new password");
		form.check_password.focus();
		return false;
	}
	
	if(form.new_private_password.value != form.check_password.value){
		alert("Your passwords are not the same, please enter the same passwords");
		form.new_private_password.value='';
		form.check_password.value='';
		form.new_private_password.focus();
		return false;
	}
}

//--------------------------------------------------------------------------------------------------

	
function validate_details(form)
{
	//Start validating stuff from the Register form
	
	if(form.surname.value ==""){
		alert("You must enter your surname");
		form.surname.focus();
		return false;
	}
	
	if(form.first_name.value ==""){
		alert("You must enter your first name");
		form.first_name.focus();
		return false;
	}

	if(form.street_address.value ==""){
		alert("You must enter your street");
		form.street_address.focus();
		return false;
	}
	
	if(form.city.value ==""){
		alert("You must enter your city");
		form.city.focus();
		return false;
	}

	if(form.postcode.value==""){
		alert("You must enter your postcode");
		form.postcode.focus();
		return false;
	}
	
	if (isNaN(form.postcode.value)){	
		alert("Please enter a valid postcode");
		form.postcode.value='';
		form.postcode.focus();
		return false;
	}
	
	if(form.get_state.value ==""){
		alert("You must enter your state");
		form.get_state.focus();
		return false;
	}

	if(form.get_country.selectedIndex==0){
		alert("Please select a country");
		form.get_country.focus();
		return false;
	}

	return checkMail(form);
		
	return true;
}

//End validating surname,firstname,street,suburb,postcode,country, mail from the register form
//--------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------
