		function CheckPaymentType() 
		{
			document.frmPayment.trnCardOwner.disabled = false;
			document.frmPayment.trnCardNumber.disabled = false;
			document.frmPayment.trnExpMonth.disabled = false;
			document.frmPayment.trnExpYear.disabled = false;			
		}
		
		function PositiveInteger(objName)
		{
			if (objName.value != "") {
				if (IsPosNumeric(objName.value) == false)
				{
					alert("This value must be numeric")
					objName.focus()
					objName.select()
					return false
				}
				else
				{
					return true
				}
			}
		}
		
		function OnChangeShipSameAsOrd()
		{
			// Disables Shipping fields if the "Shipping info is same as billing" checkbox is checked
			if (document.frmPayment.shipSameAsOrd.checked == true)
			{
				dControl = true
			}
			else
			{
				dControl = false
			}
			DisableControl(document.frmPayment.shipName, dControl)
			DisableControl(document.frmPayment.shipEmailAddress, dControl)
			DisableControl(document.frmPayment.shipPhoneNumber, dControl)
			DisableControl(document.frmPayment.shipAddress1, dControl)
			DisableControl(document.frmPayment.shipAddress2, dControl)
			DisableControl(document.frmPayment.shipCity, dControl)
			DisableControl(document.frmPayment.shipProvince, dControl)
			DisableControl(document.frmPayment.shipPostalCode, dControl)
			DisableControl(document.frmPayment.shipCountry, dControl)
		}
	
		function ValidateEmailAddress (emailStr)
		{
			// Validates the email address
			var emailPat=/^(.+)@(.+)$/
			var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
			var validChars="\[^\\s" + specialChars + "\]"
			var quotedUser="(\"[^\"]*\")"
			var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
			var atom=validChars + '+'
			var word="(" + atom + "|" + quotedUser + ")"
			var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
			var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")	
			var matchArray=emailStr.match(emailPat)
			
			if (matchArray==null)
			{
				alert("Email address seems incorrect (check @ and .)");
				return false
			}
			
			var user=matchArray[1]
			var domain=matchArray[2]
			
			// See if "user" is valid 
			if (user.match(userPat)==null)
			{
				alert("The username does not seem to be valid.")
				return false
			}
			
			// if the e-mail address is at an IP address 
			var IPArray=domain.match(ipDomainPat)
			if (IPArray!=null)
			{
				for (var i=1;i<=4;i++)
				{
					if (IPArray[i]>255)
					{
						alert("Destination IP address is invalid!")
						return false
					}
				}
				return true
			}
			
			// Domain is symbolic name
			var domainArray=domain.match(domainPat)
			if (domainArray==null)
			{
				alert("The domain name does not seem to be valid.")
				return false
			}
			
			// Make sure that it ends in a three-letter word or a two-letter word, and that hostname preceding domain or country.
			var atomPat=new RegExp(atom,"g")
			var domArr=domain.match(atomPat)
			var len=domArr.length
			if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3)
			{
				alert("The address must end in a three-letter domain, or two letter country.")
				return false
			}
			

			if (len<2)
			{
				var errStr="This address is missing a hostname!"
				alert(errStr)
				return false
			}
			
			return true;
		}
	
		function CreditModCheck(objName,result)
		{

			var ccnLength;
			var cPrefix2;
			var nString = "";
			var total = 0;
	
			ccNumber = objName.value;
			if (ccNumber == '') return false;
                        ccnLength = ccNumber.length;


                       if (result == "Visa") {
                          if ((ccnLength == 16) || (ccnLength ==13))
                             validcard = true;
                          if (ccNumber.substring (0, 1) != "4")
                             return  false;
                       }
                       if (result == "AmericanExpress") {
                          if (ccnLength == 15)
                             validcard = true;
                          if ((ccNumber.substring (0, 2) != "34") &&  (ccNumber.substring (0, 2) != "37"))
                             return false;
                       }
                       if (result == "Discover") {
                          if (ccnLength == 16)
                             validcard = true;
                          if (ccNumber.substring (0, 4) != "6011")
                             return  false;
                       }

			
			

			if (ccnLength >= 13)
			{
				cPrefix2 = parseInt(ccNumber.charAt(0) + ccNumber.charAt(1));
				cPrefix3 = parseInt(ccNumber.charAt(0) + ccNumber.charAt(1) + ccNumber.charAt(2));
				cPrefix4 = parseInt(ccNumber.charAt(0) + ccNumber.charAt(1) + ccNumber.charAt(2) + ccNumber.charAt(3));
				if (cPrefix2 > 49 && cPrefix2 < 56)
				{
					//Mastercard	***** CHANGE - using test version - Test mastercards can start with 50, valid cards cannot
					if (ccnLength != 16)
					{
						return false;
					}
				}
				else if (ccNumber.charAt(0) == "4")
				{
					//VISA
					if (ccnLength != 16 && ccnLength != 13)
					{
						return false;
					}
				}
				else if (cPrefix2 == 34 || cPrefix2 == 37)
				{
					//AMEX
					if (ccnLength != 15)
					{
						return false;
					}
				}
				else if ((cPrefix3 > 299 && cPrefix3 < 306) || cPrefix2 == 36 || cPrefix2 == 38)
				{
					//Diners Club/Carte Blanche
					if (ccnLength != 14)
					{
						return false;
					}
				}
				else if (cPrefix4 == 6011)
				{
					//Discover
					if (ccnLength != 16)
					{
						return false;
					}
				}
				else if (cPrefix4 > 3527 && cPrefix4 < 3590)
				{
					//JCB
					if (ccnLength != 16)
					{
						return false;
					}
				}
				else
				{
					return false;
				}
				
				// Perform MOD check
				for (i=1; i <= ccnLength; i++)
				{
					if ((i % 2) == 0)
					{
						nString = nString + (parseInt(ccNumber.charAt(ccnLength - i)) * 2);
					}
					else
					{
						nString = nString + ccNumber.charAt(ccnLength - i);
					}
				}
				
				for (i=0; i < nString.length; i++)
				{
					total = total + parseInt(nString.charAt(i));
				}
				
				if (total % 10 != 0)
				{
					return false;
				}
				else
				{
					return true;
				}
	
			}
			else
			{
				return false;
			}
	
		}
		
		function FormatAmount(obj)
		{
			// Purpose: to format a numberic value to currency formating, ie xxxxx.xx
			//			Values are rounded up. ie. 45.105 = 45.11
			// Pre:		obj is a textbox object
			// post:	sets obj.value = the formated currency
	
			var newValue = ""
	
			if (obj.value == "") {obj.value="0.00"; return}
	
			obj.value = MoneyChopValue(obj.value);
			if (obj.value < 0) {
				objValue = parseFloat(obj.value) - parseFloat('0.005');
			}
			else {
				objValue = parseFloat(obj.value) + parseFloat('0.005');
			}
			objValue = eval("'" + objValue + "'")
			if (objValue.length > 0) {
				if (objValue.charAt(0) == '.') {objValue = "0" + objValue}
			}
			for (x=0; x < objValue.length; x++) {
				if (objValue.charAt(x) == '.') {
					if (x == (objValue.length - 1)) {
						newValue = newValue + ".00"
					}
					else if (x == (objValue.length - 2)) {
						newValue = newValue + "." + objValue.charAt(x+1) + "0"
					}
					else {
						newValue = newValue + "." + objValue.charAt(x+1) + objValue.charAt(x+2)
					}
					obj.value = newValue
					return;
				}
				newValue = newValue + objValue.charAt(x)
			} 
			obj.value = newValue + ".00"
		}
		
		
		function FormatAmountValue(value)
		{
			// Purpose: To format a monetary value.  Like above, except not an obj
			this.value = value;
			FormatAmount(this);
			return this.value;
		}
		
		function MoneyChop(Obj)
		{
			// Purpose: See MoneyChopValue
			Obj.value = MoneyChopValue(Obj.value);
		}
		
		reMoney = /^-?[0-9]*\.?[0-9]{0,4}/;
		function MoneyChopValue(value)
		{
			// Purpose: Chops numbers off to four decimal places to work around the
			//		  JavaScript math errors.
			// Comments: Finds 0 or 1 '-' then any digits then 0 or 1 decimal points then 
			//			up to four more digits.
			value += "";
			return parseFloat(value.match(reMoney));
		}		
		
		function IsNumeric(sNumber)
		{
			// Checks that a number is numeric
			var decimal = 0;
			sNumber += "";
			if (sNumber.length == 0) return false;
			for (x = 0; x < sNumber.length; x++) {
				if (!(sNumber.charCodeAt(x) >= 48 && sNumber.charCodeAt(x) <= 57)) {
					switch (sNumber.charAt(x)) {
						case ".":
							if (decimal++ != 0) return false;
							break;
						case "-":
							if (x > 0) return false;
							if (sNumber.length == 1) return false;
							break;
						default:
							return false;
					}
				}
			}
			return true;
		}
		
		function IsPosNumeric(sNumber)
		{
			// Checks that a number is a positive numeric
			sNumber += "";
			return (sNumber.charAt(0) != "-" && IsNumeric(sNumber));
		}
		
		function RequireNumericOnly(editBox, defaultValue)
		{
			// Checks that a textbox contains only numeric values
			if( editBox.value != '' && !IsNumeric(editBox.value) )
			{
				editBox.value = defaultValue;
				alert('Please enter only numeric values');
				editBox.focus();
			}
		}
		
		function DisableControl(objName, dControl)
		{
			// Disables a form object
			if (dControl == true)
			{
				objName.disabled = true
				objName.style.background = "E5E5E5"
			}
			else
			{
				objName.disabled = false
				objName.style.background = "FFFFFF"
			}
		}
		
		// End of JavaScript error handling and data validation functions
	
