// 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;

function setlinks()
{
	var alinks = document.getElementsByTagName('a');
	for (var i = 0; i < alinks.length; i++) 
	{
		var link = alinks[i];
		
	}
}

// clear the Sarch Text & reset the Style
function styleSearch()
{
	//alert('in the stylesearch func');
	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)
{
	var ExitPage_url = "/ExitPage.aspx?source_url=" + source_url + "&dest_url=" + dest_url;
	window.open(ExitPage_url,"ExitPage","width=528,height=226,menubar=no,resizeable=no,status=no,toolbar=no,scrollbar=no");
	
	return false;
}

// Asign 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 )
	{
		window.opener.location = vars["dest_url"];		
		window.close();
	}
}

function PrintPage()
{
	if(window.print)
	{
		window.print();
	} else
	{
		alert("Please Use File->Print to Print this page.");
	}
}


//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 = "/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();			
      }          
}


