
/* - Fonction : Equalcols height
   ------------------------------------*/
function equalHeight(group, important) {
    tallest = 0;
    important = (important == false ? "" : " !important");
    group.each(function() {
        thisHeight = jQuery(this).height();
        if(thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.attr("style", "height:" + tallest + "px" + important + ";");
}
function clearEqualHeight(group) {
	group.each(function() {
        jQuery(this).css("height","");
    });
}

/* -- Fonctions gestion des popups DIV
-------------------------------------------*/
function ShowBoxAjax(id, anchor, focus) {
    HideAllBoxes();
    $("#" + id).show();

    if (focus == true || typeof (focus) == 'undefined')
        $("#" + id + " input:text:visible:first").focus();

    if (anchor && anchor != "")
        window.location = '#' + anchor;
}
function HideBoxAjax(id) {
    $("#" + id).hide();
    //$("#recevez_discussion").attr('checked', false);
}
function HideAllBoxes() {
    //$("#recevez_discussion").attr('checked', false);
    $("div.boite_ajax").hide();
    $("div.overlay").hide();
}

/*----------------------------------------------------------------------------*/
// Detection des vieux navigateurs
/*----------------------------------------------------------------------------*/
function OldBrowserDetect() {
    if (jQuery.browser.mozilla && jQuery.browser.version.substr(0, 3) < "1.9")//Firefox 2.0 et moins
        return true;
    else if (jQuery.browser.msie && jQuery.browser.version < "7.0")//IE 6.0 et moins
        return true;
    else if (jQuery.browser.safari && jQuery.browser.version <= "418.8")//Safari 2.0.4 et moins
        return true;
    else if (jQuery.browser.opera && jQuery.browser.version.substr(0, 1) < "9")//Safari 2.0.4 et moins
        return true;
    else
        return false;
}
function InitOldBrowser() {
    var cookieOldBrowser = getcookie("OldBrowserError");
    if (OldBrowserDetect() && cookieOldBrowser == "") {
        var txtLang = "fr";
        var txtCloseBtn = "Fermer cette alerte";
        var txtTitle = "Votre navigateur n'est pas support&eacute;&nbsp;!";
        var txtDescription = "Pour une meilleure exp&eacute;rience web, prenez le temps de mettre votre navigateur &agrave; jour parmi un de&nbsp;ceux-ci.";
        var txtDownload = "T&eacute;l&eacute;charger";
        
        var box = "<div style='border: 1px solid #CA1600; background:#fffed7; text-align: center; clear: both; height: 90px; position: relative; margin:-10px 0 15px -10px;'>";
        box += "<div style='position: absolute; right: 3px; top: 3px; font-family: courier new; font-weight: bold;'><a href='#' onclick='javascript:CloseOldBrowser(this);'><img src='/images/navigateur/Bt_Fermer.gif' style='border: none;' alt='" + txtCloseBtn + "'/></a></div>";
        box += "<div style='width: 600px; margin: 0 auto; text-align: left; padding: 0 0 0 95px; overflow: hidden; color: black; background:#fffed7 url(/images/navigateur/Ico_Erreur.png) no-repeat 15px 18px; height:90px;'>";
        box += "<div style='width: 275px; float: left; font-family: Arial, sans-serif;'>";
        box += "<div style='font-size: 14px; font-weight: bold; margin-top: 12px;'>" + txtTitle + "</div>";
        box += "<div style='font-size: 12px; margin-top: 6px;'>" + txtDescription + "</div>";
        box += "</div>";
        box += "<div style='width: 75px; float: left;'><a href='http://www.mozilla.com/" + txtLang + "/' target='_blank'><img src='/images/navigateur/Img_Firefox.gif' style='border: none;' alt='" + txtDownload + " Firefox 3.5'/></a></div>";
        box += "<div style='width: 75px; float: left;'><a href='http://www.microsoft.com/downloads/details.aspx?FamilyID=341c2ad5-8c3d-4347-8c03-08cdecd8852b&DisplayLang=" + txtLang + "' target='_blank'><img src='/images/navigateur/Img_IE.gif' style='border: none;' alt='" + txtDownload + " Internet Explorer 8'/></a></div>";
        box += "<div style='width: 73px; float: left;'><a href='http://www.apple.com/" + (txtLang == 'fr' ? 'fr/' : '') + "safari/download/' target='_blank'><img src='/images/navigateur/Img_Safari.gif' style='border: none;' alt='" + txtDownload + " Safari 4'/></a></div>";
        box += "<div style='float: left;'><a href='http://www.google.com/chrome?hl=" + txtLang + "' target='_blank'><img src='/images/navigateur/Img_Chrome.gif' style='border: none;' alt='" + txtDownload + " Google Chrome'/></a></div>";
        box += "</div>";
        box += "</div>";
        jQuery("body").prepend(box);
    }
}
function CloseOldBrowser(obj) {
    obj.parentNode.parentNode.style.display = 'none';
    putcookie("OldBrowserError", "true", 30);
    return false;
}

/* -- Fonctions pour la gestion des cookies
-------------------------------------------*/
function putcookie(name, value, days) {
    var expire = "";
    if (days != null) {
        expire = new Date((new Date()) + days);
        expire = "; expires=" + expire.toGMTString() + ";";
    }
    document.cookie = name + "=" + escape(value) + expire + "path=/";
}
function getcookie(name) {
    var cookieValue = "";
    var search = name + "=";
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search);
        if (offset != -1) {
            offset += search.length;
            end = document.cookie.indexOf(";", offset);
            if (end == -1) end = document.cookie.length;
            cookieValue = unescape(document.cookie.substring(offset, end))
        }
    }
    return cookieValue;
}


function submitenter(myfield,e,url)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	 
	if (keycode == 13)
	   {
	   return performSearch(myfield.id,url);
	   }
	else
	   return true;
}