function replaceAll(strText, strTarget, strSub){
 var strReplaceAll = strText;
 var intIndexOfMatch = strReplaceAll.indexOf( strTarget );
  
 while (intIndexOfMatch != -1){
 // Relace out the current instance.
    strReplaceAll = strReplaceAll.replace( strTarget, strSub ) 
 // Get the index of any next matching substring.
    intIndexOfMatch = strReplaceAll.indexOf( strTarget );
 }
 return strReplaceAll;

}

function submitFormCC(){
   if (ValidateEmailAddress(document.OrderForm1.get_billing_email.value) == false){

       document.OrderForm1.get_billing_email.focus();
       return false;

   }
   if (document.OrderForm1.get_shipping_email.value != '' && ValidateEmailAddress(document.OrderForm1.get_shipping_email.value) == false){
       document.OrderForm1.get_shipping_email.focus();
       return false;
   } 

  if (CreditModCheck(document.OrderForm1.get_ccnumber,document.OrderForm1.get_cctype.value) == false){
       alert('Please enter valid credit card number');
       document.OrderForm1.get_ccnumber.focus();
       return false;
  } 
  if (document.OrderForm1.get_cctype.value == "AmericanExpress") {
     if (document.OrderForm1.get_cvv2.value.length != 4){
          alert('Please enter valid Security Code');
          document.OrderForm1.get_cvv2.focus();
          return false;
     }
  }else{
     if (document.OrderForm1.get_cvv2.value.length != 3){
          alert('Please enter valid Security Code');
          document.OrderForm1.get_cvv2.focus();
          return false;
     }
  }
  var str=document.OrderForm1.get_billing_phone.value;
  str2 = replaceAll(str, "-", ""); 
  str2 = replaceAll(str2, ".", ""); 

  if (str2.length <10){
      alert('Please enter valid Daytime Phone');
      document.OrderForm1.get_billing_phone.focus();
      return false;
  }

  var str_ = document.OrderForm1.get_billing_phone2.value;
  str2 = replaceAll(str_, "-", ""); 
  str2 = replaceAll(str2, ".", ""); 

  if (str2.length <10){
      alert('Please enter valid Evening Phone');
      document.OrderForm1.get_billing_phone2.focus();
      return false;
  }


  var str=document.OrderForm1.get_shipping_phone.value;
  if (str.length > 0){
     str2 = replaceAll(str, "-", ""); 
     str2 = replaceAll(str2, ".", ""); 

     if (str2.length <10){
         alert('Please enter valid Daytime Phone');
         document.OrderForm1.get_shipping_phone.focus();
         return false;
     }
  }
  var str_ = document.OrderForm1.get_shipping_phone2.value;
  if (str_.length > 0){
     str2 = replaceAll(str_, "-", ""); 
     str2 = replaceAll(str2, ".", ""); 

     if (str2.length <10){
         alert('Please enter valid Evening Phone');
         document.OrderForm1.get_shipping_phone2.focus();
         return false;
     }
  }

  document.OrderForm1.act.value='order_add';
  return true;

}
function submitFormCC2(){
   if (ValidateEmailAddress(document.OrderForm1.get_billing_email.value) == false){

       document.OrderForm1.get_billing_email.focus();
       return false;

   }
   if (document.OrderForm1.get_shipping_email.value != "" && ValidateEmailAddress(document.OrderForm1.get_shipping_email.value) == false){
       document.OrderForm1.get_shipping_email.focus();
       return false;
   } 

  if (CreditModCheck(document.OrderForm1.get_ccnumber, document.OrderForm1.get_cctype.value) == false){
       alert('Please enter valid credit card number');
       document.OrderForm1.get_ccnumber.focus();
       return false;
  } 
  if (document.OrderForm1.get_cctype.value == "AmericanExpress") {
     if (document.OrderForm1.get_cvv2.value.length != 4){
          alert('Please enter valid Security Code');
          document.OrderForm1.get_cvv2.focus();
          return false;
     }
  }else{
     if (document.OrderForm1.get_cvv2.value.length != 3){
          alert('Please enter valid Security Code');
          document.OrderForm1.get_cvv2.focus();
          return false;
     }
  }
  var str=document.OrderForm1.get_billing_phone.value;
  str2 = replaceAll(str, "-", ""); 
  str2 = replaceAll(str2, ".", ""); 

  if (str2.length <10){
      alert('Please enter valid Daytime Phone');
      document.OrderForm1.get_billing_phone.focus();
      return false;
  }

  var str_ = document.OrderForm1.get_billing_phone2.value;
  str2 = replaceAll(str_, "-", ""); 
  str2 = replaceAll(str2, ".", ""); 

  if (str2.length <10){
      alert('Please enter valid Evening Phone');
      document.OrderForm1.get_billing_phone2.focus();
      return false;
  }

  var str=document.OrderForm1.get_shipping_phone.value;
  if (str.length > 0){
     str2 = replaceAll(str, "-", ""); 
     str2 = replaceAll(str2, ".", ""); 

     if (str2.length <10){
         alert('Please enter valid Daytime Phone');
         document.OrderForm1.get_shipping_phone.focus();
         return false;
     }
  }
  var str_ = document.OrderForm1.get_shipping_phone2.value;
  if (str_.length > 0){
     str2 = replaceAll(str_, "-", ""); 
     str2 = replaceAll(str2, ".", ""); 

     if (str2.length <10){
         alert('Please enter valid Evening Phone');
         document.OrderForm1.get_shipping_phone2.focus();
         return false;
     }
  }


  document.OrderForm1.act.value='order_add';
  return true;

}

