// $Header: /MASweb_MMSQL/6.26.01/debug/client/mascls.js 196   9/27/10 1:57p Jwood $
// © 2010 copyright UTC Fire and Security all rights reserved 
// For Legal Notice, Terms & Conditions see www.ge.com/en/ge/gl_terms.htm 

var sendlook, LookupField, LookupForm, lk_winref, HelpWinRef, ReportWinRef, scrollPos;
var DropDownMenu, DropDownEvent, PullUpMenu, PullUpEvent;
var ScreenHeight, ScreenWidth, ScreenLeft, ScreenTop, ContentLeftMargin, ContentWidth, ContentHeight, ContentBottom, ColNamePrefix;
var OldContentWidth=0;
var ScrollbarWidth=0;
var DateFormat="MM/dd/yyyy";
var PageAdjustCount=0;
var PageAdjustDone=false;
var LockFocus=true;
var Scrolling=false;
var RTFActive=false;
var WindowWidth, WindowHeight;
var BrowserType=new Browser();
var MinStartDate=new Date();
var StartDateLimit=false;

//MERGE: Copied from Commercial - MK 3/4/2008
var lookctl;
var MenuEvent=null;
var MenuEventCount=0;

var imgExpand=null;
var imgCollapse=null;

ScreenHeight=window.screen.availHeight;
ScreenWidth=window.screen.availWidth;
ScreenLeft=window.screenLeft-ScreenWidth>0 ? window.screenLeft : 0;
ScreenTop=window.screenTop>0 ? window.screenTop : 0;
ColNamePrefix="";

function Sel(getit){
	if (window.parent.Frame0.lookctl==""){
		clear_lookup();
		return;
	}
	
	var code;

	code=window.parent.Frame0.lookctl+"=getit;";
	eval(code);
//	window.parent.Frame0.recvlook=getit;
	clear_lookup();

	return;
}
//END MERGE

function lookup_rtn(columnValue, returnString){		// executed in lookup window
	self.opener.LookupReturn(columnValue, returnString);
	
	window.close();
}

function LookupReturn(columnValue, returnString){	// executed from calling window
	var regexPattern=/\$#\d\d\d/;
	var matches, xx, yy, thisMatch, scrap;
	
	if (returnString==null || returnString==undefined){returnString="";}
	
	while (returnString.indexOf("$#039;")!=-1){returnString=returnString.replace("$#039;", "'");}  // character substitution in MASwebutil.dll
	while (columnValue.indexOf("$#039;")!=-1){columnValue=columnValue.replace("$#039;", "'");}
		
	matches=columnValue.match(regexPattern);
	
	// find and replace all other character codes
	if (matches!=null){
		for (xx=0; xx<matches.length; xx++){
			thisMatch=matches[xx];
			yy=parseInt(thisMatch.substr(2, 3), 10);
			scrap="%"+Dec2Hex(yy);
			
			columnValue=columnValue.replace(matches[xx], unescape(scrap));
		}
	}
	
	var columnName=LookupField;
	var formName=LookupForm;
	var returnFields=returnString.split(",");  // character substitution in MASwebutil.dll
	var xx, returnValue, returnField, scrap;
	var returnPair=new Array();

	try 
	{
	    eval("document."+formName+"."+columnName).value=columnValue;
	    eval("document."+formName+"."+columnName).onchange();
	}
	catch (error){
		try 
		{
			document.getElementById(columnName).innerHTML=columnValue;
			document.getElementById(columnName).onchange();
		}
		catch (error){}

		try {eval("document."+formName+".xX_"+columnName).value=columnValue;}
		catch (error){}
	}
	
	for (xx=0; xx<returnFields.length; xx++){
		scrap=returnFields[xx];
		
		if (scrap!=null && scrap!=""){
			returnPair=scrap.split("=");
			returnField=ColNamePrefix+returnPair[0];
			returnValue=unescape(returnPair[1]);
			
			while (returnValue.indexOf("$#044;")!=-1){returnValue=returnValue.replace("$#044;", ",");}  // character substitution in MASwebutil.dll
			
			matches=returnValue.match(regexPattern);

			// find and replace all other character codes
			if (matches!=null){
				for (xx=0; xx<matches.length; xx++){
					thisMatch=matches[xx];
					yy=parseInt(thisMatch.substr(2, 3), 10);
					scrap="%"+Dec2Hex(yy);
					
					returnValue=returnValue.replace(matches[xx], unescape(scrap));
				}
			}
			
			switch (returnField){
				case "colnameprefix": // assumes this is the first value in the return string
					//colNamePrefix=returnValue; obsolete??
					break;
				case "err_msg":  // used by httpRequest lookup returns
					window.alert(returnValue);

					try {eval("document."+formName+"."+columnName).value="";}
					catch (error){}
					
					break;
				default:
					try {document.getElementById(returnField).innerHTML=returnValue;} // prefered form format (Text)
					catch (error){}
					
					try {eval("document."+formName+"."+returnField).value=returnValue;} // old form format or hidden form field
					catch (error){}
					
					try {eval("document."+formName+".xX_"+returnField).value=returnValue;} // support for form submission errors
					catch (error){}
					
					break;
			}
		}
	}
	
	if (columnName.indexOf("dispage_no")>-1 || columnName.indexOf("_open_page")>-1 || columnName.indexOf("_close_page")>-1){dispPageToggle(columnName);}
	if (columnName.indexOf("gldisp_id")>-1){dispPageToggle(columnName);}
	if (columnName=="fail_to_open_event_id" || columnName=="fail_to_close_event_id"){failurePageToggle(eval("document."+formName+"."+columnName));}
	
	return;
}

function lookup_cancel(){
	var columnName=self.opener.LookupField;
	var formName=self.opener.LookupForm;
	
	eval("self.opener."+formName+"."+columnName).focus();
	
	window.close();
	
	return;
}

function checkit(arg){
	var foo=arg;
	return;
}

function do_lookup(colName, windowURL, formName){
	try {lk_winref.close();} catch(error){};
	
	if (formName=="undefined" || formName==null || formName==""){formName="form1";}
	
	try{
		if 	(eval("document."+formName+"."+colName).getAttribute("disabled")){return;}
	}
	catch (error){}
	
	var leftPos=ScreenWidth-575-15;
	var height=300;
	var width=575;
	var parts=new Array();
	var addFields=new Array();
	var firstPart=null;
	var secondPart=null;
	var thirdPart=null;
	var qString="";
	var splitter, scrap, xx, getSeconds, openString, rootColName;
	var dateSelect=(windowURL.indexOf("dateselector.aspx")!=-1);
	var timeSelect=(windowURL.indexOf("timeselector.aspx")!=-1);
	var lookupWindowName="lookup";
	var lookupSeqno=0;
	var openerWindowRef=window.opener;
	//MERGE: Copied from Commercial - MK 3/4/2008
	var DynamicDateSelect=(windowURL.indexOf("dyndateselector.aspx")!=-1);
	//END MERGE
	
	while (openerWindowRef!=undefined){
		lookupSeqno++;
		openerWindowRef=openerWindowRef.opener;
	}
	
	if (lookupSeqno>0){lookupWindowName+=lookupSeqno;}
	
	ColNamePrefix="";
	
	//MERGE: Copied from Commercial - MK 3/4/2008
	if (DynamicDateSelect){height=200; width=375; dateSelect=false;}
	//END MERGE
	if (dateSelect){height=400; width=350;}
	if (timeSelect){height=150; width=300;}
	
	openString="top=30,left="+leftPos+",height="+height+",width="+width+",resizable,scrollbars";
	
	try {
		xx=colName.indexOf("_");
		scrap=colName.substring(0, 3);
		
		if (scrap=="Row" && xx>4){
			rootColName=colName.substring(xx+1);
			ColNamePrefix=colName.substring(0, xx+1);
			//qString+="&colnameprefix="+ColNamePrefix;
		}
		else {rootColName=colName;}
	}
	catch (error){rootColName=colName;}
	
	try {scrap=eval(rootColName+"_Lookup");}
	catch (error){scrap="";}
	
	if (scrap!=""){
		addFields=scrap.split(",");
		
		for (xx=0; xx<addFields.length; xx++){
			qString+="&"+addFields[xx]+"="+escape(eval("document."+formName+"."+ColNamePrefix+addFields[xx]).value);
		}
	}
	
	try {scrap=eval(rootColName+"_Return");}
	catch (error){scrap="";}
	
	if (scrap!=""){qString+="&return="+scrap;}
	
	if (dateSelect){splitter="/";}
	if (timeSelect){splitter=":";}
	
	if (dateSelect || timeSelect){
		LockFocus=false;  // prevents the following focus event from screwing things up
		
		eval("document."+formName+"."+colName).focus();
		
		try {parts=eval("document."+formName+"."+colName).value.split(splitter);}
		catch (error){}
		
		if (parts.length>=1){firstPart=parts[0];}
		if (parts.length>=2){secondPart=parts[1];}
		if (parts.length>=3){thirdPart=parts[2];}
		
		if (dateSelect && parts.length==3){
			if (firstPart!=null){qString+="&part1="+firstPart;}
			if (secondPart!=null){qString+="&part2="+secondPart;}
			if (thirdPart!=null){qString+="&part3="+thirdPart;}
		}
		
		if (timeSelect && parts.length>=2){
			try {getSeconds=eval("document."+formName+"."+colName).getAttribute("seconds");}
			catch (error){}
			
			if (firstPart!=null){qString+="&hour="+firstPart;}
			if (secondPart!=null){qString+="&minute="+secondPart;}
			
			if (getSeconds){
				if (thirdPart==null){thirdPart="00";}
				
				qString+="&second="+thirdPart;
			}
		}
	}
	//MERGE: Copied from Commercial - MK 3/4/2008
	else if (DynamicDateSelect){
		qString="?dateformula="+eval("document."+formName+"."+colName).value;
	}
	//END MERGE
	
	if (qString!=""){
		if (windowURL.indexOf("?")==-1){windowURL+="?"+qString.substring(1);}
		else {windowURL+=qString;}
	}
	
	//MERGE: Copied from Commercial - MK 3/4/2008
	while (openerWindowRef!=undefined){
		lookupSeqno++;
		openerWindowRef=openerWindowRef.opener;
	}

	if (lookupSeqno>0){lookupWindowName+=lookupSeqno;}
	//END MERGE
	
	LookupField=colName;
	LookupForm=formName;
	lk_winref=window.open(windowURL, lookupWindowName, openString);
	
	if (LockFocus){lk_winref.focus();}
	
	return;
}

//MERGE: Copied from Commercial - MK 3/4/2008
function do_search(){
	window.open("search.aspx", "popup", "status,top=150,left=350,height=300,width=450,resizable,scrollbars");
}
//NOTE: Later, maybe add height and width parameters to AdvancedSearch() and call AdvancedSearch from do_search().
//END MERGE

