var RequiredFields = new Array( "cbxRepeatCustomer",
																"edtBusinessName",
																"edtPhoneNumber",
																"edtBusinessAddress1",
																"edtCity",
																"edtState",
																"edtZip",
																"edtName",
																"edtEmail",
																"edtQuoteRequiredDate",
																"edtDueToShipDate",
																"edtRquiredDeliveryDate",
																"edtOrigin",
																"edtFinal",
																"cbxTrailerSize",
																"edtCommodity",
																"edtEstimatedWeight",
																"edtVolume"
															);

var pageCode = "RateQuoteRequest"; //IM2464(2007-08-20)

function loadPage(){ //IM2464(2007-08-20)
	var xmlArray = getCachedTablesArray("esc_module_page_element");
	setPageHints(xmlArray[0]);
	setButtonEffects();
	linkInputs();
}

function onTrailerChange(pSelect) {
	var inp = document.getElementById("edtTrailerSize");
	var lblSelect = window.document.getElementById("lblFeetSel");
	var lblInput = window.document.getElementById("lblFeetInp");
	
	if (pSelect.options[pSelect.selectedIndex].value == "Other") {
		inp.style.visibility = "visible";
		lblInput.style.visibility = "visible";
		lblSelect.style.visibility = "hidden";		
		inp.value = "";		
	}else {
		inp.style.visibility = "hidden";
		lblInput.style.visibility = "hidden";
		lblSelect.style.visibility = "visible";
		inp.value = pSelect.options[pSelect.selectedIndex].value;	
	}
	if (pSelect.options[pSelect.selectedIndex].value != "") {	
		SetstdField("cbxTrailerSize");
	}
}

function validateActualDate(strDate) {
	var result = false;
	var delimChar = "/";
	var delim1 = strDate.indexOf(delimChar);
	var delim2 = strDate.lastIndexOf(delimChar);
	mo = parseInt( strDate.substring(0, delim1), 10 );
	day = parseInt(strDate.substring(delim1+1, delim2),10);
	yr = parseInt(strDate.substring(delim2+1),10);

	iActualYear = parseInt(strActualYear);
	iActualMonth = parseInt(strActualMonth);
	iActualDay = parseInt(strActualDay);
	
	if (yr >= iActualYear ) {
		if (yr > iActualYear) {
			result = true;
		}else { //yr = iActualYear
			if (mo >= iActualMonth) {
				if (mo > iActualMonth) {
					result = true;
				}	else { //mo = iActualMonth
					if (day >= iActualDay) {
						result = true;
					}					
				}
			}
		}		
	}
	return result;
}

function saveData(){
  var rlist =CheckRequiredFields(RequiredFields,true);  
  var glist =CheckRequiredFields(RequiredFields,false);     
  var httpreq = new XMLHttpRequestHandler();
  var error = false;	
  
  SetStdFieldArray(glist);
  if (rlist.length > 0){
    SetErrorFieldArray(rlist,Array(DEFAULT_VAL_MSG,DEFAULT_VAL_MSG,DEFAULT_VAL_MSG,DEFAULT_VAL_MSG,DEFAULT_VAL_MSG,DEFAULT_VAL_MSG,DEFAULT_VAL_MSG,DEFAULT_VAL_MSG,DEFAULT_VAL_MSG,DEFAULT_VAL_MSG,DEFAULT_VAL_MSG,DEFAULT_VAL_MSG,DEFAULT_VAL_MSG,DEFAULT_VAL_MSG,DEFAULT_VAL_MSG,DEFAULT_VAL_MSG,DEFAULT_VAL_MSG,DEFAULT_VAL_MSG));
		error = true;
  }  

	if (!error){
		/*QuoteRequiredDate*/
		var inpQuoteDate = window.document.getElementById("edtQuoteRequiredDate");
		var inpDueToShipDate = window.document.getElementById("edtDueToShipDate");
		var inpDeliveryDate =  window.document.getElementById("edtRquiredDeliveryDate");

		if (!validateActualDate(inpQuoteDate.value)) {
			SetErrorField("edtQuoteRequiredDate","Invalid Date");			
			error = true;
		}			
		if (!validateActualDate(inpDueToShipDate.value)) {
			SetErrorField("edtDueToShipDate","Invalid Date");					
			error = true;
		}		
		if (!validateActualDate(inpDeliveryDate.value)) {
			SetErrorField("edtRquiredDeliveryDate","Invalid Date");			
			error = true;
		}		
	}
	if (!error) {
		/*Trailer size: Other*/	
		var selTrailerSize = window.document.getElementById("cbxTrailerSize");
		var inpTrailerSize = window.document.getElementById("edtTrailerSize");
		if ( (selTrailerSize.options[selTrailerSize.selectedIndex].value == "Other") && 
				(inpTrailerSize.value == "") ) {
			SetErrorField("edtTrailerSize", DEFAULT_VAL_MSG);
			inpTrailerSize.focus();
			error = true;
		}
	}
	
	if (!error) {
    document.getElementById("rateQuoteForm").submit();		
	}
}