	//Fill in initial from first name
   	function DoInitial(form) 
   	{
	  	form.Initials.value = form.FirstName.value.charAt(0);
		form.Initials.value = form.Initials.value.toUpperCase();
	}
   	

   // One word
   function ValidateIsOneWord(sText)
   {
      var n;
      for (n = 0; n < sText.length; n++)
         if (sText.charAt(n) == " ") return false;

      return true;
   }

   // Alpha text
   function ValidateIsAlpha(sText)
   {
      if (sText == "")
         return false;
   
      var n;
	   for (n = 0; n < sText.length; n++)
	   {
	      if ((sText.charAt(n) == "0") ||
	          (sText.charAt(n) == "1") ||
	          (sText.charAt(n) == "2") ||
	          (sText.charAt(n) == "3") ||
	          (sText.charAt(n) == "4") ||
	          (sText.charAt(n) == "5") ||
	          (sText.charAt(n) == "6") ||
	          (sText.charAt(n) == "7") ||
	          (sText.charAt(n) == "8") ||
	          (sText.charAt(n) == "9"))
	         return false;
	   }
	   return true;
   }

   // Alpha text
   function ValidateHasAlpha(sText)
   {
      if (sText == "")
         return false;
   
      if (ValidateIsNumeric(sText))
         return false;
      
	   return true;
   }
   
   // NumericText
   function ValidateIsNumeric(sText)
   {
      if (sText == "")
         return false;

      var n;
	   for (n = 0; n < sText.length; n++)
	   {
	      if ((sText.charAt(n) != "0") &&
	          (sText.charAt(n) != "1") &&
	          (sText.charAt(n) != "2") &&
	          (sText.charAt(n) != "3") &&
	          (sText.charAt(n) != "4") &&
	          (sText.charAt(n) != "5") &&
	          (sText.charAt(n) != "6") &&
	          (sText.charAt(n) != "7") &&
	          (sText.charAt(n) != "8") &&
	          (sText.charAt(n) != "9") &&
	          (sText.charAt(n) != "."))
	         return false;
	   }
	   return true;
   }
   
   // Date
   function ValidateDate(strDate) {

   var parsedDate = strDate.split ("/");
   if (parsedDate.length != 3)
    return false;
   var day, month, year;
   month = parsedDate[0]-1;
   day = parsedDate[1];
   year = parsedDate[2];
   var objDate = new Date (strDate);
   
   if (month != objDate.getMonth())
	{
	return false;
	}
   if (day != objDate.getDate().toString())
   	 {
	 return false;
	 }
   if (year != objDate.getFullYear().toString()) 
   	 {
	 return false;
	 }
   return true;
}
   
   // Email Addressess
   function ValidateEmail(sEmail)
   {
      // Must be something
      if (sEmail == "") return "Please enter an Email Addressess";
   
      // Must contain @ character
      var n;
      for (n = 0; n < sEmail.length; n++)
         if (sEmail.charAt(n) == "@") break;
      if (n == sEmail.length) return "Please enter a valid Email Addressess";
      
      // Must contain . character
      for (n = 0; n < sEmail.length; n++)
         if (sEmail.charAt(n) == ".") break;
      if (n == sEmail.length) return "Please enter a valid Email Addressess";
      
      // No spaces
      if (!ValidateIsOneWord(sEmail)) return "Please enter a valid Email Addressess";
      
      return "";
   }
   
   // Money
   function ValidateMoney(sMoney)
   {
      // Must be something
      if (sMoney == "") return "Please enter an amount";
         
      // Must be numeric
      if (!ValidateIsNumeric(sMoney)) return "The amount must be numeric and greater than zero";
         
      // Must be > 0
      if (sMoney <= 0) return "The amount must be greater than zero";

      // Must no be smaller than one cent
      if (sMoney < 0.01) return "The amount must be 0.01 or greater";

      return "";
   }
   
   // Card number
   function ValidateCardNumber(sCardNo)
   {
      // Must be something
      if (sCardNo == "") return "Please enter a card number";
   
      // Must be 16 long
      if (sCardNo.length != 16) return "The card number must be 16 characters long";
      
      // Must be numeric
      if (!ValidateIsNumeric(sCardNo)) return "The card number must contain only numeric characters";

      return "";
   }   

   // Account number
   function ValidateAccountNumber(sAccNo)
   {
      // Must be something
      if (sAccNo == "") return "Please enter an account number";
   
      // Must be 12 long
      if (sAccNo.length != 12) return "The account number must be 12 characters long";
      
      // Must be numeric
      if (!ValidateIsNumeric(sAccNo)) return "The account number must contain only numeric characters";
      
      // Check digit validation
      var nSum; var nIndex; var nTemp;
      var sAccNo11; var nCheckDigit; var nWorkNum;
   
      sAccNo11 = sAccNo.substr(0, 11);
      nCheckDigit = sAccNo.charCodeAt(11) - 48;
      nSum = 0;
      
      for (nIndex = 0; nIndex < 11; nIndex++)
      {
         nTemp = sAccNo11.charCodeAt(nIndex) - 48;
               
         if (nIndex % 2 == 0)
         {
            nTemp = nTemp * 2;
            if (nTemp > 9)
            {
               nTemp = Math.floor((nTemp / 10)) + (nTemp % 10);
            }
         }
               
         nSum = nSum + nTemp;
      }
      nWorkNum = (10 - (nSum % 10)) % 10;
      if (nWorkNum != nCheckDigit) return "You have entered an invalid account number";

      return "";
   }   

   // DAC
   function ValidateDAC(sDAC)
   {
      // Must be something
      if (sDAC == "") return "Please enter an Identity Validation Code";
      
      // Must be 4 long
      if (sDAC.length != 4) return "The Identity Validation Code must be 4 characters long";
      
      // Must be numeric
      if (!ValidateIsNumeric(sDAC)) return "The Identity Validation Code must contain only numeric characters";

      return "";
   }   

   // Activation Code
   function ValidateActCode(sActCode)
   {
      // Must be something
      if (sActCode == "") return "Please enter a Activation Code";
         
      // Must be 4 long
      if (sActCode.length != 4) return "The Activation Code must be 4 characters long";
      
      return "";
   }   

   // Phone Number
   function ValidatePhoneNum(sPhoneNum)
   {
      if (sPhoneNum == "") return "";
         
      // Must be 6 long
      if (sPhoneNum.length < 6) return "The phone number must be at least 6 digits long";
      
      return "";
   }

   // Password
   function ValidatePassword(sPass)
   {
      // Must be something
      if (sPass == "") return "Please enter a Password";
   
      // Must be at least 6 long
      if (sPass.length < 6) return "The Password must be at least 6 characters long";

      // Must be one word
      if (!ValidateIsOneWord(sPass)) return "The Password must not contain any spaces";

      // Must contain at least one
      // numeric character
      if ((sPass.indexOf('1') == -1) &&
          (sPass.indexOf('2') == -1) &&
          (sPass.indexOf('3') == -1) &&
          (sPass.indexOf('4') == -1) &&
          (sPass.indexOf('5') == -1) &&
          (sPass.indexOf('6') == -1) &&
          (sPass.indexOf('7') == -1) &&
          (sPass.indexOf('8') == -1) &&
          (sPass.indexOf('9') == -1) &&
          (sPass.indexOf('0') == -1))
         return "The Password must contain at least one numeric character";
      return "";
   }

   function ValidateCCNo(sCCNo)
   {
      // Must be something
      if (sCCNo == "") return "Please enter a credit card number";
   
      // May not be longer than 19
      if (sCCNo.length > 19) return "The card number must not be longer than 19 digits";

      // May not be shorter than 16
      if (sCCNo.length < 16) return "The card number must not be shorter than 16 digits";

      // Must be numeric
      if (!ValidateIsNumeric(sCCNo)) return "The card number must contain only numeric characters";

      return "";
   }
