function loadForm(response, szerokosc) {

    //Dodanie div'ów w których wyświetlana jest zawartość okienka 
    var d1 = document.createElement('div');
    d1.id = "ajx";
    d1.style.display = "none";
    document.body.appendChild(d1);

    var d2 = document.createElement('div');
    d2.id = "ajx_form_bg";
    d2.style.display = "none";
    document.body.appendChild(d2);

    var d3 = document.createElement('div');
    d3.id = "ajx_content";
    d3.style.display = "none";
    d3.style.width = szerokosc+"px";
    d3.style.height = "auto";
    d2.appendChild(d3);

    
    $('div#ajx').css('opacity',0.6).show();
    $('div#ajx_form_bg').show();
    $('div#ajx_content').html(response+'<div id="ajx_close" onclick="ajx_close()" title="Zamknij okno"></div>').show();

    if (document.getElementById('#wysiwyg')){
        
        $('#wysiwyg').wysiwyg();

        var html = $.ajax({url : "http://localhost/bilb/public/bilb/szablonyumow/index/umowy/listapunktow/",async: false}).responseText;
        $('#eee').append(html);

    }

}
function updateSelectlist(response) {
    $('td.wartosc#change').html(response);
}

function loadSelectlist(link) {
    var id = $('select :selected').val();
    link = link+'dk/'+id;
    var html = $.ajax({
        url: link,
        async: false
    }).responseText;
    updateSelectlist(html);
}

function ajx_close() {
    $('div#ajx_content').remove();
    $('div#ajx').remove();
    $('div#ajx_form_bg').remove();

}

function callAjax(link, szerokosc) {
    var html = $.ajax({
        url: link,
        async: false
    }).responseText;
    loadForm(html, szerokosc);
    JT_init();
}

function okienko(){

    var d1 = document.createElement('div');
    d1.id = "dialog";
    d1.style.width = "400px";
    d1.style.height = "400px";
    
    document.body.appendChild(d1);

        $('#dialog').dialog({
            autoOpen: false,
            width: 600,
            buttons: {
                "Ok": function() {
                    $(this).dialog("close");
                },
                "Cancel": function() {
                    $(this).dialog("close");
                }
            }
        });

}

function check_login(){

}

function check_subdomain(){

}

function mapa(){

    var mapka = document.createElement('div');
    mapka.id = "map";
    mapka.style.display = "none";
    document.body.appendChild(mapka);

	$('div#map').show();
	
	if (GBrowserIsCompatible()) {

      var lastmarker;

      // == creates a draggable marker with an input form ==
      function createInputMarker(point) {
        var marker = new GMarker(point,{draggable:true, icon:G_START_ICON});
        GEvent.addListener(marker, "click", function() {
          lastmarker = marker;
        });
        map.addOverlay(marker);
        lastmarker=marker;
		process();
        return marker;
      }

      // == creates a "normal" marker
      function createMarker(point,text) { 
        var marker = new GMarker(point);
        GEvent.addListener(marker,"click", function() {
          marker.openInfoWindow(document.createTextNode(text));
        });
        map.addOverlay(marker);
        return marker;
      }

      // == Display the map, with some controls and set the initial location 
      var map = new GMap2(document.getElementById("map"),{draggableCursor:"default"});
	  var wsp = new GClientGeocoder();

      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());
	  
	  var address = document.getElementsByName('miejscowosc')[0].value+', '+document.getElementsByName('ulice')[0].value;
	  
	  wsp.getLatLng(
                address,
                function(pt) {
                  if (!pt) {
                    alert(address + " - nie umiem znaleźć");
                  } else {
                    map.setCenter(pt, 16);
                  }
                }
              );

      GEvent.addListener(map,"click",function(overlay,point){
        if (!overlay) {
          createInputMarker(point);
        }
      });

      function process() {
        // == obtain the data
        var lat = lastmarker.getPoint().lat();
        var lng = lastmarker.getPoint().lng();
		document.getElementsByName('wsp_x')[0].value = lng;
		document.getElementsByName('wsp_y')[0].value = lat;

        // ===== send the data to the server
        //GDownloadUrl(url, function(doc) {    });  

        // == remove the input marker and replace it with a completed marker
        //map.closeInfoWindow();
        //var marker = createMarker(lastmarker.getPoint(),details);
        //GEvent.trigger(marker,"click");

      }
      

    }
    
    // display a warning if the browser was not compatible
    else {
      alert("Sorry, the Google Maps API is not compatible with this browser");
    }
 

}
