// This function is used for the Suckerfish (flyout) menus

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);



// menuExpandable.js - implements an expandable menu based on a HTML list
// Author: Dave Lindquist (http://www.gazingus.org)

if (!document.getElementById)
    document.getElementById = function() { return null; }

function initializeMenu(menuId, actuatorId) {
    var menu = document.getElementById(menuId);
    var actuator = document.getElementById(actuatorId);

    if (menu == null || actuator == null) return;

    //if (window.opera) return; // I'm too tired



   actuator.parentNode.style.background = "url(http://bmb.utmb.edu/img/arrow-down-sm.gif) 90% 10px no-repeat";
    actuator.onclick = function() {
        var display = menu.style.display;
        this.parentNode.style.background =
            (display == "block") ? "url(http://bmb.utmb.edu/img/arrow-down-sm.gif) 90% 10px no-repeat" : "url(http://bmb.utmb.edu/img/arrow-up-sm.gif) 90% 10px no-repeat";
        menu.style.background = "url(/images/square.gif)";
        menu.style.display = (display == "block") ? "none" : "block";

        return false;
    }
}


// Preload images

function Preload() {
 	var args = simplePreload.arguments;
	document.imageArray = new Array(args.length);
	for(var i=0; i<args.length; i++) {
		document.imageArray[i] = new Image;
		document.imageArray[i].src = args[i];
	}
   }
   
