var shipstate = "";
var shipcntry = "";
var consstate = "";
var conscntry = "";
var tppstate = "";
var tppcntry = "";
var codstate = "";
var codcntry = "";
var detailrows = 0;
var porows = 0;
var rmarows = 0;
var fieldnamesarr;
var fielddescsarr;
var fielengthsarr;
var dfieldnamesarr;
var dfielddescsarr;
var dfieldengthsarr;
var curfind = 0;
var EMAILMUST;
var EMAILFULL;
var drowsall = 4;
var zipluwindow;
var codtypecomp;
var codtypecert;
var y;
var iscod = false;
var maxlines = 0;
var accswithsubcodesarr;
var logonstring;
var ttypestring;
var tnamestring;
var ttypenamestring;
var ampersand;
var lastid;
var maxtoadd = 9;
var curdate
function BOLinitForm() {
	var frm = document.forms['BillOfLading'];
	addCalendar('CalendarBOL', 'Select Date', 'shipdate', 'BillOfLading');
	addCalendar('CalendarBOLReq', 'Select Date', 'rdddate', 'BillOfLading');
	//getCurrentDate();
	frm.dovalidation.value = 'Y';
}

function PRinitForm() {
	var frm = document.forms['PickupRequest'];
	addCalendar('CalendarPR', 'Select Date', 'pickdate', 'PickupRequest');
	//addCalendar('CalendarBOLReq', 'Select Date', 'rdddate', 'PickupRequest');
	//getCurrentDate();
	//frm.dovalidation.value = 'Y';
}

function BOLparseDate(str_in) {
	ts = new String(str_in);
	tmon = ts.substr(4, 2);
	tday = ts.substr(7, 2);
	tyr = ts.substr(10, 4);
	//alert("tmon=" + tmon + ", tday=" + tday + ", tyr=" + tyr);

	tmm2 = new String(tmon);
	td2 = tmm2.substr(0,1);
	if (td2 == "0") {
		nmon = parseInt(tmm2.substr(1,1));
	} else {
		nmon = parseInt(tmm2);
	}

	//parse day string
	tdd2 = new String(tday);
	tc = tdd2.substr(0, 1);
	if (tc == "0") {
		nday = parseInt(tdd2.substr(1,1));
	} else {
		nday = parseInt(tday);
	}

	nyr = parseInt(tyr);
	//alert("nyr=" + nyr + ", nmon=" + nmon + ", nday=" + nday);
	//myret = new Date(nyr, nmon - 1, nday);
	myret = new Date();
	myret.setUTCFullYear(nyr, nmon - 1, nday);
	return myret;

}
function BOLvalidateEmail(valin) {
	var myret = true;
	var valstr = new String(valin);
	var c = "";
	var pos = 0;
	for (var i = 0; i < EMAILMUST.length; i++) {
		c = EMAILMUST.substr(i, 1);
		pos = valstr.indexOf(c.toLowerCase());
		if (pos >= 0) {
		} else {
			myret = false;
		}
	}
	if (myret == true) {
		for (var i = 0; i < valstr.length; i++) {
			c = valstr.substr(i, 1);
			pos = EMAILFULL.indexOf(c.toLowerCase());
			if (pos >= 0) {
			} else {
				myret = false;
			}
		}
	}
	return myret;
}
function BOLvalidatePhone(strin) {
	var ts = getDigitsOnly(strin);
	//nts = parseInt(ts);
	//if (nts > 9999999999) {
	//	return false;
	//} else if (nts <= 999999999) {
	//	return false;
	//}
	if (ts.length != 10) {
		return false;
	} else {
		return true;
	}
}
function BOLvalidatePro(strin) {
	ts = new String(strin);
	//var ts = getDigitsOnly(strin);
	//nts = parseInt(ts);
	//if (nts > 9999999999) {
	//	return false;
	//} else if (nts <= 999999999) {
	//	return false;
	//}
	if (ts.length != 10) {
		return false;
	} else {
		if (ts.substr(0, 1) != "3") {
			return false;
		} else {
			return true;
		}
	}
}

