/**
 * Functions to coordinate the onclick events of the search boxes 
 *
**/

function SetFocus(txt)
 {
	document.activeElement = txt;
 }

function ResetFocus()
 {
	document.activeElement = null;
 }

function clickButtonHeader(e,search)
{ 	
	var buttonheaderid = document.getElementById(search);
    
    if (typeof buttonheaderid == 'object')
    {
		if(navigator.appName.indexOf("Netscape")>(-1))
		{ 
			if (e.keyCode == 13)
			{ 	
				if(null != buttonheaderid)
				{
					buttonheaderid.click();
				}				
               return false; 
            } 
        } 
        if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1))
        { 
			if (event.keyCode == 13)
			{ 
				if(null != buttonheaderid)
				{
					buttonheaderid.click();
				}				
				return false;			
			}
            
        }      
    }
} 




/* JavaScript function to build the current window's queryString.
 * This function acts like class with a constructor using javascripts abilty to save function as properties which makes them 
 * essentially methods
 * The set of "methods" in this class allows you to build and manage querystring values similar to how you would 
 * access parameters in ASP uing QueryString["key"] but here you will use queryString("key")
 */

function PageQuery(q) 
{
	if(q.length > 1) 
		this.q = q.substring(1, q.length);
	else this.q = null;
		this.keyValuePairs = new Array();

	if(q) 
	{
		for(var i=0; i < this.q.split("&").length; i++) 
		{
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}

	this.getKeyValuePairs = function() 
				{ 
					return this.keyValuePairs; 
				}
	this.getValue = function(s) 
			{
				for(var j=0; j < this.keyValuePairs.length; j++) 
				{
					if(this.keyValuePairs[j].split("=")[0] == s)
					return this.keyValuePairs[j].split("=")[1];
				}
				return false;
			}
	
	this.getParameters = function() 
						{
							var a = new Array(this.getLength());
							for(var j=0; j < this.keyValuePairs.length; j++) 
							{
								a[j] = this.keyValuePairs[j].split("=")[0];
							}
					
							return a;
						}
			     
	this.getLength = function() 
					 { 
			 			return this.keyValuePairs.length; 
					 } 
	// Rebuild the queryString with the new queryParam and queryValue provided	 
	this.rebuildUrlWithNewParam = function(queryParam,queryValue) 
					  {
						  var newQueryString = "?";
						  for(var j=0; j < this.keyValuePairs.length; j++) 
						  {
								if(this.keyValuePairs[j].split("=")[0] != queryParam)
								{
									newQueryString += this.keyValuePairs[j].split("=")[0] + "=" + this.keyValuePairs[j].split("=")[1] + "&";
								}
						  }
						newQueryString += queryParam + "=" + queryValue;
						return newQueryString;
					  }		 
}

/*
 *
 * Build and load new url using existing url with a new showSummaries value (on / off)
 * onclick="buildUrlAfterShowSummariesSelection(window.location.search, this)"
 *
 */
 
function updateUrlAfterChange(cb)
{
	var newQueryString; 
	var page = new PageQuery(window.location.search); 
		
	if (cb.checked)
    {
		newQueryString = unescape(page.rebuildUrlWithNewParam("Exp","On"));
    }
    else
    {
		newQueryString = unescape(page.rebuildUrlWithNewParam("Exp","Off"));
    }
		//This will cause the browser to navigate to the given querystring	
		window.location.search = newQueryString;
}

/*
 *
 * Place Description here
 *
 */

function ShowHideSummaries(showChkBox)
{
   var obj

   // get all spans
   obj=document.getElementsByTagName('div')

   // run through them
   for (var i=0;i<obj.length;i++)
   {
      // if it has a class of ENESummary
      if(/ENESummary/.test(obj[i].className))
      {
         // Show/Hide
         if (showChkBox.checked)
         {
      	   obj[i].style.display='';
      	 }
         else
         {
      	   obj[i].style.display='none';
      	 }
      }
   }
   
    //This will update the querystring parameters after selections have been made
   	updateUrlAfterChange(showChkBox);
}

/*
 *
 * Place Description here
 *
 */

function HideSummaries()
{
   if (document.forms["ENESearchPage"].ENESearchResults1_ShowSummariesCheckBox == null)
   {
	  //alert("ShowSummCheckBox == null - Hide");
	  Hide();
   }
   else if (document.forms["ENESearchPage"].ENESearchResults1_ShowSummariesCheckBox.checked != true)
   {
	  //alert("ShowSummCheckBox != true - Hide");
 	  Hide();
   }
   	  //alert("Else, do nothing");

}

/*
 *
 * Place Description here
 *
 */

function Hide()
{
   var obj
   // get all spans
   obj=document.getElementsByTagName('div')
   // run through them
   for (var i=0;i<obj.length;i++)
   {
      // if it has a class of ENESummary
	  if(/ENESummary/.test(obj[i].className))
	  {
      	obj[i].style.display='none';
	  }
   }
}

/*
 *
 * Place Description here
 *
 */

function navRadioButtonOnClick(button)
{
	if( !button.defaultChecked )
	{
		window.location.search = button.value;
	}
}

function clearText(thefield)
{
	if (thefield.value==document.getElementById("hdnSearchtxt").value )
	{
		thefield.value = "";
		thefield.style.color="#000";
	}
}

function SetSearchTxt(thefield)
{
	if (thefield.value=="")
	{
		thefield.value = document.getElementById("hdnSearchtxt").value;
		thefield.style.color="#bfbfbf";
	}
}
		
function SetSearchTxtById(id)
{
	searchTextBox = document.getElementById(id);
	if (searchTextBox != null)
	{
		searchTextBox.value = document.getElementById("hdnSearchtxt").value;
		searchTextBox.style.color="#bfbfbf";
	}
}
