function func_JS_Resize_iFrame_ToFitContents(iFrameID,iPercent,iParent_YN){
	//dynamically resizes iFrame height based on content
	//iFrameID is the ID tag for the iFrame and it must be unique to the page
	//iPercent is the relative size you want to make the frame (e.g., 1.2 = 120%, 1 = 100%)
	//iParent_YN is used to indicate if the iFrame is located in a parent document (1 = Yes = Parent document)
	//EXAMPLE: 
	//sFrame = sFrame + '<iframe id="'+ iFrameName +'" name="'+ iFrameName +'" src="' + sUrl + '"  width="100%" height="0" frameborder="0" dir="ltr" wrap="soft" class="clsShow" APPLICATION="yes" onLoad="func_JS_Resize_iFrame_ToFitContents(this.id,1.2,0);" ></iframe>'
	
	
	//alert("running...func_JS_Resize_iFrame_ToFitContents: iFrameID = " + iFrameID + ": iPercent = " + iPercent +": iParent_YN = " + iParent_YN)
	 
	
	if (iParent_YN==1){
		//alert("Great!")
		var iFrame_Height = parent.document.getElementById(iFrameID).contentWindow.document.body.scrollHeight;
		iFrame_Height = eval(iFrame_Height * iPercent); //add some percent e.g., 40% = 1.4
		iFrame_Height = Math.round(iFrame_Height)
		parent.document.getElementById(iFrameID).style.height = iFrame_Height + "px";
	} else {
		var iFrame_Height = document.getElementById(iFrameID).contentWindow.document.body.scrollHeight;
		
		
		
		iFrame_Height = eval(iFrame_Height * iPercent); //add some percent e.g., 40% = 1.4
		iFrame_Height = Math.round(iFrame_Height)
		document.getElementById(iFrameID).style.height = iFrame_Height + "px";
	}
	return true;
}
function func_JS_ResizeWindow(iSize){
	if(iSize==1){
		//small
		window.resizeTo(window.screen.availWidth/2, window.screen.availHeight/3);
	} else if (iSize==2){
		//Medium
		window.resizeTo(window.screen.availWidth/1, window.screen.availHeight/3)
	} else {
		//large
		window.resizeTo(window.screen.availWidth/1, window.screen.availHeight/2);
	}
} 
function func_JS_Update_iSort(sTable,sGroupingField,iGroupingValue,s_iIDField,iSort_Old,iSort_New,sWhere){
	//user wants to update iSort value (to change sorting of list)
	//alert("running...func_JS_Update_iSort")
	//sTable = table name (e.g., tblINCIDENT_STRATEGY)
	//sGroupingField = field/variable name used in WHERE clause (e.g., iIncidentID)
	//iGroupingValue = integer value only, associated with sGroupingField (e.g., iIncidentID)
	//s_iIDField = field/variable name (with datatype = int) used in SELECT statement to create iID  (e.g., iIncidentStrategyID) 
	//iSort_Old = the existing iSort value for s_iIDField (with datatype = int)
	//iSort_New = the new iSort value for s_iIDField (with datatype = int)
	//sWhere = if not "", use this in WHERE clause need to remove underscore(e.g., "iStatusID_<_4")
	//alert(sTable + "\n\n- " + sGroupingField + "\n\n- " + iGroupingValue + "\n\n- " + s_iIDField + "\n\n- " + iSort_Old + "\n\n- " + iSort_New + "\n\n- " + sWhere)
	//sUrl = "/Member/Includes/iSort/?sTable=tblINCIDENT_STRATEGY&sGroupingField=iIncidentID&iGroupingValue=16&s_iIDField=iIncidentStrategyID&iSort_Old=3&iSort_New=2"	
	//Call GetXmlHttpObject found in 'AjaxFunctions_Common.js
	var oXmlHttp_Strategies = GetXmlHttpObject();
	if (oXmlHttp_Strategies == null){
		  alert ("Your browser does not support AJAX!");
		  return;
		}
	var sUrl_Temp = "/Member/Includes/iSort/default.asp";
	sUrl_Temp += "?sTable=" + sTable ;
	sUrl_Temp += "&sGroupingField=" + sGroupingField ;
	sUrl_Temp += "&iGroupingValue=" + iGroupingValue ;
	sUrl_Temp += "&s_iIDField=" + s_iIDField ;
	sUrl_Temp += "&iSort_Old=" + iSort_Old ;
	sUrl_Temp += "&iSort_New=" + iSort_New ;
	sUrl_Temp += "&sWhere=" + sWhere ;
	sUrl_Temp += "&sid=" + Math.random();
	oXmlHttp_Strategies.onreadystatechange = function() {
			// state ==4 indicates receiving response data from server is completed
			if(oXmlHttp_Strategies.readyState == 4){
					// To make sure valid response is received from the server, 200 means response received is OK
					if(oXmlHttp_Strategies.status == 200){	
						//alert(oXmlHttp_Strategies.responseText);
						}
					else
						{
							alert("Problem retrieving data from the server, status code: " + oXmlHttp_Strategies.status);
						}
				}
		}
	oXmlHttp_Strategies.open("GET", sUrl_Temp, true);
	oXmlHttp_Strategies.send(null);
	return true;
}
function openWin(page, windowName, windowFeatures) {
	//opens new window to show CalendarPopup.asp
	alert("checking to see if openWin function is still used...")
	
	return window.open(page, "", windowFeatures);
}