function AdvancedSearch(){
	window.open("search.aspx", "popup", "top=150,left=350,height=160,width=500,status,resizable,scrollbars");
}

function clear_lookup()	// Deprecated - Use CloseLookup() instead
{
	CloseLookup();
}

function lk_foc(ctl) {
	if (LockFocus){
		if (LookupField!=""){ 
			clear_lookup(); 
			LookupField="";	
		}
	}
	else {
		try {lk_winref.focus();}
		catch (error){}
	}
	
	LockFocus=true;
	
	return;
}

function CheckAutoApply(){
	if 	(autoApply=="Y")
	{
		window.location.href="custadjustselect.aspx?recordmode=add";
	}
	else
	{
		OpenPopupWindow("autoapply.aspx", 575, 250);
	}
}

function IMouseOver(imgObject, option){
	var styleClass, srcFile, dotPos, srcExt, newSrc;
	
	if (option=="style"){
		styleClass=imgObject.className;
		imgObject.className=styleClass+"Hover";
	}
	else if (option=="image"){
		srcFile=imgObject.src;
		dotPos=srcFile.lastIndexOf(".");
	
		if (dotPos>-1){
			srcExt=srcFile.substring(dotPos);
			newSrc=srcFile.replace(srcExt, "_hover"+srcExt);
			imgObject.src=newSrc;
		}
	}
}

function IMouseOut(imgObject, option){
	var styleClass, srcFile;
	
	if (option=="style"){
		styleClass=imgObject.className;
		imgObject.className=styleClass.replace("Hover", "");
	}
	else if (option=="image"){
		srcFile=imgObject.src;
		imgObject.src=srcFile.replace("_hover", "");
	}
}

function SetCookie(colValue, colName){
	if (colName!="" && colName!=null){
		document.cookie=colName+"="+escape(colValue);
	}
}

function GetHelp(helpPage){
	try {HelpWinRef.close();} catch(error){};
	
	var xPos=document.URL.indexOf("/report/");
	var destination="help.aspx?helppage="+helpPage;
	var windowWidth=575;
	var left=window.screen.availWidth-windowWidth-15;
	var height=Math.max(600, window.screen.availHeight/2);
	
	if (xPos>-1){destination="../"+destination;}
	
	HelpWinRef=window.open(destination, "help", "top=0,left="+left+",height="+height+",width="+windowWidth+",resizable,scrollbars");
	HelpWinRef.focus();
}

function PageSizeAdjust(){
	var contentRef=document.getElementById("Content");
	var contentSRef=document.getElementById("ContentSpace");
	var headerRef=document.getElementById("PageHeader");
	var headerSRef=document.getElementById("HeaderSpace");
	var footerRef=document.getElementById("PageFooter");
	var footerSRef=document.getElementById("FooterSpace");
	var xx, yy, mName, hName, xIncr, xNumber, yPos;
	
	if (WindowWidth!=undefined && WindowHeight!=undefined){
		window.resizeTo(WindowWidth, WindowHeight);
		WindowWidth=xx; // set to undefined value
		WindowHeight=xx; // set to undefined value
	}

	ScreenHeight=window.screen.availHeight;
	ScreenWidth=window.screen.availWidth;
	ScreenLeft=window.screenLeft ? (window.screenLeft-ScreenWidth>0 ? window.screenLeft : 0) : window.screenX;
	ScreenTop=window.screenTop ? (window.screenTop>0 ? window.screenTop : 0) : window.screenY;
	
	if (contentRef.clientWidth && contentRef.offsetWidth){ // Standard Version
		ContentHeight=contentRef.clientHeight;
		ContentBottom=contentRef.offsetHeight-ContentHeight;
		ContentWidth=DocContentWidth();
		ContentLeftMargin=0;
		
		if (BrowserType.isFF){
			ContentBottom=0;
			
			if (OldContentWidth!=ContentWidth && ScrollbarWidth>0){
				contentRef.style.width=(ContentWidth-ScrollbarWidth+2)+"px";
			}
			else if (contentRef.offsetWidth>contentRef.clientWidth && ScrollbarWidth==0){
				ScrollbarWidth=contentRef.offsetWidth-contentRef.clientWidth;
				ContentWidth=DocContentWidth();
				contentRef.style.width=(ContentWidth-ScrollbarWidth+2)+"px";
			}
		}
	}
	else { // Old Version  (provided for downward compatibility to older browsers)
		ContentHeight=contentRef.offsetHeight;
		ContentBottom=-1;
		ContentWidth=contentSRef.width;
		ContentLeftMargin=contentSRef.offsetLeft;
	}

	headerRef.style.width=ContentWidth+"px";
	headerRef.style.left=ContentLeftMargin+"px";
	headerSRef.style.width=ContentWidth+"px";
	headerSRef.style.left=ContentLeftMargin+"px";
	footerRef.style.width=(ContentWidth-ContentLeftMargin-ContentLeftMargin)+"px";
	footerRef.style.left=ContentLeftMargin+"px";
	footerRef.style.bottom=ContentBottom+"px";
	footerRef.style.paddingRight="0px";
	//footerSRef.style.width=ContentWidth+"px";
	//footerSRef.style.left=ContentLeftMargin+"px";
	
	if (contentRef.clientWidth && contentRef.offsetWidth){ // New Version
		contentRef.style.paddingBottom=footerRef.clientHeight+"px";
	}
	else { // Old Version  (provided for downward compatibility to older browsers)
		contentRef.style.paddingBottom=footerRef.offsetHeight+"px";
	}

	headerSRef.innerHTML=headerRef.innerHTML;
	footerSRef.innerHTML=footerRef.innerHTML;

	if (BrowserType.isFF){
		headerSRef.className+=" HeaderSpace2";
	}

	scrollPos=contentRef.scrollTop;
	OldContentWidth=ContentWidth;

	FormScroll();

	if (DocContentWidth()!=ContentWidth){  // happens on some pages after headerSRef and footerSRef get changed
		window.resizeBy(0, 10);
		PageSizeAdjust();
	}
}

function DocContentWidth()
{
	var contentRef=document.getElementById("Content");
	var clientWidth=BrowserType.isIE ? contentRef.clientWidth : window.innerWidth;

	return clientWidth-ScrollbarWidth;
}

//MERGE: Copied from Commercial - MK 3/4/2008
function ExpandMenuTimer(startGroup){
	return;

	if (MenuEvent!=null){
		MenuEvent.cancelBubble();
		MenuEvent=null;
	}
	
	//MERGE: Copied from Residential - MK 3/4/2008
	MenuEventCount++;
	//END MERGE
	
	var fCall="ExpandMenu("+startGroup+", "+MenuEventCount+")";

   	MenuEvent=setTimeout(fCall, 500);
}
//NOTE: This seems to be defunct since it immediately return's.
//END MERGE

//MERGE: Copied from Commercial - MK 3/4/2008
function ExpandMenu(startGroup, eventCount){
	return;
	
	if (eventCount==MenuEventCount){
		var rowID, row, groupID, group;

		for (group=startGroup; group<100; group++){
			groupID="G"+String(100+group).substr(1,2);

			for (row=1; row<100; row++){
				rowID=groupID+"R"+String(100+row).substr(1, 2);

				if (group==startGroup){
					try {document.getElementById(rowID).style.display="block";}
					catch (error){break;}
				}
				else {
					try {document.getElementById(rowID).style.display="none";}
					catch (error){break;}
				}
			}
		}
	}
}
//NOTE: This seems to be defunct since it immediately return's.
//END MERGE

//MERGE: Copied from Commercial - MK 3/4/2008
function CollapseMenu(fromTag){
	return;
	
	if (MenuEvent!=null){
		MenuEvent.cancelBubble;
		MenuEvent=null;
		MenuEventCount++; // needed to correct a javascript quirk with event propagation order
	}

	var group, row, groupID, rowID;
	var toTag=event.toElement;

	if (!document.getElementById("MenuTable").contains(toTag)){
		for (group=1; group<100; group++){
			groupID="G"+String(100+group).substr(1, 2);

			for (row=1; row<100; row++){
				rowID=groupID+"R"+String(100+row).substr(1, 2);

				try {document.getElementById(rowID).style.display="none";}
				catch (error){break;}
			}
		}
	}
}
//NOTE: This seems to be defunct since it immediately return's.
//END MERGE

//MERGE: Copied from Commercial - MK 3/4/2008
function FractionToDecimal(fieldRef){
	var fractValue=fieldRef.value;
	var decimalNumber=0;
	var dividend=0;
	var	slashPos, spacePos, dotPos;

	while (fractValue.length>0 && ((isNaN(fractValue.substr(0, 1)) && fractValue.substr(0, 1)!=".") || fractValue.substr(0, 1)==" ")){
		fractValue=fractValue.substring(1, fractValue.length); // trim leading non-numerical characters
	}

	while (fractValue.length>0){
		scrap=parseFloat(fractValue);

		if (scrap=="NaN"){break;}

		while (fractValue.length>0 && (!isNaN(fractValue.substr(0, 1)) || fractValue.substr(0, 1)==".") && fractValue.substr(0, 1)!=" "){
			fractValue=fractValue.substring(1, fractValue.length); // trim characters just parsed
		}

		while (fractValue.length>0 && ((isNaN(fractValue.substr(0, 1)) && fractValue.substr(0, 1)!="." && fractValue.substr(0, 1)!="/") || fractValue.substr(0, 1)==" ")){
			fractValue=fractValue.substring(1, fractValue.length); // trim leading non-numerical characters
		}

		if (fractValue.substr(0, 1)=="/"){
			dividend=scrap;
			fractValue=fractValue.substring(1, fractValue.length); // remove "/" character
			scrap=parseFloat(fractValue);

			if (scrap=="NaN"){break;}

			if (dividend!=0){scrap=Math.floor((dividend/scrap)*100)/100;}
			else {scrap=0;}

			while (fractValue.length>0 && (!isNaN(fractValue.substr(0, 1)) || fractValue.substr(0, 1)=="." || fractValue.substr(0, 1)=="/") && fractValue.substr(0, 1)!=" "){
				fractValue=fractValue.substring(1, fractValue.length);  // trim characters just parsed
			}
		}

		decimalNumber=decimalNumber+scrap;
	}

	fieldRef.value=decimalNumber.toString();
}
//END MERGE

