window.onload=set;
function set(){
	var hp=document.getElementById('cent').offsetHeight;
	if(hp>1200)
	{
		document.getElementById('meng').style.height=hp+'px';
		document.getElementById('mend').style.height=hp+'px';
	}
	if(document.getElementById('imgprev')){
		document.getElementById('imgprev').alt='';
	}
		
}
var flag=1;
var x,y,flyDiv;
var sg=true;
var key="";
var cond=new Array();
var xml='';
document.onmousemove=GetMousePos;
if(window.XMLHttpRequest)xml = new XMLHttpRequest();
else if(window.ActiveXObject)xml = new ActiveXObject("Microsoft.XMLHTTP");
function get_cond(num)
{
	xml.open("GET",'get_cond.php?num='+num, true);	 
	xml.onreadystatechange = function()
	{ 
		if(xml.readyState == 4)
		{
			eval(xml.responseText);
		}
	} 	 
	xml.send(null);
}
function suggest_cp(cp){
	xml.open("GET",'get_cp.php?cp='+cp, true);	 
	xml.onreadystatechange = function()
	{ 
		if(xml.readyState == 4)
		{
			document.getElementById('suggest_cp').innerHTML=xml.responseText;
		}
	} 	 
	xml.send(null);
}
function suggest_ncc(ncc){
	if(sg){
		sg=false;
		key=ncc;
		xml.open("GET",'get_ncc.php?ncc='+ncc, true);	 
		xml.onreadystatechange = function()
		{ 
			if(xml.readyState == 4)
			{
				document.getElementById('suggest_cp').innerHTML=xml.responseText;
				setTimeout("up_ncc()",800);
			}
		} 	 
		xml.send(null);
	}
}
function up_ncc(){
	sg=true;
}
function Humidex(temp,relh)	{
	temp=parseFloat(temp);
	relh=parseFloat(relh);k=temp + 273;
	eTs=Math.pow(10,((-2937.4 /k)-4.9283* Math.log(k)/Math.LN10 +23.5471));
	eTd=eTs * relh /100;
	humidex=Math.round(temp+ ((eTd-10)*5/9));
	if (humidex < temp)humidex=temp;
	return humidex;
}
function windchill(temp,wind) {
	chill=(13.12+0.6215*temp-11.37*Math.pow(wind,0.16)+0.3965*temp*Math.pow(wind,0.16));
	chill=Math.round(chill);
	if ( ( wind < 5 ) || ( wind > 100 ) || ( temp < -50 ) || ( temp > 15) ) {
		return temp;
	}
	else {
		return chill;
	}
}
function GetMousePos(e)
{
	x=(e) ? e.clientX+scrollX : window.event.clientX+document.documentElement.scrollLeft;
	y=(e) ? e.clientY+scrollY : window.event.clientY+document.documentElement.scrollTop;
	x=x-70;
	y=y+20;
	if(!flag){
		flyDiv.style.top=y+'px';
		flyDiv.style.left=x+'px';
	}
}
function show(ville){
	if(cond[ville]){

		flyDiv=document.createElement('div');
		flyDiv.className='flydiv';
		flyDiv.style.top=y+'px';
		flyDiv.style.left=x+'px';
		(cond[ville][5])?dir1='E':dir1='W';
		(cond[ville][6])?dir2='N':dir2='S';
		ang=parseInt(cond[ville][7]);
		dir=dir2+dir2+dir1;
		if(ang > 80)dir=dir2;		
		if(ang < 60)dir=dir2+dir1;
		if(ang < 30)dir=dir1+dir2+dir1;
		if(ang < 10 )dir=dir1;
		
		if(cond[ville][3]<5)dir ='vrb'
		inner="<table>";
		inner+='<tr><th colspan=2>'+ville.replace(/\-/g," ")+'</th></tr>';
		inner+='<tr><td>vent  </td><td class="right">'+dir+' '+cond[ville][3]+'km/h</td></tr>';
		if(cond[ville][4] )inner+='<tr><td>rafale</td><td class="right">'+cond[ville][4]+' km/h</td></tr>';
		if(cond[ville][2])inner+='<tr><td>precip.</td><td class="right">'+cond[ville][2]+' mm</td></tr>';
		inner+='<tr><td>humidex </td><td class="right">'+Humidex(cond[ville][0],cond[ville][1])+'°</td></tr>';
		inner+='<tr><td>t° apparente </td><td class="right">'+windchill(cond[ville][0],cond[ville][3])+'°</td></tr>';
		inner+='</table>';
		flyDiv.innerHTML=inner;
		document.body.appendChild(flyDiv);
		flag=0;
	}
	
}
function hide(){
	if(!flag)document.body.removeChild(flyDiv);
	flag=1;
}
function contact(){
	window.open('http://meteo.region-nord.com/contact.php','contact','height=280,width=480,scrollbars=0,status=0,toolbar=0,top=50,left=50,resizable=0');
}

