var server_name = null;

var Base64 = {
 
	// private property
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
 
	// public method for encoding
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;
 
		input = Base64._utf8_encode(input);
 
		while (i < input.length) {
 
			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);
 
			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;
 
			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}
 
			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
 
		}
 
		return output;
	},
 
	// public method for decoding
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;
 
		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
 
		while (i < input.length) {
 
			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));
 
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
 
			output = output + String.fromCharCode(chr1);
 
			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}
 
		}
 
		output = Base64._utf8_decode(output);
 
		return output;
 
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}

var google_maps_load = 0;

var map;
var geocoder;
var blnMarker = 0;
var directions = null;
var paginator = null;

var google_maps_latitude_default = "52.227799";
var google_maps_altitude_default = "21.005859";

var z = Array(" ", "-", "A", "Ą", "B", "C", "Ć", "D", "E", "Ę", "F", 
		  "G", "H", "I", "J", "K", "L", "Ł", "M", "N", "Ń", "O", 
		  "Ó", "P", "R", "S", "Ś", "T", "U", "W", "Y", "Z", "Ź", "Ż");

var cities = Array();
var actMarkers;

var arrMarker = new Array(); 
var marker_id = 0;

function setServerName(name)
{
	server_name = name;
}

function addMarker( uniqueID, groupID, latitude, altitude, strUrlIcon, blnDraggable, marker, strHtml, strLocation, strTyp, miasto, specjalizacja, adres, specjalizacjaNames )
{		
	var i = getArrMarkerID( uniqueID );	
	if ( i == null )
	{
		i = marker_id;
		marker_id++;
	}
	var spec = specjalizacja.split(";");
	var specNames = specjalizacjaNames.split(";");
	
	arrMarker[i] = new Array( uniqueID, groupID, latitude, altitude, strUrlIcon, blnDraggable, marker, strHtml, strLocation, strTyp, miasto, spec, adres, specNames );		

	
	if ( latitude.length == 0 || altitude.length == 0 )
	{
		//setMarkerLoc( miasto+' '+adres, i );
	}
}

function setMarkerLoc( strLoc, i )
{
	var GCG = new GClientGeocoder();
	var id = i;	
	GCG.getLatLng( strLoc, function(latlng){						
			if ( latlng != null )
			{
				arrMarker[id][2] = latlng.lat();
				arrMarker[id][3] = latlng.lng();
			}
	});
}


function clearMarker( ID )
{
	for ( var i=0; i<arrMarker.length; i++ )
	{
		if ( arrMarker[i][0] == ID || arrMarker[i][1] == ID )
		{						
			if ( arrMarker[i][6] != null )			
			{
				var marker = arrMarker[i][6];
				marker.remove();					
			}			
		}
	}
}

function clearMarkerNotID( uniqueID, typ )
{
	for ( var i=0; i<arrMarker.length; i++ )
	{
		if ( arrMarker[i][0] != uniqueID || arrMarker[i][9] != typ )
		{						
			if ( arrMarker[i][6] != null )			
			{
				var marker = arrMarker[i][6];
				marker.remove();					
			}			
		}
	}
}


function getArrMarkerID( uniqueID )
{
	for ( var i=0; i<arrMarker.length; i++ )
	{
		if ( arrMarker[i][0] == uniqueID )
		{			
			return i;
		}
	}
	
	return null;
}

function createMarker( groupID, uniqueID, strTyp )
{
	for ( var i=0; i<arrMarker.length; i++ )
	{
		if ( ( groupID != null && uniqueID != null && arrMarker[i][0] == uniqueID && arrMarker[i][1] == groupID ) ||
			 ( groupID == null && uniqueID != null && arrMarker[i][0] == uniqueID )	||
			 ( groupID != null && uniqueID == null && arrMarker[i][1] == groupID ) || 
			 ( strTyp  != null && uniqueID != null && arrMarker[i][0] == uniqueID && arrMarker[i][9] == strTyp ) 
		   )
		{			
			if ( arrMarker[i][2] != null && arrMarker[i][3] != null )
			{
				var marker = google_maps_create_marker( arrMarker[i][2], arrMarker[i][3], arrMarker[i][5], google_icon( arrMarker[i][4] ) );			
				setLocMarker( marker, i );		
				createInfoWindow( marker, i );						    		    
			    google_map.addOverlay(marker);		    		    
			    arrMarker[i][6] = marker;		    		    
		    }		    
		}
	}
}


