var largeur_chemin=10;
var tab_points=new Array();
var tab_polygone_detail=new Array();
var tab_points_polygone=new Array();
var tab_instruction=new Array();
var tab_point_form=new Array();
var tab_coordonnees=new Array();
var tab_touristique=new Array();
var tab_photo=new Array();
var tab_ville=new Array();
var cpt_point_commentaire=-1;
var cpt_id;
var marker_repere;
var polygon;
var point_polygone_detail;
var tab_color=new Array();
var cpt_color=0;
var couleur_segment='#ff0000';
var opacity=0.5;
var zoom_ok=0;

var assistant_etape_2='<span>2</span> - Cliquez sur la carte pour placer le départ de votre itinéraire';
var assistant_etape_3='<span>3</span> - Cliquez sur la carte pour placer les étapes successives de votre itinéraire<br /> - Les points peuvent être déplacés par glisser-déposer';
var assistant_etape_4='<span>4</span> - Cliquez sur la carte pour placer les étapes successives de votre itinéraire<br /> - Cliquer sur un segment de l\'itinéraire pour insérer un point<br /> - Clic droit sur un point pour le supprimer';
var assistant_etape_5='<span>5</span> - Une fois votre itinéraire terminé cliquez sur un point pour renseigner les instructions, les commentaires ou d\'eventuelles photos pour ce dernier<br /> - Une fois vos points terminé renseigner le nom de ce dernier, la durée, une description générale ainsi que les différents critères, puis enregistrez';

var flag_dessine_chemin_ok=0;

