
var gsButtonName = "";
var gbChanged = false;
var gsHelpRoot = "";
var gsHeaderLinkPage = "sHelp";

// VARIABLE DECLARATIONS

var digits = "0123456789";
var fdigits = "0123456789."
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz"
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
var whitespace = " \t\n\r";
var decimalPointDelimiter = "."
var phoneNumberDelimiters = "()- ";
var validUSPhoneChars = digits + phoneNumberDelimiters;


var validWorldPhoneChars = digits + phoneNumberDelimiters + "+";
// (a leading + is OK)
var SSNDelimiters = "- ";
var validSSNChars = digits + SSNDelimiters;
var digitsInSocialSecurityNumber = 9;
var digitsInUSPhoneNumber = 10;
var ZIPCodeDelimiters = "- ";
var ZIPCodeDelimeter = "-"
var validZIPCodeChars = digits + ZIPCodeDelimiters
var digitsInZIPCode1 = 5
var digitsInZIPCode2 = 9

var bDisableNavTest = false;



// CONSTANT STRING DECLARATIONS
// (grouped for ease of translation and localization)

// m is an abbreviation for "missing"

// s is an abbreviation for "string"

var sUSLastName = "Last Name"
var sUSFirstName = "First Name"
var sWorldLastName = "Family Name"
var sWorldFirstName = "Given Name"
var sTitle = "Title"
var sCompanyName = "Company Name"
var sUSAddress = "Street Address"
var sWorldAddress = "Address"
var sCity = "City"
var sStateCode = "State Code"
var sWorldState = "State, Province, or Prefecture"
var sCountry = "Country"
var sZIPCode = "ZIP Code"
var sWorldPostalCode = "Postal Code"
var sPhone = "Phone Number"
var sFax = "Fax Number"
var sDateOfBirth = "Date of Birth"
var sExpirationDate = "Expiration Date"
var sEmail = "e-mail"
var sSSN = "Social Security Number"
var sOtherInfo = "Other Information"


/*
var xStateCode = "This field must be a valid two character U.S. state abbreviation (like CA for California). Please reenter it now."
var xZIPCode = "This field must be a 5 or 9 digit U.S. ZIP Code (like 94043). Please reenter it now."
var xUSPhone = "This field must be a 10 digit U.S. phone number (like 415 555 1212). Please reenter it now."
var xWorldPhone = "This field must be a valid international phone number. Please reenter it now."
var xSSN = "This field must be a 9 digit U.S. social security number (like 123 45 6789). Please reenter it now."
var xEmail = "This field must be a valid e-mail address (like foo@bar.com). Please reenter it now."
var xDay = "This field must be a day number between 1 and 31.  Please reenter it now."
var xMonth = "This field must be a month number between 1 and 12.  Please reenter it now."
var xYear = "This field must be a 2 or 4 digit year number.  Please reenter it now."
*/

// p is an abbreviation for "prompt"
/*
var pEntryPrompt = "Please enter a "
var pStateCode = "2 character code (like CA)."
var pZIPCode = "5 or 9 digit U.S. ZIP Code (like 94043)."
var pUSPhone = "10 digit U.S. phone number (like 415 555 1212)."
var pWorldPhone = "international phone number."
var pSSN = "9 digit U.S. social security number (like 123 45 6789)."
var pEmail = "valid e-mail address (like foo@bar.com)."

var pDay = "day number between 1 and 31."
var pMonth = "month number between 1 and 12."
var pYear = "2 or 4 digit year number."
*/

var defaultEmptyOK = false

function PageHeaderHelpLink(){
	//gsHeaderLinkPage is variable that is set on each page that loads PAGE level help, if not set
	// then it uses the default Help link
	if(gsHeaderLinkPage == "sHelp"){
		window_onhelp('shelp.htm');
	}
	else{
		//Uncomment for testing
		//alert(gsHeaderLinkPage);
		//txtError.value = "";
		if(gsHelpRoot.toUpperCase().indexOf("CCI") == -1){
			if(gsHeaderLinkPage.indexOf("fields") > -1){//javascript:window_onhelp('fields/reassign_valuation.htm')
				window_onhelp(gsHeaderLinkPage + '.htm');
			}
			else{
			window_onhelp('shelp.htm#pages/' + gsHeaderLinkPage + '.htm');
			}
		}
		else{
		window_onhelp('CCI.htm#' + gsHeaderLinkPage + '.htm');
		//window_onhelp(gsHeaderLinkPage + '.htm');
		}
	}
}

