﻿// Functions Created by Dominion Digital (c) 2007
// info@dominiondigital.com

window.onload = init;

function init() 
{

	traverseTree(document.getElementById("myGuideStarMenu"));
	traverseTree(document.getElementById("mainmenu"));

	var theFont = getCookie("font");
	contentDIV = document.getElementById("contentContainer");

	if (theFont) 
	{
		setFontSize(theFont); 
	} 
	else 
	{
		changeFontSize();
	}

}

function traverseTree(whatTree)
{	
  if (whatTree != null)
  {
	  version=0
	  if (navigator.appVersion.indexOf("MSIE")!=-1)
	  {
		  temp=navigator.appVersion.split("MSIE")
		  version=parseFloat(temp[1])
	  }

	  if (whatTree.hasChildNodes()) 
	  {
		  for(var i=0;i<whatTree.childNodes.length;i++) 
		  {
			  var node_str = whatTree.childNodes[i]
			  if (node_str.nodeName=="UL") 
			  {
				  for(var j=0;j<node_str.childNodes.length;j++) 
				  {
					  var subnode_str = node_str.childNodes[j]
					  if (subnode_str.nodeName=="LI") 
					  {
  //						eval(whichFunction + "(subnode_str);");
						  if (version==6) 
						  {
							  setItAndForgetIt(subnode_str);
							  traverseTree(subnode_str);
						  }
					  }
				  }
			  }
		  }		
		}
	} 
}

function setItAndForgetIt(whichNode) 
{
	whichNode.onmouseover=function() 
	{
	  this.className+=" over";
	  hideSelect()
	}
	whichNode.onmouseout=function() 
	{
	  this.className=this.className.replace("over", "");
	  restoreSelect()
	}
}

function hideSelect()
{
 for (var i = 0; i < document.all.length; i++) 
 {
  o = document.all(i);
  if (o.type == 'select-multiple') 
  {
   if (o.style) o.style.visibility = 'hidden';
  }
  if (o.type == 'select-one') 
  {
   if (o.style) o.style.visibility = 'hidden';
  }
 }
} 

function restoreSelect()
{
 for (var i = 0; i < document.all.length; i++) {
  o = document.all(i);
  if (o.type == 'select-one') 
  {
   if (o.style) o.style.visibility = 'visible';
  }
  if (o.type == 'select-multiple') 
  {
   if (o.style) o.style.visibility = 'visible';
  }
 }
}

function toggleStyle(whichID)
{
  var divObject = document.getElementById(whichID)
  if (divObject.className == "close")
  {
    divObject.className = "open";
  }
  else
  {
    divObject.className = "close";
  }
}

function toggleDiv(whichID) 
{
	var divObject = document.getElementById(whichID)
	if (divObject.style.display == "block") 
	{
		  divObject.style.display = "none";
	} 
	else 
	{
		  divObject.style.display = "block";
	}
}	

function hideDiv(whichID) 
{
  if(document.getElementById(whichID) != null){
    document.getElementById(whichID).style.display = "none";
  }
}	
function showDiv(whichID) 
{
  if(document.getElementById(whichID) != null){
    document.getElementById(whichID).style.display = "block";
  }
}	

function setControlValue(whichID, value)
{
  document.getElementById(whichID).value = value;
}

/***** Font resizer *****/
function changeFontSize(whichDirection) 
{
  if (contentDIV != null)
  {
	  //This works by swapping the current class for the content area for a different preset one in rex_content.css
	  var min=0;
	  var max=5;
	  var classParts = contentDIV.className.split("_");
  	
	  currentClass = parseInt(classParts[1]);

	  if (!currentClass) 
	  {
		  newClass = 2;
	  }
  	
	  if (whichDirection=="up") 
	  {
		  if(currentClass!=max) 
		  {
			  newClass = currentClass + 1;
		  } 
		  else 
		  {
			  newClass = currentClass;
		  }
	  } 
	  else if (whichDirection=="down") 
	  {
		  if(currentClass!=min) 
		  {
			  newClass = currentClass - 1;
		  } 
		  else 
		  {
			  newClass = currentClass;
		  }
	  } 
	  else 
	  {
		  newClass = 2;
	  }
  			
	  setFontSize(newClass); 
	  setCookie("font",newClass);
  }
}

function setFontSize(whatSize) 
{
	if (contentDIV) 
	{
		contentDIV.className = "fontSize_" + whatSize; 
	}
}

function setCookie(name,inpVal) 
{
	inpVal=escape(inpVal); // just in case of special characters
	var nodays = 15;
	var UTCstring;
	Today = new Date();
	nomilli=Date.parse(Today);
	Today.setTime(nomilli+nodays*24*60*60*1000);
	UTCstring = Today.toUTCString();
	document.cookie = name + "=" + inpVal + "; path=/; expires="+UTCstring;
	return true;
}

function getCookie(name) 
{ // use: getCookie("name");
	var allCookies = document.cookie;
  var index = allCookies.indexOf(name + "=");
  
  if (index == -1) 
    return false;
  
  index = allCookies.indexOf("=", index) + 1; // first character
  var endstr = allCookies.indexOf(";", index);
  
  if (endstr == -1) 
    endstr = allCookies.length; // last character
    
  return unescape(allCookies.substring(index, endstr));
}