function submitFormPP(){
   if (ValidateEmailAddress(document.OrderForm2.get_shipping_email.value) == false){
       document.OrderForm2.get_shipping_email.focus();
       return false;
   } 
  var str=document.OrderForm2.get_shipping_phone.value;
  str2 = replaceAll(str, "-", ""); 
  str2 = replaceAll(str2, ".", ""); 

  if (str2.length <10){
      alert('Please enter valid Daytime Phone');
      document.OrderForm2.get_shipping_phone.focus();
      return false;
  }

  var str_ = document.OrderForm2.get_shipping_phone2.value;
  str2 = replaceAll(str_, "-", ""); 
  str2 = replaceAll(str2, ".", ""); 

  if (str2.length <10){
      alert('Please enter valid Evening Phone');
      document.OrderForm2.get_shipping_phone2.focus();
      return false;
  }

  document.OrderForm2.act.value='order_add_paypal';
  return true;

}
function submitFormPP2(){
  if (ValidateEmailAddress(document.OrderForm2.get_email.value) == false){
       document.OrderForm2.get_email.focus();
       return false;
   } 
 
   if (ValidateEmailAddress(document.OrderForm2.get_shipping_email.value) == false){
       document.OrderForm2.get_shipping_email.focus();
       return false;
   }

  var str=document.OrderForm2.get_shipping_phone.value;
  str2 = replaceAll(str, "-", ""); 
  str2 = replaceAll(str2, ".", ""); 

  if (str2.length <10){
      alert('Please enter valid Daytime Phone');
      document.OrderForm2.get_shipping_phone.focus();
      return false;
  }

  var str_ = document.OrderForm2.get_shipping_phone2.value;
  str2 = replaceAll(str_, "-", ""); 
  str2 = replaceAll(str2, ".", ""); 

  if (str2.length <10){
      alert('Please enter valid Evening Phone');
      document.OrderForm2.get_shipping_phone2.focus();
      return false;
  }
 
  document.OrderForm2.act.value='order_add_paypal';
  return true;

}
function submitFormP(){
   if (ValidateEmailAddress(document.OrderForm2.get_shipping_email.value) == false){
       document.OrderForm2.get_shipping_email.focus();
       return false;
   }
  var str=document.OrderForm2.get_shipping_phone.value;
  str2 = replaceAll(str, "-", ""); 
  str2 = replaceAll(str2, ".", ""); 

  if (str2.length <10){
      alert('Please enter valid Daytime Phone');
      document.OrderForm2.get_shipping_phone.focus();
      return false;
  }

  var str_ = document.OrderForm2.get_shipping_phone2.value;
  str2 = replaceAll(str_, "-", ""); 
  str2 = replaceAll(str2, ".", ""); 

  if (str2.length <10){
      alert('Please enter valid Evening Phone');
      document.OrderForm2.get_shipping_phone2.focus();
      return false;
  }
 
  document.OrderForm2.act.value='order_add_pay';
  return true;

}
function doTax(value,taxfee,ref,total,totaltax) {

    if (value == ref){
       document.getElementById('tax1').innerHTML = '<b>' + taxfee + '</b>';
       document.getElementById('total1').innerHTML = '<b>' + totaltax + '</b>';

    }else{
       document.getElementById('tax1').innerHTML = '<b>$0.00</b>';
       document.getElementById('total1').innerHTML = '<b>' + total + '</b>'; 
    }

}
function doTaxPP(value,taxfee,ref,total,totaltax) {

    if (value == ref){
       document.getElementById('tax2').innerHTML = '<b>' + taxfee + '</b>';
       document.getElementById('total2').innerHTML = '<b>' + totaltax + '</b>';

    }else{
       document.getElementById('tax2').innerHTML = '<b>$0.00</b>';
       document.getElementById('total2').innerHTML = '<b>' + total + '</b>'; 
    }

}
