function TECChideShow(){
	if (origlen > 1) {
		doorig = true;
	} else if (origlen == 0) {
		origerror = true;
	}
	if (destlen > 1) {
		dodest = true;
	} else if (destlen == 0) {
		desterror = true;
	}
	TECCHomeSelect();
	document.form0.origcity.selectedIndex = 0;
	document.form0.origst.selectedIndex = 0;
	document.form0.origtype.selectedIndex = 0;
	document.form0.destcity.selectedIndex = 0;
	document.form0.destst.selectedIndex = 0;
	document.form0.desttype.selectedIndex = 0;

}
function TECCHomeSelect(){
	isNS4 = (document.layers) ? true : false;
	isIE4 = (document.all && !document.getElementById) ? true : false;
	isIE5 = (document.all && document.getElementById) ? true : false;
	isNS6 = (!document.all && document.getElementById) ? true : false;
	if (isNS4){handle = "document.layers"; stylevar=""}
	if (isIE4 || isIE5){handle = "document.all"; stylevar=".style"}
	if (isNS6){handle = "document.getElementById";stylevar=".style"}
	if (isIE4 || isIE5 || isNS4){
		eval(handle+'["'+'O'+'"]'+stylevar+'.visibility = "hidden"');
		eval(handle+'["'+'D'+'"]'+stylevar+'.visibility = "hidden"');
		eval(handle+'["'+'OERROR'+'"]'+stylevar+'.visibility = "hidden"');
		eval(handle+'["'+'DERROR'+'"]'+stylevar+'.visibility = "hidden"');
		if (doorig) {
			eval(handle+'["'+'O'+'"]'+stylevar+'.visibility = "visible"');
		}
		if (dodest) {
			eval(handle+'["'+'D'+'"]'+stylevar+'.visibility = "visible"');
		}
		if (origerror) {
			eval(handle+'["'+'OERROR'+'"]'+stylevar+'.visibility = "visible"');
			eval(handle+'["'+'SUB'+'"]'+stylevar+'.visibility = "hidden"');
		}
		if (desterror) {
			eval(handle+'["'+'DERROR'+'"]'+stylevar+'.visibility = "visible"');
			eval(handle+'["'+'SUB'+'"]'+stylevar+'.visibility = "hidden"');
		}
		if (origerror || desterror){
			eval(handle+'["'+'TryAgainButton'+'"]'+stylevar+'.visibility = "visible"');
		}
	}
	if (isNS6){
		eval(handle+"('O')"+stylevar+'.visibility = "hidden"');
		eval(handle+"('D')"+stylevar+'.visibility = "hidden"');
		eval(handle+"('OERROR')"+stylevar+'.visibility = "hidden"');
		eval(handle+"('DERROR')"+stylevar+'.visibility = "hidden"');
		if (doorig) {
			eval(handle+"('O')"+stylevar+'.visibility = "visible"');
		}
		if (dodest) {
			eval(handle+"('D')"+stylevar+'.visibility = "visible"');
		}
		if (origerror) {
			eval(handle+"('OERROR')"+stylevar+'.visibility = "visible"');
			eval(handle+"('SUB')"+stylevar+'.visibility = "hidden"');
		}
		if (desterror) {
			eval(handle+"('DERROR')"+stylevar+'.visibility = "visible"');
			eval(handle+"('SUB')"+stylevar+'.visibility = "hidden"');
		}
		if (origerror || desterror){
			eval(handle+"('TryAgainButton')"+stylevar+'.visibility = "visible"');		
		}
	}
}
function TECCsetOrigFields() {
	var sel = document.form0.origterm.selectedIndex;
	document.form0.origcity.selectedIndex = sel;
	document.form0.origst.selectedIndex = sel;
	document.form0.origtype.selectedIndex = sel;
}

