Conf = new function() {
	
	var xmlConf = "../xml/conf/prevision10jours.conf.xml";
	var listName = [];
	var listValue = [];
	var confReady = false;
	
	this.init = function() {

		getXml();
	}
	
	this.getValue = function(name) {
		
		return getValue(name);
	}
	
	this.isConfReady = function() {
		return confReady;
	}
	
	var getXml = function() {
		
		dojo.io.bind({
			url: xmlConf,
			load: getXmlResultHandler,
			error: errorHandler,
			mimetype: "text/html"
		});	
	}
	
	var getXmlResultHandler = function(type, data, evt) {
		//alert(data);
		parseConfXml(data);
	}
	
	var errorHandler = function(type, errObj) {
		//alert(type +' : '+ errObj)
	}
	
	var parseConfXml = function(data) {
		var xml = GXml.parse(data);
		var listItem = xml.documentElement.getElementsByTagName("item");
		for (var i = 0; i < listItem.length; i++) {
			var tag = listItem[i];
			//alert(tag.getAttribute("name").toString());
			listValue[tag.getAttribute("name").toString()] = tag.getAttribute("value").toString();
		}
		confReady = true;
	}
	
	var getValue = function(name) {
		if (listValue[name]) {
			var t = listValue[name];
			if (t == "true") t = true;
			if (t == "false") t = false;
		} else {
			alert("["+name+"]");
		}
		return t;
	}
}

Lang = new function() {
	
	var listName = [];
	var listValue = [];
	var langReady = false;
	var listLang = [];
	var dynLang = false;
	
	this.init = function(lang) {

		getLang(lang);
	}
	
	this.getValue = function(name) {
		
		return getValue(name);
	}
	
	this.isLangReady = function() {
		return langReady;
	}
	
	var getLang = function (lang) {
		if (Conf.isConfReady() == false) {
			setTimeout(function() { getLang(lang) }, 50);
		} else {
			getXml(lang)
		}
	}
		
	var clicLang = function(e) {
		var element = e.target;
		//alert(element.id.replace('Lang', ''))
		document.location = Fisheye.getUrlDeLaPage(element.id.replace('Lang', ''));
		//dynChangeLang(element.id.replace('Lang', ''));
		//dynLang = true;
		//alert(Fisheye.getUrlDeLaPage(element.id.replace('Lang', '')))
	}
	
	var dynChangeLang = function(lang) {
		
		listName = [];
		listValue = [];
		getXml(lang);
	}
	
	
	var getXml = function(lang) {
		
		dojo.io.bind({
			url: "../xml/lang/prevision10jours/lang.php?lang="+lang,
			load: getXmlResultHandler,
			error: errorHandler,
			mimetype: "text/html"
		});	
	}
	
	var getXmlResultHandler = function(type, data, evt) {
		//alert(data);
		parseLangXml(data);
	}
	
	var errorHandler = function(type, errObj) {
		//alert(type +' : '+ errObj)
	}
	
	var parseLangXml = function(data) {
		var xml = GXml.parse(data);
		var listItem = xml.documentElement.getElementsByTagName("item");
		for (var i = 0; i < listItem.length; i++) {
			var tag = listItem[i];
			listValue[tag.getAttribute("name").toString()] = tag.getAttribute("value").toString();
		}
		langReady = true;
	}
	
	var getValue = function(name) {
		if (listValue[name]) {
			var t = listValue[name];
			if (t == "true") t = true;
			if (t == "false") t = false;
			if (t == undefined) t = "";
		} else {
			alert(name);	
		}
		return t;
	}
	
	var reinitModules = function() {
		//Fisheye.init();
		Historique.init();
		Calendrier.init();
	}
}

// JavaScript Document
Navigator = new function() {
	
	var IE6 = false;
	var IE7 = false;
	var FIREFOX2 = false;
	var FIREFOX = false;
	var NETSCAPE7 = false;
	var NETSCAPE = false;
	var OPERA9 = false;
	var OPERA = false;
	var AUTRE = false;
  
  	this.supportSearchEngine = function() {
 		if (window.external && ("AddSearchProvider" in window.external)) {
			return true;
 		} else if (window.sidebar && ("addSearchEngine" in window.sidebar)) {
			return true;
		} 
		return false;
	}
   	this.installSearchEngine = function(url, icon, name) {
 		if (window.external && ("AddSearchProvider" in window.external)) {
   			// Firefox 2 and IE 7, OpenSearch
   			window.external.AddSearchProvider(url);
 		} else if (window.sidebar && ("addSearchEngine" in window.sidebar)) {
   			// Firefox <= 1.5, Sherlock
   			window.sidebar.addSearchEngine(url,
            		                      icon,
                    		              name, "");
 		} else {
   			// No search engine support (IE 6, Opera, etc).
   			alert("No search engine support");
 		}	
 	}
 
  	/**
     *
	 * */
	this.isIE7 = function() {
		return IE7;	
	}
  
  	/**
     *
	 * */
	this.isIE6 = function() {
		return IE6;	
	}
  
  	/**
     *
	 * */
	this.isFirefox2 = function() {
		return FIREFOX2;
	}
  
  	/**
     *
	 * */
	this.isFirefox = function() {
		return FIREFOX;	
	}
  
  	/**
     *
	 * */
	this.isNetscape7 = function() {
		return NETSCAPE7;
	}
  
  	/**
     *
	 * */
	this.isNetscape = function() {
		return NETSCAPE;	
	}
  
  	/**
     *
	 * */
	this.isOpera9 = function() {
		return OPERA9;
	}
  
  	/**
     *
	 * */
	this.isOpera = function() {
		return OPERA;
	}
  
  	/**
     *
	 * */
	this.isAutre = function() {
		return AUTRE;
	}
	
	this.getNavigator = function() {
		if (IE7) return "IE7";
		if (IE6) return "IE6";
		if (FIREFOX2) return "FIREFOX2";
		if (FIREFOX) return "FIREFOX";
		if (NETSCAPE7) return "NETSCAPE7";
		if (NETSCAPE) return "NETSCAPE";
		if (OPERA9) return "OPERA9";
		if (OPERA) return "OPERA";
		if (AUTRE) return "AUTRE";
	}
  
  	/**
     *
	 * */
	this.init = function() {
		
		var strChUserAgent = navigator.userAgent;
		var intSplitStart = strChUserAgent.indexOf("(",0);
		var intSplitEnd = strChUserAgent.indexOf(")",0);
		var strChStart = strChUserAgent.substring(0,intSplitStart);
		var strChMid = strChUserAgent.substring(intSplitStart, intSplitEnd);
		var strChEnd = strChUserAgent.substring(strChEnd);
		
		if (strChMid.indexOf("MSIE 7") != -1) {
			IE7 = true;
		} else if(strChMid.indexOf("MSIE 6") != -1) {
			IE6 = true;
		} else if(strChEnd.indexOf("Firefox/2") != -1) {
			FIREFOX2 = true;
		} else if(strChEnd.indexOf("Firefox") != -1) {
			FIREFOX = true;
		} else if(strChEnd.indexOf("Netscape/7") != -1) {
			NETSCAPE7 = true;
		} else if(strChEnd.indexOf("Netscape") != -1) {
			NETSCAPE = true;
		} else if(strChStart.indexOf("Opera/9") != -1) {
			OPERA9 = true;
		} else if(strChStart.indexOf("Opera") != -1) {
			OPERA = true;
		} else {
			AUTRE = true;
		}
	}
}

Board = new function() {

	var teteIsShow = false;
	var inputList = ['q', 'q2', 'searchInput', 'prenomInviterUnAmi', 'emailInviterUnAmi', 'prenomAmiInviterUnAmi', 'emailAmiInviterUnAmi'];

	/**
	 *
	 * */
	this.init = function () {
				
		unselectable();
		hideUseless();
		hideLoader();
		showMLNPO();
		GEvent.addDomListener(document, 'click', function(event) { 
			var id = event.target.id;
			if (id != 'searchInput') {
				WZSearch.closeResult(); 
			}
		});
		//dojo.byId('SplitContainerTout').style.height = (document.body.clientHeight - dojo.byId('tete').style.height.replace('px','')-5)+'px';
		
		GEvent.addDomListener(dojo.byId('mainContainer_spacer'), "click", function() {
			MapAction.changeSize();
		});
		if (MLNPO.getInDebug()) {
			debug();	
			Trace.init();
		}
		
	}
	
	var bodyResizeHandler = function(e) {
		alert("i'm here")	
	}
	
	/************ INIT *******************/
	 
	/**
	 *
	 * */
	var unselectable = function() {
		
		if (!MLNPO.getInDebug()) {
			document.oncontextmenu = function(){return false;} ;
			
			//if IE4+
			document.onselectstart=new Function ("return false")
			
			//if NS6
			if (window.sidebar)
			{
				document.onmousedown=disableselect
				document.onclick=reEnable
			}
		}
	}
	
	/**
	 *
	 * */
	var disableselect = function(e) {	
	
		for (var i = 0; i < inputList.length; i++) {
			if (e.target.id == inputList[i]) {
				return true;	
			}
		}
		return false;
	}
	
	/**
	 *
	 * */
	var reEnable = function() { 
	
		return true 
	}

	
	/**
	 *
	 * */
	var hideUseless = function() {
		
		for (var i = 0; i < 10; i++) {
			if (dojo.byId('TexteMeteoJour'+(i+1)+'Vent')) {
				dojo.byId('TexteMeteoJour'+(i+1)+'Vent').style.display = "none";
				dojo.byId('TexteMeteoJour'+(i+1)+'Pluie').style.display = "none";
				dojo.byId('TexteMeteoJour'+(i+1)+'Humidite').style.display = "none";
				dojo.byId('TexteMeteoJour'+(i+1)+'Lever').style.display = "none";
				dojo.byId('TexteMeteoJour'+(i+1)+'Coucher').style.display = "none";
			}
		}
	}
	
	/**
	 *
	 * */
	var debug = function() {

		dojo.byId('debug').style.display = "block";
		switch (MLNPO.getInDebugLevel()) {
			case "0":
				dojo.byId('debugInfoCentreCarte').style.display = "block";
				break;
			case "1":
				dojo.byId('debugInfoGeneral').style.display = "block";
				dojo.byId('debugInfoCentreCarte').style.display = "block";
				GEvent.addDomListener(dojo.byId('getDebug'), "click", getDebug);
				break;
			default:
				alert('['+MLNPO.getInDebugLevel()+']');
				break;
		}	
	}
	
	/**
	 *
	 * */
	var getDebug = function(e) {
	
		dojo.byId('nomContinent').innerHTML = MLNPO.getNomContinent();
		dojo.byId('nomPays').innerHTML = MLNPO.getNomPays();
		dojo.byId('nomLieuMeteo').innerHTML = MLNPO.getNomLieuMeteo();
		dojo.byId('nomLieu').innerHTML = MLNPO.getNomLieu();
		
		dojo.byId('idContinent').innerHTML = MLNPO.getIdContinent();
		dojo.byId('idPays').innerHTML = MLNPO.getIdPays();
		dojo.byId('idLieuMeteo').innerHTML = MLNPO.getIdLieuMeteo();
		dojo.byId('idLieu').innerHTML = MLNPO.getIdLieu();
		
		dojo.byId('latVille').innerHTML = MLNPO.getLatVille();
		dojo.byId('longVille').innerHTML = MLNPO.getLongVille();
		dojo.byId('zoomVille').innerHTML = MLNPO.getZoomVille();
		
		dojo.byId('latPays').innerHTML = MLNPO.getLatVille();
		dojo.byId('longPays').innerHTML = MLNPO.getLongVille();
		dojo.byId('zoomPays').innerHTML = MLNPO.getZoomVille();

		dojo.byId('latPays').innerHTML = MLNPO.getLatPays();
		dojo.byId('longPays').innerHTML = MLNPO.getLongPays();
		dojo.byId('zoomPays').innerHTML = MLNPO.getZoomPays();
		
		dojo.byId('latContinent').innerHTML = MLNPO.getLatContinent();
		dojo.byId('longContinent').innerHTML = MLNPO.getLongContinent();
		dojo.byId('zoomContinent').innerHTML = MLNPO.getZoomContinent();
		
		dojo.byId('typeMap').innerHTML = MapAction.getTypeMap();
		dojo.byId('numJourMap').innerHTML = Calendrier.getLastSelected();
		dojo.byId('paysContinentMap').innerHTML = MapAction.getVillePaysContinent();
		
		var gll = GoogleMap.getCenter();
		dojo.byId('currentLat').innerHTML = gll.lat();
		dojo.byId('currentLong').innerHTML = gll.lng();
		dojo.byId('currentZoom').innerHTML = 17-GoogleMap.getZoom()
	}
	
	/**
	 *
	 * */
	var hideLoader = function() {
		dojo.byId('beta').style.display = "none";
		//dojo.byId('loader').style.display = "none";
		dojo.byId('divChargement').style.display = "none";
		dojo.byId('divChargementPlus').style.display = "none";
	}
	
	/**
	 *
	 * */
	var showMLNPO = function() {
	
		dojo.byId('mainContainer').style.visibility = 'visible';
	}	
}

var popupJour1, popupJour2, popupJour3, popupJour4, popupJour5;
var popupJour6, popupJour7, popupJour8, popupJour9, popupJour10;

Calendrier = new function() {
	
	var NBRE_JOUR = 10;
	var SK_ID_BUTTON = "jour";
	var SK_ID_BUTTON_MAP = "jourMap";
	var SK_INFO_METEO = "infoMeteoJour";
	var SK_DATE = "date";
	
	var texteJourSpeciaux;
	var isPlay = false;
	var aBlocker = false;
	var lastSelected = 1;
	var tempUnitSelected;
	var speedUnitSelected;

	/**
	 *
	 * */
	this.init = function() {
		for (var i = 1; i <= NBRE_JOUR; ++i) {
			if (i != lastSelected) {
				if (dojo.byId(SK_INFO_METEO+i)) {
					dojo.byId(SK_INFO_METEO+i).style.display = 'none';
					dojo.byId(SK_DATE+i).style.display = 'none';
				} else {
					NBRE_JOUR = i-1;	
				}
			}
		}
		texteJourSpeciaux = [[1,Lang.getValue('aujourdhui')],[2,Lang.getValue('demain')],[3,Lang.getValue('apresDemain')],[8,Lang.getValue('dansUneSemaine')]];
		initPopup();
		initCal();
		initPub();
		initMeteoInfo();
		initChangeTemp();
		initChangeSpeed();
	}

	this.preInit = function() {
		tempUnitSelected = Lang.getValue('tempUnit');
		speedUnitSelected = Lang.getValue('vitesseUnit');
	}
	
	this.initPub = function() {
		initPub();
	}

	/**
	 *
	 * */
	this.getLastSelected = function() {
		return lastSelected;
	}
	
	/**
	 *
	 * */
	this.setSelectedJour = function(jour) {
		if (lastSelected != jour) {
			setAll(jour)
		}
	}
	
	/**
	 *
	 * */
	this.showLoad = function() {
		showLoad();
	}
	
	/**
	 *
	 * */
	var initMeteoInfo = function() {
		
		for (var i = 1 ; i < NBRE_JOUR; i++) {
			if (dojo.byId('infoMeteoJour'+(i+1))) {
				dojo.lfx.html.fadeOut('infoMeteoJour'+(i+1), 0).play();
				GEvent.addDomListener(dojo.byId('date'+i), "click", openInfoPopup);
				GEvent.addDomListener(dojo.byId('moreInfo'+i), "click", openInfoPopup);
				GEvent.addDomListener(dojo.byId('moreEvolution'+i), "click", function() { TabManager.changeTab(2) });
			}
		}
		dojo.lfx.html.fadeIn(SK_INFO_METEO+lastSelected, 500).play();
	}
	
	var openInfoPopup = function(e) {
		var i = this.id.replace("date", "").replace("moreInfo","");
		eval("popupJour"+i+".show()");
	}
	
	var initChangeTemp = function() {
		for (var i = 1 ; i <= NBRE_JOUR; i++) {
			if (dojo.byId('changeTemperatureC'+i)) {
				if (Lang.getValue('tempUnit') == "c") {
					dojo.byId('changeTemperatureC'+i).checked = true;
					dojo.byId('changeTemperatureF'+i).checked = false;
				} else {
					dojo.byId('changeTemperatureC'+i).checked = false;
					dojo.byId('changeTemperatureF'+i).checked = true;
				} 
				GEvent.addDomListener(dojo.byId('changeTemperatureC'+i), "click", function (e) { doChangeTemp('c') });
				GEvent.addDomListener(dojo.byId('changeTemperatureF'+i), "click", function (e) { doChangeTemp('f') });
			}
		} 
	}
	
	var doChangeTemp = function(type) {
		switch (type) {
			case "c":
				for (var i = 1; i <= NBRE_JOUR; i++) {
					if (dojo.byId('changeTemperatureC'+i)) {
						dojo.byId('changeTemperatureC'+i).checked = true;
						dojo.byId('changeTemperatureF'+i).checked = false;
					}
				}
				tempUnitSelected = "c";
				break;
			case "f":
				for (var i = 1; i <= NBRE_JOUR; i++) {
					if (dojo.byId('changeTemperatureC'+i)) {
						dojo.byId('changeTemperatureC'+i).checked = false;
						dojo.byId('changeTemperatureF'+i).checked = true;
					}
				}
				tempUnitSelected = "f";
				break;
			default:
				break;
		}
		MLNPO.changeTemp(type, true);
	}
	
	var initChangeSpeed = function() {
		for (var i = 1 ; i <= NBRE_JOUR; i++) {
			if (dojo.byId('changeVitesseKH'+i)) {
				if (Lang.getValue('vitesseUnit') == "km") {
					dojo.byId('changeVitesseKH'+i).checked = true;
					dojo.byId('changeVitesseMH'+i).checked = false;
				} else {
					dojo.byId('changeVitesseKH'+i).checked = false;
					dojo.byId('changeVitesseMH'+i).checked = true;
				}
				GEvent.addDomListener(dojo.byId('changeVitesseKH'+i), "click", function (e) {doChangeSpeed('km')});
				GEvent.addDomListener(dojo.byId('changeVitesseMH'+i), "click", function (e) {doChangeSpeed('m')});
			}
		} 
	}
	
	var doChangeSpeed = function(type) {
		switch (type) {
			case "km":
				for (var i = 1; i < NBRE_JOUR; i++) {
					if (dojo.byId('changeVitesseKH'+i)) {
						dojo.byId('changeVitesseKH'+i).checked = true;
						dojo.byId('changeVitesseMH'+i).checked = false;
					}
				}
				speedUnitSelected = "km";
				break;
			case "m":
				for (var i = 1; i < NBRE_JOUR; i++) {
					if (dojo.byId('changeVitesseKH'+i)) {
						dojo.byId('changeVitesseKH'+i).checked = false;
						dojo.byId('changeVitesseMH'+i).checked = true;
					}
				}
				speedUnitSelected = "m";
				break;
			default:
				break;
		}
		MLNPO.changeSpeed(type, true);
	}
	
	/**
	 *
	 * */
	var initPub = function() {
		
		var idPays = MLNPO.getIdPays();
		var nomLieuMeteo = MLNPO.getNomLieuMeteo();
		var nomLieu = MLNPO.getNomLieu();
		var currentTime = new Date();
		googleAdCalendrier.location = "2.0/ads.php?h=250&w=300&e=0ads_al&idPays="+idPays+"&nomLieuMeteo="+nomLieuMeteo+"&nomLieu="+nomLieu+"&s=" + currentTime.getTime() + "03&lang="+Lang.getValue('ext')+"&p=false";
	}
	
	/**
	 *
	 * */
	var initCal = function() {
		
		for (var i = 1; i <= NBRE_JOUR; i++) {
			if (dojo.byId(SK_ID_BUTTON+i)) {
				GEvent.addDomListener(dojo.byId(SK_ID_BUTTON+i), "click", doAction);
				GEvent.addDomListener(dojo.byId(SK_ID_BUTTON_MAP+i), "click", doActionMap);
			}
		}
		if (dojo.byId('changeMapPlay')) {
			GEvent.addDomListener(dojo.byId('changeMapPlay'), "click", startDefil);
			GEvent.addDomListener(dojo.byId('changeMapStop'), "click", stopDefil);
		}
	}
	
	/**
	 *
	 * */
	var startDefil = function(e) {
		
		isPlay = true;
		dojo.byId('changeMapPlay').style.display = "none";
		dojo.byId('changeMapStop').style.display = "inline";
		play(getNextDay(lastSelected));
	}
	
	/**
	 *
	 * */
	var initPopup = function() {
		
		popupJour1 = dojo.widget.byId("popupJour1");
		popupJour1.setCloseControl(dojo.byId("btn_popupJour1"));
		
		popupJour2 = dojo.widget.byId("popupJour2");
		popupJour2.setCloseControl(dojo.byId("btn_popupJour2"));
	
		popupJour3 = dojo.widget.byId("popupJour3");
		popupJour3.setCloseControl(dojo.byId("btn_popupJour3"));
	
		popupJour4 = dojo.widget.byId("popupJour4");
		popupJour4.setCloseControl(dojo.byId("btn_popupJour4"));
		
		if (dojo.byId("popupJour5")) {	
			popupJour5 = dojo.widget.byId("popupJour5");
			popupJour5.setCloseControl(dojo.byId("btn_popupJour5"));
		}
		if (dojo.byId("popupJour6")) {		
			popupJour6 = dojo.widget.byId("popupJour6");
			popupJour6.setCloseControl(dojo.byId("btn_popupJour6"));
		}
		if (dojo.byId("popupJour7")) {	
			popupJour7 = dojo.widget.byId("popupJour7");
			popupJour7.setCloseControl(dojo.byId("btn_popupJour7"));
		}
		if (dojo.byId("popupJour8")) {
			popupJour8 = dojo.widget.byId("popupJour8");
			popupJour8.setCloseControl(dojo.byId("btn_popupJour8"));
		}
		if (dojo.byId("popupJour9")) {
			popupJour9 = dojo.widget.byId("popupJour9");
			popupJour9.setCloseControl(dojo.byId("btn_popupJour9"));
		}
		if (dojo.byId("popupJour10")) {
			popupJour10 = dojo.widget.byId("popupJour10");
			popupJour10.setCloseControl(dojo.byId("btn_popupJour10"));
		}
	}
	
	/**
	 *
	 * */
	var play = function(jour) {
		
		if (aBlocker == false) {
			aBlocker = true;
			setAll(jour);
			
			setTimeout(function() { 
				if(isPlay == true) {
					play(getNextDay(jour)); 
				}
			}, 3000);
			
			setTimeout(function() { 
				aBlocker = false;
			}, 2950);
		}
	}

	/**
	 *
	 * */
	var stopDefil = function (e) {
		
		dojo.byId('changeMapStop').style.display = "none";
		dojo.byId('changeMapPlay').style.display = "inline";
		isPlay = false;
		debloque();	
	}
	
	/**
	 *
	 * */
	var doAction = function(e) {
		
		if (aBlocker == false) {
			aBlocker = true;
			
			var element = e.target;
			var jour = element.id.replace(SK_ID_BUTTON, "");
			
			setAll(jour);
			debloque();	
		}
		return false;
	}
	
	/**
	 *
	 * */
	var doActionMap = function(e) {
		
		if (aBlocker == false) {
			aBlocker = true;
			
			var element = e.target;
			var jour = element.id.replace(SK_ID_BUTTON_MAP, "");
			
			setAll(jour);
			debloque();	
		}
		return false;
	}
	
	/**
	 *
	 * */
	var setAll = function(jour) {
		
		setImg(jour);
		setText(jour);
		setInfoJour(jour);
		setDateJour(jour);
		lastSelected = jour;
		setMap();
	}
	
	/**
	 *
	 * */
	var setMap = function() {
	
		MapAction.setNewContentOnMap();
	}
	
	/**
	 *
	 * */
	var setInfoJour = function(jour) {
		
		var localLastSelected = lastSelected;
		
		dojo.lfx.html.fadeOut(SK_INFO_METEO+localLastSelected, 500).play();
		WZMoonPhase.change(jour);
		setTimeout(function() {
			dojo.byId(SK_INFO_METEO+localLastSelected).style.display = "none";
			dojo.byId(SK_INFO_METEO+jour).style.display = "block";
			dojo.lfx.html.fadeIn(SK_INFO_METEO+jour, 500).play();
		},500);
	}
	
	/**
	 *
	 * */
	var setDateJour = function(jour) {
		
		dojo.byId(SK_DATE+lastSelected).style.display = "none";
		dojo.byId(SK_DATE+jour).style.display = "block";
	}
	 
	/**
	 *
	 * */
	var setImg = function(jour) {

		var lastElement = dojo.byId(SK_ID_BUTTON+lastSelected);
		var element = dojo.byId(SK_ID_BUTTON+jour);
		lastElement.src = lastElement.src.replace("_selected.gif", ".gif");
		element.src = element.src.replace(".gif", "_selected.gif");

		var lastElementMap = dojo.byId(SK_ID_BUTTON_MAP+lastSelected);
		var elementMap = dojo.byId(SK_ID_BUTTON_MAP+jour);
		lastElementMap.src = lastElement.src.replace(".gif", ".png");
		elementMap.src = element.src.replace(".gif", ".png");
	}
	
	/**
	 *
	 * */
	var setText = function(jour) {
		
		var bool = false;
		
		for (var i = 0; i < texteJourSpeciaux.length; i++) {
			if (jour == texteJourSpeciaux[i][0]) {
				Fisheye.setDescription(texteJourSpeciaux[i][1]);
				bool = true;
				break;
			}
		}
		if (bool == false) {
			Fisheye.setDescription(sprintf(Lang.getValue('dansXjour'), (jour-1)));
		}
	}
	
	/**
	 *
	 * */
	var debloque = function() {
		setTimeout(function() { 
			aBlocker = false;
		}, 750);
	}
	
	/**
	 *
	 * */
	var getNextDay = function (jour) {
		var day = jour-1+2;
		if (day == NBRE_JOUR+1) {
			day = 1
		}
		return day;
	}
	
	
	/**
	 *
	 * */
	var showLoad = function() {
		
		dojo.byId('ImageMeteoJour'+lastSelected+'Jour').src= Conf.getValue('urlBaseStatic')+'img/loader/small_128x128.gif';
		dojo.byId('ImageMeteoJour'+lastSelected+'Nuit').src= Conf.getValue('urlBaseStatic')+'img/loader/small_128x128.gif';
	}
	
	/**
	 *
	 * */
	this.getTempUnitSelected = function () {
		return tempUnitSelected;	
	}
	this.getSpeedUnitSelected = function () {
		return speedUnitSelected;	
	}

}

