var mAWindowsList = new Array();
var mBOLWindow=null;

function _doDatePriceCompare(y,m,d) {
	var lDate = document.archiveform.dc.value.substr(6,4)+document.archiveform.dc.value.substr(0,2)+document.archiveform.dc.value.substr(3,2);
	document.archiveform.action = document.archiveform.action + "&d=" + lDate;

	document.archiveform.submit();
}

function isInitialHomeScreen() {

	var query = location.search.substring(1); // skip question mark (?)
	var pairs = query.split("&");
	if (pairs.length > 0) {
		var pos = pairs[0].indexOf('=');
		if (pos != -1) {
			if (pairs[0].substring(0,pos).toLowerCase() == "username") {

				return true;
			}
		}
	}

	return false;
}
function focusFirst()
{
	var lPage = getPageName().toLowerCase();
	//status = window.screen.width + ", " + window.screen.height + "  :  " + lPage;
	if (lPage == "usermanagement") {
		window.scrollBy(0,document.SORTFORM.SCROLLDATA.value);
		return;
	} else if (lPage == "checkproducts") {
		checkBIO();
		checkCHECKPRODUCTS(1);
		return;
	} else if (lPage == "corpadminaddui" || lPage == "corpadminupdui") {
		checkIfCorpUser();
	} else if (isInitialHomeScreen() == true) {

		//_openSpecialLetter();
	}
	for(var i=0;i<document.forms.length;++i) {
		for(var j=0;j<document.forms[i].elements.length;++j) {
			if ((document.forms[i].elements[j].type == "text" || document.forms[i].elements[j].type == "textarea") && document.forms[i].elements[j].disabled == false) {
					document.forms[i].elements[j].focus();
					document.forms[i].elements[j].select();
					break;
			}
		}
	}
	////////////////////////////////////////////////////////
}

function checkBIO()
{

	var lFound=0;
	for(var i=0;i<document.forms.length && lFound == 0;++i) {
		for(var j=0;j<document.forms[i].elements.length;++j) {
			if (document.forms[i].elements[j].type == "checkbox") {
				var lID = document.forms[i].elements[j].id;
				if ((lID.indexOf("ULTRA_LOW_DIESEL") != -1 && lID.indexOf("_BIO_") == -1) ||
					(lID.indexOf("WINTER_ULTRA_LOW") != -1)) {
					if (document.forms[i].elements[j].checked) {
						lFound++;
					}
				}
			}
		}
	}
	var lBIOField = document.getElementById("on_BIO_ULTRA_LOW_DIESEL");
	if (lBIOField) {
		if (lFound  == 0) {
			lBIOField.disabled = true;
			lBIOField.checked = false;
		} else {
			lBIOField.disabled = false;
		}
	}
}

function SaveScrollValue(pForm) {
	var lPage = getPageName().toLowerCase();
	if (lPage == "usermanagement") {
		for(var j=0;j<pForm.elements.length;++j) {
			if (pForm.elements[j].name == "username") {
				pForm.elements[j].value = window.document.body.scrollTop;
				break;
			}
		}
	} else {
	}
	return true;
}

function deleteWindows() {
	var lPage = getPageName().toLowerCase();
	if (mAWindowsList && mAWindowsList.length > 0) {
		for (lUID in mAWindowsList) {
			var lWindow = mAWindowsList[lUID];
			if (lWindow.closed == false) {
				lWindow.close();
			}
		}
		mAWindowsList.length = 0;
	}
}

function checkIfCorpUser() {
	var lSubmitButton;

	if (document.CA_FORM) {
		for(var j=0;j<document.CA_FORM.elements.length;++j) {
			if (document.CA_FORM.elements[j].value.toLowerCase() == "select corp users") {
				lSubmitButton = document.CA_FORM.elements[j];
			}
		}

		if (document.CA_FORM.group[1].checked) { // the corp button
			if (lSubmitButton) lSubmitButton.disabled=false;
		} else {
			if (lSubmitButton) lSubmitButton.disabled=true;
		}
	}
}

