function lockfield(elmntA,elmntB)
{
	if(document.getElementById(elmntA).checked == true)
	{
		document.getElementById(elmntB).disabled = true;
	}
	else
	{
		document.getElementById(elmntB).disabled = false;
	}
}

function switchIt(elmnt)
{
	if(document.getElementById(elmnt).style.display=="none")
	{ document.getElementById(elmnt).style.display="block"; }
	else
	{ document.getElementById(elmnt).style.display="none"; }
}


// $Header: jscripts/common.js 1.11 2005/09/12 11:38:44PDT blgerrar Ready  $
// General JavaScript Routines
// Copyright(c) Sage Software, Inc. 1988-2005. All rights reserved.

// Semantic and other general lazy errors fixed by Roger Ondra


function SetForms() {
// Set initial display of check boxes and list boxes
// This function should be placed in the body tag with the onLoad event handler
// The value of the preceding object in the form is used to set the value of the check box or list box.
// For a check box, when this value is "Y", the checked property of the check box is set to true.
// For a list box, when this value is encountered as one of the select options, the options selected property is set to true.

	var form_num = document.forms.length;
	var cbTest = "checkbox";
	var lbTest = "select-one";
	if (form_num >= 0 ) {
		for (var f=0; f < form_num; f++) {
			var form = window.document.forms[f];
			for (var i=0; i < form.elements.length; i++) {
				var testval = form.elements[i].type;
				var InitVal = form.elements[i-1].value;
				if (testval == cbTest) {
					if (InitVal == "Y") { form.elements[i].checked = true; } 
				} // end of check box if
				else if (testval == lbTest) {
					for (var o=0; o < form.elements[i].options.length; o++) {
						if (form.elements[i].options[o].value == InitVal) {
						form.elements[i].options[o].selected = true;
						} // end of lb options if
					} // end of for to loop thru LB options
				} // end of list box if
			} // end of for to loop thru form elements
		} // end of for to loop thru forms
	} // end of main if
	return;
} // end of function


function submitFormOld (thisForm, btnName, btnValue, skipRequired) { // OLD //
// Generic submit a form via an HREF link tag:
// i.e. <a href="javascript:submitForm('formname','buttonname','buttonvalue')">Submit Form</a>
// or a button input tag:
// i.e. <input type="button" name="submit" value="Submit Form"
// onClick="submitForm('formname','buttonname','buttonvalue')">
// Add a <input type="hidden" name="FormIOL" value=""> field to the form to use the IOL building feature.

	retVal = true

	if (skipRequired != true) {
		retVal = CheckRequired(eval(thisForm))
	}

	if (retVal && eval("document." + thisForm + ".FormIOL")) { // if FormIOL hidden field exists
		// load form element names into CSV FormIOL field
		var formname = eval(thisForm);
		var iol = '';
		for (var i=0; i<formname.length; i++) {
			element = formname.elements[i];
			if (element.name != '') { iol += element.name + ',' }
		}

		eval("document." + thisForm + ".FormIOL.value = '" + iol + "'");
    }

	if (retVal) {
		if (btnName != "") {
			eval("document." + thisForm + "." + btnName + ".value = '" + btnValue + "'");
		}
		eval("document." + thisForm + ".submit()");
	}
}

function submitForm (thisForm, btnName, btnValue, skipRequired) {
// Generic submit a form via an HREF link tag:
// i.e. <a href="javascript:submitForm('formname','buttonname','buttonvalue')">Submit Form</a>
// or a button input tag:
// i.e. <input type="button" name="submit" value="Submit Form"
// onClick="submitForm('formname','buttonname','buttonvalue')">
// Add a <input type="hidden" name="FormIOL" value=""> field to the form to use the IOL building feature.

	retVal = true;

	if (skipRequired != true)
	{
		if(document.getElementById(thisForm)==null)
		{ retVal = CheckRequired(eval(thisForm)); }
		else
		{ retVal = CheckRequired(document.getElementById(thisForm)); }
	}

	if(retVal && eval("document." + thisForm + ".FormIOL")) // if FormIOL hidden field exists
	{
		// load form element names into CSV FormIOL field
		var formname;
		if(document.getElementById(thisForm)==null)
		{ formname = eval(thisForm); }
		else
		{ formname = document.getElementById(thisForm); }
		var iol = '';
		for (var i=0; i<formname.length; i++)
		{
			element = formname.elements[i];
			if (element.name != '')
			{ iol += element.name + ','; }
		}

		if(document.getElementById("FormIOL")==null)
		{ eval("document." + thisForm + ".FormIOL.value = '" + iol + "'"); }
		else
		{ document.getElementById("FormIOL").value = iol; }
    }

	if (retVal) {
		if (btnName !== "") {
			if(document.getElementById(btnName)==null)
			{ eval("document." + thisForm + "." + btnName + ".value = '" + btnValue + "'"); }
			else
			{ document.getElementById(btnName).value=btnValue; }
		}
		if(document.getElementById(thisForm)==null)
		{ eval("document." + thisForm + ".submit()"); }
		else
		{ document.getElementById(thisForm).submit(); }
	}
}



