/**
 * @author jeremy@eolas.fr
 */
//<![CDATA[

    geopoint = {
        oHTTP				:	false,
        initialisedMap		:	false,
        inputLongitude		:	null,
        inputLatitude		:	null,
        map					:	null,
        infoMap				:	null,
        contextmenu			:	null,
        showeddiv			:	null,
        form_id				:	null,
        form_stop_submit	:	false,
        selectedli			:	null,
        clickedPixel		:	null,
        path_icon			:	null,
        list_icon			:	new Array(),
        country_cache		:	new Array(),
        place_cache			:	new Array(),
        xml_args			:	new Array(),
        input_region		:	null,
        input_pays			:	null,
        input_place			:	null,
        div_place_liste 	:	null,
        path				:	null,
        timerPlaceListener	:	0,
        tabDown				:	null,
        tabUp				:	null,
        place_last_search	:	'',
        pay_code_init		:	'',
        marker_principal 	:	null,
        marker_secondaire 	:	new Array(),
        marker_polyline  	:	new Array(),
        compteur_id			:	1,
        marker_type			:	1,
        toolbar_left		:	null,
        toolbar_top			:	null,
        marker_data			:	new Array(),
        timer				:	null,
        markers_placed		:	new Array(),
        marker_types		:	new Array(),
        markers_i_anchors	:	new Array(),
        markerGroups		:   new Array(),
        xml_loaded			: 	false,
        object_types		:	new Array(),
		zoom_mode			:	null,
		map_type			:   null,
		geocoder			:	null,

        /**
        * Faire apparaitre / Cacher les menus de recherche
        * @param varchar id Identifiant div a afficher
        * @param Element oA Element A en cours
        */
        showDiv : function (id, oA) {
            if (geopoint.showeddiv != id) {
                if (geopoint.showeddiv != null) {
                    document.getElementById(geopoint.showeddiv).style.display = 'none';
                    geopoint.selectedli.className = '';
                }

                oLi = oA.parentNode;
                while (oLi.tagName != 'LI') oLi = oLi.parentNode;
                oLi.className = 'selected';
                geopoint.selectedli = oLi;

                geopoint.showeddiv = id;
                document.getElementById(id).style.display = 'block';
            }
        },

        /**
        * Faire apparaitre / Cacher les données
        * @param varchar divId Identifiant div a afficher ou cacher
        */
        showForm : function(divId) {
            oDiv = document.getElementById(divId);
            oDiv.style.display = 'block';

            if (geopoint.infoMap != null && geopoint.initialisedMap == false) {
                geopoint.loadForEdition();
            }
        },



        /**
        * Création d'un marker sur la carte
        * @param point point
        * @param varchar _title Titre (opt)
        * @param varchar _desc Description (opt)
        * @param varchar _type Type (opt)
        * @return GMarker
        */
        createMarkerEdition : function(point, _title, _desc, _type) {
            if (_type > 0 && _type < 4) {
                geopoint.marker_type = _type
            }

            if (geopoint.marker_type == 1 && geopoint.marker_principal != null) {
                // Le point principale existe, on le déplace simplement
                tmpMarker = geopoint.marker_principal;
                tmpMarker.setPoint(point);
                geopoint.marker_principal = tmpMarker;
            } else {
                tmpMarker = new GMarker(point, {icon:geopoint.getIcon(), title:(_title ? _title : ''), draggable: true});
                tmpMarker.type = geopoint.marker_type;
                tmpMarker.id = 'm' + geopoint.compteur_id++;
                tmpMarker.libelle = (_title ? _title : '');
                tmpMarker.desc = (_desc ? _desc : '');

                // Evenements (click et dragndrop)
                GEvent.addListener(tmpMarker, 'click', function() {
                    html = ''
                        +	'<div id="geopoint_infos" style="width: 250px">'
                        +		'<b>Libell&eacute; : </b><input type="text" value="' + this.libelle + '" id="' + this.id + '_libelle"><br/><hr class="geopoint_dashed"/>'
                        +		'Vous pouvez ins&eacute;rer un commentaire sur ce point<br/>'
                        +		'<textarea style="width: 98%; height: 70px; margin-top: 4px;" id="' + this.id + '_desc">' + this.desc + '</textarea>'
                        +		'<br/><input type="button" onclick="geopoint.removeMarker(\'' + this.id + '\', ' + this.type + ');" value="Supprimer"/>'
                        +		'<input type="button" onclick="geopoint.recordMarkerData(\'' + this.id + '\', ' + this.type + '); " value="Enregistrer"/>'
                        +	'</div>';
                    this.openInfoWindowHtml(html);
                });
                GEvent.addListener(tmpMarker, "dragstart", function() {this.closeInfoWindow();});
                GEvent.addListener(tmpMarker, "dragend", function() {
                    if (this.type == 3) {
                        myMarker = geopoint.setMarkerById(this.id,this,  3);
                    }
                    geopoint.displayMarkers();
                });

                // Enregistrement du marquer
                if (tmpMarker.type == 1) {
                    geopoint.marker_principal = tmpMarker;
                } else if (tmpMarker.type == 2) {
                    geopoint.marker_secondaire.push(tmpMarker);
                } else if (tmpMarker.type == 3) {
                    geopoint.marker_polyline.push(tmpMarker);
                }
            }

            // Affichage
            geopoint.displayMarkers();

            return tmpMarker;
        },

        /**
        * Création d'un marker sur la carte
        * @param point point
        * @param varchar _title Titre (opt)
        * @param varchar _desc Description (opt)
        * @param varchar _type Type (opt)
        * @return GMarker
        */
        createMarkerView : function(point, _title, _desc, _type) {
            if (_type > 0 && _type < 4) {
                geopoint.marker_type = _type
            }

            if (geopoint.marker_type == 1 && geopoint.marker_principal != null) {
                // Le point principale existe, on le déplace simplement
                tmpMarker = geopoint.marker_principal;
                tmpMarker.setPoint(point);
                geopoint.marker_principal = tmpMarker;
            } else {
                tmpMarker = new GMarker(point, {icon:geopoint.getIcon(), title:(_title ? _title : ''), draggable: false});
                tmpMarker.type = geopoint.marker_type;
                tmpMarker.id = 'm' + geopoint.compteur_id++;
                tmpMarker.libelle = (_title ? _title : '');
                tmpMarker.desc = (_desc ? _desc : '');

                if (_title || _desc)
                {
                    // Evenements (click et dragndrop)
                    GEvent.addListener(tmpMarker, 'click', function() {
						html = ''
							+	'<div style="width: 250px">'
							+		'<b>' + this.libelle + '</b><br />'
							+		'<br/>' + this.desc
							+	'</div>';
						this.openInfoWindowHtml(html);
                    });
                }
                // Enregistrement du marquer
                if (tmpMarker.type == 1) {
                    geopoint.marker_principal = tmpMarker;
                } else if (tmpMarker.type == 2) {
                    geopoint.marker_secondaire.push(tmpMarker);
                } else if (tmpMarker.type == 3) {
                    geopoint.marker_polyline.push(tmpMarker);
                }
            }

            // Affichage
            geopoint.displayMarkers();

            return tmpMarker;
        },

        /**
        *	Enregistrer les données d'un point
        *	@param varchar marker_id
        *	@param int type
        *	@return void
        */
        recordMarkerData : function(marker_id, type) {
            myMarker = geopoint.getMarkerById(marker_id, type);
            if (myMarker) {
                myMarker.libelle = document.getElementById(marker_id + '_libelle').value;
                myMarker.desc = document.getElementById(marker_id + '_desc').value;
                geopoint.setMarkerById(marker_id, myMarker, type);
                // Enregistrement Recorder
                document.getElementById('geopoint_' + marker_id + '_desc').value =  myMarker.desc;
                document.getElementById('geopoint_' + marker_id + '_libelle').value =  myMarker.libelle;
            }
            geopoint.map.closeInfoWindow();
        },

        /**
        *	Suppression d'un marqueur
        *	@param varchar marker_id
        *	@param int type
        *	@return void
        */
        removeMarker : function(marker_id, type) {
            if (confirm('Voulez vous supprimer ce point ?')) {
                geopoint.map.closeInfoWindow();
                if (type == 1) { // Marqueur principal ?
                    if (geopoint.marker_principal.id == marker_id) {
                        geopoint.marker_principal = null;
                        geopoint.displayMarkers();
                    }
                } else if (type == 2) {	// Marqueurs secondaires ?
                    a = new Array();
                    for (i=0;geopoint.marker_secondaire[i];i++) {
                        if (geopoint.marker_secondaire[i].id != marker_id) {
                            a.push(geopoint.marker_secondaire[i]);
                        }
                    }
                    geopoint.marker_secondaire = a;
                    geopoint.displayMarkers();
                } else if (type == 3) {	// Marqueurs parcours ?
                    a = new Array();
                    for (i=0;geopoint.marker_polyline[i];i++) {
                        if (geopoint.marker_polyline[i].id != marker_id) {
                            a.push(geopoint.marker_polyline[i]);
                        }
                    }
                    geopoint.marker_polyline = a;
                    geopoint.displayMarkers();
                }
            }
        },

        /**
        *	Recupération d'un marqueur
        *	@param varchar marker_id
        *	@param int type
        *	@return GMarker
        */
        getMarkerById : function(marker_id, type) {
            if (type == 1) { // Marqueur principal ?
                if (geopoint.marker_principal.id == marker_id) {
                    return geopoint.marker_principal;
                }
            } else if (type == 2) {	// Marqueurs secondaires ?
                for (i=0;geopoint.marker_secondaire[i];i++) {
                    if (geopoint.marker_secondaire[i].id  == marker_id) {
                        return geopoint.marker_secondaire[i];
                    }
                }
            } else if (type == 3) {	// Marqueurs parcours ?
                for (i=0;geopoint.marker_polyline[i];i++) {
                    if (geopoint.marker_polyline[i].id == marker_id) {
                        return geopoint.marker_polyline[i];
                    }
                }
            }
            return false;
        },

        /**
        *	Enregistrement d'un marqueur
        *	@param varchar marker_id
        *	@param GMarker newMarker
        *	@param int type
        *	@return boolean
        */
        setMarkerById : function(marker_id, newMarker, type) {

            if (type == 1) { // Marqueur principal ?
                if (geopoint.marker_principal.id == marker_id) {
                    geopoint.marker_principal = newMarker;
                    return true;
                }
            } else if (type == 2) {	// Marqueurs secondaires ?
                for (i=0;geopoint.marker_secondaire[i];i++) {
                    if (geopoint.marker_secondaire[i].id  == marker_id) {
                        geopoint.marker_secondaire[i] = newMarker;
                        return true;
                    }
                }
            } else if (type == 3) {	// Marqueurs parcours ?
                for (i=0;geopoint.marker_polyline[i];i++) {
                    if (geopoint.marker_polyline[i].id  == marker_id) {
                        geopoint.marker_polyline[i] = newMarker;
                        return true;
                    }
                }
            }
            return false;
        },

        /**
        * Affichage des marqueurs et enregistrements des données pour le formulaire
        * @param GMarker
        * @param int ordre (optionnelle, juste pour type 3)
        * @return void
        */
        createInputRecorder : function(tmpMarker, ordre) {
            oDivRecorder = document.getElementById('geopoint_div_recorder');

            marker_id = tmpMarker.id
            // Latitude
            oInput = document.createElement("input");
            oInput.setAttribute('name', 'geopoint_' + marker_id + '_lt');
            oInput.setAttribute('value', tmpMarker.getPoint().lat());
            oDivRecorder.appendChild(oInput);
            // Longitude
            oInput = document.createElement("input");
            oInput.setAttribute('name', 'geopoint_' + marker_id + '_lg');
            oInput.setAttribute('value', tmpMarker.getPoint().lng());
            oDivRecorder.appendChild(oInput);
            // Description
            oInput = document.createElement("input");
            oInput.setAttribute('name', 'geopoint_' + marker_id + '_desc');
            oInput.setAttribute('id', 'geopoint_' + marker_id + '_desc');
            oInput.setAttribute('value', tmpMarker.desc);
            oDivRecorder.appendChild(oInput);
            // Libelle
            oInput = document.createElement("input");
            oInput.setAttribute('name', 'geopoint_' + marker_id + '_libelle');
            oInput.setAttribute('id', 'geopoint_' + marker_id + '_libelle');
            oInput.setAttribute('value', tmpMarker.libelle);
            oDivRecorder.appendChild(oInput);
            // Type
            oInput = document.createElement("input");
            oInput.setAttribute('name', 'geopoint_' + marker_id + '_type');
            oInput.setAttribute('value', tmpMarker.type);
            oDivRecorder.appendChild(oInput);
            if (!isNaN(ordre) && tmpMarker.type == 3) {
                // Order pour type 3
                oInput = document.createElement("input");
                oInput.setAttribute('name', 'geopoint_' + marker_id + '_ordre');
                oInput.setAttribute('value', ordre);
                oDivRecorder.appendChild(oInput);
            }
            // Liste des élèments
            oInput = document.createElement("input");
            oInput.setAttribute('name', 'geopoint_liste_id[]');
            oInput.setAttribute('value', marker_id);
            oDivRecorder.appendChild(oInput);

        },

        /**
        * Affichage des marqueurs et enregistrements des données pour le formulaire
        * @return void
        */
        displayMarkers : function() {
            geopoint.map.clearOverlays();

            oDivRecorder = document.getElementById('geopoint_div_recorder');
            if (!oDivRecorder) {
                oDivRecorder = document.createElement("div");
                oDivRecorder.setAttribute('id','geopoint_div_recorder');
                oDivRecorder.style.display = 'none';
                document.getElementById('gMapWrapper').appendChild(oDivRecorder);
            }
            oDivRecorder.innerHTML = '';

            // Marqueur principal
            if (geopoint.marker_principal != null) {
                geopoint.map.addOverlay(geopoint.marker_principal);
                geopoint.createInputRecorder(geopoint.marker_principal);
            }

            // Marqueurs secondaires
            if (geopoint.marker_secondaire.length > 0) {
                for (i=0;geopoint.marker_secondaire[i];i++) {
                    geopoint.map.addOverlay(geopoint.marker_secondaire[i]);
                    geopoint.createInputRecorder(geopoint.marker_secondaire[i]);
                }
            }

            // Marqueurs parcours
            if (geopoint.marker_polyline.length > 0) {
                var latlngs = new Array();
                for (i=0;geopoint.marker_polyline[i];i++) {
                    geopoint.map.addOverlay(geopoint.marker_polyline[i]);
                    geopoint.createInputRecorder(geopoint.marker_polyline[i], i);
                    latlngs.push(geopoint.marker_polyline[i].getPoint());
                }
                var polyline = new GPolyline(latlngs, "#F00000", 3);
                geopoint.map.addOverlay(polyline);
            }
        },

        /**
        * Highlight off type de marqueurs
        * @return void
        */
        markertype_out : function (num) {
            if (num > 0 && num < 4 && geopoint.marker_type != num) {
                o = document.getElementById('geopoint_marker_type_' + num);
                o.src = o.src.replace('type_' + num + '_on', 'type_' + num + '_off');
            }
        },

        /**
        * Highlight on type de marqueurs
        * @return void
        */
        markertype_over : function (num) {
            if (num > 0 && num < 4 && geopoint.marker_type != num) {
                o = document.getElementById('geopoint_marker_type_' + num);
                if (o)
                {
                    o.src = o.src.replace('type_' + num + '_off', 'type_' + num + '_on');
                }
            }
        },

        /**
        * Séclection type de marqueurs
        * @return flase
        */
        markertype_click : function (num) {
            if (num > 0 && num < 4) {
                o = document.getElementById('geopoint_marker_type_' + geopoint.marker_type);
                o.src = o.src.replace('type_' + geopoint.marker_type + '_on', 'type_' + geopoint.marker_type + '_off');

                o = document.getElementById('geopoint_marker_type_' + num);
                o.src = o.src.replace('type_' + num + '_off', 'type_' + num + '_on');
                geopoint.marker_type = num;
            }
            return false;
        },

        /**
        * Highlight off icons
        * @return void
        */
        icons_out : function (name) {
            o = document.getElementById('geopoint_' + name);
            if (o) {
                o.src = o.src.replace(name + '_on', name+ '_off');
            }
        },

        /**
        * Highlight on icons
        * @return void
        */
        icons_over : function (name) {
            o = document.getElementById('geopoint_' + name);
            if (o) {
                o.src = o.src.replace(name + '_off', name+ '_on');
            }
        },

        /**
        * Afficher / Cacher la barre
        * @return false
        */
        showToolbar : function() {
            o = document.getElementById('geopoint_toolbar');
            cDiv = o.getElementsByTagName('div');
            icons_display = 'none';
            for (i=0;cDiv[i];i++) {
                if (cDiv[i].className == 'geopoint_icons') {
                    icons_display = (cDiv[i].style.display == 'none' ? 'block' : 'none');
                    cDiv[i].style.display = icons_display;
                }
            }

            o = document.getElementById('geopoint_toolbar_img');
            o.src = (icons_display == 'none')
                        ? o.src.replace('control_down.gif', 'control_up.gif')
                        : o.src.replace('control_up.gif', 'control_down.gif');

            return false;
        },

        /**
        * Initialise la toolbar
        * @return false
        */
        initToolbar : function() {
            if (geopoint.toolbar_left == null) {
                ddToolBar = new YAHOO.util.DD('geopoint_toolbar');
                ddToolBar.addInvalidHandleType('input');
                ddToolBar.addInvalidHandleType('a');
                ddToolBar.addInvalidHandleType('img');
                geopoint.toolbar_left = '90%';
                geopoint.toolbar_top = '30px';
                return false;
            }

            o = document.getElementById('geopoint_toolbar');
            o.style.left = geopoint.toolbar_left;
            o.style.top = geopoint.toolbar_top;
            geopoint.markertype_click(1);
            geopoint.showToolbar();
            return false;
        },

        /**
        * Efface tous les points
        * @return false
        */
        clear : function () {
            if (confirm('Voulez-vous supprimer tous les points ?')) {
                geopoint.marker_principal = null;
                geopoint.marker_secondaire = new Array();
                geopoint.marker_polyline = new Array();
                geopoint.displayMarkers();
            }
            return false;
        },

        /**
        * Défini quel icone afficher
        * @param int _mode
        * @return GIcon
    */
        getIcon : function() {

            if (geopoint.path_icon == null) {
                var re = new RegExp('^http[s]?://([^/])*/');
                var m = re.exec(window.location.href);
                if (m) {
                    geopoint.path_icon = m[0] + '/i/geopoint/';
                }
                if (geopoint.path_icon == null) {
                    // TODO Enlever en fin de dev
                    // geopoint.path_icon = 'file:///D:/_Developpement/SkiPass/svn/www/i/geopoint/';
                }
            }

            if (geopoint.list_icon.length == 0) {
                geopoint.list_icon.push(''); // valeur 0 vide

                _icon = new GIcon();
                _icon.infoWindowAnchor = new GPoint(20,25);
                _icon.iconAnchor = new GPoint(13,25);
                _icon.iconSize = new GSize(20,25);
                _icon.image = geopoint.path_icon + 'm_1.png';
                _icon.shadow = geopoint.path_icon + 'shadow.png';
                geopoint.list_icon.push(_icon);

                _icon = new GIcon();
                _icon.infoWindowAnchor = new GPoint(20,25);
                _icon.iconAnchor = new GPoint(13,25);
                _icon.iconSize = new GSize(20,25);
                _icon.image = geopoint.path_icon + 'm_2.png';
                _icon.shadow = geopoint.path_icon + 'shadow.png';
                geopoint.list_icon.push(_icon);

                _icon = new GIcon();
                _icon.iconSize=new GSize(11,11);
                _icon.shadowSize=new GSize(0,0);
                _icon.iconAnchor=new GPoint(6,6);
                _icon.infoWindowAnchor=new GPoint(6,6);
                _icon.image = geopoint.path_icon + 'm_3.gif';
                _icon.shadow = geopoint.path_icon + 'shadow.png';
                geopoint.list_icon.push(_icon);
            }

            return geopoint.list_icon[geopoint.marker_type];
        },

        /**
        * Initialisation de la carte
        * @param decimal _lt Latitude centre
        * @param decimal _lg longitude centre
        * @param decimal _zoom Niveau de zoom
        * @return GMarker
        */
        initMapsForEdition : function(_lt, _lg, _zoom) {
            geopoint.infoMap = new Array(_lt, _lg, _zoom);
            geopoint.initToolbar();
        },


        /**
        * Affiche du menu contextuel (clique droit)
        * @param
        * @param
        * @return void
        */
        showContextMenu : function (pixel, tile) {

            geopoint.clickedPixel = pixel;
            var x = pixel.x;
            var y = pixel.y;
            if (x > geopoint.map.getSize().width - 120) { x = geopoint.map.getSize().width - 120 }
            if (y > geopoint.map.getSize().height - 100) { y = geopoint.map.getSize().height - 100 }
            var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(x,y));
            pos.apply(geopoint.contextmenu);
            geopoint.contextmenu.style.visibility = "visible";
        },


        loadMap : function(mapObject) {
            geopoint.map = mapObject;
        },


        /**
        * Initialisation de la carte
        * @param decimal _lt Latitude centre
        * @param decimal _lg longitude centre
        * @param decimal _zoom Niveau de zoom
        * @return GMarker
        */
        initMapsForView : function(_lt, _lg, _zoom) {
            geopoint.infoMap = new Array(_lt, _lg, _zoom);
            if (geopoint.infoMap != null && geopoint.initialisedMap == false) {
                geopoint.loadForDisplay();
            }
        },


        /**
        * Chargement de la map pour une edition
        * @return void
        */
        loadForDisplay : function() {
            if (GBrowserIsCompatible()) {

				lt = geopoint.infoMap[0];
                lg = geopoint.infoMap[1];
                zoom = geopoint.infoMap[2]

                geopoint.map = new GMap2(document.getElementById('geopoint_map'));
                geopoint.map.setCenter(new GLatLng(lt, lg), zoom);
                // passŽ dans le geoMap.classs.php
                // geopoint.map.addControl(new GLargeMapControl());
                geopoint.map.addControl(new GHierarchicalMapTypeControl());

				geopoint.map.addMapType(geopoint.getMapType());
                geopoint.map.setMapType(geopoint.getMapType());
				
				geopoint.geocoder	= new GClientGeocoder();
            }
            geopoint.initialisedMap = true;
        },

        /**
        * Chargement de la map pour une edition
        * @return void
        */
        loadForEdition : function() {
            if (GBrowserIsCompatible()) {

                lt = geopoint.infoMap[0];
                lg = geopoint.infoMap[1];
                zoom = geopoint.infoMap[2]

                geopoint.map = new GMap2(document.getElementById('geopoint_map'));
                geopoint.map.setCenter(new GLatLng(lt, lg), zoom);

                geopoint.inputLongitude = document.getElementById('geopoint_lg');
                geopoint.inputLatitude = document.getElementById('geopoint_lt');

                geopoint.map.addControl(new GLargeMapControl());
                geopoint.map.addControl(new GHierarchicalMapTypeControl());
                geopoint.map.addMapType(geopoint.getMapType());
                geopoint.map.setMapType(geopoint.getMapType()); // G_HYBRID_MAP);
				
				geopoint.geocoder	= new GClientGeocoder();

                // Context Menu
                geopoint.contextmenu = document.createElement('div');
                geopoint.contextmenu.className = 'geoPointContextDroit';
                geopoint.contextmenu.style.visibility = 'hidden';
                geopoint.contextmenu.innerHTML =  ''
                        + 	'<a href="javascript:void(0);" onclick="geopoint.createMarkerHere()">Cr&eacute;er un point ici</a>'
                        +	'<a href="javascript:void(0);" onclick="geopoint.zoomIn()">Zoom avant</a>'
                        +	'<a href="javascript:void(0);" onclick="geopoint.zoomOut()">Zoom arri&egrave;re</a>'
                        + 	'<hr><a href="javascript:void(0);" onclick="geopoint.centreMapHere()">Centrer ici</a>'
                        +	'<a href="javascript:void(0);" onclick="geopoint.initToolbar()">Initialiser menu</a>';
                geopoint.map.getContainer().appendChild(geopoint.contextmenu);


                GEvent.addListener(geopoint.map, "singlerightclick", function(pixel, tile) {
                    geopoint.showContextMenu(pixel, tile);
                });

                GEvent.addListener(geopoint.map, "click", function() {
                    geopoint.hideContextMenu();
                });

                // Desactivation du formulaore
                cInput = document.getElementById(geopoint.form_id).getElementsByTagName('input');
                for (i=0; cInput[i]; i++) {
                    if (cInput[i].id && cInput[i].id != '' && cInput[i].id.substring(0, 9) == 'geopoint_') {
                        GEvent.addDomListener(cInput[i], "focus", function() {geopoint.form_stop_submit = true});
                    } else {
                        GEvent.addDomListener(cInput[i], "focus", function() {geopoint.form_stop_submit = false});
                        if (cInput[i].getAttribute('type') == 'submit') {
                            GEvent.addDomListener(cInput[i], "click", function() {geopoint.form_stop_submit = false});
                        }
                    }
                    switch (cInput[i].id) {
                        case 'geopoint_lg' :
                        case 'geopoint_lt' :
                            cInput[i].setAttribute('autocomplete', 'off');
                            GEvent.addDomListener(cInput[i], "keydown", function(e) {
                                geopoint.form_stop_submit = true;
                                switch (e.keyCode) {
                                    case 13 :
                                        lt = geopoint.inputLatitude.value;
                                        lg = geopoint.inputLongitude.value;
                                        geopoint.getPlace(lt, lg, true);
                                        return false; // tab
                                }
                            });
                            break;

                        case 'geopoint_adresse' :
                            cInput[i].setAttribute('autocomplete', 'off');
                            GEvent.addDomListener(cInput[i], "keydown", function(e) {
                                geopoint.form_stop_submit = true;
                                switch (e.keyCode) {
                                    case 13 :
                                        geopoint.trouverAdresse();
                                        return false; // tab
                                }
                            });
                            break;

                        case 'geopoint_place' :
                            cInput[i].setAttribute('autocomplete', 'off');
                            break;
                    }
                }

                // Evenement Placer des coordonnée GPS
                GEvent.addDomListener(document.getElementById('geopoint_placer'), "click", function() {
                    lt = geopoint.toDecimals(geopoint.inputLatitude.value);
                    lg = geopoint.toDecimals(geopoint.inputLongitude.value);

                    geopoint.getPlace(lt, lg, true);
                });

                // Evenement Cherche une adresse
                GEvent.addDomListener(document.getElementById('geopoint_chercher'), "click", geopoint.trouverAdresse);

                // Evenement Changement de pays
                GEvent.addDomListener(document.getElementById('geopoint_pays'), "change", geopoint.changerPays);
            }

            geopoint.initialisedMap = true;
        },

        /**
        * @return integer
        */
        toDecimals : function (point) {
            deg_position = point.indexOf('º');
            if (deg_position > 0)
            {
                min_position = point.indexOf("'");
                degrees					= point.substr(0,deg_position)  / 1;
                if (min_position > 0)
                {
                    minutes				= point.substr(deg_position + 1, min_position - deg_position - 1) ;
                }
                else
                {
                    minutes				= point.substr(deg_position + 1);
                }

                if (degrees < 0)
                {
                    minutes				= -1 * minutes;
                }
                point					= degrees + (minutes / 60);
            }
            return point  / 1;
        },

        toMinutes : function (point) {
            degrees						= Math.floor(point);
            minutes						= (point - Math.floor(point)) * 60;
            point						= degrees + 'º ' + minutes + "'";
            return point / 1;
        },


        /**
        * Cacher le menu contextuel
        * @return void
        */
        hideContextMenu : function () {
            geopoint.contextmenu.style.visibility = "hidden";
        },

        /**
        * Zoom in
        * @return void
        */
        zoomIn : function () {
            geopoint.map.zoomIn();
            geopoint.hideContextMenu();
        },

        /**
        * Zoom out
        * @return void
        */
        zoomOut : function () {
            geopoint.map.zoomOut();
            geopoint.hideContextMenu();
        },

        /**
        * Centrer la carte sur le pixel courant
        * @return void
        */
        centreMapHere : function () {
            var point = geopoint.map.fromContainerPixelToLatLng(geopoint.clickedPixel);
            geopoint.map.setCenter(point, geopoint.map.getZoom());
            geopoint.hideContextMenu();
        },

        /**
        * Centrer la carte sur le point principal (ou sinon 1er secondaire ou sinon 1er parcours)
        * @return void
        */
        centerPrincipal : function() {
            if (geopoint.marker_principal != null) {
                geopoint.map.setCenter(geopoint.marker_principal.getPoint(), geopoint.map.getZoom());
            } else if (marker_secondaire[0]) {
                geopoint.map.setCenter(geopoint.marker_secondaire[0].getPoint(), geopoint.map.getZoom());
            } else if (marker_polyline[0]) {
                geopoint.map.setCenter(geopoint.marker_polyline[0].getPoint(), geopoint.map.getZoom());
            }
        },

        /**
        * Création d'un marqueur sur le pixel courant
        * @return void
        */
        createMarkerHere : function () {
            var point = geopoint.map.fromContainerPixelToLatLng(geopoint.clickedPixel);
            tmpMarker = geopoint.createMarkerEdition(point, '')
            geopoint.hideContextMenu();
        },

        /**
        * Création d'un marqueur avec un zoom spécifique
        * @param double lt latitude
        * @param double lg longitude
        * @param int zoom Zoom (optionel)
        * @return void
        */
        setPlace : function(lt, lg, zoom) {
            if (zoom) {
                geopoint.map.setZoom(zoom)
            }
            geopoint.getPlace(lt, lg, false);
        },

        /**
        * Création d'un marqueur ou déplacement de la carte en un point préci
        * @param double lt latitude
        * @param double lg longitude
        * @param boolean create (si true création d'un marqueur)
        * @return void
        */
        getPlace : function(lt, lg, create) {

            if (lt == '' || isNaN(lt) || lt > 85 || lt < -85) {
                alert('Votre point gps n\'a pas &eacute;t&eacute; reconnu');
                geopoint.inputLatitude.focus();
                geopoint.inputLatitude.select();
            } else if (lg == '' || isNaN(lg) || lg > 180 || lt < -180) {
                alert('Votre point gps n\'a pas &eacute;t&eacute; reconnu');
                geopoint.inputLongitude.focus();
                geopoint.inputLongitude.select();
            } else {
                point = new GLatLng(lt, lg);
                if (create) {
                    tmpMarker = geopoint.createMarkerEdition(point);
                }
                geopoint.map.setCenter(point, geopoint.map.getZoom());
            }
        },

        /**
        * Chargement des markeurs depuis XML
        * @param varchar url Url du XML
        * @return void
        */
        loadMarkerTypes : function(url)
        {
            GDownloadUrl(url, function(data)
            {
                var xml 		= GXml.parse(data);
                var markers 	= xml.documentElement.getElementsByTagName('marker');
                var images	 	= xml.documentElement.getElementsByTagName('image');
                var shadows 	= xml.documentElement.getElementsByTagName('shadow');
                for (var i = 0; i < markers.length; i++)
                {
                    var type					= markers[i].getAttribute('type');
                    var anchor_x				= markers[i].getAttribute('anchor_x');
                    var anchor_y				= markers[i].getAttribute('anchor_y');
                    var info_anchor_x			= markers[i].getAttribute('info_anchor_x');
                    var info_anchor_y			= markers[i].getAttribute('info_anchor_y');
                    var size_w					= markers[i].getAttribute('width');
                    var size_h					= markers[i].getAttribute('height');

                    _icon 						= new GIcon();
                    _icon.iconAnchor 			= new GPoint(anchor_x, anchor_y);
                    _icon.iconSize 				= new GSize(size_w, size_h)
                    _icon.image					= GXml.value(images[i]);
                    _icon.shadow 				= GXml.value(shadows[i]);

                    geopoint.markers_i_anchors[type]		= new Array(info_anchor_x, info_anchor_y);
                    geopoint.marker_types[type]				= _icon;
                }
                if (geopoint.xml_loaded)
                {
                    geopoint.markers_placed				= new Array();
                    geopoint.markerGroups				= new Array();
                    geopoint.refreshXMLPoints();
                }
            });
        },

        /**
        * Initialisation du chargement des données depuis XML
        * @param varchar path Chemin du module courant (exple '/blogs/')
        * @param form_id identifiant du formulaire (pour bloquer le submit)
        * @return void
        */
        initXML : function(path, form_id) {
            geopoint.path 				=	path;
            geopoint.form_id 			=	form_id;
            geopoint.loadMarkerTypes(geopoint.path + 'markers.php');

            GEvent.addDomListener(geopoint.map, 'moveend', geopoint.refreshXMLPoints);
            geopoint.pointsFromXml();
        },

        refreshXMLPoints : function()
        {
            if (geopoint.timer)
            {
                clearTimeout(geopoint.timer);
            }
            $('#map_html_loading').show();
            geopoint.timer = setTimeout("geopoint.pointsFromXml()",800);
        },

        addXMLArgument : function(argument, value)
        {
            geopoint.xml_args[argument]		= value;
        },

        selectObjectType : function(objectType, select)
        {
            geopoint.object_types[objectType]	= select;
            if (!geopoint.markerGroups[objectType])
            {
                geopoint.markerGroups[objectType]	=  new Array();
            }

            for (var i = 0; i < geopoint.markerGroups[objectType].length; i++)
            {
                var marker = geopoint.markerGroups[objectType][i];
                if (select == true)
                {
                    marker.show();
                }
                else
                {
                    marker.hide();
                }
            }
        },


        pointsFromXml : function()
        {
            $('#map_html').empty();
						
            var bounds			= geopoint.map.getBounds();
            var searchUrl 		= geopoint.path + 'xml.php?SWLat=' + bounds.getSouthWest().lat() + '&SWLng=' + bounds.getSouthWest().lng() + '&NELat=' + bounds.getNorthEast().lat() + '&NELng=' + bounds.getNorthEast().lng() + '&ZoomLevel=' + geopoint.map.getZoom();
            for (var key in geopoint.xml_args) {
                searchUrl		+= '&' + key + '=' +  geopoint.xml_args[key];
            }
            for (var key in geopoint.object_types) {
                if (geopoint.object_types[key])
                {
                    searchUrl		+= '&ObjectTypes[]=' +  key;
                }
            }
	
            GDownloadUrl(searchUrl, function(data)
            {
                geopoint.xml_loaded	= true;
                var xml 		= GXml.parse(data);
				var options		= xml.documentElement.getElementsByTagName('options');
                var markers 	= xml.documentElement.getElementsByTagName('marker');
                var teasers		= xml.documentElement.getElementsByTagName('teaser');
                var titles		= xml.documentElement.getElementsByTagName('title');
				
				if(options[0] != null)
				{
					var tmpZoomMode	= options[0].getAttribute('zoom_mode');
					// Pour pas que les marqueurs des autres de zoom restent affichŽs dans l'affichage multiZoom
					if(tmpZoomMode != geopoint.zoom_mode)
					{
						geopoint.zoom_mode = tmpZoomMode;
						geopoint.displayMarkers();
						geopoint.markers_placed = new Array();					
					}
				}
				
                for (var i = 0; i < markers.length; i++)
                {
                    var id = markers[i].getAttribute('id');
                    var html = GXml.value(teasers[i]);

                    if (i < 6)
                    {
                        $('#map_html').append(html);
                    }
                    if (!geopoint.markers_placed[id])
                    {
                        geopoint.markers_placed[id]	= true;
                        var title = GXml.value(titles[i]);
                        var type = markers[i].getAttribute('type');
						
						// Pour les marker dont les parametre ne sont pas dans la classe geoMap.class mais passŽ en xml
						if(type == 'other')
						{
							type			= new Array();
							type["image"]	= markers[i].getAttribute('image');
							type["shadow"]	= markers[i].getAttribute('shadow');
							type["anchor_x"]= markers[i].getAttribute('anchor_x');
							type["anchor_y"]= markers[i].getAttribute('anchor_y');
							type["width"]	= markers[i].getAttribute('width');
							type["height"]	= markers[i].getAttribute('height');
						}
						
                        var point = new GLatLng(parseFloat(markers[i].getAttribute('lat')),
                                                parseFloat(markers[i].getAttribute('lng')));
                        var marker = geopoint.createMarker(type, point, title, html);
                        if (geopoint.markerGroups[type])
                        {
                            geopoint.markerGroups[type].push(marker);
                        }
                        geopoint.map.addOverlay(marker);
                    }
                }
            });
            $('#map_html_loading').hide();
        },

        createMarker : function(type, point, title, html)
        {
			if (type.constructor == Array)
			{
				icon = new GIcon();
                icon.image = type["image"];
                icon.shadow = type["shadow"];
                icon.iconAnchor = new GPoint(type["anchor_x"],type["anchor_y"]);
                icon.iconSize = new GSize(type["width"],type["height"]);
			}
            else if (geopoint.marker_types[type])
            {
                icon = geopoint.marker_types[type];
            }
            else
            {
                icon = new GIcon();
                icon.image = '/c/i/maps/i-general.png';
                icon.shadow = '/c/i/maps/i-shadow.png';
                icon.iconAnchor = new GPoint(8,16);
                icon.iconSize = new GSize(24,16);
            }
            icon.infoWindowAnchor = new GPoint(16,16);

            var marker = new GMarker(point, {icon: icon, title: title});
            GEvent.addListener(marker, 'click', function()
            {
				if( !geopoint.hasInformations(html) )
				{
					if(geopoint.zoom_mode == 'country')
					{
						var delta_zoom	= 1;
					}
					else if(geopoint.zoom_mode == 'mountainRegion')
					{
						var delta_zoom	= 2;
					}
					geopoint.map.setZoom(geopoint.map.getZoom()+delta_zoom);
					geopoint.map.panTo(point);
				}
				else
				{
					marker.openInfoWindowHtml(html, {maxWidth:400});
				}
            });
            return marker;
        },





        /**
        * Initialisation du moteur de recherchde
        * @param varchar path Chemin du module courant (exple '/blogs/')
        * @param form_id identifiant du formulaire (pour bloquer le submit)
        * @return void
        */
        initSearchEngine : function(path, form_id) {

            geopoint.path 				=	path;
            geopoint.form_id 			=	form_id;
            geopoint.pay_code_init 		=	'';

            geopoint.input_region 		=	document.getElementById('geopoint_region');
            geopoint.input_pays 		= 	document.getElementById('geopoint_pays');
            geopoint.input_place 		=	document.getElementById('geopoint_place');
            geopoint.div_place_liste 	=	document.getElementById('geopoint_place_liste');

            // Ajout Evenement
            // Gestion changement de région
            GEvent.addDomListener(geopoint.input_region, 'change', geopoint.changeRegion);
            // Gestion changement de pays
            GEvent.addDomListener(geopoint.input_pays, 'change', geopoint.changerPays);
            // Gestion sélection de Place
            GEvent.addDomListener(geopoint.input_place, 'keyup', geopoint.placeListener);
            GEvent.addDomListener(geopoint.input_place, 'keydown', function(e) {
                geopoint.form_stop_submit = true;
                if (geopoint.div_place_liste.style.display == 'block') {
                    switch (e.keyCode) {
                        case 13 :
                        var nTr = YAHOO.util.Dom.getElementsByClassName('selected', 'tr', geopoint.div_place_liste)[0];
                        if (nTr) {
                            geopoint.input_place.value = nTr.firstChild.firstChild.nodeValue;
                            var re = new RegExp('coor_([^_]*)_+(.*)');
                            if (m = re.exec(nTr.id)) {
                                geopoint.setPlace(m[1], m[2], 12);
                            }
                            geopoint.fermerListe();
                        }
                    }
                }
            });


            // Gestion désactivation du formulaire
            GEvent.addDomListener(document.getElementById(geopoint.form_id), "submit", function(e) {
                if (geopoint.form_stop_submit) {
                    YAHOO.util.Event.stopEvent(e);}
                }
            );

            geopoint.changerPays();
        },


        /**
        * Action pour trouver une adresse (GEOCODER) : centrer carte
        * @return void
        */
        trouverAdresse : function() {
            var geocoder = new GClientGeocoder();
            if (geocoder) {
                adresse = document.getElementById('geopoint_adresse').value;
                geocoder.getLocations(adresse, function(response) {
                    if (!response || response.Status.code != 200) {
                        alert('Impossible de localiser cette adresse');
                    } else {
                        place = response.Placemark[0];
                        point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
                        geopoint.map.setCenter(point, geopoint.map.getZoom());
                        geopoint.createMarkerEdition(point,  null, null, 1);
                        geopoint.markertype_over(1);
                    }
                });
            }
            return false;
        },

        /**
        * Action aprés changement d'un pays (GEOCODER) : centrer carte
        * @return void
        */
        changerPays : function() {
            geopoint.fermerListe();

            if (geopoint.input_pays.value == 0) {
                geopoint.input_place.style.visibility = 'hidden';
            } else {
                geopoint.input_place.style.visibility = 'visible';

                var geocoder = new GClientGeocoder();
                if (geocoder) {
                    oCountry = document.getElementById('geopoint_pays');
                    cou_libelle = oCountry.options[oCountry.selectedIndex].text;
                    tmp = cou_libelle.split('(');
                    cou_search =tmp[0];
                    cou_code = oCountry.options[oCountry.selectedIndex].value;
                if (cou_code != '' && cou_code != '0') {
                        geocoder.getLocations(cou_search, function(response) {
                            if (response && response.Status.code == 200) {
                                place = response.Placemark[0];
                                point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
                                geopoint.map.setCenter(point, 5);
                            }
                        });
                    }
                }
            }
            return false;
        },

        /**
        * Action aprés changement d'une region (AJAX)
        * @return void
        */
        changeRegion : function() {
            region_id = geopoint.input_region.value;
            if (geopoint.country_cache[region_id]) {
                geopoint.populateCountry(geopoint.country_cache[region_id]);
            } else {
                sPost = 'action=get_pays_de_region&region_id=' + region_id;
                geopoint.oHTTP = geopoint.getHTTPObject();
                if (geopoint.oHTTP) {
                    geopoint.oHTTP.onreadystatechange = geopoint.retourChangeRegion;
                    geopoint.oHTTP.open("POST", geopoint.path + 'xml.php', true); // ouverture asynchrone
                    geopoint.oHTTP.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
                    geopoint.oHTTP.send(sPost);
                }
            }
        },

        /**
        * Action aprés changement d'une region (Retour AJAX)
        * @return void
        */
        retourChangeRegion : function() {
            if (!geopoint) return false;
            if (geopoint.oHTTP.readyState != 4 || geopoint.oHTTP.status != 200) return false;

            region_id = geopoint.input_region.value;
            geopoint.country_cache[region_id] = geopoint.oHTTP.responseText;
            geopoint.populateCountry(geopoint.country_cache[region_id]);
            geopoint.changerPays();
        },

        /**
        * Créer la bonne liste de pays
        *	@param varchar txt donnée pour crée la liste de pays sou la forme : INITIALES[tab]LIBELLE[tab]CODE@@@INITIALES[tab]LIBELLE[tab]CODE@@....
        * 	@return void
        */
        populateCountry : function(txt) {

            // Suppression existant
            while (geopoint.input_pays.firstChild) {
                geopoint.input_pays.removeChild(geopoint.input_pays.firstChild);
            }

            aReturn = txt.split('@@@');
            if (aReturn != '') {
                labelOptGroup = '';
                objOptGroup = document.createElement('optgroup');
                for (var i=0; aReturn[i]; i++) {
                    aTmp = aReturn[i].split('\t');
                    if (labelOptGroup != aTmp[0]) {
                        if (i > 0) {
                            objOptGroup.setAttribute('label', labelOptGroup);
                            geopoint.input_pays.appendChild(objOptGroup);

                            objOptGroup = document.createElement('optgroup');
                            objOptGroup.setAttribute('label', aTmp[0]);
                        }
                        labelOptGroup = aTmp[0];
                    }

                    objOption = document.createElement('option');
                    objOption.value = aTmp[2];
                    objOption.innerText = aTmp[1]; // IE
                    objOption.text = aTmp[1]; // MOZ
                    objOptGroup.appendChild(objOption);
                }
                geopoint.input_pays.appendChild(objOptGroup);
            } else {
            geopoint.input_pays.options[0] = new Option('---------------------------', '0');
            }

            if (geopoint.pay_code_init != '') {
                cOp = geopoint.input_pays.getElementsByTagName('option');
                pay_code = geopoint.pay_code_init;
                geopoint.pay_code_init = '';
                for (i=0;cOp[i];i++) {
                    if (cOp[i].value == pay_code) {
                        cOp[i].selected = true;
                        break;
                    }
                }
            }
        },

        /**
        * Action lors de la recherche d'une "place" (KeyUp)
        * @return void
        */
        placeListener : function(E) {

            switch (E.keyCode) {
                case 9 : // tab
                case 37 :  // fleche gauche
                case 39 :  // fleche droite
                    return;
                case 13 : // entrer
                    return;
                case 27 : // echap
                    geopoint.fermerListe();
                    return;
                case 38 : // fleche haut
                    var nTr = YAHOO.util.Dom.getElementsByClassName('selected', 'tr',  geopoint.div_place_liste)[0];
                    if (!nTr || !nTr.previousSibling) {
                        return;
                    }
                    nTr.className = '';
                    nTr = nTr.previousSibling;
                    nTr.className = 'selected';
                    geopoint.input_place.value = nTr.firstChild.firstChild.nodeValue;

                    if (!nTr.previousSibling && geopoint.tabUp.firstChild) {
                        geopoint.tabDown.insertBefore(nTr.parentNode.lastChild, geopoint.tabDown.firstChild);
                        nTr.parentNode.insertBefore(geopoint.tabUp.lastChild, nTr.parentNode.firstChild);
                    }
                    return;
                case 40 : // fleche bas
                    geopoint.afficherListe();
                    var nTr = YAHOO.util.Dom.getElementsByClassName('selected', 'tr', geopoint.div_place_liste)[0];
                    if (nTr) {
                        if (!nTr.nextSibling) {
                            return;
                        }
                        nTr.className = '';
                        nTr = nTr.nextSibling;
                    } else {
                        nTr = geopoint.div_place_liste.firstChild; //le tableau
                        if (!nTr || !nTr.firstChild) return;
                        nTr = nTr.firstChild.nextSibling.firstChild;
                    }
                    nTr.className = 'selected';
                    geopoint.input_place.value = nTr.firstChild.firstChild.nodeValue;
                    if (!nTr.nextSibling && geopoint.tabDown.firstChild) {
                        geopoint.tabUp.appendChild(nTr.parentNode.firstChild);
                        nTr.parentNode.appendChild(geopoint.tabDown.firstChild);
                    }
                    return;
                default :
                    break;
            }

            check_last_search = geopoint.input_pays.value + '|' +  geopoint.input_place.value;
            if (geopoint.place_last_search == check_last_search) {
                return;
            }

            clearTimeout(geopoint.timerPlaceListener);
            geopoint.timerPlaceListener = window.setTimeout(function() {geopoint.placeSearch(E)}, 500);
        },

        /**
        * Fonction de nettoyage d'une chaine de caractère on enleve les accents)
        * @param varchar str Chaine à nettoyer
        * @return varchar
        */
        cleanTxt : function(str) {

            str = str.toLowerCase();
            str = str.replace(new RegExp('[àâäá]', 'g'), 'a');
            str = str.replace(new RegExp('[êëéè]', 'g'), 'e');
            str = str.replace(new RegExp('[îïí]', 'g'), 'i');
            str = str.replace(new RegExp('[ôöó]', 'g'), 'o');
            str = str.replace(new RegExp('[ùûü]', 'g'), 'u');
            str = str.replace(new RegExp('[ñ]', 'g'), 'n');
            str = str.replace(new RegExp('[ç]', 'g'), 'c');
            return str;
        },

        /**
        * Action lors de la recherche d'une "place" (AJAX)
        * @return void
        */
        placeSearch : function(E) {
            if (geopoint.input_place.value.length < 2) {
                geopoint.fermerListe();
                return;
            }
            place_txt = geopoint.cleanTxt(geopoint.input_place.value);
            geopoint.place_last_search = geopoint.input_pays.value + '|' +  place_txt;
            if (geopoint.place_cache[geopoint.place_last_search]) {
                geopoint.populatePlace(geopoint.place_cache[geopoint.place_last_search]);
            } else {
                region_id = geopoint.input_region.value;
                pays_code = geopoint.input_pays.value;
                sPost = 'action=get_place_liste&region_id=' + region_id + '&pays_code=' + pays_code + '&place_txt=' + place_txt;
                geopoint.oHTTP = geopoint.getHTTPObject();
                if (geopoint.oHTTP) {
                    geopoint.oHTTP.onreadystatechange = geopoint.retourPlaceListener;
                    geopoint.oHTTP.open("POST", geopoint.path + 'xml.php', true); // ouverture asynchrone
                    geopoint.oHTTP.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
                    geopoint.oHTTP.send(sPost);
                }
            }
        },

        /**
        * Action lors de la recherche d'une "place" (AJAX retour)
        * @return void
        */
        retourPlaceListener : function() {
            if (geopoint.oHTTP.readyState != 4 || geopoint.oHTTP.status != 200) return false;

            check_last_search = geopoint.input_pays.value + '|' +  geopoint.cleanTxt(geopoint.input_place.value);
            geopoint.place_cache[check_last_search] = geopoint.oHTTP.responseText;
            geopoint.populatePlace(geopoint.place_cache[geopoint.place_last_search]);
        },

        /**
        * Création de la liste de "place"
        * @return void
        */
        populatePlace : function(aTXT) {

            nDiv = geopoint.setDivTemp(aTXT);
            var rech_libre_liste = geopoint.div_place_liste;
            while (rech_libre_liste.firstChild) {
                rech_libre_liste.removeChild(rech_libre_liste.firstChild);
            }

            var tabTemp = nDiv.getElementsByTagName('table')[0];
            if (!tabTemp || tabTemp.rows.length == 0) return;

            geopoint.afficherListe();

            var table = document.createElement('table');
            rech_libre_liste.appendChild(table);
            var thead = document.createElement('thead');
            table.appendChild(thead);
            var tbody = document.createElement('tbody');
            table.appendChild(tbody);
            var tfoot = document.createElement('tfoot');
            table.appendChild(tfoot);

            geopoint.tabDown = document.createElement('table');
            geopoint.tabUp = document.createElement('table');

            var cTr = tabTemp.getElementsByTagName('tr');
            for (i=0; cTr[i]; i++) {

                GEvent.addDomListener(cTr[i], "click", function () {
                    geopoint.input_place.value = this.firstChild.firstChild.nodeValue;
                    var re = new RegExp('coor_([^_]*)_+(.*)');
                    if (m = re.exec(this.id)) {
                        geopoint.setPlace(m[1], m[2], 12);
                    }
                    geopoint.fermerListe();
                });

                GEvent.addDomListener(cTr[i], "mouseover", function () {
                    var cTr2 = YAHOO.util.Dom.getElementsByClassName('selected', 'tr', geopoint.div_place_liste);
                    var i = 0;
                    while (cTr2[i]) {
                        cTr2[i++].className = '';
                    }
                    this.className = 'selected';
                });
            }

            var cpt = 0;
            while (tabTemp.rows.length>0) {
                if (cpt < 15)
                    tbody.appendChild(tabTemp.rows[0]);
                else
                    geopoint.tabDown.appendChild(tabTemp.rows[0]);
                cpt++;
            }

        },

        /**
        * Cacher la liste de "place"
        * @return void
        */
        fermerListe : function() {
            if (geopoint.input_place.style.display == 'block') {
                geopoint.input_place.focus();
            }
            geopoint.div_place_liste.style.display = 'none';

        },

        /**
        * Afficher la liste de "place"
        * @return void
        */
        afficherListe : function () {
            if (geopoint.div_place_liste.style.display == 'none') {
                geopoint.div_place_liste.style.display = 'block';
                geopoint.form_stop_submit = true;
                return true;
            }
            return false;
        },

        /**
        * Création d'un élèment temporaire pour la création de la liste de "place"
        * @return void
        */
        setDivTemp : function (txt) {
            var nDiv = document.getElementById('geopoint_div_temp');
            if (!nDiv) {
                nDiv = document.createElement('div');
                nDiv.id = 'geopoint_div_temp';
            }
            nDiv.innerHTML = txt;
            return nDiv;
        },

        /**
        * Création OBJECT ajax
        * @return XMLHttpRequest
        */
        getHTTPObject : function() {
            var xmlhttp = false;
            /* Compilation conditionnelle d'IE */
            /*@cc_on
            @if (@_jscript_version >= 5)
                try {
                    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
                } catch (e) {
                    try {
                        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                    } catch (ex2) {
                xmlhttp = false;
                }
            }
            @else
                xmlhttp = false;
            @end @*/
            /* on essaie de créer l'objet si ce n'est pas déjà  fait */
            if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
                try {
                    xmlhttp = new XMLHttpRequest();
                } catch (e) {
                    xmlhttp = false;
                }
            }
            return xmlhttp;
        },
		
		/**
		* Cadre la carte sur les points suivant
		*/
		setMapBounds : function(northLat, eastLng, southLat, westLng) {
			var bounds	= new GLatLngBounds();

			bounds.extend( new GLatLng(southLat, westLng));
			bounds.extend( new GLatLng(northLat, eastLng));
			
			geopoint.map.setZoom(geopoint.map.getBoundsZoomLevel(bounds));
			geopoint.map.setCenter(bounds.getCenter());
		},
		
		/**
		 * Permet de savoir si l'info bulle est renseignŽe
		 * renseignŽe pour savoir si le marker est un pays/region ou un point d'interet
		 */
		hasInformations : function(html) {
			if(html.length == 0)
			{
				return false;
			}
			else
			{
				return true;
			}
		},
		
		moveToAddress : function(address) {
		   if (geopoint.geocoder) {
		        geopoint.geocoder.getLatLng(
				    address,
				    function(point) {
				        if (!point) {
				          alert(address + " introuvable");
				        } else {
				          geopoint.map.panTo(point);
				        }
				    }
			    );
		    }
	    },
		
		getMapType : function() {
		
			return (geopoint.map_type == null) ? G_PHYSICAL_MAP : geopoint.map_type;
		},
		
		setMapType : function(maptype) {
	
			if(maptype == undefined)
			{
				maptype = G_PHYSICAL_MAP;
			}
		    switch(maptype)
			{
			    case'plan':			maptype	= G_NORMAL_MAP;
									break;
				case'satellite':	maptype	= G_SATELLITE_MAP
									break;
				case'hybrid':		maptype	= G_HYBRID_MAP
									break;
				default:			maptype	= G_PHYSICAL_MAP;
									break;
			}
			geopoint.map_type		= maptype;
		}
    };
//]]>
