//====================================================================================================
//	Function Name	:	Validate_Form()
//----------------------------------------------------------------------------------------------------

function validator(theForm)
{ 

	if (theForm.title.value == "")
	{
		alert("Please enter a value for the title field.");
		theForm.title.focus();
		return (false);
	}
	
   if (theForm.first_name.value == "")
   {
		alert("Please enter a value for the name field.");
		theForm.first_name.focus();
		return (false);
   }
  if (theForm.surname.value == "")
  {
	alert("Please enter a value for the surname field.");
	theForm.surname.focus();
	return (false);
  }
  if (theForm.company_name.value == "")
  {
	alert("Please enter a value for the company name field.");
	theForm.company_name.focus();
	return (false);
  }

  if (theForm.position.value == "")
  {
	alert("Please enter a value for the position field.");
	theForm.position.focus();
	return (false);
  }

 if (theForm.add1.value == "")
  {
	alert("Please enter address 1 field.");
	theForm.add1.focus();
	return (false);
  }
  if (theForm.add2.value == "")
  {
	alert("Please enter address 2 field.");
	theForm.add2.focus();
	return (false);
  }
  if (theForm.city.value == "")
  {
	alert("Please enter city field.");
	theForm.city.focus();
	return (false);
  }
  if (theForm.postcode.value == "")
  {
	alert("Please Enter post code.");
	theForm.postcode.focus();
	return (false);
  }
  
  if (theForm.country.value == "0")
  {
	alert("Please select your country.");
	theForm.country.focus();
	return (false);
  }
  if (theForm.phone.value == "")
  {
	alert("Please enter phone number.");
	theForm.phone.focus();
	return (false);
  }
  
  if (theForm.email.value == "")
  {
	alert("Please enter email address.");
	theForm.email.focus();
	return (false);
  }
  if(!IsEmail(theForm.email,'Please enter valid email address'))
  {
	return false;
  }
  
  if (theForm.email_con.value == "")
  {
	alert("Please enter Varify email address.");
	theForm.email_con.focus();
	return (false);
  }
  
  else  if(theForm.email_con.value != theForm.email.value)
  {
	alert('Email confirmation does not match!!');	
	theForm.email_con.focus();
	return (false);
  }
  
  if (theForm.website.value == "")
  {
	alert("Please enter company website.");
	theForm.website.focus();
	return (false);
  }
  
  
  theForm.Submit1.value = "Submit";
  submit();
  
}

function IsEmail(fld,msg)
{
	var regex = /^[\w]+(\.[\w]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/ ;
	if(!regex.test(fld.value))
	{
		alert(msg);
		fld.focus();
		return false;
	}
	return true;
}

function IsEmpty(fld,msg)
{
	if((fld.value == "" || fld.value.length == 0) && (msg == ''))
	{
		return false;
	}
	if(fld.value == "" || fld.value.length == 0)
	{
		alert(msg);
		try {fld.focus();}catch(e){return true;}
		return false;
	}
	return true;
}