function validateBOL() {
	
	var frm = document.forms["BillOfLading"];
	dosubmit = false;
	var sd = frm.shipdate.value;
	var rdd = frm.rdddate.value;
	docod = false;
	docall = false;
	tv = frm.codstring.value;
	if ((tv != "") && (tv != "0")) {
		docod = true;
	}
	if ((frm.CA.checked == true) || ((frm.CL.checked == true))) {
		docall = true;
	}
	var doshipe = false;
	if (frm.bltoship.checked == true) {
		doshipe = true;
	}
	var doconse = false;
	if (frm.bltocons.checked == true) {
		doconse = true;
	}	
	var dotppe = false;
	if (frm.bltotpp.checked == true) {
		dotppe = true;
	}
	//frm.dovalidation.value = "N";
	if (frm.dovalidation.value != "N") {
		disableButton("CreateBOL", true);
	 	fname = "";
	 	fval = "";
	 	fdesc = "";
		alertstring = "";
	 	var focusfield = "";
	 	var typeval = "";
	 	allisvalid = true;

	 	for (var fn = 0; fn < fieldnamesarr.length; fn++) {
			fname = new String(fieldnamesarr[fn]);
			fdesc = new String(fielddescsarr[fn]);
			var tv = "";
			var isstring = false;
			curmsg = "";
			isvalid = true;
			if (fname == "BLRQTYPE") {
				rvalid = false;
				for (var r = 0; r < frm.blrqtype.length; r++) {
					if (frm.blrqtype[r].checked == true) {
						rvalid = true;
						typeval = frm.blrqtype[r].value;
						break;
					}
				}
				//isvalid = validateOneRadioChecked("document.forms['BillOfLading'].blrqtype");
				if (rvalid == false) {
					isvalid = false;
					curmsg = "You must select who you are.";
				}
				isstring = false;
			}
				
			if (fname == "BLPPDCOL" ) {
				rvalid = false;
				for (var r = 0; r < frm.blppdcol.length; r++) {
					if (frm.blppdcol[r].checked == true) {
						rvalid = true;
						break;
					}
				}
				//isvalid = validateOneRadioChecked("document.forms['BillOfLading'].blrqtype");
				//isvalid = rvalid;
				if (rvalid == false) {
					isvalid = false;
					curmsg = "You must select your payment terms.";
				}
				isstring = false;
			}
				
			if (fname == "BLRQNAME" ) {
				//alert("in BLRQNAME");
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				isstring = true;				
				if (tv == "") {
					curmsg = "You must enter your name.";
					isvalid = false;
				}
			}
				
			if (fname == "BLRQEMAIL" ) {
				isstring = true;
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				if (BOLvalidateEmail(tv) == false) {
					isvalid = false;
					curmsg = 'Your email is invalid.';				
				}
			}
				
			if (fname == "BLRQPHONE" ) {
				isstring = false;
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				isvalid = BOLvalidatePhone(tv);
				if (isvalid == false) {
					curmsg = "Your phone number is invalid. Please be sure to include area code.";
				}
			}				

			if (fname == "BLRQPHEXT" ) {
				isstring = true;
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				frm.blrqphext.value = getDigitsOnly(tv);
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
			}				

			if (fname == "BLRQFAX" ) {
				isstring = false;
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				if (tv != "") {
					isvalid = BOLvalidatePhone(tv);					
					if (isvalid == false) {
						curmsg = "Your fax number is invalid.";
					}
				}
			}			
				
			if (fname == "SHIPNAME" ) {
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				isstring = true;				
				if (tv == "") {
					curmsg = "You must enter a shipper name.";
					isvalid = false;
				}
			}
				
			if (fname == "SHIPATTN" ) {
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				isstring = true;				
			}

			if (fname == "SHIPADDRES" ) {
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				isstring = true;				
				if (tv == "") {
					curmsg = "You must enter a shipper address.";
					isvalid = false;
				}
			}

			if (fname == "SHIPCITY" ) {
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				isstring = true;				
				if (tv == "") {
					curmsg = "You must enter a shipper city.";
					isvalid = false;
				}
			}

			if (fname == "SHIPSTATE" ) {
				svalid = false;
				for (var s = 1; s < frm.shipstate.options.length; s++) {
					if (frm.shipstate.options[s].selected == true) {
						svalid = true;
						break;
					}
				}
				if (svalid == false) {
					isvalid = false;
					curmsg = "Shipper state must be selected.";
				}
				isstring = false;
			}

			if (fname == "SHIPZIP" ) {
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				isstring = true;				
				if (tv == "") {
					curmsg = "You must enter a shipper postal code.";
					isvalid = false;
				}
			}

			if (fname == "SHIPCNTRY" ) {
				rvalid = false;
				for (var r = 0; r < frm.shipcntry.length; r++) {
					if (frm.shipcntry[r].checked == true) {
						rvalid = true;
						break;
					}
				}
				//isvalid = rvalid;
				//isvalid = validateOneRadioChecked("document.forms['BillOfLading'].shipcntry");
				if (rvalid == false) {
					isvalid = false;
					curmsg = "You must choose a shipper country.";
				}
				isstring = false;
			}				
				
			if (fname == "SHIPPHONE" ) {
				isstring = false;
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				if (tv != "") {
					isvalid = BOLvalidatePhone(tv);
					if (isvalid == false) {
						curmsg = "The shipper phone number is invalid. Please be sure to include area code.";
					}
				}
			}				

			if (fname == "SHIPPHEXT" ) {
				isstring = true;
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				if (tv != "") {
					var tempvalid = BOLvalidatePhone(frm.shipphone.value);
					if (tempvalid == false) {
						isvalid = false;
						curmsg = "You must enter a shipper phone number when entering a extension.";
					}
				}				
				frm.shipphext.value = getDigitsOnly(tv);
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
			}				
				
			if (fname == "SHIPEMAIL" ) {
				isstring = true;
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				if ((tv != "") || (doshipe == true)) {
					if (BOLvalidateEmail(tv) == false) {
						isvalid = false;
						curmsg = 'Shipper\'s email is invalid.';				
					}		
				}
			}				
			if (fname == "CONSNAME" ) {
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				isstring = true;				
				if (tv == "") {
					curmsg = "You must enter a consignee name.";
					isvalid = false;
				}
			}
				
			if (fname == "CONSATTN" ) {
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				isstring = true;				
			}

			if (fname == "CONSADDRES" ) {
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				isstring = true;				
				if (tv == "") {
					curmsg = "You must enter a consignee address.";
					isvalid = false;
				}
			}

			if (fname == "CONSCITY" ) {
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				isstring = true;				
				if (tv == "") {
					curmsg = "You must enter a consignee city.";
					isvalid = false;
				}
			}

			if (fname == "CONSSTATE" ) {
				svalid = false;
				for (var s = 1; s < frm.consstate.options.length; s++) {
					if (frm.consstate.options[s].selected == true) {
						svalid = true;
						break;
					}
				}
				if (svalid == false) {
					isvalid = false;
					curmsg = "Consignee state must be selected.";
				}
				isstring = false;
			}

			if (fname == "CONSZIP" ) {
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				isstring = true;				
				if (tv == "") {
					curmsg = "You must enter a consignee postal code.";
					isvalid = false;
				}
			}

			if (fname == "CONSCNTRY" ) {
				rvalid = false;
				for (var r = 0; r < frm.conscntry.length; r++) {
					if (frm.conscntry[r].checked == true) {
						rvalid = true;
						break;
					}
				}
				//isvalid = rvalid;
				//isvalid = validateOneRadioChecked("document.forms['BillOfLading'].shipcntry");
				if (rvalid == false) {
					isvalid = false;
					curmsg = "You must choose a consignee country.";
				}
				isstring = false;
			}				
				
			if (fname == "CONSPHONE" ) {
				isstring = false;
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");				
				if (tv != "") {
					isvalid = BOLvalidatePhone(tv);
					if (isvalid == false) {
						curmsg = "The consignee phone number is invalid. Please be sure to include area code.";
					}
				}
			}				

			if (fname == "CONSPHEXT" ) {
				isstring = true;
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				if (tv != "") {
					var tempvalid = BOLvalidatePhone(frm.consphone.value);
					if (tempvalid == false) {
						isvalid = false;
						curmsg = "You must enter a consignee phone number when entering a extension.";
					}
				}								
				frm.consphext.value = getDigitsOnly(tv);
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
			}				
				
			if (fname == "CONSEMAIL" ) {
				isstring = true;
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				if ((tv != "") || (doconse == true)) {
					if (BOLvalidateEmail(tv) == false) {
						isvalid = false;
						curmsg = 'Consignee\'s email is invalid.';				
					}		
				}
			}	

			if (fname == "TPPNAME" ) {
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				isstring = true;							
				if (typeval == "T") {
					if (tv == "") {
						curmsg = "You must enter a third-party name.";
						isvalid = false;
					}
				}
			}
				
			if (fname == "TPPATTN" ) {
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				isstring = true;				
			}

			if (fname == "TPPADDRESS" ) {
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				isstring = true;	
				if (typeval == "T") {
					if (tv == "") {
						curmsg = "You must enter a third-party address.";
						isvalid = false;
					}
				}
			}

			if (fname == "TPPCITY" ) {
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				isstring = true;				
				if (typeval == "T") {
					if (tv == "") {
						curmsg = "You must enter a third-party city.";
						isvalid = false;
					}
				}
			}

			if (fname == "TPPSTATE" ) {
				isstring = false;
				if (typeval == "T") {
					svalid = false;
					for (var s = 1; s < frm.tppstate.options.length; s++) {
						if (frm.tppstate.options[s].selected == true) {
							svalid = true;
							break;
						}
					}
					if (svalid == false) {
						isvalid = false;
						curmsg = "Third-party state must be selected.";
					}
					
				}
			}

			if (fname == "TPPZIP" ) {
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				isstring = true;	
				if (typeval == "T") {
					if (tv == "") {
						curmsg = "You must enter a third-party postal code.";
						isvalid = false;
					}
				}
			}

			if (fname == "TPPCNTRY" ) {
				isstring = false;
				if (typeval == "T") {
					rvalid = false;
					for (var r = 0; r < frm.tppcntry.length; r++) {
						if (frm.tppcntry[r].checked == true) {
							rvalid = true;
							break;
						}
					}
					//isvalid = rvalid;
					//isvalid = validateOneRadioChecked("document.forms['BillOfLading'].shipcntry");
					if (rvalid == false) {
						isvalid = false;
						curmsg = "You must select a third-party country.";
					}
					//isstring = false
				}	
			}
				
			if (fname == "TPPPHONE" ) {
				isstring = false;
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				if (tv != "") {
					isvalid = BOLvalidatePhone(tv);
					if (isvalid == false) {
						curmsg = "The third-party phone number is invalid. Please be sure to include area code.";
					}
				}
			}				

			if (fname == "TPPPHEXT" ) {
				isstring = true;
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				if (tv != "") {
					var tempvalid = BOLvalidatePhone(frm.tppphone.value);
					if (tempvalid == false) {
						isvalid = false;
						curmsg = "You must enter a third party phone number when entering a extension.";
					}
				}								
				frm.tppphext.value = getDigitsOnly(tv);
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
			}				
				
			if (fname == "TPPEMAIL" ) {
				isstring = true;
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				if ((typeval == "T") || (dotppe == true)) {
					if ((tv != "") || (dotppe == true)) {
						if (BOLvalidateEmail(tv) == false) {
							isvalid = false;
							curmsg = 'Third party\'s email is invalid.';				
						}		
					}
				}
			}							
			if (fname == "CODSTRING") {
				isstring = true;
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				if ((tv != "") && (tv != "0")) {
					docod = true;
					ntv = new Number(tv);
					if (isNaN(ntv) == true) {
						fieldvalid = false;
						curmsg = "COD value is not valid.";
					} else {
						if (ntv > 99999.99) {
							isvalid = false;
							curmsg = "COD amount cannot be greater than $99,999.99.";
						}
					}
				}
			}				
			if (fname == "CODTYPE") {
				isvalid = true;
				if (docod == true) {
					var tcodtype = "";
					rvalid = false;
					var tl = frm.codtype.length;
					//alert("tl=" + tl);
					for (var r = 0; r < frm.codtype.length; r++) {
						if (frm.codtype[r].checked == true) {
							rvalid = true;
							tcodtype = frm.codtype[r].value;
							break;
						}
					}
					//isvalid = validateOneRadioChecked("document.forms['BillOfLading'].blrqtype");
					if (rvalid == false) {
						isvalid = false;
						curmsg = "You must select a COD collection method.";
					}
				} else {
				
				}
				isstring = false;

			}
			if (fname == "CODNAME" ) {
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				isstring = true;							
				if (docod == true) {
					if (tv == "") {
						curmsg = "You must enter a COD name.";
						isvalid = false;
					}
				}
			}

			if (fname == "CODADDRESS" ) {
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				isstring = true;	
				if (docod == true) {
					if (tv == "") {
						curmsg = "You must enter a COD address.";
						isvalid = false;
					}
				}
			}

			if (fname == "CODCITY" ) {
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				isstring = true;				
				if (docod == true) {
					if (tv == "") {
						curmsg = "You must enter a COD city.";
						isvalid = false;
					}
				}
			}

			if (fname == "CODSTATE" ) {
				isstring = false;
				if (docod == true) {
					svalid = false;
					for (var s = 1; s < frm.codstate.options.length; s++) {
						if (frm.codstate.options[s].selected == true) {
							svalid = true;
							break;
						}
					}
					if (svalid == false) {
						isvalid = false;
						curmsg = "COD state must be selected.";
					}
					
				}
			}

			if (fname == "CODZIP" ) {
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				isstring = true;	
				if (docod == true) {
					if (tv == "") {
						curmsg = "You must enter a COD postal code.";
						isvalid = false;
					}
				}
			}

			if (fname == "CODCNTRY" ) {
				isstring = false;
				if (docod == true) {
					rvalid = false;
					for (var r = 0; r < frm.codcntry.length; r++) {
						if (frm.codcntry[r].checked == true) {
							rvalid = true;
							break;
						}
					}
					//isvalid = rvalid;
					//isvalid = validateOneRadioChecked("document.forms['BillOfLading'].shipcntry");
					if (rvalid == false) {
						isvalid = false;
						curmsg = "You must select a COD country.";
					}
					//isstring = false
				}	
			}
			
			if (fname == "SHIPDATE" ) {
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");			
				var we = checkIfWeekend(sd);
				if (we == 'Y') {
					isvalid = false;
					curmsg = 'Choose a weekday for a Ship Date.';
				} else {
					ttoday = new Date();
					//ttoday2 = new Date(ttoday.getFullYear(), ttoday.getMonth(), ttoday.getDate());
					ttoday2 = new Date();
					ttoday2.setUTCFullYear(ttoday.getFullYear(), ttoday.getMonth(), ttoday.getDate());
					tsd = BOLparseDate(sd);
					//alert('ttoday=' + ttoday2 + ', tsd=' + tsd);
					if ((ttoday2 - tsd) > 0) {
						isvalid = false;
						curmsg = 'You cannot choose a Ship Date prior to today.';
					}
				}
				isstring = false;
			}
			if (fname == "RDDDATE" ) {
				if (frm.RDD.checked == true) {
					tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");			
					var we = checkIfWeekend(rdd);
					if (we == 'Y') {
						isvalid = false;
						curmsg = 'Choose a weekday for a Required Delivery Date.';
					} else {
						ttoday2 = new Date();
						//ttoday22 = new Date(ttoday2.getFullYear(), ttoday2.getMonth(), ttoday2.getDate());
						ttoday22 = new Date();
						ttoday22.setUTCFullYear(ttoday2.getFullYear(), ttoday2.getMonth(), ttoday2.getDate());
						tsd2 = BOLparseDate(rdd);
						//alert('ttoday22=' + ttoday22 + ', tsd2=' + tsd2);
						if ((ttoday22 - tsd2) >= 0) {
							isvalid = false;
							curmsg = 'You cannot choose a Required Delivery Date prior to today.';
						}
					}
					isstring = false;
				}
			}			
			if (fname == "PRO") {
				isstring = false;
				tv = frm.pro.value;
				if (tv != "") {
					tv = getDigitsOnly(tv);
					frm.pro.value = tv;
					if (BOLvalidatePro(tv) == true) {
					} else {
						isvalid = false;
						curmsg = "Invalid PRO number.";
					}
				}
			}
			if (fname == "BLDNBR") {
				isstring = true;
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
			}
			if (fname == "BLTEMPNAME" ) {
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				isstring = true;				
				//if (tv == "") {
				//	curmsg = "You must enter a consignee city.";
				//	isvalid = false;
				//}
			}			
			if (fname == "ADDEMAIL" ) {
				isstring = true;
				tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				if (tv != "") {
					if (BOLvalidateEmail(tv) == false) {
						isvalid = false;
						curmsg = 'Additional send-to email is invalid.';				
					}		
				}

			}
			if (docall == true) {
				if (fname == "BLCLNAME") {
					isstring = true;
					tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
					if (tv.length == 0) {
						isvalid = false;
						curmsg = "You must enter a person to call when choosing these options.";
					}
				}
				if (fname == "BLCLPHONE" ) {
					isstring = false;
					tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
					isvalid = BOLvalidatePhone(tv);
					if (isvalid == false) {
						curmsg = "The person to call phone number is invalid. Please be sure to include area code.";
					}
				}
				if (fname == "BLCLPHEXT" ) {
					isstring = true;
					tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
					frm.blclphext.value = getDigitsOnly(tv);
					tv = eval("document.forms['BillOfLading']." + fname.toLowerCase() + ".value");
				}				
			}
			if (isstring == true) {
				fval = new String(tv + "");
				if (BOLvalidateFieldLength(fval, fn) == false) {
					curmsg = curmsg + " Field " + fdesc + " has a maximum length of " +fieldlengthsarr[fn] + ".";
					isvalid = false;
				}
			}
			if (isvalid == false) {
				allisvalid = false;
				if (focusfield == "") {
					focusfield = fname.toLowerCase();
				}
			}
			if (curmsg != "") {
				if (alertstring != "") {
					alertstring = alertstring + " " + curmsg;
				} else {	
					alertstring = curmsg;
				}
			}
			
		}
		
		
		var fillcnt = 0;
		var drow = 0;
		var currLine = -1;
		var packLine = 0;

		for (drow = 0; drow < detailrows; drow++) {
			var dLine = document.getElementById('detailbdline_' + drow).value;
			var i_dLine = parseInt(dLine);
			if (dLine != currLine) {
				currLine = dLine;
				packLine = 1;
				//alert("Validate Handling Unit for " + currLine);
				
				var packUnit = document.getElementById('bdhdform' + currLine).value;
				//alert('Unit Value=' + packUnit);
				if (packUnit == '') {
					alert('You must select a Handling Unit type for all Commodities.');
					document.getElementById('bdhdform' + currLine).focus();
					disableButton("CreateBOL", false);
					return false;
				}
				
				packUnit = document.getElementById('bdhdunit' + currLine).value;
				if (packUnit < 1) {
					alert('You must enter a value greater than 0 for the number of units of all Commodities.');
					document.getElementById('bdhdunit' + currLine).focus();
					disableButton("CreateBOL", false);
					return false;
				}
				
			}
			//alert("Validate Packaging for " + currLine + "_" + packLine);
			
			var packUnit = document.getElementById('bdwgt' + currLine + "_" + packLine).value;
			//alert('Unit Value=' + packUnit);
			if (packUnit < 1) {
				alert('You must enter a value greater than 0 for the weight for all Commodities.');
				document.getElementById('bdwgt' + currLine + "_" + packLine).focus();
				disableButton("CreateBOL", false);
				return false;
			}
			
			packUnit = document.getElementById('bddesc' + currLine + "_" + packLine).value;
			//alert('Desc=' + packUnit);
			if (packUnit == '') {
				alert('You must enter a Description for all Commodities.');
				document.getElementById('bddesc' + currLine + "_" + packLine).focus();
				disableButton("CreateBOL", false);
				return false;
			}
			
			//Check for HazMat Values
			var hazmat = document.getElementById('bdhmflag' + currLine + "_" + packLine).checked;
			
			if (hazmat) {
				packUnit = document.getElementById('bdhmclass' + currLine + "_" + packLine).value;
				if (packUnit == '') {
					alert('You must select a Hazardous Class.');
					document.getElementById('bdhmclass' + currLine + "_" + packLine).focus();
					disableButton("CreateBOL", false);
					return false;
				} 
				
				var packElement = document.getElementById('bdhmunna' + currLine + "_" + packLine)
				tv = packElement.value;
				if (tv == "") {
					alert("UN/NA# must be entered.");
					packElement.focus();
					disableButton("CreateBOL", false);
					return false;
				} else {
					if (tv.length < 6) {
						alert("Invalid UN/NA#.");
						packElement.focus();
						disableButton("CreateBOL", false);
						return false;
					} else {
						var unnapre = tv.substr(0, 2);
						if ((unnapre.toUpperCase() != "NA") && (unnapre.toUpperCase() != "UN")) {
							alert("UN/NA# number must start with UN or NA.");
							packElement.focus();
							disableButton("CreateBOL", false);
							return false;
						} else {
							var unnarest = getDigitsOnly(tv.substr(2, 4));
							if (unnarest.length < 4) {
								alert("Invalid UN/NA#.");
								packElement.focus();
								disableButton("CreateBOL", false);
								return false;									
							}									
						}
					}
				}
			} else {
				document.getElementById('bdhmclass' + currLine + "_" + packLine).selectedIndex = 0;
				document.getElementById('bdhmunna' + currLine + "_" + packLine).value='';
				document.getElementById('bdhmpg' + currLine + "_" + packLine).value='';
				//document.getElementById('bdhzphone' + currLine + "_" + packLine).value='';
			}
			packLine++;
		}
		
		
		//validate hazmat information.
		if (showHideHazMat()) {
			var hzresp1 = false;
			var hzresp2 = false;
			
			if (frm.tmphzemergencyphone1.value != '' || frm.tmphzrespprovider.value != '' || frm.tmphzrespcontract.value != '') {
				hzresp1 = true;
			}
			if (frm.tmphzemergencyphone2.value != '' || frm.tmphzphoneext.value != '' || frm.tmphzrespcontact.value != '') {
				hzresp2 = true;
			}
			
			if (hzresp1 && hzresp2) {
				allisvalid = false;
				alert('Please enter information into only one portion of the Hazardous Emergency Response Information section.');
				frm.tmphzemergencyphone1.focus();
				disableButton("CreateBOL", false);
				return;
			} else if (!hzresp1 && !hzresp2) {
				allisvalid = false;
				alert('Please enter information into one portion of the Hazardous Emergency Response Information section.');
				frm.tmphzemergencyphone1.focus();
				disableButton("CreateBOL", false);
				return;
				
			} else if (hzresp1) {
				//Validate first options
				if (frm.tmphzemergencyphone1.value == '' || !BOLvalidatePhone(frm.tmphzemergencyphone1.value)) {
					allisvalid = false;
					alert('Please enter a properly formatted (xxx-xxx-xxxx) hazmat Emergency Contact Phone number.');
					frm.tmphzemergencyphone1.focus();
					disableButton("CreateBOL", false);
					return;
				}
				if (frm.tmphzrespprovider.value == '') {
					allisvalid = false;
					alert('Please enter the hazmat Emergency Provider Name.');
					frm.tmphzrespprovider.focus();
					disableButton("CreateBOL", false);
					return;
				}
				if (frm.tmphzrespcontract.value == '') {
					allisvalid = false;
					alert('Please enter the hazmat Emergency Response contract number.');
					frm.tmphzrespcontract.focus();
					disableButton("CreateBOL", false);
					return;
				}
				
				//now set the hidden values
				frm.blhzphone.value = getDigitsOnly(frm.tmphzemergencyphone1.value);
				frm.blhzphext.value = "";
				frm.blhzcontact.value = frm.tmphzrespprovider.value;
				frm.blhzcontract.value = frm.tmphzrespcontract.value;
	
			} else {
				//Validate second option
				if (frm.tmphzemergencyphone2.value == '' || !BOLvalidatePhone(frm.tmphzemergencyphone2.value)) {
					allisvalid = false;
					alert('Please enter a properly formatted (xxx-xxx-xxxx) hazmat Emergency Contact Phone number.');
					frm.tmphzemergencyphone2.focus();
					disableButton("CreateBOL", false);
					return;
				}
				if (frm.tmphzrespcontact.value == '') {
					allisvalid = false;
					alert('Please enter the hazmat Emergency Contact Name.');
					frm.tmphzrespcontact.focus();
					disableButton("CreateBOL", false);
					return;
				}
				
				//now set the hidden values
				frm.blhzphone.value = getDigitsOnly(frm.tmphzemergencyphone2.value);
				frm.blhzphext.value = frm.tmphzphoneext.value;
				frm.blhzcontact.value = frm.tmphzrespcontact.value;
				frm.blhzcontract.value = "";
			}
		}
		
		//validate the Shipping labels information
		if (frm.startLabels.value == '') {
			frm.startLabels.value = 1;
		}
		if (frm.numberLabels.value == '') {
			frm.numberLabels.value = 0;
		}
		
		var tmpStrLabels = parseInt(frm.startLabels.value);
		var tmpNumLabels = parseInt(frm.numberLabels.value);
		
		if (isNaN(tmpStrLabels)) {
			allisvalid = false;
			alert('Please enter a numeric value for the Start With Label field.');
			frm.startLabels.focus();
			disableButton("CreateBOL", false);
			return;
		}
		if (isNaN(tmpNumLabels)) {
			allisvalid = false;
			alert('Please enter a numeric value for the Number of Labels field.');
			frm.numberLabels.focus();
			disableButton("CreateBOL", false);
			return;
		}
		if(tmpStrLabels < 1 || tmpStrLabels > 6) {
			allisvalid = false;
			alert('Please enter a numeric value between 1 and 6 for the Start With Label field.');
			frm.startLabels.focus();
			disableButton("CreateBOL", false);
			return;
		}
		
		var prow = 0;
		for (prow = 0; prow < porows; prow++) {
			//alert("in drow loop");
			prows = prow + "";
			//alert("drows=" + drows);
			prowp = prow + 1;
			prowsp = prowp + "";
			isvalid = true;
			rowmsg = "";
			rowvalid = true;				
			for (var fn = 0; fn < dfieldnamesarr.length; fn++) {
				//alert("fname=" + fname);
				fname = new String(dfieldnamesarr[fn]);
				var tv = "";
				var isstring = false;
				curmsg = "";
				fieldvalid = true;	
				if (fname == "PONMBR" ) {
					isstring = true;
					tv = eval("document.forms['BillOfLading'].ponmbr" + prows + ".value;");
				}
				if (isstring == true) {
					fval = new String(tv + "");
					if (BOLvalidateDetailFieldLength(fval, fn) == false) {
						curmsg = curmsg + "PO entry for row " + prowsp + " is too long.";
						fieldvalid = false;
					}
				}
				
				if (curmsg != "") {
					if (rowmsg != "") {
						rowmsg = rowmsg + " " + curmsg;
					} else {	
						rowmsg = curmsg;
					}
				}
				if (fieldvalid == false) {
					rowvalid = false;
					if (focusfield == "") {
						focusfield = fname.toLowerCase() + prows;
					}
				}

			}
			//alert("ecnt aft=" + ecnt);
			isvalid = rowvalid;
			if (isvalid == false) {
				allisvalid = false;
				//if (focusfield == "") {
				//	focusfield = fname.toLowerCase() + drows;
				//}
			}
			if (rowmsg != "") {
				if (alertstring != "") {
					alertstring = alertstring + " " + rowmsg;
				} else {	
					alertstring = rowmsg;
				}
			}
		}
		var rrow = 0;
		for (rrow = 0; rrow < rmarows; rrow++) {
			//alert("in drow loop");
			rrows = rrow + "";
			//alert("drows=" + drows);
			rrowp = rrow + 1;
			rrowsp = rrowp + "";
			isvalid = true;
			rowmsg = "";
			rowvalid = true;				
			for (var fn = 0; fn < dfieldnamesarr.length; fn++) {
				//alert("fname=" + fname);
				fname = new String(dfieldnamesarr[fn]);
				var tv = "";
				var isstring = false;
				curmsg = "";
				fieldvalid = true;	
				if (fname == "RMANMBR" ) {
					isstring = true;
					tv = eval("document.forms['BillOfLading'].rmanmbr" + rrows + ".value;");
				}
				if (isstring == true) {
					fval = new String(tv + "");
					if (BOLvalidateDetailFieldLength(fval, fn) == false) {
						curmsg = curmsg + "RMA entry for row " + rrowsp + " is too long.";
						fieldvalid = false;
					}
				}
				
				if (curmsg != "") {
					if (rowmsg != "") {
						rowmsg = rowmsg + " " + curmsg;
					} else {	
						rowmsg = curmsg;
					}
				}
				if (fieldvalid == false) {
					rowvalid = false;
					if (focusfield == "") {
						focusfield = fname.toLowerCase() + rrows;
					}
				}

			}
			//alert("ecnt aft=" + ecnt);
			isvalid = rowvalid;
			if (isvalid == false) {
				allisvalid = false;
				//if (focusfield == "") {
				//	focusfield = fname.toLowerCase() + drows;
				//}
			}
			if (rowmsg != "") {
				if (alertstring != "") {
					alertstring = alertstring + " " + rowmsg;
				} else {	
					alertstring = rowmsg;
				}
			}
		}
		if (frm.CA.checked == true) {
			if (frm.CAselect.selectedIndex < 1) {
				allisvalid = false;
				curmsg = "You must specify more information when choosing Call For Appointment.";
				if (alertstring != "") {
					alertstring = alertstring + " " + curmsg;
				} else {	
					alertstring = curmsg;
				}				
				if (focusfield == "") {
					focusfield  = "CAselect";
				}
			}
		}
		if (frm.CL.checked == true) {
			if (frm.CLselect.selectedIndex < 1) {
				allisvalid = false;
				curmsg = "You must specify more information when choosing Call Consignee Before Delivery.";
				if (alertstring != "") {
					alertstring = alertstring + " " + curmsg;
				} else {	
					alertstring = curmsg;
				}								
				if (focusfield == "") {
					focusfield  = "CLselect";
				}
			}
		}			
		if (frm.LAO.checked == true) {
			if (frm.LAOselect.selectedIndex < 1) {
				allisvalid = false;
				curmsg = "You must specify more information when choosing Limited Access Pickup.";
				if (alertstring != "") {
					alertstring = alertstring + " " + curmsg;
				} else {	
					alertstring = curmsg;
				}								
				if (focusfield == "") {
					focusfield  = "LAOselect";
				}				
			}
		}						
		if (frm.LAD.checked == true) {
			if (frm.LADselect.selectedIndex < 1) {
				allisvalid = false;
				curmsg = "You must specify more information when choosing Limited Access Delivery.";
				if (alertstring != "") {
					alertstring = alertstring + " " + curmsg;
				} else {	
				alertstring = curmsg;
				}								
				if (focusfield == "") {
					focusfield  = "LADselect";
				}				
			}
		}
		
		
		if (frm.VL != null) {
			if (frm.VL.checked) {
				if (frm.FVCAmount.value == "") {
					allisvalid = false;
					alert('You must enter an Amount if you Select Full Value Coverage.');
					frm.FVCAmount.focus();
					disableButton("CreateBOL", false);
					return false;
				} else {
					if (!IsNumeric(frm.FVCAmount.value)) {
						allisvalid = false;
						alert('You must enter a valid number for Full Value Coverage.');
						frm.FVCAmount.focus();
						disableButton("CreateBOL", false);
						return;
					}
					var tmpnumstr = convertIt(frm.FVCAmount.value);
					var tmpnumval = parseFloat(tmpnumstr);
					if (tmpnumval > 99999) {
						allisvalid = false;
						alert('You must enter an Amount less than $100,000 for Full Value Coverage.');
						frm.FVCAmount.focus();
						disableButton("CreateBOL", false);
						return;
					}
				}
			}
		}
		if (allisvalid == true) {

		}
		if (allisvalid == true) {
			var tvalid = checkDupTemplateName();
			if (tvalid == false) {
				allisvalid = false;
				focusfield = "bltempname";
				eval("document.forms['BillOfLading']." + focusfield + ".focus()");
			} else {
				dosubmit = true;
			}
		} else {
			if (focusfield != "") {
				eval("document.forms['BillOfLading']." + focusfield + ".focus()");
			}
			alert(alertstring);
		}
		disableButton("CreateBOL", false);
	} else {
		dosubmit = true;
		
		//need to setup any hazmat information to carry over.
		if (showHideHazMat()) {
			var hzresp1 = false;
			var hzresp2 = false;
			
			if (frm.tmphzemergencyphone1.value != '' || frm.tmphzrespprovider.value != '' || frm.tmphzrespcontract.value != '') {
				hzresp1 = true;
			}
			if (frm.tmphzemergencyphone2.value != '' || frm.tmphzphoneext.value != '' || frm.tmphzrespcontact.value != '') {
				hzresp2 = true;
			}
			
		 	if (hzresp1) {
				//now set the hidden values
				frm.blhzphone.value = getDigitsOnly(frm.tmphzemergencyphone1.value);
				frm.blhzphext.value = "";
				frm.blhzcontact.value = frm.tmphzrespprovider.value;
				frm.blhzcontract.value = frm.tmphzrespcontract.value;
			} else {				
				//now set the hidden values
				frm.blhzphone.value = getDigitsOnly(frm.tmphzemergencyphone2.value);
				frm.blhzphext.value = frm.tmphzphoneext.value;
				frm.blhzcontact.value = frm.tmphzrespcontact.value;
				frm.blhzcontract.value = "";
			}
		}	
	}
	
	if (dosubmit == true) {
		//frm.dovalidation.value = "Y";
		if (docod == true) {
			var tcodtype = "";
			rvalid = false;
			var tl = frm.codtype.length;
			//alert("tl=" + tl);
			for (var r = 0; r < frm.codtype.length; r++) {
				if (frm.codtype[r].checked == true) {
					rvalid = true;
					tcodtype = frm.codtype[r].value;
					//alert("tcodtype="  + tcodtype);
					break;
				}
			}
			//isvalid = validateOneRadioChecked("document.forms['BillOfLading'].blrqtype");
			if (tcodtype == codtypecomp) {
				frm.cdcmpy.value = y;
				frm.cdcert.value = "";
			} else if (tcodtype == codtypecert) {
				frm.cdcmpy.value = "";
				frm.cdcert.value = y;
			}
		}

		frm.shipdate.value = sd.substring(sd.length - 10, sd.length);
		frm.rdddate.value = rdd.substring(rdd.length - 10, rdd.length);
		//alert("shipdate=" + frm.shipdate.value + "-");
		//Next line calls a function that is in BillOfLading.jsp
		//showWait();
		//frm.submit();
		if (frm.dovalidation.value == "N") {
			formSubmit();
		}
		
		return true;
	} else {
		return false;
	}
}

