// JavaScript Document

// AJAX REQUEST
// url : Url to request
// id : Html id where put the content
function AjaxRequest(url, id)
{
	var xmlhttp = GetXmlHttpObject();
	if (xmlhttp == null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	xmlhttp.onreadystatechange = function() 
	{
		if (xmlhttp.readyState != 4) { return; }
		var html = xmlhttp.responseText;
		
		if (id != "" && id != null)
			document.getElementById(id).innerHTML = html;
			
		if (html.indexOf("<script>") >= 0)
		{
			// Executes the script in html
			var v1 = html.indexOf("<script>");
			var v2 = html.indexOf("</script>");
			var script = html.substr(v1 + 8, v2 - v1 - 8);
			eval(script);
		}
	};
	if (id != "" && id != null)
		document.getElementById(id).innerHTML = "<br><div align='center'><img src='img/loading.gif'></div><br>";	
		
	url += url.indexOf("?") >= 0 ? "&" : "?";
	url += "sid=" + Math.random();
	xmlhttp.open("GET", url, true);
	xmlhttp.send(null);
}

function ChangeContent(id, content)
{
	document.getElementById(id).innerHTML = content;
}

function ShowContent(id, value)
{
	document.getElementById(id).style.visibility = value;
}

// GETS THE HTTPREQUEST
function GetXmlHttpObject()
{
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject)
	{
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}