var cpt_color_rempli=0;
var h=new Array('00','33','66','99','CC','FF');
var col=""; 
for(var i=0;i<6;i=i+2) 
{ 
	for(var j=0;j<6;j=j+2) 
	{ 
		for(var k=0;k<6;k=k+2)
		{ 
			tab_color[cpt_color_rempli]="#"+h[i]+h[j]+h[k];
			cpt_color_rempli++;
		}
	}
}
function efface_chemin(map)
{
	if(tab_points.length>=2)
	{
		for(var cpt_points=0;cpt_points<tab_points.length-1;cpt_points++)
		{
			GEvent.clearListeners(tab_points[cpt_points].polyline,"click");
			map.removeOverlay(tab_points[cpt_points].polyline);
		}
	}
}
function dessine_chemin(map)
{
	var distance=0;
	flag_dessine_chemin_ok=1;
	if(tab_points.length>=2)
	{
		for(var cpt_points=0;cpt_points<tab_points.length-1;cpt_points++)
		{
			if(document.getElementById('aff_itineraire').value==1)
			{
				/*-----------------------------------------------------------
						RECHERCHE D'INSTRUCTION POUR CHANGEMENT DE COULEUR
				-----------------------------------------------------------*/
				if(document.getElementById('point_commentaire').value.length)
				{
					tab_instruction_tmp=explode(",",document.getElementById('point_commentaire').value);
					for(cpt_instruction=0;cpt_instruction<count(tab_instruction_tmp);cpt_instruction++)
					{
						tab_instruction[cpt_instruction]=str_replace("|",",",tab_instruction_tmp[cpt_instruction]);
					}
				}
				if(tab_instruction[cpt_points])
				{
					if(couleur_segment=='#ff0000')
						couleur_segment='#0000ff';
					else
						couleur_segment='#ff0000';
				}
				/*-----------------------------------------------------------
						FIN RECHERCHE D'INSTRUCTION POUR CHANGEMENT DE COULEUR
				-----------------------------------------------------------*/			
				if(document.getElementById('point_ville').value.length)
				{
					tab_ville=explode(",",document.getElementById('point_ville').value);
				}
				if(tab_ville[cpt_points])
				{
					if(tab_ville[cpt_points]==1)
						opacity=0;
					else
						opacity=0.5;
				}
			}
			tab_points[cpt_points].polyline=new GPolyline(new Array(tab_points[cpt_points].point,tab_points[cpt_points+1].point),couleur_segment,largeur_chemin,opacity);
			tab_points[cpt_points].polyline.cpt_point_depart=cpt_points;
			map.addOverlay(tab_points[cpt_points].polyline);
			distance=distance+distance_entre_2_point(tab_points[cpt_points].point,tab_points[cpt_points+1].point);
			if(document.getElementById("aff_itineraire_distance"))
				document.getElementById("aff_itineraire_distance").innerHTML=Math.round(distance/1000)+' KM';
			GEvent.addListener(tab_points[cpt_points].polyline,"click",function(point)
			{
				if(point&&document.getElementById('aff_itineraire').value==0)
				{
					add_point(map,point,this.cpt_point_depart,'new'+cpt_id++,0,1,0);
				}
			});		
		}
	}
}
function dessine_polygon(map,cpt_txt_polygone)
{
	if(tab_points_polygone.length>=3)
	{
		var tab_polygon=new Array();
		for(var cpt_points=0;cpt_points<tab_points_polygone.length;cpt_points++)
		{	
			tab_polygon[cpt_points]=tab_points_polygone[cpt_points].point;
		}
		if(!document.getElementById('point_polygone'))
		{
			if(polygon)
				map.removeOverlay(polygon);
		}
		
		polygon=new GPolygon(tab_polygon,tab_color[cpt_color],5,0.5,tab_color[cpt_color],0.3);
		map.addOverlay(polygon);
		if(document.getElementById('texte_polygone'))
		{
			legende_polygone2='';
			tab_polygone_tmp2=explode("|",point_polygone_detail);
			for(cpt_polygone2=0;cpt_polygone2<count(tab_polygone_tmp2);cpt_polygone2++)
			{
				tab_polygone_detail_polygone2=explode(';',tab_polygone_tmp2[cpt_polygone2]);
				legende_polygone2=legende_polygone2+tab_polygone_detail_polygone2[0]+"|";
			}
			
			/*tab_texte_polygone=explode('|',document.getElementById('texte_polygone').value);*/
			tab_texte_polygone=explode('|',legende_polygone2);
			GEvent.addListener(polygon,"click",function()
			{
				//map.getCenter()
				tablatlng=explode("/",document.getElementById("coords").value);
				//47°18'44"
				
				var tab_coordonnees_lat=new Array();
				var tab_coordonnees_lng=new Array();
				
				tab_coordonnees_tmp_lat=explode("°",tablatlng[0]);
				tab_coordonnees_lat['d']=tab_coordonnees_tmp_lat[0];
				tab_minute_lat=explode("'",tab_coordonnees_tmp_lat[1]);
				tab_coordonnees_lat['m']=tab_minute_lat[0];
				tab_coordonnees_lat['s']=rogneright(tab_minute_lat[1],1);
				
				tab_coordonnees_tmp_lng=explode("°",tablatlng[1]);
				tab_coordonnees_lng['d']=tab_coordonnees_tmp_lng[0];
				tab_minute_lng=explode("'",tab_coordonnees_tmp_lng[1]);
				tab_coordonnees_lng['m']=tab_minute_lng[0];
				tab_coordonnees_lng['s']=rogneright(tab_minute_lng[1],1);
				
				map.openInfoWindow(new GLatLng(dms2GG(tab_coordonnees_lat['d'],tab_coordonnees_lat['m'],tab_coordonnees_lat['s']),dms2GG(tab_coordonnees_lng['d'],tab_coordonnees_lng['m'],tab_coordonnees_lng['s'])),document.createTextNode(tab_texte_polygone[cpt_txt_polygone]));
			});
			GEvent.addListener(polygon,"mouseout",function()
			{
				map.closeInfoWindow();
			});
		}
	}
}
function add_point(map,point,apres_point,id,id_partenaire,flag_dessine_chemin,id_point_interet)
{
	if(id_partenaire==0&&flag_dessine_chemin_ok>0&&id_point_interet==0)
		efface_chemin(map);
	var nb_points=tab_points.length;
	var cpt_new_point=0;
	if(apres_point==-1)
		cpt_new_point=nb_points;
	else
	{
   	for(var cpt_point=nb_points-1;cpt_point>=apres_point+1;cpt_point--)
   	{
   		tab_points[cpt_point+1]=tab_points[cpt_point];
   		tab_points[cpt_point+1].marker.cpt_point++;
   		enrg_point(cpt_point+1);
   		tab_instruction[cpt_point+1]=tab_instruction[cpt_point];
   		tab_touristique[cpt_point+1]=tab_touristique[cpt_point];
   	}
     	cpt_new_point=apres_point+1;
     	tab_instruction[cpt_new_point]='';
     	tab_touristique[cpt_new_point]='';
	}
	tab_points[cpt_new_point]=new Object();
	tab_points[cpt_new_point].point=point;

	if(document.getElementById('point_partenaire').value.length||document.getElementById('point_point_interet').value.length)
	{
		if(cpt_new_point==0)
			tab_points[cpt_new_point].marker=new GMarker(new GLatLng(point.lat(),point.lng()),{icon:icon_depart,draggable:false});		
		else if(id_partenaire!=0)
			tab_points[cpt_new_point].marker=new GMarker(new GLatLng(point.lat(),point.lng()),{icon:icon_partenaire,draggable:false});
		else if(id_point_interet!=0)
			tab_points[cpt_new_point].marker=new GMarker(new GLatLng(point.lat(),point.lng()),{icon:icon_point_interet,draggable:false});
		else if(cpt_new_point==tab_point_php.length-1)
			tab_points[cpt_new_point].marker=new GMarker(new GLatLng(point.lat(),point.lng()),{icon:icon_arrivee,draggable:false});
		else
			tab_points[cpt_new_point].marker=new GMarker(new GLatLng(point.lat(),point.lng()),{icon:icon_rouge,draggable:false});
	}
	else
	{
		if(document.getElementById('aff_itineraire').value==1)
		{
			if(cpt_new_point==0)
				tab_points[cpt_new_point].marker=new GMarker(new GLatLng(point.lat(),point.lng()),{icon:icon_depart,draggable:false});
			else if(cpt_new_point==tab_point_php.length-1)
				tab_points[cpt_new_point].marker=new GMarker(new GLatLng(point.lat(),point.lng()),{icon:icon_arrivee,draggable:false});
			else if(document.getElementById('aff_otcc'))
				tab_points[cpt_new_point].marker=new GMarker(new GLatLng(point.lat(),point.lng()),{icon:icon_rouge,draggable:false});
			else
				tab_points[cpt_new_point].marker=new GMarker(new GLatLng(point.lat(),point.lng()),{icon:icon_polygone,draggable:false});
			
		}
		else
  			tab_points[cpt_new_point].marker=new GMarker(new GLatLng(point.lat(),point.lng()),{icon:icon_rouge,draggable:true});
  	}
  	tab_points[cpt_new_point].marker.cpt_point=cpt_new_point;
  	//cpt_id++;
  	tab_points[cpt_new_point].id=id;
  	tab_points[cpt_new_point].instruction='';
  	tab_points[cpt_new_point].touristique='';

	GEvent.addListener(tab_points[cpt_new_point].marker,"click",function()
	{
		/*this.openInfoWindowHtml('Temps av :   '+tab_point_php[this.cpt_point]['temps_avant']+'<br />'+'Temps ap :   '+tab_point_php[this.cpt_point]['temps_apres']+'<br />'+'Dist av :   '+tab_point_php[this.cpt_point]['distance_avant']+'<br />'+	'Dist ap :   '+tab_point_php[this.cpt_point]['distance_apres']+'<br />'+' Vitesse :   '+tab_point_php[this.cpt_point]['vitesse']+'<br />'+' Angle :   '+tab_point_php[this.cpt_point]['angle']+'<br />');*/
		if(document.getElementById('point_partenaire').value.length&&id_partenaire!=0)
		{
			for(cpt_node=0;cpt_node<document.getElementById('partenaire_'+id_partenaire).parentNode.childNodes.length;cpt_node++)
			{
				if(document.getElementById('partenaire_'+id_partenaire).parentNode.childNodes[cpt_node].id)
					document.getElementById('partenaire_'+id_partenaire).parentNode.childNodes[cpt_node].style.backgroundColor='#ffffff';
			}
			document.getElementById('partenaire_'+id_partenaire).style.backgroundColor='#ffffc1';
			this.openInfoWindowHtml(document.getElementById('partenaire_info_bulle_'+id_partenaire).innerHTML);
			//map.setCenter(this.getLatLng(),14);
		}
		else if(document.getElementById('point_point_interet').value.length&&id_point_interet!=0)
		{
			for(cpt_node=0;cpt_node<document.getElementById('point_interet_'+id_point_interet).parentNode.childNodes.length;cpt_node++)
			{
				if(document.getElementById('point_interet_'+id_point_interet).parentNode.childNodes[cpt_node].id)
					document.getElementById('point_interet_'+id_point_interet).parentNode.childNodes[cpt_node].style.backgroundColor='#ffffff';
			}
			document.getElementById('point_interet_'+id_point_interet).style.backgroundColor='#ffffc1';
			this.openInfoWindowHtml(document.getElementById('point_interet_info_bulle_'+id_point_interet).innerHTML);
			//map.setCenter(this.getLatLng(),14);
		}
		else
		{
			if(!document.getElementById('aff_otcc'))
			{
				load_instruction(this.cpt_point);
				load_entree_ville(this.cpt_point);
				document.getElementById('detail_point').style.display='block';
				if(document.getElementById('aff_itineraire').value==0)
					document.getElementById('detail_point_vide').style.display='none';
				document.getElementById('id_point').value=tab_points[cpt_new_point].id;
		
				//suppression des images de l'ancien point selectionné
				var nombre_noeud = document.getElementById("aff_img").childNodes.length;
				if(nombre_noeud>0)
				{
					for(cpt_noeud=0;cpt_noeud<nombre_noeud;cpt_noeud++)
					{
						var noeud=document.getElementById("aff_img").firstChild;
						disparu = document.getElementById("aff_img").removeChild(noeud);
					}
				}
				//affichage des image du point selectionné
				if(count(tab_photo))
				{
					if(tab_photo[cpt_new_point].length)
					{
						tab_photo_detail=explode(",",tab_photo[cpt_new_point]);
						for(cpt_photo=0;cpt_photo<count(tab_photo_detail);cpt_photo++)
						{
							nouveauIMG = document.createElement("img");
							nouveauIMG.id ="photo_"+cpt_photo+"_"+tab_points[cpt_new_point].id;
							nouveauIMG.src=tab_photo_detail[cpt_photo];
							document.getElementById("aff_img").appendChild(nouveauIMG);
							if(document.getElementById('aff_itineraire').value==0)
							{
								nouveauA = document.createElement("a");
								nouveauA.href='#';
								nouveauA.innerHTML="Supprimer cette photo";
								nouveauA.cpt_photo=cpt_photo;
								if (document.all) {
								nouveauA.onclick = function() {
									delete_img("photo_"+this.cpt_photo+"_"+tab_points[cpt_new_point].id,tab_photo_detail[this.cpt_photo]);
									this.style.display='none';
									return false;
								};						
								}
								else
									nouveauA.setAttribute("onclick","delete_img('photo_"+cpt_photo+"_"+tab_points[cpt_new_point].id+"','"+tab_photo_detail[cpt_photo]+"');this.style.display='none';return false;");
								
								document.getElementById("aff_img").appendChild(nouveauA); 
							}
						}
					}
				}
			}
		}
	});
	GEvent.addListener(tab_points[cpt_new_point].marker,"mouseover",function()
	{
	});

	GEvent.addListener(tab_points[cpt_new_point].marker,"dragstart",function()
	{
		load_instruction(this.cpt_point);
	});
	GEvent.addListener(tab_points[cpt_new_point].marker,"drag",function()
	{
		efface_chemin(map);
     	tab_points[this.cpt_point].point=tab_points[this.cpt_point].marker.getPoint();
     	enrg_point(this.cpt_point);
		dessine_chemin(map);
	});
	
	map.addOverlay(tab_points[cpt_new_point].marker);

	enrg_point(cpt_new_point);
	if(id_partenaire==0&&flag_dessine_chemin>0&&id_point_interet==0)
		dessine_chemin(map);
}