EvolutionAccordion = new function() {

	var IMG_LOADER = '';

	/**
	 *
	 * */
	this.init = function() {
		IMG_LOADER = Conf.getValue('urlBaseStatic')+'img/loader/small_250x140.gif';
	}

	/**
	 *
	 * */
	this.selectLast = function() { 
		selectLast();	
	}

	/**
	 *
	 * */
	this.showLoad = function() {
		showLoad();	
	}

	/**
	 *
	 * */
	var selectLast = function() {
		
		var wid = dojo.widget.byId("AccordionContainerEvolution");
		wid.selectChild(wid.children[3]);	
	}

	/**
	 *
	 * */
	var showLoad = function() {
		
		dojo.byId('ImageEvolutionTemperature').src = IMG_LOADER;
		dojo.byId('ImageEvolutionVent').src = IMG_LOADER;
		dojo.byId('ImageEvolutionHumidite').src = IMG_LOADER;
		dojo.byId('ImageEvolutionPrecipitation').src = IMG_LOADER;
	}
}

var Dlg0, Dlg4;

// singleton fisheye
Fisheye = new function() {
	
	var listItem;
	var saveContentDesc = "";
	
	/*********************************************/
	/**			Methode Public					**/
	/*********************************************/
	/**
	 *
	 * */
	this.init = function() {
		listItem = [['inviter', Lang.getValue('inviterAmi'), 'Dlg0.show();'], ['urlPage', Lang.getValue('recupereURL'), 'document.location = gup();'], ['addThis',Lang.getValue('ajoutFavoris'), 'add();']];
		initItem()
		initPopup();
		InviterAmi.init();
	}
		
	/**
	 *
	 * */
	this.setDescription = function(value) {
		
		setDescription(value)
	}
	
	/**
	 *
	 * */
	this.openItem = function(value) {
	
		openItem(value);
	}
	
	/**
	 *
	 * */
	this.gup = function(lang) {
		
		return gup(lang);
	}
	
	this.getRssDeLaPage = function(lang) {
		return getRssDeLaPage(lang);
	}
	this.getKmlDeLaPage = function(lang) {
		return getKmlDeLaPage(lang);
	}
	
	
	/*********************************************/
	/**			Methode Private					**/
	/*********************************************/
	
	/**
	 *
	 * */
	var initItem = function() {
		
		for (var i = 0; i < listItem.length; i++) {
			var fItem = dojo.byId(listItem[i][0]);
			GEvent.addDomListener(fItem, "click", doAction);
			
		}
	}
	
	/**
	 *
	 * */
	var setDescription = function(value) {
		saveContentDesc = dojo.byId('infoFisheyeContent').innerHTML;
		dojo.byId('infoFisheyeContent').innerHTML = value;
	}
	
	/**
	 *
	 * */
	var initPopup = function() {
		
		Dlg0 = dojo.widget.byId("dialog0");
		Dlg0.setCloseControl(dojo.byId("hider0"));
	}
	
	
	/**
	 *
	 * */
	var setDesc = function(e) {

		var element = e.target.parentNode;
		
		for (var i = 0; i < listItem.length; i++) {
			if (element.id == listItem[i][0]) {
				setDescription(listItem[i][1]);
			}
		}
	}
	
	/**
	 *
	 * */
	var restoreDesc = function(e) {
		
		dojo.byId('infoFisheyeContent').innerHTML = saveContentDesc;
	}
	
	/**
	 *
	 * */
	var doAction = function(e) {
		openItem(e.target.id)
	}
	
	/**
	 *
	 * */
	var openItem = function(id) {
		
		for (var i = 0; i < listItem.length; i++) {
			if (id == listItem[i][0]) {
				eval(listItem[i][2]);
			}
		}	
	}
	
	/**
	 *
	 * */
	var mailUrl = function() {
		var c = "mailto:?subject="+Lang.getValue('sujetMailEnvoyerURL')+"&body="+gup();
		location.href = c;
	}
	
	/**
	 *
	 * */
	var add =  function() {
		addthis_url = gup();
		addthis_title = document.title; 
		return addthis_click();
	}
	
	/**
	 * Fonction qui renvoit l'URL format� de la page actuelle
	 */
	var gup = function(lg) {
		
		if (lg == undefined) {
			lg = Lang.getValue('ext');	
		}
		
		var idPays = MLNPO.getIdPays();
		var idLieuMeteo = MLNPO.getIdLieuMeteo();
		var idLieu = MLNPO.getIdLieu();
		
		var nomPays = MLNPO.getUrlNomPays();
		var nomLieuMeteo = MLNPO.getUrlNomLieuMeteo();
		var nomLieu = MLNPO.getUrlNomLieu();
		
		var retour = Conf.getValue(lg+'UrlBaseComplete');

		// on est sur un pays
		if (nomPays != '' && nomLieuMeteo == '')
			retour += sprintf(Conf.getValue(lg+'LinkPays'), nomPays, idPays);
		// on est sur une ville avec meteo
		else if (nomPays != '' && nomLieuMeteo != '' && nomLieu == '')
			retour += sprintf(Conf.getValue(lg+'LinkLieuMeteo'), nomLieuMeteo, nomPays, idPays, idLieuMeteo);
		else if (nomPays != '' && nomLieuMeteo != '' && nomLieu != '')
			retour += sprintf(Conf.getValue(lg+'LinkLieu'), nomLieu, nomPays, idPays, idLieuMeteo, idLieu);	
		return retour;
	}
	
	var getRssDeLaPage = function(lg) {
		return gup().replace(".html", ".xml");	
	}
	
	var getKmlDeLaPage = function(lg) {
		return gup().replace(".html", ".kml");	
	}
	
}


Historique = new function() {
	
	var COOKIE_HISTORIQUE_NAME = 'cookieHistorique';
	var COOKIE_COLOR_NAME = 'cookieColor';
	var cssNumber = 13;
	
	/**
	 *
	 * */
	this.init = function() {
		for (var i = 1; i <= cssNumber; i++) {
			GEvent.addDomListener(dojo.byId('css'+i), 'click', function() {
				dojo.lfx.html.fadeOut('mainContainer', 300).play();
				var obj = this;
				setTimeout(function() {
					dojo.byId('css').href = 'css_'+obj.className+'.css';
					var c = new Cookie(COOKIE_COLOR_NAME);
					var date = c.getDateCookie();
					c.setCookie(obj.className, date, "/");
					setTimeout(function() {
						dojo.lfx.html.fadeIn('mainContainer', 200).play();
						//dojo.byId('tout').style.fontStyle = "Verdana";
					}, 400);
				}, 300);
			});
		}

		setPositionByCookie();
	}
		
	/**
	 *
	 * */
	this.add = function() {
	
		setPositionByCookie();
	}
	
	/**
	 *
	 * */
	var del = function(e) {
		
		var element = e.target.parentNode;
		var c = new Cookie(COOKIE_HISTORIQUE_NAME);
		var currentContent = c.getCookie();
		var date = c.getDateCookie();
		
		currentContent = deleteAlreadyRegistred(currentContent, element.id.replace('_del', ''));
		c.setCookie(currentContent, date, "/");
		showCurrentHistorique(c.getCookie());
	}

	
	/**
	 *
	 * */
	var setPositionByCookie = function() {
		
		var c = new Cookie(COOKIE_HISTORIQUE_NAME);
		var newContent = getNewContentCookie();	
		var date = c.getDateCookie();
		var currentContent = c.getCookie();
		
		currentContent = deleteAlreadyRegistred(currentContent, newContent);	
		c.setCookie(newContent+'_'+currentContent, date, "/");
		showCurrentHistorique(c.getCookie())
	}
	
	/**
	 *
	 * */
	var getNewContentCookie = function() {
		
		var idLieu = MLNPO.getIdLieu();
		var idLieuMeteo = MLNPO.getIdLieuMeteo();
		var idPays = MLNPO.getIdPays();
		
		if (idLieu == '') { 
			idLieu = '0';
		}
		return idLieu+"-"+idLieuMeteo+"-"+idPays;
	}
	
	/**
	 *
	 * */
	var deleteAlreadyRegistred = function(currentContent, newContent) {

		var r = currentContent.split(newContent+'_');
		while (r.length > 1) {
			currentContent = currentContent.replace(newContent+'_', '');
			r = currentContent.split(newContent+'_');
		}
		
		return currentContent;
	}	
	
	/**
	 *
	 * */
	var showCurrentHistorique = function(value) {
		dojo.io.bind({
			url: "2.0/historique.php?c="+value+"&lang="+Lang.getValue('ext'),
			load: showCurrentHistoriqueResultHandler,	
			mimetype: "text/html"
		});
	}
	
	/**
	 *
	 * */
	var showCurrentHistoriqueResultHandler = function(type, data, evt) {
		dojo.byId('historique').innerHTML = data;
		initItem();
	}
		
	/**  
	 *
	 * */
	var initItem = function() {
		
		var historiqueContainer = dojo.byId('historique');
		var arrayMeteo = historiqueContainer.getElementsByTagName('a');

		for (var i = 0; i < arrayMeteo.length; i++) {
			GEvent.addDomListener(arrayMeteo[i].parentNode, "mouseover", showDeleteOption);		
			GEvent.addDomListener(arrayMeteo[i], "click", loadMeteo);
		}
	}
	 
	/**
	 *
	 * */
	var loadMeteo = function(e) {
		
		//currentIdPays = MLNPO.getIdPays();
		var element = e.currentTarget;
		var idArray = element.id.split('-');
		var idLieu = idArray[0];
		var idLieuMeteo = idArray[1];
		var idPays = idArray[2];
		
		//EvolutionAccordion.showLoad();
		Calendrier.showLoad();
		
		if (MLNPO.getIdPays() == idPays) {
			ListeVille.loadInfoVilleByIds(idLieuMeteo, idLieu);
		} else {
			ListePays.loadInfoPaysById(idPays, idLieuMeteo, idLieu);
		}
	}
	
	/**
	 *
	 * */
	var loadMeteoResultHandler = function() {
		//if (currentIdPays != MLNPO.getIdPays())
		MapAction.vpc('pays');
		ListeVille.init();
		Historique.add();
	}
	
	/**
	 *
	 * */
	var showDeleteOption = function(e) {
		
		var element = e.target;
		var historiqueContainer = dojo.byId('historique');
		var arrayMeteo = historiqueContainer.getElementsByTagName('a');

		for (var i = 0; i < arrayMeteo.length; i++) {
			var elementDel = dojo.byId(arrayMeteo[i].id+'_del')			
			if (element.id == arrayMeteo[i].id) {
				elementDel.style.display = "block";
				GEvent.addDomListener(elementDel, "click", del); 
			} else if (element.id != '') {
				elementDel.style.display = "none";
			}
		}
	}
}


var InfoMeteo = function() {
	
	this.index;
	this.tempMax;
	this.tempMin;
	this.iconJour;
	this.iconNuit;
	this.humidite;
	this.pluie;
	this.heureLever;
	this.heureCoucher;
	this.vitesseVent;
	this.directionVent;
	
	this.InfoMeteo = function(aIndex, aTempMax, aTempMin, aIconJour, aIconNuit, aHumidite, aPluie, aHeureLever, aHeureCoucher, aVitesseVent, aDirectionVent) {
		/*
		alert(aTempMax);
		this.index = aIndex;
		this.tempMax = aTempMax;
		this.tempMin = aTempMin;
		this.iconJour = aIconJour;
		this.iconNuit = aIconNuit;
		this.humidite = aHumidite;
		this.pluie = aPluie;
		this.heureLever = aHeureLever;
		this.heureCoucher = aHeureCoucher;
		this.vitesseVent = aVitesseVent;
		this.directionVent = aDirectionVent;
		*/
	}
}

ListePays = new function() {
	
	var RECHERCHE;
	var ajaxBlocker = false;
	
	/**
	 *
	 * */
	this.init = function() {
		
		//RECHERCHE = Lang.getValue('recherche')
		
		//searchInit();
		//initPub();
		initPaysByContainer('nuageTagPays');
	}
	
	/**
	 *
	 * */
	this.loadInfoPaysById = function(idPays, idLieuMeteo, idLieu) {
		loadInfoPaysById(idPays, idLieuMeteo, idLieu);
	}
	 
	
	/**************** INIT *******************/
	/**
	 *
	 * */
	var searchInit = function() {
		dojo.byId('q2').value = RECHERCHE;
		GEvent.addDomListener(dojo.byId('q2'), "click", searchOnClick);
		GEvent.addDomListener(dojo.byId('q2'), "keyup", searchPays);
	}
		
	/**
	 *
	 * */
	var initPub = function() {
		var nomPays = dojo.byId('nomPays').innerHTML;
		var nomLieuMeteo = dojo.byId('nomLieuMeteo').innerHTML;
		var nomLieu = dojo.byId('nomLieu').innerHTML;
		var currentTime = new Date();
		
		googleadPays.location = "2.0/ads.php?h=200&w=200&e=as&nomPays="+nomPays+"&nomLieuMeteo="+nomLieuMeteo+"&nomLieu="+nomLieu+"&s=" + currentTime.getTime() + "01&p=false&lang="+Lang.getValue('ext');
	
		GEvent.addDomListener(dojo.byId('googleadPaysContainer'), "mouseover", function(e) { dojo.byId('googleadPaysContainer').style.backgroundColor = '#EAEAEA' } );
		GEvent.addDomListener(dojo.byId('googleadPaysContainer'), "mouseout", function(e) { dojo.byId('googleadPaysContainer').style.backgroundColor = '#FFFFFF' } );
	}
	
	
	/**************** FIN INIT  *******************/
	
	/**************** RECHERCHE *******************/
	/**
	 *
	 * */
	var searchOnClick = function(e) {
		
		var element = e.target;
		if (element.value == RECHERCHE) {
			element.value = "";
		}
	}
	
	/**
	 *
	 * */
	var searchPays = function(e) {
		
		if (ajaxBlocker == false) {
			ajaxBlocker = true;
			var element = e.target;
			
			MeteoAccordion.showLoad();
			
			dojo.io.bind({
				url: "2.0/recherchePays.php?q="+element.value+"&lang="+Lang.getValue('ext'),
				load: searchPaysResultHandler,
				mimetype: "text/javascript"
			});
		}
	}
	
	/**
	 *
	 * */
	var searchPaysResultHandler = function() {
		
		ajaxBlocker = false;
		MeteoAccordion.hideLoad();
		initPaysByContainer('result_q2');
	}

	/**************** FIN RECHERCHE *******************/
	
	/**************** LOAD INFO     *******************/
	/**
	 *
	 * */
	var loadInfoPays = function(e) {
		
		var element = e.target;
		if (element.id == '') {
			element = element.parentNode;
		}
		var idPays = element.id.replace('pays_', '');
		loadInfoPaysById(idPays);
	}
	
	/**
	 *
	 * */
	var loadInfoPaysById = function(idPays, idLieuMeteo, idLieu) {
		MapAction.showIconCountry(true)
		MapAction.setZoomInit(false);
		if (idLieuMeteo == undefined) {	
			idLieuMeteo = "";	
		}
		if (idLieu == undefined) {
			idLieu = "";	
		}
		
		dojo.io.bind({
			url: "2.0/changeCountry.php?id="+idPays+"&idLieuMeteo="+idLieuMeteo+"&idLieu="+idLieu+"&lang="+Lang.getValue('ext'),
			load: loadInfoPaysResultHandler,
			mimetype: "text/html"
		});
		
		showLoad();
		//MeteoAccordion.selectLast();
		//EvolutionAccordion.selectLast();
		Calendrier.setSelectedJour(1);
		//MeteoAccordion.hideLoad();
		//ListeVille.uninit();
	}
	
	
	/**
	 *
	 * */
	var loadInfoPaysResultHandler = function(type, data, evt) {
		WoozorXHR.setXHRPays(data);
		MapAction.showIconCountry(false)
		MLNPO.setNewInterface("pays");
		ListeVille.init();
		MapAction.vpc('pays');
		Historique.add();
		
	}
													   
													 
	
	/**************** FIN LOAD INFO     *******************/
	
	/**
	 *
	 * */
	var showLoad = function() {
		
		//MeteoAccordion.showLoad();
		EvolutionAccordion.showLoad();
		Calendrier.showLoad()
	}

	/**
	 *
	 * */
	var initPaysByContainer = function(id) {
		var paysContainer = dojo.byId(id);
		var arrayPays = paysContainer.getElementsByTagName('a');
		
		for (var i = 0; i < arrayPays.length; i++) {
			GEvent.addDomListener(arrayPays[i], "click", loadInfoPays);
		}
	}
	
	/**
	 *
	 * */
	var changeBackgroundColor = function(e, color) {
		
		e.target.style.backgroundColor = color;
	}
}

