if(!Array.indexOf){ 
	Array.prototype.indexOf = function(obj){ 
		for(var i=0; i<this.length; i++){ 
			if(this[i]==obj){ return i; } 
		} return -1; 
	} 
}

function ajaxmeteo()
{

 var xhr=null;

 if (window.XMLHttpRequest) 
 { 
  xhr = new XMLHttpRequest();
 }
 else if (window.ActiveXObject) 
 {
  xhr = new ActiveXObject("Microsoft.XMLHTTP");
 }
 
var strTS = new Date().toString().replace(/(:|\s)/gi,"");
 //on définit l'appel de la fonction au retour serveur
 xhr.onreadystatechange = function() { alert_ajaxmeteo(xhr); };    
 xhr.open("GET", "http://www.fasonews.net/php/getmeteo.php?" + strTS, true);
 xhr.send(null);

}

function alert_ajaxmeteo(xhr)
{
    if (xhr.readyState==4) 
    {    	
    	if(xhr.responseXML != null)
    	{
    	    var jourFr = new Array("Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam");
    	    var jourEn = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
    	    
    	    var vdate = new Date();
    	    var heure = vdate.getHours();

    	    
            var docXML= xhr.responseXML;
    	    var ccs = docXML.getElementsByTagName("cc");
	        var sh = '';
	        
            var temp = 0;
            if(ccs.length > 0) // Grande Icone + temperature du moment
      	    for (i=0;i < 1;i++)
    	    {
    	            var low = ccs.item(i).getElementsByTagName("tmp");
    	            var lowValue = low[0].firstChild.nodeValue;
    	            if(lowValue != 'N/A')
                    temp = lowValue;
                    else
                    temp = '';
                    var ic = ccs.item(i).getElementsByTagName("icon");
                    var icon = ic.item(1).firstChild.nodeValue;
    	            	        
    	        sh = sh + '<div style="width:120px;height:64px;float:left;;color:#505050"><img src="/images/weather/64x64/'+icon+'.png" width=64 heigh=64 align=left><h1 style="margin:0px"> ' + temp + '°</h1><small>Ouaga.</small></div>';
	        }

    	    var days = docXML.getElementsByTagName("day");

            if(days.length > 1)        
      	        for (i = days.length-1; i > 0; i--)
    	        {
		            var t = days.item(i).getAttribute('t');
		            var pos = '';
		            if(typeof t == 'string')
			            pos = t;
		            else
			            pos = t.value;

    	            var iJour = jourEn.indexOf(pos);
    	            var jour = jourFr[iJour];
    	            var hi = days.item(i).getElementsByTagName("hi");
    	            var hiValue = hi[0].firstChild.nodeValue;
        	        
    	            var low = days.item(i).getElementsByTagName("low");
    	            var lowValue = low[0].firstChild.nodeValue;

                    var ic = days.item(i).getElementsByTagName("icon");
                    var icon = ic.item(0).firstChild.nodeValue;
        	        
    	            sh = sh + '<div style="width:50px;height:64px;float:right;text-align:center;color:#505050"><small>' + jour + '<br/><img src="/images/weather/32x32/'+icon+'.png" width=32 heigh=32><br/>' + lowValue + '°-' + hiValue + '°</small></div>';
	            }
sh = sh + '<div style="height:10px;text-align:right;color:#DDDDDD"><small>Source Weather Channel<sup>&reg;</sup></small></div>';
	     
	        var objDiv = document.getElementById("meteoLayer");
	        if(objDiv != null)
		        objDiv.innerHTML = sh;
            
        }
        
    }
}

function init_ajaxmeteo()
{
	setTimeout("ajaxmeteo()", 1000);
}



