var loadtime="0";
var loading=true;
var t1;
var didmath;
var BLOCK_SUBMIT = false;
var BLOCK_INV_SUBMIT = false;
var BLOCK_PO_SUBMIT = false;

var frameHolder = new Array();
var _showPrint = false;

var debugState = "";
var debugCounter = 0;

var searchHold 	= "";
var doc			= this.document;

if(this.name == "profileFrame")
	doc = top.document;

var isNav4, isIE4;

spacerImage = new Image(1,1);
spacerImage.src = "../../images/spacer.gif";
/* rfs 080314103926 - moved trim method from storeroomReports.js */
String.prototype.trim = function() {
/* skip leading and trailing whitespace and return everything in between */
  return this.replace(/^\s*(\b.*\b|)\s*$/, "$1");
}

String.prototype.rmWhiteSpace  = function() { 

return this.replace(/\s+/g,'');

// \s+ Description
// + 1 or more of previous expression.
// \s Matches any white-space character.
// Equivalent to the Unicode character categories [\f\n\r\t\v\x85\p{Z}].
// If ECMAScript-compliant behavior is specified with the ECMAScript option,
// \s is equivalent to [ \f\n\r\t\v].
}


function isDebug() {
	try {
		if(doc.forms[0].DEBUG && doc.forms[0].DEBUG.value == "TRUE")
			return true;
		else
			return false;
	} catch(e) {return false;}
}

function saveData() {
	try {
		if(!window.opener &&
			!(doc.forms[0].target && doc.forms[0].target != undefined)) {
			//capturing ALT + F4
			// RFS 090408134303 - Don't kill if ctrl also pressed - user may be locking PC
			if (event.altKey == true && event.keyCode == 0 && event.ctrlKey == false) {
				killSession();
			}
			//capturing RED X
			Xwidth = window.document.body.offsetWidth - window.event.clientX
			YHeight = window.event.clientY
		
			if(Xwidth <= 30 && YHeight < 0) {
				killSession();
			}
		}
	} catch(e) {}
}

window.onbeforeunload=saveData

function killSession() {
	loadSection('KillSessionAM','SIGNOUT','killSession.jsp');
}

function debugAlert() {
	if(isDebug()) {
		if(debugState.length > 1000) {
			var outerCount = 1;
			var maxLengthDisplay = 1000;
			var textLength = debugState.length;
			for(t = 0; t<textLength;t++) {
				i = Math.min(maxLengthDisplay,textLength-t);
				x = debugState.substring(t,i+t);
				if(!confirm("PAGE " + outerCount++ + "(" + t + "," + (i+t) + ")\n" + x))
					break;
				t += (i-1);
			}
		} else {
			alert(debugState);
		}
	}
}

function getFunctionName(_func) {
	try {
		var myName = "" + _func;
		if(myName.length > 0 &&
			myName.indexOf("{") > 0) {
			return myName.substring(0,myName.indexOf("{"));
		} else {
			return _func
		}
	} catch(e) { return e + ": " + _func;}
}

function appendDebugState(_state) {
	var x = debugCounter++ + " - " + doc.readyState + " - " + getFunctionName(_state) + "\n";
	debugState += x;
}

function addLoadEvent(func) {
	appendDebugState("load event: " + func);
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
		appendDebugState("init onload with: " + func);
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
				appendDebugState("onload oldonload set: " + func);
            }
            try{func();appendDebugState("onload func executed: " + func);}catch(e){if(isDebug())alert(e);}
        }
    }
}

function setBlurEvent() {
	window.onblur = hideUserWait;
}

function containsFrame(_obj) {
	for(i=0;i<frameHolder.length;i++) {
		if(frameHolder[i].name = _obj.name)
			return true;
	}
}	

function addFrame(_obj) {
	if(_obj)
		frameHolder.push(_obj);
}

function peoplePlaceSearch(_type) {
    sendToFrame("submitPage('PeoplePlaceSearchAM','"+_type+"','none','peoplePlaceSearch.jsp')","im.jsp","height: 550; width: 420;top: 15; left: 5;");
}

function writeToFrame(title,_content,_style,_print,_targetFrame) {
	if(checkBlockSubmit()) {
		return;
	}
	if(_print)
		_showPrint = true;
	else
		_showPrint = false;

	addFrame(_targetFrame);
	setFrame(_style);		
	frameHolder[frameHolder.length-1].document.write(_content);
	frameHolder[frameHolder.length-1].document.close();
	//insertButtons(frameHolder[frameHolder.length-1]);
}

