// JavaScript Document

//-------------------------------------------------------------------------------
// Affichage profil partiel
//-------------------------------------------------------------------------------
function AfficheVolet() {
    var options = { direction: "right" };
    $("#volet").toggle("slide", options, 1000);
    pan();
};

function AfficheSliderMap() {
    var options = { direction: "up" };
    $("#SliderMap").toggle("slide", options, 1000);

};

function AfficheProfilPartiel(id) {
    if (document.getElementById("btn_masquer")) {
        if (document.getElementById("btn_masquer").innerHTML == "Masquer") {
            AfficheVolet();
        }
    }
    AfficheSliderMap();
    $("#profil_partiel").html("<div style='margin-top:215px;color:#4B90C1; text-align:center; font-size:13px;'>Chargement en cours<br/><img src='/App_Themes/BonjourVoisinsNC/images/commun/ajax-loader2.gif' width='42' height='42' /></div>");

    _point = _map.getPosition();
    
    $.ajax({
        type: "POST",
        url: "/Ajax/ProfilPartiel.aspx",
        data: "idVoisin=" + id + "&fltLat=" + _point.lat + "&fltLng=" + _point.lng,
        success: function(msg) {
        $("#profil_partiel").html(msg);
   
        }
    });
};

function ProfilPartiel() {
    if (document.getElementById("btn_masquer")) {
        if (document.getElementById("btn_masquer").innerHTML == "Masquer") {
            AfficheVolet();
        }
    }
    AfficheSliderMap();
};

$(function() {

    $("#btn_masquer").click(function() {
        AfficheVolet();
        if (document.getElementById("btn_masquer").innerHTML == "Afficher") {
            document.getElementById("btn_masquer").innerHTML = "Masquer";
        }
        else {
            document.getElementById("btn_masquer").innerHTML = "Afficher";
        }
        return false;
    });

    $("#btn_masquerSliderMap, #btn_masquerSliderMap2").click(function() {
        ProfilPartiel();
        return false;
    });

});

//-------------------------------------------------------------------------------
// Liste adresses utiles
//-------------------------------------------------------------------------------
$(function(){

	$("#listeAdresses").accordion({ 
			header: "h3", 
			clearStyle: true,
			autoHeight: false
	});

});

//-------------------------------------------------------------------------------
// PNG Fix
//-------------------------------------------------------------------------------
$(document).ready(function() {
    //ie6 PNGFIX
    $('body').pngFix();

    // si encart_pub_index_existe
    if ($("#encart_pub_index").length > 0) {

        // ne pas mettre la pub dans le bandeau gauche
        //$("#emplacement_pub_250x250").html("");
        $("#emplacement_pub_250x250").attr("style", "display:none;");
    }
    else {

        // ne fonctionne pas car le script n'est pas executé
        //$("#emplacement_pub_250x250").html("<script language=\"javascript\" type=\"text/javascript\" src=\"http://a01.gestionpub.com/GP6fa3410a781f44\"></script>");
        $("#emplacement_pub_250x250").attr("style, margin-top:10px;");
    }



});


//-------------------------------------------------------------------------------
// Affichage tooltip sur les derniers inscrits
//-------------------------------------------------------------------------------
$(document).ready(function() {

$(".div_tooltip a[title]").tooltip('#zone_tooltip');

});


//-------------------------------------------------------------------------------
// Notice légale
//-------------------------------------------------------------------------------
function showCPR(s)
{
            var y = new Date().getYear();
            if (y<1900) y+=1900;
            if (s!=y)
                        document.write(s + " - " + y);
            else
                        document.write(y);
}


//-------------------------------------------------------------------------------
// Fonction Opacité
//-------------------------------------------------------------------------------
function setOpacity(obj, opacity) 
{
	  opacity = (opacity == 100)?99.999:opacity;
	  // IE/Win
	  obj.style.filter = "alpha(opacity:"+opacity+")";
	  // Safari<1.2, Konqueror
	  obj.style.KHTMLOpacity = opacity/100;
	  // Older Mozilla and Firefox
	  obj.style.MozOpacity = opacity/100;
	  // Safari 1.2, newer Firefox and Mozilla, CSS3
	  obj.style.opacity = opacity/100;
}

//-------------------------------------------------------------------------------
// Fonction Maj listes Recherche
//-------------------------------------------------------------------------------