function ValidFileName(elmnt, suffixExt, makeUpper) {
// Make sure a file has an extension of some sort

	var gField;

	if(document.getElementById(elmnt)!==null)
	{ gField = document.getElementById(elmnt); }
	else
	{ gField = elmnt; }

	var newStr = gField.value;
	if (newStr.indexOf(".") < 0) {
		newStr += suffixExt;
	}
	if (makeUpper == 1) { gField.value = newStr.toUpperCase(); }
	if (makeUpper == 2) { gField.value = newStr.toLowerCase(); }
	if (makeUpper <= 0) { gField.value = newStr; }
}


function GetToday(gField, delim, y2kYear, yrDisp) {
// If a null value is set, replace null with today's date formatted
// with specified delimiter

	var testVar = gField.value;
	if (testVar === ""){
		var thisDate = new Date();
		var toDay = thisDate.toLocaleString();
		myArray = toDay.split(" ");
		toDay = myArray[0];
		gField.value = toDay;
		ValidDate(gField,delim, y2kYear, yrDisp);
	}
}

/**
 * Loop through all objects of form and validate objects with ID="REQUIRED" and that there is a value available.
 * @param {Object} thisForm Name of form to check.
 */
function CheckRequiredOLD(thisForm) {
// Loop through all objects of form and validate objects with ID="REQUIRED"
// and that there is a value available.

	var crLf = String.fromCharCode(13,10);
	errMsg = "";
	pass = true;
	find = 0;
	
	for (k=1; k < thisForm.length; k++){
		var tempobj = thisForm.elements[k];
		nameVal = NameToEnglish(tempobj.name);

		if (tempobj.id && tempobj.id.toUpperCase() == "REQUIRED"){
			if ((tempobj.type == "text" || tempobj.type == "textarea" || tempobj.type == "password" || tempobj.type == "hidden") && (tempobj.value === "")){
			// Check text boxes, text area boxes, and password boxes.
				pass = false;
				find += 1;
				errMsg += "     " + nameVal + crLf;
			}
			if (tempobj.type.toString().charAt(0) == "s" && tempobj.selectedIndex <= 0){
			// Check select boxes.
				pass = false;
				find += 1;
				errMsg += "     " + nameVal + crLf;
			}
			if (tempobj.type.toString().charAt(0) == "c" && tempobj.checked <= 0){
			// Check check boxes.
				pass = false;
				find += 1;
				errMsg += "     " + nameVal + crLf;
			}
		}
	}
	if (find > 1){
		errMsg = "Required Fields:" + crLf + errMsg;
	} else {
		errMsg = "Required Field:" + crLf + errMsg;
	}
	if (pass === false){
		alert(errMsg);
	}
	return pass;
}



/**
 * Loop through all objects of form and validate objects with ID="REQUIRED" and that there is a value available.
 * @param {Object} thisForm Name of form to check.
 */