function writeToFrame2(title,data,_style,_print,_targetFrame){
	if(checkBlockSubmit()) {
		return;
	}
	if(_print)
		_showPrint = true;
	else
		_showPrint = false;

	if(_targetFrame)
		addFrame(_targetFrame);

	var htmlHeader = "";
	var htmlFooter = "";
	var printWinOpts = "";
	var htmlBody = "";
	
	htmlHeader = "<HTML><HEAD><TITLE>" + title + "</TITLE>\n" +
				"<!--f0d9b0775fdc65513515cf88982375bc-->\n" ;

	htmlHeader += "<LINK REL=\"STYLESHEET\" TYPE=\"text/css\" HREF=\"../../styles/_styles2.css\">\n" ;	
	
	if(useSmallPrint)
		htmlHeader += "<LINK REL=\"STYLESHEET\" TYPE=\"text/css\" HREF=\"../../styles/_smallPrintable.css\">\n" ;

	htmlHeader += "<LINK REL=\"STYLESHEET\" TYPE=\"text/css\" HREF=\"../../styles/motionDialogue.css\">\n" ;	
	htmlHeader += "<LINK REL=\"STYLESHEET\" TYPE=\"text/css\" HREF=\"../../styles/ccm.css\">\n" ;

	htmlHeader += "<SCRIPT LANGUAGE=\"JavaScript1.2\" SRC=\"../../js/motionDialogue.js\"></SCRIPT>\n" ;	
	htmlHeader += "<SCRIPT LANGUAGE=\"JavaScript1.2\" SRC=\"../../js/ssm.js\"></SCRIPT>\n" ;	
	htmlHeader += "<SCRIPT LANGUAGE=\"JavaScript1.2\" SRC=\"../../js/validation.js\"></SCRIPT>\n" ;	
	htmlHeader += "<SCRIPT LANGUAGE=\"JavaScript1.2\" SRC=\"../../js/javascript1.js\"></SCRIPT>\n" ;	
	htmlHeader += "<SCRIPT LANGUAGE=\"JavaScript1.2\" SRC=\"../../js/main.js\"></SCRIPT>\n" ;	
	htmlHeader += "<SCRIPT LANGUAGE=\"JavaScript1.2\" SRC=\"../../js/AnchorPosition.js\"></SCRIPT>\n" ;	
	htmlHeader += "<SCRIPT LANGUAGE=\"JavaScript1.2\" SRC=\"../../js/_security.js\"></SCRIPT>\n";

	htmlHeader += "</HEAD><BODY";

	if (printWinOnUnload != "") {
		htmlHeader += " onbeforeunload=\"" + printWinOnUnload + ";\"";
	}
	htmlHeader += ">";
	htmlFooter = "</body></HTML>";

	if(data && document.getElementById(data)){	
		//if you are just displaying the contents of an element in the parent page
		htmlBody += document.getElementById(data).outerHTML;
			
		node = document.getElementById(data); // <- why is this here?

	}else if (data){
		//if you have passed in a string to be displayed in the printable window
		htmlBody += data;
	}
	
	if(alertLandscapePC || alertLandscape){
		htmlFooter += "<SCRIPT language='javascript'>alert('To print properly, you must change the Printer Page Setup to \"Landscape Orientation\"on a branch PC.')</SCRIPT>\n" ;
	}

	printWindow = frameHolder[frameHolder.length-1];//window.open("",frameHolder[frameHolder.length-1],printWinOpts);
	setFrame(_style);		
	frameHolder[frameHolder.length-1].document.write(htmlHeader + "<form>" + htmlBody + "</form>" + htmlFooter);

	/* RFS #: 041110154625 - change to readonly when applicable, remove all but selected on select lists, disable only non checked radio buttons, all other types will be disabled */
	if(disableInputs){
		for(i=0;printWindow.document.forms[0].elements.length>i;i++){
		    if (printWindow.document.forms[0].elements[i].type) {
			    if (printWindow.document.forms[0].elements[i].type.toLowerCase() == "text" || printWindow.document.forms[0].elements[i].type.toLowerCase() == "password" || printWindow.document.forms[0].elements[i].type.toLowerCase() == "textarea") {
				   printWindow.document.forms[0].elements[i].readOnly=true;
				}
				else{
			   		if (printWindow.document.forms[0].elements[i].type.toLowerCase().indexOf("select") != -1) {
			       		var sel = printWindow.document.forms[0].elements[i].options[printWindow.document.forms[0].elements[i].selectedIndex];
				   		printWindow.document.forms[0].elements[i].options.length = 0;
				   		printWindow.document.forms[0].elements[i].options[0] = sel;
			   		}
			   		else{
					    if (printWindow.document.forms[0].elements[i].type.toLowerCase() == "radio") {
						    if (!printWindow.document.forms[0].elements[i].checked) {
							    printWindow.document.forms[0].elements[i].disabled=true;
							}
						}
						else{
			       			printWindow.document.forms[0].elements[i].disabled=true;
						}
			   		}
				}
			}
			else{
				printWindow.document.forms[0].elements[i].disabled=true;
			}
		}
	}
	frameHolder[frameHolder.length-1].document.close();
	//insertButtons(frameHolder[frameHolder.length-1]);
}

function openFrame(_pageURL,_style,_print,_targetFrame) {
	if(checkBlockSubmit()) {
		return;
	}
	
	addFrame(_targetFrame);
	frameHolder[frameHolder.length-1].location.href = _pageURL;
	
	if(_print)
		_showPrint = true;
	else
		_showPrint = false;

	setFrame(_style);		

}

function sendToFrame(_action,_templateForm,_style,_print,_targetFrame) {
	if(checkBlockSubmit()) {
		return;
	}

	if(_print)
		_showPrint = true;
	else
		_showPrint = false;

	addFrame(_targetFrame);
	setFrame(_style);		

	doc.forms[0].target = frameHolder[frameHolder.length-1].name;
	eval(_action);
   	doc.forms[0].target = "";
	document.forms[0].action = _templateForm;
	return;
}

function setFrame(_style) {
	try {
		doc.getElementById("mainBody").style.zIndex = -1;
		doc.getElementById("mainBody").style.filter = "progid:DXImageTransform.Microsoft.Alpha( Opacity=30, FinishOpacity=20, Style=0, StartX=0,  FinishX=0, StartY=0, FinishY=0, enabled='true')";
	} catch(e){}
	obj = doc.getElementById(frameHolder[frameHolder.length-1].name).style;
	obj.background = "#FFFFFF";
	obj.border = "3px outset #900000";
	obj.filter = "progid:DXImageTransform.Microsoft.dropshadow(OffX=2, OffY=2, Color='#999999', Positive='true')";
	obj.position = "absolute";
	obj.zIndex = 100;
	obj.visibility = "visible";
	hideElements('hide');
	if(_style)
		parseStyle(obj, _style);

}

function moveFrameCover(_targetId) {
/*<iframe id="coverAll" src="about:blank" scrolling="no" frameborder="0"></iframe>*/
	try {
		if(_targetId) {
			var _obj = document.getElementById(_targetId).style;
			var _style = document.getElementById("coverAll").style;
			_style.left = _obj.left; 
			_style.top = _obj.top; 
			_style.height = _obj.height;
			_style.width = _obj.width;
			_style.display = "block";
		}
	}catch(e) {}
}

function parseStyle(obj,_val) {
	
	try {
		start = 0;
		if(_val.indexOf(" ") == start)
			start = 1;

		var attName = _val.substring(start,_val.indexOf(":"))
		var attValue = _val.substring(_val.indexOf(":")+1,_val.indexOf(";"));
		
		if(attName == "top") {
			attValue = parseInt(document.body.scrollTop,10) + parseInt(attValue,10);
		}
		
		obj[attName] = attValue;
	} catch(e) {}
	
	if(_val.indexOf(":") == _val.lastIndexOf(":"))
		return;
	else
		parseStyle(obj,_val.substring(_val.indexOf(";")+1));

}

