
//~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·
// XMLHTTPREQUEST
//~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·
//funcURL = URL de la llamada, funcName = nombre de la función a llamar, funcNameParam = parametros para la función a llamar, 
//funcXML = true/false si queremos que devuelva text o xml, funcMethod = post/get/head, funcAsincrono = true/false si es asincrono, funcObj = nombre del objecto (this)
function WSGC_xmlHttpRequest(funcURL, funcName, funcNameParam, funcXML, funcMethod, funcAsincrono, funcObj, funcParamPost) 
{
    surl = document.location.href;
	
	//bGcampsa = false;
	//if (surl.indexOf("file:") > -1 || surl.indexOf("guiacampsa.com") > -1 || surl.indexOf("http://localhost") > -1 || surl.indexOf("repsolypf.com") > -1 || surl.indexOf("http://guiat") > -1)
		bGcampsa = true;
	
	//if (!bGcampsa) 
	//	return false;
	

	if (funcParamPost == "undefined" || !funcParamPost)
		funcParamPost = null;

	if (window.XMLHttpRequest) 
	{
		var req = new XMLHttpRequest();
		req.onreadystatechange = function processReqChange()
		{
			if (req.readyState == 4) 
			{
				if (req.status == 200) 
				{
					if (funcName != "")
					{
						if (funcXML == true)
							eval(funcName+"('"+funcNameParam+"', req.responseXML, funcObj)");
						else
							eval(funcName+"('"+funcNameParam+"', req.responseText, funcObj)");
						return;
					}
					else
					{
						if (funcXML)
							return req.responseXML;
						else
							return req.responseText;
					}
				} 
				else 
				{
					//alert(funcURL + "/nError obteniendo los datos:\n El servidor dice: " + req.statusText + " (" + req.status + ")");
				}
			}
		}
		//Metodo de peticion
		if (funcMethod == "POST")
		{
			req.open("POST", funcURL, funcAsincrono);
			req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
			req.send(funcParamPost);
		}
		else
		{
			req.open("GET", funcURL, funcAsincrono);
			req.send(null);
		}
			
	} 
	else if (window.ActiveXObject) 
	{
		var req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) 
		{
			req.onreadystatechange = processReqChange;

			if (funcMethod == "POST")
			{
				req.open("POST", funcURL, funcAsincrono);
				req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
				req.send(funcParamPost);
			}
			else
			{
				req.open("GET", funcURL, funcAsincrono);
				req.send(null);
			}
		}
	}
	else
	{
		alert("No hay compatibilidad con XMLHTTPRequest");
	}
}
//-----------------------------------------------------------------------------