function checkDupTemplateName() {
	var frm = document.forms['BillOfLading'];
	var tname = frm.bltempname.value;
	var myret = true;
	if (tname != "") {	
		for (var i = 0; i < frm.templateselect.options.length; i++) {
			if (frm.templateselect.options[i].value.toUpperCase() == tname.toUpperCase()) {
				myret = confirm("This template name has already been used. Do you want to overwrite the previous template with this name?");
				break;
			}
		}
	}
	
	return myret;
	
}

function disableButton(mb, st) {
	var frm = document.forms['BillOfLading'];
	for (i = 0; i < frm.length; i++) {
		var tempobj = frm.elements[i];
		if (tempobj.name == mb) {
			tempobj.disabled = st;
		}
	}

}

function pleaseWait(){
	//reloading the animated GIF image
	showWait();
	disableButton("CreateBOL", true);
	document.forms[0].action="/webapp/BillOfLading/ProcessServlet" + logonstring;	
	document.forms[0].submit();
	if(document.images) document.progressImage.src=document.progressImage.src;
}

function formSubmit(){
	document.forms[0].action="/webapp/BillOfLading/ProcessServlet" + logonstring;
	document.forms[0].submit();
	return false; //because we're doing the submit in this method	
}
function BOLvalidateFieldLength(fval, ind) {
	var frm = document.forms['BillOfLading'];
	var ts = fval
	//var ind = findArrInd(fieldnamesarr, fname.toUpperCase());
	if (ts.length > parseInt(fieldlengthsarr[ind])) {
		return false;
	} else {
		return true;
	}
}
function BOLvalidateDetailFieldLength(fval, ind) {
	var frm = document.forms['BillOfLading'];
	var ts = fval
	//var ind = findArrInd(dfieldnamesarr, fname.toUpperCase());
	if (ts.length > parseInt(dfieldlengthsarr[ind])) {
		return false;
	} else {
		return true;
	}
}