function insertButtons(_targetFrame,_closeFunction) {
	appendDebugState("begin insertButtons");
	if(_targetFrame) {
		if(!containsFrame(_targetFrame)) {
			appendDebugState("new frame");
			frameHolder.push(_targetFrame);
		}
	} else if(!containsFrame(printFrame)) {
		appendDebugState("default to print frame");
		frameHolder.push(printFrame);
	}
	
	var closeFunction = "parent.closeFrame();";
	if(_closeFunction) {
		closeFunction = "parent." + _closeFunction
	}

	if(frameHolder[frameHolder.length-1].document) {
		appendDebugState("document found");
		appendDebugState("state: " + frameHolder[frameHolder.length-1].document.readyState);
		try {
			if(frameHolder[frameHolder.length-1].document && 
				frameHolder[frameHolder.length-1].document.readyState && 
				(frameHolder[frameHolder.length-1].document.readyState == "complete" 
				|| frameHolder[frameHolder.length-1].document.readyState == "loading" )) {
				frameHolder[frameHolder.length-1].document.createStyleSheet('../../styles/printFriendly.css');
				appendDebugState("start");
				var theBody = frameHolder[frameHolder.length-1].document.getElementsByTagName('body')[0];
				var _lang = "0";
				try {
					_lang = document.forms[0].LANGUAGE.value;
				}catch(e) {}
				var newP = frameHolder[frameHolder.length-1].document.createElement("<INPUT id='close' type='image' onclick='javascript:" + closeFunction + "' style='position: absolute; top: 5px; right: 23px; z-index: 2;' src='../../images/inmotion/buttons/btnCloseWindow_" +_lang + ".gif' alt='Close Window' border='0'>");
				theBody.appendChild(newP);
				if(_showPrint) {
					var newT = frameHolder[frameHolder.length-1].document.createElement("<INPUT id='print' type='image' onclick='javascript:hideAddedButtons();top.window.print();showAddedButtons();' style='position: absolute; top: 5px; right: 132; z-index: 2;' src='../../images/inmotion/buttons/btnPrint_" +_lang + ".gif' alt='Print' border='0'>");
					theBody.appendChild(newT);
					printMe(frameHolder[frameHolder.length-1]);
				}
			}
		} catch(ee) {if(isDebug())alert(ee);}
	}
	hideUserWait();
	appendDebugState("finished insertButtons");
}

var printCount = 0;

function printMe(_iframe) {
	try {
	if(++printCount % 2 == 1) {
		_iframe.focus(); 
		_iframe.hideAddedButtons();
		_iframe.print(); 
		_iframe.showAddedButtons();
	}
	} catch(e) {if(isDebug())alert(e);}
}

function closeFrame() {
	try{
		hideUserWait();
	}catch(e){}
	hideElements('show');
	if(frameHolder[frameHolder.length-1].document) {
		frameHolder[frameHolder.length-1].document.write("");
		frameHolder[frameHolder.length-1].document.close();
	}

	document.getElementById(frameHolder[frameHolder.length-1].name).style.visibility = "hidden";
	document.getElementById(frameHolder[frameHolder.length-1].name).style.width = 0;
	document.getElementById(frameHolder[frameHolder.length-1].name).style.height = 0;
	if(frameHolder.length >1)
		frameHolder.pop();
}

function hideUserWait() {
	try{
		hideLayer("USER_WAIT");
		doc.getElementById("mainBody").style.zIndex = 0;
		top.document.getElementById("mainBody").style.filter = "none";
	}catch(e){}
}

function alertUserWait()  {
	if(doc.forms[0].target && doc.forms[0].target != undefined)
		return;
	try{
		var t = doc.location + "";
		if(doc.location && t.indexOf("inmotion")>0) {
			if(doc.getElementById("mainBody")) {
				doc.getElementById("mainBody").style.zIndex = -1;
				doc.getElementById("mainBody").style.filter = "progid:DXImageTransform.Microsoft.Alpha( Opacity=30, FinishOpacity=20, Style=0, StartX=0,  FinishX=0, StartY=0, FinishY=0, enabled='true')";
				hideElements('hide');
			}
			alertInnerWait();
		}
	}catch(e){} 
}

function alertInnerWait() {
	try {
		var _lang = doc.forms[0].LANGUAGE.value;
		if(doc.getElementById("USER_WAIT").src == null)
			doc.getElementById("USER_WAIT").src= "pleaseWait.jsp?LANGUAGE="+_lang;

		obj = doc.getElementById("USER_WAIT").style;
		obj.filter = "progid:DXImageTransform.Microsoft.Alpha(Opacity=100, FinishOpacity=30, Style=2)";
		obj.position = "absolute";
		obj.zIndex = 100;
		obj.width = "220px";
		obj.height = "200px";
		attValue = parseInt(document.body.scrollTop,10) + parseInt(200,10);
		obj.top = attValue;
		obj.left = "25%";
		obj.visibility = "visible";
	} catch(e) {}
}

function setBlockSubmit(_state) {
	BLOCK_SUBMIT = _state;
	return true;
}

function setBlockInvSubmit(_state) {
	BLOCK_INV_SUBMIT = _state;
	return true;
}

function setBlockPOSubmit(_state) {
	BLOCK_PO_SUBMIT = _state;
	return true;
}

function getBlockPOSubmit() {
	return BLOCK_PO_SUBMIT;
}
function getBlockInvSubmit() {
	return BLOCK_INV_SUBMIT;
}
function setT1(_t1) {
  if(_t1 == null) {
    t1 = (new Date()).getTime();
  } else {
    t1 = _t1;
  }
}

function refresh() {
     if(t1 == null) {
        setTimeout("count()",250);
	  }	
    }
    function count() {
        if (loading) {
          loadtime=loadtime+++250; // .25
          refresh();
        } 
	}
	
	function startTimer() {
	  t2 = new Date();
	  document.forms[0].START_TIME.value = t2.getTime();
	  return true;
	}
	