ListeVille = new function() {
	
	var RECHERCHE;
	var ajaxBlocker = false;
	
	/**
	 *
	 * */
	this.init = function() {
		
		//RECHERCHE = Lang.getValue('recherche')
		//searchInit();
		//initPub();
		initVilleByContainer('nuageTagVille');
	}
	
	this.uninit = function() {
		if (dojo.byId('result_q').innerHTML != '') {
			dojo.byId('result_q').innerHTML = '';
		}
		//dojo.byId('googleadVille').style.display = "none";
	}
	
	this.loadInfoVilleByIds = function(idLieuMeteo, idLieu) {
		
		loadInfoVilleByIds(idLieuMeteo, idLieu);
	}
	
	/**************** INIT *******************/
	/**
	 *
	 * */
	var searchInit = function() {
		dojo.byId('q').value = RECHERCHE;
		GEvent.addDomListener(dojo.byId('q'), "click", searchOnClick);
		GEvent.addDomListener(dojo.byId('q'), "keyup", searchVille);
	}
		
	/**
	 *
	 * */
	var initPub = function() {
		var nomPays = MLNPO.getNomPays();
		var nomLieuMeteo = MLNPO.getNomLieuMeteo();
		var nomLieu = MLNPO.getNomLieu();
		var currentTime = new Date();
		
		googleadVille.location = "2.0/ads.php?h=200&w=200&e=as&nomPays="+nomPays+"&nomLieuMeteo="+nomLieuMeteo+"&nomLieu="+nomLieu+"&s=" + currentTime.getTime() + "01&p=false&lang="+Lang.getValue('ext');
		GEvent.addDomListener(dojo.byId('googleadVilleContainer'), "mouseover", 
										function() {dojo.byId('googleadVilleContainer').style.backgroundColor = '#EAEAEA'});
		GEvent.addDomListener(dojo.byId('googleadVilleContainer'), "mouseout", 
										function() {dojo.byId('googleadVilleContainer').style.backgroundColor = '#FFFFFF'});
		
		/*if (dojo.byId('googleadVille').style.display = "none") {
			dojo.byId('googleadVille').style.display = "block";
		}*/
	}
	
	
	/**************** FIN INIT  *******************/
	
	/**************** RECHERCHE *******************/
	/**
	 *
	 * */
	var searchOnClick = function(e) {
		var t = e.target;
		if (t.value == RECHERCHE) {
			t.value = "";
		}	
	}
	
	/**
	 *
	 * */
	var searchVille = function(e) {
		
		if (ajaxBlocker == false) {
			ajaxBlocker = true;
			var element = e.target;
			var idPays = MLNPO.getIdPays();
			
			MeteoAccordion.showLoad();
			
			dojo.io.bind({
				url: "2.0/recherche.php?q="+element.value+"&id="+idPays+"&lang="+Lang.getValue('ext'),
				load: searchVilleResultHandler,
				mimetype: "text/javascript"
			});
		}
	}
	
	/**
	 *
	 * */
	var searchVilleResultHandler = function() {
		
		ajaxBlocker = false;
		MeteoAccordion.hideLoad();
		initVilleByContainer('result_q');
	}
		 
	/**************** FIN RECHERCHE *******************/
	
	/**
	 *
	 * */
	var loadInfoVille = function(e) {
		
		var element = e.target;
		var idArray = element.id.replace('ville_', '').split('_');
		var idLieuMeteo = idArray[0];
		var idLieu = idArray[1];
		loadInfoVilleByIds(idLieuMeteo, idLieu);
		
	}
	
	/**
	 *
	 * */
	var loadInfoVilleByIds = function(idLieuMeteo, idLieu) {
		showLoad();
		
		dojo.io.bind({
			url: "2.0/changeCity.php?idLieuMeteo="+idLieuMeteo+"&idLieu="+idLieu+"&lang="+Lang.getValue('ext'),
			load: loadInfoVilleResultHandler,
			mimetype: "text/html"
		});
	}
	
	/**
	 *
	 * */
	var showLoad = function() {
		
		//MeteoAccordion.showLoad();
		//EvolutionAccordion.showLoad();
		Calendrier.showLoad()
	}
	
	/**
	 *
	 * */
	var loadInfoVilleResultHandler = function(type, data, evt) {
		WoozorXHR.setXHRVille(data);
		MLNPO.setNewInterface();
		//MeteoAccordion.hideLoad();
		Historique.add();
		MapAction.followCity();
		MapAction.addPin();
	}
	
	/**
	 *
	 * */
	var initVilleByContainer = function(id) {
		var villeContainer = dojo.byId(id);
		var arrayVille = villeContainer.getElementsByTagName('a');
		
		for (var i = 0; i < arrayVille.length; i++) {
			GEvent.addDomListener(arrayVille[i], "click", loadInfoVille);
		}
	}
}

