// Check to see if in text only mode
if (GetCookie("textonly")) {
	textOnly(true);	
}


// top of page
function backToTop() {
    var x1 = x2 = x3 = 0;
    var y1 = y2 = y3 = 0;

    if (document.documentElement) {
        x1 = document.documentElement.scrollLeft || 0;
        y1 = document.documentElement.scrollTop || 0;
    }

    if (document.body) {
        x2 = document.body.scrollLeft || 0;
        y2 = document.body.scrollTop || 0;
    }

    x3 = window.scrollX || 0;
    y3 = window.scrollY || 0;

    var x = Math.max(x1, Math.max(x2, x3));
    var y = Math.max(y1, Math.max(y2, y3));

    window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));

    if (x > 0 || y > 0) {
        window.setTimeout("backToTop()", 25);
    }
}

// Print web page
function printpage() {
	window.print();
}


function graphicVersion() {
	DeleteCookie("textonly");
	window.location.reload(true);
}

// Set to text only version
function textOnly(mode) {
	
	  
	  // Set & Delete cookie
	  if (mode) {
	  	SetCookie("textonly","1");
		disableStyle();
		disableInlineStyles();
	  }
	  else {
		DeleteCookie("textonly");
	   }
}

// top of page
function backToTop() {
    var x1 = x2 = x3 = 0;
    var y1 = y2 = y3 = 0;

    if (document.documentElement) {
        x1 = document.documentElement.scrollLeft || 0;
        y1 = document.documentElement.scrollTop || 0;
    }

    if (document.body) {
        x2 = document.body.scrollLeft || 0;
        y2 = document.body.scrollTop || 0;
    }

    x3 = window.scrollX || 0;
    y3 = window.scrollY || 0;

    var x = Math.max(x1, Math.max(x2, x3));
    var y = Math.max(y1, Math.max(y2, y3));

    window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));

    if (x > 0 || y > 0) {
        window.setTimeout("backToTop()", 25);
    }
}

//Suckerfish JavaScript menu
sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

if (window.attachEvent) window.attachEvent("onload", sfHover); 

function markListDaddies(parentElement) {
	var listItem, listItems, link;
	
	if (typeof(parentElement) == "string") {
		parentElement = document.getElementById(parentElement);
	}
	
	listItems = parentElement.getElementsByTagName("LI");

	cleanUpIds(parentElement);
	
	for (var i = 0; i < listItems.length; i++) {
		listItem = listItems[i];
		if (listItem.parentNode.tagName == "UL" && listItem.parentNode.parentNode.tagName != "LI") continue;
		if (listItem.getElementsByTagName("UL").length > 0) {
			link = listItem.getElementsByTagName("A")[0];
			link.className = (link.className ? link.className + " " : "") + "daddy";
		}
	}
}

function cleanUpIds(elem, foundFirst) {
	if (elem.id == "nav") {
		if (foundFirst) {
			elem.id = "";
		} else {
			foundFirst = true;
		}
	}
	if (elem.childNodes) {
		for (var i = 0; i < elem.childNodes.length; i++) {
			cleanUpIds(elem.childNodes[i], foundFirst);
		}
	}
}
	
// Search site
function checkSearchFields(objForm)
{	
		if(trim(objForm.keywords.value) == "" | trim(objForm.keywords.value) == "Site Search...") {
			alert("Please enter your keyword(s)");
			objForm.keywords.value = '';
			objForm.keywords.focus();
			return false;
		}
		else {
			return true;
		}
}

// Gallery
function doGalleryClick(iFullID, iImageNumber) {
	var strType = '';
	var strPage = window.location.pathname;
	var iItemID = iFullID.substring(0, iFullID.lastIndexOf(":"));
	
	strPage = strPage.substring(0, strPage.indexOf("_1.aspx"));
	if(strPage.toLowerCase().indexOf("news_gallery") != -1) {
		strType = "news";
		window.location = window.location.href + "&img_num=" + iImageNumber;
	}
	else if(strPage.toLowerCase().indexOf("gallery") != -1) {
		strType = "doc";
		window.location = window.location.href + "&" + strType + "=" + iItemID + "&img_num=" + iImageNumber;
	}
	
}