/*
function setTrue() {
	return true;
}

function setFalse() {
	return false;
}

function allowCutPaste(status) {
	if(status) {
		document.oncontextmenu = setTrue;
		document.onselectstart = setTrue;
		document.ondragstart = setTrue;
	} else {
		document.oncontextmenu = nocontextmenu;
		document.onselectstart = preventHighlight;
		document.ondragstart = preventHighlight;
	}
}

//No RIGHT CLICK************************
// ****************************
function nocontextmenu(e) {
	if(e) {
	 	e.cancelBubble = true;
	 	return e.ctrlKey;
	} else {
		event.cancelBubble = true;
	 	return event.ctrlKey;
	}
		
} 

function preventHighlight(e) {
	if(e) {
	 	e.cancelBubble = true;
		return e.altKey;
	} else {
		event.cancelBubble = true;
		return event.altKey;
	}
}

**************************************
****************************
Block backspace onKeyDown************
***************************
 function onKeyDown() {
 	if ((event.altKey) || ((event.keyCode == 8) && 
 		(event.srcElement.type != "text" &&
 		event.srcElement.type != "textarea" &&
 		event.srcElement.type != "password")) || 
 		((event.ctrlKey) && ((event.keyCode == 78) || (event.keyCode == 82)) ) ||
		(event.keyCode == 116) ) {
   	 		event.keyCode = 0;
   	 		event.returnValue = false;
 	}
 }
*/

//Auto Tab -- onKeyUp="return autoTab(this, 25, event);"************************
// ****************************
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
	if (!isNN) {
		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();
		}
			
		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;
}
function getEndOfMonth(month,year) {
	var days = "28";

	switch (month) {
		case "01":
			days = "31";
			break;
		case "02": 
			var rem = year % 4 ;
			var rem100 = year % 100;
			var rem400 = year % 400
			if (rem > 0){
				days = "28";
			} else if(rem100 == 0 && rem400 > 0) {
				days = "28";
			} else {
				days = "29";
			}
			break;
		case "03" : 
			days = "31";
			break;
		case "04" : 
			days = "30";
			break;
		case "05" : 
			days = "31"; 
			break;
		case "06" : 
			days = "30";
			break;
		case "07" : 
			days = "31"; 
			break;
		case "08" : 
			days = "31"; 
			break;
		case "09" : 
			days = "30"; 
			break;
		case "10" : 
			days = "31"; 
			break;
		case "11" : 
			days = "30"; 
			break;
		case "12" : 
			days = "31"; 
			break;
	}
	return days;
}

function defaultImage(image,width,height) {
	if(image.src) {
		image.src = spacerImage.src;
		image.width = width;
		image.height = height;
		image.border = 0;
	} else if(image.length > 0) {
		imageName = image;
		document.images[imageName].src = spacerImage.src;
		document.images[imageName].width = width;
		document.images[imageName].height = height;
		document.images[imageName].border = 0;
	}
}		

if(parseInt(navigator.appVersion)>=4) {	
	isNav4 	= (navigator.appName == "Netscape");
	isIE4 	= (navigator.appName.indexOf("Microsoft") != -1);	
}

var deleteTemplateMessage	= new Array("This Template will be PERMANENTLY DELETED.  Do you wish to continue?",
								"Ce modèle va être détruit de façon permanente. Voulez-vous continuer ?",
								"Esta Plantilla SERA BORRADA PERMANENTEMENTE. ¿Desea usted continuar?");

var deleteOrderMessage		= new Array("This Order will be CANCELED and PERMANENTLY DELETED.  Do you wish to continue?",
								"Cette commande va être Annuler et détruite de façon permanente. Voulez-vous continuer ?",
								"Esta Orden SERA CANCELADA y SERA BORRADA PERMANENTEMENTE. ¿Desea usted continuar?");

var deleteInvoiceMessage    = new Array("This invoice/shipper will be CANCELED and PERMANENTLY DELETED. Do you wish to continue?",
							"This invoice/shipper will be CANCELED and PERMANENTLY DELETED. Do you wish to continue?",
							"Este factura/expedidor SERA CANCELADO y SERA BORRADO PERMANENTEMENTE. ¿Desea usted continuar?");
var cancelInvoiceMessage    = new Array("You have chosen to cancel update of this invoice/shipper. Any unsaved changes will be lost. Do you wish to continue?",
							"You have chosen to cancel update of this invoice/shipper. Any unsaved changes will be lost. Do you wish to continue?",
							"Usted ha escogido cancelar actualiza de este factura/expedidor. Cualquier unsaved cambio será perdido. ¿Desea usted continuar?");
	
function confirmPurge(type,lang)	{
	var language = 0;
	if(lang)
		language = lang;
	if(type)	{
		if(type == '1')
			return confirm(deleteTemplateMessage[language]);
		else if(type == '2')
			return confirm(deleteInvoiceMessage[language]); 
		else if(type == '3')
			return confirm(cancelInvoiceMessage[language]); 
		else 
			return confirm(deleteOrderMessage[language]);
	}	else
			return confirm(deleteOrderMessage[language]);
}
function clearDate(obj) {
	var str = obj.value;
	mon = /mm/i;
	day = /dd/i;
	yr = /yy/i;
	foundMon = str.match(mon);
	foundDay = str.match(day);
	foundYr	 = str.match(yr);
	if(foundMon || foundDay || foundYr) {
		obj.value = "";
		obj.focus();
	}
}

function setCGCPartNumType() {
	var box = document.forms[0].PART_NUM_TYPE;
	var no = new Option();
	no.value = "006";
	no.text = "PARAMETRIC DATA"; 
	box.options[box.options.length] = no;
	document.forms[0].PART_NUM_TYPE.selectedIndex = (box.options.length - 1);
}

function setupSearch(val)	{
	var box = document.forms[0].PART_NUM_TYPE;
	if(box.options.length == 7) {
		doc.forms[0].SEARCH_DESC.value = "";
		box.options[(box.options.length - 2)] = null;
	}	
	if(val.indexOf("04") > 0)	{
		searchHold = doc.forms[0].SEARCH_DESC.value;
		doc.forms[0].SEARCH_DESC.value = "";
		doc.getElementById("leftHideSearch").style.display = "none";
		doc.getElementById("leftHideSearch").style.overflow = "hidden";
		doc.getElementById("leftHideSearch").style.visibility = "hidden";
		doc.getElementById("MFR_LABEL").style.color = "#D63B41";
		doc.forms[0].MFR.focus();
	} else	{
		if(searchHold.length > 0) {
			doc.forms[0].SEARCH_DESC.value = searchHold;
			searchHold = "";
		}
		doc.getElementById("leftHideSearch").style.display = "inline";
		doc.getElementById("leftHideSearch").style.overflow = "visible";
		doc.getElementById("leftHideSearch").style.visibility = "visible";
		doc.getElementById("MFR_LABEL").style.color = getValidColor("MFR_LABEL");
		doc.forms[0].SEARCH_DESC.focus();
	}
}