function FormScroll(){
	var formItem, currentPos, xx, formxx, thisForm, fieldType, fieldVisibility, topPos, bottomPos, topCheck, bottomCheck;
	var element, prevElement, elementPos, testInfo;
	var includePos=true;
	
	if (document.forms.length>0){
		currentPos=document.getElementById("Content").scrollTop;

		if (currentPos==scrollPos && document.forms.length>0){ // scrolling has stopped
			topCheck=document.getElementById("PageHeader").offsetTop+document.getElementById("PageHeader").offsetHeight;
			bottomCheck=document.getElementById("PageFooter").offsetTop;
			Scrolling=false;

			for (formxx=0; formxx<document.forms.length; formxx++){
				thisForm=document.forms[formxx];
				
				for (xx=0; xx<thisForm.length; xx++){
					fieldType=thisForm[xx].type;
					
					if (fieldType.indexOf("select")==0){
						topPos=-currentPos;
						element=thisForm[xx];
						prevElement="";
						
						//if (element.name=="alarm_type"){testInfo="Start:"+topPos+"<br>";}
						
						while(element.id!="Content"){	// calculate the element's top-edge (y-coordinate) in the window
							includePos=true;
							elementPos=element.offsetTop;

							//if (element.tagName=="FORM" && prevElement=="TABLE"){includePos=false;}
							//if (element.tagName=="FORM" && prevElement=="DIV"){includePos=false;}
							if (element.tagName=="FORM"){includePos=false;}
							if (element.tagName=="P"){includePos=false;}
							if (element.tagName=="TBODY"){includePos=false;}
							if (element.tagName=="TR"){includePos=false;}
							if (element.tagName=="DIV" && element.currentStyle.styleFloat=="none"){includePos=false;}
							
							if (includePos){topPos=topPos+elementPos;}
							
							//if (thisForm[xx].name=="alarm_type"){testInfo+=element.tagName+": "+elementPos+" ("+includePos+", "+element.currentStyle.styleFloat+")<br>";}
							
							prevElement=element.tagName;
							element=element.offsetParent;
						}
						/*
						if (thisForm[xx].name=="alarm_type"){
							testInfo+="topPos: "+topPos+"<br>topCheck: "+topCheck;
							document.getElementById("testReport").innerHTML=testInfo;
						}
						*/
						bottomPos=topPos+thisForm[xx].offsetHeight-2;
						
						if (topPos>topCheck && (bottomPos<bottomCheck || bottomCheck==0)){
							thisForm[xx].style.visibility="visible";
						}
						else {
							fieldType=thisForm[xx].type;
							fieldVisibility=thisForm[xx].style.visibility;
							
							if (fieldType.indexOf("select")==0 && fieldVisibility!="hidden"){
								thisForm[xx].style.visibility="hidden";
							}
						}
					}
				}
			}
		}
		else {
			if (!Scrolling){
				for (formxx=0; formxx<document.forms.length; formxx++){
					thisForm=document.forms[formxx];
					
					for (xx=0; xx<thisForm.length; xx++){
						fieldType=thisForm[xx].type;
						
						if (fieldType.indexOf("select")==0){
							thisForm[xx].style.visibility="hidden";
						}
					}
				}
			}
			
			Scrolling=true;
			setTimeout("FormScroll()", 500);
		}
	}
	
	scrollPos=document.getElementById("Content").scrollTop;
}

function PreSubmit(thisForm){	// disabled fields are not posted back to the server.
	var xx, disabledValue;		// use this function as an onSubmit event handler to remove the disabled attribute
	var eventType=null;			// from the form fields before submitting.
	var proceed=false;			// If this is called outside of an onSubmit event it will do nothing (important
								// for form security).
	try {eventType=event.type;} // Important: This function will only be called if a Submit button is clicked.
	catch (error){}				// If you submit the form using form1.submit() then call FormSubmit() instead.
	
	if (eventType="submit"){
		proceed=true;
		
		for (xx=0; xx<thisForm.length; xx++){
			disabledValue=thisForm[xx].disabled;
			
			if (disabledValue){thisForm[xx].disabled = !disabledValue;}
		}
	}
	
	return proceed;
}

function FormSubmit(){			// This function replaces calls to "form1.submit()".  It is needed whenever a form contains
	var xx, disabledValue;		// disabled fields and is not submitted using a submit button.
	
	for (xx=0; xx<document.form1.length; xx++){
		disabledValue=document.form1[xx].disabled;
		
		if(document.form1[xx].className.indexOf("MLFDeleted")==-1){
			if (disabledValue){document.form1[xx].disabled = !disabledValue;}
		}
	}
	
	document.form1.submit();
	
	return true;
}

function OpenReportWindowQL(reportURL)
{
    if (ReportWinRef!=undefined && ReportWinRef!=null)
	{
		try {ReportWinRef.close();}
		catch (error){}
	}

	ReportWinRef=window.open("about:blank", "ReportViewerWindow", "status,resizable");
	//ReportWinRef=window.open("", "ReportViewerWindow", "status,resizable");

	if (ReportWinRef.document.URL.indexOf("getreport.aspx")!=-1) // || ReportWinRef.document.URL=="about:blank")
	{  // about:blank is the URL for a previous report in IE7 (a bug?)
		ReportWinRef.close();
		ReportWinRef=window.open("about:blank", "ReportViewerWindow", "status,resizable");
	}
	else {
		ReportWinRef=window.open("about:blank", "ReportViewerWindow", "status,resizable", true);
	}

	// In IE7 open window again to prevent automation error (a bug)
	if (BrowserType.isIE && BrowserType.version>=7){ReportWinRef=window.open(reportURL, "ReportViewerWindow", "status,resizable");}
	
	ReportWinRef.location=reportURL;
}

function OpenReportWindow()
{
	var outputType;

	try 
	{
	    for (var i=0; i<document.form1.output_type.length;i++)
	    {
	        if (document.form1.output_type[i].checked)
	        {
	            outputType=document.form1.output_type[i].value;
	            break;
	        }
	    }
	}
	catch (Error)
	{
	    outputType="pdf";
	}
	
	if (outputType=="xls")
	{
	    FormSubmit();
	}
	else
	{
	    if (ReportWinRef!=undefined && ReportWinRef!=null)
		{
			try {ReportWinRef.close();}
			catch (error){}
		}

		ReportWinRef=window.open("about:blank", "ReportViewerWindow", "status,resizable");
		//ReportWinRef=window.open("", "ReportViewerWindow", "status,resizable");

		if (ReportWinRef.document.URL.indexOf("getreport.aspx")!=-1) // || ReportWinRef.document.URL=="about:blank")
		{  // about:blank is the URL for a previous report in IE7 (a bug?)
			ReportWinRef.close();
			ReportWinRef=window.open("about:blank", "ReportViewerWindow", "status,resizable");
		}
		else {
			ReportWinRef=window.open("about:blank", "ReportViewerWindow", "status,resizable", true);
		}

		// In IE7 open window again to prevent automation error (a bug)
		if (BrowserType.isIE && BrowserType.version>=7){ReportWinRef=window.open("about:blank", "ReportViewerWindow", "status,resizable");}

		document.form1.target="ReportViewerWindow";
		FormSubmit();
		document.form1.target="";
		ReportWinRef.focus();
	}
}

function Trim(textToTrim){
	return textToTrim.replace(/^\s+/, "").replace(/\s+$/, "");
}

function ToPascalCase(transText){
	transText=Trim(transText).replace(/[\s_]+([a-z])/g, function($1){return $1.toUpperCase();});
	transText=transText.replace(/[\s_]/g, "");
	
	return transText.replace(/^([a-z])/, function($1){return $1.toUpperCase();});
}

function ToCamelCase(transText){
	transText=Trim(transText).replace(/[\s_]+([a-z])/g, function($1){return $1.toUpperCase();});
	transText=transText.replace(/[\s_]/g, "");
	
	return transText.replace(/^([A-Z])/, function($1){return $1.toLowerCase();});
}

function ToTitleCase(transText){
	transText=Trim(transText).replace(/([A-Z][a-z])/g, " $1").replace(/[\s_]+/g, " ");
	transText=transText.replace(/( [a-z])/g, function($1){return $1.toUpperCase();});
	
	return transText.replace(/^([a-z])/, function($1){return $1.toUpperCase();});
}

function ViewDispPage(fieldName, pageID){
	var windowURL;
	
	if (fieldName.indexOf("gldisp_id")>-1){
		windowURL="globaldispview.aspx?gldisp_id="+pageID;
	}
	else {
		windowURL="sitedispview.aspx?dispage_no="+pageID;
	}
	
	LockFocus=false;
	
	OpenPopupWindow(windowURL, 575, 400);
	
	return;
}

function ViewOnlyLookup(pageName, width, height){
	if (pageName.indexOf(".aspx")==-1){
		pageName+=".aspx";
	}
	
	LockFocus=false;
	
	OpenPopupWindow(pageName, width, height);
	
	return;
}

function CheckNumber(inputField){
	var inputValue=inputField.value;
	var fCall;
	
	if (inputValue!="" && isNaN(inputValue)){
		alert(GetFieldPrompt("InvalidNumericEntry"));
		inputField.value="";
		
		if (inputField.type.toLowerCase()!="hidden"){
			fCall="form1."+inputField.name+".focus()";
			setTimeout(fCall, 1);
		}
	}
}

function SetHiddenValue(formField){
	var hiddenFields=formField.getAttribute("hField").split(",");
	var hiddenValues=formField.getAttribute("hValue").split(",");
	var hiddenValue, xx;
	
	for (xx=0; xx<hiddenFields.length; xx++){
		if (hiddenValues[xx]=="this"){hiddenValue=formField.value;}
		else {hiddenValue=hiddenValues[xx];}
		
		try {eval("document.form1."+hiddenFields[xx]).value=hiddenValue;}
		catch (error){}
	}
}

function SetFieldAccess(formField){  // only valid for checkboxes and radio buttons
	var accessFields=formField.getAttribute("aField").split(",");
	var fieldType=formField.type.toLowerCase();
	var enable=false;
	var xx;
	
	if (formField.tagName=="INPUT"){
		if (fieldType=="checkbox"){
			enable=(formField.getAttribute("aEnable").toLowerCase()=="true");
			
			if (!formField.checked){enable=!enable;}
		}
		else if (fieldType=="radio"){
			for (xx=0; xx<formField.length; xx++){
				if (formField[xx].checked){
					enable=(formField[xx].getAttribute("aEnable").toLowerCase()=="true");
					break;
				}
			}
		}
		else {return;}
	}
	else {return;}
	
	for (xx=0; xx<accessFields.length; xx++){
		if (enable){
			try {eval("document.form1."+accessFields[xx]).removeAttribute("disabled");} catch (error){}
			try {eval("document.form1."+accessFields[xx]).removeAttribute("readOnly");} catch (error){}
			try {eval("document.form1."+accessFields[xx]).className="";} catch (error){}
			
			if (xx==0){
				try {eval("document.form1."+accessFields[xx]).focus;} catch (error){}
			}
		}
		else {
			try {eval("document.form1."+accessFields[xx]).value="";} catch (error){}
			try {eval("document.form1."+accessFields[xx]).setAttribute("disabled", true);} catch (error){}
			try {eval("document.form1."+accessFields[xx]).setAttribute("readOnly", true);} catch (error){}
			try {eval("document.form1."+accessFields[xx]).className="ReadOnly";} catch (error){}
		}
	}
}

