

function GotoUrl(url,sameWinFlag) {
  var d = url.options[url.selectedIndex].value;
  if(d!="NULL") {
    // 1st line, opens in the same window (losing frames,if any)
    // 2nd line, opens in new window... So choose only one & comment other!!!
    window.top.location.href = d;
    //window.open(url.options[url.selectedIndex].value,sameWinFlag);
  }
  url.selectedIndex=0;
}


function submit()  {
  document.form1.submit();
}


// keep track of number of submit hits.
var submitcount=0;
var states_matched;
var state_name;
var po_htb_6=false;
var cc_number;
var po_prefix=false;
var po_required=true;
var cc_number_req=false;
function verify(form) {

  if(document.checkout.po_htb_lmtd.value ==1 && document.checkout.po_htb_lmtd.value !=null) {
    po_htb_6 = true;
  } //document.checkout.po_htb_lmtd.value; 
  
  //Prevent submitting the form when submit is clicked more than once.
  if (submitcount == 0) {
    submitcount++;
  }
  else {
    alert("You have already submitted the form. Thank you!");
    return false;
  }

  for(var y=0; y <= (form.elements.length - 1); ++y) {
    var temp = form.elements[y];
    if(temp.name == "data[creditCardNum]") {
      cc_number = temp.value;
    }
    else if(temp.name == "cc_number_required" && temp.value == "t" && !cc_number) {
      cc_number_req = true;
    }
    else if(temp.name == "po_prefix_js") {
      po_prefix = temp.value;
    }
    else if(temp.name == "po_required_js" && temp.value == "f") {
      po_required = false; 
    }
  }

  for(var y=0; y <= (form.elements.length - 1); ++y) {
    var temp = form.elements[y];

    if(temp.type =="checkbox" && temp.name =="data[SameBillShip]")
      if(temp.checked)
        var sameBillShip = temp.checked;

    //upgrade,9-21-01,if astname is entered then js kicks in.
    if(temp.name =="data[astname]" && temp.value !="")
      var useAltShipto = true;

    /*
    if(temp.name =="data[aststate]" && temp.value !="" && !states_matched)  {
      state_name = temp.value;
      for(var z=0; z <= (document.checkout.states.length - 1); ++z) {
        if(state_name == document.checkout.states[z].value) {
          states_matched=1;
        }
      }
      if(!states_matched) { 
        alert("Alternate state (" + state_name + ") doesnt match any of your ship to states");
      }
    }
    */

    //Fields that could be left blank. 
    if(temp.type !="hidden" && temp.value == ""  
        && temp.name != "data[astaddress2]" 
        && temp.name != "data[instructions]"
        && temp.name != "data[instructions2]"
        && temp.name != "data[astemail]"
        && temp.name != "data[RShipAddress2]"
        && temp.name != "data[RBillAddress2]"
        && temp.name != "data[RShipAddress3]"
        && temp.name != "data[RBillAddress3]"
        && temp.name != "data[note]"
        && temp.name != "data[couponNum]"
        && temp.name != "data[ShipPhone]" 
        && temp.name != "data[ShipCompany]"
        && temp.name != "data[po]"
        && temp.name != "data[creditCardNum]"
        && temp.name != "data[ccExpirationMonth]"
        && temp.name != "data[ccExpirationYear]"
        && temp.name != "data[cc_cvv2]"
        && temp.name != "data[authorizer_assigned_area]"  
        && temp.name != "data[resellerID]")
    {

      var tmp;
  
      if(temp.name == "data[po]")
        tmp = "Customer PO";
      else if(temp.name == "data[email]")
        tmp = "Email";
      else if(temp.name == "data[shipto]")
        tmp = "Shipping Address";
      else if(temp.name == "data[instructions]")
        tmp = "Instructions 1";
      else if(temp.name == "data[instructions2]")
        tmp = "Instructions 2";
      else if(temp.name == "data[astname]")
        tmp = "Alternate Name";  
      else if(temp.name == "data[astaddress1]")
        tmp = "Alternate Shipping Address 1";
      else if(temp.name == "data[astaddress2]")
        tmp = "Alternate Shipping Address 2";    
      else if(temp.name == "data[astcity]")
        tmp = "Alternate Shipping City";   
      else if(temp.name == "data[aststate]")
        tmp = "Alternate Shipping State";
      else if(temp.name == "data[astzip]")
        tmp = "Alternate Shipping Zip";
      else if(temp.name == "data[firstName]")
        tmp = "First Name";
      else if(temp.name == "data[lastName]")
        tmp = "Last Name";    
      else if(temp.name == "data[creditCardNum]")
        tmp = "Credit Card Number";
      else if(temp.name == "data[RShipAddress1]")
        tmp = "Ship-to Address 1";
      else if(temp.name == "data[RShipAddress2]")
        tmp = "Ship-to Address 2";
      else if(temp.name == "data[RShipCity]")
        tmp = "Ship-to City";
      else if(temp.name == "data[RShipState]")
        tmp = "Ship-to State";
      else if(temp.name == "data[RShipZip]")
        tmp = "Ship-to Zipcode";
      else if(temp.name == "data[RBillAddress1]")
        tmp = "Billing Address 1";
      else if(temp.name == "data[RBillAddress2]")
        tmp = "Billing Address 2";
      else if(temp.name == "data[RBillCity]")
        tmp = "Billing City";
      else if(temp.name == "data[RBillState]")
        tmp = "Billing State";
      else if(temp.name == "data[RBillZip]")
        tmp = "Billing Zipcode";
      else if(temp.name == "data[cc_cvv2]")
        tmp = "CVV2";
      else if(temp.name == "data[employee_id]")
        tmp = "Employee Id";
      else if(temp.name == "data[shippingMethod]")
        tmp = "Shipping Method";
      else 
        tmp = temp.name;

      if( (!useAltShipto && (tmp =="Alternate Shipping Address 1"
                        || tmp =="Alternate Name"
                        || tmp =="Alternate Shipping City"
                        || tmp =="Alternate Shipping State"
                        || tmp =="Alternate Shipping Zip")) ||
          (sameBillShip && (tmp =="Billing Address 1"
                        || tmp =="Billing City"
                        || tmp =="Billing State"
                        || tmp =="Billing Zipcode")) )
      {
        //do nothing.
        temp.name = temp.name;  
      }
      else {
        alert("Please provide the required " + tmp + ".");
        temp.focus();
        submitcount=0;
        return false;
      } 
    }
    else if(po_htb_6 && temp.name == "data[po]" && temp.value.length !=0 && temp.value.length !=6) {
      alert("Po field must be 6 chars long. Yours have: " + temp.value.length + " chars.");
      temp.focus();
      submitcount=0;
      return false; 
    }
    else if( cc_number && 
            (temp.value == "" && (temp.name == "data[ccExpirationMonth]" ||
                                  temp.name == "data[cc_cvv2]" || 
                                  temp.name == "data[ccExpirationYear]") )) { 
      var tmp;
      if(temp.name == "data[ccExpirationMonth]")
        tmp = "CC Expiration Month";
      else if(temp.name == "data[ccExpirationYear]")
        tmp = "CC Expiration Year";
      else if(temp.name == "data[creditCardNum]")
        tmp = "Credit Card Number";
      else if(temp.name == "data[cc_cvv2]")
        tmp = "CVV2";

      alert("Please provide the required " + tmp + ".");
      temp.focus();
      submitcount=0;
      return false;
    }
    else if(temp.name == "data[po]" && temp.value == "" && po_required) {
      alert("Please provide the required Customer PO.");
      temp.focus();
      submitcount=0;
      return false;
    }
    else if(temp.name == "data[creditCardNum]" && temp.value =="" && cc_number_req) {
      alert("Please provide the required Credit Card Number.");
      temp.focus();
      submitcount=0;
      return false;
    }
    else if(temp.name == "data[taxable_text]" && temp.value == "") {
      alert("Please indicate if taxable order or not?");
      temp.focus();
      submitcount=0;
      return false;
    }
  } // end for
  return true;
} // end verify function


