routeEnd=''
routeStart=''
//loading('on','loading interface functions...')

function showAddress3(address) {//questa usa il geocoding dell'indirizzo
//loading('on')
//alert(address)
geocoder = new GClientGeocoder();
geocoder.getLocations(address,function(locObject) {
if (locObject.Status.code==602)alert('indicazioni troppo vaghe o indirizzo sconosciuto')
if (locObject.Placemark.length==1) {
			Windows.close('locationPoint')
			loading('off')
		showPoint(locObject.Placemark[0].address);
		}
	else {
	if (locObject.Placemark.length>1){
		$('subAddr').style.display='inline';
			$('subAddr').options[0]=new Option;
			$('subAddr').options[0].text='scegli una alternativa:'
		
		for(x=0;x<(locObject.Placemark.length);x++){
			$('subAddr').options[x+1]=new Option;
			$('subAddr').options[x+1].value=locObject.Placemark[x].Point.coordinates
			$('subAddr').options[x+1].text=locObject.Placemark[x].address
		}
	loading('off')
	}//if
}//else


})	
}//function showAddress3

function showPoint(address){
lastAddress=address;//serve per il tracciamento della strada
geocoder = new GClientGeocoder();
geocoder.getLatLng(address,function(point) {
	if (!point) {
		alert(address + " non riesco a trovarlo!");
	} else {
		myPoint=point;
		var icon = new GIcon();
		icon.image = "img/24-tag-add.png";
		//icon.shadow = "homeshadow.png";
		icon.iconSize = new GSize(29, 25);
		icon.shadowSize = new GSize(41,36);
		icon.iconAnchor = new GPoint(6, 20);
		icon.infoWindowAnchor = new GPoint(5, 1);
		marker = new GMarker(point,icon);
		map.addOverlay(marker);
		map.panTo(new GLatLng(point.y,point.x))
		rd=Math.floor(Math.random()*1001)
		//infowindow
			var win = new Window('tool', {className: "dialog", width:350, height:200,zIndex: 100, resizable: true}) 
			win.getContent().innerHTML=address
			win.getContent().innerHTML+='<br>tc[][\'name\']=\'\''
			win.getContent().innerHTML+='<br>tc[][\'tel\']=\'\''
			win.getContent().innerHTML+='<br>tc[][\'adr\']=\''+address+'\''
			win.getContent().innerHTML+='<br>tc[][\'x\']='+point.x
			win.getContent().innerHTML+='<br>tc[][\'y\']='+point.y
			win.setDestroyOnClose()
			win.setStatusBar("informazioni sul circolo"); 
			win.show()

		//listeners
		GEvent.addListener(marker, "mouseover", function() {
			AdrToolTip(marker,address, rd);
		});
		GEvent.addListener(marker, "mouseout", function() {
			AdrRemoveToolTip(rd);
		});
		GEvent.addListener(marker, "click", function() {
							permaToolTip(marker,'home');
					});
    }
    }
);
}



function AdrToolTip(marker, address,rd){
a=document.createElement('DIV')
a.setAttribute('class','pox')
a.setAttribute('id','pox'+rd)

map.getPane(G_MAP_MAP_PANE).appendChild(a)
iH='<p>'+address+'</p>';
document.getElementById('pox'+rd).style.position='absolute'
document.getElementById('pox'+rd).style.left=(map.fromLatLngToDivPixel(marker.getPoint()).x+10)+'px'
document.getElementById('pox'+rd).style.top=(map.fromLatLngToDivPixel(marker.getPoint()).y-10)+'px'
//utilities
//iH+=point;
document.getElementById('pox'+rd).innerHTML=iH;
}

function AdrRemoveToolTip(rd){
a=document.getElementById('pox'+rd);
map.getPane(G_MAP_MAP_PANE).removeChild(a)
}

