var GM=0;
var VE=1;

function ShowMap() {
	map = new VEMap('MTMap');
	map.LoadMap();
	map.AttachEvent("onchangeview", MapInfo);
	map.SetZoomLevel(initzoom);
	MapInfo();
	}

function MapInfo() {
	var html = "";
	if(selected>-1){html+="Geselecteerd object: nr. " + selected + ", ";}
	html += "Centrum: " + map.GetCenter();
	html += ", huidig zoomlevel: " + map.GetZoomLevel();
	document.getElementById("mapinfo").innerHTML = html;
	}

function ZoomMap(x) {
	map.SetZoomLevel(parseInt(x));
	}

function CenterMap(x,y) {
	map.SetCenter(new VELatLong(parseFloat(x), parseFloat(y)));
	}

function CalcMapPoint(x,y) {
	return new VELatLong(x,y);
	}

function DrawPolyline(points) {
    var poly = new VEShape(VEShapeType.Polyline, points);
    poly.HideIcon();
    map.AddShape(poly);
    map.SetMapView(points);
	}

function CenterObject(x, z) {
    var pts = myObjects[x].GetPoints();
    var LatLng = new VELatLong(pts[0].Latitude, pts[0].Longitude);
    map.PanToLatLong(LatLng);
    if(z>0){map.SetCenterAndZoom(LatLng, parseInt(z))}
    }

function ClearAllMarkers() {
	//map.DeleteAllPushpins();
	//map.DeleteAllPolylines();
	map.DeleteAllShapes();
    }
    		
function pushpin(x,id,name,lat,lng) {
    var marker =  map.AddPushpin(new VELatLong(lat, lng));
    marker.SetTitle(name);
    //if(id==-1){marker.SetCustomIcon(myIcon(id));
    if (id == -1) {
        if(hismarker==0)
            {
                marker.SetCustomIcon(myIcon(id));
            }else{
                marker.SetCustomIcon("<p class=history>" + name +"</p>");
            }
    }else{
        if(objecticons==0) { marker.SetCustomIcon(myIcon(x+1)) }
        if(objecticons==1) { marker.SetCustomIcon(myIcon(id.substr(id.length-4))) }
        }
	return marker;
    }

function pushpinmove(x,lat,lng) {
    var np = new VELatLong(lat, lng);
    myObjects[x].SetPoints(np);
    }
            
function AddHistoryMarker(x,y,header,info) {
    historymarker = map.AddPushpin(new VELatLong(x, y));
    historymarker.SetTitle(header);
    historymarker.SetDescription(info);
	}

function MoveHistoryMarker(x,y,info) {
	var point = new VELatLong(parseFloat(x),parseFloat(y));
	historymarker.SetPoints(point);
	historymarker.SetDescription(info);
	map.PanToLatLong(point);
	}

function myIcon(i) {
	if(i==-1){
	    var icon = "/images/icons/bzn.gif";
	}else{
	    var icon = "/images/icons/numbered/NI" + LZ(i) + ".png";
	    }
	return icon;
	}

