//antispam
function traiterEmail(chaine1, chaine2, chaine3) {
    window.location.replace("mai" + "lto:" + chaine1 + "@" + chaine2 + chaine3);
}

function ValiderFormulaire(url) {

    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    var address = document.getElementById('2_2').value;
    var bValide = true;
    if (reg.test(address) == false) {
        document.getElementById('2_2').value = 'Email non valide';
        bValide = false;
    }
    if (document.getElementById('1_1').value == '') {
        document.getElementById('1_1').value = 'Champ obligatoire';
        bValide = false;
    }
    if (document.getElementById('2_2').value == '') {
        document.getElementById('2_2').value = 'Champ obligatoire';
        bValide = false;
    }
    if (bValide) {
        document.getElementById('form').action = url;
        document.getElementById('form').submit();
    }
}

/*********************************************************/
/************ D E B U T   F O N C T I O N S **************/
/*********************************************************/


/* ---------- DEBUT PRECHARGEMENT IMAGE FONCTION ---------- */
function preChargementImg(tabImg) {
    for (i = 0; i < tabImg.length; i++) {
        img = new Image();
        img.src = tabImg[i];
    }
}
/* ---------- FIN PRECHARGEMENT IMAGE FONCTION ---------- */


/* ---------- DEBUT BLOC DEFILANT FONCTION ---------- */
function cBlocDefilant(aDonnee, aAdresse, aCouleur, aVitesseEnSec) {

    //reference à this
    var oThis = this;

    //attributs
    this.donnee = aDonnee;
    this.adresse = aAdresse;
    this.tabAdresse;
    this.couleur = aCouleur;
    this.vitesseEnSec = aVitesseEnSec;
    this.compteur = 0;
    this.nbSlide = aDonnee.length;
    this.timeout;

    //construction des points de navigations
    $(this.adresse).parent().children('.navAPoint').empty();
    var sNavHtml = '<div class="navPointCouleur point0">&nbsp;</div>';
    for (var i = 1; i < this.nbSlide; i++) {
        sNavHtml += '<div class="navPointSobre point' + i + '">&nbsp;</div>\n';
    }

    $(this.adresse).parent().children('.navAPoint').append('<span class="flecheGauche"><img src="/_include/brest/images/template/icone-et-puce/fleche' + oThis.couleur + 'Gauche.png" alt="vers la gauche" /></span>' +
        '<div class="navPoints">' +
        sNavHtml +
        '</div>' +
        '<span class="flecheDroite"><img src="/_include/brest/images/template/icone-et-puce/fleche' + oThis.couleur + 'Droite.png" alt="vers la droite" /></span>');
    cssWidth = this.nbSlide * 18;
    cssPadding = ((parseInt($(this.adresse).parent().css('width')) - cssWidth) / 2) - 26;

    $(this.adresse).parent().children('.navAPoint').children('.navPoints').css('width', cssWidth + 'px');
    $(this.adresse).parent().children('.navAPoint').children('.navPoints').css('padding-right', cssPadding + 'px');
    $(this.adresse).parent().children('.navAPoint').children('.navPoints').css('padding-left', cssPadding + 'px');

    //navigation flèche + fin timeout
    $(this.adresse).parent().children('.navAPoint').children('.flecheGauche').click(function () {
        clearTimeout(oThis.timeout);
        oThis.mFaireDefiler(0);
    });
    $(this.adresse).parent().children('.navAPoint').children('.flecheDroite').click(function () {
        clearTimeout(oThis.timeout);
        oThis.mFaireDefiler(1);
    });

    //navigation par point + fin timeout
    $(this.adresse).parent().children('.navAPoint').children('.navPoints').children().each(function (cptJQ) {
        $(this).click(function () {

            //compatibilité compteur
            oThis.compteur = cptJQ + 1;
            if (oThis.compteur > (oThis.nbSlide - 1))
                oThis.compteur = 0;

            clearTimeout(oThis.timeout);
            $(oThis.adresse).fadeOut();
            $(oThis.adresse).empty();
            $(oThis.adresse).append(oThis.donnee[cptJQ]).hide();
            $(oThis.adresse).parent().children('.navAPoint').children('.navPoints').children('.navPointCouleur').removeClass('navPointCouleur').addClass('navPointSobre');
            //alert(this.adresse + ' ~ .navAPoint .point' + this.compteur);
            $(oThis.adresse).parent().children('.navAPoint').children('.navPoints').children('.point' + cptJQ).removeClass('navPointSobre').addClass('navPointCouleur');
            $(oThis.adresse).fadeIn();
        });
    });


    //methodes
    this.mFaireDefiler = function (avantOuArriere) {
        if (avantOuArriere == 0) {
            this.compteur -= 2;
            if (this.compteur < 0)
                this.compteur += this.nbSlide;
        }
        $(this.adresse).fadeOut();
        $(this.adresse).empty();
        $(this.adresse).append(this.donnee[this.compteur]).hide();
        //alert(this.adresse + ' ~ .navAPoint .navPointCouleur');
        $(this.adresse).parent().children('.navAPoint').children('.navPoints').children('.navPointCouleur').removeClass('navPointCouleur').addClass('navPointSobre');
        //alert(this.adresse + ' ~ .navAPoint .point' + this.compteur);
        $(this.adresse).parent().children('.navAPoint').children('.navPoints').children('.point' + this.compteur).removeClass('navPointSobre').addClass('navPointCouleur');
        $(this.adresse).fadeIn();
        if (this.compteur < (this.nbSlide - 1))
            this.compteur++;
        else
            this.compteur = 0;
    };

    this.mRappel = function () {
        this.timeout = setInterval(function () { oThis.mFaireDefiler(1); }, (this.vitesseEnSec * 1000));
    };
}
/* ---------- DEBUT BLOC DEFILANT FONCTION ---------- */