function gClosePage(){
	//*** this is now that catch for any opened window - gGlosePage is called from the skeleton - Body:OnUnload();	
	//*** there is no reason to worry about a catch - if it doesn't work - it just doesnt exist for the page that is currently closing.

//	alert(gsPageName);

	if (gsPageName == "BVSAddEquipment" || gsPageName == "BVSEditEquipment") {
		if (frmMe.txtAction.value == "btnOK" || frmMe.txtAction.value == "btnCancel") {
			try{winCalc.close();}catch(e){}	// pop up window for Adding Equipment Additions
			try{winHelp.close();}catch(e){}  // pop up window for downloading reports
		}
	}
	if (gsPageName == "BVSReports" || gsPageName == "BVSReportsOutside" || gsPageName == "BVSReportsInside" || gsPageName == "CCIReports" || gsPageName == "CCISummary"  ) {
//		if (frmMe.txtAction.value != "btnDownload" && frmMe.txtAction.value != "btnPreview"  && frmMe.txtAction.value != "btnPrint") {
			try{winNew.close();}catch(e){}	// pop up window for Adding Equipment Additions
//		}
	}
	
}

function Changed()
{   
   gbChanged = true;
   window.document.frmMe.txtChanged.value = gbChanged;
}

function RemoveAll(sFieldName)
{
	var oTblName = document.all.item('txt' + sFieldName +'1').parentElement.parentElement.parentElement.parentElement;
	// DDL - requirment change - don't restore the system defualts
	var oTblContain = oTblName.parentElement.parentElement.parentElement.parentElement
	var oTblContain2 = oTblContain.rows(0).cells(1).children(0)
	var sDisplay = new String();
	
	for (var i = 1; i<=oTblName.rows.length; i++)
	{
		document.all.item('txt' + sFieldName + i).value = '';
		if (document.all.item('txt' + sFieldName + i).none=='true')
		{
			document.all.item('txt' + sFieldName + i).value = '100';
		}
	}
	
	eval('Assumed' + sFieldName + '= false') ;
	document.all.item('Assumed' + sFieldName).value = 'false';
	AdjustRunTotal(sFieldName);
	;
}

function RestoreAssumptions(sFieldName)
{
	var conf = confirm("This will erase all materials for the material system(s) (including any you have entered or changed), replacing them with typical materials for this building.  Click OK to reload the assumptions.");
	if (conf == true)
	{
		var oTblName =  document.all.item('txt' + sFieldName +'1').parentElement.parentElement.parentElement.parentElement;
		var sDefault = "";	
		for (var i = 1; i<=oTblName.rows.length; i++)
		{
			if (sFieldName == "") {
				sDefault = "txt[" + i + "]"
			}
			else
			{
				sDefault = sFieldName + "[" + i + "]"
			}
			document.getElementById(sFieldName + i).value = eval(sDefault);
		}
		eval('Assumed' + sFieldName + '= true') ;
		document.all.item('Assumed' + sFieldName).value = 'true'; 
		AdjustRunTotal(sFieldName);
			
	}
}

