
<!--
/*
Name: UIElements.js
Purpose: Repository of functions for controlling the display of elements (mostly form elements) or
			and their supportting functions
Author: Michael Bane (mtb)
Date: 02/19/2003
Modification History:
02/19/2003	mtb	Most functions are written by me; however, some are snippets collected from the web

LIST OF FUNCTIONS

GENERAL FUNCTIONS
function openScript(url, width, height)

STRING FUNCTIONS
function LTrim(str)
function RTrim(str)
function Trim2(str)

NEW APPLICANT FUNCTIONS
function onChangeMgmtTeam(frm,cboSelect,txtID, txtFirstName, txtLastName, txtTitle) 
function addMgmtOption(cboSelect,txtID, txtFirstName, txtLastName, txtTitle, blnClear)
function removeMgmtOption(cboSelect,txtID, txtFirstName, txtLastName, txtTitle, blnClear)
function FilterSubList(cboMain,cboSubAll,cboSubFilter)
function onChangeInvProps(frm,cboSelect,txtID, cboState, cboMSA,cboMSAFilter, txtQty)
function addInvPropsOption(cboInvProp, cboInvPropH,txtID, cboState, cboMSAFilter, txtQty, blnClear)
function removeInvPropsOption(cboInvProp, cboInvPropH,txtID,  cboState, cboMSAFilter, txtQty, blnClear) 
function removeAll(cboSelect)
function addUpdGlobalEntryInvProps(strText, intID, intQty)
function removeGlobalEntryInvProps(intID)
function addUpdGlobalEntryAssetClass(strText, intID, intQty)
function removeGlobalEntryAssetClass(intID)
function clearID(txtID)
function listArrays()
function findDDEntryByText(cboSelect,strValue) 
function findDDEntryByValue(cboSelect,strValue) 
function setIsPrimaryContact(chkIsPrimary,frm,txtFirst, txtLast, txtTitle, txtPCFirst, txtPCLast, txtPCTitle) 
function setIsMgmt(chkIsMgmt,frm,txtID, txtFirst, txtLast, txtTitle, cboSelect)
function findEntry(cboSelect,txtFirst, txtLast, txtTitle)

*/

/*
FUNCTION DEFINITIONS
*/

function removeAll(cboSelect){
	var numElements = cboSelect.length;
	for(var intIndex = 0; intIndex < numElements; intIndex++){
		//alert('Removing = (length='+ cboMSAFilter.length + ') intIndex(' + intIndex + ')' + cboMSAFilter.options[0].text);
		cboSelect.options[0] = null; // This should always be the first
										// element not the index since the
										// values will shift as they are removed
	}

}

function clearID(txtID){
	// Ensure that if the use changed a crucial option then the ID is cleared
	txtID.value = 0;
}

function findDDEntryByText(cboSelect,strValue) {
	// Trim the string
	/*
	alert('Start Length = ' + strValue.length);
	strValue.replace('^\s',"");
	strValue.replace('\s$',"");
	alert('End Length = ' + strValue.length);
	
	*/
	//strValue.trim();
	strValue = trim3(strValue);
	//alert('strValue = ' + strValue);
	//alert('cboSelect.length = ' + cboSelect.length);
	for(var intIndex = 0; intIndex <= cboSelect.length - 1; intIndex++){
		// See if the entry matches
		var strOption = cboSelect.options[intIndex].text;
		
		//alert('Option.text = ' + strOption + ' Option.length = ' + strOption.length + '\nstrValue.text = ' + strValue + ' strValue.length = ' + strValue.length + '\nequal = ' + (cboSelect.options[intIndex].text == strValue));
		//alert('equal = ' + (cboSelect.options[intIndex].text == strValue));
		if(cboSelect.options[intIndex].text == strValue){
			// Select the item
			cboSelect.options[intIndex].selected = true;
			// Return the index
			return intIndex;
			break;
		}
	
	}
	return -1;
}
function findDDEntryByValue(cboSelect,strValue) {
		
	//alert('strValue = ' + strValue);
	//alert('cboSelect.length = ' + cboSelect.length);
	for(var intIndex = 0; intIndex <= cboSelect.length - 1; intIndex++){
		// See if the entry matches
		//alert('cboSelect.options[intIndex].text = ' + cboSelect.options[intIndex].text);
		//alert('equal = ' + (cboSelect.options[intIndex].text == strValue));
		if(cboSelect.options[intIndex].value == strValue){
			// Select the item
			cboSelect.options[intIndex].selected = true;
			// Return the index
			return intIndex;
			break;
		}
	
	}
	return -1;
}




////////////////////////////////////////////////////////////////////
// Misc
////////////////////////////////////////////////////////////////////
function setIsPrimaryContact(chkIsPrimary,frm,txtAppFirstName, txtAppLastName, txtAppTitle, txtPCFirst, txtPCLast, txtPCTitle) {


    	//alert('IsPrimary = ' + chkIsPrimary.checked);
	if (chkIsPrimary.checked) {
		// Copy the values into the primary contact fields
		txtPCFirst.value = txtAppFirstName.value;
		txtPCLast.value = txtAppLastName.value;
		txtPCTitle.value = txtAppTitle.value;
	}else{
		// Only clear the boxes if the value entered is the
		// same as the app
		if ((txtPCFirst.value ==txtAppFirstName.value) && 
			(txtPCLast.value ==txtAppLastName.value) &&
			(txtPCTitle.value == txtAppTitle.value)) {
			txtPCFirst.value = '';
			txtPCLast.value = '';	
			txtPCTitle.value = '';
		}
	}

}


function findEntry(cboSelect,txtFirst, txtLast, txtTitle) {
	
	var strValue = txtFirst.value + ' | ' + txtLast.value  + ' | ' + txtTitle.value;
	//alert('strValue = ' + strValue);
	//alert('cboSelect.length = ' + cboSelect.length);
	for(var intIndex = 0; intIndex <= cboSelect.length - 1; intIndex++){
		// See if the entry matches
		//alert('cboSelect.options[intIndex].text = ' + cboSelect.options[intIndex].text);
		//alert('equal = ' + (cboSelect.options[intIndex].text == strValue));
		if(cboSelect.options[intIndex].text == strValue){
			// Select the item
			cboSelect.options[intIndex].selected = true;
			// Return the index
			return intIndex;
			break;
		}
	
	}
	return -1;
	
}

function selectall(cboSelect) {
	for ( i=0;i< cboSelect.options.length; i++){		
		cboSelect.options[i].selected = true;
	}
}

