var agt = navigator.userAgent.toLowerCase();
var is_ie5 = (agt.indexOf('msie 5') != -1);

// Create the XML HTTP request object. We try to be more cross-browser as possible.
function CreateXmlHttpReq(target)
{
	var xmlhttp = false;
	if (window.XMLHttpRequest)			// Mozilla, Safari,...
	{
		xmlhttp = new XMLHttpRequest();
		if (xmlhttp.overrideMimeType)
			xmlhttp.overrideMimeType('text/html; charset=windows-1252');
	}
	else if (window.ActiveXObject)		// IE
	{
		try
		{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	xmlhttp.onreadystatechange = function ()
		{
			if (ajax_req.readyState == 4 && ajax_req.status == 200)
			{
				var result = ajax_req.responseText;
				document.getElementById(target).innerHTML = result;
			}
		}
	return xmlhttp;
}

function ajaxGet(url,target) {
    ajax_req = CreateXmlHttpReq(target);
	ajax_req.open('GET',url);
	ajax_req.send(null);
}

function getPosY(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;
}

function getReplace(url, target, set_scroll)
{
	var h = document.createElement("span");
	h.id = "check_loaded";
	h.style.display = "none";
	document.getElementById(target).appendChild(h);
	
	ajaxGet(url, target);
	if (set_scroll == '1')
	{
		var posy = getPosY(document.getElementById(target));
		window.scroll(0, posy);
	}
}

function open_box(url, obj_id, force_open, set_scroll)
{
	obj = document.getElementById(obj_id);
	var d = obj.style.display;
	if ((d == "none") || (force_open == "1"))
	{
		getReplace(url, obj_id, set_scroll);
		d = "block";
	}
	else
		d = "none";
	obj.style.display = d;
}