var objXHR = null;
var currentRow = 0;
var currentType = 0;

function createXhrObject()
{
    if (window.XMLHttpRequest)
        return new XMLHttpRequest();
 
    if (window.ActiveXObject)
    {
        var names = [
            "Msxml2.XMLHTTP.6.0",
            "Msxml2.XMLHTTP.3.0",
            "Msxml2.XMLHTTP",
            "Microsoft.XMLHTTP"
        ];
        for(var i in names)
        {
            try{ return new ActiveXObject(names[i]); }
            catch(e){}
        }
    }
    window.alert("Warning: XmlHttpRequest not supported.\nUpdates on database would be failed");
    return null; // non supporté
}
objXHR = createXhrObject();

function requestBlocStatus(idPeople, idBloc, status)
{
    var ret = -1;    
    if (objXHR == null)
        return ret;
    var url = 'Contents/Ajax/WriteBlocStatus.aspx';
    var params = "idPeople="+encodeURIComponent(idPeople)+"&idBloc="+encodeURIComponent(idBloc)+"&status="+encodeURIComponent(status);
    objXHR.open('POST', url, true);
    objXHR.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    objXHR.setRequestHeader("Content-length", params.length);
    objXHR.setRequestHeader("Connection", "close");
    objXHR.onreadystatechange = managestatechange;       
    try {
        objXHR.send(params);
        ret = 1;
    }
    catch (e) {        
        var xmlDoc = objXHR.responseXML;
        var info_node = xmlDoc.getElementsByTagName('info').item(0).childNodes[0];
        var errMessage = info_node.firstChild.data;
        alert("Could not perform the update at this time\n" + errMessage);
    }        
    return ret;
}

function managestatechange()
{
    if (objXHR == null)
        return;
    switch (objXHR.readyState) {
        case 2: // loading
        case 3: 
            break;
        case 4: // end of the request
        {
            if (objXHR.status == 200 || window.location.href.indexOf("http") == -1)
            {              
            }
            break;
        }
    }	    
}