function permaToolTip(marker,what){
	mk=marker;
	rndTT=Math.floor(Math.random()*1000)
	idpTT='pTT'+rndTT

	//alert(what)
	if(what>0) buildWindow(what,idpTT) //è un numero, quindi un circolo tennis

	//window generation
	leftK=map.fromLatLngToDivPixel(mk.getPoint()).x+50
	topK=map.fromLatLngToDivPixel(mk.getPoint()).y

	//alert(mk.getPoint().x)


	var win = new Window(idpTT, {className: "dialog", width:350, height:200,zIndex: 100, resizable: true}) 
	win.setLocation(topK, leftK)

	if(what!='home') win.setTitle(tc[what]['name'])

	win.getContent().innerHTML=ih
	win.setDestroyOnClose()
	win.setStatusBar("informazioni sul circolo"); 
	win.show()
}

function buildWindow(myData,idpTT){
	ih='';
	if(myData!='home'){
	ih+='<p class=name>'+tc[myData]['name']+'</p>'
	ih+='<p class=adr>'+tc[myData]['adr']+'</p>'
	ih+='<p class=tel>'+tc[myData]['tel']+'</p>'
	}


else ih+='<p>rispetto al punto definito:</p>'

ih+='<p><a href=\"javascript:setRoute(\'start\','+myData+'),Windows.close(\''+idpTT+'\')\">parti da qui</a> </p>';
ih+='<p><a href=\"javascript:setRoute(\'end\','+myData+'),Windows.close(\''+idpTT+'\')\">arriva qui</a> </p>';
ih+='<p><a href=\"javascript:zoomTc('+myData+'),Windows.close(\''+idpTT+'\')\">guarda il circolo</a> </p>';
if(tc[myData]['img']){
for(x=0;x<tc[myData]['img'].length;x++)
ih+='<a href=javascript:showImg(\''+'img/'+tc[myData]['img'][x]+'\')><img class=\"th\" src=\"img/'+tc[myData]['img'][x]+'\"></a>'
}
return ih;
}

function showImg(imgSource){
var win = new Window(imgSource, {className: "dialog", width:650, height:490,zIndex: 101, resizable: true})
win.setTitle(imgSource)
win.getContent().innerHTML='<img src=' + imgSource + ' />'
win.setDestroyOnClose()
win.setStatusBar("immagini del circolo"); 
win.show()
}



function setRoute(mode,x){
url='http://maps.google.it'
arg1='/maps?f=d&hl=it&saddr='
arg2='&daddr='
//alert(x)
if(Math.ceil(x)>0){//è uno dei punti segnati in tennisASC
if(mode=='end') routeEnd=tc[x]['adr'];
if(mode=='start') routeStart=tc[x]['adr'];
}
else{//è un punto inserito a mano
if(mode=='end') routeEnd=lastAddress;
if(mode=='start') routeStart=lastAddress;
}
getReq=url+arg1+escape(routeStart)+arg2+escape(routeEnd)
if((routeEnd!='')&&(routeStart!='')) document.location.href=getReq
}

function zoomTc(x){
map.setZoom(17)
map.setMapType(G_SATELLITE_MAP)
map.setCenter(new GLatLng(tc[x]['y'],tc[x]['x']))
}

function addLocation() {
var win = new Window('locationPoint', {className: "dialog", width:600, height:200,zIndex: 100, resizable: true}) 
win.setTitle('aggiungi un punto')
win.getContent().innerHTML='<p style=text-align:center><img src=img/24-tag-add.png><P>'
win.getContent().innerHTML+='<p>Puoi inserire un punto sulla mappa per utilizzarlo nei calcoli dei percorsi stradali;'
win.getContent().innerHTML+='per esempio puoi inserire l\'indirizzo di casa tua per pianificare il percorso per raggiungere uno dei punti</p>'  
win.getContent().innerHTML+='<p>Indirizzo del punto da inserire:<br><input type=text id=adr><input value=cerca type=button onclick="lookAdr()">'
win.getContent().innerHTML+='<select onmouseup="showPoint(this.options[this.options.selectedIndex].text);Windows.close(\'locationPoint\')" id="subAddr"/>'
win.getContent().innerHTML+='</p>'
win.setDestroyOnClose()
win.setStatusBar("inserimento punto"); 
win.showCenter()
}

