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;
		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 propName=parent.document.getElementById("propName"+prop_cnt).value;
			var brandId=parent.document.getElementById("brandId"+prop_cnt).value;
			var phLink=parent.document.getElementById("photoLink"+prop_cnt).value;
			var photoLink=phLink.replace(/\s/g,"%20");
			var mnPhoto=parent.document.getElementById("mainPhoto"+(prop_cnt)).value;
			var mainPhoto=mnPhoto.replace(/\s/g,"%20");
			var address=parent.document.getElementById("Address"+(prop_cnt)).value;
			var address2=parent.document.getElementById("Address2"+(prop_cnt)).value;
			var city=parent.document.getElementById("city"+(prop_cnt)).value;
			var stateCode=parent.document.getElementById("stateCode"+(prop_cnt)).value;
			var zip=parent.document.getElementById("Zip"+(prop_cnt)).value;
			var country=parent.document.getElementById("Country"+(prop_cnt)).value;
			var phone=parent.document.getElementById("Phone"+(prop_cnt)).value;
			var btLink=parent.document.getElementById("buttonLink"+(i+1)).value;
			var buttonLink=btLink.replace(/\s/g,"%20");
			var availability=parent.document.getElementById("availability"+(prop_cnt)).value;
			var propNumber=parent.document.getElementById("propNumber"+(prop_cnt)).value;
			var photoTour=photoLink.replace(/tab1/,"tab3");
			var distance=parent.document.getElementById("distance"+(prop_cnt)).value;
			var altImage=null;
			var aImage=parent.document.getElementById("Altimage"+(prop_cnt)).value;
                       var customIcon ="<div class='pinStyle1'><div class='text'>"+propNumber+"</div></div>";
                       var amenitiesList =parent.document.getElementById("AmenitiesList"+(prop_cnt)).innerHTML;
 
			if(aImage==""){
				altImage= mnPhoto.replace(/[0-9][0-9].*/, 'SRBrandLogo.gif');
			}else{
				altImage= mnPhoto.replace(/[0-9][0-9].*/, aImage);
			}
			
			var text = "Reserve";
			if (brandId=="KG")
			{
				text = "Check Rates";
			}
			if (brandId=="TL")
			{
				text = "Show Rates & Rooms";
			}
			text = (availability!="")?text:"Check Alternative Dates";
			text = (brandId=="WY")? "Check Availability & Rates" : text;
			var customIcon ="<div class='pinStyle1'><div class='text1'>"+propNumber+"</div></div>";

			var pop= '';
			if (navigator.appName == "Microsoft Internet Explorer") {
			pop = '<div style="width:450px; margin-right: 0px; margin-left: 0px; margin-top: 10px; margin-bottom: -15px; z-index:90;"><table cellpadding="2" cellspacing="0" border="0" width="450"><tr valign="top">'
				+ '<td style="padding:0 0 10px 0;" align=center><a href="'+photoLink+'"><img src="'+mainPhoto+'" width="88" height="67" border="0" alt="Photo of Property"></a>';
			}else{
			pop = '<div style="width:450px; margin-right: 0px; margin-left: 0px; margin-top: 10px; margin-bottom: -50px; z-index:90;"><table cellpadding="2" cellspacing="0" border="0" width="450"><tr valign="top">'
				+ '<td style="padding:0 0 10px 0;" align=center><a href="'+photoLink+'"><img src="'+mainPhoto+'" width="88" height="67" border="0" alt="Photo of Property"></a>';
			}	
			if (brandId!='WY') {
				pop+= '<br><a href="'+photoTour+'" style="font-size:10px; color:black;">Photo Tour</a>';
			}
			pop+='<br><br><img src="'+altImage+'" border="0" alt="Tier"></td>'
				+ '<td width="20" style="font-size:95%;"><span class="boldRed searchResNCol" style="padding:2px; margin:0;">'+propNumber+'.</span></td>'
				+ '<td width="175" style="font-size:95%;"><span class="bigBold"><a style="text-decoration:none;" href="'+photoLink+'">'+propName+'</a></span>'
				+ '<table width="175"><tr><td><div class="checkmarkPad smallest" style="padding:0 10px 0 0;"><br>'+address+address2+city+stateCode+zip+country+'<br>'+phone+'<br>&nbsp;</div></td></tr>'
				+ '<tr><td><a href="'+buttonLink+'"class="buttontext"><div class="checkBtn" style="width:166px; margin:5px 0;">'+text+'</div></a></td></tr>'
				+ '</table></td>'
				+ '<td><div class="featureBorder" style="padding: 0pt 0pt 0pt 1px;">'+amenitiesList+'</div>'
				+ '</td></tr>'
				+ '<tr valign="top"><td colspan="4" align="right"; style="font-size:12px;">'+distance+'</td></tr>';
			if (!nodates && brandId!='WY') {
				var statusText=parent.document.getElementById("statusText"+(prop_cnt)).value;
				pop+= '<tr valign="top"><td colspan="4" align=right><div class="thinBorderHeader"><div class="thinBorderHeaderLink" style="font-size:95%;padding:3 5 3 0;">'+statusText+'</div></div></td></tr>';
			}
			pop+= '</table></div>';
			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;
}