function AdjustRunTotal(sFieldName)
{
	var iTot = 0;
	var sDisplay = new String();
	var sRows = new String();
	var bOver100 = false;
	var sPad;
	var iEnterCount = 0;
	var sUOM = new String();
	var sPad = new String();
	
	sUOM = "%"
	if(sFieldName == 'WL') sUOM = "Feet";
			/*
			alert( document.all.item('txt' + sFieldName +'1').parentElement.name)
			alert( document.all.item('txt' + sFieldName +'1').parentElement.parentElement.name) 
			alert( document.all.item('txt' + sFieldName +'1').parentElement.parentElement.parentElement.name)
			alert( document.all.item('txt' + sFieldName +'1').parentElement.parentElement.parentElement.parentElement.name) //Table
			alert( document.all.item('txt' + sFieldName +'1').parentElement.parentElement.parentElement.parentElement.id) //Table
			*/
	//oTblName is the Table that contains the fields for category entry ( ie Roof percentages fields)
	var oTblName =  document.all.item('txt' + sFieldName +'1').parentElement.parentElement.parentElement.parentElement;
			//alert( oTblName.parentElement.parentElement.parentElement.parentElement.name) //Table
	
	//This oTblContain - is the running Total section table on the right of the categoies screen ( ie. Roof)
	var oTblContain = oTblName.parentElement.parentElement.parentElement.parentElement
			/*
			alert('the table has # rows =' + oTblContain.rows.length);
			alert('the table has # cells =' + oTblContain.rows(0).cells.length);
			alert('cell 0 contains =' + oTblContain.rows(0).cells(0).innerText);
			alert('cell 1 contains =' + oTblContain.rows(0).cells(1).innerText);
			alert('number of children' + oTblContain.rows(0).cells(1).children.length);
			alert('child name' + oTblContain.rows(0).cells(1).children(0).name);
			*/	
	//oTblContain2 - is the Table that is in temBVSSecMaterialRunningTot.asp
	var oTblContain2 = oTblContain.rows(0).cells(1).children(0)
	
	for (var i = 1; i<=oTblName.rows.length; i++){
			
		var iVal = document.getElementById(sFieldName + i).value;
			
		if(iVal != ''){
			//Clear None if anything other then None is filled in.
			if (i != oTblName.rows.length){
				if (document.all.item(sFieldName + oTblName.rows.length).none=='true'){
					document.getElementById(sFieldName + oTblName.rows.length).value ="";
				}
			}
			// otherwise ensire none is 100%
			else
				if (document.all.item(sFieldName + oTblName.rows.length).none=='true'){
					document.getElementById(sFieldName + oTblName.rows.length).value ="100";
					iVal = "100";
				}


			iEnterCount += 1;
			sPad = '&nbsp;';
			iTot += parseInt(iVal);
			if(parseInt(iVal) >= 100)
			{
				bOver100 = true;
				sPad = '';
			}
				
			if(parseInt(iVal) < 10){
				sPad =  '&nbsp;&nbsp;';
				
			}
			sRows = sRows + "<tr><td valign='buttom' align='left'>" + oTblName.rows(i-1).cells(0).innerText + "</td><td align='right'><kbd>" + sPad + iVal + "</kbd>&nbsp;" + sUOM + "&nbsp;</td></tr>";
		}
	}


	sDisplay = "<table border=0 cellspacing=0 cellpadding=0 width='100%'>";	
	
	if ((document.all.item("OccCount").value > 1) & (iTot == 0 )){
		if(gbHideAssumptions)
		{
			sDisplay = sDisplay + "<tr><td colspan='2' class='clsGridRowOddSmallFontItalics'>(Use Typical.)</td></tr>";
		}
		else
		{
			sDisplay = sDisplay + "<tr><td colspan='2' class='clsGridRowOddSmallFontItalics'>(Unable to display System Generated Assumptions for buildings with multiple occupancies.)</td></tr>";
		}
	}
	else if ((document.all.item("MultiConst").value == "true") & (iTot == 0 )){
		if(gbHideAssumptions)
		{
			sDisplay = sDisplay + "<tr><td colspan='2' class='clsGridRowOddSmallFontItalics'>(Use Typical.)</td></tr>";
		}
		else
		{
			sDisplay = sDisplay + "<tr><td colspan='2' class='clsGridRowOddSmallFontItalics'>(Unable to display System Generated Assumptions for buildings with multiple construction types.)</td></tr>";
		}
	}
	else {
		if (document.all.item("Assumed" + sFieldName).value =='false') {
			sDisplay = sDisplay + "<tr><td colspan='2' class='clsGridRowOddSmallFontItalics'>(Using: User Specified Values)</td></tr>";
		}
		else
		{
			sDisplay = sDisplay + "<tr><td colspan='2' class='clsGridRowOddSmallFontItalics'>(Using: System Generated Assumptions)</td></tr>";
		}
	}
	
	sDisplay = sDisplay + sRows
	
	sDisplay = sDisplay + "</table>";
	oTblContain2.all.item('tdRunItemsTot').innerHTML = "";
		if(iTot != 0)
		{
			// Figure padding for better display
			sPad = '&nbsp;';
			if(iTot < 100)
				sPad = '&nbsp;&nbsp;';
			if(iTot < 10)
				sPad = '&nbsp;&nbsp;&nbsp;&nbsp;';

		  oTblContain2.all.item('tdRunItemsTot').innerHTML = '<hr size="1">Total&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + sPad + iTot + ' ' + sUOM +'<br>';
		}
		if ((oTblContain2.all.item('tdRunItems').getAttribute('defaultText').indexOf("Unable ") > 0) || (document.all.item("OccCount").value >1) || (document.all.item("MultiConst").value == "true")){
			oTblContain2.all.item('tdRunItemsTot').innerHTML += '<br><input type="button" value="Remove All" onclick="RemoveAll(' + "'"+ sFieldName +"'" + ')">';
			}
		else
		{
			oTblContain2.all.item('tdRunItemsTot').innerHTML += '<br><input type="button" value="Remove All" onclick="RemoveAll(' + "'"+ sFieldName +"'" + ')">&nbsp;&nbsp;&nbsp;<input type="button" value="Restore Assumptions" onclick="RestoreAssumptions(' + "'" + sFieldName + "'" + ')">';
		}
	oTblContain2.all.item('tdRunItems').innerHTML = sDisplay;		
}

//*** BUG: If I put this line in, I get two error messages:
//(1) Window.length can't be set by assignment
//(2) daysInMonth has no property indexed by 4
//If I leave it out, the code works fine.
//   this.length = n;

function makeArray(n) 
{
   for (var i = 1; i <= n; i++) {
      this[i] = 0
   } 
   return this;
}


