var http = createRequestObject();




function createRequestObject()
{
    var ro;
    ro = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
    return ro;
}




function handleResponse()
{
    if(http.readyState == 4) {
        var response = http.responseText;
        var update = new Array();

        if(response.indexOf('|') != -1) {
            update = response.split('|');
            document.getElementById(update[0]).innerHTML = update[1];
        }
    }
}




function writediv(texte)
{
    document.getElementById('ShortNameShop').innerHTML = texte;
}




function file(fichier)
{
    if(window.XMLHttpRequest) // FIREFOX
        xhr_object = new XMLHttpRequest();
    else if(window.ActiveXObject) // IE
        xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
    else
        return(false);
        xhr_object.open("GET", fichier, false);
        xhr_object.send(null);

        if(xhr_object.readyState == 4) {
            return(xhr_object.responseText);
        } else {
            return(false);
        }
}




function GetIdCountry()
{
    var ID_Country = document.getElementById('countryList').options[document.getElementById('countryList').selectedIndex].value;
    return ID_Country;
}




function GetIdState()
{
    var ID_State = document.getElementById('stateList').options[document.getElementById('stateList').selectedIndex].value;
    return ID_State;
}




function sndReq(param, param2)
{
    var IdCountry = GetIdCountry();
    http.open('get', './ajax.php?param='+param+'&ID_Country='+IdCountry+'&param2='+param2);
    http.onreadystatechange = handleResponse;
    http.send(null);
}




function sndReq1(param, param1)
{
    http.open('get', './ajax.php?param='+param+'&param1='+param1);
    http.onreadystatechange = handleResponse;
    http.send(null);
}




function sndReq2(param, param2)
{
    var IdState = GetIdState();
    http.open('get', './ajax.php?param='+param+'&ID_State='+IdState+'&param2='+param2);
    http.onreadystatechange = handleResponse;
    http.send(null);
}




function accountGeoData(param1, param2, param3, param4)
{

    var id = document.getElementById(param2).options[document.getElementById(param2).selectedIndex].value;
    http.open('get', './ajax.php?id='+id+'&param='+param1+'&param2='+param2+'&param3='+param3+'&param4='+param4);
    http.onreadystatechange = handleResponse;
    http.send(null);
}




function listCountry(param)
{
    http.open('get', './ajax.php?param='+param);
    http.onreadystatechange = handleResponse;
    http.send(null);
}




function basketTotalGen(param, frais, ttc)
{
    http.open('get', './ajax.php?param='+param+'&frais='+frais+'&ttc='+ttc);
    http.onreadystatechange = handleResponse;
    http.send(null);
}




function viewPaymentInfo(param, ID_PaymentType)
{
    http.open('get', './ajax.php?param='+param+'&cp='+ID_PaymentType);
    http.onreadystatechange = handleResponse;
    http.send(null);
}




function verrifData(field, msgAlertNumber)
{
    var fieldValue = document.getElementById(field).value;

    return_result = file('./ajax.php?param=verrifData&field='+field+'&value='+fieldValue+'&msgAlert='+msgAlertNumber);
    //writediv('Msg_'+field, text);

    if (return_result > 0) {
        if (return_result == 1) {
            alert('Cette adresse email est deja presente dans notre base, veuillez en choisir une autre. Merci');
        }
    }
}