//MERGE: Copied from Commercial - MK 3/4/2008
function GetMonthName(monthNo){ // 0=January, 11=December
	var monthName;

	switch (monthNo)
	{
		case 0:
			monthName="Jan";
			break;
		case 1:
			monthName="Feb";
			break;
		case 2:
			monthName="Mar";
			break;
		case 3:
			monthName="Apr";
			break;
		case 4:
			monthName="May";
			break;
		case 5:
			monthName="Jun";
			break;
		case 6:
			monthName="Jul";
			break;
		case 7:
			monthName="Aug";
			break;
		case 8:
			monthName="Sep";
			break;
		case 9:
			monthName="Oct";
			break;
		case 10:
			monthName="Nov";
			break;
		case 11:
			monthName="Dec";
			break;
		default:
			monthName="Unk"; // unknown month
			break;
	}

	return monthName;
}
//END MERGE

//MERGE: Copied from Commercial - MK 3/4/2008
function AdjustLayout()
{
	var needsAdj=true;
	var bannerBG, newWidth, lWidth, cWidth, mWidth;

	try {bannerBG=document.getElementById("Banner").background;}
	catch (error){needsAdj=false;}

	if (needsAdj){
		if (bannerBG==undefined || bannerBG.indexOf("/pixel.gif")==-1){return;}

		try {
			lWidth=document.getElementById("PageLayout").offsetWidth;
			cWidth=document.getElementById("Content").offsetWidth;
			mWidth=parseInt(document.getElementById("LeftMenu").currentStyle.width, 10);

			if (lWidth==undefined || cWidth==undefined || mWidth==undefined){needsAdj=false;}
		}
		catch (error){needsAdj=false;}

		if (needsAdj){
			newWidth=lWidth-mWidth;

			if (newWidth>cWidth){
				document.getElementById("Content").style.width=(lWidth-mWidth)+"px";
			}
		}
	}
}
//END MERGE

//MERGE: Copied from Commercial - MK 3/4/2008
function RemoveStyleClassByID(tagID, className){
	var tagRef, tagClass;

	try {
		tagRef=document.getElementById(tagID);
		tagClass=tagRef.className;

		tagClass=tagClass.replace(className, "");
	}
	catch (error){tagClass="";}

	if (tagRef){
		while (tagClass.indexOf("  ")!=-1){tagClass=tagClass.Replace("  ", " ");}
		while (tagClass.substring(0)==" "){tagClass=tagClass.substring(1);}
		while (tagClass.substring(tagClass.length-1)==" "){tagClass=tagClass.substring(0, tagClass.length-1);}



		tagRef.className=tagClass;
	}
}
//END MERGE

function TranslatePage(aHREF){
	if (!aHREF){aHREF="";}

	LockFocus=true;
	
	OpenPopupWindow(aHREF+"translate.aspx", 800, 600);
	
	return;
}

function OpenPopupWindow(pageName, width, height, popupName, center){
	if (width==null || width==undefined){width=575;}
	if (height==null || height==undefined){height=400;}
	if (center==null || center==undefined || center!=true){center=false;}
	
	ScreenLeft=window.screenLeft-ScreenWidth>0 ? ScreenWidth : 0;
	
	var leftPos, topPos;
	var openerWindowRef=window.opener;
	var lookupSeqno=0;
	
	//MERGE: Copied from Commercial - MK 3/4/2008
	ContentWidth=BrowserType.isIE ? document.clientWidth : window.innerWidth;
	ContentHeight=document.clientHeight;
	//END MERGE
	
	if (popupName==undefined || popupName==null){popupName="lookup";}
	
	if (center)
	{
		leftPos=ScreenLeft+ContentWidth/2-width/2;
		topPos=ScreenTop+ContentHeight/2-height/2;
		
		if (topPos>40){topPos-=40;}
	}
	else
	{
		leftPos=ScreenLeft+ScreenWidth-width-20;
		topPos=10;
	}

	openString="top="+topPos+",left="+leftPos+",height="+height+",width="+width+",resizable,scrollbars,status";
	
	while (openerWindowRef!=undefined){
		lookupSeqno++;
		openerWindowRef=openerWindowRef.opener;
	}
	
	if (lookupSeqno>0){popupName+=lookupSeqno;}

	if (lk_winref!=undefined){
		try {lk_winref.close();} catch (error){};
	}
	
	lk_winref=window.open(pageName, popupName, openString);

	if (LockFocus){lk_winref.focus();}
	
	return;
}

function ParseDate(inString){
	var outDate=null;
	var month=null;
	var day=null;
	var year=null;
	var validDate=false;
	var dateParts, scrap;
	var formatParts=DateFormat.split("/");
	
	if (inString.indexOf("/")==-1 && (inString.length==8 || inString.length==6) && !isNaN(inString)){
		month=Number(inString.substring(0, 1));
		day=Number(inString.substring(2, 3));
		year=Number(inString.substring(4, inString.length-4));
	}
	else if (inString.indexOf("/")>-1){
		dateParts=inString.split("/");
		
		try {
			month=Number(dateParts[0]);
			day=Number(dateParts[1]);
			year=Number(dateParts[2]);
		}
		catch (error){}
	}
	
	if (month!=null && day!=null && year!=null){
		if (year<100){
			if (year>70){year+=1900;}
			else {year+=2000;}
		}
		
		if (formatParts[0]=="dd"){
			scrap=month;
			month=day;
			day=scrap;
		}
		
		outDate=new Date(year, month-1, day);
	}
	
	return outDate;
}

function CheckAllRange(startField, endField, allField, selectNFocus){
	var startRef=eval("document.form1."+startField);
	var endRef=eval("document.form1."+endField);
	var allRef=eval("document.form1."+allField);
	var startValue=startRef.value;
	var endValue=endRef.value;
	
	if (selectNFocus==undefined){selectNFocus=false;}

    if (startValue=="" && 
        (endValue=="" ||
         endValue=="ZZZZZZZZZZ") && 
        !startRef.getAttribute("disabled"))
    {
		if (allRef.checked){allRef.click();}
		
		allRef.click();
		
		if (selectNFocus){
			allRef.select();
			allRef.focus();
		}
	}
	else if (selectNFocus){
		if (allRef.checked){allRef.click();}
		
		startRef.select();
		startRef.focus();
	}
}

function EnableFormField(fieldName, formName){
	var fieldRef, disabled, readOnly, className;
	
	if (formName==undefined){formName="form1";}
	
	try {
		fieldRef=eval("document."+formName+"."+fieldName);
		
		if (fieldRef==undefined){return;}
	}
	catch (Exception){return;}
	
	disabled=fieldRef.getAttribute("disabled");
	readOnly=fieldRef.getAttribute("readOnly");
	className=fieldRef.className;
	
	if (disabled){fieldRef.removeAttribute("disabled");}
	if (readOnly){fieldRef.removeAttribute("readOnly");}

	if (className.indexOf("ReadOnly")>-1){
		className=className.replace("ReadOnly", "").replace("  ", " ");

		if (className.substring(className.length-1)==" "){className=className.substring(0, className.length-1);}
		if (className.substring(0, 1)==" "){className=className.substring(1);}
		
		fieldRef.className=className;
	}
	
	return;
}

function DisableFormField(fieldName, formName){
	var fieldRef, disabled, readOnly, className;
	
	if (formName==undefined){formName="form1";}
	
	try {
		fieldRef=eval("document."+formName+"."+fieldName);
		
		if (fieldRef==undefined){return;}
	}
	catch (Exception){return;}
	
	disabled=fieldRef.getAttribute("disabled");
	readOnly=fieldRef.getAttribute("readOnly");
	className=fieldRef.className;
	
	if (!disabled){fieldRef.setAttribute("disabled", true);}
	if (readOnly){fieldRef.setAttribute("readOnly", true);}

	if (className.indexOf("ReadOnly")==-1){
		className=(className=="" || className==undefined) ? "ReadOnly" : className+" ReadOnly";
		
		fieldRef.className=className;
	}
	
	return;
}

function CreateHttpRequest(method, serverPage, aSync, contentLength){
	var httpRequest=null;
	
	if (window.ActiveXObject){	// IE
		httpRequest=new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest){	// Not IE
		httpRequest=new XMLHttpRequest();
		httpRequest.overrideMimeType('text/xml');
	}
	
	if (aSync==undefined || (aSync!=true && aSync!=false)){aSync=true;}
	if (!contentLength){contentLength=0;}

	if (httpRequest){
		httpRequest.open(method, serverPage, aSync);
		httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		httpRequest.setRequestHeader("Content-Length", contentLength);
		
		return httpRequest;
	}
}

function GetOthers(event){
	var fieldRef, fieldName, fieldValue, fieldType, formName, lookupField;
	var returnList, httpRequest, queryString, xx, scrap, rootColName, rootPath;
	var wEvent=event==undefined ? window.event : event;  // in IE the value will be undefined.
	
	if (!wEvent){return;}

	fieldRef=wEvent.srcElement;

	if (fieldRef==undefined){return;}

	fieldName=fieldRef.name;
	formName=fieldRef.form.name;
	LookupField=fieldName;
	LookupForm=formName;
	ColNamePrefix="";
	
	if (fieldRef.tagName=="INPUT"){fieldType=fieldRef.type.toLowerCase();}
	else {fieldType="";}
	
	try
	{
		switch (fieldRef.type.toLowerCase())
		{
			case "radio":
				fieldValue=GetRadioValue(fieldRef);
				break;
			case "checkbox":
				fieldValue=GetCheckboxValue(fieldRef);
				break;
			default:
				fieldValue=fieldRef.value;
				break;
		}
	}
	catch (error){fieldValue="";}

	try {
		xx=fieldName.indexOf("_");
		scrap=fieldName.substring(0, 3);

		if (scrap=="Row" && xx>4){
			rootColName=fieldName.substring(xx+1);
			ColNamePrefix=fieldName.substring(0, xx+1);
		}
		else {rootColName=fieldName;}
	}
	catch (error){rootColName=fieldName;}

	try {returnList=eval(rootColName+"_Return");}
	catch (error){return;}

	if (returnList=="" || returnList==null){return;}

	scrap=BuildLookupQueryString(rootColName, ColNamePrefix, formName);
	queryString="?field="+fieldName+"&value="+escape(fieldValue)+(scrap=="" ? "" : "&"+scrap)+"&return="+returnList;

	if (document.URL.indexOf("report/")==-1){rootPath="";}
	else {rootPath="../";}

	httpRequest=CreateHttpRequest("POST", rootPath+"dynamicvalue.aspx"+queryString, true);

	httpRequest.onreadystatechange=function(){
		if (httpRequest.readyState==4){
			LookupReturn(fieldValue, httpRequest.responseText);
		}
	}

	httpRequest.send("");

	return true;
}
	
