function goto_bulgaria() {
	map.SetCenterAndZoom(new VELatLong(42.10, 24.74), 6);
}

function goto_sofia() {
	map.SetCenterAndZoom(new VELatLong(42.65, 23.33), 9);
}

function goto_varna() {
	map.SetCenterAndZoom(new VELatLong(43.20, 27.91), 9);
}

function goto_plovdiv() {
	map.SetCenterAndZoom(new VELatLong(42.10, 24.74), 9);
}

function goto_object(zoom) {
	if(zoom == 0) zoom = map.GetZoomLevel();
	map.SetCenterAndZoom(LL, zoom);
}


function MouseHandler(e) {

	var setpos = document.getElementById('setpos_checkbox');
	if(setpos && setpos.checked == 1) {
		if (e.leftMouseButton) {
			LL = map.PixelToLatLong(new VEPixel(e.mapX, e.mapY));
			//alert('Lat:'+LL.Latitude+' Lon:'+LL.Longitude);
			if(lat_input) lat_input.value = LL.Latitude;
			if(lon_input) lon_input.value = LL.Longitude;

			var z = map.GetZoomLevel();
			if(mapzoom_input) mapzoom_input.value = z;

			map.DeleteAllShapes();
			var shape = new VEShape(VEShapeType.Pushpin, LL);
			shape.SetTitle('Property location');
			map.AddShape(shape);
			setpos.checked = 0;
			//alert(mapzoom_input.value);
		}else if(e.rightMouseButton) {
		}
	}
	return 1;

}

var LL = null;
var map = null;
var lat_input = document.getElementById('lat_input_id');
var lon_input = document.getElementById('lon_input_id');
var mapzoom_input = document.getElementById('mapzoom_input_id');
var title_input = document.getElementById('title_input_id');
var latlon = null;

function GetMap() {
	map = new VEMap('map');
	map.SetDashboardSize(VEDashboardSize.Small);
	map.LoadMap();
	map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);

	map.AttachEvent('onclick', MouseHandler);
}   

if(document.getElementById('map')) {
	GetMap();

	//alert(LL);
	//shape = new VEShape(VEShapeType.Pushpin, LL);
	if(lat_input && lon_input && mapzoom_input) {
		if(lat_input.value != 0 && lon_input.value != 0) {
	
			//LL = new VELatLong(lat_input.value, lon_input.value);
			//LL = new VELatLong(43.20, 27.91);
			//alert(lon_input.value);
			LL = new VELatLong(parseFloat(lat_input.value), parseFloat(lon_input.value));


			var shape = new VEShape(VEShapeType.Pushpin, LL);
			if(title_input && title_input.value.length>0) {
				shape.SetTitle(title_input.value);
			}else{
				shape.SetTitle('Property location');
			}
			goto_object(mapzoom_input.value);
			map.AddShape(shape);

		}else{
			goto_bulgaria();
		}
	}else{
		goto_bulgaria();
	}
}