function setURLFormat(txtWebsite){
	var blnAddHTTP = true;
	var blnAddSlash1 = false, blnAddSlash2 = false;
	var strURL = txtWebsite.value;
	var strNewURL = '';
	if(strURL == '') return;
	
	strURL = strURL.toLowerCase();
	//alert('strURL (bf) = ' + strURL)
	// If they just entered a www then add http://
	if(strURL.substring(0,3) == 'www') blnAddHTTP = true;
	if(strURL.substring(0,3) == 'ftp') blnAddHTTP = false;
	if(strURL.substring(0,4) == 'http') blnAddHTTP = false;
	if(strURL.substring(0,5) == 'https') blnAddHTTP = false;
	
	if(strURL.substring(0,1) == '\/') {
	
		if(strURL.substring(0,2) == '\/\/') {
			// Has both so add none
			blnAddSlash1 = false;
			blnAddSlash2 = false;
			
		}else{
			// Has one so add one more
			blnAddSlash1 = true;
			blnAddSlash2 = false;			
		}
	}else{
		// No slashes so add both
		blnAddSlash1 = false;
		blnAddSlash2 = true;
	}
	
	//if(blnAddSlash1) blnAddSlash2 = false;
	//if(blnAddSlash2) blnAddSlash1 = false;
	
	//alert('strURL.substring(0,1)= ' + strURL.substring(0,1) + ' blnAddSlash1 = ' + blnAddSlash1)
	//alert('strURL.substring(0,2)= ' + strURL.substring(0,2) + ' blnAddSlash2 = ' + blnAddSlash2)
		
	if(blnAddHTTP) {
		strNewURL = 'http:';
		if(blnAddSlash2) strNewURL += '\/\/';
		if(blnAddSlash1) strNewURL += '\/';
		
		
		txtWebsite.value = strNewURL + txtWebsite.value;
	}
	//alert('substring= ' + strURL.substring(0,3))
	//alert('txtWebsite.value (af) = ' + txtWebsite.value)
}
var g_intErrMsgTop, g_intErrMsgLeft = 0;
var g_intErrMsgClientTop, g_intErrMsgClientLeft = 0;
var g_intErrMsgOffsetTop, g_intErrMsgOffsetLeft = 0;
function afterFormLoad(blnGlobalsOnly){
	//alert('Running afterFormLoad');
	if(blnGlobalsOnly == null) blnGlobalsOnly = false;
	
	
	
	//alert('Calling appMoveNext...');
	// Setup the navigation buttons
	//alert('currentPage.value = ' + $('currentPage').value);
	if(!(blnGlobalsOnly) && $('currentPage').value == 0) {
		appMoveNext('frmApplication',$('currentPage'));
		//alert("skipping appMoveNext...");
	}
	//alert('appMoveNext complete...\nCalling loadStoredGlobals\n');
	
	// Repopulate any global values
	loadStoredGlobals();
	
	//alert('loadStoredGlobals complete...\nSetting ErrorMsg location...');
	if(!($('ErrorMsgs') == null)){
		//alert('ErrorMsg is not null...setting variables...');
		g_intErrMsgTop = $('ErrorMsgs').style.top;
		g_intErrMsgLeft = $('ErrorMsgs').style.left;
		g_intErrMsgClientTop = $('ErrorMsgs').clientTop;
		g_intErrMsgClientLeft = $('ErrorMsgs').clientLeft;
		g_intErrMsgOffsetTop = $('ErrorMsgs').offsetTop;
		g_intErrMsgOffsetLeft = $('ErrorMsgs').offsetLeft;
		/*alert('g_intErrMsgTop = ' + g_intErrMsgTop + '\n' +
				'g_intErrMsgLeft = ' + g_intErrMsgLeft + '\n' +
				'g_intErrMsgClientTop = ' + g_intErrMsgClientTop + '\n' +
				'g_intErrMsgClientLeft = ' + g_intErrMsgClientLeft + '\n' +
				'g_intErrMsgOffsetTop = ' + g_intErrMsgOffsetTop + '\n' +
				'g_intErrMsgOffsetLeft = ' + g_intErrMsgOffsetLeft);*/
	}else{
		alert ('ErrorMsgs is null...');
	}
		
}

/*******************************************************************************************************
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'	SetSecurityCookie : Saves strCoookieName cookie with value of 
'						strCookieValue for Security Purposes
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'	Returns: True/false to indicate success/failure
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''*/
function SetSecurityCookie(strCookieName, strCookieValue){	
	var expires = null;  
	var path = "/";  // -- automatically set to expire when browser ends
	var domain =  null;  
	var secure = false;  
	document.cookie = strCookieName + "=" + escape (strCookieValue) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + path)) +  
	((domain == null) ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");
	return true;
}



function showArticle(object) {
    if (document.layers && document.layers[object] != null)
        document.layers[object].visibility = 'visible';
    else  {
        document.getElementById(object).style.visibility = 'visible';
    }
}
function hideArticle(object) {
    if (document.layers && document.layers[object] != null)
        document.layers[object].visibility = 'hidden';
    else 
         document.getElementById(object).style.visibility = 'hidden';
}

function enableOther(chkOption, txtOther){
	//alert('enableOther for checkbox');
	//alert('Option: ' + chkOption.name + ' Other: ' + txtOther.name);
	
	if(chkOption.checked) 
		txtOther.disabled = false;
	else
		txtOther.disabled = true;
	//alert('Enable/Disable: ' + txtOther.disabled);
}
function enableOtherCBX(strOtherList, cboOption,txtOther){
	
	var arrValues;	
	var blnOtherSelected = false;
	//alert('enableOther for combos');
	strOtherList = strOtherList.trim();	
	arrValues = strOtherList.split(',');
	
	for (var i = 0; i < arrValues.length; i++){
		if (arrValues[i] == cboOption.value) {
			blnOtherSelected = true;
			break;
		}
	}
	if(blnOtherSelected) 
		txtOther.disabled = false;
	else
		txtOther.disabled = true;

	return blnOtherSelected;
}
function changeBox(cbox, intIndex) {
	// Allows user to click on the checkbox/radio text to make an item selected/checked
	// Code snippet from http://www.itechcentral.net/java/Forms/checkbox-text.html
	// 09/10/2003	mtb Exit if the checkbox has been disabled
	box = eval(cbox);
	if(box.disabled) return;
	box.checked = !box.checked;
	//alert(box.value);
}

function isOther(strOtherList, strValue){
	/*' -------------------------------------------------------------------------------------------
	' NAME:IsCheckedByCtrl
	' PURPOSE: Like the original above it determines is a control array of checkboxes should be check;
	'			however, here the value cannot or are not using a poweroftwosum e.g. values are C1S2,C1S3
	'			This is primarily used to repopulated controls from the Request object.
	' PARAMETERS:
	'	strValueList - comma-delimited list of selections 1,3,4
	'	strCtrlValue - value assigned to the given control
	' AUTHOR: Michael Bane (mtb)
	' DATE: 03/19/2003
	' MODIFICATION HISTORY:
	' -------------------------------------------------------------------------------------------*/	
	var arrValues;	
	var blnChecked = false;
	
	strOtherList = strOtherList.trim();	
	arrValues = strOtherList.split(',');
	
	for (var i = 0; i < arrValues.length; i++){
		if (arrValues[i] == strValue) {
			blnChecked = true;
			break;
		}
	}
	

	return blnChecked;
}
function doNothing(){}


function onStateCountryChange(cboCountry, cboState){
	var intCountryID = eval(cboCountry.options[cboCountry.selectedIndex].value);
	var intStateID = eval(cboState.options[cboState.selectedIndex].value);
	
	if(intCountryID == 268) { // US
		// State must be US or unselected (at this point)
		if(g_blnHasCtryChange){
			if(intStateID >=60) {
				alert('You must select a US state.')
				cboState.selectedIndex = 0;
			}
		}
		g_blnHasCtryChange = true;
	}else{ // Non-US
		// State must be Non-US
		if((g_intNonUSStateID > 0) && (intStateID != g_intNonUSStateID))
			alert('State must be outside the US if the country is not in the United States.');
		
		//cboState.selectedIndex = 59;
		findDDEntryByText (cboState,'- Outside U.S. -');	
		g_intNonUSStateID = eval(cboState.options[cboState.selectedIndex].value);
		g_blnHasCtryChange = false;
	}	
}
function checkAuthentication(e){
	// Check the user authentication field
	var authCode = $('x29p3').value;
	//alert('authCode = ' + authCode);
	if($('txtAuthCode').value != authCode){
		//alert('User authentication does not match the image.\nNote: The authentication is case-sensitive.');
		showErrorMsg('User authentication does not match the image.\nNote: The authentication is case-sensitive.', e);
				
	}
	
}