var submitcnt=0;
function ktrackSubmit() {
  if (submitcnt == 0) {
    submitcnt++;
    return true;
  }
  else {
    alert("You have already submitted the form. Thank you!");
    return false;
  }
}


function popUpWindow(url) {
  window.open(url,'Window','width=600,height=400,toolbar=0,directories=0,menubar=0,status=0,resizable=1,location=0,scrollbars=1,copyhistory=0');
}


function ow(url) {
  window.open(url,"",'width=320,height=400,toolbar=0,directories=0,menubar=0,status=0,resizable=0,location=0,scrollbars=1,copyhistory=0');
}

function mfgAvail(url) {
  window.open(url,'Window','width=320,height=400,toolbar=0,directories=0,menubar=0,status=0,resizable=0,location=0,scrollbars=1,copyhistory=0');
}

// Items details js
function mfgAvail_d_NOTUSED() {
  window.open('index.php?loc=mfg_avail&item_code=[itemcode20_]&vndr=[vendorName_]','Window','width=320,height=400,toolbar=0,directories=0,menubar=0,status=0,resizable=0,location=0,scrollbars=1,copyhistory=0');
}

function load_NOTUSED() {  
  window.open('index.php?loc=stk_avail&item_code=[itemcode20_]&data[catalog]=[catalogNum_]','Window','width=320,height=400,toolbar=0,directories=0,menubar=0,status=0,resizable=0,location=0,scrollbars=1,copyhistory=0');
}  

