function myAjax()
{ 

	var xmlhttp=false;
	try
	{
		// Creacion del objeto AJAX para navegadores no IE
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			// Creacion del objet AJAX para IE
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(E)
		{
			if (!xmlhttp && typeof XMLHttpRequest!='undefined') xmlhttp=new XMLHttpRequest();
		}
	}
	return xmlhttp; 
}

function email(id,ruta,contenedor){
main=contenedor;
		//creamos  objeto ajax 
		var contenedor=document.getElementById(main);
		var ajax_cesta=myAjax();		
		ajax_cesta.open("GET", ruta+"&id="+id+"&capa="+main, true);
		ajax_cesta.onreadystatechange=function() 
		{ 
			if (ajax_cesta.readyState==1) {
            	contenedor.innerHTML="Cargando.......";
         	}
         	else if (ajax_cesta.readyState==4){
                   if(ajax_cesta.status==200){
                      document.getElementById(main).innerHTML=ajax_cesta.responseText;
                   }
                   else if(ajax_cesta.status==404)
                                             {

                            contenedor.innerHTML = "La direccion no existe";
                                             }
                                             else
                                             {
                            contenedor.innerHTML = "Error: ".ajax_cesta.status;
                                             }
           }                  
		}
		ajax_cesta.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		ajax_cesta.send(null);
}

function FAjax (url,capa,valores,metodo)
{
          var ajax=myAjax();
          var capaContenedora = document.getElementById(capa);

/*Creamos y ejecutamos la instancia si el metodo elegido es POST*/
if(metodo.toUpperCase()=='POST'){
         ajax.open ('POST', url, true);
         ajax.onreadystatechange = function() {
         if (ajax.readyState==1) {
                          capaContenedora.innerHTML="Cargando.......";
         }
         else if (ajax.readyState==4){
                   if(ajax.status==200)
                   {
                        document.getElementById(capa).innerHTML=ajax.responseText;
                   }
                   else if(ajax.status==404)
                                             {

                            capaContenedora.innerHTML = "La direccion no existe";
                                             }
                           else
                                             {
                            capaContenedora.innerHTML = "Error: ".ajax.status;
                                             }
                                    }
                  }
         ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
         ajax.send(valores);
         return;
}
}