function CheckZipCode(doAfter, zipRef){
	var zipQS, queryString, httpRequest, rootPath, errorRef, formRef;
	var returnText, returnPair, returnFields, errorMsg, xx, scrap, fieldName, fieldValue, errMsg;
	var errored=false;
	
	if (zipRef){zipQS="?zipname="+zipRef.name+"&zip="+escape(zipRef.value);}
	else {return true;}
	
	if (document.URL.indexOf("report/")==-1){rootPath="";}
	else {rootPath="../";}
	
	queryString=zipQS;
	httpRequest=CreateHttpRequest("POST", rootPath+"checkzipcode.aspx"+queryString, false);
	
	httpRequest.send("");
	
	returnText=httpRequest.responseText;
	
	while (returnText.indexOf("$#039;")!=-1){returnText=returnText.replace("$#039;", "'");}
	
	returnFields=returnText.split(',');

	for (xx=0; xx<returnFields.length; xx++){
		scrap=returnFields[xx];
		
		if (scrap!=null && scrap!=""){
			returnPair=scrap.split('=');
			fieldName=returnPair[0];
			fieldValue=returnPair[1];
			
			if (fieldName=="error"){
				errMsg=unescape(fieldValue);
				errored=true;
				errorRef=document.getElementById("ErrorMsg");

				if (!errorRef)
				{
					errorRef=document.createElement("p");
					errorRef.id="ErrorMsg";
					formRef=zipRef.form;					
					formRef.offsetParent.insertBefore(errorRef, formRef);
				}

				errorRef.innerHTML=errMsg;
				scrap=errorRef.className;
				
				if (scrap && scrap.indexOf("NoDisplay")>-1){scrap=scrap.replace(" NoDisplay", "");}
				else {scrap="ErrorMsg";}
				
				errorRef.className=scrap;
			}
			else if (fieldName!=""){
				zipRef.form[fieldName].value=unescape(fieldValue);
			}
		}
	}
	
	if (!errored){
		try {
			document.getElementById("ErrorMsg").innerHTML="";
			scrap=document.getElementById("ErrorMsg").className;
			
			if (scrap && scrap.indexOf("NoDisplay")==-1){scrap+=" NoDisplay";}
			else {scrap="ErrorMsg NoDisplay";}
			
			document.getElementById("ErrorMsg").className=scrap;
		}
		catch (error){}
		
		if (doAfter){
			while(doAfter.indexOf("$#039;")!=-1){doAfter=doAfter.replace("$#039;", "'");}
			
			eval(unescape(doAfter));
		}
	}
	
	return !errored;
}

function CheckDateRange(doAfter, startDateRef, endDateRef, startTimeRef, endTimeRef, /*MERGE: Copied from Commercial - MK 3/4/2008*/fleetListRef/*END MERGE*/){
	var startDateQS, endDateQS, startTimeQS, endTimeQS, /*MERGE: Copied from Commercial - MK 3/4/2008*/fleetListQS,/*END MERGE*/ queryString, httpRequest, rootPath;
	var returnText, returnPair, returnFields, errorMsg, xx, scrap, fieldName, fieldValue, errMsg;
	var errored=false;
	var fleets=new Array();
	
	if (startDateRef){startDateQS="?sdatename="+startDateRef.name+"&sdate="+escape(startDateRef.value);}
	else {return true;}
	
	if (startTimeRef){startTimeQS="&stimename="+startTimeRef.name+"&stime="+escape(startTimeRef.value);}
	if (endDateRef){endDateQS="&edatename="+endDateRef.name+"&edate="+escape(endDateRef.value);}
	if (endTimeRef){endTimeQS="&etimename="+endTimeRef.name+"&etime="+escape(endTimeRef.value);}

	//MERGE: Copied from Commercial - MK 3/4/2008
	if (fleetListRef){
		if (fleetListRef.length==0){
			if (fleetListRef.checked){fleetListQS="&fleetlist="+fleetListRef.value;}
		}
		else {
			for (xx=0; xx<fleetListRef.length; xx++){
				if (fleetListRef[xx].checked){fleets.push(fleetListRef[xx].value);}
			}

			fleetListQS="&fleetlist="+fleets.join(',');
		}
	}
	//END MERGE

	if (document.URL.indexOf("report/")==-1){rootPath="";}
	else {rootPath="../";}

	queryString=startDateQS+(startTimeQS ? startTimeQS : "")+(endDateQS ? endDateQS : "")+(endTimeQS ? endTimeQS : "")/*MERGE: Copied from Commercial - MK 3/4/2008*/+(fleetListQS ? fleetListQS : "")/*END MERGE*/;
	httpRequest=CreateHttpRequest("POST", rootPath+"checkdaterange.aspx"+queryString, false);
	
	httpRequest.send("");
	
	returnText=httpRequest.responseText;
	
	while (returnText.indexOf("$#039;")!=-1){returnText=returnText.replace("$#039;", "'");}
	
	returnFields=returnText.split(',');

	for (xx=0; xx<returnFields.length; xx++){
		scrap=returnFields[xx];
		
		if (scrap!=null && scrap!=""){
			returnPair=scrap.split('=');
			fieldName=returnPair[0];
			fieldValue=returnPair[1];
			
			if (fieldName=="error"){
				errMsg=unescape(fieldValue);
				errored=true;
				errorRef=document.getElementById("ErrorMsg");

				if (!errorRef)
				{
					errorRef=document.createElement("p");
					errorRef.id="ErrorMsg";
					scrap=startTimeRef.form;
					
					scrap.offsetParent.insertBefore(errorRef, scrap);
				}

				errorRef.innerHTML=errMsg;
				scrap=errorRef.className;
				
				if (scrap && scrap.indexOf("NoDisplay")>-1){scrap=scrap.replace(" NoDisplay", "");}
				else {scrap="ErrorMsg";}
				
				errorRef.className=scrap;
			}
			else if (fieldName!=""){
				startDateRef.form[fieldName].value=unescape(fieldValue);
			}
		}
	}
	
	if (!errored){
		try {
			document.getElementById("ErrorMsg").innerHTML="";
			scrap=document.getElementById("ErrorMsg").className;
			
			if (scrap && scrap.indexOf("NoDisplay")==-1){scrap+=" NoDisplay";}
			else {scrap="ErrorMsg NoDisplay";}
			
			document.getElementById("ErrorMsg").className=scrap;
		}
		catch (error){}
		
		if (doAfter){
			while(doAfter.indexOf("$#039;")!=-1){doAfter=doAfter.replace("$#039;", "'");}
			
			eval(unescape(doAfter));
		}
	}
	
	return !errored;
}

function CheckTimeRange(doAfter, startTimeRef, endTimeRef){
	var startTimeQS, endTimeQS, queryString, httpRequest, rootPath, errorRef;
	var returnText, returnPair, returnFields, errorMsg, xx, scrap, fieldName, fieldValue, errMsg;
	var errored=false;
	
	if (startTimeRef){startTimeQS="?stimename="+startTimeRef.name+"&stime="+escape(startTimeRef.value);}
	else {return true;}

	if (endTimeRef){endTimeQS="&etimename="+endTimeRef.name+"&etime="+escape(endTimeRef.value);}

	if (document.URL.indexOf("report/")==-1){rootPath="";}
	else {rootPath="../";}

	queryString=startTimeQS+(endTimeQS ? endTimeQS : "");
	httpRequest=CreateHttpRequest("POST", rootPath+"checktimerange.aspx"+queryString, false);
	
	httpRequest.send("");
	
	returnText=httpRequest.responseText;
	
	while (returnText.indexOf("$#039;")!=-1){returnText=returnText.replace("$#039;", "'");}
	
	returnFields=returnText.split(',');

	for (xx=0; xx<returnFields.length; xx++){
		scrap=returnFields[xx];
		
		if (scrap!=null && scrap!=""){
			returnPair=scrap.split('=');
			fieldName=returnPair[0];
			fieldValue=returnPair[1];
			
			if (fieldName=="error"){
				errMsg=unescape(fieldValue);
				errored=true;
				errorRef=document.getElementById("ErrorMsg");

				if (!errorRef)
				{
					window.alert(errMsg);
				}
				else
				{
					errorRef.innerHTML=errMsg;
					scrap=errorRef.className;
					
					if (scrap && scrap.indexOf("NoDisplay")>-1){scrap=scrap.replace(" NoDisplay", "");}
					else {scrap="ErrorMsg";}
					
					errorRef.className=scrap;
				}
			}
			else if (fieldName!=""){
				startTimeRef.form[fieldName].value=unescape(fieldValue);
			}
		}
	}
	
	if (!errored){
		try {
			document.getElementById("ErrorMsg").innerHTML="";
			scrap=document.getElementById("ErrorMsg").className;
			
			if (scrap && scrap.indexOf("NoDisplay")==-1){scrap+=" NoDisplay";}
			else {scrap="ErrorMsg NoDisplay";}
			
			document.getElementById("ErrorMsg").className=scrap;
		}
		catch (error){}
		
		if (doAfter){eval(unescape(doAfter));}
	}
	
	return !errored;
}

//MERGE: Copied from Commercial - MK 3/4/2008
function CheckIfValid(doAfter, fieldName, fieldValue, qs1, qs2, qs3, qs4){
	var queryString="?field="+escape(fieldName)+"&value="+escape(fieldValue);
	var isValid=false;
	var httpRequest, rootPath, returnText;

	if (qs1){queryString+="&qs1="+escape(qs1);}
	if (qs2){queryString+="&qs2="+escape(qs2);}
	if (qs3){queryString+="&qs3="+escape(qs3);}
	if (qs4){queryString+="&qs4="+escape(qs4);}

	if (window.location.href.indexOf("report/")==-1){rootPath="";}
	else {rootPath="../";}

	httpRequest=CreateHttpRequest("POST", rootPath+"checkifvalid.aspx"+queryString, false, 0);

	httpRequest.send("");

	returnText=httpRequest.responseText;

	isValid=returnText=="True";

	if (doAfter!=null){window.setTimeout(doAfter+"("+isValid.toString()+")", 1);}

	return isValid;
}
//END MERGE

//MERGE: Copied from Commercial - MK 3/4/2008
function CheckDeviceType(deviceTypeRef)
{
	var queryString, httpRequest;
	var returnText;

	if (deviceTypeRef) 
	{
	    queryString="devicetype="+deviceTypeRef.value;
	}
	else
	{
	    queryString="devicetype=TNC";
	}

	httpRequest=CreateHttpRequest("POST", "checkdevicetype.aspx?"+queryString, false, 0);

	httpRequest.send("");

	returnText=httpRequest.responseText;

	return returnText;
}
//END MERGE

