// JavaScript Document

function formValidation(theForm, action)
{
  	var greenlight = true;
  
	if (theForm.name.value == "")
	{
		alert("Please enter a value for the \"Name\" field.");
		theForm.name.focus();
		return false;
	}
  
	if (theForm.surname.value == "")
	{
		alert("Please enter a value for the \"Surname\" field.");
		theForm.surname.focus();
		return false;
	}
  
	if(action == "register")
	{
		if (theForm.email.value == "")
		{
			alert("Please enter a value for the \"Email\" field.");
			theForm.email.focus();
			return false;
		}
	}
	
	var phonecounter = 0;
	
	if (theForm.homeprefix.value != "select" && theForm.home.value != "" )
	{
		phonecounter++;
	}
	
	if (theForm.workprefix.value != "select" && theForm.work.value != "" )
	{
		phonecounter++;
	}
	
	if (theForm.mobileprefix.value != "select" && theForm.mobile.value != "" )
	{
		phonecounter++;
	}

 	if(phonecounter<=1){
		alert("You must enter at least two phone numbers.");
		return false;
	}	
	
	if(action == "register"){
		if (theForm.password_form.value == "")
		{
			alert("Please enter a value for the \"Password\" field followed by the same password in the confirmation field.");
			theForm.password_form.focus();
			return false;
		}	
	}
	
	
	if(theForm.agree_to_terms.checked==false){
		alert("You must agree to our terms and conditions");
		return false;
	}
	
	return true;
	
  
}

function checkPassword () {
  // check if password is entered
  if (document.personalData.password_form.value == "") {
   alert("Please enter a password!");
   document.personalData.password_form.focus();
   return false;
  }
 
  // check if password and repetition are same
  if (document.personalData.password_form.value != document.personalData.password_confirm.value) {
   alert("Passwords are NOT identical!");
   document.personalData.password_form.focus();
   return false;
  }
  return true;
}