$(document).ready(function() {
    majListeMere(0);

    $("#menu_recherche1").click(function() {
        btnDefault();
        MenuTypeAnnonceActive = 0;
        $("#menu_recherche1").attr("class", "menu_recherche_active1");
        majListeMere(0);
    });

    $("#menu_recherche2").click(function() {
    btnDefault();
    MenuTypeAnnonceActive = 1;
        $("#menu_recherche2").attr("class", "menu_recherche_active2");
        majListeMere(1);
    });

    $("#menu_recherche3").click(function() {
    btnDefault();
    MenuTypeAnnonceActive = 2;
        $("#menu_recherche3").attr("class", "menu_recherche_active3");
        majListeMere(2);
    });

    $("#menu_recherche4").click(function() {
    btnDefault();
    MenuTypeAnnonceActive = 3;
        $("#menu_recherche4").attr("class", "menu_recherche_active4");
        majListeMere(3);
    });

    $("#menu_recherche5").click(function() {
    btnDefault();
    MenuTypeAnnonceActive = 4;
        $("#menu_recherche5").attr("class", "menu_recherche_active5");
        majListeMere(4);
    });

});


var MenuTypeAnnonceActive = 0;

function majListeMere(intTypeAnnonce) {
    
    $("#ListeQuoi").html("<div style='width:180px;float:left;text-align:center;margin-top:-9px;'><img src='/App_Themes/BonjourVoisinsNC/images/commun/ajax-loader_liste_mere.gif' width='32' height='32' /></div>");
    
    $.ajax({
        type: "POST",
        url: "/Ajax/ListeMere.aspx",
        data: "intTypeAnnonce=" + intTypeAnnonce,
        success: function(msg) {
            $("#ListeQuoi").html(msg);
        }
    });

    

    // si div existe
    if (document.getElementById("liens_rapides")) {
        // Mettre à jour la liste

       // $("#liens_rapides").html("<div style='padding-top:37px;padding-bottom:37px;text-align:center;'>Chargement en cours...<br/><br/><img src='/App_Themes/BonjourVoisinsNC/images/commun/ajax-loader_derniers_inscrits.gif' width='42' height='42' /></div>");


        var _strData = "typeannonce=" + intTypeAnnonce;
        $.ajax({
            type: "POST",
            url: "/Ajax/liensrapides.aspx",
            data: _strData,
            success: function(msg) {            
            $("#liens_rapides").html(msg);

            }
        });
    } // fin si div existe

}


function majListeMere(intTypeAnnonce, idAnnonce) {

    $("#ListeQuoi").html("<div style='width:180px;float:left;text-align:center;margin-top:-9px;'><img src='/App_Themes/BonjourVoisinsNC/images/commun/ajax-loader_liste_mere.gif' width='32' height='32' /></div>");

    $.ajax({
        type: "POST",
        url: "/Ajax/ListeMere.aspx",
        data: "intTypeAnnonce=" + intTypeAnnonce,
        success: function(msg) {
        $("#ListeQuoi").html(msg);
            
            // Sélectionné l'élément.
            $("#eQuoi").val(idAnnonce);
        }
    });



    // si div existe
    if (document.getElementById("liens_rapides")) {
        // Mettre à jour la liste

        // $("#liens_rapides").html("<div style='padding-top:37px;padding-bottom:37px;text-align:center;'>Chargement en cours...<br/><br/><img src='/App_Themes/BonjourVoisinsNC/images/commun/ajax-loader_derniers_inscrits.gif' width='42' height='42' /></div>");


        var _strData = "typeannonce=" + intTypeAnnonce;
        $.ajax({
            type: "POST",
            url: "/Ajax/liensrapides.aspx",
            data: _strData,
            success: function(msg) {
                $("#liens_rapides").html(msg);

            }
        });
    } // fin si div existe


}




function majListFille(idTypeAnnonce) {

    $.ajax({
        type: "POST",
        url: "/Ajax/ListeFille.aspx",
        data: "idTypeAnnonce=" + idTypeAnnonce,
        success: function(msg) {
            $("#ListeFille").html(msg);
        }
    });

}

function btnDefault() {
    $("#menu_recherche1").removeAttr("class");
    $("#menu_recherche2").removeAttr("class");
    $("#menu_recherche3").removeAttr("class");
    $("#menu_recherche4").removeAttr("class");
    $("#menu_recherche5").removeAttr("class");
}


//-------------------------------------------------------------------------------
// Fonction Recherche
//-------------------------------------------------------------------------------
function Recherche() {

    // Rechercher la liste des villes possibles
    ListeAdressesExistes($("#eOu").val(), oncallback_listeVille);
}