function implode(glue, pieces)
{
    var res = "";
    for (var i = 0; i < pieces.length; i++)
    	res += pieces[i] + glue;
    return res;
}

function compareResults(a, b)
{
	var spec1 = arrMarker[a][11];
	var spec2 = arrMarker[b][11];
	
	var ai = 0;
	var bi = 0;
	
	while (!document.getElementById(spec1[ai]).checked)
		ai++;
	while (!document.getElementById(spec2[bi]).checked)
		bi++;
	
	return ai - bi;
}

function showSelectedMarkers()
{
	var i;
	var tekst = "";
	actMarkers.sort(compareResults);
	for ( var j=0; j<actMarkers.length; j++ )
	{			
		i = actMarkers[j];
		var marker = google_maps_create_marker( arrMarker[i][2], arrMarker[i][3], arrMarker[i][5], google_icon( arrMarker[i][4] ) );			
		setLocMarker( marker, i );		
		createInfoWindow( marker, i );						    		    
		google_map.addOverlay(marker);		    		    
		arrMarker[i][6] = marker;
		tekst += "<div style='border-bottom:1px solid #000000'>";
		tekst += implode("<br>", arrMarker[i]);		
		tekst += "</div>";
	}
	document.getElementById('placowki_opis').innerHTML = tekst;
}

function selectAll(str, check)
{
	var tab = str.split(";");
	for (var i = 0; i < tab.length; i++)
		document.getElementById(tab[i]).checked = check;
}

function testMarkerSpec(i)
{
	hej = 0;
	for (var j = 0; j < arrMarker[i][11].length; j++)
		if (document.getElementById(arrMarker[i][11][j]).checked)
			return true;
	return false;
}

function showMarker()
{
	actMarkers = new Array();
	for ( var i=0; i<arrMarker.length; i++ )
	{			
		if ( testMarkerSpec(i) && arrMarker[i][2] != null && arrMarker[i][3] != null )
			actMarkers.push(i);
	}
	showSelectedMarkers();
}

function showMarkerProvCity(prov, city)
{
	var arg = (city == 0);
	var arg2 = (prov == 0);
	actMarkers = new Array();
	for ( var i=0; i<arrMarker.length; i++ )
	{			
		if ( testMarkerSpec(i) && (arg || arrMarker[i][10] == city) && (arrMarker[i][1] == "wojewodztwo_" + prov || arg2) && arrMarker[i][2] != null && arrMarker[i][3] != null )
			actMarkers.push(i);
	}
	showSelectedMarkers();
}

function insertOption(city)
{
	var elSel = document.getElementById('city');
    var elOptNew = document.createElement('option');
    elOptNew.text = city;
    elOptNew.value = city;
    elSel.options.add(elOptNew); 
}

function updateAmbOptions() {
	var city = $("#city").val();
	
	$.ajax({
	  url: "index.php?option=com_maps&view=ajaxselect",
	  dataType: 'json',
	  data: "secondSelect=1&city=" + city,
	  type: 'POST',
	  success: function (data) {
	  	$("#amb option:dowolna, #szp option:dowolna").nextAll('option').remove();
	  
		var elSel = document.getElementById('amb');
		var elOptNew;
		for (var i = 0; i < data.spec.length; i++) {
		    elOptNew = document.createElement('option');
		    elOptNew.text = data.spec[i][0];
		    elOptNew.value = data.spec[i][1];
		    elSel.options.add(elOptNew); 			
		}
		
		elSel = document.getElementById('szp');
		elOptNew;
		for (var i = 0; i < data.szp.length; i++) {
		    elOptNew = document.createElement('option');
		    elOptNew.text = data.szp[i][0];
		    elOptNew.value = data.szp[i][1];
		    elSel.options.add(elOptNew); 			
		}	
		
	  
	  }
	});
}