function search(lang)	{
	var fields 		= new Array();
	fieldCounter 	= 0;

	var searchString = doc.forms[0].SEARCH_DESC.value;
	var mfrSelectedIndex = doc.forms[0].MFR.selectedIndex;
	var reqType		= doc.forms[0].PART_NUM_TYPE[doc.forms[0].PART_NUM_TYPE.selectedIndex].value;

	if(document.forms[0].customer && document.forms[0].customer.length > 0)
		fields[fieldCounter++] = new requiredField(new selectBox("customer",0),"customerLABEL","select");

	if(reqType.indexOf("03") > 0)
		fields[fieldCounter++] = new requiredField("SEARCH_DESC","SEARCH_DESC_LABEL","mino");
	else if(reqType.indexOf("04") > 0)
		fields[fieldCounter++] = new requiredField(new selectBox("MFR",1),"MFR_LABEL","select");
	else if(reqType.indexOf("07") > 0)
		fields[fieldCounter++] = new requiredField("SEARCH_DESC","SEARCH_DESC_LABEL","itemNumber");
	else
		fields[fieldCounter++] = new requiredField("SEARCH_DESC","SEARCH_DESC_LABEL","text");
	
	return validatePage(fields,lang);
}

function idKeyPress(e,idValue)	{
	if(window.event || !e.which) { // IE
		if (e.keyCode == 13)
			if(this.document.getElementById(idValue)) {
				eval(this.document.getElementById(idValue).href);
				e.returnValue = false;
			}
	} else if(e) { // netscape
		if (e.which == 13)
			if(this.document.getElementById(idValue)) {
				eval(this.document.getElementById(idValue).href);
				e.returnValue = false;
			}
	}
}

function numbersOnly(e) {
	if(window.event || !e.which) { // IE
		if(e.keyCode < 48 || e.keyCode > 57)
			if(e.keyCode != 46)
				e.returnValue = false;
	} else if(e) { // Netscape
		if(e.which < 48 || e.which > 57)
			if(e.which != 46)
				e.returnValue = false;
	}
}	

function replace(originalText, toBeReplaced, replaceWith)	{
	var outgoing = originalText;
	var stringScrubber = new RegExp();	
	stringScrubber.compile(toBeReplaced,"g", "i");
	stringScrubber.multiline=true;
	outgoing = outgoing.replace(stringScrubber,replaceWith);
	return outgoing;
}

// I Change an image color by using the unique name of the image and the status ('on','off).
// I can change the status ONLY IF the image is a .gif file and ends with either '_on' or '_off' 
// where the stat will be either 'on' or 'off'
function roll(name,stat)	{	
	var src = doc.images[name].src;
	
	if(src.indexOf(".gif") < 0 ||
		(src.indexOf("_on") < 0 &&
		src.indexOf("_off") < 0))
			return;

	doc.images[name].src = src.substring(0,src.lastIndexOf("_")+1) + stat + ".gif";		
}

function switchImage(name)	{
	var src = doc.images[name].src;
	var stat = "";

	if(src.indexOf(".gif") < 0 ||
		(src.indexOf("_on") < 0 &&
		src.indexOf("_off") < 0))
			return;
			
	if(src.indexOf("_on.gif") > 0)
		stat = "off.gif";
	else if(src.indexOf("_off.gif") > 0)
		stat = "on.gif";
		
	doc.images[name].src = src.substring(0,src.lastIndexOf("_")+1) + stat;		

}

// I change the background color of an object based on the 'id' which defined the 
// style for the id, the unique 'name' of the object, and wether the object has
// gained or lost focus
function setBackground(id,name,on)	{
	if(on)
		document.getElementById(id)[name].style.background =  "#F7F2E4";
	else
		document.getElementById(id)[name].style.background =  "#FFFFFF";
}

function setBG(name,on)	{
	if(on)
		name.style.background =  "#E0E0E0";
	else
		name.style.background =  "#FFFFFF";
}

function setFocusElement()	{
	if(doc.getElementById("focusOnMe"))	{
		doc.getElementById("focusOnMe").focus();
	}
}

function resetDefaultCustNum()	{
	val = doc.forms[0].customer.selectedIndex;
	doc.forms[0].DEFAULT_CUST_NUM.value = (val - (val%3))/3;
			
	return true;
} 

// I set the value of an object given the 'fieldName' and a value 'fieldValue'
function setValue(fieldName, fieldValue, formIdx)	{
	/* Form logic to allow multiple forms on a page moved from ccm.js, unknown if/where this is/was used. */
	if(formIdx) {
		var idx = (formIdx) ? formIdx: 0;
		var field = document.forms[idx][fieldName];
		
		if(field)
			field.value = fieldValue;
		else { 
			// fix for IE and dynamically generated elements
			for(var i=0;i<document.forms[idx].length;++i)
			{
				if(fieldName == document.forms[idx][i].name)
				{
					document.forms[idx][i].value = fieldValue;
					break;
				}
			}
		}
	} else {
	var temp = doc.forms[0];
	if(fieldName!=null) {
		if(temp[fieldName]) {
		  temp[fieldName].value=fieldValue;
		} else {
			try {
				if(document.readyState && 
					document.readyState == "complete") {
						var theForm = document.getElementsByTagName('form')[0];
						
						var newField = document.createElement("<INPUT type='hidden' name='" + fieldName + "' value='" + fieldValue + "'>");
						theForm.appendChild(newField);
				}
			}catch(e) {}
		}
	} 
}
}

