//function mapaAdmin(lat, lng, message) {
//    document.getElementById('lat').value ='';
//    document.getElementById('lng').value = '';
//    var application = new MapaAdmin(message);
//    if(lat && lng){
//        application.istnieje(lat,lng);
//    }
//}

function mapa() {
    this.map = new GMap2(document.getElementById("maps"));
    this.map.setCenter(new GLatLng(54.358,18.648), 10);
    this.map.addControl(new GMapTypeControl());
    this.map.addControl(new GLargeMapControl());
    this.p = new Array();
    this.m = new Array();
    this.i = 0;
    this.odzial = function(lat,lng,message){
        this.p.push(new GLatLng(lat,lng));
        this.m.push(new GMarker(this.p[this.i]));
        this.map.addOverlay(this.m[this.i]);
        GEvent.bind(this.m[this.i], "click", this,function() {
            var myHtml = message;
//            this.map.setCenter(new GLatLng(lat,lng), 12);
            this.map.openInfoWindowHtml(new GLatLng(lat,lng), myHtml);
        });
        this.i = this.i + 1;
    }


}

function MapaAdmin(message) {
    this.message = message;
    this.map = new GMap2(document.getElementById("maps"));
    this.map.setCenter(new GLatLng(54.358,18.648), 10);

    this.map.addControl(new GMapTypeControl());
    this.map.addControl(new GLargeMapControl());

    this.m = new GMarker(new GLatLng(0,0));
    this.map.addOverlay(this.m);
    this.m.hide();
    this.p;

    this.istnieje = function(lat,lng){
        this.p = new GLatLng(lat,lng);
        this.m.setLatLng(this.p);
        this.m.show();
        document.getElementById('lat').value = this.m.getLatLng().lat();
        document.getElementById('lng').value = this.m.getLatLng().lng();
    }

    var myEventListener = GEvent.bind(this.map, "click", this, function(marker,point) {
        if (point) {
            this.m.setPoint(point);
            this.p = point;
            this.m.show();
            document.getElementById('lat').value = this.m.getLatLng().lat();
            document.getElementById('lng').value = this.m.getLatLng().lng();
        }

    });

    var myWindow= GEvent.bind(this.m, "click", this,function() {
        var myHtml = this.message;
        this.map.openInfoWindowHtml(this.p , myHtml);
    });

}
