// JavaScript Document
/* horaires
------------------------------------------------------------------------------*/

$(document).ready(function() {

    // mdejoux : fiche horaire excel
    $(".grille_fiche_horaire, .grille_nav_horaire").hide();
    $(".grille_fiche_horaire:first, .grille_nav_horaire:first").show();

    $(".horaires_suivants a, .horaires_precedents a").click(function() {
        // On masque tous les éléments
        //$(".grille_fiche_horaire").hide();
        $(".heures, .onglet, .grille_fiche_horaire, .grille_nav_horaire").hide();

        // On affiche la div de la bonne grille horaire
        $($(this).attr("href")).show();

        // On affiche la bonne nav (horaires suivants / horaires précédents)
        $($(this).attr("href") + "_nav_horaire").show();

        // On affiche les bons onglets et horaires
        $($(this).attr("href")).children(".heures:first").show();
        $($(this).attr("href")).children(".onglet:first").show();

        /*$($(this).attr("href")).show();

        $($(this).attr("href")).prev(".heures").show();
        $($(this).attr("href")).prev(".heures").find('.actif a').focus();

        $(this).blur();*/
        return (false);
    });
    // mdejoux


    $(".heures, .onglet").hide();
    $(".heures:first, .onglet:first").show();

    $(".heures a, a.plan").click(function() {
        $(".heures, .onglet").hide();
        $($(this).attr("href")).show();

        $($(this).attr("href")).prev(".heures").show();
        $($(this).attr("href")).prev(".heures").find('.actif a').focus();

        $(this).blur();
        return (false);
    });

    /**************************************************************/

    $("ul.subMenu:not('.open_at_load')").hide();
    $("li.toggleSubMenu > a").each(function() {
        //$("li.toggleSubMenu h3 span").each( function () {
        var TexteSpan = $(this).text();
        $(this).replaceWith('<a href="" title="Afficher le sous-menu">' + TexteSpan + '</a>');
    });

    $('.open_at_load').prev("a").attr("title", "Masquer le sous-menu");

    $("li.toggleSubMenu > a, li.toggleSubMenu > h3 span").click(function() {
        var $this = $(this);
        //alert("debut : "+ $this.next("ul.subMenu").is(":visible"));
        //alert($this.next("ul.subMenu").count);
        if ($this.next("ul.subMenu").is(":visible")) {
            //alert("vizible true");
            $this.attr("title", "Afficher le sous-menu").next("ul.subMenu").slideUp(1000);
            $this.parent("li").removeClass("open");
        }
        else {
            //alert("vizible false");
            $("ul.subMenu").slideUp(1000);
            $("li.toggleSubMenu").removeClass("open");
            $("li.toggleSubMenu > a, li.toggleSubMenu > h3 span").attr("title", "Afficher le sous-menu");
            $this.attr("title", "Masquer le sous-menu").next("ul.subMenu").slideDown(1000);
            $this.parent("li").addClass("open");
        }
        //alert("fin : "+ $this.next("ul.subMenu").is(":visible"));
        return false;
    });

    /**************************************************************/

    $("ul.subMenu:not('.open_at_load')").hide();

    $("li.toggleSubMenu h3 > span").each(function() {
        var TexteSpan = $(this).text();
        //JCA@22/04/2010 - Accessibilité - 6.3
        //$(this).replaceWith('<a href="" title="Afficher le sous-menu">' + TexteSpan + '</a>');
        $(this).replaceWith('<a href="" title="Afficher le sous-menu ' + TexteSpan + '">' + TexteSpan + '</a>');
    });
    //JCA@22/04/2010 - Accessibilité - 6.3
    $('.open_at_load').prev().children("a").attr("title", "Masquer le sous-menu");


    // version antoine
    /*$("#te_menuFaq li.toggleSubMenu").each(function() {
    var self = this;
    var $collapsable = $('ul', this);
    var $link = $('h3 > a', this); // lien cliquable déclenchant le slide
    //$collapsable.css('border', '1px solid green');
    $link
    //.css('border', '1px solid red')
    .click(function() {
    if($(self).hasClass('open')) {
    $collapsable.slideUp('slow');
    $(self).removeClass('open');
    }
    else {
    $('#te_menuFaq li.toggleSubMenu.open').removeClass('open').find('ul').slideUp('slow');
    $collapsable.slideDown('slow');
    $(self).addClass('open');
    }
    return false;
    });
    });*/

    $("#te_menuFaq li.toggleSubMenu h3 > a").click(function() {
        //JCA@22/04/2010 - Accessibilité - 6.3
        var TexteSpan = $(this).text();
        if ($(this).parent().next().is(":visible")) {
            $(this).parent().next().slideUp(1000, function() {
                $(this).parent().removeClass("open");
                //JCA@22/04/2010 - Accessibilité - 6.3
                //$(this).prev().children("a").attr("title", "Afficher le sous-menu ");
                $(this).prev().children("a").attr("title", "Afficher le sous-menu "+ TexteSpan);
            });
            $("#te_menuFaq .open h3 > a").attr("title", "Masquer le sous-menu "+ TexteSpan);
        }
        else {
            $("#te_menuFaq ul.subMenu").slideUp("slow", function() {
                $(this).parent().removeClass("open");
            });
            $(this).parent().next().slideDown(1000, function() {
                $(this).parent().addClass("open");
                $(this).prev().children("a").attr("title", "Masquer le sous-menu "+ TexteSpan);
            });
            $("#te_menuFaq .open h3 > a").attr("title", "Afficher le sous-menu "+ TexteSpan);
        }
        return false;
    });

    //version safe
    /*$("li.toggleSubMenu h3 > a").click(function() {
    var $a = $(this);
    if($(this).parent().next().is(":visible")) {
    $(this).parent().next().slideUp(2000, function() {
    $(this).parent().removeClass("open");
    $(this).prev().children("a").attr("title", "Afficher le sous-menu");
    });
    $(".open h3 > a").attr("title", "Masquer le sous-menu");
    }
    else {
    $("ul.subMenu").slideUp("slow", function() {
    $(this).parent().removeClass("open");
    });
    $(this).parent().next().slideDown(2000, function() {
    $(this).parent().addClass("open");
    $(this).prev().children("a").attr("title", "Masquer le sous-menu");
    });
    $(".open h3 > a").attr("title", "Afficher le sous-menu");
    }
    return false;
    });*/

    //    $("ul.subMenu:not('.open_at_load')").hide();
    //    $("li.toggleSubMenu span").each(function() {
    //        var TexteSpan = $(this).text();
    //        $(this).replaceWith('<a href="" title="Afficher le sous-menu">' + TexteSpan + '</a>');
    //    });
    //    $('.open_at_load').prev("a").attr("title", "Masquer le sous-menu");
    //    $("li.toggleSubMenu > a").click(function() {
    //        if ($(this).next("ul.subMenu:visible").length != 0) {
    //            $(this).next("ul.subMenu").slideUp("slow", function() {
    //                $(this).parent().removeClass("open");
    //                $(this).prev("a").attr("title", "Afficher le sous-menu");
    //            });
    //            $(".open a").attr("title", "Masquer le sous-menu");
    //        }
    //        else {
    //            $("ul.subMenu").slideUp("slow", function() { $(this).parent().removeClass("open") });
    //            $(this).next("ul.subMenu").slideDown("slow", function() {
    //                $(this).parent().addClass("open");
    //                $(this).prev("a").attr("title", "Masquer le sous-menu");
    //            });
    //            $(".open a").attr("title", "Afficher le sous-menu");
    //        }
    //        return false;
    //    });

    // Date limite à deux mois
    DateNow = new Date();
    DateLimit = new Date(DateNow.getFullYear(), DateNow.getMonth() + 2, DateNow.getDate());
			
    $('.date-pick').datePicker({
        endDate: DateLimit.asString()
    });
    $('.date-pick').change(function() {
        v = $(this).attr("value");
        v = v.split(/\//);
        $(".date_aller option[value='" + v[0] + "']").attr("selected", true);
        $(".mois_aller option[value='" + v[1] + "']").attr("selected", true);
        $(".annee_aller option[value='" + v[2] + "']").attr("selected", true);
    });


    $('.date-pick2').datePicker({
        endDate: DateLimit.asString()
    });
    $('.date-pick2').change(function() {
        v = $(this).attr("value");
        v = v.split(/\//);
        $(".date_retour option[value='" + v[0] + "']").attr("selected", true);
        $(".mois_retour option[value='" + v[1] + "']").attr("selected", true);
        $(".annee_retour option[value='" + v[2] + "']").attr("selected", true);
    });

    $(".agenda_selection > dl").addClass("hide");
    $(".agenda_lien").click(function() {
        $(this).parent().find("dl").toggleClass("hide");
        return false;
    });
		
		/*Pyco Add*/
		/*
		var getDateCur = DateNow.getDate();
		if(getDateCur < 10) 
			getDateCur = '0' + getDateCur;
		$('.DuDateAller').val(getDateCur);
		$('.DuMoisAller').val(Date.monthNames[DateNow.getMonth()]);
		$('.DuAnneeAller').val(DateNow.getFullYear());
		$('.DuAnneeAller option').text(DateNow.getFullYear());
		
		
		
		$('.AuDateAller').val(getDateCur);
		$('.AuMoisAller').val(Date.monthNames[DateNow.getMonth()]);
		$('.AuAnneeAller').val(DateNow.getFullYear());
		$('.AuAnneeAller option').text(DateNow.getFullYear());
		
		$('.DuDateRetour').val(getDateCur);
		$('.DuMoisRetour').val(Date.monthNames[DateNow.getMonth()]);
		$('.DuAnneeRetour').val(DateNow.getFullYear());
		$('.DuAnneeRetour option').text(DateNow.getFullYear());
		
		$('.AuDateRetour').val(getDateCur);
		$('.AuMoisRetour').val(Date.monthNames[DateNow.getMonth()]);
		$('.AuAnneeRetour').val(DateNow.getFullYear());
		$('.AuAnneeRetour option').text(DateNow.getFullYear());
		
		var getHourCur = DateNow.getHours();
		if(getHourCur < 10) 
			getHourCur = '0' + getHourCur;
		$('.EtrHour').val(getHourCur);
		$('.EtHour').val(getHourCur + 3);
		
		var getMinCur = DateNow.getMinutes();
		if(getMinCur%5 == 0){
			getMinCur = getMinCur;
			if(getMinCur < 10) 
				getMinCur = '0' + getMinCur;
			$('.EtrMin').val(getMinCur);
			$('.EtMin').val(getMinCur);
		} else {
			var EvnHour = new Array();
			var i = getMinCur;
			var j = 0;
			for(var i; i <= 60; i++) {
				if(i%5 == 0) {
					EvnHour[j] = i;
					j++;
				}
			}
			getMinCur = EvnHour[0];
			if(getMinCur < 10) 
				getMinCur = '0' + getMinCur;
			$('.EtrMin').val(getMinCur);
			$('.EtMin').val(getMinCur);
		}
		*/
		$('.DatePick1').datePicker({
        endDate: DateLimit.asString()
    });
    $('.DatePick1').change(function() {
        v = $(this).attr("value");
        v = v.split(/\//);
        $(".DuDateAller option[value='" + v[0] + "']").attr("selected", true);
        $(".DuMoisAller option[value='" + v[1] + "']").attr("selected", true);
        $(".DuAnneeAller option[value='" + v[2] + "']").attr("selected", true);
    });
		
		$('.DatePick2').datePicker({
        endDate: DateLimit.asString()
    });
    $('.DatePick2').change(function() {
        v = $(this).attr("value");
        v = v.split(/\//);
        $(".AuDateAller option[value='" + v[0] + "']").attr("selected", true);
        $(".AuMoisAller option[value='" + v[1] + "']").attr("selected", true);
        $(".AuAnneeAller option[value='" + v[2] + "']").attr("selected", true);
    });
		/*JCA@20111005 - LOT 3.0 FH REC PAGE*/
		/*$('.BlkSH').hide();
		$('.ExpCol').addClass('Collapse');
		$('.ExpCol').attr('title','Bouton permettant l\'ouverture du bloc "RETOUR"');
		if($('.ExpCol').length > 0){
			$('.ExpCol').bind('click', function(){
				if($('.BlkSH').is(':visible')){
					$('.BlkSH').hide();
					$(this).addClass('Collapse');
					$('.ExpCol').attr('title','Bouton permettant l\'ouverture du bloc "RETOUR"');
				} else {
					$('.BlkSH').show();
					$(this).removeClass('Collapse');
					$('.ExpCol').attr('title','Bouton permettant la fermeture du bloc "RETOUR"');
				}
				return false;
			});
		}*/
		
		$('.DatePick3').datePicker({
        endDate: DateLimit.asString()
    });
    $('.DatePick3').change(function() {
        v = $(this).attr("value");
        v = v.split(/\//);
        $(".DuDateRetour option[value='" + v[0] + "']").attr("selected", true);
        $(".DuMoisRetour option[value='" + v[1] + "']").attr("selected", true);
        $(".DuAnneeRetour option[value='" + v[2] + "']").attr("selected", true);
    });
		
		$('.DatePick4').datePicker({
        endDate: DateLimit.asString()
    });
    $('.DatePick4').change(function() {
        v = $(this).attr("value");
        v = v.split(/\//);
        $(".AuDateRetour option[value='" + v[0] + "']").attr("selected", true);
        $(".AuMoisRetour option[value='" + v[1] + "']").attr("selected", true);
        $(".AuAnneeRetour option[value='" + v[2] + "']").attr("selected", true);
    });
		
    // CLA - 20091124 - 001
    /* Commente par Nicolas Bourles pour accessibilite 20100701*/
    /*if (jQuery('.myselectbox').length > 0) {
        jQuery('.myselectbox').selectbox();
    }
    if (jQuery('.myselectbox2').length > 0) {
        jQuery('.myselectbox2').selectbox();
    } */
    // CLA - 20091124 - 001
    // GFA@25/01/2010 1478
    if (jQuery('.myselectbox3').length > 0) {
        jQuery('.myselectbox3').selectbox();
    }
    // GFA@25/01/2010 1479
    if (jQuery('.myselectbox4').length > 0) {
        jQuery('.myselectbox4').selectbox();
    }
    if (jQuery('.myselectbox5').length > 0) {
        jQuery('.myselectbox5').selectbox();
    }
    
    $(".menu2 a").append("<em></em>");

    $(".menu2 a").hover(function() {
        $(this).find("em").animate({ opacity: "show" }, "slow");
        var hoverText = $(this).attr("title");
        $(this).find("em").text(hoverText);
        ma_var = $(this).attr("title");
        $(this).attr("title", "");
        ma_alt = $(this).find("img").attr("alt");
        $(this).find("img").attr("alt", "");

    }, function() {
        $(this).find("em").animate({ opacity: "hide" }, "fast");
        $(this).attr("title", ma_var);
        $(this).find("img").attr("alt", ma_alt);

    });

    if ($('.te_message_client').is('div')) {
        $('.te_message_client tr').each(function() {
            $(this).mouseover(function() {
                $(this).addClass('te_over_tr');
            });
            $(this).mouseout(function() {
                $(this).removeClass('te_over_tr');
            });
        });
    }
    //sdi
    $(function() {
        /*$(".te_heures_loisirs, .onglet_loisirs").hide();
        $(".te_heures_loisirs:first, .onglet_loisirs:first").show();*/

        $(".te_heures_loisirs a").click(function() {
            $(".te_heures_loisirs, .onglet_loisirs").hide();
            $($(this).attr("href")).show();

            $($(this).attr("href")).prev(".te_heures_loisirs").show();

            $(this).blur();
            return (false);
        });
    });
    //sdi fin
		$('.TblData table').hide();
		$('.TblData table:eq(0)').show();
		/*JCA@20111017 - LOT 3.0 Adaptation code FULL6*/
		/*Pyco Command 31/05/2011*/
		/*$('.LnkTab a').bind('click',function(){
			$('.TblData table').hide();
			$('.LnkTab a').removeClass('active');
			$(this).addClass('active');
			var id = $(this).attr('href');
			$('table' + id ).show();
			return false;
		});*/
});

function init_focus_home() {
    fobj = document.getElementById("focus_home");
    fobj.className = 'dyn';
    fobj.cur = 0;
    fobj.chld = fobj.getElementsByTagName("DIV");
    fobj.className = 'dyn';
    for (i = 0; i < fobj.chld.length; i++) {
        evt = fobj.chld[i].getElementsByTagName("H2")[0];
        tablnk = document.createElement("A");
        tablnk.setAttribute("href", "#");
        // tablnk.setAttribute("title", "Onglet actif");
        tablnk.innerHTML = evt.innerHTML;
        evt.innerHTML = '';
        evt.appendChild(tablnk);
        evt = fobj.chld[i].evt = tablnk;
        evt.prt = fobj;
        evt.onclick = function() {
            return this.prt.show_focus_home(1 - fobj.cur);
        }
    }
    fobj.show_focus_home = function(ind) {
        fobj.chld[1 - ind].style.visibility = 'hidden';
        fobj.chld[(fobj.cur = ind)].style.visibility = 'visible';
        return false;
    }
    fobj.show_focus_home(0);
}

function favoris(_url, _titre) {
    if (navigator.appName != 'Microsoft Internet Explorer') {
        window.sidebar.addPanel(_titre, _url, "");
    }
    else {
        window.external.AddFavorite(_url, _titre);
    }
}
function init_focus_home_normal() {
    $(document).ready(function() {
        $("a#deplivente").click(function() {
            
            $("#listeenvente").attr('class', '');
            $("#listeenligne").attr('class', 'on');

            $('#flash_actus_on').attr('src', '../../../images/home/flash-actus-on.png');
            $('#info_travaux_on').attr('src', '../../../images/home/travaux-of.png');

            /*$('#flash_actus_on').attr('alt', 'flash_actu_active');*/
            $('#flash_actus_on').attr('alt', 'flash actu onglet actif');
            /*$('#info_travaux_on').attr('alt', 'info_travaux_non_active');*/
            $('#info_travaux_on').attr('alt', 'travaux');

        });
        $("a#depliligne").click(function() {
            
            $("#listeenvente").attr('class', 'of');
            $("#listeenligne").attr('class', 'active');

            $('#flash_actus_on').attr('src', '../../../images/home/flash-actus-of.png');
            $('#info_travaux_on').attr('src', '../../../images/home/travaux-on.png');
            
            /*$('#flash_actus_on').attr('alt', 'flash_actu_non_active');*/
            $('#flash_actus_on').attr('alt', 'flash actu');
            /*$('#info_travaux_on').attr('alt', 'info_travaux_active');*/
            $('#info_travaux_on').attr('alt', 'travaux onglet actif');
        });
        $("img.flash_actus_of").toggleClass("of");
        $("img.info_travaux_on").toggleClass("of");
        $('body').addClass('js');

    });
}

function init_focus_home_light() {
    $(document).ready(function() {
        $("a#deplivente_light").click(function() {
            
            $("#listeenvente").attr('class', '');
            $("#listeenligne").attr('class', 'on');

            $('#flash_actus_on_light').attr('src', '../../../images/home/flash-actus-on.png');
            $('#info_travaux_on_light').attr('src', '../../../images/home/travaux-of.png');

            /*$('#flash_actus_on_light').attr('alt', 'flash_actu_active');*/
            $('#flash_actus_on_light').attr('alt', 'flash actu onglet actif');
            /*$('#info_travaux_on_light').attr('alt', 'info_travaux_non_active');*/
            $('#info_travaux_on_light').attr('alt', 'travaux');

        });
        $("a#depliligne_light").click(function() {
            $("#listeenvente").attr('class', 'of');
            $("#listeenligne").attr('class', 'active');

            $('#flash_actus_on_light').attr('src', '../../../images/home/flash-actus-of.png');
            $('#info_travaux_on_light').attr('src', '../../../images/home/travaux-on.png');
            
            /*$('#flash_actus_on_light').attr('alt', 'flash_actu_non_active');*/
            $('#flash_actus_on_light').attr('alt', 'flash actu');
            /*$('#info_travaux_on_light').attr('alt', 'info_travaux_active');*/
            $('#info_travaux_on_light').attr('alt', 'travaux onglet actif');
        });
        $("img.flash_actus_of_light").toggleClass("of");
        $("img.info_travaux_on_light").toggleClass("of");
        $('body').addClass('js');

    });
}

function init_onglet_home_normal(idx_onglet) {
    if (idx_onglet == 0) {

        $("#listeenvente").attr('class', '');
        $("#listeenligne").attr('class', 'on');

        $('#flash_actus_on').attr('src', '../../../images/home/flash-actus-on.png');
        $('#info_travaux_on').attr('src', '../../../images/home/travaux-of.png');

        /*$('#flash_actus_on').attr('alt', 'flash_actu_active');*/
        $('#flash_actus_on').attr('alt', 'flash actu onglet actif');
        /*$('#info_travaux_on').attr('alt', 'info_travaux_non_active');*/
        $('#info_travaux_on').attr('alt', 'travaux');
    } else {

        $("#listeenvente").attr('class', 'of');
        $("#listeenligne").attr('class', 'active');

        $('#flash_actus_on').attr('src', '../../../images/home/flash-actus-of.png');
        $('#info_travaux_on').attr('src', '../../../images/home/travaux-on.png');
        
        /*$('#flash_actus_on').attr('alt', 'flash_actu_non_active');*/
        $('#flash_actus_on').attr('alt', 'flash actu');        
        /*$('#info_travaux_on').attr('alt', 'info_travaux_active');*/
        $('#info_travaux_on').attr('alt', 'travaux onglet actif');
    }
}

function init_onglet_home_light(idx_onglet) {
    if (idx_onglet == 0) {

        $("#listeenvente").attr('class', '');
        $("#listeenligne").attr('class', 'on'); ;

        $('#flash_actus_on_light').attr('src', '../../../images/home/flash-actus-on.png');
        $('#info_travaux_on_light').attr('src', '../../../images/home/travaux-of.png');

        /*$('#flash_actus_on_light').attr('alt', 'flash_actu_active');*/
        $('#flash_actus_on_light').attr('alt', 'flash actu onglet actif');
        /*$('#info_travaux_on_light').attr('alt', 'info_travaux_non_active');*/
        $('#info_travaux_on_light').attr('alt', 'travaux');

    } else {
        $("a#deplivente_light").toggleClass("active");
        $("a#depliligne_light").toggleClass("active");

        $("#listeenvente").attr('class', 'of');
        $("#listeenligne").attr('class', 'active');

        $('#flash_actus_on_light').attr('src', '../../../images/home/flash-actus-of.png');
        $('#info_travaux_on_light').attr('src', '../../../images/home/travaux-on.png');
        
        /*$('#flash_actus_on_light').attr('alt', 'flash_actu_non_active');*/
        $('#flash_actus_on_light').attr('alt', 'flash actu');
        /*$('#info_travaux_on_light').attr('alt', 'info_travaux_active');*/
        $('#info_travaux_on_light').attr('alt', 'travaux onglet actif');
    }
}


