XHR = new Array;

function cXHR(){ 
    var XHR=false; 
    if (window.ActiveXObject){
        XHR=new ActiveXObject("Microsoft.XMLHTTP");
    }
    else if(window.XMLHttpRequest){
        XHR = new XMLHttpRequest();
    }
    
    if(XHR)
        return XHR;
    else 
        alert("Error: AJAX no funciona en su navegador actualicelo.");
}



function ajax(id_div,URL_a_cargar) {
	n=XHR.length;
	XHR[n]=cXHR(); 
	XHR[n].open( "GET", URL_a_cargar , true );
	XHR[n].onreadystatechange=function(){
                   if (XHR[n].readyState==4)	
                      if (XHR[n].status==200) { 
                        document.getElementById(id_div).innerHTML = XHR[n].responseText; 
                        XHR[n]="";
                      }
                      else if(XHR[n].status==404) alert("Error: La página llamada con AJAX no existe");
                           else alert("Error "+XHR[n].status+": "+XHR[n].statusText);}
        XHR[n].send(null);}