/*
   function ValidateCCExpMonth(m, y)
   {
      // Must be something
      if (m == "") return "Invalid expiry date entered";
   
      // Must be two characters in length
      if (m.length != 2) return "Invalid expiry date entered";

      // Must be numeric
      if (!ValidateIsNumeric(m)) return "Invalid expiry date entered";

      // Must not be < 1 or > 12
      if ((m < 1) || (m > 12)) return "Invalid expiry date entered";
      
      if ((y == 2001) && (m < 5)) return "Invalid expiry date entered";

      return "";
   }
*/

/*
   function ValidateCCExpYear(y)
   {
      // Must be something
      if (y == "") return "Invalid expiry date entered";
   
      // Must be two characters in length
      if (y.length != 4) return "Invalid expiry date entered";

      // Must be numeric
      if (!ValidateIsNumeric(y)) return "Invalid expiry date entered";

      // must not be less than current Year or greater than current Year+4
      if ((y < 2001) || (y > 2005)) return "Invalid expiry date entered";
      return "";
   }
*/
   function ValidateCCCVC(cvc)
   {
      // cvc must be either nothing or a valid 3 digit cvc
      if (cvc == "")
      {
         return "";
      }
      else
      {
         // cvc must be 3 characters in length
         if (cvc.length != 3) return "Please enter a valid CVC";

         // Must be numeric
         if (!ValidateIsNumeric(cvc)) return "Please enter a valid CVC";
      }

      return "";
   }

   function ValidateCCName(name)
   {
      
      // Must be something
      if (name == "") return "Please enter the embossed name as it appears on your credit card";
   
      // Name length must not be greater than 100 characters.
      if (name.length > 100) return "The credit card name appears to be invalid";

      // Must contain alpha characters
      if (!ValidateHasAlpha(name)) return "The credit card name appears to be invalid";

      return "";
   }
   
