function remVill(index,id){
	document.getElementById(id).innerHTML="-- Empty --";
	document.getElementById(id).style.color="";
	document.getElementById(id).style.fontWeight="";
	document.forms['pref_vill'].elements["v"+index].value="";
}

function chkVill(index,id){
		var w = document.getElementById("w"+index).value;
		var v = document.getElementById("v"+index).value;
		var url = "checkVillage.php?w="+w+"&v="+escape(v);
		
		
		if(v!="")
		var myAjax = new Ajax.Request(
			url, 
			{
				method: 'get',
				onFailure: function()
					{
						alert("Error sending data server.");
						document.getElementById(id).innerHTML="-- Empty --";
						document.getElementById(id).style.color="";
						document.getElementById(id).style.fontWeight="";
					},
				onSuccess: function(response)
					{
						var r = response.responseText;
						if (r != "-- Empty --") {
							var name = r.substring( r.indexOf(";")+1)
							var coord = r.substring( 0,r.indexOf(";"))
							document.forms['pref_vill'].elements["v"+index].value=coord+","+name;
							document.getElementById(id).innerHTML = "<img src='../images/graphic/buildings/snob.png'>&nbsp;" + name;
							document.getElementById(id).style.color = "#4F9840";
							document.getElementById(id).style.fontWeight = "bold";
						}
						else{
							alert("Villaggio non trovato controlla coordinate e mondo o riprova dopo il prossimo aggiornamento del server.")
							document.getElementById(id).innerHTML="-- Empty --";
							document.getElementById(id).style.color="";
							document.getElementById(id).style.fontWeight="";
						}
					}
			});
		
	}

function dotNum(mynum){

	if(""+mynum == "undefined" || ""+mynum == "NaN")
		return 0;

	var out ="";
	var count=1;
	for(var i=((""+mynum).length -1);i>=0;i--){
		out = (""+mynum).charAt(i) + out;
		if( count%3==0 && count!=(""+mynum).length)
			out =  "." + out ;
		count++;
	}	
	
	return out;
}

var header = '<table class="brd" width=100% cellpadding=5><tr>	<td align="center"><a href="http://www.antopedia.org/modules/news/"><img border=0 src="../common/ant.png" alt="antopedia" title="Ant-O-Pedia Homepage" /></a></td>	<td align="center"><a href="../index.html"><img border=0 src="../common/graphic/snob.png" alt="tw home" title="Tribal Suite Home" /></a></td>	<td align="center"><a href="../distance/distance.html"><img border=0 src="../common/speed.png" alt="distance" title="Distance Calculator" /></a></td>	<td align="center"><a href="../beautifier/CR_parser.html"><img border=0 src="../common/def.png" alt="cr" title="Combat Report Beautifier" /></a></td>	<td align="center"><a href="../freefarm/freefarm.html"><img border=0 src="../common/graphic/farm.png" alt="factory" title="Free My Factory" /></a></td></tr></table>';


function parseVillage(v,s){
	v = v.replace(" ","")
	if(v.indexOf("\(")!=-1)
		v = v.substring( v.indexOf("\(")+1);
	if(v.indexOf("\)")!=-1)
		v = v.substring(0, v.indexOf("\)") );

	if( v.indexOf("\|")<0 )
		alert("Formato coordinate "+s+" non corretto!")

	return v;
}

function calcTrip(v1,v2){
	var data_v1 = v1.split("\|");
	var data_v2 = v2.split("\|");
	var x = parseInt(data_v1[0]) - parseInt(data_v2[0]);
	var y = parseInt(data_v1[1]) - parseInt(data_v2[1]);
	return Math.sqrt( (x*x)+(y*y));
}