function textCounter( field, countfield, maxlimit ) {
  if ( field.value.length > maxlimit )
  {
    field.value = field.value.substring( 0, maxlimit );
    alert( 'Textarea value can only be ' + maxlimit + ' characters in length.' );
    return false;
  }
  else
  {
    countfield.value = maxlimit - field.value.length;
  }
}


function confirmPriority(obj){
	//user wants to set the request priority to high or low
	var objValue = obj.value
	if (objValue==1){
		alert("***It is unusual to set the priority to 'Low'.***\n\nPlease write a comment to justify this priority and let NCRLAP staff know what to do differently to accommodate this priority level. Otherwise, please reset this priority to 'Typical'.")	
	} else if (objValue==3){
		alert("***It is unusual to set the priority to 'High'.***\n\nPlease write a comment to justify this priority and let NCRLAP staff know what to do differently to accommodate this priority level. Otherwise, please reset this priority to 'Typical'.")		
	} else {
		//alert("Priority is typical")		
	}
	return true;
}

function lookUp_sEmail(){
	//user wants to look up sEmail in db
	var sValue = document.form1.sEmail.value
	var sTemp = document.form1.iUniqueID.value
	var sURL = "/Resources/Pages/Lookup.asp?sEmail=" + sValue + "&iUniqueID=" + sTemp
	//run function to view
	popupWin(sURL);
	return true;
}

function func_JS_ToggleStyleDisplay(sElementID){
	//alert("sElementID = " + sElementID)
	//toggle view
	var eSpan = document.getElementById(sElementID);
	//alert("eSpan.className = " + eSpan.className)
	if (eSpan.style.display == "block"){
		eSpan.style.display = "none"
	} else {
		eSpan.style.display = "block"
	}   
	return true;
}

function func_JS_display_none(sElementID){
	//alert("sElementID = " + sElementID)
	//hide
	var eSpan = document.getElementById(sElementID);
	eSpan.style.display = "none"
	return true;
}
function func_JS_display_parent_none(sElementID){
	//alert("sElementID = " + sElementID)
	//hide
	var eSpan = parent.document.getElementById(sElementID);
	eSpan.style.display = "none"
	return true;
}
function func_JS_display_parent_block(sElementID){
	//alert("sElementID = " + sElementID)
	//hide
	var eSpan = parent.document.getElementById(sElementID);
	eSpan.style.display = "block"
	return true;
}
function func_JS_display_block(sElementID){
	//alert("sElementID = " + sElementID)
	//hide
	var eSpan = document.getElementById(sElementID);
	eSpan.style.display = "block"
	return true;
}
function func_JS_display_inline(sElementID){
	//alert("sElementID = " + sElementID)
	//hide
	var eSpan = document.getElementById(sElementID);
	eSpan.style.display = "inline"
	return true;
}
function func_JS_display_parent_inline(sElementID){
	alert("sElementID = " + sElementID)
	//hide
	var eSpan = parent.document.getElementById(sElementID);
	eSpan.style.display = "inline"
	return true;
}
function func_isControlVisible(str){
    var id = str;
    var eSpan = document.getElementById(id);
    
	if (eSpan.className== "clsHide"){
		return false;
	} else {
        return true;
	}   
}
function toggleDetails(str){
	//alert("str = " + str)
	var id = str;
	//toggle view
	var eSpan = document.getElementById(id);
	//alert("eSpan.className = " + eSpan.className)
	if (eSpan.className== "clsShow"){
		eSpan.className = "clsHide";
	} else {
		eSpan.className = "clsShow";
	}   
	
	return true;
}
function toggleDetails_YN(sObjectID,iYesNoInteger_10){
	//e.g., return toggleDetails_YN('rowConfirmationMemo_FAC','1')
	//this toggles the object based on state of iYesNoInteger_10
	var sID = sObjectID 
	var eSpan = document.getElementById(sID);
	var iYN = iYesNoInteger_10
	
	if (iYN==1){
		//yes, show
		if (eSpan.className== "clsHide"){
			eSpan.className = "clsShow"
		} else {
			eSpan.className = "clsShow"
		} 
	} else {
		//no, hide
		if (eSpan.className== "clsShow"){
			eSpan.className = "clsHide"
		} else {
			eSpan.className = "clsHide"
		} 
	}
return true;
}

