//Garry Harstad
//Checkout scripts.

   //use_siteexitmessage = false; // somehow this will need to be overwritten to allow the site exit popup window to work.
   function submitorder()
   {
   	  formobj=document.forms["cartform"];
      if(!formobj) { alert("No Form on this page named 'cartform'"); return; }
      formobj.randomkey.value=Math.random();
      try
      {
	       var topbutton=document.getElementById("continuebutton_top");
         var bottombutton=document.getElementById("continuebutton_bottom");
         topbutton.value="Processing..."; topbutton.disabled=true;
         bottombutton.value="Processing..."; bottombutton.disabled=true;
	       formobj.mode.value="processpayment";
         //alert("I was about to submit this order!");
         formobj.submit();
      }
      catch(e) { alert("Problem Submitting the Order"); }
   }

   //used on the cart page for removing a particular item
   function deleteitem(pid,oidid,qty,paytype)
   {
      if(!paytype){paytype = 'currency'}
      var widget = 'this item';
      if (arguments.length > 4) {widget = arguments[4]}
      var formobj=document.cartform;
      formobj.productid.value=pid;
      formobj.paytype.value=paytype;
      formobj.orderitemdetailid.value=oidid;
      formobj.prodqty.value=parseInt(qty);
      formobj.mode.value="delete";
      //deleteaction(formobj.mode,'this item');
      formobj.randomkey.value=Math.random();
      deleteaction(formobj.mode,widget);
   }

    //validates that a particular character containing box does not exceed the specified character limit
    function checkchars(maxchars,charcontainer)
    { 
       formobj = document.cartform;
       if(!parseInt(maxchars)) { maxchars=240; }
       var charobj = formobj.elements[charcontainer];
       numofchars = maxchars - charobj.value.length ;
       var countdownobj = formobj.elements[charcontainer+"_chars"];
       if (numofchars >= 0)
       { countdownobj.value=numofchars; }
       else
       { charobj.value = charobj.value.substring(0,charobj.value.length-1); }
       if (charobj.value.length > maxchars)
       {
          charstodelete = charobj.value.length - maxchars ;
          charobj.value = charobj.value.substring(0,charobj.value.length-charstodelete) ;
       }       
       
       if(charobj.value.length >= maxchars) 
        { 
          countdownobj.className = 'textlengthWarn'; 
          addClass(charobj,'overlength')
         }
       else 
        { 
          countdownobj.className = 'textlengthOK';
          killClass(charobj,'overlength')
         }
    }
    
    ///shows a popup of shipping method description. If you pass a shipping method id (or list) it will use that othewise it fetches the id from [cartform.shippingmethodid]
    function showshippingmethoddetails(currentshippingmethodid)
    {
       if(!currentshippingmethodid)
       {
          var formobj=document.cartform;
          var shipmethodobj=formobj.shippingmethodid;
          currentshippingmethodid = shipmethodobj.options[shipmethodobj.selectedIndex].value;
       }
       //to'h 20060601: changed test to NaN test; sometimes getting a string passed
       if (!isNaN(parseInt(currentshippingmethodid)))
       { newwindow('/displayshippingmethod_details.cfm?shippingmethodidlist=' + currentshippingmethodid); }
       else
       {alert("N O T E\nNo valid selection was made.\nSelect a method and then click for information")}
    }
    
    //determines if the checkbox for "this is my billing address" is used, and WARNS and selects the email box.
    function checkemailrequired(obj)
    {
      formobj = obj.form;
      var requiredstring="REQUIRED IF BILLING ADDRESS";
      var emailobj=formobj.email;
      if(obj.checked==true)
      {
         if(emailobj.value=="")
         {
            emailobj.value=requiredstring;
            emailobj.focus();
            emailobj.select();
         }
      }
      else
      {
         if(emailobj.value==requiredstring)
         { emailobj.value=""; }
      }
    }
    
   function checkisgift(obj)
   {
      if(!obj) { return; }
      var formobj=obj.form;
      if(obj.checked)
      {
         formobj.giftmessage.disabled=false;
         togglelayer("giftmsgrow1",1);
         togglelayer("giftmsgrow2",1);
      }
      else
      {
         formobj.giftmessage.disabled=true;
         togglelayer("giftmsgrow1",0);
         togglelayer("giftmsgrow2",0);
      }
   }
 
 //function to set the amount of current payment from a link  
 function setPPAmount(amount)
   {
    var paymentField = document.cartform.mindeposit
    if(paymentField) {paymentField.value = amount}
    return false
   }
