var ie = document.all;
var ie5 = false;
var ie6 = false;
var ie7 = false;
var ns = document.layers;
getagent();

function getagent(){
    var agent = navigator.userAgent.toLowerCase();
    var amajor = parseInt(navigator.appVersion);
    var aie = ((agent.indexOf('msie') != -1) && (agent.indexOf('opera') == -1));
    var offsetie6 = 0;
    if (aie && (amajor == 4)) {
        var tie = agent.split(';');
        var ver = 0;
        for(var k = 0; k < tie.length; k++) {
            if (tie[k].indexOf('msie') != -1) {
                xx = tie[k].replace(/msie/g,'');
                ver = xx.replace(/ /g,'');
                k = tie.length;
            }
        }
        if (ver < 6) {ie5 = true;}
        if ((ver >= 6) && (ver < 7)) {ie6 = true;}
        if (ver >= 7) {ie7 = true;}
    }
}

function OpenWin(URL, width, height, nom) {
	window.open(URL, nom, "toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,width=" + width + ",height=" + height + ",resizable=no");
}

function OpenWin2(URL, width, height, nom) {
	window.open(URL, nom, "toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,width=" + width + ",height=" + height + ",resizable=yes");
}

function transfertP(URL) {
  window.open(URL);
}

function Max (a, b){if (a > b) {return a;} else {return b;}}
function Min (a, b){if (a < b) {return a;} else {return b;}}
function AfficheMaxi(URL1, URL2, nom_jv, CSS, withOnLoad) {
    var nom = stripslashes(nom_jv);
    image = new Image; 
    image.src = URL1 + URL2;
    if (withOnLoad == '1') {
        image.onload = function(){  
            largeur = Max(Min(image.width+40, screen.width-10),160); 
            hauteur = Min(image.height+63, screen.height-25); 
            var html = '<html><head><title>Zoom</title><link rel="stylesheet" type="text/css" href="' + CSS + '"></head><body bgcolor="#772B4E"><div style="text-align:center;"><div style="text-align:left; background-color:black;" class="jauneik">&nbsp;&nbsp;&nbsp;&nbsp;<b>' + nom + '</b></div><div style="margin-top:10px;"><img src="' + URL1 + URL2 + '"></div><div style="margin-top:10px;"><a href="javascript:close();"><img src="' + URL1 + '/images/b_fermer.png"></div></body></html>';
            popupImage = window.open('', '_blank', 'toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=1, width='+largeur+', height='+hauteur+', left=180, top=50');
            popupImage.document.open();
            popupImage.document.write(html);
            popupImage.document.close();
        } 
    } else {
        largeur = Max(Min(image.width+40, screen.width-10),160); 
        hauteur = Min(image.height+63, screen.height-25); 
        var html = '<html><head><title>Zoom</title><link rel="stylesheet" type="text/css" href="' + CSS + '"></head><body bgcolor="#772B4E"><div style="text-align:center;"><div style="text-align:left; background-color:black;" class="jauneik">&nbsp;&nbsp;&nbsp;&nbsp;<b>' + nom + '</b></div><div style="margin-top:10px;"><img src="' + URL1 + URL2 + '"></div><div style="margin-top:10px;"><a href="javascript:close();"><img src="' + URL1 + '/images/b_fermer.png"></div></body></html>';
        popupImage = window.open('', '_blank', 'toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=1, width='+largeur+', height='+hauteur+', left=180, top=50');
        popupImage.document.open();
        popupImage.document.write(html);
        popupImage.document.close();
    }
}

function AfficheStock(P1) {
  var html = '<html><head><meta http-equiv="Refresh" content="0; URL=' + P1 + '"></head><body bgcolor="#772B4E" leftMargin="0" topMargin="0" rightMargin="0" bottomMargin="0" marginheight="0" marginwidth="0">&nbsp;</body></html>';
  popupImage = window.open('', '_blank', 'toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=1, width=300, height=30, left=180, top=50');
  popupImage.document.open();
  popupImage.document.write(html);
  popupImage.document.close();
  popupImage.document.focus();
}

function AfficheW(P1) {
  var html = '<html><head><meta http-equiv="Refresh" content="0; URL=' + P1 + '"></head><body bgcolor="#772B4E" leftMargin="0" topMargin="0" rightMargin="0" bottomMargin="0" marginheight="0" marginwidth="0">&nbsp;</body></html>';
  popupImage = window.open('', '_blank', 'toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=1, width=300, height=30, left=50, top=50');
  popupImage.document.open();
  popupImage.document.write(html);
  popupImage.document.close();
  popupImage.document.focus();
}

