var xmlhttp

function getPrice(prov,pri) {
  xmlhttp=GetXmlHttpObject();
  if (xmlhttp==null) {
    alert ("Your browser does not support AJAX!");
    return;
  }
  var url="order_get.php";
  url+="?prov="+prov;
  url+="&pri="+pri;
  url+="&sid="+Math.random();
  xmlhttp.onreadystatechange=stateChanged;
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
}

function stateChanged() {
  if (xmlhttp.readyState==4) {
    document.getElementById("price").innerHTML=xmlhttp.responseText;
  }
}

function GetXmlHttpObject() {
  if (window.XMLHttpRequest) {
    return new XMLHttpRequest();
  }
  if (window.ActiveXObject) {
    return new ActiveXObject("Microsoft.XMLHTTP");
  }
  return null;
}

function checkRadio(radioName) {
  if (radioName.length) {
    for (i=0; i<radioName.length; i++) if (radioName[i].checked) break;
    if (i==radioName.length) return false;
  } else if (radioName.checked) return true;
    else return false;
  return true;
}

function verifySubmit() {
  var a=document.orderform;
  var validateFailed=false
  
  if (!checkRadio(a.sub_offer)) validateFailed=true;
  if (a.firstname.value  == "") {
    validateFailed=true;
    a.firstname.style.backgroundColor='rgb(255,128,128)';
    }
  if (a.lastname.value == "") { 
    validateFailed=true;
    a.lastname.style.backgroundColor='rgb(255,128,128)';
  }
  if (a.address.value == "") { 
    validateFailed=true;
    a.address.style.backgroundColor='rgb(255,128,128)';
  }
  if (a.city.value == "") { 
    validateFailed=true;
    a.city.style.backgroundColor='rgb(255,128,128)';
  }
  if (a.postalcode.value == "") { 
    validateFailed=true;
    a.postalcode.style.backgroundColor='rgb(255,128,128)';    
  }
  if (a.prov.value == "") { 
    validateFailed=true;
    a.prov.style.backgroundColor='rgb(255,128,128)';
  }
  if (a.phone.value == "") { 
    validateFailed=true;
    a.phone.style.backgroundColor='rgb(255,128,128)';
  }
  if (a.email.value      == "") {  
    validateFailed=true;
    a.email.style.backgroundColor='rgb(255,128,128)';
  }
  if (a.age.value == "") {
    validateFailed=true;
    a.age.style.backgroundColor='rgb(255,128,128)';
  }

  if (!checkRadio(a.gender)) validateFailed=true;
    
  if (!validateFailed)
    return true;
  alert("You have not filled out all required fields.");
  return false;
}

function verifyGiftSubmit() {
  var a=document.orderform;
  var failedFields='';

  if (!checkRadio(a.sub_offer))       failedFields+='\nSubscription Offer';
  if (a.firstname.value == '')        failedFields+='\nShipping First Name';
  if (a.lastname.value == '')         failedFields+='\nShipping Last Name';
  if (a.address.value == '')          failedFields+='\nShipping Address';
  if (a.city.value == '')             failedFields+='\nShipping City';
  if (a.postalcode.value == '')       failedFields+='\nShipping Postal Code';
  if (a.prov.value == '')             failedFields+='\nShipping Province';
  if (a.bill_firstname.value == '')   failedFields+='\nBilling First Name';
  if (a.bill_lastname.value == '')    failedFields+='\nBilling Last Name';
  if (a.bill_address.value == '')     failedFields+='\nBilling Address';
  if (a.bill_city.value == '')        failedFields+='\nBilling City';
  if (a.bill_prov.value == '')        failedFields+='\nBilling Province';
  if (a.bill_postalcode.value == '')  failedFields+='\nBilling Postal Code';
  if (a.bill_phone.value == '')       failedFields+='\nBilling Phone Number';
  if (a.bill_email.value == '')       failedFields+='\nBilling Email Address';

  if (failedFields=='') return true;

  alert("You have not filled out all required fields.\n"+failedFields);
  return false;
}