/**
    Retourne un objet de type XMLHttpRequest
    @return objet de type XMLHttpRequest
*/
function getXhr() {
    var xhr = null; 
    if (window.XMLHttpRequest) // Firefox et autres
       xhr = new XMLHttpRequest(); 

    else if (window.ActiveXObject) { // Internet Explorer 
       try {
            xhr = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            xhr = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    else { // XMLHttpRequest non supporte par le navigateur 
       alert("Votre navigateur ne supporte pas les technologies ajax."); 
       xhr = false; 
    } 
    return xhr;
}

function getLoadingDiv( div ) {
    var height = document.getElementById(div).clientHeight;
    var width = document.getElementById(div).clientWidth;
    if (height == 0)
        height = 24;
    
    var padding_top = (height - 50) / 2;
    var padding_left = (width - 75) / 2;
    var s = "<form><div style='margin:0px;padding-left:" + padding_left + "px; padding-top:" + padding_top + "px; height:" + height + "px; vertical-align:middle;text-align:left'><img src='img/loading.gif' /> chargement</div></form><br/>";
    //alert(s);
    return s;
}

function clearWin(id) {
    document.getElementById(id).innerHTML = "";
}

function postXhr(url, strParam, divResponse) {
    document.getElementById(divResponse).innerHTML = getLoadingDiv( divResponse );
    postXhrSansImg(url, strParam, divResponse);
}

function justPostAndFunction(url, strParam, myFunction) {
    var xhr = getXhr();
    xhr.onreadystatechange = function() {
	// On demande confirmation en affichant le nom de l'entreprise prete � etre supprimee
	if (xhr.readyState == 4 && xhr.status == 200) {
                myFunction();
        }
    }
    xhr.open("POST", url, true);
    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

    xhr.send(strParam);
}


function postXhrSansImg(url, strParam, divResponse) {
    var xhr = getXhr();
    xhr.onreadystatechange = function() {
	// On demande confirmation en affichant le nom de l'entreprise prete � etre supprimee
	if (xhr.readyState == 4 && xhr.status == 200) {
                document.getElementById(divResponse).innerHTML = xhr.responseText;                
        }
    }
    xhr.open("POST", url, true);
    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

    xhr.send(strParam);
}



function postXhrWithMenu(url, strParam, divResponse, divMenu) {
    var xhr = getXhr();
    document.getElementById(divResponse).innerHTML = getLoadingDiv( divResponse );
    xhr.onreadystatechange = function() {
	// On demande confirmation en affichant le nom de l'entreprise prete � etre supprimee
	if (xhr.readyState == 4 && xhr.status == 200) {
                document.getElementById(divResponse).innerHTML = xhr.responseText; 
                initializetab(divMenu);
                breadCrumb();
        }
    }
    xhr.open("POST", url, true);
    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

    xhr.send(strParam);
}


function postXhrWithMenuAndFunction(url, strParam, divResponse, divMenu, myFunction) {
    var xhr = getXhr();
    document.getElementById(divResponse).innerHTML = getLoadingDiv( divResponse );
    xhr.onreadystatechange = function() {
	// On demande confirmation en affichant le nom de l'entreprise prete � etre supprimee
	if (xhr.readyState == 4 && xhr.status == 200) {
                document.getElementById(divResponse).innerHTML = xhr.responseText; 
                myFunction();
                initializetab(divMenu);                
        }
    }
    xhr.open("POST", url, true);
    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

    xhr.send(strParam);
}

function postXhrAndFunction(url, strParam, divResponse, myFunction) {
    var xhr = getXhr();
    document.getElementById(divResponse).innerHTML = getLoadingDiv( divResponse );
    xhr.onreadystatechange = function() {
	// On demande confirmation en affichant le nom de l'entreprise prete � etre supprimee
	if (xhr.readyState == 4 && xhr.status == 200) {
                document.getElementById(divResponse).innerHTML = xhr.responseText; 
                myFunction();
        }
    }
    xhr.open("POST", url, true);
    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

    xhr.send(strParam);
}


function alterWinBox(win, titre) {
    new Win(win, titre, true);
}

function getBureauBox() {    
    new Win("winConsult", "Bureau", true);
    initializetab("tabXpControl");
}


function postXhrAndDisplay(url, strParam) {
    var xhr = getXhr();
    xhr.onreadystatechange = function() {
	// On demande confirmation en affichant le nom de l'entreprise prete � etre supprimee
	if (xhr.readyState == 4 && xhr.status == 200) {
                displayClose( xhr.responseText );
        }
    }
    xhr.open("POST", url, true);
    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

    xhr.send(strParam);
}



function postXhrAndDisplayAndFunction(url, strParam, myFunction) {
    var xhr = getXhr();
    xhr.onreadystatechange = function() {
	// On demande confirmation en affichant le nom de l'entreprise prete � etre supprimee
	if (xhr.readyState == 4 && xhr.status == 200) {
                displayClose( xhr.responseText );
                myFunction();
        }
    }
    xhr.open("POST", url, true);
    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

    xhr.send(strParam);
}

