// rollovers for images ... use <img class="imgover" ... /> or 
// <input type="image" class="imgover" /> to invoke.  Save the rollover
// image with "_over" suffix, and in the same folder as the non-rollover image.
// For example, menuitem.gif and menuitem_over.gif should be saved in the same folder.
function initRollovers() {
	//check for incompatible browser
	if (!document.getElementById) return
	
	var aPreLoad = new Array();
	var sTempSrc;
	
	// declare image and input element variables
	var aInputs = document.getElementsByTagName("input");
	var aImg = document.getElementsByTagName('img');
	var aImages = new Array();
	
	// loop that finds the input elements
	for(var i = 0; i < aInputs.length; i++)
	{
		aImages[i] = aInputs.item(i);
	}
	// loop that finds all image elements and adds to 
	// inputs for total images that need swapping
	for(var i = 0; i < aImg.length; i++)
	{
		aImages[i + aInputs.length] = aImg.item(i);
	}

	// looks for images or inputs that have the imgover class and runs the following methods
	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == 'imgover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_over'+ftype);

			aImages[i].setAttribute('hsrc', hsrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			// adds the mouseover event
			aImages[i].onmouseover = function() {
			
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			// adds the mouseout event
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_over'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}
window.onload=initRollovers;

// clear the Sarch Text & reset the Style
function styleSearch()
{
	var searchBox = document.getElementById("search_field");
	if( searchBox.value == "Search the Site" )
	{
		searchBox.value = "";
		searchBox.style.color = "#000";
	}
	else if( searchBox.value == "" )
	{
		searchBox.value = "Search the Site";
		searchBox.style.color = "#999";
	}
}


// Provide an Exit Page Popup
function ExternalLink(source_url, dest_url, popupYN)
{
	var ExitPage_url = "/hcp/ExitPage.aspx?source_url=" + source_url + "&dest_url=" + dest_url;
	
	if( popupYN != null && popupYN.length > 0 )
		ExitPage_url += "&pop_up=" + popupYN;
	
	window.open(ExitPage_url,"ExitPage","width=528,height=226,menubar=no,resizeable=no,status=no,toolbar=no,scrollbar=no");
	
	return false;
}

// Assign the Continue Button the Proper Link & Close this window
function AssignExternalLink()
{
	var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    
	if( vars != null & vars.length > 0 )
	{
		if(vars["pop_up"] != null && vars["pop_up"].length > 0)
		{
			//window.open(vars["dest_url"],"_blank","location=yes,menubar=yes,resizeable=yes,status=yes,toolbar=yes",true);
			window.open(vars["dest_url"],"_blank","channelmode=0,dependent=0,directories=0,fullscreen=0,location=1,menubar=1,resizable=1,scrollbars=0,status=1,toolbar=1",true);
			setTimeout("window.close();",300);
		}
		else
		{
			window.opener.location = vars["dest_url"];
			window.close();
		}
	}
}


// Assign the url to favorites under name
function AddFavorite(url, name)
{
	window.external.AddFavorite(url, name);
}

//function to remove special characters from the search query
function filterNum(str) 
{
          var re = /\?|\&|=|\#/g;
          // remove special character like "?" 
          return str.replace(re, "");
}


// Search Function
function pageSearch()
{
	//alert('in the pagesearch func');
	var lvsearchterm = filterNum(document.getElementById("search_field").value);
	//alert(searchterm);
	var reNonSpace = /\S/g;
	var rex = /[^a-zA-Z ]/;
	// setting the max length for the search query term 
	var searchterm = lvsearchterm.slice(0,75);  
	
	if(searchterm != "Search the Site")
	{
	        if ((reNonSpace.test(searchterm)))
	        {		
		        var loc = "/hcp/search.aspx?q="+ searchterm +"";
		        window.location = loc;		
	        } 
	        else 
	        {
		        alert("Please enter a question and click 'Go'.");
		        document.getElementById("search_field").focus();
		        return false;
	        }
	 }
	 else
	 {
	    
	    //alert('if not the search the site term');
	    //alert("Please enter a question and click 'Go'.");
		document.getElementById("search_field").focus();
		return false;
	 }
	 	
}

function doClick(e)
{
	//the purpose of this function is to allow the enter key to 
	//point to the correct button to click.	    
    var code;
	if (!e) var e = window.event;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
		
    if (code == 13)
       {	
			if (e.cancelable)	
			{
				e.preventDefault();							
			}
			else
			{			
				e.keyCode=0;			
			}
			pageSearch();			
      }          
}


//opening PI window
function OpenPIBehind(url1,url2)
{
          
          mywindow2= window.open(url2,"pi"); 
          mywindow1= window.open(url1,"pdf");  
}