function Dictionary_Help(sPageName,sKeyWord){
	//opens help page (dynamic for each page)
	alert("This function is to be replaced by popupWin")
		var urlstr;
		urlstr = "/Resources/Pages/Help.asp?sPageName="+sPageName+"&sKeyWord="+sKeyWord+""
		newwindow=window.open(urlstr, 'Help', 'height=700,width=650,left=50,top=100,directories=no,resizable=yes,scrollbars=yes,toolbar=no,status=no,toolbar=no');
		if (window.focus) {newwindow.focus()}
		return;
	}

function checkform(frmObj,alertMsg){
	//confirms that the user has entered values in the fields zzz
	x=0;
	while (x<frmObj.elements.length){
		 if(frmObj.elements[x].value==""){
			alert(alertMsg);
			frmObj.elements[x].focus();
					return false;
		 }
		 x++;
	}
	return true;
}

function Trim(obj){
	//removes blank spaces from beginning and end of string
	
	var objValue = obj.value
	
	if(objValue.length < 1){
	return "";
	}
	objValue = RTrim(objValue);
	objValue = LTrim(objValue);
	if(objValue==""){
	obj.value = objValue
	return objValue;
	}
	else{
	obj.value = objValue
	return objValue;
	}
} //End Function
function RTrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0){
	return"";
	}
	var iTemp = v_length -1;
	
	while(iTemp > -1){
	if(VALUE.charAt(iTemp) == w_space){
	}
	else{
	strTemp = VALUE.substring(0,iTemp +1);
	break;
	}
	iTemp = iTemp-1;
	
	} //End While
	return strTemp;
} //End Function

