// JavaScript Document

/* ************************************************************************************************ */
// begin resize text 
function AddClass(target, classValue)
{
	var pattern = new RegExp("(^| )" + classValue + "( |$)");
	var classWasAdded = false;
	if(!pattern.test(target.className))
	{
		classWasAdded = true;
		if(target.className == "")
		{
			target.className = classValue;
		}
		else
		{
			target.className += " " + classValue;
		}
	}
	return classWasAdded;
}

function RemoveClass(target, classValue)
{
	var removedClass = target.className;
	var pattern = new RegExp("(^| )" + classValue + "( |$)");
	var classWasRemoved = false;
	if(pattern.test(target.className))
	{
		classWasRemoved = true;
		removedClass = removedClass.replace(pattern, "$1");
		removedClass = removedClass.replace(/ $/, "");
		target.className = removedClass;
	}
	return classWasRemoved;
}

function Increase()
{
	//document.title = this.size;
    var collOfTags = document.getElementsByTagName("*");
    for(var i = 0; i < collOfTags.length; i++)
    {
        if(collOfTags[i].className.indexOf("resize") < 0)
        {
            continue;
        }
		if(this.RemoveClass(collOfTags[i], this.size))
		{
			this.AddClass(collOfTags[i], this.GetNext(this.size));
		}
	}
	this.size = this.GetNext(this.size);
	//document.title = this.size;
}

function Decrease()
{
    //document.title = this.size;
    var collOfTags = document.getElementsByTagName("*");
    for(var i = 0; i < collOfTags.length; i++)
    {
        if(collOfTags[i].className.indexOf("resize") < 0)
        {
            continue;
        }
		if(this.RemoveClass(collOfTags[i], this.size))
		{
			this.AddClass(collOfTags[i], this.GetPrevious(this.size));
		}
    }
	this.size = this.GetPrevious(this.size);
    //document.title = this.size;
}

function SetTextSize(sizeIn)
{
    var found = false;
    this.size = this.values[parseInt(this.values.length / 2)];
    for(var i = 0; i < this.values.length && !found; i++)
    {
        if(sizeIn == this.values[i])
        {
            this.size = sizeIn;
            found = true;
        }
    }

    var collOfTags = document.getElementsByTagName("*");
    for(var i = 0; i < collOfTags.length; i++)
    {
        if(collOfTags[i].className.indexOf("resize") < 0)
        {
            continue;
        }

        for(var j = 0; j < this.values.length; j++)
        {
            if(collOfTags[i].className.indexOf(this.values[j]) >= 0)
            {
		    	this.RemoveClass(collOfTags[i], this.values[j]);
		    	break;
            }
        }
		this.AddClass(collOfTags[i], this.size);
    }
}

function GetNext(sizeIn)
{
    var found = false;
    var j;
    for(var i = 0; (i < this.values.length) && !found; i++)
    {
        if(sizeIn == this.values[i])
        {
            j = i + 1;
            found = true;
        }
    }
    return (j >= this.values.length) ? this.values[this.values.length - 1] : this.values[j];
}

function GetPrevious(sizeIn)
{
    var found = false;
    var j;
    for(var i = 0; (i < this.values.length) && !found; i++)
    {
        if(sizeIn == this.values[i])
        {
            j = i - 1;
            found = true;
        }
    }
    return (j < 0) ? this.values[0] : this.values[j];
}

function TextResize()
{
    this.values = ["xSmall","small","medium","large","xLarge"];
    this.size = this.values[parseInt(this.values.length / 2)];
    this.Increase = Increase;
    this.Decrease = Decrease;
    this.SetTextSize = SetTextSize;
    this.AddClass = AddClass;
    this.RemoveClass = RemoveClass;
    this.GetNext = GetNext;
    this.GetPrevious = GetPrevious;
}
// end resize text 
/* ************************************************************************************************ */

/* ************************************************************************************************ */
// begin site search functions 
function showHideScope(btn, sel)
{
    if(btn.className == "show")
    {
        btn.className = "hide";
        //btn.value = "-";
        sel.style.display = "block"; 
        sel.style.position = "absolute";
    }
    else
    {
        btn.className = "show";
        //btn.value = "+";
        sel.style.display = "none";
    }
    return false;
}

function search()
{
    alert("Search - to be implemented!");
    return true;
}
// end site search functions 
/* ************************************************************************************************ */

/* ************************************************************************************************ */
// begin ajax functions
var xmlHttp;

