// Ben alors les gars ! on vient pomper le script ? on a pas d'idées dans sa petite caboche ? faut pas faire de sites web si vous avez pas d'idées !
// Aller ! Faites vous plaisir, j'ai pas crypté le code ... Mais vous ne devriez pas l'utiliser... car j'y ai mis un truc un peu tordu dedans, expres pour vous ... 


var icon_ici = new GIcon();
icon_ici.image = "http://www.chambresdhotes.travel/ico_ici.png";
icon_ici.shadow = "http://www.chambresdhotes.travel/ico_ici_sd.png";
icon_ici.shadowSize = new GSize(35, 35);
icon_ici.iconSize = new GSize(35, 35);
icon_ici.iconAnchor = new GPoint(8, 28);
icon_ici.infoWindowAnchor = new GPoint(8, 8);

var icon_test = new GIcon();
icon_test.image = "http://www.chambresdhotes.travel/ico10.png";
icon_test.iconSize = new GSize(35, 42);
icon_test.iconAnchor = new GPoint(8, 28);
icon_test.infoWindowAnchor = new GPoint(8, 8);

var icon_ch = new GIcon();
icon_ch.image = "http://www.chambresdhotes.travel/ico00.png";
icon_ch.iconSize = new GSize(32, 32);
icon_ch.iconAnchor = new GPoint(8, 28);
icon_ch.infoWindowAnchor = new GPoint(8, 8);

var icon_chp = new GIcon();
icon_chp.image = "http://www.chambresdhotes.travel/ico01.png";
icon_chp.iconSize = new GSize(32, 32);
icon_chp.iconAnchor = new GPoint(8, 28);
icon_chp.infoWindowAnchor = new GPoint(8, 8);

var icon_pr = new GIcon();
icon_pr.image = "http://www.chambresdhotes.travel/ico10.png";
icon_pr.iconSize = new GSize(32, 32);
icon_pr.iconAnchor = new GPoint(8, 28);
icon_pr.infoWindowAnchor = new GPoint(8, 8);

var icon_gt = new GIcon();
icon_gt.image = "http://www.chambresdhotes.travel/ico20.png";
icon_gt.iconSize = new GSize(32, 32);
icon_gt.iconAnchor = new GPoint(8, 28);
icon_gt.infoWindowAnchor = new GPoint(8, 8);

var icon_mh = new GIcon();
icon_mh.image = "http://www.chambresdhotes.travel/ico30.png";
icon_mh.iconSize = new GSize(32, 32);
icon_mh.iconAnchor = new GPoint(8, 28);
icon_mh.infoWindowAnchor = new GPoint(8, 8);

var icon_cht = new GIcon();
icon_cht.image = "http://www.chambresdhotes.travel/ico50.png";
icon_cht.iconSize = new GSize(32, 32);
icon_cht.iconAnchor = new GPoint(8, 28);
icon_cht.infoWindowAnchor = new GPoint(8, 8);



var map; 
var LALISTE=new Array();

function load() {
  if (GBrowserIsCompatible()) {
	map = new GMap2(document.getElementById("mapch"));
	map.setCenter(new GLatLng(46.950262,2.526855), 6);
	map.addControl(new GLargeMapControl());
  }
}

function loadTO(LAT,LNG,ZOOM) {
  if (GBrowserIsCompatible()) {
	map = new GMap2(document.getElementById("mapch"));
	map.setCenter(new GLatLng(LAT,LNG), ZOOM);
	map.addControl(new GLargeMapControl());
  }
}

function GetLimites()
{
var limites= map.getBounds();	
var sw=limites.getSouthWest();
var ne=limites.getNorthEast();
var leslimites=new Array(sw.lng(),ne.lng(),ne.lat(),sw.lat());
return leslimites;
}

function AddMark(Lat,Long)
{
	markerOptions = { icon:icon_ici };
	map.addOverlay(new GMarker(new GLatLng(Lat,Long), markerOptions));	
}

