function validate_txt(field,alerttxt)
{
  with (field)
  {
    if (value==null||value=="")
    {
      alert(alerttxt);
      return false;
    }
    else 
    {
    return true;
    }
  }
}

function validate_form(thisform)
{
  with (thisform)
  {
    if (validate_txt(Name,"Please enter your first name.")==false) { Name.focus(); return false; }
    if (validate_txt(LName,"Please enter your last name.")==false) { LName.focus(); return false; }
    if (validate_txt(Email,"Please enter an e-mail address.")==false) { Email.focus(); return false; }
    if (validate_txt(Phone,"Please enter your phone number.")==false) { Phone.focus(); return false; }
    if (validate_txt(Addr_Line1,"Please enter your billing address.")==false) { Addr_Line1.focus(); return false; }
    if (validate_txt(Addr_City,"Please enter your billing city.")==false) { Addr_City.focus(); return false; }
    if (validate_txt(Addr_State,"Please select a billing state.")==false) { Addr_State.focus(); return false; }
    if (validate_txt(Addr_Zip,"Please enter a billing zip code.")==false) { Addr_Zip.focus(); return false; }
    
    
    if ( $('#chkShipping').is(":checked") )
    {
      if (validate_txt(shpName,"Please enter your shipping first name.")==false) { shpName.focus(); return false; }
      if (validate_txt(shpLName,"Please enter your shipping last name.")==false) { shpLName.focus(); return false; }
      if (validate_txt(shpAddr_Line1,"Please enter your shipping address.")==false) { shpAddr_Line1.focus(); return false; }
      if (validate_txt(shpAddr_City,"Please enter your shipping city.")==false) { shpAddr_City.focus(); return false; }
      if (validate_txt(shpAddr_State,"Please select a shipping state.")==false) { shpAddr_State.focus(); return false; }
      if (validate_txt(shpAddr_Zip,"Please enter a shipping zip code.")==false) { shpAddr_Zip.focus(); return false; }
    }
    
    if (validate_txt(CC_Number,"Please enter your credit card number.")==false) { CC_Number.focus(); return false; }
    if (validate_txt(CC_Name,"Please enter the name on your credit card.")==false) { CC_Name.focus(); return false; }
    if (validate_txt(CC_CCV,"Please enter your CCV number.")==false) { CC_CCV.focus(); return false; }
    
  }
  //window.onbeforeunload = null;
  document.getElementById('subm').disabled=true;
}

function ship2()
{
  if ($('#chkShipping').is(':checked'))
  { $('#ship2').slideDown('fast'); }
  else
  { $('#ship2').slideUp('fast'); }
}


function doPrices() {
  
  var formData = $(":input").serialize();
  $.post("/x_products.php", formData,
  function(data){
    //$('#x_products').html(data);
    var returndata = eval('('+data+')');
    
    for ( var i in returndata.pPrice )
    {
      $('#p_'+i).html("$"+(returndata.pPrice[i]).toFixed(2));
    }
    for ( var i in returndata.pIPrice )
    {
      $('#pI_'+i).html("$"+(returndata.pIPrice[i]).toFixed(2));
    }
    
    $('#x_numItems').html("<b></b>"+returndata.numItems);
    $('#x_subtotal').html("$"+(returndata.pSubtotal).toFixed(2));
    $('#x_insurance').html("$"+(returndata.pInsurance).toFixed(2));
    //$('#x_discount').html("$"+(returndata.pDiscount).toFixed(2)+" Off");
    //$('#discount2').html("$"+(returndata.pDiscount).toFixed(2));
    $('#x_coupon').html("$"+(returndata.pCoupon).toFixed(2)+" Off");
    $('#x_total').html("$"+(returndata.pTotal).toFixed(2));
    $('#x_total2').html("$"+(returndata.pTotal).toFixed(2));
    $('#x_shpDrop').html("<b></b>"+returndata.shpDrop);
    
    if (returndata.msg!='') { alert(returndata.msg); }
    
    
    if (returndata.pCoupon==0)
    {
      $('#x_coupon').fadeOut("slow");
      $('#txtCoupon').val("");
    }
    else
    {
      $('#x_coupon').fadeIn("slow");
    }
    
    document.getElementById('subm').disabled=false;
  });
  
}
/*
function tenCheck(abc) {
  if (abc.value>10) abc.value=10;
  if (abc.value<0) abc.value=0;
  if (isNaN(abc.value)) abc.value=0;
}
*/
$(document).ready(function () {

  doPrices();
  
});

//window.onbeforeunload = unloadMessage;
//function unloadMessage() {
//     return "\n\nWait!  Before you go...\n\nLIMITED TIME OFFER: 5% OFF COUPON!\n\nEnter coupon FIVE during checkout!\n\n";
//}