// NSI security and validation functions for the checkout form
// A Daniel Klarmann June, 2003

var strSendButton = "send"; // should be changed by cart.asp

function secure(bEncode){ //pass true to encode, false to decode
   if (document.forms["frmCheckout"].elements["CC"]){
      var strCC = document.forms["frmCheckout"].elements["CC"].value;
      if (strCC.charAt(0) == 'x'){ //has been encoded
         if (! bEncode){
            runCrypt(strCC.substr(1));
         }
      } else {
         if (bEncode){
            runCrypt(strCC+'x');
         }
      }
   } // endif have field in form
} // secure()

function runCrypt(strCC){
   var strOut = '';
   var iLen = strCC.length;
   for (var i=0;i<iLen;i++){
      strOut += strCC.charAt(iLen-i-1);
   }
   document.forms["frmCheckout"].elements["CC"].value = strOut;
} // runCrypt

function HasNecessaryFields(){
   var bValid = true;
   if (document.forms["frmCheckout"].elements["BillName"].value.length < 3){
      alert ("Please fill in the Billing Name field");
      document.forms["frmCheckout"].elements("BillName").focus();
      bValid = false;
   }
   if (bValid && (document.forms["frmCheckout"].elements["BillPhone"].value.length < 10)){
      alert ("Please fill in the Billing Phone Number field (with area code)");
      document.forms["frmCheckout"].elements["BillPhone"].focus();
      bValid = false;
   }
   if (document.forms["frmCheckout"].elements["BillZip"].value.length < 5){
      alert ("Please fill in the Billing Zipcode field");
      document.forms["frmCheckout"].elements("BillZip").focus();
      bValid = false;
   }
   return bValid;
}//
function sendIt(){
   if (HasNecessaryFields()){
      //document.forms["frmCheckout"].elements["sender"].value = strSendButton;
      secure(true);
      document.forms["frmCheckout"].submit();
   } else {
      //document.forms["frmCheckout"].elements["sender"].value = "";
   }
} // sendIt()

function printIt(){
   secure(false);
   print();
} // printIt