function add_point_polygon(map,point,apres_point,id,reaffiche)
{
	var nb_points=tab_points_polygone.length;
	var cpt_new_point=0;
	if(apres_point==-1)
		cpt_new_point=nb_points;
   else
   {
   	for(var cpt_point=nb_points-1;cpt_point>=apres_point+1;cpt_point--)
   	{
   		tab_points_polygone[cpt_point+1]=tab_points_polygone[cpt_point];
   		tab_points_polygone[cpt_point+1].marker.cpt_point++;
   		enrg_point(cpt_point+1);
   		tab_instruction[cpt_point+1]=tab_instruction[cpt_point];
   		tab_touristique[cpt_point+1]=tab_touristique[cpt_point];
   	}
     	cpt_new_point=apres_point+1;
     	tab_instruction[cpt_new_point]='';
     	tab_touristique[cpt_new_point]='';
   }
  	tab_points_polygone[cpt_new_point]=new Object();
  	tab_points_polygone[cpt_new_point].point=point;
	
	if(document.getElementById('point_polygone'))
		tab_points_polygone[cpt_new_point].marker=new GMarker(new GLatLng(point.lat(),point.lng()),{icon:icon_polygone,draggable:false});
	else
		tab_points_polygone[cpt_new_point].marker=new GMarker(new GLatLng(point.lat(),point.lng()),{icon:icon_rouge,draggable:true});
	tab_points_polygone[cpt_new_point].marker.cpt_point=cpt_new_point;
	
	
  	//cpt_id++;
  	tab_points_polygone[cpt_new_point].id=id;
  	tab_points_polygone[cpt_new_point].instruction='';
  	tab_points_polygone[cpt_new_point].touristique='';

	GEvent.addListener(tab_points_polygone[cpt_new_point].marker,"click",function()
	{	
		document.getElementById('id_point').value=tab_points_polygone[cpt_new_point].id;
		if(tab_points_polygone[cpt_new_point].marker.cpt_point==0)
		{	
			add_point_polygon(map,tab_points_polygone[cpt_new_point].point,-1,cpt_id++,0);
		}
	});
	GEvent.addListener(tab_points_polygone[cpt_new_point].marker,"mouseover",function()
	{
	});

	GEvent.addListener(tab_points_polygone[cpt_new_point].marker,"dragstart",function()
	{
	});
	GEvent.addListener(tab_points_polygone[cpt_new_point].marker,"drag",function()
	{
     	tab_points_polygone[this.cpt_point].point=tab_points_polygone[this.cpt_point].marker.getPoint();
     	enrg_point_polygon(this.cpt_point);
		dessine_polygon(map,0);
	});
	
	map.addOverlay(tab_points_polygone[cpt_new_point].marker);

	enrg_point_polygon(cpt_new_point);
	
	if(reaffiche==0)
		dessine_polygon(map,0);	
}

