//
//
//

var xhttp = null; 
var xhttp_busy = false; 
var xtarget = '';

function getXHttp() 
{
	if (!xhttp) {
		// Probamos con IE
		try
		{
			// Funcionará para JavaScript 5.0
			xhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				xhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(oc)
			{   
				xhttp = null;
			}
		}
	}
	
	if (!xhttp) {
		// Probamos con el resto
		try {
			xhttp = new XMLHttpRequest();
		}
		catch (e) {
			xhttp = null;
		}
	}
	
	return xhttp;
}

function handleXmlHttpResponse()
{
	if (xhttp.readyState == 4) {
		//document.getElementById(xupdate).innerHTML = 'analyzing response ...';
		if (xhttp.status == 200) {
			document.getElementById(xupdate).innerHTML = 'ok!';
			document.getElementById(xupdate).innerHTML = xhttp.responseText;
		}
		else {
			//document.getElementById(xupdate).innerHTML = 'xmlhttp response status = '+xhttp.status.toString();
		}
		xhttp_busy = false;
		
	}
}

function XHttpGET(url)
{
	if (!xhttp_busy) {
		getXHttp();
		if (xhttp) {
			xhttp.open("GET",url,true);
			xhttp.onreadystatechange = handleXmlHttpResponse;
			//xmlHttp.setRequestHeader('Content-Type', 'application/text');
			//document.getElementById(xupdate).innerHTML = 'waiting ...';
			xhttp_busy = true;
			xhttp.send(null);
		}
		else
			document.getElementById(xupdate).innerHTML = 'XMLHttp not found!';
	}
}

function XHttpUpdate(id,url)
{
	if (!xhttp_busy) {
		xupdate = id;
		document.getElementById(xupdate).innerHTML = '(consultando ...)';
		XHttpGET(url);
	}
}

function XQueryUpdate(id,query)
{
	XHttpUpdate(id,query);
}

