var bIsMapSearch;var map;var strCountry;var strRegion;var strPlace;
function callGmapSearch(selectedCountry,selectedRegion,selectedPlace,languageCode)
{
	Dtf.WebSite.Default.DoGMapSearch(languageCode,searchCallBack);
	strCountry = selectedCountry;
	strRegion = selectedRegion;		
	strPlace = selectedPlace;	
}
function searchCallBack(arr)
{
	DisplayProgressBar(false);		
	getActiveMapType();
 	var baseIcon = new GIcon();var zoomLevel;var iconWidth;var iconHeight;	      
    baseIcon.infoWindowAnchor = new GPoint(10, 5);
    baseIcon.infoShadowAnchor = new GPoint(18, 25);
    var bounds = new GLatLngBounds(); 		
    map.setCenter(new GLatLng(0,0),0);    
    if(arr != null && arr.value != null && arr.value[0] != null && arr.value[1] != null)
    {
		var resultHotel = arr.value[0];
		var strLinktxt= arr.value[1];		
		if(resultHotel != null && resultHotel.Rows.length > 0)
		{		
			DisplayMapResult(resultHotel.Rows.length,true);		
			DisplayNoMapResult(false);
			var nPoint;
			for(var i=0;i<resultHotel.Rows.length;i++)
			{			
				var hotelId = resultHotel.Rows[i]["HotelId"].toString();
				var supplierId = resultHotel.Rows[i]["SupplierID"].toString();
				var hotelName = resultHotel.Rows[i]["HotelName"].toString();
				var latitude = resultHotel.Rows[i]["Latitude"].toString();
				var longitude = resultHotel.Rows[i]["Longitude"].toString();				
				var starimg = resultHotel.Rows[i]["Classification"].toString();
				var img1 = resultHotel.Rows[i]["img1"].toString();
				var img2 = resultHotel.Rows[i]["img2"].toString();
				var country = resultHotel.Rows[i]["Country"].toString();
				var city = resultHotel.Rows[i]["Region"].toString();
				if(latitude != "" && longitude != "")
					nPoint = new GLatLng(latitude , longitude);     
				else
					nPoint = new GLatLng(50 , 15);	
				var logoImage;
				if(supplierId == "1")
					logoImage = "Images/GoogleMap/Logo.gif";
				else if(supplierId == "2")
					logoImage = "Images/GoogleMap/BTLogo.gif";			
				
				if(strCountry != null)
				{
					iconWidth = 19;iconHeight = 25;
					baseIcon.iconAnchor = new GPoint(7, 22);
					if(supplierId == "1")
						baseIcon.image = "Images/GoogleMap/googlemaps_small.png";
					else if(supplierId == "2")
						baseIcon.image = "Images/GoogleMap/BT_small.png";
				}
				if(strCountry != null && strRegion != null)
				{
					iconWidth = 30;iconHeight = 40;
					baseIcon.iconAnchor = new GPoint(12, 35);
					if(supplierId == "1")
						baseIcon.image = "Images/GoogleMap/googlemaps_big.png";
					else if(supplierId == "2")
						baseIcon.image = "Images/GoogleMap/BT_big.png";
				}
				if(strCountry != null && strRegion != null && strPlace != null)			
				{
					iconWidth = 30;iconHeight = 40;
					baseIcon.iconAnchor = new GPoint(12, 35);
					if(supplierId == "1")
						baseIcon.image = "Images/GoogleMap/googlemaps_big.png";
					else if(supplierId == "2")
						baseIcon.image = "Images/GoogleMap/BT_big.png";
				}
				if(strCountry == null && strRegion == null && strPlace == null)			
				{
					iconWidth = 19;iconHeight = 25;
					baseIcon.iconAnchor = new GPoint(7, 22);
					if(supplierId == "1")
						baseIcon.image = "Images/GoogleMap/googlemaps_small.png";
					else if(supplierId == "2")
						baseIcon.image = "Images/GoogleMap/BT_small.png";
				}
				baseIcon.iconSize = new GSize(iconWidth, iconHeight);    
				map.addOverlay(CreateMarker(nPoint,baseIcon,hotelId,hotelName,starimg,img1,img2,country,city,strLinktxt,resultHotel.Rows[i]["qryString"].toString(),logoImage));
				bounds.extend(nPoint);			
			}
			map.setZoom(map.getBoundsZoomLevel(bounds));			
			map.setCenter(bounds.getCenter());
		}
		else
		{
			DisplayMapResult(resultHotel,false);
			DisplayNoMapResult(true);	
			nPoint = new GLatLng(50 , 15);
			map.setCenter(nPoint, 4);  
		}	
	}
	try{document.getElementById('gmapWait').style.display = 'none';}catch(e){};
}
function CreateMarker(point,baseIcon,hotelId,hotelName,starimg,img1,img2,country,city,linktxt,qryString,logoImage)
{
	var icon = new GIcon(baseIcon);			
    var marker = new GMarker(point, icon);       
    GEvent.addListener(marker, "click", function(){
    marker.openInfoWindowHtml("<div style='background-color:white;font-family:Verdana;font-size:11px;'><table cellSpacing=0 cellPadding=0 border=0><tr><td><img src="+logoImage+" width='55px'height='39px' border='0'><br><br></td></tr><tr><td style='font-family:Verdana;font-size:11px;font-weight:bold;'>"+starimg+"&nbsp;"+hotelName+" </td></tr><tr><td  style='font-family:Verdana;font-size:11px;font-weight:bold;'>"+country+", "+city+"<br><br></td></tr><tr><td style='font-family:Verdana;font-size:12px; text-decoration:underline;font-weight:bold;'><a style='color:#1066C5;' href=default.aspx?"+qryString+">"+linktxt+"</a><br><br><br></td></tr><tr><td><img src="+img1+" width='126px' height='126px' border=0>&nbsp;&nbsp;<img src="+img2+" width='126px' height='126px' border=0></td></tr></table></div>");});    
    return marker;    
}