/*
function validateForm(form)
{
	bug = 0;
	
//	if ((!bug) && (form.Title.selectedIndex == 0)) {bug++; form.Title.focus(); alert("Please select a Title");}
	if ((!bug) && (!ValidateHasAlpha(form.CompanyName.value))) {bug++; form.CompanyName.focus(); alert("Please enter a valid Company name");}
    if ((!bug) && ((r = ValidateEmail(form.Email.value)) != "")) {bug++; form.Email.focus(); alert(r);}	
	if ((!bug) && (!ValidateHasAlpha(form.FirstName.value))) {bug++; form.FirstName.focus(); alert("Please enter a valid first name");}
	if ((!bug) && (!ValidateHasAlpha(form.Initials.value))) {bug++; form.Initials.focus(); alert("Please enter valid Initials");}
	if ((!bug) && (!ValidateHasAlpha(form.LastName.value))) {bug++; form.LastName.focus(); alert("Please enter a valid last name");}
	//check Initials
//  if ((!bug) && (form.Initials.value.charAt(0) != form.FirstName.value.charAt(0))) {bug++; form.Initials.focus(); alert("Please enter all your Initials, including that of your first name");}
//	if ((!bug) && (!ValidateDate(form.DOB.value))) {bug++; form.Day.focus(); alert("Please select a valid date of birth");}
//	if ((!bug) && (form.Gender.selectedIndex == 0)) {bug++; form.Gender.focus(); alert("Please select a gender.");}

	//check Passwords
	if ((!bug) && (form.Password.value.length <= 0)) {bug++; form.Password.focus(); alert("Please enter a Password.")}
	if ((!bug) && (form.Password.value.length < 6)) {bug++; form.Password.focus(); alert("Your Password should be at least 6 characters in length.")}
//	if ((!bug) && (form.Password1.value != form.Password2.value)) {
//		bug++;
//		form.Password2.value = "";
//		form.Password2.focus();
//		alert("The Passwords you entered do not match. Please re-enter to ensure that your Password is correct.");
//		}
	//check Emails match
//	if ((!bug) && (form.Email1.value != form.Email2.value)) {
//		bug++;
//		form.Email2.value = "";
//		form.Email2.focus();
//		alert("The Email Addressesses you entered do not match. Please re-enter to ensure that your Email is correct.");
//		}
		
	if ((!bug) && (!ValidateHasAlpha(form.Address.value))) { bug++; form.Address.focus(); alert("Please enter a valid Addressess");}
	if ((!bug) && (form.Address.length > 150)) {bug++; form.Address.focus; alert("The Addressess may not exceed 150 characters");}
	if ((!bug) && (!ValidateHasAlpha(form.City.value))) { bug++; form.City.focus(); alert("Please enter a valid City");}
	if ((!bug) && ((form.usState.selectedIndex == 0) && (!ValidateHasAlpha(form.otherProvince.value)))) {bug++; alert("Please choose a US state or enter a province if not in the US");}
	if ((!bug) && (form.ZipCode.value == "")) { bug++; form.ZipCode.focus(); alert("Please enter the ZipCode or postal code");}
	if ((!bug) && (form.Country.selectedIndex == 0)) { bug++; form.Country.focus(); alert("Please select a Country");}
	
    if ((!bug) && ((form.HomePhone.value == "") && (form.WorkPhone.value == "") && (form.MobilePhone.value == "") && (form.Fax.value == ""))) { bug++; form.HomePhone.focus(); alert("Please enter at least one contact number");}
    if ((!bug) && ((r = ValidatePhoneNum(form.HomePhone.value)) != "")) {bug++; form.HomePhone.focus(); alert(r);}
    if ((!bug) && ((r = ValidatePhoneNum(form.WorkPhone.value)) != "")) {bug++; form.WorkPhone.focus(); alert(r);}
    if ((!bug) && ((r = ValidatePhoneNum(form.Fax.value)) != "")) {bug++; form.Fax.focus(); alert(r);}
    if ((!bug) && ((r = ValidatePhoneNum(form.MobilePhone.value)) != "")) {bug++; form.MobilePhone.focus(); alert(r);}

    if ((!bug) && ((r = ValidateEmail(form.Email1.value)) != "")) {bug++; form.Email1.focus(); alert(r);}

	//accept terms
    if ((!bug) && (form.chkAcceptInfinia.checked != true)) {bug++; form.chkAcceptInfinia.focus; alert("You must accept infinia's Privacy Policy and Terms and Conditions before you can submit this form.");}
	if ((!bug) && (form.chkAcceptCharge.checked != true)) {bug++; form.chkAcceptCharge.focus; alert("You must accept the annual $15 Account & Card Fee.");}

	if ((!bug) && (form.Initials.value.length > 0))
      if (form.Initials.value.charAt(form.Initials.value.length - 1) == form.LastName.value.charAt(0))
      {
         if (confirm("Please note that the first letter of your last name must NOT be included as part of your Initials. Do you want to continue?"))
            return true;
         else
            return false;
      }
	
	if (bug > 0)
		return false;
	
	//form.submit.disabled = true;
	return true;
	
	// Credit card details
   //if ((!bug) && ((r = ValidateCCName(form.ccname.value)) != "")) {bug++; form.ccname.focus(); alert(r);}
   //if ((!bug) && ((r = ValidateCCNo(form.ccno.value)) != "")) {bug++; form.ccno.focus(); alert(r);}
   //if ((!bug) && ((r = ValidateCCExpYear(form.ccexpYear.value)) != "")) {bug++; form.ccexpYear.focus(); alert(r);}
   //if ((!bug) && ((r = ValidateCCExpMonth(form.ccexpMonth.value, form.ccexpYear.value)) != "")) {bug++; form.ccexpMonth.focus(); alert(r);}
   //if ((!bug) && (form.cctype.value == "")) {bug++; form.cctype.focus(); alert("Please select a credit card type from the list.");}
   //if ((!bug) && ((r = ValidateCCCVC(form.cccvc.value)) != "")) {bug++; form.cccvc.focus(); alert(r);}
}
*/