function delete_img(id_photo,url_photo)
{
	if(document.getElementById('tab_photo').value)
	{
		tab_photo_tmp=explode("|",document.getElementById('tab_photo').value);
		if(tab_photo_tmp.length)
		{
			for(cpt_photo_tmp=0;cpt_photo_tmp<count(tab_photo_tmp);cpt_photo_tmp++)
			{
				if(tab_photo_tmp[cpt_photo_tmp]==url_photo)
					tab_photo_tmp[cpt_photo_tmp]='';
			}
		}
	}
	document.getElementById('tab_photo').value=tab_photo_tmp;
	document.getElementById(id_photo).style.display='none';
}
function enrg_point(cpt)
{
	tab_point_form[cpt]=tab_points[cpt].id+'|'+tab_points[cpt].marker.cpt_point+'|'+tab_points[cpt].point.lat()+'/'+tab_points[cpt].point.lng();
	document.getElementById('point_coordonnees').value=tab_point_form;
}
function enrg_point_polygon(cpt)
{
	tab_point_form[cpt]=tab_points_polygone[cpt].id+'|'+tab_points_polygone[cpt].marker.cpt_point+'|'+tab_points_polygone[cpt].point.lat()+'/'+tab_points_polygone[cpt].point.lng();
	document.getElementById('point_coordonnees').value=tab_point_form;
}
function load_instruction(cpt_point)
{
	save_instruction(1);
	save_touristique(1);
	cpt_point_commentaire=cpt_point;
	
	if(tab_touristique[cpt_point_commentaire])
	{
		if(document.getElementById('aff_itineraire').value==1)
		{
			if((cpt_point!=tab_point_php.length-1&&cpt_point!=0))
				tab_points[cpt_point_commentaire].marker.setImage(icon_touristique_sel.image);
		}
		else
			tab_points[cpt_point_commentaire].marker.setImage(icon_touristique_sel.image);
	}
	else
	{
		if(document.getElementById('aff_itineraire').value==1)
		{
			if((cpt_point!=tab_point_php.length-1&&cpt_point!=0))
				tab_points[cpt_point_commentaire].marker.setImage(icon_verte_sel.image);
		}
		else
			tab_points[cpt_point_commentaire].marker.setImage(icon_touristique_sel.image);
	}
	if(document.getElementById('aff_itineraire').value==1)
	{
		document.getElementById('instruction').innerHTML=tab_points[cpt_point_commentaire].instruction;
		document.getElementById('touristique').innerHTML=tab_points[cpt_point_commentaire].touristique;
	}
	else
	{
		var reg=new RegExp("[|]", "g");
		tab_points[cpt_point_commentaire].instruction=tab_points[cpt_point_commentaire].instruction.replace(reg,",");
		document.getElementById('instruction').value=tab_points[cpt_point_commentaire].instruction;
		tab_points[cpt_point_commentaire].touristique=tab_points[cpt_point_commentaire].touristique.replace(reg,",");
		document.getElementById('touristique').value=tab_points[cpt_point_commentaire].touristique;
	}
}
function save_instruction(load)
{
	if(cpt_point_commentaire>=0)
	{
		if(load)
		{
			if(tab_instruction[cpt_point_commentaire])
				tab_points[cpt_point_commentaire].instruction=tab_instruction[cpt_point_commentaire];
		}
		else
			tab_points[cpt_point_commentaire].instruction=document.getElementById('instruction').value;
		if(tab_points[cpt_point_commentaire].instruction.length&&cpt_point_commentaire!=0&&cpt_point_commentaire!=tab_point_php.length-1)
			tab_points[cpt_point_commentaire].marker.setImage(icon_verte.image);
		else
		{
			if(document.getElementById('aff_itineraire').value==1)
			{
				if(cpt_point_commentaire!=0&&cpt_point_commentaire!=tab_point_php.length-1)
					tab_points[cpt_point_commentaire].marker.hide();
			}
			else
				tab_points[cpt_point_commentaire].marker.setImage(icon_rouge.image);
		}
		var reg=new RegExp("(,)", "g");
		tab_instruction[cpt_point_commentaire]=tab_points[cpt_point_commentaire].instruction.replace(reg,"|");
		document.getElementById('point_commentaire').value=tab_instruction;
	}
}
function load_entree_ville(cpt_point)
{
	save_entree_ville(1);
	cpt_point_commentaire=cpt_point;
	if(document.getElementById('aff_itineraire').value!=1)
	{
		if(tab_points[cpt_point_commentaire].ville==1)
			document.getElementById('entree_ville').checked=true;
		else
			document.getElementById('entree_ville').checked=false;
	}
}
function save_entree_ville(load)
{
	if(cpt_point_commentaire>=0)
	{
		if(load)
		{
			if(tab_ville[cpt_point_commentaire])
				tab_points[cpt_point_commentaire].ville=tab_ville[cpt_point_commentaire];
		}
		else
		{
			if(document.getElementById('entree_ville').checked)
				tab_points[cpt_point_commentaire].ville=1;
			else
				tab_points[cpt_point_commentaire].ville=0;	
		}
		tab_ville[cpt_point_commentaire]=tab_points[cpt_point_commentaire].ville;
		document.getElementById('point_ville').value=tab_ville;
	}
}
function save_touristique(load)
{
	if(cpt_point_commentaire>=0)
	{
		if(load)
		{
			if(tab_touristique[cpt_point_commentaire])
				tab_points[cpt_point_commentaire].touristique=tab_touristique[cpt_point_commentaire];
		}
		else
			tab_points[cpt_point_commentaire].touristique=document.getElementById('touristique').value;
		if(tab_points[cpt_point_commentaire].touristique.length&&cpt_point_commentaire!=0&&cpt_point_commentaire!=tab_point_php.length-1)
		{
			tab_points[cpt_point_commentaire].marker.setImage(icon_touristique.image);
			/*
			var cpt_point_tmp=tab_points[cpt_point_commentaire].marker.cpt_point;
			tab_points[cpt_point_commentaire].marker=new GMarker(new GLatLng(tab_points[cpt_point_commentaire].point.lat(),tab_points[cpt_point_commentaire].point.lng()),{icon:icon_touristique,draggable:false});
			tab_points[cpt_point_commentaire].marker.cpt_point=cpt_point_tmp;
			*/
			tab_points[cpt_point_commentaire].marker.show();
		}
		var reg=new RegExp("(,)", "g");
		tab_touristique[cpt_point_commentaire]=tab_points[cpt_point_commentaire].touristique.replace(reg,"|");
		document.getElementById('point_commentaire_touristique').value=tab_touristique;
	}
}
function del_instruction(cpt)
{
	for(cpt_instruction=cpt;cpt_instruction<count(tab_instruction);cpt_instruction++)
	{
		tab_instruction[cpt_instruction]=tab_instruction[cpt_instruction+1];
	}
	document.getElementById('point_commentaire').value=tab_instruction;
}
function del_touristique(cpt)
{
	for(cpt_commentaire=cpt;cpt_commentaire<count(tab_touristique);cpt_commentaire++)
	{
		tab_touristique[cpt_commentaire]=tab_touristique[cpt_commentaire+1];
	}
	document.getElementById('point_commentaire_touristique').value=tab_touristique;
}
function del_point(point)
{
	efface_chemin(map);

	map.removeOverlay(point.marker);

	var nb_points=tab_points.length;
	for(var cpt_point=point.marker.cpt_point;cpt_point<nb_points-1;cpt_point++)
	{
		tab_points[cpt_point]=tab_points[cpt_point+1];
		tab_points[cpt_point].marker.cpt_point--;
		enrg_point(cpt_point);
	}
	del_instruction(point.marker.cpt_point);
	del_touristique(point.marker.cpt_point);
	tab_point_form[cpt_point]='';
	document.getElementById('point_coordonnees').value=tab_point_form;
	tab_points.length=tab_points.length-1;

	dessine_chemin(map);	
}
function del_point_polygon(point)
{
	map.removeOverlay(point.marker);

	var nb_points=tab_points_polygone.length;
	for(var cpt_point=point.marker.cpt_point;cpt_point<nb_points-1;cpt_point++)
	{
		tab_points_polygone[cpt_point]=tab_points_polygone[cpt_point+1];
		tab_points_polygone[cpt_point].marker.cpt_point--;
		enrg_point_polygon(cpt_point);
	}
	tab_point_form[cpt_point]='';
	document.getElementById('point_coordonnees').value=tab_point_form;
	tab_points_polygone.length=tab_points_polygone.length-1;

	dessine_polygon(map,0);
}
function get_detail_coord(coord)
{//47.716216
	var ret=new Array();
	ret['d']=Math.floor(coord);//47
	coord=coord-ret['d'];//0,716216
	ret['m']=Math.floor(coord*60);//42
	coord=(coord*60)-ret['m'];//0,97296
	ret['s']=Math.floor(coord*60);//58
	ret['DMS']=ret['d']+'°'+ret['m']+"'"+ret['s']+'"';//47°42'58"
	return ret;
}
function get_coord(dms)
{
	if(!(dms['d']>0))
		dms['d']=1;
	if(!(dms['m']>0))
		dms['m']=0;
	if(!(dms['s']>0))
		dms['s']=0;
	dms['GG']=parseInt(dms['d'])+(parseInt(dms['m'])/60)+(parseInt(dms['s'])/3600);
	return dms;
}
function dms2GG(d,m,s)
{
	var temp=get_coord(get_dms(d,m,s));
	return temp['GG'];
}
function get_dms(d,m,s)
{
	var dms=new Array;
	dms['d']=d;
	dms['m']=m;
	dms['s']=s;
	return dms;
}
function go_to()
{
	var ma_lat=new Array();
	ma_lat['d']=document.getElementById('lat_d').value;ma_lat['m']=document.getElementById('lat_m').value;ma_lat['s']=document.getElementById('lat_s').value;
	var ma_lng=new Array();
	ma_lng['d']=document.getElementById('lng_d').value;ma_lng['m']=document.getElementById('lng_m').value;ma_lng['s']=document.getElementById('lng_s').value;
	if(ma_lat['d']>0&&ma_lng['d'])
	{
		ma_lat=get_coord(ma_lat);
		ma_lng=get_coord(ma_lng);
//		map.removeOverlay(marker_repere);

	add_point(map,new GLatLng(ma_lat['GG'],ma_lng['GG']),-1,'new'+cpt_id++,0,1,0);
//		marker_repere.setLatLng(new GLatLng(ma_lat['GG'],ma_lng['GG']));
//		map.addOverlay(marker_repere);
	//	map.setCenter(marker_repere.getLatLng());
	}
	else if(document.getElementById('recherche_ville').value)
	{
		ville=new GClientGeocoder();
		ville.getLatLng(document.getElementById('recherche_ville').value,
			function(point)
			{
				if(!point)
					alert("Cette adresse n\'a pu être trouvée");
				else
				{
					map.setCenter(point,14);//centre la carte sur le bien
					document.getElementById('assistant').innerHTML=assistant_etape_2;
					document.getElementById('assistant').style.backgroundColor='#ff6600';
				}	
			}
		);
	}
}
var ign;
function GGcarte_load()
{
	if(GBrowserIsCompatible())
	{
		icon_verte=new GIcon();
		icon_verte.image="picto/icon_navigation.png";
		icon_verte.iconAnchor=new GPoint(18,32);
		icon_verte.infoWindowAnchor=new GPoint(5,1);
		icon_verte.iconSize=new GSize(34,34);
		
		icon_verte_sel=new GIcon();
		icon_verte_sel.image="picto/icon_navigation_sel.png";
		icon_verte_sel.iconAnchor=new GPoint(18,32);
		icon_verte_sel.infoWindowAnchor=new GPoint(5,1);
		icon_verte_sel.iconSize=new GSize(34,34);
		
		icon_rouge=new GIcon();
		icon_rouge.image="picto/mm_20_red.png";
		icon_rouge.iconAnchor=new GPoint(18,32);
		icon_rouge.infoWindowAnchor=new GPoint(5,1);
		icon_rouge.iconSize=new GSize(34,34);

		icon_bleue=new GIcon();
		icon_bleue.image="http://labs.google.com/ridefinder/images/mm_20_blue.png";
		icon_bleue.iconAnchor=new GPoint(6,20);
		icon_bleue.infoWindowAnchor=new GPoint(5,1);
		icon_bleue.iconSize=new GSize(12,20);
		
		icon_touristique=new GIcon();
		icon_touristique.image="picto/icon_touristique.png";
		icon_touristique.iconAnchor=new GPoint(18,32);
		icon_touristique.infoWindowAnchor=new GPoint(5,1);
		icon_touristique.iconSize=new GSize(34,34);
		
		icon_touristique_sel=new GIcon();
		icon_touristique_sel.image="picto/icon_touristique_sel.png";
		icon_touristique_sel.iconAnchor=new GPoint(18,32);
		icon_touristique_sel.infoWindowAnchor=new GPoint(5,1);
		icon_touristique_sel.iconSize=new GSize(34,34);
		
		icon_partenaire=new GIcon();
		icon_partenaire.image="picto/icon_partenaire.png";
		icon_partenaire.iconAnchor=new GPoint(30,20);
		icon_partenaire.infoWindowAnchor=new GPoint(5,1);
		icon_partenaire.iconSize=new GSize(32,32);
		
		icon_point_interet=new GIcon();
		icon_point_interet.image="picto/icon_point_interet.png";
		icon_point_interet.iconAnchor=new GPoint(30,20);
		icon_point_interet.infoWindowAnchor=new GPoint(5,1);
		icon_point_interet.iconSize=new GSize(32,32);
		
		icon_depart=new GIcon();
		icon_depart.image="picto/icon_depart.png";
		icon_depart.iconAnchor=new GPoint(18,32);
		icon_depart.infoWindowAnchor=new GPoint(5,1);
		icon_depart.iconSize=new GSize(32,32);
		
		icon_arrivee=new GIcon();
		icon_arrivee.image="picto/icon_arrivee.png";
		icon_arrivee.iconAnchor=new GPoint(18,32);
		icon_arrivee.infoWindowAnchor=new GPoint(5,1);
		icon_arrivee.iconSize=new GSize(32,32);
		
		icon_polygone=new GIcon();
		icon_polygone.image="picto/vide.gif";
		icon_polygone.iconAnchor=new GPoint(18,32);
		icon_polygone.infoWindowAnchor=new GPoint(5,1);
		icon_polygone.iconSize=new GSize(34,34);

		map=new GMap2(document.getElementById("GG_carte"));
		map.addControl(new GSmallMapControl());//zoom, fleches de deplacement
		map.addControl(new GMapTypeControl());//mode satellite/carte
		map.addMapType(G_PHYSICAL_MAP);
		map.setMapType(G_PHYSICAL_MAP);

		cpt_id=document.getElementById('id_point_max').value;
		
		if(document.getElementById('polygone'))
		{
			map.setCenter(new GLatLng(46.37,2.263),6);
			GEvent.addListener(map,"click",function(overlay,point)
			{
				if(point)
				{
					add_point_polygon(map,point,-1,cpt_id++,0,1);
				}
			});
			GEvent.addListener(map,"singlerightclick",function(point,src,overlay)
			{
				if(overlay.cpt_point>=0)
				{
					del_point_polygon(tab_points_polygone[overlay.cpt_point]);
				}
			});
			zoom_carte();
			/*------------------------------------------------------------------------
					REAFFICHAGE DES POINTS APRES VALIDATION DU FORMULAIRE INCORRECT
			------------------------------------------------------------------------*/
			if(document.getElementById('point_coordonnees').value.length)
			{
				//1|0|46.2315/5.2364,2|1|46.896/1.235,...
				tab_coordonnees_tmp=explode(",",document.getElementById('point_coordonnees').value);
				for(cpt_coordonnees=0;cpt_coordonnees<count(tab_coordonnees_tmp);cpt_coordonnees++)
				{	
					//1|0|46.2315/5.2364
					if(tab_coordonnees_tmp[cpt_coordonnees].length)
					{
						tab=explode("|",tab_coordonnees_tmp[cpt_coordonnees]);
						tab_coordonnees[tab[1]]=(tab[2]+','+tab[0]).replace("/",",");
					}
				}
				for(var cpt_coordonnees in tab_coordonnees)
				{
					tab_point=explode(",",tab_coordonnees[cpt_coordonnees]);
					add_point_polygon(map,new GLatLng(tab_point[0],tab_point[1]),-1,tab_point[2],1);
				}
				dessine_polygon(map,0);
			}
			/*
			if(tab_point_php.length)
			{
				for(cpt_point=0;cpt_point<count(tab_point_php);cpt_point++)
				{
					if(cpt_point==count(tab_point_php)-1)
						flag_dessine_chemin=1;
					else
						flag_dessine_chemin=0;
					add_point(map,new GLatLng(tab_point_php[cpt_point]['lat'],tab_point_php[cpt_point]['lon']),-1,tab_point_php[cpt_point]['id'],0,flag_dessine_chemin);
				}
				dessine_polygon(map,0);
			}
			*/
		}
		else
		{
			/*------------------------------------------------------------------------
								CENTRAGE DE LA PAGE SUIVANT LES POINTS
			------------------------------------------------------------------------*/
			zoom_carte();
			
			GEvent.addListener(map,"mousemove",function(point)
			{
				var lat=point.lat();
				var lng=point.lng();
				var ma_lat=get_detail_coord(lat);
				var ma_lng=get_detail_coord(lng);
				document.getElementById('coords').value=ma_lat['DMS']+"/"+ma_lng['DMS'];
			});
			
			if(document.getElementById('aff_itineraire').value==1)
			{
				GEvent.addListener(map,"zoomend",function(overlay,point)
				{
					ajax_aff_polygone(map.getBounds().getSouthWest(),map.getBounds().getNorthEast());					
				});
				GEvent.addListener(map,"move",function(overlay,point)
				{
					ajax_aff_polygone(map.getBounds().getSouthWest(),map.getBounds().getNorthEast());					
				});
			}
			else if(document.getElementById('assistant'))
			{
				if(document.getElementById('point_zoom').value!='')
				{
					tab_zoom_tmp=explode("|",document.getElementById('point_zoom').value);
					if(tab_zoom_tmp[0]>=10)
					{
						document.getElementById('assistant').innerHTML=assistant_etape_5;
						document.getElementById('assistant').style.backgroundColor='#669900';
						if(document.getElementById('aff_itineraire').value==0)
						{
							GEvent.addListener(map,"click",function(overlay,point)
							{
								if(point)
								{
									add_point(map,point,-1,'new'+cpt_id++,0,1,0);
								}
							});
							GEvent.addListener(map,"singlerightclick",function(point,src,overlay)
							{
								if(overlay.cpt_point>=0)
								{
									del_point(tab_points[overlay.cpt_point]);
								}
							});
						}
						zoom_ok=1;
					}
				}
				GEvent.addListener(map,"zoomend",function(overlay,point)
				{
					if(map.getZoom()>=10&&!zoom_ok)
					{
						if(map.getZoom()==10)
						{
							document.getElementById('assistant').innerHTML=assistant_etape_2;
							document.getElementById('assistant').style.backgroundColor='#ff6600';
						}
						if(document.getElementById('aff_itineraire').value==0)
						{
							GEvent.addListener(map,"click",function(overlay,point)
							{
								document.getElementById('assistant').style.backgroundColor='#669900';
								if(point)
								{
									add_point(map,point,-1,'new'+cpt_id++,0,1,0);
									if(count(tab_points)<=1)
										document.getElementById('assistant').innerHTML=assistant_etape_3;
									if(count(tab_points)>=2)
										document.getElementById('assistant').innerHTML=assistant_etape_4;
									if(count(tab_points)>=5)
										document.getElementById('assistant').innerHTML=assistant_etape_5;
								}
							});
							GEvent.addListener(map,"singlerightclick",function(point,src,overlay)
							{
								if(overlay.cpt_point>=0)
								{
									del_point(tab_points[overlay.cpt_point]);
								}
							});
						}
						zoom_ok=1;
					}					
				});
			}
			else
			{
				GEvent.addListener(map,"click",function(overlay,point)
				{
					if(point)
					{
						add_point(map,point,-1,'new'+cpt_id++,0,1,0);
					}
				});
				GEvent.addListener(map,"singlerightclick",function(point,src,overlay)
				{
					if(overlay.cpt_point>=0)
					{
						del_point(tab_points[overlay.cpt_point]);
					}
				});
			}
	//			var boundaries=new GLatLngBounds(new GLatLng(45.083,5.69),new GLatLng(45.172,5.818));//BGHD
			var boundaries=new GLatLngBounds(new GLatLng(dms2GG(45,4,55),dms2GG(5,41,22)),new GLatLng(dms2GG(45,10,31),dms2GG(5,49,18)));//BGHD
			ign=new GGroundOverlay("echirolles2.png",boundaries);
			map.addOverlay(ign);
	
			/*------------------------------------------------------------------------
					REAFFICHAGE DES POINTS APRES VALIDATION DU FORMULAIRE INCORRECT
			------------------------------------------------------------------------*/
			if(document.getElementById('point_coordonnees').value.length)
			{
				//1|0|46.2315/5.2364,2|1|46.896/1.235,...
				/*
				tab_coordonnees_tmp=explode(",",document.getElementById('point_coordonnees').value);
				for(cpt_coordonnees=0;cpt_coordonnees<count(tab_coordonnees_tmp);cpt_coordonnees++)
				{	
					//1|0|46.2315/5.2364
					if(tab_coordonnees_tmp[cpt_coordonnees].length)
					{
						tab=explode("|",tab_coordonnees_tmp[cpt_coordonnees]);
						tab_coordonnees[tab[1]]=(tab[2]+','+tab[0]).replace("/",",");
					}
				}
				for(var cpt_coordonnees in tab_coordonnees)
				{
					tab_point=explode(",",tab_coordonnees[cpt_coordonnees]);
					add_point(map,new GLatLng(tab_point[0],tab_point[1]),-1,tab_point[2],0);
				}
				*/
			}
			if(tab_point_php.length)
			{
				for(cpt_point=0;cpt_point<count(tab_point_php);cpt_point++)
				{
					if(cpt_point==count(tab_point_php)-1)
						flag_dessine_chemin=1;
					else
						flag_dessine_chemin=0;
					add_point(map,new GLatLng(tab_point_php[cpt_point]['lat'],tab_point_php[cpt_point]['lon']),-1,tab_point_php[cpt_point]['id'],0,flag_dessine_chemin,0);
				}
			}
			/*------------------------------------------------------------------------
				REAFFICHAGE DES COMMENTAIRES APRES VALIDATION DU FORMULAIRE INCORRECT
			------------------------------------------------------------------------*/
			if(document.getElementById('point_commentaire').value.length)
			{
				tab_instruction_tmp=explode(",",document.getElementById('point_commentaire').value);
				for(cpt_instruction=0;cpt_instruction<count(tab_instruction_tmp);cpt_instruction++)
				{
					tab_instruction[cpt_instruction]=str_replace("|",",",tab_instruction_tmp[cpt_instruction]);
					cpt_point_commentaire=cpt_instruction;
					save_instruction(1);
				}
			}
			/*-------------------------------------------------------------------------------------
				REAFFICHAGE DES COMMENTAIRES TOURISTIQUE APRES VALIDATION DU FORMULAIRE INCORRECT
			--------------------------------------------------------------------------------------*/
			if(document.getElementById('point_commentaire').value.length)
			{
				tab_touristique_tmp=explode(",",document.getElementById('point_commentaire_touristique').value);
				for(cpt_commentaire=0;cpt_commentaire<count(tab_touristique_tmp);cpt_commentaire++)
				{
					tab_touristique[cpt_commentaire]=str_replace("|",",",tab_touristique_tmp[cpt_commentaire]);
					cpt_point_commentaire=cpt_commentaire;
					save_touristique(1);
				}
			}
			/*------------------------------------------------------------------------
				REAFFICHAGE DES ENTREES VILLES APRES VALIDATION DU FORMULAIRE INCORRECT
			------------------------------------------------------------------------*/
			if(document.getElementById('point_ville').value.length)
			{
				tab_ville=explode(",",document.getElementById('point_ville').value);
				for(cpt_ville=0;cpt_ville<count(tab_ville);cpt_ville++)
				{
					cpt_point_commentaire=cpt_ville;
					save_entree_ville(1);
				}
			}
			/*------------------------------------------------------------------------
						AFFICHAGE DES PHOTOS
			------------------------------------------------------------------------*/
			if(document.getElementById('tab_photo').value.length)
			{
				//format img/photo.jpg,img/photo1.jpg...|img/photo.jpg,img/photo1.jpg...|...
				tab_photo=explode("|",document.getElementById('tab_photo').value);
			}
			
			/*------------------------------------------------------------------------
						AFFICHAGE DES POINT A PARTIR D'UN FICHIER GPX
			------------------------------------------------------------------------*/
			if(document.getElementById('fichier_gpx').value.length)
				import_gpx(document.getElementById('fichier_gpx').value);
			/*------------------------------------------------------------------------
						AFFICHAGE DES POINTS PARTENAIRES
			------------------------------------------------------------------------*/
			if(document.getElementById('point_partenaire').value.length)
			{
				//id|lat|lng,id|lat|lng,...
				tab_partenaire_tmp=explode(",",document.getElementById('point_partenaire').value);
				for(cpt_partenaire=0;cpt_partenaire<count(tab_partenaire_tmp);cpt_partenaire++)
				{
					tab_partenaire=explode("|",tab_partenaire_tmp[cpt_partenaire]);
					add_point(map,new GLatLng(tab_partenaire[1],tab_partenaire[2]),-1,cpt_id++,tab_partenaire[0],1,0);
				}
			}
			/*------------------------------------------------------------------------
						AFFICHAGE DES POINTS D'INTERET
			------------------------------------------------------------------------*/
			if(document.getElementById('point_point_interet').value.length)
			{
				//id|lat|lng,id|lat|lng,...
				tab_point_interet_tmp=explode(",",document.getElementById('point_point_interet').value);
				for(cpt_point_interet=0;cpt_point_interet<count(tab_point_interet_tmp);cpt_point_interet++)
				{
					tab_point_interet=explode("|",tab_point_interet_tmp[cpt_point_interet]);
					add_point(map,new GLatLng(tab_point_interet[1],tab_point_interet[2]),-1,cpt_id++,0,1,tab_point_interet[0]);
				}
			}
			/*------------------------------------------------------------------------
						AFFICHAGE DES POLYGONES
			------------------------------------------------------------------------*/
			if(document.getElementById('aff_itineraire').value==1)					
				ajax_aff_polygone(map.getBounds().getSouthWest(),map.getBounds().getNorthEast());
		}
	}
}
function liste_photo(value)
{
	var nouveauLI = document.createElement("li");
	nouveauLI.innerHTML=left(value,5)+'...'+right(value,20);
	document.getElementById("liste_photo").appendChild(nouveauLI);
	
	input=document.getElementById('upload_photo').cloneNode(true);
	
	ordre_photo_max=document.getElementById("liste_photo").getElementsByTagName("LI").length;
	
	document.getElementById('upload_photo').name="point_photo_"+document.getElementById('id_point').value+"_"+ordre_photo_max;
	document.getElementById('upload_photo').style.display="none";
	document.getElementById('upload_photo').id="point_photo";

	document.getElementById('ordre_max_photo').value=ordre_photo_max;
	
	input.value='';
	document.getElementById("detail_point").appendChild(input);
}
function import_gpx(value)
{
	GDownloadUrl(value, function(data, responseCode) {
	  var xml = GXml.parse(data);
	  var markers = xml.documentElement.getElementsByTagName("trkpt");
	  if(!markers[0])
	  	var markers = xml.documentElement.getElementsByTagName("rpt");
	  var firstPoint=new GLatLng(parseFloat(markers[0].getAttribute("lat")),
                  		     parseFloat(markers[0].getAttribute("lon")));
	  var lastPoint=firstPoint
	  for (var i = 1; i < markers.length; i++) {
	    var newPoint=new GLatLng(parseFloat(markers[i].getAttribute("lat")),
                     		     parseFloat(markers[i].getAttribute("lon")));
	    if(newPoint.distanceFrom(lastPoint)>1||i==markers.length-1||i == 1) 
		 {
	      add_point(map,new GLatLng(markers[i].getAttribute("lat"),markers[i].getAttribute("lon")),-1,cpt_id++,0,1,0);
	      lastPoint=newPoint;
	    }
	  }
	  zoom_carte();
	});
}
function zoom_carte()
{
	if(document.getElementById('point_zoom').value.length)
	{
		tab_zoom=explode("|",document.getElementById('point_zoom').value);
		map.setCenter(new GLatLng(tab_zoom[1],tab_zoom[2]),parseInt(tab_zoom[0]));
	}
	else
		map.setCenter(new GLatLng(46.37,2.263),6);
}
function ajax_aff_polygone(sud_ouest,nord_est)
{
	var mon_cpt_ajax=new_ajax();
	var mon_ajax=tab_ajax[mon_cpt_ajax];

	if(mon_ajax)
	{
		requete_ajax(
			mon_ajax,
			'GET',
			'ajax/polygone.php',
			'sud_ouest='+sud_ouest+
			'&'+
			'nord_est='+nord_est);
			
	}
	mon_ajax.onreadystatechange=function()
	{
		if (mon_ajax.readyState == 4) // 4 : état "complete" 
		{
			if (mon_ajax.status == 200) // 200 : code HTTP pour OK 
			{
				//alert("="+mon_ajax.responseText+"=");
				point_polygone_detail=mon_ajax.responseText;
				if(count(tab_polygone_detail))
				{
					for(cpt_polygone_delete=0;cpt_polygone_delete<count(tab_polygone_detail);cpt_polygone_delete++)
					{
						map.removeOverlay(tab_polygone_detail[cpt_polygone_delete]);
					}
				}
				if(document.getElementById('liste_legende'))
				{
					ancienUL = document.getElementById('liste_legende');
					document.getElementById('legende_polygone').removeChild(ancienUL);
					
				}
				nouveauUL = document.createElement("ul");
				nouveauUL.id='liste_legende';
				document.getElementById("legende_polygone").appendChild(nouveauUL);
				//format lat,lng,lat,lng...|...|...
				tab_polygone_tmp=explode("|",point_polygone_detail);
				cpt_color=0;
				for(cpt_polygone=0;cpt_polygone<count(tab_polygone_tmp);cpt_polygone++)
				{
					if(count(tab_points_polygone))
					{
						for(cpt=0;cpt<count(tab_points_polygone);cpt++)
							tab_points_polygone=unset(tab_points_polygone, cpt);
					}
					tab_polygone_detail_polygone=explode(';',tab_polygone_tmp[cpt_polygone]);
					tab_polygone=explode(",",tab_polygone_detail_polygone[1]);
					for(cpt_point_polygone=0;cpt_point_polygone<count(tab_polygone);cpt_point_polygone++)
					{
						if(cpt_point_polygone%2==1)
							add_point_polygon(map,new GLatLng(tab_polygone[cpt_point_polygone-1],tab_polygone[cpt_point_polygone]),-1,cpt_id++,1);
					}
					dessine_polygon(map,cpt_polygone);
					tab_polygone_detail[cpt_polygone]=polygon;
					//affichage de la legende
					if(tab_polygone_detail_polygone[0])
					{
						document.getElementById('legende_polygone').style.display='block';
						nouveauLI = document.createElement("li");
						nouveauUL.appendChild(nouveauLI);
						nouveauUL.style.margin='0px';
						nouveauUL.style.padding='7px';
						
						nouveauSPAN = document.createElement("span");
						nouveauLI.appendChild(nouveauSPAN);

						nouveauLI.className='liste_legende_polygone';
						nouveauSPAN.className='legende_polygone';
						nouveauSPAN.style.backgroundColor=tab_color[cpt_color];
						
						nouveauLI.style.color=tab_color[cpt_color];
						nouveauSPAN2 = document.createElement("span");
						nouveauLI.appendChild(nouveauSPAN2);
						nouveauSPAN2.innerHTML=tab_polygone_detail_polygone[0];
						nouveauSPAN2.style.lineHeight='20px';
					}
					cpt_color++;
				}
				nouveauBR = document.createElement("br");
				nouveauBR.style.clear='left';
				document.getElementById("liste_legende").appendChild(nouveauBR);
			}
		}
	}
	
	return mon_ajax;
}
function distance_entre_2_point(premier_point,deuxieme_point)
{
	return premier_point.distanceFrom(deuxieme_point);
}
function zoom_partenaire(partenaire_lat,partenaire_lon)
{
	map.setCenter(new GLatLng(partenaire_lat,partenaire_lon),14);
}
function zoom_point_interet(point_interet_lat,point_interet_lon)
{
	map.setCenter(new GLatLng(point_interet_lat,point_interet_lon),14);
}
