

function OuvreFenetre(nom, fichier, hauteur, largeur) {
    window.open(fichier, nom, "location=0,status=0,menubar=0,resizable=0,scrollbars=0,width=" + largeur + ",height=" + hauteur);
}


function FermeFenetre(cible) {
    window.close();
    window.opener.location = cible;
}

function RetourPage() {
    window.history.back();
}

function InitScrollPosition() {
    document.cookie = "yPos=!~0~!";
}

function SetScrollPosition(element) {
    var strCook = document.cookie;
    if (strCook.indexOf("!~") != 0) {
        var intS = strCook.indexOf("!~");
        var intE = strCook.indexOf("~!");
        var strPos = strCook.substring(intS + 2, intE);
        try {
            document.getElementById(element).scrollTop = strPos;
        }
        catch (e) {
        }

    }
}

function GetScrollPosition(element) {
    var intY = document.getElementById(element).scrollTop;
    document.cookie = "yPos=!~" + intY + "~!";
}

function photoClick(img, path) {

    //   html = "<html> <head> <title>ImageMax</title> </head> <body onBlur='top.close()'>";
    //   html += "<IMG src='" + path + "' BORDER='0' NAME='ImageMax' Visible='true' onLoad='window.resizeTo(document.ImageMax.width+100, document.ImageMax.height+140)'/>";
    //   html += "</body></html>";
    //   popupImage = window.open('','_blank','toolbar=0,status=0, location=0, directories=0, menuBar=0, scrollbars=0, resizable=1');
    //   popupImage.document.open();
    //   popupImage.document.write(html);
    //   popupImage.document.close()

    document.getElementById(img).src = document.getElementById(path).src;
    document.getElementById(img).style.display = 'block';
}

function tailleClick(img, path) {

    document.getElementById(img).src = path;
    document.getElementById(img).style.display = 'block';
}

function photoOut(img) {
    document.getElementById(img).style.display = 'none';
}


function align() {

    var lmt = document.getElementById('corps');

    if (lmt) {
        var h = "-270px";
        var w = "-450px";

        if (document.documentElement.clientHeight > 500) {
            lmt.style.marginTop = h;
            lmt.style.top = "50%";
        }
        else {
            lmt.style.marginTop = "0";
            lmt.style.top = "0";
        }
        if (document.documentElement.clientWidth > 850) {
            lmt.style.marginLeft = w;
            lmt.style.left = "50%";
        }
        else {
            lmt.style.marginLeft = "0";
            lmt.style.left = "0";
        }
    }
}

function addevent(obj, evt, fn, capt) {
    if (obj.addEventListener) {
        obj.addEventListener(evt, fn, capt);
        return true;
    }
    else if (obj.attachEvent) {
        obj.attachEvent('on' + evt, fn);
        return true;
    }
    else return false;
}

var Timer;
var Pas = 6;

function moveLayer(Sens) {
    Objet = document.getElementById("ctl00_ContentCentre_content");
    if (parseInt(Objet.style.top) + (Pas * Sens) > 0) {
        clearTimeout(Timer);
    }
    else if (parseInt(Objet.style.top) + (Pas * Sens) < -(Objet.offsetHeight - document.getElementById("scroll").offsetHeight)) {
        clearTimeout(Timer);
    }
    else {
        Objet.style.top = (parseInt(Objet.style.top) + (Pas * Sens)) + "px";
    }
    Timer = setTimeout("moveLayer(" + Sens + ");", 30);
}

function CheckAll() {
    var table = document.getElementsByTagName("span");
    var all = document.getElementById("all");
    for (var i = 0; i < table.length; i++) {
        try {
            table.item(i).children(0).checked = all.checked;
        }
        catch (e) { }
    }
}


//compte à rebours


function disp_delai() {
    var combien = document.getElementById("ctl00_ContentCentre_Temps").innerHTML;
    var txt = delai(combien);
    //if (combien == "")
        //txt = "";
    if (txt != "") {
        document.getElementById("ctl00_ContentCentre_Compteur").innerHTML = "votre commande expire dans " + txt;
        setTimeout("disp_delai()", 100);
    }
    //else
        //window.location.href = "panier.aspx" + window.location.search;
}

function delai(combien) {
    var date_deb = new Date(combien) ;
    var date_jour = new Date();
    var tps = (date_deb.getTime() - date_jour.getTime()) / 1000;
    var j = Math.floor(tps / 3600 / 24);     	// récupere le nb de jour
    tps = tps % (3600 * 24);
    var h = Math.floor(tps / 3600); 	// recupère le nb d'heure
    tps = tps % 3600;
    var m = Math.floor(tps / 60); 	// récupère le nb minute
    tps = tps % 60
    var s = Math.floor(tps);

    var txt = m + " minutes et " + s + " secondes";
    if (tps<0)
        txt = "";
    return txt;
}



function SortieFrame(page) {
    window.opener.top.location.href = page;
    window.close();
}


$(document).ready(function() {

    // fonction check all
    $("#all").click(function(sender) {
        var pos = this.checked;
        $("input[type='checkbox'][name*=$GridView1$]").each(function() {
            this.checked = pos;
        });
    });
});