//used to change tabs and class names on product detail pages
function selectTab(showDivId, hideDivIds){

  //display div to be shown
  showDiv(showDivId);
 
  //find parent list of shown div to set its class property
  var parent = getParentListObject(showDivId);
  parent.className = "current";
  
  //cycle through others
  for(var i=0; i < hideDivIds.length; i++ ){

     //hide div
     hideDiv(hideDivIds[i]);
    
     //find parent list of hidden div to set its class property
     var parent = getParentListObject(hideDivIds[i]);
     parent.className = "";
  }
}

//for use by selecting nav bars from a list.  gets parent list object from associated div
//NOTE - div must be named 'div_something' and its associated list must be 'li_something'
function getParentListObject(divId){

  var parentId = divId.replace("div", "li")
  var parentObject = document.getElementById(parentId)
  return parentObject;

}



var this_month_name_array = new Array("January","February","March","April","May","June","July","August","September","October","November","December")	//predefine month names

var this_date_timestamp=new Date()	//get current day-time stamp

var this_date = this_date_timestamp.getDate()	//extract day of month
var this_month = this_date_timestamp.getMonth()	//extract month
var this_year = this_date_timestamp.getYear()	//extract year

if (this_year < 1000)
	this_year+= 1900;	//fix Y2K problem
if (this_year==101)
	this_year=2001;		//fix Netscape browsers - it displays the year as being the year 101!

var this_date_string1 = this_month_name_array[this_month] + " " + this_date + ", " + this_year	//concat long date string



//this function is called from the report page to display a selected report section div, highlight nav link and hide all others
//sectionId = div id to display
//listItemId = li id to display in different color
//containingDivId = parent div of all report sections
//containingUlId = parent ul of all nav lis
function ShowReportSectionDiv(sectionId, navItemId, containingDivId, containingNavDivId)
{

	
  //hide all divs
	HideReportSectionDivs(containingDivId);

  //turn off all selected navigation tabs
	HideNavigationLinks(containingNavDivId);
	
	//display selected div
	showDiv(sectionId);

	//highlight selected nav div
	var navItem = document.getElementById(navItemId);

	if (navItem != null)
	{
	
	  //find link inside nav
    var link = navItem.getElementsByTagName('a')[0];
    if (link != null)
    {
       link.className = "blueTabActive short";
     }
		}
}


//this function is called from the report page to display a selected financial report section year and hide all others
//sectionId = div id to display
//containingDivId = parent div of all report sections
function ShowFinancialYearDiv(sectionId, containingDivId)
{
	
  //hide all divs
	HideReportSectionDivs(containingDivId);

	//display selected div
	showDiv(sectionId);
	
}



//this hides all report section divs under the indicated containing div
function HideReportSectionDivs(containingDivId)
{

    //find each child div under container that has an id and hide them
    var parent_div = document.getElementById(containingDivId)
    
    if (parent_div != null){
      var child_divs = parent_div.childNodes;
      for (var i=0;i<child_divs.length;i++)
      { 
        if((child_divs[i].id != null) &&
           (child_divs[i].id != ""))
        {
           hideDiv(child_divs[i].id);
        }
      }
    }

}


//this deselects all navigation links under the indicated containing div
function HideNavigationLinks(containingDivId)
{

    //find each child div under container and deselect them
    var divs = document.getElementById(containingDivId).childNodes;
    
    if (divs != null && divs.length > 0)
	  {

      for (var i=0;i<divs.length;i++)
      { 
        if(divs[i].id != null)
        {
           //get link inside div
           var link = divs[i].getElementsByTagName('a')[0];

        if (link != null)
        {
           link.className = "blueTab short";
          }
        }
      }
    }
}

// this function is called from the report page to mark the clicked year
// obj     : anchor object to work with
// disable : true/false
function disableAnchor(obj, disable)
{
  if(disable){
    obj.style.color="black";
    obj.style.fontWeight="bold";
    obj.style.textDecoration="none";
  }
  else{
    obj.style.color="#316ac5";
    obj.style.fontWeight="normal";
    obj.style.textDecoration="underline";
    //obj.style.color="#66CCCC";
  }
}

// this function is called from the report page to reset all anchors
// divID   : Div ID to work with
function resetAnchors(divID)
{
  var divSection = document.getElementById(divID);
  if (divSection != null)
  { 
    var links = divSection.getElementsByTagName('a');
    if (links != null)
    {
      for(var i=0; i<links.length; i++) 
      { 
        disableAnchor(links[i], true);
        disableAnchor(links[i], false);
      }
    }
  }
}

// this function is called when any of the terms such as Did You Mean/Clustering is clicked
// searchBarKeywordClientID : Client ID of search bar's keyword textbox
// newKeyword               : New search keyword
// searchBarButtonClientID  : Client ID of search bar's search button
// isPhrase                 : Boolean to indiate whether we should treat this as a phrase
function submitForm(searchBarKeywordClientID, newKeyword, searchBarButtonClientID, isPhrase)
{
  if (isPhrase)
  {
    document.getElementById(searchBarKeywordClientID).value = "\"" + newKeyword + "\"";
  }
  else
  {
    document.getElementById(searchBarKeywordClientID).value = newKeyword;
  }
  document.getElementById(searchBarButtonClientID).click();
}

// This is used to close popup windows gracefully in IE 6 and 7 without the popup confirmation message showing
function closeWindow()
{
    window.open('','_self','');
    window.opener=this;
    window.close();
}