<!--

var from = escape(document.referrer);
var query = location.search;
var colorDepth = window.screen.colorDepth;
var res = window.screen.width + "," + window.screen.height;
document.write("<img src='statystyka/zlicz.php?referer=" + from + "&query=" + query + "&kolory=" + colorDepth + "&rozdzielczosc=" + res + "' align='middle' style='display:none'>");

var okno = null;
function OtworzMape(url)
{
	width = 320;
	height = 430;
	if(okno) okno.close();
	ScrWidth = 640;
	ScrHeight = 480;
	if(window.screen)
	{
		ScrWidth = window.screen.width;
		ScrHeight = window.screen.height;
	}
	PosX = Math.round((ScrWidth - width) / 2);
	PosY = Math.round((ScrHeight - height) / 2);
	okno = window.open(url, "mapa", "menubar=no,toolbar=no,location=no,directories=no,status=yes,scrollbars=no,resizable=no,copyhistory=no,width=" + width + ",height=" + height + ",left=" + PosX + ",top=" + PosY);
	okno.focus();
}

function ZamknijOkno()
{
	jQuery('#homePopup').css("display","none");
}

function podmien_array(jeden, dwa)
{
	for(i = 1; i < dwa.length; i++)
	{
		if(dwa[i] == jeden)
		{
			if(document.getElementById)
			{
				if(document.getElementById('konfigurator_'+dwa[i]).style.display=="block")
				{
					document.getElementById('konfigurator_'+dwa[i]).style.display="none";
				}
				else
				{
					document.getElementById('konfigurator_'+dwa[i]).style.display="block";
				}
			}
			else if(document.all)
			{
				if(document.all['konfigurator_'+dwa[i]].style.display=="block")
				{
					document.all['konfigurator_'+dwa[i]].style.display="none";
				}
				else
				{
					document.all['konfigurator_'+dwa[i]].style.display=="block";
				}
			}
			else
			{
				alert("Twoja przeglądarka nie obsluguje JS poprawnie.");
			}
		}
		else
		{
			if(document.getElementById)
			{
				document.getElementById('konfigurator_'+dwa[i]).style.display="none";
			}
			else if(document.all)
			{
				document.all['konfigurator_'+dwa[i]].style.display="none";
			}
			else
			{
				alert("Twoja przeglądarka nie obsluguje JS poprawnie.");
			}
		}
	}
}

function SearchControl() {}

SearchControl.prototype.initialize = function(map) {
	var container = document.createElement("div");

	var inputSearch = document.createElement("input");
	inputSearch.style.zIndex=1000000000;
	container.appendChild(inputSearch);
	container.style.zIndex=1000000000;

	map.getContainer().appendChild(container);

	return container;
}
SearchControl.prototype.getDefaultPosition = function() {
	return new GControlPosition(G_ANCHOR_BOTTOM_RIGHT , new GSize(7, 7));
}




var map ='';
var directions =[];

var licznik =0;
var i =0;
var bounds='';
var points = [];
var newStartMarker ='';
function showAddress(address)
{


	// map = new GMap2(document.getElementById("mapArea"));
	//  map.addControl(new GSmallMapControl());
	geo = new  GClientGeocoder();
	map.clearOverlays();

	//GEvent.addListener(geo, "error", handleErrors);
	geo.getLatLng(address+", PL",
	function(response)
	{

		map.setCenter(response,11);

		newStartMarker = new GMarker(response,{ icon:redIcon });
		newStartMarker.bindInfoWindowHtml( 'Tu się znajdujesz: <br /><strong>'+address+'</strong>');

		// map.addOverlay(newStartMarker);
		points = [];
		jQuery.getJSON('/include/ajx/fillHotelPosition.php',{Lat:response.lat(), Lng: response.lng()},
		function (ret)
		{

			if(ret.items.length>0)
			{
				var poly='';
				var startMarker='';
				var endMarker='';

				 bounds = map.getBounds();
				jQuery('#mapDirect').html('');
				for (var i =0; i<ret.items.length; i++)
				{
					directions[i] = new GDirections();
					directions[i].nazwa = ret.items[i].nazwa	;
					directions[i].g = ret.items[i].g	;
					directions[i].tel = ret.items[i].tel	;
					directions[i].miasto = ret.items[i].m	;
					directions[i].ulica = ret.items[i].u	;
					GEvent.addListener(directions[i], "error", handleErrors);
					GEvent.addListener(directions[i], "load", function(test)
					{


						        poly=this.getPolyline();
						        startMarker	=this.getMarker(0);
						        endMarker	=this.getMarker(1);
								bounds.extend(endMarker.getLatLng());
								map.setZoom(map.getBoundsZoomLevel(bounds));

						        var newEndMarker  = new GMarker(endMarker.getLatLng(),{ icon:greenIcon });
						        newEndMarker.bindInfoWindowHtml( '<strong>'+this.nazwa+' '+this.g+' </strong><br />'+this.miasto+''+(this.ulica?', '+this.ulica:'')+'<br />tel: '+this.tel+'<br />Rezerwacja Hotel Express: <b>+48 0 514 583 951</b><br />odległość: '+this.getSummaryHtml());
						        map.addOverlay(newEndMarker);
						        fillOtherPoints();
						       map.addOverlay(newStartMarker);
					});
					points[points.length]= new GPoint(ret.items[i].Lng, ret.items[i].Lat);
					directions[i].load("from: "+response.lat()+', '+ response.lng()+"  to:  "+ret.items[i].Lat+", "+ret.items[i].Lng,{getPolyline:true});
					//alert('test');
				}
 				map.addOverlay(newStartMarker);


			}
		});
	});
}