function showInformation(searchValue, scopeValue, fileName)
{
    //document.title = searchValue;
    if(typeof document.getElementById("results") == "undefined")
    {
        alert("Results placeholder not set up.");
        return;
    }
    if(searchValue.length == 0)
    { 
        document.getElementById("results").innerHTML = "";
        return;
    }
    xmlHttp = getXmlHttpObject();
    if(xmlHttp == null)
    {
        alert("Data cannot be obtained.");
        return;
    } 
    var url = fileName;
    url = url + "?txtValue=" + searchValue;
    url = url + "&selScope=" + scopeValue;
    url = url + "&sid=" + Math.random();
  
    //document.title = url;
  
    xmlHttp.onreadystatechange = stateChanged;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}

function getXmlHttpObject()
{
    var xmlHttp = null;
    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    }
    catch(e)
    {
        // Internet Explorer
        try
        {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e)
        {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

function stateChanged() 
{ 
    if(xmlHttp.readyState == 4)
    { 
        document.getElementById("results").innerHTML = xmlHttp.responseText;
    }
}
// end ajax functions
/* ************************************************************************************ */

/* ************************************************************************************ */
// begin cookie functions
var MAX_DAYS_TO_EXPIRE = 365;

function Trim(strStringIn) 
{
	var strString = strStringIn;
	return strString.replace(/^\s*/, "").replace(/\s*$/, "");
}

function SetCookie(cookieName, cookieValue, daysToExpire)
{
	var theCookie = cookieName + "=" + cookieValue;
	var expDate = new Date();
	expDate.setDate(expDate.getDate() + daysToExpire);
	var cookieDate = expDate.toGMTString();
	theCookie += ";expires=" + cookieDate;
	document.cookie = theCookie;
	//document.title = document.cookie;
}

function GetCookie(searchName)
{
	var cookies = document.cookie.split(";");
	for(var i = 0; i < cookies.length; i++)
	{
		var cookieCrumbs = cookies[i].split("=");
		var cookieName = Trim(cookieCrumbs[0]);
		var cookieValue = cookieCrumbs[1];
		if(cookieName == searchName)
		{
			//document.title = document.cookie;
			return cookieValue;
		}
	}
	return "";
}

function CheckCookie()
{
	var textSize = GetCookie("textSize");
	if(textSize == "")
	{
		textSize = "medium";
		SetCookie("textSize", textSize, MAX_DAYS_TO_EXPIRE);
	}
	return textSize;
}
// end cookie functions
/* ************************************************************************************ */

/* ************************************************************************************ */
// begin page initialization and cleanup functions
function initTemplate()
{
    if(document.getElementById("incBtn") == null)
    {
        return;
    }
    if(document.getElementById("decBtn") == null)
    {
        return;
    }
	tr = new TextResize();
	document.getElementById("incBtn").onclick = function()
	{
		tr.Increase();
		SetCookie("textSize", tr.size, MAX_DAYS_TO_EXPIRE);
		return false;
	};
	document.getElementById("decBtn").onclick = function()
	{
		tr.Decrease();
		SetCookie("textSize", tr.size, MAX_DAYS_TO_EXPIRE);
		return false;
	};
	tr.SetTextSize(CheckCookie());
}
// end page initialization and cleanup functions
/* ************************************************************************************ */


/* ************************************************************************************ */
// Set Search Criteria - CC
function setSearch(obj) {
		document.forms['siteSearch'].siteSearchInput.value = obj;
}
/* ************************************************************************************ */


Event.observe(window, "load", initTemplate, false);

/*if (window.addEventListener) //DOM method for binding an event
window.addEventListener("load", initTemplate, false)
else if (window.attachEvent) //IE exclusive method for binding an event
window.attachEvent("onload", initTemplate)
else if (document.getElementById) //support older modern browsers
window.onload=initTemplate
*/

/*
startList = function() {
if (document.all && document.getElementById) {
navRoot = document.getElementById("searchOpt");
navList = document.getElementById("searchList");
//alert(navRoot);
for (i=0; i<navRoot.childNodes.length; i++) {
  node = navRoot.childNodes[i];
// alert(node.nodeName);
  if (node.nodeName=="A") {
//  alert(node.nodeName);
  node.onmouseover=function() {
  navList.className+="over";
    }
  node.onmouseout=function() {
  navList.className=this.className.replace
      (" over", "");
   }
   }
  }
 }
}
window.onload=startList;


//-->
*/

function selPdf()
{
	document.frmPerformance.action="/download_form_disclaimer.asp";
	document.frmPerformance.submit();
}