
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);




// Check to see if in text only mode
if (GetCookie("textonly")) {
	textOnly(true);	
}

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");
	   }
}

// new onload
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}



// Suckerfish JavaScript menu
sfHover = function() {
	if (document.getElementById || document.getElementById("nav") != null) {
		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"), "");
			}
		}
	}
}

//ie 6 nav fix
if (window.attachEvent) window.attachEvent("onload", sfHover); 

// onload
addLoadEvent(function() {
 
});


// Change Language for Language College
function changeLanguage(oSelect) {
	var strUrl = window.location.toString();
	
	strUrl = strUrl.replace(/\&language\=\d*/i, "");
	if(strUrl.indexOf(".asp") == -1) {
		// domain only
		strUrl = "language_college_1.aspx?id=0:35755&id=0:35635&language=" + oSelect.options[oSelect.selectedIndex].value;
	} else {
		strUrl += "&language=" + oSelect.options[oSelect.selectedIndex].value;
	}
	window.location = strUrl;
}
	
// Search site
function checkSearchFields(objForm)
{	
		if(trim(objForm.keywords.value) == "") {
			alert("Please enter your keyword(s)");
			objForm.keywords.focus();
			return false;
		}
		else {
			return true;
		}
}

// Open the Gallery template passing in the url params
function viewGallery(strPage) {

	var strQuery = strPage.substr(strPage.indexOf("?"));
	var strPage = strPage.substring(0, strPage.indexOf("_1.aspx"));
	
	if(strPage.toLowerCase().indexOf("language_") != -1) {
		strPage = "language_gallery";	
	}
	else {
		// set gallery as default
		strPage = "gallery";
	}
	window.location = strPage + "_1.aspx" + strQuery + "&back=1";
}

// Print web page
function printpage() {
	window.print();
}

// 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";}
	}

}


document.write("<script type=\"text/javascript\" src=\"assets/scripts/EdeptiveAjax.js\"></script>");
/*** keep alive ***/
var gsDomain = window.location.protocol + "//" + window.location.host;
var gfUsingIP = (((window.location.host.substring(0, 1) >= "0") && (window.location.host.substring(0, 1) <= "9")) || (window.location.host == "localhost"));
var gsFolder = "/";
if(gfUsingIP) {
	gsFolder = "/" + window.location.pathname.substring(1, window.location.pathname.indexOf("/", 1)) + "/";
}
gsDomain += gsFolder;
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 = gsDomain + "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);
