// Sources prévision meteo 
var titre_=new Array();
var nom_w_zone=new Array();
var url_=new Array();
var disp_mode_x=new Array();
var period_x=new Array();
var type_list_x=new Array();

var disp_mode_idx=new Array();
var period=new Array();var period_idx=new Array();
var source_type=new Array();var source_type_idx=new Array();

									   
 function disp_sources() {
	 
	 s="";
	 var reg=new RegExp("_","g");
	 document.getElementById("sources_meteo").innerHTML="titre"+titre_.length;
	 for(var i=1;i<titre_.length;i++){
			 
	  s+='<div   >';
	  			var nwz_l=decodeURIComponent(nom_w_zone[i]);
				var nwz=nwz_l.replace(reg," ");
				 s+='<h2><div class="w_zone"><a href="/weather_zone/'+nwz_l+'">'+nwz+'</a></div>'+decodeURIComponent(titre_[i])+'</h2>';
						 
						 var k=0;
						  for (var j=0;j<period_idx.length;j++) {
							  if (period_x[i]==period_idx[j]) k=j;
						  }
					 s+='<div>'+decodeURIComponent(period[k])+' : '; 
					 var type_list_idx="*,"+type_list_x[i]+','; var v="";
					 
							 for (var j=0;j<source_type.length;j++) {
																if(	type_list_idx.indexOf(","+source_type_idx[j]+",",0)>0)	{s+=v+' '+decodeURIComponent(source_type[j]);v=",";}
							}
					 s+='</div>';
					if (disp_mode_x[i]==1) { // Inclusion 600
							s+='<iframe src="'+decodeURIComponent(url_[i])+'" width="870" height="600"></iframe>';
					}
					if (disp_mode_x[i]==2) { // Image
							s+='<img src="'+decodeURIComponent(url_[i])+'" alt="" title="" >';
					}
					if (disp_mode_x[i]==3) { // Inclusion1000
							s+='<iframe src="'+decodeURIComponent(url_[i])+'" width="870" height="1000"></iframe>';
					}			
					
					s+='<div class="fsize10">Source: ' +decodeURIComponent(url_[i])+'</div>	';
			s+='</div>';
	  }
	
	 document.getElementById("sources_meteo").innerHTML=s;
 }
 function call_source(){
	titre_.splice(0,titre_.length);
	nom_w_zone.splice(0,nom_w_zone.length);
 url_.splice(0,url_.length);
  disp_mode_x.splice(0, disp_mode_x.length);
   period_x.splice(0,period_x.length);
  type_list_x.splice(0,type_list_x.length);

  disp_mode_idx.splice(0,disp_mode_idx.length);
  period.splice(0, period.length);  period_idx.splice(0,period_idx.length);
  source_type.splice(0,source_type.length);  source_type_idx.splice(0,source_type_idx.length);

	 var message_="call_source=&lat="+lat_site+"&lng="+lng_site;
	 
	 go_(message_);
 }
// Meteo WX local
function appel_un_wx() {
  request = 'http://ws.geonames.org/findNearByWeatherJSON?lat='+lat_site+'&lng='+lng_site+'&callback=retour_un_wx&lang='+langue;
 
  // Create a new script object
 
  aObj = new JSONscriptRequest(request);
  // Build the script tag
  aObj.buildScriptTag();
  // Execute (add) the script tag
  aObj.addScriptTag();
}
 
