/*----------------------------------------------------------------------------//
// 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/abso.navigateur.js");
importJavascript("/includes/js/swfobject.js");
importJavascript("/includes/js/plugins/jcarousel.js");
importJavascript("/includes/js/plugins/abso.caroussel.js");
importJavascript("/includes/js/plugins/abso.uploadfield.js");
importJavascript("/includes/js/plugins/jquery.colorbox.js");
importCss("/includes/js/plugins/abso.uploadfield.css", "screen");
importCss("/includes/js/plugins/datePicker.css", "screen");

/*----------------------------------------------------------------------------*/
// Declarations jQuery
/*----------------------------------------------------------------------------*/

var loginBoxDeployed = false;
var menuFocus = false;
var slideshowPosition = "";

$(document).ready(function () {

    InitOldBrowser();

    jQuery(".upload").uploadfield();
    jQuery("hr").replaceWith("<div class=\"hr\">&nbsp;</div>");
    jQuery(".BlocColonne:last-child").find(".hr").remove();
    jQuery(".TableauNavigateurs").each(function () {
        jQuery(this).find("table").find("tr:even").children("td").addClass("Alt");
    });
    jQuery("a.LienSpecial").each(function () {
        jQuery(this).html("<span>" + jQuery(this).text() + "</span>");
    });

    jQuery(".Colorbox").colorbox({ inline: true, href: "#ColorboxContent", opacity: 0.3 });

    // ------------------------------------------------------------------------
    // TABLEAUX POUR CLIENTS
    // ------------------------------------------------------------------------
    jQuery("tr", ".TableauClients").each(function () {
        jQuery(this).children("td:last-child").addClass("DernierItem");
    });

    // ------------------------------------------------------------------------
    // BOUTONS À COINS RONDS
    // ------------------------------------------------------------------------
    jQuery("a.LienBouton, a.uf_UploadButton, a.uf_ResetButton").css("border-radius", "5px");
    jQuery("a.LienBouton, a.uf_UploadButton, a.uf_ResetButton").css("-moz-border-radius", "5px");
    jQuery("a.LienBouton, a.uf_UploadButton, a.uf_ResetButton").css("-webkit-border-radius", "5px");

    $("a.uf_UploadButton").each(function () {
        $(this).html("<span>" + $(this).text() + "</span>");
    });

    // ------------------------------------------------------------------------
    // EFFET AVEC FOND GRIS AU SURVOL D'UN ÉLÉMENT
    // ------------------------------------------------------------------------
    jQuery("li", ".ListeGeneree").hover(
		function () {
		    $(this).addClass("Hover");
		},
	  	function () {
	  	    $(this).removeClass("Hover");
	  	}
	);

    jQuery(".Nouvelle").hover(
		function () {
		    $(this).addClass("Hover");
		},
	  	function () {
	  	    $(this).removeClass("Hover");
	  	}
	);

    jQuery("li", ".ContenuCaroussel").hover(
		function () {
		    $(this).addClass("Hover");
		},
	  	function () {
	  	    $(this).removeClass("Hover");
	  	}
	);

    // ------------------------------------------------------------------------
    // CALENDRIER
    // ------------------------------------------------------------------------
    if (jQuery("body").attr("id") == "lang-FR") {
        var nomMois = ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'];
        var nomJournee = ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'];
        var nomJourneeMin = ['D', 'L', 'M', 'M', 'J', 'V', 'S'];
    }
    else {
        var nomMois = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
        var nomJournee = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
        var nomJourneeMin = ['S', 'M', 'T', 'W', 'T', 'F', 'S'];
    }

    if (jQuery(".Calendrier").length == 1) {
        jQuery(".Calendrier").datepicker({
            monthNames: nomMois,
            dayNames: nomJournee,
            dayNamesMin: nomJourneeMin,
            showOtherMonths: true,
            dateFormat: 'yy-mm-dd',
            beforeShow: function () {
                jQuery(".ui-datepicker").css("border-radius", "5px");
                jQuery(".ui-datepicker").css("-moz-border-radius", "5px");
                jQuery(".ui-datepicker").css("-webkit-border-radius", "5px");
            }
        });
    }


    // ------------------------------------------------------------------------
    // EFFET DE SURVOL SUR LE MENU PRINCIPAL
    // ------------------------------------------------------------------------
    jQuery("#BlocMenus li").mouseover(function () {
        menuFocus = true;
        var menuElementWidth = jQuery(this).children("a").width();
        var menuElementPosition = jQuery(this).position().left;
        jQuery("#Highlight").stop().animate({
            width: menuElementWidth,
            left: menuElementPosition
        });
    });
    jQuery("#BlocMenus li").mouseout(function () {
        menuFocus = false;
    });

    setInterval(function () {
        if (menuFocus == false) removeHighlight();
    }, 500);

    // ------------------------------------------------------------------------
    // APPEL DES CAROUSSELS
    // ------------------------------------------------------------------------
    jQuery(".Caroussel").each(function () {
        carouselID = jQuery(this).attr("id");
        var itemCount = jQuery(this).find("li").length;
        if (itemCount < 4) {
            jQuery(this).children(".BoutonPrecedent").remove();
            jQuery(this).children(".BoutonSuivant").remove();
        }
        jQuery(this).children(".ContenuCaroussel").jCarouselLite({
            btnNext: "#" + carouselID + " " + ".BoutonSuivant",
            btnPrev: "#" + carouselID + " " + ".BoutonPrecedent",
            visible: jQuery(this).find("li").length
        });
    });

    // ------------------------------------------------------------------------
    // CONNEXION POUR ZONE CLIENT
    // ------------------------------------------------------------------------
    jQuery("#BoiteConnexion .TxtBox").css({ opacity: 0 });
    jQuery("#BoiteConnexion .BoutonConnexion").css({ opacity: 0 });
    jQuery(".LienZoneClient").click(function () {
        if (loginBoxDeployed == false) openLoginBox();
        else closeLoginBox();
        return false;
    });
    jQuery(".BoutonFermeture").click(function () {
        closeLoginBox();
        return false;
    });

    // ------------------------------------------------------------------------
    // INPUT LABEL FOCUS
    // ------------------------------------------------------------------------
    if (jQuery(".LabelFocus").length > 0) {
        jQuery(".LabelFocus").each(function () {
            jQuery(this).val(jQuery(this).attr("title"));
            jQuery(this).focus(function () {
                if (jQuery(this).val().length == 0 || jQuery(this).val() == jQuery(this).attr("title")) {
                    jQuery(this).val("");
                }
            });
            jQuery(this).blur(function () {
                if (jQuery(this).val().length == 0 || jQuery(this).val() == jQuery(this).attr("title")) {
                    jQuery(this).val(jQuery(this).attr("title"));
                }
            });
        });
    }

    // ------------------------------------------------------------------------
    // ACCORDÉONS DES EMPLOIS OFFERTS
    // ------------------------------------------------------------------------
    jQuery(".Poste").hover(
		function () {
		    $(this).addClass("Hover");
		},
	  	function () {
	  	    $(this).removeClass("Hover");
	  	}
	);

    //jQuery(classList).click(function() { return triggerJobDetails($(this));}); 

    // ------------------------------------------------------------------------
    // FAUX MENU DÉROULANT
    // ------------------------------------------------------------------------
    jQuery(".SelectionMenuDeroulant").click(function () {
        jQuery(".SelectionMenuDeroulant").toggleClass("On");
        jQuery(this).parent(".BlocMenuDeroulant").find(".MenuDeroulant").toggleClass("On");
        jQuery(document).bind("click", function () {
            jQuery(".SelectionMenuDeroulant").removeClass("On");
            jQuery(".MenuDeroulant").removeClass("On");
            jQuery(this).unbind("click");
        });
        return false;
    });

    jQuery("a", ".MenuDeroulant").click(function () {
        var specialite = jQuery(this).text();
        jQuery(this).parents(".BlocMenuDeroulant").find("a.SelectionMenuDeroulant").html(specialite);
        jQuery(this).parents(".BlocMenuDeroulant").find(".inputMenuDeroulant").val(specialite);
        jQuery(this).parents(".BlocMenuDeroulant").find(".SelectionMenuDeroulant").removeClass("On");
        jQuery(this).parents(".BlocMenuDeroulant").find(".MenuDeroulant").removeClass("On");
        return false;
    });

    // ------------------------------------------------------------------------
    // CAROUSSEL DES RÉALISATIONS
    // ------------------------------------------------------------------------

    /*
    jQuery("#SlideshowRealisations").mousemove(function(e){
    var cursorPosition = (e.pageY - slideshowPosition) - 18;
    jQuery("#BtRealisationPrecedente, #BtRealisationSuivante").css("top", cursorPosition);
    });
	
    jQuery("#SlideshowRealisations").hover(
    function () {
    slideshowFocus = true;
    },
    function () {
    slideshowFocus = false;
    }
    );
	
    jQuery("#BtRealisationPrecedente").hover(
    function () {
    prevFocus = true;
    },
    function () {
    prevFocus = false;
    }
    );
	
    jQuery("#BtRealisationSuivante").hover(
    function () {
    nextFocus = true;
    },
    function () {
    nextFocus = false;
    }
    );
	
    setInterval(function(){
    if(slideshowFocus == false && prevFocus == false && nextFocus == false) jQuery("#BtRealisationPrecedente, #BtRealisationSuivante").stop().animate({ opacity : 0 }, 200);
    else jQuery("#BtRealisationPrecedente, #BtRealisationSuivante").stop().animate({ opacity : 1 }, 200);
    }, 200);
    */


    // ------------------------------------------------------------------------
    // BOITE DES TÉMOIGNAGES
    // ------------------------------------------------------------------------
    jQuery("#BoiteTemoignages").children("li").css("display", "none");
    jQuery("#BoiteTemoignages").children("li:first-child").css("display", "block");
    jQuery("#BoiteTemoignages").css("height", jQuery("#BoiteTemoignages").children("li:first-child").height());

    jQuery("a", ".SelectionTemoignage").click(function () {
        var selectedTestimony = jQuery(this).attr("href");
        jQuery("#BoiteTemoignages").children("li").fadeOut(200);
        jQuery(selectedTestimony).fadeIn(1000);
        jQuery("#BoiteTemoignages").animate({ height: jQuery(selectedTestimony).height() });
        jQuery("a", ".SelectionTemoignage").removeClass("On");
        jQuery(this).addClass("On");
        return false;
    });

    // ----------------------------------------------------------------------------
    // LOGIN
    // ----------------------------------------------------------------------------
    function login() {
        var cultureName = $("#CurrentCulture").val();
        var login = $("#txtLogin").val();
        var password = $("#txtPasword").val();

        $.ajax({
            type: "POST",
            url: "/Presentation/Services/ValidateLogin.ashx",
            data: "c=" + cultureName + "&l=" + login + "&p=" + password,
            success: function (msg) {
                if (msg != "") {
                    document.location = msg;
                }
                else {
                    $("#txtLogin").addClass("Erreur");
                    $("#txtPasword").addClass("Erreur");

                    if (!$("#LoginErrorMessage").is(':visible')){
                        var boxWidth = $('#LoginErrorMessage').width();
                        $("#LoginErrorMessage").css({ 'display': 'block', 'width': '0' });
                        $('#LoginErrorMessage').animate({ width: boxWidth }, 500);
                    }
                }
            }
        });

        return false;
    }


    jQuery("#ValidateLogin").click(function () {
        login();
    });

    //<![CDATA[
    jQuery('#txtLogin').keypress(function (e) {
        if (e.which == 13) {
            return login();
        }
    });

    //<![CDATA[
    jQuery('#txtPasword').keypress(function (e) {
        if (e.which == 13) {
            return login();
        }
    });

    // ----------------------------------------------------------------------------
    // INFOLETTRE
    // ----------------------------------------------------------------------------
    jQuery("#SubscribeInfolettre").click(function () {
        SubscribeInfoLettre();
        return false;
    });

    jQuery('#InfolettreEmail').keypress(function (e) {
        if (e.which == 13) {
            SubscribeInfoLettre();
            return false;
        }
    });

    // ------------------------------------------------------------------------
    // AFFICHAGE DES DATES IMPORTANTES
    // ------------------------------------------------------------------------
    jQuery("#DatesImportantes").children("span:last-child").remove();
    jQuery("#DetailDatesImportantes").children("li").css("display", "none");
    jQuery("#DatesImportantes").children("a:first").addClass("On");
    jQuery("#DetailDatesImportantes").children("li:first-child").css("display", "block");

    jQuery("a", "#DatesImportantes").click(function () {
        var selectedDate = jQuery(this).attr("href");
        jQuery("#DetailDatesImportantes").children("li").fadeOut(200);
        jQuery(selectedDate).fadeIn(500);
        jQuery("a", "#DatesImportantes").removeClass("On");
        jQuery(this).addClass("On");
        return false;
    });



    // ------------------------------------------------------------------------
    // Like Facebook
    // ------------------------------------------------------------------------
    $('.LikeFacebook').html('<iframe src="http://www.facebook.com/plugins/like.php?locale=' + ((jQuery('body').attr('id') == 'lang-FR') ? 'fr_FR' : 'en_US') + '&amp;href=http%3A%2F%2Fwww.facebook.com%2FAbsolunet&amp;layout=standard&amp;show_faces=false&amp;width=245&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=50" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:245px; height:50px;" allowTransparency="true"></iframe>');
});