var daysInMonth = makeArray(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;   // must programmatically check this
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;

var USStateCodeDelimiter = "|";
var USStateCodes = "AL|AK|AS|AZ|AR|CA|CO|CT|DE|DC|FM|FL|GA|GU|HI|ID|IL|IN|IA|KS|KY|LA|ME|MH|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|MP|OH|OK|OR|PW|PA|PR|RI|SC|SD|TN|TX|UT|VT|VI|VA|WA|WV|WI|WY|AE|AA|AE|AE|AP|NL|NU|QC"




// popw stands for popup window, pws:popup window size, mon:monitor, av:available, par:parent (window)
var winNew;
var winHelp = "notset";
var popwwidth;
var popwheight;
var popwsarr=new Array(6);

var monw = 0;
var monh = 0;

monw = screen.width;
monh = screen.height;

var avw = screen.availWidth;
var avh = screen.availHeight;

var avt = screenTop;
var avl = screenLeft;

var popwt = 15;
var popwl = (avw/4) - 145;


popwsarr[1]=new Array();
popwsarr[1][1]=640;
popwsarr[1][2]=615;
popwsarr[1][3]=375;

popwsarr[2]=new Array();
popwsarr[2][1]=800;
popwsarr[2][2]=775;
popwsarr[2][3]=575;

popwsarr[3]=new Array();
popwsarr[3][1]=1024;
popwsarr[3][2]=800;
popwsarr[3][3]=600;

popwsarr[4]=new Array();
popwsarr[4][1]=1152;
popwsarr[4][2]=800;
popwsarr[4][3]=650;

popwsarr[5]=new Array();
popwsarr[5][1]=1280;
popwsarr[5][2]=1000;
popwsarr[5][3]=700;

popwsarr[6]=new Array();
popwsarr[6][1]=1400;
popwsarr[6][2]=1000;
popwsarr[6][3]=750;


function HelpWindow(strHelpPage, lAlternatePositionID, sHelpPrefix){
	var strURL;
	strURL = gsHelpRoot +  "/" + strHelpPage;

	SmartScreenSize(grvHelpSize, monw, monh);
	if (popwwidth>800)	{
		popwt = Math.floor((avt/2)) + (Math.floor((avh/20)));
		popwl = avl + (Math.floor((avw/20)));
	};

	if (lAlternatePositionID == 1) {
		popwwidth = Math.floor(popwwidth * .5)
		popwheight =  Math.floor(popwheight * .7)
		popwt = screen.height - (popwheight + 100);
		popwl = screen.width - (popwwidth + 20);
	};	
	
	if (sHelpPrefix == "undefined") {
		alert(sHelpPrefix); 
		sHelpPrefix = "";
	}
	
// use this to debug!!!.... 	
//	alert(strURL); 

	if (lAlternatePositionID == 1) 
		{
		winHelp = window.open(strURL,sHelpPrefix + "help", "width=" + popwwidth + ", height=" + popwheight + ", left=" + popwl + ", top=" + popwt + ", resizable=yes, scrollbars=yes, alwaysRaised=yes, dependent=yes, status=no, menubar=no");
		winHelp.document.focus();
	};	
	else {
		winNew = window.open(strURL,sHelpPrefix + "help", "width=" + popwwidth + ", height=" + popwheight + ", left=" + popwl + ", top=" + popwt + ", resizable=yes, scrollbars=yes, alwaysRaised=yes, dependent=yes, status=no, menubar=no");
		winNew.document.focus();
	};

	window.event.cancelBubble = true;
	return false;

}

function InitReportWindow()	{
	SmartScreenSize(grvReportSize, monw, monh);
	if (popwwidth>800)	{
		popwt = Math.floor((avt/2)) + (Math.floor((avh/20)));
		popwl = avl + (Math.floor((avw/20)));
	}
}

function gRemoveAllComboboxOptions(cbo) {
	for (var i = cbo.options.length; i >= 0; i-- ){
		cbo.options[i] = null;
	}
}
function gAddComboboxOption(cbo, strDisplay, strValue){
	cbo.options[cbo.options.length] = new Option(strDisplay, strValue);
}

function gRemoveAllComboboxOptions(cbo) {
	for (var i = cbo.options.length; i >= 0; i-- ){
		cbo.options[i] = null;
	}
}
function gAddComboboxOption(cbo, strDisplay, strValue){
	cbo.options[cbo.options.length] = new Option(strDisplay, strValue);
}

function gRemoveAllComboboxOptions(cbo) {
	for (var i = cbo.options.length; i >= 0; i-- ){
		cbo.options[i] = null;
	}
}
function gAddComboboxOption(cbo, strDisplay, strValue){
	cbo.options[cbo.options.length] = new Option(strDisplay, strValue);
}

// captures screen size using screen.properties an uses info to choose a help window size 
function SmartScreenSize(booESPW, intScrWidth, intScrHeight){

// use this to debug!!!.... 	
//	alert ('intScrWidth=' + intScrWidth + ' intScrHeight=' + intScrHeight + ' ');

	popwwidth=popwsarr[1][2];
	popwheight=popwsarr[1][3];
	if (booESPW==true)	{
		for (loocnt=1;loocnt<popwsarr.length;loocnt++)	{
			if (loocnt==(popwsarr.length-1))	{
				popwwidth=popwsarr[loocnt][2];
				popwheight=popwsarr[loocnt][3];
				break;
			}
			else	{
				if (intScrWidth<=popwsarr[loocnt][1])	{
					popwwidth=popwsarr[loocnt][2];
					popwheight=popwsarr[loocnt][3];
					break;
				}
			}
		}
	}
}



// Returns true if string s is null or length of string s is zero.
function getSize(s)
{
   return s.length;
}

function StripLeadZero(s){
   for (var i = 0; i < s.length; i++)
   {   
		var c = s.charAt(i);
		if (c != '0'){
			return s.substr(i);  //Get substring.				
		} 
   }
	return s;
}

// Removes all characters which appear in string bag from string s.
function stripCharsInBag (s, bag)
{   var returnString = "";
    for (var i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}


// Removes all characters which do NOT appear in string bag from string s.
function stripCharsNotInBag (s, bag)
{   
    var returnString = "";
    for (var i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) != -1) returnString += c;
    }
    return returnString;
}