function retour_un_wx(jData) {
	 var jw=jData.weatherObservation;
  if (jData == null || jw==null) {
	  
    
    return;
  }
 
 
  var s='<h2>'+lg_wx('Local Weather - last report','M&eacute;t&eacute;o locale (dernier relev&eacute;)','','')+'</h2>';
  s+='<table width="100%" cellspacing="4"><tr class="mt"><td><div  class="mt">Location</div></td><td><div  class="mt">Time <span class="mt_u">(TU)</span></div></td><td><div  class="mt">Wind speed <span class="mt_u">(knot)</span></div></td><td><div  class="mt">Wind direction <span class="mt_u">(deg)</span></div></td><td><div  class="mt">Sky</div></td><td><div  class="mt">Conditions</div></td><td><div  class="mt">Temperature <span class="mt_u">(&deg;C)</span></div></td><td><div  class="mt">Pressure <span class="mt_u">(hpa)</span></div></td></tr>';
  s+='<tr ><td><div  class="md">'+jw.stationName+'</div></td><td><div  class="md">'+jw.datetime+'</div></td><td><div  class="md">'+jw.windSpeed+'</div></td><td><div  class="md">'+jw.windDirection+'</div></td><td><div  class="md">'+jw.clouds+'</div></td><td><div  class="md">'+jw.weatherCondition+'</div></td><td><div  class="md">'+jw.temperature+'</div></td><td><div  class="md">'+jw.hectoPascAltimeter+'</div></td></tr>';
	s+='</table>';
	
   // On ne publie plus document.getElementById('wx_site').innerHTML = s;
  if ((Math.abs(lat_site-jw.lat)+Math.abs(lng_site-jw.lng))<0.4) { //aeroport pas loin à creer si besoin
	  var message_='aeroport='+encodeURIComponent(jw.stationName+" ("+jw.ICAO+")")+'&lat='+jw.lat+'&lng='+jw.lng+'&ICAO='+jw.ICAO+'&wind_s='+jw.windSpeed+'&wind_d='+jw.windDirection+'&pressure='+jw.hectoPascAltimeter+'&time_tu='+jw.datetime+'&other=';  // envoi pour créer ou updater un site			
		if (jw.clouds!="" && jw.clouds!="n/a") message_+=' '+jw.clouds;
		if (jw.weatherCondition!="" && jw.weatherCondition!="n/a") message_+=' Weather:'+jw.weatherCondition;
		if (jw.temperature!="" && jw.temperature!="n/a") message_+='  Air temperature:'+jw.temperature;
		go_(message_);
  }
}

function appel_wikipedia() {
 var ln=lat_site+0.02;var ls=lat_site-0.02;var le=lng_site+.03;var lw=lng_site-0.03;
 request = 'http://ws.geonames.org/wikipediaBoundingBoxJSON?north='+ln+'&south='+ls+'&east='+le+'&west='+lw+'&lang='+langue+'&callback=retour_wikipedia';
 
  // Create a new script object
 
  aObj = new JSONscriptRequest(request);
  // Build the script tag
  aObj.buildScriptTag();
  // Execute (add) the script tag
  aObj.addScriptTag();
}
//info local wikipedia
function retour_wikipedia(jData) {
  if (jData == null) {
    // There was a problem parsing search results
    return;
  }
  var wkp=jData.geonames;
   var s='<h2>'+lg_wx('Local Info','Informations locale','','')+' <span class="mt_u">(Wikipedia)</span></h2>';
  for (var i=0;i<wkp.length;i++) {
     s+='<a href="http://'+wkp[i].wikipediaUrl+'" target="_blank">'+wkp[i].title+'</a>: '+wkp[i].summary+'<br />';
  }
 	if (wkp.length>0) {
  			document.getElementById('info_wikipedia').innerHTML = s;
	}
}




function lg_wx(en,fr,it,es) { 
	 var s=en;
	 if (langue=="fr" && fr.length>0 ) s=fr;
	 if (langue=="it" && it.length>0 ) s=it;
	 if (langue=="es" && es.length>0 ) s=es;
	 return s;
 }




//
function JSONscriptRequest(fullUrl) {
    // REST request path
    this.fullUrl = fullUrl;
    // Keep IE from caching requests
    this.noCacheIE = '&noCacheIE=' + (new Date()).getTime();
    // Get the DOM location to put the script tag
    this.headLoc = document.getElementsByTagName("head").item(0);
    // Generate a unique script tag id
    this.scriptId = 'YJscriptId' + JSONscriptRequest.scriptCounter++;
}
 
// Static script ID counter
JSONscriptRequest.scriptCounter = 1;
 
// buildScriptTag method
//
JSONscriptRequest.prototype.buildScriptTag = function () {
 
    // Create the script tag
    this.scriptObj = document.createElement("script");
   
    // Add script object attributes
    this.scriptObj.setAttribute("type", "text/javascript");
    this.scriptObj.setAttribute("src", this.fullUrl + this.noCacheIE);
    this.scriptObj.setAttribute("id", this.scriptId);
}
 
// removeScriptTag method
//
JSONscriptRequest.prototype.removeScriptTag = function () {
    // Destroy the script tag
    this.headLoc.removeChild(this.scriptObj); 
}
 
// addScriptTag method
//
JSONscriptRequest.prototype.addScriptTag = function () {
    // Create the script tag
    this.headLoc.appendChild(this.scriptObj);
}

//Appel en fin de chargement
 

appel_wikipedia(); 