function BOLsetCountryRadio(namein) {
	for (var i = 0; i < countrynames.length; i++) {
		var lineout = "";
		if (eval(namein) == countryabbrevs[i]) {
			lineout = "<TD VALIGN=\"MIDDLE\" ALIGN=\"LEFT\" NOWRAP><FONT SIZE=\"2\"><INPUT TYPE=\"RADIO\" NAME=\"" + namein + "\" VALUE=\"" + countryabbrevs[i] + "\" CHECKED >" + countrynames[i] + "</FONT></TD>";
		} else {
			lineout = "<TD VALIGN=\"MIDDLE\" ALIGN=\"LEFT\" NOWRAP><FONT SIZE=\"2\"><INPUT TYPE=\"RADIO\" NAME=\"" + namein + "\" VALUE=\"" + countryabbrevs[i] + "\" >" + countrynames[i] + "</FONT></TD>";		
		}
		//alert("lineout=" + lineout);
		document.write(lineout);
	}
	
}

function BOLremoveItem(itemno) {	
	frm = document.forms["BillOfLading"];
	if (detailrows <= 1) {
		alert("You must have at least 1 commodity row.");
	} else {
		var es = "document.forms['BillOfLading'].itemremove" + itemno + ".value='Y'";
		eval(es);
		frm.dovalidation.value = "N";
		validateBOL();
	}
}