function CheckRequired(getForm) {
// Loop through all objects of form and validate objects with CLASS="REQUIRED"
// and that there is a value available.

	var crLf = String.fromCharCode(13,10);
	errMsg = "";
	pass = true;
	find = 0;

	var thisForm;

	if(document.getElementById(getForm)!==null)
	{ thisForm = document.getElementById(getForm); }
	else
	{ thisForm = getForm; }

	for (k=1; k < thisForm.length; k++){
		var tempobj = thisForm.elements[k];
		nameVal = NameToEnglish(tempobj.name);

		if (tempobj.className && tempobj.className.toUpperCase() == "REQUIRED"){
			if ((tempobj.type == "text" || tempobj.type == "textarea" || tempobj.type == "password" || tempobj.type == "hidden") && (tempobj.value === "")){
			// Check text boxes, text area boxes, and password boxes.
				pass = false;
				find += 1;
				errMsg += "     " + nameVal + crLf;
			}
			if (tempobj.type.toString().charAt(0) == "s" && tempobj.selectedIndex <= 0){
			// Check select boxes.
				pass = false;
				find += 1;
				errMsg += "     " + nameVal + crLf;
			}
			if (tempobj.type.toString().charAt(0) == "c" && tempobj.checked <= 0){
			// Check check boxes.
				pass = false;
				find += 1;
				errMsg += "     " + nameVal + crLf;
			}
		}
	}
	if (find > 1){
		errMsg = "Required Fields:" + crLf + errMsg;
	} else {
		errMsg = "Required Field:" + crLf + errMsg;
	}
	if (pass === false){
		alert(errMsg);
	}
	return pass;
}


function NameToEnglish(nameIn) {
// convert field name to psuedo English format

	nameOut = nameIn;

	if (nameOut.indexOf("_")==-1) {	// no underscores, insert space before uppercase chars
		nameOut = nameOut.replace(/([A-Z])/g, " $1");
	} else {  // contains underscore(s), replace "_" with space and proper case string
		nameOut = ReplaceString(nameOut,"_"," ");
		wordArray = nameOut.split(/\s+/);
		for (c=0; c < wordArray.length; c++){
			wordArray[c] = wordArray[c].substr(0,1).toUpperCase() + wordArray[c].substr(1).toLowerCase();
		}
		nameOut = wordArray.join(" ");
	}

	// remove any spaces from beginning of string
	nameOut = nameOut.replace(/^\s*(.*)/, "$1");

	return nameOut;
}

function IsRequired(elmnt) {
// Validate single field.

	var gField;

	if(document.getElementById(elmnt)!==null)
	{ gField = document.getElementById(elmnt); }
	else
	{ gField = elmnt; }


	var pass = true;
	fName = FmtAlpha(elmnt,"3");
	if (gField.value === ""){
		alert(fName + " is required.");
		gField.focus();
		gField.select();
		pass = false;
	}
	return pass;
}


function ReplaceString(strData, lookFor, replaceWith) {
// Replace all occurances of a substring with a specified substring
// within the data object.

	newStr = "";
	var testStr = strData;
	if (testStr.indexOf(lookFor) != -1) {
		myArray = testStr.split(lookFor);
		for (i=0; i < myArray.length; i++){
			if (i != myArray.length-1){
				newStr += myArray[i] + replaceWith;
			} else {
				newStr += myArray[i];
			}
		}
		return newStr;
	} else {
		return strData;
	}
}


function FmtAlpha(strData, fmtCode) {
// Format a string to either 1-Uppercase, 2-Lowercase, or 3-Titlecase

	if (fmtCode == "1"){
		strData = strData.toUpperCase();
		return strData;
	}
	if (fmtCode == "2"){
		strData = strData.toLowerCase();
		return strData;
	}
	if (fmtCode == "3"){
		newStr = "";
		newStr = ReplaceString(strData,"_"," ");
		strData = newStr;
		newStr = strData.toLowerCase();
		strData = newStr;
		newStr = "";
		max = strData.length;
		for (i=0; i < max; i++){
			if (i === 0 || strData.substr(i-1,1) == " "){
				newStr += strData.substr(i,1).toUpperCase();
			} else {
				newStr += strData.substr(i,1);
			}
		}
	}
	return newStr;
}


function FmtPhone(elmnt) {

	var gField;

	if(document.getElementById(elmnt)!==null)
	{
		gField = document.getElementById(elmnt);
	}
	else
	{
		gField = elmnt;
	}

	var crLf = String.fromCharCode(13,10);
	testVar = gField.value;
	if (testVar.length > 0){
		testVar = ReplaceString(testVar,"(","");
		testVar = ReplaceString(testVar,")","");
		testVar = ReplaceString(testVar,"-","");
		testVar = ReplaceString(testVar," ","");
		testVar = ReplaceString(testVar,".","");
		testVar = ReplaceString(testVar,"+","");
		testVar = ReplaceString(testVar,"/","");
		if (testVar.length > 10){
			return;
		}
		if (testVar.length < 10 && testVar.length < 7){
			alert("An insufficient number of characters has been entered or" + crLf + "the data entered was in the wrong format.");
			gField.focus();
			gField.select();
		} else {
			if (testVar.length == 10){
				testVar = "(" + testVar.substr(0,3) + ") " + testVar.substr(3,3) + "-" + testVar.substr(6);
			}
			if (testVar.length == 7){
				testVar = testVar.substr(0,3) + "-" + testVar.substr(3,4);
			}
			gField.value = testVar;
		}
	}
	return true;
}

