var map = null;
var layer = null;
var noduri = [];

function viewStartLocation(Lat,Lon,Location) {
	var point = new VELatLong(Lat,Lon);
	var shape = new VEShape(VEShapeType.Pushpin,point);
	shape.SetTitle(Location);
	var icon = new VECustomIconSpecification();
	icon.Image = "/img/icons/flag_green2.png";
	icon.ImageOffset = new VEPixel(-2,-11);
	icon.TextContent = '  ';
	shape.SetCustomIcon(icon);
	addLayer();
	layer.AddShape(shape);
	noduri.push(point);
}

function viewEndLocation(Lat,Lon,Location) {
	var point = new VELatLong(Lat,Lon);
	var shape = new VEShape(VEShapeType.Pushpin,point);
	shape.SetTitle(Location);
	var icon = new VECustomIconSpecification();
	icon.Image = "/img/icons/flag_red2.png";
	icon.ImageOffset = new VEPixel(-2,-11);
	icon.TextContent = '  ';
	shape.SetCustomIcon(icon);
	addLayer();
	layer.AddShape(shape);
	noduri.push(point);
}

function viewLocation(Lat,Lon,Location) {
	var point = new VELatLong(Lat,Lon);
	var shape = new VEShape(VEShapeType.Pushpin,point);
	shape.SetTitle(Location);
	var icon = new VECustomIconSpecification();
	icon.Image = "/img/markerN.png";
	icon.ImageOffset = new VEPixel(8,8);
	icon.TextContent = '  ';
	shape.SetCustomIcon(icon);
	addLayer();
	layer.AddShape(shape);
	noduri.push(point);
}

function viewIntersection(Lat,Lon) {
	var point = new VELatLong(Lat,Lon);
	var shape = new VEShape(VEShapeType.Pushpin,point);
	var icon = new VECustomIconSpecification();
	icon.Image = "/img/markerX.png";
	icon.ImageOffset = new VEPixel(8,8);
	icon.TextContent = '  ';
	shape.SetCustomIcon(icon);
	addLayer();
	layer.AddShape(shape);
	noduri.push(point);
}

function drawRoute(r,g,b,a,Description) {
	var route = new VEShape(VEShapeType.Polyline, drum);
	route.SetLineWidth(3);
	var icon = new VECustomIconSpecification();
	icon.Image = "/img/marker0.png";
	route.SetCustomIcon(icon);
	route.SetLineColor(new VEColor(r,g,b,a));
	layer.AddShape(route);
	map.SetMapView(drum);
	//setTimeout("map.ZoomIn();",500);
	
}

function drawRestrictionRoute(source, destination, restriction, road, r,g,b,a) {
	var drum = [];
	drum.push(source);
	drum.push(destination);
	var route = new VEShape(VEShapeType.Polyline, drum);
	route.SetLineWidth(3);
	var icon = new VECustomIconSpecification();
	road='';
	if(road!='') {
		icon.CustomHTML = "<span style='font-size:8px; background: #FFFFCC; border: 1px solid #000000; color: #000000; filter:alpha(opacity=90); -moz-opacity: 0.9; opacity: 0.9;'>" + road + "</span>";
	} else {
		icon.Image = "/img/marker0.png";
		//icon.TextContent = road;
		//icon.ForeColor = new VEColor(0,0,0,a);
		//icon.TextSize = 8;
		//icon.BackColor = new VEColor(255,255,0,1);
	}
	route.SetCustomIcon(icon);
	route.SetLineColor(new VEColor(r,g,b,a));
	route.SetTitle(restriction);
	layer.AddShape(route);
}

function addLayer() {
	if(layer==null) {
		layer = new VEShapeLayer();
		map.AddShapeLayer(layer);
	}
}

function removeMarkers() {
	map.DeleteAllShapeLayers();
	layer = null;
	drum = [];
}