MapAction = new function() {

	var IMG_FOLDER = "";
	var MENU_MAP_IMG_FOLDER = "";
	var XML_FOLDER = "";
	
	var villePaysContinent = "pays";
	var typeMap = "soleil";
	var isIconOnMap = true;
	
	var currentIdPays = "";
	var currentMarker = "";
	
	var size = "half";
	var zoomInit = true;
	
	var markerList = [];
	var countryMarkerList = [];
	
	var countryIconSize = 32;
	
	/*************************************/
	/**				PUBLIC				**/
	/*************************************/
	/**
	 *
	 * */
	this.init = function() {
		IMG_FOLDER = Conf.getValue('urlBaseStatic')+"img/"
		MENU_MAP_IMG_FOLDER = Conf.getValue('urlBaseStatic')+"img/menuMap/"
		XML_FOLDER = "../xml/";
		this.createMap();
		setMiddleControlImg('');
		setTopControlImg();
		setMoveAndZoomVPC();
		setNewContentOnMap();
		GoogleMap.setMapType(G_PHYSICAL_MAP); //  G_SATELLITE_MAP
		//GoogleMap.setMapType();
		// this was buggy on the last version of the googleMap
		var adsManager = new GAdsManager(GoogleMap, "pub-9189697428741326");
		adsManager.enable();
		//initCloudLayer();
		loadCountry();
	}
		
	var loadCountry = function() {
		GDownloadUrl("2.0/countryList.php?lang="+Lang.getValue('ext'), function(data, responseCode) 
		{
			if(responseCode == 200) 
			{
				//alert(data);
				var xml = GXml.parse(data);
				var markers = xml.documentElement.getElementsByTagName("marker");
				var len = markers.length;
				var i = 0;
				var marker;
				var point;
				var id = 0;
				var icon_01;
				var dMarker;
				
				for (i = 0; i < len; ++i) 
				{
					marker = markers[i];
					point = new GLatLng(parseFloat(marker.getAttribute("lat")), parseFloat(marker.getAttribute("lng")));
					id = marker.getAttribute("id");
					
					icon_01 = new GIcon();
					icon_01.image = marker.getAttribute("icon");
					icon_01.iconSize = new GSize(countryIconSize, countryIconSize);
					icon_01.iconAnchor = new GPoint(countryIconSize/2, countryIconSize/2);
					
					dMarker = new GMarker(point, {"icon" : icon_01, "title" : marker.getAttribute("title")});
					countryListener(dMarker, id);
					countryMarkerList[id] = dMarker;
					
					GoogleMap.addOverlay(dMarker);
					
					if (MLNPO.getIdPays() == id) {
						dMarker.hide();
					}
				}
				updateCountry();
			}
		} );
	}
	
	var updateCountry = function() {
		var i = 0;
		var len = countryMarkerList.length;
		var marker;
		var point;
		var icon;
		
		var newIcon;
		var newPoint;
		var newMarker;
		
		var iconSize = 32;
		var zoom = GoogleMap.getZoom();
		//alert(zoom)
		if (zoom == 3) {
			iconSize = 24
		} else if (zoom == 2) {
			iconSize = 16
		} else if (zoom == 1 || zoom == 0) {
			iconSize = 8;	
		}
		if (iconSize == countryIconSize) {
			return;	
		}
		countryIconSize = iconSize;
		//alert(countryIconSize);
		//alert(GoogleMap.getZoom());
		for (i = 0; i < len; ++i) {
			//alert(i)
			marker = countryMarkerList[i];
			if (marker) {
				GoogleMap.removeOverlay(marker);
				
				point = marker.getLatLng();
				icon = marker.getIcon();
				
				newIcon = new GIcon();
				newIcon.image = icon.image;
				newIcon.iconSize = new GSize(countryIconSize, countryIconSize);
				newIcon.iconAnchor = new GPoint(countryIconSize/2, countryIconSize/2);
				
				newMarker = new GMarker(point, {"icon" : newIcon, "title" : marker.getTitle()});
				countryListener(newMarker, i);
				countryMarkerList[i] = newMarker;
				
				GoogleMap.addOverlay(newMarker);
				
					
				if (MLNPO.getIdPays() == i) {
					newMarker.hide();
				}
			}
		}
	}
	
	var countryListener = function(dMarker , id) {
		GEvent.addListener(dMarker, "click", function() {
			loadInfoPays(id);								  
		});
	}
	
	this.showIconCountry = function(show) {
		if (countryMarkerList[MLNPO.getIdPays()]) {
			if (show == true) {
				countryMarkerList[MLNPO.getIdPays()].show();
			} else {
				countryMarkerList[MLNPO.getIdPays()].hide();
			}
		}
	
	}
	
	var mapTopControl;
	var mapMiddleControl;
	var mapChangeDayControl;
	var gScaleControl;
	var gSmallMapControl;
	var gMenuMapTypeControl;
	
	this.createMap = function() {
		GoogleMap = new GMap2(dojo.byId("Map"));
		GoogleMap.enableDoubleClickZoom();
		GoogleMap.enableContinuousZoom();
		GoogleMap.enableScrollWheelZoom();
		GoogleMap.addMapType(G_PHYSICAL_MAP);
		GoogleMap.addMapType(G_SATELLITE_3D_MAP)
		
		
		mapTopControl = 		new MapTopControl();
		mapMiddleControl = 		new MapMiddleControl();
		mapChangeDayControl = 	new MapChangeDayControl();
		gScaleControl = 		new GScaleControl();
		gSmallMapControl = 		new GSmallMapControl();
		gMenuMapTypeControl = 	new GMenuMapTypeControl();
		
		GoogleMap.addControl(mapTopControl);
		GoogleMap.addControl(mapMiddleControl);		
		GoogleMap.addControl(mapChangeDayControl);
		GoogleMap.addControl(gScaleControl);
		if (Lang.getValue('isCssReverse') == true) {
			GoogleMap.addControl(gSmallMapControl, new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(3,5)));
			GoogleMap.addControl(gMenuMapTypeControl, new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(53,7)));
		} else {
			GoogleMap.addControl(gSmallMapControl, new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(3,5)));
			GoogleMap.addControl(gMenuMapTypeControl, new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(53,7)));
		}
		GEvent.addListener(GoogleMap, 'maptypechanged', mapTypeChangeHandler)
		//GoogleMap.addControl(new GMenuMapTypeControl());
		dojo.byId('Map').style.width = "100%";
		dojo.byId('Map').style.height = "100%";
		GoogleMap.checkResize();
		
		GEvent.addListener(GoogleMap, "zoomend", customMap);
		GEvent.addListener(GoogleMap, "dragend", customMap);
	}
	
	var mapTypeChangeHandler = function() {
		if (this.getCurrentMapType().getName() == "Earth") {
			GoogleMap.removeControl(mapTopControl);
			GoogleMap.removeControl(mapMiddleControl);
			GoogleMap.removeControl(mapChangeDayControl);
			GoogleMap.removeControl(gScaleControl);
			GoogleMap.removeControl(gSmallMapControl);
			GoogleMap.removeControl(gMenuMapTypeControl);
			dojo.byId('infoFisheye').style.display = 'none';
			dojo.byId('googleWidgetOnMap').style.display = 'none';
			dojo.byId('mainContainer_spacer').id = 'mainContainer_spacer_no_move';
		}
	}
	
	this.setZoomInit = function(value) {
		zoomInit = zoomInit;
	}
	
	var customMap = function() {
		//alert('ici');
		//alert((17 - MLNPO.getZoomPays())+ " < "+ (GoogleMap.getZoom()-1))
		if (villePaysContinent == "pays") {
			if (zoomInit) {											  
				zoomInit = false;
			} else {
				clearMap();
				var gLatLngBounds = GoogleMap.getBounds();
				var sw = gLatLngBounds.getSouthWest();
				var ne = gLatLngBounds.getNorthEast();
				showContentOnMap("2.0/customCountryMap.php?id="+MLNPO.getIdPays()+"&z="+(17-GoogleMap.getZoom())+"&lang="+Lang.getValue("ext")+"&date="+Calendrier.getLastSelected()+"&minLat="+sw.lat()+"&maxLat="+ne.lat()+"&minLng="+sw.lng()+"&maxLng="+ne.lng());				
			}
		}
	}
	
	/**
	 *
	 * */
	this.addPin = function() {
		addPin();
	}
	
	/**
	 * appeler depuis MapTopControl
	 * */
	this.vpc = function(aVpc) {
		
		villePaysContinent = aVpc;
		
		switch(aVpc) {
			case "ville": 
				hideMiddleControl(true);
				hideChangeDayControl(true);
				setMiddleControlImg("transparent");
				clearMap();
				isIconOnMap = false;
				break;
			case "pays":
				//zoomInit = true;
				hideMiddleControl(false);
				hideChangeDayControl(false);
				setMiddleControlImg('');
				setNewContentOnMap();
				isIconOnMap = true;
				break; 
			case "continent":
				hideMiddleControl(false);
				hideChangeDayControl(false);
				setMiddleControlImg('');
				setNewContentOnMap();
				isIconOnMap = true;
				break;
		}
		setMoveAndZoomVPC();
		setTopControlImg(); 
	}
	
	/**
	 * appeler depuis MapMiddleControl
	 * */
	this.slv = function (aSlv) {
		
		typeMap = aSlv;
		setNewContentOnMap();
	}
	
	/**
	 * appeler depuis Calendrier
	 * */
	this.setNewContentOnMap = function() {
		setNewContentOnMap();
	}
	
	/**
	 * appeler depuis certain requete ajax
	 * */
	this.moveAndZoom = function(lat, lng, z) {
		moveAndZoom(lat, lng, z)
	}
	
	/**
	 *
	 * */
	this.getTypeMap = function() {
		return typeMap;
	}
	
	/**
	 *
	 * */
	this.getVillePaysContinent = function() {
		return villePaysContinent;
	}
	
	/**
	 * appeler depuis la bulle de la carte
	 * */
	this.loadInfoPays = function(value) {
		loadInfoPays(value);
	}
	
	/**
	 * appeler depuis la bulle de la carte
	 * */
	this.loadInfoVille = function(value) {
		
		loadInfoVille(value);
	}
	
	/**
	 *
	 * */
	this.followCity = function() {
		
		switch (villePaysContinent) {
			case "ville":			
				var lat = MLNPO.getLatVille();
				var lng = MLNPO.getLongVille();
				var z = MLNPO.getZoomVille();
				moveAndZoom(lat, lng, z); 
				break;
				
			default:
				break;
		}
	}
	
	this.changeSize= function(value) {
		changeSize(value);
	}
	this.getSize = function() {
		return size;	
	}
	
	/*************************************/
	/**				PRIVATE				**/
	/*************************************/	
	
	var changeSize = function(value) {
		if (GoogleMap.getCurrentMapType().getName() == "Earth") {
			return;	
		}

		if (value == undefined) {
			value = size;
		}

		if (value == "half") {	
			dojo.lfx.html.fadeOut('mainContainer_1', 200).play();
			setTimeout(function() {
				dojo.byId('mainContainer_2').style.overflow = "";
				dojo.byId('mainContainer_2').style.zIndex = "3";
				if (Lang.getValue('isCssReverse') == true) {
					dojo.lfx.html.slideTo('Map', { top: 0, right: -(dojo.byId("mainContainer_1").offsetWidth) },  400).play();
					dojo.lfx.html.propertyAnimation('Map', [{property: "width", end:  dojo.byId("mainContainer").offsetWidth-17}], 400).play();			
					dojo.byId('mainContainer_spacer').style.right = '5px';
				} else {
					dojo.lfx.html.slideTo('Map', { top: 0, left: -(dojo.byId("mainContainer_1").offsetWidth)-0 },  400).play();
					dojo.lfx.html.propertyAnimation('Map', [{property: "width", end:  dojo.byId("mainContainer").offsetWidth-10}], 400).play();			
					dojo.byId('mainContainer_spacer').style.left = '5px';
				}

				setTimeout(function() {
					hideChangeDayControl(false);
					GoogleMap.checkResize();
					if ((17-GoogleMap.getZoom()) == MLNPO.getZoomPays()) {
						GoogleMap.panTo(new GLatLng(MLNPO.getLatPays(), MLNPO.getLongPays()));
					}
				}, 400);
			}, 200);
			size = "full";
		} else {

			hideChangeDayControl(true);
			dojo.byId('mainContainer_spacer').style.display = 'none';
			setTimeout(function () {
				if (Lang.getValue('isCssReverse') == true) {
					dojo.lfx.html.slideTo('Map', { top: 0, right: 0 },  400).play()
				} else {
					dojo.lfx.html.slideTo('Map', { top: 0, left: 0 },  400).play()
				}
				dojo.lfx.html.propertyAnimation('Map', [{property: "width", end: (dojo.byId("mainContainer_2").offsetWidth)}], 400).play();	

				setTimeout(function () {
					dojo.byId('mainContainer_2').style.zIndex = "0";
					dojo.byId('mainContainer_2').style.overflow = "hidden";
					GoogleMap.checkResize();
					if ((17-GoogleMap.getZoom()) == MLNPO.getZoomPays()) {
						GoogleMap.panTo(new GLatLng(MLNPO.getLatPays(), MLNPO.getLongPays()));
					}
					dojo.byId('mainContainer_spacer').style.display = 'block';
					if (Lang.getValue('isCssReverse') == true) {
						dojo.byId('mainContainer_spacer').style.right = '325px';
					} else {
						dojo.byId('mainContainer_spacer').style.left = '325px';
					}
					
					dojo.lfx.html.fadeIn('mainContainer_1', 200).play();
					//IE sucks
					//dojo.byId('tabContentContainer').style.fontFamily = "Verdana";
				}, 400);
			}, 400);
			size = "half";
		} 
		
	}
	
	/**
	 *
	 * */
	var setNewContentOnMap = function() {
		
		var xml = getXml();
		//alert(xml)
		if (xml != '') {
			clearMap();
			showContentOnMap(xml);
		}
	}
	
	/**
	 *
	 * */
	var moveAndZoom = function(lat, lng, z) {
		//GoogleMap.setZoom(z);
		//GoogleMap.set
		if (!GoogleMap.isLoaded()) {
			GoogleMap.setCenter(new GLatLng(lat, lng), 17-z);
		} else if ((17-z) == GoogleMap.getZoom()) {
			GoogleMap.panTo(new GLatLng(lat, lng)); 
		} else {
			GoogleMap.panTo(new GLatLng(lat, lng));
			setTimeout(function() {
				GoogleMap.setCenter(new GLatLng(lat, lng), 17-z);
			}, 1000);
			//GoogleMap.zoomIn();
		}
	}
	
	/**
	 *
	 * */
	var setMoveAndZoomVPC = function() {
		
		switch (villePaysContinent) {
			case "ville":			
				var lat = MLNPO.getLatVille();
				var lng = MLNPO.getLongVille();
				var z = MLNPO.getZoomVille();
				break;
			case "pays":
				var lat = MLNPO.getLatPays();
				var lng = MLNPO.getLongPays();
				var z = MLNPO.getZoomPays();
				break;
			case "continent":
				var lat = MLNPO.getLatContinent();
				var lng = MLNPO.getLongContinent();
				var z = MLNPO.getZoomContinent();
				break;
		}
		moveAndZoom(lat, lng, z);
	}
	
	/**
	 *
	 * */
	var setTopControlImg = function() {
		
		/*switch (villePaysContinent) {
			case "ville":			
				dojo.byId('mapTopControlIcon3').src = MENU_MAP_IMG_FOLDER+'navVille.png';
				dojo.byId('mapTopControlIcon2').src = MENU_MAP_IMG_FOLDER+'navPays.png';
				dojo.byId('mapTopControlIcon1').src = MENU_MAP_IMG_FOLDER+'navContinentChoisi.png';
				break;
			case "pays":
				dojo.byId('mapTopControlIcon3').src = MENU_MAP_IMG_FOLDER+'navVille.png';
				dojo.byId('mapTopControlIcon2').src = MENU_MAP_IMG_FOLDER+'navPaysChoisi.png';
				dojo.byId('mapTopControlIcon1').src = MENU_MAP_IMG_FOLDER+'navContinent.png';
				break;
			case "continent":
				dojo.byId('mapTopControlIcon3').src = MENU_MAP_IMG_FOLDER+'navVilleChoisi.png';
				dojo.byId('mapTopControlIcon2').src = MENU_MAP_IMG_FOLDER+'navPays.png';
				dojo.byId('mapTopControlIcon1').src = MENU_MAP_IMG_FOLDER+'navContinent.png';
				break;
		}*/
	}
	
	/**
	 *
	 * */
	var hideMiddleControl = function(bool) {
		//if (bool == false) {
		//	dojo.lfx.html.fadeIn('menuMapContainerMiddle', 200).play();
		//	dojo.lfx.html.slideTo('menuMapContainerMiddle', { top: 114, left: 0 },  400).play()
		//} else {
		//	dojo.lfx.html.fadeOut('menuMapContainerMiddle', 400).play();
		//	dojo.lfx.html.slideTo('menuMapContainerMiddle', { top: 114, left: -50 }, 400).play()
		//}
	}
	
	var hideChangeDayControl = function(bool) {
		if (!dojo.byId('menuMapContainerChangeDay')) {
			return;	
		}
		
		if (size == "full") {
			if (Lang.getValue('isCssReverse')) {
				if (bool == false && villePaysContinent != "ville") {
					dojo.byId('menuMapContainerChangeDay').style.display = "block";				
					dojo.lfx.html.slideTo('menuMapContainerChangeDay', { top: 228, left: dojo.byId('mainContainer').offsetWidth- 298 },  400).play();
				} else {
					dojo.lfx.html.slideTo('menuMapContainerChangeDay', { top: 228, left: dojo.byId('mainContainer').offsetWidth },  400).play();
					setTimeout(function () {
						dojo.byId('menuMapContainerChangeDay').style.display = "none";	
					}, 400);
				}
			} else {
				if (bool == false && villePaysContinent != "ville") {
					dojo.byId('menuMapContainerChangeDay').style.display = "block";				
					dojo.lfx.html.slideTo('menuMapContainerChangeDay', { top: 228, left: 0 },  400).play();
				} else {
					dojo.lfx.html.slideTo('menuMapContainerChangeDay', { top: 228, left: -285 },  400).play();
					setTimeout(function () {
						dojo.byId('menuMapContainerChangeDay').style.display = "none";	
					}, 400);
				}
			}
		}
	}
	
	/**
	 *
	 * */
	var setMiddleControlImg = function(type) {
		dojo.byId('changeMapVent').src = MENU_MAP_IMG_FOLDER+'manche'+type+'.png';
		dojo.byId('changeMapSoleil').src = MENU_MAP_IMG_FOLDER+'changeMapSoleil'+type+'.png';
		dojo.byId('changeMapTempMin').src = MENU_MAP_IMG_FOLDER+'changeMapLune'+type+'.png';
	}
	
	/**
	 *
	 * */
	var addPin = function(force) {
		var zoom = GoogleMap.getZoom();
		
		if (zoom > 3) {
			var lat = MLNPO.getLatVille();
			var lng = MLNPO.getLongVille();
			//if (lat != "" && lng != "") {
			var point = new GLatLng(parseFloat(lat), parseFloat(lng));
			if (currentMarker == "" || force == true) {	
				if (currentMarker != "") {
					GoogleMap.removeOverlay(currentMarker);
				}
				var icon = new GIcon();
				icon.image = IMG_FOLDER+"icone/pin/pin_red.png";
				icon.iconSize = new GSize(48, 48);
				icon.iconAnchor = new GPoint(38, 38);
					
				currentMarker = new GMarker(point, icon);
				GoogleMap.addOverlay(currentMarker);
			
			} else {
				currentMarker.setLatLng(point);
			}
		} else {
			//alert('tit '+zoom)
			if (currentMarker != "") {
				GoogleMap.removeOverlay(currentMarker);
				currentMarker = "";
			}
		}
		//}
	}
	
	/**
	 *
	 * */
	var getXml = function()
	{
		var xml = '';
		var idPays = MLNPO.getIdPays();
		var idContinent = MLNPO.getIdContinent();
		var jour = Calendrier.getLastSelected();	

		if ((villePaysContinent == "pays")) {// && idPays != currentIdPays) || isIconOnMap == false) {
				currentIdPays = idPays;
				var gLatLngBounds = GoogleMap.getBounds();
				var sw = gLatLngBounds.getSouthWest();
				var ne = gLatLngBounds.getNorthEast();
				xml = "2.0/customCountryMap.php?id="+idPays+"&z="+(17-GoogleMap.getZoom())+"&lang="+Lang.getValue("ext")+"&date="+(Calendrier.getLastSelected())+"&minLat="+sw.lat()+"&maxLat="+ne.lat()+"&minLng="+sw.lng()+"&maxLng="+ne.lng();				
			
		} else if (villePaysContinent == "continent") {
				var gLatLngBounds = GoogleMap.getBounds();
				var sw = gLatLngBounds.getSouthWest();
				var ne = gLatLngBounds.getNorthEast();
				xml = "2.0/customContinentMap.php?id="+idContinent+"&z="+(17-GoogleMap.getZoom())+"&lang="+Lang.getValue("ext")+"&date="+(Calendrier.getLastSelected())+"&minLat="+sw.lat()+"&maxLat="+ne.lat()+"&minLng="+sw.lng()+"&maxLng="+ne.lng();				
		}

		return xml;
	}
	
	/**
	 *
	 * */
	var clearMap = function () {
		var len = markerList.length;
		var item2;
		for (var i = 0; i < len; ++i) {
			item2 = markerList[i];
			if (item2) {
				GoogleMap.removeOverlay(item2);
			}
		}
		if (currentMarker != "") {
			//alert('removeOverlay');
			GoogleMap.removeOverlay(currentMarker);
		}
		markerList = [];
		currentMarker = "";
		//GoogleMap.clearOverlays();	
	}
	
	
	
	/**
	 *
	 * */
	var showContentOnMap = function(xml) {

		GDownloadUrl(xml, function(data, responseCode) 
		{
		// To ensure against HTTP errors that result in null or bad data,
		  // always check status code is equal to 200 before processing the data
			if(responseCode == 200) 
			{
				//alert( 16 - GoogleMap.getZoom()+" < "+MLNPO.getZoomPays())
				//alert(data);
				var xml = GXml.parse(data);
				var markers = xml.documentElement.getElementsByTagName("marker");
				for (var i = 0; i < markers.length; i++) 
				{
					var marker = markers[i];
					// le point
					var point = new GLatLng(parseFloat(marker.getAttribute("lat")), parseFloat(marker.getAttribute("lng")));
					
					//l'icone
					var icon_01 = new GIcon();
					var icon_02 = new GIcon();
					var icons = [];
					
					icons = getMapIcons(marker, i, markers.length);						
					icon_01 = icons[0];
					icon_02 = icons[1];
					if (icons[2]) {
						return;	
					}
					
					// la bulle
					var textHtmlShort = "";
					
					if (marker.getAttribute("nomPays") != null && villePaysContinent == "continent") {	
						textHtmlShort = "<h2 onclick=\"MapAction.loadInfoPays('"+marker.getAttribute("idPays")+"')\">"+sprintf(Lang.getValue('meteoEn'), " "+marker.getAttribute("nomPays"))+"</h2>";					
					} else if (marker.getAttribute("nomPays") == null) {
						textHtmlShort = "<h2 onclick=\"MapAction.loadInfoVille('"+marker.getAttribute("id")+"')\">"+sprintf(Lang.getValue('meteoA'), " "+marker.getAttribute("nom"))+"</h2>";
					}
					textHtmlShort += adsForInfoWindow(i);
					
					if (icon_01.image) {
						var mark1 = createMarker(point, icon_01, marker.getAttribute("nom"), textHtmlShort, marker.getAttribute("id"), marker.getAttribute("idPays"));
						markerList[markerList.length] = mark1;
						GoogleMap.addOverlay(mark1);
					}
					if (icon_02.image) {
						var mark2 = createMarker(point, icon_02, marker.getAttribute("nom"), "", marker.getAttribute("id"), marker.getAttribute("idPays"));
						markerList[markerList.length] = mark2;
						GoogleMap.addOverlay(mark2);
					}
					
				}
				//		var trafficManager = new GTrafficOverlay();
		//trafficManager.show();
		//GoogleMap.addOverlay(trafficManager)

				addPin(true);
			} 
			else if(responseCode == -1) 
			{
				//alert("Data request timed out. Please try later.");
				alert("Veuillez actualiser la fenêtre de votre navigateur. [101]");
			} 
			else 
			{ 
				alert("Veuillez actualiser la fenêtre de votre navigateur. [102]");
				//alert("Request resulted in error. Check XML file is retrievable.");
			}
		});
		updateCountry();
	}
	var c2f = function(t) {
		return Math.round(t*9/5 + 32);
	}
	var km2m = function(s) {
		return Math.round(s/1.609344);
	}

	/**
	 *
	 * */
	var loadInfoPays = function(value) {
		if (size == "full") {
			changeSize("full");
		}
		ListePays.loadInfoPaysById(value);
	}	
	
	/**
	 *
	 * */
	var loadInfoVille = function(value) {
		if (size == "full") {
			changeSize("full");
		}
		ListeVille.loadInfoVilleByIds(value, '0');
	}
	
	/**
	 *
	 * */
	var adsForInfoWindow = function(i) 
	{
		var textHtmlShort;
		
		switch (i % 2) 
		{
			case 0 :
				textHtmlShort = "<div style='font-size:9px; cursor:pointer; margin-top:15px;' onclick='Fisheye.openItem(\"inviter\")'>"+Lang.getValue('aimeProfiterAmi')+"</div>";
				break;
			case 1 :
				textHtmlShort = "<div style='font-size:9px; cursor:pointer; margin-top:15px;' onclick='Fisheye.openItem(\"addThis\")'>"+Lang.getValue('aimeAjouterFavoris')+"</div>";
				break;
			//case 2 :
			//	textHtmlShort = "<div style='font-size:9px; cursor:pointer; margin-top:15px;' onclick='Fisheye.openItem(\"don\")'>"+Lang.getValue('aimeFaireDon')+"</div>";
			//	break;
			default :
				break;	
		}
		return textHtmlShort;
	}
		
	/**
	 *
	 * */
	var createMarker = function (point, icon, title, longText, idLieuMeteo, idPays) {
		
	  	var marker = new GMarker(point, {"icon" : icon, "title" : title});
		
		GEvent.addListener(marker, "click", function() {
			GoogleMap.closeInfoWindow();
			if (longText != "") {
				marker.openInfoWindowHtml("<div class='GMapDivSmall'>"+longText+"</div>");
			}
			if (idPays != null) {
				loadInfoPays(idPays);
			} else {
				loadInfoVille(idLieuMeteo);
			}  
		});
		
		return marker;
	}
	
	var getMapIcons = function (marker, number, totalLen) {
		
		var fold = "";
		var firstIconFold = "";
		var firstIcon = ""
		var secondIconFold = "";
		var secondIcon = ""
		var gZoom = GoogleMap.getZoom();
		var pZoom = MLNPO.getZoomPays();
		var iconSizeLists = [];
		var size1_1;
		var size1_2;
		var size2_1;
		var size2_2;
		var funct;
		var block = false;
		for (var i = 0; i < 6; i++) {
			iconSizeLists[i] = [];
			iconSizeLists[i][0] = [];
			iconSizeLists[i][1] = [];
		}
		
		if (typeMap == 'soleil') {
			fold = Calendrier.getTempUnitSelected().replace("°","").toLowerCase();
			if (fold == "c") {
				funct = "returnFunction";	
			} else {
				funct = "c2f";
			}
			firstIconFold = "icone";
			firstIcon = "iconJour";
			secondIconFold = "iconeTemp";
			secondIcon = "tempMax";
			iconSizeLists[0][0] = [48, 48];
			iconSizeLists[0][1] = [41, 24];

			iconSizeLists[1][0] = [24, 24];
			
			iconSizeLists[2][0] = [32, 32];
			iconSizeLists[2][1] = [30, 18];

			iconSizeLists[3][0] = [128, 128];
			iconSizeLists[3][1] = [41, 24];
		
			iconSizeLists[4][0] = [64, 64];
			iconSizeLists[4][1] = [41, 24];
			
			iconSizeLists[5][0] = [48, 48];
			iconSizeLists[5][1] = [41, 24];
		} else if (typeMap == 'lune') {
			fold = Calendrier.getTempUnitSelected().replace("°","").toLowerCase();
			if (fold == "c") {
				funct = "returnFunction";	
			} else {
				funct = "c2f";
			}
			firstIconFold = "icone";
			firstIcon = "iconNuit";
			secondIconFold = "iconeTemp";
			secondIcon = "tempMin";
			iconSizeLists[0][0] = [48, 48];
			iconSizeLists[0][1] = [41, 24];

			iconSizeLists[1][0] = [24, 24];
			
			iconSizeLists[2][0] = [32, 32];
			iconSizeLists[2][1] = [30, 18];

			iconSizeLists[3][0] = [128, 128];
			iconSizeLists[3][1] = [41, 24];
		
			iconSizeLists[4][0] = [64, 64];
			iconSizeLists[4][1] = [41, 24];
			
			iconSizeLists[5][0] = [48, 48];
			iconSizeLists[5][1] = [41, 24];
		} else if (typeMap == 'vent') {
			var unit = Calendrier.getSpeedUnitSelected();
			if (unit == "km") {
				funct = "returnFunction";	
			} else {
				funct = "km2m";
			}
			firstIconFold = "iconeVent";
			firstIcon = "directionVent";
			secondIconFold = "iconeVVent";
			secondIcon = "vitesseVent";
			
			iconSizeLists[0][0] = [48, 48];
			iconSizeLists[0][1] = [41, 24];

			iconSizeLists[1][0] = [24, 24];
			
			iconSizeLists[2][0] = [32, 32];
			iconSizeLists[2][1] = [30, 18];

			iconSizeLists[3][0] = [128, 128];
			iconSizeLists[3][1] = [41, 24];
		
			iconSizeLists[4][0] = [64, 64];
			iconSizeLists[4][1] = [41, 24];
			
			iconSizeLists[5][0] = [48, 48];
			iconSizeLists[5][1] = [41, 24];
		}
		
		var icon_01 = new GIcon();
		var icon_02 = new GIcon();
		
		
		if (14 - gZoom > pZoom) {
			block = true;
		} else if (15 - gZoom > pZoom) {
			size1_1 = iconSizeLists[0][0][0];
			size1_2 = iconSizeLists[0][0][1];
			size2_1 = iconSizeLists[0][1][0]
			size2_2 = iconSizeLists[0][1][1];

			icon_01.image = IMG_FOLDER+firstIconFold+"/"+size1_1+"x"+size1_2+"/png/"+marker.getAttribute(firstIcon)+".png";
			icon_01.iconSize = new GSize(size1_1, size1_2);
			icon_01.iconAnchor = new GPoint(size1_1/2, size1_2/2);
			icon_01.infoWindowAnchor = new GPoint(size1_1/2, size1_2/2);

			icon_02.image = IMG_FOLDER+secondIconFold+"/"+fold+"/"+size2_1+"x"+size2_2+"/png/"+eval(funct+"('"+marker.getAttribute(secondIcon)+"')")+".png";
			icon_02.iconSize = new GSize(size2_1, size2_2);
			icon_02.iconAnchor = new GPoint(0, 0);
			if (number == 1) block = true;
		}else if (16 - gZoom > pZoom) {
			size1_1 = iconSizeLists[1][0][0];
			size1_2 = iconSizeLists[1][0][1];
			icon_01.image = IMG_FOLDER+firstIconFold+"/"+size1_1+"x"+size1_2+"/png/"+marker.getAttribute(firstIcon)+".png";
			icon_01.iconSize = new GSize(size1_1, size1_1);
			icon_01.iconAnchor = new GPoint(size1_1/2, size1_2/2);
			icon_01.infoWindowAnchor = new GPoint(size1_1/2, size1_2/2);

		
		}else if (17 - gZoom > pZoom) {
			size1_1 = iconSizeLists[2][0][0];
			size1_2 = iconSizeLists[2][0][1];
			size2_1 = iconSizeLists[2][1][0]
			size2_2 = iconSizeLists[2][1][1];
			
			icon_01.image = IMG_FOLDER+firstIconFold+"/"+size1_1+"x"+size1_2+"/png/"+marker.getAttribute(firstIcon)+".png";
			icon_01.iconSize = new GSize(size1_1, size1_1);
			icon_01.iconAnchor = new GPoint(size1_1/2, size1_2/2);
			icon_01.infoWindowAnchor = new GPoint(size1_1/2, size1_2/2);
			
			icon_02.image = IMG_FOLDER+secondIconFold+"/"+fold+"/"+size2_1+"x"+size2_2+"/png/"+eval(funct+"('"+marker.getAttribute(secondIcon)+"')")+".png";
			icon_02.iconSize = new GSize(size2_1, size2_2);
			icon_02.iconAnchor = new GPoint(0, 0);

		}else if (20 - gZoom < pZoom && totalLen < 20) {
			size1_1 = iconSizeLists[3][0][0];
			size1_2 = iconSizeLists[3][0][1];
			size2_1 = iconSizeLists[3][1][0]
			size2_2 = iconSizeLists[3][1][1];
			
			icon_01.image = IMG_FOLDER+firstIconFold+"/"+size1_1+"x"+size1_2+"/png/"+marker.getAttribute(firstIcon)+".png";
			icon_01.iconSize = new GSize(size1_1, size1_1);
			icon_01.iconAnchor = new GPoint(size1_1/2, size1_2/2);
			icon_01.infoWindowAnchor = new GPoint(size1_1/2, size1_2/2);
			
			icon_02.image = IMG_FOLDER+secondIconFold+"/"+fold+"/"+size2_1+"x"+size2_2+"/png/"+eval(funct+"('"+marker.getAttribute(secondIcon)+"')")+".png";
			icon_02.iconSize = new GSize(size2_1, size2_2);
			icon_02.iconAnchor = new GPoint(0, 0);

		}else if (17 - gZoom < pZoom && totalLen < 30) {
			size1_1 = iconSizeLists[4][0][0];
			size1_2 = iconSizeLists[4][0][1];
			size2_1 = iconSizeLists[4][1][0]
			size2_2 = iconSizeLists[4][1][1];
			
			icon_01.image = IMG_FOLDER+firstIconFold+"/"+size1_1+"x"+size1_2+"/png/"+marker.getAttribute(firstIcon)+".png";
			icon_01.iconSize = new GSize(size1_1, size1_1);
			icon_01.iconAnchor = new GPoint(size1_1/2, size1_2/2);
			icon_01.infoWindowAnchor = new GPoint(size1_1/2, size1_2/2);
			
			icon_02.image = IMG_FOLDER+secondIconFold+"/"+fold+"/"+size2_1+"x"+size2_2+"/png/"+eval(funct+"('"+marker.getAttribute(secondIcon)+"')")+".png";
			icon_02.iconSize = new GSize(size2_1, size2_2);
			icon_02.iconAnchor = new GPoint(0, 0);
		} else {
			size1_1 = iconSizeLists[5][0][0];
			size1_2 = iconSizeLists[5][0][1];
			size2_1 = iconSizeLists[5][1][0]
			size2_2 = iconSizeLists[5][1][1];
			
			icon_01.image = IMG_FOLDER+firstIconFold+"/"+size1_1+"x"+size1_2+"/png/"+marker.getAttribute(firstIcon)+".png";
			icon_01.iconSize = new GSize(size1_1, size1_1);
			icon_01.iconAnchor = new GPoint(size1_1/2, size1_2/2);
			icon_01.infoWindowAnchor = new GPoint(size1_1/2, size1_2/2);
			
			icon_02.image = IMG_FOLDER+secondIconFold+"/"+fold+"/"+size2_1+"x"+size2_2+"/png/"+eval(funct+"('"+marker.getAttribute(secondIcon)+"')")+".png";
			icon_02.iconSize = new GSize(size2_1, size2_2);
			icon_02.iconAnchor = new GPoint(0, 0);
		}


		icon_01.title = marker.getAttribute("nom");
		
		return [icon_01, icon_02, block];
	
	}
	
	var returnFunction = function(value) {
		return value;	
	}
	
	var initCloudLayer  = function() {
	 	
		var gLatLngBounds = GoogleMap.getBounds();
		var sw = gLatLngBounds.getSouthWest();
		var ne = gLatLngBounds.getNorthEast();
		xml = "2.0/cloudLayer.php?minLat="+sw.lat()+"&maxLat="+ne.lat()+"&minLng="+sw.lng()+"&maxLng="+ne.lng();				
			
		dojo.byId('cloudLayer').src =  "http://dev.woozor.com/prevision10jours/"+xml;
 		
	}
}