function FmtQty(elmnt,qtyDec,maxQty) {

	var gField;

	if(document.getElementById(elmnt)!==null)
	{
		gField = document.getElementById(elmnt);
	}
	else
	{
		gField = elmnt;
	}


	var qtyVal = gField.value;
	var regexp = / /g;
	qtyVal = qtyVal.replace(regexp,""); // remove spaces
	regexp = /,/g;
	qtyVal = qtyVal.replace(regexp,""); // remove commas

	if (qtyVal === "") {
		qtyVal = "0";
	}

	var pass = true;
	var numVal = parseFloat(qtyVal);

	var doubledec = /\.\./g; // check for double decimals
	var singledec = /\./g; // check for multiple single decimals
	var singleCount = 0;

	singleResult = qtyVal.match(singledec);
	if (singleResult) {
		singleCount = singleResult.length;
	}

	if (qtyVal.match(doubledec) || singleCount>1 || isNaN(numVal) || numVal<0) {
		alert ("Quantity must be numeric and cannot be less than zero.");
		pass = false;
	} else {
		if (numVal >= maxQty) {
			alert ("Quantity entered exceeds maximum quantity allowed.\n" +
					"Quantity has been changed to maximum allowed.");
			numVal = maxQty-1;
			pass = false;
		}
		var str = "" + Math.round(eval(numVal) * Math.pow(10,qtyDec));
		if (qtyDec > 0) { // format number with decimal
			while (str.length <= qtyDec) { str = "0" + str; }
			var decPoint = str.length - qtyDec;
			numVal = str.substring(0,decPoint) + "." + str.substring(decPoint,str.length);
		} else {
			numVal = str;
		}
		gField.value = numVal;
	}
	
	if (pass === false) {
		gField.focus();
		gField.select();
	}

	return pass;
}


function ValidDate(elmnt, delim, y2kYear, yrDisp) {
// Validate date and format date with specified delimiters. Date can be
// space, dash, period, or slash delimited. Dates are returned as
// MMDDYYYY or MMDDYY depending on the parameter passed in yrDisp.
//
//   yrDisp = C = MMDDYYYY
//   yrDisp = Y = MMDDYY

	var gField;

	if(document.getElementById(elmnt)!==null)
	{
		gField = document.getElementById(elmnt);
	}
	else
	{
		gField = elmnt;
	}

	if (gField.value == "") {
		return;
	}

	// convert hyphen,space,period delimiters to specified date delimiter
	var inputStr = gField.value;
	newStr = "";
	newStr = ReplaceString(inputStr,"-",delim);
	inputStr = newStr;
	newStr = ReplaceString(inputStr," ",delim);
	inputStr = newStr;
	newStr = ReplaceString(inputStr,".",delim);
	inputStr = newStr;
	var delim1 = inputStr.indexOf(delim);
	var delim2 = inputStr.lastIndexOf(delim);
	if (delim1 != -1) {
	// there are delimiters; extract component values
		var mm = parseInt(inputStr.substring(0,delim1),10);
		var dd = parseInt(inputStr.substring(delim1 + 1,delim2),10);
		var yyyy = parseInt(inputStr.substring(delim2 + 1, inputStr.length),10);
	} else {
	// there are no delimiters; extract component values
		var mm = parseInt(inputStr.substring(0,2),10);
		var dd = parseInt(inputStr.substring(2,4),10);
		var yyyy = parseInt(inputStr.substring(4,inputStr.length),10);
	}
	if (isNaN(mm) || isNaN(dd) || isNaN(yyyy)) {
	// there is a non-numeric character in one of the component values
		alert("The date entry is not in an acceptable format.\n\nYou can enter dates in the following formats: mmddyyyy, mm/dd/yyyy, mm dd yyyy or mm-dd-yyyy.");
		gField.value = "";
		gField.focus();
		gField.select();
		return false;
	}
	if (mm < 1 || mm > 12) {
	// month value is not 1 thru 12
		alert("Months must be entered between the range of 01 (January) and 12 (December).");
		gField.value = "";
		gField.focus();
		gField.select();
		return false;
	}
	// validate year
	if (yyyy < 100) {
	// entered value is two digits
		if (yyyy > y2kYear) {
			yyyy += 1900;
		} else {
			yyyy += 2000;
		}
	}
	var today = new Date();
	// If day exceed highest day of month, set to highest day of month
	var monthMax = new Array(31,31,29,31,30,31,30,31,31,30,31,30,31);
	mMax = monthMax[mm];
	if (dd > mMax){
		dd = monthMax[mm];
	}
	// Adjust day of February for leap years
	if (mm == 2 && dd >= 29) {
		dd = (((yyyy %4 === 0) && ((!(yyyy % 100 === 0)) || (yyyy % 400 === 0))) ? 29 : 28);
	}
	// Format MM and DD with preceeding "0"s
	mm = mm.toString();
	if (mm.length != 2){
		mm = "0" + mm;
	}
	dd = dd.toString();
	if (dd.length != 2){
		dd = "0" + dd;
	}
	// Format the year based on the yrDisp value. "Y" = 2 digit year.
	yyyy = yyyy.toString();
	if (yrDisp == "Y"){
		yyyy = yyyy.substr(2,2);
	}
	gField.value = mm + delim + dd + delim + yyyy.toString();
	return true;
}