// ----------------------------------------------------------------------------
// RETRAIT DE L'EFFET DE SURVOL SUR LE MENU PRINCIPAL
// ----------------------------------------------------------------------------
function removeHighlight(){
	jQuery("#Highlight").stop().animate({
		width: 0
	});	
}

// ----------------------------------------------------------------------------
// OUVERTURE DE LA BOITE D'ACCÈS À LA ZONE CLIENT
// ----------------------------------------------------------------------------
function openLoginBox(){
	jQuery("#BoiteConnexion").slideDown(250);
	jQuery("#BoiteConnexion .TxtBox").animate({opacity: 1});
	jQuery("#BoiteConnexion .BoutonConnexion").animate({ opacity: 1 });
	jQuery("#BoiteConnexion p").animate({ opacity: 1 });	
	jQuery("#BoiteActions .BoutonFermeture").fadeIn();
	jQuery(".LienZoneClient").addClass("Off");
	loginBoxDeployed = true;
}

// ----------------------------------------------------------------------------
// FERMETURE DE LA BOITE D'ACCÈS À LA ZONE CLIENT
// ----------------------------------------------------------------------------
function closeLoginBox(){
	jQuery("#BoiteConnexion").slideUp(250);
	jQuery("#BoiteConnexion .TxtBox").animate({opacity: 0});
	jQuery("#BoiteConnexion .BoutonConnexion").animate({ opacity: 0 });
	jQuery("#BoiteConnexion p").animate({ opacity: 0 });												
	jQuery(".LienZoneClient").removeClass("Off");
	jQuery("#BoiteActions .BoutonFermeture").fadeOut();
	loginBoxDeployed = false;
}