function openWin(page, nam, w, h, s,tool)	{	
	var w = w;
	var h = h;
	var scroll;
	var toolbar = 0;
	if(s==true){
		scroll=1
	} else {
		scroll=0
	}
	
	if(tool && !isNaN(tool))
		toolbar = tool;
	
	remote = window.open("","remote",'toolbar=' + toolbar + ',menubar=' + toolbar + ',scrollbars='+scroll+',width=' + w + ',height=' + h +',resizable=1,status=1');
	remote.location.href = page;
	if (remote.opener == null) 
		remote.opener = window;
	remote.opener.name = "opener";
	try{hideUserWait();}catch(e){}
}

function checkBlockSubmit() {
	if(BLOCK_SUBMIT) {
		notifyOfOrder();
		return true;
	} else if (BLOCK_INV_SUBMIT) {
		notifyOfInvoice();
		return true;	
	} else if (BLOCK_PO_SUBMIT) {
		notifyOfPO();
		return true;	
		
	} 
	return false;
}

// I am the default submit function, I submit the page with no validation
function _submit() {
	if(checkBlockSubmit()) {
		return;
	}
	try {
  		startTimer();
	} catch(e) {}
	try{handleOnSubmitEvents()}catch(e){};
  	doc.forms[0].submit(); 
	try{if(!window.opener){alertUserWait()}}catch(e){if(isDebug())alert(e);};
}


function submitPageToUrl(action, target)	{
        if(action != null) {
           doc.forms[0].action = action;
           doc.forms[0].target = target;
        }
	_submit();
}

// I submit forms.  I take an 'amAction' which is the java AM class name, a
// 'busAction' which is used as a conditional item for having an AM perform
// different functions.  I also take a 'validation' object which is the name of
// function used to validate the form.  An optional field 'action' is used in the
// case where the page will not post to "templateOne.jsp"
function submitPage(amAction,busAction,validation,action)	{
	var temp = doc.forms[0].action;
	var valid = "";
	
	if(validation.indexOf("(") != -1)
		valid = validation;
	else
		valid = validation + "()";
	
	if(action)
		temp = action;
	if(validation == "none")	{
		doc.forms[0].action 			= temp;
		doc.forms[0].AM_ACTION.value  = amAction;
		doc.forms[0].BUS_ACTION.value = busAction;
		_submit();
	}	else if(eval(valid))	{
			doc.forms[0].action 			= temp;
			doc.forms[0].AM_ACTION.value  = amAction;
			doc.forms[0].BUS_ACTION.value = busAction;
			_submit();
	}
}

function loadSection(amAction,busAction,action)	{
	//if(parent)
		//doc = parent.document;
	var temp = doc.forms[0].action;
	if(action)
		temp = action;

	doc.forms[0].action 			= temp;
	doc.forms[0].AM_ACTION.value  = amAction;
	doc.forms[0].BUS_ACTION.value = busAction;
	_submit();
}

//I allow for two variables to be passed between pages.
function parseBusAction(amAction,busAction, validation){
tempVar = busAction.split("_");
doc.forms[0].var1.value= tempVar[0];
doc.forms[0].var2.value= tempVar[1];
submitPage(amAction,busAction,validation);
}

var lastMenuShown = "";
var lastLinkClicked = "";

function showHTML(pageLink,pageType,section,action) {
	var temp = doc.forms[0].action;
	if(action)
		temp = action;
	doc.forms[0].action 			= temp;
	doc.forms[0].AM_ACTION.value  	= "HTML_DisplayAM";
	doc.forms[0].PAGE_LINK.value  	= pageLink;
	doc.forms[0].PAGE_TYPE.value 	= pageType;
	doc.forms[0].SECTION.value		= section;
	_submit();
}

function showFORM(pageLink,pageType,section,action) {
	var temp = doc.forms[0].action;
	if(action)
		temp = action;
	doc.forms[0].action 			= temp;
	doc.forms[0].AM_ACTION.value  	= "FormSubmitAM";
	doc.forms[0].BUS_ACTION.value 	= "view";
	doc.forms[0].PAGE_LINK.value  	= pageLink;
	doc.forms[0].PAGE_TYPE.value 	= pageType;
	doc.forms[0].SECTION.value		= section;
	_submit();
}

function loadPage(amAction,busAction,section,action) {
	//if(parent)
		//doc = parent.document;
	var temp = doc.forms[0].action;
	if(action)
		temp = action;
	doc.forms[0].action 			= temp;
	doc.forms[0].AM_ACTION.value  = amAction;
	doc.forms[0].BUS_ACTION.value = busAction;
	doc.forms[0].SECTION.value	= section;
	_submit();
}

function setLastViewed(id,menu) {
	if(id.lastIndexOf("00") == (id.length - 2)) {
		expandList(id);
	} else {
		tempId = id.substring(0,id.length - 2) + "00";
		expandList(tempId);
		highlightLink(id);
	}
}

function highlightLink(id,menu) {
	if(lastLinkClicked.length > 0) {
		document.getElementById(lastLinkClicked).style.color = validateColor(lastLinkClicked);
		if(document.getElementById(id)) {
			document.getElementById(id).style.color = "#900000";
			lastLinkClicked = id;
		}
	} else if(document.getElementById(id)) {
		document.getElementById(id).style.color = "#900000";
		lastLinkClicked = id;
	}
}		

var ie5 = (document.all && document.getElementsByTagName);

function setSB(v, el) {
	if (ie5 || document.readyState == "complete") {
		filterEl = el.children[0];
		valueEl  = el.children[1];
		
		if (filterEl.style.pixelWidth > 0) {
			var filterBackup = filterEl.style.filter;
			filterEl.style.filter = "";
			filterEl.style.filter = filterBackup;
		}
		
		filterEl.style.width = v + "%";
		valueEl.innerText = "Please Wait. . ." + v + "%";
	}
}

function fakeProgress(v, el) {
	if (v >= 100)
		setSB(100, el);
	else {
		setSB(v, el);
		window.setTimeout("fakeProgress(" + (v + 1) + ", document.all['" + el.id + "'])", 100);
	}
}

function expandList(id,lms) {
	if(document.getElementById(id)) {
		if(document.getElementById(id+'DIV')) {
			document.getElementById(id+'DIV').style.display = "inline";
			roll(id+"IMG","off");
			document.getElementById(id+'LINK').href = "javascript:collapseList('" + id + "');";
		}
		highlightLink(id);
		if(lastMenuShown.length > 0) {
			collapseList(lastMenuShown);
			lastMenuShown = id;
		} else {
			lastMenuShown = id;
		}
	}
}