// Removes leading and trailing whitespace characters from s.
function trimWhitespace(s)
{  
   return trimLeadingWhitespace(trimTrailingWhitespace(s));
}


/***************************************************************/
/* FUNCTIONS TO NOTIFY USER OF INPUT REQUIREMENTS OR MISTAKES. */
/***************************************************************/


// Display prompt string s in status bar.
function prompt (s)
{   window.status = s
}


//set focus to theField and select all characters in it
//display warning message and return false
function warnAndFocus(theField, warning)
{   
    alert(warning);
    if (theField.disabled == false)
    {	theField.focus();
		//alert('theField.type='+theField.type);
		if (theField.type == 'text') theField.select();
	}
   return false;
}


/****************************************************/
/* FUNCTIONS TO INTERACTIVELY CHECK VARIOUS FIELDS. */
/****************************************************/


//function checkPercentage (theField, fieldDesc, emptyOK)
function checkPercentage (theField, fieldDesc, emptyOK)
{   if (checkPercentage.arguments.length < 3) emptyOK = defaultEmptyOK;
    return checkFloatRange(theField, fieldDesc+" Percentage", 0.0, 100.0, emptyOK);
}


//set the selected parameter of an html <SELECT drop down list box
function setSelection(select,value)
{
   for (var i = 0; i < select.options.length; i++)
      select.options[i].selected = (select.options[i].value == value);
}

function getSelection(select, ReturnValue)
{
   for (var i = 0; i < select.options.length; i++)
     if (select.options[i].selected == true) 
		if (ReturnValue == 1)
		return select.options[i].value + '';
        else
        return select.options[i].text + '';
   return '';
}
//set focus to the first input field on the page
function FocusOnFirst() {
	var i = 0;
	var bFocused = false;
	
	while(!bFocused && (i< window.document.frmMe.elements.length)) {
		try {
			document.frmMe.elements[i].focus();
			bFocused = true;
		}
		catch(exception) {
			i++;
		}
	}
}

function DebugPrint(sText){
	if (sText != "") {
		tblDebug.style.display = "inline";
		divDebugPrint.innerText = sText;
	}
	else {
		tblDebug.style.display = "none";
		divDebugPrint.innerText = "";
	};

}

function isArray(Array_IN) {
	return(typeof(Array_IN) == 'Object' && Array_IN.constructor == Array)
} 



//submit page to the COM engine
function SendAction(strAction, strPage, bChanged) {
   window.document.frmMe.txtAction.value = strAction;
   window.document.frmMe.txtPage.value = strPage;
   window.document.frmMe.txtChanged.value = bChanged;
   
   window.document.frmMe.submit();
}

function checkUserAction(){	
	if((!bDisableNavTest) && (window.event.clientY < 0)){ 
		var msg = "MS/B highly recommends that you NOT use your browser navigation because data will be lost!"		
		window.event.returnValue = msg;
	}
}