// fonction calla pas des listes des villes trouvées
function oncallback_listeVille(addresses) {

    _champQuoi = false;
    _champOu = false;
    
    
    var _iNbVilles = 0;

    // si aucune adresse
    if (addresses == null) {
        _iNbVilles = 0;
    }
    else {

        // récupérer le nombre de ville
        _iNbVilles = addresses.length;
    }

    // si aucune ville trouvée
    if (_iNbVilles <= 0) {
        _champOu = false;
        $("#eOu").val("Saisie de la ville incorrecte");
        $("#eOu").attr("style", "border:#FF0000 1px solid;");
    }
    else if (($("#eOu").val() != "(Ville, CP)")
    && ($("#eOu").val() != "")
    && ($("#eOu").val() != "Veuillez saisir une ville")
    && ($("#eOu").val() != "Saisie de la ville incorrecte")
    ) {
        $("#eOu").removeAttr("style");
        _champOu = true;
    }
    else {
        _champOu = false;
        $("#eOu").val("Veuillez saisir une ville");
        $("#eOu").attr("style", "border:#FF0000 1px solid;");
    }

    if ($("#eQuoi").val() != "") {
        $("#eQuoi").removeAttr("style");
        _champQuoi = true;
    }
    else {
        _champQuoi = false;
        $("#eQuoi").attr("style", "border:#FF0000 1px solid;");
    }

    // si tous les champs OK
    if (_champQuoi && _champOu) {
        // si une ville
        if (_iNbVilles == 1) {
            _strVille = $("#eOu").val();
            AfficherFenChoixTypeAnnonceRecherche($("#eQuoi :selected").attr("NomLong"));
        }
        else {
            // sinon plusieurs villes
            AfficherChoixVille(addresses, $("#eQuoi :selected").attr("NomLong"));
        }// fin si une ville
    }// fin si tous les champs OK

} // fin fctoncallback_listeVille
var _strVille = "";
// Fonction pour afficher le choix des villes
function AfficherChoixVille(addresses, lib) {
    _c = 0;
    for (var _i = 0; _i < addresses.length; _i++) {        
        if (addresses[_i].accuracy >= 4 && addresses[_i].accuracy <= 8) _c++;
    }

    if (_c > 1) {

        _resultatsAdresses = "<div style='width:540px;background:#ffffff;padding:15px;margin-left:auto;margin-right:auto;'>";
        _resultatsAdresses += "<span style='font-size:14px;'>Il existe plusieurs villes,  veuillez sélectionner la ville souhaitée parmi :</span>";
        _resultatsAdresses += "<a id='btn_masquerSliderMap' style='float:right;' onclick='fermerLightBox();'/></a><br/><br/>";
        _resultatsAdresses += "<span style='font-size:13px;'><strong>" + _c + "</strong> au choix :</span><br/><br/>";

        for (var _i = 0; _i < addresses.length; _i++) {            
                if (addresses[_i].accuracy >= 4 && addresses[_i].accuracy <= 8)
                _resultatsAdresses += "- <a onClick=\"_strVille = '" + addresses[_i].address + "'; fermerLightBox();AfficherFenChoixTypeAnnonceRecherche('"+ lib + "');\" style='color:#4B90C1;'><strong>" + addresses[_i].address + "</strong></a><br/>";
        }
        _resultatsAdresses += "</div>";

        afficheLightBox(_resultatsAdresses);

    }
    else if (_c ==1)
    {
        _strVille = addresses[0].address;
        AfficherFenChoixTypeAnnonceRecherche(lib);       
    }
    else {
        $("#eOu").val("Saisie de la ville incorrecte");
        _strVille = "";
    }
}


// Fenêtre pour afficher le choix du type de recherche
  function AfficherFenChoixTypeAnnonceRecherche(lib) {
            _resultatsAdresses = "<div style='margin-left:auto; margin-right:auto;width:710px;background:url(/App_Themes/BonjourVoisinsNC/images/commun/fd_lightbox_recherche.png) no-repeat left top;'>";
            _resultatsAdresses += "<a id='btn_masquerSliderMap' style='float:right;margin-right:24px;margin-top:20px;' onclick='fermerLightBox();'/></a>";            
            _resultatsAdresses += "<div style='font-size:13px;color:#ffffff;text-align:center;'>Afin d’affiner votre recherche sélectionnez<br/>le type d’annonce que vous souhaitez parmi :</div>";
            _resultatsAdresses += "<a id='blocRecherche' onClick=\"ChoixTypeAnnonceRecherche(1);\"><span style='font-size:40px;'>Les voisins qui<br/><strong style='text-transform:uppercase;'>recherchent</strong><br/></span><span style='font-size:18px;'>" + lib + "</span></a>";
            _resultatsAdresses += "<a id='blocPropose' onClick=\"ChoixTypeAnnonceRecherche(2);\"><span style='font-size:40px;'>Les voisins qui<br/><strong style='text-transform:uppercase;'>proposent</strong><br/></span><span style='font-size:18px;'>" + lib + "</span></a>";
            _resultatsAdresses += "<div style='clear:both;'></div>";
            _resultatsAdresses += "</div>";
            afficheLightBox(_resultatsAdresses);
        }