function clearField() {
	document.NOTE_TYPE.pre.value = "";
}

function checkNoteType(pType) {
	if (document.NOTE_TYPE.lastv.value == pType) {
		return;
	}
	//status = "-" + document.NOTE_TYPE.lastv.value + "- -" + pType + "-";
	if (document.NOTE_TYPE.lastv.value == 1) {
		document.NOTE_TYPE.field1.value = document.NOTE_TYPE.pre.value;
	} else if (document.NOTE_TYPE.lastv.value == 2) {
		document.NOTE_TYPE.field2.value = document.NOTE_TYPE.pre.value;
	} else if (document.NOTE_TYPE.lastv.value == 3) {
		document.NOTE_TYPE.field3.value = document.NOTE_TYPE.pre.value;
	} else if (document.NOTE_TYPE.lastv.value == 4) {
		document.NOTE_TYPE.field4.value = document.NOTE_TYPE.pre.value;
	} else {
		document.NOTE_TYPE.field0.value = document.NOTE_TYPE.pre.value;
	}
	document.NOTE_TYPE.lastv.value = pType;
	if (pType == 1) {
		document.NOTE_TYPE.pre.value = document.NOTE_TYPE.field1.value;
	} else if (pType == 2) {
		document.NOTE_TYPE.pre.value = document.NOTE_TYPE.field2.value;
	} else if (pType == 3) {
		document.NOTE_TYPE.pre.value = document.NOTE_TYPE.field3.value;
	} else if (pType == 4) {
		document.NOTE_TYPE.pre.value = document.NOTE_TYPE.field4.value;
	} else {
		document.NOTE_TYPE.pre.value = document.NOTE_TYPE.field0.value;
	}
}

function checkCHECKPRODUCTS(pType) {
	var lCountSet=0;
	var lSubmitButton;
	var lOptionsIndex=0;
	var lLocationsA = new Array();
	for(var j=0;j<document.CHECKPRODUCTS.elements.length;++j) {
		if (document.CHECKPRODUCTS.elements[j].type.toLowerCase() == "checkbox" && document.CHECKPRODUCTS.elements[j].disabled == false) {
			if (document.CHECKPRODUCTS.elements[j].checked == true) {
				lCountSet++;
				var lID = "H_" + document.CHECKPRODUCTS.elements[j].id;
				var lHiddenElem = document.getElementById(lID);
				if (lHiddenElem) {
					var lAr = lHiddenElem.value.split(',');
					for (var i=0;i < lAr.length;i++) {
						lLocationsA[lOptionsIndex++] = lAr[i];
					}
				}
			}
		} else if (document.CHECKPRODUCTS.elements[j].type.toLowerCase() == "submit") {
			lSubmitButton = document.CHECKPRODUCTS.elements[j];
		}
	}
	if (lCountSet) {
		if (lSubmitButton) lSubmitButton.disabled=false;
		var lSelectedValue = "-NO TERMINAL SELECTED-";
		if (pType == 1) {
			lSelectedValue = document.CHECKPRODUCTS.H_SELECTEDLOCATION.value;
		} else {
			if (document.CHECKPRODUCTS.SelectProdsLoc.selectedIndex == -1) {
				lSelectedValue = "";
			} else {
				lSelectedValue = document.CHECKPRODUCTS.SelectProdsLoc.options[document.CHECKPRODUCTS.SelectProdsLoc.selectedIndex].value;
			}
		}
		document.CHECKPRODUCTS.SelectProdsLoc.options.length=0;

		document.CHECKPRODUCTS.SelectProdsLoc.options[0] = new Option("-NO TERMINAL SELECTED-","-NO TERMINAL SELECTED-");

		if (lLocationsA.length > 0) {
			var lSelectedIndex=-1;

			lLocationsA.sort();
			var lLast=lLocationsA[0];
			var lLastCount = 0;
			lOptionsIndex = 1;

			for (var i=0;i < lLocationsA.length;i++) {
				if (lLocationsA[i] != lLast) {
					if (lLastCount == lCountSet) {
						if (lSelectedValue == lLast) {
							lSelectedIndex=lOptionsIndex;
							document.CHECKPRODUCTS.SelectProdsLoc.options[lOptionsIndex++] = new Option(lLast,lLast,true,true);
						} else {
							document.CHECKPRODUCTS.SelectProdsLoc.options[lOptionsIndex++] = new Option(lLast,lLast);
						}
					}
					lLast = lLocationsA[i];
					lLastCount=1;
				} else {
					lLastCount++;
				}
			}
			if (lLastCount == lCountSet) {
				if (lSelectedValue == lLast) {
					lSelectedIndex=lOptionsIndex;
					document.CHECKPRODUCTS.SelectProdsLoc.options[lOptionsIndex++] = new Option(lLast,lLast,true,true);
				} else {
					document.CHECKPRODUCTS.SelectProdsLoc.options[lOptionsIndex++] = new Option(lLast,lLast);
				}
			}
			if (lSelectedIndex != -1) {
				document.CHECKPRODUCTS.SelectProdsLoc.selectedIndex=lSelectedIndex;
			} else {
				document.CHECKPRODUCTS.SelectProdsLoc.selectedIndex=0;
			}
			//////////////////////////////////////document.CHECKPRODUCTS.SelectProdsLoc.focus();

		}
	} else {
		if (lSubmitButton) lSubmitButton.disabled=true;
		document.CHECKPRODUCTS.SelectProdsLoc.options.length=0;
		document.CHECKPRODUCTS.SelectProdsLoc.options[0] = new Option("-NO TERMINAL SELECTED-","-NO TERMINAL SELECTED-");
		document.CHECKPRODUCTS.SelectProdsLoc.selectedIndex=0;
	}

}

