
// implement selectNodes and selectSingleNode
if (!window.ActiveXObject) {
	
	Element.prototype.selectNodes = function(sXPath) {
		var oEvaluator = new XPathEvaluator();
		var oResult = oEvaluator.evaluate(sXPath, this, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
		var aNodes = new Array();
		if (oResult != null) {
			var oElement = oResult.iterateNext();
			while(oElement) {
				aNodes.push(oElement);
				oElement = oResult.iterateNext();
			}
		}
		return aNodes;
	}

	Element.prototype.selectSingleNode = function(sXPath) {
		var oEvaluator = new XPathEvaluator();
		// FIRST_ORDERED_NODE_TYPE returns the first match to the xpath.
		var oResult = oEvaluator.evaluate(sXPath, this, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
		if (oResult != null) {
			return oResult.singleNodeValue;
		} else {
			return null;
		}              
	}

}

// Search site
function checkSearchFields(objForm)
{	
		if(trim(objForm.keywords.value) == "") {
			alert("Please enter your keyword(s)");
			objForm.keywords.focus();
			return false;
		}
		else {
			return true;
		}
}

// 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';
}

//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

function showGallery() {
	if (window.location.href.indexOf("document_1") != -1) {
		window.location = window.location.href.replace("document_1", "document_gallery_1");
	} else if (window.location.href.indexOf("news_1") != -1) {
		window.location = window.location.href.replace("news_1", "news_gallery_1");
	}
}

/*** keep alive ***/
document.write("<script type=\"text/javascript\" src=\"/assets/scripts/EdeptiveAjax.js\"></script>");
var goAjax = null;
function keepAlive() {
	var strUrl = "";

	strUrl = window.location.protocol + "//" + window.location.host + "/webservices/keep_alive.asmx/Ping";
	goAjax = new EdeptiveAjax();
	goAjax.postRequest(strUrl, "", onKeepAliveResponse);
}
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);

function toggle(e) {
	if (!e) var e = window.event;
	if (e.target) targ = e.target; else if (e.srcElement) targ = e.srcElement;
	var oThis = targ.parentNode.parentNode; // span->a->li
	var oNext = oThis.firstChild.nextSibling;
	if(oNext) {
		oNext.style.display = (oNext.style.display != "block" ? "block" : "none");
	}
	return false;
}
function nullFn() {
	return false;
}
function setupMenuToggles() {
	var oMenu = document.getElementById("submenu"); // ul
	if(oMenu != null) {
		for(var i = 0; i < oMenu.childNodes.length; i++) {
			var oItem = oMenu.childNodes[i];
			if(oItem.childNodes.length > 1) {
				oItem.firstChild.onclick = toggle;
			}
		}
	}
}

function onDomReady(funcToCall) {
		if (document.addEventListener) {
            document.addEventListener("DOMContentLoaded", funcToCall, false);
        } else {
            document.write("<scr" + "ipt id='__ieinit' defer='true' " + "src='//:'><\/script>");
            var script = document.getElementById("__ieinit");
            script.onreadystatechange = function() {
                if (this.readyState != "complete") return;
                this.parentNode.removeChild(this);
                funcToCall();
            }
            script = null;
        }
};

onDomReady(setupMenuToggles);