function compare(a, b)
{
	var ai, bi, asub, bsub;
	var _short = Math.min(a.length, b.length);
	for (var i = 0; i < _short; i++)
	{
		ai = bi = 0;
		asub = a.substring(i, i+1);
		bsub = b.substring(i, i+1);
		while (asub != z[ai]) ai++;
		while (bsub != z[bi]) bi++;
		if (ai == bi) continue;
		else return ai - bi;
	}
	return a.length - b.length;
}

function cacheCities()
{
	for (var prov = 0; prov < 17; prov++)
	{
		cities.push(new Array());
	
		var actCity = "";
		var arrayCity = new Array();
		
//		for ( var i = 0; i < arrMarker.length; i++ )		
//			if (arrMarker[i][1] == "wojewodztwo_" + prov || prov == 0)
//				arrayCity.push(arrMarker[i][10]);


		for ( var i = 0; i < arrPC.length; i++ )		
			if (arrPC[i][0] == "wojewodztwo_" + prov || prov == 0)
				arrayCity.push(arrPC[i][1]);
		
		arrayCity.sort(compare);
		
		for ( var i = 0; i < arrayCity.length; i++ )
			if (actCity != arrayCity[i])
			{
				actCity = arrayCity[i];
				cities[prov].push(actCity);
			}
	}
	refreshMap(0,0, false);
	document.getElementById('selects').style.display = 'block';
	
}

function refreshMap(prov, city, refMap)
{
	if (city == 0)
	{
		document.getElementById('city').options.length = 1;
		for ( var i = 0; i < cities[prov].length; i++ )
				insertOption(cities[prov][i]);
	}
		
	if (refMap)
	{
		google_clear_marker();
		if (prov == 0 && city == 0)
			showMarker();
		else
			showMarkerProvCity(prov, city);
	}
}

function google_maps_szukaj( str )
{
	google_clear_marker();
	
	var dane = str.split(",");
	var res;
	actMarkers = new Array();
	for ( var i=0; i<arrMarker.length; i++ )
	{
		res = false;
		var re = new RegExp(dane[0].toUpperCase());
		res = res || re.test(arrMarker[i][10]);
		
		if (dane.length > 1)
		{
			var re2 = new RegExp(dane[1].toLowerCase());
			for (var j = 0; j < arrMarker[i][11].length; j++)
				res = res || re2.test(arrMarker[i][11][j]);
		}
		if (res)
			actMarkers.push(i);
	}
	showSelectedMarkers();
}



/*
function createInfoWindowPolygon( polygon, i )
{
	var strHtml = getInfoWindow( i );	
	GEvent.addListener( polygon, "click", function( overlay, latlng ) { 				  									 					 					  					  
		  google_map.openInfoWindow( polygon.getBounds().getCenter(), strHtml );
	});	
}
*/


function getInfoWindow( i )
{
	if ( arrMarker[i][7] == null || arrMarker[i][7] == "undefined" )
	{
		var strHtml = '';	
	}
	else
	{
		var strHtml = arrMarker[i][7];		
		
	}
	strHtml += arrMarker[i][13];

	//strHtml += google_marker_form_search_loc( i );	
	return strHtml;
}

function createInfoWindow( marker, i )
{	
	var strHtml = getInfoWindow( i );
	
	GEvent.addListener(marker, "click", function() { 				  				
		marker.openInfoWindowHtml( strHtml );
	});	
}

