
  function updateLatLang(latitude, longitude) {
								//console.debug('updateLatLang.latitude '+latitude);
							  	//console.debug('updateLatLang.longitude '+longitude);
							  	jQuery('#search-latitude-input').val(latitude);
							  	jQuery('#search-longitude-input').val(longitude);
  }
  	
						
  var geocoder;
  function initGoogleMap() {
   	if(GBrowserIsCompatible()) {  
   		
   		geocoder = new GClientGeocoder();
   		geocoder.setBaseCountryCode('pl')
   	}
  }
  
   jQuery().ready(function() {
   		
 	 	google.load("maps", "2", {"callback" : initGoogleMap});
			 jQuery("#main-search-form").submit(function() {
			 	//console.debug('search with address');

				var form = jQuery(this);
				form.unbind("submit");
				//console.debug( jQuery('#search-box-input').val());
				//console.debug( jQuery('#search-box-input').attr('title'));
				if( jQuery('#search-box-input').val() == jQuery('#search-box-input').attr('title') ) {
					//console.debug("same");
					jQuery('#search-box-input').val('');
				}
				if( jQuery('#search-box-address-input').val() == jQuery('#search-box-address-input').attr('title') ) {
					jQuery('#search-box-address-input').val('');
					
				}
  						if(jQuery('#search-box-address-input').val().indexOf(',') == -1) {
  							// only city so don't set lat lng
  							updateLatLang('','');
  							
  							
  							form.submit();
  							return true;
  						}
  						
							 if(geocoder) {
								 /*geocoder.getLocations('Polska, '+jQuery('#search-box-address-input').val(),function(point) {
									 if (!point.Placemark) {
										 alert(jQuery('#address-input').val() + " nie został znaleziony!");
									 }  else {
										 console.dir(point.Placemark);
										 alert(point.Placemark);
								     } 
								 });*/
								 
							 	geocoder.getLatLng(
							 		'Polska, '+jQuery('#search-box-address-input').val(),
							 			function(point) {
								 			if (!point) {
									 			jQuery('#simple-address-input-errors').html(jQuery('#search-box-address-input').val() + " nie został znaleziony");
								 				
								 			} else {
								 				// first update lat lang
								 				updateLatLang(point.y, point.x);
								 				//console.debug('finish getLatLng');
								 				// save address
								 				//sendSaveSimpleAddress()
								 				
								 				form.submit();
								 				return true;
								 			}
							 			}
								 );
								 
							 } 

				return false;
			});
		
   });