function OptnOnLoad()
	    {
	        var cssPageSize = ReadCookie("cssPageSize");
	        
	        if (cssPageSize == "" || cssPageSize == "NaN" || cssPageSize == null)
	            SetCookie("cssPageSize", "14");
	        else
	        {
	            if (parseInt(cssPageSize) < 10) 
	                cssPageSize = "10";
	            else if (parseInt(cssPageSize) > 20) 
	                cssPageSize = "20";
	            document.getElementById("css").href = "/css/styles_" + cssPageSize + ".css";
	        }    
	        
	        var links;
	        if (document.getElementById("sitecontent") != null)
	            links = sitecontent.getElementsByTagName("a");
	        else
	            links = content1.getElementsByTagName("a");
            
            setLinks(links);
            
            setFooter();
            
            setPdfPlugIn();
	    }
	    
	    function setPdfPlugIn()
	    {
	        if (document.getElementById("pdfPluginDiv") != null)   
	        {
	            var links;
                var hasPdf = false;
                var hasDoc = false;
                var pdfLink, docLink;
            
                links = document.getElementsByTagName("a");
                hasPdf = checkFileType(links, ".pdf");
                
                if (!hasPdf)
                  document.getElementById("pdfPluginDiv").style.display = "none";
            }
	    }
	    
	    function checkFileType(links, fileType)
        {
            var hasFile = false;
            for(i=0; i < links.length; i++)
            {
                var link = links[i].href.toLowerCase();
                if (link.indexOf(fileType) > 0)
                {
                    hasFile = true;
                    break;
                }   
            }
            return hasFile;
        }
	    
	    function setLinks(links) // set the Exit Disclaimer link if external link
	    {
	        for(i=0; i < links.length; i++)
	        {
	            var link = links[i].href.toLowerCase();
	            if (link.length > 0){
	                var isGovSite = checkGovSite(link);
	                    if (!isGovSite)
	                    {
	                        if ((link.indexOf("javascript") < 0) && (link.indexOf("mailto") < 0))
	                        {
	                            if (links[i].innerHTML.toLowerCase().indexOf("img") < 0)
	                            {
	                                ExitDisclaimer(links[i]);
	                            }
	                            else 
	                            {
	                                if (navigator.appName != "Netscape")
	                                {
	                                    if (links[i].innerText.length > 0 && links[i].innerText != " ")
                                            ExitDisclaimer(links[i]);
                                    }
                                    else
                                    {
                                        if (links[i].textContent.length > 0)
                                            ExitDisclaimer(links[i]);
                                    }
                                }
                            }
                        }        
                  }
	        }
	    }
	    
	    function checkGovSite(link)
	    {
	        if ((link.indexOf("optn") < 0) && (link.indexOf(".gov") < 0))
	            return false;
	        else
	            return true;
	    }
	    
	    function ExitDisclaimer(link)
	    {
	        var exitDiv = document.createElement('a');
	        var divIdName = 'exitDiv' + i;
	        exitDiv.setAttribute('id', divIdName);
	        exitDiv.setAttribute('href', 'http://www.hrsa.gov/external_disclaim.htm');
	        exitDiv.innerHTML = '&nbsp;[Exit Disclaimer]';
	        link.appendChild(exitDiv);
	    }
	    
	    function ReadCookie(cookieName) {
            var theCookie=""+document.cookie;
            var ind=theCookie.indexOf(cookieName);
            if (ind==-1 || cookieName=="") return ""; 
                var ind1=theCookie.indexOf(';',ind);
            if (ind1==-1) ind1=theCookie.length; 
                return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
        }
        
        function SetCookie(cookieName, cookieValue) {
        	var expire = new Date ();
	  	    expire.setTime (expire.getTime() + (6000 * 24 * 3600000)); //expires in 6 days from users clock
	  	    expire = expire.toGMTString();
	        document.cookie="" + cookieName + "="+cookieValue+"; path=/; expires="+expire;
        }
        
        
        function increaseOptnContent()
        {
            var cssPageSize = ReadCookie("cssPageSize");
            
            if (parseInt(cssPageSize) < 20)
            {
                var newCssPageSize = parseInt(cssPageSize) + 2;
                SetCookie("cssPageSize", newCssPageSize.toString());
                document.getElementById("css").href = "/css/styles_" + newCssPageSize + ".css";
            }
        }
        
        function decreaseOptnContent()
        {
            var cssPageSize = ReadCookie("cssPageSize");
            
            if (parseInt(cssPageSize) > 10)
            {
                var newCssPageSize = parseInt(cssPageSize) - 2;
                SetCookie("cssPageSize", newCssPageSize.toString());
                document.getElementById("css").href = "/css/styles_" + newCssPageSize + ".css";
            }
        }
        
        function setFooter()
        { 
            var browser = navigator.appName;
            var userAgent = navigator.userAgent;
            var isFirefox = false;
            
            if ((browser == "Netscape") && (userAgent.indexOf("Firefox") > 0))
                isFirefox = true;
            
            var pageHeightWithScroll;                                    
            var heightDifference;
                    
            document.getElementById("clearfoot").style.height = "0px";
                            
                if (document.getElementById("leftBarEnd") != null)                                
                    var leftBarEnd = findPosY(document.getElementById("leftBarEnd"));
                if (document.getElementById("secondaryContentEnd") != null)
                    var secondaryContentEnd = findPosY(document.getElementById("secondaryContentEnd"));
                
                var pageHeight
                
                if (!isFirefox)
                {
                    pageHeight = document.body.clientHeight;
                    if (leftBarEnd > secondaryContentEnd) 
                        heightDifference = leftBarEnd - secondaryContentEnd + 260;
                    else if (secondaryContentEnd < pageHeight)
                        heightDifference = pageHeight - secondaryContentEnd;
                    else
                        heightDifference = 0;
                }    
                else
                {
                    pageHeight = window.innerHeight + window.scrollMaxY;
                    if ((leftBarEnd > 700) && (pageHeight < 1600))
                        heightDifference = 700;
                    else if (secondaryContentEnd < pageHeight)
                        heightDifference = pageHeight - secondaryContentEnd;
                    else
                        heightDifference = 0;
                }    
                
                document.getElementById("clearfoot").style.height = heightDifference.toString() + "px";
        }           


    
    //following functions added to persist field values on invalid Captcha response - DR 36904
    function SetCaptchaFocus()
    {
        document.getElementById("txtCaptchaResponse").focus();   
    }
    
    function PersistFields(fields, values)
    {
        var field = fields.split("|");
        var value = values.split("|");
       
        
        for(j=0; j<field.length ; j++)
        {
            FindSelectedIndex(field[j], value[j]);
        }
    }
    
    function FindSelectedIndex(dropDownName, selectedValue)
    {
        for (i=0;i<document.getElementById(dropDownName).length;i++)
        {
            if (selectedValue == document.getElementById(dropDownName).options[i].value)
            {
                document.getElementById(dropDownName).options[i].selected = true;
                return;
            }
        }
    }