function setLocMarker( marker, i )
{
	GEvent.addListener(marker, "dragend", function(overlay, latlng){		
		var arrLoc = marker.getPoint().toUrlValue().split(',');		
		arrMarker[i][2] = arrLoc[0];
		arrMarker[i][3] = arrLoc[1];		
	});	
}



function google_maps_initialize( latitude, altitude, nameID ) 
{
	if ( google_maps_load == 0 )
	{	
    	google_maps_load = 1;
    	if (GBrowserIsCompatible()) 
    	{
    		google_map = new GMap2( document.getElementById(nameID) );        
        	if ( latitude == 0 && altitude == 0 )
        	{
        		google_map.setCenter(new GLatLng(google_maps_latitude_default,google_maps_altitude_default));
        	}	
        	else
        	{
        		google_map.setCenter(new GLatLng(latitude, altitude));
        	}        	        	        	  

			google_map.setZoom(6);
			google_map.addControl(new GSmallMapControl());
        	google_map.addControl(new GMapTypeControl());
        	google_map.addControl(new GScaleControl());		           
    	}
	}
}

function google_maps_create_marker( latitude, altitude, blnDraggable, gicon )
{    	
	if ( latitude == "" )
	{
		latitude = google_maps_latitude_default;
	}
	
	if ( altitude == "" )
	{
		altitude = google_maps_altitude_default;
	}
		
	var point  = new GLatLng(latitude,altitude);		
	var marker = new GMarker(point, { draggable: blnDraggable, icon: gicon } );
                 	        
    return marker;
}



/*
function google_marker_form_search_loc( marker_id )
{		
	var strHtml = '';		
	strHtml += '<input type="text" name="szukaj_w_poblizu" id="szukaj_w_poblizu"  onfocus="if( this.value == \'Szukaj w pobliżu...\' ) {this.value = \'\';}" onblur="if( this.value == \'\' ) {this.value = \'Szukaj w pobliżu...\';}" value="Szukaj w pobliżu..."><input type="button" name="szukaj" value="szukaj" onClick="google_maps_szukaj( '+marker_id+', document.getElementById(\'szukaj_w_poblizu\').value );"><br />';
	strHtml += '<select name="pt_google_type" id="pt_google_type"><option value="1">Z tego miejsca</option><option value="2">Do tego miejsca</option></select>';
	strHtml += '<input type="text" name="google_search_place" id="google_search_place" value="">';
	strHtml += '<input type="button" name="szukaj" value="szukaj" onClick="google_narysuj_droge( '+marker_id+', document.getElementById(\'pt_google_type\').value, document.getElementById(\'google_search_place\').value );">';		
	return strHtml;
}
*/


/*
function google_maps_szukaj( marker_id, str )
{
	var s = str.replace(/^\s+|\s+$/g, '');
	
	if ( s.length >= 3 )
	{	
		$.get("/?option=com_maps&view=wyszukiwarka&str="+s+"&id="+arrMarker[marker_id][0]+"&typ="+arrMarker[marker_id][9], function(data) { 		 						
			 						$("#list_search").html('');
			 						$("#content_search").html(data);				 								 								 								 												 						
			 					});	
	}	 					
	else
	{
		alert( 'Szukany ciąg powinien mieć więcej co najmniej 3 znaki' );
	}
}
*/

/*
function google_narysuj_droge( marker_id, typ, adres )
{
	var latitude = 0;
	var altitude = 0;
	
	if ( arrMarker[marker_id][2] != null && arrMarker[marker_id][3] != null )
	{
		latitude = arrMarker[marker_id][2]; 
		altitude = arrMarker[marker_id][3]; 		    
    }
    else if ( arrMarker[marker_id][8] != null )
    {    			
		var arrLoc = arrMarker[marker_id][8].split('|');    	
		for ( var j=0; j<1; j++ )
		{
			var arrLoc2 = arrLoc[j].split(';');			
			latitude = arrLoc2[0];
			altitude = arrLoc2[1];
		}	
	}
	
	
	
	
	
	if ( typ == 1 )
	{
		var arr = new Array( new GLatLng(latitude, altitude), adres );	
	}
	else
	{
		var arr = new Array( adres, new GLatLng(latitude, altitude) );	
	}
	
	if ( directions != null )
	{
		directions.clear();
	}	
	
	directionsPanel = document.getElementById("route");					
    directions = new GDirections(google_map, directionsPanel);        
  	directions.loadFromWaypoints(arr);     	
  	
}
*/


