function doHelp(msg){
	window.defaultStatus = statusMSG[msg];
}

function daysFromToday(sdate) {
	cm = twoDig(crdate.getMonth());
	cd = twoDig(crdate.getDate());
	cy = twoDig(crdate.getYear());
	cr = cy+""+cm+""+cd;
	
	nrdate = new Date();
	nm = twoDig(nrdate.getMonth());
	nd = twoDig(nrdate.getDate());
	ny = twoDig(nrdate.getYear());
	nr = ny+""+nm+""+nd;
	return (cr<nr);
}

function twoDig(num){
	if(num.toString().length<2){
		return "0"+num;
	}else{
		return num;
	}
}

 
function DoReset(form) {
	form.baseresult.value = "  ";
	form.upchresult.value = "  ";
	form.fuelresult.value = "  ";
	form.txtresult.value = "  ";
	form.from.selectedIndex = 0;
	form.to.selectedIndex = 0;
	form.footage.selectedIndex = 0;
	form.weight.selectedIndex = 0;
	form.service.selectedIndex = 0;
}
 
function DoClear(form) {
	form.baseresult.value = "  ";
	form.upchresult.value = "  ";
	form.fuelresult.value = "  ";
	form.txtresult.value = "  ";
}

function DoCalc(form){
	fuelper=fuelpert;
	se = false;
	fromIdx		= form.from.selectedIndex;
	from		= statesList[form.from[fromIdx].value];
	toIdx		= form.to.selectedIndex;
	to		= statesList[form.to[toIdx].value];
	footageIdx	= form.footage.selectedIndex;
	footage		= form.footage[footageIdx].value*1;
	weightIdx	= form.weight.selectedIndex;
	weight		= form.weight[weightIdx].value*1;
	serviceIdx	= form.service.selectedIndex;
	service		= form.service[serviceIdx].value*1;
	
	DoClear(form);
	
	if (daysFromToday(crdate)) {
		alert ("This calculator is expired.");
	}else if(!fromIdx||!toIdx||!footageIdx||!weightIdx||!serviceIdx){
		alert("You have to select all options");
	}else if(from[2] > 13 && to[2] > 13){
		alert("This calculator currently does not support shipping\nfrom Alaska/PR to Alaska/PR");
	}else if((from[3]>0 && to[3]>13)||(from[3]>13 && to[3]>0)){
		alert("This calculator currently does not support shipping\n from Alaska/Canada/PR to Alaska/Canada/PR");
	}else{
		myTable = zoneTable;
		myFrom = from[2]-1;
		myTo = to[2]-1;
		if(from[3]>0 && to[3]>0){
			if(from==to){
				alert("Sealed Divider service is unavailable for shipments whose origin and destination are in the same province.");
			}else{
				myTable = canTable;
				myFrom = from[3]-1;
				myTo = to[3]-1;
			}
		}
		if(weight>footage){
			footage = weight;
			form.footage.selectedIndex = weightIdx;
		}
		foot = (footage<15)? 1 : 2;
		foot = (footage<9) ? 0 : foot;
		baserate = myTable[myFrom][foot][myTo];
		baserate = baserate * footage;
		if(service==1.2){
			baserate = baserate * service;
			service = 0;
			se = true;
		}
		upchrate = service * baserate;
		fuelrate = baserate * fuelper ;
		totrate = (baserate*1)+(upchrate*1)+(fuelrate*1);
		fuelper = fuelper * 100;
		service = service * 100;
		
		form.baseresult.value	= "  $"+baserate.toFixed(2);
		form.upchresult.value	= (se) ? "  Sealed Exhibit" : "  $"+upchrate.toFixed(2)+" ("+service.toFixed(0)+"%)" ;
		form.fuelresult.value	= "  $"+fuelrate.toFixed(2)+" ("+fuelper.toFixed(1)+"%)" ;
		form.txtresult.value	= "  $"+totrate.toFixed(2) ;
	}
		
}

function loadStates(){
	form = document.forms['form1'];
	from = form.from;
	to = form.to;
	from.length = to.length = statesList.length+1;
	for(i=0;i<statesList.length;i++){
		from[i+1].value=i;
		from[i+1].text=statesList[i][1];
		to[i+1].value=i;
		to[i+1].text=statesList[i][1];
	}
}
