var totShipping=0;
var length;
var theShipCode;
var totalBags=totalItems(0);
var cur='USD';

/////////////////////////////////////////////////////
function shipReset() {document.multiForm.reset();totShipping=0;}

function selectShipoptValue() {return document.multiForm.shipopt.selectedIndex;}


/////////////////////////////////////////////////////
function setArea() {
               document.multiForm.DesBox.value = 'Description';
               var selectDest = document.multiForm.destination;
               var selectShipopt = document.multiForm.shipopt;
               var theDest = selectDest.options[selectDest.selectedIndex].value; //ie CAN, USA, INT
     selectShipopt.options.length = 0;

     for (var i=0; i<eval(theDest+1).length; i++) {
     	selectShipopt.options[selectShipopt.options.length] = new Option(eval(theDest+1)[i]);
     	selectShipopt.options[0].selected = true;
     	}
}

/////////////////////////////////////////////////////
function setOption()  {
				var selectDest = document.multiForm.destination;
				var selectShipopt = document.multiForm.shipopt;
				var shipoptIDX=document.multiForm.shipopt.selectedIndex;
				var theDest = selectDest.options[selectDest.selectedIndex].value; //ie CAN, USA, INT

				if (checkSierra() == 0) {theShipCode=theDest+shipoptIDX;} else {theShipCode='USA3';}
//alert ('checkSierra()='+checkSierra());

				if (selectDest.options[selectDest.selectedIndex].value == 0) {
					var theDest = initCategory;
               		} else {
               		var theDest = selectDest.options[selectDest.selectedIndex].value;
               		}
var totShipping=0;
var theTotalWeight=totalWeight();
var theRateCode;
var theIndex;

length = shipping.length;
document.multiForm.DesBox.value = eval(theDest+2)[selectShipoptValue()];

//alert ('totalItems(0)='+totalItems(0));
//alert ('totalBags='+totalBags);
//alert ('theShipCode='+theShipCode);
//alert ('theTotalWeight='+theTotalWeight);
//alert ('totalWeight()='+totalWeight());

// get rateCode
theRateCode=getRateCode();

//alert ('theRateCode='+theRateCode);
//alert ('checkSierra()='+checkSierra());


for (var i=0; i < length; i++) {
		if (shipping[i].code == theShipCode && shipping[i].rateCode == theRateCode) {
			//check Sierra
			if (checkSierra() == 0) {
				totShipping=parseFloat(shipping[i].rateUSD);theIndex=i;
				} else {
				//totShipping=parseFloat(eval('shipping[i].rate'+'USD'));
				totShipping=parseFloat(shipping[i].rateUSD*(theTotalWeight/16));theIndex=i;
				}
			
			break;
		}
}

//alert ('totShipping='+totShipping);
//alert ('theIndex='+theIndex);


document.multiForm.TotalBox.value = 'USD $'+convDec(totShipping);

}



/////////////////////////////////////////////////////
function shipConfirm()      {
     self.location="checkout-fin.php?"+cur+','+theShipCode;
     }

////////////////////////////////////////////
//define ship option data arrays

var USARecord=0;
var USA1=new Array(USARecord);
var USA2=new Array(USARecord);
var USAidx=0;

USA1[USAidx]='Shipping Options';
USA2[USAidx]='Description';

if (checkSierra() == 0) {
		USAidx+=1;USA1[USAidx]='CanPost USA Small Packet (Air)';USA2[USAidx]='Arrives in 4 business days';
		USAidx+=1;USA1[USAidx]='CanPost USA Small Packet (Surface)';USA2[USAidx]='Arrives in 10 days';
		} else {
		USAidx+=1;USA1[USAidx]='FedEx Priority Courier (Air)';USA2[USAidx]='Arrives in 1 day';
		}

USARecord = USAidx;


////////////////////////////////////////////
var CANRecord=0;
var CAN1=new Array(CANRecord);
var CAN2=new Array(CANRecord);
var CANidx=0;

CAN1[CANidx]='Shipping Options';
CAN2[CANidx]='Description';
CANidx+=1;CAN1[CANidx]='CanPost Regular Parcel';CAN2[CANidx]='Arrives in 9 days';
CANidx+=1;CAN1[CANidx]='CanPost Xpresspost';CAN2[CANidx]='Arrives in 2 business days';

CANRecord = CANidx;


////////////////////////////////////////////
var INTRecord=0;
var INT1=new Array(INTRecord);
var INT2=new Array(INTRecord);
var INTidx=0;

INT1[INTidx]='Shipping Options';
INT2[INTidx]='Description';
INTidx+=1;INT1[INTidx]='CanPost International Small Packet (Air)';INT2[INTidx]='Arrives in 10-12 days';
INTidx+=1;INT1[INTidx]='CanPost International Small Packet (Surface)';INT2[INTidx]='Arrives in up to 21 days';

INTRecord = INTidx;
