function func_JS_Check_UncheckAll(sCheckStatus_True_False, sElementName){
	//checks or unchecks element
	//sCheckStatus_True_False = true (or false)
	//example: 
	//	 'buttons: check / uncheck
	//	response.Write("<div class='pad1'>")
	//	response.Write("<input type='button' value='Check all' onclick='func_JS_Check_UncheckAll(true, ""iAsmtTypeID"");' class='font9 bgPink'  >")
	//	response.Write("&nbsp;&nbsp;&nbsp;")
	//	response.Write("<input type='button' value='Uncheck all' onclick='func_JS_Check_UncheckAll(false, ""iAsmtTypeID"");' class='font9 bgPink' >")
	//	response.Write("</div>")
	
	if (document.getElementsByName(sElementName)){
		for (i = 0; i < document.getElementsByName(sElementName).length; i++) {
			document.getElementsByName(sElementName)[i].checked = sCheckStatus_True_False;
		}
	}
    return true; 
}

function func_JS_OnLoad_Header_Image(sSource,iWidth,iHeight,sPageName){
	/* loads header image in top left corner
	sSource = image source (e.g., "/Images/Calendar.gif")
	iWidth= image width --recommend 67
	iHeight = image height -- recommend 73
	sPageName = text to show next to the image (e.g., "staff details")
	
	Example:    func_JS_OnLoad_Header_Image("/Images/Calendar.gif",67,73,"Calendar details")
	*/
	if (document.getElementById('div_Header_Image')){
		sTemp = "<div id='div_Header_Image_Replacement' style='vertical-align:middle; width:50%;height:57px;' onmouseOver='func_JS_MouseOver_Header();' onmouseOut='func_JS_MouseOut_Header();'>"
		if (sSource.length==0){
			sTemp = sTemp + "<div id='div_PageTitle' style='margin: 1%; padding: 1%; float:left; display: table-cell; vertical-align: 50%; height:57px; font-size:1.2em; color:black; font-weight: bold;' title='" + sPageName + "'>"
			sTemp = sTemp + "" + sPageName
			sTemp = sTemp + "</div>"
		} else {
		
		sTemp = sTemp + "<img id='img_Header_Image' src='" + sSource + "' width='" + iWidth + "' height='" + iHeight + "' title='Go to home page'  style='float:left'/>"
		sTemp = sTemp + "<div id='div_PageTitle' style='margin-left: 1%; padding-left: 1%; float:left; display: table-cell; vertical-align: 50%; height:57px; font-size:1.2em; color:black; font-weight: bold;'>"
		sTemp = sTemp + "<br>" + sPageName
		sTemp = sTemp + "</div>"
		
		}
		sTemp = sTemp + "</div>"
		document.getElementById('div_Header_Image').innerHTML=sTemp
	}
}
function func_JS_AddItemInList(sElementID,sLabel,iValue){
	//adds a new list item to ddl
	//sElementID = the id for the ddl
	//sLabel = the text to use for in the ddl
	//iValue = the value of the list item (NOTE: this could be a string too!)
	var sElement =  document.getElementById(sElementID);
	var oOption = document.createElement('OPTION');
	oOption.text = sLabel;
	oOption.value = iValue;
	sElement.add(oOption);
	//set focus
	for (var i=0; i < document.getElementById(sElementID).length; i++){
		if (document.getElementById(sElementID)[i].value == iValue){
			document.getElementById(sElementID)[i].selected = true;
		}
	}
	return true;
}
function func_JS_RemoveItemInList(sElementID_x,iValue_x){
	//removes the List Item with iValue from the sElementID (ddl) control
	var sElement  = document.getElementById(sElementID_x);
	var iLength = document.getElementById(sElementID_x).length
	for (var x=0; x < iLength ; x++){
		if (parseInt(document.getElementById(sElementID_x)[x].value) == parseInt(iValue_x)){
			//alert("about to remove..." + document.getElementById(sElementID)[x].value)
			sElement.remove(x);
		} 
	}
	return true;
}
function func_JS_CheckPositiveInteger_Min_Max(sElementID,iMin,iMax){
	var iValue = document.getElementById(sElementID).value
	if(!isInteger(iValue)){
		alert("The value entered is not a valid number.\n\nPlease enter a valid number or zero (0).");
		document.getElementById(sElementID).value = 0;
		document.getElementById(sElementID).focus();
		document.getElementById(sElementID).select();
		return false;
	}
	if ((iValue < iMin)||(iValue > iMax)){
		var agree = confirm("Click 'OK' to confirm that you want to enter a value, '" + iValue + "', that is outside the typical range (" + iMin + " to " + iMax + ").")
		if (agree){
			return true;	
		} else {
			return false;	
		}
	}
	return true;
}