// Differenciate between USA and Other Countries.
function CountryCall(form) {
   
	if (form.Country[form.Country.selectedIndex].value == "225")
	{
		form.usState[form.usState.selectedIndex].value = "0"
		if (form.usState[form.usState.selectedIndex].value == "0")
		{
			form.usState.focus ()
			alert("Please pick a US state")
		}		
	}
	else
	{
		form.StateOrProvince.value = ""
		form.usState.selectedIndex = "0"
		if (form.StateOrProvince.value == "")
		{
			form.StateOrProvince.focus ()
			alert("Enter a non us province")
		}	
	}
	
	return 0
}

// Handle the State and Select the USA
function StateCall(form) {
	if (form.usState.selectedIndex.value == "1")
	{ 	
		form.Country.selectedIndex = "0";
		alert('Please select a Non-Us Country');
		form.Country.focus ();
	}
	else
	{	 
		form.Country.selectedIndex = "226";
	}
	return 0
	
}

//  ------ check login form ------
function checkData() {
	var f1 = document.forms[0];
	var wm = "<?PHP echo $strJSHello; ?>\n\r\n";
	var noerror = 1;

	// --- entered_login ---
	var t1 = f1.entered_login;
	if (t1.value == "" || t1.value == " ") {
		wm += "<?PHP echo $strLogin; ?>\r\n";
		noerror = 0;
	}

	// --- entered_password ---
	var t1 = f1.entered_password;
	if (t1.value == "" || t1.value == " ") {
		wm += "<?PHP echo $strPassword; ?>\r\n";
		noerror = 0;
	}

	// --- check if errors occurred ---
	if (noerror == 0) {
		alert(wm);
		return false;
	}
	else return true;
}