function DateIsLater(lgDate, smDate, y2kYear) {
// Check two date fields and verify that the lgDate is LATER than
// smDate, Null lgDate = last, Null smDate = first.

	quote = '"';
	if (lgDate.length < 1){
		return true;
	}
	if (smDate.length < 1){
		return true;
	}
	var largeDt = lgDate.value;
	var smallDt = smDate.value;
	pass = true;
	if (largeDt.length != 10){
		delim = largeDt.substr(2,1);
		yrVar = largeDt.substr(6,2);
		mmVar = largeDt.substr(0,2);
		dyVar = largeDt.substr(3,2);
		// entered value is two digits
		if (yrVar > y2kYear){
			yrVar = 1900 + parseInt(yrVar,8); // FNORD! 8
		} else {
			yrVar = 2000 + parseInt(yrVar,8); // FNORD! 8
		}
		largeDt = mmVar + delim + dyVar + delim + yrVar;
	}
	if (smallDt.length != 10){
		delim = smallDt.substr(2,1);
		yrVar = smallDt.substr(6,2);
		mmVar = smallDt.substr(0,2);
		dyVar = smallDt.substr(3,2);
		// entered value is two digits
		if (yrVar > y2kYear) {
			yrVar = 1900 + parseInt(yrVar,8); // FNORD! 8
		} else {
			yrVar = 2000 + parseInt(yrVar,8); // FNORD! 8
		}
		smallDt = mmVar + delim + dyVar + delim + yrVar;
	}
	largeDt = largeDt.substr(6,4) + largeDt.substr(0,2) + largeDt.substr(3,2);
	smallDt = smallDt.substr(6,4) + smallDt.substr(0,2) + smallDt.substr(3,2);
	if (largeDt < smallDt){
		alert("The ending date must be later than or equal to the starting date.");
		lgDate.focus();
		lgDate.select();
		pass = false;
	}
	return pass;
}


function CheckMin(elmnt, minLeng) {

	var gField;

	if(document.getElementById(elmnt)!==null)
	{
		gField = document.getElementById(elmnt);
	}
	else
	{
		gField = elmnt;
	}

	quote = '"';
	pass = true;
	testVal = gField.value;
	if (testVal.length < minLeng){
		nameVal = gField.name;
		nameVal = ReplaceString(nameVal,"_"," ");
		wordArray = nameVal.split(" ");
		for (c=0; c < wordArray.length; c++){
			wordArray[c] = wordArray[c].substr(0,1).toUpperCase() + wordArray[c].substr(1).toLowerCase();
		}
		nameVal = wordArray.join(" ");
		alert(nameVal + " requires a minimum of " + quote + minLeng + quote + " characters/numbers.");
		pass = false;
		gField.focus();
		gField.select();
	}
	return pass;
}


