// JavaScript Document

  function ShowBigPicture(picture_index)
  {
//if (ie)
    {
      var width = pictures_big_width[picture_index] + 30;
      var height = pictures_big_height[picture_index] + 30;
      var scrollbar = scrollbars[picture_index];

      NewWindow=window.open('', '','width='+width+',height='+height+',toolbar=no,directories=no,menubar=no,locations=no,status=no,scrollbars='+scrollbar+',resizable=yes,fullscreen=no');
      NewWindow.document.open();

      NewWindow.document.writeln("<html>\n<head>\n");
      NewWindow.document.writeln("<title>Inwestycje.pl</title>");      
      NewWindow.document.writeln("</head>");
      NewWindow.document.writeln("<body style=\"margin-top: 0; font-family:Arial, Helvetica, sans-serif; font-size:11px; background: white;\">");
      NewWindow.document.writeln("<div style=\"margin: 0 auto; text-align: center; width: 100%;\">");
      NewWindow.document.writeln("<a href=\"javascript:window.close();\"><img src=\""+pictures_big[picture_index]+"\" border=\"0\" alt=\"\" /></a><br />");
      NewWindow.document.writeln("<br /><a href=\"javascript:window.close();\">Zamknij okno</a>\n");
      NewWindow.document.writeln("</div><br /><br /></body>\n</html>\n");
      NewWindow.document.close();
      NewWindow.focus();
    }
    return;
  }
  var inwestycje_request = false;

    function pobierzInwestycjeMiasta(miasto,map,woj16) {

        url="/inwestycje_xml.php?miasto="+escape(miasto);
        //url="/text.xml";
        inwestycje_request = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            inwestycje_request = new XMLHttpRequest();
            if (inwestycje_request.overrideMimeType) {
                inwestycje_request.overrideMimeType('text/xml');                
            }
        } else if (window.ActiveXObject) { // IE
            try {
                inwestycje_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    inwestycje_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!inwestycje_request) {
            alert('Poddaję się :( Nie mogę stworzyć instancji obiektu XMLHTTP');
            return false;
        }
        
        inwestycje_request.onreadystatechange = function() { aktualizujMape(inwestycje_request,map); };
        inwestycje_request.open('GET', url, true);
        inwestycje_request.send(null);
        //makeNoweOferty(woj16,miasto);
    }
    
    function aktualizujMape(request,map) {
        //var form     = document.forms['inwestycje_dodaj'];
        
        if (request.readyState == 4) {
            if (request.status == 200) {
                var xmldoc = request.responseXML;
                var root_node = xmldoc.getElementsByTagName('inwestycje').item(0);
                
                var miasto = root_node.getElementsByTagName('miasto');                                
                
                map_x=miasto[0].getElementsByTagName('map_x').item(0).firstChild.data;  
                map_y=miasto[0].getElementsByTagName('map_y').item(0).firstChild.data; 

                map.setCenter(new GLatLng(map_y, map_x), 11);
                
                var inw = root_node.getElementsByTagName('inwestycja');
                
                //map.clearOverlays(); nie kasuj poprzednich punktow
                
                markery = new Array();
                                
                for (i=0; i<inw.length; i++)  {                                
                    var point = new GLatLng(inw[i].getElementsByTagName('map_y').item(0).firstChild.data,
                                        inw[i].getElementsByTagName('map_x').item(0).firstChild.data);              
                    var balonik = '<div class="balon">';
                    
                    /*if (inw[i].getElementsByTagName('foto').length) {
                       balonik += '<div class="balon_foto"><img style="float: right;" src="/inwestycje_foto/thumb70s.php?id='+inw[i].getElementsByTagName('foto').item(0).firstChild.data+'" alt="foto" /></div>';
                    }*/
                    balonik += '<div class="balon_txt"><b>' + inw[i].getElementsByTagName('nazwa').item(0).firstChild.data + '</b><br />';
                    //balonik += 'przeznaczenie: '     + inw[i].getElementsByTagName('nazwa').item(0).firstChild.data + '<br />';
                    balonik += 'termin realizacji: ' + inw[i].getElementsByTagName('termin').item(0).firstChild.data + '<br /></div>';
                    balonik += '<div style="clear: both;"></div><p align="right"><a href="?id=' + inw[i].getElementsByTagName('id').item(0).firstChild.data + '">więcej &raquo;</a></p>';
                    
                    balonik += '</div>'
                    //markery[i] = createMarker(point,inw[i].getElementsByTagName('nazwa').item(0).firstChild.data);
                    map.addOverlay(createMarker(point,balonik));
                  
                }
                                
            } else {
                alert('Wystąpił problem z zapytaniem. '+request.statusText);
            }
        }
  }
  
  function pobierzInwestycjeWoj16(map,woj16) {

        url="/inwestycje_xml.php?woj16="+escape(woj16);
        //url="/text.xml";
        
        inwestycje_request = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            inwestycje_request = new XMLHttpRequest();
            if (inwestycje_request.overrideMimeType) {
                inwestycje_request.overrideMimeType('text/xml');                
            }
        } else if (window.ActiveXObject) { // IE
            try {
                inwestycje_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    inwestycje_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!inwestycje_request) {
            alert('Poddaję się :( Nie mogę stworzyć instancji obiektu XMLHTTP');
            return false;
        }
        inwestycje_request.onreadystatechange = function() { aktualizujMapeWoj16(inwestycje_request,map); };
        inwestycje_request.open('GET', url, true);
        inwestycje_request.send(null);
        //makeNoweOferty(woj16,miasto);
    }
    
    function aktualizujMapeWoj16(request,map) {
        //var form     = document.forms['inwestycje_dodaj'];
        
        if (request.readyState == 4) {
            if (request.status == 200) {
                var xmldoc = request.responseXML;
                var root_node = xmldoc.getElementsByTagName('inwestycje').item(0);
                
                var woj16 = root_node.getElementsByTagName('wojewodztwo');                                
                
                map_x=woj16[0].getElementsByTagName('map_x').item(0).firstChild.data;  
                map_y=woj16[0].getElementsByTagName('map_y').item(0).firstChild.data;  
                zoom=woj16[0].getElementsByTagName('zoom').item(0).firstChild.data;  

                map.setCenter(new GLatLng(map_y, map_x), 8);
                
                var inw = root_node.getElementsByTagName('inwestycja');
                
                map.clearOverlays();
                
                markery = new Array();
                                
                for (i=0; i<inw.length; i++)  {                                
                    var point = new GLatLng(inw[i].getElementsByTagName('map_y').item(0).firstChild.data,
                                        inw[i].getElementsByTagName('map_x').item(0).firstChild.data);              
                    var balonik = '<div class="balon">';
                    
                    /*if (inw[i].getElementsByTagName('foto').length) {
                       balonik += '<div class="balon_foto"><img style="float: right;" src="/inwestycje_foto/thumb70s.php?id='+inw[i].getElementsByTagName('foto').item(0).firstChild.data+'" alt="foto" /></div>';
                    }*/
                    balonik += '<div class="balon_txt"><b>' + inw[i].getElementsByTagName('nazwa').item(0).firstChild.data + '</b><br />';
                    //balonik += 'przeznaczenie: '     + inw[i].getElementsByTagName('nazwa').item(0).firstChild.data + '<br />';
                    balonik += 'termin realizacji: ' + inw[i].getElementsByTagName('termin').item(0).firstChild.data + '<br /></div>';
                    balonik += '<div style="clear: both;"></div><p align="right"><a href="?id=' + inw[i].getElementsByTagName('id').item(0).firstChild.data + '">więcej &raquo;</a></p>';
                    
                    balonik += '</div>'
                    //markery[i] = createMarker(point,inw[i].getElementsByTagName('nazwa').item(0).firstChild.data);
                    map.addOverlay(createMarker(point,balonik));
                  
                }
                                
            } else {
                alert('Wystąpił problem z zapytaniem. '+request.statusText);
            }
        }
  }
  
  
  function makeNoweOferty(woj16){
	//alert('makeNoweOferty('+woj16+','+miejscowosc);
		//url = '/ajax/nowe_inwestycje.php?woj16='+woj16+'&miejscowosc='+miejscowosc;
url = '/ajax/nowe_inwestycje.php?woj16='+woj16;
		
		
		ajax =  new Ajax.Updater(
							'najnowsze_inwestycje',        // DIV id must be declared before the method was called
							 url,        // URL
							{                // options
								method:'get',
								onComplete:function(){ new Effect.Highlight('najnowsze_inwestycje', {duration: 3});
								},
								encoding:'UTF-8'             
							}
						  );
		
		
}
