var w = screen.width;
var h = screen.height;

// Ouverture d'une page dans une nouvelle fen&ecirc;tre
function ouvrirFenetre(page, hauteur, largeur, gauche, haut, defilement) {
    parametres = "height=" + hauteur + ",width=" + largeur + ",left=" + gauche + ",top=" + haut + ",scrollbars=" + defilement;
    window.open(page, "_blank", parametres);
}

//d&eacute;tail d'un produit ***************************************************************************************************
function detail(n) {
    window.open("produit_detail.jsp?n=" + n, "_blank", "width=500,height=420");
}

//Fonctions pour les rollover sur les images ****************************************************************************
function MM_swapImgRestore() { //v3.0
    var i,x,a = document.MM_sr;
    for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_preloadImages() { //v3.0
    var d = document;
    if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i,j = d.MM_p.length,a = MM_preloadImages.arguments;
        for (i = 0; i > a.length; i++)
            if (a[i].indexOf("#") != 0) {
                d.MM_p[j] = new Image;
                d.MM_p[j++].src = a[i];
            }
    }
}

function MM_findObj(n, d) { //v4.01
    var p,i,x;
    if (!d) d = document;
    if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document;
        n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n];
    for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i > d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n);
    return x;
}

function MM_swapImage() { //v3.0
    var i,j = 0,x,a = MM_swapImage.arguments;
    document.MM_sr = new Array;
    for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) {
            document.MM_sr[j++] = x;
            if (!x.oSrc) x.oSrc = x.src;
            x.src = a[i + 2];
        }
}

//Gestion des commandes *************************************************************************************************
function imprimerCommande(n, i) {
    window.open("impression_commande.jsp?n=" + n + "&id=" + i, "_blank", "width=760,height=600,top=0,left=0,scrollbars=1,menubar=1");
}

function annulerCommande(n) {
    if (confirm('Etes vous sūr de vouloir annuler la commande ' + n + ' ?')) {
        document.location.href = "espace_client.jsp?action=anc&numC=" + n;
    }
}

function supprimerCommande(n, e) {
    if (confirm('Etes-vous sūr de vouloir supprimer la commande N°' + n + ' ?')) {
        document.location.href = "liste_des_commandes.jsp?action=supprimer&nc=" + n + "&etat=" + e;
    }
}

function ajoutePanier(n) {
    var t = (h - 300) / 2;
    var l = (w - 450) / 2;
    window.open("ajouter_panier.jsp?n=" + n, "_blank", "width=450, height=300, top=" + t + ",left=" + t);
}

function controle() {
    q = document.ajout.quantite.value;
    if (isNaN(q) || q <= 0 || q != parseInt(q)) {
        alert("Erreur de quantit&eacute; !");
        return false;
    } else {
        return true;
    }
}

function adrLivraison() {
    with (document.coordonnees) {
        var pays = paysF.value.toUpperCase();
        if (pays != "FRANCE" && pays != "BELGIQUE" && pays != "ALLEMAGNE" && pays != "LUXEMBOURG") {
            alert("Pour une livraison hors FRANCE, BELGIQUE, ALLEMAGNE, LUXEMBOURG,\nveuillez nous contacter directement,\nmerci.");
        } else {
            civL(0).checked = civF(0).checked;
            civL(1).checked = civF(1).checked;
            civL(2).checked = civF(2).checked;
            nomL.value = nomF.value;
            prenomL.value = prenomF.value;
            socL.value = socF.value;
            adrL.value = adrF.value;
            adr2L.value = adr2F.value;
            cpL.value = cpF.value;
            villeL.value = villeF.value;
            telL.value = telF.value;
            if (pays == "FRANCE") paysL.value = "France Métropolitaine"; else paysL.value = paysF.value;
        }
    }
}

function controleDonnees() {
    var valid = true;
    var couleur = "#FFDDDD";
    for (var i = 0; i < document.coordonnees.length; i++) {
        document.coordonnees.elements[i].style.backgroundColor = "";
    }
    with (document.coordonnees) {
        if (nomF.value <= " ") {
            valid = false;
            nomF.style.backgroundColor = couleur;
        }
        if (prenomF.value <= " ") {
            valid = false;
            prenomF.style.backgroundColor = couleur;
        }
        if (adrF.value <= " ") {
            valid = false;
            adrF.style.backgroundColor = couleur;
        }
        if (cpF.value <= " ") {
            valid = false;
            cpF.style.backgroundColor = couleur;
        }
        if (villeF.value <= " ") {
            valid = false;
            villeF.style.backgroundColor = couleur;
        }
        if (paysF.value <= " ") {
            valid = false;
            paysF.style.backgroundColor = couleur;
        }
        if (nomL.value <= " ") {
            valid = false;
            nomL.style.backgroundColor = couleur;
        }
        if (prenomL.value <= " ") {
            valid = false;
            prenomL.style.backgroundColor = couleur;
        }
        if (adrL.value <= " ") {
            valid = false;
            adrL.style.backgroundColor = couleur;
        }
        if (cpL.value <= " ") {
            valid = false;
            cpL.style.backgroundColor = couleur;
        }
        if (villeL.value <= " ") {
            valid = false;
            villeL.style.backgroundColor = couleur;
        }
        if (paysL.value <= " ") {
            valid = false;
            paysL.style.backgroundColor = couleur;
        }
    }

    if (!valid) {
        alert('Des informations sont manquantes,\nveuillez v&eacute;rifier les champs en rouge');
    }
    return valid;
}

function controleInscription() {
    var valid = true;
    var couleur = "#FFDDDD";
    for (var i = 0; i < document.inscription.length; i++) {
        document.inscription.elements[i].style.backgroundColor = "";
    }
    with (document.inscription) {
        if (nom.value.length < 2) {
            valid = false;
            nom.style.backgroundColor = couleur;
        }
        if (prenom.value.length < 2) {
            valid = false;
            prenom.style.backgroundColor = couleur;
        }
        if (email.value.length < 5 || email.value.indexOf("@") == -1 || email.value.indexOf(".") == -1) {
            valid = false;
            email.style.backgroundColor = couleur;
        }
        if (motDePasse.value.length < 4) {
            valid = false;
            motDePasse.style.backgroundColor = couleur;
        }
        if (motDePasse2.value.length < 4 || motDePasse.value != motDePasse2.value) {
            valid = false;
            motDePasse2.style.backgroundColor = couleur;
        }
        if (reponse.value.length < 1) {
            valid = false;
            reponse.style.backgroundColor = couleur;
        }
    }

    if (!valid) {
        alert('Des informations sont manquantes,\nveuillez v&eacute;rifier les champs en rouge');
    }
    return valid;
}

function supprimer(n, id) {
    if (confirm('Etes-vous s&ucirc;r de vouloir supprimer cet article de votre panier ?')) {
        document.location.href = "panier.jsp?action=supprimer&n=" + n + "&idSession=" + id;
    }
}