function BOLremovePackage(itemno,packno) {	
	frm = document.forms["BillOfLading"];
	if (detailrows <= 1) {
		alert("You must have at least 1 commodity row.");
	} else {
		var es = "document.forms['BillOfLading'].itemremove" + itemno + "_" + packno + ".value='Y'";
		//alert("Eval Statement: " + es);
		eval(es);
		frm.dovalidation.value = "N";
		validateBOL();
	}
}

function BOLremovePo(itemno) {	
	frm = document.forms["BillOfLading"];
	var es = "document.forms['BillOfLading'].poremove" + itemno + ".value='Y'";
	//alert("es=" + es);
	eval(es);
	//alert("0=" + frm.poremove0.value);
	frm.dovalidation.value = "N";
	//alert("0=" + frm.dovalidation.value);
	//alert("b4 submit");
	
	//alert("frm=" + frm);
	validateBOL();
}
function BOLremoveRma(itemno) {	
	frm = document.forms["BillOfLading"];
	var es = "document.forms['BillOfLading'].rmaremove" + itemno + ".value='Y'";
	//alert("es=" + es);
	eval(es);
	//alert("0=" + frm.poremove0.value);
	frm.dovalidation.value = "N";
	//alert("0=" + frm.dovalidation.value);
	//alert("b4 submit");
	
	//alert("frm=" + frm);
	validateBOL();
}


function BOLshowUnitHelp() {
	ddrivetip("This is where help would be for commodities.",'#DB2147', 300);
	//alert("not yet implemented");
}
function BOLpop() {
	ddrivetip("Check box to designate if the commodity is a Hazardous Material (as defined in the Department of Transportation Regulations).",'#DB2147', 300);
	//alert("not yet implemented");
}
function BOLpopHover(val_in) {
	var PUMessage = getPUMessage(val_in);
	ddrivetip(PUMessage,'#DB2147', 300);
}
function BOLunPopHover(val_in) {
	hideddrivetip()
	//alert(val_in);
}
function BOLpopLiability() {
	ddrivetip("LME\'s cargo liability is limited to a specified maximum value per pound per distribution package, based on the actual National Motor Freight Classification of the article, for any item that is new.  For new machinery that is uncrated and articles that are previously used or reconditioned, including but not limited to machinery, equipment, implements, parts and household goods, the carrier\’s cargo liability is limited to a value not exceeding $0.10 per pound per distribution package.<BR><BR>(The schedule of liability limitations based on classification is published in the Lakeville Motor Express Rules and Regulations publication; contact your account executive for details.)",'#DB2147', 300);
	//alert("not yet implemented");
}
function BOLnd() {
	
}
function BOLsetClassSelect(namein, val_in) {
	document.write("<select name=\"" + namein + "\">");
	document.write("<option value=\"\">(--)</option>");
	for (var i = 0; i < freightclasses.length; i++) {
		var lineout = "";
		//alert("val_in=" + val_in + ", freightclasses[i]=" + freightclasses[i]);
		if (val_in == freightclasses[i]) {
			lineout = "<option value=\"" + freightclasses[i] + "\" SELECTED>" + freightclasses[i] + "</option>";
		} else {
			lineout = "<option value=\"" + freightclasses[i] + "\">" + freightclasses[i] + "</option>";
		}
		//alert("lineout=" + lineout);
		document.write(lineout);
	}
	document.write("</select>")
}
function BOLshowHideHazMatInfo(numin) {
	frm = document.forms["BillOfLading"];
	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 (eval("frm.bdhmflag" + numin + ".checked") == true) {
			eval(handle+'["'+'hazmat'+ numin + '"]'+stylevar+'.visibility = "visible"');
			eval(handle+'["'+'hazmat'+ numin + '"]'+stylevar+'.display = "block"');
			eval(handle+'["'+'hazmatphone'+ numin + '"]'+stylevar+'.visibility = "visible"');			
		} else {
			eval(handle+'["'+'hazmat'+ numin + '"]'+stylevar+'.visibility = "hidden"');
			eval(handle+'["'+'hazmat'+ numin + '"]'+stylevar+'.display = "none"');
			eval(handle+'["'+'hazmatphone'+ numin + '"]'+stylevar+'.visibility = "hidden"');
		}
		//eval(handle+'["'+'O'+'"]'+stylevar+'.visibility = "hidden"');
	}
	if (isNS6){
		if (eval("frm.bdhmflag" + numin + ".checked") == true) {
			//eval(handle+"('hazmat" + numin +  "')"+ stylevar+'.visibility = "visible"');		
			eval(handle+"('hazmat" + numin +  "')"+ stylevar+'.display = "block"');		
			//eval(handle+"('hazmatphone" + numin + "')"+stylevar+'.visibility = "visible"');	
		} else {
			//eval(handle+"('hazmat" + numin + "')" + numin +stylevar+'.visibility = "hidden"');
			eval(handle+"('hazmat" + numin + "')" + numin +stylevar+'.display = "none"');					
			//eval(handle+"('hazmatphone" + numin + "')" + numin +stylevar+'.visibility = "hidden"');	
		}
		//eval(handle+"('O')"+stylevar+'.visibility = "hidden"');
	}
	if (eval("frm.bdhmflag" + numin + ".checked") == true) {	
		if (frm.blhzphone.value != "") {
			eval("frm.bdhzphone" + numin + ".value=frm.blhzphone.value");
			eval("frm.bdhzphext" + numin + ".value=frm.blhzphext.value");
		}
	}

	
}