// Lancer la page
        function ChoixTypeAnnonceRecherche(modeRecherche) {

            var _strUrl = GetUrlMembreOuNon() + "/resultatrecherchesimple.aspx?quoi=" + $("#eQuoi").val() + "&ou=" + _strVille + "&idParent=" + $("#eIdCategorieAnnonceParent").val() + "&type=" + modeRecherche + "&typeVoisin=7" + "&lib=" + escape($('#eQuoi :selected').attr("NomLong"));
   window.location = _strUrl;
}


//-------------------------------------------------------------------------------
// Fonction lecture varable GET
//-------------------------------------------------------------------------------
function getVar(nomVariable) {
    var infos = location.href.substring(location.href.indexOf("?") + 1, location.href.length) + "&"
    if (infos.indexOf("#") != -1)
        infos = infos.substring(0, infos.indexOf("#")) + "&"
    var variable = 0
    {
        nomVariable = nomVariable + "="
        var taille = nomVariable.length
        if (infos.indexOf(nomVariable) != -1)
            variable = infos.substring(infos.indexOf(nomVariable) + taille, infos.length).substring(0, infos.substring(infos.indexOf(nomVariable) + taille, infos.length).indexOf("&"))
    }
    return unescape(variable)
}

//-------------------------------------------------------------------------------
// Fonction LightBox
//-------------------------------------------------------------------------------
function afficheLightBox(_content) {
    $("#lightBox").attr("style", "display:block !important;padding-top:270px;height:" + document.body.offsetHeight + "px");
    $("#lightBox").html(_content);
}

function fermerLightBox() {
    $("#lightBox").removeAttr("style");
    $("#lightBox").html("");
}


// -----------------------------------------------------------------------------------------------
// Fonction Autocompletion : Complétion des localités
// -----------------------------------------------------------------------------------------------
// TODO remettre la completion

$(document).ready(function() {
    $('#eOu').autocomplete('/HttpHandler/completion.ashx', { width: 180 });
});

//-------------------------------------------------------------------------------
// Fonction GoogleMap
//-------------------------------------------------------------------------------
$(function() {
    $('#volet input').click(function() {
        _map.onChange();
    });
    $('#ePrecisionDistance').change(function() {
        _map.setRadius(this.value);
    });
    $('#btn_satellite').click(function() {
        setMapType(1);
    });
    $('#btn_plan').click(function() {
        setMapType(0);
    });
    $("a[name='retourAdresse']").click(function() {
        retourAdresse();
    });
});

function retourAdresse() {
    //_map.clearMarkers();

    
    var latVoisin = 0;
    var lngVoisin = 0;

    if ((document.getElementById("ctl00_page_latVoisin")) && (document.getElementById("ctl00_page_lngVoisin"))) 
    {
        latVoisin = $('#ctl00_page_latVoisin').val();
        lngVoisin = $('#ctl00_page_lngVoisin').val();                
    }
    else if ((document.getElementById("ctl00_latVoisin")) && (document.getElementById("ctl00_lngVoisin"))) 
    {
        latVoisin = $('#ctl00_latVoisin').val();
        lngVoisin = $('#ctl00_lngVoisin').val();
        
    }
    else
    {
        latVoisin = $('#latVoisin').val();
        lngVoisin = $('#lngVoisin').val();
        
    }
    
    
    latVoisin = latVoisin.replace(",", "."); latVoisin = parseFloat(latVoisin);    
    lngVoisin = lngVoisin.replace(",", "."); lngVoisin = parseFloat(lngVoisin);
    //alert("_map.setPosition("+latVoisin+", "+lngVoisin+", 13);");
    _map.setPosition2(latVoisin, lngVoisin);
}

//-------------------------------------------------------------------------------
// Fonction Connexion
//-------------------------------------------------------------------------------
function afficheConnexion() {

    if (_etatSliderHaut == 1) {
        fermerSliderHaut();
        
    }
    else {
        fermerSliderHaut();
        setTimeout("chargementContenuConnexion()", 750);

        ouvrirSliderHaut("200px", 1);
    }
}

