function setMapCentre() {
    map_center = getMapCenter();
    $('lat').value = map_center.lat;
    $('lon').value = map_center.lon;
}

function closeInfo() {
    clearLayers(['markers']);
    Element.hide('popup');
}

function markMapID(e) {
    var loc = map.getLonLatFromViewPortPx(e.xy);
    var cur_layer = map.getLayersByName('markers').first();
    cur_layer.destroyFeatures();    
    var pgeom = new OpenLayers.Geometry.Point(loc.lon,loc.lat)
    var point = new OpenLayers.Feature.Vector(pgeom,{'icon' : 'marker.png'}, null);
    cur_layer.addFeatures(point);
    atoken = $('auth_token').value;
    if (popup != null) { map.removePopup(popup); popup = null; }    
    var content = "<span style='position:absolute;top:0px;right:0px;'><img src='/images/close.gif' onClick='closeInfo();' /></span><div id='response' style='padding:7px;border:5px solid #fbef65;height:150px;font-size:12px;background:#fff'><form action='/custom_map/create' onsubmit=\"new Ajax.Request('/custom_map/create', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\"><input type='hidden' name='authenticity_token' value=" + atoken + "><input type='hidden' name=custom_map[lat] value=" + loc.lat + "><input type='hidden' name=custom_map[lon] value=" + loc.lon + "><input type=hidden name=custom_map[zoom] value=" + map.getZoom() + "><span style='color:#000'>Enter a label</span><br/><input type='text' name='custom_map[label]' size='17'/><br/><span style='color:#000'>Notes/Details (optional)</span><br/><textarea name='custom_map[address]' rows=3 cols=20></textarea><br/><input type='submit' value='save' /><input type='button' value='cancel' onClick=\"Element.hide('popup');\" /></form></div>";
    popup = new OpenLayers.Popup("popup",
        new OpenLayers.LonLat(loc.lon,loc.lat),
        new OpenLayers.Size(570,510),
        content,
        false);
    popup.setSize(new OpenLayers.Size(210,160));
    popup.setOpacity(5.5);
    popup.setBackgroundColor('transparent');
    popup.setBorder('5px solid #4c4c4c');
    map.addPopup(popup);
}

function showCustomMap(result) {
    res = result.custom_map;
    render([{'icon' : 'move.gif', 'lon' : res.lon, 'lat' : res.lat}], {'centerMap' : true, 'layer' : 'mapid', 'zoom' : res.zoom});
    render([{'icon' : 'highlight.gif', 'lon' : res.lon, 'lat' : res.lat}], {'centerMap' : true, 'layer' : 'highlight', 'zoom' : res.zoom});
    map.raiseLayer(map.getLayersByName('mapid').first(),1);
    
    _text = "<DIV><IMG style='display:block;' src='/images/call_out.png'/></DIV><div style='padding:3px;font-family:Arial;font-weight:bold;background-color:#000;color:#FFF;font-size:10.5px;width:110px;'>";
    _text += "<div style='text-align:center;'>" + res.label + "</div>";
    if(res.address != null) {
        _text += "<hr/><div style='text-align:left;'>" + res.address + "</div>";
    }
    _text += "</div>";
    /*marker=new OpenLayers.Marker.Label(loc,icon,_text,options);
    custommaps.addMarker(marker);
    yellow_marker=new OpenLayers.Marker.Label(loc,flashing_yellow_icon,"", options);
    custommap_highlights.addMarker(yellow_marker);*/
}