

var saveHeight;
var showing = true;



function tabbingOff(theField) {

var a = $(theField);

a.disabled = true;

}

function tabbingOn(theField) {

var a = $(theField);

a.disabled = false;


}



function toggleTabbing(tabaction) {



  if(tabaction == 'off'){

   tabbingOff('bill_firstname'); 
   tabbingOff('bill_lastname'); 
   tabbingOff('bill_street-address'); 
   tabbingOff('bill_city'); 
   tabbingOff('bill_postcode'); 
   tabbingOff('bill_country'); 
   tabbingOff('bill_company'); 
   tabbingOff('bill_suburb'); 
   tabbingOff('bill_country'); 
   tabbingOff('bill_telephone'); 
   tabbingOff('bill_gender-male'); 
   tabbingOff('bill_gender-female'); 
   tabbingOff('bill_stateZone'); 
   tabbingOff('bill_state'); 

  } else {

   tabbingOn('bill_firstname'); 
   tabbingOn('bill_lastname'); 
   tabbingOn('bill_street-address'); 
   tabbingOn('bill_city'); 
   tabbingOn('bill_postcode'); 
   tabbingOn('bill_country'); 
   tabbingOn('bill_company'); 
   tabbingOn('bill_suburb'); 
   tabbingOn('bill_country'); 
   tabbingOn('bill_telephone'); 
   tabbingOn('bill_gender-male'); 
   tabbingOn('bill_gender-female'); 
   tabbingOn('bill_stateZone'); 
   tabbingOn('bill_state'); 

  }
      



}





function toggleSlide() {
 if ( showing )
 { slideShippingAddressUp(); showing = false; }
 else
 { slideShippingAddressDown(); showing = true; }

}

function slideShippingAddressUp() {
  var menu = $('shippingAddress');
  saveHeight = menu.offsetHeight;

  menu.style.overflow = "hidden";
  new Rico.Effect.Size( menu, null, 1, 120, 8 );
  menu.display = "none";
//alert("disabling menu");
  menu.disabled = true;
  toggleTabbing("off");
}

function slideShippingAddressDown() {
  var menu = $('shippingAddress');
  new Rico.Effect.Size( menu, null, saveHeight, 120, 8, {complete:function() { $(menu).style.overflow = "visible"; }} );
  menu.display = "block";
//alert("re-enabling menu");
  menu.disabled = false;
  toggleTabbing("on");

}


function processShipping(){


  var x=document.getElementById("shipping_quote")
//  alert(x.selectedIndex + " : " +  $F('shipping_quote')  + " : " +  $F('comments'))

    
new Ajax.Request('index.php?main_page=ajax'


, {

method:'post',
parameters:'&rs=shipping_process' 
+ "&shipping=" + $F('shipping_quote')
+ "&comments=" + $F('comments')
+ "&action=process"
,

 onSuccess: function(transport){
  var response = transport.responseText || "no response text";
//          alert("Success! [shipping_process]\n\n" + response);
eval(transport.responseText);
 loadViewInDiv('main_total','main_totals');
},
 onFailure: function(){ alert('shipping_process failed') }

 });


}





function getShippingQuotes()
{
     new Ajax.Request
	 (
	       'index.php?main_page=ajax', 
	       { 
	        method:'post', 
			parameters:'&rs=shipping_quotes',
			onSuccess: 
		    function(transport)
		    {
				 var response = transport.responseText || "no response text";
				 var shippingSelect = document.getElementById("shipping_quote");
				 var oldShippingVal = null;
				 if(shippingSelect.value){
				 	oldShippingVal = shippingSelect.value;
				 }
				 
				 //remove the old values
				 while(shippingSelect.length > 0){
					shippingSelect.remove(0);
			 	}
			 eval(response);
			 var y;
			 for (x in quotes){
			      for (xx in quotes[x]['methods']){
				   if(quotes[x]['methods'][xx]['id']){
					y=document.createElement('option');
					y.text=quotes[x]['module'];
					y.value=quotes[x]['id'] + '_' + quotes[x]['methods'][xx]['id'];
					
					//test if this was previously selected
					if (y.value == oldShippingVal){
						y.selected=true;
					}
					try
					{
					     shippingSelect.add(y,null); // standards compliant
					}
					catch(ex)
					{
					     shippingSelect.add(y); // IE only
					}
				   }
			      }
			 }
			 processShipping(); //get the new default
			 loadViewInDiv('main_total','main_totals');
		    },
			 onFailure:  function(){ document.getElementById('shipping_quote_debug').innerHTML="shipping_quotes failed"; }
		    
	       }
	       );
}