function chargementContenuConnexion() {
    $("#DivCompteValider").attr("style", "display:none;");
    $("#inscription").attr("style", "display:none;");
    $("#connexion").removeAttr("style");
}

//-------------------------------------------------------------------------------
// Fonction Inscription
//-------------------------------------------------------------------------------
function afficheInscription() {

    if (_etatSliderHaut == 2) {
        fermerSliderHaut();
        
    }
    else {
        fermerSliderHaut();
        setTimeout("chargementContenuInscription()", 750);

        ouvrirSliderHaut("450px", 2);
    }
}


function chargementContenuValidationInscription(text) {
    
    
    $("#DivCompteValider").attr("style", "display:none;");
    $("#connexion").attr("style", "display:none;");
    $("#inscription").attr("style", "display:none;");
    $("#DivValidationInscription").html(text);
    $("#DivValidationInscription").removeAttr("style");
    
    // réinitialiser les valeurs de l'inscription
    $("#ctl00_txtInscriptionIdentifiant").val("");
    $("#ctl00_txtInscriptionEmail").val("");
    $("#ctl00_txtInscriptionConfirmationEmail").val("");
    $("#ctl00_txtInscriptionMdp").val("");
    $("#ctl00_txtInscriptionConfirmationMdp").val("");
    $("#ctl00_chkInscriptionCGDV").attr("checked", false);
    $("#ctl00_chkInscriptionNewsletter").attr("checked", false);
    // pour les "validateurs"
    $("#ctl00_txtInscriptionIdentifiant_Img").attr("src", "/App_Themes/BonjourVoisinsNC/images/commun/spacer.gif");
    $("#ctl00_txtInscriptionIdentifiant_Msg").text("");
    $("#ctl00_txtInscriptionEmail_Img").attr("src", "/App_Themes/BonjourVoisinsNC/images/commun/spacer.gif");
    $("#ctl00_txtInscriptionEmail_Msg").text("");
    $("#ctl00_txtInscriptionConfirmationEmail_Img").attr("src", "/App_Themes/BonjourVoisinsNC/images/commun/spacer.gif");
    $("#ctl00_txtInscriptionConfirmationEmail_Msg").text("");
    $("#ctl00_txtInscriptionMdp_Img").attr("src", "/App_Themes/BonjourVoisinsNC/images/commun/spacer.gif");
    $("#ctl00_txtInscriptionMdp_Msg").text("");
    $("#ctl00_txtInscriptionConfirmationMdp_Img").attr("src", "/App_Themes/BonjourVoisinsNC/images/commun/spacer.gif");
    $("#ctl00_txtInscriptionConfirmationMdp_Msg").text("");
    $("#ctl00_chkInscriptionCGDV_Img").attr("src", "/App_Themes/BonjourVoisinsNC/images/commun/spacer.gif");
    $("#ctl00_chkInscriptionCGDV_Msg").text("");
    
    
}

function chargementContenuInscription() {
    $("#DivCompteValider").attr("style", "display:none;");
    $("#connexion").attr("style", "display:none;");
    $("#DivValidationInscription").attr("style", "display:none;");
    $("#inscription").removeAttr("style");
    
}

//-------------------------------------------------------------------------------
// Fonction Validation compte
//-------------------------------------------------------------------------------
function afficheValidation() {
    $(document).ready(function() {
        chargementContenuValidation();
        ouvrirSliderHaut("400px", 3);
    });
}

function chargementContenuValidation() {
    $("#DivCompteValider").removeAttr("style");
    $("#connexion").attr("style", "display:none;");
    $("#inscription").attr("style", "display:none;");
    $("#DivValidationInscription").attr("style", "display:none;");
    
}

//-------------------------------------------------------------------------------
// Initialisation du slidepanel
//-------------------------------------------------------------------------------
$(document).ready(function() {

    $("#slidepanel").slideBox({ width: "100%", height: "500px", position: "top" });
});


//-------------------------------------------------------------------------------
// Emulation du #colonne_droite{min-height:676px;}
//-------------------------------------------------------------------------------
$(document).ready(function() {
    //if (document.getElementById('colonne_droite').offsetHeight <= 676) document.getElementById('colonne_droite').style.height = '676px';
});



//-------------------------------------------------------------------------------
// Fonction pour cacher le mail
//-------------------------------------------------------------------------------
    function CacheMail(mail, domain) {
        this.location = 'mailto:' + mail + '@' + domain;
    }