function getPageName() {
	//status = "location = <" + location.search + ">";

	var query = location.search.substring(1); // skip question mark (?)
	var pairs = query.split("&");
	if (pairs.length > 0) {
		var pos = pairs[0].indexOf('=');
		if (pos != -1) {
			if (pairs[0].substring(0,pos).toLowerCase() == "page") {
				return pairs[0].substring(pos+1).toLowerCase();
			}
		}
	}
	return "";
}

function _openSpecialLetter()
{

	if (window.windoid) {
		//windoid('popupFACTAAnnouncement.html','Letter',556,670,'resizable=1,scrollbars=1');
		//windoid('popupSummerGrade2007.html','Letter',556,670,'resizable=1,scrollbars=1');
		//windoid('brokenpump.pdf','Warning',800,800,'resizable=1,scrollbars=1');
		windoid('7108salestaxchanges.htm','Letter',556,670,'resizable=1,scrollbars=1');
	}
}
function _openChristmasScheduleLetter()
{

	if (window.windoid) {
		windoid('popupChristmasSchedule.html','Letter',556,487,'resizable=1,scrollbars=1');
	}
}
function _openPopupSwitchUltraLetter()
{

	if (window.windoid) {
		windoid('popupSwitchToUltraLetter.htm','Letter',556,487,'resizable=1,scrollbars=1');
	}
}
function _openNewUserForm()
{

	if (window.windoid) {
		windoid('table.html','Letter',556,670,'resizable=1,scrollbars=1');
	}
}