function BOLshowHideHazMatInfo2(is, cs) {
	frm = document.forms["BillOfLading"];
	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 (eval("frm.bdhmflag" + is + "_" + cs + ".checked") == true) {
			eval(handle+'["'+'hazmat'+ is + '_' + cs + '"]'+stylevar+'.visibility = "visible"');
			eval(handle+'["'+'hazmat'+ is + '_' + cs + '"]'+stylevar+'.display = "block"');
			//eval(handle+'["'+'hazmatphone'+ is + '_' + cs + '"]'+stylevar+'.visibility = "visible"');			
		} else {
			eval(handle+'["'+'hazmat'+ is + '_' + cs + '"]'+stylevar+'.visibility = "hidden"');
			eval(handle+'["'+'hazmat'+ is + '_' + cs + '"]'+stylevar+'.display = "none"');
			//eval(handle+'["'+'hazmatphone'+ is + '_' + cs + '"]'+stylevar+'.visibility = "hidden"');
		}
		//eval(handle+'["'+'O'+'"]'+stylevar+'.visibility = "hidden"');
	}
	if (isNS6){
		if (eval("frm.bdhmflag" + is + "_" + cs + ".checked") == true) {
			//eval(handle+"('hazmat" + is +  "')"+ stylevar+'.visibility = "visible"');		
			eval(handle+"('hazmat" + is +  "_" + cs + "')"+ stylevar+'.display = "block"');		
			//eval(handle+"('hazmatphone" + is + "_" + cs + "')"+stylevar+'.visibility = "visible"');	
		} else {
			//eval(handle+"('hazmat" + is + "')" + is +stylevar+'.visibility = "hidden"');
			eval(handle+"('hazmat" + is + "_" + cs + "')" + stylevar+'.display = "none"');					
			//eval(handle+"('hazmatphone" + is + "')" + is +stylevar+'.visibility = "hidden"');	
		}
		//eval(handle+"('O')"+stylevar+'.visibility = "hidden"');
	}	
	
	showHideHazMat();
}

function BOLsetHazClassSelect(namein, val_in) {
	//alert("Val in: " + val_in);
	document.write("<select name=\"" + namein + "\" id=\"" + namein + "\">");
	document.write("<option value=\"\">(--)</option>");
	for (var i = 0; i < hazardousclasses.length; i++) {
		var lineout = "";
		if (val_in == hazardousclasses[i]) {
			lineout = "<option value=\"" + hazardousclasses[i] + "\" SELECTED>" + hazardousclassdescs[i] + "</option>";
		} else {
			lineout = "<option value=\"" + hazardousclasses[i] + "\">" + hazardousclassdescs[i] + "</option>";
		}
		//alert("lineout=" + lineout);
		document.write(lineout);
	}
	document.write("</select>")
}
function BOLaddRows() {
	window.open("/BOLAddItems.html","AddItems","Width=400,Height=300");
	
	//var frm = document.forms["BillOfLading"];
	//num = prompt("How many more rows?","1");
}
function BOLAddItemsSubmit() {
	tnum = document.forms[0].num.value;
	var nnum = parseInt(tnum);
	//alert("opener.detailrows=" + opener.detailrows);
	if (isNaN(nnum)) {
		alert("Invalid number");
	} else {
		if ((opener.detailrows + nnum) > opener.maxlines) {
			alert("Maximum number of commodities is " + opener.maxlines);
		} else {
			if (nnum > opener.maxtoadd) {
				alert("You can only add a maximum of " + opener.maxtoadd + " lines at a time.");
			} else {
				opener.document.forms['BillOfLading'].adddetailrows.value = tnum;
				opener.document.forms['BillOfLading'].dovalidation.value = "N";
				opener.validateBOL();
			}
		}
	}
	window.close();
}
function BOLaddPoRows() {
	window.open("/BOLAddPos.html","AddPos","Width=400,Height=300");
	//var frm = document.forms["BillOfLading"];
	//num = prompt("How many more rows?","1");
	//var nnum = parseInt(num);
	//if (isNaN(nnum)) {
	//	alert("Invalid number");
	//	return;
	//} else {
	//	frm.addporows.value = num;
	//	frm.dovalidation.value = "N";
	//	frm.submit();
	//}
}

function BOLaddPackRows(inline) {
	window.open("/BOLAddPack.html?forline=" + inline,"AddPack","Width=400,Height=300");
}

function BOLAddPackSubmit() {
	tnum = document.forms[0].num.value;
	var nnum = parseInt(tnum);
	//alert("opener.detailrows=" + opener.detailrows);
	if (isNaN(nnum)) {
		alert("Invalid number");
	} else {
		//alert("in code");
		//alert(document.forms[0].commlineAdd.value);
		opener.document.forms['BillOfLading'].commPackAdd.value = tnum;
		opener.document.forms['BillOfLading'].commPackLine.value = document.forms[0].commlineAdd.value;
		opener.document.forms['BillOfLading'].dovalidation.value = "N";
		opener.validateBOL();
	}
	window.close();
}

function PRaddDetailRows() {
	
	window.open("/PRAddLineItem.html","addDet","Width=400,Height=300");
	
}


function BOLaddRmaRows() {
	window.open("/BOLAddRmas.html","AddRmas","Width=400,Height=300");
	//var frm = document.forms["BillOfLading"];
	//num = prompt("How many more rows?","1");
	//var nnum = parseInt(num);
	//if (isNaN(nnum)) {
	//	alert("Invalid number");
	//	return;
	//} else {
	//	frm.addporows.value = num;
	//	frm.dovalidation.value = "N";
	//	frm.submit();
	//}
}

function BOLAddPosSubmit() {
	tnum = document.forms[0].num.value;
	var nnum = parseInt(tnum);
	if (isNaN(nnum)) {
		alert("Invalid number");
	} else {
		if (nnum > opener.maxtoadd) {
			alert("You can only add a maximum of " + opener.maxtoadd + " lines at a time.");			
		} else {
			opener.document.forms['BillOfLading'].addporows.value = tnum;
			opener.document.forms['BillOfLading'].dovalidation.value = "N";
			opener.validateBOL();
		}
	}
	window.close();
}

function PRAddDetailSubmit(){
	alert('In PRAddDetailSubmit');
	tnum = document.forms[0].num.value;
	var nnum = parseInt(tnum);
	if (isNaN(nnum)) {
		alert("Invalid number");
	} else {
		if (nnum > opener.maxtoadd) {
			alert("You can only add a maximum of " + opener.maxtoadd + " lines at a time.");			
		} else {
			opener.document.forms['PickupRequest'].adddetrows.value = tnum;
			//opener.document.forms['PickupRequest'].dovalidation.value = "N";
			//opener.validateBOL();
alert('At the end of PRAddDetailSubmit');
		}
	}
	window.close();
}

