	// This stops backspace unless you're typing in a text element
	document.onkeydown = function(e) {handleKeys(e)}
	document.onkeypress = function(e) {handleKeys(e)}
	function handleKeys(e) {
	    var evt = (e) ? e : window.event;
	    var target = evt.target ? evt.target : evt.srcElement;
	    if (evt.keyCode == 8 && target.type != "text" && target.type != "textarea" && target.type != "password"){
	       if(window.event) {
	         evt.returnValue = false; 
	       }
	        else { 
	         evt.preventDefault();
	       }
	    }   
	}
	function selectCompany() {
		if (isEmpty(getSelectedValue('companyCode'))) {
			setInnerHTML("errors", "** Select a Company for this session.");
			return;
		}
		submitForm('selectcompany');
	}
	function cursorWait() {
		document.body.style.cursor = "wait";
	}
	function cursorDefault() {
		document.body.style.cursor = "default";
	}
	function setValue(elementId, value){
		var el = document.getElementById(elementId);
		if (el) {
	  		el.value = value;
		}
	}
	function getValue(elementId){
		var el = document.getElementById(elementId);
		if (el) {
		  return el.value;
		}
		return null;
	}
	function getSelectedRadioValue(radioId) {
		var radioEl = document.getElementsByName(radioId);
		for (var i = 0; i< radioEl.length; i++) {
		    if (radioEl[i].checked) 
		    	return radioEl[i].value;
		}
		return null;
	}
	function setSelectedRadioValue(radioId, value) {
		var radioEl = document.getElementsByName(radioId);
		for (var i = 0; i< radioEl.length; i++) {
		    if (radioEl[i].value == value) 
		    	radioEl[i].checked = true;
		        return;
		}
	}
	function setInnerHTML(elementId, value){
		var el = document.getElementById(elementId);
		if (el) {
	  		el.innerHTML = value;
		}
	}
	function getInnerHTML(elementId){
		var el = document.getElementById(elementId);
		if (el) {
	  		return el.innerHTML;
		}
		return null;
	}
	function appendInnerHTML(elementId, value){
		var el = document.getElementById(elementId);
		if (el) {
			var innerHtml = el.innerHTML;
	  		el.innerHTML = innerHtml + value;
		}
	}
	function showField(elementId){
	   	var el = document.getElementById(elementId);
	   	//alert("Element Id is " + elementId + " el is " + el);
		if (el) {
	  		el.style.display = '';
		}
	}
	function hideField(elementId){
	   	var el = document.getElementById(elementId);
		if (el) {
	  		el.style.display = 'none';
		}
	}
	function showElement(el){
		//alert ("show El ");
		if (el) {
	  		el.style.display = '';
		}
	}
	function hideElement(el){
		//alert ("hide El ");
		if (el) {
	  		el.style.display = 'none';
		}
	}
	function upCase(el) {
	  if (el) {
	  	setValue(el.id, el.value.toUpperCase());
	  }
	}
	
	function disableField(elementId){
	   	var el = document.getElementById(elementId);
		if (el) {
	  		el.disabled = true;
		}
	}
	function enableField(elementId){
	   	var el = document.getElementById(elementId);
		if (el) {
	  		el.disabled = false;
		}
	}
	function clearSellInfo() {
		var lCode = getValue("locCode");
		setValue('actualTerminal',lCode);
		setValue('actualThirdParty','');
		setValue('sellingPrice',0.0);
		setValue('sellToPrice',0.0);
		setValue('actTerminal','');
		hideField('actTermDescRow');
  		setInnerHTML('actTermDesc','');
		setValue('actThirdParty','');
		hideField('actThirdPartyCityRow');
		setInnerHTML('actThirdPartyCity','');
		hideField('actThirdPartyDescRow');
		setInnerHTML('actThirdPartyDesc','');
		setValue('sellingTerminal','');
  		hideField('actualTermDescRow');
  		setInnerHTML('actualTermDesc','');
		setValue('actualThirdParty','');
		hideField('actualThirdPartyCityRow');
		setInnerHTML('actualThirdPartyCity','');
		hideField('actualThirdPartyDescRow');
		setInnerHTML('actualThirdPartyDesc','');
		hideSellLoadDiv();
	}
	function cancelSellInfo() {
		setValue('sellToPrice',0.0);
		setValue('actTerminal','');
		hideField('actTermDescRow');
  		setInnerHTML('actTermDesc','');
		setValue('actThirdParty','');
		hideField('actThirdPartyCityRow');
		setInnerHTML('actThirdPartyCity','');
		hideField('actThirdPartyDescRow');
		setInnerHTML('actThirdPartyDesc','');
		setValue('sellingTerminal','');
 		hideSellLoadDiv();
	}
	function sellLoad() {
		var term = getValue("actTerminal");
		var thrd = getValue("actThirdParty");
		var locCode = getValue('locCode');
		var sellToPrice = getValue("sellToPrice");
		if (term != null && term != "") {
			if (sellToPrice != null && sellToPrice > 0.00) {
		  		setValue('sellingPrice',sellToPrice);
			  	setValue('actualTerminal',term);
			  	showField('actualTermDescRow');
			  	setInnerHTML('actualTermDesc',getInnerHTML('actTermDesc'));
		  		setValue('actualThirdParty','');
		  		hideField('actualThirdPartyCityRow');
		  		setInnerHTML('actualThirdPartyCity','');
		  		hideField('actualThirdPartyDescRow');
		  		setInnerHTML('actualThirdPartyDesc','');
		  		setValue('sellingTerminal',locCode);
	  			showField("lookupTruckButtonCell");
	  			showField("lookupDriverButtonCell");
		  		hideSellLoadDiv();		  
		  	} else {
		  		alert('The selling price must be greater than $0.00');
		  	}
		} else {
			if (thrd != null && thrd != "") {
				if (sellToPrice != null && sellToPrice > 0.00) {
			  		setValue('sellingPrice',sellToPrice);
					setValue('actualTerminal','');
			  		hideField('actualTermDescRow');
			  		setInnerHTML('actualTermDesc','');
		  			setValue('actualThirdParty',thrd);
		  			showField('actualThirdPartyCityRow');
		  			setInnerHTML('actualThirdPartyCity',getInnerHTML('actThirdPartyCity'));
		  			showField('actualThirdPartyDescRow');
		  			setInnerHTML('actualThirdPartyDesc',getInnerHTML('actThirdPartyDesc'));
		  			setValue("truckNumber", "999999");
		  			setValue("driverNumber","999");
		  			hideField("driverNameRow");
		  			setInnerHTML("driverName", "");
		  			hideField("lookupTruckButtonCell");
		  			hideField("lookupDriverButtonCell");
					hideSellLoadDiv();
		  			setValue('sellingTerminal',locCode);
					enableButton('sellToButton','images/sellTo.gif','javascript:showSellLoadDiv("sellLoadAnchor");');
				} else {
			  		alert('The selling price must be greater than $0.00');				
				}
			}
		}
	}
	function hideLoadDetailRows(tableId) {
		var tableEl = document.getElementById(tableId);
		for (var i = 0; i < tableEl.rows.length; i++) {
			if (tableEl.rows[i].id.indexOf("detail") != -1) {
				tableEl.rows[i].style.display = 'none';
			}
		}
	}	
	function showSellLoadDiv(anchorId){
		var anchorEl = document.getElementById(anchorId);
		var sellLoadDiv = document.getElementById('sellLoadDiv');
		//var sellingTerm = getValue('sellingTerminal');
		//var sellToPrice = getValue('sellingPrice');
		//var haulingTerm = getValue('actualTerminal');
		//var actThird = getValue('actualThirdParty');
		sellLoadDiv.style.left = getLeft(anchorEl) - 50 + 'px';
		sellLoadDiv.style.top = getTop(anchorEl) - 50 + 'px';
		/*if (!isEmpty(sellingTerm)) {
			setValue('sellToPrice',sellToPrice);
			if (isEmpty(haulingTerm)) {
				if (!isEmpty(actThird)) {
					setValue('actThirdParty',actThird);
				} 
			} else {
				if (!isEmpty(sellingTerm) && sellingTerm != haulingTerm) {
					setValue('actTerminal',haulingTerm);
				}
			}
		} else {
			setValue('actTerminal','');
		}*/
		sellLoadDiv.style.display = '';
	}
	function hideSellLoadDiv() {
		var div = document.getElementById("sellLoadDiv");
		div.style.display = 'none';
    }
    function closeAssignWindow() {
	    submitForm('cancelAssign','/LTMSLite/mainView');
	}
	function showLocationDiv(anchorId, returnView, locNumId, addEditLoc){
		resetLocationMaintenanceForm();
		var anchorEl = document.getElementById(anchorId);
		setValue("addLocAnchor",anchorId);
		var addLocDiv = document.getElementById("addEditLocDiv");
		var newLocNum = getValue(locNumId);
		addLocDiv.style.left = (getLeft(anchorEl)) + "px";
		addLocDiv.style.top = getTop(anchorEl) + "px";
		addLocDiv.style.display = "";
		setValue("locationNumber",newLocNum);
		setValue("addLocReturnField",locNumId);	
		if (addEditLoc == "addLocation") {
		  setInnerHTML("title", "Add New Location");
		  document.getElementById('isDummy').checked=false;
		  showField('dummyRow');
		  showField('locationNumRow'); 
		  showField("addLocButtonRow");
		  hideField("editLocButton");	
		  hideField("findExistingLoc");	
		} else {
		  setInnerHTML("title", "Edit Existing Location");
		  setValue("locationNumber","");
		  showField('locationNumRow'); 
		  showField("editLocButton");
		  hideField("addLocButtonRow");
		  showField("findExistingLoc");	
  		  setValue("returnView", "mainView");
  		  document.getElementById('isDummy').checked=false;
  		  hideField('dummyRow');
		}
	}
	function checkUncheckDummyLoc(checkbox) {
		if (checkbox.checked) { 
			hideField('locationNumRow'); 
			setValue('locationNumber','');
		} else {
			showField('locationNumRow');
		}
	}
	function addLocation(){
		var isDummy = document.getElementById('isDummy').checked ? "Y" : "N";
		var locationCode = getValue("locationNumber");
		var locationName = getValue("locationName");
		var locationAddress1 = getValue("locationAddress1");
		var locationAddress2 = getValue("locationAddress2");
		var locationCityName = getValue("locationCityName");
		var locationState = getValue("locationState");
		var locationZipCode = getValue("locationZipCode");
		var locationDirections = getValue("locationDirections");
        var url = "/LTMSLite/locationMaint?method=addLocation&locationNumber=" + escape(locationCode) + "&locationName=" + escape(locationName) + "&locationAddress1=" + escape(locationAddress1) + "&locationAddress2=" + escape(locationAddress2) + "&locationCityName=" +escape(locationCityName) + "&locationState=" + escape(locationState) + "&locationZipCode=" + escape(locationZipCode) + "&locationDirections=" + escape(locationDirections) + "&addLocReturnField=" + escape(getValue("addLocReturnField")) + "&dummy=" + escape(isDummy);
        sendAjaxRequest(url);
	}
	function updateLocation(){
		var locationCode = getValue("locationNumber");
		var locationName = getValue("locationName");
		var locationAddress1 = getValue("locationAddress1");
		var locationAddress2 = getValue("locationAddress2");
		var locationCityName = getValue("locationCityName");
		var locationState = getValue("locationState");
		var locationZipCode = getValue("locationZipCode");
		var locationDirections = getValue("locationDirections");
        var url = "/LTMSLite/locationMaint?method=updateLocation&locationNumber=" + escape(locationCode) + "&locationName=" + escape(locationName) + "&locationAddress1=" + escape(locationAddress1) + "&locationAddress2=" + escape(locationAddress2) + "&locationCityName=" +escape(locationCityName) + "&locationState=" + escape(locationState) + "&locationZipCode=" + escape(locationZipCode) + "&locationDirections=" + escape(locationDirections) + "&addLocReturnField=" + escape(getValue("addLocReturnField"));
        sendAjaxRequest(url);
	}
	function findLocation(){
	  	var locCode = getValue("locationNumber");
        var url = "/LTMSLite/locationMaint?method=findSelectedLocation&locCode=" + escape(locCode);
        sendAjaxRequest(url);
	}
	function findLocationByNameCity(){
	  	var name = getValue("locationName");
	  	var city = getValue("locationCity");
        var url = "/LTMSLite/locationMaint?method=searchLocations&name=" + escape(name) + "&city=" + escape(city);
        sendAjaxRequest(url);
	}
	function findTruckForSupport(){
	  	var trkNumber = getValue("truckNumber");
	  	hideField('driverInfo');
        var url = "/LTMSLite/ltmsSupport?method=FindTruck&truckNumber=" + escape(trkNumber);
        sendAjaxRequest(url);
	}
	function findDriverForSupport(){
	  	var drvrNumber = getValue("driverNumber");
	  	hideField('truckInfo');
        var url = "/LTMSLite/ltmsSupport?method=FindDriver&driverNumber=" + escape(drvrNumber);
        sendAjaxRequest(url);
	}

	function getLeft(el) {
    	var oNode = el;
    	var iLeft = 0;
    	while(oNode.tagName != "BODY" && oNode.tagName != "HTML") {
        	iLeft += oNode.offsetLeft;
        	oNode = oNode.offsetParent;        
    	}
    	return iLeft;
	}

	function hideAddLocDiv(addEdit) {
		var div = document.getElementById("addEditLocDiv");
		div.style.display = 'none';
		resetLocationMaintenanceForm(addEdit);
    }
	function resetLocationMaintenanceForm() {
		setValue("locationNumber", "");
		setValue("locationName", "");
		setValue("locationAddress1", "");
		setValue("locationAddress2", "");
		setValue("locationCityName", "");
		setValue("locationState", "");
		setValue("locationZipCode", "");	
		setValue("locationDirections", "");
		setInnerHTML('locationError',"");
		hideField('locationCityRow');
		changeImage(document.getElementById("addLocButton"),'images/addLocation.gif');
		changeImage(document.getElementById("cancelLocAddButton"),'images/cancelAdd.gif');
		changeImage(document.getElementById("updateLocButton"),'images/saveChanges.gif');
		changeImage(document.getElementById("cancelEditLocButton"),'images/cancelChanges.gif');
		clearAddLocationErrors();
	}
    function clearAddLocationErrors() {
	    setInnerHTML('locationError','');
    	setInnerHTML('locationNumError','');
    	setInnerHTML('locationNameError','');
    	setInnerHTML('locationAddr1Error','');
    	setInnerHTML('locationCityError','');
    	setInnerHTML('locationStateError','');    	    	    	
    }
    function showHideLocationCityField(selectEl) {
		var selectedValue = getSelectedValue(selectEl.id);
		if (isEmpty(selectedValue)) {
			setValue("locationCityName", "");
			hideField("locationCityRow");
		} else {
			showField("locationCityRow");
		}
	}
	
	function validateCity() {
		var locationCityName = getValue("locationCityName");
		var locationState = getSelectedValue("locationState");
		if (isEmpty(locationState)) {
			alert("Select a state");
			return;
		}
	    if (!locationCityName || locationCityName.length < 3) {
	      alert("City Name must be at least 3 characters.");
	      changeImage('lookupCityButton','images/lookupCity.gif');
	      return;
	    }
	    var url = "/LTMSLite/locationMaint?method=validateCity&locationCityName=" + escape(locationCityName) + "&locationState=" + escape(locationState);
        sendAjaxRequest(url);
	}
	function getTop(el) {
	    var oNode = el;
    	var iTop = 0; 
    	while(oNode.tagName != "BODY" && oNode.tagName != "HTML") {
        	iTop += oNode.offsetTop;
        	oNode = oNode.offsetParent;
    	}
    	return iTop;
	}
	function selectFilterItem(optionValue,userInput,userInput2) {
		setSelectedValue("field", optionValue);
		setValue("userInput",userInput);
	    setValue("userInput2", userInput2);
	    showField("updateButton");
	    hideField("addButton");
		setFilterFields(document.getElementById("field"),true);
	}
	function setFilterFields(selectEl,isEdit){
  		var selectedValue = getSelectedValue(selectEl.id);
  		if (isEmpty(selectedValue)) {
    		hideField("dateButton");
    		hideField("dateButton2");
    		hideField("userInput2Span");
    		hideField("dateInstr2");
    		hideField("dateInstr");
    		hideField("timeInstr");
    		hideField("booleanInstr");
    		hideField("blankRow");
    		checkUncheckCheckBox("blankValue", false);
    		setValue('userInput','');
    		setValue('userInput2','');
     		document.getElementById('userInput').onchange = function(){void(0);};
  		}
  		else {
  		  	var fieldType = selectedValue.substring(selectedValue.indexOf("_") + 1, selectedValue.lastIndexOf("_"));
  		  	var maxLengthStr = selectedValue.substring(selectedValue.lastIndexOf("_") + 1);
  		  	document.getElementById('userInput').maxLength = parseInt(maxLengthStr);
  			if ("D" == fieldType) {
  			    if (!isEdit) {
  			    	setValue("userInput", getValue("defaultFromDate"));
  			    	setValue("userInput2", getValue("defaultToDate"));
  			    }
    			showField("dateButton");
    			showField("dateButton2");
    			showField("userInput2Span");
    			showField("dateInstr2");
    			showField("dateInstr");
    			hideField("blankRow");
    			checkUncheckCheckBox("blankValue", false);
    			setInnerHTML("valueLabel","From<br/>To");
    			hideField("timeInstr");
    			hideField("booleanInstr");
     			document.getElementById('userInput').onchange = function(){void(0);};
 			} else if ("B" == fieldType) {
    			hideField("dateButton");
    			hideField("dateInstr");
    			hideField("dateButton2");
    			hideField("userInput2Span");
    			hideField("dateInstr2");
    			hideField("timeInstr");
    			showField("blankRow");
    			checkUncheckCheckBox("blankValue", false);
    			setInnerHTML("valueLabel","Value");
    			showField("booleanInstr");
    			setValue('userInput','');
    		    setValue('userInput2','');
    			document.getElementById('userInput').onchange = function(){void(0);};
    		} else if ("T" == fieldType) {
    			hideField("dateButton");
    			hideField("dateInstr");
    			hideField("dateButton2");
    			hideField("userInput2Span");
     			setInnerHTML("valueLabel","Value");
    			hideField("dateInstr2");
    			showField("timeInstr");
     			checkUncheckCheckBox("blankValue", false);
    			showField("blankRow");
    			hideField("booleanInstr");
    			setValue('userInput','');
    		    setValue('userInput2','');
    			document.getElementById('userInput').onchange = function(){insertColon(this);};
    		} else {
 	   			hideField("dateButton");
    			hideField("dateInstr");
    			hideField("dateButton2");
    			hideField("userInput2Span");
    			setInnerHTML("valueLabel","Value");
     			checkUncheckCheckBox("blankValue", false);
    			showField("blankRow");
       			hideField("dateInstr2");
    			hideField("timeInstr");
    			hideField("booleanInstr");
    			setValue('userInput','');
    		    setValue('userInput2','');
    			document.getElementById('userInput').onchange = function(){void(0);};
    		}
  		}
	}
	function showDateEntered() {
		setSelectedValue('field','a.dateentered_D_10');
		setFilterFields(document.getElementById('field'),false);
	}
	function viewFilteredList(method,ltmsLoadView, filtered, dateRangeSet) {
	  if (filtered && ltmsLoadView && !dateRangeSet) {
		setInnerHTML('inputError','** At least one date field must be selected.<br/>** Please enter a range for Date Entered or choose another date range field.');
		showDateEntered();
		changeImage(document.getElementById('filterButton'),'images/viewListResults.gif');
	  } else {
		submitForm(method, "/LTMSLite/mainView?refresh=true");
	  }
	}
	function getSelectedValue(elementId){
		var el = document.getElementById(elementId);
		if (el) {
	 		return el.options[el.selectedIndex].value;
		}
		return null;
	}
	function setSelectedValue(elementId,value){
		var el = document.getElementById(elementId);
		if (el) {
			for (var i = 0;i < el.length;i++){
			 	if (el.options[i].value == value){
			    	el.options[i].selected = true;
	 				return;
	 			}
			}
		}
	}
	function setSelectedIndex(elementId,index){
		var el = document.getElementById(elementId);
		if (el) {
			el.selectedIndex = index;
		}
	}
	function setSelectedLast(elementId){
		var el = document.getElementById(elementId);
		if (el) {
			el.selectedIndex = el.length-1;
		}
	}
	function isMultiSelected(elementId){
		var el = document.getElementById(elementId);
		if (el) {
		    for (var i = 0; i < el.options.length; i++) {
		    	if (el.options[i].selected) return true;
		    }
		}
 		return false;
	}
	function popupCalendar(dateInputEl, offsetX, offsetY, userFcn) {
		var popupCalendar = new CalendarPopup('calendarDiv', offsetX, offsetY);
		if (userFcn)
			popupCalendar.setUserFcn(userFcn);
		popupCalendar.setCssPrefix('venture_');
		popupCalendar.select(dateInputEl,'dateAnchor','MM/dd/yyyy'); 

	}
	function submitForm(method, actionVal, formIndex) {
    	document.getElementById("method").value = method;
    	var index = 0;
        if (formIndex) { 
          index = formIndex;
        }
    	if (actionVal) {
    		document.forms[index].action = actionVal;
    	}
		cursorWait();
    	document.forms[index].submit();
	}	
	
	XmlHttp = function() {
		var xmlHttp = null;
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {			
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				xmlHttp = false;
			}
		}
		if (!xmlHttp && typeof XMLHttpRequest!='undefined') {
			try {
  				xmlHttp = new XMLHttpRequest();
			} catch (e) {
				xmlHttp = false;
			}
		}
		return xmlHttp;
	}
	function sendAjaxRequest(url, ignoreCursor) {
		var xmlHttp = new XmlHttp();
		xmlHttp.open("POST", url, true);
		if (!ignoreCursor) {
			cursorWait();
		}
 		xmlHttp.onreadystatechange=function() {
 			handleResponse(xmlHttp);
  		}
		xmlHttp.send(null);
	}
	function handleResponse(xmlHttp) {
 		if (xmlHttp.readyState==4) {
 			var responseText = xmlHttp.responseText;
 			//alert(responseText);
   			eval(responseText);
   			cursorDefault();
  		}
	}	
	function setErrors(errorText) {
		eval(errorText);
	}
	function findStopByNumber(prefix,restoreOriginal){
	  setValue('refresh','true');
	  var prefixStr = "";
	  if (prefix) prefixStr = prefix;
	  var inputStr = getValue(prefixStr + "stopLocationCode");
	  if (isEmpty(inputStr)) {
	  	alert("Enter a phone number.");
	  	changeImage(document.getElementById(prefix + 'findByNumberButton'), 'images/findByPhone.gif');
	  	return;
	  }
	  var url = "/LTMSLite/stopMaint?method=findStopByNumber&stopLocationCode=" +escape(inputStr) + "&prefix=" + escape(prefixStr);
	  if (restoreOriginal) {
	  	  url += "&restoreOriginal=Y";
	  }
      sendAjaxRequest(url);	 
	}	
	function findStopByNameCity(prefix){
	  setValue('refresh','true');
	  var prefixStr = "";
	  if (prefix) prefixStr = prefix;
	  var nameInputStr = getValue(prefixStr + "stopLocationName");
	  var cityInputStr = getValue(prefixStr + "stopLocationCity");
	  if (isEmpty(cityInputStr)) {
	    cityInputStr = "%";
	  }
	  if (isEmpty(nameInputStr)) {
	  	alert ("Enter a portion of the location name.");
	  	changeImage(document.getElementById(prefix + 'findByNameButton'), 'images/findByName.gif');
	  	return;
	  }
	  var url = "/LTMSLite/stopMaint";
      sendAjaxRequest(url + "?method=findStopByNameCity&stopLocationName=" + escape(nameInputStr) + "&stopLocationCity=" + escape(cityInputStr) + "&prefix=" + escape(prefixStr));	 
	}	
   function findCustomerByNumber(confirmedChange,isCancel){
      var locCode = "";
      if (document.getElementById('locationCode')) {
	   	  locCode = getLocationCode();
		  if (isEmpty(locCode)) {
			setInnerHTML("customerError", "** You must select a terminal # first.");
			return;
		  }
	  }
	  setInnerHTML("customerError", "");	  
	  var inputStr = getValue('customerNumber');
	  if (isEmpty(inputStr)) {
	  	alert("Enter a customer number.");
	  	changeImage(document.getElementById('cust_findByNumberButton'), 'images/findByPhone.gif');
	  	return;
	  }
	  var url = "/LTMSLite/loadMaint?method=updateCustomerNumber&customerNumber=" +escape(inputStr) + "&locCode=" + escape(locCode);
	  if (confirmedChange) {
	  	url += "&confirmCustChange=Y";
	  }
	  if (isCancel) {
	  	url += "&cancel=true";
	  }
      sendAjaxRequest(url);	 
	}		
	function findCustomerByNameCity(selectedFunction){	
	  var nameInputStr = getValue("custName");
	  var cityInputStr = getValue("custCity");
	  if (isEmpty(cityInputStr)) {
	    cityInputStr = "%";
	  }
	  if (isEmpty(nameInputStr)) {
	  	alert ("Enter a portion of the customer name.");
	  	changeImage(document.getElementById('cust_findByNameButton'), 'images/findByName.gif');
	  	return;
	  }
	  
	  var url = "/LTMSLite/loadMaint?method=findCustomerByNameCity&customerName=" + escape(nameInputStr) + "&customerCity=" + escape(cityInputStr) + "&selFunction=" + escape(selectedFunction);
	  if (document.getElementById('locationCode')) {
	  	url += "&locationCode=" + escape(getLocationCode());
	  }
      sendAjaxRequest(url);	 
	}
	function findCompanyByNumber(restoreOriginal){
	  var prefixStr = "company_";
	  var inputStr = getValue("companyNumber");
	  if (isEmpty(inputStr)) {
	  	alert("Enter a phone number.");
	  	changeImage(document.getElementById('company_findByNumberButton'), 'images/findByPhone.gif');
	  	return;
	  }
	  var url = "/LTMSLite/loadMaint?method=findCompanyByNumber&companyNumber=" +escape(inputStr) + "&prefix=" + escape(prefixStr);
	  if (restoreOriginal) {
	  	  url += "&restoreOriginal=Y";
	  }
      sendAjaxRequest(url);	 
	}	
	function findCompanyByNameCity(){
	  var prefixStr = "company_";
	  var nameInputStr = getValue("companyName");
	  var cityInputStr = getValue("companyCity");
	  if (isEmpty(cityInputStr)) {
	    cityInputStr = "%";
	  }
	  if (isEmpty(nameInputStr)) {
	  	alert ("Enter a portion of the company name.");
	  	changeImage(document.getElementById('company_findByNameButton'), 'images/findByName.gif');
	  	return;
	  }
	  var url = "/LTMSLite/loadMaint";
      sendAjaxRequest(url + "?method=findCompanyByNameCity&companyName=" +escape(nameInputStr) + "&companyCity=" + escape(cityInputStr) + "&prefix=" +escape(prefixStr));	 
	}
   	function deleteStop(stopNumber){
   		
   		setValue("stopNumber",stopNumber);
   		submitForm("DeleteStop","/LTMSLite/stopMaint");
   	}
   	function deleteCommodity(commLine){
   		
   		setValue("commLine",commLine);
   		submitForm("deleteCommodity","/LTMSLite/commodityMaint");
   	}
   	function deleteWellCharge(wellLine){
   		
   		setValue("wellLine",wellLine);
   		submitForm("deleteWellCharge","/LTMSLite/wellchargeMaint");
   	}
   	function highlightStopCells(rowEl) {
   		rowEl.cells[0].className = "selectedRowThreeBorder";
   	  	rowEl.cells[1].className = "selectedRowThreeBorder";
   	  	rowEl.cells[2].className = "selectedRowThreeBorder";
   	  	rowEl.cells[3].className = "selectedRowBordered";
   		var parentEl = rowEl.parentNode;
   		for (var i = 1; i < parentEl.rows.length -1; i++) {
   		    if (i != rowEl.rowIndex) {
   	  			parentEl.rows[i].cells[0].className = "threeBorderCell";
   	  			parentEl.rows[i].cells[1].className = "threeBorderCell";
   	  			parentEl.rows[i].cells[2].className = "threeBorderCell";
   	  			parentEl.rows[i].cells[3].className = "borderedCell";
   	  		} 
   	  	}
	}
	function highlightWellChargeCells(tdEl) {
   		tdEl.className = "selectedRowBordered";
   		var parentEl = tdEl.parentNode.parentNode;
   		var rowIndex = tdEl.parentNode.rowIndex;
   		for (var i = 0; i < parentEl.rows.length; i++) {
   		    if (i != rowIndex) {
   	  			parentEl.rows[i].cells[0].className = "borderedCell";
   	  		} 
   	  	}
	}
	function showOriginInfo(selectEl){
		var selectedVal=getSelectedValue(selectEl.id);
		var url = "/LTMSLite/commodityMaint";
      	sendAjaxRequest(url + "?method=updateOriginInfo&originLocationCode=" +escape(selectedVal));
	}
	function showDestinationInfo(selectEl){
		var selectedVal=getSelectedValue(selectEl.id);
		var url = "/LTMSLite/commodityMaint";
      	sendAjaxRequest(url + "?method=updateDestinationInfo&destinationLocationCode=" +escape(selectedVal));
	}
	function expandView(viewId, commoditiesExist, errorMessage) {
	  var origDestSet = !isEmpty(getValue('orig_stopLocationCode')) && !isEmpty(getValue('dest_stopLocationCode'));
	  if (viewId != "loadHeader" && viewId != "origDestInfo" && (!origDestSet || (commoditiesExist && commoditiesExist == "false"))) {
	      if (!origDestSet) { 
		      alert(errorMessage);            
	      } else {
	          alert("One or more commodities must be added before expanding WellCharges.");
	      }
	      return;
	  } else if ("true" == getValue("refresh")){
		    
	  	    setValue("refreshView", viewId);
		  	submitForm("refresh","/LTMSLite/loadMaint");
	  } else  {
	   	  	showField(viewId);
	   	  	hideField(viewId + "Expand");
	   	  	showField(viewId + "Close");
	  } 
	}
	// by passes above restrictions to show validation errors
	// for committed load when user updates the load
	function showViewForCommittedValidation(viewId) {
	   	  	showField(viewId);
	   	  	hideField(viewId + "Expand");
	   	  	showField(viewId + "Close");
	
	}
	function closeView(viewId) {
			hideField(viewId);
	   	  	showField(viewId + "Expand");
	   	  	hideField(viewId + "Close");
	}
	function showCashCustInputFields() {
		setInnerHTML('cust_nameDisplay','');
		hideField("cust_nameDisplay");
		setValue("customerName",'');
		showField("cust_nameEntry");

		setInnerHTML('customerAddress1','');	
		hideField('customerAddress1');
		setValue("customerAddr1",'');
		showField("cust_addr1Entry");

		setValue("customerAddr2",'');
		showField("cust_addr2Entry");
		
		setInnerHTML("cust_cityStateDisplay",'');
		hideField("cust_cityStateDisplay");
		setValue('customerCity','');
		showField("cust_cityEntry");
		setInnerHTML('customerError','');
				
		setInnerHTML('customerZipCode','');
		hideField("customerZipCode");
		setValue("customerZip","");
		showField("cust_zipEntry");
	}
	function showCustomerNumberFields() {
		setInnerHTML('cust_nameDisplay','');
		showField("cust_nameDisplay");
		setValue("customerName",'');
		hideField("cust_nameEntry");

		setInnerHTML('customerAddress1','');	
		showField('customerAddress1');
		setValue("customerAddr1",'');
		hideField("cust_addr1Entry");

		setValue("customerAddr2",'');
		hideField("cust_addr2Entry");
		
		setInnerHTML("cust_cityStateDisplay",'');
		showField("cust_cityStateDisplay");
		setValue('customerCity','');
		hideField("cust_cityEntry");
		setInnerHTML('customerError','');
				
		setInnerHTML('customerZipCode','');
		showField("customerZipCode");
		setValue("customerZip","");
		hideField("cust_zipEntry");
		
		setInnerHTML("cashCustType","");
	}

	function showNumberSearchFields(prefix) {
	  	var prefixStr = "";
	  	if (prefix) prefixStr = prefix;
	  	if ("cust_" == prefix) {
			setValue('customerNumber','');
			setValue('customerName','');
			setValue('customerCity','');
			setInnerHTML('customerError','');
			setInnerHTML('customerAddress1','');			
			setInnerHTML('customerZipCode','');
			setRadioValue(prefixStr + 'searchType', prefixStr +'number');		
			
	  	} else if ("company_" == prefix) {
			setValue('companyNumber','');
			setValue('companyName','');
			setValue('companyCity','');
			setInnerHTML('orderByCompanyError','');
			setInnerHTML('companyAddress1','');			
			setInnerHTML('companyZipCode','');
			setRadioValue('companySearchType', 'company_phone');
			
	  	} else {
			setValue(prefixStr + 'stopLocationCode','');
			setValue(prefixStr + 'stopLocationName','');
			setValue(prefixStr + 'stopLocationCity','');
			setInnerHTML(prefixStr + 'stopError','');
			setInnerHTML(prefixStr + 'stopLocationAddress1','');
			setInnerHTML(prefixStr + 'stopLocationZipCode','');	
			setRadioValue(prefixStr + 'searchType', prefixStr +'phone');		
		}
  		setInnerHTML(prefixStr + 'numberDisplay','');
		setInnerHTML(prefixStr + 'nameDisplay','');
		setInnerHTML(prefixStr + 'cityStateDisplay','');
		setInnerHTML(prefixStr + 'cityLabel', 'City, State');
		setInnerHTML(prefixStr + 'stateDisplay','');
		showField(prefixStr + 'numberEntry');
		hideField(prefixStr + 'numberDisplay');
		showField(prefixStr + 'findByNumber');
		hideField(prefixStr + 'nameEntry');
		showField(prefixStr + 'nameDisplay');
		hideField(prefixStr + 'cityEntry');
		showField(prefixStr + 'cityStateDisplay');
		hideField(prefixStr + 'stateDisplayRow');
		hideField(prefixStr + 'findByName');
		
	}
	function showNameCitySearchFields(prefix) {
	  	var prefixStr = "";
	  	if (prefix) prefixStr = prefix;
	  	if ("cust_" == prefix) {
			setValue('customerNumber','');
			setValue('customerName','');
			setValue('customerCity','');
			setInnerHTML('customerError','');
			setInnerHTML('customerAddress1','');			
			setInnerHTML('customerZipCode','');
			
	  	} else if ("company_" == prefix) {
			setValue('companyNumber','');
			setValue('companyName','');
			setValue('companyCity','');
			setInnerHTML('orderByCompanyError','');
			setInnerHTML('companyAddress1','');			
			setInnerHTML('companyZipCode','');
			
	  	} else {
			setValue(prefixStr + 'stopLocationCode','');
			setValue(prefixStr + 'stopLocationName','');
			setValue(prefixStr + 'stopLocationCity','');
			setInnerHTML(prefixStr + 'stopError','');
			setInnerHTML(prefixStr + 'stopLocationAddress1','');
			setInnerHTML(prefixStr + 'stopLocationZipCode','');			
		}
  		setInnerHTML(prefixStr + 'numberDisplay','');
		setInnerHTML(prefixStr + 'nameDisplay','');
		setInnerHTML(prefixStr + 'cityStateDisplay','');
		setInnerHTML(prefixStr + 'cityLabel', 'City Name');
		setInnerHTML(prefixStr + 'stateDisplay','');
		hideField(prefixStr + 'numberEntry');
		showField(prefixStr + 'numberDisplay');
		hideField(prefixStr + 'findByNumber');
		showField(prefixStr + 'nameEntry');
		hideField(prefixStr + 'nameDisplay');
		showField(prefixStr + 'cityEntry');
		showField(prefixStr + 'stateDisplayRow');
		hideField(prefixStr + 'cityStateDisplay');
		showField(prefixStr + 'findByName');
	}
	function moveStopUp() {
		
		var stopNum = getValue('stopNumber');
		if (isEmpty(stopNum) || stopNum == "0") return;
		submitForm('moveStopUp','/LTMSLite/stopMaint');
	}
	function moveStopDown() {
		var stopNum = getValue('stopNumber');
		if (isEmpty(stopNum) || stopNum == "999") return;
		submitForm('moveStopDown','/LTMSLite/stopMaint');
	}
	function isEmpty(input) {
		return (!input || input == "" || input == null || input == "null");
	}
	function editLoad() {
		if (isEmpty(getValue('loadId'))) {
			alert("Select a Load to Edit");
			return;
		}
		submitForm('RequestEditLoad', '/LTMSLite/loadMaint');
	}
	function duplicateLoad() {
		if (isEmpty(getValue('loadId'))) {
			alert("Select a Load to Duplicate");
			return;
		}
		submitForm('duplicateLoad', '/LTMSLite/loadMaint');
	}
	function unFlagLoadForExport() {
		if (isEmpty(getValue('loadId'))) {
			alert("Select a Load to UnFlag for Export");
			return;
		}
		submitForm('unFlagForExport', '/LTMSLite/loadMaint');
	}
	function showStringLoadDiv() {
		setInnerHTML('stringLoadNum',getValue('loadLocCode') + "-" + getValue('loadId').replace('_','-'));
		setInnerHTML('stringLoadError','');
		var stringDiv = document.getElementById('stringLoadDiv');
		var anchorEl = document.getElementById('locationAnchor');
		stringDiv.style.left = (getLeft(anchorEl) + 250) + "px";
		stringDiv.style.top = (getTop(anchorEl) + 350) + "px";
		showField('stringLoadDiv');
	}
	function hideStringLoadDiv() {
		setValue('numStringLoads','');
		hideField('stringLoadDiv');
		setInnerHTML('stringLoadError','');
	}
	function stringLoad() {
	    var numLoads = getValue('numStringLoads');
		if (isEmpty(numLoads) || !isNumeric(numLoads)) {
			setInnerHTML('stringLoadError','** Enter a numeric value or click \'Cancel\'.');
			return;
		} 
		setInnerHTML('stringLoadError','');
		setValue("numLoads", numLoads);
		submitForm('stringLoad', '/LTMSLite/loadMaint');
	}
	function isNumeric(inputStr) {
		var numberStr = "0123456789";
		for (var i = 0; i < inputStr.length; i++) {
			if (numberStr.indexOf(inputStr.charAt(i)) == -1) {
				return false;
			}	
		}
		return true;
	}
	function enterKeyOnLogon(e) {
		var keycode;
		if (window.event) keycode = window.event.keyCode;
		else if (e) keycode = e.which;
		else return true;
		if (keycode == 13) {
			submitForm('login');
			return false;
   		}
		else
   			return true;
	}
	function addLoad() {
		var selectEl = document.getElementById('locationCode');
		submitForm('executeAddLoad','/LTMSLite/loadMaint');
	}
	function addWellCharge() {
		var selectEl = document.getElementById('commodities');
		if (selectEl && !isMultiSelected('commodities')) {
			alert("You must select at least one commodity.");
			return;
		}
		submitForm('addWellCharge','/LTMSLite/wellchargeMaint');
	}
	function addStop() {
		if (isEmpty(getValue('stopLocationCode'))) {
			alert("Enter a phone number.");
			return;
		}
		submitForm('AddStop','/LTMSLite/stopMaint');
	}
	function editCommodity(commLine) {
		
	    sendAjaxRequest("/LTMSLite/commodityMaint?method=editCommodity&commLine=" + escape(commLine));
	}
	
	function editWellCharge(wellLine) {
	// from followup info
		var allowEdit = getValue("allowWellChargeEdit");
	    if (allowEdit == "N") {
	    	alert ("You cannot edit two wellcharges at the same time.");
	    	return;
	    }
	    
	    sendAjaxRequest("/LTMSLite/wellchargeMaint?method=editWellCharge&wellLine=" + escape(wellLine));
	}
	
    function showWellChargeHoverText(wellLine){
       sendAjaxRequest("/LTMSLite/wellchargeMaint?method=showWellChargeHoverText&wellLine=" + escape(wellLine));
    }
	
	function setRadioValue(radioInputName,value) {
		var radio = document.getElementsByName(radioInputName);
		for (var i = 0; i < radio.length; i++) {
			if (radio[i].value == value) {
			 radio[i].checked=true;
			 break;
			}
		}
	}
	function setCheckBoxValue(checkBoxId, value) {
	    var checkBoxEl = document.getElementById(checkBoxId);
    	if (checkBoxEl) {
	       checkBoxEl.checked = checkBoxEl.value == value;
	    }
	}
	function isChecked(checkBoxId) {
	    var checkBoxEl = document.getElementById(checkBoxId);
    	if (checkBoxEl) {
	       return checkBoxEl.checked;
	    }
	    return false;
	}
	function checkUncheckCheckBox(checkBoxId, checked) {
	    var checkBoxEl = document.getElementById(checkBoxId);
    	if (checkBoxEl) {
	       checkBoxEl.checked = checked;
	    }
	}
	function setMultiSelectValues(selectId, values) {
	    var selectEl = document.getElementById(selectId);
    	if (selectEl) {
	       for (var i = 0;i < values.length;i++){
	       	  for (var k = 0;k < selectEl.options.length;k++){
	       	      if (values[i] == selectEl.options[k].value){
	       	         selectEl.options[k].selected = true;
	       	      }
	       	  }
	       }
	    }
	}
	function deSelectAllValues(selectId) {
	    var selectEl = document.getElementById(selectId);
    	if (selectEl) {
	       	  for (var k = 0;k < selectEl.options.length;k++){
	       	      selectEl.options[k].selected = false;
	          }
	    }
	}
	function updateOriginDest(locationNum, prefix){
		var url = "/LTMSLite/stopMaint";
      	sendAjaxRequest(url + "?method=updateOriginDest&locationCode=" +escape(locationNum) + "&prefix=" + escape(prefix));
	}
	function changeImage(imageEl, srcImage) {
	 	if (imageEl) {
			imageEl.src = srcImage;
		}
	}
	function cancelCommodityChange() {
		setRadioValue('commodityType','M');
		setValue('commodityDesc','');
		setValue('commodityWeight','');
		setRadioValue('stripStrapPyr','');
		setRadioValue('collars','');
		setCheckBoxValue('hazmat','');
		setSelectedIndex ('origin', 1);
		setSelectedLast('destination');
		showField('addCommodityButton');
		hideField('cancelCommodityButton');
		hideField('saveCommodityButton');
		setValue('commLine','');
		setValue('commodityComments', '');
		showOriginInfo(document.getElementById('origin'));
		showDestinationInfo(document.getElementById('destination'));
	}
	function cancelWellChargeChange() {
		showField('addWellChargeButton');
		hideField('cancelWellChargeButton');
		hideField('saveWellChargeButton');
		setValue('wellLine','');
		deSelectAllValues('commodities');
		sendAjaxRequest("/LTMSLite/wellchargeMaint?method=cancelWellChargeChange");
	}
	function cancelLocationSearch(prefix) {
		var prefixStr = "";
		if (prefix) prefixStr = prefix;
		hideField(prefixStr + 'cancelSearch');
		showNumberSearchFields(prefixStr);
		setRadioValue(prefixStr + 'searchType',prefixStr+'phone');
		var originalCode = getValue(prefixStr + 'originalStopLocationCode');
		setValue(prefixStr + 'stopLocationCode', originalCode);
		if (!isEmpty(originalCode)) {
			findStopByNumber(prefixStr,'Y');
		}
	}
	function cancelCompanySearch() {
		var prefixStr = "company_";
		hideField(prefixStr + 'cancelSearch');
		showNumberSearchFields(prefixStr);
		setRadioValue('companySearchType',prefixStr+'phone');
		var originalCode = getValue('originalCompanyCode');
		setValue('companyNumber', originalCode);
		if (!isEmpty(originalCode)) {
			findCompanyByNumber();
		}
	}
	function cancelCustomerSearch() {
		hideField('cust_cancelSearch');
		showNumberSearchFields('cust_');
		setRadioValue('cust_searchType','cust_number');
		var originalCustNum = getValue('originalCustomerNumber');
		setValue('customerNumber', originalCustNum);
		if (!isEmpty(originalCustNum)) {
			findCustomerByNumber('',true);
		}
	}
	function showDispatchSheet() {
		if (isEmpty(getValue('loadId'))) {
			alert("Select a Load");
			return;
		}
		document.forms[0].target = '_blank';
		submitForm('dispatch', '/LTMSLite/dispatchSheet.pdf');
		document.forms[0].target = '_self';
		document.forms[0].action = "/LTMSLite/mainView";
		cursorDefault();
	}
	function showMilitaryDispatchSheet() {
		if (isEmpty(getValue('loadId'))) {
			alert("Select a Load");
			return;
		}
		document.forms[0].target = '_blank';
		submitForm('military', '/LTMSLite/dispatchSheet.pdf');
		document.forms[0].target = '_self';
		document.forms[0].action = "/LTMSLite/mainView";
		cursorDefault();
	}	
	function showLoadSummary() {
	    var loadId = getValue('loadId');
		if (isEmpty(loadId)) {
			alert("Select a Load");
			return;
		}
		var url = "/LTMSLite/mainView?method=loadSummary&loadId=" + escape(loadId);
		var newWindow = window.open(url,"","width=700,height=800,scrollbars=1,resizable=1");
		newWindow.moveTo(0,0);
	}
	function filterLoads(view) {
		submitForm("FilterLoads");
	}
	function unfilterLoads(view) {
		submitForm('unfilterLoads');		
	}
	function selectRow(tableRow) {
		var parentEl = tableRow.parentNode;
		for (var i = 2; i<parentEl.rows.length; i+=2) {
	    	if ((i/2) % 2 != 0) {
	    		parentEl.rows[i].className = 'listOddRow';
	    	} else {
	    		parentEl.rows[i].className = 'listEvenRow';
	    	}
	  	}
	  	tableRow.className = 'selectedRow';
	}
	function newConfirm(title,mess,icon,defbut,mods) {
  		var IE4 = ((parseInt(navigator.appVersion) >= 4) && (navigator.appName != "Netscape"));
   		if (IE4) {
   	  		icon = (icon==0) ? 0 : 2;
      		defbut = (defbut==0) ? 0 : 1;
      		retVal = makeMsgBox(title,mess,icon,4,defbut,mods);
      		retVal = (retVal==6);
   		}
   		else {
      		retVal = confirm(mess);
   		}
  		return retVal;
	}
	function deleteAvailableLoad(availLoadNum) {
	  if (confirm("Are you sure you want to delete the selected Available Load?")) {
		setValue('loadId',availLoadNum);
		submitForm('requestDeleteLoad','/LTMSLite/availLoadMaint');
	  }
	}
	function editAvailableLoad(availLoadNum) {
		setValue('loadId',availLoadNum);
		submitForm('requestEditLoad','/LTMSLite/availLoadMaint');
	}
	function addFilterField() {
		if (isEmpty(getSelectedValue('field'))) {
			alert("Select a field.");
			return;
		}
		submitForm('AddFilterField')
	}
	function showLookupTruckTypeDiv(positionAnchor,leftOffset,topOffset,truckPrefix) {
		var truckTypeDiv = document.getElementById('truckLookupDiv');
		if (!truckTypeDiv) {
			sendAjaxRequest("/LTMSLite/loadMaint?method=showLookupTruckTypeDiv&posAnchor=" + escape(positionAnchor) + "&truckPrefix=" + escape(truckPrefix) + "&leftOffset=" + escape(leftOffset) + "&topOffset=" + escape(topOffset));
			return;
		}
		var truckTypeLookupDiv = new TruckTypeLookupDiv(positionAnchor,leftOffset,topOffset,truckPrefix);
		setSelectedValue('truckSumCode','');
		setValue('truckDesc','');
		var tableEl = document.getElementById('truckTypeResults');
		// clear previous results, if any
		if (tableEl.childNodes.length > 0)
    		tableEl.removeChild(tableEl.childNodes[0]);
    	truckTypeDiv.style.visibility = "visible";
	}
	function showLookupCustomerDiv(positionAnchor,leftOffset,topOffset, selFunction) {
		if (document.getElementById('locationCode')) {
			var locCode = getLocationCode();
			if (isEmpty(locCode)) {
				setInnerHTML("customerError", "** You must select a terminal # first.");
				return;
			}
		}
		setInnerHTML("customerError", "");
		setValue('custName','');
		setValue('custCity','');
		setInnerHTML('cSearchError','');
		var customerDiv = new CustomerLookupDiv(document.getElementById(positionAnchor),leftOffset,topOffset,selFunction);
		var tableEl = document.getElementById('customerResults');
		// clear previous results, if any
		if (tableEl && tableEl.childNodes.length > 0)
    		tableEl.removeChild(tableEl.childNodes[0]);
	}
	function showLookupLocationDiv(positionAnchor,leftOffset,topOffset) {
		var locationDiv = new LocationLookupDiv(document.getElementById(positionAnchor),leftOffset,topOffset);
		setSelectedValue('locationName','');
		setValue('locationCity','');
		var tableEl = document.getElementById('locationResults');
		// clear previous results, if any
		if (tableEl && tableEl.childNodes.length > 0)
    		tableEl.removeChild(tableEl.childNodes[0]);
	}
	function showLocationMaintDiv(positionAnchor,leftOffset,topOffset) {
		var locMaintDiv = new LocationMaintenanceDiv(document.getElementById(positionAnchor),leftOffset,topOffset);
		setSelectedValue('locNumber','');
		var tableEl = document.getElementById('locationResults');
		// clear previous results, if any
		if (tableEl && tableEl.childNodes.length > 0)
    		tableEl.removeChild(tableEl.childNodes[0]);
	}
	function searchTrucks() {
		var sumCode = getSelectedValue('truckSumCode');
		var truckDesc = getValue('truckDesc');
		if (isEmpty(truckDesc) && isEmpty(sumCode)) {
			alert('You must enter a partial description or choose a summary type.');
			return;
		}
		sendAjaxRequest("/LTMSLite/loadMaint?method=searchTrucks&sumCode=" + escape(sumCode) + "&truckDesc=" + escape(truckDesc));
	}
	function validateTruckType(truckPrefix) {
	    hideField(truckPrefix + 'TruckDescRow');
	    setInnerHTML(truckPrefix + 'TruckDesc','');
	    setInnerHTML(truckPrefix + 'TruckTypeError','');
	    var truckType = getValue(truckPrefix + 'TruckType');
	    if (!isEmpty(truckType)) {
			sendAjaxRequest("/LTMSLite/loadMaint?method=validateTruckType&truckType=" + escape(truckType) + "&truckPrefix=" + escape(truckPrefix));
		}
	}
	function validateTerminal(prefix) {
		setValue(prefix + 'ThirdParty','');
		hideField(prefix + 'ThirdPartyDescRow');
	    setInnerHTML(prefix + 'ThirdPartyDesc','');
	    hideField(prefix + 'ThirdPartyCityRow');
	    setInnerHTML(prefix + 'ThirdPartyCity','');
	    setInnerHTML(prefix + 'ThirdPartyError','');
	    hideField(prefix + 'TermDescRow');
	    setInnerHTML(prefix + 'TermDesc','');
	    setInnerHTML(prefix + 'TerminalError','');
	    var terminal = getValue(prefix + 'Terminal');
	    if (!isEmpty(terminal)) {
			sendAjaxRequest("/LTMSLite/loadMaint?method=validateTerminal&terminal=" + escape(terminal) + "&prefix=" + escape(prefix));
		}
	}
	function validateThirdParty(prefix) {
			setValue(prefix + 'Terminal','');
			hideField(prefix + 'TermDescRow');
	        setInnerHTML(prefix + 'TermDesc','');
	        setInnerHTML(prefix + 'TerminalError','');
	        hideField(prefix + 'ThirdPartyDescRow');
	        setInnerHTML(prefix + 'ThirdPartyDesc','');
	        hideField(prefix + 'ThirdPartyCityRow');
	        setInnerHTML(prefix + 'ThirdPartyCity','');
	        setInnerHTML(prefix + 'ThirdPartyError','');
	        var thirdParty = getValue(prefix + 'ThirdParty');
	        if (!isEmpty(thirdParty)) {
				sendAjaxRequest("/LTMSLite/loadMaint?method=validateThirdParty&thirdParty=" + escape(thirdParty) + "&prefix=" + escape(prefix));
			}
	}
	function lookupThirdParty(leftOffset, topOffset, prefix) {
		var thirdPartyDiv = new ThirdPartyLookupDiv(document.getElementById('thirdPartyLookupAnchor'),leftOffset,topOffset, prefix);
		setValue('thirdPartyName','');
		setValue('thirdPartyCity','');
		var tableEl = document.getElementById('thirdPartyResults');
		// clear previous results, if any
		if (tableEl && tableEl.childNodes.length > 0) {
    		tableEl.removeChild(tableEl.childNodes[0]);
    	}
	}
	function lookupSellToThirdParty() {
		var thirdPartyDiv = document.getElementById('thirdPartyDiv');
		if (!thirdPartyDiv) {
			thirdPartyDiv = new ThirdPartyLookupDiv(document.getElementById('sellLoadAnchor'),0,0);
		} else {
			setValue('thirdPartyName','');
			setValue('thirdPartyCity','');
			var tableEl = document.getElementById('thirdPartyResults');
			// clear previous results, if any
			if (tableEl.childNodes.length > 0)
    			tableEl.removeChild(tableEl.childNodes[0]);
    	}
	}
	function searchThirdParty() {
		var thirdPartyName = getValue('thirdPartyName');
		var thirdPartyCity = getValue('thirdPartyCity');
		if (isEmpty(thirdPartyName) || isEmpty(thirdPartyCity)) {
			alert('You must enter a partial name and partial city.');
			return;
		}
		sendAjaxRequest("/LTMSLite/loadMaint?method=searchThirdParty&thirdPartyName=" + escape(thirdPartyName) + "&thirdPartyCity=" + escape(thirdPartyCity));
	}
	function updateReqLoadDateTime() {
		if (!isEmpty(getValue("reqLoadDate"))) {
			updateLoadDetail();
			return;
		}
		sendAjaxRequest("/LTMSLite/loadMaint?method=updateReqLoadDateTime&urgency=" + escape(getSelectedValue("urgency")));
	}
	function commitLoad() {
		if (isEmpty(getValue('loadId'))) {
			alert("Select a Load to Commit");
			return;
		}
		submitForm('commitLoad', '/LTMSLite/loadMaint');
	}
	function unAssignLoad() {
		if (isEmpty(getValue('loadId'))) {
			alert("Select a Load to UnAssign");
			return;
		}
		submitForm('unAssignLoad', '/LTMSLite/loadMaint');
	}
	function cancelLoad(confirmed) {
		if (!confirmed) {
		 		sendAjaxRequest("/LTMSLite/mainView?method=cancelLoad&loadId=" + escape(getValue('loadId')) + "&confirmed=" + escape(confirmed));
		} else {
	     		submitForm("cancelLoad","/LTMSLite/mainView?confirmed=" + confirmed);
	   	}
	}		
	function unlockLoad(confirmed) {
	   if (!confirmed) {
		 sendAjaxRequest("/LTMSLite/mainView?method=unlockLoad&loadId=" + escape(getValue('loadId')) + "&confirmed=" + escape(confirmed));
	   } else {
	     submitForm("unlockLoad","/LTMSLite/mainView?confirmed=" + escape(confirmed));
	   }
	}

	function lockLoad() { 
     submitForm("lockLoad","/LTMSLite/mainView"); 
	}
	
	function unCancelLoad() {
		if (isEmpty(getValue('loadId'))) {
			alert("Select a Load to UnCancel");
			return;
		}
		submitForm('unCancelLoad', '/LTMSLite/loadMaint');
	}	
	function requestAssignLoad() {
		if (isEmpty(getValue('loadId'))) {
			alert("Select a Load to Assign");
			return;
		}
		submitForm('requestAssignLoad', '/LTMSLite/loadMaint');
	}
	function next() {
		submitForm('next');
	}
	function previous() {
		submitForm('previous');
	}
	
	function swapOrigDest() {
		if (isEmpty(getValue('orig_stopLocationCode')) || isEmpty(getValue('dest_stopLocationCode'))) {
			alert('There must be an origin and destination to swap.');
			changeImage(document.getElementById('swapButton'), "images/swap.gif");
			return;
		}
		submitForm('swapOrigDest','/LTMSLite/stopMaint');
	}
	function enableButton(buttonId, imageUrl, anchorHref) {
		var buttonEl = document.getElementById(buttonId);
		if (buttonEl) {
			buttonEl.src = imageUrl;
			buttonEl.parentNode.href = anchorHref;
		}
	}
	function disableButton(buttonId, imageUrl) {
		var buttonEl = document.getElementById(buttonId);
		if (buttonEl) {
			buttonEl.src = imageUrl;
			buttonEl.parentNode.href = "javascript:void(0)";
		}
	}
	function validateDriverNumber() {
		var driverNum = getValue('driverNumber');
		if (isEmpty(driverNum)) {
		   hideField('driverNameRow');
		   setInnerHTML('driverName','');
		   setInnerHTML("driverNumError", "");
		   return;
		}
		if (!isEmpty(getValue("actualThirdParty"))) {
		  if (driverNum != "999") {
			  alert("Driver Number must be 999 for Third Parties");
		  }
		  setValue("driverNumber", "999");
		  hideField('driverNameRow');
		  setInnerHTML('driverName','');
		  return;
		}
		sendAjaxRequest("/LTMSLite/loadMaint?method=validateDriverNumber&driverNumber=" + escape(driverNum));
	}
	function showDriverNumberLookupDiv(anchorEl, topOffset, leftOffset) {
		var driverNumDiv = document.getElementById('driverNumberLookupDiv');
		if (!driverNumDiv) {
		    driverNumDiv = new DriverNumberLookupDiv(anchorEl, topOffset,leftOffset);
			return;
		}
		setValue('driverFirstName','');
		setValue('driverLastName','');
		var tableEl = document.getElementById('driverNumberResults');
		// clear previous results, if any
		if (tableEl.childNodes.length > 0)
    		tableEl.removeChild(tableEl.childNodes[0]);
    	driverNumDiv.style.visibility = "visible";
	}
	function lookupDrivers() {
		var firstName = getValue('driverFirstName');
		var lastName = getValue('driverLastName');
		if (isEmpty(firstName) && isEmpty(lastName)) {
		  alert("Enter a value for First Name or Last Name");
		  return;
		}
		sendAjaxRequest("/LTMSLite/loadMaint?method=lookupDrivers&firstName=" + escape(firstName) + "&lastName=" + escape(lastName));
	}
	function validateTruckNumber() {
		var truckNum = getValue('truckNumber');
		if (isEmpty(truckNum)) {
		   setInnerHTML("truckNumError", "");
		   setInnerHTML('ownerNameCell','');
		   return;
		}
		if (!isEmpty(getValue("actualThirdParty"))) {
		setValue("truckNumber", "999999");
		alert("Truck Number must be 999999 for Third Party");
		return;
		}
		sendAjaxRequest("/LTMSLite/loadMaint?method=validateTruckNumber&truckNumber=" + escape(truckNum));
	}
	function validateCustomerNumber() {
	  var locCode = ""; // rate estimator will have blank locCode
	  if (document.getElementById('locationCode')) {
		  locCode = getLocationCode();
		  if (isEmpty(locCode)) {
			setInnerHTML("customerError", "** You must select a terminal # first.");
			return;
		  }
	  }
	  setInnerHTML('customerError','');
	  var custNum = getValue('customerNumber');
	  if (!isEmpty(custNum)) {
		sendAjaxRequest("/LTMSLite/loadMaint?method=updateCustomerNumber" + "&customerNumber=" + escape(custNum) + "&locCode=" + escape(locCode));
	  } else if (!document.getElementById('locationCode')){ // this is rate estimator
		  clearRateEstCustFields();
	  }
	}
	function clearRateEstCustFields() {
		setInnerHTML('cust_nameDisplay','');
		setValue('customerName','');
		setInnerHTML('customerAddress1','');
		setInnerHTML('cust_cityStateDisplay','');
		setValue('customerCity','');
		setInnerHTML('cust_stateDisplay','');
		setInnerHTML('customerZipCode','');
		
	}
	function getLocationCode() {
		var locCodeEl = document.getElementById("locationCode");
		if (locCodeEl.options) 
			return getSelectedValue("locationCode");
		else
			return getValue("locationCode");
	}
	function showTruckNumberLookupDiv(anchorEl, topOffset, leftOffset) {
		var truckNumDiv = document.getElementById('truckNumberLookupDiv');
		if (!truckNumDiv) {
		    truckNumDiv = new TruckNumberLookupDiv(anchorEl, topOffset,leftOffset);
			return;
		}
		setValue('ownerName','');
		var tableEl = document.getElementById('truckNumberResults');
		// clear previous results, if any
		if (tableEl.childNodes.length > 0)
    		tableEl.removeChild(tableEl.childNodes[0]);
    	truckNumDiv.style.visibility = "visible";
	}
	function lookupTruckNumbers() {
		var ownerName = getValue('ownerName');
		if (isEmpty(ownerName)) {
		  alert("Enter a value for Owner Name");
		  return;
		}
		sendAjaxRequest("/LTMSLite/loadMaint?method=lookupTruckNumbers&ownerName=" + escape(ownerName));
	}
	function insertColon (inputEl) {
		var inputValue = inputEl.value;
		if (inputValue.indexOf (":") != -1 || isEmpty(inputValue)) {
			return;
		}
		if (inputValue.length < 3) {
			alert ("Time values must contain 3 or 4 digits.");
			return;
		}
		if (inputValue.length == 3) {
			inputEl.value = "0" + inputValue.substring(0,1) + ":" + inputValue.substring(1);
		}
		if (inputValue.length == 4) {
			inputEl.value = inputValue.substring(0,2) + ":" + inputValue.substring(2);
		}
		if (inputValue.length > 4 ) {
			alert("Time Values must contain 3 or 4 digits.");
		}
	}
	function checkCommodities(checkboxEl) {
		if (!checkboxEl.checked && getValue("hasHazmat") == "Y") {
			checkboxEl.checked = true;
			alert("Load currently has one or more hazmat commodities.");
		}
	}
	function addSortFields(sortString) {
		sendAjaxRequest("/LTMSLite/mainView?method=addSortFields&sortString=" + escape(sortString));
	}
	function clearSort() {
		sendAjaxRequest("/LTMSLite/mainView?method=clearSort");
	}
	function textAreaMaxLength(textAreaInput, maxlength) {
		var textValue = textAreaInput.value;
		if (textValue) {
			var textLength = textValue.length;
			if (textLength > maxlength) {
		   		textValue = textValue.substring(0, maxlength - 1);
		   		textAreaInput.value = textValue;
		   		alert("Your comments are limited to 240 characters.");
			}
		}
	}
	function useCompany(prefix) {
		showNumberSearchFields(prefix);
		var orderByCompanyNum = getValue("companyNumber");
		if (isEmpty(orderByCompanyNum)) {
			alert("Order By Company has not been entered for this load.");
			return;
		}
		setValue(prefix + 'stopLocationCode', orderByCompanyNum);
		findStopByNumber(prefix);
	}
	var timer;
	function resetTimer() {
	    updateLastPing();
	    getMessages();
		timer = setTimeout("resetTimer();",30000);
	}
	function stopTimer() {
		clearTimeout(timer);
	}
	function updateLastPing() {
		sendAjaxRequest("/LTMSLite/logon?method=updateLastPing", true);
	}
	function getMessages() {
		sendAjaxRequest("/LTMSLite/messages?method=findUnreadMessages", true);
	}
	function updateReadMessages() {
		sendAjaxRequest("/LTMSLite/messages?method=updateReadMessages", true);
	}
	function requestRateLoad () {
		submitForm('requestRateLoad','/LTMSLite/loadMaint');
	}
	function unrateLoad() {
		submitForm('unrateLoad','/LTMSLite/loadMaint');
	}
	function setDeliverDate() {
		var delDate = getValue("reqDeliverDate");
		if (delDate == null || delDate == "") {
		  var ldDate = getValue("reqLoadDate");
		  if (ldDate != null && ldDate != "") {
		    setValue("reqDeliverDate", ldDate);
		  }
		}
	}
	function requestFollowupInfo() {
		submitForm('requestFollowupInfo','/LTMSLite/loadMaint');
	}
	function flagForExport() {
		submitForm('flagForExport','/LTMSLite/loadMaint');
	}
	function saveFollowupInfo(updateWellCharge) {
	    setValue('updateWellCharge', updateWellCharge);
		submitForm('updateFollowupInfo');
	}
	function showWellChargeEditFields() {
		var wcEditTable = document.getElementById('wcEditRow');
		if (!wcEditTable) return;
		var wellLine = getValue('wellLine');
		setInnerHTML("wcTitle", "Well Charge " + wellLine);
		var wcDisplayTable = document.getElementById('wc_' + wellLine);
		var displayNode = wcDisplayTable.childNodes[0];
		wcDisplayTable.removeChild(wcDisplayTable.childNodes[0]);
		var editNode = wcEditTable.childNodes[0];
		wcDisplayTable.appendChild(wcEditTable.childNodes[0]);
		wcEditTable.appendChild(displayNode);
	}
	function cancelWellChargeEditFields() {
		var wcEditTable = document.getElementById('wcEditRow');
		var wcDisplayTable = document.getElementById('wc_' + getValue('wellLine'));
		var displayNode = wcDisplayTable.childNodes[0];
		wcDisplayTable.removeChild(displayNode);
		var editNode = wcEditTable.childNodes[0];
		wcDisplayTable.appendChild(editNode);
		wcEditTable.appendChild(displayNode);
		setValue("allowWellChargeEdit", "Y");
	}
	function showRateEstimator() {
		submitForm('showRateEstimator','/LTMSLite/loadMaint');
	}
	function showThirdPartyMaint() {
		sendAjaxRequest("/LTMSLite/mainView?method=showThirdPartyMaint");
	}
	function showThirdPartyMaintDiv() {
		resetThirdPartyMaintDiv();
		var thirdPartyMaintDiv = document.getElementById('thirdPartyMaintDiv');
		var selectEl = document.getElementById('masterCarrier');
		if (selectEl.length == 1) {
			findMasterCarriers();
		}
		thirdPartyMaintDiv.style.display = '';
	}
	function hideThirdPartyMaintDiv() {
		var thirdPartyMaintDiv = document.getElementById('thirdPartyMaintDiv');
		resetThirdPartyMaintDiv();
		hideField('thirdPartyMaintDiv');
		var cityDiv = document.getElementById('cityDiv');
		if (cityDiv) {
			cityDiv.style.visibility = "hidden";
		}
		var lookupDiv = document.getElementById('thirdPartyLookupDiv');
		if (lookupDiv) {
			lookupDiv.style.visibility = "hidden";
		}
	}
	function showHideThirdPartyCityField(selectEl) {
		var selectedValue = getSelectedValue(selectEl.id);
		if (isEmpty(selectedValue)) {
			setValue("cityName", "");
			hideField("cityRow");
			setValue("cityName", "");
			hideField("thrdptyzip");
		} else {
			showField("cityRow");
			showField("zipCodeRow");
		}
	}
	function showThirdPartyAddInstructions() {
		clearThirdPartyErrors();
		showField('addInstructions');
		hideField('editInstructions');
		hideField('thrdPtyLookupButton');
		hideField('editThirdPtyButton');
		showField('addThirdPtyButton');
		hideField('disableInput');
	}
	function showThirdPartyEditInstructions() {
		clearThirdPartyErrors();
		checkUncheckCheckBox('disableThirdParty', false);
		hideField('addInstructions');
		showField('editInstructions');
		showField('thrdPtyLookupButton');
		showField('editThirdPtyButton');
		hideField('addThirdPtyButton');
		showField('disableInput');
		if (!isEmpty(getValue('thrdptynumber'))) {
			findThirdPartyByNum();
		}
	}
	function clearThirdPartyErrors() {
	  setInnerHTML('thirdPartyNumberError','');
	  setInnerHTML('thirdPartyNameError','');
	  setInnerHTML('thirdPartyStateError','');
	  setInnerHTML('cityError','');
	  setInnerHTML('masterCarrierError','');
	}
	function clearThirdPartyFields() {
	  setValue('thrdptynumber','');
	  setValue('thrdptyname','');
	  setSelectedValue('thrdptystate','');
	  setValue('cityName','');
	  setValue('thrdptyzip','');
	  setSelectedValue('masterCarrier','');
	  checkUncheckCheckBox('disableThirdParty', false);
	}
	function resetThirdPartyMaintDiv() {
		clearThirdPartyErrors();
		clearThirdPartyFields();
		hideField('cityRow');
		showThirdPartyAddInstructions();
		setSelectedRadioValue('thirdPtyAddEdit','add');
	}
	function cancelThirdParty() {
		hideField('thirdPartyMaintDiv');
		hideField('thirdPartyLookupDiv');
		hideField('cityDiv');
		resetThirdPartyMaintDiv();
	}
	function findThirdPartyByNum() {
		var thirdPartyNum = getValue('thrdptynumber');
		var addEdit = getSelectedRadioValue('thirdPtyAddEdit');
		if (isEmpty(thirdPartyNum)) {
			resetThirdPartyMaintDiv();
		} else {
			sendAjaxRequest("/LTMSLite/thrdptyMaint?method=lookupThirdParty&addEdit=" + addEdit + "&thirdPartyNum=" + escape(thirdPartyNum));
		}
	}
	function setThirdPartyFields(name,state,city,masterCarrier,zip) {
		setValue('thrdptyname',name);
		setSelectedValue('thrdptystate',state);
		setValue('cityName',city);
		setValue('cityValidated','Y');
		showField('cityRow');
		setValue('thrdptyzip',zip);
		showField('zipCodeRow');
		setSelectedValue('masterCarrier',masterCarrier);
	}
	function findMasterCarriers() {
		sendAjaxRequest("/LTMSLite/thrdptyMaint?method=findMasterCarriers");
	}
	function populateMasterCarriers(masterCarriers) {
		//alert ("in populate master carriers");
		var selectEl = document.getElementById('masterCarrier');
		selectEl.length = masterCarriers.length + 1;
		for (var i = 1; i < masterCarriers.length; i++) {
			var opt = new Option();
			opt.value = masterCarriers[i][0];
			opt.text = masterCarriers[i][1];
			selectEl.options[i] = opt;
		}
		//alert ("out populate master carriers");
	}
	function validateThirdPartyCity() {
		var cityName = getValue("cityName");
		var state = getSelectedValue("thrdptystate");
		var zip = getValue("thrdptyzip");
	    if (!cityName || cityName.length < 3) {
	      alert("City Name must be at least 3 characters.");
	      changeImage('lookupCityButton','images/lookup.gif');
	      return;
	    }
	    var url = "/LTMSLite/thrdptyMaint?method=validateCity&cityName=" + escape(cityName) + "&thrdptystate=" + escape(state) + "&thrdptyzip=" + escape(zip);
        sendAjaxRequest(url);
	}
	function addThirdParty() {
	  	var url ="/LTMSLite/thrdptyMaint?method=addThirdParty" + getThirdPartyFormValues();
	  	sendAjaxRequest(url);
	}
	function getThirdPartyFormValues() {
		var disable = document.getElementById('disableThirdParty').checked ? "Y" : "N";
	 	return "&thrdptynumber=" + escape(getValue('thrdptynumber')) +
	 		"&disableThirdParty=" + disable +
	  		"&thrdptyname=" + escape(getValue('thrdptyname')) + 
	  		"&thrdptystate=" + escape(getSelectedValue('thrdptystate')) + 
	  		"&cityName=" + escape(getValue('cityName')) + 
	  		"&thrdptycounty=" + escape(getValue('thrdptycounty')) +
	  		"&thrdptyzip=" + escape(getValue('thrdptyzip')) +
	  		"&cityValidated=" + escape(getValue('cityValidated')) +
	  		"&masterCarrier=" + escape(getSelectedValue('masterCarrier'));
	}
	function updateThirdParty() {
		if (document.getElementById('disableThirdParty').checked && !confirm("Are you sure you want to deactivate this Third Party?")) {
			return;
		}
		var url ="/LTMSLite/thrdptyMaint?method=updateThirdParty" + getThirdPartyFormValues();
		sendAjaxRequest(url);
	}
	function appendInvoiceRefNum(textEl, termNum) {
		var inputStr = textEl.value;
		if (!isEmpty(inputStr)) {
			if (inputStr.length > 12 ) {
				inputStr = inputStr.substring(0,12);
			}
			textEl.value = inputStr + termNum;
		}
	}
	function updateLoadDetail() {
		var url = "/LTMSLite/loadMaint?method=updateLoadDetail";
		url += "&orderedBy=" + escape(getValue('orderedBy'));
		url += "&companyArea=" + escape(getValue('companyArea'));
		url += "&companyPhone=" + escape(getValue('companyPhone'));
		url += "&companyExtension=" + escape(getValue('companyExtension'));
		url += "&customerRep=" + escape(getValue('customerRep'));
		url += "&estTotalMileage=" + escape(getValue('estTotalMileage'));
		url += "&estTotalWeight=" + escape(getValue('estTotalWeight'));
		url += "&deliveryContact=" + escape(getValue('deliveryContact'));
		url += "&urgency=" + escape(getSelectedValue('urgency'));
		url += "&reqLoadDate=" + escape(getValue('reqLoadDate'));
		url += "&reqLoadTime=" + escape(getValue('reqLoadTime'));
		url += "&loadComments=" + escape(getValue('loadComments'));
		url += "&reqDeliverDate=" + escape(getValue('reqDeliverDate'));
		url += "&reqDeliverTime=" + escape(getValue('reqDeliverTime'));
		url += "&deliverComments=" + escape(getValue('deliverComments'));
		url += "&reqTruckType=" + escape(getValue('reqTruckType'));
		url += "&reqDriver=" + escape(getValue('reqDriver'));
		url += "&reqTerminal=" + escape(getValue('reqTerminal'));
		url += "&reqThirdParty=" + escape(getValue('reqThirdParty'));
		url += "&hazmat=" + (isChecked('hazmat') ? "on" : "");
		url += "&permit=" + (isChecked('permit') ? "on" : "");
		url += "&specEquip=" + (isChecked('specEquip') ? "on" : "");
		url += "&backhaul=" + (isChecked('backhaul') ? "on" : "");
		url += "&comments=" + escape(getValue('comments'));
		url += "&waybillNumber=" + escape(getValue('waybillNumber'))
		url += "&customerName=" + escape(getValue('customerName'))
		url += "&customerAddr1=" + escape(getValue('customerAddr1'))
		url += "&customerAddr2=" + escape(getValue('customerAddr2'))
		url += "&customerCity=" + escape(getValue('customerCity'))
		url += "&customerZip=" + escape(getValue('customerZip'));
		url += "&mileageOverridden=" + escape(getValue('mileageOverridden'));
		sendAjaxRequest(url);
	}
	function showRatingComments() {
		showField('ratingComments');
		showField('hideLink');
		hideField('showLink');
	}
	function hideRatingComments() {
		hideField('ratingComments');
		hideField('hideLink');
		showField('showLink');
	}
	function findTempLocation() {
		var tempLocNum = getValue('tempLocNum');
		if (isEmpty(tempLocNum)) {
			setInnerHTML('tempLocNumError','*** You must enter the Temporary Location Number.');
			return;
		}
		sendAjaxRequest("/LTMSLite/locationMaint?method=findTempLocation&tempLocNum=" + escape(tempLocNum));
	}
	function showChangeTempLocNumDiv(anchorId){
		var anchorEl = document.getElementById(anchorId);
		var changeTempLocNumDiv = document.getElementById("changeTempLocNumDiv");
		changeTempLocNumDiv.style.left = getLeft(anchorEl) + "px";
		changeTempLocNumDiv.style.top = getTop(anchorEl) + "px";
		resetChangeTempLocNumForm();
		showField("changeTempLocNumDiv");	
	}
	function hideChangeTempLocNum() {
		hideField("changeTempLocNumDiv");
		resetChangeTempLocNumForm();
	}
	function resetChangeTempLocNumForm() {
		setInnerHTML('tempLocNumError','');
		setValue('tempLocNum','');
        clearTempLocFields();
	}
	function clearTempLocFields() {
		setInnerHTML('permLocNumError','');
		setValue('permLocNum','');
		setInnerHTML('tempLocName','');
		setInnerHTML('tempLocAddress1','');
		setInnerHTML('tempLocAddress2','');
		setInnerHTML('tempLocCityStateZip','');
	}
	function updateTempLocNum() {
		var tempLocNum = getValue('tempLocNum');
		var permLocNum = getValue('permLocNum');
		if (isEmpty(tempLocNum)) {
			setInnerHTML('tempLocNumError','*** You must enter the Temporary Location Number.');
			return;
		}
		if (isEmpty(permLocNum)) {
			setInnerHTML('permLocNumError','*** You must enter the Permanent Location Number.');
			return;
		}
		sendAjaxRequest("/LTMSLite/locationMaint?method=updateTempLocNum&tempLocNum=" + escape(tempLocNum) + "&permLocNum=" + escape(permLocNum));
	}
	function viewDirections() {
		var method = "viewDirections";
		var formEl =  document.forms["routeInfoForm"];
		formEl.target= "_blank";
		formEl.action = '/LTMSLite/stopMaint?method=' + method;
		formEl.submit();
		formEl.target="_self";
		cursorDefault();
	}
	function viewMapDirections() {
		document.getElementById("mapDiv").style.display = '';
		var method = "viewMapDirections";
		var formEl = document.forms["drivingDirectionsForm"];
		formEl.target= "routeMap";
		formEl.action = '/LTMSLite/stopMaint?method=' + method;
		formEl.submit();
		formEl.target="_self";
		location.href="#mapAnchor";
	}
	function panMap(direction) {
		var formEl = document.forms["drivingDirectionsForm"];
		formEl.target= "routeMap";
		formEl.action = '/LTMSLite/stopMaint?method=panMap&direction='+direction;
		formEl.submit();
		formEl.target="_self";
		location.href="#mapAnchor";
	}
	function zoomMap(increment) {
		var formEl = document.forms["drivingDirectionsForm"];
		formEl.target= "routeMap";
		formEl.action = '/LTMSLite/stopMaint?method=zoomMap&increment='+increment;
		formEl.submit();
		formEl.target="_self";
		location.href="#mapAnchor";
	}
	function showHideMapLayer() {
		var formEl = document.forms["drivingDirectionsForm"];
		formEl.action = "/LTMSLite/stopMaint?method=showHideMapLayer";
		formEl.target= "routeMap";
		formEl.submit();
		formEl.target="_self";
		location.href="#mapAnchor";
	}
	function resetMap() {
		var formEl = document.forms["drivingDirectionsForm"];
		formEl.target= "routeMap";
		formEl.action = '/LTMSLite/stopMaint?method=resetMap';
		formEl.submit();
		formEl.target="_self";
		location.href="#mapAnchor";
	}
	function highlightRouteInfoCells(rowEl) {
		var parentEl = rowEl.parentNode.parentNode;
		if (rowEl.rowIndex != (parentEl.rows.length - 1) && rowEl.rowIndex != 0){
	  		rowEl.cells[0].className = "selectedRowThreeBorder";
	   	  	rowEl.cells[1].className = "selectedRowThreeBorder";
	   	  	rowEl.cells[2].className = "selectedRowBordered";
   	  	}
    	for (var i = 1; i < parentEl.rows.length - 1; i++) {
   		    if (i != rowEl.rowIndex) {
   	  			parentEl.rows[i].cells[0].className = "threeBorderCell";
   	  			parentEl.rows[i].cells[1].className = "threeBorderCell";
   	  			parentEl.rows[i].cells[2].className = "borderedCell";
   	  		} 
   	  	}
	}
	function updateRouteInfoStops(stopsArray, totalMiles, selectedStopNum) {
		var tableEl = document.getElementById("routeInfoStopsList");
	    if (tableEl.childNodes.length > 0) {
    		tableEl.removeChild(tableEl.childNodes[0]);
  		}
    	if (stopsArray.length == 0) {
    		hideField("routeInfoStopsListRow");
    		return;
    	}
		var tbodyEl = document.createElement("tbody");
		tbodyEl.onmouseup = function (event) {
			routeInfoRowClick(event);
    		};
    	tableEl.appendChild(tbodyEl);
    	//alert ("after append tbody");
    	var headerRow = document.createElement("tr");
    	tbodyEl.appendChild(headerRow);
    	var stopNumHdrCell = document.createElement("td");
    	stopNumHdrCell.innerHTML = "Stp #";
    	stopNumHdrCell.className = "boldText";
    	headerRow.appendChild(stopNumHdrCell);
    	var descHdrCell = document.createElement("td");
    	descHdrCell.innerHTML = "City, State Zip";
    	descHdrCell.className = "boldText";
    	headerRow.appendChild(descHdrCell);
    	var milesHdrCell = document.createElement("td");
    	milesHdrCell.innerHTML = "Miles";
    	milesHdrCell.className = "boldText";
    	headerRow.appendChild(milesHdrCell);
    	//alert ("stops array length is " + stopsArray.length);
    	for (var i = 0; i < stopsArray.length; i++) {
    		var stopNum = stopsArray[i][0];
    		var desc = stopsArray[i][1];
    		var valid = stopsArray[i][2];
    		var miles = stopsArray[i][3];
    		var rowEl  = document.createElement("tr");
    		var rowId = "routeInfoRow" + i;
    		rowEl.id = rowId;
    		var stopNumCell = document.createElement("td");
    		stopNumCell.innerHTML = stopNum;
    		if (stopNum == selectedStopNum) {
    			stopNumCell.className = "selectedRowThreeBorder";
    		} else {
	    		stopNumCell.className = "threeBorderCell";
    		}
    		var descCell = document.createElement("td");
    		if ("N" == valid) {
    			desc = "<span class='errors'>** Invalid City - Mileage can't be calculated</span><br/>" + desc;
    		}
    		descCell.innerHTML = desc;
    		if (stopNum == selectedStopNum) {
    			descCell.className = "selectedRowThreeBorder";
    		} else {
	    		descCell.className = "threeBorderCell";
    		}
    		var milesCell = document.createElement("td");
    		milesCell.innerHTML = miles;
    		if (stopNum == selectedStopNum) {
    			milesCell.className = "selectedRowBordered";
    		} else {
	    		milesCell.className = "borderedCell";
    		}
    		var deleteCell = document.createElement("td");
    		deleteCell.style.width = "100px";
    		deleteCell.style.textAlign = "center";
    		var deleteAnchor = document.createElement("a");
    		deleteAnchor.className = "imageAnchor";
    		deleteAnchor.href = "javascript:deleteRouteInfoStop('"+stopNum+"');";
    		var deleteImage = document.createElement("img");
    		deleteImage.src = "images/delete.gif";
    		deleteImage.width="83";
    		deleteImage.height="24";
    		deleteImage.border="0";
    		deleteImage.onmousedown = function () {
    			changeImage(deleteImage,'images/deleteClicked.gif');
    		}
    		deleteImage.onmouseup = function () {
    			changeImage(deleteImage,'images/delete.gif');
    		}
    		deleteImage.alt = "Delete Stop";
    		deleteAnchor.appendChild(deleteImage);
    		deleteCell.appendChild(deleteAnchor);
     		rowEl.appendChild(stopNumCell);
    		rowEl.appendChild(descCell);
    		rowEl.appendChild(milesCell);
    		rowEl.appendChild(deleteCell);
    		tbodyEl.appendChild(rowEl);
    		showField("routeInfoStopsListRow");
    		//alert ("after show route info stops list row");
    	}
    	var totalRow = document.createElement("tr");
    	var labelCell = document.createElement("td");
    	labelCell.innerHTML = "Total Miles";
    	labelCell.colSpan = "2";
    	labelCell.className = "boldText";
    	labelCell.style.textAlign = "right";
    	labelCell.style.paddingRight = "25px";
    	var amtCell = document.createElement("td");
    	amtCell.innerHTML = totalMiles;
    	amtCell.className = "borderedCell";
    	var blankCell = document.createElement("td");
    	totalRow.appendChild(labelCell);
    	totalRow.appendChild(amtCell);
    	totalRow.appendChild(blankCell);
    	tbodyEl.appendChild(totalRow);
    	//alert ("after total row");
	}
	function clearRouteInfo(isRateEst) {
		clearRouteInfoInputs();
		if (isRateEst != 'Y') {
			var tableEl = document.getElementById("routeInfoStopsList");
			if (tableEl.childNodes.length > 1)
	    		tableEl.removeChild(tableEl.childNodes[1]);
	    	hideField("routeInfoStopsListRow");
    	}
	}
	function clearRouteInfoInputs() {
		setValue("routeInfoCityName","");
		setValue("routeInfoZipCode","");
		//setInnerHTML("routeInfoError","");
	}
	function showRouteInfoDiv(updateFieldId,leftOffset,topOffset,isRateEst) {
		clearRouteInfo(isRateEst);
		var anchorEl = document.getElementById('routeInfoAnchor');
		var routeInfoDiv = document.getElementById("routeInfoDiv");
		routeInfoDiv.style.left = (getLeft(anchorEl) + leftOffset) + "px";
		routeInfoDiv.style.top = (getTop(anchorEl) + topOffset) + "px";
		setValue('updateFieldId',updateFieldId);
		setValue('leftOffset', leftOffset);
		setValue('topOffset', topOffset);
		setValue('rateEst', isRateEst);
		routeInfoDiv.style.display = "";
	}
	function requestRouteInfoDiv(updateFieldId, leftOffset, topOffset,isRateEstimator) {
		var rateEst = isRateEstimator ? 'Y' : 'N';
		if (rateEst == 'Y') {
			if (isEmpty(getValue('customerNumber'))) {
				alert ("Please select a customer before calculating mileage.");
				return;
			}
			if (isEmpty(getValue('reqLoadDate'))) {
				alert ("Please enter a load date before calculating mileage.");
				return;
			}
		}
		var url = '/LTMSLite/stopMaint?method=routeInformation&updateFieldId=' + escape(updateFieldId) + "&leftOffset=" + escape(leftOffset) + "&topOffset=" + escape(topOffset) + "&rateEst=" + rateEst + "&loadDate=" + getValue('reqLoadDate');
		sendAjaxRequest(url);
	}
	function addRouteInfoStop() {
		if ((isEmpty(getValue('routeInfoCityName')) || isEmpty(getSelectedValue('routeInfoState'))) && isEmpty('routeInfoZipCode')) {
			alert("Enter the city,state or zip code.");
			return;
		}
		sendAjaxRequest('/LTMSLite/stopMaint?method=AddRouteInfoStop&routeInfoZipCode='+ escape(getValue('routeInfoZipCode'))
		+ '&routeInfoCityName='+ escape(getValue('routeInfoCityName')) + '&routeInfoState=' + escape(getSelectedValue('routeInfoState')) + '&rateEst=' + getValue('rateEst'));
	}
	function deleteRouteInfoStop(stopNumber){
    	sendAjaxRequest("/LTMSLite/stopMaint?method=DeleteRouteInfoStop&stopNumber=" + escape(stopNumber)+ '&rateEst=' + getValue('rateEst'));
   	}
   	function moveRouteInfoStopUp() {
		var stopNum = getValue('stopNumber');
		if (isEmpty(stopNum)) {
			alert("Please select a stop");
			return;
		}
		if (parseInt(stopNum)<= 1) return;
		sendAjaxRequest('/LTMSLite/stopMaint?method=moveRouteInfoStopUp&stopNumber=' + escape(stopNum)+ '&rateEst=' + getValue('rateEst'));
	}
	function moveRouteInfoStopDown() {
		var stopNum = getValue('stopNumber');
		if (isEmpty(stopNum)) {
			alert("Please select a stop");
			return;
		}	
		if (parseInt(stopNum) >= parseInt(getValue('numStops'))) return;
		sendAjaxRequest('/LTMSLite/stopMaint?method=moveRouteInfoStopDown&stopNumber=' + escape(stopNum)+ '&rateEst=' + getValue('rateEst'));
	}
   	function exitRouteInfo() {
   		sendAjaxRequest('/LTMSLite/stopMaint?method=exitRouteInfo&updateFieldId=' + escape(getValue('updateFieldId')));
   	}
   	function searchRouteInfoCity() {
		var locationCityName = getValue("routeInfoCityName");
		var locationState = getSelectedValue("routeInfoState");
		if (isEmpty(locationState)) {
			alert("Select a state");
			return;
		}
	    if (!locationCityName || locationCityName.length < 3) {
	      alert("City Name must be at least 3 characters.");
	      changeImage('lookupCityButton','images/lookupCity.gif');
	      return;
	    }
	    var url = "/LTMSLite/stopMaint?method=searchCity&locationCityName=" + escape(locationCityName) + "&locationState=" + escape(locationState) ;
        sendAjaxRequest(url);
	}
	function routeInfoRowClick(event) {
		var evt = event || window.event;
		var target = evt.target || evt.srcElement;
		if (target.tagName != "TR") 
			var rowEl = getRowElement(target);
	    var rowIndex = rowEl.rowIndex;
		var numStops = parseInt(getValue('numStops'));
		if (rowIndex == 0 || rowIndex > numStops) {
			setValue("stopNumber","");
		} else {
			setValue("stopNumber", rowEl.rowIndex);
		}
		highlightRouteInfoCells(rowEl);
	}
	function getRowElement(target) {
	    if (target.nodeName == "TR") return target;
		else if (target.nodeName == "DIV" || target.nodeName == "TABLE" || target.nodeName == "TBODY") {
			return getRowElement(target.childNodes[0]);
		} else {
	    	return getRowElement(target.parentNode);
	    }
	}
	function showRouteInfoCityDiv(cityArray) {
		var leftOffsetStr = getValue('leftOffset');
		var leftOffset = parseInt(leftOffsetStr) + 200;
		var topOffsetStr = getValue('topOffset');
		var topOffset = parseInt(topOffsetStr) + 200;
		var cityDiv = new CityListingDiv(document.getElementById('routeInfoAnchor'),leftOffset,topOffset,'routeInfoCityName','routeInfoZipCode');
		cityDiv.showSuggestions(cityArray);
	}
	function isIE() {
		var browserName = navigator.appName;
		return browserName.indexOf("Explorer") != -1;
	}
	function subMenus(menuEl) {
		return;
		/*	if (menuEl.id == "dispatch") {
				var dispatchSubMenu = document.getElementById("dispatchSubMenu");
				dispatchSubMenu.style.top = (getTop(menuEl) - 5) + "px";
				dispatchSubMenu.style.left = (getLeft(menuEl) + 165) + "px";
				dispatchSubMenu.style.display = 'block';
			} else {
				hideSubMenus();
			}
		*/
	}
	function hideSubMenus() {
		return;
		/*hideField('dispatchSubMenu');*/
	}
	function requestAddLoadComments() {
		var loadId = getValue('loadId');
		var locCode = getValue('loadLocCode');
		var url = "/LTMSLite/loadMaint?method=requestAddLoadComments&loadId=" + escape(loadId) + '&locCode=' + escape(locCode);
		sendAjaxRequest(url);
	}
	function showAddLoadCommentsDiv() {
		var addCommentsDiv = document.getElementById('addCommentsDiv');
		var anchorEl = document.getElementById('locationAnchor');
		addCommentsDiv.style.left = (getLeft(anchorEl) + 250) + "px";
		addCommentsDiv.style.top = (getTop(anchorEl) + 150) + "px";
		showField('addCommentsDiv');
	}
	function addLoadComments() {
	    var comments = getValue("comments");
	    var url = "/LTMSLite/loadMaint?method=addLoadComments&comments=" + escape(comments);
	    sendAjaxRequest(url);
	    setInnerHTML('prevComments','');
	    setValue('comments','');
		hideField('addCommentsDiv');
	}
	function requestCalcMiles(mileageLabel, updateFieldId, errorFieldId, overriddenId, calcdId) {
		var overridden = 'Y' == getValue(overriddenId ? overriddenId : "mileageOverridden");
		var estMiles = getValue(updateFieldId);
		var hasValue = !isEmpty(estMiles) && parseInt(estMiles) > 0;
		if (overridden && hasValue) {
			alert(mileageLabel + " has been manually overridden and will not be changed.\nThis field must be cleared before it can be automatically calculated.");
			return;
		}
		setValue(calcdId ? calcdId : "mileageCalcd", 'N');
		var url = "/LTMSLite/stopMaint?method=requestCalcMiles&updateFieldId=" + updateFieldId + "&errorFieldId=" + errorFieldId + "&mileageCalcd=";
		if (calcdId) {
			url += calcdId;
		} else {
			url += "mileageCalcd";
		}
		sendAjaxRequest(url);
	}
	function calcMiles(updateFieldId, errorFieldId) {
		var url = "/LTMSLite/stopMaint?method=executeCalcMiles&updateFieldId=" + updateFieldId + "&errorFieldId=" + errorFieldId;
		sendAjaxRequest(url);
	}
	function csrFollowup() {
		submitForm('requestCSRFollowup', '/LTMSLite/loadMaint');
	}
	function updateCSRFollowup() {
		submitForm('updateCSRFollowup', '/LTMSLite/loadMaint');
	}
	function updateStripStrap() {
		var commType = getSelectedValue('commodityType');
		if ("P" == commType) {
			setRadioValue('stripStrapPyr','stripStrap');
		}
	}
	function disableAutoComplete() {
		if (document.getElementsByTagName) {
			var inputElements = document.getElementsByTagName("input");
			for (i=0; inputElements[i]; i++) {
				inputElements[i].setAttribute("autocomplete","off");
			}//loop thru input elements
		}//basic DOM-happiness-check
	}
