// store.js
// This file contains Javascript that is used to update
// quantities and prices on the UWEX store web page.
// http://bulk.uwex.edu/store/index.html



   function same_address() {
      if (document.store.same_addresses.checked) {
         // Fill in billing address automatically
         document.store.bill_line1.value = document.store.ship_line1.value;
         document.store.bill_line2.value = document.store.ship_line2.value;
         document.store.bill_line3.value = document.store.ship_line3.value;
         document.store.bill_line4.value = document.store.ship_line4.value;
      }
      else {
         document.store.bill_line1.value = "";
         document.store.bill_line2.value = "";
         document.store.bill_line3.value = "";
         document.store.bill_line4.value = "";
         
      }
   }

   function openWindow(url,name) {
      popupWin = window.open(url,name,'scrollbars=yes,resizable=yes,width=630,height=520')
   }

   function IsPosInt(inputVal) {
      inputStr = inputVal.toString()
      // first check if there is a value at all
      if (inputVal == null || inputVal == "") {
         return false
      }
      // next make sure the value is a *positive* integer
      for (var i = 0; i < inputStr.length; i++) {
         var oneChar = inputStr.charAt(i)
         if (oneChar < "0" || oneChar > "9") {
            alert ("You must enter a positive integer for quantity");
            return false;
         }
      }
      // if all is good, return true.
      return true
   }

   function AllFilled() {
   // check to make sure all mandatory fields are filled in
      if (document.store.department.value == null || document.store.department.value == "") {
         alert ("You must enter a department."); 
         return 0; 
      }
      else if (document.store.contact.value == null || document.store.contact.value == "") {
         alert ("You must enter a contact person.");
         return 0;
      }
      else if (document.store.email.value == null || document.store.email.value == "") {
         alert ("You must enter an email address.");
         return 0;
      }
      else if (document.store.phone.value == null || document.store.phone.value == "") {
         alert ("You must enter a phone number.");
         return 0;
      }
      else {
         return 1;
      }
   }

   function SubmitInfo() {
      if ( AllFilled() ) { 
         document.store.submit();
      }
   }
   
