
/* 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;
					  }		 
}

/*
 * Check to see if we need to hide the Corp Summaries
 */

function HideSummariesCorp()
{
   if (document.forms["summmaryForm"].ENESearchResults1_ShowSummariesCheckBox == null)
   {
	  HideCorp();

   }
   else if (document.forms["summmaryForm"].ENESearchResults1_ShowSummariesCheckBox.checked != true)
   {
 	  HideCorp();
   }
}

/*
 * Check to see if we need to hide the LAS Summaries
 */

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 ShowHideSummariesCorp(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(/alternateItemSummary/.test(obj[i].className) || /itemSummary/.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, "Exp");
}


/*
 *
 * 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, "Exp");
}

function updateUrlAfterChange(cb, paramName)
{
	var newQueryString; 
	var page = new PageQuery(window.location.search); 
	if (cb.checked)
    {
		newQueryString = unescape(page.rebuildUrlWithNewParam(paramName,"On"));
    }
    else
    {
		newQueryString = unescape(page.rebuildUrlWithNewParam(paramName,"Off"));
    }
		//This will cause the browser to navigate to the given querystring	
		window.location.search = newQueryString;
}

/*
 * This code hides the Corp search summaries
 */

function HideCorp()
{
   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(/alternateItemSummary/.test(obj[i].className) || /itemSummary/.test(obj[i].className))
	  {
      	obj[i].style.display='none';
	  }
   }
}

/*
 *
 * This code hides the LAS search summaries
 *
 */

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;
	}
}