// ----------------------------------------------------------------------------
// CAROUSSEL À L'ACCUEIL
// ----------------------------------------------------------------------------
function homeCarrousel(){
	jQuery(".WrapperDescriptionSlideshow").css({opacity: 0});
	jQuery(".WrapperDescriptionSlideshow").eq(0).clone().appendTo("#BulleSlideshow");
	jQuery("#BulleSlideshow").find(".WrapperDescriptionSlideshow").css({opacity: 1});	
	if (jQuery('.Slideshow li').length){		
		jQuery("li",".Slideshow").each(function(){
			var descriptionHeight = Math.floor((jQuery(this).children(".WrapperDescriptionSlideshow").height() + 8) / 2);
			jQuery(".WrapperDescriptionSlideshow").css("margin-top", "-" + descriptionHeight + "px");
		});
		AbsoCaroussel.init({
			id: "SlideshowAccueil",
			wrap: true,
			autostart: true,
			transition: "slide",
			postSwitchCallback: function(data){
				slideshowDescription = jQuery("#BulleSlideshow").find(".WrapperDescriptionSlideshow");
				slideshowDescription.animate({opacity: 0}, function(){
					slideshowDescription.remove();
				});
				jQuery(data.target.obj).find(".WrapperDescriptionSlideshow").clone().appendTo("#BulleSlideshow");
				jQuery("#BulleSlideshow").find(".WrapperDescriptionSlideshow").animate({opacity: 1});
			}
		});
	}	
}