function encodeEmail(strEmail) {
	/***************************************************************************************
	NAME:
	PURPOSE:
	Doc. No. /wbw/emailencoder.html 
	DATE:
	AUTHOR:
	Document Author and WBW Web Master: David R. Kerwood
	Documents created by: West Bay Web 
	email: &#119;&#098;&#119;&#064;&#119;&#098;&#119;&#105;&#112;&#046;&#099;&#111;&#109; 
	http://www.wbwip.com/wbw/
	MODIFICATION HISTORY:
	03/26/2003	mtb Code snippet adapted fro the mop site
					Most modification is converting multi-line statement to single line for 
					greater use of space.
					Also adding a value to be passed in and returned rather than a field
					being set directly.
					This is also being adapted for ASP script
	***************************************************************************************/

	var regEmail = strEmail.toLowerCase(); //document.ENCODER.regEmail.value.toLowerCase()
	var codeEmail = ""
	
	if (regEmail == "") {
	        alert("Please enter your regular e-mail address.")
	}else {
        var regLength = regEmail.length
        for (i = 0; i < regLength; i++) {
                var charNum = "000"
                var curChar = regEmail.charAt(i)
                if (curChar == "a") {                    	 charNum = "097"                }
                if (curChar == "b") {                        charNum = "098"                }
                if (curChar == "c") {                        charNum = "099"                }
                if (curChar == "d") {                        charNum = "100"                }
                if (curChar == "e") {                        charNum = "101"                }
                if (curChar == "f") {                        charNum = "102"                }
                if (curChar == "g") {                        charNum = "103"                }
                if (curChar == "h") {                        charNum = "104"                }
                if (curChar == "i") {                        charNum = "105"                }
                if (curChar == "j") {                        charNum = "106"                }
                if (curChar == "k") {                        charNum = "107"                }
                if (curChar == "l") {                        charNum = "108"                }
                if (curChar == "m") {                        charNum = "109"                }
                if (curChar == "n") {                        charNum = "110"                }
                if (curChar == "o") {                        charNum = "111"                }
                if (curChar == "p") {                        charNum = "112"                }
                if (curChar == "q") {                        charNum = "113"                }
                if (curChar == "r") {                        charNum = "114"                }
                if (curChar == "s") {                        charNum = "115"                }
                if (curChar == "t") {                        charNum = "116"                }
                if (curChar == "u") {                        charNum = "117"                }
                if (curChar == "v") {                        charNum = "118"                }
                if (curChar == "w") {                        charNum = "119"                }
                if (curChar == "x") {                        charNum = "120"                }
                if (curChar == "y") {                        charNum = "121"                }
                if (curChar == "z") {                        charNum = "122"                }
                if (curChar == "0") {                        charNum = "048"                }
                if (curChar == "1") {                        charNum = "049"                }
                if (curChar == "2") {                        charNum = "050"                }
                if (curChar == "3") {                        charNum = "051"                }
                if (curChar == "4") {                        charNum = "052"                }
                if (curChar == "5") {                        charNum = "053"                }
                if (curChar == "6") {                        charNum = "054"                }
                if (curChar == "7") {                        charNum = "055"                }
                if (curChar == "8") {                        charNum = "056"                }
                if (curChar == "9") {                        charNum = "057"                }
                if (curChar == "&") {                        charNum = "038"                }
                if (curChar == " ") {                        charNum = "032"                }
                if (curChar == "_") {                        charNum = "095"                }
                if (curChar == "-") {                        charNum = "045"                }
                if (curChar == "@") {                        charNum = "064"                }
                if (curChar == ".") {                        charNum = "046"                }
				
                if (charNum == "000") {
                        codeEmail += curChar
                }
                else {
                        codeEmail += "&#" + charNum + ";"               
                }
        }
        //document.ENCODER.codeEmail.value = codeEmail
		return codeEmail;
	}
	return "";
}

function setAppliedDateFilter(ctrl){
	if(ctrl.value == 0){
		$('Between').style.visibility = 'hidden';
		$('Exact').style.visibility = 'hidden'; 
	}else{
		if(ctrl.value == 7){
			$('Exact').style.visibility = 'hidden'; 
			$('Between').style.visibility = '';
		} else{
			$('Exact').style.visibility = ''; 
			$('Between').style.visibility = 'hidden';
		}
	}
}

function setCompanyFilter(ctrl){
	//alert('ctrl.value = ' + ctrl.value);	
		if(ctrl.value > 1){
			// Show company like
			$('CompanyExact').style.visibility = 'hidden'; 
			$('CompanyLike').style.visibility = '';
			
		} else{
			// show company exact
			$('CompanyExact').style.visibility = ''; 
			$('CompanyLike').style.visibility = 'hidden';
			
		}
	//}
}

/*
Preload images script
By JavaScript Kit (http://javascriptkit.com)
Over 400+ free scripts here!
*/

var myimages = new Array();
function preloadImages(){
	for (i = 0; i < preloadImages.arguments.length; i++){
		myimages[i] = new Image();
		myimages[i].src = preloadImages.arguments[i];
		
	}
}

function getImage(dest,image){ 
/*
Enter path of images to be preloaded inside parenthesis. Extend list as desired.
Ex. preloadimages("http://mydomain.com/firstimage.gif","http://mydomain.com/secondimage.gif","http://mydomain.com/thirdimage.gif")

MODIFICATION HISTORY:
08/26/2008	MTB	Adding Firefox code block.
*/
	//alert('isIE = ' + isIE + ' image = ' + image);
	var intLoopCnt = 0
	// check if more pics 
	if(!document.images) return;
	
	//if(myimages[image] == null) document.write("Unable to locate image (" + image + ")");
	//thispic=(thispic+1)%mypix.length;
	if(isIE){  	
		// 09/22/2003	mtb On the production site, the images are taking 
		//					a while to preload. The Navigation code start to process before
		//					they are done causing an object is null error. So we will give them
		//					more time to load. (May need to add a counter to be sure we can eventually 
		//					exit the loop if used for other purposes where the image may never be found.).
		//					Yes, eventual exit was necessary.
		// 09/22/2003	mtb A better and more consistent solution was to just test if the image object
		//					was null before making the assignment. It appears to load everything correctly
		//					and faster using this test.
		//setTimeOut(self.focus(),10000);
		/*while (myimages[image] == null){
		intLoopCnt += 1;
		if(intLoopCnt > 1000000) break;
		}*/
		// 10/24/2008	mtb	This can now use the other format as style rather than property of the object.
		//if(!(myimages[image] == null)) $(dest).background = myimages[image].src;
		if(!(myimages[image] == null)) $(dest).style.background= "url('" + myimages[image].src + "')";
	}else if(isNS4 || isNS6 || isFireFox){
		if(!(myimages[image] == null)) $(dest).style.background= "url('" + myimages[image].src + "')";
	}
} 

function initImages()
{
	
	preloadImages("../images/tab_left_corner_on.gif" ,
				"../images/tab_top_edge_on.gif",
				"../images/tab_right_corner_on.gif" ,
				"../images/tab_left_edge_on.gif" ,
				"../images/tab_right_edge_on.gif",
				"../images/tab_left_corner_off.gif" ,
				"../images/tab_top_edge_off.gif",
				"../images/tab_right_corner_off.gif" ,
				"../images/tab_left_edge_off.gif" ,
				"../images/tab_right_edge_off.gif"  );
	
	return true;
}

function synchReportListings(){
	var intReportIndex = $('cboReports').selectedIndex;
	$('cboParameters').selectedIndex = 
	$('cboSubReports').selectedIndex = 
	$('cboMultiSelect').selectedIndex = 
	$('cboFileName').selectedIndex = 
	$('cboPrefix').selectedIndex = 
	$('cboFilePath').selectedIndex = 
	$('cboCompanyName').selectedIndex = 
	$('cboPaperSize').selectedIndex = 
	$('cboPaperOrientation').selectedIndex = 
	$('cboFixedFileName').selectedIndex = 
	$('cboNoFilter').selectedIndex = 
		intReportIndex;

	//alert('intReportIndex = ' + intReportIndex);
}

function synchCompanyListings(){
	var intCompanyIndex = $('cboCompanies').selectedIndex;
	$('cboCompanyName').selectedIndex = 
		
						intCompanyIndex;
}
function synchCountryState(){
	if($('cboStates').options.length < 0) return;
	if($('cboCountries').options[$('cboCountries').selectedIndex].value != 268){
		$('cboStates').selectedIndex = findDDEntryByValue($('cboStates'), 60);
		$('cboStates').disabled = true;
	}else{
		//alert('synchCountryState: Doing else...');
		$('cboStates').selectedIndex = 0;
		$('cboStates').disabled = false;
	}
}

