var localForm; 
function initForm(theForm)   { localForm = theForm; }
//function closeCalendar(io)   {}
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 Validate(theForm) 
{
	if (Trim(theForm.Property.value) == "") {
        alert("Please enter property name.");
        theForm.Property.focus();
        return (false);
    }
	if (Trim(theForm.Amount.value) == "") {
        alert("Please enter Amount.");
        theForm.Amount.focus();
        return (false);
    }
    if (Trim(theForm.FirstName.value) == "") {
        alert("Please enter first name.");
        theForm.FirstName.focus();
        return (false);
    }
   if (Trim(theForm.LastName.value) == "")   
      {
      alert("Please enter last name.");
      theForm.LastName.focus();
      return (false);
      }
   if (Trim(theForm.Email.value) == "")
  {
    alert("Please enter email address.");
    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.Address.value) == "")
  {
    alert("Please enter address.");
    theForm.Address.focus();
    return (false);
  }
  if (Trim(theForm.City.value) == "")
  {
    alert("Please enter City.");
    theForm.City.focus();
    return (false);
  }
  if ((Trim(theForm.State.value) == "")&& ((Trim(theForm.Country.value) == "US")))
  {
    alert("State is required for US Residence.");
    theForm.State.focus();
    return (false);
  }
 
    if ((Trim(theForm.Zip.value) == "")&& ((Trim(theForm.Country.value) == "US")))
  {
    alert("Zip code is required for US Residence.");
    theForm.Zip.focus();
    return (false);
  }
 
	
   if (Trim(theForm.Country.value) == "")
  {
    alert("Please enter Country.");
    theForm.Country.focus();
    return (false);
  }
   if (Trim(theForm.PhoneArea.value) == "")
  {
    alert("Please enter Phone Area.");
    theForm.PhoneArea.focus();
    return (false);
  }
  if (Trim(theForm.Phone.value) == "")
  {
    alert("Please enter Phone");
    theForm.Phone.focus();
    return (false);
  }
  var checkOK = "0123456789()- ";
	var checkStr = theForm.Phone.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 digits for the Phone Number.");
		theForm.Phone.focus();
		return (false);
	}
	var myOption = -1;
for (i=0; i < theForm.SendTo.length; i ++) 
{
	if (theForm.SendTo[i].checked) 
	{
		myOption = i; 
		break;
	}
}
 if (myOption == theForm.SendTo.length || myOption == -1) 
{
	alert("Please select to whom deliver.");
	theForm.SendTo[0].focus();
	return false;
}

if ((theForm.SendToN.checked==true)&&(theForm.R_First_Name.value==""))
{
   alert("Please enter recipient first name.");
   theForm.R_First_Name.focus();
   return (false);
}	

if ((theForm.SendToN.checked==true)&&(theForm.R_Last_Name.value==""))
{
   alert("Please enter recipient last name.");
   theForm.R_Last_Name.focus();
   return (false);
}	

if ((theForm.SendToN.checked==true)&&(theForm.R_Address.value==""))
{
   alert("Please enter recipient address.");
   theForm.R_Address.focus();
   return (false);
}	

if ((theForm.SendToN.checked==true)&&(theForm.R_City.value==""))
{
   alert("Please enter recipient city.");
   theForm.R_City.focus();
   return (false);
}	

if ((theForm.SendToN.checked==true)&&(theForm.R_State.value=="")&&(theForm.R_Country.value=="US"))
{
   alert("Please enter recipient state.");
   theForm.R_State.focus();
   return (false);
}

if ((theForm.SendToN.checked==true)&&(theForm.R_Zip.value=="")&&(theForm.R_Country.value=="US"))
{
   alert("Please enter recipient zip code.");
   theForm.R_Zip.focus();
   return (false);
}	
if ((theForm.SendToN.checked==true)&&(theForm.R_Country.value==""))
{
   alert("Please enter recipient country.");
   theForm.R_Country.focus();
   return (false);
}	
	
   if (Trim(theForm.NameOnCard.value) == "")
  {
    alert("Please enter Name On Card");
    theForm.NameOnCard.focus();
    return (false);
  }
if (Trim(theForm.CardNum.value) == "")
  {
    alert("Please enter Card Number");
    theForm.CardNum.focus();
    return (false);
  }
  var checkOK = "0123456789";
		var checkStr = strip(theForm.CardNum.value) + '';
		var CrValid = true;
		var checksum=0;
		var ddigit=0;
		var kdig = 0;
		
		if (checkStr.length < 13) {
			alert ('You have not entered enough digits. Please check the number for errors.');
					return(false);
		}
		
		for (i = checkStr.length-1;  i >= 0;  i--) {
			kdig++;
			ch = checkStr.charAt(i);
			if ((kdig % 2) != 0) {
				checksum=checksum+parseInt(ch)
			}
			else {
				ddigit=parseInt(ch)*2;
				if (ddigit >= 10)
					checksum=checksum+1+(ddigit-10)
				else
					checksum=checksum+ddigit;
			}
			for (j = 0;  j < checkOK.length;  j++) {
				if (ch == checkOK.charAt(j)) {
					break;
				}
				if (j == checkOK.length) {
					alert('Please enter only digits. No dashes or non-numeric characters.');
					return(false);
				}
			}
		}
  
		if ((checksum % 10) != 0) {
			alert('You have entered an invalid credit card number. Please check the number for errors.');
			theForm.CardNum.focus();
			return (false);
		}
		  if (theForm.ExpirationYear.value < TodayYear )
  {
	  
    alert("Please enter a valid expiration year");
    theForm.ExpirationYear.focus();
    return (false);
  }
  
  if ((theForm.ExpirationYear.value == TodayYear ) && (theForm.ExpirationMonth.value < TodayMonth ) )
  {
    alert("Please enter a valid expiration month");
    theForm.ExpirationMonth.focus();
    return (false);
  }
		 if (Trim(theForm.boxCode.value) == "")   
  {
      alert("Please retry the secret code. The form will not be submitted unless the correct letters and digits are entered.  If you are having trouble viewing the code, you can refresh your Internet screen, and a new code will appear.");
      theForm.boxCode.focus();
      return (false);
  }

return (true);
}