
function LTrim(str)
{  var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(0)) != -1) {
       var j=0, i = s.length;
       while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
              j++;
       s = s.substring(j, i);
   }
return s;
}
function RTrim(str)
{  var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
       var i = s.length - 1;       
       while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
              i--;
       s = s.substring(0, i+1);
   }
return s;
}
var TodayDate=new Date();
var TodayMonth=TodayDate.getMonth()+1;
var TodayYear=TodayDate.getYear();
var TodayDay=TodayDate.getDate();
function Trim(str)  { return RTrim(LTrim(str)); }
function strip(number) {
		var sOut = '';
		mask = '1234567890';
		for(count = 0; count <= number.length; count++) {
 			if(mask.indexOf(number.substring(count, count+1),0) != -1 ) sOut += number.substring(count,count+1);
 		}
		return sOut;
	}
function ValidateBirthday(theForm) {
	if (Trim(theForm.DesiredMonth.value) == "")
  {
    alert("Please enter month of your desired date.");
    theForm.DesiredMonth.focus();
    return (false);
  }
  if (Trim(theForm.DesiredDay.value) == "")
  {
    alert("Please enter day of your desired date.");
    theForm.DesiredDay.focus();
    return (false);
  }
  if (Trim(theForm.DesiredYear.value) == "")
  {
    alert("Please enter year of your desired date.");
    theForm.DesiredYear.focus();
    return (false);
  }
  
   if (Trim(theForm.DesiredYear.value) < TodayYear)
  {
    alert("Please choose date in future.");
    theForm.DesiredYear.focus();
    return (false);
  }
  if ((theForm.DesiredMonth.value < TodayMonth) && (theForm.DesiredYear.value == TodayYear))
  {
    alert("Please choose a date in future.");
    theForm.DesiredMonth.focus();
    return (false);
  }
   if ((theForm.DesiredDay.value <= TodayDay) && (theForm.DesiredMonth.value == TodayMonth))
  {
	  //alert(TodayDay);
    alert("Please choose a date in future.");
    theForm.DesiredDay.focus();
    return (false);
  }
  
	if (Trim(theForm.BChildName.value) == "")
  {
    alert("Please enter child name.");
    theForm.BChildName.focus();
    return (false);
  }
  
  if (Trim(theForm.BAge.value) == "")
  {
    alert("Please enter child age.");
    theForm.BAge.focus();
    return (false);
  }
   if ((theForm.Girls.value== "")&& (theForm.Boys.value== ""))
  {
    alert("Please enter party guest age/s.");
    theForm.Girls.focus();
    return (false);
  }
  
  if (Trim(theForm.ParentName.value) == "")
  {
    alert("Please enter parent name.");
    theForm.ParentName.focus();
    return (false);
  }
   if (Trim(theForm.Address.value) == "")
  {
    alert("Please enter your address.");
    theForm.Address.focus();
    return (false);
  }
   if (Trim(theForm.City.value) == "")
  {
    alert("Please enter your city.");
    theForm.City.focus();
    return (false);
  }
  if (Trim(theForm.State.value) == "")
  {
    alert("Please enter your state.");
    theForm.State.focus();
    return (false);
  }
  if (Trim(theForm.Zip.value) == "")
  {
    alert("Please enter your zip code.");
    theForm.Zip.focus();
    return (false);
  }
  if (Trim(theForm.HPhone.value) == "")
  {
    alert("Please enter your home phone.");
    theForm.HPhone.focus();
    return (false);
  }
  
  if (Trim(theForm.Email.value) == "")
  {
    alert("Please enter your email.");
    theForm.Email.focus();
    return (false);
  }

	var checkStr = theForm.Email.value;
	var ch = checkStr.indexOf('@');

	if (ch==0 || ch==-1) {
		alert("Please enter a valid email address.");
		theForm.Email.focus();
		return (false);
	}
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzfSOZsozYÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ0123456789-@.-_'";
	var checkStr = theForm.Email.value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++) {
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;
				if (j == checkOK.length) {
					allValid = false;
					break;
				}
	}
	if (!allValid) {
		alert("Please enter only letter, digit and \"@.-_'\" characters in the \"Email\" field.");
		theForm.Email.focus();
		return (false);
	}
	 if (Trim(theForm.Adult.value) == "")
  {
    alert("Please enter number of adults.");
    theForm.Adult.focus();
    return (false);
  }
  
   if (Trim(theForm.Children.value) == "")
  {
    alert("Please enter number of children.");
    theForm.Children.focus();
    return (false);
  }
var myOption = -1;
for (i=0; i < theForm.Payment.length; i ++) 
{
	if (theForm.Payment[i].checked) 
	{
		myOption = i; 
		break;
	}
}
 if (myOption == theForm.Payment.length || myOption == -1) 
{
	alert("Please select method of your payment.");
	theForm.Payment[0].focus();
	return false;
}
if ((theForm.Check.checked==true)&&(theForm.CheckNumber.value==""))
{
   alert("Please enter your check number.");
   theForm.CheckNumber.focus();
   return (false);
}

if (theForm.CreditCard.checked==true)
{
var myOption = -1;
for (i=0; i < theForm.CreditCardType.length; i ++) 
{
	if (theForm.CreditCardType[i].checked) 
	{
		myOption = i; 
		break;
	}
}
}
if (myOption == theForm.CreditCardType.length || myOption == -1) 
{
	alert("Please select credit card type.");
	theForm.CreditCardType[0].focus();
	return false;
}
if ((theForm.CreditCard.checked==true)&&(theForm.CreditCardNumber.value==""))
  {
    alert("Please enter your credit card number.");
    theForm.CreditCardNumber.focus();
    return (false);
  }
	

 if ((theForm.CID.value == "") &&  (theForm.CreditCard.checked==true))
  {
    alert("Please enter security code.");
    theForm.CID.focus();
    return (false);
  }
  if ((theForm.ExpireYear.value < TodayYear ) && (theForm.CreditCard.checked==true))
  {
	  
    alert("Please enter a valid expiration year");
    theForm.ExpireYear.focus();
    return (false);
  }
  
  if ((theForm.ExpireYear.value == TodayYear ) && (theForm.ExpireMonth.value < TodayMonth ) && (theForm.CreditCard.checked==true))
  {
    alert("Please enter a valid expiration month");
    theForm.ExpireMonth.focus();
    return (false);
  }
  if ((theForm.NameOnCard.value == "") && (theForm.CreditCard.checked==true))
  {
    alert("Please enter name on card.");
    theForm.NameOnCard.focus();
    return (false);
  }
  if ((theForm.MAddress.value == "") && (theForm.CreditCard.checked==true))
  {
    alert("Please enter mailing address.");
    theForm.MAddress.focus();
    return (false);
  }
  if ((theForm.MCity.value== "") && (theForm.CreditCard.checked==true))
  {
    alert("Please enter mailing city.");
    theForm.MCity.focus();
    return (false);
  }
  if ((theForm.MState.value == "") && (theForm.CreditCard.checked==true))
  {
    alert("Please enter mailing state.");
    theForm.MState.focus();
    return (false);
  }
  if ((theForm.MZip.value == "") && (theForm.CreditCard.checked==true))
  {
    alert("Please enter mailing zip code.");
    theForm.MZip.focus();
    return (false);
  }
  if ((theForm.MCountry.value == "") && (theForm.CreditCard.checked==true))
  {
    alert("Please enter mailing country.");
    theForm.MCountry.focus();
    return (false);
  }
 

return (true);
}