function InitRTFEditor(){
	var editorRef=document.getElementById("RTFEditor");
	var editDocRef=editorRef.contentWindow.document;
	
	editDocRef.onkeypress=function(){UpdateRTF();}
	editDocRef.onkeyup=function(){UpdateRTF();}
	editDocRef.onmouseup=function(){UpdateRTF();}
	editDocRef.body.onblur=function(){UpdateRTF();}
	
	// Delay because these events fire before they occur
	editDocRef.body.ondrop=function(){setTimeout("UpdateRTF()", 100);}
	editDocRef.body.oncut=function(){setTimeout("UpdateRTF()", 100);}
	editDocRef.body.onpaste=function(){setTimeout("UpdateRTF()", 100);}
	
	RTFSetSelectRange();
}

function SetRTFAction(controlRef){
	var controlName=controlRef.name;
	var command=controlName.substring(3);
	var editorRef=document.getElementById("RTFEditor");
	var editDocRef=editorRef.contentWindow.document;
	var controlIndex=controlRef.selectedIndex;
	var scrap, xPos, yPos, screenWidth, screenHeight, dWidth, dHeight;
	
	RTFSetSelectRange();
	
	if (controlIndex!=null){  // <select ...> controls
		scrap=controlRef[controlIndex].value;
		
		editDocRef.execCommand(command, false, scrap);
	}
	else if (command=="ForeColor" || command=="BackColor"){
		scrap=DecimalToRGB(editDocRef.queryCommandValue(command));
		xPos=event.screenX;
		yPos=event.screenY;
		dWidth=180;
		dHeight=186;
		
		if (xPos+dWidth>ScreenWidth){xPos=ScreenWidth-dWidth-10;}
		if (yPos+dHeight>ScreenHeight-30){yPos=ScreenHeight-dHeight-40;}
		
		scrap=showModalDialog("colorselector.aspx", scrap, "dialogWidth:"+dWidth+"px; dialogHeight:"+dHeight+"px; dialogLeft:"+xPos+"; dialogTop:"+yPos+"; resizable:yes; help:no; status:no; scroll:no");
		
		if (scrap!=null){editDocRef.execCommand(command, false, scrap);}
	}
	else {
		// undo superscript and subscript when in conflict
		if ((command=="Superscript" || command=="Subscript") && editDocRef.queryCommandState(command)){editDocRef.execCommand(command);}
		
		editDocRef.execCommand(command);
	}
	
	UpdateRTF();
}

function UpdateRTF(){
	if (RTFActive){
		setTimeout("UpdateRTF()", 333);
		return;
	}

	RTFActive=true;
	
	var editorRef=document.getElementById("RTFEditor");
	var editDocRef=editorRef.contentWindow.document;
	var editEventRef=editorRef.contentWindow.event;
	var isActiveCmd, buttonRef, className, fontName, fontSize, fonts, found, fontRef, sizeRef, xx, yy, scrap;
	var commands=new Array("BackColor", "Bold", "ForeColor", "Indent", "InsertHorizontalRule", "InsertOrderedList", "InsertUnorderedList", 
		"Italic", "JustifyCenter", "JustifyLeft", "JustifyRight", "Outdent", "StrikeThrough", "Underline");
	
	document.form1.RTFText.value=editDocRef.body.innerHTML;
	
	for (xx=0; xx<commands.length; xx++){
		try {
			buttonRef=document.form1["RTF"+commands[xx]];
			
			if (buttonRef==null || buttonRef==undefined){continue;}
		}
		catch (error){continue;}
		
		isActiveCmd=editDocRef.queryCommandState(commands[xx]);
		className=buttonRef.className;
		
		if (isActiveCmd){
			if (className==""){className="ButtonDown";}
			else if (className.indexOf("ButtonDown")==-1){className=className.replace("Button", "ButtonDown");}
			
			if (className.indexOf("ButtonDown")==-1){className="ButtonDown "+className;}
		}
		else {
			if (className==""){className="Button";}
			else if (className.indexOf("ButtonDown")!=-1){className=className.replace("ButtonDown", "Button");}
			
			if (className.indexOf("Button")==-1){className="Button "+className;}
		}
		
		buttonRef.className=className;
	}
	
	fontName=editDocRef.queryCommandValue("FontName");
	fontSize=editDocRef.queryCommandValue("FontSize");
	found=false;
	
	if (fontName!=null){fontName=fontName.toLowerCase();}
	
	try {
		fontRef=document.form1["RTFFontName"];
		
		if (fontRef){
			if (fontName==null){fontRef.value=fontName;}
			else {
				for (xx=0; xx<fontRef.length; xx++){
					scrap=fontRef[xx].value.toLowerCase();
					fonts=scrap.split(/\s*,\s*/);
					
					for (yy=0; yy<fonts.length; yy++){
						if (fonts[yy]==fontName){
							found=true;
							fontRef[xx].selected=true;
							break;
						}
					}
					
					if (found){break;}
				}
				
				if (!found){fontRef.value=fontName;}
			}
		}
	}
	catch (error){}
	
	found=false;
	
	try {
		sizeRef=document.form1["RTFFontSize"];
		
		if (sizeRef){
			if (fontSize==null){sizeRef.value=fontSize;}
			else {
				for (xx=0; xx<sizeRef.length; xx++){
					scrap=sizeRef[xx].value;
					
					if (scrap==fontSize){
						found=true;
						sizeRef.value=fontSize;
						break;
					}
				}
				
				if (!found){sizeRef.value=fontSize;}
			}
		}
	}
	catch (error){}
	
	RTFActive=false;
}

function RTFSetSelectRange()
{
	var editorRef=document.getElementById("RTFEditor");
	var editDocRef=editorRef.contentWindow.document;
	var editRange=editDocRef.body.createTextRange();
	var selectedRange=editDocRef.selection.createRange();

	if (selectedRange.boundingHeight==0 || !editRange.inRange(selectedRange))
	{
		editRange.collapse();  // set insertion point at the beginning
		editRange.select();  // ensures the selection is highlighted
		selectedRange=editRange;
	}
	else if (editRange.inRange(selectedRange))
	{
		editDocRef.focus(); // Deselect the button just pressed by the user
		selectedRange.select(); // Ensures that the insertion point is set to the current cursor position or selected text
	}
}

function DecimalToRGB(decimalNo){
	var rgbValue="#";
	var xx, firstByte, firstNybble, secondNybble;
	
	for (xx=0; xx<3; xx++){
		firstByte=decimalNo&0xFF;	// get low byte
		secondNybble=firstByte&0x0F;	// get low nybble (4 bits)
		firstNybble=(firstByte>>4)&0x0F;	// get high nybble
		
		rgbValue+=firstNybble.toString(16);	// convert nybbles to hex
		rgbValue+=secondNybble.toString(16);
		
		decimalNo>>=8;	// drop first byte for next loop
	}
	
	return rgbValue.toUpperCase();
}

//MERGE: Copied from Residential - MK 3/4/2008
function Disabled(){}
//END MERGE

function ValidateEmail(emailAddress){
     var emailReg="^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
     var regex=new RegExp(emailReg);
     
     return regex.test(emailAddress);
}

function CheckAll(checked, fieldList){
	var fields=fieldList.split(",");
	try {
		for (xx=0; xx<fields.length; xx++){
			try {
				document.getElementById(fields[xx]).checked=checked;
			}
			catch (error) {}
		}
	}
	catch (error) {}
}

function JSLinkAction(){
	// do nothing - place the actual JS call in an OnClick event
}

function GetArrayFieldValue(fieldRef)
{
	var fieldValue="";
	var xx;

	for (xx=0; xx<fieldRef.length; xx++)
	{
		if (fieldRef[xx].checked)
		{
			if (fieldValue!=""){fieldValue+=",";}
			
			fieldValue+=fieldRef[xx].value;
			
			if (fieldRef.type.toLowerCase()=="radio"){break;}
		}
	}

	return fieldValue;
}

function GetRadioValue(fieldRef)
{
	  // go through fieldRef.form to be sure we are referencing the array of radio choices instead of a single choice
	return GetArrayFieldValue(fieldRef.form[fieldRef.name]);
}

function GetCheckboxValue(fieldRef)
{
	var fieldRef=fieldRef.form[fieldRef.name];
	var fieldValue;

	if (fieldRef.length==1)
	{
		if (fieldRef.checked){fieldValue=fieldRef.value;}
		else {fieldValue="";}
	}
	else {fieldValue=GetArrayFieldValue(fieldRef);}

	return fieldValue;
}

function GetSelectMultiValue(fieldRef)
{
	var choices=fieldRef.options;
	var fieldValues=new Array();
	var xx;
	
	for (xx=0; xx<choices.length; xx++)
	{
		if (choices[xx].selected){fieldValues.push(escape(choices.value));}
	}
	
	return fieldValues.join(',');
}

function GetFieldValue(fieldRef){
	var fieldRef=fieldRef.form[fieldRef.name];  // ensure that reference is to the field and not one single radio or checkbox option
	var fieldValue;
	
	switch (fieldRef.type)
	{
		case "radio":
			fieldValue=GetRadioValue(fieldRef);
			break;
		case "checkbox":
			fieldValue=GetCheckboxValue(fieldRef);
			break;
		case "select-multiple":
			fieldValue=GetSelectMultiValue(fieldRef);
			break;
		default:
			fieldValue=fieldRef.value;
			break;
	}
	
	return fieldValue;
}

function GetLookupData(fieldRef)
{
	var fieldName=fieldRef.name;
	var lookupList="";
	var fieldType, fieldValue, lookupRef, lookupType, queryString, colNamePrefix, rootPath, httpRequest, scrap, xx;
	
	colNamePrefix="";

	try {
		xx=fieldName.indexOf("_");
		scrap=fieldName.substring(0, 3);

		if (scrap=="Row" && xx>4){
			colNamePrefix=fieldName.substring(0, xx+1);
			fieldName=fieldName.substring(xx+1);
		}
	}
	catch (error){}
	
	if (fieldRef.tagName=="INPUT"){fieldType=fieldRef.type.toLowerCase();}
	else {fieldType="";}
	
	try
	{
		switch (fieldRef.type.toLowerCase())
		{
			case "radio":
				fieldValue=GetRadioValue(fieldRef);
				break;
			case "checkbox":
				fieldValue=GetCheckboxValue(fieldRef);
				break;
			default:
				fieldValue=fieldRef.value;
				break;
		}
	}
	catch (error){fieldValue="";}
	
	scrap=BuildLookupQueryString(fieldName, colNamePrefix, fieldRef.form.name);
	queryString="?field="+fieldName+"&value="+escape(fieldValue)+(scrap=="" ? "" : "&"+scrap);

	if (document.URL.indexOf("report/")==-1){rootPath="";}
	else {rootPath="../";}

	httpRequest=CreateHttpRequest("POST", rootPath+"dynamicvalue.aspx"+queryString, false);

	httpRequest.send("");
	
	return httpRequest.responseText;
}