MLNPO = new function () {
	
	var widgetAddUrl = "http://fusion.google.com/add?source=atgs&moduleurl=http%3A//widgets.woozor.com/GEvolution/";
	var widgetWebAddUrl = "http://gmodules.com/ig/creator?synd=open&url=http%3A//widgets.woozor.com/GEvolution/";
	
	var inDebug;
	var inDebugLevel;
	
	var idContinent;
	var idPays;
	var idLieuMeteo;
	var idLieu;
	
	var nomContinent;
	var nomPays;
	var nomLieuMeteo;
	var nomLieu;
	
	var urlNomContinent;
	var urlNomPays;
	var urlNomLieuMeteo;
	var urlNomLieu;
	
	var latVille;
	var longVille;
	var zoomVille;
	
	var latPays;
	var longPays;
	var zoomPays;
	
	var latContinent;
	var longContinent;
	var zoomContinent;

	var infoMeteoList = [];
	var tagCloud;
	
	/*************************************/
	/**				PUBLIC				**/
	/*************************************/
	/**
	 *
	 * */
	this.init = function(anIdLieu, anIdLieuMeteo, anIdPays, anIdContinent, aNomLieu, aNomLieuMeteo, aNomPays, aNomContinent, aNomLieuUrl, aNomLieuMeteoUrl, aNomPaysUrl, aNomContinentUrl, aLatVille, aLongVille, aZoomVille, aLatPays, aLongPays, aZoomPays, aLatContinent, aLongContinent, aZoomContinent) {
		
		init(anIdLieu, anIdLieuMeteo, anIdPays, anIdContinent, aNomLieu, aNomLieuMeteo, aNomPays, aNomContinent, aNomLieuUrl, aNomLieuMeteoUrl, aNomPaysUrl, aNomContinentUrl, aLatVille, aLongVille, aZoomVille, aLatPays, aLongPays, aZoomPays, aLatContinent, aLongContinent, aZoomContinent);
	}
	
	
	/*************************************/
	/**				PRIVATE				**/
	/*************************************/
	
	var init = function(anIdLieu, anIdLieuMeteo, anIdPays, anIdContinent, aNomLieu, aNomLieuMeteo, aNomPays, aNomContinent, aNomLieuUrl, aNomLieuMeteoUrl, aNomPaysUrl, aNomContinentUrl, aLatVille, aLongVille, aZoomVille, aLatPays, aLongPays, aZoomPays, aLatContinent, aLongContinent, aZoomContinent) {

		if (Lang.isLangReady() == false) {
			setTimeout(function() {
				init(anIdLieu, anIdLieuMeteo, anIdPays, anIdContinent, aNomLieu, aNomLieuMeteo, aNomPays, aNomContinent, aNomLieuUrl, aNomLieuMeteoUrl, aNomPaysUrl, aNomContinentUrl, aLatVille, aLongVille, aZoomVille, aLatPays, aLongPays, aZoomPays, aLatContinent, aLongContinent, aZoomContinent);
			}, 50);
		} else {
			dojo.io.bind({
				url: "2.0/changeCity.php?idLieuMeteo="+anIdLieuMeteo+"&idLieu="+anIdLieu+"&lang="+Lang.getValue('ext'),
				load: changeCityHandler,
				mimetype: "text/html"
			});

			// les variables
			//alert(Conf.getValue('debug')) 
			inDebug = Conf.getValue('debug');
			inDebugLevel = Conf.getValue('debugLevel');
			
			idContinent = anIdContinent;
			idPays = anIdPays;
			idLieuMeteo = anIdLieuMeteo;
			idLieu = anIdLieu;
			
			urlNomContinent = aNomContinentUrl;
			urlNomPays = aNomPaysUrl;
			urlNomLieuMeteo = aNomLieuMeteoUrl;
			urlNomLieu = aNomLieuUrl;			
			
			nomContinent = aNomContinent;
			nomPays = aNomPays;
			nomLieuMeteo = aNomLieuMeteo;
			nomLieu = aNomLieu;
			
			latVille = aLatVille;
			longVille = aLongVille;
			zoomVille = aZoomVille;
			
			latPays = aLatPays;
			longPays = aLongPays;
			zoomPays = aZoomPays;
			
			latContinent = aLatContinent;
			longContinent = aLongContinent;
			zoomContinent = aZoomContinent;
	
			// init de tout :)
			Board.init();
			WZSearch.init();
			ListeVille.init();
			Calendrier.preInit();
			ListePays.init();
			Historique.init();
			TabManager.init();
			MapAction.init();
			Fisheye.init(); 
			Calendrier.init();
			EvolutionAccordion.init();
			WZMoonPhase.init();
			Localisation.changeCity(nomLieuMeteo, latVille, longVille);
		}
	}
	
	var changeCityHandler = function (type, data, evt) {
		WoozorXHR.setXHRVille(data);
		//setVilleInterface()
	}
	
	this.setNewInterface = function(type) {
		TabManager.changeTab(1)
		if (type == "pays") {
			setPaysInterface();
		}
		setVilleInterface();
	}
	
	this.changeTemp = function(type, changeMap) {
		changeTemp(type, changeMap);
	}
	
	this.changeSpeed = function(type, changeMap) {
		changeSpeed(type, changeMap);
	}
	
	var changeTemp = function(type, changeMap) {
	
		switch (type) {
			case "f":
				for (var i = 0; i < infoMeteoList.length; i++) {
					var infoMeteo = infoMeteoList[i];
					if (dojo.byId('TexteMeteoJour'+(i+1)+"Maximal")) {
						dojo.byId('TexteMeteoJour'+(i+1)+"Maximal").innerHTML = c2f(infoMeteo.tempMax)+Lang.getValue('tempUnitDisplayF');
						dojo.byId('TexteMeteoJour'+(i+1)+"Minimal").innerHTML = c2f(infoMeteo.tempMin)+Lang.getValue('tempUnitDisplayF');
						
						dojo.byId('TexteMeteoJour'+(i+1)+"MaximalTexte").innerHTML = Lang.getValue('infoMeteoTempMaxTextePresent').replace('%s', c2f(infoMeteo.tempMax))+Lang.getValue('tempUnitDisplayF');
						dojo.byId('TexteMeteoJour'+(i+1)+"MinimalTexte").innerHTML = Lang.getValue('infoMeteoTempMinTextePresent').replace('%s', c2f(infoMeteo.tempMin))+Lang.getValue('tempUnitDisplayF');
					}
				}
				break;
			default:
				for (var i = 0; i < infoMeteoList.length; i++) {
					var infoMeteo = infoMeteoList[i];
					if (dojo.byId('TexteMeteoJour'+(i+1)+"Maximal")) {
						dojo.byId('TexteMeteoJour'+(i+1)+"Maximal").innerHTML = infoMeteo.tempMax+Lang.getValue('tempUnitDisplayC');
						dojo.byId('TexteMeteoJour'+(i+1)+"Minimal").innerHTML = infoMeteo.tempMin+Lang.getValue('tempUnitDisplayC');
						
						dojo.byId('TexteMeteoJour'+(i+1)+"MaximalTexte").innerHTML = Lang.getValue('infoMeteoTempMaxTextePresent').replace('%s', infoMeteo.tempMax+Lang.getValue('tempUnitDisplayC'));
						dojo.byId('TexteMeteoJour'+(i+1)+"MinimalTexte").innerHTML = Lang.getValue('infoMeteoTempMinTextePresent').replace('%s', infoMeteo.tempMin+Lang.getValue('tempUnitDisplayC'));
					}
				}
				break;
		}
		dojo.byId('ImageEvolutionTemperature').src = getEvolutionTemperatureGraphique(type);
		if (changeMap) {
			MapAction.setNewContentOnMap();
		}
	}
	
	var changeSpeed = function(type, changeMap) {
		switch (type) {
			case "m":
				for (var i = 0; i < infoMeteoList.length; i++) {
					var infoMeteo = infoMeteoList[i];
					if (dojo.byId('TexteMeteoJour'+(i+1)+"VentTexte")) {
						dojo.byId('TexteMeteoJour'+(i+1)+"VentTexte").innerHTML = Lang.getValue('infoMeteoVent').replace('%s', getDirectionVent(infoMeteo.directionVent)).replace('%s', km2m(infoMeteo.vitesseVent)).replace('%s', Lang.getValue('vitesseUnitDisplayM'));
						dojo.byId('TexteMeteoJour'+(i+1)+"Vent").innerHTML = Lang.getValue('infoMeteoVent').replace('%s', getDirectionVent(infoMeteo.directionVent)).replace("%s", km2m(infoMeteo.vitesseVent)).replace("%s", Lang.getValue('vitesseUnitDisplayM'));
						dojo.byId('TexteMeteoJour'+(i+1)+"Vent2").innerHTML = Lang.getValue('infoMeteoVent').replace('%s', infoMeteo.directionVent).replace("%s", km2m(infoMeteo.vitesseVent)).replace("%s", Lang.getValue('vitesseUnitDisplayM'));
					}
				}
				break;
			default:
				for (var i = 0; i < infoMeteoList.length; i++) {
					var infoMeteo = infoMeteoList[i];
					if (dojo.byId('TexteMeteoJour'+(i+1)+"VentTexte")) {
						dojo.byId('TexteMeteoJour'+(i+1)+"VentTexte").innerHTML = Lang.getValue('infoMeteoVent').replace('%s', getDirectionVent(infoMeteo.directionVent)).replace('%s', infoMeteo.vitesseVent).replace('%s', Lang.getValue('vitesseUnitDisplayKM'));
						dojo.byId('TexteMeteoJour'+(i+1)+"Vent").innerHTML = Lang.getValue('infoMeteoVent').replace('%s', getDirectionVent(infoMeteo.directionVent)).replace("%s", infoMeteo.vitesseVent).replace("%s", Lang.getValue('vitesseUnitDisplayKM'));
						dojo.byId('TexteMeteoJour'+(i+1)+"Vent2").innerHTML = Lang.getValue('infoMeteoVent').replace('%s', infoMeteo.directionVent).replace("%s",infoMeteo.vitesseVent).replace("%s", Lang.getValue('vitesseUnitDisplayKM'));
					}
				}
				break;
		}
		dojo.byId('ImageEvolutionVent').src = getEvolutionVentGraphique(type);
		if (changeMap) {
			MapAction.setNewContentOnMap();
		}
	}
	
	var setPaysInterface = function() {
		dojo.byId('nuageTagVille').innerHTML = tagCloud;
	}
	
	var setVilleInterface = function () {
		//document.getElementById('tabContent1').scrollTo('topTabContent1')
		WZMoonPhase.setLng(latVille);
		WZMoonPhase.change(1);
		//alert(longVille);
		
		var url = Conf.getValue('urlBaseStatic')+'img/icone/128x128/jpg/';
		for (var i = 0; i < infoMeteoList.length; i++) {
			
			var infoMeteo = infoMeteoList[i];
			if (dojo.byId('ImageMeteoJour'+(i+1)+"Jour")) {
				dojo.byId('ImageMeteoJour'+(i+1)+"Jour").src = url+infoMeteo.iconJour+'.jpg';
				dojo.byId('ImageMeteoJour'+(i+1)+"Nuit").src = url+infoMeteo.iconNuit+'.jpg';
				dojo.byId('ImageMeteoJour'+(i+1)+"JourPopUp").src = url+infoMeteo.iconJour+'.jpg';
				dojo.byId('ImageMeteoJour'+(i+1)+"NuitPopUp").src = url+infoMeteo.iconNuit+'.jpg';
				dojo.byId('ImageMeteoJour'+(i+1)+"VentPopUp").src = Conf.getValue('urlBaseStatic')+'img/iconeVent/128x128/jpg/'+infoMeteo.directionVent+'.jpg';
				
				dojo.byId('ImageMeteoJour'+(i+1)+"JourTexte").innerHTML = Lang.getValue('infoMeteoDescIcon_'+infoMeteo.iconJour);
				dojo.byId('ImageMeteoJour'+(i+1)+"NuitTexte").innerHTML = Lang.getValue('infoMeteoDescIcon_'+infoMeteo.iconNuit);
				dojo.byId('ImageMeteoJour'+(i+1)+"NuitTextePopUp").innerHTML = Lang.getValue('infoMeteoDescIcon_'+infoMeteo.iconJour);
				dojo.byId('ImageMeteoJour'+(i+1)+"NuitTextePopUp").innerHTML = Lang.getValue('infoMeteoDescIcon_'+infoMeteo.iconNuit);
			}
			//dojo.byId('ImageMeteoJour'+(i+1)+"VentTextePopUp").innerHTML = sprintf(Lang.getValue('infoMeteoVent'), getDirectionVent(infoMeteo.directionVent), infoMeteo.vitesseVent, Calendrier.getSpeedUnitSelected()+"/h");
		}
		dojo.byId('ImageEvolutionHumidite').src = getEvolutionHumiditeGraphique();
		dojo.byId('ImageEvolutionPrecipitation').src = getEvolutionPrecipitationGraphique();
		if (Calendrier.getTempUnitSelected() == "c") { 
			changeTemp('c' ,false)
		} else {
			changeTemp('f',false)
		}
		if (Calendrier.getSpeedUnitSelected() == "km") { 
			changeSpeed('km' ,false)
		} else {
			changeSpeed('m',false)
		}
		
		var title = getTitle();
		dojo.byId('titre').innerHTML = title;
		document.title = Lang.getValue('metaTitle').replace('%s', title);
		createRss();
		
		dojo.byId('rssLink').href = Fisheye.getRssDeLaPage();
		dojo.byId('kmlLink').href = Fisheye.getKmlDeLaPage();
		dojo.byId('htmlLink').href = Fisheye.gup();
		//alert(1)
		setWidgetUrl();
		//alert(2)
		Calendrier.initPub();
		Localisation.changeCity(nomLieuMeteo, latVille, longVille);

		//alert(3)
	}
	
	var createRss = function() {
		var head = document.getElementsByTagName('head').item(0);
		var link = document.createElement("link");
		link.setAttribute("rel", "alternate");
		link.setAttribute("type", "application/rss+xml");
		link.setAttribute("title", getTitle());
		link.setAttribute("href", Fisheye.getRssDeLaPage());
		head.appendChild(link);
	}
	
	var getTitle = function () {
		var name;
		if (nomLieu != "" && nomLieu && nomLieu != undefined) {
			name = nomLieu;
		} else { 
			name = nomLieuMeteo;
		}
		return Lang.getValue('meteoA').replace('%s', name+", "+nomPays+" ("+nomContinent+")")
		
	}
	
	var getDirectionVent = function(dVent) {
		
		var directionVent = "";
		
		for (var j = 0; j < dVent.length; j++)
		{
			switch (dVent[j])
			{
				case "N": directionVent += Lang.getValue('nord')+" "; break;
				case "E": directionVent += Lang.getValue('est')+" "; break;
				case "W": directionVent += Lang.getValue('ouest')+" "; break;
				case "S": directionVent += Lang.getValue('sud')+" "; break;
				default: directionVent +=""; break;
			}
		}
		tabVent = directionVent.split(' ');
		if (tabVent[3] != undefined)
			directionVent = tabVent[0]+", "+tabVent[1]+" "+tabVent[2];
		return directionVent;
	}
	
	var getEvolutionTemperatureGraphique = function( type) {
		
		var evolutionTempMax = "";
		var evolutionTempMin = "";
		for (var i = 0; i < infoMeteoList.length; i++) {
			var infoMeteo = infoMeteoList[i];
			
			if (type == "f") {
				
				evolutionTempMax += "dh"+i+"="+c2f(infoMeteo.tempMax)+"&";
				evolutionTempMin += "dl"+i+"="+c2f(infoMeteo.tempMin)+"&";
			
			} else {
			
				evolutionTempMax += "dh"+i+"="+infoMeteo.tempMax+"&";
				evolutionTempMin += "dl"+i+"="+infoMeteo.tempMin+"&";
				
			}
		}
		return "../images/evolution/graph_temp2.php?"+evolutionTempMax+evolutionTempMin+"lang="+Lang.getValue('ext')+"&unit="+type;
	}
	
	var getEvolutionVentGraphique = function(type) {
		var evolutionVent = "";
		for (var i = 0; i < infoMeteoList.length; i++) {
			var infoMeteo = infoMeteoList[i];
		
			if (type == "km") {
				evolutionVent += "vv"+i+"="+infoMeteo.vitesseVent+"&";
			} else {
				evolutionVent += "vv"+i+"="+km2m(infoMeteo.vitesseVent)+"&";
			}
		}
		return "../images/evolution/graph_v_vent.php?"+evolutionVent+"lang="+Lang.getValue('ext')+"&unit="+type;
	}	
	
	var getEvolutionHumiditeGraphique = function() {
		var evolutionHumidite = "";
		for (var i = 0; i < infoMeteoList.length; i++) {
			var infoMeteo = infoMeteoList[i];
			evolutionHumidite += "hu"+i+"="+infoMeteo.humidite+"&";
		}
		return "../images/evolution/graph_humid.php?"+evolutionHumidite+"lang="+Lang.getValue('ext');
	}	
	
	var getEvolutionPrecipitationGraphique = function() {
		var evolutionPrecipitation = "";
		for (var i = 0; i < infoMeteoList.length; i++) {
			var infoMeteo = infoMeteoList[i];
			evolutionPrecipitation += "pr"+i+"="+infoMeteo.pluie+"&";
		}
		return "../images/evolution/graph_prec.php?"+evolutionPrecipitation+"lang="+Lang.getValue('ext');
	}	
	
	var setWidgetUrl = function() {
		dojo.byId('evolutionPrecipitationWidget').href = widgetAddUrl+"GRainEvolution.php?id="+idLieuMeteo;
		dojo.byId('evolutionHumiditeWidget').href = widgetAddUrl+"GHumidityEvolution.php?id="+idLieuMeteo;
		dojo.byId('evolutionVentWidget').href = widgetAddUrl+"GWindEvolution.php?id="+idLieuMeteo;
		dojo.byId('evolutionTemperatureWidget').href = widgetAddUrl+"GTempEvolution.php?id="+idLieuMeteo;
		
		dojo.byId('evolutionPrecipitationWidgetWeb').href = widgetWebAddUrl+"GRainEvolution.php?id="+idLieuMeteo;
		dojo.byId('evolutionHumiditeWidgetWeb').href = widgetWebAddUrl+"GHumidityEvolution.php?id="+idLieuMeteo;
		dojo.byId('evolutionVentWidgetWeb').href = widgetWebAddUrl+"GWindEvolution.php?id="+idLieuMeteo;
		dojo.byId('evolutionTemperatureWidgetWeb').href = widgetWebAddUrl+"GTempEvolution.php?id="+idLieuMeteo;
	}
	
	/*
	var getTagCloud = function() {
		var tg = "";
		var tgList = tagCloud.getElementsByTagName("a");
		for (var i = 0; i < tgList.length; i++) {
			tg += tgList.item(i)+" ";
		}
		return tg;
		
	}*/
	
	var f2c = function(t) {
		return Math.round((t-32)*5/9);
	}
	
	var c2f = function(t) {
		return Math.round(t*9/5 + 32);
	}
	
	var km2m = function(s) {
		return Math.round(s/1.609344);
	}

	var m2km = function(s) {
		return Math.round(s*1.609344);
	}
	/************ ACCESSEUR *******************/
	/**
	 *
	 * */
	this.getInDebug = function() {
		return inDebug;	
	}
	this.getInDebugLevel = function() {
		return inDebugLevel;	
	}

	/**************************/
	/**
	 *
	 * */
	this.setIdPays = function(id) {
		idPays = id;
	}
	this.getIdPays = function() {
		return idPays;	
	}
	
	/**
	 *
	 * */
	this.setIdContinent = function(id) {
		idContinent = id;
	}
	this.getIdContinent = function() {
		return idContinent	;
	}
	
	/**
	 *
	 * */
	this.setIdLieuMeteo = function(id) {
		idLieuMeteo = id;
	}
	this.getIdLieuMeteo = function() {
		return idLieuMeteo;	
	}
	
	/**
	 *
	 * */
	this.setIdLieu = function(id) {
		idLieu = id;
	}
	this.getIdLieu = function() {
		return idLieu;	
	}
	
	/**************************/
	/**
	 *
	 * */
	this.setNomContinent = function(nom) {
		nomContinent = nom;	
	}
	this.getNomContinent = function() {
		return nomContinent;
	}
	
	/**
	 *
	 * */
	this.setNomPays = function(nom) {
		nomPays = nom;	
	}
	this.getNomPays = function() {
		return nomPays;
	}
	
	/**
	 *
	 * */
	this.setNomLieuMeteo = function(nom) {
		nomLieuMeteo = nom;	
	}
	this.getNomLieuMeteo = function() {
		return nomLieuMeteo;
	}
	
	/**
	 *
	 * */
	this.setNomLieu = function(nom) {
		nomLieu = nom;	
	}
	this.getNomLieu = function() {
		return nomLieu;
	}

	/**************************/
	/**
	 *
	 * */
	this.setUrlNomContinent = function(nom) {
		urlNomContinent = nom;	
	}
	this.getUrlNomContinent = function() {
		return urlNomContinent;
	}
	
	/**
	 *
	 * */
	this.setUrlNomPays = function(nom) {
		urlNomPays = nom;	
	}
	this.getUrlNomPays = function() {
		return urlNomPays;
	}
	
	/**
	 *
	 * */
	this.setUrlNomLieuMeteo = function(nom) {
		urlNomLieuMeteo = nom;	
	}
	this.getUrlNomLieuMeteo = function() {
		return urlNomLieuMeteo;
	}
	
	/**
	 *
	 * */
	this.setUrlNomLieu = function(nom) {
		urlNomLieu = nom;	
	}
	this.getUrlNomLieu = function() {
		return urlNomLieu;
	}

	/**************************/

	/**
	 *
	 * */
	this.setLatVille = function(l) {
		latVille = l;
	}
	this.getLatVille = function() {
		return latVille;	
	}
	
	/**
	 *
	 * */
	this.setLongVille = function(l) {
		longVille = l;	
	}
	this.getLongVille = function() {
		return longVille;	
	}
	
	/**
	 *
	 * */
	this.setZoomVille = function(l) {
		zoomVille = l;	
	}
	this.getZoomVille = function() {
		return zoomVille;	
	}

	/**************************/

	/**
	 *
	 * */
	this.setLatPays = function(l) {
		latPays = l;	
	}
	this.getLatPays = function() {
		return latPays;	
	}
	
	/**
	 *
	 * */
	this.setLongPays = function(l) {
		longPays = l;	
	}
	this.getLongPays = function() {
		return longPays;	
	}
	
	/**
	 *
	 * */
	this.setZoomPays = function(l) {
		zoomPays = l;	
	}
	this.getZoomPays = function() {
		return zoomPays;	
	}
	
	/**************************/

	/**
	 *
	 * */
	this.setLatContinent = function(l) {
		latContinent = l;	
	}
	this.getLatContinent = function() {
		return latContinent;	
	}
	
	/**
	 *
	 * */
	this.setLongContinent = function(l) {
		longContinent = l;	
	}
	this.getLongContinent = function() {
		return longContinent;	
	}
	
	/**
	 *
	 * */
	this.setZoomContinent = function(l) {
		zoomContinent = l;	
	}
	this.getZoomContinent = function() {
		return zoomContinent;	
	}
	
	/**
	 *
	 * */
	this.setInfoMeteoList = function(a) {
		infoMeteoList = a;
	}
	this.getInfoMeteoList = function() {
		return 	infoMeteoList;
	}	
	
	/**
	 *
	 * */
	this.setTagCloud = function(x) {
		tagCloud = x;	
	}
}