//initialize global variables<IMG class=clsFinger title="Refresh Records" onclick="Update('Refresh')" 
//src="Images/BVSFrameLogoS.jpg" align=absBottom border=0>
function GlobalInit(pageName, bSetFocusToFirst)
{
	
   gsPageName = pageName;
   gbChanged = false;
//   if (pageName != "Groups" && pageName != "Records" )  {
//		document.title = pageName;
//   };
   window.document.frmMe.txtPage.value = pageName;
   history.go(1); 

gsHelpRoot = gsrvHelpRoot;


	if (document.all.item('CopyrightYear') != null) 
	{
		var time=new Date();
		document.all.item('CopyrightYear').innerText = time.getYear();
	}
	//kjh
   if ( gsrvNewGUI == "true") 
   {
		document.body.onbeforeunload=checkUserAction;
		//alert(pageName);
		switch (pageName){
		   
		   case ("Records"):
		   {
				
				//alert(pageName);
				document.body.onbeforeunload = "";
				colBody.style.width="100%";
				divMenuOptions.style.display="inline";
				divPageBanner1.style.display="none";
				divPageBanner.style.display="none";
				colBodyBanner.style.display="none";
				colBodyFooter.style.display="none";
				colDivideVERT.style.display="none";
				colSideNav.style.display="none";
				if (document.all.item('divFAQ') != null) divFAQ.style.display="inline";		
				if (bSetFocusToFirst == true) FocusOnFirst(true);
				return true;
				break;
		   }
		   case ("BVSAssignPolicy"):
		   case ("ChangeOwnership"):
		   case ("CCINewOccupant"):
		   case ("EditCompany"):
		   case ("SystemSettings"):
		   case ("NewSystemSetting"):
		   case ("EditSystemSetting"):
		   case ("NewGroup"):
		   case ("EditGroup"):
		   case ("EditRole"):
		   case ("NewRole"):
		   case ("NewUser"):
		   case ("EditUser"):
		   case ("EditMessage"):
		   case ("NewMessage"):
		   case ("UserOptions"):
		   case ("RoleRights"):		   
		   case ("ChangePass"):		   
		   case ("BVSOccLookup"):
		   case ("BVSLocationReorder"):
		   case ("History"):
		   case ("ForgottenPass"):
		   case ("CCIChangeOwnership"):
		   case ("UserGroups"):
		   case ("AssignGroups"):		   
		   {
				//alert(pageName);
				if (document.all.item('divFAQ') != null) divFAQ.style.display="none";
				if (document.all.item('CommentLink') != null) CommentLink.style.display="none";
				colBody.style.width="100%";
				divMenuOptions.style.display="none";
				divPageBanner1.style.display="none";
				divPageBanner.style.display="none";
				colBodyBanner.style.display="none";
				colBodyFooter.style.display="none";
				colDivideVERT.style.display="none";
				colSideNav.style.display="none";		
				divLogout.style.display="none";
				if (bSetFocusToFirst == true) FocusOnFirst(true);
				return true;
				break;
		   }
		   case ("Error"):
		   {
				//alert(pageName);
				if (document.all.item('divFAQ') != null) divFAQ.style.display="none";
				colBody.style.width="100%";
				divMenuOptions.style.display="none";
				divPageBanner1.style.display="none";
				divPageBanner.style.display="none";
				colBodyBanner.style.display="none";
				colBodyFooter.style.display="none";
				colDivideVERT.style.display="none";
				colSideNav.style.display="none";		
				divLogout.style.display="inline";
				if (bSetFocusToFirst == true) FocusOnFirst(true);
				return true;
				break;
		   }
		   case ("BVSNewValuation1"):
		   case ("BVSNewValuation2"):
		   case ("BVSNewValuation4"):
		   case ("BVSNewValuation3"):
		   case ("BVSNewBuilding1"):
		   case ("BVSNewBuilding2"):
		   case ("BVSNewBuilding3"):
		   case ("BVSNewSection1"):
		   case ("BVSNewSection2"):
		   case ("BVSNewSection3"):
		   case ("Groups"):
		   case ("Roles"):
		   case ("Users"):
		   case ("BVSReportsOutside"):
		   case ("Messages"):
		   {
				if (document.all.item('divFAQ') != null) divFAQ.style.display="none";
				colBody.style.width="100%";
				colDivideVERT.style.display="none";
				colSideNav.style.display="none";		
				divMenuOptions.style.display="none";
				divPageBanner1.style.display="none";
				divPageBanner.style.display="none";
				colBodyBanner.style.display="none";
				colBodyFooter.style.display="none";
				if (bSetFocusToFirst == true) FocusOnFirst(true);
				return true;
				break;
			}
		   case ("Administration"):
		   {
				if (document.all.item('divFAQ') != null) divFAQ.style.display="none";
				if (document.all.item('CommentLink') != null) document.all.item('CommentLink').style.display="none";
				colBody.style.width="572";
				divLogout.style.display="inline";
				divMenuOptions.style.display="none";
				divPageBanner1.style.display="none";
				divPageBanner.style.display="none";
				colBodyBanner.style.display="none";
				colBodyFooter.style.display="none";
				colDivideVERT.style.display="inline";
				colSideNav.style.display="inline";		
				if (bSetFocusToFirst == true) FocusOnFirst(true);
				return true;
				break;
			}
		   case ("LockedRecord"):
		   case ("Message"):
		   case ("BVSAddEquipment"):
		   case ("BVSEditEquipment"):
		   case ("BVSAddMiscAdjustment"):
		   case ("BVSEditMiscAdjustment"):
		   {
				if (document.all.item('divFAQ') != null) divFAQ.style.display="none";
				colBody.style.width="100%";
				divMenuOptions.style.display="none";
				divPageBanner1.style.display="none";
				divPageBanner.style.display="none";
				colBodyBanner.style.display="none";
				colBodyFooter.style.display="none";
				colDivideVERT.style.display="none";
				colSideNav.style.display="none";		
				//tdMenu.style.display="none";
				if (bSetFocusToFirst == true) FocusOnFirst(true);
				return true;
				break;
		   }
//		   case else {
//   	   		  colBody.style.width="572";
//   			  colDivideVERT.style.display="inline";
//			  colSideNav.style.display="inline";		
		   case ("Logon"):
		   case ("Logout"):
			{
				document.body.onbeforeunload = "";			
				if (document.all.item('divFAQ') != null) divFAQ.style.display="none";
				if (bSetFocusToFirst == true) FocusOnFirst(true);
				return true;
			}

		}
	}
	if (document.all.item('divFAQ') != null) divFAQ.style.display="none";	
	if (document.all.item('colBody') != null) colBody.style.width="572";
	if (document.all.item('colBodyBanner') != null) colBodyBanner.style.display="inline";
	if (document.all.item('colBodyFooter') != null) colBodyFooter.style.display="inline";
	if (document.all.item('colDivideVERT') != null) colDivideVERT.style.display="inline";
	if (document.all.item('colSideNav') != null) colSideNav.style.display="inline";		
	if (document.all.item('divPageBanner1') != null) divPageBanner1.style.display="inline";
	if (document.all.item('divPageBanner') != null) divPageBanner.style.display="inline";
	if (bSetFocusToFirst == true) FocusOnFirst(true);
	
	if (document.all.item('tblDevModeFunctions') != null && frmMe.txtDevMode.value == '(DevModeOn)') {
		tblDevModeFunctions.style.display="inline";
	}
	
//	alert(frmMe.txtDevMode.value);
   if (bSetFocusToFirst == true) FocusOnFirst(true);
   return true;
}

