
    //<![CDATA[

function getHTTPObject() {
var xmlhttp;
/*@cc_on
@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@else
xmlhttp = false;
@end @*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp = false;
	}
}
return xmlhttp;
}


var http = getHTTPObject(); // We create the HTTP Object


var map;
var icon0;
var marker;
var geocoder;
var adres_js;



function load() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(50.061020, 19.936680), 15);

        geocoder = new GClientGeocoder();

    icon0 = new GIcon();
	icon0.image = "http://www.google.com/mapfiles/marker.png";
	icon0.shadow = "http://www.google.com/mapfiles/shadow50.png";
	icon0.iconSize = new GSize(20, 34);
	icon0.shadowSize = new GSize(37, 34);
	icon0.iconAnchor = new GPoint(9, 34);
	icon0.infoWindowAnchor = new GPoint(9, 2);
	icon0.infoShadowAnchor = new GPoint(18, 25);

		GetPoint();


      }

    }
    //]]>

function handleHttpResponse_googlemaps() {
 // if (http.readyState == 1) { theobj.innerHTML = 'Aktualizacja...';  }

  if (http.readyState == 4) {
     results = http.responseText.split(",");
     x_tmp=results[0];
     y_tmp=results[1];
	 if(x_tmp!='' && y_tmp!='') { Setstart(x_tmp,y_tmp); }
    }
}

function handleHttpResponse_googlemaps_save() {
  //if (http.readyState == 1) { theobj.innerHTML = 'Aktualizacja...';  }
  if (http.readyState == 4) { SetMarketTxt(adres_js+'<br><br>'+http.responseText ); }
}

//pobierz dane juz wpisane
function GetPoint() {
   http.open("get",'googlemap.php?action=GetPoint',true);
   http.onreadystatechange = handleHttpResponse_googlemaps;
   http.send(null);
}

//zapsz nowe wspolrzedne
function SetPoint(xy) {
   http.open("get",'googlemap.php?action=SetPoint&xy='+xy, true);
   http.onreadystatechange = handleHttpResponse_googlemaps_save;
   http.send(null);
}

function Setstart(x,y)
{
map.clearOverlays();
//jesli jest juz ustawione

var point = new GLatLng(x,y);
marker = new GMarker(point, {draggable: true});
marker = createMarker(point)
map.addOverlay(marker);
map.setCenter(point,15);
//var point = new GPoint(y, x);

//map.addOverlay(createMarker(point, ''));

//------------------------
}

function createMarker(point) {
	 marker = new GMarker(point, {draggable: true});

    GEvent.addListener(marker, "dragend", function() {
     adres_js='';
     xy=marker.getPoint().toString();

     SetPoint(xy)
	 });

return marker;
}

 function SetMarketTxt(txt)
 {
  marker.openInfoWindowHtml(txt);
 }

    function addAddressToMap(response) {
      map.clearOverlays();
      if (!response || response.Status.code != 200) {
        alert("Przepraszamy, adres nie został znaleziony");
      } else {
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1],
                            place.Point.coordinates[0]);

        marker = new GMarker(point, {draggable: true});
        marker = createMarker(point)
        xy=marker.getPoint().toString();
        adres_js=place.address;
        SetPoint(xy)
        map.addOverlay(marker);
        marker.openInfoWindowHtml(place.address);
      }
    }

    function showLocation() {
      var address = document.getElementById('q').value;
      geocoder.getLocations(address, addAddressToMap);
    }

//GetPoint();