/*
function openInfoMarker( uniqueID, strTyp )
{
	for ( var i=0; i<arrMarker.length; i++ )
	{
		if ( arrMarker[i][0] == uniqueID && arrMarker[i][9] == strTyp )
		{
			if ( strTyp == 'nocleg' )
			{
				arrMarker[i][6].openInfoWindowHtml(getInfoWindow( i )); 
			}
			else
			{													  									 				
				google_map.openInfoWindow( arrMarker[i][6].getBounds().getCenter(), getInfoWindow( i ) );
			}	
		}
	}
}
*/


function google_icon( strUrl )
{
	var blueIcon = new GIcon(G_DEFAULT_ICON);
    if ( strUrl != null )
	{
		blueIcon.image = strUrl;		
	}
 	return blueIcon;
}


/*
function google_maps_geocoder( nameID )
{	
	google_maps_initialize( 0, 0, nameID );
	if (GBrowserIsCompatible()) {
		geocoder = new GClientGeocoder();
		GEvent.addListener(google_map, "click", function(overlay, latlng){
			if (latlng) {							
				clearMarker( 'search' );
			    addMarker( 'search', 'search', latlng.lat(), latlng.lng(), null, true, null );
			    createMarker( 'search' );																				
			}
		});
		
	}	 
}


function google_maps_add_address_to_map(response) 
{	  
	  if (!response || response.Status.code != 200) {
	    alert("Przepraszamy, nie możemy znaleźć Twojego adresu na mapie. Kliknij na mape i wskaż go sam.");
	  } else {	    
	    var place = response.Placemark[0];	    
	    var point = new GLatLng(place.Point.coordinates[1],
	                        place.Point.coordinates[0]);	    
	    
	    clearMarker( 'search' );
	    addMarker( 'search', 'search', place.Point.coordinates[1], place.Point.coordinates[0], null, true, null );
	    createMarker( 'search' );
	    google_map.setCenter(point);	    	    		
	  }
}

function google_maps_search_location( address ) 
{      
   geocoder.getLocations(address, google_maps_add_address_to_map);
}
*/

function google_clear_marker()
{
	google_map.clearOverlays();
}

var form_wojewodztwo = null;
var form_miasto      = null;
var arrFormId        = new Array();
var strGet = '';

function changePage(i)
{
	var nowa = (paginator == 1) ? i : 1;
	document.getElementById('page').value = nowa;
	form_set_marker(1);
}

function createPaginator(ile, page, res)
{
	if (!res)
	{
		var pag = "<ul class='pagination'><li><strong>Nie znaleziono wyników</strong></li></ul>";
		$("#paginator").html(pag);
		return;
	}
	
	var pag = "<br /><ul class='pagination'>";
	var i = 1;
	var poile = 15;
	var j = 15;
    if (page == 1){
        pag += "<li style='display: none;' class='prev'><a href='#'> < Poprzednia</a></li>";
    }else{
        pag += "<li class='prev'><a href='#' onClick=\"changePage(" + (page-1) + ");\"> < Poprzednia</a></li>";
    }
    
    var blnNext = false;
	while (j < ile)
	{
		if (i == page)
        {
			pag += "<li><strong>" + i + "</strong></li>";
            blnNext = false;
        }    
		else
        {
			pag += "<li><a href='#' onClick=\"changePage(" + i + ");\">" + i + "</a></li>";
            blnNext = true;
        }    
        
		j += poile;
		i++;
	}
	if (j > ile)
	{
		if (i == page)
        {
			pag += "<li><strong>" + i + "</strong></li>";
            blnNext = false;
        }    
		else
        {
			pag += "<li><a href='#' onClick=\"changePage(" + i + ");\">" + i + "</a></li>";
            blnNext = true;
        }    
	}
    
    if ( blnNext == true )
    {
        pag += "<li class='next'><a href='#' onClick=\"changePage(" + (page+1) + ");\">Następna > </a></li>";
    }
	pag += "</ul>";
	$("#paginator").html(pag);
}

