function creaxmlhttp() {
	var xmlhttp = false;

	try{
		xmlhttp = new ActiveXObject("Msxm12.XMLHTTP");
	}catch (e){
		try{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(E){
			xmlhttp = false;
		}
	}

	if(!xmlhttp && typeof XMLHttpRequest != 'undefined'){
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function peticion(url,capa,valores,metodo){	
	var ajax = creaxmlhttp();
	var id = document.getElementById(capa);
	
	if(metodo.toUpperCase() == 'POST'){
		ajax.open(metodo,url,true);
		ajax.onreadystatechange = function() {
         if (ajax.readyState == 1) {
	         id.innerHTML="<br><br><center>Cargando..<br><br><IMG SRC='imagenes/cargando.gif'></center>";
			 //id.style.background = "url('espera.gif') no-repeat";
         }
         else if (ajax.readyState==4){
             if(ajax.status == 200) {
		        id.innerHTML=ajax.responseText;
				//id.style.background = "url('nieve1.jpg') no-repeat";
             }
             else if(ajax.status == 404) {
			     id.innerHTML = "La direccion no existe";
             }
             else {
				 estado = ajax.status;
                 id.innerHTML = "Error....".estado; //.ajax.status;                      }
             }
		}
     }
     ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
     ajax.send(valores);
     return;
	}
	
}