function makeNewWindow(pString, pType) {
	var lWindow;
	if (mAWindowsList && mAWindowsList.length > 0) {
		// Both invoices (type-4) and CCards (type-10) use same
		// pString. So we need to distinguish further with pType
		var lVal = pString;
		if (pType == '4' || pType == '10') {
			lVal = lVal + pType;
		}
		for (lUID in mAWindowsList) {
			if (lVal == lUID) {
				lWindow = mAWindowsList[lUID];
				if (lWindow.closed == false) {
					lWindow.focus();
					return;
				}
			}
		}
	}
	var lString;
	var lUID = pString;
	var lHeight = 600;
	var lCustName="";

	if (pType == '1') {
		var pos = pString.indexOf('-');
		if (pos != -1) {
			lUID = pString.substring(0,pos);
			var lCount = pString.substring(pos+1);
			lHeight = 120 + (lCount * 250);
			//status = "PSTRING=" + pString + "  HEIGHT = " + lHeight + " UID= " + lUID;
		}
		if ((window.screen.height-150) < lHeight) {
			lHeight = (window.screen.height-150);
		}
	}

	if (pType == '1' || pType == '8') {
		if (pType == '1') {
			lString = location.protocol + "//" + location.host + "/priceWindow.php?url=" + lUID;
		} else {
			lString = location.protocol + "//" + location.host + "/priceWindow.php?url=" + lUID+"&typ=X";
		}
		var l2 = "scrollbars=1,resizable=1,height=" + lHeight + ",width=360";
		lWindow = window.open(lString,lUID,l2);
	} else if (pType == '2') {
		lString = location.protocol + "//" + location.host + "/priceUpdate.php?url=" + pString;
		lWindow = window.open(lString,pString,"scrollbars=1,resizable=1,height=120,width=700");
	} else if (pType == '3') {
		lString = location.protocol + "//" + location.host + "/taxHistoryUpdate.php?url=" + pString;
		lWindow = window.open(lString,pString,"status,scrollbars=1,resizable=1,height=150,width=600");
	} else if (pType == '4') {
		lString = location.protocol + "//" + location.host + "/index.pl?page=SIIA&CUSTID=" + lUID;
		lWindow = window.open(lString,pString,"scrollbars=1,resizable=1,height=600,width=600");
		pString = pString + pType;
	} else if (pType == '5') {
		lString = location.protocol + "//" + location.host + "/pricePointTool.php?url=" + pString;
		lWindow = window.open(lString,pString,"scrollbars=1,resizable=1,height=540,width=960");
	} else if (pType == '6') {
		lString = location.protocol + "//" + location.host + "/index.php?page=info&NoOutput=1";
		lWindow = window.open(lString,"","scrollbars=1,resizable=1,height=420,width=700");
	} else if (pType == '10') {
		lString = location.protocol + "//" + location.host + "/index.pl?page=SICCA&CUSTID=" + lUID;
		lWindow = window.open(lString,pString,"scrollbars=1,resizable=1,height=600,width=600");
		pString = pString + pType;
	} else if (pType == '11') {
		lString = location.protocol + "//" + location.host + "/scripts/BOL/BOLSwftDisplay.pl";
		lWindow = window.open(lString,pString,"scrollbars=1,resizable=1,height=400,width=800");
		pString = pString + pType;
		mBOLWindow = lWindow;
	} else if (pType == '12') {
		lString = location.protocol + "//" + location.host + "/Fleet/getFleetHTML.pl?id=" + lUID;
		lWindow = window.open(lString,pString,"scrollbars=1,resizable=1,height=500,width=1000");
		pString = pString + pType;
	}
	// use menubar=1 to get at source

	mAWindowsList[pString] = lWindow;


}

// validates that the field value string has one or more characters in it
function isNotEmpty(elem) {
	var str = elem.value;
	var re = /.+/;
	if(!str.match(re)) {
		//alert("Please fill in the required field.");
		//setTimeout("focusElement('" + elem.id + "')", 100);
		return false;
	} else {
		return true;
	}
}
var mCashField = "";
// validates that the entry is formatted as an e-mail address
function isMoneyValue(elem)
{
	var str = elem.value;
	var lNegative = false;
	if (str.length == 0) {
		elem.value = "0.0000";
	} else if (str.charAt(0) == '-') {
		str = str.substr(1);
		lNegative = true;
	}
	if (str.charAt(0) == '.') {
		str = "0" + str;
	} else if (str.charAt(1) != '.') {
		str = "0." + str;
	}
	while (str.length < 6) {
		str = str + "0";
	}

	var re = /^\d\.\d{4}$/;

	if (!re.test(str)) {
		alert("Field must be in format [-]0.0000");
		 _doErr(elem)
	 } else {
		if (lNegative) {
			str = "-"+str;
		}
		elem.value = str;
		if (mCashField.length == 0) {  // only once do we do this
			mCashField = elem.value;
			adjustLikeFields(elem);
		}
	}
}

