
var forceUrl = 'https://www.utechsoft.com';
//var forceUrl = 'http://localhost:8080';
var url = document.location + "";
if (url.substring(0, forceUrl.length).toLowerCase() != forceUrl.toLowerCase()) {

  //do a redirect...
  var suburl = url.substring(url.indexOf("/", 10), url.length);
  location.replace(forceUrl + suburl);
}


var licensetype = 2;
var payment = 1; // credit card is the default

function validateForm() {
  var valid = true;

  if (valid)
    processForm();
}

function validateFields() {
  try {
    if ((document.licenseform.numcon.value) == 1 && (document.licenseform.licenseType[0].checked || document.licenseform.licenseType[1].checked)) {
      var answer = confirm("If this is your initial purchase of the servlet, we recommend 3 or more connections. Continue with purchase?");
      if (answer == false) {
        return (false);
      }
    }
  }
  catch (e){}
  if (document.paypal.x_First_Name.value == "") {
    alert("You can't leave the 'Purchaser Name' field blank.");
    document.paypal.x_First_Name.focus();
    return (false);
  }
  if (document.paypal.x_Company.value == "") {
    alert("You can't leave the 'Company Name' field blank.");
    document.paypal.x_Company.focus();
    return (false);
  }
  if (document.paypal.x_Address.value == "") {
    alert("You can't leave the 'Street Address' field blank.");
    document.paypal.x_Address.focus();
    return (false);
  }
  //if (document.paypal.bill_address_two.value == "") {
  //  alert("You can't leave the Street Address field blank.");
  //  document.paypal.bill_address_two.focus();
  //}
  if (document.paypal.x_City.value == "") {
    alert("You can't leave the 'City' field blank.");
    document.paypal.x_City.focus();
    return (false);
  }
  if (document.paypal.x_State.value == "") {
    alert("You can't leave the 'State/Province' field blank.");
    document.paypal.x_State.focus();
    return (false);
  }
  if (document.paypal.x_Zip.value == "") {
    alert("You can't leave the 'Zip/Postal Code' field blank.");
    document.paypal.x_Zip.focus();
    return (false);
  }// else {
  //  var postal_code = document.paypal.bill_postal_code.toUpperCase();
  //document.paypal.bill_postal_code.value = postal_code;
  //}
  //if (document.paypal.bill_country.value == "") {
  //  alert("You can't leave the Country field blank.");
  //  document.paypal.bill_country.focus();
  //}
  if (document.paypal.x_Phone.value == "") {
    alert("You can't leave the 'Phone #' field blank.");
    document.paypal.x_Phone.focus();
    return (false);
  }

  if (document.paypal.x_Email.value == "") {
    alert("You can't leave the 'Email Address' field blank.");
    document.paypal.x_Email.focus();
    return (false);
  }
  if (document.paypal.x_Email.value.toLowerCase().indexOf("yahoo.") >=0) {
    alert("We don't accept Yahoo email accounts");
    document.paypal.x_Email.focus();
    return (false);
  }
  if (document.paypal.x_Email.value.toLowerCase().indexOf("gmail.") >=0) {
    alert("We don't accept Gmail email accounts");
    document.paypal.x_Email.focus();
    return (false);
  }
  if (document.paypal.x_Email.value.toLowerCase().indexOf("hotmail.") >=0) {
    alert("We don't accept Hotmail email accounts");
    document.paypal.x_Email.focus();
    return (false);
  }
  if (document.paypal.x_Card_Num.value == "") {
    alert("You can't leave the 'Credit Card Number' field blank.");
    document.paypal.x_Card_Num.focus();
    return (false);
  }
  if (document.paypal.x_Exp_Date.value == "") {
    alert("You can't leave the 'Expiry Date' field blank.");
    document.paypal.x_Exp_Date.focus();
    return (false);
  }
  //if (document.paypal.bill_note.value == "") {
  //  alert("You can't leave the \"IP or Domain Name\" field blank.");
  //  document.paypal.bill_note.focus();
  //return (false);
  //}
  return (true);
}

function getShippingInfo() {
  document.paypal.x_Ship_To_Address.value = document.paypal.x_Address.value;
  document.paypal.x_Ship_To_City.value   =  document.paypal.x_City.value;
  document.paypal.x_Ship_To_Company.value   =  document.paypal.x_Company.value;
  document.paypal.x_Ship_To_Country.value   =  document.paypal.x_Country.value;
  document.paypal.x_Ship_To_First_Name.value   =  document.paypal.x_First_Name.value;
  document.paypal.x_Ship_To_Last_Name.value   =  document.paypal.x_Last_Name.value;
  document.paypal.x_Ship_To_State.value   =  document.paypal.x_State.value;
  document.paypal.x_Ship_To_Zip.value  = document.paypal.x_Zip.value
}

function confirmProduct(amount, desc, itemConstant) {
  //do discount here...
  amount = getDiscountedPrice(itemConstant, amount);

  if (itemConstant == CONST_CUSTOM_PAYMENT) {
    document.getElementById('taxDisplay').innerHTML = '';
    amount = amount*1.0;
  } else if (document.paypal.x_Country.options[document.paypal.x_Country.selectedIndex].value=="CA") {
    document.getElementById('taxDisplay').innerHTML = '(13% sales tax added for Canadian residents)';
    amount = amount*1.13;  // add HST for Canadian residents
  } else {
    document.getElementById('taxDisplay').innerHTML = '';
    amount = amount*1.0; // apply sales discount
  }

  document.paypal.total.value = formatCurrency(amount);
  //document.paypal.price0.value= formatCurrency(amount);
  //document.paypal.subtotal0.value= formatCurrency(amount);
  document.paypal.x_Amount.value= simpleFormatCurrency(amount);
  tempTotal=amount;
  document.paypal.x_Description.value= desc;
  tempDesc = desc;
  if (document.licenseform.ipdomain) {
    document.paypal.IP_OR_DOMAIN.value = document.licenseform.ipdomain.value;
  }
  if (document.licenseform.details) {
    document.paypal.AdditionalInfo.value = document.licenseform.details.value;
  }
}

function submitForm() {
  if (false){
    alert("You must select product and a license type first!");
    return;
  }
  var valid = true;
  processForm();

  //if (validateFields()) {
  //  getShippingInfo();
  if (payment==2) {
    valid = false;
    //alert("You have selected cheque as a method of payment");
    alert("If paying by cheque follow these instructions:\n\r\n\r"+
      "Print this order form\n\r"+
      "include it with your payment");
  }
  if (valid){
    if (validateFields()) {
      getShippingInfo();
      document.paypal.submit();
    }
  }
//}
}