//-------------------------------------------------------------------------------
// Fonction recherche par locaité
//-------------------------------------------------------------------------------
    function RechercheParLocalite() {

        var _Ville = $("#villeIntro").val();

        
        if (_Ville == "") {
            $("#villeIntro").val("Saisie de la ville incorrecte");
        }
        else {
            // Rechercher la liste des villes qui existent
            ListeAdressesExistes(_Ville, oncallback_listeVillePourRechercheLocatlite);
        }
}

function oncallback_listeVillePourRechercheLocatlite(addresses) {


    
    var _iNbVilles = 0;

    // si aucune adresse
    if (addresses == null) {
        _iNbVilles = 0;
    }
    else {

        // récupérer le nombre de ville
        _iNbVilles = addresses.length;
    }

    // si une ville
    if (_iNbVilles == 1) {
        RechercherLocalite($("#villeIntro").val());
    }
    else {
        //alert(addresses);
        // sinon plusieurs villes
        AfficherChoixVillePourRechercheLocalite(addresses);
    }  // fin si une ville
    
    
}


function AfficherChoixVillePourRechercheLocalite(addresses) {
    _c = 0;
   // alert("av adresse length = " + addresses.length);
    for (var _i = 0; _i < addresses.length; _i++) {        
        if (addresses[_i].accuracy >= 4 && addresses[_i].accuracy <= 8) _c++;
    }

    //alert("apr _c = " + _c);
    if (_c > 1) {

        _resultatsAdresses = "<div style='width:540px;background:#ffffff;padding:15px;margin-left:auto;margin-right:auto;'>";
        _resultatsAdresses += "<span style='font-size:14px;'>Il existe plusieurs villes,  veuillez sélectionner la ville souhaitée parmi :</span>";
        _resultatsAdresses += "<a id='btn_masquerSliderMap' style='float:right;' onclick='fermerLightBox();'/></a><br/><br/>";
        _resultatsAdresses += "<span style='font-size:13px;'><strong>" + _c + "</strong> au choix :</span><br/><br/>";

        for (var _i = 0; _i < addresses.length; _i++) {            
                if (addresses[_i].accuracy >= 4 && addresses[_i].accuracy <= 8)
                _resultatsAdresses += "- <a onClick=\"fermerLightBox();RechercherLocalite('"+ addresses[_i].address + "');\" style='color:#4B90C1;'><strong>" + addresses[_i].address + "</strong></a><br/>";
        }
        _resultatsAdresses += "</div>";

        afficheLightBox(_resultatsAdresses);

    }
    else if (_c ==1)
    {
        RechercherLocalite(addresses[0].address);        
    }
    else {
        $("#villeIntro").val("Saisie de la ville incorrecte");
        _strVillePourLocalite = "";
    }
}


function RechercherLocalite(ville) {


    var _strUrl = GetUrlMembreOuNon() + "/recherchelocalite.aspx";

    _localiteDejaRecherche = false;
    _recherche = $("#villeIntro").val();
    if ((_recherche != "(Ville, CP)") && (_recherche != "")) {
        window.location.replace(_strUrl + "?recherche=" + escape(ville));
    }
}


//-------------------------------------------------------------------------------
// Fonction pour gérer la deconnexion
//-------------------------------------------------------------------------------
function GererDeconnexion() {

// Afficher la page index du site ce qui géra automatiquement la déconnexion
    window.location = "/index.aspx";
}

function GetUrlMembreOuNon() {
    var _strUrl = "";

    if ((location.href.indexOf("EspaceMembre") >= 0)
    && (location.href.indexOf("ReturnUrl=") == -1)
    ) {
        _strUrl = "/EspaceMembre";
    }
    return _strUrl;
}

function Contacter(mode) {

    var _strUrl = GetUrlMembreOuNon() + "/contact.aspx";

    window.location = _strUrl;

}
function SignalerUnAbus(mode) {

    var _strUrl = GetUrlMembreOuNon() + "/contact.aspx?opt=1";

    window.location = _strUrl;

}


function RecommanderSite() {
    var _strUrl = GetUrlMembreOuNon() + "/recommander.aspx";

    window.location = _strUrl;
}

