/* APPLICATION SCRIPTS */


/* 
FUNCTION: addPopUpLink
DESCRIPTION: Opens the linked document of all links with a certain class in a pop-up window and adds a message to the link that there will be a new pop-up window.
*/
function addPopUpLink() {
  // check that the client supports DOM scripting
  if(!document.getElementById || !document.createTextNode){return;}
		  
  // assets of the link -- the class that indicates which link should get the functionality and the message to add the link text
  var popupClass = 'popup';
  var popupMessage = '';
		  
  // temporary variables to use in a loop
  var pop,t;
		  
  // get all links in the document
  var as=document.getElementsByTagName('a');
  // loop over all links
  for (var i=0; i<as.length; i++) {
    t=as[i].className;

	// check to see if the link has a class and the class is the right one
	if (t && t.toString().indexOf(popupClass)!=-1) {
	  // add the message
	  as[i].appendChild(document.createTextNode(popupMessage));

	  // assign a function when the link is clicked
	  as[i].onclick=function() {
	    // open a new window with
	    pop=window.open(this.href, 'popup', 'width=960', 'height=600');
		// don't follow the link, otherwise the linked doc would be opened in a new window AND in the parent
        return false;
	  }
	}
  }
}


/* 
FUNCTION: setPage
DESCRIPTION: Marks the current nav list item.
*/
function setPage()
{
	if(document.location.href) 
		hrefString = document.location.href;
	else
		hrefString = document.location;

	if (document.getElementById("navigation")!=null)
		setActiveMenu(document.getElementById("navigation").getElementsByTagName("a"), extractPageName(hrefString));
}


/* 
FUNCTION: extractPageName
DESCRIPTION: Determines the URL of the current page.
*/
function extractPageName(hrefString)
{
	var arr = hrefString.split('.');
	arr = arr[arr.length-2].split('/');
	return arr[arr.length-1].toLowerCase();	
}


/* 
FUNCTION: setActiveMenu
DESCRIPTION: Sets the menu item to current
*/

function setActiveMenu(arr, crtPage)
{
	for(var i=0; i < arr.length; i++)
		if(extractPageName(arr[i].href) == crtPage)
		{
			arr[i].className = "current";
			arr[i].parentNode.className = "current";
		}
}


// **********************************************************
// Browser checks for AJAX support
// **********************************************************

// Create a boolean variable to check for a valid IE instance
var xmlhttp = false;
        
// Check if the client is IE
try {
  // If the JS version is greater than 5
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch(e) {
  // If not, then use the older active X object
  try {
    // If the client is IE...
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch(E) {
    // Else the client must be non-IE
    xmlhttp = false;
  }
}
        
// If the client is not IE, create a JS instance of the object
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
  xmlhttp = new XMLHttpRequest();
}
        
function makerequest(serverPage, objID) {
var obj = document.getElementById(objID);
xmlhttp.open("GET", serverPage);
xmlhttp.onreadystatechange = function() {
  if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
    obj.innerHTML = xmlhttp.responseText;
    }
  }
xmlhttp.send(null);
}

// **********************************************************


// **********************************************************
// FUNCTION: showHideCalendar
// DESCRIPTION: Reveals or hides the calendar
// **********************************************************

// Create a variable to distinguish between an open or closed calendar
var showElement = true;

function showHide(divID) {
  
  // The location to load the page into
  var objID = divID;
  
  // Change the icon img to a + or -
  if(showElement == true) {
  
    // Show the calendar
    document.getElementById("openCloseImg" + objID).src = "images/minus.gif";
    // The page we are loading
    document.getElementById(objID).style.display = "block";
    // Set the open/close variable
    showElement = false;

  } else {
  
    // Hide the calendar
    document.getElementById("openCloseImg" + objID).src = "images/plus.gif";
    showElement = true;
    
    document.getElementById(objID).style.display = "none";
  }
}

// **********************************************************


/* RUN ON LOAD */
window.onload=function(){
setPage();
addPopUpLink();
}