﻿///////////////////////////////////////////
// Common.js

function swapImgRestore() {
  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 preloadImages() {
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=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 findObj(n, d) {
  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=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function swapImage() {
  var i,j=0,x,a=swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function showHideLayers() {
  var i,p,v,obj,args=showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    }
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + (opacity) + ")";

    
    if(opacity == 0) object.visibility = "hidden";
    else object.visibility = "visible";
}

function shiftOpacity(id, millisec) { 
    //if an element is invisible, make it visible, else make it ivisible 
    if(document.getElementById(id).style.opacity == 0 || document.getElementById(id).style.opacity == "" ) { 
        opacity(id, 0, 100, millisec); 
    } else { 
        opacity(id, 100, 0, millisec);
    } 
}

function elementEnfantDe(enfant, parent)
{
    enfantDe = false;
    
    while(enfant != null && !enfantDe)
    {
        enfantDe = (enfant == parent);
        enfant = enfant.parentNode;
    }
    
    return enfantDe;
}

var mouseX, mouseY;

function mouseMove (evt) {
	var x=0; var y=0;
	if (document.layers) {
		x=evt.x; y=evt.y;
	} 
	if (document.all) {
		x=event.clientX; y=event.clientY;
	} else {
		if (document.getElementById) {
			x=evt.clientX; y=evt.clientY; 
		}
	}
	mouseX = x; mouseY = y;
}

if (document.layers) 
document.captureEvents(Event.MOUSEMOVE); 
if (document.layers || document.all) 
document.onmousemove = mouseMove; 
if (document.addEventListener) 
document.addEventListener('mousemove', mouseMove, true); 


function mouseOverImageProduit(idProduit)
{
}

function mouseOutImageProduit(idProduit)
{
}


/* Fonctions de gestion de l'affichage du menu AJAX */
var httpCalqueCateg;
var enCoursAffichageCalque = false;
var enCoursMasquageCalque = false;

function calqueCateg(pays, langue, idCateg) {
    httpCalqueCateg = createRequestObject();
    httpCalqueCateg.open('GET', '/' + pays + '/' + langue + '/calque_menu.aspx?pays=' + pays + '&langue=' + langue + '&idCateg=' + idCateg, true);
    httpCalqueCateg.onreadystatechange = calqueCategAjaxReturn;
    httpCalqueCateg.send(null);

    masquerCalqueCateg();
}

function calqueCategAjaxReturn() {
    if (httpCalqueCateg.readyState == 4) {
        if (httpCalqueCateg.status == 200) {
            var obj = window.document.getElementById("emplacementCalqueCateg");

            if (obj) {
                obj.innerHTML = httpCalqueCateg.responseText;
                afficherCalqueCateg();
            }
        }
    }
}

function afficherCalqueCateg() {
    while (enCoursMasquageCalque) { };
    
    enCoursAffichageCalque = true;
    if (document.getElementById("calque_calqueOnglet").style.visibility != "visible") opacity("calque_calqueOnglet", 0, 95, 50);
    enCoursAffichageCalque = false;
}

function masquerCalqueCateg() {
    while (enCoursAffichageCalque) { };
    
    enCoursMasquageCalque = true;
    if (document.getElementById("calque_calqueOnglet").style.visibility == "visible") opacity("calque_calqueOnglet", 95, 0, 50);
    enCoursMasquageCalque = false;
}

function masquerCalqueCategDirect() {
    while (enCoursAffichageCalque) { };
    
    enCoursMasquageCalque = true;
    changeOpac(0, "calque_calqueOnglet");
    enCoursMasquageCalque = false;
}



// redirection javascript vers un produit marchand
function redirpm(prefixepl, idPm, emplacement, phase) {
    var f = window.document.getElementById("__redirpm");
    f.target = "_blank";
    f.action = "/redir" + prefixepl + "/rp-pm" + idPm + "-e" + emplacement + "-ph" + phase + ".html";
    f.submit();
}

// redirection Javascript vers une URL
function redir(url) {
    var f = window.document.getElementById("__redir");
    f.action = url;
    f.submit();
}



///////////////////////////////////////////
// ajaxEtForms.js

//var urlReecrite;

//function PageLoadedHandler(sender, args) {
//    //Code that you want to happen on every postback.
//    //Asynch or Synch.

//    annulerRequetesAjaxInutiles();
//    document.forms[0].action = urlReecrite;
//}

//function modifierForm(url) {
//    urlReecrite = url;
//    var prm = Sys.WebForms.PageRequestManager.getInstance();
//    //alert('url réécrite');
//    document.forms[0].action = urlReecrite;
//    prm.add_pageLoaded(PageLoadedHandler);
//}

function initRequest(sender, args) {
    if (Sys.WebForms!=undefined && Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack())
        args.set_cancel(true);
}

function annulerRequetesAjaxInutiles() {
    if(Sys.WebForms!=undefined)
        Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(initRequest);
}

var http; // Notre objet XMLHttpRequest
function createRequestObject() {
    var http;
    if (window.XMLHttpRequest) { // Mozilla, Safari, IE7 ...
        http = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) { // Internet Explorer 6
        http = new ActiveXObject("Microsoft.XMLHTTP");
    }
    return http;
}

function appelUrl(url, asyncFunc) {
    http = createRequestObject();
    http.open('GET', url, true);
    http.onreadystatechange = handleAJAXReturn;
    http.send(null);
}

function handleAJAXReturn() {
    if (http.readyState == 4) {
        if (http.status == 200) {
            alert(http.responseText);
        }
    }
}



var timer = null;  //Timer du Loader
var nbtimer = 0;  //Nombre de timer lancé
var noLoaderOnSubmit = false;

function TimeLoader() {
    if (noLoaderOnSubmit) {
        noLoaderOnSubmit = false;
    }
    else {
        //On augmente le nombre de timer
        nbtimer++;

        // On rélge l'opacité du div global à 0 (transparent) et on bloque la page en l'affichant
        if (nbtimer == 1) {
            OpacityLoaderBox(0);
            document.getElementById('waitpostback').style.display = "block";
        }

        //Lancement du timer à 0,5 pour afficher le message "Traitement en cours" que si le timer n'est pas déjà instancier
        if (timer == null && nbtimer == 1)
            timer = setTimeout("LoaderDisplay('block')", 500);
    }

    return true;
}

function LoaderDisplay(etat) {
    //On stop le timer pour ne pas relancer le processus toutes les 2 secondes
    clearTimeout(timer);

    //On diminue le nombre de timer si on cherche à faire un display none sur le loader
    //    => si état est égal à none, c'est qu'une requête asynchrone ou synchrone est terminée
    if (etat == "none")
        nbtimer--;

    //On régle l'opacité du div global pour réinitialser ou activer son état
    if (etat == "none" && nbtimer == 0)
        OpacityLoaderBox(0);
    else if (etat == "block" && nbtimer == 1)
        OpacityLoaderBox(0.6);

    //On régle l'affichage de loader suivant l'état et le nombre de timer lancé
    // - Dernier timer et l'état à display none (évite de faire disparaitre le loader alors qu'il reste encore des requêtes en cours)
    // - Premier timer et l'état à display block (permet d'afficher le loader au premier chargement)
    if ((etat == "none" && nbtimer == 0) || (etat == "block" && nbtimer == 1)) {
        document.getElementById('waitpostback').style.display = etat;
        document.getElementById('waitpostbackmessage').style.display = etat;
    }

    if (nbtimer == 0)
        timer = null;
}

function OpacityLoaderBox(opa) {
    var box = document.getElementById('waitpostback');
    box.style.opacity = opa;
    box.style.MozOpacity = opa;
    box.style.filter = "alpha(opacity=" + opa * 100 + ")";
}



///////////////////////////////////
// utils.js

function showHideCategories(idZoneCateg1, idLien1, msgPlus, msgMoins) {
    var zone1 = document.getElementById(idZoneCateg1);
    var lien1 = document.getElementById(idLien1);

    var zone1Presente = zone1 != null && zone1 != undefined;
    var lien1Present = lien1 != null && lien1 != undefined;

    if (zone1Presente && zone1.style.display == 'none') {
        //Peu de categ -> Plus de categ
        zone1.style.display = 'block';
        if (lien1Present) lien1.innerHTML = msgMoins;
    }
    else {
        //Beaucoup de categ -> peu de categ
        if (zone1Presente) zone1.style.display = 'none';
        if (lien1Present) lien1.innerHTML = msgPlus;
    }
}

//function initZonesCateg(idZoneCateg1) {
//    var zone1 = document.getElementById(idZoneCateg1);

//    if (zone1 != null && zone1 != undefined) document.getElementById(idZoneCateg1).style.display = 'none';
//}

//Effectue des actions lors du départ d'un internaute
function departInternaute(idBtn) {
    if (isBrowserClosed()) {
        alert("Window is closed.");
    }
    else alert('changement de page !');
    var btn = document.getElementById(idBtn);
    if (btn != null) btn.click();
}

function isBrowserClosed() {

    var browserWindowWidth = 0;
    var browserWindowHeight = 0;



    // gets the width and height of the browser window

    if (parseInt(navigator.appVersion) > 3) {

        if (navigator.appName == "Netscape") {

            browserWindowWidth = window.innerWidth;

            browserWindowHeight = window.innerHeight;

        }

        if (navigator.appName.indexOf("Microsoft") != -1) {

            browserWindowWidth = top.window.document.body.offsetWidth;

            browserWindowHeight = top.window.document.body.offsetHeight;

        }

    }



    //checks if the X button was closed

    //if event.clientY < 0, then click was on the browser menu area

    //if event.screenX > (browserWindowWidth - 25), the X button was clicked

    //use screenX if working with multiple frames

    return (event.clientY < 0 && event.screenX > (browserWindowWidth - 25)) ? true : false;

}

function test() {
    if ("<%= Request.UserHostAddress %>" == "127.0.0.1") alert('test!');
}



//////////////////////////////////
// rechajax.js

var endehors;
var indexChoixCourant;
var libelleChoixCourant;
var propChoisie;
var idTbPrec;
var idTbCourante;
var timerToucheRetour;

function definirLargeurChampSaisie(idChamp, idZonePropositions, largeur) {
    var champ = document.getElementById(idChamp);
    var zoneProp = document.getElementById(idZonePropositions);

    champ.style.width = largeur;
    if (zoneProp != null) zoneProp.style.width = largeur;
}

function tailleMinZoneProp(idZone, idTbRecherche) {
    var zoneProp = document.getElementById(idZone);
    var tbRecherche = document.getElementById(idTbRecherche);

    if (zoneProp != undefined && zoneProp != null) {
        var liens = zoneProp.getElementsByTagName("a");

        var i = 0;
        var largeurZone = 0;
        for (i = 0; i < liens.length; i++) {
            if (liens[i].offsetWidth > largeurZone) {
                largeurZone = liens[i].offsetWidth;
            }
        }
    }
}

function tbFocused(idTbRecherche) {
    idTbCourante = idTbRecherche;
}

//Déplace le curseur textuel en fin de texte
function setCursorPos(tbrechid) {
    x = document.getElementById(tbrechid);
    var txtRange = x.createTextRange();
    txtRange.moveStart("character", x.value.length);
    txtRange.moveEnd("character", 0);
    txtRange.select();
}

function verifLongueur(idTbRecherche, idZoneProp) {
    if (document.getElementById(idTbRecherche).value.length < 3 && document.getElementById(idZoneProp) != null) 
        document.getElementById(idZoneProp).style.visibility = 'hidden';
}

function rechercherPropositions(idTbRecherche, idZonePropositions, idButCache, idChampCache) {
    var tb = document.getElementById(idTbRecherche);
    //Déclenche l'événement TextChanged
    if (tb.value.length >= 3) {
        //La recherche n'est lancée qu'à partir de 3 caractères
        noLoaderOnSubmit = true;
        __doPostBack(idButCache, '');
    }
    else {
        //Si la zone de saisie dispose de moins de 3 caractères, on la cache.
        if (document.getElementById(idZonePropositions) != null) 
            document.getElementById(idZonePropositions).style.visibility = 'hidden';
    }

    indexChoixCourant = 0;
    libelleChoixCourant = null;
}

//Appelé lorsque la touche retour est relâchée
function toucheRetour(e, idTbRecherche, idZoneProp, idButache, idChampCache, idChampRechAuto) {
    var touche;
    //Récupération de la touche
    if (window.event) {
        touche = e.keyCode;
    }
    else {
        touche = e.which;
    }

    if (touche == 8) {
        //Mise à jour de la valeur à rechercher
        document.getElementById(idChampCache).value = document.getElementById(idTbRecherche).value;

        //Une autre touche a été utilisée
        if (document.getElementById(idTbRecherche).value.length < 3) {
            //Mise à jour de la valeur à rechercher
            if (document.getElementById(idZoneProp) != null) document.getElementById(idZoneProp).style.visibility = 'hidden';
            return;
        }

        //La recherche n'est lancée que si la précédente est achevée
        if (document.getElementById(idChampRechAuto).value == '1' && document.getElementById(idChampCache).value.length >= 3) {
            document.getElementById(idChampRechAuto).value == '0';
            //Recherche de résultats
            rechercherPropositions(idTbRecherche, idZoneProp, idButache, idChampCache);
        }
    }
}

//Appelé lors de l'appui sur une touche
function toucheSpecPressee(e, idTbRecherche, idZoneProp, idButache, idChampCache, idChampRechAuto, lancementImmediat) {
    var touche;
    //Récupération de la touche
    if (window.event) {
        touche = e.keyCode;
    }
    else {
        touche = e.which;
    }

    if (touche == 13) {
        if (libelleChoixCourant == null) 
            return;
        //Une proposition est choisie par l'utilisateur
        document.getElementById(idTbRecherche).value = libelleChoixCourant;
        choixProposition(libelleChoixCourant, idTbRecherche, idZoneProp, idChampCache, lancementImmediat);
    }
    else if (touche == 38 || touche == 40) {
        //Touche haut ou bas -> Déplacement parmi les propositions
        deplacerChoix(e, idZoneProp);
    }
}

//Appelé lors de l'appui sur une touche
function touchePressee(e, idTbRecherche, idZoneProp, idButache, idChampCache, idChampRechAuto) {
    var caractere;
    var touche;
    //Récupération de la touche
    if (window.event) {
        touche = e.keyCode;
    }
    else {
        touche = e.which;
    }

    if (touche == 13 || touche == 38 || touche == 40 || touche == 8 || touche == 0) return;

    if (window.event) {
        caractere = String.fromCharCode(e.keyCode);
    }
    else {
        caractere = String.fromCharCode(e.charCode);
    }

    //Mise à jour de la valeur à rechercher
    document.getElementById(idChampCache).value = document.getElementById(idTbRecherche).value + caractere;

    //Une autre touche a été utilisée
    if (document.getElementById(idTbRecherche).value.length < 3) {
        //Mise à jour de la valeur à rechercher
        if (document.getElementById(idZoneProp) != null) 
            document.getElementById(idZoneProp).style.visibility = 'hidden';
        return;
    }

    //La recherche n'est lancée que si la précédente est achevée
    if (document.getElementById(idChampRechAuto).value == '1' && document.getElementById(idChampCache).value.length >= 3) {
        document.getElementById(idChampRechAuto).value == '0';

        //Recherche de résultats
        rechercherPropositions(idTbRecherche, idZoneProp, idButache, idChampCache);
    }
}

//Cache la zone de propositions
function cacherPropositions(idZone, idTbRecherche) {
    idTbPrec = idTbRecherche;

    if (endehors == true && document.getElementById(idZone) != null)
         document.getElementById(idZone).style.visibility = 'hidden';
    if (endehors == false) { setTimeout("if(idTbPrec!=idTbCourante && document.getElementById('" + idZone + "')!=null){document.getElementById('" + idZone + "').style.visibility='hidden';}", 200); }
}

function dedans() {
    endehors = false;
}

function dehors() {
    endehors = true;
}

//Appelé lorsque l'utilisateur clique sur un choix.
function choixProposition(libelle, idTbRecherche, idzoneProp, idChampCache, lancementImmediat) {
    if (libelle == null) return;

    var tb = document.getElementById(idTbRecherche);
    var zoneProp = document.getElementById(idzoneProp);
    var lib = libelle;
    var champCache = document.getElementById(idChampCache);

    tb.value = lib;
    champCache.value = lib;

    if (zoneProp != null) 
        zoneProp.style.visibility = 'hidden';
    libelleChoixCourant = null;
    propChoisie = true;

    idTbPrec = idTbRecherche;

    if (lancementImmediat) 
        __doPostBack(idTbRecherche, libelle);
}

//Sélectionne une proposition
function appliquerCssChoix(idLien) {
    document.getElementById(idLien).parentNode.parentNode.className = "rechChoix";
}

//Déselectionne une proposition
function enleverCssChoix(idLien) {
    document.getElementById(idLien).parentNode.parentNode.className = "";
}

//Déplace la zone de surbrillance sur les différentes propositions
function deplacerChoix(e, idZoneProp) {
    //La zone de propositions
    var zonePropositions = document.getElementById(idZoneProp);
    var liensEnfants = zonePropositions.getElementsByTagName('a');

    //Récupération de la touche
    var touche = window.event ? e.keyCode : e.which;

    if (touche == 38) {
        //Flèche haut

        //On ne peut pas aller plus haut
        if (indexChoixCourant == 0 || indexChoixCourant == 1) return;

        //Déplacement d'un cran vers le haut
        liensEnfants[indexChoixCourant - 1].parentNode.parentNode.className = '';
        liensEnfants[indexChoixCourant - 2].parentNode.parentNode.className = 'rechChoix';
        libelleChoixCourant = liensEnfants[indexChoixCourant - 2].innerText;
        if (libelleChoixCourant == undefined)
            libelleChoixCourant = liensEnfants[indexChoixCourant - 2].textContent;
        indexChoixCourant--;
    }
    else if (touche == 40) {
        //Flèche bas

        //On ne peut pas aller plus bas
        if (indexChoixCourant == liensEnfants.length) return;

        //Déplacement d'un cran vers le haut
        if (indexChoixCourant > 0) liensEnfants[indexChoixCourant - 1].parentNode.parentNode.className = '';
        liensEnfants[indexChoixCourant].parentNode.parentNode.className = 'rechChoix';
        libelleChoixCourant = liensEnfants[indexChoixCourant].innerText;
        if (libelleChoixCourant == undefined)
            libelleChoixCourant = liensEnfants[indexChoixCourant].textContent;
        indexChoixCourant++;  
    }

}

//Gère l'activation ou non de la touche entrée pour soumettre le formulaire
function kH(e) {
    var pK = e ? e.which : window.event.keyCode;
    if (propChoisie == undefined || propChoisie == false) {
        return true;
    }
    else {
        propChoisie = false;
        return pK != 13;
    }
}

document.onkeypress = kH;
if (document.captureEvents && Event.KEYPRESS) document.captureEvents(Event.KEYPRESS);



function clicRechAjax(inpt) {
    inpt.select();
    inpt.focus();
}

/*
 * Vide le contenu d'un champ textuel uniquement s'il dispose de la valeur indiquée.
 */
function ViderInputSelonValeur(idInpt, valeur) {

    var input = document.getElementById(idInpt);
    if (input != undefined && input.value == valeur) {
    input.value = '';
    }
}

/*
* Gestion du zoom images
*/

/*
 * Affiche sur l'écran, et au dessus de tout élement, l'image d'url indiquée.
 */
function AfficherZoomImg(imgObj,urlImgZoom) {

    var divZoomImg = document.getElementById("divZoomImage");
    
    if (divZoomImg != undefined) {
        //Position
        divZoomImg.style.top = (mouseY + document.documentElement.scrollTop) + "px";
        divZoomImg.style.left = (mouseX + document.documentElement.scrollLeft) + "px";

        //Pour le suivi souris
        imgObj.onmouseout = function() { imgObj.onmousemove = ''; MasquerZoomImg(); }
        imgObj.onmousemove = function(e) {
            var y = document.documentElement.scrollTop;
            var x = document.documentElement.scrollLeft;
            divZoomImg.y = y;
            divZoomImg.x = x;

            if (e) {
                divZoomImg.ey = e.clientY;
                divZoomImg.ex = e.clientX;
                x += e.clientX;
                y += e.clientY;

                divZoomImg.style.top = (y - (divZoomImg.offsetHeight / 2)) + 'px';
                divZoomImg.style.left = (x + 20) + 'px';
            }
            else {
                divZoomImg.ey = event.clientY;
                divZoomImg.ex = event.clientX;
                x += event.clientX;
                y += event.clientY;

                divZoomImg.style.top = (y - (divZoomImg.offsetHeight / 2)) + 'px';
                divZoomImg.style.left = (x + 20) + 'px';
            }
        }

        divZoomImg.style.display = "block";
        
        PreloadImage("" + urlImgZoom + "", function() {
            divZoomImg.style.backgroundImage = "url(\"" + urlImgZoom + "\")";
        });
    }
}

/*
 * Masque l'image actuellement affichée en zoom à l'écran.
 */
function MasquerZoomImg() {
    
    var divZoomImg = document.getElementById("divZoomImage");
    if (divZoomImg != undefined) {
        divZoomImg.style.backgroundImage = "url('/images/loading.gif')";
        divZoomImg.style.display = 'none';
    }
}

function PreloadImage(imgSrc, callback) {
    var objImagePreloader = new Image();

    objImagePreloader.src = imgSrc;
    if (objImagePreloader.complete) {
        callback();
        objImagePreloader.onload = function() { };
    }
    else {
        objImagePreloader.onload = function() {
            callback();
            //    clear onLoad, IE behaves irratically with animated gifs otherwise
            objImagePreloader.onload = function() { };
        }
    }
}

/************* Gestion Comptes Clients *****************/
/*
 * Indique si l'utilisateur courant est connecté ou pas.
 */
function utilisateurConnecte() {
    return $(".infosConnexion").css('visibility') == 'visible';   
}

/************* Gestion Avis ******************/
function GestionVisibiliteFormAvis() {
    
}

function switchNotes(imgElement) {
    imgElement.src = "/images/avis" + getNote(imgElement) + "-5.png";
    afficherCommentNote(getNote(imgElement));
}

function setNote(imgElement) {
    alert('setNote!');
    alert(getNote(imgElement));
    imgElement.src = "/images/avis" + getNote(imgElement) + "-5.png";
    afficherCommentNote(getNote(imgElement));
}

function getNote(posXBase, posXActuel) {

    if (posXBase + 4 * 16 > posXActuel)
        if (posXBase + 3 * 16 > posXActuel)
            if (posXBase + 2 * 16 > posXActuel)
                if (posXBase + 1 * 16 > posXActuel)
                    if (posXBase + 0 * 16 > posXActuel)
                        return 0;
                    else
                        return 1;
                else
                    return 2;
            else
                return 3;
        else
            return 4;
    else
        return 5;
}
function getCommentNote(note) {
    return $(".hidComment" + note + "_5").val();
}
function afficherCommentNote(note) {
    $(".commentNote").html(getCommentNote(note));
 }

/*
 * Affiche le formulaire de saisie d'un avis sur la fiche produit
 */
function showFormAvis() {
    $('.formAvis').slideToggle('slow'); 
    $('.formAvis').css('display', 'block');
    $('#lienDonnezAvis').css('display', 'none');

    jumpToAnchor('#avis');
    GestionNotes();
}
/*
 * Cache le formulaire de saisie d'un avis sur la fiche produit
 */
function hideFormAvis() {
    $('.formAvis').css('display', 'none');
    $('#lienDonnezAvis').css('display', 'block');
}
function checkNoteChoisie(src,args) {
    args.IsValid = $(".hidNoteChoisie").val() != '' && $(".hidNoteChoisie").val() != '0';
}

function checkUtilisateurConnectePourAvis(src, args) {
    args.IsValid = utilisateurConnecte();
    if (!args.IsValid) {
        showFormConnexion('#avis');
    }
 }

function GestionNotes() {
    //Surbrillance lors du passage souris
    $(".imgChoixNote").mousemove(function(e) {
        var y = document.documentElement.scrollTop;
        var x = document.documentElement.scrollLeft;

        if (e) {
            x += e.clientX;
            y += e.clientY;
        }
        else {
            x += event.clientX;
            y += event.clientY;
        }

        var posXImgBase = $(".imgChoixNote").offset().left;
        var noteAAfficher = getNote(posXImgBase,x);

        $(".imgChoixNote").attr("src", "/images/avis" + noteAAfficher + "-5.png");
        afficherCommentNote(noteAAfficher);
    });

    //Choix d'une note
    $(".imgChoixNote").click(function() {

        var noteChoisie = 0;
        var src = $(".imgChoixNote").attr("src");

        if (src == "/images/avis1-5.png")
            noteChoisie = 1;
        else if (src == "/images/avis2-5.png")
            noteChoisie = 2;
        else if (src == "/images/avis3-5.png")
            noteChoisie = 3;
        else if (src == "/images/avis4-5.png")
            noteChoisie = 4;
        else if (src == "/images/avis5-5.png")
            noteChoisie = 5;

        $(".hidNoteChoisie").val(noteChoisie);
        afficherCommentNote(noteChoisie);
    });

    //Réaffectation de la dernière note choisie
    $(".imgChoixNote").mouseout(function() {

        var noteChoisie = $(".hidNoteChoisie").val();
        if (noteChoisie == undefined || noteChoisie == '')
            noteChoisie = 0;

        $(".imgChoixNote").attr("src", "/images/avis" + noteChoisie + "-5.png");
        afficherCommentNote(noteChoisie);
    });
}

/************* Gestion Connexion Client ******************/
function showEncartConnexion(id) {
    if ($(".divConnexion").css('visibility') == 'hidden') {
        $(".divConnexion").css('visibility', 'visible');
        $(".divConnexion").animate({opacity:1},500,function() {});
    }
    else {
        $(".divConnexion").animate({ opacity: 0 }, 500, function() { $(".divConnexion").css('visibility', 'hidden'); });
    }
}

function showFormConnexion(anchor) {
    if ($(".formConnexion").css('display') == 'none') {
        $(".formConnexion").css('display', 'block');
        $(".formConnexion").animate({ opacity: 1 }, 500, function() { });
        if($(".divConnexion").css('visibility') == 'visible')
            $(".divConnexion").css('visibility', 'hidden');

        $(".lienFermer").attr('href', anchor);
     }
}
function hideFormConnexion() {
    if ($(".formConnexion").css('display') == 'block') {
        $(".formConnexion").animate({ opacity: 0 }, 500, function() { $(".formConnexion").css('display', 'none'); });
     }
}
function GestionAffichageInfosCompte() {
    if ($('.infosConnexion').html().trim().charAt(0) == '<')
        $('.infosConnexion').css('visibility', 'hidden');
    else
        $('.infosConnexion').css('visibility', 'visible');
}

/******* Utils ********/
function afficheAide(id)
{
    $('#' + id).css('display','block');
}
function cacheAide(id) {
    $('#' + id).css('display','none');
}
function jumpToAnchor(anchor) {
    window.location = String(window.location).replace(/\#.*$/, "") + anchor;
}