function BuildLookupQueryString(fieldName, colNamePrefix, formName)
{
	if (formName==undefined){formName="form1";}
	if (colNamePrefix==undefined){colNamePrefix="";}
	
	var formRef=document.forms[formName];
	var fieldRef=formRef[colNamePrefix+fieldName];
	var queryString="";
	var lookupList, lookupFields, lookupRef, lookupType, lookupField, lookupValue, xx, scrap;
	
	try {
		lookupList=eval(fieldName+"_Lookup");
		
		if (lookupList!=null)
		{
			lookupFields=lookupList.split(',');
			
			for (xx=0; xx<lookupFields.length; xx++)
			{
				lookupField=lookupFields[xx];
				
				if (lookupField==""){continue;}
				
				try
				{
					lookupRef=formRef[colNamePrefix+lookupField];
					
					if (lookupRef.tagName=="INPUT"){lookupType=lookupRef.type.toLowerCase();}
					else {lookupType="";}
					
					switch (lookupType)
					{
						case "radio":
							lookupValue=GetRadioValue(lookupRef);
							break;
						case "checkbox":
							lookupValue=GetCheckboxValue(lookupRef);
							break;
						default:
							lookupValue=lookupRef.value;
							break;
					}
				}
				catch (error){
					try {lookupValue=document.getElementById(ColNamePrefix+lookupField).innerHTML;}
					catch (error){continue;}
				}

				if (queryString!=""){queryString+="&";}
				
				queryString+=lookupField+"="+escape(lookupValue);
			}
		}
	}
	catch (error){}
	
	return queryString;
}

function RebuildSelectOptions(fieldRef, delimData)
{
	var fieldValue=fieldRef.value;
	var rows=delimData.replace("$#039;", "'").split('$$');
	var option, columns, nameValuePair, optionValue, optionDescr, scrap, xx, yy;
	
	fieldRef.value="";
	fieldRef.options.length=0;
	
	for (xx=0; xx<rows.length; xx++)
	{
		scrap=rows[xx].replace("$#036;", "$");
		columns=scrap.split(',');
		optionValue=null;
		optionDescr=null;
		
		for (yy=0; yy<columns.length; yy++)
		{
			scrap=columns[yy].replace("$#044", ",");
			nameValuePair=columns[yy].split('=');
			
			if (nameValuePair.length==2)
			{
				if (yy==0){optionValue=unescape(nameValuePair[1]);}
				else {optionDescr=unescape(nameValuePair[1]);}
			}
			
			if (yy==1){break;}  // only use the first two columns
		}
		
		if (optionValue!=null && optionDescr!=null){
			option=document.createElement("OPTION");
			option.text=optionDescr;
			option.value=optionValue;
			fieldRef.options.add(option);
			
			if (optionValue==fieldValue){fieldRef.value=optionValue;}
		}
	}
}

// Determine browser and version.
function Browser()
{
	var userAgent=navigator.userAgent;
	var xPos;

	this.isIE=false;  // These are not declared with "var" to expand scoping so this function can be queried as an object
	this.isNS=false;
	this.isFF=false;
	this.version=null;

	if (userAgent.indexOf("MSIE")>-1)
	{
		xPos=userAgent.indexOf("MSIE");
		
		this.isIE=true;
		this.version=parseFloat(userAgent.substr(xPos+4));
	}
	else if (userAgent.indexOf("Netscape6/")>-1)
	{
		xPos=userAgent.indexOf("Netscape6/");
		
		this.isNS=true;
		this.version=parseFloat(userAgent.substr(xPos+10));
	}
	else if (userAgent.indexOf("Firefox")>-1)
	{
		xPos=userAgent.indexOf("Firefox/");
		
		this.isFF=true;
		this.version=parseFloat(userAgent.substr(xPos+8));
	}
	else if (userAgent.indexOf("Gecko")>-1) // Treat any other "Gecko" browser as NS 6.1.
	{
		xPos=userAgent.indexOf("Gecko");
		this.isNS=true;
		this.version=6.1;
	}
}

//MERGE: Copied from Commercial - MK 3/4/2008
function SetAllDayOption(startTimeRef, endTimeRef)
{
	var allDayRef=startTimeRef.form.all_day;
	var startDate=new Date();
	var endDate=new Date();
	var midnight=new Date();
	var xx, yy, startTime, endTime, timeRef, timeParts, scrapDate, scrap, midSecs, startSecs, endSecs;

	midnight.setHours(0, 0, 0, 0);
	startDate.setHours(0, 0, 0, 0);
	endDate.setHours(23, 59, 59, 999);

	for (xx=0; xx<2; xx++)
	{
		timeRef=xx==0 ? startTimeRef : endTimeRef;
		scrapDate=xx==0 ? startDate : endDate;
		scrap=timeRef.value;
		timeParts=scrap.split(':');

		if (timeParts.length>1)
		{
			for (yy=0; yy<timeParts.length; yy++)
			{
				switch (yy)
				{
					case 0:
						scrapDate.setHours(parseInt(timeParts[yy], 10));
						break;
					case 1:
						scrapDate.setMinutes(parseInt(timeParts[yy], 10));
						break;
					case 2:
						scrapDate.setSeconds(parseInt(timeParts[yy], 10));
						break;
				}
			}

			switch (xx)
			{
				case 0:
					startDate.setTime(scrapDate.getTime());
					break;
				case 1:
					endDate.setTime(scrapDate.getTime());
					break;
			}
		}
	}
		
	midSecs=Math.floor(midnight.getTime()/1000);
	startSecs=Math.floor(startDate.getTime()/1000);
	endSecs=Math.ceil(endDate.getTime()/1000);
	
	startSecs-=midSecs;
	endSecs-=midSecs;
	
	if (startSecs==0 && endSecs==86400 && !allDayRef.checked){allDayRef.click();}
}
//END MERGE

function CloseLookup()
{
	if (lk_winref!=undefined)
	{
		try {lk_winref.close();}
		catch (error){}
	}
}

// Parses a form into a name=value&... string
function BuildFormString(formRef)
{
	var formItems=new Array();
	var xx;

	for (xx=0; xx<formRef.length; xx++)
	{
		formItems[xx]=formRef[xx].name+"="+escape(GetFieldValue(formRef[xx]));
	}

   return formItems.join('&');
}

function SubmitFormAjax(formRef, serverPage, doAfterRef, objToFill)
{
	var formString=BuildFormString(formRef);
	var contentLength=formString.length;
	var httpRequest=CreateHttpRequest("POST", serverPage, true, contentLength);
	
	if (doAfterRef)
	{
		httpRequest.onreadystatechange=function()
		{
			if (httpRequest.readyState==4)
			{
				//Added objToFill to handle calls from the merged NavLogix pages.  The supporting function setAjaxContent was added.  - MK 3/4/2008
				if(objToFill)
					doAfterRef(httpRequest.responseText, objToFill);
				else
					doAfterRef(httpRequest.responseText);
			}
		}
	}
	
	httpRequest.send(formString);
}

// Merges an HTML string into the current document
function InsertHTMLToPage(containerRef, htmlFrag)
{
	//var containerDoc=containerRef.document;
	var docFrag=window.document.createDocumentFragment();
	var htmlRef;
	var bodyRef;
	var xx, childRef, parentRef, parseRef;
	
	while (htmlFrag.indexOf("$#039;")!=-1){htmlFrag=htmlFrag.replace("$#039;", "'");}
	
	if (BrowserType.isIE)
	{
		htmlRef=docFrag.createElement("html");
		bodyRef=docFrag.createElement("body");
	}
	else  // super easy in FF - Nice, since it apparently doesn't support the DHTML commands on a document fragment
	{
		containerRef.innerHTML=htmlFrag;
		return;
	}
	
	if (containerRef.tagName=="TR")
	{
		htmlFrag="<table><tr id=\"TagParser\">"+htmlFrag+"</tr></table>";
	}
	else
	{
		bodyRef.id="TagParser";
	}

	bodyRef.innerHTML=htmlFrag;
	htmlRef.appendChild(bodyRef);
	docFrag.appendChild(htmlRef);
	
	parseRef=docFrag.getElementById("TagParser");
	
	for (xx=0; xx<parseRef.childNodes.length; xx++)
	{
		CopyNode(containerRef, parseRef.childNodes[xx]);
	}
}

// Copy One Node Hierarchy into Another Parent Hierarchy
function CopyNode(newParent, sourceNode)
{
	var tagType=sourceNode.tagName;
	var nodeType=sourceNode.nodeType;
	var newChild=null;
	var canHaveChildren=true;
	var xx, attribName, attribValue, newValue, fieldName, inputType, childHTML, childParts;
	
	if (nodeType==3)
	{
		newChild=newParent.document.createTextNode(sourceNode.data);
		newParent.appendChild(newChild);
		canHavChildren=false;
	}
	else if ((tagType=="TD" && newParent.tagName=="TR") || (tagType=="TR" && newParent.tagName=="TABLE"))
	{
		if (tagType=="TD"){newChild=newParent.insertCell(-1);}
		else {newChild=newParent.insertRow(-1);}
		
		if (sourceNode.className!=newChild.className){newChild.className=sourceNode.className;}  // not in the attributes collection

		for (xx=0; xx<sourceNode.attributes.length; xx++)
		{
			attribName=sourceNode.attributes[xx].name.toLowerCase();
			attribValue=sourceNode.getAttribute(attribName);
			newValue=newChild.getAttribute(attribName);
			
			if (newValue!=attribValue && attribName!="style")
			{
				newChild.setAttribute(attribName, attribValue);
			}
		}
	}
	else if (nodeType==1)
	{
		childParts=new Array();

		childParts.push(tagType.toLowerCase());
		
		if (tagType=="INPUT"){childParts.push("type=\""+sourceNode.type+"\"");}
		if (sourceNode.name){childParts.push("name=\""+sourceNode.name+"\"");}

		childHTML="<"+childParts.join(' ')+">";	// temporary assignment
		newChild=newParent.document.createElement(childHTML);	// temporary assignment
		
		if (sourceNode.className!=newChild.className){childParts.push("class=\""+sourceNode.className+"\"");}  // not in the attributes collection
		
		for (xx=0; xx<sourceNode.attributes.length; xx++)
		{
			attribName=sourceNode.attributes[xx].name.toLowerCase();
			
			if (attribName!="name" && attribName!="type" && attribName!="style")
			{
				attribValue=sourceNode.getAttribute(attribName);
				newValue=newChild.getAttribute(attribName);
				
				if (attribValue && IsEventHandlerAttribute(attribName))
				{
					attribValue=GetFunctionText(attribValue);
					newValue="";
				}
				
				if (newValue!=attribValue)
				{
					childParts.push(attribName+"=\""+attribValue+"\"");
				}
			}
		}
		
		newChild.removeNode(true);
		childHTML="<"+childParts.join(' ')+">";
		newChild=newParent.document.createElement(childHTML);
		newParent.appendChild(newChild);
	}

	if (canHaveChildren)
	{
		// copy child nodes (call this function on each child)
		for (xx=0; xx<sourceNode.childNodes.length; xx++)
		{
			CopyNode(newChild, sourceNode.childNodes[xx]);
		}
	}
}