function FieldIsLarger(lgField, smField) {
// Check two fields and verify that the lgField is LARGER than
// smField.

	pass = true;
	quote = '"';
	if (lgField.length < 1)
	{
		return true;
	}
	var largeFd = lgField.value;
	var smallFd = smField.value;
	if (largeFd < smallFd)
	{
		alert('The ending document number must be greater than' + String.fromCharCode(13) + 'or equal to the beginning document number.');
		lgField.focus();
		lgField.select();
		pass = false;
	}
	return pass;
}


function PadNumStr(elmnt, fieldLen) {
// Add required number of padding zeros to the left to numeric strings.

	var gField;

	if(document.getElementById(elmnt)!==null)
	{
		gField = document.getElementById(elmnt);
	}
	else
	{
		gField = elmnt;
	}

	fieldVal = gField.value;
	if (fieldVal.length < 1){
		return true;
	}
	if (isNaN(fieldVal)){
		gField.value = fieldVal;
		return true;
	}
	noOfTimes = fieldLen - fieldVal.length;
	for (var cntr = 1; cntr <= noOfTimes; cntr++){
		fieldVal = '0' + fieldVal;
	}
	gField.value = fieldVal;
	return true;
}


function Mas90PadStr(elmnt, fieldLen) {
// Add required number of padding zeros to the left to numeric strings.
// If the value is an alphanumeric value, the field is converted to upper case.

	var gField;

	if(document.getElementById(elmnt)!==null)
	{
		gField = document.getElementById(elmnt);
	}
	else
	{
		gField = elmnt;
	}

	fieldVal = gField.value;
	tmpVal = '';
	if (fieldVal.length < 1) {
		return true;
	}
	if (isNaN(fieldVal)) {
		tmpVal = FmtAlpha(fieldVal,'1');
		fieldVal = tmpVal;
		gField.value = fieldVal;
		return true;
	}
	noOfTimes = fieldLen - fieldVal.length;
	for (var cntr = 1; cntr <= noOfTimes; cntr++) {
		fieldVal = '0' + fieldVal;
	}
	gField.value = fieldVal;
	return true;
}


function CheckEmail(elmnt) {

	var gField;

	if(document.getElementById(elmnt)!==null)
	{
		gField = document.getElementById(elmnt);
	}
	else
	{
		gField = elmnt;
	}

	var emailVar = gField.value;
	pass = true;
	if (!emailVar.indexOf('@') || !emailVar.indexOf('.')){
		pass = false;
	}
	if (emailVar.substr(0,emailVar.indexOf('@')) === '' || emailVar.substr(0,emailVar.indexOf('.')) === '' || emailVar.substr(emailVar.indexOf('.')+1,1) === ''){
		pass = false;
	}
	if (emailVar.substr(emailVar.indexOf('@')+1,1) == '.'){
		pass = false;
	}
	if (pass === false){
		alert("E-mail address entered is invalid.");
		gField.focus();
		gField.select();
	}
	return pass;
}


function GoToLoc() {
	var URL = document.menu.menuoption.options[document.menu.menuoption.selectedIndex].value;
	top.location = URL;
}


function GetCookie(cookieName) {

	for (var i=0; i < bites.length; i++) {
		nextBite = bites[i].split('=');
		if (nextBite[0] == cookieName){
			return unescape(nextBite[1]);
		}
	}
	return null;
}


function SetCookie(cookieName, cookieValue, expireDays) {

	var expir = new Date(today.getTime() + expireDays * 24 * 60 * 60 * 1000);
	if (cookieValue !== null && cookieValue !== ''){
		document.cookie = cookieName + '=' + escape(cookieValue) + '; expires=' + expir.toGMTString();
	}
	bites = document.cookie.split('; ');
}


var zindex=100;


function dropit2(whichone) {
	
	if (window.themenu&&themenu.id!=whichone.id)
	{
		themenu.style.visibility="hidden";
		themenu=whichone;
		if (document.all){
			themenu.style.left=document.body.scrollLeft+event.clientX-event.offsetX;
			themenu.style.top=document.body.scrollTop+event.clientY-event.offsetY+18;
			if (themenu.style.visibility=="hidden"){
				themenu.style.visibility="visible";
				themenu.style.zIndex=zindex++;
			} else {
			hidemenu();
			}
		}
	}
}


