function findPos(obj){var curleft=curtop=0;if(obj.offsetParent){do{curleft+=obj.offsetLeft;curtop+=obj.offsetTop;}while (obj=obj.offsetParent);}else if(p.x && p.y) {curleft=p.x;curtop=p.y;};return [curleft,curtop];}
var mark=[],i=0,map,dir,polska;
function creatMarker(point,txt)
{
	var ico = new GIcon();  
	ico.image = 'http://maps.google.com/mapfiles/kml/pal3/icon38.png';  
	ico.shadow = 'http://maps.google.com/mapfiles/kml/pal3/icon38s.png';  
	ico.iconSize = new GSize(32, 32);  
	ico.infoWindowAnchor = new GPoint(16,16);  
	ico.iconAnchor = new GPoint(16,16);  
	ico.shadowSize = new GSize(59, 32);   
	var marker = new GMarker(point,{icon:ico});
	GEvent.addListener(marker,'click',function(){marker.openInfoWindowHtml(txt);});
	mark[i++] = marker;
	return marker;
}
function $(e){return document.getElementById(e);}
function zoomOut()
{
	if(mark.length==0) return true;
	map.setCenter(polska, 6);
	return false;
}
function zoomIn(i)
{
	if(!mark[i]) return true;
	map.setCenter(mark[i].getPoint(), 16);
	return false;
}
function searchCB(i)
{
	$('opt'+i+'_1').style.display='';
	$('opt'+i+'_2').style.display='none';
	map.updateInfoWindow();
	
	return false;
}
function searchT(i)
{
	$('opt'+i+'_1').style.display='none';
	$('opt'+i+'_2').style.display='';
	map.updateInfoWindow();
	return false;
}


function handleErrors()
{
if (dir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
alert('Podana lokalizacja nie została odnaleziona');
       else if (dir.getStatus().code == G_GEO_SERVER_ERROR)
       alert('Błąd serwera');
       else if (dir.getStatus().code == G_GEO_MISSING_QUERY)
       alert('Błąd podczas komunikacji z serwerem');
       else if (dir.getStatus().code == G_GEO_BAD_KEY)
       alert('Nieprawidłowy klucz');
       else if (dir.getStatus().code == G_GEO_BAD_REQUEST)
       alert('Błąd podczas przetwarzania danych');
       else alert('Wystąpił nieznany błąd');
}
function fromto(e,n)
{
	$('l_from'+e).style.color = n==1 ? '#000' : 'blue';
	$('l_from'+e).style.fontWeight = n==1 ? 'bold' : 'normal';
	$('l_to'+e).style.color = n==2 ? '#000' : 'blue';
	$('l_to'+e).style.fontWeight = n==2 ? 'bold' : 'normal';
	$('i_from'+e).value = n;
	return false;
}
function makeHtmlWindow(id,title,address,img)
{
	return '<form action="" method="post" style="text-align:left;width:300px"><strong>'+title+'</strong><hr/>'+img+address+'<p style="padding-top:10px;clear:right" id="opt'+id+'_1"><a href="#" onclick="return zoomIn('+id+')" style="color:blue">Powiększ tutaj</a> <a href="#" onclick="return searchT('+id+')" style="color:blue">Pokaż trasę</a></p><p style="padding-top:10px;display:none;clear:right" id="opt'+id+'_2">Pokaż trasę: <a href="#" style="color:#000;font-weight:bold;text-decoration:none;cursor:default" onclick="this.blur();return fromto('+id+',1)" id="l_from'+id+'">Do tego miejsca</a> - <a href="#" onclick="this.blur();return fromto('+id+',2)" style="color:blue;text-decoration:none" id="l_to'+id+'">Z tego miejsca</a><br/><span style="color:#aeaeae">Adres początkowy (Ulica nr, Miasto)</span><br/><input name="localize_str" size="22" style="width:150px;padding:1px;font-size:10pt"/> <input type="submit" value="localize" style="font-size:10pt" /><input type="hidden" name="city" value="'+id+'"/><input type="hidden" name="i_from" id="i_from'+id+'" value="1"/><br/><a href="#" onclick="return searchCB('+id+')" style="color:#77c;text-decoration:none">&laquo; wstecz</a></p></form>';
}
window.onload = function(){loadEl();load();}
window.onunload = GUnload;