function LTrim(VALUE){
	var w_space = String.fromCharCode(32);
	if(v_length < 1){
	return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";
	
	var iTemp = 0;
	
	while(iTemp < v_length){
	if(VALUE.charAt(iTemp) == w_space){
	}
	else{
	strTemp = VALUE.substring(iTemp,v_length);
	break;
	}
	iTemp = iTemp + 1;
	} //End While
	return strTemp;
} //End Function



var newwindow = '';

function popupWin(url) {
	//opens a new window
	//alert("running...popupWin\n\n" + url)
	if (!newwindow.closed && newwindow.location) {
		newwindow.location.href = url;
	}
	else {
		newwindow=window.open(url,'name','height=500,width=600,left=50,top=100,directories=no,location=No,menubar=No,resizable=yes,scrollbars=yes,status=No,toolbar=No');
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
	return false;
}

function popupWin_iHeight_iWidth(url,iHeight,iWidth) {
	//opens a new window
	//alert("running...popupWin_iHeight_iWidth\n\n" + url + ", iHeight = " + iHeight + ", iWidth = " + iWidth)
	if (!newwindow.closed && newwindow.location) {
		newwindow.location.href = url;
	}
	else {
		newwindow=window.open(url,'name','height=' + iHeight + ',width=' + iWidth +',left=50,top=100,directories=no,location=No,menubar=No,resizable=yes,scrollbars=yes,status=No,toolbar=No');
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
	return false;
}

function popupWin_ForResources(url) {
	//alert("running...popupWin\n\n" + url)
	
//	if (!newwindow.closed && newwindow.location) {
//		newwindow.location.href = url;
//	}
//	else {
		newwindow=window.open(url,'name','height=500,width=600,left=50,top=100,directories=yes,location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes');
//		if (!newwindow.opener) newwindow.opener = self;
//	}
//	if (window.focus) {newwindow.focus()}
//	return false;
}

function popupWin_ForDateCalendar(url) {
	//alert("running...popupWin_ForDateCalendar\n\n" + url)
	if (!name.closed && name.location) {
		name.location.href = url;
	}
	else {
		newwindow=window.open(url,'name','width=300,height=200,toolbar=no,directories=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes,dependent=yes');
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
	return false;
}



//mainNavigation
//Bug fix in IE Mac
function addRolloverAction(tempElement){
		navRoot = document.getElementById(tempElement);
		if(navRoot!=null){
			for (i=0; i<navRoot.childNodes.length; i++) {
				node = navRoot.childNodes[i];
				if (node.nodeName=="LI") {
					node.onmouseover=function() {
						this.className+=" over";	
						if(document.getElementById("form3")!=null)
						document.getElementById("form3").className="clsHide2";
					}
					node.onmouseout=function() {
						this.className=this.className.replace(" over", "");
						//document.getElementsByTagName("FORM")[1].className.replace(" clsHide2", " clsShow2");
						if(document.getElementById("form3")!=null)
							document.getElementById("form3").className=" clsShow2";
					}
				}
			}
		}
	  return true;
	}

startList = function() {
	if (document.all&&document.getElementById) {
		addRolloverAction("mainNav");
		addRolloverAction("local_navtext");
	}
}

function submitenter(myfield,e) {
	//This script lets user hit enter key to submit search request
	var keycode;
	var str;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13){
	   //alert("You hit the enter key");
	   IsEmpty();
	   return false;
	   }
	else
	   return true;
}

function IsEmpty(objName){
	//check to see sSearch is empty prior to submission of search request
	var sForm = objName
	var strValue = ""

	if (sForm=="form2"){
		//form2 (found on Fac_Overview page)
		strValue = document.form2.sSearch.value;

		if (strValue=="") {//return if there is nothing in field
			alert("Please enter something in the search field.");
			document.form2.sSearch.focus();
			return false;
		}
		return true;
	} else {
		//frmSearch
		strValue = document.frmSearch.sSearch.value;
		if (strValue=="") {//return if there is nothing in field
			alert("Please enter something in the search field.");
			document.frmSearch.sSearch.focus();
			return false;
		}
	}
	return true;
}
function alert_LeavingPage_ForOldWebsite(){
	var agree = confirm("You are about to open a new window to view information from the old website. \n\nIf you are not currently logged into the old website, you will see a session error message at the top of the page. If you see this message, it is okay to view information but please do not change any data without first logging into the old website. \n\nIf you see another error (e.g., 'Either BOF or EOF is True, or the current record has been deleted...' ) on the page, it is likely that the facility ID was not found on the old website.\n\nClick 'OK' to proceed.")
	if (agree) {
		return true;
	} else {
		return false;
	}
}

function alert_LeavingPage(){
	var agree = confirm("You are about to leave this page without submitting the form. Any changes you made will be lost. \n\nDo you want to proceed?")
	if (agree) {
		return true;
	} else {
		return false;
	}
}

function checkPositiveInteger(obj){
	if(!isInteger(obj.value)){
		alert("The value entered is not a valid number.\n\nPlease enter a valid number or zero (0).");
		obj.value = 0;
		obj.select();
		return false;
	}
	return true;
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

// returns true if the string is a valid email
function isEmail(str)
    {
        if (str.length == 0) return false;
        var re = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i
        return re.test(str);
    }

// returns true if the string is a valid ZIP code
function isZip(str)
    {
        if (str.length == 0) return false;
        var re = /(^\d{5}$)|(^\d{5}-\d{4}$)/
        return re.test(str);
    }

// returns true if the string is a US phone number formatted as...
// (000)000-0000, (000) 000-0000, 000-000-0000, 000.000.0000, 000 000 0000, 0000000000
function isPhoneNumber(str)
    {
        if (str.length == 0) return false;
        var re = /^\(?[2-9]\d{2}[\)\.-]?\s?\d{3}[\s\.-]?\d{4}$/
        return re.test(str);
    }

// returns the value of a parameter in the URL
function func_GetURLParam( name )
    {
        name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
        var regexS = "[\\?&]"+name+"=([^&#]*)";
        var regex = new RegExp( regexS );
        var results = regex.exec( window.location.href );
        if( results == null )
            return "";
        else
            return results[1];
    }

// this will iterate through an array of errors and display an alert box.
//     var errors = [];
//     add to array with: errors[errors.length] = 'This error message.';
//     if (errors.length > 0)
//         {
//             reportErrors(errors);
//             return false;
//         }
function reportErrors(errors)
    {
        var msg;
            
        if (errors.length == 1)
            {
                msg = "There was problem...\n";
                msg += "\n    " + errors[0];
            }
        else
            {
                msg = "There were some problems...\n";
        
                for (var i = 0; i < errors.length; i++)
                    {
                        var numError = i + 1;
                        msg += "\n   " + numError + ". " + errors[i];
                    }
            }
        alert(msg);
    }

// Takes a valid telephone number format and forces it to (999) 999-9999
function func_CleanValidPhone(sPhoneNumber)
    {
        sPhoneNumber = sPhoneNumber.replace(/\./g, "");
        sPhoneNumber = sPhoneNumber.replace(/\(/g, "");
        sPhoneNumber = sPhoneNumber.replace(/\)/g, "");
        sPhoneNumber = sPhoneNumber.replace(/-/g, "");
        sPhoneNumber = sPhoneNumber.replace(/ /g, "");
        sPhoneNumber = "(" + sPhoneNumber.substring(0, 3) + ") " + sPhoneNumber.substring(3, 6) + "-" + sPhoneNumber.substring(6, 10);
        return sPhoneNumber;
    }


window.onload=startList;