function focusElement(elemID) {
	var elem = document.getElementById(elemID);
	if (elem) {
		elem.focus();
		elem.select();
	}
}

function findNextFocus(elem) {
	var lFoundindex = -1;
	var lPossibles=0;
	for(var i=0;i<document.forms.length;++i) {
		for(var j=0;j<document.forms[i].elements.length;) {
			if (document.forms[i].elements[j].type == "text" && document.forms[i].elements[j].disabled == false) {
				lPossibles++;
				if (lFoundindex == -1 && document.forms[i].elements[j].id.toLowerCase() == elem.id.toLowerCase()) {
					lFoundindex = j;
				} else if (lFoundindex != -1 && document.forms[i].elements[j].id.toLowerCase() != elem.id.toLowerCase()) {
					document.forms[i].elements[j].focus();
					document.forms[i].elements[j].select();
					break;
				}
				if ((j+1) == document.forms[i].elements.length && lFoundindex != -1 && lPossibles > 1) {
					j = 0;  // reloop one more time
					lPossibles = 0;
				} else {
					++j;
				}
			}
		}
	}
}
///////////////// FOCUSNEXT /////////////////////////
function focusNextOnEnter(evt, elem) {
	evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode :
					((evt.which) ? evt.which : evt.keyCode);
	if (charCode == 13) {
		findNextFocus(elem)
		return false;
	}
	return true;
}

function DoKeyPress(evt) {
	var lPage = getPageName().toLowerCase();
	//status = "Pagename = <" + lPage + ">";
	if (lPage == "usermanagement") {
		evt = (evt) ? evt : event;
		var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
		var chr = String.fromCharCode(charCode).toLowerCase();

		var lSortField = document.SORTFORM.CLICKDATA.value;
		var lSortDirection = lSortField.charAt(0).toLowerCase();
		var lSortField = lSortField.slice(1);
		var lCollection = document.getElementsByName(lSortField);
		var lScroller=0;


		for (var i = 0; i < lCollection.length; i++) {
			if (lSortDirection == 'a') {
				if (lCollection[i].value.charAt(0).toLowerCase() >= chr) {
					lCollection[i].scrollIntoView();
					break;
				}
			} else {
				if (lCollection[i].value.charAt(0).toLowerCase() <= chr) {
					lCollection[i].scrollIntoView();
					break;
				}
			}
		}
		return false;
	} else if (lPage == "viewprices" || lPage == "datedpriceinfo" || lPage == "showpriceinfo" || lPage == "showunbrandedpriceinfo") {
		evt = (evt) ? evt : event;
		var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);

		// 37 is left arrow...39 is right arrow
		if (document.archiveform) {
			if (charCode == 37) {
				document.archiveform.arrow.value = 'd';
				document.archiveform.submit();
				return false;
			} else if (charCode == 39) {
				document.archiveform.arrow.value = 'u';
				document.archiveform.submit();
				return false;
			}
		}
	}
	return true;
}

function changeColor(elemName) {
	elemName.style.color = "ff0000";
	return true;
}