function window_onhelp(HelpFile, Position, WindowPrefix) {
	var winHandle;
try{
	winHandle = HelpWindow(HelpFile, Position, WindowPrefix);
	window.event.cancelBubble = true;

	return winHandle;
	}
catch(e){}
}


// Removes initial (leading) whitespace characters from s.
function trimLeadingWhitespace (s)
{   return stripInitialWhitespace(s);
}

// Removes trailing whitespace characters from s.
function trimTrailingWhitespace (s)
{   
    if (isWhitespace(s)) return "";
    var i = s.length-1;
    while ((i > 0) && charInString (s.charAt(i), whitespace))
       i--;
    return s.substring (0, i+1);
}

//strip initial leading whitespace characters
function stripInitialWhitespace (s)
{   
    if (isWhitespace(s)) return "";
    var i = 0;
    while ((i < s.length) && charInString (s.charAt(i), whitespace))
       i++;
    return s.substring (i, s.length);
}

//returns true if character c is in string s
function charInString (c, s)
{   for (var i = 0; i < s.length; i++)
    {   if (s.charAt(i) == c) return true;
    }
    return false;
}

function YesNoDialog(Prompt, TrueCondition, FalseCondition ) {
   onClick=confirm(Prompt)
   if (onClick == true) {
      Update(TrueCondition);
   }
   else {
		Update(FalseCondition);
   }
}

function Dialog(Prompt, control) {
   onClick=confirm(Prompt)
   if (onClick == true) {
      Update(control);
   }
}

//Notify user that required field theField is empty.
//Set focus to the field and return false.
function warnEmpty (theField, fieldDesc)
{   
    return warnAndFocus(theField, fieldDesc+" is a required field and cannot be left blank.");
}

// reformat (TARGETSTRING, STRING, INTEGER, STRING, INTEGER ... )       
// Handy function for arbitrarily inserting formatting characters
// or delimiters of various kinds within TARGETSTRING.
// reformat takes one named argument, a string s, and any number
// of other arguments.  The other arguments must be integers or
// strings.  These other arguments specify how string s is to be
// reformatted and how and where other strings are to be inserted
// into it.
// reformat processes the other arguments in order one by one.
// * If the argument is an integer, reformat appends that number 
//   of sequential characters from s to the resultString.
// * If the argument is a string, reformat appends the string
//   to the resultString.
// NOTE: The first argument after TARGETSTRING must be a string.
// (It can be empty.)  The second argument must be an integer.
// Thereafter, integers and strings must alternate.  This is to
// provide backward compatibility to Navigator 2.0.2 JavaScript
// by avoiding use of the typeof operator.
// It is the caller's responsibility to make sure that we do not
// try to copy more characters from s than s.length.
// EXAMPLES:
// * To reformat a 10-digit U.S. phone number from "1234567890"
//   to "(123) 456-7890" make this function call:
//   reformat("1234567890", "(", 3, ") ", 3, "-", 4)
// * To reformat a 9-digit U.S. Social Security number from
//   "123456789" to "123-45-6789" make this function call:
//   reformat("123456789", "", 3, "-", 2, "-", 4)
// HINT:
// If you have a string which is already delimited in one way
// (example: a phone number delimited with spaces as "123 456 7890")
// and you want to delimit it in another way using function reformat,
// call function stripCharsNotInBag to remove the unwanted 
// characters, THEN call function reformat to delimit as desired.
// EXAMPLE:
// reformat (stripCharsNotInBag ("123 456 7890", digits),
//           "(", 3, ") ", 3, "-", 4)