MySpace = new function() {
	/**
	 *
	 * */
	this.init = function() {
		
		initPub();	
		Historique.init();
		

		//Identification.init();
	}
	
	/**
	 *
	 * */
	var initPub = function() {
		
		var nomPays = MLNPO.getNomPays();
		var nomLieuMeteo = MLNPO.getNomLieuMeteo();
		var nomLieu = MLNPO.getNomLieu();
		var currentTime = new Date();
  		
		googleadMesMeteos.location = "2.0/ads.php?h=200&w=200&e=as&nomPays="+nomPays+"&nomLieuMeteo="+nomLieuMeteo+"&nomLieu="+nomLieu+"&s=" + currentTime.getTime() + "04&p=true";
		dojo.byId('googleadMesMeteosContainer').onmouseover = function(e) { dojo.byId('googleadMesMeteosContainer').style.backgroundColor = '#EAEAEA'; }
		dojo.byId('googleadMesMeteosContainer').onmouseout = function(e) { dojo.byId('googleadMesMeteosContainer').style.backgroundColor = '#FFFFFF'; } 
	}
}

WZSearch = new function() {
	
	var resultList = [];
	var inSearch = false;
	var lastSearchSucceed;
	var currentSearch = "";
	
	var currentItemLighted = -1;
	var DEFAULT_VALUE = "Paris ou France"
	
	this.init = function() {
		
		DEFAULT_VALUE = Lang.getValue('defaultSearch');

		dojo.byId('searchInput').setAttribute("autocomplete", "off");;
	
		if (dojo.byId('searchInput').value != "") {
			doSearch(dojo.byId('searchInput').value);
		} else {
			dojo.byId('searchInput').value = DEFAULT_VALUE;
			dojo.byId('searchInput').style.color = "#CCCCCC";
			dojo.byId('searchInput').style.fontStyle = "italic";
			
		}
		
		
		GEvent.addDomListener(dojo.byId('searchInput'), "keyup", searchInputKeydownHandler);	
		GEvent.addDomListener(dojo.byId('searchInput'), "click", searchInputClickHandler);	
		GEvent.addDomListener(dojo.byId('searchSubmit'), "click", searchSubmitClickHandler)
		
	}
	
	var searchInputClickHandler = function(e) {
		if (dojo.byId('searchInput').value == DEFAULT_VALUE) {
			dojo.byId('searchInput').value = "";
			dojo.byId('searchInput').style.color = "#000000";
			dojo.byId('searchInput').style.fontStyle = "normal";
		}
		if (resultList.length > 0) {
			dojo.byId('searchResult').style.display = 'block';	
		}
	}
	
	var searchInputKeydownHandler = function(e) {
		if (e.which == 13 && resultList.length > 0) {		
			if (currentItemLighted != -1) {
				reloadWoozor(resultList[currentItemLighted].idLieu, resultList[currentItemLighted].idLieuMeteo, resultList[currentItemLighted].idPays);
			} else {
				reloadWoozor(resultList[0].idLieu, resultList[0].idLieuMeteo, resultList[0].idPays);
			}
		} else if (e.which == 40) {
			goDownInResultList();
		} else if (e.which == 38) {
			goUpInResultList(); 
		} else {
			var target = e.target;
			doSearch(target.value);
		} 
	}
	
	var goDownInResultList = function() {
		var divList = dojo.byId('searchResult').getElementsByTagName('div');
		if (currentItemLighted < resultList.length-1) {
			if (currentItemLighted != -1) {
				divList[currentItemLighted].className = 'searchResultItem';
			}	
			currentItemLighted += 1;
			divList[currentItemLighted].className = 'searchResultItemSelected';
		}
	}
	
	var goUpInResultList = function() {
		var divList = dojo.byId('searchResult').getElementsByTagName('div');
		
		if (currentItemLighted > 0) {
			divList[currentItemLighted].className = 'searchResultItem';
			currentItemLighted -= 1;
			divList[currentItemLighted].className = 'searchResultItemSelected';
		}
	}

	
	var searchSubmitClickHandler = function(e) {
		doSearch(dojo.byId('searchInput').value);
	}
	
	var doSearch = function(q) {
		if ( q != currentSearch) {
			currentSearch = q;
			if (currentSearch != "") {
				toInterface()
				if (inSearch == false) {
					showLoader();
					dojo.io.bind({
						url: "2.0/search.php?q="+currentSearch+"&idPays="+MLNPO.getIdPays()+"&lang="+Lang.getValue('ext'),
						load: doSearchResultHandler,						
						mimetype: "text/html"
					});
					inSearch = true;
				}
			} else {
				dojo.byId('searchResult').style.display = 'none';
				hideLoader();
			}
		} else {
			toInterface()
		}
	}
	
	var doSearchResultHandler = function(type, data, evt) {
		hideLoader();
		inSearch = false;
		rest(data);
	}
	
	var rest = function(data) {
		parseResult(data);
		toInterface();
		if (currentSearch != lastSearchSucceed) { 
			doSearch(dojo.byId('searchInput').value);
		}

	}
	
	var toInterface = function() {
		if (resultList.length > 0) {
			var txt = "";
			var txtEnd = "";
			for (i = 0; i < resultList.length; i++) {
				var t = resultList[i].getStrong(currentSearch);
				if (resultList[i].check == true) {
					txt += t;	
				} else {
					txtEnd += t;	
				}
			}
			dojo.byId('searchResult').style.display = 'block';
			dojo.byId('searchResult').innerHTML = txt+txtEnd;
			initResponse();
		} else {
			dojo.byId('searchResult').style.display = 'none';
		}
	}
	
	var parseResult = function(data) {
		var xml = GXml.parse(data);
		lastSearchSucceed =  xml.documentElement.getAttribute('q');
		var resList = xml.documentElement.getElementsByTagName("r");
		resultList = []
		
		for (var i = 0; i < resList.length; i++) {
			var res = resList[i];
			var searchResult = new SearchResult();
			searchResult.name = res.getAttribute('n');
			searchResult.idLieu = res.getAttribute('idL');
			searchResult.idLieuMeteo = res.getAttribute('idLM');
			searchResult.idPays = res.getAttribute('idP');
			searchResult.icon = res.getAttribute('icon');
			resultList[i] = searchResult;
		}
	}
	
	var initResponse = function() {
		var divList = dojo.byId('searchResult').getElementsByTagName('div');	
		for (var i = 0; i < divList.length; i++) {
			var div = divList[i];
			GEvent.addDomListener(div, "mouseover", function(e) { this.className = 'searchResultItemSelected'; });
			GEvent.addDomListener(div, "mouseout", function(e) { this.className = 'searchResultItem'; });
			GEvent.addDomListener(div.getElementsByTagName('a')[0], "click", linkClickHandler);
			GEvent.addDomListener(div, "click", linkClickHandler);
		}
		
	}
	
	var linkClickHandler = function(e) {
		var targetId = this.id ? this.id : this.getElementsByTagName('a')[0].id;
		var onlyIds = targetId.replace('search_','');
		var idList = onlyIds.split("_");
		reloadWoozor(idList[0], idList[1], idList[2]);
	}
	
	var reloadWoozor = function(idLieu, idLieuMeteo, idPays) {
		var divList = dojo.byId('searchResult').getElementsByTagName('div');
		
		if (currentItemLighted != -1) {
			divList[currentItemLighted].className = 'searchResultItem';
			currentItemLighted = -1;
		}
		if (idPays == MLNPO.getIdPays() && idLieuMeteo != 0) {
			ListeVille.loadInfoVilleByIds(idLieuMeteo, idLieu);
		} else {
			ListePays.loadInfoPaysById(idPays, idLieuMeteo, idLieu);
		}
				
		dojo.byId('searchResult').style.display = 'none';


	}
	this.closeResult = function() {
		hideLoader();
		dojo.byId('searchResult').style.display = 'none';
	}
	
	var showLoader = function() {
		dojo.byId('searchInput').style.backgroundImage = 'url(http://static.woozor.com/img/loader/small.gif)';
	}
	
	var hideLoader = function() {
		dojo.byId('searchInput').style.backgroundImage = 'none';
	}
}


String.prototype.ucwords = function(){ //v1.0
    return this.replace(/\w+/g, function(a){
        return a.charAt(0).toUpperCase() + a.substr(1).toLowerCase();
    });
};

String.prototype.ucfirst = function() {
	return this.charAt(0).toUpperCase() + this.substr(1).toLowerCase();
};

String.prototype.strreplace = function(a, b) {
	var c = this.replace(a,b);	
	while (c.search(a) != -1) {
   		c = c.replace(a,b);
	}
	return c;
}


var SearchResult = function() {
	
	this.idLieu;
	this.idPays;
	this.idLieuMeteo;
	this.name;
	this.icon;
	this.check;
	
	this.SearchResult = function() { }
	
	this.getStrong = function(q) {
		return this.strong(q);
	}
	
	this.strong = function(q) {
		var r = this.name;
		this.check = true;
		r = r.replace(q.ucfirst(), "<strong>"+q.ucfirst()+"</strong>");
		if (r == this.name) {
			r = r.replace(q, "<strong>"+q+"</strong>")
		}
		if (r == this.name) {
			r = r.replace(q.strreplace(" ","-"), "<strong>"+q.strreplace(" ","-")+"</strong>")	
		}
		if (r == this.name) {
			r = r.replace(q.ucwords(), "<strong>"+q.ucwords()+"</strong>")	
		}
		if (r == this.name) {
			r = r.replace(q.ucfirst().strreplace(" ","-"), "<strong>"+q.ucfirst().strreplace(" ","-")+"</strong>")	
		}		
		if (r == this.name) {
			r = r.replace(q.ucwords().strreplace(" ","-"), "<strong>"+q.ucwords().strreplace(" ","-")+"</strong>")	
		}
		return this.getResult(r);
	}
	
	this.getResult = function(r) {
		if (r == this.name) {
			this.check = false;
			if (this.icon != undefined) {
				return "<div style=\"padding:2px; background-image:url("+this.icon+"); background-repeat:no-repeat; background-position:center right; \"><a id=\"search_"+this.idLieu+"_"+this.idLieuMeteo+"_"+this.idPays+"\"><em>"+r+"</em></a></div>";
			} else {
				return "<div style=\"padding:2px; \"><a id=\"search_"+this.idLieu+"_"+this.idLieuMeteo+"_"+this.idPays+"\"><em>"+r+"</em></a></div>";
			}
		}
		if (this.icon != undefined) {
			return "<div style=\"padding:2px; background-image:url("+this.icon+"); background-repeat:no-repeat; background-position:center right; \"><a id=\"search_"+this.idLieu+"_"+this.idLieuMeteo+"_"+this.idPays+"\">"+r+"</a></div>";
		} else {
			return "<div style=\"padding:2px; \"><a id=\"search_"+this.idLieu+"_"+this.idLieuMeteo+"_"+this.idPays+"\">"+r+"</a></div>";
		}
	}
	
}


							 

TabManager = new function() {
	
	var TAB_NAME = 'tab';
	var TAB_CONTENT_NAME = 'tabContent';
	var tabLength = 5;
	var currentTabNumber = 1;
	
	this.init = function() {
		for (var i = 1; i <= tabLength; i++) {
			GEvent.addDomListener(dojo.byId(TAB_NAME+i).getElementsByTagName('a')[0], "click", tabClickHandler);
			if (i != currentTabNumber) {
				dojo.byId(TAB_CONTENT_NAME+i).style.display = 'none';
			}
			if (Navigator.isIE6 || Navigator.isIE7) {
				dojo.byId(TAB_CONTENT_NAME+i).style.height = dojo.byId('mainContainer_1').offsetHeight;
			}
		}
	}
	
	var tabClickHandler = function(e) {
		var target = e.target.parentNode;

		if (MapAction.getSize() == "full") {
			MapAction.changeSize("full");
		}
		
		dojo.byId(TAB_NAME+currentTabNumber).className = "tabOff";
		dojo.byId(TAB_CONTENT_NAME+currentTabNumber).style.display = "none"

		currentTabNumber = target.id.replace(TAB_NAME,'');
		
		dojo.byId(TAB_NAME+currentTabNumber).className = "tabOn";
		dojo.byId(TAB_CONTENT_NAME+currentTabNumber).style.display = "block";
		
		WZSearch.closeResult();
	}
	
	this.changeTab = function(num) {
		dojo.byId(TAB_NAME+currentTabNumber).className = "tabOff";
		dojo.byId(TAB_CONTENT_NAME+currentTabNumber).style.display = "none"

		currentTabNumber = num;
		
		dojo.byId(TAB_NAME+currentTabNumber).className = "tabOn";
		dojo.byId(TAB_CONTENT_NAME+currentTabNumber).style.display = "block";
	}
	
}


WoozorXHR = new function() {	

	this.setXHRPays = function(data) {
		
		var xml = GXml.parse(data);
		var continentXml = xml.documentElement.getElementsByTagName("continent")[0];
		
		MLNPO.setIdContinent(continentXml.getAttribute("id"));
		MLNPO.setNomContinent(continentXml.getAttribute("name"));
		MLNPO.setUrlNomContinent(continentXml.getAttribute("urlName"));
		MLNPO.setLatContinent(continentXml.getAttribute("lat"));
		MLNPO.setLongContinent(continentXml.getAttribute("long"));
		MLNPO.setZoomContinent(continentXml.getAttribute("zoom"));
		
		var paysXml = xml.documentElement.getElementsByTagName("pays")[0];
		MLNPO.setIdPays(paysXml.getAttribute("id"));
		MLNPO.setNomPays(paysXml.getAttribute("name"));
		MLNPO.setUrlNomPays(paysXml.getAttribute("urlName"));
		MLNPO.setLatPays(paysXml.getAttribute("lat"));
		MLNPO.setLongPays(paysXml.getAttribute("long"));
		MLNPO.setZoomPays(paysXml.getAttribute("zoom"));
		
		var txt = "";
		var root = xml.documentElement.getElementsByTagName("tagCloud")[0].getElementsByTagName('a')
		for (var i = 0; i < root.length; i++) {
			var obj = root[i];
			txt += "<a style=\""+obj.getAttribute("style")+"\" id=\""+obj.getAttribute("id")+"\" onclick=\""+obj.getAttribute("onclick")+"\" href=\""+obj.getAttribute("href")+"\">"+GXml.value(obj)+"</a> ";
		}
		
		MLNPO.setTagCloud(txt);
		this.setXHRVille(data);
	}	
	
	this.setXHRVille = function (data) {
		
		var xml = GXml.parse(data);
		
		var lieuMeteoXml = xml.documentElement.getElementsByTagName("lieuMeteo")[0];
		MLNPO.setIdLieuMeteo(lieuMeteoXml.getAttribute("id"));
		MLNPO.setNomLieuMeteo(lieuMeteoXml.getAttribute("name"));
		MLNPO.setUrlNomLieuMeteo(lieuMeteoXml.getAttribute("urlName"));

		var lieuXml = xml.documentElement.getElementsByTagName("lieu")[0];
		MLNPO.setIdLieu(lieuXml.getAttribute("id"));
		MLNPO.setNomLieu(lieuXml.getAttribute("name"));
		MLNPO.setUrlNomLieu(lieuXml.getAttribute("urlName"));

		var wLieuXml = xml.documentElement.getElementsByTagName("wlieu")[0];
		MLNPO.setLatVille(wLieuXml.getAttribute("lat"));
		MLNPO.setLongVille(wLieuXml.getAttribute("long"));
		MLNPO.setZoomVille(wLieuXml.getAttribute("zoom"));

		var infoMeteoXmlList = xml.documentElement.getElementsByTagName("infoMeteo");
		var infoMeteoList = [];
		
		for (var i = 0; i < infoMeteoXmlList.length; i++) {
			infoMeteoXml = infoMeteoXmlList[i];
			var infoMeteo = new InfoMeteo();

			infoMeteo.index	=			i;
			infoMeteo.tempMax = 		GXml.value(infoMeteoXml.getElementsByTagName("tempMax")[0]);
			infoMeteo.tempMin = 		GXml.value(infoMeteoXml.getElementsByTagName("tempMin")[0]);
			infoMeteo.iconJour = 		GXml.value(infoMeteoXml.getElementsByTagName("iconJour")[0]);
			infoMeteo.iconNuit = 		GXml.value(infoMeteoXml.getElementsByTagName("iconNuit")[0]);
			
			infoMeteo.directionVent = 	GXml.value(infoMeteoXml.getElementsByTagName("dVent")[0]);
			infoMeteo.vitesseVent = 	GXml.value(infoMeteoXml.getElementsByTagName("vVent")[0]);
			infoMeteo.pluie = 			GXml.value(infoMeteoXml.getElementsByTagName("pluie")[0]);
			infoMeteo.humidite = 		GXml.value(infoMeteoXml.getElementsByTagName("humidite")[0]);
			infoMeteo.heureLever = 		GXml.value(infoMeteoXml.getElementsByTagName("lever")[0]);
			infoMeteo.heureCoucher = 	GXml.value(infoMeteoXml.getElementsByTagName("coucher")[0]);
 
			infoMeteoList[i] = infoMeteo;
		}
		
		MLNPO.setInfoMeteoList(infoMeteoList);
	}
}