function dropit(e,whichone){

	if (window.themenu&&themenu.id!=eval(whichone).id)
	{
		themenu.visibility="hide";
		themenu=eval(whichone);
		if (themenu.visibility=="hide")
		{
			themenu.visibility="show";
		}
		else
		{
			themenu.visibility="hide";
			themenu.zIndex++;
			themenu.left=e.pageX-e.layerX;
			themenu.top=e.pageY-e.layerY+19;
			return false;
		}
	}
}


function hidemenu(whichone){

	if (window.themenu) {
		themenu.style.visibility="hidden";
	}
}


function hidemenu2(){

	themenu.visibility="hide";
}


// Generic function to open a Pop Up window.  
// Params: URL, Width, Height
function openPopupWindow(url,winWidth,winHeight) {
	popupWinRef = window.open(url, 'popupwin', 
	'width=' + winWidth + ',height=' + winHeight + ',resizable');
	popupWinOpen = 1;
}


function closePopupWindow() {

	if ((popupWinOpen == 1) && (!popupWinRef.closed))
	{
		popupWinRef.close();
	}
}

// Global variables 
// **************** 
popupWinOpen = 0;
var bites = document.cookie.split('; ');
var today = new Date();


// Products and Services Templates Common Functions
function checkItems (btnflg) {
// This function insures the quantity does not excede max value / mask

	var total_items = document.ps2form.rows.value;
	var decimal = document.ps2form.form_qdec.value;
	var maximum = document.ps2form.form_qmax.value;
	var errcnt = 0;
	for (i=0; i<=total_items; i++) { 
		j = fill(i,3,"0");
		if (FmtQty(eval("document.ps2form.qty_" + j),decimal,maximum) === false) {
			errcnt++;
			break;
		}
	}
	if (errcnt===0) {
		document.ps2form.submit();
	} else if (btnflg) {
		return false;
	}
}


function fill (itm, num, pchr) {
// This function is used by checkItems() above

	var padding = "";
	var item = itm + "";
	var pstr = item;
	if (num > item.length) {
		for (j=0; j<=num; j++) {
			padding += pchr;
		}
	pstr = padding.substr(0, num - item.length) + item;
	}
	return pstr;
}


function selectCategory (CatCode,CatLvl) {
// This function is used when a category link is pressed

	if(document.getElementById("FormSelect")!==null)
		{ document.getElementById("FormSelect").value="C"; }
	else
		{ document.ps2form.FormSelect.value = "C"; }

	if(document.getElementById("CatLvl")!==null)
		{ document.getElementById("CatLvl").value=CatLvl; }
	else
		{ document.ps2form.CatLvl.value = CatLvl; }

	if(document.getElementById("cat")!==null)
		{ document.getElementById("cat").value=CatCode; }
	else
		{ document.ps2form.cat.value = CatCode; }

	if(document.getElementById("ps2form")!==null)
		{ document.getElementById("ps2form").submit(); }
	else
		{ document.ps2form.submit(); }
}


function selectItem (ItemCode,scKey) {
// This function is used when an item link or thumbnail image is pressed	
	if(document.getElementById("FormSelect")!==null)
		{ document.getElementById("FormSelect").value="I"; }
	else
		{ document.ps2form.FormSelect.value = "I"; }

	if(document.getElementById("ItemCode")!==null)
		{ document.getElementById("ItemCode").value=ItemCode; }
	else
		{ document.ps2form.ItemCode.value = ItemCode; }

	if(document.getElementById("source")!==null)
		{ document.getElementById("source").value="ps"; }
	else
		{ document.ps2form.source.value = "ps"; }

	if(document.getElementById("k")!==null)
		{ document.getElementById("k").value=scKey; }
	else
		{ document.ps2form.k.value = scKey; }

	if(document.getElementById("ps2form")!==null)
		{ document.getElementById("ps2form").submit(); }
	else
		{ document.ps2form.submit(); }
}


function browse (browseKey,browseDirection) {
// This function is used when a page number, next or previous page link is pressed	

	document.ps2form.FormSelect.value = browseDirection;
	document.ps2form.k.value = browseKey;

	if(document.getElementById("ps2form")!==null)
		{ document.getElementById("ps2form").submit(); }
	else
		{ document.ps2form.submit(); }
}


