function billtoDialog(field) {
	var theForm  = document.editForm;
	var theCheck = theForm.elements[field];
	for (cntr=0; cntr < theCheck.length; cntr++) {
		if (theCheck[cntr].checked) {
			if (theCheck[cntr].value == 2 || theCheck[cntr].value == 3) {
				//define config object
				var dialogOpts = {
					bgiframe: true,
					width: 300,
					draggable: false,
					autoOpen: false,
					modal: true,
					closeOnEscape: false
				};
				$(function() {
					$("#dialog").dialog(dialogOpts);
				});
			}
		}
	}
}

function confirmPopup(theUrl, descr) {
	if (confirm('NOTE: You must edit Commodities separately from other Waybill edits.\rIf you have made edits in form fields above, they will be lost.')) {
		openit(theUrl);
	} else {
		return false;
	}
}

function confirmDeleteRecord(aURL, descr) {
	if (confirm('Are you sure you want to Delete this record (' + descr + ')?')) {
		location.href = aURL;
	}
}

if (document.images)  version = "n4";  
else if (navigator.userAgent.indexOf("Mozilla/2.0") != -1) version = "n3";
else version = "n2";
function on_img(imgName) {
	if (version == "n4") {
		img = eval(imgName + "_on.src");
		document [imgName].src = img;
	}
}
function off_img(imgName) {
	if (version == "n4") {
		img = eval(imgName + "_off.src");
		document [imgName].src = img;
	}
}

function message(text) {
	window.status = text;
	return true;
}

function initWtBasisValidate(url,winname) {
	if (!window.beenSeen || window.beenSeen == false) {
		launchSmWin(url,winname);
	}
}

function wtBasisUpd(input,entPrefixChar) {
	var formFinalQty = 10;
	for (var k=1; k<=formFinalQty; k++) {
		var formFieldId = entPrefixChar + "dWtBasis" + k;
		/* var qtyInput = document.getElementById(formFieldId); var qty = qtyInput.value; */
		var fieldToUpd  = document.getElementById(formFieldId);
		fieldToUpd.selectedIndex = input;
		/* fieldToUpd.disabled = true; */
	}
}

function launchSmWin(url,winname) {
	if (!winname) winname = "popWin";
	popWin = window.open(url,winname,"toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,width=300,height=200,left=35,top=30");
	if (!popWin.opener) popWin.opener = self;
	popWin.opener.name = "opener";
	if (navigator.appVersion.indexOf("2.") == -1 && navigator.appVersion.indexOf("MSIE") == -1) popWin.focus();
}

function launchRemote(url,winname) {
	if (!winname) winname = "popWin";
	popWin = window.open(url,winname,"toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,width=599,height=450,left=35,top=30");
	if (!popWin.opener) popWin.opener = self;
	popWin.opener.name = "opener";
	if (navigator.appVersion.indexOf("2.") == -1 && navigator.appVersion.indexOf("MSIE") == -1) popWin.focus();
}

var winOpts = "toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,height=650,width=850,copyhistory=0,"
var smallwindow = null;
function setEvent() {
	return false;
}
function historywin(filename) {
	fileURL = filename;
	if (parseInt(navigator.appVersion) < 4) {
		if (smallwindow != null) smallwindow.close();
	}  
	timerID= setTimeout('opener(fileURL)',100);
}
function windowFocus() {
	if (navigator.appVersion.indexOf("2.") == -1 && navigator.appVersion.indexOf("MSIE") == -1) {
		smallwindow.focus();
	}
}
function openit(winName) {
	filename    = winName;
	winName     = "newWin"
	smallwindow = window.open(filename,winName,winOpts)
	if (navigator.appVersion.indexOf("(X11") != -1  || navigator.appVersion.indexOf("(Mac") != -1) {
		smallwindow = window.open(filename,winName,winOpts)
	}
	if (navigator.appVersion.indexOf("MSIE") == -1) {
		smallwindow.mainWin = this;
	}
	windowFocus();
}

// Autotab Begin
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input, len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if (input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
		input.form[(getIndex(input)+1) % input.form.length].select();
	}
	function containsElement(arr, ele) {
		var found = false, index = 0;
		while (!found && index < arr.length)
			if (arr[index] == ele) found = true;
			else index++;
		return found;
	}
	function getIndex(input) {
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
			if (input.form[i] == input) index = i;
			else i++;
		return index;
	}
	return true;
}
// Autotab End

// dhtml quik-view mouseover
var _x; var _y; var isIE = document.all?true:false;
if (!isIE) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMousePosition;
function getMousePosition(e) {
  if (!isIE) {
    _x = e.pageX;
    _y = e.pageY;
  }
  if (isIE) {
    _x = event.clientX + document.body.scrollLeft;
    _y = event.clientY + document.body.scrollTop;
  }
  // window.status = _x + ' ' + _y
}
function showSpan (val, i) {
	//alert(val)
	document.all.span1.style.left = _x;
	document.all.span1.style.top = _y;
	document.all.span1.innerHTML = val;
	document.all.span1.style.visibility = "visible";
}
function hideSpan () {
	document.all.span1.innerHTML = ""
	document.all.span1.style.visibility = "hidden";
}
function rollAreas(i) {
	//document.OnePhoto.src = aryAreas[i].src;
	showSpan (aryAreaDesc[i], i);
	callTimer('c');
}
function rollOffAreas() {
	callTimer('s');
}
function callTimer(x) {
	if (x == "c") {
		if(typeof(t) != 'undefined') window.clearTimeout(t);
	} else if (x == "s") {
		t = window.setTimeout('hideSpan();', 450);
	}
}
// END dhtml quik-view mouseover

function changeDisplay(theChecked,theWhat) {
	var theNode; var theDisplay;
	/* alert("in changeDisplay. theWhat=" + theWhat + " theChecked = " + theChecked); */
	if (theChecked == true) {
		theDisplay = "";
	} else {
		theDisplay = "none";
	}
	for (var i=1;;i++) {
		// Check if the getElementById method is available
		if (document.getElementById) {
			theNode = document.getElementById(theWhat + i); /* alert(theNode); */
			if (theNode == null) { return; }
		} else if (document.all) {
			/* The alert lets me verify that I tested the path */
			alert("Running an older version of IE." + " May not be able to hide rows");
			theNode = document.all[theWhat+i];
			if (theNode == null){ return; }
		} else {
			alert("Cannot change visibility of the display element." + " Was " + theWhat);
			return;
		}
		theNode.style.display = theDisplay;
	}
}
function changeAll(all) {
	var all = ["pickupOn","delivOn","delivBy"];
	for (var i=0; i < all.length; i++) {
		changeDisplay(false, all[i]);
	}
}