function fillOtherPoints()
{
	var actualBounds = map.getBounds();
	var point1 = actualBounds.getSouthWest();
	var point2 = actualBounds.getNorthEast();
	jQuery.getJSON('/include/ajx/fillHotelPositionsInArea.php',{Lat1:point1.lat(), Lng1: point1.lng(),Lat2:point2.lat(), Lng2: point2.lng()},
	function (ret)
		{
			if(ret.items.length>0)
			{
				for (var i =0; i<ret.items.length; i++)
				{

					var found = 0;
					for (var j =0; j<points.length; j++)
					{
						//alert(new GPoint(ret.items[i].Lng,ret.items[i].Lat)+' = '+points[j]);
						if(points[j].equals(new GPoint(ret.items[i].Lng,ret.items[i].Lat))){found=1;}
					}
					if(found==0)
					{
					var newMarker  = new GMarker(new GPoint(ret.items[i].Lng,ret.items[i].Lat),{ icon:yellowIcon });
					newMarker.bindInfoWindowHtml( '<strong>'+ret.items[i].nazwa+' '+ret.items[i].g+' </strong><br />'+ret.items[i].m+''+(ret.items[i].u?', '+ret.items[i].u:'')+'<br />tel: '+ret.items[i].tel+'<br />Rezerwacja Hotel Express: <b>+48 0 514 583 951</b> ');
					map.addOverlay(newMarker);
					}
				}
			}
		});
}


    function handleErrors()
    {
	   if (this.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + this.getStatus().code);
	   else if (this.getStatus().code == G_GEO_SERVER_ERROR)
	     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + this.getStatus().code);

	   else if (this.getStatus().code == G_GEO_MISSING_QUERY)
	     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + this.getStatus().code);

	//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
	//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);

	   else if (this.getStatus().code == G_GEO_BAD_KEY)
	     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + this.getStatus().code);

	   else if (this.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("A directions request could not be successfully parsed.\n Error code: " + this.getStatus().code);

	   else if (this.getStatus().code == G_GEO_TOO_MANY_QUERIES)
	     alert("AThe given key has gone over the requests limit in the 24 hour period.\n Error code: " + this.getStatus().code);

	   //else alert("An unknown error occurred.: "+ this.getStatus().code);

	}



	function onDirectionsLoad(dirObj)
	{
		//map.clearOverlays();
		var html = '';
		var status = dirObj.getStatus();
		var bounds = dirObj.getBounds();

		var copyrightHTML = dirObj.getCopyrightsHtml();
		var summaryHTML = dirObj.getSummaryHtml();
		var distance = dirObj.getDistance();
		var duration = dirObj.getDuration();
		var numRoutes = dirObj.getNumRoutes();

		var startLatLng = dirObj.getRoute(0).getStep(0).getLatLng();
		var endLatLng = dirObj.getRoute(numRoutes-1).getEndLatLng();

		polyline = dirObj.getPolyline();
		pLine = copyPolyline(polyline);
		//alert(pLine);
		//map.addOverlay(polyline);


		loading = false;

	}


function copyPolyline(p) {
	pLinePoints = Array();
	for (var n = 0 ; n < p.getVertexCount() ; n++ ) {
		pLinePoints.push(p.getVertex(n));

	}
	var pLine = new GPolyline(pLinePoints,'#CCCCCC');
	return pLine;
}
-->