//inmotionPrintWindow settings
var remote;
var alertLandscape = false; //set to true to alert user to set print view to landscape
var alertLandscapePC = false; //set to true to alert user to set print view to landscape for branch PC
var disableInputs = true;	//set to false to NOT disable form elements on print view
var useSmallPrint = false;  //set to true to use alternate style sheet with smaller text
var printWinOnUnload = ""; //action for onbeforeunload of print window
function inmotionPrintWindow(title,data,reportHeader,reportFooter,w,h,inner_outer){
	var htmlHeader = "";
	var htmlFooter = "";
	var printWinOpts = "";
	var htmlBody = "";
	
	htmlHeader = "<HTML><HEAD><TITLE>" + title + "</TITLE>\n" +
				"<!--f0d9b0775fdc65513515cf88982375bc-->\n" ;

	htmlHeader += "<LINK REL='STYLESHEET' TYPE='text/css' HREF='../../styles/_styles2.css'>\n" ;	
	htmlHeader += "<LINK REL='STYLESHEET' TYPE='text/css' HREF='../../styles/printFriendly.css'>\n" ;	

	if(useSmallPrint)
		htmlHeader += "<LINK REL='STYLESHEET' TYPE='text/css' HREF='../../styles/_smallPrintable.css'>\n" ;

	htmlHeader += "<LINK REL='STYLESHEET' TYPE='text/css' HREF='../../styles/ccm.css'>\n" ;
	htmlHeader +="<SCRIPT LANGUAGE='JavaScript1.2' SRC='../../js/_security.js'></SCRIPT>\n" +
					"<SCRIPT LANGUAGE='JavaScript1.2' SRC='../../js/javascript1.js'></SCRIPT>\n" +
					"</HEAD><BODY";

	if (printWinOnUnload != "") {
		htmlHeader += " onbeforeunload=\"" + printWinOnUnload + ";\"";
	}
	htmlHeader += ">";
	htmlFooter = "</body></HTML>";

	if(reportHeader) 
		htmlBody += "<p class=\"sectionHeader\">" + reportHeader  + "</p>";
		

	if(data && document.getElementById(data)){	
		//if you are just displaying the contents of an element in the parent page
		if(inner_outer && inner_outer=="inner")
			htmlBody += document.getElementById(data).innerHTML;
		else if(inner_outer && inner_outer=="outer")
			htmlBody += document.getElementById(data).outerHTML;
		else
			htmlBody += document.getElementById(data).outerHTML;
			
		node = document.getElementById(data); // <- why is this here?

	}else if (data){
		//if you have passed in a string to be displayed in the printable window
		htmlBody += data;
	}
	
	if(alertLandscapePC || alertLandscape){
		htmlFooter += "<SCRIPT language='javascript'>alert('To print properly, you must change the Printer Page Setup to \"Landscape Orientation\"on a branch PC.')</SCRIPT>\n" ;
	}

	if(reportFooter) htmlBody += reportFooter;	
	
	printWinOpts = "toolbar=1,menubar=1,scrollbars=1,";
	if(w) printWinOpts += "width="+w+",";
	else  printWinOpts += "width=600,";
	if(h) printWinOpts += "height="+h+",";
	else  printWinOpts += "height=800,";
	printWinOpts += "resizable=1,status=1"

	/*printWindow = frameHolder[frameHolder.length-1];//window.open("",frameHolder[frameHolder.length-1],printWinOpts);
	writeToFrame(htmlHeader + "<form>" + htmlBody + "</form>" + htmlFooter,"width: 600;height: 800;top: 5px;left: 5px;",true);
	insertButtons();
	printWindow.location.reload();*/
	
	printWindow = window.open("","printWindow",printWinOpts);
	printWindow.focus();
	printWindow.document.write(htmlHeader + "<form>" + htmlBody + "</form>" + htmlFooter);
	/* RFS #: 041110154625 - change to readonly when applicable, remove all but selected on select lists, disable only non checked radio buttons, all other types will be disabled */
	if(disableInputs){
		try {
		for(i=0;printWindow.document.forms[0].elements.length>i;i++){
			if(printWindow.document.forms[0].elements[i].style.display.toLowerCase() != "none") {
			    if (printWindow.document.forms[0].elements[i].type) {
				    if (printWindow.document.forms[0].elements[i].type.toLowerCase() == "text" || printWindow.document.forms[0].elements[i].type.toLowerCase() == "password" || printWindow.document.forms[0].elements[i].type.toLowerCase() == "textarea") {
					   printWindow.document.forms[0].elements[i].readOnly=true;
					}
					else{
				   		if (printWindow.document.forms[0].elements[i].type.toLowerCase().indexOf("select") != -1) {
				       		var sel = printWindow.document.forms[0].elements[i].options[printWindow.document.forms[0].elements[i].selectedIndex];
					   		printWindow.document.forms[0].elements[i].options.length = 0;
					   		printWindow.document.forms[0].elements[i].options[0] = sel;
				   		}
				   		else{
						    if (printWindow.document.forms[0].elements[i].type.toLowerCase() == "radio") {
							    if (!printWindow.document.forms[0].elements[i].checked) {
								    printWindow.document.forms[0].elements[i].disabled=true;
								}
							}
							else{
				       			printWindow.document.forms[0].elements[i].disabled=true;
							}
				   		}
					}
				}
				else{
					printWindow.document.forms[0].elements[i].disabled=true;
				}
			}
		}
		
		var leftList = printWindow.document.getElementsByTagName('a');
		var count = leftList.length;
		for(v=0;v<count;v++) {
			leftList[v].href = "#";
			leftList[v].style.cursor = "default";
		}
		}catch(e){}
	}
	try{hideUserWait();}catch(e){}
}
function setWindowSize(width,height) {
	if (window.outerWidth) {
		window.outerWidth = width;
		window.outerHeight = height;
	}
	else if (window.resizeTo) {
		window.resizeTo(width,height);
	}
}