VillePlusRecherche = new function() {
	
	/**
	 *
	 * */
	this.init = function() {
		
		initItem();
	}
	
	/**
	 *
	 * */
	var initItem = function() {
		var container = $('nuageTagPlusRecherche');
		var listItem = container.getElementsByTagName('a');
		
		for (var i = 0; i < listItem.length; i++) {
			listItem[i].onclick = function(e) { loadMeteo(e); return false; }
		}
	}
	
	/**
	 *
	 * */
	var loadMeteo = function(e) {
		
		var element = Event.element(e);
		var idArray = element.id.replace('ville_','').split('_');
		var idLieu = idArray[1];
		var idLieuMeteo = idArray[0];
			
		EvolutionAccordion.showLoad();
		Calendrier.showLoad();
		
		dojo.io.bind({
			url: "2.0/updateInfoVille.php?idLieuMeteo="+idLieuMeteo+"&idLieu="+idLieu+"&context=43&lang="+Lang.getValue('ext'),
			load: loadMeteoResultHandler,
			mimetype: "text/javascript"
		});
	}
	
	/**
	 *
	 * */
	var loadMeteoResultHandler = function() {

		Dlg4.hide();
		Historique.add();
		MapAction.vpc('pays');
		ListeVille.init();
	}
}

InviterAmi = new function() {
	
	var email = "";
	var emailAmi = "";
	var prenom = "";
	var prenomAmi = "";
	
	/**
	 *
	 * */
	this.init = function() {
		
		initInput();
	}
	
	/**
	 *
	 * */
	var initInput = function() {
		
		var emailInput = dojo.byId('emailInviterUnAmi');
		emailInput.value = "";
		GEvent.addDomListener(emailInput, "keyup", setEmailByE);
		
		var emailAmiInput = dojo.byId('emailAmiInviterUnAmi');
		emailAmiInput.value = "";
		GEvent.addDomListener(emailAmiInput, "keyup", setEmailAmiByE);
		
		var prenomInput = dojo.byId('prenomInviterUnAmi');
		prenomInput.value = "";
		GEvent.addDomListener(prenomInput, "keyup", setPrenomByE);
		
		var prenomAmiInput = dojo.byId('prenomAmiInviterUnAmi');
		prenomAmiInput.value = "";
		GEvent.addDomListener(prenomAmiInput, "keyup", setPrenomAmiByE);
		
		var submitButton = dojo.byId('submitInviterUnAmi');
		GEvent.addDomListener(submitButton, "click", doSubmit);
	}
	
	/**
	 *
	 * */
	var setEmailByE = function(e) {

		var p = new Texte(e.target.value);
		email = p.trim();
		
		dojo.byId('inviterUnAmiDe').innerHTML = "&lt;"+email+"&gt;";
	}
	
	/**
	 *
	 * */
	var setEmailAmiByE = function(e) {
		
		var p = new Texte(e.target.value);
		emailAmi = p.trim();
		
		dojo.byId('inviterUnAmiA').innerHTML = "&lt;"+emailAmi+"&gt;";
	}
	
	/**
	 *
	 * */
	var setPrenomByE = function(e) {

		var p = new Texte(e.target.value);
		p.trim();
		prenom = p.ucfirst();
		
		dojo.byId('inviterUnAmiPrenom').innerHTML = prenom;
		dojo.byId('inviterUnAmiPrenomDe').innerHTML = prenom;
	}
	
	/**
	 *
	 * */
	var setPrenomAmiByE = function(e) {
	
		var p = new Texte(e.target.value);
		p.trim();
		prenomAmi = p.ucfirst();
		
		if (prenomAmi != '') {
			dojo.byId('inviterUnAmiPrenomAmi').innerHTML = " "+prenomAmi;
		} else {
			dojo.byId('inviterUnAmiPrenomAmi').innerHTML = '';
		}
		
		dojo.byId('inviterUnAmiPrenomAmiA').innerHTML = prenomAmi;
	}
	
	/**
	 *
	 * */
	var validate = function() {
		
		var bool = true;
		
		var e1 = new Email(email);
		var t1 = new Texte(email);
		
		var e2 = new Email(emailAmi);
		var t2 = new Texte(emailAmi);
		
		var t3 = new Texte(prenom);
		
		var t4 = new Texte(prenomAmi);
		
		if (!e1.isValid() || t1.trim() == "") {
			dojo.byId('emailInviterUnAmi').style.borderColor = '#E07E0F';
			bool = false;
		} else {
			dojo.byId('emailInviterUnAmi').style.borderColor = '#DDDDDD';
		}
		
		if (!e2.isValid() || t2.trim() == "") {
			dojo.byId('emailAmiInviterUnAmi').style.borderColor = '#E07E0F';
			bool = false;
		} else {
			dojo.byId('emailAmiInviterUnAmi').style.borderColor = '#DDDDDD';
		}
		
		if (t3.trim() == "") {
			dojo.byId('prenomInviterUnAmi').style.borderColor = '#E07E0F';
			bool = false;
		} else {
			dojo.byId('prenomInviterUnAmi').style.borderColor = '#DDDDDD';
		}
		
		if (t4.trim() == "") {
			dojo.byId('prenomAmiInviterUnAmi').style.borderColor = '#E07E0F';
			bool = false;
		} else {
			dojo.byId('prenomAmiInviterUnAmi').style.borderColor = '#DDDDDD';
		}

		return bool;
	}
	
	/**
	 *
	 * */
	var doSubmit = function(e) {
	
		if (validate()) {
			dojo.io.bind({
				url: "2.0/inviterUnAmi.php?lang="+Lang.getValue('ext')+"&prenom="+prenom+"&email="+email+"&prenomAmi="+prenomAmi+"&emailAmi="+emailAmi,
				load: doSubmitResultHandler,
				mimetype: "text/javascript"
			});
		}
	}
	
	/**
	 *
	 * */
	var doSubmitResultHandler = function(type, data, evt) {

		var emailInput = dojo.byId('emailInviterUnAmi');
		emailInput.value = "";
		emailInput.style.borderColor = '#DDDDDD';
		
		var emailAmiInput = dojo.byId('emailAmiInviterUnAmi');
		emailAmiInput.value = "";
		emailAmiInput.style.borderColor = '#DDDDDD';
		
		var prenomInput = dojo.byId('prenomInviterUnAmi');
		prenomInput.value = "";
		prenomInput.style.borderColor = '#DDDDDD';
		
		var prenomAmiInput = dojo.byId('prenomAmiInviterUnAmi');
		prenomAmiInput.value = "";
		prenomAmiInput.style.borderColor = '#DDDDDD';
		dojo.byId('inviterUnAmiPrenomAmi').innerHTML = '';
		dojo.byId('inviterUnAmiPrenomAmiA').innerHTML = '';
		dojo.byId('inviterUnAmiPrenom').innerHTML = '';
		dojo.byId('inviterUnAmiPrenomDe').innerHTML = '';
		
		Dlg0.hide();
		alert('L\'email a ete envoye avec succes !');
	}
}

// les action sont g�r�r par le calendrier
function MapChangeDayControl() {}

MapChangeDayControl.prototype = new GControl();

MapChangeDayControl.prototype.initialize = function(map) 
{	
  	var container = document.createElement("div");
  	container.id = "menuMapContainerChangeDay";
	container.style.position = 'relative';
	container.style.display = "none";
	container.style.width = "285px";

	var fond = document.createElement("img");	
	fond.src = Conf.getValue('urlBaseStatic')+'img/menuMap/navMapBackgroundCalendar.png';
	fond.className = "pngfix";
	fond.height = "46";
	fond.width = "285";
	container.appendChild(fond);

	for (var i = 1; i < 11; i++) {
		if (document.getElementById('jour'+i)) {
			var day = document.createElement("img");
			day.id = 'jourMap'+i;
			day.style.position = "absolute";
			day.style.top = "10px";
			day.style.left = ((i-1)*24+3-1)+"px";
			day.style.cursor = 'pointer';
			
			// doesn't work on Opera
			day.title = document.getElementById('jour'+i).title;
			day.alt = document.getElementById('jour'+i).alt;	
		
			day.src = document.getElementById('jour'+i).src.replace('gif','png');
			day.className = 'pngfix';
			container.appendChild(day);
		}
	}
	
	var size = document.createElement("img");
	size.id = 'size';
	size.style.position = "absolute";
	size.className = "pngfix";
	size.style.top = "6px";
	size.style.left = (10*24+6)+"px";
	size.src = Conf.getValue('urlBaseStatic')+'img/menuMap/calendar.png';
	size.style.cursor = 'pointer';
	size.width="32";
	size.heigth="32";
	
  	GEvent.addDomListener(size, "click", function() {
												  
		if (Lang.getValue('isCssReverse')) {
			if (dojo.byId('menuMapContainerChangeDay').style.left == dojo.byId('mainContainer').offsetWidth+"px") {
				//alert(1);
				dojo.lfx.html.slideTo('menuMapContainerChangeDay', { top: 228, left: dojo.byId('mainContainer').offsetWidth },  400).play();
			} else {
				//alert(2);
				dojo.lfx.html.slideTo('menuMapContainerChangeDay', { top: 228, left: dojo.byId('mainContainer').offsetWidth-200 },  400).play();
			}
		} else {
			if (dojo.byId('menuMapContainerChangeDay').style.left == "0px") {
				dojo.lfx.html.slideTo('menuMapContainerChangeDay', { top: 228, left: -240 },  400).play();
			} else {
				dojo.lfx.html.slideTo('menuMapContainerChangeDay', { top: 228, left: 0 },  400).play();
			}
		}
  	});
	container.appendChild(size);
	
	map.getContainer().appendChild(container);
	
  	return container;
}

MapChangeDayControl.prototype.getDefaultPosition = function() 
{
	if (Lang.getValue('isCssReverse') ==true ) {
		return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(-285, 228));
	}
	return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(-285, 228));
}


// nouvelle class MyControl
function MapTopControl() {}

MapTopControl.prototype = new GControl();

MapTopControl.prototype.initialize = function(map) 
{	
	var container = document.createElement("div"); 
	container.id = "menuMapContainerTop";
	container.style.position = 'relative';
	
  	var fond = document.createElement("img");	
	fond.src = Conf.getValue('urlBaseStatic')+'img/menuMap/navMapBackgroundCorner.png';
	if (Lang.getValue('isCssReverse')) {
		fond.src = Conf.getValue('urlBaseStatic')+'img/menuMap/navMapBackgroundCornerRev.png';
	}
	fond.height = "110";
	fond.width = "147";
	fond.className = "pngfix";
	container.appendChild(fond);
	
  	map.getContainer().appendChild(container);
  	return container;
}

MapTopControl.prototype.getDefaultPosition = function() 
{	
	if (Lang.getValue('isCssReverse') == true) {
	  	return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(0, 0));
	} else {
	  	return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(0, 0));
	}
}

// nouvelle class MyControl
function MapMiddleControl() {}

MapMiddleControl.prototype = new GControl();

MapMiddleControl.prototype.initialize = function(map) 
{	
  	var container = document.createElement("div");
  	container.id = "menuMapContainerMiddle";
	container.style.position = 'relative';
	 
	var fond = document.createElement("img");
	fond.src =  Conf.getValue('urlBaseStatic')+'img/menuMap/navMapBackgroundMiddle.png';
	if (Lang.getValue('isCssReverse')) {
		fond.src =  Conf.getValue('urlBaseStatic')+'img/menuMap/navMapBackgroundMiddleRev.png';
	}
	fond.className = "pngfix";
	fond.height = "114";
	fond.width = "46";
	container.appendChild(fond);

	var changeMapSoleil = document.createElement("img");
	changeMapSoleil.id = 'changeMapSoleil';
	changeMapSoleil.style.top = '8px';
	changeMapSoleil.alt = Lang.getValue('previsionJournee');
	changeMapSoleil.title = Lang.getValue('previsionJournee');
  	this.setButtonStyle_(changeMapSoleil);
  	container.appendChild(changeMapSoleil);
  	GEvent.addDomListener(changeMapSoleil, "click", function() {
		MapAction.slv("soleil");
  	});

	var changeMapTempMin = document.createElement("img");
	changeMapTempMin.id = 'changeMapTempMin';
	changeMapTempMin.style.top = '40px';
	changeMapTempMin.alt = Lang.getValue('previsionNuit');
	changeMapTempMin.title = Lang.getValue('previsionNuit');
  	this.setButtonStyle_(changeMapTempMin);
  	container.appendChild(changeMapTempMin);
  	GEvent.addDomListener(changeMapTempMin, "click", function() {
		MapAction.slv("lune");
  	});

	var changeMapVent = document.createElement("img");
	changeMapVent.id = 'changeMapVent';
	changeMapVent.style.top = '72px';
	changeMapVent.alt = Lang.getValue('previsionVent');
	changeMapVent.title = Lang.getValue('previsionVent');
  	this.setButtonStyle_(changeMapVent);
  	container.appendChild(changeMapVent);
  	GEvent.addDomListener(changeMapVent, "click", function() {
		MapAction.slv("vent");
  	});

	map.getContainer().appendChild(container);	

  	return container;
}

MapMiddleControl.prototype.getDefaultPosition = function() 
{
	if (Lang.getValue('isCssReverse')) {
		return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(0, 114));
	}
	return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(0, 114));
}

MapMiddleControl.prototype.setButtonStyle_ = function(img) 
{
  	img.width = "32";
  	img.height = "32";
	img.style.position = "absolute";
  	img.style.cursor = "pointer";
	if (Lang.getValue('isCssReverse')) {
		img.style.right = '5px';
	} else {
		img.style.left = '5px';
	}
	img.className = "pngfix";
}


WZMoonPhase = new function() {

	var hemisphere = "nord";

	this.preinit = function(day, month, year) {
		MoonPhase.init(day, month, year);
	}
	
	this.init = function() {
		var objList = MoonPhase.getValue();
		document.getElementById('moonPhase').src = "http://static.woozor.com/img/iconeLune/128x128/png/"+objList[0].getIcon(hemisphere)+".png";
		initSpecial();
		
	}
	
	var initSpecial = function() {
		var objList = MoonPhase.getSpecialValue();
		if (document.getElementById('specialMoonPhaseIcon1')) {
			for (var i = 0; i < 4; i++) {
				if (objList[i]) {
					document.getElementById('specialMoonPhaseIcon'+(i+1)).src = "http://static.woozor.com/img/iconeLune/24x24/gif/"+objList[i].getIcon(hemisphere)+".gif";
					document.getElementById('specialMoonPhaseLabel'+(i+1)).innerHTML = objList[i].getDate()+"<br>"+objList[i].utcTime+" UTC";
				}
			}
		}
	}

	this.change = function(index) {
		var objList = MoonPhase.getValue();
		document.getElementById('moonPhase').src = "http://static.woozor.com/img/iconeLune/128x128/png/"+objList[index-1].getIcon(hemisphere)+".png";
	}
	
	this.setLng = function(lng) {
		if (lng < 0) {
			hemisphere = "sud"
		} else {
			hemisphere = "nord"
		}
		initSpecial();
	}
}



var MoonData = function() {
	this.NUM_ICONS = 16;
	this.CENTER = 9;
	this.day;
	this.month;
	this.year;
	this.number;
	
	this.MoonData = function() {}
	
	this.isFromDate = function(day, month, year) {
		if (this.day == day && this.month == month && this.year == year) {
			return true;
		}
		return false;
	}
	
	this.convertPhaseToNumber = function(txt) {
		if( typeof(txt) == "string") {
			sigpha = new Array("NL","PQ","PL","DQ");
			sigphaNum = new Array(1, 8, 16, 24);
			for (var i  = 0; i < sigpha.length; i++) {
				if (sigpha[i] == txt) {
					return sigphaNum[i];
				}
			}
		}
		return txt;
	}
	
	this.getIcon = function(hemisphere) {
		var num = this.convertPhaseToNumber(this.number)+1;
		var value = Math.floor(num / (29.5/this.NUM_ICONS));
		//if (value == 9) {value = 1;}
		if (value > this.NUM_ICONS) {
			value -= this.NUM_ICONS;
		}
		if (hemisphere == "sud") {
			var diff = this.CENTER - value;
			value = this.CENTER + diff;
			if (value == 17) {
				value = 1;	
			}
		}
		return value;
	}
	
	this.toString = function() {
		return this.day+" "+this.month+" "+this.year+" "+this.number+" "+this.getIcon()+  "\r\n";
	}
}

//nompha=new Array("NOUVELLE LUNE    ","PREMIER  QUARTIER", "PLEINE   LUNE    ","DERNIER  QUARTIER");
var SpecialMoonData = function() {
	var NEW_MOON = 0;
	var FIRST_QUARTER = 1;
	var FULL_MOON = 2;
	var LAST_QUARTER = 3;
	
	this.number;
	this.day;
	this.month;
	this.year;
	this.utcTime;
	
	this.getIcon = function(hemisphere) {
		//alert(this.number)
		switch (this.number) {
			case NEW_MOON : 
				return  1;
			case FIRST_QUARTER : 
				return (hemisphere == "sud") ? 13 : 5;
			case FULL_MOON :
				return 9;
			case LAST_QUARTER :
				return (hemisphere == "sud") ? 5 : 13;
		}
	}
	
	this.getDate = function() {
		return ((this.day < 10) ? "0"+this.day : this.day) + "/"+ ((this.month < 10) ? "0"+this.month : this.month) + "/"+this.year;
	}
	
	// lA DATE RENTRE EST 
	//-1 = inferieur
	//1 = superieur
	this.compare = function(day, month, year) {
		if (this.day == day && this.month == month && this.year == year) {
			return 0;	
		}
		if (month == this.month) {
			//alert(day+" "+this.day)
			if (day > this.day) {
				return 1	
			}
			return -1;
		}
		if (month < this.month) {
			return -1;	
		} else {
			return 1;	
		}
	}
	
	this.toString = function() {
		return this.day+" "+this.month+" "+this.year+" "+this.number+" "+this.number+" "+this.utcTime+  "\r\n";
	}
}

var Oar = function() { /*objets a ranger*/
	this.OK;
	this.CODE1;
	this.CODE2;
	this.n_jrl;
	this.JR_courant;
	this.bool ;
	this.chaine;
	this.compteur;
	
	this.Oar = function() {}
}

var MoonDate = function() {
	this.JJD;
	this.AN;
	this.MOIS;
	this.JOUR;
	this.TYPEA;
	this.NBMOIS;
	
	this.MoonDate = function() {}
}

