document.write("<script type=\"text/javascript\" src=\"assets/scripts/EdeptiveAjax.js\"></script>");
// Print web page
function printpage() {
	window.print();
}

// 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;
		}
}

// 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


// Toggle Div
function ToggleDiv(id) {
	var contentitem = document.getElementById('ci' + id);
	contentitem.style.display = (contentitem.style.display  != "none" ? "none" : "block");
}

function checkScroll() {
	var value = varName = "";
	var contentVars = ["doc", "news", "event", "cat", "property"];
	var qs = getQs();
	var thisUrl = location.href.replace(/&(admin|doc|news|event|cat|property)=[^&]*/gi, "");
	var tempUrl;
	var pos, i , j;
	var qs2;
	
	for (i = 0; i < contentVars.length; i++) {
		varName = contentVars[i];
		value = qs[varName];
		if (value) {
			break;
		}
	}
	if (varName && value) {
		pos = getAnchorPosition(varName + value);
		if (pos && (pos.y > windowScroll().y + windowSize().height || pos.y < windowScroll().y)) {
			scrollTo(0, pos.y);
		}
	}
	
	// search for any links to items on this page
	for (i = 0; i < document.links.length; i++) {
		tempUrl = document.links[i].href;
		if (tempUrl.replace(/&(admin|doc|news|event|cat|property)=[^&]*/gi, "") == thisUrl) {
			value = null;
			qs2 = getQs(tempUrl.substr(tempUrl.indexOf("?")));
			for (j = 0; j < contentVars.length; j++) {
				varName = contentVars[j];
				value = qs2[varName];
				if (value) {
					pos = getAnchorPosition(varName + value);
					if (pos && (pos.y > windowScroll().y + windowSize().height || pos.y < windowScroll().y)) {
						document.links[i].href = "javascript:scrollTo(0, " + pos.y + ")";
					}
					break;
				}
			}
		}
	}
	
}

function getAnchorPosition(anchorName) {
	var coords = null, anchor;
	
	if (document.anchors) {
		for(var i = 0; i < document.anchors.length; i++) {
			if (anchorName == document.anchors[i].name) {
				anchor = document.anchors[i];
			}
		}
	}
	else if (document.getElementById) {
		anchor = document.anchors[anchorName];
	}
	if (anchor) {
		coords = findPos(anchor);
	}
	return coords;
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return { "x": curleft, "y": curtop };
}

function getQs(searchString) {
	var qsParams = new Object();
	searchString = searchString || window.location.search;
	var parms = searchString.substring(1).split('&');
	for (var i=0; i<parms.length; i++) {
		var pos = parms[i].indexOf('=');
		if (pos > 0) {
			var key = parms[i].substring(0,pos);
			var val = parms[i].substring(pos+1);
			qsParams[key] = val;
		}
	}
	return qsParams;
}

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;
        }
};

function windowSize() {
	var myWidth = 0, myHeight = 0;
	if(typeof(window.innerWidth ) == 'number') {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return { "width": myWidth, "height": myHeight };
}

function windowScroll() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return { "x": scrOfX, "y": scrOfY };
}


onDomReady(checkScroll);


//Returns string with binary notation of n bytes, rounded to 2 decimal places
function num2bytes(n)
{
   if(n<=0)
   {  return '0 Bytes';
   }
   var bSize=Array('Bytes', 'KB', 'MB', 'GB'); // add higher powers as appropriate: 'TB', 'PB', 'EB', 'ZB', 'YB'
   for(var i=bSize.length-1; i>=0; i--)
   {  if(n>=Math.pow(1000, i))
      {  return Math.round((n/Math.pow(1024, i))*100)/100+' '+bSize[i];
      }
   }
}

/*** search on another site ***/
var goAjaxSearch = null;
var gsSearchDivID = "";
function searchOtherSite(sDivID, iClientID, sKeywords, sXslFile) {
	var sUrl = "", sParams = "";

	sUrl = window.location.protocol + "//" + window.location.host + "/webservices/search.asmx/DoSearchFormatted";
	sParams = "ClientID=" + iClientID;
	sParams += "&Keywords=" + sKeywords;
	sParams += "&XslUrl=" + sXslFile;
	gsSearchDivID = sDivID;
	goAjaxSearch = new EdeptiveAjax();
	goAjaxSearch.postRequest(sUrl, sParams, onSearchResponse);
}
function onSearchResponse() {
	if(goAjaxSearch.checkReadyState(gsSearchDivID, ".", "..", "...") == "OK") {
		if(document.getElementById(gsSearchDivID)) {
			var response = goAjaxSearch.request.responseXML.documentElement;
			//document.getElementById(gsSearchDivID).insertAdjacentHTML("afterEnd", response.text);
			document.getElementById(gsSearchDivID).innerHTML = response.text;
		}
	}
}


/*** keep alive ***/
var goAjaxKeepAlive = null;
function keepAlive() {
	var sUrl = "";

	sUrl = window.location.protocol + "//" + window.location.host + "/webservices/keep_alive.asmx/Ping";
	goAjaxKeepAlive = new EdeptiveAjax();
	goAjaxKeepAlive.postRequest(sUrl, "", onKeepAliveResponse);
}
function onKeepAliveResponse() {
	if(goAjaxKeepAlive.checkReadyState("keepAlive", "ping.", "ping..", "ping...") == "OK") {
		if(document.getElementById("keepAlive")) {
			var response = goAjaxKeepAlive.request.responseXML.documentElement;
			document.getElementById("keepAlive").innerText = "sid=" + getText(response.firstChild);
		}
		setTimeout("keepAlive()", 1000*60);
	}
}
setTimeout("keepAlive()", 1000*2);