// I set the variables necessary to access Existing Orders/Quotes
function setInstructions(action,directive,target,modifier)
{

	while(action.length < 8){
			action = action + " ";}
	while(directive.length < 8){
			directive = directive + " ";}
	while(target.length < 8){
			target = target + " ";}
							
	this.document.forms[0].instruction.value = "Action="+action+"Directive="+directive+"Target="+target;
	this.document.forms[0].modifier.value = modifier;
}

function collapseList(id) {
	if(document.getElementById(id) && document.getElementById(id+'DIV')) {
		document.getElementById(id+'DIV').style.display = "none";
		document.getElementById(id).style.color = validateColor(id);
		roll(id+"IMG","on");
		document.getElementById(id+'LINK').href = "javascript:expandList('" + id + "');";
		lastMenuShown = "";
	}
}

var onLoadEvents = new Array();
var onSubmitEvents = new Array();

function registerOnLoadEvent(loadEvent){
	onLoadEvents[onLoadEvents.length] = loadEvent;
	appendDebugState("Added event: " + loadEvent);
}

function handleOnLoadEvents(){
	for(var i=0;i<onLoadEvents.length;++i) {
		try{eval(onLoadEvents[i]);appendDebugState("Executed event: " + onLoadEvents[i]);}catch(e){}
	}
}

function registerOnSubmitEvent(loadEvent){
	onSubmitEvents[onSubmitEvents.length] = loadEvent;
}

function handleOnSubmitEvents(){
	for(var i=0;i<onSubmitEvents.length;++i)
		try{eval(onSubmitEvents[i]);}catch(e){}
}

function loadPageInWindow(amAction,busAction,validation,action,remoteName,w,h,toolbar,menubar,scrollbars,resizeable) {
	
	var remote = (remoteName)?remoteName:"remote";
	var windowOptions = "";
		windowOptions +="width="+((w!="")?w:"640");
		windowOptions +=",height="+((h!="")?h:"480");
		windowOptions +=(toolbar!="")?",toolbar":"";
		windowOptions +=(menubar!="")?",menubar":"";
		windowOptions +=(scrollbars!="")?",scrollbars":"";
		windowOptions +=(resizeable!="")?",resizable":"";
   	w = open("",remoteName,windowOptions);
    this.document.forms[0].target = remoteName;
	submitPage(amAction,busAction,validation,action);
   	this.document.forms[0].target = "";
	this.document.forms[0].action = "im.jsp";
	this.document.forms[0].AM_ACTION.value = amAction;
	this.document.forms[0].BUS_ACTION.value = busAction;
	try{hideUserWait();}catch(e){}
}

function formatPhone(num)
{ 
	//trim white spaces
	num = num.replace(/^[\s]+/g,"");
	num = num.replace(/[\s]+$/g,"");
	
  	if(num.length != 10) { 
    	//if user did not enter 10 digit phone number then simply print whatever user entered 
		_return=num;
  	} else { 
    	/* formating phone number here */ 
		_return="(";
		var ini = num.substring(0,3);
		_return+=ini+") ";
		var st = num.substring(3,6);
		_return+=st+"-";
		var end = num.substring(6,10);
		_return+=end;
	}
  	return _return; 
} 

// Compare two options within a list by VALUES
function compareOptionValues(a, b) { 
  // Radix 10: for numeric values
  // Radix 36: for alphanumeric values
  var sA = parseInt( a.value, 36 );  
  var sB = parseInt( b.value, 36 );  
  return sA - sB;
}

// Compare two options within a list by TEXT
function compareOptionText(a, b) { 
  // Radix 10: for numeric values
  // Radix 36: for alphanumeric values
  var sA = parseInt( a.text, 36 );  
  var sB = parseInt( b.text, 36 );  
  return sA - sB;
}

// Moves and sorts options between select lists
function moveDualList( srcList, destList, moveAll ) 
{
  // Do nothing if nothing is selected
  if (  ( srcList.selectedIndex == -1 ) && ( moveAll == false )   ){
    return;
  }  
  newDestList = new Array( destList.options.length );
  for(var len = 0; len < destList.options.length; len++ ) {
    if ( destList.options[ len ] != null ){
      newDestList[ len ] = new Option( destList.options[ len ].text, destList.options[ len ].value, destList.options[ len ].defaultSelected, destList.options[ len ].selected );
    }
  }
  for( var i = 0; i < srcList.options.length; i++ ){ 
    if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) ){
       // Statements to perform if option is selected 
	   //Incorporate into new list
       newDestList[ len ] = new Option( srcList.options[i].text, srcList.options[i].value, srcList.options[i].defaultSelected, srcList.options[i].selected );
       len++;
    }
  }
  // Sort out the new destination list by text
  newDestList.sort( compareOptionText );   
  // Populate the destination with the items from the new array
  for ( var j = 0; j < newDestList.length; j++ ) {
    if ( newDestList[ j ] != null ){
      destList.options[ j ] = newDestList[ j ];
    }
  }
  // Erase source list selected elements
  for( var i = srcList.options.length - 1; i >= 0; i-- ) { 
    if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) ) {   
       srcList.options[i] = null;
    }
  }
} // End of moveDualList()
function launchAuxApp(currAmAction,currBusAction,targetAmAction,targetBusAction,targetPage,winVars,targetWindow){
	/* move from ccm.js for rfs 060803103313 */
	var vars = (winVars)?winVars:"toolbar=yes,dependent=yes,menubar=no,scrollbars=yes,resizable=no,status=yes,width=400,height=300";
	if(targetWindow){
		this.document.forms[0].target = targetWindow;
	}else{
	   	AuxWindow = window.open("","Auxilliary_Window",vars);
    	this.document.forms[0].target = "Auxilliary_Window";
	}
	submitPage(targetAmAction,targetBusAction,'none',targetPage);
   	this.document.forms[0].target = "";
	document.forms[0].action = "im.jsp";
	this.document.forms[0].AM_ACTION.value = currAmAction;
	this.document.forms[0].BUS_ACTION.value = currBusAction;
	try{hideUserWait();}catch(e){}
	 
    /*sendToFrame("submitPage('" + targetAmAction + "','" + targetBusAction + "','none','" + targetPage + "')","im.jsp","height: 300; width: 400;top: 5; left: 5;");*/
}