function adjustLikeFields(elem) {
	for(var i=0;i<document.forms.length;++i) {
		for(var j=0;j<document.forms[i].elements.length;++j) {
			if (document.forms[i].elements[j].id.toLowerCase() != elem.id.toLowerCase()) {
				if (document.forms[i].elements[j].type == "text" && document.forms[i].elements[j].disabled == false) {
					var lName = document.forms[i].elements[j].id.toLowerCase();
					var l1 = lName.substring(0,3);
					var l2 = lName.substring(lName.length-4,4); ////???????????????? should this be substring or substr
					//////// In this case start with id_ and end with cash
					if (lName.substring(0,3) == "id_" && lName.substring(lName.length-4,lName.length) == "cash") {
						document.forms[i].elements[j].value = elem.value;
					}
				}
			}
		}
	}
}

// validates that the entry is formatted as an e-mail address. Is used.
function isEMailAddr(elem) {
	var str = elem.value;
	if (str.length > 0) {
		var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
		if (!str.match(re)) {
			changeColor(elem);
			alert("Please correct required field : " + elem.name);
			setTimeout("focusElement('" + elem.id + "')", 200);
			return false;
		}
	}
	elem.style.color = "000000";
	return true;
}
// Used in editTaxes and modUser
function checkMoneyField(evt, elem) {
	var evt = (evt) ? evt : (window.event) ? window.event : "";
	var lRC = false;
	var theVal = elem.value;
	if (document.selection) {  // if IE
		var theR = document.selection.createRange();
		window.status="document.selection:  '"+theR.startOffset+"', '"+theR.endOffset+"'";
		var theSel = document.selection.createRange().text;
	} else if (window.getSelection) {
		var theSel = window.getSelection();
		window.status="document.getSelection:  '"+theSel+"'";
	}
	// if whole field selected then it's as if the field were blank...right?
	if (theSel == theVal) theVal = "";
	if (evt) {
		var theKey = (evt.which) ? evt.which : evt.keyCode
		if (theKey < 32) { // if enter is treated as tab
			/*if (theKey == 13) {
				findNextFocus(elem)
				return false;
			}*/
			lRC = true;
		} else if (theKey == 45 || theKey == 46) {
			lRC = true;
		} else if (theKey >= 48 && theKey <= 57) {
			lRC = true;
		}
	}
	return lRC;
}
//////// CLICKSORT  ////// Used by usermanagement
function clickSort(f1) {
	document.SORTFORM.CLICKDATA.value=f1;
	document.SORTFORM.submit();
}
function clickSave(f1) {
	document.SORTFORM.CLICKDATA.value=f1;
}
function doSubmitPrices()
{
	var lDate = document.archiveform.dc.value.substr(6,4)+document.archiveform.dc.value.substr(0,2)+document.archiveform.dc.value.substr(3,2);
	document.archiveform.action = document.archiveform.action + "&d=" + lDate;
	return true;
}
function _doSkipToTaxes()
{
	document.MODUSER.action = "/index.php?page=muf&NoOutput=1&nextpage=editTaxes";
	document.MODUSER.submit();
}

function toggleBrUn(evt) {
	evt = (evt) ? evt : event;


	var target = (evt.target) ? evt.target : evt.srcElement;
	var block1 = document.getElementById("ID_Branded");
	var block2 = document.getElementById("ID_Unbranded");
	var block3 = document.getElementById("ID_411");
	//status = "BLOCKS = <" + block1 + "," + block2 + "," + block3 + ">";
	if (block1 && block2) {
		if (target.value == "1") {
			block1.style.display = "block";
			block2.style.display = "none";
			if (block3) {
				block3.disabled=false;
			}
		} else {
			block2.style.display = "block";
			block1.style.display = "none";
			if (block3) {
				block3.checked=false;
				block3.disabled=true;
			}
		}
	}
}
function numeralsOnly(evt) {
	evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode :
		((evt.which) ? evt.which : 0));
	if (charCode > 31 && (charCode < 48 || charCode > 57)) {
		alert("Enter numerals only in this field.");
		return false;
	}
	return true;
}
function checkForDate(evt) {
	evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode :
		((evt.which) ? evt.which : 0));
	if (charCode > 31 && (charCode < 47 || charCode > 57)) {
		alert("Enter numerals or slash only in this field.");
		return false;
	}
	return true;
}