function performSearch(id, url)
{
    var query = document.getElementById(id).value;
    if(query != '' && query != 'Trouvez un article paru depuis 1999' && query != 'Recherchez dans tout le site')
    {
        document.location.replace(url + '?q=' + query);
    }
        
    return false;
}

function loginsubmitenter(e,itemid)
{
if (document.getElementById) {
    var button = document.getElementById(itemid);
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;

    if (keycode == 13)
       {
       button.click();
       }
    else
       return true;
    }
}

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_blockHideLayers() { //v6.0
  var i,p,v,obj,args=MM_blockHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'block':(v=='hide')?'none':v; }
    obj.display=v; }
}


var menu_status;

function showHide(itemid){
    //alert(itemid);
    //alert(document.getElementById(itemid).className);
    if(_pageLoadingIsCompleted)
    {
        if (document.getElementById) {
	        var switch_id = document.getElementById(itemid);
	        if(menu_status != 'show') 
	        {
		        // switch_id.className = 'show';
		        //alert('Show');
		        removeClass(switch_id, 'hide');
		        addClass(switch_id, 'show');
		        menu_status = 'show';
    			
	        }
	        else
	        {
		        // switch_id.className = 'hide';
		        //alert('Hide');
		        removeClass(switch_id, 'show');
		        addClass(switch_id, 'hide');
		        menu_status = 'hide';
	        }
        }
    }
}

function hasClass(el, className) {
    var re = new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)');
    return re.test(el.className);
}

function addClass(el, className) {
    if (hasClass(el, className)) { return; } // already present

    el.className = [el.className, className].join(' ');
}

function removeClass(el, className) {
    var re = new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)', 'g');

    if (!hasClass(el, className)) { return; } // not present

    var c = el.className;
    el.className = c.replace(re, ' ');
    if ( hasClass(el, className) ) { // in case of multiple adjacent
	    removeClass(el, className);
    }
}

function writeOffer(path,id,width,height) {
    var so = new SWFObject(path, id, width, height, "6", "#ffffff");
    so.addParam("wmode", "transparent");
    so.write(id);
} 				

function fermerVolet(itemid) {
	if (document.getElementById) {
		var switch_id = document.getElementById(itemid);
		removeClass(switch_id, 'show');
		addClass(switch_id, 'hide');
	}
}

