/*----------------------------------------------------------------------------//
// Javascript pour le site client  -------------------------------------------//
//----------------------------------------------------------------------------//
// Client : -
// Note   : -
// Date   : -
//----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------*/
// Inclusion dynamique des fichiers externes javascripts
/*----------------------------------------------------------------------------*/
function importJavascript(src)
{
	document.write("<script type=\"text/javascript\" src=\"" + src + "\"></scr" + "ipt>");
}
function importCss(href, media)
{
	document.write('<link rel="stylesheet" type="text/css" media="' + media + '" href="' + href + '" />');
}

/*----------------------------------------------------------------------------*/
// Importations de fichiers
/*----------------------------------------------------------------------------*/
// importJavascript("/includes/js/plugins/jquery.plugin.js");
// importCss("/includes/js/plugins/jquery.plugin.css", "screen");
 importJavascript("/includes/js/plugins/jquery.watermarkinput.js");
 importJavascript("/includes/js/plugins/jquery.ifixpng.js");

/*----------------------------------------------------------------------------*/
// Declarations jQuery
/*----------------------------------------------------------------------------*/
jQuery(document).ready(function() {

    //Format de contenu
if (jQuery("hr") != null) {
    jQuery("hr").replaceWith("<div class=\"HR\"></div>");
    }
    //Watermark Recherche
    jQuery("#txtRecherche").each(function() { //#Entete .Recherche input:text, body.RechercherCGA div.Formulaire input:text
    var defaultText = jQuery(this).attr("title");
        jQuery(this).Watermark(defaultText);
    });

    // DropDowns
    InitDropDown();

    //Accueil - Sections
    jQuery("body.Accueil #HautPage .Onglets .Nav a").click(function() {
        var currentTab = jQuery(this).parent().attr("class");
        jQuery("body.Accueil #HautPage .Onglets .Nav a").removeClass("On");
        jQuery(this).addClass("On");
        jQuery("body.Accueil #HautPage .Onglets div.Nouvelles, body.Accueil #HautPage .Onglets div.Publications").hide();
        jQuery("body.Accueil #HautPage .Onglets div." + currentTab).show();
    });
    jQuery("body.Accueil #Contenu .Section h2 a").click(function() {
        jQuery("body.Accueil #Contenu .Section").removeClass("On");
        jQuery(this).parents(".Section").addClass("On");
    });

    //Accueil - Témoignages
    jQuery.ifixpng("/images/spacer.gif");
    jQuery("#Temoignage .Photo img").ifixpng();

    //Intérieur - Foire aux questions
    jQuery("#FAQ h4 a").click(function() {
        var hadClassOn = jQuery(this).parents(".Section").hasClass("On");
        jQuery("#FAQ .Section").removeClass("On");
        if (!hadClassOn)
            jQuery(this).parents(".Section").addClass("On");
        return false;
    });
    //-- Pour la recherche COVEO-----------------
    jQuery('#btnRecherche').click(function() {
        redirectToSearchPage();
    });

});

function InitDropDown() {
    jQuery("div.DropDown p a").click(function() {
        var parentDD = jQuery(this).parents("div.DropDown");
        jQuery("ul", parentDD).show();
        jQuery("ul a", parentDD).click(function() {
            
            jQuery("ul a", parentDD).removeClass("On");
            jQuery(this).addClass("On");
            jQuery("ul", parentDD).hide();
            jQuery("p a", parentDD).text(jQuery(this).text())
            //jQuery(this).unbind("click");
            //return false;
        });
        jQuery(document).bind("click", function() {
            jQuery("ul", parentDD).hide();
            //jQuery(this).unbind("click");
            //return false;
        });
        return false;
    });
}
function CheckSearch(e) {
   
    if (window.event) { // IE
        keynum = e.keyCode;
    }
    else if (e.which) { // Netscape/Firefox/Opera
        keynum = e.which;
    }
    // Si Enter
    if (keynum == 13) {
        // Lancer la recherche
        redirectToSearchPage();
        return false;
    }
    
    return true;
}
function redirectToSearchPage() {
    var query = jQuery('#txtRecherche').val();
    if (query != null && query != '') {
        window.location = searchPageUrl + "?lang=" + searchLang + "&q=" + query;
    }
}