function checkDateOnChg(fld) {
	var mo, day, yr;
	var entry = fld.value;
	if (entry == "") {
		fld.style.color = "000000";
		status = "";
		return true;
	}

	var lRC="";
	var re = /\b\d{4}[\/-]\d{1,2}[\/-]\d{1,2}\b/;
	if (re.test(entry)) {
		var delimChar = (entry.indexOf("/") != -1) ? "/" : "-";
		var delim1 = entry.indexOf(delimChar);
		var delim2 = entry.lastIndexOf(delimChar);
		yr = parseInt(entry.substring(0, delim1), 10);
		mo = parseInt(entry.substring(delim1+1, delim2), 10);
		day = parseInt(entry.substring(delim2+1), 10);
		var testDate = new Date(yr, mo-1, day);
		if (testDate.getDate() == day) {
			if (testDate.getMonth() + 1 == mo) {
				if (testDate.getFullYear() == yr) {
					var dd = day.toString(10);
					if (dd.length == 1) {
						dd = "0" + dd;
					}
					var mm = mo.toString(10);
					if (mm.length == 1) {
						mm = "0" + mm;
					}
					fld.value = yr + "/" + mm + "/" + dd;
					fld.style.color = "000000";
					status = "";
					return true;
				} else {
					lRC = "There is a problem with the year entry.";
				}
			} else {
				lRC = "There is a problem with the month entry.";
			}
		} else {
			lRC = "There is a problem with the day entry.";
		}
	} else {
		lRC = "Incorrect date format. Enter as yyyy/mm/dd.";

	}
	if (lRC != "") {
		status = lRC;
		alert(lRC);
	}
	_doErr(fld);
	return false;
}

function _doErr(elem) {
	_changeColor(elem);
	setTimeout("focusElement('" + elem.id + "')", 50);
}
function _changeColor(elemName) {
	elemName.style.color = "ff0000";
	return true;
}

function _changePW()
{
	var lValue = document.login.login_name.value;
	if (lValue.length == 0) {
		alert("Need value in Username field to retrieve new password");
	} else {
		input_box=confirm("Are you sure you wish to Change Password?");
		if (input_box==true) {
			_getAJAXData(location.protocol + "//" + location.host + "/ajaxcp.pl?uc="+lValue);
		}
	}

}


function _getAJAXData(dataSource)
{
	window.status= " DOING: "+dataSource;
	var XMLHttpRequestObject = false;
	if (window.XMLHttpRequest) {
		XMLHttpRequestObject = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if(XMLHttpRequestObject) {
		XMLHttpRequestObject.open("GET", dataSource);
		XMLHttpRequestObject.onreadystatechange = function() {
			if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {
				var lResponse = XMLHttpRequestObject.responseText;
				delete XMLHttpRequestObject;
				XMLHttpRequestObject = null;
				alert(lResponse);
			}
		}

		XMLHttpRequestObject.send(null);
	}
}


function caretPos(elem)
{
	var i=elem.value.length+1;
	if (elem.createTextRange) {
		theCaret = document.selection.createRange().duplicate();
		while (theCaret.parentElement() == elem && theCaret.move("character",1) == 1) {
			--i;
		}
	}
	return i==elem.value.length+1?-1:i;
}

function _doBOLCloseWindow()
{
	window.status="Doing close window";
	if (mBOLWindow) {
		mBOLWindow.close();
		mBOLWindow = null;
	}
}

function _rerunBatchExportPrn()
{
	_getAJAXData("scripts/rerunBatchExportPrn.pl");
}

function _rerunDaily(pTaskRegex)
{
	window.status="Doing _rerunDaily";
	_getAJAXData("scripts/rerunScheduledTasks.pl?tsk="+pTaskRegex);
}