function setCompanyCtrl(){
	var blnCanMulti = $('cboMultiSelect').options[$('cboMultiSelect').selectedIndex].value.toLowerCase();
	var blnNoFilter = $('cboNoFilter').options[$('cboNoFilter').selectedIndex].value.toLowerCase();
	//alert('blnCanMulti = ' + blnCanMulti);
	//If no filter then keep both hidden
	if(eval(blnNoFilter)){
		$('SingleCompany').style.visibility = 'hidden';
		$('MultiCompany').style.visibility = 'hidden';
	}else{
		// Otherwise show one or the other
		if(eval(blnCanMulti)) {
			$('SingleCompany').style.visibility = 'hidden';
			$('MultiCompany').style.visibility = '';
			$('CompanyCol').style.height = 130;
		}else{
			$('SingleCompany').style.visibility = '';
			$('MultiCompany').style.visibility = 'hidden';
			$('CompanyCol').style.height = 25;
		}
	}
}

function  setLevel1UpdMode(chkUpdStatus) {
/*

MODIFICATION HISTORY:
04/30/2003	mtb	No date requirement just disable or set all fields
04/30/2003	mtb	If updating the status that must do an export; otherwise
				can only run without an update
				Using just one button to manage all through javascript
*/
	//alert('setLevel1UpdMode...');
	if(chkUpdStatus.checked){
		// Disable selections
		$('fbc_ctrl').disabled = true;
		$('fbt_ctrl').disabled = true;	
		$('cboROIOp_ctrl').disabled = true;	
		$('txtROI_ctrl').disabled = true;	
		$('cboDateOperator_ctrl').disabled = true;	
		
		// Force desired selections
		$('fbc_ctrl').selectedIndex = 0;
		
		// 05/01/2003	mtb	Changed from 3 to 1 after removing other options
		$('fbt_ctrl').selectedIndex = 1;		
		
		$('cboDateOperator_ctrl').selectedIndex = 0;
		
		$('cboROIOp_ctrl').selectedIndex = 4; 
		
		// Set default ROI
		$('txtROI').value = $('DefaultROI').value;
		
		$('doRpt').value = true;
		$('doUpdate').value = true;
		
		
		$('cmdFilter').value = 'Run and Export ';//Metrics';
		$('Exact').style.visibility = 'hidden';
		$('Between').style.visibility = 'hidden';
		// Set default dates
		//var datNow = new Date();
		//datNow.getDate();
	}else{
		$('fbc_ctrl').disabled = false;
		$('fbt_ctrl').disabled = false;
		$('cboROIOp_ctrl').disabled = false;	
		$('txtROI_ctrl').disabled = false;	
		$('cboDateOperator_ctrl').disabled = false;	
		// Change match back to passed
		$('fbt_ctrl').selectedIndex = 0;
		$('cboDateOperator_ctrl').selectedIndex = 0;

		$('doRpt').value = false;
		$('doUpdate').value = false;
		
		
		$('cmdFilter').value = 'Run Metrics';
	}

}
function confirmDelete( intID,strText, strFormName){
	//alert('Form:' + strFormName);
	if(confirm('Are you sure you want to DELETE "' + strText + '"?')){
		$('del').value = true;
		if(!($('rid') == null)) $('rid').value = intID;
		document.getElementsByName(strFormName)[0].submit();
	}
	else
		$('del').value = false;

}
function confirmDeleteNavigate( strText, strHREF, strPath,strActionFileName){
	if(confirm('Are you sure you want to DELETE "' + strText + '"?')){
		$('del').value = true;
		$('delFile').value = strText;
		$('pth').value = strPath;
		// Change the forms action property
		document.getElementsByTagName("form")[0].action = strActionFileName;
		document.getElementsByTagName("form")[0].submit();
	}
	else
		$('del').value = false;

}
function confirmRecovery( intID,strText, strFormName){
	if(confirm('Are you sure you want to RESTORE "' + strText + '"?')){
		//alert('strFormName = ' + strFormName);
		$('restore').value = true;
		$('rid').value = intID;
		document.getElementsByName(strFormName)[0].submit();
	}
	else
		$('restore').value = false;

}

function changeFinancialDisplay(){
	var intDate1Index = $('cboDate1').selectedIndex;
	var intDate2Index = $('cboDate2').selectedIndex;
	
	if(intDate1Index >=0) $('cboDate1Val').value = $('cboDate1').options[intDate1Index].text;
	if(intDate2Index >=0) $('cboDate2Val').value = $('cboDate2').options[intDate2Index].text;	
	
	document.getElementsByTagName("form")[0].submit();
}

function setNewPME(pty,fbp,fba,fbs,p,m,mode){
	if(mode == null) mode = 0;
	// Adding test for combo as well
	if($('period').value == ""){
		alert('You must select a Quarter.\n');
		return;
	}else if($('cboPeriod') != null){
		if($('cboPeriod').selectedIndex == 0){
			alert('You must select a Quarter.\n');
			return;
		}
	}	
	
	$('fbp').value = fbp;
	$('fba').value = fba;
	$('fbs').value = fbs;
	$('p').value = p;
	$('m').value = m;
	if($('EncPeriod') != null)
		$('EncPeriod').value = false;
	//$('period.value = $('cboPeriod.value;
	updateStateEditPME(pty);
	// Change the action location if needed
	if(mode == 1) document.getElementsByTagName("form")[0].action = 'EditPMEADM.asp';
	document.getElementsByTagName("form")[0].submit();
	//////////////////////////////////////////////////////////////////////	
	//alert("Setting New PME...");	
	//var strHREF = "./EditPMEADM.asp?pty=" + pty + "&cc=0&fbp=" + fbp + "&fba=" + fba + "&fbs=" + fbs + "&p=2&m=1";
	//alert("strHREF = " + strHREF);
	//window.location.href = strHREF;

}
function setRunExport(){
	if($('period').value == ""){
		alert('You must select a Quarter.\n');
		return false;
	}
	$('doRpt').value=true;
	
	document.getElementsByTagName("form")[0].action = 'PropertyDetailsADM.asp';
	document.getElementsByTagName("form")[0].submit();
	return true;
}

function setEvalPeriod(cboPeriod){
	$('period').value = cboPeriod.value;
	$('periodLong').value = cboPeriod.options[cboPeriod.selectedIndex].text;
	if($('pd') != null) $('pd').value = cboPeriod.value;
	if($('pdl') != null) $('pdl').value = cboPeriod.options[cboPeriod.selectedIndex].text;
	
	if($('EncPeriod') != null)
		$('EncPeriod').value = false;
}

function updateScore(rating, weight, score, itemName,i){
	// 07/30/2003	mtb To increase performance, this will only run via a recalc button
	//					Rather than removing the call from all places it is currently used
	//					(especially, in the event that the onblur processing needs to be restored)
	//					a parameter has been created that will only be passed in by the button
	// 					Without this parameter the code will simply exit
	//					This is now called by the recalScores function that is use the same conditional execution
	if(i == null) return;
	
	//alert('weightVal = ' + weight.name);
	var weightVal = weight.innerText;
	var scoreOld = score.innerHTML;
	//alert('weightVal = ' + weightVal);
	if(rating.value == null || weightVal == null) return;
	if(rating.value < 0 || weightVal  < 0) {
		alert('Either the rating or weight value is less than zero for \'' + itemName + '\'.\n');
		return;
	}
	var scoreNew = rating.value * weightVal;
	
	// Only update the screen and recalculate if the value has changed
	if(scoreNew != scoreOld){
		score.innerHTML = scoreNew;
		recalcScores();
	}
}

