var map = null;
var locs = new Array;
var pinid=0;
var defaultView='r';
var dashboardSize='Small';  //Normal, Small or Tiny
var tileBuffer=0;
var center =null;
var zoom =null;
var layer=null;

/*
function GetMap(){
	 try{
		map = new VEMap('myMap');
	//	map.SetDashboardSize(getDashboardObj(dashboardSize));
		map.HideDashboard();
	//	map.onLoadMap = function(){ center=map.GetCenter(); zoom=map.GetZoomLevel();};
	//	defaultView=parent.document.getElementById("defaultView").value;
	//	map.LoadMap(null, null, defaultView, null, null, false);
	//	var options = new VEMapOptions();   
	//	options.EnableBirdseye = false;
	//	map.LoadMap(null, null, defaultView, null, null, false, 0, options);  
		map.LoadMap(null, null, defaultView);  
		map.ClearInfoBoxStyles();
		AddMyControl();
		AddPushpin();
		map.AttachEvent("onclick",ClickHandler);
	}catch(e){
//		alert(e.faultCode?e.faultCode:e.message?e.message:e);
	}
}
*/

function GetMap()
{
	try{
	map = new VEMap('myMap');
	map.HideDashboard();
	map.onLoadMap = function(){ center=map.GetCenter(); zoom=map.GetZoomLevel();};
	map.LoadMap(new VELatLong(0,0), 11 ,'r' ,false);
	AddMyControl();
	map.ClearInfoBoxStyles();
	AddPushpin();
	//map.AttachEvent("onclick",ClickHandler);
	
	//store the center and zoom for the resetMap function
	center=map.GetCenter();
	zoom=map.GetZoomLevel();	
	}catch(e){}

}


function ClickHandler(e) {
	if (e.rightMouseButton) {
		var latlng = map.PixelToLatLong(new VEPixel(e.mapX, e.mapY));
		//alert (latlng);
		GetLocationInfo(latlng);
	}
}

function GetLocationInfo(latlng) {

	var shape = new VEShape(VEShapeType.Pushpin, latlng);
	shape.SetCustomIcon("<div class='pinStyle1'><div class='text'>#</div></div>");
	shape.SetTitle("New Location");
	shape.SetDescription("Latitude: "+latlng.Latitude+"<br>Longitude: "+latlng.Longitude);
	map.AddShape(shape);

//	document.getElementById("lat").value = latlng.Latitude;
//	document.getElementById("long").value = latlng.Longitude;

}


function AddPushpin(){

	try{
		var propsSize =parent.document.getElementById('propsSize').value;
		var poilatlng =parent.document.getElementById('poilatlng').value;
		//alert(parent.document.getElementById("checkInDate").value);
		var nodates=(parent.document.getElementById("checkInDate").value =="mm/dd")? true : false;
		if (!nodates)
		{
			nodates=(parent.document.getElementById("checkInDate").value =="dd/mm")? true : false;
		}
		var points = new Array();
		var shapes = new Array();
		var myPropertyLatLng = poilatlng.split ( ';' );

		for(var i=myPropertyLatLng.length -2;i>=0;i--) {
		
			var latlng = myPropertyLatLng[i];
			var proplat = latlng.split ( ',' );
			var lat =null;
			var lng =null;
			var shape = null;
			for(j=0;j<proplat.length-1;j++){
				lat =proplat[j];
				lng =proplat[j+1];
				shape = new VEShape(VEShapeType.Pushpin,new VELatLong(lat,lng));
			}
			var prop_cnt=parent.document.getElementById("prop_cnt"+(i+1)).value;
			var propNumber=parent.document.getElementById("propNumber"+(prop_cnt)).value;
			var customIcon ="<div class='pinStyle1'><div class='text1'>"+propNumber+"</div></div>";
			var pop= '';			
			
			pop+=parent.document.getElementById("mapPopupHtml"+(prop_cnt)).innerHTML;
			
			shape.SetDescription(pop);
			shape.SetCustomIcon(customIcon);
			shape.SetZIndex(1010,1010);
			shapes.push(shape);

			var point =new VELatLong(lat,lng);
			points.push(point);
		}
		map.AddShape(shapes);
		map.SetMapView(points);
		
		if (propsSize < 2 && map.GetZoomLevel() > 12) { 
//		alert(map.GetZoomLevel());
		map.SetZoomLevel(12); 
		}

	}catch(e){
//		alert(e.faultCode?e.faultCode:e.message?e.message:e);
	}
}

function resetMap(){

	map.SetMapStyle(VEMapStyle.Road);
	map.SetCenterAndZoom(center, zoom);
}

function resetMap2(){
	map2.SetMapStyle(VEMapStyle.Road);
	map2.SetCenterAndZoom(center2, zoom2);
}
		 
function getDashboardObj(dashboardSize){
	if (dashboardSize == 'Normal'){
		dashboardObj = VEDashboardSize.Normal;
	}else if (dashboardSize == 'Small'){
		dashboardObj = VEDashboardSize.Small;
	}else if (dashboardSize == 'Tiny'){
		dashboardObj = VEDashboardSize.Tiny;
	}else{
		dashboardObj = VEDashboardSize.Normal;
	}
	return dashboardObj;
}
