// JavaScript Document form checks


function ltrim (s){
	return s.replace( /^\s*/, "" );
}

function rtrim (s){
	return s.replace( /\s*$/, "" );
}

function trim (s){
	return rtrim(ltrim(s));
}

function isEmailAddr(email)
{
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

 function ConfirmEmail()
 {
 	if (document.webFrm.email.value != document.webFrm.confirmEmail.value)
	{
		alert("Please enter your Confirm e-mail Address again!");
		document.webFrm.confirmEmail.focus();
		return (false);
	}
 }
 
   function FormValidator(theForm)
   {
	  
	  if (theForm.realname.value == "")
	  {
		alert("Please enter Contact Name");
		theForm.realname.focus();
		return (false);
	  }
	  if (theForm.firstDate.value == "")
	  {
		alert("Please select 1st choice date");
		theForm.firstDate.focus();
		return (false);
	  }
	   if (theForm.firstMonth.value == "")
	  {
		alert("Please select 1st choice month");
		theForm.firstMonth.focus();
		return (false);
	  }
	 
	   
	   if (theForm.secondDate.value == "")
	  {
		alert("Please select 2nd choice date");
		theForm.secondDate.focus();
		return (false);
	  }
	  if (theForm.secondMonth.value == "")
	  {
		alert("Please select 2nd choice month");
		theForm.secondMonth.focus();
		return (false);
	  }
	   
	   if (theForm.thirdDate.value == "")
	  {
		alert("Please select 3rd choice date");
		theForm.thirdDate.focus();
		return (false);
	  }
	   if (theForm.thirdMonth.value == "")
	  {
		alert("Please select 3rd choice month");
		theForm.thirdMonth.focus();
		return (false);
	  }
	 
	  if (theForm.email.value == "")
	  {
		alert("Please enter your e-mail Address");
		theForm.email.focus();
		return (false);
	  }
	  if (!isEmailAddr(theForm.email.value))
	  {
		alert("Please enter a complete email address in the form: yourname@yourdomain.com");
		theForm.email.focus();
		return (false);
	  }
	   
	  if (theForm.email.value.length < 3)
	  {
		alert("Email should be more then 3 characters");
		theForm.email.focus();
		return (false);
	  }
	  	  
	  if (theForm.confirmEmail.value != theForm.email.value)
	  {
		alert("Please enter your Confirm e-mail Address");
		theForm.confirmEmail.focus();
		return (false);
	  }
	  if (theForm.country.options[theForm.country.selectedIndex].value == "")
	  {
	  	alert("Please select your Country");
		theForm.country.focus();
		return (false);
	  }
	  
	  if (theForm.type.options[theForm.type.selectedIndex].value == "")
	  {
		alert("Please select type of your wedding");
		theForm.type.focus();
		return (false);
	  }
	    if (theForm.package.options[theForm.package.selectedIndex].value == "")
	  {
		alert("Please select package");
		theForm.package.focus();
		return (false);
	  }
	  if (theForm.GuestNumber.options[theForm.GuestNumber.selectedIndex].value == "")
	  {
		alert("Please select number of planned guests");
		theForm.GuestNumber.focus();
		return (false);
	  }
	   if (theForm.currency.options[theForm.currency.selectedIndex].value == "")
	  {
		alert("Please select your currency");
		theForm.currency.focus();
		return (false);
	  }
	  	   if (theForm.reception.options[theForm.reception.selectedIndex].value == "")
	  {
		alert("Please select if you want a reception dinner or entertainment?");
		theForm.reception.focus();
		return (false);
	  }
	
	  if (theForm.LegalMarriage.options[theForm.LegalMarriage.selectedIndex].value == "")
	  {
		alert("Please select Do You Want To Have A Legal Marriage In Thailand?");
		theForm.LegalMarriage.focus();
		return (false);
	  }
	  if (theForm.HearAboutUs.options[theForm.HearAboutUs.selectedIndex].value == "")
	  {
		alert("Please select where did you hear about us?");
		theForm.HearAboutUs.focus();
		return (false);
	  }
	  if (theForm.imgverify.value == "")
	  {
		alert("Please enter Image Verification");
		theForm.imgverify.focus();
		return (false);
	  }
   }