function func_JS_Map_City_sElementName(sElementID){
	//user wants to view google map but only has city name
	if (document.getElementById(sElementID)){
		var sCity = document.getElementById(sElementID).value
		var sURL = "http://maps.google.com/maps?saddr=" + sCity + "%2C+NC+&hl=en"
		//open window
		newwindow=window.open(sURL,'name','height=500,width=600,left=50,top=100,directories=no,location=No,menubar=No,resizable=yes,scrollbars=yes,status=No,toolbar=No');
		if (window.focus) {newwindow.focus()}
		
		
	} else {
		//element not found	
	}
	
	return false; 
}
function func_JS_GoToURL(sURL){
	//
	document.location.href=sURL
	return true;
}
function func_JS_Toggle_File_List(){
	//toggles VFC files list
	if (document.getElementById("div_VFC_Edit")){
		var sElement = document.getElementById("div_VFC_Edit")
		if (sElement.style.display=="none"){
			//show list
			sElement.style.display="block";
			sElement.style.backgroundColor="#FFFFCC"
			//Change a_VFC_Link
			if (document.getElementById("a_VFC_Link")){
				document.getElementById("a_VFC_Link").innerHTML = "Hide files"
			}
		} else {
			//hide list 	
			sElement.style.display="none"
			sElement.style.backgroundColor="#FFFFCC"
			//Change a_VFC_Link
			if (document.getElementById("a_VFC_Link")){
				document.getElementById("a_VFC_Link").innerHTML = "Show files"
			}
		}
	}
	return false;
}
function func_JS_Comment_Edit_By_sType(iCommunicationID,sType,iValue,iAction){
	//this needs to be in root file 
	//sType = "sFacID", "iRequestID" , "iAsmtID"
	//iValue = 99999, 12345, 8274
	//iAction = 1 indicates a popup window is being used
	//creates iFrame to show facilty comments for selected sFacID
	var iRandomNumber = Math.floor(Math.random()*99) //generates a random number to fall between 0 and 99.
//	document.getElementById('div_Reload').style.display = 'inline';
	document.getElementById('div_Communication_Info').style.display = 'none';
	document.getElementById('div_Communication_Edit').style.display = 'inline';
	//create iFrame
	var iFrameName = 'iFrame_Comment_'+ iCommunicationID
	//build querystring
	var sURL = ""
	if (sType=="sFacID"){
	 	sURL = "/Member/Communication/Fac/Edit/default.asp";
		sURL += "?sFacID=" + iValue ;
	} else if (sType=="iRequestID"){
		sURL = "/Member/Communication/Wave/Edit/default.asp";
		sURL += "?iRequestID=" + iValue 
	} else if (sType=="iAsmtID"){
		sURL = "/Member/Communication/Asmt/Edit/default.asp";
		sURL += "?iAsmtID=" + iValue ;
	} else {
		alert("func_JS_List_Comments_By_sType\n\nunder construction...")	
	}
	sURL += "&iCommunicationID=" + iCommunicationID; 
	sURL += "&iAction=0"; //iAction = 1 indicates that a popup window is being used
	sURL += "&sid=" + Math.random();
	var sFrame = '<iframe id="'+ iFrameName +'" name="'+ iFrameName +'" src="' + sURL + '" height="0" frameborder="0"  style="background-color:#FFFFFF; width:100%;" dir="ltr" wrap="soft" class="clsShow" APPLICATION="yes"  onLoad="func_JS_Resize_iFrame_ToFitContents(this.id,1.2,0);"  ></iframe>';
	//insert iFrame into container
	document.getElementById('div_Communication_Edit').innerHTML = sFrame;
	return true;
}
function func_JS_List_Comments_By_sType(sType,iValue){
	//Inserts comments list
	//sType = sFacID, iRequestID, iAsmtID
	//iValue = 99999, 12345, 88888
	if (document.getElementById("div_Communication_Edit").style.display == "block"){
		document.getElementById("div_Communication_Edit").style.display = "none"
		document.getElementById("a_sLink").innerHTML = "Show comments"
	} else {
		document.getElementById("a_sLink").innerHTML = "Hide comments"
		//document.getElementById("div_Communication_Info").style.display = "none";
		//call AJAX function to show information
		//Call GetXmlHttpObject found in 'AjaxFunctions_Common.js
		var oXmlHttp_Communication_Edit = GetXmlHttpObject();
		if (sType=="sFacID"){
			var sURL = "/Member/Communication/Fac/List/default.asp";
			sURL += "?sFacID=" + iValue ;
			
		} else if (sType=="iRequestID"){
			var sURL = "/Member/Communication/Wave/List/default.asp";
			sURL += "?iRequestID=" + iValue 
		} else if (sType=="iAsmtID"){
			var sURL = "/Member/Communication/Asmt/List/default.asp";
			sURL += "?iAsmtID=" + iValue ;
		} else {
			alert("func_JS_List_Comments_By_sType\n\nunder construction...")	
		}
		
		sURL += "&iAction=0"; //iAction = 1 indicates that a popup window is being used
		sURL += "&sid=" + Math.random();
		oXmlHttp_Communication_Edit.onreadystatechange = function() {
			// state ==4 indicates receiving response data from server is completed
			if(oXmlHttp_Communication_Edit.readyState == 4){
					// To make sure valid response is received from the server, 200 means response received is OK
					if(oXmlHttp_Communication_Edit.status == 200){	
						//Hide
						//document.getElementById("div_Communication_Edit").style.display = "none";
						//show
						document.getElementById("div_Communication_Edit").style.display = "block";
						document.getElementById("div_Communication_Edit").style.padding = "2%";
						document.getElementById("div_Communication_Edit").innerHTML = oXmlHttp_Communication_Edit.responseText ;
					} else {
							alert("Problem retrieving data from the server, status code: " + oXmlHttp_Communication_Edit.status);
					}
			}
		}
		oXmlHttp_Communication_Edit.open("GET", sURL, true);
		oXmlHttp_Communication_Edit.send(null);
	}
	return true;
}