function submitItem (index,qdec,qmax,add_charge,btnflg) {
	// This function is used when the buy button / link is pressed on a 
	// a buy button exists on each product detail row

	idx = fill(index,3,"0");

	var formatQuant;

	if(document.getElementById("qty_"+idx)!==null)
	{ formatQuant = FmtQty(document.getElementById("qty_"+idx),qdec,qmax); }
	else
	{ formatQuant = FmtQty(eval("document.ps2form.qty_" + idx),qdec,qmax); }

	if (formatQuant != false) {

		if(document.getElementById("FormSelect")!==null)
			{ document.getElementById("FormSelect").value = ""; }
		else
			{ document.ps2form.FormSelect.value = ""; }


		if(document.getElementById("ItemIndex")!==null)
			{ document.getElementById("ItemIndex").value = idx; }
		else
			{ document.ps2form.ItemIndex.value = idx; }


		if(document.getElementById("AddCharge")!==null)
			{ document.getElementById("AddCharge").value = add_charge; }
		else
			{ document.ps2form.AddCharge.value = add_charge; }


		if(document.getElementById("ps2form")!==null)
			{ document.getElementById("ps2form").submit(); }
		else
			{ document.ps2form.submit(); }
	} else if (btnflg) { return false }
}


function clearFormSubmit() {
// This function is used to clear out previous form selection values
// It is processed on the body load
// It is needed when the user presses the browser back button

	if(document.getElementById("FormSelect")!==null)
	{
		document.getElementById("FormSelect").value = "";
	}
	else
	{
		document.ps2form.FormSelect.value = "";
	}

	if(document.getElementById("source")!==null)
	{
		document.getElementById("source").value = "";
	}
	else
	{
		document.ps2form.source.value = "";
	}
}

// End of Products and Services Templates Common Functions

function flashImg(elmnt,to)
{ elmnt.src = to; }

function flashLinks()
{
	var i = 0;
	var l = document.getElementsByTagName("img").length;

	var elmnt;
	var lio;
	var from = new String();
	var to = new String();
	var extFrom = new String();
	var extTo = new String();

	for(i=0;i<l;i++)
	{
		if(document.getElementsByTagName("img")[i].className!==""||document.getElementsByTagName("img")[i].className!==null||document.getElementsByTagName("img")[i].className!==undefined)
		{
			from = document.getElementsByTagName("img")[i].src;
			lio = from.lastIndexOf(".");
			extFrom = from.substr(lio-1);
			extTo = from.substr(lio-1).replace(/0/,1);
			to = from.replace(extFrom,extTo);

			if(document.getElementsByTagName("img")[i].className=="link_hover")
			{
				document.getElementsByTagName("img")[i].onmouseover = function(to){ return function() { flashImg(this,to); }; }(to);
				document.getElementsByTagName("img")[i].onmouseout = function(from){ return function() { flashImg(this,from); }; }(from);
			}
			else if(document.getElementsByTagName("img")[i].className=="link_click")
			{
				document.getElementsByTagName("img")[i].onmousedown = function(to){ return function() { flashImg(this,to); }; }(to);
				document.getElementsByTagName("img")[i].onmouseup = function(from){ return function() { flashImg(this,from); }; }(from);
				document.getElementsByTagName("img")[i].onmouseout = function(from){ return function() { flashImg(this,from); }; }(from);
			}
		}
	}
}

function externalLinks()
{ 
	if(!document.getElementsByTagName){return;} 
	var anchors=document.getElementsByTagName("a"); 
	for(var i=0;i<anchors.length;i++)
	{ 
		var anchor=anchors[i]; 
		if(anchor.getAttribute("href")&&anchor.getAttribute("rel")=="external") 
		{anchor.target="_blank";}
	} 
}

function initFunc(tmp)
{
	externalLinks();
	flashLinks();

	if(document.getElementById("account_username")!==null)
	{
		var account_username = document.getElementById("account_username").value;
		if(account_username!=="")
			{ document.getElementById("link_username").innerHTML=account_username+"!"; }
		else
			{ document.getElementById("link_username").innerHTML="New User!" }
	}

	if(tmp==1) {
		clearFormSubmit();
	}
}