function OnThemeChange(searchId,languageCode,dataList)
{
	DisplayMapResult(0,false);
	DisplayNoMapResult(false);
	DisplayProgressBar(true);
	var themeClientId = dataList + "__ctl0_" + "Type2_Theme";
	var selectedTheme = document.getElementById(themeClientId).value;	
	Dtf.WebSite.Default.SetThemeInSession(searchId,selectedTheme);
	if( bIsMapSearch == true ){	Dtf.WebSite.Default.DoGMapSearch(languageCode,searchCallBack); }
}
function OnFacilityChange(facilityId,facilityIndex,facilityItemId,languageCode,dataList)
{
	DisplayMapResult(0,false);
	DisplayNoMapResult(false);
	DisplayProgressBar(true);
	var facilityClientId = dataList + "__ctl" +facilityIndex+"_"+ facilityId;
	var facilityId = document.getElementById(facilityClientId);
	var facilityValue = facilityId.checked;
	Dtf.WebSite.Default.SetFacilityInSession(facilityItemId,facilityValue);
	if( bIsMapSearch == true ){ Dtf.WebSite.Default.DoGMapSearch(languageCode,searchCallBack); }
}
function OnDurationChange(durationClientId,languageCode)
{
	DisplayMapResult(0,false);
	DisplayNoMapResult(false);
	DisplayProgressBar(true);
	var durationValue = document.getElementById(durationClientId).value;	
	Dtf.WebSite.Default.SetDurationInSession(durationValue);
	if( bIsMapSearch == true ){ Dtf.WebSite.Default.DoGMapSearch(languageCode,searchCallBack); }
}
function OnAdultCountChange(adultCountClientId,languageCode)
{
	DisplayMapResult(0,false);
	DisplayNoMapResult(false);
	DisplayProgressBar(true);
	var adultCountValue = document.getElementById(adultCountClientId).value;	
	Dtf.WebSite.Default.SetAdultCountInSession(adultCountValue);
	if( bIsMapSearch == true ){ Dtf.WebSite.Default.DoGMapSearch(languageCode,searchCallBack); }
}
function OnChildCountChange(childCountClientId,languageCode)
{
	DisplayMapResult(0,false);
	DisplayNoMapResult(false);
	DisplayProgressBar(true);
	var childCountValue = document.getElementById(childCountClientId).value;	
	Dtf.WebSite.Default.SetChildCountInSession(childCountValue);	
	if( bIsMapSearch == true ){ Dtf.WebSite.Default.DoGMapSearch(languageCode,searchCallBack); }
}
function OnMaxMinPriceChange(maxPriceClientId,minPriceClientId,priceErrorRow,languageCode)
{
	DisplayMapResult(0,false);
	DisplayNoMapResult(false);
	DisplayProgressBar(true);
	var maxPriceValue = document.getElementById(maxPriceClientId).value;	
	var minPriceValue = document.getElementById(minPriceClientId).value;
	var maxPriceValueTemp = 0;
	var minPriceValueTemp = 0;
	if(maxPriceValue != "")
	{
		maxPriceValueTemp = parseInt(maxPriceValue);
	}	
	if(minPriceValue != "")
	{
		minPriceValueTemp = parseInt(minPriceValue);
	}
	
	if(minPriceValueTemp > maxPriceValueTemp && maxPriceValueTemp != 0)
	{
		document.getElementById(priceErrorRow).style.display='Block';
	}
	else
	{	
		document.getElementById(priceErrorRow).style.display='None';
		Dtf.WebSite.Default.SetMaxMinPriceInSession(maxPriceValue,minPriceValue);	
		if( bIsMapSearch == true ){ Dtf.WebSite.Default.DoGMapSearch(languageCode,searchCallBack); }
	}
}
function OnFromDateChange(fromDay,fromMonth,fromYear,languageCode,fromDateError)
{	
	DisplayMapResult(0,false);
	DisplayNoMapResult(false);	
	var fromDayValue = document.getElementById(fromDay).value;
	var fromMonthValue = document.getElementById(fromMonth).value;
	var fromYearValue = document.getElementById(fromYear).value;	
	DoFromDateSelectionSearch(true,fromDayValue,fromMonthValue,fromYearValue,languageCode,fromDateError);
}
function OnToDateChange(toDay,toMonth,toYear,languageCode,toDateError)
{	
	DisplayMapResult(0,false);
	DisplayNoMapResult(false);	
	var toDayValue = document.getElementById(toDay).value;
	var toMonthValue = document.getElementById(toMonth).value;
	var toYearValue = document.getElementById(toYear).value;		
	DoToDateSelectionSearch(true,toDayValue,toMonthValue,toYearValue,languageCode,toDateError);
}
function DoFromDateSelectionSearch(main,fromDayValue,fromMonthValue,fromYearValue,languageCode,fromDateError)
{	
	var bRet = Dtf.WebSite.Default.SetFromDateInSession(fromDayValue,fromMonthValue,fromYearValue);
	if(bRet.value == false)
	{
		if(main == true)
			document.getElementById(fromDateError).style.display = 'Block';
		else
			window.opener.document.getElementById(fromDateError).style.display = 'Block';
	}
	else if(bRet.value == true )
	{
		if( bIsMapSearch == true )
		{
			if(main == true)
			{
				DisplayProgressBar(true);
				document.getElementById(fromDateError).style.display='None';
				Dtf.WebSite.Default.DoGMapSearch(languageCode,searchCallBack);
			}
			else
			{
				DisplayProgressBar_Pop(true);
				window.opener.document.getElementById(fromDateError).style.display='None';
				Dtf.WebSite.Default.DoGMapSearch(languageCode,UpdateHotelCount_Pop);				
			}
		}
	}
}
function DoToDateSelectionSearch(main,toDayValue,toMonthValue,toYearValue,languageCode,toDateError)
{
	if( toDayValue == "" && toMonthValue == "" && toYearValue == "" )
	{
		toDayValue = "1"; toMonthValue = "1"; toYearValue = "1";
	}	
	var bRet = Dtf.WebSite.Default.SetToDateInSession(toDayValue,toMonthValue,toYearValue);
	if(bRet.value == false)
	{
		if(main == true)
			document.getElementById(toDateError).style.display='Block';			
		else
			window.opener.document.getElementById(toDateError).style.display='Block';			
	}
	else if(bRet.value == true)
	{
		if( bIsMapSearch == true )
		{
			if(main == true)
			{
				DisplayProgressBar(true);
				document.getElementById(toDateError).style.display='None';
				Dtf.WebSite.Default.DoGMapSearch(languageCode,searchCallBack);
			}
			else
			{
				DisplayProgressBar_Pop(true);
				window.opener.document.getElementById(toDateError).style.display='None';
				Dtf.WebSite.Default.DoGMapSearch(languageCode,UpdateHotelCount_Pop);				
			}
		}		
	}
}
function MakeMarkers(language)
{
	ShowGmapWait();
	InitiateGMap();
	AjaxPro.timeoutPeriod = 60*1000;
	Dtf.WebSite.Default.DoGMapSearch(language,searchCallBack);	
}    
function InitiateGMap()
{
	 if (GBrowserIsCompatible()) 
	 {		
		map = new GMap2(document.getElementById("map"),{mapTypes:[G_NORMAL_MAP,G_SATELLITE_MAP,G_HYBRID_MAP]}); 
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GScaleControl(100));
		map.enableScrollWheelZoom();
		new GKeyboardHandler(map);
		map.enableContinuousZoom();
		map.enableDoubleClickZoom();
		_mPreferMetric=true;
	 }
}
function UpdateHotelCount(HotelCountRes)
{
	DisplayProgressBar(false);
	if(HotelCountRes.value > 0)
	{
		DisplayMapResult(HotelCountRes.value,true);
		DisplayNoMapResult(false);		
	}
	else
	{
		DisplayMapResult(HotelCountRes.value,false);
		DisplayNoMapResult(true);	
	}
}
function UpdateHotelCount_Pop(HotelCountRes)
{
	DisplayProgressBar_Pop(false);
	if(HotelCountRes.value > 0)
	{
		DisplayMapResult_Pop(HotelCountRes.value,true);
		DisplayNoMapResult_Pop(false);		
	}
	else
	{
		DisplayMapResult_Pop(HotelCountRes.value,false);
		DisplayNoMapResult_Pop(true);	
	}
}
function DisplayProgressBar(bShow)
{
	var progressBarArray = getElementsByClassName(document, "div", "ProgressBar");	
	if(progressBarArray.length > 0)
	{		
		var progressBar = progressBarArray[0];
		progressBar.style.display = bShow ? "block" : "none";
	}
}
function DisplayProgressBar_Pop(bShow)
{
	var progressBarArray = getElementsByClassName(window.opener.document, "div", "ProgressBar");	
	if(progressBarArray.length > 0)
	{		
		var progressBar = progressBarArray[0];
		progressBar.style.display = bShow ? "block" : "none";
	}
}
function DisplayNoMapResult(bShow)
{
	var TableNoResultArray = getElementsByClassName(document, "table", "TableNoResult");
	if(TableNoResultArray.length > 0)
	{
		var TableNoResult = TableNoResultArray[0];
		TableNoResult.style.display = bShow ? "block" : "none";
	}
}
function DisplayNoMapResult_Pop(bShow)
{
	var TableNoResultArray = getElementsByClassName(window.opener.document, "table", "TableNoResult");
	if(TableNoResultArray.length > 0)
	{
		var TableNoResult = TableNoResultArray[0];
		TableNoResult.style.display = bShow ? "block" : "none";
	}
}
function DisplayMapResult(HotelCount,bShow)
{
	var TableResFoundArray = getElementsByClassName(document, "table", "TableResFound");
	if(TableResFoundArray.length > 0)
	{
		var TableResFound = TableResFoundArray[0];
		if(bShow)
		{
			TableResFound.style.display = "";			
			var HotelCountArray = getElementsByClassName(document, "span", "HotelCount");
			{
				var HotelCountSpan = HotelCountArray[0];				
				HotelCountSpan.innerHTML = HotelCount + " ";
			}
		}
		else
		{
			TableResFound.style.display = "none";		
		}
	}
}
function DisplayMapResult_Pop(HotelCount,bShow)
{
	var TableResFoundArray = getElementsByClassName(window.opener.document, "table", "TableResFound");
	if(TableResFoundArray.length > 0)
	{
		var TableResFound = TableResFoundArray[0];
		if(bShow)
		{
			TableResFound.style.display = "block";			
			var HotelCountArray = getElementsByClassName(window.opener.document, "span", "HotelCount");
			{
				var HotelCountSpan = HotelCountArray[0];				
				HotelCountSpan.innerText = HotelCount + " ";
			}
		}
		else
		{
			TableResFound.style.display = "none";		
		}
	}
}
function getActiveMapType()
{	
	map.clearOverlays();
	var mapTypes = map.getMapTypes();
	var actType = map.getCurrentMapType();
	var mapName = "unknown";
	if(actType == mapTypes[0])
	{
		map.setMapType(G_NORMAL_MAP);
	}
	else if(actType == mapTypes[1])
	{	
		map.setMapType(G_SATELLITE_MAP);
	}
	if(actType == mapTypes[2])
	{	
		map.setMapType(G_HYBRID_MAP);
	}	
}
function ShowGmapWait()
{
	var gW = document.getElementById('gmapWait');
	var m = document.getElementById('map');
	var cW = m.clientWidth;
	var cH = m.clientHeight;
	gW.style.width = cW;
	gW.style.height = cH;
	gW.style.display = '';
}
function starupSearch(languageCode)
{	
	ShowGmapWait();
	InitiateGMap();			
	getActiveMapType();
	Dtf.WebSite.Default.DoGMapSearch(languageCode,searchCallBack);
}
function changeIcon()
{alert("aa");}
function OnPopUpCalFromDateChange(fromDayValue,fromMonthValue,fromYearValue,languageCode,fromDateError)
{	
	DisplayMapResult_Pop(0,false);
	DisplayNoMapResult_Pop(false);
	DoFromDateSelectionSearch(false,fromDayValue,fromMonthValue,fromYearValue,languageCode,fromDateError );
}
function OnPopUpCalToDateChange(toDayValue,toMonthValue,toYearValue,languageCode,toDateError)
{	
	DisplayMapResult_Pop(0,false);
	DisplayNoMapResult_Pop(false);
	DoToDateSelectionSearch(false,toDayValue,toMonthValue,toYearValue,languageCode,toDateError);	
}
function setMapSearch(bValue)
{bIsMapSearch=bValue;}
function BuildSearchParamaters()
{
	AjaxPro.timeOutPeriod = 60*1000;
	var Ret = Dtf.WebSite.Default.BuildSearchQueryString();		
	if(Ret != null && Ret.value != null && Ret.value != "")
	{location.href = Ret.value;}
}
function CloseMap()
{
	showHideFormElements("visible");
	var mapTable = document.getElementById("MapTable");	
	mapTable.style.display = "none";
}
function GetGMapHotelLocationForDtf(mapLinkId,Latitude,Longitude)
{	
	MapLink = mapLinkId;
	if (GBrowserIsCompatible())
		{
			showHideFormElements("hidden");	
			var mapTable = document.getElementById("MapTable");var divGMap = document.getElementById("GMap");	
			divGMap.style.display = "block";mapTable.style.display = "block";
			mapTable.style.position = "absolute";mapTable.style.zIndex=10;var pos = getElementPos(MapLink);
			mapTable.style.left = pos.x;mapTable.style.top = pos.y-30;
			var map = new GMap2(divGMap);
			var pt = new GLatLng(Latitude,Longitude);		
			map.setCenter(pt, 9);var icon = new GIcon();
			icon.image = "Images/GoogleMap/googlemaps_big.png";icon.iconSize = new GSize(30,40);icon.iconAnchor = new GPoint(12, 35);
			icon.infoWindowAnchor = new GPoint(5, 1);var marker = new GMarker(map.getCenter(),icon);map.addOverlay(marker);
		}	
}
function ThemeChange(langid,themetype,Checkbox,searchId)
{
	var themeClientId = "_ctl2__ctl1_"+Checkbox ;
	var selectedTheme = document.getElementById(themeClientId).checked;	
	Dtf.WebSite.Default.SetFacilityInSession(themetype,selectedTheme);
}
function initMapDDSearch(languageCode,bSearch)
{
	InitiateGMap();			
	getActiveMapType();
	Dtf.WebSite.Default.DoMapDrilldown(languageCode,bSearch,ddCallBack);
}
function ddCallBack(arr)
{
	getActiveMapType();
 	var baseIcon = new GIcon();var zoomLevel;var iconWidth;var iconHeight;	      
    baseIcon.infoWindowAnchor = new GPoint(10, 5);
    baseIcon.infoShadowAnchor = new GPoint(18, 25);
    var bounds = new GLatLngBounds(); 		
    map.setCenter(new GLatLng(0,0),0);    
    if(arr != null && arr.value != null && arr.value[0] != null && arr.value[1] != null)
    {
		var resultHotel = arr.value[0];
		var strLinktxt= arr.value[1];		
		if(resultHotel != null && resultHotel.Rows.length > 0)
		{		
			var nPoint;
			for(var i=0;i<resultHotel.Rows.length;i++)
			{			
				var hotelId = resultHotel.Rows[i]["HotelId"].toString();
				var supplierId = resultHotel.Rows[i]["SupplierID"].toString();
				var hotelName = resultHotel.Rows[i]["HotelName"].toString();
				var latitude = resultHotel.Rows[i]["Latitude"].toString();
				var longitude = resultHotel.Rows[i]["Longitude"].toString();				
				var starimg = resultHotel.Rows[i]["Classification"].toString();
				var img1 = resultHotel.Rows[i]["img1"].toString();
				var img2 = resultHotel.Rows[i]["img2"].toString();
				var country = resultHotel.Rows[i]["Country"].toString();
				var city = resultHotel.Rows[i]["Region"].toString();
				if(latitude != "" && longitude != "")
					nPoint = new GLatLng(latitude , longitude);     
				else
					nPoint = new GLatLng(50 , 15);	
				var logoImage;
				if(supplierId == "1")
					logoImage = "Images/GoogleMap/Logo.gif";
				else if(supplierId == "2")
					logoImage = "Images/GoogleMap/BTLogo.gif";			
				
				iconWidth = 20;iconHeight = 34;
				baseIcon.iconAnchor = new GPoint(7, 22);
				baseIcon.image = "Images/GoogleMap/marker.png";
				baseIcon.iconSize = new GSize(iconWidth, iconHeight);    
				map.addOverlay(CreateMarker(nPoint,baseIcon,hotelId,hotelName,starimg,img1,img2,country,city,strLinktxt,resultHotel.Rows[i]["qryString"].toString(),logoImage));
				bounds.extend(nPoint);			
			}			
			map.setCenter(bounds.getCenter(),map.getBoundsZoomLevel(bounds)-1); 
		}
		else
		{
			nPoint = new GLatLng(50 , 15);
			map.setCenter(nPoint, 4);  
		}	
	}
	try{document.getElementById('gmapWait').style.display = 'none';}catch(e){};
}

function setCountry(country,languageCode)
{
	var checkElement = $('#'+country).next();
    if((checkElement.is('ul')) && (checkElement.is(':visible'))) {}
    if((checkElement.is('ul')) && (!checkElement.is(':visible'))) 
    {
    $('#menu ul:visible').slideUp('fast');
    checkElement.slideDown('fast');    
    }
	Dtf.WebSite.Default.SetCountry(country);
	Dtf.WebSite.Default.DoMapDrilldown(languageCode,true,ddCallBack);
	
	
}
function setRegion(region,languageCode)
{
	Dtf.WebSite.Default.SetRegion(region);
	Dtf.WebSite.Default.DoMapDrilldown(languageCode,true,ddCallBack);
}
function InitDrillDown(){$(function(){$('#menu ul').hide();});}
function BuildUrl()
{location.href = Dtf.WebSite.Default.BuildMapDDURL().value;}