function createMarker(latlng, html, iconImage) {
  if(iconImage!='') {
    var icon = new GIcon();
    icon.image = iconImage;
    icon.iconSize = new GSize(25, 25);
    icon.iconAnchor = new GPoint(14, 25);
    icon.infoWindowAnchor = new GPoint(14, 14);
    var marker = new GMarker(latlng,icon);
  } else {
    var marker = new GMarker(latlng,{draggable: true});
  }
}

function overlayAdded(overlay){
if((overlay instanceof GMarker) && overlay.draggingEnabled()) {
GEvent.addListener(overlay,"dragend", movePoint);
}
}
function movePoint() {
thePoint = this.getPoint();
infoWindow = map.closeInfoWindow();
new Ajax.Request('/podjetje/move_point?pointy=' + thePoint.y + '&pointx=' +thePoint.x, {asynchronous:true, evalScripts:true});
}
function mapMoved(){
theBounds = map.getBounds();
new Ajax.Request('../store_bounds?swpointy=' + theBounds.getSouthWest().y + '&swpointx=' +theBounds.getSouthWest().x + '&nepointy=' + theBounds.getNorthEast().y + '&nepointx=' + theBounds.getNorthEast().x, {asynchronous:true, evalScripts:true});
}
function mapMoved2(){
theBounds = map.getBounds();
new Ajax.Request('/podjetje/store_bounds?swpointy=' + theBounds.getSouthWest().y + '&swpointx=' +theBounds.getSouthWest().x + '&nepointy=' + theBounds.getNorthEast().y + '&nepointx=' + theBounds.getNorthEast().x, {asynchronous:true, evalScripts:true});
}

function auto_complete_on_select(element, selectedElement)
{
  var entityParts = selectedElement.id.split('::');
  var entityType = entityParts[0];
  var entityId   = entityParts[1];
  document.getElementById(entityType).value = entityId;
}

function unencodeHtml(str) 
{ 
  str = str.replace(/"/g,"\""); 
  str = str.replace(/'/g,"\'");
  str = str.replace(/</g,"<"); 
  str = str.replace(/>/g,">"); 
  str = str.replace(/&/g,"&"); 
  return str; 
} 

function unencodeJson(str) 
{ 
  str = unencodeHtml(str); 
  return "("+str+")"; 
}