function func_JS_Show_Map(sAddress,sCity,sState,sZip){
	//user wants to view google map
	var sClean_sAddress = sAddress
	sClean_sAddress = sClean_sAddress.replace(" ","+");
	var sClean_sCity = sCity
	sClean_sCity = sClean_sCity.replace(" ","+");
	var sClean_sState = sState
	sClean_sState = sClean_sState.replace(" ","+");
	var sClean_sZip = sZip
	sClean_sZip = sClean_sZip.replace(" ","+");
	//Example: http://maps.google.com/maps?saddr=5825+Phyllis+Lane%2C+Mint+Hill%2C+NC+28227&hl=en
	var sURL = "http://maps.google.com/maps?saddr=" + sClean_sAddress + "%2C+" + sClean_sCity + "%2C+" + sClean_sState + "+" + sClean_sZip + "&hl=en"
	//open window
	if (!newwindow.closed && newwindow.location) {
		newwindow.location.href = sURL;
	} else {
		newwindow=window.open(sURL,'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 true; 
}



function func_JS_Map_ByAddress(sAddress,sCity,sState,sZip){
	//user clicked map button
	if(sAddress==""){
		var sURL = "http://maps.google.com/maps?q=greensboro,NC"
	} else {
		var sURL = "http://maps.google.com/maps?q="+ sAddress + "," + sCity + "," + sState + "," + sZip
	}
	var temp = popupWin_iHeight_iWidth(sURL,500,750)
	return true;
}
function func_JS_Toggle_sElement_sLink_sElementID(sElementID,sLink_sElementID,sText_Show,sText_Hide){
	//toggle view
	//alert("test")
	var sElementID = document.getElementById(sElementID)
	var sLink_sElementID = document.getElementById(sLink_sElementID)
	var sText_Show = sText_Show
	var sText_Hide = sText_Hide
	if ((sElementID)&&(sLink_sElementID)){
		if (sElementID.style.display=='none'){
			//show sElementID
			sElementID.style.display='inline';
			//change sLink_sElementID
			sLink_sElementID.innerHTML=sText_Hide
		} else {
			//show sElementID
			sElementID.style.display='none';
			//change sLink_sElementID
			sLink_sElementID.innerHTML=sText_Show
		}
		
	}
	return true;
}

function func_JS_MouseOver_Header(){
	//user moused over the header image
	if (document.getElementById('img_Event')){
		document.getElementById('img_Event').src = "/Member/Images/NCRLAP_MapLogo_small_Staff.gif"
		document.getElementById('img_Event').style.height='57px'
		document.getElementById('img_Event').style.width='150px'
		document.getElementById('div_PageTitle').style.display = 'none';
	}
} 
function func_JS_MouseOut_Header(){
	//user moused OUT from the header image
	if (document.getElementById('img_Event')){
		document.getElementById('img_Event').src = "/Images/Event_Calendar.gif"
		document.getElementById('img_Event').style.height='57px'
		document.getElementById('img_Event').style.width='66px'
		document.getElementById('div_PageTitle').style.display = 'inline';
	}
}
function func_JS_Change_Parent_URL(sURL){
	//called by child iFrame to change parent href
	//alert("func_JS_Change_Parent_URL...")
	document.location = sURL
}

function func_JS_ShowHide_Processing_Image(){
	//shows or hides a processing message while page loads
	//alert("running...func_JS_ShowHide_Processing_Image")
	if (document.getElementById('img_Wait')){
		//image found
		//hide image
		document.getElementById('img_Wait').style.display = "none";
		//return body background color to original color (white)
		document.body.style.backgroundColor = "#FFFFFF"
		//show container div
		document.getElementById('container').style.display = "block";
	} else {
		//no image found
		//create image
		var oImageElement = document.createElement("IMG");
		oImageElement.src = "/Images/wait.gif";
		oImageElement.style.position = "absolute"
		oImageElement.style.zIndex = "5"
		oImageElement.style.top = "30%"
		oImageElement.style.left = "35%"
		oImageElement.id = "img_Wait"
		//append image to body
		document.body.appendChild(oImageElement)
		//change body background color (CCFFFF = light blue)
		document.body.style.backgroundColor = "#FFFFFF"
		//hide container div
		document.getElementById('container').style.display = "none";
	}
	return true;
}

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!")
		if (document.getElementById(iFrameID)){
			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 {
		if (document.getElementById(iFrameID)){
			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_ResizeWindowToFitContents(sElementID){
	//resizes window to fit contents
	//e.g., used for help screens
	//alert("running...func_JS_ResizeWindowToFitContents")
	//get element
	var oElement = document.getElementById(sElementID)
	if (oElement == false){
		return false;	
	}
	var iHeight = document.getElementById(sElementID).scrollHeight //Returns the entire height of an element (including areas hidden with scrollbars) 
	var iWidth = document.getElementById(sElementID).scrollWidth //Returns the entire width of an element (including areas hidden with scrollbars)
	var iPercent_Height = 1.5
	var iPercent_Width = 1.3
	//alert("iHeight = " + iHeight + ", iWidth = " + iWidth )
	iHeight = eval(iHeight*iPercent_Height)
	iHeight = Math.round(iHeight)
	iWidth = eval(iWidth*iPercent_Width)
	iWidth = Math.round(iWidth)
	window.resizeTo(iWidth, iHeight);	
	return true; 
}

function resize(){  
	var frame = document.getElementById("frame1");  
	var htmlheight = document.body.parentNode.scrollheight;  
	var windowheight = window.innerheight; 
	if ( htmlheight < windowheight ) { 
		document.body.style.height = windowheight + "px"; frame.style.height = windowheight + "px"; 
	}  else { 
		document.body.style.height = htmlheight + "px"; frame.style.height = htmlheight + "px"; 
	}  
} 

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 = "/Member/Includes/iSort/default.asp";
	sURL += "?sTable=" + sTable ;
	sURL += "&sGroupingField=" + sGroupingField ;
	sURL += "&iGroupingValue=" + iGroupingValue ;
	sURL += "&s_iIDField=" + s_iIDField ;
	sURL += "&iSort_Old=" + iSort_Old ;
	sURL += "&iSort_New=" + iSort_New ;
	sURL += "&sWhere=" + sWhere ;
	sURL += "&sid=" + Math.random();
	//alert("sURL = " + sURL)
	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, true);
	oXmlHttp_Strategies.send(null);
	//alert("Perfect!")
	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
	if (document.getElementById(sElementID)){
		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;
    }

    /******
    Description:    This allows multiple values to be stored in any SELECT HTML
                    object and retrieves a given value from a DDL.
    Example:        In the following ASP, multiple values are requested in the
                    SQL and stored in the selected value. The desired index can
                    be retrieved here. It is 0-based.
                    
            sOptionType = "dropdown"
            sElementName = "ddl_Domains"
            sSelectStatement = "SELECT Convert(varchar, adt.iAskDomain) + '|' + cs.sStaffName, adt.sAskDomain FROM tblASK_DOMAIN_TYPE adt INNER JOIN vw_CurrentStaff cs ON cs.iUniqueID = adt.iUniqueID_PrimaryContact WHERE adt.iValid_YN = 1 ORDER BY adt.iSort"
            sNonSelectionText = "-- Select a Domain --"
            sSelectedValue = sNonSelectionText
            sHorizVert = ""
            sAdditionalDefiningProperties = "OnChange='func_JS_SetInnerHTML(""div_AnchorName_Domain"", func_JS_ExtractDDLConcatenatedValue(""" & sElementName & """, ""|"", 1));'"
        
            Call sub_OptionElement_FromRS2(sOptionType, sElementName, sSelectStatement, sNonSelectionText, sSelectedValue, sHorizVert, sAdditionalDefiningProperties)
    ******/
    function func_JS_ExtractDDLConcatenatedValue(sDDLName, sDelimiter, iIndex)
    {
        var ddl = document.getElementById(sDDLName);
        var x = ddl.selectedIndex;
        var ddlFullValue = ddl.getElementsByTagName("option")[x].value.split(sDelimiter);
        return ddlFullValue[iIndex];
    }

    /**********
    Description:   This iterates through all items in a collection of checkboxes
                   and returns all of the checked items in a comma-delimited string.
    
    Parameters:    The name of the HTML Input group
    
    Returns:       A comma-delimited string of values or an empty string.
    
    Example:       sAsmtTypeIDs = func_JS_GetCheckedItems('iAsmtTypeID');
                   if (sAsmtTypeIDs == ''){
                       alert('An assessment type is required');
                   }
    **********/
    function func_JS_GetCheckedItems(sCheckboxName){
        var i = 0;
        var sCheckedItems = '';
        var chk = document.getElementsByName(sCheckboxName);
    
        for (i = 0; i < chk.length; i++) {
            if (chk[i].checked == true) {
                sCheckedItems += chk[i].value + ',';
            }
        }
        
        if (sCheckedItems.length > 0){
            //remove trailing comma
            var iLength = sCheckedItems.length - 1;
            sCheckedItems = sCheckedItems.slice(0,iLength);
        }
        return sCheckedItems;
    }

function func_JS_GetRadioElementValue(sRadioName){
	//alert("running...func_JS_GetRadioElementValue")
	if (document.getElementsByName(sRadioName)){
	for (var i=0; i < document.getElementsByName(sRadioName).length; i++){
		if (document.getElementsByName(sRadioName)[i].checked){
			var iValue = document.getElementsByName(sRadioName)[i].value;
		}
	}
	} else {
		alert("Sorry...unable to locate the document element named: " + sRadioName)
		return false;	
	}
	return iValue;
}
function func_JS_ChangeSelectByValue(ddlID, value, iRun_OnChange_YN) {
	
	//alert("running...func_JS_ChangeSelectByValue: ddlID = " + ddlID + "; value = " + value + "; iRun_OnChange_YN = " + iRun_OnChange_YN)
	
	//change value of ddl
	//source: http://www.aarongoldenthal.com/post/2009/04/12/How-to-Change-the-Selected-Value-of-a-Select-in-Javascript-and-Raise-the-onchange-Event.aspx
     var ddl = document.getElementById(ddlID);
     for (var i = 0; i < ddl.options.length; i++) {
         if (ddl.options[i].value == value) {
             if (ddl.selectedIndex != i) {
                 ddl.selectedIndex = i;
                 if (iRun_OnChange_YN == 1){
                     ddl.onchange();
				 }
             }
             break;
         }

     }

 }

function func_JS_Check_Or_UncheckAll(sCheckBoxName, iCheckStatus){
    for (i = 0; i < document.getElementsByName(sCheckBoxName).length; i++) {
        document.getElementsByName(sCheckBoxName)[i].checked = iCheckStatus;
    }
    return true; 
}


/**********
* Function Name: func_JS_Check_Or_Uncheck_LikeName
*
* Description:   This checks or unchecks all the checkboxes that match a portion of a given name. It was designed to allow
*                groups of checkboxes to be set at the same time.
* 
*                EXAMPLE: Subscale, Items, & Indicators
*                All checkboxes are named with a Subscale / Item convention. (name="sub1_item1" value="1.1")
*                A "Check all subscale 1" button can use the following to check all values for Subscale 1.
* 
*                       func_JS_Check_Or_Uncheck_LikeName('sub1', 1)
* 
*                Likewise, to uncheck all checkboxes for Subscale 2 Item 3 would be:
* 
*                       func_JS_Check_Or_Uncheck_LikeName('sub2_item3', 0)
*
* Parameters:    sLikeName - a string value for the names of checkboxes to be affected
*                icheckStatus - 1 or 0 (for checked or unchecked.)
*
* Returns:       true
*
* Created by:    Andy Knight 
**********/
function func_JS_Check_Or_Uncheck_LikeName(sLikeName, iCheckStatus){
    for (i = 0; i < document.getElementsByTagName('input').length; i++) {
        var chk = document.getElementsByTagName('input')[i];
        if (chk.type == 'checkbox') {
            if (chk.name.substring(0, sLikeName.length) == sLikeName) {
                chk.checked = iCheckStatus;
            }
        }
    }
    return true; 
}

window.onload=startList;