function AddOne(Lat,Long,Idweb,type,valide,prix)
{
var markerOptions = { icon:icon_ch };
switch (type) {
	case "1":
	markerOptions = { icon:icon_ch };
	break;
	case "2":
	markerOptions = { icon:icon_mh };
	break;
	case "3":
	markerOptions = { icon:icon_gt };
	break;
	case "4":
	markerOptions = { icon:icon_gt };
	break;
	case "5":
	markerOptions = { icon:icon_cht };
	break;
}

if(prix>60 && type==1) 	markerOptions = { icon:icon_chp };
if(valide==2) 	markerOptions = { icon:icon_pr };

	var options = {   maxWidth : 200};
	var MYmarker=new GMarker(new GLatLng(Lat,Long), markerOptions);
//	MYmarker.title=titre;
	GEvent.addListener(MYmarker, "click", function() {
			var URL="http://www.chambresdhotes.travel/GETDESC.php";
			var myAjax = new Ajax.Request( 
						     	URL	, {
										method: 'get',
										parameters: 'idweb='+Idweb,
										onLoading:function(){	MYmarker.openInfoWindowHtml("Loading...",options);},
										onComplete:function(t,json) {
										MYmarker.openInfoWindowHtml(t.responseText,options);
										}
					} );

	







	});
	map.addOverlay(MYmarker);	
}

function getDesc(Idweb)
{

var URL="http://www.chambresdhotes.travel/GETDESC.php";
var tmp;
var myAjax = new Ajax.Request( 
						     	URL	, {
										method: 'get',
										parameters: 'idweb='+Idweb,
										onComplete:function(t,json) {
										tmp=t.responseText;
										}
	} );

	return tmp; 

}

function AddAll()
{
//var gx = new GGeoXml("http://www.chambres-hotes.org/GGE/?idweb=full");
var gx = new GGeoXml("http://www.chambresdhotes.travel/KML.php");
	map.addOverlay(gx);	
}

function AddWysiwig()
{
var limites= map.getBounds();	
var sw=limites.getSouthWest();
var ne=limites.getNorthEast();
var GEOURL="http://www.chambresdhotes.travel/KJSON.php";
$('REPORT').innerHTML="CHARGEMENT DES ETABLISSEMENTS EN COURS ...";
$('REPORT').setStyle({backgroundColor:"#FF3366"});
var myAjax = new Ajax.Request( 
						    	GEOURL	, {
										method: 'get',
										parameters: 'lngsw='+sw.lng()+'&lngne='+ne.lng()+'&latne='+ne.lat()+'&latsw='+sw.lat(),
										onComplete:function(t,json) {
										$('REPORT').innerHTML="CHARGEMENT DES ETABLISSEMENTS : COMPLET";
										$('REPORT').setStyle({backgroundColor:"#D6FF59"});
										if(map.getZoom()==11 || map.getZoom()==12)
										{
										$('REPORT').innerHTML="ATTENTION: VOUS POUVEZ SAUVEGARDER CETTE VUE <a class=\"saveit\" onClick=\"javascript:SaveIt()\">CLIQUEZ ICI</a><br/>- Pour la partager <br/>- Pour faire d&eacute;couvrir cette r&eacute;gion";
										$('REPORT').setStyle({backgroundColor:"#FFFF00"});
										}
									//	$('REPORT').innerHTML="JSON OK"; 
									//	alert("yo:"+json.length);
												for(i=0;i<json.length;i++)
												{
											//	alert(" "+json[i].LNG+" "+json[i].TITRE);
												var tmpref=json[i].REF;

												if(LALISTE[tmpref]!='EXIST') 
													{
												//	alert("add");
													LALISTE[tmpref]='EXIST';
													AddOne(json[i].LAT,json[i].LNG,tmpref,json[i].TYPE,json[i].VALIDE,json[i].PRIX);
													}
												}		
										}
	} );


//map.addOverlay(gx);	

}

function OLDAddWysiwig()
{
var limites= map.getBounds();	
var sw=limites.getSouthWest();
var ne=limites.getNorthEast();
var GEOURL="http://www.chambresdhotes.travel/KML.php?lngsw="+sw.lng()+"&lngne="+ne.lng()+"&latne="+ne.lat()+"&latsw="+sw.lat();
//$('REPORT').innerHTML="Chargement zone : "+GEOURL;
var gx = new GGeoXml(GEOURL, function() {
	if(gx.hasLoaded() == true){ 
//	$('REPORT').innerHTML="Chargement terminé ";
		alert("here 3 "); 
		if(gx.loadedCorrectly() == true)
			{ 
			//$('REPORT').innerHTML="";
			alert("it has loaded correctly !!"); 
			
			}
			else
			{ 
			//$('REPORT').innerHTML="Erreur de chargement";
			    alert("it is not loaded correctly !!"); 
			} 
	}
	else 
	{
		alert("not");
	//$('REPORT').innerHTML="Chargement en cours ";
	}
});

map.addOverlay(gx);	

}