function triggerJobDetails(currentJob)
{
    if (currentJob.parents(".Poste").hasClass("On")) {
        currentJob.parents(".Poste").children(".DescriptionPoste").stop().slideToggle(250, function() {
        currentJob.parents(".Poste").toggleClass("On");
        });
    }
    else {
        jQuery(".Poste").children(".DescriptionPoste").stop().slideUp(250);
        jQuery(".Poste").removeClass("On");
        currentJob.parents(".Poste").children(".DescriptionPoste").stop().slideDown(250, function() {
        currentJob.parents(".Poste").addClass("On");
        });
    }
    return false;
}



// ----------------------------------------------------------------------------
// CAROUSSEL DU DÉTAIL D'UNE RÉALISATION
// ----------------------------------------------------------------------------
function realisationCarrousel(){
	jQuery("#BtRealisationPrecedente, #BtRealisationSuivante").animate({ opacity : 0 });
	slideshowPosition = jQuery("#SlideshowRealisations").offset().top;
	jQuery(".Slideshow .BoutonVoirRealisation").click(function(){
		jQuery(this).fadeOut(500, function(){
			jQuery(this).remove();
		});
		jQuery(".ImageDepart").fadeOut(500, function(){
			jQuery("#BtRealisationPrecedente, #BtRealisationSuivante").css("display", "block");
			jQuery("#BtRealisationPrecedente, #BtRealisationSuivante").animate({ opacity : 1 }, 200);
			jQuery(this).remove();
		});
		imageHeight = jQuery("#SlideshowRealisations").find(".ImageSlideshow:first").height();
		jQuery("#SlideshowRealisations").parents(".Slideshow").animate({ height : imageHeight });
		jQuery("#SlideshowRealisations").animate({ height : imageHeight }, function(){
			slideShowHeight = jQuery(this).height();
		});
		return false;
	});
	if (jQuery('.Slideshow li').length){
		AbsoCaroussel.init({
			id: "SlideshowRealisations",
			wrap: true,
			autostart: false,
			transition: "fade",
			postSwitchCallback: function(data){
				var imageHeight = jQuery(data.target.obj).find(".ImageSlideshow").height();
				jQuery(data.target.obj).parents(".Slideshow").animate({ height : imageHeight });
				jQuery("#SlideshowRealisations").animate({ height : imageHeight }, function(){
					slideShowHeight = jQuery(this).height();
				});
			}
		});
	}
}