function expandingWindow(website, id_author) {
    var id_auth = id_author;
    var sizer = window.open('', '_blank', 'toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=1, width=400, height=350, left=70, top=50');
    sizer.location = website + "?id_auth=" + id_auth;
}

function stripslashes(ch) {
  return ch.replace(/(\\)([\\\'\"])/g,"$2");
}
    
var ns6 = document.getElementById && !document.all;

function restrictinput(maxlength, e, placeholder){
    if (window.event && event.srcElement.value.length >= maxlength)
        return false;
    else if (e.target && e.target == eval(placeholder) && e.target.value.length >= maxlength){
        var pressedkey=/[a-zA-Z0-9\.\,\/]/ 
        if (pressedkey.test(String.fromCharCode(e.which)))
        e.stopPropagation();
    }
}

function countlimit(maxlength, e, placeholder){
    var theform = eval(placeholder);
    var lengthleft = maxlength - theform.value.length;
    var placeholderobj = document.all ? document.all[placeholder] : document.getElementById(placeholder);
    if (window.event || e.target && e.target == eval(placeholder)){
        if (lengthleft < 0)
            theform.value = theform.value.substring(0,maxlength);
            placeholderobj.innerHTML = lengthleft;
    }
}

function displaylimit(thename, theid, thelimit){
    var theform = theid != "" ? document.getElementById(theid) : thename;
    var limit_text = '<b><span id="' + theform.toString() + '">' + thelimit + '</span></b>';
    if (document.all || ns6) document.write(limit_text)
    if (document.all){
        eval(theform).onkeypress = function(){ return restrictinput(thelimit,event,theform)}
        eval(theform).onkeyup = function(){ countlimit(thelimit,event,theform)}
    }
    else if (ns6){
        document.body.addEventListener('keypress', function(event) { restrictinput(thelimit, event, theform) }, true); 
        document.body.addEventListener('keyup', function(event) { countlimit(thelimit, event, theform) }, true); 
    }
}

function divswitch(checkboxId, baliseId) {
    if (document.getElementById && document.getElementById(checkboxId) != null) {
        if (document.getElementById(baliseId) != null) {
            if (document.getElementById(checkboxId).checked == true) {
                document.getElementById(baliseId).style.visibility = 'visible';
                document.getElementById(baliseId).style.display = 'block';
            }
            else
            {
                document.getElementById(baliseId).style.visibility = 'hidden';
                document.getElementById(baliseId).style.display = 'none';
            }
        }
    }
}

function sel_divswitch(selectorValue, selectorId, baliseId) {
    if (document.getElementById && document.getElementById(selectorId) != null) {
        if (document.getElementById(baliseId) != null) {
            if (document.getElementById(selectorId).value == selectorValue) {
                document.getElementById(baliseId).style.visibility = 'visible';
                document.getElementById(baliseId).style.display = 'block';
            }
            else
            {
                document.getElementById(baliseId).style.visibility = 'hidden';
                document.getElementById(baliseId).style.display = 'none';
            }
        }
    }
}

function rb_divswitch(radioId, baliseId) {
    if (document.getElementById && document.getElementById(radioId) != null) {
        if (document.getElementById(baliseId) != null) {
            if (document.entryform.paiement[1].checked == true) {
                document.getElementById(baliseId).style.visibility = 'visible';
                document.getElementById(baliseId).style.display = 'block';
            }
            else
            {
                document.getElementById(baliseId).style.visibility = 'hidden';
                document.getElementById(baliseId).style.display = 'none';
            }
        }
    }
}

function getscroll(rsID){
    if (document.documentElement.scrollTop == 0) {
        document.getElementById("_RS"+rsID).value = document.body.scrollTop;
    } else {
        document.getElementById("_RS"+rsID).value = document.documentElement.scrollTop;
    }
}

function Scroller(y) {
    window.scrollTo(0,y);
}

function affiche(id, oui_non) {
  var element_style = null;
  if (document.getElementById) {
    element_style = document.getElementById(id).style;
  } else if (document.all) {
    element_style = document.all[id].style;
  } 
  if (element_style) {
     if (oui_non == true) element_style.display = "inline";
     if (oui_non == false) element_style.display = "none";
  } 
}

function get_total(totalId, nbline) {
    var thetotal = 0;
    var q = 0;
    var p = 0;
    var tot = 0;
    for (cnt = 1; cnt < nbline+1; cnt++){
        q = document.getElementById("qte"+cnt).value;
        p = document.getElementById("prix"+cnt).value;
        tot = q * p;
        thetotal += tot;
    }
    document.getElementById(totalId).innerHTML = thetotal;
}

function printPage() {
    if (typeof(window.print) != 'undefined') {
        window.print();
    }
}

function getid(what){    
    if(document.layers){ where = eval("document." + what); }    
    if(document.all){ where = eval("document.all." + what); }    
    if(!document.all && document.getElementById){ where = eval("document.getElementById('" + what + "')" ); }    
    return where;
} 

function arrondi(nombre, chiffre) {
    virgule = Math.pow(10,chiffre);
    valeur_arrondi = (Math.round(nombre*virgule))/virgule;
    return (valeur_arrondi);
}

function convertchamps(champs) {
    valeur_sans_espaces = champs.replace(/\s/g,"");
    valeur_sans_virgule = valeur_sans_espaces.replace(/,/,".");
    valeur_convertie = parseFloat(valeur_sans_virgule);
    return (valeur_convertie);
}

function avecvirgule(champs) {
    return (champs.replace(".",","));
}

function distXY(coor) {
    //retourne la distance X ou Y
    var scrOfX = 0, scrOfY = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }

    switch (coor) {
        case('X'):
        case('x'):
            return scrOfX;
            break;
        case('Y'):
        case('y'):
            return scrOfY;
            break;
    }
}

function enlarge(which, si, e, xheight, img_height){
    e = e || window.event;
    var xheight = (xheight === null) ? 2 : xheight;
    var img_height = (img_height === null) ? 150 : img_height;
    var c = (c === null) ? 100 : c;    
    var cdx = 0;
    var cdy = 0;
    var offsetie6 = 0;
    
    if (ie||ns6){
        if (ie6) {offsetie6 = -210;}
        crossobj = document.getElementById ? document.getElementById(si) : document.all.showimage;
        if (crossobj.style.visibility == "hidden"){
            cdx = distXY('x'); 
            cdy = distXY('y'); 
            crossobj.style.left = (cdx + e.clientX + 30 + offsetie6) + "px";
            crossobj.style.top = (cdy + e.clientY - (img_height - 50)) + "px";
            crossobj.innerHTML = '<img src="' + which + '" width="' + (100 * xheight) + '" alt="">';
            crossobj.style.visibility = "visible";
            fSwapSelect(si); 
        }
        else {
            crossobj.style.visibility = "hidden";
            fSwapSelect(si); 
            return false;
        }
    }
    else if (document.layers){
        if (document.showimage.visibility == "hide"){
            document.showimage.document.write('<a href=JavaScript: onMouseover="drag_dropns(showimage)"><img src="' + which + '" width="' + (100 * xheight) + '" border=0></a>');
            document.showimage.document.close();
            document.showimage.left = e.x;
            document.showimage.top = e.y;
            document.showimage.visibility = "show";
        }
        else {
            document.showimage.visibility = "hide";
            return false;
        }
    }
    else {
        return true;
    }        
}

function closepreview(si){
    crossobj.style.visibility = "hidden";
    fSwapSelect(si); 
}

fDomOffset = function(oObj, sProp) {
    var iVal = 0;
    while (oObj && oObj.tagName != 'BODY') {
        eval('iVal += oObj.' + sProp + ';');
        oObj = oObj.offsetParent;
    }
    return iVal;
}

fSwapSelect = function(sId) { 
    oObj = document.getElementById(sId); 
    Top_Element  = fDomOffset(oObj, 'offsetTop'); 
    Left_Element  = fDomOffset(oObj, 'offsetLeft'); 
    Largeur_Element = oObj.offsetWidth; 
    Hauteur_Element = oObj.offsetHeight; 
    oSelects = document.getElementsByTagName('SELECT'); 
    if (oSelects.length > 0) { 
        for (i = 0; i < oSelects.length; i++) { 
            oSlt = oSelects[i]; 
            Top_Select = fDomOffset(oSlt, 'offsetTop'); 
            Left_Select = fDomOffset(oSlt, 'offsetLeft'); 
            Largeur_Select = oSlt.offsetWidth; 
            Hauteur_Select = oSlt.offsetHeight; 
            isLeft = false; 
            if ((Left_Element > (Left_Select - Largeur_Element)) && (Left_Element < (Left_Select + Largeur_Select))) { 
                isLeft = true; 
            } 
            isTop = false; 
            if ((Top_Element > (Top_Select - Hauteur_Element)) && (Top_Element < (Top_Select + Hauteur_Select))) { 
                isTop = true; 
            } 
            if (isLeft && isTop) { 
                sVis = (oObj.style.visibility == 'hidden') ? 'visible' : 'hidden'; 
                if (oSlt.style.visibility != sVis) {oSlt.style.visibility = sVis;} 
            } else { 
                if (oSlt.style.visibility != 'visible') {oSlt.style.visibility = 'visible';} 
            } 
        } 
    } 
} 

function returnSize() {
    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if(document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    var result = new Array(myWidth,myHeight);
    return result;
}