function recalcScores(i){
	// 07/30/2003	mtb To increase performance, this will only run via a recalc button
	//					Rather than removing the call from all places it is currently used
	//					(especially, in the event that the onblur processing needs to be restored)
	//					a parameter has been created that will only be passed in by the button
	// 					Without this parameter the code will simply exit
	//					Also, adding the update scores here with the same extra param
	////////////////////////////////////////////////////////////////////////////////////
	if(i == null) return;
	document.body.style.cursor="wait";
	// INCOME
	var IncomeRatingVal = eval($('txtIncomeRating').value);
	if(IncomeRatingVal == null) IncomeRatingVal = eval($('txtIncomeRating').innerText);
	var IncomeWeightVal = eval($('txtIncomeWeight').innerText);	
	var IncomeScoreVal = eval(IncomeRatingVal * IncomeWeightVal);
	$('txtIncomeScore').innerText = IncomeScoreVal;
	
	
	
	// EXPENSES
	var ExpensesRatingVal = eval($('txtExpensesRating').value);
	if(ExpensesRatingVal == null) ExpensesRatingVal = eval($('txtExpensesRating').innerText);
	var ExpensesWeightVal = eval($('txtExpensesWeight').innerText);	
	var ExpensesScoreVal = eval(ExpensesRatingVal * ExpensesWeightVal);
	$('txtExpensesScore').innerText = ExpensesScoreVal;
	
	// NOI
	var NOIRatingVal = eval($('txtNOIRating').value);
	if(NOIRatingVal == null) NOIRatingVal = eval($('txtNOIRating').innerText);
	var NOIWeightVal = eval($('txtNOIWeight').innerText);	
	var NOIScoreVal = eval(NOIRatingVal * NOIWeightVal);
	$('txtNOIScore').innerText = NOIScoreVal;
	
	// CAPITAL	
	updateScore($('txtCapitalRating'), $('txtCapitalWeight'), $('txtCapitalScore'), 'Capital',1);	

	var CapitalRatingVal = eval($('txtCapitalRating').value);
	if(CapitalRatingVal == null) CapitalRatingVal = eval($('txtCapitalRating').innerText);
	var CapitalWeightVal = eval($('txtCapitalWeight').innerText);	
	var CapitalScoreVal = eval(CapitalRatingVal * CapitalWeightVal);
	$('txtCapitalScore').innerText = CapitalScoreVal;
	

	
	// CASH FLOW
	var CashFlowRatingVal = eval($('txtCashFlowRating').value);
	if(CashFlowRatingVal == null) CashFlowRatingVal = eval($('txtCashFlowRating').innerText);
	var CashFlowWeightVal = eval($('txtCashFlowWeight').innerText);	
	var CashFlowScoreVal = eval(CashFlowRatingVal * CashFlowWeightVal);
	$('txtCashFlowScore').innerText = CashFlowScoreVal;
	
	// OCCUPANCY	
	if(!($('txtOccupancyRating') == null))
		updateScore($('txtOccupancyRating'), $('txtOccupancyWeight'), $('txtOccupancyScore'), 'Occupancy',1);
	var OccupancyRatingVal = eval($('txtOccupancyRating').value);	
	if(OccupancyRatingVal == null) OccupancyRatingVal = eval($('txtOccupancyRating').innerText);
	var OccupancyWeightVal = eval($('txtOccupancyWeight').innerText);	
	var OccupancyScoreVal = eval(OccupancyRatingVal * OccupancyWeightVal);
	$('txtOccupancyScore').innerText = OccupancyScoreVal;
	
	
	
	// FINANCIALS SCORE	
	var FinScoreVal = IncomeScoreVal + ExpensesScoreVal + NOIScoreVal 
			+ CapitalScoreVal + CashFlowScoreVal + OccupancyScoreVal;
	$('txtFinScoreTop').innerText = FinScoreVal;
	$('txtFinScoreBottom').innerText = FinScoreVal; 
	////////////////////////////////////////////////////////////////////////////////////
	// INNOVATION
	updateScore($('txtInnovationRating'), $('txtInnovationWeight'), $('txtInnovationScore'), 'Innovation',1);
	var InnovationRatingVal = eval($('txtInnovationRating').value);
	var InnovationWeightVal = eval($('txtInnovationWeight').innerText);
	var InnovationScoreVal = eval(InnovationRatingVal * InnovationWeightVal);
	/*
	alert(
		'InnovationRatingVal = ' + InnovationRatingVal + '\n' +
		'InnovationWeightVal = ' + InnovationWeightVal + '\n' +
		'InnovationScoreVal = ' + InnovationScoreVal + '\n' 
		);
	*/
	$('txtInnovationScore').innerText = InnovationScoreVal;
	
	// SHARED VALUES
	updateScore($('txtSharedRating'), $('txtSharedWeight'), $('txtSharedScore'), 'Shared',1);
	var SharedRatingVal = eval($('txtSharedRating').value);
	var SharedWeightVal = eval($('txtSharedWeight').innerText);	
	var SharedScoreVal = eval(SharedRatingVal * SharedWeightVal);
	$('txtSharedScore').innerText = SharedScoreVal;
	
	// INNOVATION AND SHARED VALUES SCORE		
	var InnScoreVal = InnovationScoreVal + SharedScoreVal;
	$('txtInnScoreTop').innerText = InnScoreVal;
	$('txtInnScoreBottom').innerText = InnScoreVal; 
	////////////////////////////////////////////////////////////////////////////////////
	// APR
	updateScore($('txtAPRRating'), $('txtAPRWeight'), $('txtAPRScore'), 'APR',1);
	var APRRatingVal = eval($('txtAPRRating').value);
	var APRWeightVal = eval($('txtAPRWeight').innerText);	
	var APRScoreVal = eval(APRRatingVal * APRWeightVal);
	$('txtAPRScore').innerText = APRScoreVal;
	
	// CAP
	updateScore($('txtCapRating'), $('txtCapWeight'), $('txtCapScore'), 'Cap',1);
	var CapRatingVal = eval($('txtCapRating').value);
	var CapWeightVal = eval($('txtCapWeight').innerText);	
	var CapScoreVal = eval(CapRatingVal * CapWeightVal);
	$('txtCapScore').innerText = CapScoreVal;

	// MARKET
	updateScore($('txtMarketRating'), $('txtMarketWeight'), $('txtMarketScore'), 'Market',1);
	var MarketRatingVal = eval($('txtMarketRating').value);
	var MarketWeightVal = eval($('txtMarketWeight').innerText);	
	var MarketScoreVal = eval(MarketRatingVal * MarketWeightVal);
	$('txtMarketScore').innerText = MarketScoreVal;

	// CUSTOMER SCORE
	var CustScoreVal =  APRScoreVal + CapScoreVal + MarketScoreVal;
	$('txtCustScoreTop').innerText = CustScoreVal;
	$('txtCustScoreBottom').innerText  = CustScoreVal;
	////////////////////////////////////////////////////////////////////////////////////
	// OTHER
	updateScore($('txtOtherRating'), $('txtOtherWeight'), $('txtOtherScore'), 'Other',1);
	var OtherRatingVal = eval($('txtOtherRating').value);
	var OtherWeightVal = eval($('txtOtherWeight').innerText);	
	var OtherScoreVal = eval(OtherRatingVal * OtherWeightVal);
	$('txtOtherScore').innerText = OtherScoreVal;

	// MIDDLE
	updateScore($('txtMiddleRating'), $('txtMiddleWeight'), $('txtMiddleScore'), 'Middle',1);
	var MiddleRatingVal = eval($('txtMiddleRating').value);
	var MiddleWeightVal = eval($('txtMiddleWeight').innerText);	
	var MiddleScoreVal = eval(MiddleRatingVal * MiddleWeightVal);
	$('txtMiddleScore').innerText = MiddleScoreVal;
	
	// SENIOR
	updateScore($('txtSeniorRating'), $('txtSeniorWeight'), $('txtSeniorScore'), 'Senior',1);
	var SeniorRatingVal = eval($('txtSeniorRating').value);
	var SeniorWeightVal = eval($('txtSeniorWeight').innerText);	
	var SeniorScoreVal = eval(SeniorRatingVal * SeniorWeightVal);
	$('txtSeniorScore').innerText = SeniorScoreVal;
	
	// LEASING
	if(!($('txtLeasingRating') == null))
		updateScore($('txtLeasingRating'), $('txtLeasingWeight'), $('txtLeasingScore'), 'Leasing',1);
	var PropTypeVal = $('PropType').value;
	var LeasingRatingVal = 0;
	var LeasingWeightVal = 0;	
	var LeasingScoreVal = 0;
	if(PropTypeVal == 'C'){
		LeasingRatingVal = eval($('txtLeasingRating').value);
		LeasingWeightVal = eval($('txtLeasingWeight').innerText);	
		LeasingScoreVal = eval(LeasingRatingVal * LeasingWeightVal);
		$('txtLeasingScore').innerText = LeasingScoreVal;
	}
	

	// PEOPLE SCORE
	var PeopScoreVal = OtherScoreVal + MiddleScoreVal + SeniorScoreVal + LeasingScoreVal;
	$('txtPeopScoreTop').innerText = PeopScoreVal;
	$('txtPeopScoreBottom').innerText  = PeopScoreVal;
	
	////////////////////////////////////////////////////////////////////////////////////
	// MRI
	updateScore($('txtMRIRating'), $('txtMRIWeight'), $('txtMRIScore'), 'MRI',1);
	var MRIRatingVal = eval($('txtMRIRating').value);
	var MRIWeightVal = eval($('txtMRIWeight').innerText);	
	var MRIScoreVal = eval(MRIRatingVal * MRIWeightVal);
	$('txtMRIScore').innerText = MRIScoreVal;
	
	
	// PHYSICAL
	updateScore($('txtPhysicalRating'), $('txtPhysicalWeight'), $('txtPhysicalScore'), 'Physical',1);
	var PhysicalRatingVal = eval($('txtPhysicalRating').value);
	var PhysicalWeightVal = eval($('txtPhysicalWeight').innerText);	
	var PhysicalScoreVal = eval(PhysicalRatingVal * PhysicalWeightVal);
	$('txtPhysicalScore').innerText = PhysicalScoreVal;
	
	
	// SPACE
	updateScore($('txtSpaceRating'), $('txtSpaceWeight'), $('txtSpaceScore'), 'Space',1);
	var SpaceRatingVal = eval($('txtSpaceRating').value);
	var SpaceWeightVal = eval($('txtSpaceWeight').innerText);	
	var SpaceScoreVal = eval(SpaceRatingVal * SpaceWeightVal);
	$('txtSpaceScore').innerText = SpaceScoreVal;
	

	// PROCESS SCORE
	var ProcScoreVal = MRIScoreVal + PhysicalScoreVal + SpaceScoreVal;
	$('txtProcScoreTop').innerText = ProcScoreVal;
	$('txtProcScoreBottom').innerText  = ProcScoreVal;
	
	////////////////////////////////////////////////////////////////////////////////////
	
	// PLAN
	updateScore($('txtPlanRating'), $('txtPlanWeight'), $('txtPlanScore'), 'Plan',1);
	var PlanRatingVal = eval($('txtPlanRating').value);
	var PlanWeightVal = eval($('txtPlanWeight').innerText);	
	var PlanScoreVal = eval(PlanRatingVal * PlanWeightVal);
	$('txtPlanScore').innerText = PlanScoreVal;
	

	// PROCESS SCORE
	$('txtPropPlanScoreTop').innerText = PlanScoreVal;
	$('txtPropPlanScoreBottom').innerText  = PlanScoreVal;

	////////////////////////////////////////////////////////////////////////////////////
	
	var TotalScoreVal = FinScoreVal + InnScoreVal + CustScoreVal + PeopScoreVal + ProcScoreVal + PlanScoreVal;
	var TotalPctVal = (TotalScoreVal * 100) / 500;
	/*
	alert(
		'FinScoreVal = ' + FinScoreVal + '\n' +
		'InnScoreVal = ' + InnScoreVal + '\n' +
		'CustScoreVal = ' + CustScoreVal + '\n' +
		'PeopScoreVal = ' + PeopScoreVal + '\n' +
		'ProcScoreVal = ' + ProcScoreVal + '\n' +
		'PlanScoreVal = ' + PlanScoreVal + '\n' +
		'TotalScoreVal = ' + TotalScoreVal + '\n' +
		'TotalPctVal = ' + TotalPctVal + '\n' 
		);
	*/
	$('txtTotalScore').innerText = TotalScoreVal;
	$('txtTotalPct').innerText = TotalPctVal;
	
	document.body.style.cursor = "default";
}
function updateStatePMEFiles(fbpA, fbaA, fbsA, fbmA, pdA, pdlA){
	if(fbpA != null) SetSecurityCookie('fbpA', fbpA);
	if(fbaA != null) SetSecurityCookie('fbaA', fbaA);
	if(fbsA != null) SetSecurityCookie('fbsA', fbsA);
	if(fbmA != null) SetSecurityCookie('fbmA', fbmA);
	if(pdA != null) SetSecurityCookie('pdA', pdA);
	if(pdlA != null) SetSecurityCookie('pdlA', pdlA);
}
function updateStateRNKFiles(fbpD, fbaD, fbsD, fbmD, pdD, pdlD){
	if(fbpD != null) SetSecurityCookie('fbpD', fbpD);
	if(fbaD != null) SetSecurityCookie('fbaD', fbaD);
	if(fbsD != null) SetSecurityCookie('fbsD', fbsD);
	if(fbmD != null) SetSecurityCookie('fbmD', fbmD);
	if(pdD != null) SetSecurityCookie('pdD', pdD);
	if(pdlD != null) SetSecurityCookie('pdlD', pdlD);
}
function updateStateSearchPME(fbpB, fbaB, fbsB, fbmB, pdB, pdlB){
	//alert('updateStateSearchPME running...');
	if(fbpB != null) SetSecurityCookie('fbpB', fbpB);
	if(fbaB != null) SetSecurityCookie('fbaB', fbaB);
	if(fbsB != null) SetSecurityCookie('fbsB', fbsB);
	if(fbmB != null) SetSecurityCookie('fbmB', fbmB);
	if(pdB != null) SetSecurityCookie('pdB', pdB);
	if(pdlB != null) SetSecurityCookie('pdlB', pdlB);

}
function updateStateEditPME(fbpC, fbaC, fbsC, fbmC, pdC, pdlC){
	if(fbpC != null) SetSecurityCookie('fbpC', fbpC);
	if(fbaC != null) SetSecurityCookie('fbaC', fbaC);
	if(fbsC != null) SetSecurityCookie('fbsC', fbsC);
	if(fbmC != null) SetSecurityCookie('fbmC', fbmC);
	if(pdC  != null) SetSecurityCookie('pdC', pdC);
	if(pdlC != null) SetSecurityCookie('pdlC', pdlC);

}
function disableLink(){
	alert('Coming Soon!');
	return false;
}

