/**
 * Detailed Bing Map Implementation JavaScript.
 * @author Cognizant Technology Solutions
 * @version 1.0
 * @project Wyndham Hotels- WBER
 * 
 */

var map = null;
var pinPoint = null;
var pinPixel = null;

function GetMap() {
	map = new VEMap('myMap');
	map.LoadMap(new VELatLong(0, 0), 12, VEMapStyle.Road, false,
			VEMapMode.Mode2D, true, 1);
	map.ClearInfoBoxStyles();
	AddPin();
}
//EAS - BEGIN -- ADDED
function GetMapAltSell() {
	map = new VEMap('myMap');
	map.LoadMap(new VELatLong(0, 0), 12, VEMapStyle.Road, false,
			VEMapMode.Mode2D, true, 1);
	map.ClearInfoBoxStyles();
	AddPin();
}
//EAS - END 
function AddPin() {
	var poilatlng = parent.document.getElementById('poilatlng').value;
	var myPropertyLatLng = poilatlng.split(';');
	var points = new Array();
	var shapes = new Array();
	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));
		}
		/*property details as hidden param from doc */
		var prop_cnt=parent.document.getElementById("prop_cnt"+(i+1)).value;
		var propName=parent.document.getElementById("propName"+prop_cnt).value;
		var propPhotoLink=parent.document.getElementById("propPhotoLink"+prop_cnt).value;
		var mainPhoto=propPhotoLink.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;
		
		if(parent.document.getElementById("stateCode"+(prop_cnt)).value== "**")
		{
		var stateCode="";
		}
		else
		{
		var stateCode=parent.document.getElementById("stateCode"+(prop_cnt)).value;
		stateCode=stateCode+", ";
		}	
		
		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 propNumber=parent.document.getElementById("propNumber"+(prop_cnt)).value;
		var propertyMinRate=parent.document.getElementById("propertyMinRate"+(prop_cnt)).value;
		var propertyCurrencyCode=parent.document.getElementById("propertyCurrencyCode"+(prop_cnt)).value;
		var propertyRateHead=parent.document.getElementById("propertyRateHead"+(prop_cnt)).value;
		var propertyImageUrl=parent.document.getElementById("propertyImageUrl"+(prop_cnt)).value;
		var tierImageUrl=parent.document.getElementById("tierImageUrl"+(prop_cnt)).value;
		var propLinkRedirection= null;
		var propLinkRedirectionText=parent.document.getElementById("propLinkRedirectionText"+(prop_cnt)).value;
		var viewRoomRateBtnLinkEvent = '';
		var brand = parent.document.getElementById("brand"+(prop_cnt)).value;
		if(parent.document.getElementById("viewRoomLink_ThickBox_"+(prop_cnt)) != null) {
			var propViewRoomLink="viewRoomLink_ThickBox_"+(prop_cnt);
			if (brand == 'WP' || brand == 'WT'){
				viewRoomRateBtnLinkEvent=' '+'onclick="clickLinkWp(\''+propViewRoomLink+'\')"'+' ';			
				}
				else
				{
				viewRoomRateBtnLinkEvent = ' '+'onclick="clickLink(\''+propViewRoomLink+'\')"'+' ';
				}

		} else if(parent.document.getElementById("propLinkRedirection"+(prop_cnt)) != null) {
			propLinkRedirection = parent.document.getElementById("propLinkRedirection"+(prop_cnt)).value;
			viewRoomRateBtnLinkEvent = ' '+'href=\"'+propLinkRedirection+'\"'+' ';
		}
		
		if(propertyMinRate == 0.0 && (brand != 'WP' && brand != 'WT'))
		{
			propAvailText = "This Hotel does not have rooms available that match your criteria.";
			viewRoomRateBtn = '';
		} else if (brand != 'WP' && brand != 'WT'){
			propAvailText = '<table width="100%">'+
							'<tr><td align="center" class="amt_desc_map">'+propertyRateHead+'</td></tr>'+
							'<tr><td class="amt_map" align="center">'+propertyMinRate+'&nbsp;<span style="font-size:8px;"><b>'+propertyCurrencyCode+'</b></span></td></tr>'+
							'<tr><td align="center" class="amt_desc_map">nightly rate per room</td></tr>'+
							'</table>';
			viewRoomRateBtn = '<tr><td class="viewRoom_btn_map" align="center">'+
							'<a'+viewRoomRateBtnLinkEvent+' id="propBtn" style="cursor:pointer;">'+propLinkRedirectionText+'</a>'+
							'</td></tr>'; 
		} else if (brand == 'WP'){
			viewRoomRateBtn = '<tr><td class="viewRoom_btn_map" align="center">'+
			'<a'+viewRoomRateBtnLinkEvent+' id="propBtn" style="cursor:pointer;">'+propLinkRedirectionText+'</a>'+
			'</td></tr>'; 
		} else if (brand == 'WT'){
		viewRoomRateBtn = '<tr><td class="viewRoom_btn_map" align="center">'+
		'<a'+viewRoomRateBtnLinkEvent+' id="propBtn" style="cursor:pointer;">'+propLinkRedirectionText+'</a>'+
		'</td></tr>'; 
		}
		if(address2 == null || address2 == "") {
			var address2text = "";
		} else {
			var address2text = '<br>'+address2+'<br>';
		}
		/*Pushpin style*/
		var customIcon ='<div class="pushPinIcon"><div class="pushPinText" align="center">'+propNumber+'</div></div>';
		/*popup contents start*/
		
		popDesc = '';
		popDesc = 	'<div  style="width:450px">'+
					'<table width="100%">'+
						'<tr>'+
							'<td align="center">'+
							'<table><tr><td align="center">'+
								'<div><img src="'+propertyImageUrl+'" width="90" height="90"></div>'+
							'</td></tr><tr><td align="center">'+
								'<div><img src="'+tierImageUrl+'"></div>'+
							'</td></tr></table>'+
							'</td>'+
							'<td class="prop_details_map">'+
								'<div class="prop_name_map">'+propName+'</div>'+
									'<div style="width:200px" class="prop_address_map float-left">'+ address + address2text +'<br>' +
									city+", "+stateCode+country+"-"+zip+
								'</div>'+
							'</td>'+
							'<td align="center" valign="top">';
								
		
		if (propAvailText == ""){
			popDesc = popDesc + '<table><tr><td align="center">'+		 
								'<div class="priceDetail_map">'+ propAvailText +'</div>'+
								'</td></tr>'+
								viewRoomRateBtn +
								'</table>'+
							'</td>'+
						'</tr>'+
					'</table>'+
					'</div>';
		}else{
			popDesc = popDesc + '<table>' +
								viewRoomRateBtn +
								'</table>'+
							'</td>'+
						'</tr>'+
					'</table>'+
					'</div>';
		}
		
		/*popup contents end*/
		shape.SetDescription(popDesc);
		shape.SetCustomIcon(customIcon);
		shape.SetZIndex(1010,1010);
		shapes.push(shape);
		var point = new VELatLong(lat, lng);
		points.push(point);
	}
	
	var altsellpoilatlngobj =parent.document.getElementById('altSellLatLng');
	if(altsellpoilatlngobj != undefined && altsellpoilatlngobj != '')
	var altsellpoilatlng =altsellpoilatlngobj.value;
	
	if(altsellpoilatlng != undefined && altsellpoilatlng != ''){
		var proplat = altsellpoilatlng.split ( ',' );
		var lat = proplat[j-1];
		var	lng = proplat[j];
		
		shape = new VEShape(VEShapeType.Pushpin,new VELatLong(lat,lng));
		var customIcon ="<div class='pinStyleAltSell'></div>";
		shape.SetCustomIcon(customIcon);
		shape.SetZIndex(1020,1020);
		
		var point =new VELatLong(lat,lng);
		
		shapes.push(shape);
		points.push(point);
	}
		
	map.AddShape(shapes);
	map.SetMapView(points);
}
function clickLinkWp(propViewRoomLink)
{
obj = parent.document.getElementById(propViewRoomLink);
window.open(obj);
}

function clickLink(propViewRoomLink) {			
			obj = parent.document.getElementById(propViewRoomLink);
				fireEvent(obj,'click');
}
/*Function to handle ThickBox Implementation*/	
function fireEvent(element,event) {
	 if (document.createEvent) {
		 // dispatch for firefox + others
		 var evt = document.createEvent("HTMLEvents");
		 evt.initEvent(event, true, true ); // event type,bubbling,cancelable
		 return !element.dispatchEvent(evt);
	 } else {
		 // dispatch for IE
		 var evt = document.createEventObject();
		 return element.fireEvent('on'+event,evt)
	 }
}