// Fix the SetCustomIcon() function to include pixel units for offset
  VEShape.prototype.SetCustomIcon = function(b) {
   if (typeof b == "undefined" || b == null) return null;
   if (typeof b == "object") {
    VEValidator.ValidateObject(b, "_content_", VECustomIconSpecification, "VECustomIconSpecification");
    if (typeof b.TextContent == "string" && b.TextContent != null) this.Primitives[0].name = b.TextContent;
    var a = this.Primitives[0].symbol;
    if (a.id == MC_PROPERTY_PARK || a.id == MC_PROPERTY_PUSHPIN) a = a.Clone();
    if (typeof b.Image == "string" && b.Image != null) a.imagedata_src = GetImageFullUrl(b.Image);
    else a.imagedata_src = Msn.VE.API.Constants.iconurl;
    var e = b.ForeColor;
    if (typeof e == "object" && e != null) {
     VEValidator.ValidateObject(e, "fC", VEColor, "VEColor");
     a.textbox_color = e.ToHexString();
     a.textbox_color_opacity = e.A
    } var d = b.BackColor;
    if (typeof d == "object" && d != null) {
     VEValidator.ValidateObject(d, "bC", VEColor, "VEColor");
     a.textbox_backcolor = d.ToHexString();
     a.textbox_backcolor_opacity = d.A
    } var g = b.TextOffset;
    if (typeof g == "object" && g != null) {
     VEValidator.ValidateObject(g, "tO", VEPixel, "VEPixel");
     a.textbox_OffsetX = b.TextOffset.x;
     a.textbox_OffsetY = b.TextOffset.y
    } var f = b.ImageOffset;
    if (typeof f == "object" && f != null) {
     VEValidator.ValidateObject(f, "iO", VEPixel, "VEPixel");
     a.img_offsetX = f.x;
     a.img_offsetY = f.y
    } if (b.TextBold) a.textbox_bold = true;
    if (b.TextItalics) a.textbox_italic = true;
    if (b.TextUnderline) a.textbox_underscore = true;
    var l = parseInt(b.ImageWidth);
    if (!isNaN(l)) a.img_width = l;
    var k = parseInt(b.ImageHeight);
    if (!isNaN(k)) a.img_height = k;
    a.textbox_font = b.TextFont;
    a.imagedata_on = true;
    var i = parseInt(b.TextSize);
    if (!isNaN(i)) a.textbox_size = i;
    a.isOn = true;
    this.Primitives[0].symbol = a;
    if (b.CustomHTML != null) this._customIcon = b.CustomHTML;
    else if (this.Primitives[0].name) {
     var c = [];
     c.push("<div style='position:relative'>");
     c.push(" <div style='position:absolute;left:" + a.textbox_OffsetX + "px;top:" + a.textbox_OffsetY + "px;");
     c.push("font-size:" + a.textbox_size + "pt;font-family:" + a.textbox_font + ";");
     c.push("color:" + a.textbox_color + ";");
     var h = this.GetZIndex();
     if (a.textbox_italic) c.push("font-style:italic;");
     if (a.textbox_bold) c.push("font-weight:bold;");
     if (a.textbox_underscore) c.push("text-decoration:underline;");
     c.push("z-index:" + (h + 1) + ";");
     c.push("'>");
     c.push(this.Primitives[0].name);
     c.push("</div>");
     c.push(" <img style='position:relative;top:" + a.img_offsetY + "px;left:" + a.img_offsetX + "px;z-index:" + h + "' src='" + a.imagedata_src + "'' ");
     var j = Msn.VE.Environment.BrowserInfo;
     if (j.Type == Msn.VE.BrowserType.MSIE && parseFloat(j.MajorVersion) < 7 && a.imagedata_src != null && a.imagedata_src.search(/.gif$/) < 0) c.push(' onload=\'this.onload="";if(this.fileSize!=-1){this.style.width=this.width;this.style.height=this.height;this.src="' + Msn.VE.API.Constants.spacerurl + '";this.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\\"' + a.imagedata_src + '\\", sizingMethod=\\"scale\\")";}\' />');
     else c.push("/>");
     c.push("</div>");
     this._customIcon = c.join("")
    } else this._customIcon = a.imagedata_src
   } else if (typeof b == "string") {
    this._customIcon = b;
    if (b.indexOf("<") < 0) {
     var a = this.Primitives[0].symbol;
     if (a.id == MC_PROPERTY_PARK || a.id == MC_PROPERTY_PUSHPIN) a = a.Clone();
     a.imagedata_src = GetImageFullUrl(b);
     a.isOn = true;
     this.Primitives[0].symbol = a
    }
   } this._IconContent = null;
   this.Redraw(false, false, false, true)
  };