MoonPhase = new function() {

	var car;
	var date;
	var moonDataList = [];
	var specialMoonDataList = []
	var index = 0;
	var specialIndex = 0;
	
	var trunc = function(x) {
		if (x>0.0) 
			return(Math.floor(x));
		else 
			return Math.ceil(x);
	}
	
	var JJDATEJ = function()
	{
		Z1=date.JJD+0.5;          
		Z=trunc(Z1);                                                               
		A=Z;                                                                       
		B=A+1524;                                                                  
		C=trunc((B-122.1)/365.25);                                                 
		D=trunc(365.25*C);                                                         
		E=trunc((B-D)/30.6001);                                                    
		date.JOUR=trunc(B-D-trunc(30.6001*E));     
		if(E<13.5)
			date.MOIS = trunc(E-1);      
		else 
			date.MOIS = trunc(E-13);                
		if(date.MOIS>=3) 
			date.AN = trunc(C-4716);       
		else 
			date.AN = trunc(C-4715);       
	} 
	
	var JJDATE = function()
	{
		Z1=date.JJD+0.5;
		Z=trunc(Z1);                                                               
		if (Z<2299161) A=Z;                                                        
		else {ALPHA=trunc((Z-1867216.25)/36524.25);                               
		A=Z+1+ALPHA-trunc(ALPHA/4);}                                         
		B=A+1524;                                                                  
		C=trunc((B-122.1)/365.25);                                                 
		D=trunc(365.25*C);                                                         
		E=trunc((B-D)/30.6001);                                                    
		date.JOUR=trunc(B-D-trunc(30.6001*E));  
		if(E<13.5) date.MOIS = trunc(E-1);     
		else date.MOIS = trunc(E-13);           
		if(date.MOIS>=3) date.AN = trunc(C-4716);      
		else   date.AN = trunc(C-4715);         
	}
	
	var BISG = function()
	/*         TYPEA = 0 annee commune.                         */
	/*         TYPEA = 1 annee bissextile.                      */
	
	{ 
		date.NBMOIS=12;
		date.TYPEA=0;
		if ((date.AN % 4)==0)               
			date.TYPEA=1;
		if ((date.AN % 100)==0 && (date.AN % 400)!=0) 
			date.TYPEA=0;
	}
	
	
	var BISJ = function()
		 /*         TYPEA = 0 annee commune.                         */
		 /*         TYPEA = 1 annee bissextile.                      */
	
	{ 
		date.NBMOIS=12;
		if ((date.AN % 4)==0) 
			date.TYPEA=1; 
		else 
			date.TYPEA=0;  
	}

	
	var moonph = function()     /* Fonction calculant les phases de la Lune */
	{
		PI314=3.141592653589793;
		tabm=new Array(0.041e0, 0.126e0, 0.203e0, 0.288e0, 0.370e0, 0.455e0, 0.537e0, 0.622e0,0.707e0, 0.789e0, 0.874e0, 0.956e0);
		xMOIS=date.MOIS;
		oar.CODE1=date.AN; 
		oar.CODE2=date.MOIS;
		if(date.MOIS==1){
			an=date.AN-1; 
			date.MOIS=12;
		} else {
			an=date.AN; 
			date.MOIS--;
		}
		an+=tabm[date.MOIS-1];
		k=(an-1900)*12.3685e0;
		lik=trunc(k);
		rk=lik;
		k=rk-0.25e0; 
		if(k<0.e0)
			k=k-1;
		rad=PI314/180e0;
		nx=0;
		with (Math) {
			for(ii=0;ii<12;ii++)
			{
				k = k+0.25;  
				t=k/1236.85e0; 
				t2=t*t; 
				t3=t*t2;
				j = 2415020.75933e0 + 29.5305888531e0*k + 0.0001337e0*t2 - 0.000000150e0*t3 + 0.00033e0*sin(rad*(166.56e0 + 132.87*t - 0.009*t2));
				m = rad*(359.2242e0 + 29.10535608e0*k - 0.0000333e0*t2 - 0.00000347e0*t3);
	
				m=m%(2*PI314);
				mp = rad*(306.0253e0 + 385.81691806e0*k + 0.0107306e0*t2 + 0.00001236e0*t3);
				mp=mp%(2*PI314);
				f = rad*(21.2964e0 + 390.67050646e0*k - 0.0016528e0*t2 - 0.00000239e0*t3);
				f=f%(2*PI314);
				oar.OK=0; 
				i=ii%4;
				if(i==0 || i==2)
				{
					j = j + (0.1734e0 - 0.000393e0*t)*sin(m)
						+ 0.0021e0*sin(2*m) - 0.4068e0*sin(mp)
						+ 0.0161e0*sin(2*mp) - 0.0004e0*sin(3*mp)
						+ 0.0104e0*sin(2*f) - 0.0051e0*sin(m+mp)
						- 0.0074e0*sin(m-mp) + 0.0004e0*sin(2*f+m)
						- 0.0004e0*sin(2*f-m) - 0.0006e0*sin(2*f+mp)
						+ 0.001e0*sin(2*f-mp) + 0.0005e0*sin(m+2*mp);
					date.JJD = j;
					testmoi(i,xMOIS);                     /*NL,PL */
					if(oar.OK==1) 
						affmoph(i);
				}
				else
				{
					j = j + (0.1721e0 - 0.0004e0*t)*sin(m)
						+ 0.0021e0*sin(2*m) - 0.6280e0*sin(mp)
						+ 0.0089e0*sin(2*mp) - 0.0004e0*sin(3*mp)
						+ 0.0079e0*sin(2*f) - 0.0119e0*sin(m+mp)
						- 0.0047e0*sin(m-mp) + 0.0003e0*sin(2*f+m)
						- 0.0004e0*sin(2*f-m) - 0.0006e0*sin(2*f+mp)
						+ 0.0021e0*sin(2*f-mp) + 0.0003e0*sin(m+2*mp)
						+ 0.0004e0*sin(m-2*mp) - 0.0003e0*sin(2*m+mp);
					if(i==1)
					{                            /* Premier quartier */
						date.JJD = j + 0.0028e0 - 0.0004*cos(m) + 0.0003e0*cos(mp);
						testmoi(i,xMOIS);
						if(oar.OK==1) 
							affmoph(i);
					}
					else
					{                            /* Dernier quartier */
						date.JJD = j - 0.0028e0 + 0.0004*cos(m) - 0.0003e0*cos(mp);
						testmoi(i,xMOIS);
						if(oar.OK==1) 
							affmoph(i);
					}
				}
			}   /*fermeture biblio Math*/
			if (oar.OK==1) 
				nx++;
			if (nx>=4 && oar.OK==0) 
				alert('break');               
		}
		date.AN=oar.CODE1; 
		date.MOIS=oar.CODE2;
		if (date.MOIS==2) 
			date.NBJRS=((date.TYPEA==0)?28:29);
		else {
			if(date.MOIS<8) 
				date.NBJRS=(((date.MOIS&1)!=0)?31:30);
			else 
				date.NBJRS=(((date.MOIS&1)!=0)?30:31);
		}
		/* editer les derniers jours du mois*/
		while (oar.JR_courant <= date.NBJRS) {
			affich_age();
		}
	}
	
	var testmoi = function(i,pMOIS)    /* le test sur le mois doit etre
									  fait sur JJD final et non sur sa
									  valeur brute. */
	{
		D=oar.CODE1/100.0;               /* TE-TU (P.B.) en secondes */
		TETUS = 32.23*(D-18.30)*(D-18.30)-15;
		TETUJ = TETUS/86400e0;
		date.JJD+=0.0003472222e0;  /* ajout de 30s pour arrondi sur la minute avant troncature lors de l'affichage */
		date.JJD+=(-TETUJ);
		if(date.JJD<2299160.5e0){
			JJDATEJ();
			BISJ();
		} else {
			JJDATE();
			BISG();
		}
		oar.OK=0;
		if(date.MOIS==pMOIS) 
			oar.OK=1;
		/*NL*/
		if (i==0) 
			if (pMOIS>date.MOIS) 
				init_jrl(pMOIS);
			else if (date.MOIS==12 && pMOIS==1) 
				init_jrl(pMOIS); 
	}
	
	var init_jrl = function(xmois)  /* calcul no jour lune du 1er du mois*/
	{
		if (oar.bool==0) {
			if (date.MOIS==2) 
				date.NBJRS=((date.TYPEA==0)?28:29);
			else {
				if(date.MOIS<8) 
					date.NBJRS=(((date.MOIS&1)!=0)?31:30);
				else 
					date.NBJRS=(((date.MOIS&1)!=0)?30:31);
			}
			oar.JR_courant=1; 
			oar.n_jrl=date.NBJRS-date.JOUR+2;  
		}
	}
	
	var affmoph = function(i)            /* affichage phase Lune */
	{
		mois=new Array("nul","janvier","février","mars ","avril"," mai ","juin ", "juillet","août ","septembre","octobre","novembre","décembre");
		mois_fix=new Array("nul","janvier  ","février  ","mars     ","avril    ","mai      ","juin     ","juillet  ","août     ","septembre","octobre  ","novembre ","décembre ");
		nompha=new Array("NOUVELLE LUNE    ","PREMIER  QUARTIER", "PLEINE   LUNE    ","DERNIER  QUARTIER");
		sigpha=new Array("NL","PQ","PL","DQ");
		tabjm=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
					  /* date et heure */
		if(date.JJD<2299160.5E0) 
			JJDATEJ(); 
		else 
			JJDATE();
		FRACJ=(date.JJD+0.5E0)%1.0;
		jour=date.JOUR;
		HH=FRACJ*24e0; 
		hh=Math.floor(HH);
		FRACJ-=hh/24.e0; 
		MM=FRACJ*1440.e0; 
		mm=Math.floor(MM);
		if(hh==24)                    /* cas op heure=24 ....... */
		{
			jfin=tabjm[date.MOIS-1];
			if(date.JJD<2299160.5E0) 
				BISJ(); 
			else  
				BISG();
			if(date.MOIS==2 && date.TYPEA==1)
				jfin=29;
			if(date.JOUR<jfin) { 
				hh=0; 
				jour=date.JOUR+1;
			}
		} 
		if (hh<10) 
			hh="0"+hh;
		if (mm<10) 
			mm="0"+mm;
		
		while (oar.JR_courant < date.JOUR) /*affich_age(form);*/ 
		{
			nombre=oar.JR_courant++;
			
			var moonData = new MoonData();
			moonData.day = nombre;
			
			//document.form.CAL_JR.value=document.form.CAL_JR.value +  nombre;
			nombre=oar.n_jrl++;
			if (date.AN>=-9 && date.AN<=99) 
				oar.chaine="  " + date.AN;
			else 
				oar.chaine=date.AN;
			
			moonData.month = date.MOIS;
			moonData.year = oar.chaine;
			moonData.number = nombre;
			moonDataList[index] = moonData;
			index++;
	
			//document.form.CAL_JR.value=document.form.CAL_JR.value + " "+ mois_fix[date.MOIS] + " " + oar.chaine +"    " + nombre + "\r\n  ";
		}
	
	/*marquer phase*/
		nombre=oar.JR_courant++;

		var moonData = new MoonData();
		moonData.day = nombre;

		//document.form.CAL_JR.value=document.form.CAL_JR.value +  nombre;
		if (date.AN>=-9 && date.AN<=99) 
			oar.chaine="  " + date.AN;
		else 
			oar.chaine=date.AN;
			
		moonData.month = date.MOIS;
		moonData.year = oar.chaine;
		//moonData.number = moonData.convertPhaseToNumber(sigpha[i]);
		moonData.number = sigpha[i];
		moonDataList[index] = moonData;
		index++;
		
		//document.form.CAL_JR.value=document.form.CAL_JR.value + " "+ mois_fix[date.MOIS] + " " + oar.chaine +"    " + sigpha[i] + "\r\n  ";
		if (i==0) {
			oar.n_jrl=2; 
			oar.bool=1;
		} else 
			oar.n_jrl++;
		
		var moonDataSpe = new SpecialMoonData();
		moonDataSpe.day = jour;
		moonDataSpe.month = date.MOIS;
		moonDataSpe.year = date.AN;
		moonDataSpe.number = i;
		moonDataSpe.utcTime = hh + ":" + mm;
		specialMoonDataList[specialIndex] = moonDataSpe;
		specialIndex++;
		
		
		//form.PHASES.value=form.PHASES.value + nompha[i] + " " + jour + " " + mois[date.MOIS] + " " + date.AN + " à " + hh + "h" + mm + "m UTC\r\n";
	}
	
	var affich_age = function()
	{
		mois_fix=new Array("nul","janvier  ","février  ","mars     ","avril    ","mai      ","juin     ","juillet  ","août     ","septembre","octobre  ","novembre ","décembre ");
		

		nombre=((oar.JR_courant<=9)?"0" + oar.JR_courant++:oar.JR_courant++);
		
		var moonData = new MoonData();
		moonData.day = nombre;

		//document.form.CAL_JR.value=document.form.CAL_JR.value +  nombre;
		nombre=((oar.n_jrl<=9)?"0" + oar.n_jrl++:oar.n_jrl++); 
		if (date.AN>=-9 && date.AN<=99) 
			oar.chaine="  " + date.AN;
		else 
			oar.chaine=date.AN;
			
		moonData.month = date.MOIS;
		moonData.year = oar.chaine;
		moonData.number = nombre;
		moonDataList[index] = moonData;
		index++;

		//document.form.CAL_JR.value=document.form.CAL_JR.value + " "+ mois_fix[date.MOIS] + " " + oar.chaine +"    " + nombre + "\r\n  ";
	}
	
	
	var couran = function(month, year) {
		date = new MoonDate();
		oar = new Oar();
		
		date.AN=year//(form.nyear.value=="") ? "0" :eval(form.nyear.value);
		date.MOIS=month//(form.nmonth.value=="") ? "0" :eval(form.nmonth.value);
		oar.bool=0;
		//if (date.AN<-4000 || date.AN>2500) {
		//	alert('hors limites');
		//}
		//if (date.MOIS<1 || date.MOIS>12) {
		//	alert('hors limites');
		//}
		//form.PHASES.value="";
		//form.CAL_JR.value="";
		moonph();
	}
	
	var suivan = function() {
		//date.AN=(form.nyear.value=="") ? "0" :eval(form.nyear.value);
		//date.MOIS=(form.nmonth.value=="") ? "0" :eval(form.nmonth.value);
		if (++date.MOIS==13) { 
			date.MOIS=1; date.AN++;
			if (date.AN<-4000 || date.AN>2500) {
				alert('hors limites');
				date.AN--; 
				date.MOIS=12;
				return;
			}
		}
		//form.nyear.value=date.AN; 
		//form.nmonth.value=date.MOIS;
		//form.PHASES.value="";
		//form.CAL_JR.value="";
		oar.bool=0;
		moonph();
	}
	
	var findFirst =  function(day, month, year) {
		for (var i = 0; i < moonDataList.length; i++) {
			if (moonDataList[i].isFromDate(day, month, year)) {
				return i;
			}
		}
		return -1;
	}
	
	var findSpecialFirst = function(day, month, year) {
		for (var i = 0; i < specialMoonDataList.length; i++) {
			var result = specialMoonDataList[i].compare(day, month, year);
			if (result == 0 || result == -1) {
				return i;	
			} 
		}
		return -1;
	}
	
	this.init = function(day, month, year) {
		
		couran(month, year);
		suivan();
		var indexBegin = findFirst(day, month, year);
		var specialIndexBegin = findSpecialFirst(day, month, year);
		if (specialIndexBegin == -1) specialIndexBegin = 4;
		
		moonDataList = moonDataList.slice(indexBegin, indexBegin+10);
		specialMoonDataList = specialMoonDataList.slice(specialIndexBegin, specialIndexBegin+4);
		//alert(this.toString());
		//alert(findSpecialFirst(day, month, year))
	}
	
	this.getValue = function() {
		return moonDataList;
	}
	
	this.getSpecialValue = function() {
		return specialMoonDataList;
	}
	
	this.toString = function() {
		var ret = "";
		for (var i = 0; i < moonDataList.length; i++) {
			ret += moonDataList[i].toString();
		}
		for (var i = 0; i < specialMoonDataList.length; i++) {
			ret += specialMoonDataList[i].toString();
		}

		return ret;
	}
}

Localisation = new function() {	

	this.GOOGLE_MAP_URL = "http://maps.google.com/?ie=UTF8&ll=${LAT},${LNG}&z=10";
	this.YAHOO_MAP_URL = "http://maps.yahoo.com/broadband/#mvt=m&lat=${LAT}&lon=${LNG}&mag=6&zoom=12&q1=${LAT}%2C${LNG}";
	this.LIVE_MAP_URL = "http://maps.live.com/default.aspx?v=2&FORM=LMLTCP&cp=${LAT}~${LNG}&style=r&lvl=11&tilt=-90&dir=0&alt=-1000&cam=${LAT}~${LNG}&scene=-1&phx=0&phy=0&phscl=1&encType=1";
	this.OPEN_STREET_MAP_URL = "http://www.openstreetmap.org/index.html?lat=${LAT}&lon=${LNG}&zoom=12";

	this.cityName = "";
	this.lat = 0.0;
	this.lng = 0.0;
	this.locMap = null;

	this.changeCity = function(cityName, lat, lng) {
		this.cityName = cityName;
		this.lat = lat;
		this.lng = lng;
		if (this.locMap == null) {
			locMap = new GMap2(dojo.byId("mapLocalisation"), {backgroundColor:'#FFFFFF'});
			locMap.addControl(new GSmallZoomControl());
			//dojo.byId('mapLocalisation').style.width = "100%";
			//dojo.byId('mapLocalisation').style.height = "100%";
			locMap.checkResize();
			locMap.setCenter(new GLatLng(this.lat, this.lng), 10);
		} else {
			locMap.panTo(new GLatLng(this.lat, this.lng));
		}

		this.initModule();
	}
	
	this.initModule = function() {
		dojo.byId('localisationHeader').innerHTML = this.cityName;
		dojo.byId('localisationLat').innerHTML = this.convertCoordToString(true, this.lat);
		dojo.byId('localisationLat').title = this.lat;
		dojo.byId('localisationLng').innerHTML = this.convertCoordToString(false, this.lng);
		dojo.byId('localisationLng').title = this.lng;
		
		dojo.byId('viewInGoogleMap').href = 		this.getFormatedUrl(this.GOOGLE_MAP_URL);
		dojo.byId('viewInYahooMap').href = 			this.getFormatedUrl(this.YAHOO_MAP_URL);
		dojo.byId('viewInLiveMap').href = 			this.getFormatedUrl(this.LIVE_MAP_URL);
		dojo.byId('viewInOpenStreetMap').href = 	this.getFormatedUrl(this.OPEN_STREET_MAP_URL);
	}
	
	this.getFormatedUrl = function(url) {
		url=url.replace('${LAT}', this.lat).replace('${LAT}', this.lat);
		url=url.replace('${LNG}', this.lng).replace('${LNG}', this.lng);
		return url;
	}
	
	this.convertCoordToString = function(b, latOrLng)  {
		var choice = ['N', 'S'];
		if (b == false) {
			choice = ['E', 'W'];
		}
		var coord = this.convertCoord(latOrLng);
		//40°26'21"N 79°58'36"W
		return coord[1]+"°"+coord[2]+"'"+coord[3]+choice[coord[0]]
	}
	
	this.convertCoord = function(degfloat) {
		var digits = 2;
		var sign = 0;
		if (degfloat < 0) {
			sign = 1;
			degfloat *= -1;
		}
		
		var deg = parseInt( degfloat )
   		var minfloat = 60 * ( degfloat - deg )
		var min = parseInt ( minfloat )
		var secfloat = 60 * ( minfloat - min )
		
		//Round seconds to desired accuracy:
		
		var secfloat = parseInt( secfloat);//, digits )
		
		//After rounding, the seconds might become 60. These two
		//if-tests are not necessary if no rounding is done.
		
		if (secfloat == 60) {
			min = min + 1
			secfloat = 0
		}
		
		if (min == 60) {
			deg = deg + 1;
			min = 0
		}
		
		//Return output: 
		
		return [sign, deg, min, secfloat]


	}


}


function Cookie(_1){
var _2=_1;
this.getCookie=function(){
if(document.cookie){
var _3=document.cookie.indexOf(_2);
if(_3!=-1){
var _4=(document.cookie.indexOf("=",_3)+1);
var _5=document.cookie.indexOf(";",_3);
if(_5==-1){
_5=document.cookie.length;
}
return unescape(document.cookie.substring(_4,_5));
}
}
return "";
};
this.setCookie=function(_6,_7,_8,_9,_a){
var _b=_2+"="+escape(_6)+((_7)?"; expires="+_7.toGMTString():"")+((_8)?"; path="+_8:"")+((_9)?"; domain="+_9:"")+((_a)?"; secure":"");
document.cookie=_b;
};
this.getDateCookie=function(){
var _c=new Date;
_c.setFullYear(_c.getFullYear()+10);
return _c;
};
}

function Email(_1){
var _2=_1;
this.isValid=function(){
var _3=/^[a-zA-Z0-9_-]+@[a-zA-Z0-9-]{2,}[.][a-zA-Z]{2,3}$/;
if(_3.exec(_2)==null){
return false;
}
return true;
};
}

function sprintf(){
if(!arguments||arguments.length<1||!RegExp){
return;
}
var _1=arguments[0];
var re=/([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X)(.*)/;
var a=b=[],numSubstitutions=0,numMatches=0;
while(a=re.exec(_1)){
var _4=a[1],pPad=a[2],pJustify=a[3],pMinLength=a[4];
var _5=a[5],pType=a[6],rightPart=a[7];
numMatches++;
if(pType=="%"){
subst="%";
}else{
numSubstitutions++;
if(numSubstitutions>=arguments.length){
alert("Error! Not enough function arguments ("+(arguments.length-1)+", excluding the string)\nfor the number of substitution parameters in string ("+numSubstitutions+" so far).");
}
var _6=arguments[numSubstitutions];
var _7="";
if(pPad&&pPad.substr(0,1)=="'"){
_7=_4.substr(1,1);
}else{
if(pPad){
_7=pPad;
}
}
var _8=true;
if(pJustify&&pJustify==="-"){
_8=false;
}
var _9=-1;
if(pMinLength){
_9=parseInt(pMinLength);
}
var _a=-1;
if(_5&&pType=="f"){
_a=parseInt(_5.substring(1));
}
var _b=_6;
if(pType=="b"){
_b=parseInt(_6).toString(2);
}else{
if(pType=="c"){
_b=String.fromCharCode(parseInt(_6));
}else{
if(pType=="d"){
_b=parseInt(_6)?parseInt(_6):0;
}else{
if(pType=="u"){
_b=Math.abs(_6);
}else{
if(pType=="f"){
_b=(_a>-1)?Math.round(parseFloat(_6)*Math.pow(10,_a))/Math.pow(10,_a):parseFloat(_6);
}else{
if(pType=="o"){
_b=parseInt(_6).toString(8);
}else{
if(pType=="s"){
_b=_6;
}else{
if(pType=="x"){
_b=(""+parseInt(_6).toString(16)).toLowerCase();
}else{
if(pType=="X"){
_b=(""+parseInt(_6).toString(16)).toUpperCase();
}
}
}
}
}
}
}
}
}
}
_1=_4+_b+rightPart;
}
return _1;
}

function Texte(_1){
var _2=_1;
this.getTexte=function(){
return _2;
};
this.ucfirst=function(){
var t=new Array();
for(j=0;j<_2.length;j++){
if(j==0){
t[j]=_2.substr(j,1).toUpperCase();
}else{
t[j]=_2.substr(j,1);
}
}
_2=t.join("");
return _2;
};
this.trim=function(){
_2=_2.replace(/(^\s*)|(\s*$)/g,"");
return _2;
};
}

Trace=new function(){
var _1="debugTrace";
var _2="";
this.init=function(){
$(_1).style.display = "block";
};
this.add=function(_3){
_2=_3+"<br>"+_2;
$(_1).innerHTML=_2;
};
};



