function donnez_votre_avis(){
    $('#right_content').hide();

    tb_show('Donnez votre avis', 'http://survey.univadis.fr/survey.php?surveyid=47&modal=true&height=288&width=570&placeValuesBeforeTB_=savedValues&keepThis=true&TB_iframe=true');

    //$('#TB_window').prepend('<div id="TB_title" style="background: #099 url(../images/msd_logo_46px.gif) no-repeat left top; height:52px" ><div id="TB_ajaxWindowTitle">&nbsp;</div><div id="TB_closeAjaxWindow" style="background: #099 url(../images/bg_nav_int.png) no-repeat right top;width:200px; height:40px">&nbsp;</div></div>');
$('#TB_window').prepend('<div style="background-color:#3d7c85; height: 60px;background-image:url(http://publish.univadis.com/univadis/localFiles/fr_FR/images/header.jpg);"><img style="float:right;padding: 5px 5px 0px 0px;cursor:hand; cursor:pointer;" onclick="fermer_la_fenetre();" src="http://publish.univadis.com/univadis/localFiles/fr_FR/images/close.gif" width="10" height="10" /></div>');

//    $('#TB_window').append('<div id="TB_fotter" style="background-color:#FFF;height:27px;"><div id="TB_fermerLaFenetre" style="float:left;margin-bottom:1px;padding:7px 10px 5px 10px;text-align:left;"><div style="color:#939393; font-weight:bold; cursor:hand; cursor:pointer;" onclick="fermer_la_fenetre();" >Fermer la fen&ecirc;tre</div></div><div id="TB_repondrePlusTard" style="float:right;margin-bottom:1px;padding:7px 10px 5px 0;text-align:right;"><div style="color:#939393; font-weight:bold; cursor:hand; cursor:pointer;" onclick="repondre_plus_tard();" >R&eacute;pondre plus tard</div></div></div>');
$('#TB_window').append('<div style="background-image:url(http://publish.univadis.com/univadis/localFiles/fr_FR/images/footer.jpg);height: 30px;"><div id="TB_fermerLaFenetre" style="float:left;margin-bottom:1px;padding:7px 10px 5px 10px;text-align:left;"><div style="color: #FFFFFF;font-weight:bold; cursor:hand; cursor:pointer;" onclick="fermer_la_fenetre();" >Fermer la fen&ecirc;tre</div></div><div id="TB_repondrePlusTard" style="float:right;margin-bottom:1px;padding:7px 10px 5px 0;text-align:right;"><div style="color: #FFFFFF;font-weight:bold; cursor:hand; cursor:pointer;" onclick="repondre_plus_tard();" >R&eacute;pondre plus tard</div></div></div>');

    creer_cookie(deja_vu, 'oui', date);
    creer_cookie(deja_vu_date, date.getTime(), date);
}

function repondre_plus_tard(){
    creer_cookie(deja_vu, 'non', date);
    creer_cookie(deja_vu_date, maintenant, date);
    showAlert("Fin 0");
    tb_remove();
    $('#right_content').show();
}

function fermer_la_fenetre(){
    showAlert("Fin 5");
    tb_remove();
    $('#right_content').show();
}


function creer_cookie(cname, cvalue, cexpires){
    showAlert("Je cree le cookie "+cname);
    $.cookie(cname, cvalue, {expires: cexpires, path: '/'});
}

function supp_cookie(nom){
    showAlert("Je supprime le cookie "+cname);
    $.cookie(nom, null);
}

function showAlert(message){
    //alert(message);
}

$(document).ready(function() {
    deja_vu = 'deja_vu';
    deja_vu_date = 'deja_vu_date';
    date = new Date();
    var diff = 0;
    var duree = 60*1000; //1 minute
    var intervalle = date.getTime() + duree; //1 minute
    maintenant = date.getTime();
    date.setTime(date.getTime() + (365 * 24 * 60 * 60 * 1000));//1 annee

    var valeur_deja_vu = '' + $.cookie(deja_vu);
    var valeur_deja_vu_date = '' + $.cookie(deja_vu_date);

    if(valeur_deja_vu == 'null'){
        showAlert("Le cookie n'existe pas");
        creer_cookie(deja_vu, 'non', date);
        creer_cookie(deja_vu_date, maintenant, date);
        showAlert("Fin 1");
    }else{
        showAlert('Le cookie existe');
        if(valeur_deja_vu == 'non'){
            showAlert("La valeur du cookie = 'non'");
            showAlert("maintenant="+maintenant);
            showAlert("valeur_deja_vu_date="+valeur_deja_vu_date);
            
            diff = maintenant - eval(valeur_deja_vu_date);
            showAlert("maintenant - valeur_deja_vu_date = " + diff);
            showAlert(diff+" > "+duree);
            if(diff > duree){
                showAlert("Age du cookie > " + eval(duree/1000) + "s");
                donnez_votre_avis();
                showAlert("Fin 4");
            }else{
                showAlert("Fin 3");
            }
        }else{
            showAlert("Fin 2");
        }
    }
});
