var y=new Array(); 

function FindZone(zip,type) { 
	if(isNaN(zip)) return 0;
	if(zip.length!=5) return 0;
	zip=""+zip;
	zip=zip.substr(0,3)*1+type;  
	while (isNaN(z[zip]))zip--; 
	return z[zip];
};

function PriorityMail(zip,lbs) {
	if(zip=="0") return 0;
	if(Math.ceil(lbs)>10) return 0; 
	return pm[Math.ceil(lbs)][FindZone(zip,0)];
};

function ExpressMail(zip,lbs) {
	// WAS:: if (lbs<=0.5) return fix2( express[0] );	
	// WAS:: return express[Math.ceil(lbs)];
	//Below added for new variable zone express rates
	if(zip=="0") return 0;
	if(Math.ceil(lbs)>10) return 0;
	return express[Math.ceil(lbs)][FindZone(zip,0)];
};

function PutQuote(x,y) { 
	if(x==0) x="" ;else{x="$"+fix2(x)} ; 
	this.document.forms[0].elements[y].value=x; 
};	
function UPSground(zip,lbs) {
	if(zip=="0") return 0;
	if(Math.ceil(lbs)>10) return 0;
	return upsg[Math.ceil(lbs)][FindZone(zip,1000)]*Surcharge; 
};

function UPS3day(zip,lbs) {
	if(zip=="0") return 0;
	if(Math.ceil(lbs)>10) return 0;
	return ups3d[Math.ceil(lbs)][FindZone(zip,1000)]*Surcharge;
};

function UPS2day(zip,lbs) {
	if(zip=="0") return 0;
	if(Math.ceil(lbs)>10) return 0;
	return ups2d[Math.ceil(lbs)][FindZone(zip,1000)]*Surcharge;
};

function UPSnday(zip,lbs) {
	if(zip=="0") return 0;
	if(Math.ceil(lbs)>10) return 0;
	return upsnd[Math.ceil(lbs)][FindZone(zip,1000)]*Surcharge;
};

function QuoteShipping() {
	if(SCV != "JAPAN12" && document.forms[0].ShipCountry.value == "JAPAN12") alert("For Special Prices see our Japanese Site at http://www.yandina.com/YandinaJapan/");
	SCV=document.forms[0].ShipCountry.value; //Shipping Country Value, eg USA1
	SCR=SCV.substring(SCV.length-2,SCV.length);			//Shipping Country Rate, eg 1  
	SCN=SCV.substring(0,SCV.length-2); //Shipping country Name,  
	for(x=2;x<16;x=x+2){this.document.forms[0].elements[x].value=""}; // Clear out any old data.
	var SZVal = document.forms[0].ShipZip.value;  
	if(shipweight==0) return 0;			//Can't quote shipping until something ordered.
	if (SCN =="USA") {  //Domestic shipping tables start at [1,1] so don't have to correct for zero entry
		x=PriorityMail(SZVal,shipweight); 		//This one comes first so not erased if foreign shipping quote below.	
		PutQuote(x,QuotePriority);

		x=ExpressMail(SZVal, shipweight); 
		PutQuote(x,QuoteExpress);				//To erase old data if any
		//if(SZVal>100 && document.forms[0].ShipZip.value.length==5) PutQuote(x,QuoteExpress);
		
		
		x=UPSground(SZVal,shipweight)*1;
		if(x>0){
			x=x+BoxCharge;
			if(!document.forms[0].Commercial.checked&&x>0) x=x+ResidentialSurcharge;
		};
		PutQuote(x,QuoteUPSg);
	
		x=UPS3day(SZVal,shipweight)*1;
		if(x>0){
			x=x+BoxCharge;
			if(!document.forms[0].Commercial.checked&&x>0) x=x+ResidentialSurcharge;
		};
		PutQuote(x,QuoteUPS3d);
	
		x=UPS2day(SZVal,shipweight)*1;
		if(x>0){
			x=x+BoxCharge;
			if(!document.forms[0].Commercial.checked&&x>0) x=x+ResidentialSurcharge;
		};
		PutQuote(x,QuoteUPS2d);
	
		x=UPSnday(SZVal,shipweight)*1;
		if(x>0){
			x=x+BoxCharge;
			if(!document.forms[0].Commercial.checked&&x>0) x=x+ResidentialSurcharge;
		};
		PutQuote(x,QuoteUPSnd);
	};
	if(SCN!="USA") { //alert("ZONE "+(SCR-1)+" Wt "+shipweight); 
		x=Foreign[Math.ceil(shipweight)-1][(SCR-1)]; //-1 SCR and -1 shipweight becasue table starts at zero.
		document.forms[0].elements[3].checked = true; //Priority mail radio button
		if(x==undefined)x=0.001;
		PutQuote(x,QuotePriority);
	};	
};

Javacount=Javacount+2;
if(JavaCheck==true)alert("Shipping add 2="+Javacount);
