function debug() {
	var debugWindow = window.open("content/debug.html", "debug", "height=500,width=800,status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes");
}

function ajaxComplete() {} // empty function - do not delete

function ajaxScrollToFeedbackForm() {
	var e = document.getElementById(ajax.element);
	ajax.elementObj.innerHTML = ajax.response;
	e.style.visibility="visible";
	var y;
	var objBrowse = navigator.appName;
	if (objBrowse == "Microsoft Internet Explorer") {
		y = document.body.scrollHeight;
	} else {
		y = document.documentElement.scrollHeight;
	}
	window.scrollTo(0, y);
	try {
		document.getElementById('realname').focus();
	} catch (err) {}
}
	
function showTooltip(e, message) {
	var objX = Event.pointerX(e);
	var objY = Event.pointerY(e);
	var coordsArray = new Array(objX, objY);
	var tooltipDiv = $('tooltip');
	tooltipDiv.innerHTML = message;
	var dimensionsArray = tooltipDiv.getDimensions();
	$('tooltip').style.left = objX/1 - dimensionsArray.width/2 + "px";
	$('tooltip').style.top = objY/1 - dimensionsArray.height/1 - 10 + "px";
	$('tooltip').style.visibility = "visible";
}

function hideDiv() {
	$('tooltip').innerHTML = "";
	$('tooltip').style.visibility = "hidden";
}

function showflash(filelocation, mywidth, myheight) {
	showPopup('content/flash_popup.html', (mywidth/1 + 55), (myheight/1 + 110), new Array('filelocation', 'width', 'height'), new Array(filelocation, mywidth, myheight));
}

function showPopup(myLocation, w, h, attribKeys, attribValues) {
	var attribString = (attribKeys.length > 0)? "?" : "";
	var i;
	for (i = 0; i < attribKeys.length; i++) {
		attribString += attribKeys[i] + "=" + attribValues[i] + "&";
	}
	attribString = attribString.replace(/&$/g, '');
	if (typeof(myWindow) == "undefined" || myWindow.closed) { // second condition is a workaround for a problem in Mozilla
		myWindow = window.open(myLocation + attribString, null,'scrollbars=yes,toolbar=no,status=no,location=no,menubar=yes,resizable=yes,top=130,left=130,width=' + w + ',height=' + h + '');
	}
	myWindow.location = myLocation + attribString;
	myWindow.focus();
}

function initialisation()
{
    if (!window.opera) { writeFooter (); }

    if (window.opera)
    {
    document.FormName.WidthMinusScrollbar.value = window.innerWidth;
    document.FormName.HeightMinusScrollbar.value = window.innerHeight;
    }
    else if (document.layers)
    {
    window.captureEvents(Event.RESIZE) ;
    window.onresize = writeFooter ;
    }
    else if (document.all)
    {
    window.onresize = writeFooter ;
    }
    else if (window.addEventListener)
    {
    window.addEventListener("resize" , writeFooter , false) ;
    };
}

function writeFooter() {
	var height = Math.max(document.getElementById("content").clientHeight, document.getElementById("content").scrollHeight);
	if (height > 600) {
		document.getElementById("content_footer").style.visibility = "visible";
	}
}

//#######################################################
// ##### functions relating to the side navigation ######
// #####                                           ######

var expandoArr = new Array();
var expandoString = (getCookieVal("expando="));
expandoArr = expandoString.split(",");
if (isNaN(expandoArr[0]/1)) {
	expandoString = "";
	expandoArr = new Array();
}
function showHideNav(imgObj, ident) {
	if (imgObj.nodeName == "A") {
		imgObj = (imgObj.parentNode.previousSibling.nodeName == '#text')? imgObj.parentNode.previousSibling.previousSibling.firstChild : imgObj.parentNode.previousSibling.firstChild;
		if (imgObj.id != "plus" && imgObj.id != "plus_last") {
			return;
		}
	}
	switch (imgObj.id) {
		case ("plus") :
			imgObj.id = "minus";
			imgObj.src = "images/tree_menu_minus.gif";
			updateExpandoArr("add", ident);
			break;
		case ("minus") :
			imgObj.id = "plus";
			imgObj.src = "images/tree_menu_plus.gif";
			updateExpandoArr("remove", ident);
			break;
		case ("plus_last") :
			imgObj.id = "minus_last";
			imgObj.src = "images/tree_menu_minus_last.gif";
			updateExpandoArr("add", ident);
			break;
		case ("minus_last") :
			imgObj.id = "plus_last";
			imgObj.src = "images/tree_menu_plus_last.gif";
			updateExpandoArr("remove", ident);
			break;
	}
	var previousElement = imgObj;
	while (true) {
		previousElement = previousElement.parentNode;
		if (previousElement.nodeName == "TABLE") {
			var parentTableElement = previousElement;
			break;
		}
	}
	var spanElement = (parentTableElement.nextSibling.nodeName == "#text")? parentTableElement.nextSibling.nextSibling : parentTableElement.nextSibling;
	if (spanElement.style.display == "none") {
		//spanElement.id = "shown";
		spanElement.style.display = "block";
	}
	else {
		//spanElement.id = "hidden";
		spanElement.style.display = "none";
	}
}

function updateExpandoArr(methid, ident) {
	var identFound = false;
	var i;
	for (i = 0; i < expandoArr.length; i++) {
		if (expandoArr[i] == ident) {
			identFound = true;
			break;
		}
	}
	if (!identFound && methid == "add") {
		expandoArr.push(ident);
	}
	else if (identFound && methid == "remove") {
		expandoArr.splice(i, 1);
	}
	expandoString = expandoArr.toString();
	setCookieVal("expando", expandoString, "/");
}

// #####                                           ######
//#######################################################


// cookie handling methods
function getCookieVal(offset) {
	var start = document.cookie.indexOf(offset)+offset.length;
	var end = document.cookie.indexOf(";", start);
	if (end == -1) end = document.cookie.length;
	return unescape(document.cookie.substring(start, end));
}


// path should be set to whatever subfolder the site will eventually be contained within
function setCookieVal(cookieName, cookieValue, path) {
	//alert(cookieName + "=" + cookieValue);
	var expdate = new Date();
	expdate.setTime(expdate.getTime() + (1000*3600*3) ); // 1000ms*3600s*3h = 3hr
	document.cookie = cookieName + '=' + cookieValue + '; path=' + path;
}

function dosearch() {
	document.getElementById('secondarysearch').submit()
}