$(document).ready(function() {
	
	//Remplissage/vidage de la valeur du champ recherche
	$("#inputRecherche").focus(function(){
		$(this.value = '');
	});
	
	$("#inputRecherche").blur(function(){
		if(this.value == ''){
			$(this.value = 'Rechercher');
		}
	}); 
        
	//Hack transparence des png pour ie6
	if(jQuery.browser.msie) {
		if(jQuery.browser.version == '6.0') {
			DD_belatedPNG.fix('body, .png');
		} 
	}
	
	//Menu Principal
        var SelfLocation = window.location.href.split('?');
        switch (SelfLocation[1]) {
            case "justify_right":
                jQuery(".megamenu").megamenu({'justify':'right'});
                break;
            case "justify_left":
            default:
                jQuery(".megamenu").megamenu();
        }
	
	//Gestion de l'affichage par onglet de la home
	$(".actuOnglet").each(function(){
		
		$(this).click(function(){
			
			$(".actuOnglet").css('z-index', '0');
			
			$(this).css('z-index', '200');
			
			$div = $(this).attr('class').substring(11 , $(this).attr('class').length);
		
			$(".contenuOnglet").css('display', 'none');
			
			$('#'+$div).css('display', 'block');
			
		});
		
	});
        $(".actuOngletInterieur").each(function(){

		$(this).click(function(){

			$(".actuOngletInterieur").css('z-index', '0');

			$(this).css('z-index', '200');
                        //alert("ici");
			$div = $(this).attr('class').substring(20 , $(this).attr('class').length);
                        alert($div);
			$(".contenuOnglet").css('display', 'none');

			$('#'+$div).css('display', 'block');

		});

	});
        $("a.reglinks").click(function(){
              var div = $(this).attr('id').split('_');
              $(".structures").css('display', 'none');
              $('#'+div[1]).css('display', 'block'); 
              $('#'+div[1]).css('width', '600px');
              $('#'+div[1]).css('line-height', '14px');
              
              
              
              return false;
              
	 });
         $("a.reglinks2").fancybox({
                'autoSize'        :     false,
                'width'                 : '600px',
                'maxHeight'                :'400'
	});
	 $("a.pres").fancybox({
                'autoSize'        :     false,
                'width'                 : '600'
               
	});
        
        $("a.maplink").fancybox({
                maxWidth	: 600,
		maxHeight	: 600,
		fitToView	: false,
		width		: '70%',
		height		: '70%',
		autoSize	: false,
		closeClick	: false,
		openEffect	: 'none',
		closeEffect	: 'none'
	});
         
         //voting
         $("a.votebtn").click(function(){

	      $("#choix").val($(this).attr("href"));
              $('#vote').submit();
	      return false;
	 });
         
	 // Fonction lien dans un nouvel onglet
	 $("a.externe").click(function(){
	      window.open(this.href);
	      return false;
	 });
	 
	 $("#bandeauLogo").click(function(){
	      window.location.href='index.php';
	 });
	 $("#bandeauLogoSmall").click(function(){
	      window.location.href='index.php';
	 });
         $("#delete_action").click(function(){
	      return confirm("Voulez-vous supprimer cet element ? \n(Cette action est irréversible)")
	 });
          //Animation sur Focus
        $("div.miseEnValeur").mouseover(function(){
            $(this).children().removeClass('hidden');
            $(this).children().stop().animate({height:'255px'},{queue:false, duration:600, easing: 'easeOutBounce'})
        });
        $("div.subFocus").mouseout(function(){
//            $(this).fadeOut( 'fast', function() {
//                $(this).addClass('hidden');
//              });
             
             $(this).stop().animate({height:'0px'},{queue:false, duration:600, easing: 'easeOutBounce'});
        });
        function gup( name )
        {
          name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
          var regexS = "[\\?&]"+name+"=([^&#]*)";
          var regex = new RegExp( regexS );
          var results = regex.exec( window.location.href );
          if( results == null )
            return "";
          else
            return results[1];
        }
        $('#year9').change(function () {
                    var current_year= gup('year');
                     if($(this).val()!="" && current_year!=$(this).val()){
                         window.location.href='?focus=9&year='+ $(this).val() +'&view=list';
                     }
                 }).change();
        $('#year10').change(function () {
                     var current_year= gup('year');
                     if($(this).val()!="" && current_year!=$(this).val()){
                         window.location.href='?focus=10&year='+ $(this).val() +'&view=list';
                     }
                 }).change();
        $('#year11').change(function () {
                     var current_year= gup('year');
                     if($(this).val()!="" && current_year!=$(this).val()){
                         window.location.href='?focus=11&year='+ $(this).val() +'&view=list';
                     }
                 }).change();
        $('#year12').change(function () {
                     var current_year= gup('year');
                     if($(this).val()!="" && current_year!=$(this).val()){
                         window.location.href='?focus=12&year='+ $(this).val() +'&view=list';
                     }
                 }).change();
        $('#year13').change(function () {
                     
                     var current_year= gup('year');
                     if($(this).val()!="" && current_year!=$(this).val()){
                         //alert('change');
                         window.location.href='?focus=13&year='+ $(this).val();
                     }
                 }).change();
        
        $("#autre_syndicat").click(function () {
                    //alert($(this).attr('checked'));
                    if($(this).attr('checked')){
                        $("#detail_autre_syndicat").fadeIn("slow");
                        $("#detail_autre_syndicat").addClass("required");

                    }else{
                        $("#detail_autre_syndicat").fadeOut("slow");
                        $("#detail_autre_syndicat").removeClass("required");
                    }
                 });
         setTimeout("$('#message').fadeOut();",3000)
                //$('.required').parent().parent().find('td').find('label').append("<span class='requiredlabel'>*</span>");
                $(".required").blur(function() {
                     if($(this).val()==""){
                         $(this).addClass("error");

                         //alert('please enter a value '+$(this).attr('placeholder'));
                         document.getElementById($(this).attr('id')).value="";
                         //document.getElementById($(this).attr('id')).focus();
                     }else{
                         $(this).removeClass("error");
                     }
                 });
                $(".email").blur(function() {
                    var reg = new RegExp('^[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*@[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*[\.]{1}[a-z]{2,6}$', 'i');
                     //alert($(this).val());
                     if(!reg.test($(this).val())){
                         $(this).addClass("error");

                         //alert('please enter a value '+$(this).attr('placeholder'));
                         //document.getElementById($(this).attr('id')).value="";
                         //document.getElementById($(this).attr('id')).focus();
                     }else{
                         $(this).removeClass("error");
                     }
                 });
                 
         
        
        $("ul.tabs li").click(function() {
            var activeLi = '#'+$(this).attr('id');
            var reg=new RegExp("[_]+", "g");
            var tableau=activeLi.split(reg);

            $("ul.tabs li").removeClass("active"); //Remove any "active" class
            
            $("ul.tabs "+activeLi).addClass("active");
            $('#pager [value="'+tableau[1]+'"]').attr('selected',true)
            $(".tab_content").hide(); //Hide all tab content
            var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
            $(activeTab).fadeIn();
            
            return false;
        });
        
        $("ul.tabs2 li").click(function() {
        	var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
        	
        	$("ul.tabs2 li").removeClass("active");
        	
        //alert($(this).find("a").attr("href"))
            var activeLi = '#'+$(this).attr('id');
            $(this).addClass("active");
            //var reg=new RegExp("[_]+", "g");
            //var tableau=activeLi.split(reg);

            //$("ul.tabs li").removeClass("active"); //Remove any "active" class
            
            //$("ul.tabs "+activeLi).addClass("active");
            //$('#pager [value="'+tableau[1]+'"]').attr('selected',true)
            $(".tab_content2").hide(); //Hide all tab content
            
            $(activeTab).fadeIn();
            
            return false;
        });
        
        
        $("#pager").change(function () {
                    var str = "";
                    str =$("select option:selected").val();
                                        var activeLi = '#li_'+str;
                    $("ul.tabs li").removeClass("active");
                    $("ul.tabs "+activeLi).addClass("active");
                    var activeTab='#page_'+str;
                   
                    $(".tab_content").hide();
                    $(activeTab).fadeIn();
                    
                    
         });
                 
        $(".tab_content").hide();
        $(".tab_content:first").show();
        $(".tab_content2").hide();
        $(".tab_content2:first").show();
        $(".autre").click(function() {
            if($(this).attr('checked')){
                $("#secteur_autre").addClass("required");
            }else{
                $("#secteur_autre").removeClass("required");
            }
        });
        
        $('#secteur').change(function () {
                    if($(this).val()=="autre"){
                    	$("#autre_secteur_user").val($("#backup_autre").val());
                      	$("#autre_secteur_user").fadeIn("slow");
                        //$("#autre_secteur_user").addClass("required");
					}else{
                        $("#autre_secteur_user").fadeOut("slow");
                        //$("#autre_secteur_user").removeClass("required");
                        $("#autre_secteur_user").val("");
                    }

                 }).change();
		$('#secteur2').change(function () {
                    if($(this).val()=="autre"){
                    	$("#autre_secteur_user2").val($("#backup_autre2").val());
                      	$("#autre_secteur_user2").fadeIn("slow");
                        //$("#autre_secteur_user").addClass("required");
					}else{
                        $("#autre_secteur_use2r").fadeOut("slow");
                        //$("#autre_secteur_user").removeClass("required");
                        $("#autre_secteur_user2").val("");
                    }

                 }).change();
	
	
});