// ----------------------------------------------------------------------------
// INSCRIPTION À L'INFOLETTRE
// ----------------------------------------------------------------------------
function SubscribeInfoLettre() {
	var cultureName = $("#CurrentCulture").val();
	var email = $("#InfolettreEmail").val();
	var validator=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
	if(validator.test(email)){         
		$.ajax({
			type: "POST",
			url: "/Presentation/Services/SubscribeMediasend.ashx",
			data: "e=" + email + "&c=" + cultureName,
			success: function(msg) {
				if (msg != "") {
					document.location = msg;
				}
			}
		});
	}
	else{   
		jQuery("#InfolettreEmail").addClass("Erreur"); 
	}
}

// ----------------------------------------------------------------------------
// CAROUSSEL DE LA PAGE DES EMPLOIS
// ----------------------------------------------------------------------------
function jobsCarrousel(){
	if (jQuery('.Slideshow li').length){
		//var firstChildHeight = jQuery("#SlideshowEmplois").children("li:first-child").height();
		var firstChildHeight = 505; // valeur totalement arbitraire...
		jQuery("#SlideshowEmplois").parents(".Slideshow").css("height", firstChildHeight);
		AbsoCaroussel.init({
			id: "SlideshowEmplois",
			wrap: true,
			autostart: false,
			transition: "fade",
			postSwitchCallback: function(data){
				var imageHeight = jQuery(data.target.obj).height();
				jQuery(data.target.obj).parents(".Slideshow").animate({ height : imageHeight });
				jQuery("#SlideshowEmplois").animate({ height : imageHeight }, function(){
					slideShowHeight = jQuery(this).height();
				});
			}
		});
	}
}

// ----------------------------------------------------------------------------
// CAROUSSEL DE LA PAGE À PROPOS
// ----------------------------------------------------------------------------
function aboutCarrousel(){
	if (jQuery('.Slideshow li').length){
		AbsoCaroussel.init({
			id: "SlideshowAbsolunet",
			wrap: true,
			autostart: true,
			transition: "fade"
		});
	}
}

function CheckForm(formName) {
    if (typeof (Page_ClientValidate) == 'function') {
        if (!Page_ClientValidate(formName)) {
            ValidateForm(formName, true, "Erreur");
            return false;
        }
    }
    return true;
}

function ValidateForm(groupName, OnlyOneErrorByField, classError) {
    var msg = new Array();
    var ctl = new Array();
    if (classError != '') jQuery('.' + classError).removeClass(classError);
    for (var i = 0; i < Page_Validators.length; i++) {
        if (Page_Validators[i].validationGroup == groupName && !Page_Validators[i].isvalid) {
            if (OnlyOneErrorByField) {
                var exist = false;
                for (var y = 0; y < ctl.length; y++) {
                    if (ctl[y] == Page_Validators[i].controltovalidate)
                        exist = true;
                }
                if (!exist) {
                    msg[msg.length] = Page_Validators[i].errormessage;
                    if (classError != '') jQuery('#' + Page_Validators[i].controltovalidate).addClass(classError);
                }
            }
            else {
                msg[msg.length] = Page_Validators[i].errormessage;
                if (classError != '') jQuery('#' + Page_Validators[i].controltovalidate).addClass(classError);
            }
            ctl[i] = Page_Validators[i].controltovalidate;
        }
    }
    return msg;
}

function ValidateCheckboxList(source, args) {
    var valid = false;
    var checkValidator = 0;
    jQuery(source).parents(".CheckBoxes").find("input").each(function() {
        if (jQuery(this).attr("checked") == true) checkValidator++;
    });
    if (checkValidator > 0){
        valid = true;
    } else {
        valid = false;
    }
	args.IsValid = valid;
}


var classList = '';