function setPMEFileForm(intMode,fbpA, fbaA, fbsA, fbmA, pdA, pdlA){
	if($('cboPeriod').selectedIndex == 0) {
		alert('You must select a Quarter.\n');
		return;
	}
	if(intMode == 1){ // View Files
		// Nothing	 
	}else{ // Create Combo Report and then view files
	 	$('doComboRpt').value=true; 
	}
	updateStatePMEFiles(fbpA, fbaA, fbsA, fbmA, pdA, pdlA);
	$('p').value=2; 
}
function setRNKFileForm(intMode,fbpD, fbaD, fbsD, fbmD, pdD, pdlD){
	if($('cboPeriod').selectedIndex == 0) {
		alert('You must select a Quarter.\n');
		return;
	}
	if(intMode == 1){ // View Files
		// Nothing	 
	}else{ // Create Combo Report and then view files
	 	$('doComboRpt').value=true; 
	}
	updateStateRNKFiles(fbpD, fbaD, fbsD, fbmD, pdD, pdlD);
	$('p').value=2; 
	document.getElementsByName("frmNav")[0].submit();
}
function confirmExit(){
	// Return if the elements do not exist
	if($('IsDirty') == null) return true;
	if($('IsSubmit') == null) return true;
	
	// Check if the user is submitting the form
	// If so, just continue
	if($('IsSubmit').value == 'true') return true;
	
	// Check and confirm the dirty state as needed
	if($('IsDirty').value == 'true'){
		strMsg = "All work will be lost if you leave without saving.\nDo you want to continue?"
		return strMsg;	
	}
	return true;
}
function setPageDirty(){
	$('IsDirty').value = 'true';
}
function setDoingSubmit(){
	$('IsSubmit').value = 'true';
}
function checkPeriodStateInfoOnly(cboStatus){
	// The period is required by just an FYI not an error yet
	if(cboStatus.selectedIndex > 0){
		if($('cboPeriod').selectedIndex == 0) {
			alert('Remember to also select a Quarter to create this filter.\n');
			return;
		}
	}
}
function checkPeriodState(){
	// In this case the period is required
	if($('cboPeriod').selectedIndex == 0) {
		alert('You must select a Quarter.\n');
		return;
	}
}