//-------------------------------------------------------------------------------
// Derniers inscrits
//-------------------------------------------------------------------------------
function DerniersInscrits(bPositionOK) {


    var _strData = "";



    if (bPositionOK == true) {

        if (_map != null) {
            var _point = _map.getPosition();
            _strData = "lat=" + _point.lat + "&lng=" + _point.lng + "&rayon=" + _point.radius;

        }
        else {
            _strData = "";
        }
    }
    else {

        // mettre l'opt à 1 pour ne pas mettre les liens sur les images
        _strData = "opt=1";
    }

    if ($("#derniers_inscrits").html() == "") {

        $("#derniers_inscrits").html("<div style='padding-top:37px;padding-bottom:37px;text-align:center;'>Chargement en cours...<br/><br/><img src='/App_Themes/BonjourVoisinsNC/images/commun/ajax-loader_derniers_inscrits.gif' width='42' height='42' /></div>");

        $.ajax({
            type: "POST",
            url: "/Ajax/dernierinscrit.aspx",
            data: _strData,
            success: function(msg) {
                $("#derniers_inscrits").html(msg);

            }
        });

    }
   
    
    if (document.getElementById("derniers_inscrits_index")) {

        $($("#derniers_inscrits_index").html()=="")
        {
            _strData += "&nb=16";

            $("#derniers_inscrits_index").html("<div style='padding-top:37px;padding-bottom:37px;text-align:center;'>Chargement en cours...<br/><br/><img src='/App_Themes/BonjourVoisinsNC/images/commun/ajax-loader_derniers_inscrits.gif' width='42' height='42' /></div>");

            $.ajax({
                type: "POST",
                url: "/Ajax/dernierinscrit.aspx",
                data: _strData,
                success: function(msg) {
                    $("#derniers_inscrits_index").html(msg);

                }
            });
        }
    
    }
    
    
    
}



function AfficherDernierInscritCarte(page, latitude, longitude) {


    if (location.href.indexOf(page) == -1) {
        window.location.replace(page + ".aspx?lat=" + latitude + "&lng=" + longitude);
    }
    else {        
        _map.setPosition2(latitude, longitude);       
    }

}


//-------------------------------------------------------------------------------
// Affichage de la zone d'explication de la page
//-------------------------------------------------------------------------------
$(document).ready(function() {

    // aller rechercher l'information sur la page.    
    $.ajax({
        type: "POST",
        url: "/Ajax/explicationpage.aspx",
        data: "url="+window.location,
        success: onExplicationLoad
    });

});

function onExplicationLoad(msg) {

    $('#ExplicationPage').html(msg);

    sAccordion({
        container: 'sAccordion', // ID du container
        activeContent: 0, // Accordeon ouvert par defaut
        speed: 'speed' // vitesse de l'effet slideToggle ( slow, medium, speed )
    });
}


var SurvolTypeAnnonceEnCours = 0;

function AfficherPanelMenu(typeAnnonce) {

    ArreterTimerPanelMenu();
    
    SurvolTypeAnnonceEnCours = typeAnnonce;

    // A chaque affichage du panel remettre les autres boutons à l'heure était normal (sans class).
    // Par contre remettre la class pour le menu actif
    // Pour tous les boutons
    for (var i = 0; i < 5; i++) 
    {
      
        // si survol diff
        if (SurvolTypeAnnonceEnCours != i) {
            // si bouton actif
            if (MenuTypeAnnonceActive == i) 
            {
                // mettre l'image active
                $("#menu_recherche" + (i + 1)).attr("class", "menu_recherche_active" + (i + 1));
            }
            else {
                // effacer la clas
                $("#menu_recherche" + (i + 1)).removeAttr("class");
            }// fin si bouton actif
        }// si différent du survol
    }// FIn pour tous les boutons


    // si le sous menu n'a pas déjà était chargé
   // if ($("#Sous_menu_recherche" + (typeAnnonce + 1)).html() == "")
    //{

        // Charger les informations

        var _params = "typeannonce=" + typeAnnonce;

        $.ajax({
            type: "POST",
            url: "/Ajax/listetypeannoncepanel.aspx",
            data: _params,
            success: function(msg) {

           // $("#Sous_menu_recherche" + (SurvolTypeAnnonceEnCours + 1)).html(msg);

                
                $("#listeQuoiPanel").html(msg);


                // Récupérer la position
                var _position = $("#menu_recherche" + (SurvolTypeAnnonceEnCours + 1)).position();
                // récupérer la largeur de la div.
                var _Largeur = $("#menu_recherche" + (SurvolTypeAnnonceEnCours + 1)).width();
                // Récupérer la hauteur de la div.
                var _hauteur = $("#menu_recherche" + (SurvolTypeAnnonceEnCours + 1)).height();

                var _strStyle = "display:block;z-index:9;position: absolute;"; //background-color:#FFFFFF;"            
                _strStyle += "top:" + (_position.top + _hauteur - 1) + "px;"
                _strStyle += "left:" + (_position.left) + "px;"


                $("#panelmenu").attr("style", _strStyle);            
                $("#panelmenu").attr("onmouseover", "ReAffichePanelMenu(" + typeAnnonce + ");");

                $("#listeQuoiPanel").attr("style", "min-width:" + _Largeur + "px;");
                $("#listeQuoiPanel").attr("onmouseover", "ReAffichePanelMenu(" + typeAnnonce + ");");
                // $("#listeQuoiPanel").attr("onmouseout", "TestCacherPanelMenu(100);");

                $("#menu_recherche" + (typeAnnonce + 1)).attr("class", "menu_recherche" + (typeAnnonce + 1) + "_hover");
                

            }
        });
        
    
   // }// fin si le sous menu n'a pas déjà était chargé

    
}