function form_set_marker(ref_map)
{					
	if (ref_map == 1)
	{
		$("#map_load").css('display', ''); 
	}
	arrMarker = new Array();
	strGet = '';
	if ( $("#city").val() != 0 )
	{						
		
		var city = Base64.encode($("#city").val());
		strGet += 'arr[miasto]='+city+'&'; 
	}
	
	if ( $("#prov").val() != 0 )
	{
		strGet += 'arr[wojewodztwo_id]='+$("#prov").val()+'&'; 
	} 
	
	strGet += 'page='+$("#page").val()+'&'; 
	strGet += 'paginator='+paginator+'&'; 
	strGet += 'ref_map='+ref_map+'&'; 
	
	if ( $("#placowka_id").attr( 'value' ) != 0 )
	{
		strGet += 'arr[placowka_id]='+$("#placowka_id").attr( 'value' )+'&'; 
		$("#placowka_id").attr( 'value', 0 );
	}
	else
	{
		$("#show_amb").each( function(i) {
			if ( this.checked == true )
			{
				strGet += 'arr[show_amb]=1&'; 
			}
			else
			{
				strGet += 'arr[show_amb]=0&';
			}
		});
		
		$("#show_szp").each( function(i) {
			if ( this.checked == true )
			{
				strGet += 'arr[show_szp]=1&'; 
			}
			else
			{
				strGet += 'arr[show_szp]=0&';
			}
		});	
		
		strGet += 'arr[amb]='+$("#amb").val()+'&';
		strGet += 'arr[szp]='+$("#szp").val()+'&';
	}

	$.get("http://" + server_name + "/index.php?option=com_maps&view=ajax&"+strGet, function(data){
		paginator = 1;
		pageTracker._trackPageview("index.php?option=com_maps&view=ajax&"+strGet);  	
		
	  	arrMarker = new Array(); 
		marker_id = 0;		
		
		
	  	$("#placowka_js").html( data );
	  	if (ref_map == 1)
	  	{
			for ( var i=0; i<arrMarker.length; i++ )
			{
				var marker = google_maps_create_marker( arrMarker[i][2], arrMarker[i][3], arrMarker[i][5], google_icon( arrMarker[i][4] ) );			
				setLocMarker( marker, i );		
				createInfoWindow( marker, i );						    		    
			    google_map.addOverlay(marker);		    		    
			    arrMarker[i][6] = marker;
			    
			    if ( arrMarker.length == 1 )
			    {		    	
			 		//marker.openInfoWindowHtml( getInfoWindow( i ) );
			 		openMarkerWindow( i );
			    }		    
			}	
			
			$("#map_load").css('display', 'none');		  		
	  	}
														
	});			
}

function openMarkerWindow( i )
{
	var marker = arrMarker[i][6];
	marker.openInfoWindowHtml( getInfoWindow( i ) );
	scroll(0,0);
	setTimeout( "setAnchor()",50 );
}

function setAnchor()
{
//	window.location.href='#gmap';
	return false;	
}	

function setCitySelect(auto)
{					
	var s = '';
	if ( $("#prov").val() != 0 )
	{
		s = 'wojewodztwo_id='+$("#prov").val(); 
	} 
	$.get("index.php?option=com_maps&view=ajaxselect&"+s+"&auto="+auto, function(data){	  
		$("#select_city").html( data );
		updateAmbOptions();
	});				
}

function setLoaded()
{
	paginator = 0;
}