function setIsProspect(){

	if($('chkIsProspect').checked){
		$('ReqState').style.visibility='';
		$('ReqStatus').style.visibility='';
		$('ReqAssetType').style.visibility='';

		ToggleStatesAll($('ProspectCtrls'), false);
	}else{
		$('ReqState').style.visibility='hidden';
		$('ReqStatus').style.visibility='hidden';
		$('ReqAssetType').style.visibility='hidden';

		// Hide the reject reason asterisk if not a prospect
		$('ReqReason').style.visibility = 'hidden';
		ToggleStatesAll($('ProspectCtrls'), true);
	}
	
}
function ToggleStatesAll(eTheDiv, blnDisable){
	// Code Sample from http://forums.devshed.com/t52639/s.html
	// 09/08/2003	mtb Modified to toggle all states except for the Other controls

	// Retrieve the inputs.	
	eTheInputs = eTheDiv.getElementsByTagName("input");
	
	// If the changed input has text in it, disable all other inputs,
	// otherwise if it's empty, enable all the elements.
	//var strAllElements = '';
	for (var i = 0; i < eTheInputs.length; i++){
	  // Do all input elements.
	 
	  var strName = eTheInputs[i].name	  	
	  // If disabling, disable all. If enabling, skip "others"
	  if ((strName.indexOf('Other') == -1) || (blnDisable))
	   eTheInputs[i].disabled = blnDisable;
	  //strAllElements += strName + '\n';
	}
	
	// Do Dropdowns
	eTheInputs = eTheDiv.getElementsByTagName("select");
	for (var i = 0; i < eTheInputs.length; i++){
	  // Do all input elements.
	 
	  var strName = eTheInputs[i].name	 
	  // If disabling, disable all. If enabling, skip "others" 	
	  if ((strName.indexOf('Other') == -1) || (blnDisable))
	   eTheInputs[i].disabled = blnDisable;
	  //strAllElements += strName + '\n';
	}
	//alert('Elements: ' + strAllElements);
}
function ToggleStates(eElement){
	// Code Sample from http://forums.devshed.com/t52639/s.html
	// Retrieve the inputs.
	eTheDiv = document.getElementById("groupedTextBoxes");
	eTheInputs = eTheDiv.getElementsByTagName("input");
	
	// If the changed input has text in it, disable all other inputs,
	// otherwise if it's empty, enable all the elements.
	for (var i = 0; i < eTheInputs.length; i++)
	  // Only operate on the text boxes that are not the changed element.
	  if (eTheInputs[i] != eElement)
	    eTheInputs[i].disabled = (eElement.value ? true : false);
}

function setRejectReason(){
	if($('cboDiligenceStage').options[$('cboDiligenceStage').selectedIndex].value == 7){
	 	$('ttaRejectReason').disabled = false;
		$('ReqReason').style.visibility = '';
	}else{
		$('ttaRejectReason').disabled = true;
		$('ReqReason').style.visibility = 'hidden';
	}
	

}
function setRoleAccess(blnTypeChange, blnRoleChange){
	// 09/08/2003	mtb	Using same function for both controls but prevent
	//					duplicate checking by sending in flags
	//					If need additional reuse can look into passing just fired element
	// 09/10/2003	mtb Elminating redundancy
	
	//alert('UserType: ' + this.options[this.selectedIndex].value); 
	var blnSetupCorrespondent = false;
	if((blnTypeChange) && ($('cboUserTypes').options[$('cboUserTypes').selectedIndex].value == 2) ) {
		blnSetupCorrespondent = true;
	}else if ((blnRoleChange) && $('cboRoles').options[$('cboRoles').selectedIndex].value == 4){
		blnSetupCorrespondent = true;	
	}else {		
		
	}
	if(blnSetupCorrespondent){
		// Disable and set to correspondent
		$('cboAccess').disabled = true; 
		$('cboRoles').disabled = true; 
		$('cboUserTypes').selectedIndex = 1;	
		$('cboRoles').selectedIndex = 3;	
		$('cboAccess').selectedIndex = 0;
		// Disable can update metrics
		$('chkCanUpdMetricL1').disabled = true;
		$('txtUserName').disabled = true;		
		$('txtPassword').disabled = true;
		
		$('txtUserName').value = "blank";
		$('txtPassword').value = "password";
	}else{	
		// Enable and set to user 
		// 12/10/2007	mtb	If we always change the role type to 'USER' then we cannot select anything else
		//					just change it if we have a correspondent.
		$('cboAccess').disabled = false; 
		$('cboRoles').disabled = false; 
		$('cboUserTypes').selectedIndex = 0;	
		$('chkCanUpdMetricL1').disabled = false;
		
		$('txtUserName').disabled = false;
		$('txtPassword').disabled = false;
		
		if($('txtUserName').value == 'blank') $('txtUserName').value = '';
		
	}

}

function setGeneralReports(){
	if($('cboReports').selectedIndex <= 0) {
		alert('You must select a report.');
	}else{
		$('p').value=2; 
		document.getElementsByName("frmRunReports")[0].submit();
	}
}