function TECCsetDestFields() {
     	var sel = document.form0.destterm.selectedIndex;
     	document.form0.destcity.selectedIndex = sel;
	document.form0.destst.selectedIndex = sel;
	document.form0.desttype.selectedIndex = sel;
}
function TEHomeSelect(){
	isNS4 = (document.layers) ? true : false;
	isIE4 = (document.all && !document.getElementById) ? true : false;
	isIE5 = (document.all && document.getElementById) ? true : false;
	isNS6 = (!document.all && document.getElementById) ? true : false;
	if (isNS4){handle = "document.layers"; stylevar=""}
	if (isIE4 || isIE5){handle = "document.all"; stylevar=".style"}
	if (isNS6){handle = "document.getElementById";stylevar=".style"}

	if (isIE4 || isIE5 || isNS4){
		if (showstd == "Y") {
			eval(handle+'["'+'ServiceStandard'+'"]'+stylevar+'.visibility = "visible"');				
			eval(handle+'["'+'ServiceStandardADate'+'"]'+stylevar+'.visibility = "visible"');								
			eval(handle+'["'+'ServiceStandardADateLabel'+'"]'+stylevar+'.visibility = "visible"');												
			if (holiday != "0") {
				eval(handle+'["'+'HolidayMsg'+'"]'+stylevar+'.visibility = "visible"');
				eval(handle+'["'+'HolidayMsgBalance'+'"]'+stylevar+'.visibility = "visible"');				
			} else {
				eval(handle+'["'+'HolidayMsg'+'"]'+stylevar+'.visibility = "hidden"');
				eval(handle+'["'+'HolidayMsgBalance'+'"]'+stylevar+'.visibility = "hidden"');				
			}				
		} else {
			eval(handle+'["'+'ServiceStandard'+'"]'+stylevar+'.visibility = "hidden"');				
			eval(handle+'["'+'ServiceStandardADate'+'"]'+stylevar+'.visibility = "hidden"');											
			eval(handle+'["'+'ServiceStandardADateLabel'+'"]'+stylevar+'.visibility = "hidden"');															
			eval(handle+'["'+'HolidayMsg'+'"]'+stylevar+'.visibility = "hidden"');
			eval(handle+'["'+'HolidayMsgBalance'+'"]'+stylevar+'.visibility = "hidden"');								
		}
		if (showast == "Y") {
			eval(handle+'["'+'ServiceStandardAst'+'"]'+stylevar+'.visibility = "visible"');			
		} else {
			eval(handle+'["'+'ServiceStandardAst'+'"]'+stylevar+'.visibility = "hidden"');			
		}
		if (showmsg == "Y") {
			eval(handle+'["'+'Message'+'"]'+stylevar+'.visibility = "visible"');			
		} else {
			eval(handle+'["'+'Message'+'"]'+stylevar+'.visibility = "hidden"');						
		}
	}
	if (isNS6){
		if (showstd == "Y") {
			eval(handle+"('ServiceStandardNS')"+stylevar+'.visibility = "visible"');
			eval(handle+"('ServiceStandardADate')"+stylevar+'.visibility = "visible"');
			eval(handle+"('ServiceStandardADateLabel')"+stylevar+'.visibility = "visible"');				
			if (holiday != "0") {
				eval(handle+"('HolidayMsg')"+stylevar+'.visibility = "visible"');
				eval(handle+"('HolidayMsgBalance')"+stylevar+'.visibility = "visible"');				
			} else {
				eval(handle+"('HolidayMsg')"+stylevar+'.visibility = "hidden"');
				eval(handle+"('HolidayMsgBalance')"+stylevar+'.visibility = "hidden"');				
			}				
		} else {
			eval(handle+"('ServiceStandardNS')"+stylevar+'.visibility = "hidden"');
			eval(handle+"('ServiceStandardADate')"+stylevar+'.visibility = "hidden"');
			eval(handle+"('ServiceStandardADateLabel')"+stylevar+'.visibility = "hidden"');				
			eval(handle+"('HolidayMsg')"+stylevar+'.visibility = "hidden"');
			eval(handle+"('HolidayMsgBalance')"+stylevar+'.visibility = "hidden"');								
		}
		if (showast == "Y") {
			eval(handle+"('ServiceStandardAstNS')"+stylevar+'.visibility = "visible"');
		} else {
			eval(handle+"('ServiceStandardAstNS')"+stylevar+'.visibility = "hidden"');
		}
		if (showmsg == "Y") {
			eval(handle+"('MessageNS')"+stylevar+'.visibility = "visible"');
		} else {
			eval(handle+"('MessageNS')"+stylevar+'.visibility = "hidden"');
		}		
	}
}
function TEprintIt(){
	isNS4 = (document.layers) ? true : false;
	isIE4 = (document.all && !document.getElementById) ? true : false;
	isIE5 = (document.all && document.getElementById) ? true : false;
	isNS6 = (!document.all && document.getElementById) ? true : false;
	if (isNS4){handle = "document.layers"; stylevar=""}
	if (isIE4 || isIE5){handle = "document.all"; stylevar=".style"}
	if (isNS6){handle = "document.getElementById";stylevar=".style"}

	if (isIE4 || isIE5 || isNS4){
		eval(handle+'["'+'Banner'+'"]'+stylevar+'.visibility = "hidden"');
		eval(handle+'["'+'PrintBanner'+'"]'+stylevar+'.visibility = "visible"');
	}	
	if (isNS6){
		eval(handle+"('Banner')"+stylevar+'.visibility = "hidden"');
		eval(handle+"('PrintBanner')"+stylevar+'.visibility = "visible"');
	}
	print()
	if (isIE4 || isIE5 || isNS4){
		eval(handle+'["'+'PrintBanner'+'"]'+stylevar+'.visibility = "hidden"');
		eval(handle+'["'+'Banner'+'"]'+stylevar+'.visibility = "visible"');
	}	
	if (isNS6){
		eval(handle+"('PrintBanner')"+stylevar+'.visibility = "hidden"');
		eval(handle+"('Banner')"+stylevar+'.visibility = "visible"');
	}
}
function TEZFhideShow(){
	document.form0.city.selectedIndex = 0;
	document.form0.st.selectedIndex = 0;
	isNS4 = (document.layers) ? true : false;
	isIE4 = (document.all && !document.getElementById) ? true : false;
	isIE5 = (document.all && document.getElementById) ? true : false;
	isNS6 = (!document.all && document.getElementById) ? true : false;
	if (isNS4){handle = "document.layers"; stylevar=""}
	if (isIE4 || isIE5){handle = "document.all"; stylevar=".style"}
	if (isNS6){handle = "document.getElementById";stylevar=".style"}
	if (document.forms[0].city.options.length == 1){
		if (isIE4 || isIE5 || isNS4){
			eval(handle+'["'+'IfNone'+'"]'+stylevar+'.visibility = "visible"');
			eval(handle+'["'+'Z'+'"]'+stylevar+'.visibility = "hidden"');
			eval(handle+'["'+'ZC'+'"]'+stylevar+'.visibility = "hidden"');
			eval(handle+'["'+'ContinueButtons'+'"]'+stylevar+'.visibility = "hidden"');
			eval(handle+'["'+'TryAgainButton'+'"]'+stylevar+'.visibility = "visible"');
		}
		if (isNS6){
			eval(handle+"('TryAgainButton')"+stylevar+'.visibility = "visible"');
			eval(handle+"('ContinueButtons')"+stylevar+'.visibility = "hidden"');
			eval(handle+"('Z')"+stylevar+'.visibility = "hidden"');
			eval(handle+"('ZC')"+stylevar+'.visibility = "hidden"');
			eval(handle+"('IfNone')"+stylevar+'.visibility = "visible"');		
		}
	}

}
function TEZFsetFields() {
     	var sel = document.form0.zip.selectedIndex;
     	document.form0.city.selectedIndex = sel;
	document.form0.st.selectedIndex = sel;
}
function TEZFpushOriginFields(){
     	var selCity = document.form0.city.options[document.form0.city.selectedIndex].value;
     	var selState = document.form0.st.options[document.form0.st.selectedIndex].value;
     	var tmpZip = document.form0.zip.options[document.form0.city.selectedIndex].value;
     	var selZip = replaceString(" ","",tmpZip)
     	var andPos = opener.location.href.indexOf("&");
     	var CRIPos = opener.location.href.indexOf("CRIStart.jsp");
     	var RIPos = opener.location.href.indexOf("RateInquiry.html");
     	var BOLPos = opener.location.href.indexOf("BillOfLading");
     	//alert("andPos=" + andPos + ", opener.location.href=" + opener.location.href);
     	if(CRIPos != -1){
     		opener.document.forms["CustomerRateInquiry"].CRIOriginZip_1.value = selZip
     		opener.document.forms["CustomerRateInquiry"].CRIOriginCity_1.value = selCity;
     		opener.document.forms["CustomerRateInquiry"].CRIOriginState_1.value = selState;     	
     	} else if(RIPos != -1){
     		opener.document.forms["RateInquiry"].OriginZip_1.value = selZip
     		opener.document.forms["RateInquiry"].OriginCity_1.value = selCity;
     		opener.document.forms["RateInquiry"].OriginState_1.value = selState;
     	} else if (BOLPos != -1) {
     	     	opener.document.forms["BillOfLading"].zipluzip.value = selZip
	     	opener.document.forms["BillOfLading"].ziplucity.value = selCity;
     		opener.document.forms["BillOfLading"].ziplustate.value = selState;
     		opener.BOLfinishZipLU();
     	} else {
     		opener.document.forms["TransitTime"].OriginZip.value = selZip;
     		opener.document.forms["TransitTime"].PreviousOrigZip.value = selZip;
     		opener.document.forms["TransitTime"].OriginCity.value = selCity;
     		opener.document.forms["TransitTime"].OriginState.value = selState;
     	}
     	window.close()
}
function TEZFpushDestinationFields(){
        var selCity = document.form0.city.options[document.form0.city.selectedIndex].value;
        var selState = document.form0.st.options[document.form0.st.selectedIndex].value;
        var tmpZip = document.form0.zip.options[document.form0.city.selectedIndex].value;
     	var selZip = replaceString(" ","",tmpZip)
     	var andPos = opener.location.href.indexOf("&");
     	var CRIPos = opener.location.href.indexOf("CRIStart.jsp");
     	var RIPos = opener.location.href.indexOf("RateInquiry.html");
     	var BOLPos = opener.location.href.indexOf("BillOfLading");
     	//alert("andPos=" + andPos + ", opener.location.href=" + opener.location.href);
     	if(CRIPos != -1){
     		opener.document.forms["CustomerRateInquiry"].CRIDestinationZip_1.value = selZip
     		opener.document.forms["CustomerRateInquiry"].CRIDestinationCity_1.value = selCity;
     		opener.document.forms["CustomerRateInquiry"].CRIDestinationState_1.value = selState;     	
     	} else if(RIPos != -1){
     		opener.document.forms["RateInquiry"].DestinationZip_1.value = selZip
     		opener.document.forms["RateInquiry"].DestinationCity_1.value = selCity;
     		opener.document.forms["RateInquiry"].DestinationState_1.value = selState;
     	} else if (BOLPos != -1) {
     	     	opener.document.forms["BillOfLading"].zipluzip.value = selZip
	     	opener.document.forms["BillOfLading"].ziplucity.value = selCity;
     		opener.document.forms["BillOfLading"].ziplustate.value = selState;     		
     		opener.BOLfinishZipLU();
     	} else {
     		opener.document.forms["TransitTime"].DestinationZip.value = selZip;
     		opener.document.forms["TransitTime"].PreviousDestZip.value = selZip;
     		opener.document.forms["TransitTime"].DestinationCity.value = selCity;
     		opener.document.forms["TransitTime"].DestinationState.value = selState;
     	}   
        window.close();
}
function TEZreturn() {
        var selCity = document.form0.city.options[document.form0.city.selectedIndex].value;
        var selState = document.form0.st.options[document.form0.st.selectedIndex].value;
        var tmpZip = document.form0.zip.options[document.form0.city.selectedIndex].value;
     	var selZip = replaceString(" ","",tmpZip)
	opener.ZIPreturnValues(selCity, selState, selZip);
	window.close();
}
function TEZLshowWait(){
	eval('document.all'+'["'+'Hit'+'"].style.visibility = "visible"');
}
function TEZinitForm() {
	document.forms['ZipToZip'].City.value = getSearchParam(window.location.search, 'city=');
	var ts = getSearchParam(window.location.search, 'state=');
	for (var i = 0; i < document.forms['ZipToZip'].State.options.length; i++) {
		if (ts == document.forms['ZipToZip'].State.options[i].value) {
			document.forms['ZipToZip'].State.selectedIndex = i;
			break;
		}
	}
}
function TEcheckOrigZip(){
	if (window.document.forms[0].PreviousOrigZip.value != "" && window.document.forms[0].PreviousOrigZip.value != window.document.forms[0].OriginZip.value){
		window.document.forms[0].PreviousOrigZip.value = "";
		window.document.forms[0].OriginCity.value = "";
		window.document.forms[0].OriginState.value = ""
	}
}
function TEcheckDestZip(){
	if (window.document.forms[0].PreviousDestZip.value != "" && window.document.forms[0].PreviousDestZip.value != window.document.forms[0].DestinationZip.value){
		window.document.forms[0].PreviousDestZip.value = "";
		window.document.forms[0].DestinationCity.value = "";
		window.document.forms[0].DestinationState.value = ""
	}
}
function TEgenDefaultShipDate(){
	addCalendar("CalendarTE", "Select Date", "Shipdate", "TransitTime");
	document.forms[0].Shipdate.value=getCurrentDate();
}
function TEValidate() {
	TEcheckOrigZip();
	TEcheckDestZip();
	var sd = document.forms[0].Shipdate.value;
	var we = checkIfWeekend(sd);
	if (we == 'Y') {
		alert('Choose a weekday for a Pickup Date.');
	} else {
		document.forms['TransitTime'].Shipdate.value = sd.substring(sd.length - 10, sd.length);
		
				//check that the shipdate is not less than today or more than 30 days out.
		var dateString = document.forms['TransitTime'].Shipdate.value;
		var mm = parseInt(dateString.substring(0,2),10) - 1;
		var dd = parseInt(dateString.substring(3,5),10);
		var yyyy = parseInt(dateString.substring(6),10);
		var today = new Date();
		var shipDate = new Date();
		shipDate.setDate(dd);
		shipDate.setMonth(mm);
	 	shipDate.setFullYear(yyyy);
	 	shipDate.setHours(today.getHours());
	 	shipDate.setMinutes(today.getMinutes());
	 	shipDate.setSeconds(today.getSeconds());
	 	shipDate.setMilliseconds(today.getMilliseconds());
	 	
	 	var ONE_DAY = 1000 * 60 * 60 * 24;
	 	var todayTime = today.getTime();
	 	var shipTime = shipDate.getTime();
	 	var timeMills = shipTime - todayTime;
	 	var days = Math.round(timeMills/ONE_DAY);
	 	
	 	if (days < 0) {
	 		alert('Please enter a date of today or greater.');
	 		return false;
	 	} else if (days > 30) {
	 		alert('Please enter a date less than 30 days from today.');
	 		return false;
	 	}
		document.forms['TransitTime'].submit();
	}
}
function TEParseInput() {
	var qs = window.location.search;
	var dpos = qs.indexOf("SD=");
	var opos = qs.indexOf("SO=");
	var apos = -1;
	if (dpos >= 0) {
		apos = qs.indexOf("&",dpos + 3);	
		if (apos >= 0) {
			document.forms['TransitTime'].DestinationZip.value = qs.substring(dpos + 3, apos);
		} else {
			document.forms['TransitTime'].DestinationZip.value = qs.substring(dpos + 3, qs.length);
		}
	}
	if (opos >= 0) {
		apos = qs.indexOf("&",opos + 3);	
		if (apos >= 0) {
			document.forms['TransitTime'].OriginZip.value = qs.substring(opos + 3, apos);
		} else {
			document.forms['TransitTime'].OriginZip.value = qs.substring(opos + 3, qs.length);
		}
	}
	
}
function TEfinishZipLU() {
	eval('document.forms[\"TransitTime\"].' + zipzipfieldname + '.value = \"' + zipzipvalue + '\"');
	eval('document.forms[\"TransitTime\"].' + zipcityfieldname + '.value = \"' + zipcityvalue + '\"');
	eval('document.forms[\"TransitTime\"].' + zipstatefieldname + '.value = \"' + zipstatevalue + '\"');
	if (zipzipfieldname == "DestinationZip") {
		document.forms["TransitTime"].PreviousDestZip.value = zipzipvalue;
	} else {
		document.forms["TransitTime"].PreviousOrigZip.value = zipzipvalue;
	}
}

function PKfinishZipLU() {
	eval('document.forms[\"PickupRequest\"].' + zipzipfieldname + '.value = \"' + zipzipvalue + '\"');
	eval('document.forms[\"PickupRequest\"].' + zipcityfieldname + '.value = \"' + zipcityvalue + '\"');
	eval('document.forms[\"PickupRequest\"].' + zipstatefieldname + '.value = \"' + zipstatevalue + '\"');
	if (zipzipfieldname == "detaildestzip") {
		document.forms["PickupRequest"].PreviousDestZip.value = zipzipvalue;
	} else {
		document.forms["PickupRequest"].PreviousOrigZip.value = zipzipvalue;
	}
}

function PKfinishZipLU1(index) {
        //alert("index=" + index);
        //alert(eval('document.forms[1].detaildestzip[' + index + '].value') );
	eval('document.forms[\"PickupRequest\"].detaildestzip[' + index + '].value = \"' + zipzipvalue + '\"');
}

function printIt(){
	print();
}