function BOLAddRmasSubmit() {
	tnum = document.forms[0].num.value;
	var nnum = parseInt(tnum);
	if (isNaN(nnum)) {
		alert("Invalid number");
	} else {
		if (nnum > opener.maxtoadd) {
			alert("You can only add a maximum of " + opener.maxtoadd + " lines at a time.");			
		} else {	
			opener.document.forms['BillOfLading'].addrmarows.value = tnum;
			opener.document.forms['BillOfLading'].dovalidation.value = "N";
			opener.validateBOL();
		}
	}
	window.close();
}
function BOLfinishZipLU() {
	frm = document.forms['BillOfLading'];
	//fname = frm.ziplutype.value;
	//frm.ziplutype.value == '';
	if (zipzipfieldname == "shipzip") {
		frm.shipcity.value = zipcityvalue;
		frm.shipzip.value = zipzipvalue;
		for (var i = 1; i < frm.shipstate.options.length; i++) {
			if (zipstatevalue == frm.shipstate.options[i].value) {
				frm.shipstate.selectedIndex = i;
				break;
			}
		}
		
	} else if (zipzipfieldname == "conszip") {
		frm.conscity.value = zipcityvalue;
		frm.conszip.value = zipzipvalue;
		for (var i = 1; i < frm.consstate.options.length; i++) {
			if (zipstatevalue == frm.consstate.options[i].value) {
				frm.consstate.selectedIndex = i;
				break;
			}
		}

	} else if (zipzipfieldname == "tppzip") {
		frm.tppcity.value = zipcityvalue;
		frm.tppzip.value = zipzipvalue;
		for (var i = 1; i < frm.tppstate.options.length; i++) {
			if (zipstatevalue == frm.tppstate.options[i].value) {
				frm.tppstate.selectedIndex = i;
				break;
			}
		}

	} else if (zipzipfieldname == "codzip") {
		frm.codcity.value = zipcityvalue;
		frm.codzip.value = zipzipvalue;
		for (var i = 1; i < frm.codstate.options.length; i++) {
			if (zipstatevalue == frm.codstate.options[i].value) {
				frm.codstate.selectedIndex = i;
				break;
			}
		}

	}
}
function BOLcodSameAsShipperClick() {
	frm = document.forms['BillOfLading'];
	if (frm.codsameasshipper.checked == true) {
		frm.codname.value = frm.shipname.value;
		frm.codaddress.value = frm.shipaddres.value;
		frm.codcity.value = frm.shipcity.value;
		frm.codzip.value = frm.shipzip.value;
		var ts = frm.shipstate.options[frm.shipstate.selectedIndex].value;
		for (var i = 1; i < frm.codstate.options.length; i++) {
			if (ts == frm.codstate.options[i].value) {
				frm.codstate.selectedIndex = i;
				break;
			}
		}
		var tc = "";
		for (var i = 0; i < frm.shipcntry.length; i++) {
			if (frm.shipcntry[i].checked == true) {
				tc = frm.shipcntry[i].value;
			}
		}
		for (var i = 0; i < frm.codcntry.length; i++) {
			if (frm.codcntry[i].value == tc) {
				frm.codcntry[i].checked = true;
			}
		}
	} else {
		frm.codname.value = "";
		frm.codaddress.value = "";
		frm.codcity.value = "";
		frm.codzip.value = "";
		frm.codstate.selectedIndex = 0;
		for (var i = 0; i < frm.codcntry.length; i++) {
			frm.codcntry[i].checked = false;
		}
	}
}
function BOLCODonBlur() {
	var frm = document.forms['BillOfLading'];
	var tval = frm.codstring.value;
	var iscod = false;
	//alert("tval=" + tval);
	if ((tval != "") && (tval != "0")) {
		iscod = true;
	} else {
		iscod = false;
	}
	if (iscod == true) {
		//alert("tval is true");
		if (frm.codsameasshipper.checked == true) {
			//alert("same as shipper checked");
			BOLcodSameAsShipperClick();
		} else {
		}
	} else {
		frm.codname.value = "";
		frm.codaddress.value = "";
		frm.codcity.value = "";
		frm.codzip.value = "";
		frm.codstate.selectedIndex = 0;
		for (var i = 0; i < frm.codcntry.length; i++) {
			frm.codcntry[i].checked = false;
		}
	}
}
function BOLHazPhoneOrExtonBlur(is) {
	var frm = document.forms['BillOfLading'];
	if ((frm.blhzphone.value != eval('frm.bdhzphone' + is + '.value')) || (frm.blhzphext.value != eval('frm.bdhzphext' + is + '.value'))){
		frm.blhzphone.value = eval('frm.bdhzphone' + is + '.value');
		frm.blhzphext.value = eval('frm.bdhzphext' + is + '.value');
	}
	for (var numin = 0; numin < detailrows; numin++) {
		if (eval("frm.bdhmflag" + numin + ".checked") == true) {	
			eval("frm.bdhzphone" + numin + ".value=frm.blhzphone.value");
			eval("frm.bdhzphext" + numin + ".value=frm.blhzphext.value");
		}
	}
}

function BOLHazPhoneOrExtonBlur2(is, cs) {
	var frm = document.forms['BillOfLading'];
	if ((frm.blhzphone.value != eval('frm.bdhzphone' + is + '_' + cs + '.value')) || (frm.blhzphext.value != eval('frm.bdhzphext' + is + '_' + cs +'.value'))){
		frm.blhzphone.value = eval('frm.bdhzphone' + is + '_' + cs +'.value');
		frm.blhzphext.value = eval('frm.bdhzphext' + is + '_' + cs +'.value');
	}
	
	var currLine = -1;
	for (drow = 0; drow < detailrows; drow++) {
		var dLine = document.getElementById('detailbdline_' + drow).value;
		var i_dLine = parseInt(dLine);
		if (dLine != currLine) {
			currLine = dLine;
			packLine = 1;	
		}
		
		if (eval("frm.bdhmflag" + currLine + "_" + packLine + ".checked") == true) {	
			eval("frm.bdhzphone" + currLine + "_" + packLine  + ".value=frm.blhzphone.value");
			eval("frm.bdhzphext" + currLine + "_" + packLine  + ".value=frm.blhzphext.value");
		}
		
			
		packLine++;
	}
}
//Creating parallel arrays to assist in pop-up lookups
ServCodeArray = new Array(40)
ServCodeArray[0] = "HP"
ServCodeArray[1] = "IP"
ServCodeArray[2] = "LGO"
ServCodeArray[3] = "LAO"
ServCodeArray[4] = "CA"
ServCodeArray[5] = "LAD"
ServCodeArray[6] = "HD"
ServCodeArray[7] = "ID"
ServCodeArray[8] = "LGD"
ServCodeArray[9] = "LAD"
ServCodeArray[10] = "CL"
ServCodeArray[11] = "RDD"
ServCodeArray[12] = "CC"
ServCodeArray[13] = "OD"
ServCodeArray[14] = "DB"
ServCodeArray[15] = "DS"
ServCodeArray[16] = "DT"
ServCodeArray[17] = "FG"
ServCodeArray[18] = "HT"
ServCodeArray[19] = "KP"
ServCodeArray[20] = "NT"
ServCodeArray[21] = "N5"
ServCodeArray[22] = "PF"
ServCodeArray[23] = "PH"
ServCodeArray[24] = "PJ"
ServCodeArray[25] = "PU"
ServCodeArray[26] = "SL"
ServCodeArray[27] = "TP"
ServCodeArray[28] = "WP"
ServCodeArray[29] = "WR"
ServCodeArray[30] = "templateselect"
ServCodeArray[31] = "templatetobedeleted"
ServCodeArray[32] = "bltempname"
ServCodeArray[33] = ""
ServCodeArray[34] = "VL"
ServCodeArray[35] = "HU"
ServCodeArray[36] = "NU"
ServCodeArray[37] = "PackUnits"
ServCodeArray[38] = "PackQuantity"
ServCodeArray[39] = "IQ"

//Replace the following values in quotation marks, with additional information about the services.
PUMessageArray = new Array(40)
PUMessageArray[0] = "Select this if your shipment will be picked up at a private residence, condominium or apartment."
PUMessageArray[1] = "Select when your shipment needs to be picked up from positions not immediately adjacent to the vehicle."
PUMessageArray[2] = "Select if the loading of your freight requires the use of a vehicle equipped with a hydraulic tailgate lift."
PUMessageArray[3] = "Select this if your shipment will be picked up at any of the following (but not limited to) types of locations: Amusement Park, Camp (other than military), Chautauqua, Church, Commercial Establishments (not open to the walk in public during normal business hours), Construction Site (includes areas where building excavating, erecting, construction and road building is carried on), Country Club, Estate, Exhibition, Fair, Farm, Individual (mini) Storage Unit, Military Base or Installation, Mine (site of any pit, excavation shaft or deposit at which coal, ore or minerals is, have been or will be extracted), Other Non-Commercial Site, Prison, Rectory, School, Synagogue, Temple of Worship, Trade Show, Traveling Show."
PUMessageArray[4] = "Select if the consignee requires an appointment be made in order to deliver your shipment."
PUMessageArray[5] = "Select this if your shipment will be delivered to any of the following (but not limited to) types of locations: Amusement Park, Camp (other than military), Chautauqua, Church, Commercial Establishments (not open to the walk in public during normal business hours), Construction Site (includes areas where building excavating, erecting, construction and road building is carried on), Country Club, Estate, Exhibition, Fair, Farm, Individual (mini) Storage Unit, Military Base or Installation, Mine (site of any pit, excavation shaft or deposit at which coal, ore or minerals is, have been or will be extracted), Other Non-Commercial Site, Prison, Rectory, School, Synagogue, Temple of Worship, Trade Show, Traveling Show."
PUMessageArray[6] = "Select this if your shipment will be delivered to a private residence, condominium or apartment."
PUMessageArray[7] = "Select when your shipment needs to be delivered to positions not immediately adjacent to the vehicle."
PUMessageArray[8] = "Select if the unloading of your freight requires the use of a vehicle equipped with a hydraulic tailgate lift."
PUMessageArray[9] = ""
PUMessageArray[10] = "Select if the consignee requires arrival notification before delivery."
PUMessageArray[11] = "You may request that delivery be performed on a specific date. However, no date earlier than the delivering carrier’s service date applicable to the shipment may be specified. This does not constitute a guarantee or a request for guaranteed service, although every effort will be made to accommodate your request."
PUMessageArray[12] = "Select when your shipment requires the entire capacity of the vehicle or the maximum legal weight or size limitations has been reached for the vehicle."
PUMessageArray[13] = "Select when your shipment contains one or more articles measuring in excess of 12 feet."
PUMessageArray[14] = ""
PUMessageArray[15] = ""
PUMessageArray[16] = ""
PUMessageArray[17] = ""
PUMessageArray[18] = ""
PUMessageArray[19] = ""
PUMessageArray[20] = ""
PUMessageArray[21] = ""
PUMessageArray[22] = ""
PUMessageArray[23] = ""
PUMessageArray[24] = ""
PUMessageArray[25] = ""
PUMessageArray[26] = ""
PUMessageArray[27] = ""
PUMessageArray[28] = ""
PUMessageArray[29] = "Select this if the shipment weight is unknown. Your freight will be weighed at a terminal with a certified legal for trade scale."
PUMessageArray[30] = "By selecting a template from this field and then clicking the Use Template button, this BOL form will pre-populate with previously saved values."
PUMessageArray[31] = "By checking the checkbox, the template name enclosed in parenthesis will be deleted when the Create BOL button is clicked."
PUMessageArray[32] = "By entering a name in the field to the right, this BOL will be saved for future use as a template when the Create BOL button is clicked."
PUMessageArray[33] = "Select when the carrier may call the consignee prior to delivery but is not required to do so."
PUMessageArray[34] = "Select this if you are requesting liability coverage in place of the normal Lakeville Motor Express liability limits.  For Complete information on the coverage available and limitations thereto, please refer to the Rules and Accessorial Charges, Item 350, \"Articles of Extraordinary Value, Limitation of Liability, Prohibited or Restricted Articles, Released Value and Full Value Coverage\"." 
PUMessageArray[35] = "Select the type of unit that will be handled.  For example, when shipping a pallet with boxes on it, 'Pallet' should be selected as the Handling Unit - NOT 'Box'"
PUMessageArray[36] = "Enter the number of units that will be handled.  For example, when shipping 2 pallets contains 50 boxes, '2' should be entered as the number of Handling Units - Not '50'"
PUMessageArray[37] = "Select the type of packaging. For example, when shipping a pallet with boxes on it, 'Box' should be selected as the packaging - NOT 'Pallet'"
PUMessageArray[38] = "Enter the number of packages.  For example, when shipping 2 pallets containing 50 boxes, '50' should be entered as the number of Packages - NOT '2'"
PUMessageArray[39] = "Inquiry/quote #'s are generated based on the information you have provided; inquiries/quotes are NOT a guarantee of charges.  All shipments are subject to inspection with actual shipment weight, class, etc. taking precedence.  Rates and charges are also subject to tariffs/rules/contracts/pricing agreements in effect on the date of shipment."