function synchMetricL2Lookups(cboSelect){
	// Reset an needed controls
	$('reportCtrls').style.display = '';
	$('noProspectRpts').style.display = 'none';
	var intIndex = cboSelect.selectedIndex;	
	if(intIndex > -1) {
		$('cboIsProspect').selectedIndex = intIndex;
		var blnIsProspect = $('cboIsProspect').options[$('cboIsProspect').selectedIndex].text.toLowerCase();
		//blnIsProspect = Boolean("False");
		/*alert('intIndex  = ' + intIndex + '\n' +
			'blnIsProspect  = ' + blnIsProspect + '\n' +
			'Boolean("False")  = ' + Boolean("false") + '\n' 
		
		);*/
		if(blnIsProspect == 'true'){
			$('reportCtrls').style.display = 'none';
			$('noProspectRpts').style.display = '';
		}
	}
}
function hideTableColRow(strTableName, iCol, iRow, strCols, strRows, blnShow){
// MODIFICATION HISTORY
// 06/18/2004	mtb Adding a test for null for the row or col object
// 06/18/2004	mtb Using a lookup for the correct column to accomodate
//					colspans. This  has only been applied to individual columns
//					Also adding a show param to display column again.
// 06/13/2006	mtb Adding row correction
	var blnHideCol = false;
	var blnHideRow = false;
	var mode = '';
	//alert('hideTableColRow...');
	// Hide a give table column 
	// Generally for initial setup; however, it could be called later.
	if(strTableName == null || strTableName == '') return;
	if(iCol > '0' || strCols != '') blnHideCol = true;
	if(iRow > '0' || strRows != '') blnHideRow = true;
	
	mode = 'none';
	if(blnShow) mode = '';
	// To do all table use these (the second one would be a variable in a loop
	// Here is just the first table	
	var objTables = document.getElementsByTagName("TABLE");	
	var objTable = objTables[0];
	//alert('objTables[0].name = ' + objTables[0].name);
	
	var objTable = document.getElementById(strTableName)	
	
	/*
	if(objTable == null) {
		alert("Table object is null" + '\n' +
		' Paramters...\n' +
		'strTableName: ' + strTableName + '\n' +
		'iCol: ' + iCol + '\n' + 
		'iRow: ' + iRow + '\n' + 
		'strCols: ' + strCols + '\n' +
		'strRows: ' + strRows + '\n' +		
		'blnHideCol: ' + blnHideCol + '\n' +			
		'blnHideRow: ' + blnHideRow + '\n' +		
		'Table (' +  strTableName + ') is Null: ' + (objTable == null) + '\n'
		);
		return;
	}
	*/
	/*
	alert(' Paramters...\n' +
		'strTableName: ' + strTableName + '\n' +
		'iCol: ' + iCol + '\n' + 
		'iRow: ' + iRow + '\n' + 
		'strCols: ' + strCols + '\n' +
		'strRows: ' + strRows + '\n' +		
		'blnShow: ' + blnShow + '\n' +	
		'mode: ' + mode + '\n' +	
		'blnHideCol: ' + blnHideCol + '\n' +			
		'blnHideRow: ' + blnHideRow + '\n' +		
		'Table (' +  strTableName + ') is Null: ' + (objTable == null) + '\n' +
		'objTable.rows.length: ' + objTable.rows.length + '\n' +
		'objTable.rows.childNodes.length: ' + objTable.rows[0].childNodes.length );
		//return;
	*/
	if(blnHideCol){
		if(iCol > 0){		
			// Apply the style to the CSS display property for the cells
			for (var row = 0; row < objTable.rows.length; row++){
				//if(!(objTable.rows[row].childNodes[iCol-1] == null)) 
				//	objTable.rows[row].childNodes[iCol-1].style.display = mode;		
				var blnShowAlerts = false;
				//if(row < 3) blnShowAlerts = true;
				
				var intCurrCol = findTableCol(objTable.rows[row],iCol,blnShowAlerts);
				
				//if(row < 5) alert('intCurrCol= ' + intCurrCol);
				
				if(!(objTable.rows[row].childNodes[intCurrCol] == null)) {
					//if(row == 0) alert('iCol - 1 = ' + (iCol-1));
					objTable.rows[row].childNodes[intCurrCol].style.display = mode;			
				}	
			}
		}
		if(strCols != ''){
			var arrCols = strCols.split(',');
			for(var col = 0; col < arrCols.length; col++){
				// Apply the style to the CSS display property for the cells
				for (var row = 0; row < objTable.rows.length; row++){
					if(!(objTable.rows[row].childNodes[arrCols[col]-1] == null)) 
						objTable.rows[row].childNodes[arrCols[col]-1].style.display = mode;			
				}
			}
		}
	}
	if(blnHideRow) { 
		//alert('doing blnHideRow...');
		if(iRow > 0){		
			//alert('show/hide row(' + iRow + ')');
			// Apply the style to the CSS display property for the cells
			//alert('length=' + objTable.rows[iRow-1].childNodes.length);
			for (var col = 0; col < objTable.rows[iRow-1].childNodes.length; col++){ //objTable.Columns.length; col++){				
				if(!(objTable.rows[iRow-1].childNodes[col] == null)) {
					//alert('setting row(' + iRow-1 + ')  col (' + col + ') to display mode of (' + mode + ')');
					objTable.rows[iRow-1].childNodes[col].style.display = mode;								
				}
			}
		}
		if(strRows != ''){
			//alert('strRows != \'\'...');
			var arrRows = strRows.split(',');
			//alert('arrRows[0] = ' + arrRows[0]);
			//return;
			for(var row = 0; row < arrRows.length; row++){
				// Apply the style to the CSS display property for the cells
				for (var col = 0; col < objTable.rows[row].childNodes.length; col++){ //objTable.Columns.length; col++){
					if(!(objTable.rows[arrRows[row]-1].childNodes[col] == null)) 
						objTable.rows[arrRows[row]-1].childNodes[col].style.display = mode;			
				}
				//alert('objTable.rows[row].childNodes.length = ' + objTable.rows[row].childNodes.length);
			}
		}
	}
	
	//alert('show/hide complete...');
}
var g_intCalls = 0;
function hideTableColRowWithChg(strTableName, iCol, iRow, strCols, strRows, blnShow, objLink){
// MODIFICATION HISTORY
// 06/13/2006 mtb	Same as above exit it switches the link to back and forth
//					from hide to show
	if(g_intCalls == 0){
		g_intCalls += 1
		hideTableColRow(strTableName, iCol, iRow, strCols, strRows, blnShow);
	
		alert('blnShow is ' + blnShow + ' and the opposite of blnShow is ' + (!(blnShow)));
		this.onClick = hideTableColRowWithChg(strTableName, iCol, iRow, strCols, strRows, (!(blnShow)), this);
	}
	g_intCalls = 0;
	return
}
function addWaterfallRows(){
	if($('WaterfallCnt').value <=5)
		hideTableColRow('tblWaterfall', 0, 0, '',$('WaterfallCnt').value ,true);
	else
		alert('You can add up to 4 Waterfall entries.\nPlease contact your administrator if additional entries are needed.');
	$('WaterfallCnt').value = eval($('WaterfallCnt').value) + 1;	
}

function validateReqCap(ctrlChg,sFldText,sCtrlType,ctrlMin,ctrlMax,ctrlVal,blnShowMsg){
/*

MODIFICATION HISTORY:
08/08/2008	mtb	This should not produce an error if the value is zero (default)
*/
	var iMin = eval(ctrlMin.options[ctrlMin.selectedIndex].text);
	var iMax = eval(ctrlMax.options[ctrlMax.selectedIndex].text);
	var iVal = eval(ctrlVal.value);	
	
	var bWithinRng = false;
	if(blnShowMsg == null) blnShowMsg = true;
	if(iVal == 0) return true;
	
	/*alert('Ctrl Type = ' + sCtrlType + '\n' +
		'Min = ' + iMin + '\n' +
		'Max = ' + iMax + '\n' +
		'Value = ' + iVal );*/
		
	// First verify if the value is within the selected range
	if(iVal >= iMin){
		if(iMax == -1)
			bWithinRng = true;
		else if(iVal <= iMax)
			bWithinRng = true;
	}
	// If Not...
	if(!(bWithinRng)){			
		// If someone has modified the text (reqcapval), then update the range to reflect the change
		// If someone has changed the range and the value is out of range, simply inform the user of the discrepancy
		// Rather than fixing anything for them, just inform for any discrepancy.
		if(blnShowMsg) alert('The range selected for (' + sFldText + ') is inconsistent with the entered value.');
		
	}
	return bWithinRng;
}
function synchReqCap(ctrl,cboReqCap12MosMin,cboReqCap12MosMax){
	var intReqCapIndex = ctrl.selectedIndex;
	cboReqCap12MosMin.selectedIndex = 
		cboReqCap12MosMax.selectedIndex =
						intReqCapIndex;	
}

function getText(n)
{
  if('textContent' in n) {
    return n.textContent;
  } else if('innerText' in n) {
    return n.innerText;
  } else {
    // Call a custom collecting function, throw an error, something like that.
  }
  return "";
}
function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
  	var blnShowAlerts = false;
    var curtop = 0;
	try{
	    if(obj.offsetParent){
	        while(1)
	        {		
	          curtop += obj.offsetTop;
			  if(blnShowAlerts) alert('(FindPosY) curtop = ' + curtop);
	          if(!obj.offsetParent)
	            break;
	          obj = obj.offsetParent;
	        }
	    }else if(obj.y){
			if(blnShowAlerts) alert ('(FindPosY) no offsetParent');
	        curtop += obj.y;
		}else{
			if(blnShowAlerts) alert('(FindPosY) return default of zero');
			if(blnShowAlerts) alert('(FindPosY) obj.offsetTop = ' + obj.offsetTop);
			if(obj.offsetTop) curtop = obj.offsetTop;
			
		}
	}catch(ex){
		if(blnShowAlerts) alert('(FindPosY) errored');
	}
    return curtop;
  }

//-->