var TimerPanelMenu = null;

function TestCacherPanelMenu() {

    if (TimerPanelMenu == null) {
        TimerPanelMenu = window.setTimeout("CacherPanelMenu()", 100);
        
    }
}


function ArreterTimerPanelMenu() 
{
    if (TimerPanelMenu != null) {
        
        window.clearTimeout(TimerPanelMenu);
        TimerPanelMenu = null;
    }

}

function CacherPanelMenu() 
{

    ArreterTimerPanelMenu();
    //listepanel

    $("#panelmenu").attr("style", "display:none;");

    //alert("MenuTypeAnnonceActive  = " + MenuTypeAnnonceActive + "\tSurvolTypeAnnonceEnCours =" + SurvolTypeAnnonceEnCours);
    if (MenuTypeAnnonceActive == SurvolTypeAnnonceEnCours) {
        $("#menu_recherche" + (SurvolTypeAnnonceEnCours + 1)).attr("class", "menu_recherche_active" + (SurvolTypeAnnonceEnCours + 1));
    }
    else {
        $("#menu_recherche" + (SurvolTypeAnnonceEnCours + 1)).attr("class", "menu_recherche" + (SurvolTypeAnnonceEnCours + 1));
    }

    
}

function ReAffichePanelMenu(typeAnnonce) {


    ArreterTimerPanelMenu();
    
    // 400px
    var _position = $("#menu_recherche" + (typeAnnonce + 1)).position();

    // récupérer la largeur de la div.
    var _Largeur = $("#menu_recherche" + (typeAnnonce + 1)).width();

    var _hauteur = $("#menu_recherche" + (SurvolTypeAnnonceEnCours + 1)).height();
    $("#menu_recherche" + (typeAnnonce + 1)).attr("class", "menu_recherche" + (typeAnnonce + 1) + "_hover");

    var _strStyle = "display:block;z-index:9;position: absolute;";//background-color:#FFFFFF;"
    //_strStyle += "top:" +  (_position.top + 48) + "px;"
    _strStyle += "top:" + (_position.top + _hauteur-1) + "px;"
    // reculer de 2 px (pour la taille sur le coté
    _strStyle += "left:" + (_position.left) + "px;"

    $("#panelmenu").attr("style", _strStyle);
    
    
}


function ChangementMenu(typeAnnonce, idAnnonce) {
    btnDefault();


    MenuTypeAnnonceActive = typeAnnonce;
    CacherPanelMenu();
    $("#menu_recherche" + (typeAnnonce + 1)).attr("class", "menu_recherche_active" + (typeAnnonce + 1));

    //alert("maj liste avec id " + idAnnonce);
    // Mettre à jour la liste
    majListeMere(typeAnnonce, idAnnonce);


}


function TextvilleIntro_Change(event) {

    if (event.keyCode == 13) {
        RechercheParLocalite();
    }
}

function TextOuChange(event) {

    if (event.keyCode == 13) {
        Recherche();
    }

}

function TextConnexionChange(iConnexion, event) {
   

    // Si touche entrée
    if (event.keyCode == 13) {
        
       switch(iConnexion)
       {
           case 1:
               if (($("#loginConnexion1").val() != "")
                && ($("#passwordConnexion1").val() != "")
              ) {
                   ValiderFormulaireConnexion1();
               }
                break;
           case 2:
           if (    ($("#loginConnexion2").val() != "")
                && ($("#passwordConnexion2").val() != "")
              )       
                {
                 ValiderFormulaireConnexion2();
                }
                break;
            case 3:
                if (($("#loginConnexion3").val() != "")
                && ($("#passwordConnexion3").val() != "")
              ) {
                    ValiderFormulaireConnexion3();
                }
                
                break;
       }// fin selon 
       
            

    }// fin si touche entrée

}

