UrlHelper.prepare(28);

function expandMenu(boxTitleId) {
		$("#"+boxTitleId+"_detail").slideToggle("slow");
	    $("#"+boxTitleId).parent(".element_section").toggleClass("open");
	    // Ouverture automatique si 1 seul element
	    if( $("#"+boxTitleId+"_detail.box_sub_title").size() == 1 && !$("#"+boxTitleId+"_detail.box_sub_title").parent(".element_sub_section").hasClass("openSub")){
			$("#"+boxTitleId+"_detail.box_sub_title").trigger("click");
	    }
	}

$().ready(function() {
    // Ajout des onclick sur chaque section
    $(".box_title").each(function(){
	$("#"+this.id).click(function(){
            $("#"+this.id+"_detail").slideToggle("slow");
	    $("#"+this.id).parent(".element_section").toggleClass("open");
	    // Ouverture automatique si 1 seul element
	    if( $("#"+this.id+"_detail .box_sub_title").size() == 1 && !$("#"+this.id+"_detail .box_sub_title").parent(".element_sub_section").hasClass("openSub")){
		$("#"+this.id+"_detail .box_sub_title").trigger("click");
	    }
	});
    });

    // Ajout des onclick sur chaque sous section
    $(".box_sub_title").each(function(){
	$("#"+this.id).click(function(){
	    $("#"+this.id+"_detail").slideToggle("slow");
	    $("#"+this.id).parent(".element_sub_section").toggleClass("openSub");
	});
    });

    // Pointe sur une section specifique
    expand = $.urlParam('expand');
    $target = $("#"+$.urlParam('expand'));
    
    // Initialisation des vieilles facon de faire
    // FIXME::Enlever quand tout les appels de page utiliseront expand
    if($.urlParam('expand') == "nousjoindre1"){
        expand = 'jnd_1'; $target = $("#formulaire");
    }else if($.urlParam('cigm') == "1"){
        expand = 'gst_ann_9';$target = $("#gst_ann_9");
    }else if($.urlParam('outilr') == "1"){
        expand = 'ggr_rch_7';$target = $("#ggr_rch_7");
    }else if($.urlParam('error') == "4"){
        expand = 'jnd_1'; $target = $("#formulaire");
        document.faq.sujet.value= "Liste noire";
    }

    document.faq.sujet.selectedIndex= $.urlParam('idSujet');
    // Ouverture et scroll de la section specifique
    if(expand != ''){
        $("#"+expand+"_detail").show();
        $("#"+expand).parent(".element_sub_section").toggleClass("openSub");
        if ($target.length) {
	    var targetOffset = $target.offset().top;
	    $('html,body').animate({
	        scrollTop: targetOffset
	    }, "slow");
	}
    }


    $("#jsSubmit").removeClass("none");
    $("#noJsSubmit").addClass("none");

    // Ajout du click sur le href submit
    $("#jsSubmit").click(function(){
	$("#faq").submit();
	return(false);
    });


    // validate signup form on keyup and submit
    $("#faq").validate({
	errorClass: "boxAlerte2",
	errorElement: "div",
	errorLabelContainer: "#boxErreur",

	highlight: function( element, errorClass, validClass ) {
	    $(element).addClass(errorClass).removeClass(validClass);
	},
	unhighlight: function( element, errorClass, validClass ) {
	    $(element).removeClass(errorClass).addClass(validClass);
	},
	onkeyup: false,
	rules: {
	    nom: "required",
	    telephone: "required",
	    sujet: "required",
	    question: "required",
	    courriel: {
		required: true,
		email: true
	    }
	},
	messages: {
	    nom: "Vous devez saisir votre nom.",
	    telephone: "Vous devez saisir votre téléphone.",
	    sujet: "Vous devez choisir un sujet.",
	    question: "Vous devez saisir un message.",
	    courriel: "Vous devez saisir une adresse courriel valide"
	}
    });

    $('#findAnn').click(function(){
        var urlMaker = UrlHelper.getInstance(28);
        urlMaker.loadParam("mots", $('#txtFindAnn').val());
        document.location = urlMaker.getUrlSeoFriendly();
        return false;
    });
    
    $('#findMem').click(function(){
        var urlMaker = UrlHelper.getInstance(28);
        urlMaker.loadParam("mots", $('#txtFindMem').val());
        document.location = urlMaker.getUrlSeoFriendly();
        return false;
    });
});


// Action lorsque la validation est ok
$.validator.setDefaults({
    submitHandler: function() {
	document.faq.submit();
    }
});


$.urlParam = function(name){
    var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
    return (results)?results[1]:0;
}

    var modalWindow = {
        parent:"body",
        windowId:null,
        content:null,
        width:null,
        height:null,
        close:function()
        {
            $(".modal-window").remove();
            $(".modal-overlay").remove();
        },
        open:function()
        {
            var modal = "";
            modal += "<div class=\"modal-overlay\"></div>";
            modal += "<div id=\"" + this.windowId + "\" class=\"modal-window\" style=\"width:" + this.width + "px; height:" + this.height + "px; margin-top:-" + (this.height / 2) + "px; margin-left:-" + (this.width / 2) + "px;\">";
            modal += this.content;
            modal += "</div>";

            $(this.parent).append(modal);

            $(".modal-window").append("<a class=\"close-window\"></a>");
            $(".close-window").click(function(){modalWindow.close();});
            $(".modal-overlay").click(function(){modalWindow.close();});
        }
    };

    var openMyModal = function(source)
    {
        modalWindow.windowId = "myModal";
        modalWindow.width = 500;
        modalWindow.height = 70;
        source = source + "?nomem=" + $('#noMemAutresPac').val();
        modalWindow.content = "<iframe width='500' height='70' frameborder='0' scrolling='no' allowtransparency='true' src='" + source + "'></iframe>";
        modalWindow.open();
    };

