function ajax()
{
	var httpReq;
	if (window.XMLHttpRequest)
	{
		httpReq = new XMLHttpRequest();
	}
	else
	{
		try
		{
			httpReq = new ActiveXObject('MSXML2.XMLHTTP');
		}
		catch(e)
		{
			try
			{
				httpReq = new ActiveXObject('Microsoft.XMLHTTP');
			}
			catch(e){}
		}
	}
	if(!httpReq)
	{
		httpReq = "No funciona";
	}
	return httpReq;
}

function llamaAjax(url,elem,val,met)
{
	var a = ajax();
	var cont = document.getElementById(elem);
	//Caso de usar POST:
	if(met.toUpperCase() == 'POST')
	{
		a.open ('POST', url, true);
		a.onreadystatechange = function()
		{
			if(a.readyState == 1)
			{
				cont.innerHTML = "Loading...";
			}
			else if(a.readyState == 4)
			{
				if(a.status == 200)
				{
					cont.innerHTML = a.responseText;
				}
				else if(a.status == 404)
				{
					cont.innerHTML = "La direccion no existe";
				}
				else
				{
					cont.innerHTML = "Error: " + a.status;
				}
			}
		}
		a.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		a.send(val);
		return;
	}
	//Caso de usar GET:
	if (met.toUpperCase() == 'GET')
	{
		a.open ('GET', url, true);
		a.onreadystatechange = function()
		{
			if (a.readyState == 1)
			{
				cont.innerHTML = "Loading.......";
			}
			else if (a.readyState == 4)
			{
				if(a.status == 200)
				{
					cont.innerHTML = a.responseText;
				}
				else if(a.status == 404)
				{
					cont.innerHTML = "La direccion no existe";
				}
				else
				{
					cont.innerHTML = "Error: " + a.status;
				}
			}
		}
	a.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	a.send(null);
	return;
	}
} 