function ouvrirVolet(itemid){
	if (document.getElementById) {
		var switch_id = document.getElementById(itemid);
		removeClass(switch_id, 'hide');
		addClass(switch_id, 'show');
	}
}

//TODO: Completer cette logique pour envoyer a un ami
function Suggerer(pURL, pDocumentID, pParams)
{
	jsURL= pURL + '?pDocumentID=' + pDocumentID + '&pParams=' + pParams;
	jsNom='suggerer';
	jsParam='toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,history=no,resizable=yes,width=405,height=525,left=1,top=1';
	window.open(jsURL, jsNom, jsParam)
}

function Hein()
{
    jsURL = "/Templates/EnvoyerTrouvailles.aspx";
	jsParam='toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,history=no,resizable=no,width=405,height=365,left=1,top=1';
	window.open(jsURL, "trouvailles", jsParam);
}

function Print(pURL, pDocumentID, pNodeTypeID)
{
	jsURL=pURL+'?pDocumentID='+pDocumentID+'&pNodeTypeID='+pNodeTypeID;
	jsNom='print';
	jsParam='toolbar=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=405,height=510,left=1,top=1';
	window.open(jsURL, jsNom, jsParam)
}

//DateSelection
function pv_daysinmonth(lnMonth,lnYear) {
    var dt1, cmn1, cmn2, dtt, lflag, dycnt, lmn
    lmn = lnMonth-1
    dt1 = new Date(lnYear,lmn,1)
    cmn1 = dt1.getMonth()
    dtt=dt1.getTime()+2332800000
    lflag = true
    dycnt=28
    while (lflag) {
       dtt = dtt + 86400000
       dt1.setTime(dtt)
       cmn2 = dt1.getMonth()
       if (cmn1!=cmn2) {
          lflag = false }
       else {dycnt = dycnt + 1}}
    if (dycnt > 31) {dycnt = 31}
    return dycnt
}

function pv_setdays(sobjname, datemode){
    var dobj = $get(sobjname + "D")
    var mobj = $get(sobjname + "M")
    var yobj = $get(sobjname + "Y")
    
    var hobj = $get(sobjname)
    var monthdays = pv_daysinmonth(mobj.options[mobj.selectedIndex].value,yobj.options[yobj.selectedIndex].value)
    var selectdays = dobj.length
    var curdy = dobj.options[dobj.selectedIndex].value
    if (curdy.length==1) {curdy = "0"+curdy}
    var curmn = mobj.options[mobj.selectedIndex].value
    if (curmn.length==1) {curmn = "0"+curmn}
    var curyr = yobj.options[yobj.selectedIndex].value
    if (selectdays > monthdays) {
       for (var dlp=selectdays; dlp > monthdays; dlp--) {
           dobj.options[dlp-1] = null }}
    else if (monthdays > selectdays) {
       for (var dlp=selectdays; dlp < monthdays; dlp++) {
           dobj.options[dlp] = new Option(dlp+1,dlp+1) }}       
    if (curdy > monthdays) {
       dobj.options[monthdays-1].selected = true
       curdy = monthdays }
    if (datemode==1) {
       var curdate = curmn+"/"+curdy+"/"+curyr }
    else if (datemode==2) {
       var curdate = curdy+"/"+curmn+"/"+curyr }
    else if (datemode==3) {
       var curdate = curyr+curmn+curdy }
    else if (datemode==4) {
       var cdate = new Date(curyr,curmn-1,curdy)
       var curdate = cdate.toGMTString() }
}

function ValidateLength(source, arguments) {
   arguments.IsValid = arguments.Value.length >= 6;
}

function ValidateInteger(textbox) {
    var entry = parseInt(textbox.value);
    if (isNaN(entry)) {
        entry = 0;
    }
    textbox.value = entry;
}

function ShoppingCartItemQuantityChange(buttonClientID, textBoxClientID, buttonUniqueID) {
    if (document.getElementById(textBoxClientID).value == "0") {
        __doPostBack(buttonUniqueID, '')
        return;
    }
    $("#" + buttonClientID).show();
}