function AddMoveLoc()
{
GEvent.addListener(map, 'moveend',
    function(){ 
      GetInfoLoc();
    });
}


function AddMove()
{
GEvent.addListener(map, 'moveend',
    function(){ 
      GetInfo();
    });
}

function AddMover()
{

GEvent.addListener(map, 'dragend',
    function(){ 
		//alert(this.getZoom());
		if(this.getZoom()>7)
		{
     // this.clearOverlays();
	 // alert("Cleared");
	   AddWysiwig();
		}
    });
GEvent.addListener(map, 'zoomend',
    function(){ 
		if(this.getZoom()>6)
		{
     //	this.clearOverlays();
	 	// alert("Cleared");
	   	AddWysiwig();
		}
    });
}



function AddCroix()
{
	croix = new GScreenOverlay('cross.gif',
        new GScreenPoint(375, 244, 'pixels', 'pixels'),  // screenXY
        new GScreenPoint(0, 0),  // overlayXY
        new GScreenSize(50, 50)  // size on screen
      );
    map.addOverlay(croix);	
}

function GetInfo()
{
	var MYGLatLngBounds=map.getBounds();
	var MYcenter=MYGLatLngBounds.getCenter();
	//alert(MYcenter.lat()+" "+MYcenter.lng());
	$('lgt').value=MYcenter.lng();
	$('lat').value=MYcenter.lat();
	$('ENDIT').innerHTML="<input type=\"button\" name=\"Submit\" value=\"Mon etablissement est precisement au milieu du carre : Finaliser l\'inscription CLIQUEZ ICI \" class=\"btfin\" onclick=\"javascript:Finalize()\">";
}

function GetInfoLoc()
{
	var MYGLatLngBounds=map.getBounds();
	var MYcenter=MYGLatLngBounds.getCenter();
	//alert(MYcenter.lat()+" "+MYcenter.lng());
	$('lgt').value=MYcenter.lng();
	$('lat').value=MYcenter.lat();
	$('zoom').value=map.getZoom();
}

function SaveIt()
{
//		var tmp=GetLimites();
//	alert(tmp[0]+" "+tmp[1]+" "+tmp[2]+" "+tmp[3]);
	var url    = 'getform.php';
	var rand   = Math.random(9999);
	var pars   = 'rand=' + rand;
	var myAjax = new Ajax.Request( 
									url, {
										method: 'post',
										parameters: pars, 	
										onComplete:function(t,json) {
										 		$('REPORT').innerHTML=t.responseText;
    										}
	} );
}

function SaveItNow()
{
	var MYGLatLngBounds=map.getBounds();
	var MYcenter=MYGLatLngBounds.getCenter();
//'&Name='+$F('Name')+

	var url    = 'SaveItNow.php';
	var rand   = Math.random(9999);
	var pars   = 'rand=' + rand+'&Name='+$F('Name')+'&LAT='+MYcenter.lat()+'&LNG='+MYcenter.lng()+'&ZOOM='+map.getZoom();
	var myAjax = new Ajax.Request( 
									url, {
										method: 'post',
										parameters: pars, 	
										onComplete:function(t,json) {
										 		$('REPORT').innerHTML=t.responseText;
    										}
	} );
}

function myzoom(a) {
	a > 0 ? map.zoomIn('', false, true): map.zoomOut('', true);
}

function mymove(a,b) {
	map.panDirection(a,b);
}

function affiche_marker(i) {
	map.panTo(aMarkers[i].getPoint());
	aMarkers[i].openInfoWindowHtml(aMarkersHtml[i]);
	aMarkers[i].setImage(icon_ville1.image);
}

function affiche_marker2(i) {
	map.panTo(aMarkers[i].getPoint());
	aMarkers[i].openInfoWindowHtml(aMarkersHtml[i]);
	//aMarkers[i].setMarkerZIndex (600000);
}

function revert_marker(i) {
	aMarkers[i].setImage(icon_annonce.image);
	//aMarkers[i].setMarkerZIndex (1);
}

function wheelZoom(a) {
	if (!a) a = window.event; 
	if (a.preventDefault) a.preventDefault(); 
	a.returnValue = false; 

	//if(a.cancelable){
	//	a.preventDefault();
	//}
	//(a.detail || -a.wheelDelta) < 0 ? map.zoomIn('', false, true): map.zoomOut('', true);
	//return false;
}

function changeType(a){
	if(a=='sat'){
		map.setMapType(G_SATELLITE_TYPE);
	}

	if(a=='route'){
		map.setMapType(G_MAP_TYPE);
	}
}