// Gets the inner text from a function (preferably an anonymous function event handler)
function GetFunctionText(functRef)
{
	var innerText=null;
	var outerText, ePos, sPos;
	
	if (functRef)
	{
		outerText=functRef.toString();

		if (outerText.indexOf("function")==0)
		{
			sPos=outerText.indexOf("{");
			ePos=outerText.lastIndexOf("}");
			
			if (sPos>-1 && ePos>sPos)
			{
				innerText=Trim(outerText.substring(sPos+1, ePos));
			}
		}
	}
	
	if (innerText==null){innerText="";}
	
	return innerText;
}

function IsEventHandlerAttribute(attribName)
{
	var answer=false;
	
	switch (attribName.toLowerCase())	// more efficient than a huge if (...or...or...or...)
	{
		case "onabort":
			answer=true;
		case "onblur":
			answer=true;
		case "onchange":
			answer=true;
		case "onclick":
			answer=true;
		case "ondblclick":
			answer=true;
		case "onerror":
			answer=true;
		case "onfocus":
			answer=true;
		case "onkeydown":
			answer=true;
		case "onkeypress":
			answer=true;
		case "onkeyup":
			answer=true;
		case "onload":
			answer=true;
		case "onmousedown":
			answer=true;
		case "onmouseout":
			answer=true;
		case "onmouseover":
			answer=true;
		case "onmouseup":
			answer=true;
		case "onreset":
			answer=true;
		case "onresize":
			answer=true;
		case "onsubmit":
			answer=true;
		case "onunload":
			answer=true;
	}
	
	return answer;
}

//ADDED: To merge the support for SubmitFormAjax in Dealer and Commercial.
function setAjaxContent(responseText, objToFill)
{
	try
	{
		objToFill.innerHTML=responseText;
	}
	catch(error){}
}
//END ADD

function GetCSSeqno(event){ // Similar to GetOthers(...) - with custom code, as a temp work-around for 6.22.01.201
	var fieldRef, fieldName, fieldValue, fieldType, formName, lookupField;
	var returnList, httpRequest, queryString, xx, scrap, rootColName, rootPath;
	var wEvent=event==undefined ? window.event : event;  // in IE the value will be undefined.
	
	if (!wEvent){return;}
	if (document.form1.Z_SQLpending.value!="Add"){return;}
	if (document.form1.cs_seqno==undefined){return;}
	if (document.form1.cs_seqno.value!=""){return;}

	fieldRef=wEvent.srcElement;

	if (fieldRef==undefined){return;}

	fieldName=fieldRef.name;
	formName=fieldRef.form.name;
	LookupField=fieldName;
	LookupForm=formName;
	ColNamePrefix="";
	
	if (fieldRef.tagName=="INPUT"){fieldType=fieldRef.type.toLowerCase();}
	else {fieldType="";}
	
	try
	{
		switch (fieldRef.type.toLowerCase())
		{
			case "radio":
				fieldValue=GetRadioValue(fieldRef);
				break;
			case "checkbox":
				fieldValue=GetCheckboxValue(fieldRef);
				break;
			default:
				fieldValue=fieldRef.value;
				break;
		}
	}
	catch (error){fieldValue="";}

	try {
		xx=fieldName.indexOf("_");
		scrap=fieldName.substring(0, 3);

		if (scrap=="Row" && xx>4){
			rootColName=fieldName.substring(xx+1);
			ColNamePrefix=fieldName.substring(0, xx+1);
		}
		else {rootColName=fieldName;}
	}
	catch (error){rootColName=fieldName;}

	try {returnList=eval(rootColName+"_Return");}
	catch (error){return;}

	if (returnList=="" || returnList==null){return;}

	scrap=BuildLookupQueryString(rootColName, ColNamePrefix, formName);
	queryString="?field=contact_type&value="+escape(fieldValue)+(scrap=="" ? "" : "&"+scrap)+"&return="+returnList;

	if (document.URL.indexOf("report/")==-1){rootPath="";}
	else {rootPath="../";}

	httpRequest=CreateHttpRequest("POST", rootPath+"dynamicvalue.aspx"+queryString, true);

	httpRequest.onreadystatechange=function(){
		if (httpRequest.readyState==4){
			LookupReturn(fieldValue, httpRequest.responseText);
		}
	}

	httpRequest.send("");

	return true;
}
			
function checkContactType()
{
	try
	{
		ctactypeRef=document.getElementById("ctactype_id");
		
		if (ctactypeRef.value!="")
		{
			ctactypeRef.onClick=GetCSSeqno;
			ctactypeRef.click();
			ctactypeRef.onClick=function(){};
		}
	}
	catch (error){}
}

function ShowSingleToolTip(elem_id)
{
    if(document.getElementById(elem_id))
	    document.getElementById(elem_id).style.display = "block";
}

function HideSingleToolTip(elem_id)
{
    if(document.getElementById(elem_id))
	    document.getElementById(elem_id).style.display = "none";
}

function HideAllToolTips()
{
    for( var i = 1; i <= 99; i++ )
	    HideSingleToolTip('hover_item_'+i);
}

function ShowAllToolTips()
{
    for( var i = 1; i <= 99; i++ )
	    ShowSingleToolTip('hover_item_'+i);
}

function ShowToolTip(elem_id)
{
    HideAllToolTips();
	ShowSingleToolTip(elem_id);
}

function SetCollapseExpandImagesSource(srcCollapse, srcExpand)
{
    if (imgExpand==null)
    {
        imgExpand = new Image();
    }
    
    if (imgCollapse==null)
    {
        imgCollapse = new Image();
    }
    
    imgExpand.src=srcExpand;
    imgCollapse.src=srcCollapse;
}

function SetImageSrc(imgName, source)
{
    if (document.images)
    {
        document.images[imgName].src=eval(source+".src");
    }
}

function ShowHideDiv(elem_id)
{
    
    if (document.getElementById) 
    {
    	if (document.getElementById(elem_id).style.display == "none")
    	{
			document.getElementById(elem_id).style.display = 'block';
			SetImageSrc(("img"+elem_id),'imgCollapse');			
		}
		else
		{
			SetImageSrc(("img"+elem_id),'imgExpand');
			document.getElementById(elem_id).style.display = 'none';			
		}	
	} 
	else 
	{ 
		if (document.layers) 
		{	
			if (document.elem_id.display == "none")
			{
				document.elem_id.display = 'block';
				SetImageSrc(("img"+elem_id),'imgCollapse');
			}
			else
			{
				SetImageSrc(("img"+elem_id),'imgExpand');	
				document.elem_id.display = 'none';
			}
		}
		else
		{
			if (document.all.elem_id.style.visibility == "none")
			{
				document.all.elem_id.style.display = 'block';
				SetImageSrc(("img"+elem_id),'imgCollapse');
			}
			else
			{
				SetImageSrc(("img"+elem_id),'imgExpand');
				document.all.elem_id.style.display = 'none';
			}
		}
	}
}

function CheckStartDate(startDateRef)
{
	var startDate;
	
	if (StartDateLimit)
	{
		startDate=ParseDate(startDateRef.value);

		if (startDate<MinStartDate)
		{
			startDateRef.value=FormatDate(MinStartDate);
			window.alert(GetFieldPrompt("MinEventHistoryStartMosMsg"));
		}
	}
}

function FormatDate(dateVal)
{
	var formatParts=DateFormat.split("/");
	var dateParts=DateFormat.split("/");
	var datePart, scrap;
	
	for (xx=0; xx<dateParts.length; xx++)
	{
		datePart=dateParts[xx];
		scrap=1;
		
		switch (datePart)
		{
			case "MM":
				scrap=dateVal.getMonth()+1;  // JS months are zero-based (Jan=0)
				break;
			case "dd":
				scrap=dateVal.getDate();
				break;
			case "yyyy":
				scrap=dateVal.getFullYear();
				break;
		}
		
		dateParts[xx]=scrap<10 ? "0"+scrap : scrap;
	}
	
	return dateParts.join("/");
}

function MASEncodeURL(urlValue)
{
    var values = urlValue.split('?');
    if (values.length==2)
    {
        var parms=values[1].split('&');
        var newUrl=values[0] + "?";
        for (var i=0;i<parms.length;i++)
        {
            var pos=parms[i].indexOf("=");
            var valKey=parms[i].substring(0,pos);
            var valVal=parms[i].substring(pos+1,parms[i].length);
            
            var scrap=encodeURIComponent(valVal);
            if (i>0)
            {
                newUrl=newUrl+"&";
            }
            newUrl=newUrl+valKey+"="+scrap;
        }
        return newUrl;
        
    }
    return urlValue;
}

function GetFieldPrompt(fieldName)
{
	var rootPath, returnText, prompt, returnPair;
	
	if (document.URL.indexOf("report/")==-1){rootPath="";}
	else {rootPath="../";}
	
	httpRequest=CreateHttpRequest("POST", rootPath+"ajaxfielddef.aspx?field="+fieldName+"&return=prompt", false);

	httpRequest.send("");

	returnText=httpRequest.responseText;
	
	while (returnText.indexOf("$#039;")!=-1){returnText=returnText.replace("$#039;", "'");}
	
	returnPair=returnText.split('=');
	prompt=returnPair[1];
	
	return prompt;
}

function Dec2Hex(decValue){return decValue.toString(16);}

function Hex2Dec(hexValue){return parseInt(hexValue, 16);}

function CheckUserId(){
	try {		
		var userID=document.form1.user_id;
		var panelCode=document.form1.panel_code;
		var userIdEndDate=document.form1.user_id_end_date;
		
		if (userID){	
			if (userID.value==""){
				if (panelCode){
					panelCode.value="";
					panelCode.disabled=true;
					panelCode.className="ReadOnly";
				}
				
				if (userIdEndDate){
					userIdEndDate.value="";
					userIdEndDate.disabled=true;
					userIdEndDate.className="ReadOnly";
				}
			}
			else {
				if (panelCode){
					panelCode.disabled=false;
					panelCode.className="";
				}
				
				if (userIdEndDate){
					userIdEndDate.disabled=false;
					userIdEndDate.className="";
				}
			}
		}
	}
	catch(error){}
}