function getAPRS(){

loading('on','get APRS weather stations data....')
//sc='http://utenti.linkomm.net/php/aprs/weather.php?lat='+map.getCenter().y+'&lon='+map.getCenter().x
//sc='http://utenti.linkomm.net/php/aprs/aprs.php?lat='+map.getCenter().y+'&lon='+map.getCenter().x
var w=map.getBounds().getSouthWest().x;
var s=map.getBounds().getSouthWest().y;
var e=map.getBounds().getNorthEast().x;
var n=map.getBounds().getNorthEast().y;
sc='http://utenti.linkomm.net/php/aprs/aprs.php?s='+s+'&n='+n+'&w='+w+'&e='+e
if(($('lastxhours').value)>0) sc+='&hour='+$('lastxhours').value
if($('onlymeteo').checked==true) sc+='&only=meteo';
/*
document.location=sc;
*/
addScript(sc);
}
	
function showAPRS(){
//cancello lo vecchie icone (?)
map.clearOverlays();

for(x=1;x<data.length;x++){
	//if(data[x]['wx']) {// e' una stazione meteo
	if(1==1) {// e' una stazione meteo
		myLat=(data[x]['lat'])
		myLon=(data[x]['lon'])
		point=new GLatLng(data[x]['lat'],data[x]['lon']);
		var icon = new GIcon();
			icon.shadow= 'img/sqshadow.png'
			icon.image= 'img/arancio.png'
            	if($('onlymeteo').checked) {
			celsius=(data[x]['tempf']-32)
			dig=(Math.floor((celsius/9)*5))
            		icon.image = 'http://utenti.linkomm.net/php/aprs/celsius.php?t='+dig;
			}
		else {
			 if(data[x]['type'])icon.image='img/'+data[x]['type'].replace('%','p');
			else icon.image='/img/iconbase.png'
			}
			//$('logo').innerHTML+='<br>' + icon.image +'<img src=' +icon.image + '>';
			icon.iconSize = new GSize(20, 20);
			icon.iconAnchor = new GPoint(6, 20);
			icon.shadowSize = new GSize(24, 24);
            		icon.infoWindowAnchor = new GPoint(5, 1);
			addWxMarker(point,icon,x,data[x]['station'],data[x]['status'],data[x]['type'].replace('%','p'))   
			//marker.openInfoWindowTabsHtml(infoTabs);
	}//if is meteo
}//fori
//alert(x)
if(x>99) alert('reach limit: 100 stations, no more data, try narrow search')
//alert(msg)
}
         

function openBar(marker,x){
	rndTT=Math.floor(Math.random()*1000)
	idpTT='pTT'+rndTT
	//window generation
	leftK=map.fromLatLngToDivPixel(marker.getPoint()).x+50
	topK=map.fromLatLngToDivPixel(marker.getPoint()).y
	var win = new Window(idpTT, {className: "dialog", width:340, height:320,zIndex: 100, resizable: true}) 
	win.setLocation(topK, leftK)
	//win.setTitle(data[x]['station'])
	win.getContent().innerHTML='<div id=bar></div>'
	win.setDestroyOnClose()
	win.setTitle("personal weather station"); 
	win.setStatusBar("APRS weather station data"); 
	win.show()
	goSize(x)
}

function addWxMarker(point,icon,x,station,status,type){
/*
var infoTabs = [
 new GInfoWindowTab("<div id=bar></div>\n<script src=js/weather.js></script>\n<script>\ngoSize(26)\n</script>\n"),
 new GInfoWindowTab("Tab #2", "This is tab #2 content")
];
*/
	var marker= new GMarker(point,icon)
		GEvent.addListener((marker), "click", function() {
			openBar(marker,x)
		});
		GEvent.addListener(marker, "mouseover", function() {
			var index=type.charAt(0)+type.charAt(2)
			var typeMsg=eval('sym[\''+index +'\']')
			AdrToolTip(marker,station + ' ' + typeMsg +'<br>' + type + ' ppp ' + status, 'rd');
		});
		GEvent.addListener(marker, "mouseout", function() {
			AdrRemoveToolTip('rd');
		});

map.addOverlay(marker);
			
}