function loadSA_NOTUSED() {  
  window.open('index.php?loc=stk_avail&item_code=[itemcode20_]&vAlllnk=[vallLnkOnOff_]&data[catalog]=[catalogNum_]','Window','width=320,height=400,toolbar=0,directories=0,menubar=0,status=0,resizable=0,location=0,scrollbars=1,copyhistory=0');  
}

// authzspol js
function confirmDelete(location) {
  var where_to= confirm("Do you really want to delete?");
  if (where_to == true ) {
    window.location=location;
  }
}

function confirmLoad(location) {
  var where_to= confirm("Current shopping cart contents will be deleted, continue?");
  if (where_to == true ) {
    window.location=location;
  }
}

function confirmNotApproved(location) {
  var where_to = confirm("Do you really want to remove from spool and not approve this order?");
  if (where_to == true ) {
    window.location=location;
  }
}

function passwdverify(form) {
  for(var y=0; y <= (form.elements.length - 2); ++y) {
    var temp = form.elements[y];
    if(temp.type == "text" && temp.value == "") {
      var tmp;
      if(temp.name == "data[username]")
        tmp = "User ID";
      else if(temp.name == "data[business]")
        tmp = "Business Name";
      else if(temp.name == "data[contact]")
        tmp = "Contact Email Address";

      alert("Please Enter " + tmp + " field!");
      temp.focus();
      submitcount=0;
      return false;
    }
  }
  return true;
}

function qto_verify(form) {
  for(var y=0; y <= (form.elements.length - 2); ++y) {
    var temp = form.elements[y];
    if(temp.name == "data[to]" && temp.value == "") {
      alert("Please enter the email address, where the quote should be sent");
      temp.focus();
      return false;
    }
  }
  return true;
}

function sc_verify(form) {
  for(var y=0; y <= (form.elements.length - 2); ++y) {
    var temp = form.elements[y];
    if(temp.name == "data[scfileName]" && temp.value == "") {
      alert("Please provide a description for the new cart");
      temp.focus();
      return false;
    }
  }
  return true;
}