// Show & Hide
function show(c) {
	if (document.getElementById && document.getElementById(c)!= null) 
		node = document.getElementById(c).style.display='block'; 
	else if (document.layers && document.layers[c]!= null) 
		document.layers[c].display = 'block'; 
	else if (document.all && document.all(c)!= null) 
		document.all[c].style.display = 'block';
} 

function hide(c) {	
	if (document.getElementById && document.getElementById(c)!= null)
		node = document.getElementById(c).style.display='none';
	else if (document.layers && document.layers[c]!= null) 
		document.layers[c].display = 'none';
	else if (document.all && document.all(c)!= null) 
		document.all[c].style.display = 'none';
}

// Cookie functions
function getCookieVal (offset) {  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1)    
	endstr = document.cookie.length;  
	return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
	var j = i + alen;    
	if (document.cookie.substring(i, j) == arg)      
	return getCookieVal (j);    
	i = document.cookie.indexOf(" ", i) + 1;    
	if (i == 0) break;   
	}  
	return null;
}
function SetCookie (name, value) {  
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + path)) +  
	((domain == null) ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) {  
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	var cval = GetCookie (name);  
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
// End Cookie functions

//Trim string
function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}
//End Function

//Right Trim string
function rtrim(str)
{
	return str.replace(/\s*$/, ""); 
}
//End Function

//Left Trim string
function ltrim(str)
{
	return str.replace(/^\s*/, ""); 
}
//End Function

// mozXPath [http://km0ti0n.blunted.co.uk/mozxpath/] km0ti0n@gmail.com
// Code licensed under Creative Commons Attribution-ShareAlike License 
// http://creativecommons.org/licenses/by-sa/2.5/
if( document.implementation.hasFeature("XPath", "3.0") )
{
	XMLDocument.prototype.selectNodes = function(cXPathString, xNode)
	{
		if( !xNode ) { xNode = this; } 

		var oNSResolver = this.createNSResolver(this.documentElement)
		var aItems = this.evaluate(cXPathString, xNode, oNSResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
		var aResult = [];
		for( var i = 0; i < aItems.snapshotLength; i++)
		{
			aResult[i] =  aItems.snapshotItem(i);
		}
		
		return aResult;
	}
	XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode)
	{
		if( !xNode ) { xNode = this; } 

		var xItems = this.selectNodes(cXPathString, xNode);
		if( xItems.length > 0 )
		{
			return xItems[0];
		}
		else
		{
			return null;
		}
	}

	Element.prototype.selectNodes = function(cXPathString)
	{
		if(this.ownerDocument.selectNodes)
		{
			return this.ownerDocument.selectNodes(cXPathString, this);
		}
		else{throw "For XML Elements Only";}
	}

	Element.prototype.selectSingleNode = function(cXPathString)
	{	
		if(this.ownerDocument.selectSingleNode)
		{
			return this.ownerDocument.selectSingleNode(cXPathString, this);
		}
		else{throw "For XML Elements Only";}
	}

}

/*** keep alive ***/
document.write("<script type=\"text/javascript\" src=\"assets/scripts/EdeptiveAjax.js\"></script>");
var goAjax = null;
function keepAlive() {
	var strUrl = "";
	var sTiming = document.lastChild.lastChild.innerHTML;
	var sParams = "";

	sTiming = sTiming.substring(sTiming.lastIndexOf("<!--"));
	sTiming = sTiming.substring(5, sTiming.indexOf(" -->"));
	strUrl = window.location.protocol + "//" + window.location.host + "/webservices/keep_alive.asmx/PingWithTiming";
	sParams = "Timing=" + sTiming;
	try {
		goAjax = new EdeptiveAjax();
		goAjax.postRequest(strUrl, sParams, onKeepAliveResponse);
	} catch(e) {
		setTimeout("keepAlive()", 1000*1);
	}
}
function onKeepAliveResponse() {
	if(goAjax.checkReadyState("keepAlive", "ping.", "ping..", "ping...") == "OK") {
		if(document.getElementById("keepAlive")) {
			var response = goAjax.request.responseXML.documentElement;
			document.getElementById("keepAlive").innerText = "sid=" + getText(response.firstChild);
		}
		setTimeout("keepAlive()", 1000*60);
	}
}
setTimeout("keepAlive()", 1000*2);