/* ---------- DEBUT PAGINATION FONCTION ---------- */
function cPagination(NomZone, nbDivParPage, scroll) {
    var oThis = this;
    this.NomZone = NomZone;
    this.nbDivParPage = nbDivParPage;
    this.pageCourante = 1;
    this.pages = 0;
    this.initialise = false;

    this.montrerDivs = function (premier, dernier) {
        var compteur = 1;
        $('#' + NomZone + ' > div').each(function () {
            if (compteur < premier || compteur > dernier)
                $(this).css('display', 'none');
            else
                $(this).css('display', 'block');
            compteur++;
        });
    }

    this.montrerSelection = function (numeroPage) {
        var ancreAncienneSelection = $('#pg' + this.pageCourante);
        ancreAncienneSelection.removeClass('pg-selected');
        ancreAncienneSelection.addClass('pg-normal');

        this.pageCourante = numeroPage;
        var ancreNouvelleSelection = $('#pg' + this.pageCourante);
        ancreNouvelleSelection.removeClass('pg-normal');
        ancreNouvelleSelection.addClass('pg-selected');

        var premier = (numeroPage - 1) * nbDivParPage + 1;
        var dernier = premier + nbDivParPage - 1;

        //alert(premier);
        //alert(dernier);
        this.montrerDivs(premier, dernier);
        if (scroll != 0) {
            window.scrollTo(0, 0);
        }
        //alert(this.pageCourante);
        //alert(this.pages);
    }

    this.prev = function () {
        //alert(this.pageCourante);
        if (this.pageCourante > 1) {
            this.montrerSelection(parseInt(this.pageCourante) - 1);
        }
    }

    this.next = function () {
        //alert(this.pageCourante);
        //alert(this.pages);
        if (this.pageCourante < this.pages) {
            this.montrerSelection(parseInt(this.pageCourante) + 1);
        }
    }

    this.initialiser = function () {
        divs = new Array();
        $('#' + NomZone + ' > div').each(function () {
            divs.push($(this));
        });
        var nbDivs = divs.length;
        this.pages = Math.ceil(nbDivs / nbDivParPage);
        this.initialise = true;
    }



    this.montrerPaginationNav = function (objetPagination, positionId) {
        if (oThis.pages > 1) {
            var element = $('#' + positionId);
            var paginationHtml = '<div class="navigationHautContenu"><span class="pg-normal precedente" id="prev">Page précédente</span><div class="boutonsCentraux">';
            for (var page = 1; page <= this.pages; page++) {
                paginationHtml += '<span id="pg' + page + '" class="pg-normal numPage">' + page + '</span>';
            }
            paginationHtml += '</div><span class="pg-normal suivante" id="next">Page suivante</span><div class="clear1px">&nbsp;</div></div><div class="piedNavigationHautContenu">&nbsp;</div>';
            element.html(paginationHtml);
            $('#prev').click(function () {
                objetPagination.prev();
            });

            $(".numPage").each(function () {
                $(this).click(function () {
                    valeurPage = $(this).attr('id');
                    valeurPage = valeurPage.replace('pg', '');
                    objetPagination.montrerSelection(valeurPage);
                });
            });


            $('#next').click(function () {
                objetPagination.next();
            });
        }

    }
}
/* ---------- FIN PAGINATION FONCTION ---------- */


/* ---------- DEBUT RECHERCHE VOYAGE FONCTION ---------- */
/* ---------- FIN RECHERCHE VOYAGE FONCTION ---------- */


/* ---------- DEBUT FICHE VOYAGE FONCTION ---------- */
function constructionDiaporama(tabPhoto) {
    var oThis = this;
    this.aTabPhoto = tabPhoto;
    this.aCompteur = 0;
    this.nbImg = (tabPhoto.length) - 1;

    preChargementImg(this.aTabPhoto);

    this.mChargerImg = function () {
        if (this.nbImg > 0) {
            $('#blocDiapo td .imgCourante').remove();
            $('#blocDiapo td').append('<img src="' + tabPhoto[oThis.aCompteur] + '" class="imgCourante" ></img>');
        }
        else {
            $('#blocDiapo td').append('<div class="center verdanaBlancNormal"><br/><br/>Aucune photo n\'est disponible<br/> pour ce voyage.</div>');
        }
    }
    if (this.nbImg > 0) {
        $('#defilementDroite').click(function () {
            if (oThis.aCompteur < oThis.nbImg) {
                oThis.aCompteur++;
            }
            else {
                oThis.aCompteur = 0;
            }
            oThis.mChargerImg();
        });
        $('#defilementGauche').click(function () {
            if (oThis.aCompteur > 0) {
                oThis.aCompteur--;
            }
            else {
                oThis.aCompteur = oThis.nbImg;
            }
            oThis.mChargerImg();
        });
    }
    else {
        $('#defilementGauche').hide();
        $('#defilementDroite').hide();
    }
}

