function treat_maps(clas,usemap) {
	
	var nb_earth=0;
	
	if(window["evt_"+clas]) {
		document.getElementById(usemap).innerHTML=window["evt"+usemap+"_"+clas];
		//alert(window["nb_earth_"+clas]);
		nb_event_maps(window["nb_earth"+usemap+"_"+clas]);
	}
	else {
		var ma=document.getElementById(usemap);
		ma.innerHTML=window["save_map_"+usemap+"_html"];
		var lesclass=new Array();
		for (var i=1; i<(allclass.length+1) ;i++) {
			lesclass[i]=allclass[i];
				//alert(allclass[i]);
			if(window["CL"+usemap+"_"+allclass[i]]) nb_earth = nb_earth + window["CL"+usemap+"_"+allclass[i]].length;
			if(allclass[i]==clas) break;
		}	
		var j=0;
		while(document.getElementById("shape_"+usemap+"_"+j)) {
			var z=document.getElementById("shape_"+usemap+"_"+j);
					//alert(z.className+"  "+z);
			if(in_array(lesclass,z.className)==false) z.parentNode.removeChild(z); 
			j++;
		}
		window["evt"+usemap+"_"+clas]=ma.innerHTML;
		window["nb_earth"+usemap+"_"+clas]=nb_earth;
			//alert(window["nb_earth_"+clas]);
		nb_event_maps(nb_earth);
		
	}
}

function nb_event_maps(nb) {
	var new_nb=nb;
	if(nb==1) new_nb+=" earthquake";
	else new_nb+=" earthquakes";
			
	new_nb+=" on this map";
	document.getElementById("nb_earthquake").innerHTML=new_nb;
}	

function go_anchor(mapdefault) {
	if(window.location.hash.length>0) showcarte(parseInt(window.location.hash.substr(1)));
	else showcarte(mapdefault);
}	
//addonload(go_anchor);

function findMap(usemap) {
	//alert(document.getElementById("lacarte").fileCreatedDate+"  "+document.getElementById("lacarte").fileModifiedDate+"  "+document.getElementById("lacarte").fileUpdatedDate); 
	var url=document.getElementById("lacarte").src;
	var sr2=url.substring(url.lastIndexOf("/")+1);
	var mmap=sr2.substr(0,sr2.indexOf("."));
	var mtyp=sr2.substring(sr2.indexOf(".")+1,sr2.lastIndexOf("."));

	LoadMapHTML(mmap,mtyp,usemap);
}	

function LoadMapHTML(map,thetyp,usemap) {
	var xhr = getXhr();
	xhr.onreadystatechange = function(){
		// On recupere la liste des elements geographiques si on a tout reçu et que le serveur est ok
		if(xhr.readyState == 4 && xhr.status == 200){	
				//recuperation du retour
				//alert(xhr.responseText);
				var response = xhr.responseXML.documentElement;
				if(response.getElementsByTagName("area")[0]) {
				//	if(usemap=="world_map") {
					var ma=document.getElementById(usemap);
					if(!window["S_shape_"+usemap]) find_poly(usemap);
					
					ma.innerHTML=response.getElementsByTagName("area")[0].firstChild.nodeValue;
					ma.innerHTML+=window["S_shape_"+usemap];
					//}	
				}
				if(response.getElementsByTagName("nb")[0]) nb_event_maps(response.getElementsByTagName("nb")[0].firstChild.nodeValue);
		}
	}
		// ecriture de la requete ajax en post
	xhr.open("POST","/indexAjax_maparea.php",true); //http://static4.emsc-csem.org/
	xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		//envoi des arguments
	xhr.send("map="+map+"&typ="+thetyp+"&usemap="+usemap);
}	

function find_poly(usemap) {
	var te=document.getElementById(usemap);
	var j=0;
	while(document.getElementById("shape_"+usemap+"_"+j)) {
			var z=document.getElementById("shape_"+usemap+"_"+j);
			z.parentNode.removeChild(z); 
			j++;
	}		
		//alert(te.innerHTML);
	window["S_shape_"+usemap]=te.innerHTML;
}

function go_area_href(e) {
	//var x = e.pageX - $jq("#lacarte").offset().left;
	var x = xm1 - $jq("#lacarte").offset().left;
	var y = ym1 - $jq("#lacarte").offset().top;
	send_coo(x,y);
}	
	
function send_coo(x,y) {
		var el=document.getElementById("lacarte").src;
		var sr=el.substring(el.lastIndexOf("/")+1); 
		sr=sr.substring(0,sr.lastIndexOf("."));
		var xhr = getXhr();
		xhr.open("GET","/Earthquake/choose_correct.php?disp=ajax&l="+x+"&t="+y+"&c="+sr,true); 
		xhr.send(null);
		xhr.onreadystatechange = function(){
			if(xhr.readyState == 4 && xhr.status == 200){	
				var message=(typeof (JSON) !='undefined') ?  JSON.parse(xhr.responseText) : eval('('+xhr.responseText+')'); //alert(message+"       "+message.NB_POINTS);
				if(message.NB_POINTS && (message.NB_POINTS>1)) { /*alert("+1  "+message.NB_POINTS);*/
					//window.location.href="/Earthquake/earthquake.php?l="+x+"&t="+y+"&c="+sr;
					//window.open("/Earthquake/choose_correct.php?l="+x+"&t="+y+"&c="+sr,"Please select the specific earthquake","directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no, width=960, height=450");
					emsc_popup("/Earthquake/choose_correct.php?divpop=yes&l="+x+"&t="+y+"&c="+sr,960,450);
				} 
				else if(message.NB_POINTS && (message.NB_POINTS==1)) window.location.href="/Earthquake/earthquake.php?id="+message.EVID;
			}
		}	
}

function emsc_popup(url,width,height) {
	if(!document.getElementById("popup")) {
		var popup=document.createElement("div"); popup.id="popup"; 
		var ifr=document.createElement("iframe"); ifr.id="popifr"; ifr.src=url; ifr.width=width+"px"; ifr.height=height+"px"; //display:none;
		var sty=document.createElement("style"); sty.setAttribute("type", "text/css"); 
		var stytext=document.createTextNode("#popup {position:fixed;top:0;left:0;width:100%;height:100%;display:none;background:transparent url(/Css/img/fond_gris.png);} #popifr {border:0;frameborder:0;position:absolute;top:50%;left:50%;width:"+width+"px;height:"+height+"px;text-align:center;z-index:2;margin-left:-"+(width/2)+"px;margin-top:-"+(height/2)+"px;}");
		if(sty.styleSheet)   sty.styleSheet.cssText = stytext.nodeValue;	
		else sty.appendChild(stytext);
		popup.appendChild(ifr);
		document.getElementsByTagName('head')[0].appendChild(sty);
		document.body.appendChild(popup);
	}
	else { document.getElementById("popifr").src=url; }
	document.getElementById("popup").style.display="block";
}	
function emsc_pop_close() {document.getElementById("popup").style.display="none"; }

