document.observe('dom:loaded',function() {
	getPrice();
	new Form.Element.Observer('pri_code', 2, 
		function(form, value){
	    getPrice();
	});
});

function getPrice() {
 	var pri = $('pri_code').value;
	new Ajax.Updater('price', 'order_get.php', {"parameters": {"pri": pri}, "method": "get"});
}

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;
}