function changerOngletMOS(id1, id2) {
    $('#contenuMOS' + id2).hide();
    $('#contenuMOS' + id1).show();
    $('#ongletMOS' + id2 + ' > .enteteOngletClairMOS').removeClass('enteteOngletClairMOS').addClass('enteteOngletFonceMOS');
    $('#ongletMOS' + id1 + ' > .enteteOngletFonceMOS').removeClass('enteteOngletFonceMOS').addClass('enteteOngletClairMOS');
    $('#ongletMOS' + id2 + ' > .contenuOngletClairMOS').removeClass('contenuOngletClairMOS').addClass('contenuOngletFonceMOS');
    $('#ongletMOS' + id1 + ' > .contenuOngletFonceMOS').removeClass('contenuOngletFonceMOS').addClass('contenuOngletClairMOS');
    $('#ongletMOS' + id2).removeClass('ongletClairMOS').addClass('ongletFonceMOS');
    $('#ongletMOS' + id1).removeClass('ongletFonceMOS').addClass('ongletClairMOS');
    $(this).unbind('click');
    $('#ongletMOS' + id2).click(function () {
        changerOngletMOS(id2, id1);
    });


}
/* ---------- FIN FICHE VOYAGE FONCTION ---------- */

/* ---------- DEBUT FICHE DESTINATION FONCTIONS ---------- */
function choixOnglet(onglet) {
    $('#' + onglet).addClass('ongletActif');
    $('#' + onglet).removeClass('ongletInactifActifGauche');

    tabOnglet = new Array("ongletPresentation", "ongletInfosUtiles", "ongletVols");
    for (i = 0; i < tabOnglet.length; i++) {
        if (onglet != tabOnglet[i]) {
            $('#' + tabOnglet[i]).removeClass('ongletActif');
        }
    }
    if (onglet == "ongletPresentation") {
        $('#ongletInfosUtiles').removeClass('ongletInactifActifGauche');        
        $('#DiaporamaComplet').show();
        $('#contenuVols').hide();
        $('#contenuInfoUtiles').hide();

        $('#contenuPresentation').show();
        $('#blocCarteDestination').show();
        $('#blocMeteo').hide();
    }
    else if (onglet == "ongletInfosUtiles") {
        $('#ongletPresentation').addClass('ongletInactifActifGauche');
        $('#DiaporamaComplet').show();
        $('#contenuVols').hide();
        $('#contenuInfoUtiles').show();

        $('#contenuPresentation').hide();
        $('#blocCarteDestination').hide();
        $('#blocMeteo').show();
    }
    else if (onglet == "ongletVols") {
        $('#ongletInfosUtiles').addClass('ongletInactifActifGauche');
        $('#ongletPresentation').removeClass('ongletInactifActifGauche');
        $('#DiaporamaComplet').hide();
        $('#contenuVols').show();
        $('#contenuInfoUtiles').hide();

        $('#contenuPresentation').hide();
        $('#blocCarteDestination').hide();
        $('#blocMeteo').hide();
    }
}
/* ---------- FIN FICHE DESTINATION FONCTIONS ---------- */


/* ---------- DEBUT LISTES DESTINATIONS FONCTIONS ---------- */
function afficherSectionDestinations(min, max) {
    i = 0;
    $(".contenuBLC").each(function () {
        if ((i >= min) && (i <= max)) {
            $(this).show();
        }
        else {
            $(this).hide();
        }
        i++;
    });
}
/* ---------- FIN LISTES DESTINATIONS FONCTIONS ---------- */


/* ---------- DEBUT LISTE AGENCES VOYAGES FONCTIONS  ----------*/
function posterFormulaire(ZoneAgenceID) {
    $("#ZoneAgenceID").attr("value", ZoneAgenceID);
    $("#frm").submit();
}
function retourFormulaire() {
    $("#Mode").attr("value", 2);
    $("#frm").submit();
}
/* ---------- FIN LISTE AGENCES VOYAGES FONCTIONS  ----------*/


/* ---------- DEBUT TARIFS PARKING FONCTIONS  ----------*/
/* ---------- FIN  TARIFS PARKING  FONCTIONS  ----------*/


/*********************************************************/
/************** D E B U T   S C R I P T S ****************/
/*********************************************************/

