// quick order form validation
function validateQuickOrder(form) {        
  if ((form.ProductNumber.value == "")|| (form.ProductNumber.value == "Enter Product #")){
        alert("Please enter an item number.");
        form.ProductNumber.focus();
        return false;
 }
        return true;
}


// used on one-page check out to populate the shipping address from the billing address
function UseBillingAsShipping(form)
{

  if (form.ship_to_bill_address.checked)
  {
    form.FName_SHIP.value = form.FirstName.value;
    form.LName_Ship.value = form.LastName.value;
    form.Address1_Ship.value = form.Address1.value;
    form.Address2_Ship.value = form.Address2.value;
    form.City_Ship.value = form.City.value;
    form.State_SHIP.value = form.State.value;
    form.COUNTRY_SHIP.value = form.COUNTRY.value;
    form.PostalCode_SHIP.value = form.PostalCode.value;
    form.Phone_Ship.value = form.Phone.value;

    populateCartTotal();
//alert('Test Click');
  }
  else
  {
    form.Address1_Ship.value = '';
    form.Address2_Ship.value = '';
    form.City_Ship.value = '';
    form.State_SHIP.value = '';
    form.PostalCode_SHIP.value = '';
    form.FName_SHIP.value = '';
    form.LName_Ship.value = '';
    form.Phone_Ship.value = '';

    populateCartTotal();
  }
}

// used on one-page check out to update order total (for example after state, country, or shipping method change)
function populateCartTotal()
{
  var state_ship = document.getElementsByName("State_SHIP")[0].value;
  var country_ship = document.getElementsByName("COUNTRY_SHIP")[0].value;
  var zip_ship = document.getElementsByName("PostalCode_SHIP")[0].value;
   
  if (state_ship != " - Select - " && country_ship != " - Select - " && document.getElementById("shipping_method") != null)
  {
    //shipping_method dropdown wont exist if page portion is being refreshed by AJAX call
    var ship_method = document.getElementsByName("shipping_method")[0].value;

    DmiAjaxFetch('CheckoutCartTotalContent', 'DmiAjaxSecure.aspx', 'request=CheckoutCartTotalContent&state_ship=' + state_ship + '&country_ship=' + country_ship + '&zip_ship=' + zip_ship + '&shipping_method=' + ship_method + '&extra=', rnd());
  }
}

// used on one-page check out to apply the promo code the customer provides
function applyKeyCode()
{
  var keycode = document.getElementsByName("keycode")[0].value;
   
  DmiAjaxFetch('CheckOutCartItemsContent', 'DmiAjaxSecure.aspx', 'request=CheckOutCartItemsContent&keycode=' + keycode + '&extra=', rnd());
}

// used to generate random string that will be appended to AJAX requests to avoid getting cached response
function rnd() { 
  return String((new Date()).getTime()).replace(/\D/gi,'') 
}

// used on one-page check out to update billing state or country and order total
function updateBillingInfo()
{
  var state_bill = document.getElementsByName("State")[0].value;
  var country_bill = document.getElementsByName("COUNTRY")[0].value;
  var zip_bill = document.getElementsByName("PostalCode")[0].value;
   
  if (state_bill != " - Select - " && country_bill != " - Select - ")
  {
    DmiAjaxFetch('CheckoutCartTotalContent', 'DmiAjaxSecure.aspx', 'request=CheckoutCartTotalContent&state_bill=' + state_bill + '&country_bill=' + country_bill + '&zip_bill=' + zip_bill + '&extra=', rnd());
  }

}