function UpdateTotal() {
// This function updates all price fields on the form
// If the price of an item changes, this is where you change it.
// You would also have to update the billing database with the new price.

   var price59 = 25.00;
   var price60 = 25.00;
   var price61 = 25.00;
   var price62 = 20.00;
   var price63 = 20.00;
   var price64a = 10.00;
   var price64b = 10.00;
   var price65 = 50.00;
   var price66 = 125.00;
   var price67 = 3.75;
   var price68 = 30.00;
   var price68a = 30.00;
   var price69 = 10.00;
   var price69b = 35.00;
   var price91 = .85;
   var price92 = 1.15;
//   var price93 = 2.35;
//   var price94 = 5.05;

   var TOTAL59
   var TOTAL60
   var TOTAL61
   var TOTAL62
   var TOTAL63
   var TOTAL64A
   var TOTAL64B
   var TOTAL65
   var TOTAL66
   var TOTAL67
   var TOTAL68
   var TOTAL68A
   var TOTAL69
   var TOTAL69B
   var TOTAL91
   var TOTAL92
//   var TOTAL93
//   var TOTAL94
   var GRANDTOTAL

   if (IsPosInt(document.store.qty59.value)) {
      TOTAL59 = Math.round(parseFloat(document.store.qty59.value) * price59 * 100);
      if (TOTAL59 == 0) {
         TOTAL59 = "000";
      }
      TOTAL59 = String(TOTAL59);
      document.store.total59.value = (TOTAL59.substr(0,TOTAL59.length-2) + "." + TOTAL59.substr(TOTAL59.length-2));
   }
   if (IsPosInt(document.store.qty60.value)) {
      TOTAL60 = Math.round(parseFloat(document.store.qty60.value) * price60 * 100);
      if (TOTAL60 == 0) {
         TOTAL60 = "000";
      }
      TOTAL60 = String(TOTAL60);
      document.store.total60.value = (TOTAL60.substr(0,TOTAL60.length-2) + "." + TOTAL60.substr(TOTAL60.length-2));
   }
   if (IsPosInt(document.store.qty61.value)) {
      TOTAL61 = Math.round(parseFloat(document.store.qty61.value) * price61 * 100);
      if (TOTAL61 == 0) {
         TOTAL61 = "000";
      }
      TOTAL61 = String(TOTAL61);
      document.store.total61.value = (TOTAL61.substr(0,TOTAL61.length-2) + "." + TOTAL61.substr(TOTAL61.length-2));
   }
   if (IsPosInt(document.store.qty62.value)) {
      TOTAL62 = Math.round(parseFloat(document.store.qty62.value) * price62 * 100);
      if (TOTAL62 == 0) {
         TOTAL62 = "000";
      }
      TOTAL62 = String(TOTAL62);
      document.store.total62.value = (TOTAL62.substr(0,TOTAL62.length-2) + "." + TOTAL62.substr(TOTAL62.length-2));
   }
   if (IsPosInt(document.store.qty63.value)) {
      TOTAL63 = Math.round(parseFloat(document.store.qty63.value) * price63 * 100);
      if (TOTAL63 == 0) {
         TOTAL63 = "000";
      }
      TOTAL63 = String(TOTAL63);
      document.store.total63.value = (TOTAL63.substr(0,TOTAL63.length-2) + "." + TOTAL63.substr(TOTAL63.length-2));
   }
   if (IsPosInt(document.store.qty64a.value)) {
      TOTAL64A = Math.round(parseFloat(document.store.qty64a.value) * price64a * 100);
      if (TOTAL64A == 0) {
         TOTAL64A = "000";
      }
      TOTAL64A = String(TOTAL64A);
      document.store.total64a.value = (TOTAL64A.substr(0,TOTAL64A.length-2) + "." + TOTAL64A.substr(TOTAL64A.length-2));
   }
   if (IsPosInt(document.store.qty64b.value)) {
      TOTAL64B = Math.round(parseFloat(document.store.qty64b.value) * price64b * 100);
      if (TOTAL64B == 0) {
         TOTAL64B = "000";
      }
      TOTAL64B = String(TOTAL64B);
      document.store.total64b.value = (TOTAL64B.substr(0,TOTAL64B.length-2) + "." + TOTAL64B.substr(TOTAL64B.length-2));
   }
   if (IsPosInt(document.store.qty65.value)) {
      TOTAL65 = Math.round(parseFloat(document.store.qty65.value) * price65 * 100);
      if (TOTAL65 == 0) {
         TOTAL65 = "000";
      }
      TOTAL65 = String(TOTAL65);
      document.store.total65.value = (TOTAL65.substr(0,TOTAL65.length-2) + "." + TOTAL65.substr(TOTAL65.length-2));
   }
   if (IsPosInt(document.store.qty66.value)) {
      TOTAL66 = Math.round(parseFloat(document.store.qty66.value) * price66 * 100);
      if (TOTAL66 == 0) {
         TOTAL66 = "000";
      }
      TOTAL66 = String(TOTAL66);
      document.store.total66.value = (TOTAL66.substr(0,TOTAL66.length-2) + "." + TOTAL66.substr(TOTAL66.length-2));
   }
   if (IsPosInt(document.store.qty67.value)) {
      TOTAL67 = Math.round(parseFloat(document.store.qty67.value) * price67 * 100);
      if (TOTAL67 == 0) {
         TOTAL67 = "000";
      }
      TOTAL67 = String(TOTAL67);
      document.store.total67.value = (TOTAL67.substr(0,TOTAL67.length-2) + "." + TOTAL67.substr(TOTAL67.length-2));
   }
   if (IsPosInt(document.store.qty68.value)) {
      TOTAL68 = Math.round(parseFloat(document.store.qty68.value) * price68 * 100);
      if (TOTAL68 == 0) {
         TOTAL68 = "000";
      }
      TOTAL68 = String(TOTAL68);
      document.store.total68.value = (TOTAL68.substr(0,TOTAL68.length-2) + "." + TOTAL68.substr(TOTAL68.length-2));
   }
   if (IsPosInt(document.store.qty68a.value)) {
      TOTAL68A = Math.round(parseFloat(document.store.qty68a.value) * price68a * 100);
      if (TOTAL68A == 0) {
         TOTAL68A = "000";
      }
      TOTAL68A = String(TOTAL68A);
      document.store.total68a.value = (TOTAL68A.substr(0,TOTAL68A.length-2) + "." + TOTAL68A.substr(TOTAL68A.length-2));
   }
   if (IsPosInt(document.store.qty69.value)) {
      TOTAL69 = Math.round(parseFloat(document.store.qty69.value) * price69 * 100);
      if (TOTAL69 == 0) {
         TOTAL69 = "000";
      }
      TOTAL69 = String(TOTAL69);
      document.store.total69.value = (TOTAL69.substr(0,TOTAL69.length-2) + "." + TOTAL69.substr(TOTAL69.length-2));
   }
   if (IsPosInt(document.store.qty69b.value)) {
      TOTAL69B = Math.round(parseFloat(document.store.qty69b.value) * price69b * 100);
      if (TOTAL69B == 0) {
         TOTAL69B = "000";
      }
      TOTAL69B = String(TOTAL69B);
      document.store.total69b.value = (TOTAL69B.substr(0,TOTAL69B.length-2) + "." + TOTAL69B.substr(TOTAL69B.length-2));
   }
   if (IsPosInt(document.store.qty91.value)) {
        TOTAL91 = Math.round(parseFloat(document.store.qty91.value) * price91 * 100);
        if (TOTAL91 == 0) {
           TOTAL91 = "000";
        }
        TOTAL91 = String(TOTAL91);
        document.store.total91.value = (TOTAL91.substr(0,TOTAL91.length-2) + "." + TOTAL91.substr(TOTAL91.length-2));
   }
   if (IsPosInt(document.store.qty92.value)) {
        TOTAL92 = Math.round(parseFloat(document.store.qty92.value) * price92 * 100);
        if (TOTAL92 == 0) {
           TOTAL92 = "000";
        }
        TOTAL92 = String(TOTAL92);
        document.store.total92.value = (TOTAL92.substr(0,TOTAL92.length-2) + "." + TOTAL92.substr(TOTAL92.length-2));
   }
//   if (IsPosInt(document.store.qty93.value)) {
//        TOTAL93 = Math.round(parseFloat(document.store.qty93.value) * price93 * 100);
//        if (TOTAL93 == 0) {
//           TOTAL93 = "000";
//        }
//        TOTAL93 = String(TOTAL93);
//        document.store.total93.value = (TOTAL93.substr(0,TOTAL93.length-2) + "." + TOTAL93.substr(TOTAL93.length-2));
//   }
   //if (IsPosInt(document.store.qty94.value)) {
   //     TOTAL94 = Math.round(parseFloat(document.store.qty94.value) * price94 * 100);
   //     if (TOTAL94 == 0) {
   //        TOTAL94 = "000";
   //     }
   //     TOTAL94 = String(TOTAL94);
   //     document.store.total94.value = (TOTAL94.substr(0,TOTAL94.length-2) + "." + TOTAL94.substr(TOTAL94.length-2));
   //}
    document.store.grandtotal.value = 0.00;
    if (isNaN(parseFloat(document.store.total59.value))) { TOTAL59 = 0.00; }
    else { TOTAL59 = parseFloat(document.store.total59.value); }

    if (isNaN(parseFloat(document.store.total60.value))) { TOTAL60 = 0.00; }
    else { TOTAL60 = parseFloat(document.store.total60.value); }

    if (isNaN(parseFloat(document.store.total61.value))) { TOTAL61 = 0.00; }
    else { TOTAL61 = parseFloat(document.store.total61.value); }

    if (isNaN(parseFloat(document.store.total62.value))) { TOTAL62 = 0.00; }
    else { TOTAL62 = parseFloat(document.store.total62.value); }

    if (isNaN(parseFloat(document.store.total63.value))) { TOTAL63 = 0.00; }
    else { TOTAL63 = parseFloat(document.store.total63.value); }

    if (isNaN(parseFloat(document.store.total64a.value))) { TOTAL64A = 0.00; }
    else { TOTAL64A = parseFloat(document.store.total64a.value); }

    if (isNaN(parseFloat(document.store.total64b.value))) { TOTAL64B = 0.00; }
    else { TOTAL64B = parseFloat(document.store.total64b.value); }

    if (isNaN(parseFloat(document.store.total65.value))) { TOTAL65 = 0.00; }
    else { TOTAL65 = parseFloat(document.store.total65.value); }

    if (isNaN(parseFloat(document.store.total66.value))) { TOTAL66 = 0.00; }
    else { TOTAL66 = parseFloat(document.store.total66.value); }

    if (isNaN(parseFloat(document.store.total67.value))) { TOTAL67 = 0.00; }
    else { TOTAL67 = parseFloat(document.store.total67.value); }

    if (isNaN(parseFloat(document.store.total68.value))) { TOTAL68 = 0.00; }
    else { TOTAL68 = parseFloat(document.store.total68.value); }

    if (isNaN(parseFloat(document.store.total68a.value))) { TOTAL68A = 0.00; }
    else { TOTAL68A = parseFloat(document.store.total68a.value); }

    if (isNaN(parseFloat(document.store.total69.value))) { TOTAL69 = 0.00; }
    else { TOTAL69 = parseFloat(document.store.total69.value); }

    if (isNaN(parseFloat(document.store.total69b.value))) { TOTAL69B = 0.00; }
    else { TOTAL69B = parseFloat(document.store.total69b.value); }

    if (isNaN(parseFloat(document.store.total91.value))) { TOTAL91 = 0.00; }
    else { TOTAL91 = parseFloat(document.store.total91.value); }

    if (isNaN(parseFloat(document.store.total92.value))) { TOTAL92 = 0.00; }
    else { TOTAL92 = parseFloat(document.store.total92.value); }

//    if (isNaN(parseFloat(document.store.total93.value))) { TOTAL93 = 0.00; }
//    else { TOTAL93 = parseFloat(document.store.total93.value); }

//    if (isNaN(parseFloat(document.store.total94.value))) { TOTAL94 = 0.00; }
//    else { TOTAL94 = parseFloat(document.store.total94.value); }

    GRANDTOTAL = Math.round((TOTAL59 + TOTAL60 + TOTAL61 + TOTAL62 + TOTAL63 + TOTAL64A + TOTAL64B + TOTAL65 + TOTAL66 + TOTAL67 + TOTAL68 + TOTAL68A + TOTAL69 + TOTAL69B + TOTAL91 + TOTAL92) * 100) ;
    if (GRANDTOTAL == 0) {
       GRANDTOTAL = "000";
    }
    GRANDTOTAL = String(GRANDTOTAL);
    document.store.grandtotal.value = (GRANDTOTAL.substr(0,GRANDTOTAL.length-2) + "." + GRANDTOTAL.substr(GRANDTOTAL.length-2));

}