function Trim(s) 
{
  // Remove leading spaces and carriage returns
  
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }

  // Remove trailing spaces and carriage returns

  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}


function getPUMessage(val_in){
	for (var i = 0; i < ServCodeArray.length; i++){
		if (Trim(ServCodeArray[i]) == Trim(val_in)){
			break
		}
	}
	return PUMessageArray[i]
}
function BOLreturnOnLoad() {
	//window.open("/webapp/BillOfLading/PDFBillOfLading.pdf");
	window.open('/webapp/BillOfLading/PDFFileServlet.pdf','BillOfLading');
	//window.open('/webapp/BillOfLading/PDFBillOfLading.pdf','BillOfLading');
	//setTimeout('window.location.replace("/")',3000);
	window.location.replace("/BOLConfirm.html");
}
function BOLdoesAccHaveSub(code_in) {
	for (var i = 0; i < accswithsubcodesarr.length; i++) {
		if (code_in == accswithsubcodesarr[i]) {
			return true;
		}
	}
	return false;
}
function BOLAccClick(code_in) {
	var frm = document.forms['BillOfLading'];
	var elm;
	if (BOLdoesAccHaveSub(code_in) == true) {
		elm = document.getElementById(rtrim(code_in) + "extra");
		var t = eval("frm." + code_in + ".checked");
		if (t == true) {
			elm.style.display = "";
		} else {
			elm.style.display = "none";
		}
	}
	elm = document.getElementById("callinfodiv");
	if (rtrim(code_in) == 'CA') {
		if (frm.CA.checked == true) {
			elm.style.display = "";
		} else {
			elm.style.display = "none";
		}
	}
	if (rtrim(code_in) == 'CL') {
		if (frm.CL.checked == true) {
			elm.style.display = "";
		} else {
			elm.style.display = "none";
		}
	}
	elm = document.getElementById("reqdatediv");
	if (rtrim(code_in) == 'RDD') {
		if (frm.RDD.checked == true) {
			elm.style.display = "";
		} else {
			elm.style.display = "none";
		}
	}
	
}
function BOLDisableBox() {
	BOLDisableDelLocBox();
	BOLDisableCallBox();
}
function BOLDisableDelLocBox(){
	var frm = document.forms['BillOfLading'];
	//if (frm.CSD.checked == true){
	//	frm.HD.disabled = true;
	//}
	//if (frm.CSD.checked == false){
	//	frm.HD.disabled = false;
	//}
	//if (frm.HD.checked == true){
	//	frm.CSD.disabled = true;
	//	}
	//if (frm.HD.checked == false){
	//	frm.CSD.disabled = false;
	//}
}
function BOLDisableCallBox(){
	var frm = document.forms['BillOfLading'];
	if (frm.CA.checked == true){
		frm.CL.disabled = true;
	}
	if (frm.CA.checked == false){
		frm.CL.disabled = false;
	}
	if (frm.CL.checked == true){
		frm.CA.disabled = true;
		}
	if (frm.CL.checked == false){
		frm.CA.disabled = false;
	}
}
function deflectOnClick(ofield, zipf, citf, staf, cval, sval, zval) {

	ofield.blur();
	ZIPstartZipLU('BillOfLading', zipf, citf, staf, cval, sval, zval, 'BOLfinishZipLU()');
	
}
function deflectOnFocus(ofield, nextfield, label) {

	ofield.blur();
	if (ofield.value == "") {
		alert("Please use the link above to choose " + label + " city, state, and zip.");
	} else {
		nextfield.focus();
	}
	
}
function deflectOnFocusSelect(ofield, nextfield, label) {

	ofield.blur();
	if (ofield.selectedIndex < 1) {
		alert("Please use the link above to choose " + label + " city, state, and zip.");
	} else {
		nextfield.focus();
	}
	
}

function clearCSZ(cf, sf, zf) {
	cf.value = "";
	sf.selectedIndex = 0;
	zf.value = "";
}
function BOLsetStateSelectDeflect(namein, nextfieldstring, label, zipf, citf, staf, cvalstring, svalstring, zvalstring) {
	document.write("<select name=\"" + namein + "\" onFocus=\"deflectOnFocusSelect(document.forms[0]." + namein + "," + nextfieldstring + ", '" + label + "');\" onClick=\"deflectOnClick(document.forms[0]." + namein + ", '" + zipf + "', '" + citf + "', '" + staf + "' , " + cvalstring + ", " + svalstring + ", " + zvalstring + ");\">");
	document.write("<option value=\"\">(select state or province)</option>");
	for (var i = 0; i < statenames.length; i++) {
		var lineout = "";
		if (eval(namein) == stateabbrevs[i]) {
			lineout = "<option value=\"" + stateabbrevs[i] + "\" SELECTED>" + statenames[i] + "</option>";
		} else {
			lineout = "<option value=\"" + stateabbrevs[i] + "\">" + statenames[i] + "</option>";
		}
		//alert("lineout=" + lineout);
		document.write(lineout);
	}
	document.write("</select>");
	
}
function BOLsetStateSelect(namein) {
	document.write("<select name=\"" + namein + "\">");
	document.write("<option value=\"\">(select state or province)</option>");
	for (var i = 0; i < statenames.length; i++) {
		var lineout = "";
		if (eval(namein) == stateabbrevs[i]) {
			lineout = "<option value=\"" + stateabbrevs[i] + "\" SELECTED>" + statenames[i] + "</option>";
		} else {
			lineout = "<option value=\"" + stateabbrevs[i] + "\">" + statenames[i] + "</option>";
		}
		//alert("lineout=" + lineout);
		document.write(lineout);
	}
	document.write("</select>");
	
}
function BOLUseTemplate() {
	var frm = document.forms['BillOfLading'];		
	var tval = frm.templateselect.options[frm.templateselect.selectedIndex].value;
	if (tval != "") {
		window.location = "/webapp/BillOfLading/StartServlet" + logonstring + ampersand + ttypestring + ttypenamestring + ampersand + tnamestring + encodeURIComponent(tval);
	} else {
		alert("You must choose a template name.");
	}
}

function convertIt(_a) {
  var _c = _a;
  var _x = _a.indexOf("$");
  if (_x == -1 ) _x = _a.indexOf(",");
  if (_x != -1) {
    var _p1 = _a.substr(0,_x);
	var _p2 = _a.substr(_x+1,_a.length);
    _c = convertIt(_p1+_p2);
  }
  return (_c);
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.$,";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
 }
 
 function showHideHazMat() {
 
 	var drow = 0;
	var currLine = -1;
	var packLine = 0;
	var ele = document.getElementById('hazmatinfo');
	
 	for (drow = 0; drow < detailrows; drow++) {
		var dLine = document.getElementById('detailbdline_' + drow).value;
		var i_dLine = parseInt(dLine);
		if (dLine != currLine) {
			currLine = dLine;
			packLine = 1;
		}
		
		var hazmat = document.getElementById('bdhmflag' + currLine + "_" + packLine).checked;
		if (hazmat) {
			ele.style.display = 'block';
			return true;
		}
		
		packLine++;
	}
	ele.style.display = 'none';
	return false;
	
}

