var peticion = false; 

if (window.XMLHttpRequest) 
	{
     	peticion = new XMLHttpRequest();
     } else if (window.ActiveXObject) 
	 	{
         	peticion = new ActiveXObject("Microsoft.XMLHTTP");
		}

function Get(url,capa) 
	{ 
		if(peticion) 
			{
     			// Capa en la que cargaremos la url
				var obj = document.getElementById(capa); 
				
    			// Abrimos la petición con el método GET
				peticion.open("GET", encodeURI(url));
				// Realizamos la petición
     			peticion.onreadystatechange = function()  
					{ 
          				if (peticion.readyState == 4) 
							{ 
               					// Si se ha cargado la información
								obj.innerHTML = decodeURI(peticion.responseText);
								cargandoAjax(true);
          					} else {
								// Si todavía no se ha cargado
								cargandoAjax(false);
							}
     				} 
				peticion.send(null); 
			}
	}
function Post(formulario,destino,capa) 
	{ 	
		if(peticion) 
			{
     			// Capa en la que cargaremos la url
				var obj = document.getElementById(formulario); 
		
				// Recorremos el formulario y construimos la url
				url = destino + "?";
				incremento = 0;
				for(i=0;i<obj.length;i++)
					{
						comprueba = compruebaForm(i,formulario);
						if(comprueba!="") 
							{ 
								if(incremento>0) { url+="&";}
								incremento++;
								url+= comprueba;
							}
					}
				
    			// Abrimos la petición con el método POST
				peticion.open("POST", encodeURI(url));
				peticion.setRequestHeader("Method", "POST " + url + " HTTP/1.1");
        		peticion.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
				// Realizamos la petición
     			peticion.onreadystatechange = function()  
					{ 
          				if (peticion.readyState == 4) 
							{ 
               					// Si se ha cargado la información
								obj.innerHTML = decodeURI(peticion.responseText);
								cargandoAjax(true);
          					} else {
								// Si todavía no se ha cargado
								cargandoAjax(false);
							}
     				} 
				peticion.send(null); 
			}		
	}

function cargandoAjax(estado)
	{
		// Capa en la que mostramos la precarga
		carga = document.getElementById("cargando");
		
		if(estado==false)
			{
				carga.style.display = "block";
			} else {
				carga.style.display = "none";				
			}
	}
function compruebaForm(campo,formulario)
	{
		obj = document.getElementById(formulario)
		tipo = obj[campo];
		valor = "";
		
		// Si el campo es de tipo text
		if(tipo.type == "text" || tipo.type == "password" ||  
			tipo.type == "textarea" || tipo.type == "hidden" ||
			tipo.type == "submit" || tipo.type == "reset" || tipo.type == "button")
			{
				if(tipo.value!="") 
					{ 
						valor = tipo.name + "=" + tipo.value;
					} 
			} else if(tipo.type == "checkbox" || tipo.type == "radio")
			{
				if(tipo.checked) 
					{ 
						valor = tipo.name + "=" + tipo.value;
					} 
			}
		
		return valor;
	}