function reformat (s)
{   var arg;
    var sPos = 0;
    var resultString = "";
    for (var i = 1; i < reformat.arguments.length; i++) {
       arg = reformat.arguments[i];
       if (i % 2 == 1) resultString += arg;
       else {
           resultString += s.substring(sPos, sPos + arg);
           sPos += arg;
       }
    }
    return resultString;
}


// takes ZIPString, a string of 5 or 9 digits;
// if 9 digits, inserts separator hyphen
function reformatZIPCode (ZIPString)
{   if (ZIPString.length == 9) 
       return (reformat (ZIPString, "", 5, "-", 4));
    else
       return ZIPString;
}


//function checkString (theField, fieldDesc, emptyOK)
//performs same function as checkEmpty()
function checkString (theField, fieldDesc, emptyOK)
{   if (checkString.arguments.length < 3) emptyOK = defaultEmptyOK;
    return checkEmpty(theField, fieldDesc, emptyOK);
}


function SetCommentCount()
{
	var iCount = 0;
	if((frmMe.txtCommentsAgent.value != "No Agent Comments")
			&& (frmMe.txtCommentsAgent.value != ""))
		iCount = 1;
	if((frmMe.txtCommentsUnderwriter.value != "No Underwriter Comments")
			&& (frmMe.txtCommentsUnderwriter.value != ""))
		iCount = iCount + 1;
	document.all.commentCount.innerText = iCount;
}

function SetAgentComment(bReadOnly, sText)
{
	frmMe.txtCommentsAgent.value =sText;	
	if (bReadOnly)
	{
		frmMe.txtCommentsAgent.readOnly = true;
		frmMe.txtCommentsAgent.style.border = "0px";
		if (sText == "")
			frmMe.txtCommentsAgent.value = "No Agent Comments";		
	}
}

function SetUnderwriterComment(bReadOnly, sText)
{
	frmMe.txtCommentsUnderwriter.value =sText;	
	if (bReadOnly)
	{
		frmMe.txtCommentsUnderwriter.readOnly = true;
		frmMe.txtCommentsUnderwriter.style.border = "0px";
		
		if (sText == "")
			frmMe.txtCommentsUnderwriter.value = "No Underwriter Comments";		
	}
}

function HideComments()
{
	tblComments.style.display = 'none';
	document.all.item('btnCloseValuation').style.display = 'inline';
	ShowAllDropDowns();	
}
var sUC
var sAC

function CommentsCancel()
{
	frmMe.txtCommentsUnderwriter.value = sUC;
	frmMe.txtCommentsAgent.value = sAC;
	HideComments();
}

function CommentsOk()
{
	//frmMe.txtComments.value = frmMe.txtCommentsAgent.value + "#/#" + frmMe.txtCommentsUnderwriter.value;
	HideComments();
	SetCommentCount();
}

function ShowComments()
{		
	if ((tblCloseValuationCheck.style.display != "inline") && (tblCalculator.style.display != "inline"))
		{
			sUC = frmMe.txtCommentsUnderwriter.value;
			sAC = frmMe.txtCommentsAgent.value;
			
			tblComments.style.display = 'inline';
			document.all.item('btnCloseValuation').style.display = 'none';
			HideAllDropDowns();		
			if(true != 	frmMe.txtCommentsUnderwriter.readOnly)
				frmMe.txtCommentsUnderwriter.focus();
			if(true != 	frmMe.txtCommentsAgent.readOnly)
				frmMe.txtCommentsAgent.focus();	
		}
}

function ShowConversionCalculator()
{		
	if (tblCloseValuationCheck.style.display != "inline")
		{
			
			tblCalculator.style.display = 'inline';
			document.all.item('btnCloseValuation').style.display = 'none';
			HideAllDropDowns();		
			frmMe.txtFeet.focus();
		}
}

function ConversionCalcClose()
{
	tblCalculator.style.display = 'none';
	document.all.item('btnCloseValuation').style.display = 'inline';
	ShowAllDropDowns();	
}