$(document).ready(function () {
    /* -------- DEBUT GENERALE --------- */

    //datepicker
    if (($('#typePage')) && ($('#typePage').val() == "volsaudepart" || $('#typePage').val() == "volsalarrivee")) {
        datemini = "-1d";
    }
    else {
        datemini = 0
    }
    $.datepicker.regional['fr'];
    $(".datepicker").datepicker({
        constrainInput: true,
        showOn: "both",
        dateFormat: "dd/mm/yy",
        buttonImage: "/_include/brest/images/template/date.png",
        buttonImageOnly: true,
        showOtherMonths: true,
        selectOtherMonths: true,
        gotoCurrent: true,
        minDate: datemini
    });


    //validation de formulaire
    $("form").submit(function () {
        bValid = true;
        $(".msgErreur", this).hide();
        $(".nonVide", this).each(function () {
            if ($(this).val() == "") {
                $(this).after("<span class=\"msgErreur fs9px\">Champ obligatoire</span>");
                bValid = false;
            }
        });
        $(".heure", this).each(function () {
            if (($(this).val() < 0) || ($(this).val() > 23) || isNaN($(this).val())) {
                $(this).after("<span class=\"msgErreur fs9px\">(0 à 23)</span>");
                bValid = false;
            }
        });
        $(".minute", this).each(function () {
            if (($(this).val() < 0) || ($(this).val() > 59) || isNaN($(this).val())) {
                $(this).after("<span class=\"msgErreur fs9px\">(0 à 59)</span>");
                bValid = false;
            }
        });
        $(".cp", this).each(function () {
            var reg = new RegExp('^((0[1-9])|([1-8][0-9])|(9[0-8])|(2A)|(2B))[0-9]{3}$');
            if (!reg.test($(this).val())) {
                $(this).after("<span class=\"msgErreur fs9px\">Le code postal doit contenir 5 chiffres</span>");
                bValid = false;
            }
        });
        $(".mdpAConfirmer", this).each(function () {
            if (($(this).val() != $(".mdpConfirmant").val()) || ($(this).val().length < 4) || ($(this).val() == '')) {
                $(this).after("<span class=\"msgErreur fs9px\">4 caractères min</span>");
                $(".mdpConfirmant").after("<span class=\"msgErreur fs9px\">doivent correspondre</span>");
                bValid = false;
            }
        });
        $(".mail", this).each(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');
            if (!reg.test($(this).val())) {
                $(this).after("<span class=\"msgErreur fs9px\">L'adresse mail doit être au format exemple@test.fr</span>");
                bValid = false;
            }
        });
        if ((($('#typePage')) && ($('#typePage').val() == "offreemploiformulaire")) && bValid) {
            $('#offreemploiformulaireSubmit').val('Traitement...').attr('disabled', 'disabled');
            $('#offreemploiformulaireSubmit').css('cursor', 'default');
        }
        return (bValid);
    });

    /* -------- FIN GENERALE --------- */

    /* ---------- DEBUT MASTER PAGE ------------ */


    //chargement d'images communes
    tabImgMenu = new Array('/_include/brest/images/template/fondListeBleuPale.png',
    '/_include/brest/images/template/focusListeBleuPale.png',
    '/_include/brest/images/template/enteteListeBleuePaleMoyenne.png',
    '/_include/brest/images/template/corpsListeBleuePaleMoyenne.png');
    preChargementImg(tabImgMenu);

    //Publicité 728x90 du Menu Haut
    //alert("'" + $.trim($("#publiciteMenuHaut").text()) + "'");
    var test = $.trim($("#publiciteMenuHaut").html());
    if (test == "") {
        $('#menuHaut, #menuHaut .liMenu, #menuHaut .aMenu').css('height', '78px');
        $('.sousMenu').css('top', '78px');
        $('#menuHaut').css('margin-top', '45px');
        $('.langues').css('margin-top', '15px');
        $('#publiciteMenuHaut').hide();
    } else {
        $('#menuHaut, #menuHaut .liMenu, #menuHaut .aMenu').css('height', '48px');
        $('.sousMenu').css('top', '48px');
        $('.langues').css('margin-top', '30px');
        $('#menuHaut').css('margin', '0');
        $('#publiciteMenuHaut').show();
    }

    //langues
    $('#changeLangue').click(function () {
        if ($(this).children('.champBleuBlanc').css('display') == 'none') {
            $(this).children('.champBleuBlanc').show();
        }
        else {
            $(this).children('.champBleuBlanc').hide();
        }
    });

    //pied de page
    $('#autreSiteCCI').change(function () {
        $('#autreSiteCCI option:selected[value!=""]').each(function () {
            window.open($(this).val(), '_blank');
        });
    });


    /* --------------FIN  GENERALE SCRIPT ---------------- */


    /* --------------DEBUT ACCUEIL SCRIPT -------------- */
    if (($('#typePage')) && ($('#typePage').val() == "accueil")) {
        //chargement dynamique des images 
        tabImg = new Array('/_include/brest/images/accueil/boutonDestinationSelect.png',
            '/_include/brest/images/accueil/destination-france.png',
            '/_include/brest/images/accueil/destination-europe.png',
            '/_include/brest/images/accueil/destination-monde.png');
        preChargementImg(tabImg);
        //mouseover sur Nos Destinations
        $('.navDest a:nth-child(1)').mouseover(function () {
            $('.vueRegion').css('background', 'url(/_include/brest/images/accueil/destination-france.png) top left no-repeat');
        });
        $('.navDest a:nth-child(2)').mouseover(function () {
            $('.vueRegion').css('background', 'url(/_include/brest/images/accueil/destination-europe.png) top left no-repeat');
        });
        $('.navDest a:nth-child(3)').mouseover(function () {
            $('.vueRegion').css('background', 'url(/_include/brest/images/accueil/destination-monde.png) top left no-repeat');
        });

    }
    /* --------------FIN ACCUEIL SCRIPT -------------- */


    /* ------------ DEBUT MENU HAUT SCRIPT ----------------*/
    /* ------------ FIN MENU HAUT SCRIPT----------------*/


    /* ------------- DEBUT LISTE AGENCES VOYAGES SCRIPT --------------*/
    //pagination
    if (($('#typePage')) && ($('#typePage').val() == "agencesvoyages")) {
        var nbElementJQ = $('.enteteBLC');
        if (nbElementJQ.length > 0) {
            var paginationRech = new cPagination('agencesvoyages', 14);
            paginationRech.initialiser();
            paginationRech.montrerPaginationNav(paginationRech, 'pageNavPosition');
            paginationRech.montrerSelection(1);
        }
    }
    /* ------------- FIN LISTE AGENCES VOYAGES SCRIPT --------------*/


    /* ------------- DEBUT VOLS AU DEPART SCRIPT --------------*/
    if (($('#typePage')) && ($('#typePage').val() == "volsaudepart")) {
        $(".datepicker").datepicker("option", "maxDate", '+365d');
        $("#champDate").change(function () {
            $('.chargement').show();
            $('#rechercherDate').submit();
        });
        $('.submitInfo').click(function () {
            $(this).parent('form').submit();
        });
        $(".ongletInactif").click(function () {
            $("#rechercherDate").attr("action", "/vols-et-destinations/vols-a-l-arrivee");
            //alert($("#rechercherDate").attr("action"));
            $('#rechercherDate').submit();
        });
        $('.contenuOnglet').css('visibility', 'visible');
    }
    /* ------------- FIN VOLS AU DEPART SCRIPT --------------*/


    /* ------------- DEBUT VOLS A L'ARRIVEE SCRIPT --------------*/
    if (($('#typePage')) && ($('#typePage').val() == "volsalarrivee")) {
        $(".datepicker").datepicker("option", "maxDate", '+365d');
        $("#champDate").change(function () {
            $('.chargement').show();
            $('#rechercherDate').submit();
        });
        $('.submitInfo').click(function () {
            $(this).parent('form').submit();
        });
        $(".ongletInactif").click(function () {
            $("#rechercherDate").attr("action", "/vols-et-destinations/vols-au-depart");
            //alert($("#rechercherDate").attr("action"));
            $('#rechercherDate').submit();
        });
        $('.contenuOnglet').css('visibility', 'visible');
    }
    /* ------------- FIN VOLS A L'ARRIVEE SCRIPT --------------*/


    /* --------------DEBUT ACCES ROUTIER SCRIPT -------------- */
    if (($('#typePage')) && ($('#typePage').val() == "accesroutier")) {

        $('#accesroutierItineraire').click(function () {
            $(".msgErreur").hide();
            var valeurDuChamp = $('#accesroutierVilleDepart').val();
            if ((valeurDuChamp) && (valeurDuChamp != '')) {
                href = 'http://maps.google.fr?f=d&saddr=' + valeurDuChamp + '&daddr=Chemin%20de%20Kernoas/D167%20Guipavas';
                window.open(href);
            }
            else {
                $('#accesroutierItineraire').after("<span class=\"msgErreur\"><br />Veuillez saisir votre ville de départ.</span>");
            }
        });
        $('#accesroutierVilleDepart').keypress(function (e) {
            if (e.which == 13)
                $('#accesroutierItineraire').trigger("click");
        });
    }
    /* --------------FIN ACCES ROUTIER SCRIPT -------------- */

    /* --------------DEBUT QUITTER AEROPORT SCRIPT -------------- */
    if (($('#typePage')) && ($('#typePage').val() == "quitteraeroport")) {

        $('#quitteraeroportItineraire').click(function () {
            $(".msgErreur").hide();
            var valeurDuChamp = $('#accesroutierVilleArrivee').val();
            if ((valeurDuChamp) && (valeurDuChamp != '')) {
                href = 'http://maps.google.fr?f=d&daddr=' + valeurDuChamp + '&saddr=Chemin%20de%20Kernoas/D167%20Guipavas';
                window.open(href);
            }
            else {
                $('#quitteraeroportItineraire').after("<span class=\"msgErreur\"><br />Veuillez saisir votre ville d'arrivée.</span>");
            }
        });
        $('#accesroutierVilleArrivee').keypress(function (e) {
            if (e.which == 13)
                $('#quitteraeroportItineraire').trigger("click");
        });
    }
    /* --------------FIN ACCES ROUTIER SCRIPT -------------- */


    /* --------------DEBUT RECHERCHE DE VOYAGES SCRIPT -------------- */
    if (($('#typePage')) && ($('#typePage').val() == "listevoyages")) {
        //pagination
        var nbElementJQ = $('.enteteBLC');
        if (nbElementJQ.length > 0) {
            var paginationRech = new cPagination('listeVoyage', 10);
            paginationRech.initialiser();
            paginationRech.montrerPaginationNav(paginationRech, 'pageNavPosition');
            paginationRech.montrerSelection(1);
        }
    }
    /* --------------FIN RECHERCHE DE VOYAGES SCRIPT -------------- */


    /* --------------DEBUT PANIER SCRIPT -------------- */
    if (($('#typePage')) && ($('#typePage').val() == "panier")) {
        $('.submitSupprimer').click(function () {
            $(this).parent('.supprimerDuPanier').submit();
        });
    }
    /* --------------FIN PANIERSCRIPT -------------- */


    /* ----------DEBUT FICHE VOYAGES SCRIPT --------------*/
    if (($('#typePage')) && ($('#typePage').val() == "fichevoyage")) {


        if ($('.lien').size() < 1) {
            $('#resaVoyage').hide();
        }

        //popup reserver par TEL
        $('#lienTel').click(function () {
            $("#popupTel").show();
            $("#pageOmbree").show();
        });
        $('#fermerPopupTel').click(function () {
            $('#popupTel').hide();
            $('#pageOmbree').hide();
        });

        //popup reserver par TEL
        $('#lienSI').click(function () {
            $("#popupSI").show();
            $("#pageOmbree").show();
        });
        $('#fermerPopupSI').click(function () {
            $('#popupSI').hide();
            $('#pageOmbree').hide();
        });

        //popup reserver par Agence Voyage
        $('#lienAV').click(function () {
            $("#popupAV").show();
            $("#pageOmbree").show();
        });
        $('#fermerPopupAV').click(function () {
            $('#popupAV > .mailAgence').empty();
            $('#popupAV > .choixAgence').show();
            $('#popupAV').hide();
            $('#pageOmbree').hide();
        });

        //click sur un département
        $('#popupAV > .choixAgence > ul > li').click(function () {
            $('#popupAV > .choixAgence > ul > li > ul').hide();
            $('#popupAV > .choixAgence > ul > li').css('list-style-image', 'url(/_include/brest/images/template/icone-et-puce/puceCercle.png');
            $(this).css('list-style-image', 'url(/_include/brest/images/template/icone-et-puce/puceCerclePlein.png');
            $(this).children('ul').fadeIn();
        });

        //click sur une zone agence
        $('#popupAV > .choixAgence > ul > li > ul > li').click(function () {
            $('#popupAV > .choixAgence > ul > li > ul > li > ul').hide();
            $('#popupAV > .choixAgence > ul > li > ul > li').css('list-style-image', 'url(/_include/brest/images/template/icone-et-puce/puceCercle.png');
            $(this).css('list-style-image', 'url(/_include/brest/images/template/icone-et-puce/puceCerclePlein.png');
            $(this).children('ul').fadeIn();
        });

        //click sur une agence
        $('#popupAV > .choixAgence > ul > li > ul > li > ul > li').click(function () {
            $('#popupAV > .choixAgence').hide();
            $('#popupAV > .mailAgence').empty();

            //recuperation variable
            var agence = $(this).text();

            //depuis les inputs
            var adresse = $(this).children('input[name=adresse1Agence]').val();
            if ($(this).children('input[name=adresse2Agence]').val() != "") adresse += "<br />" + $(this).children('input[name=adresse2Agence]').val()
            if ($(this).children('input[name=adresse3Agence]').val() != "") adresse += "<br />" + $(this).children('input[name=adresse3Agence]').val()
            var cp = $(this).children('input[name=cpAgence]').val();
            var ville = $(this).children('input[name=villeAgence]').val();
            var mailAgence = $(this).children('input[name=mailAgence]').val();
            var tel = $(this).children('input[name=telAgence]').val();
            var siteInternet = $(this).children('input[name=siteInternetAgence]').val();

            //depuis les ID
            var fournisseur = $('#fournisseur').val();
            var codeproduit = $('#codeproduit').val();
            var titre = $('#titre').val();
            var destination = $('#destination').val();
            var duree = $('#duree').val();
            var dateDepart = $('input[name=vacancesDepart]').val();
            var prixVoyage = $('#prixVoyage').val();
            var sessionNom = $('#sessionNom').val();
            var sessionPrenom = $('#sessionPrenom').val();
            var sessionAdresse = $('#sessionAdresse').val();
            var sessionCP = $('#sessionCP').val();
            var sessionVille = $('#sessionVille').val();
            var sessionMail = $('#sessionMail').val();
            var contenuDateTarif = $("#contenuDateTarif").html();
            //alert(contenuDateTarif);


            //html            
            $('#popupAV > .mailAgence').append('<h2 style="margin:0px !important;">Réservation auprès de ' + agence + '</h2><div class="hr" style="margin:0px !important;">&nbsp;</div><br />'); ;
            $('#popupAV  > .mailAgence').append('<form name="formAgence" action="" method="post"></form>');

            $('#popupAV form').append('<h3>Mon agence</h3><br />');
            $('#popupAV form').append('<div class="center" id="jqMonAgence"></div>');
            if (agence != "") $('#popupAV form #jqMonAgence').append("<strong>" + agence + "</strong><br />");
            if (adresse != "") $('#popupAV form #jqMonAgence').append(adresse + "<br />");
            if (cp != "") $('#popupAV form #jqMonAgence').append(cp + " ");
            if (ville != "") $('#popupAV form #jqMonAgence').append(ville + "<br />");
            if (tel != "") $('#popupAV form #jqMonAgence').append("<strong>" + tel + "</strong><br />");
            if (siteInternet != "") $('#popupAV form #jqMonAgence').append('<strong><a href="http://' + siteInternet + '" target="_blank">' + siteInternet + '</a></strong><br />');

            $('#popupAV form').append('<br /><h3>Récapitulatif du voyage</h3><br />');
            $('#popupAV form').append('<div id="jqRecapVoyage" style="padding-left:5px !important;"></div>');
            if (destination != "") $('#popupAV form #jqRecapVoyage').append("Destination : " + destination + "<br />");
            if (fournisseur != "") $('#popupAV form #jqRecapVoyage').append("Tour-opérateur : " + fournisseur + "<br />");
            if (titre != "") $('#popupAV form #jqRecapVoyage').append("Intitulé : " + titre + "<br />");
            if (codeproduit != "") $('#popupAV form #jqRecapVoyage').append("Code : " + codeproduit + "<br />");
            if (duree != "") $('#popupAV form #jqRecapVoyage').append("Durée : " + duree + "<br />");
            $('#popupAV form #jqRecapVoyage').append("<br />Date de départ et prix : ");
            //$('#popupAV form #jqRecapVoyage').append('<input type="text" class="inputLong center" readonly="true" id="inputDateEtPrix" value="' + dateDepart + '" /><br />');
            $('#popupAV form #jqRecapVoyage').append(contenuDateTarif + "<br />");
            $('#dateTarif option').each(function () {
                if ($(this).attr("title") == dateDepart) {
                    //alert("'" + $(this).val() + "'" + " - " + "'" + dateDepart + "'");             
                    $(this).attr('selected', 'selected');
                }
            });
            //            if (dateDepart != "" && prixVoyage != "")
            //                $('#popupAV form #jqRecapVoyage #inputDateEtPrix').val(dateDepart + " - " + prixVoyage + " €/pers.");
            //            else if (dateDepart == "" && prixVoyage != "")
            //                $('#popupAV form #jqRecapVoyage #inputDateEtPrix').val(prixVoyage + " €/pers.");
            //            else if (dateDepart != "" && prixVoyage == "")
            //                $('#popupAV form #jqRecapVoyage #inputDateEtPrix').val(dateDepart);
            //            else
            //                $('#popupAV form #jqRecapVoyage #inputDateEtPrix').val("Aucune donnée");

            $('#popupAV form #jqRecapVoyage').append("<em>Les prix sont donnés à titre indicatif, <u>sous réserve de disponibilités</u>.</em><br />");
            $('#popupAV form #jqRecapVoyage').append("<em>Prix TTC par personne, base chambre double, <u>n'incluant pas les frais de dossier</u>.</em><br />");

            $('#popupAV form #jqRecapVoyage').append("<br /><div class=\"inlineDiv\">Nombre de participants : <input type=\"text\" name=\"nbAdulteClient\" class=\"inputMini\" value=\"0\" /> Adulte(s)</div><div class=\"inlineDiv\"><input type=\"text\" name=\"nbEnfantClient\" class=\"inputMini\" value=\"0\" /> Enfant(s)<br /><sub>Moins de 12 ans</sub></div><div class=\"inlineDiv\"><input type=\"text\" name=\"nbBebeClient\" class=\"inputMini\" value=\"0\" /> Bébé(s)<br /><sub>Moins de 2 ans</sub></div><div class=\"clear\">&nbsp;</div>");






            //            Nombre de participants : 	0   Adulte(s)	         0	Enfant(s)	       0	Bébé(s)
            //            Moins de 12 ans		Moins de 2 ans


            $('#popupAV form #jqMonAgence').append('<input type="hidden" name="destination" value="' + destination + '" />');
            $('#popupAV form #jqMonAgence').append('<input type="hidden" name="titre" value="' + titre + '" />');
            $('#popupAV form #jqMonAgence').append('<input type="hidden" name="codeproduit" value="' + codeproduit + '" />');
            $('#popupAV form #jqMonAgence').append('<input type="hidden" name="fournisseur" value="' + fournisseur + '" />');
            $('#popupAV form #jqMonAgence').append('<input type="hidden" name="duree" value="' + duree + '" />');
            $('#popupAV form #jqMonAgence').append('<input type="hidden" name="nomAgence" value="' + agence + '" />');
            $('#popupAV form #jqMonAgence').append('<input type="hidden" name="adresseAgence" value="' + adresse + '" />');
            $('#popupAV form #jqMonAgence').append('<input type="hidden" name="cpAgence" value="' + cp + '" />');
            $('#popupAV form #jqMonAgence').append('<input type="hidden" name="villeAgence" value="' + ville + '" />');
            $('#popupAV form #jqMonAgence').append('<input type="hidden" name="telAgence" value="' + tel + '" />');
            $('#popupAV form #jqMonAgence').append('<input type="hidden" name="siteInternetAgence" value="' + siteInternet + '" />');



            var reg = new RegExp('^[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*@[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*[\.]{1}[a-z]{2,6}$', 'i');
            if (mailAgence != 'inconnu' && reg.test(mailAgence)) {
                $('#popupAV form #jqRecapVoyage').append('<br />Demandes particulières ou commentaires :<br /><textarea name="commentaire" class="mAuto" cols="50" rows="4"></textarea><br /><br />');
                $('#popupAV form').append('<input type="hidden" name="envoyerMail" value="1" />');
                $('#popupAV form').append('<input type="hidden" name="mailAgence" value="' + mailAgence + '" />');
                $('#popupAV form').append('<h3>Mes coordonnées</h3><br />');
                $('#popupAV form').append('<div id="coordonnees" style="padding-left:5px !important;"></div>');
                $('#popupAV form #coordonnees').append('Civilité* <select name="civiliteClient" style="width:55px;"><option value="Mlle">Mlle</option><option value="Mme">Mme</option><option value="M.">M.</option></select>');
                $('#popupAV form #coordonnees').append(' &nbsp;&nbsp;Nom* <input type="text" class="nonVide inputMoyen" value="' + sessionNom + '" name="nomClient" /> ');
                $('#popupAV form #coordonnees').append(' &nbsp;&nbsp;Prénom* <input type="text" class="nonVide inputMoyen" value="' + sessionPrenom + '" name="prenomClient" /><br />');
                $('#popupAV form #coordonnees').append('Adresse <input type="text" class="inputLong" value="' + sessionAdresse + '" name="adresseClient" /><br />');
                $('#popupAV form #coordonnees').append('Code postal <input type="text" class="inputMoyen" value="' + sessionCP + '" name="cpClient" /> ');
                $('#popupAV form #coordonnees').append(' &nbsp;&nbsp;Ville <input type="text" class="inputMoyen" value="' + sessionVille + '" name="villeClient" /><br />');
                $('#popupAV form #coordonnees').append('Téléphone 1* <input type="text" class="nonVide inputMoyen" name="tel1Client" /> ');
                $('#popupAV form #coordonnees').append(' &nbsp;&nbsp;Téléphone 2 <input type="text" class="inputMoyen" name="tel2Client" /><br />');
                $('#popupAV form #coordonnees').append('E-mail* <input type="text" class="mail inputLong" value="' + sessionMail + '" name="mailClient" /><br />');
                $('#popupAV form').append('<em>*champs obligatoires</em><br /><br />');

                $('#popupAV form').append("<div class=\"dashedBorder\">L'agence de voyages recevra ces informations par e-mail d’ici quelques secondes. Elles vous seront également envoyées à l’adresse e-mail indiquée ci-dessus.<br /><br /> Un conseiller de l’agence vérifiera le prix et la disponibilité de l’offre sélectionnée. Il vous contactera dans les meilleurs délais afin de finaliser votre réservation.</div>");
                $('#popupAV form').append('<input type="submit" value="Envoyer" />');
            }
            else if (tel != 'inconnu') {
                $('#popupAV form').append('<h3>Informations </h3><br />Vous pouvez joindre l\'agence <strong>' + agence + '</strong> par téléphone.<br />');
                $('#popupAV form').append('Tel. de l\'agence : <strong>' + tel + ' </strong><br /><br />');
            }
            else {
                $('#popupAV form').append('<h3>Informations </h3><br />Nous ne disposons pas des coordonnées de l\'agence <strong>' + agence + '</strong>.<br />');
            }
            $("#popupAV form").submit(function () {
                bValid = true;
                $(".msgErreur", this).hide();
                $(".nonVide", this).each(function () {
                    if ($(this).val() == "") {
                        $(this).after("<span class=\"msgErreur fs9px\">Vide</span>");
                        bValid = false;
                    }
                });
                $(".mail", this).each(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');
                    if (!reg.test($(this).val())) {
                        $(this).after("<br /><span class=\"msgErreur fs9px\">L'adresse mail doit être au format exemple@test.fr</span>");
                        bValid = false;
                    }
                });
                return (bValid);
            });
        });

        //onglets
        $('#contenuMOS2').hide();
        $('#ongletMOS2').click(function () {
            changerOngletMOS('2', '1');
        });

        //impression
        $('#imprimer').css('cursor', 'pointer');
        $('#imprimer').click(function () {
            $('#impression').submit();
        });
        $('#aSubmit').click(function () {
            $('#formRechercheVoyage').submit();
        });
    }
    /* ----------FIN FICHE VOYAGES SCRIPT --------------*/


    /* ---------- DEBUT FICHE DESTINATION SCRIPT ---------- */
    if (($('#typePage')) && ($('#typePage').val() == "destination")) {
        $('.contenuOnglet').css('visibility', 'visible');
        $('.imagePetite').each(function () {
            if ($(this).attr('src') == "") {
                $(this).remove();
            }
        });

        $('.imagePetite').click(function () {
            src = $(this).attr('src');
            alt = $(this).attr('alt');
            $(this).parent().parent().children('.imageGde').children('img').remove();
            $(this).parent().parent().children('.imageGde').children('.blocResume').children('span').remove();
            $(this).parent().parent().children('.imageGde').prepend('<img src="' + src + '" alt="' + "" + '" class="imageGde" />');
            $(this).parent().parent().children('.imageGde').children('.blocResume').append('<span>' + alt + '</span>');
        });
        if ($('#DestCodeSIA').val() != "") {
            $('#vacDestModule').val($('#DestCodeSIA').val());
        }
        choixOnglet('ongletPresentation');

    }
    /* ---------- FIN FICHE DESTINATION SCRIPT ---------- */


    /* -------- DEBUT LISTES DESTINATIONS SCRIPT -------- */
    if (($('#typePage')) && ($('#typePage').val() == "destinations")) {
        switch ($("#RegionID").val()) {
            case "1":
                $("#ongletMonde").addClass("actif");
                break;
            case "2":
                $("#ongletFrance").addClass("actif");
                break;
            case "3":
                $("#ongletEurope").addClass("actif");
                break;
        }
    }
    /* -------- FIN LISTES DESTINATIONS SCRIPT -------- */

    /* -------- DEBUT FORMULAIRE COMPTE SCRIPT -------- */
    if (($('#typePage')) && ($('#typePage').val() == "formulairecompte")) {
        $('#renvoyerMdp').click(function () {
            $('#frmRenvoiMdp').submit();
        });
    }
    /* -------- FIN FORMULAIRE COMPTE SCRIPT -------- */

});


