function toggle(section_id) {
	if(document.getElementById(section_id).style.display) {
		document.getElementById(section_id + "-img").src = "/images/details-open.gif";
		document.getElementById(section_id).style.display = '';
	}
	else {
		document.getElementById(section_id + "-img").src = "/images/details-closed.gif";
		document.getElementById(section_id).style.display = 'none';
	}
}

function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

if (typeof XMLHttpRequest == "undefined" && window.ActiveXObject){
	function XMLHttpRequest ()	{
		var arrSignatures = ["MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
		for (var i=0; i < arrSignatures.length; i++)		{
			try			{
				var oRequest = new ActiveXObject(arrSignatures[i]);
				return oRequest;
			} catch (oError) {
				//ignore
			}
		}
		throw new Error("MSXML is not installed on your system.");
	}
}

function newXMLRequest() {
	var xmlhttp=false;
	if (typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}

	return(xmlhttp);
}

function formAsString(form) {
	var form_string = "";

	for(var i = 0; i < form.elements.length; i++) {
		switch(form.elements[i].type) {
			case "text" :
			case "hidden" :
			case "hidden" :
			case "textarea" :
			case "password" :
			case "button" :
			case "submit" :
				form_string += form.elements[i].name + "=" + escape(form.elements[i].value) + "&";
				
				break;

			case "select-one" :
				form_string += form.elements[i].name + "=" + form.elements[i].options[form.elements[i].selectedIndex].value + "&";
				
				break;
			
			case "select-multiple" :
				form_string += form.elements[i].name + "=";

				for(var x = 0; x < form.elements[i].length; x++)
					if(form.elements[i].options[x].selected)
						form_string += form.elements[i].options[x].value + ",";
				
				if(form_string.substr(form_string.length - 1, form_string.length) == ",")
					form_string = form_string.substr(0, form_string.length - 1);
				
				form_string += "&";
				break;
			
			case "checkbox" :
			case "radio" :
				form_string += form.elements[i].name + "=";

				if(form.elements[i].checked)
					form_string += form.elements[i].value + ",";
				
				if(form_string.substr(form_string.length - 1, form_string.length) == ",")
					form_string = form_string.substr(0, form_string.length - 1);
				
				form_string += "&";
				break;
		}
	}

	form_string = form_string.substr(0, form_string.length - 1);
	return form_string;
}

function getMousePos(oEvent) {
	var oPos = {x:0, y:0};

	if(typeof oEvent == "undefined") oEvent = window.event;
	if(typeof oEvent.pageX == "undefined" || typeof oEvent.pageY == "undefined") {
		oEvent.pageX = oEvent.clientX + document.body.scrollLeft;
		oEvent.pageY = oEvent.clientY + document.body.scrollTop;
	}

	oPos.x = oEvent.pageX;
	oPos.y = oEvent.pageY;

	return oPos;
}

function trim(string) {
	return string.replace(/^\s+(.*?)\s+$/, "$1");
}

function printWindow(in_path, selection)
{
	var query = /\?/;
	var select = '';
	if(selection != null)
		select = '&select=' + selection;

	if(!query.test(in_path))
		openit = window.open(in_path + "?print=true" + select, 'openit', 'width=800,height=725,left=30,top=20,resizable,scrollbars');
	else
		openit = window.open(in_path + "&print=true" + select, 'openit', 'width=800,height=725,left=30,top=20,resizable,scrollbars');
	openit.focus();
}

function restorePrintButton()
{
	document.getElementById('print_button').style.visibility = 'visible';
}
