function performSearch(intPage)
{
	$('#main_search_page_number').val(intPage);
	$('#main_search_frm').submit();
}

function lookup(inputString, strBackend, strIdSuffix) 
{
	if (strIdSuffix == null)
	{
		strIdSuffix = '';
	}
	
	if(inputString.length == 0) 
	{
		$('#suggestions' + strIdSuffix).hide();
	}
	else 
	{
		$.post(strBackend, {queryString: ""+inputString+""}, function(data){
			if(data.length >0) 
			{
				$('#suggestions' + strIdSuffix).show();
				$('#autoSuggestionsList' + strIdSuffix).html(data);
			}
		});
	}
}

function fill(thisValue, strIdSuffix) 
{
	if (strIdSuffix == null)
	{
		strIdSuffix = '';
	}
	
	$('#main_search_input' + strIdSuffix).val(thisValue);
	var action = "$('#suggestions" + strIdSuffix +"').hide();"
	setTimeout(action, 200);
}

var map = null;
var geocoder = null;
var lastmarker = null;
var first = false;

function mapinit_blank()
{
    if (GBrowserIsCompatible()) 
    {
    	 map = new GMap2(document.getElementById("map"));
         map.addControl(new GSmallMapControl());
         
         $(document).unload(function() { GUnload(); });
    }
    else
    {
        alert("Przeglądarka jest nieobsługiwana");
    }
}

function mapinit(lon, lat) 
{
	var zoom = 13;
	
	if (lon == null || lat == null)
	{
		lon = 19.5;
		lat = 52.2284048;
		
		zoom = 5;
	}
		
	if (GBrowserIsCompatible()) 
	{
		var point = new GLatLng(lat, lon);
		
		map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallMapControl());
		map.setCenter(point, zoom);
		
		map.addOverlay(new GMarker(point));
		
		$(document).unload(function() { GUnload(); });
    }
    else
    {
    	alert("Przeglądarka jest nieobsługiwana");
    }
}

function mapinit_addrfrm(form) 
{
	if (GBrowserIsCompatible()) 
	{
		var point = new GLatLng(form.floLat.value, form.floLon.value);
      
		map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallMapControl());
		map.setCenter(point, 13);
		geocoder = new GClientGeocoder();

		lastmarker = new GMarker(point);
		map.addOverlay(lastmarker);
		
		$(document).unload(function() { GUnload(); });
    }
    else
    {
    	alert("Przeglądarka jest nieobsługiwana");
    }
}

function SignupFillAndRefreshMap(thisValue)
{
	fill(thisValue, '_signup');
	SignupRefreshMap();
}

function SignupRefreshMap() 
{
	var form = document.addressfrm;
	address = form.strCountry.value 
			+ ' '
		    + form.strCity.value
		    + ' ' 
		    + form.strStreet.value
		    + ' ' 
		    + form.strHouseNo.value;
	
    if (geocoder) 
    {
      geocoder.getLatLng(
        address,
        function(point) 
        {
          if (!point) 
          {
        	  form.floLat.value = 'UNKNOWN';
              form.floLon.value = 'UNKNOWN';
          } 
          else 
          {
        	map.removeOverlay(lastmarker);
            map.setCenter(point, 13);
            
            var marker = new GMarker(point);
            map.addOverlay(marker);
            
            lastmarker = marker;
            
            form.floLat.value = point.lat();
            form.floLon.value = point.lng();
          }

          window.status = form.floLat.value + ' ' + form.floLon.value;
        }
      );
    }

    return true;
}

function addmarker(lon, lat, desc, icon)
{
	var ico = new GIcon();   

	ico.iconSize = new GSize(12, 20);   
	ico.infoWindowAnchor = new GPoint(16,16);   
	ico.iconAnchor = new GPoint(16,16);   
	ico.shadowSize = new GSize(22, 20);   
    
    if (icon == 1)
    {
    	ico.image = "http://labs.google.com/ridefinder/images/mm_20_green.png";   
    	ico.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
    }
    else
    {
    	ico.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";   
    	ico.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";   
    }
    
	var point = new GLatLng(lat, lon);
	var marker = new GMarker(point, {icon: ico});

	GEvent.addListener(marker, "click", function() {
        marker.openInfoWindowHtml(desc);
      });
	
	if (first == false)
	{
		map.setCenter(point, 12);
    	first = true;
	}
	
    map.addOverlay(marker);
}
