  $(document).ready(function(){
	$("#example").autocomplete("function/data.php", { minChars: 3, 
							   						  width : 300, 
													  delay : 600, 
													  max : 20,
													  cacheLength : 1,
													  extraParams : {mesto : function () { var mesto = $("#mesto").val(); return mesto; }},
													  formatItem : function(row, i, max) {
														  var data = eval('(' + row[0] + ')');
														  return data.ulica;
													  },
													  formatResult : function(row, i, max) {
														  var data = eval('(' + row[0] + ')');
														  return data.ulica;														  
													  }
													  });
  });
  
  var blueIcon;
  var terminalIcon;
  var prodajnaMesta = new Array();
  var qvoucherMarker;
  
  function getImages(posId) {
	  $.ajax({
			type: "POST",
			url: "function/pokazi-slike.php",
			data: "pos_id=" + posId,
			success: function(msg){
				$('#slike').html(msg);
			}
		});
  }
  
  function setUlicaBox() {
	  
	  var mesto = $("#mesto").val();
	  var servis = $("#servis").val();
	  
	  if (mesto != "-") {
		  $.ajax({
					type: "POST",
					url: "function/jq-ostala-mesta.php",
					data: "servis=" + servis + "&mesto=" + mesto,
					success: function(msg){
						$('#ostaliGradovi').html(msg);
					}
				}); 
		  $('#ostaliGradovi').show();
	  
	  }
	  
	  /**
	  
	  if (mesto == "Beograd") {
		  $('#example').removeAttr("disabled");
		  $('#button2').removeAttr("disabled");
		  $('#ostaliGradovi').hide();
		  $('#mapaDiv').show();
  	  }else {
  		  $('#example').attr("disabled", true);
  		  $('#button2').attr("disabled", true);
  		  
	  		$.ajax({
	  			type: "POST",
	  			url: "function/jq-ostala-mesta.php",
	  			data: "servis=" + servis + "&mesto=" + mesto,
	  			success: function(msg){
	  				$('#ostaliGradovi').html(msg);
	  			}
	  		}); 		    		  
  		  
  		  $('#ostaliGradovi').show();
  		  $('#mapaDiv').hide();
  	  }
	  */
  }
  
  
  function getResults() {
	var street = $("#example").val();
	var mesto = $("#mesto").val();
	var servis = $("#servis").val();
	
	if (street == "") {
		alert('Unesite naziuv ulice.');
		return false;
	}
	
	var regExPattern = /\(.*\)/;
	if (street.match(regExPattern) == null) {
		alert('Odaberite naziv ulice iz padajućeg menija\nkoji se pojavljuje dok kucate tekst.');
		return false;
	}
	
	
	$('#rez').html(loadingImage);
	
	$.ajax({
		type: "POST",
		url: "function/distance.php",
		data: "search=" + street + "&mesto=" + mesto + "&servis=" + servis,
		success: function(msg){
			var jSonData = eval("(" + msg + ")");
			//Ovo se koristi za google maps
			//map.clearOverlays();
			//eval (jSonData.gMapJS);
			$('#rez').html(jSonData.htmlList);
			top.frames['ppmapa'].location.href = 'loc.php?page=getloc.php&page2=recalc.php&page3=recalc2.php&xml=prepare_xml_pracenje_all_2.php!lat!44.788393*long!20.416169*search!' + street + '*mesto!' + mesto + '*servis!' + servis; 
		}
	});
  }
  
  
    
