function sendHTTPObject(){
    var xmlhttp = false;
    
    /* Compilation conditionnelle d'IE */
    /*@cc_on
     @if (@_jscript_version >= 5)
     try
     {
     xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
     }
     catch (e)
     {
     try
     {
     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
     }
     catch (E)
     {
     xmlhttp = false;
     }
     }
     @else
     xmlhttp = false;
     @end @*/
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try {
            xmlhttp = new XMLHttpRequest();
        } 
        catch (e) {
            xmlhttp = false;
        }
    }
    
    if (xmlhttp) {
        xmlhttp.onreadystatechange = function(){
            if (xmlhttp.readyState == 4) {
                if (xmlhttp.status == 200) {
                    incrementCompteur();
                }
            }
        }
    }
    return xmlhttp;
}

function getHTTPObject(theDiv){
    var xmlhttp = false;

    /* Compilation conditionnelle d'IE */
    /*@cc_on
     @if (@_jscript_version >= 5)
     try
     {
     xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
     }
     catch (e)
     {
     try
     {
     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
     }
     catch (E)
     {
     xmlhttp = false;
     }
     }
     @else
     xmlhttp = false;
     @end @*/
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try {
            xmlhttp = new XMLHttpRequest();
        }
        catch (e) {
            xmlhttp = false;
        }
    }
    if (xmlhttp) {
        xmlhttp.onreadystatechange = function(){
            if (xmlhttp.readyState == 4) {
                if (xmlhttp.status == 200) {
                    document.getElementById(theDiv).innerHTML = xmlhttp.responseText;
                    return xmlhttp.responseText;
                }
            }
        }
    }
    return xmlhttp;
}

function ajaxSend(url){
    var xmlhttp = sendHTTPObject();
    xmlhttp.open("GET", url, true);
    xmlhttp.send(null);
}

function ajaxGet(url, div){
    var xmlhttp = getHTTPObject(div);
    xmlhttp.open("GET", url, true);
    xmlhttp.send(null);
    xmlhttp = undefined;
}

function ajaxCheck(url){
    var xmlhttp = sendHTTPObject();
    xmlhttp.open("GET", url, false);
    xmlhttp.send(null);
    return xmlhttp.responseText;
}

function ajouter(type, element){
	ajaxSend('scripts/ajouterpanier.php?type=' + type + '&element=' + element);
}

function incrementCompteur(){
	compteur++;
	if(compteur == 1){
		document.getElementById('elementsPanier').innerHTML = compteur + ' article';
	}
	else{
		document.getElementById('elementsPanier').innerHTML = compteur + ' articles';
	}
}

function selectOtheradress(){
    document.theForm.adresse[1].checked = true;
}

function resetOtheradress(){
    document.theForm.adresse_1.value = '';
    document.theForm.adresse_2.value = '';
    document.theForm.codepostal.value = '';
    document.theForm.ville.value = '';
    
}

function changeValue(type, element, valeur){
	ajaxSend('scripts/modifierpanier2.php?type=' + type + '&element=' + element + '&valeur=' + valeur);
	location.reload(true);
}
