
function a(a) {return document.getElementById(a);}

function canAjax() {
    if(window.XMLHttpRequest || window.ActiveXObject) return true;
    return false;
}

function isLoading(status) {
    if (a('load')) a('load').style.visibility=status?'visible':'hidden';
}

function xmlGetObject() {
    xmlo=null;
    if (window.XMLHttpRequest) {// FF
        xmlo = new XMLHttpRequest();
    } else if(window.ActiveXObject) {// IE
        xmlo = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
        alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
    }
    return xmlo;
}


function xmlGet(eltid,script) {
    var xhro = xmlGetObject(); //création de l'obket xmlhttp
    if (xhro==null) return; //si impossible, on sort
    isLoading(true);
    xhro.open("GET", script, true);
    xhro.onreadystatechange = function() {
        if(xhro.readyState == 4) {
            eltid.innerHTML=(xhro.responseText);
            isLoading(false);
        }
    }
    xhro.send(null);
}
// la même avec perso du txt wait
function xmlGetWithWaitMsg(eltid,script,msg) {
    xmlGet(eltid,script);
}
// le meme avec une callback func
function xmlGetWithFunc(eltid,script,func) {
    var xhro = xmlGetObject(); //création de l'obket xmlhttp
    if (xhro==null) return; //si impossible, on sort
    isLoading(true);
    xhro.open("GET", script, true);
    xhro.onreadystatechange = function() {
        if(xhro.readyState == 4) {
            eltid.innerHTML=(xhro.responseText);
            isLoading(false);
            func();
        }
    }
    xhro.send(null);
}
function xmlPost(eltid,script,postdata) {
    var xhro = xmlGetObject();
    if (xhro==null) return;
    isLoading(true);
    xhro.open("POST", script, true);
    xhro.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xhro.send(postdata);
    xhro.onreadystatechange = function() {
        if(xhro.readyState == 4) {
            eltid.innerHTML=(xhro.responseText);
            isLoading(false);
        }
    }
}
