﻿var misAutoLookup = false; // scrolling to avail

//Mapping
function loadSmallMap() {
	try {
		smmp = document.getElementById("smallmap");
		if ((smmp != undefined) && GBrowserIsCompatible()) {
			if (map != undefined) map.clearOverlays();
			map = new GMap2(smmp);
			if (loadExpMap) GEvent.addListener(map, 'load', function(){magnify();});
			if (expSpecHotel) {
				map.setCenter(new GLatLng(lat, lon), 13);
			}
			else {
				loadMap(map,swLat,swLon,neLat,neLon);
			}
			map.disableDragging();
			map.disableInfoWindow();
			map.disableDoubleClickZoom();
			map.disableContinuousZoom();
			window.setTimeout('expProps();', 1000);
		}
  }
  catch(e){
		if(attno==0){
			attno=1;
			window.setTimeout('load();', 6000);
		}
	}
}

function expProps() {
	var icon = new GIcon();
	icon.image = "/images/mm_20_red.png";
	icon.shadow = "/images/mm_20_shadow.png";
	icon.iconSize = new GSize(12, 20);
	icon.shadowSize = new GSize(22, 20);
	icon.iconAnchor = new GPoint(6, 20);
	icon.infoWindowAnchor = new GPoint(5, 1);
	if (expSpecHotel) {
		var point = new GLatLng(map.getCenter().lat(),map.getCenter().lng());
		map.addOverlay(new GMarker(point, icon));
	}
	GEvent.addListener(map, 'click', function() {
		magnify();
		var avS = document.getElementById('divAvSearch');
		if (avS != undefined) avS.scrollIntoView();
	});
}

function gmapMapMode() {
	try { if (mapexp != undefined) {mapexp.setMapType(G_NORMAL_MAP);} }
	catch(e){}
}

function gmapHybMode() {
	try { if (mapexp != undefined) { mapexp.setMapType(G_HYBRID_MAP); } }
	catch(e){}
}

function gmapSatMode() {
	try { if (mapexp != undefined) { mapexp.setMapType(G_SATELLITE_MAP); } }
	catch(e){}
}

function magnify(sync) {
	try {
		if (GBrowserIsCompatible()) {
			var centrmap = document.getElementById("centrmap");
			if (centrmap != undefined) {
				centrmap.style.display = "block";
				if (sync!=undefined && sync==true) {contMagn(false)}
				else {window.setTimeout('contMagn(false);', 100);};
			}
			document.cookie = 'expandMap=1';
		}
  }
  catch(e){}
}

function contMagn(refresh) {
	try {
		if (mapexp == undefined || refresh) {
			mapexp = new GMap2(document.getElementById("map"));
			mapexp.doubleClickZoomEnabled();
			mapexp.enableContinuousZoom();
			mapexp.addControl(new GLargeMapControl());
			mapexp.addControl(new GScaleControl());
			GEvent.addListener(mapexp, "moveend", function() {
				if(mapexp.getZoom() < 9) {
					dispMapMsg('<p>Please zoom in to your point of interest to find hotels, using the zoom control at the left</p>');
				}
				else fetchHotels();
			});
			if (expSpecHotel) {
				var point = new GLatLng(lat,lon);
				mapexp.setCenter(point, 13);
				var optM = new Object();
				optM.title = 'current hotel';
				optM.clickable = false;
				mapexp.addOverlay(new GMarker(point, optM));
			}
			else {
				if ( isNaN(swLat) ) {
					Ws.General.getMapAreaFromIP(gotMapAreaFromIP);
				}
				else {
					loadMap(mapexp,swLat,swLon,neLat,neLon);
				}
			}
		}
		else {
			fetchHotels();
		}
	}
	catch(e){}
}

function closeMap() {
	try {
		var centrmap = document.getElementById("centrmap");
		if (centrmap != undefined) {
			centrmap.style.display = "none";
			document.cookie = 'expandMap=0';
		}
  }
  catch(e){}
}

function loadMap(map,swlat,swlon,nelat,nelon) {
	try {
		if (map != undefined) {
			map.clearOverlays();
			if ( isNaN(swlat) ) {
				map.setCenter(new GLatLng(0,0), 0);
			}
			else {
				var bounds = new GLatLngBounds();
				var point = new GLatLng(swlat,swlon);
				bounds.extend(point);
				point = new GLatLng(nelat,nelon);
				bounds.extend(point);
				var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2;
				var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2;			
				map.setCenter(new GLatLng(clat,clng), map.getBoundsZoomLevel(bounds));
			}
		}
	}
  catch(e){alert(e.message);}
}

function gotMapAreaFromIP(data, eventArgs) {
	try {
		if ( mapexp != undefined ) {
			mapXmlData = GXml.parse(data);
			if (mapXmlData.documentElement != undefined && mapXmlData.documentElement.getAttribute("swLatitude") != undefined) {
				var el = mapXmlData.documentElement;
				loadMap(mapexp
					, new Number(el.getAttribute("swLatitude"))
					, new Number(el.getAttribute("swLongitude"))
					, new Number(el.getAttribute("neLatitude"))
					, new Number(el.getAttribute("neLongitude"))
				);
			}
		}
	}
  catch(e){}
}

function unloadMap() {
	try {
		smmp = document.getElementById("smallmap");
		if ((smmp != undefined) && GBrowserIsCompatible()) {
			if (map != undefined) map.clearOverlays();
			//if (typeof map != 'undefined') if (undefined != map) clearInstanceListeners(map);
			GUnload();
		}
    var bgborder = document.getElementById("centrmap");
    if (undefined != bgborder) {
			bgborder.style.display = "none";
		}
  }
  catch(e){}
}

function fetchHotels() {
	try {
		document.body.style.cursor = 'wait';
		var mapDiv = document.getElementById("map");
		var bounds = mapexp.getBounds();
		var Chain = -1;
		
		dispMapMsg("<p>Looking up hotels for this map ...</p><p><img src='/images/wait.gif' alt='Searching for availability' width='30' height='30'/></p>");
		var avMap = document.getElementById('mapAvailability');
		if (avMap != undefined ) {
			Ws.General.GetMarkerProps(bounds.getSouthWest().lat(), bounds.getSouthWest().lng(), bounds.getNorthEast().lat(), bounds.getNorthEast().lng(), avMap.getAttribute("fromDate"), avMap.getAttribute("nights"), avMap.getAttribute("adults"), Chain, GotMarkerProps);
		}
		else {
			Ws.General.GetMarkerProps(bounds.getSouthWest().lat(), bounds.getSouthWest().lng(), bounds.getNorthEast().lat(), bounds.getNorthEast().lng(), '', 0, 0, Chain, GotMarkerProps);
		}
  }
  catch(e){alert(e.message);}
	try {
		document.body.style.cursor = 'default';
	}
  catch(e){alert(e.message);}
}

function dispMapMsg(msg) {
	var mapMsg = document.getElementById("mapMsg");
	mapMsg.innerHTML = msg;
	if(msg=='') {
		mapMsg.style.display = 'none';
	}
	else {
		mapMsg.style.display = 'block';
	}
}

function GotMarkerProps(data, eventArgs) {
	try {
		mapXmlData = GXml.parse(data);
		if (mapXmlData.documentElement != undefined && mapXmlData.documentElement.getAttribute("result") != undefined) {
			var mapXmlRes = mapXmlData.documentElement.getAttribute("result");	//firefox
			mapXmlMarkers = mapXmlData.documentElement.getElementsByTagName("marker");
			if ( parseInt(mapXmlRes) == -1)
				dispMapMsg('<p>More than 100 hotels found for this map.<br />Please zoom in to your point of interest</p>');
			else if ( parseInt(mapXmlRes) == 0)
				dispMapMsg('<p>No hotels found for this map.<br />Please zoom out and expand the region covered to find hotels<p>');
			else if ( parseInt(mapXmlRes) == -2)
				dispMapMsg('');
			else dispMapMsg('');
			mapexp.clearOverlays();
			if (expSpecHotel) {
				var optM = new Object();
				optM.title = 'current hotel';
				optM.clickable = false;
				mapexp.addOverlay(new GMarker(new GLatLng(lat,lon), optM));
			}
			markers = new Array();
			var imgurl;
			for (var i = 0; i < mapXmlMarkers.length; i++) {
				if ( mapXmlMarkers[i].getAttribute("minRate") == undefined ) {
					imgurl = "/images/map/propyellow.png";
				}
				else if ( mapXmlMarkers[i].getAttribute("minRate") != "0" ) {
					imgurl = "/images/map/propgreen.png";
				}
				else {
					imgurl = "/images/map/propred.png";
				}
				addMarker( i, parseFloat(mapXmlMarkers[i].getAttribute("lat")), parseFloat(mapXmlMarkers[i].getAttribute("lon")), imgurl );
			}
			if (mapXmlData.documentElement.getElementsByTagName("mapAvailability").length > 0) {
				var mapAvailability = document.getElementById("mapAvailability");
				mapAvailability.innerHTML = mapXmlData.documentElement.getElementsByTagName("mapAvailability")[0].xml;
			}
		}
	}
	catch(e){alert(e.message);}
}

function addMarker(id,lat,lon,imgurl) {
	try {
		var icon = new GIcon();
		icon.image = imgurl;
		icon.shadow = "/tmplImages/map/shadow.png";
		icon.iconSize = new GSize(12, 20);
		icon.shadowSize = new GSize(22, 20);
		icon.iconAnchor = new GPoint(6, 20);
		icon.infoWindowAnchor = new GPoint(5, 1);
		var point = new GLatLng(lat,lon);
		var opt = new Object();
		opt.icon = icon;
		opt.clickable = true;
		var marker = new GMarker(point, opt);
		markers.push(marker);
		marker.id = id;
		GEvent.addListener(marker, "click", function() {
			try {
				var mapXmlMarker = mapXmlMarkers[marker.id];
				window.location.href=mapXmlMarker.getAttribute("url");
			}
			catch(e){}
		});
		GEvent.addListener(marker, "mouseover", function() { openHotBox(marker); } );
		GEvent.addListener(marker, "mouseout", function() {
			mapHotBoxShouldClose = true;
			window.setTimeout('closeMapHotBox();', 160);
			window.event.cancelBubble = true;
		});
		mapexp.addOverlay(marker);
  }
  catch(e){alert(e.message);}
}

function openHotBoxUrl() {
	try {
		var aHotBoxRef = document.getElementById('aHotBoxRef');
		if (aHotBoxRef != undefined && aHotBoxRef.getAttribute("href") != undefined) {
			aHotBoxRef.style.cursor = 'wait';
			window.location.href=aHotBoxRef.getAttribute("href");
		}
	}
  catch(e){alert(e.message);}
}

function openHotBox(marker) {
	try {
		var mapPane = mapexp.getPane(G_MAP_FLOAT_PANE);
		if ( mapPane != undefined) {
			if ( mapHotBox == undefined ) {
				mapHotBox = document.getElementById('mapHotBox');
				mapPane.appendChild(mapHotBox);
			}
			mapHotBoxShouldClose = false;	//should prevent first opening block then closing from previous...
			var mapXmlMarker = mapXmlMarkers[marker.id];
			var html = '';
			var stars = mapXmlMarker.getAttribute("stars");
			if ( stars != undefined ) {
				html += '<div class="mapHotBoxStars" ><img src="/images/' + mapXmlMarker.getAttribute("stars") + 'st.gif" /></div>';
			}
			html += '<div class= "mapHotBoxTitle" >'
				+ '<a id="aHotBoxRef" href="' + mapXmlMarker.getAttribute("url")
				+ '" style="font-size: 10pt; font-weight: bold; letter-spacing: 0; ">' + mapXmlMarker.getAttribute("name") + '</a></div>'
				+ '<div class="mapHotBoxImg" >'
				+ '<img src="' + mapXmlMarker.getAttribute("src") + '"';
			if ( mapXmlMarker.getAttribute("width") != undefined ) {
				html += ' width="' + mapXmlMarker.getAttribute("width");
			}
			if ( mapXmlMarker.getAttribute("height") != undefined ) {
				html += ' height="' + mapXmlMarker.getAttribute("height");
			}
			html += '" />';
			html += '</div>';
			html += '<div id="mapHotBoxAvail" markerID="' + marker.id + '">' + getHotBoxAv(mapXmlMarker) + '</div>';
			mapHotBox.innerHTML = html;
			var p = mapexp.fromLatLngToDivPixel(marker.getPoint());
			var pMapSW = mapexp.fromLatLngToDivPixel(mapexp.getBounds().getSouthWest());
			var pMapNE = mapexp.fromLatLngToDivPixel(mapexp.getBounds().getNorthEast());
			var mapSize = mapexp.getSize();
			var boxleft, boxtop;
			if (pMapSW.x + mapSize.width - p.x - 200 > 0) {
				boxleft = p.x;
			}
			else {
				boxleft = p.x - 200;
			}
			if (pMapNE.y + mapSize.height - p.y - 104 > 0) {
				boxtop = p.y - 12;
			}
			else {
				boxtop = p.y - 12 - 104;
			}
			if (document.all) { // IE
				mapHotBox.style.pixelLeft = boxleft;
				mapHotBox.style.pixelTop = boxtop;
			}
			else {
				mapHotBox.style.left = '' + boxleft + 'px';
				mapHotBox.style.top = '' + boxtop + 'px';
			}
			mapHotBox.style.display = 'block';
			//Search for availability
			var avMap = document.getElementById('mapAvailability');
			if (avMap != undefined && mapXmlMarker.getAttribute("minRate") == undefined) {
				mapXmlMarker.setAttribute("minRate", -1);
				window.setTimeout('fetchPropAv("' + marker.id + '",' + mapXmlMarker.getAttribute("propertyID") + ',"' + avMap.getAttribute("fromDate") + '",' + avMap.getAttribute("nights") + ',' + avMap.getAttribute("adults") + ');', 40);
			}
		}
  }
  catch(e){alert(e.message);}
}

function fetchPropAv(markerId,propertyID,fromDate,nights,adults) {
	Ws.General.GetPropAvInfo(markerId,propertyID,fromDate,nights,adults,GotPropAvInfo);
}

function GotPropAvInfo(data) {
	try {
		//Process data, i.e. assign minRate to marker
		mapXmlData = GXml.parse(data);
		if (mapXmlData.documentElement == undefined) return;
		var mapXmlAdd = mapXmlData.getElementsByTagName("marker");
		var markerID;
		if (mapXmlAdd.length > 0) {
			markerID = mapXmlAdd[0].getAttribute("ID");
			//Keep data local
			var mapXmlMarker = mapXmlMarkers[markerID];
			mapXmlMarker.setAttribute("minRate", mapXmlAdd[0].getAttribute("minRate"));
			//Adapt ui
			if ( mapXmlAdd[0].getAttribute("minRate") != "0" ) {
				markers[markerID].setImage("/images/map/propgreen.png");
			}
			else {
				markers[markerID].setImage("/images/map/propred.png");
			}
		}
		//Expose the result, if current hotBox corresponds to data
		var mapHotBoxAvail = document.getElementById('mapHotBoxAvail');
		if (mapHotBoxAvail != undefined && mapHotBoxAvail.getAttribute('markerID') == markerID) {
			mapHotBoxAvail.innerHTML = getHotBoxAv(mapXmlMarker);
		}
	}
  catch(e){alert(e.message);}
}

function HotBoxMouseOver() {
	try {
		if ( mapHotBox != undefined ) {
			mapHotBox.style.display = 'block';
			mapHotBoxShouldClose = false;
			window.event.cancelBubble = true;
		}
	}
	catch(e) {
		//ignore exceptions as firefox does not accept window.event
	}
}

function HotBoxMouseOut() {
	try {
		if ( mapHotBox != undefined ) {
			mapHotBox.style.display = 'none';
			mapHotBoxShouldClose = true;
			window.event.cancelBubble = true;
		}
	}
	catch(e) {
		//ignore exceptions as firefox does not accept window.event
	}
}

function closeMapHotBox() {
	try {
		if ( mapHotBox != undefined && mapHotBoxShouldClose ) {
			mapHotBox.style.display = 'none';
		}
	}
  catch(e){alert(e.message);}
}

function getHotBoxAv(mapXmlMarker) {
	try {
		var avMap = document.getElementById('mapAvailability');
		var html = '';
		if ( mapXmlMarker.getAttribute("minRate") != undefined && mapXmlMarker.getAttribute("minRate") != "-1" ) {
			if ( mapXmlMarker.getAttribute("minRate") != "0" ) {
				html += '<p>Rooms available starting from <span class="mapHotBoxRate">' + mapXmlMarker.getAttribute("currency") + ' ' + mapXmlMarker.getAttribute("minRate") + ' only</span></p>';
				html += '<p><a href="' + mapXmlMarker.getAttribute("url") + '">Click for full details</a></p>';
			}
			else {
				html += '<p>The hotel is fully booked. Please move to another hotel</p>';
			}
		}
		else {
			if (avMap != undefined) {
				html += '<p><img src="/images/wait.gif" alt="Searching for availability" width="30" height="30"/></p>';
			}
			else {
				html += '';
			}
		}
		return html;
  }
  catch(e) {return 'An error occurred while processing availability information. ' + e.message;}
}

//Reviews
function openReviews(propID) {
	try {
		togPage('');
		document.body.style.cursor = 'wait';
		Ws.General.getReviewDetails(propID,gotReviewDetails);
  }
  catch(e) {return 'An error occurred while fetching review details. ' + e.message;}
}

function gotReviewDetails(result, eventArgs) {
	try {
		var blck = document.getElementById('intPageStatCont');
		blck.innerHTML = result;
		if (result != '') {
			blck.style.display = 'block';
		}
		else {
			blck.style.display = 'none';
		}
		document.body.style.cursor = 'default';
	}
	catch(e){alert(e.message);}
}

function addReview(propID) {
	togPage('/pages/addReview.aspx?propID=' + propID);
}

function togPage(pageto) {
	try {
		var blackBckg = document.getElementById('blackBckg');
		var intPageBox = document.getElementById('intPageBox');
		var intPageFrame = document.getElementById('intPageFrame');
		var intPageStatCont = document.getElementById('intPageStatCont');
		if (intPageBox.style.display == 'none' || pageto != undefined) {
			blackBckg.style.display = 'block';
			intPageBox.style.display = 'block';
			intPageFrame.src = pageto;
			if ( pageto == '' ) { intPageFrame.style.display = 'none'; }
			else { 
				intPageStatCont.style.display = 'none';
				intPageFrame.style.display = 'block';
			}
		}
		else {
			blackBckg.style.display = 'none';
			intPageBox.style.display = 'none';
			intPageFrame.src = '';
			intPageFrame.style.display = 'none';
			intPageStatCont.innerHTML = '&160;';
			intPageStatCont.style.display = 'none';
		}
  }
	catch(e){alert(e.message);}
}

function hidePage() {
	togPage();
}

//General fts
function getCrtlPrefix() {
	var prefix;
	var cpfx = document.getElementById("cpfx");
	if (cpfx) prefix = cpfx.value;
	return prefix;
}

function getPage(e) {
	try {
		var f = document.getElementById('aspnetForm'), a;
		if ( e.target != undefined ) {
			a = e.target;
		}
		else {
			a = window.event.srcElement;
		}
		a = GetA(a);
		if ( a == undefined || a.href == undefined || a.nodeName == undefined || (a.host != undefined && a.host.replace(":80","") != window.location.host) || a.href.indexOf('#') != -1 ) return(true);
		if ( a.nodeName == 'A' ) {
			if ( a.pathname.substring(0,1) == '/' ) {
				f.action = a.pathname;
			}
			else {
				f.action = '/' + a.pathname;
			}
			var rn = document.getElementById(getCrtlPrefix() + 'hidRecordNumber');
			if ( a.getAttribute('recordNumber') != undefined ) {
				rn.value = a.getAttribute('recordNumber');
			}
			else { rn.value = 1; };
			var rc = document.getElementById(getCrtlPrefix() + 'useContext');
			rc.value = GetContext(a);
			f.submit();
		}
		return(false);
	}
	catch(e){alert(e.message);}
}

function GetA(node) {
	try {
		for ( ; node != undefined && node.nodeName != 'A'; node = node.parentNode) {};
		return (node);
	}
	catch(e){alert(e.message);}
}

function GetContext(anode) {
	try {
		for ( ; (anode != undefined) && (! anode.context); anode = anode.parentNode) {};
		if (anode == undefined) return (false);
		if (anode.context = 'true') return (true);
		return (false);
	}
	catch(e){alert(e.message);}
}

function scrollToLoc(toID) {
	try {
		document.getElementById('azloc' + toID).scrollIntoView(1);
	}
	catch(e){}
}

function changeSortOrder() {
	try {
		var f = document.getElementById('aspnetForm');
		if ( window.location.pathname.substring(0,1) == '/' ) {
			f.action = window.location.pathname;
		}
		else {
			f.action = '/' + window.location.pathname;
		}
		f.submit();
	}
	catch(e){alert(e.message);}
}

function changePictB(elname, pictid, link) {
  if (document.getElementById) {
		var el = document.getElementById(elname);
    el.style.backgroundImage = 'url("http://images.hotels-world.com/2' + pictid + '")';
    var l = link;
    for(l = link; l != null; l = l.nextSibling){
			if (l.tagName == 'A' && l.style != null) l.style.fontWeight = 'normal';
    }
    for(l = link; l != null; l = l.previousSibling){
			if (l.style != null) l.style.fontWeight = 'normal';
    }
    if (link.tagName == 'A' && link.style != null) link.style.fontWeight = 'bold';
  }
}

function changePictP(elname, pictid, link) {
  if (document.getElementById) {
		var el = document.getElementById(elname);
    el.style.backgroundImage = 'url("' + pictid + '")';
    var l = link;
    for(l = link; l != null; l = l.nextSibling){
			if (l.tagName == 'A' && l.style != null) l.style.fontWeight = 'normal';
    }
    for(l = link; l != null; l = l.previousSibling){
			if (l.style != null) l.style.fontWeight = 'normal';
    }
    if (link.tagName == 'A' && link.style != null) link.style.fontWeight = 'bold';
  }
}

function toTop() {
	try {
		document.getElementById('master').scrollIntoView(1);
		return(false);
	}
	catch(e){alert(e.message);}
}

function toBottom() {
	try {
		document.getElementById('bottomline').scrollIntoView(1);
		return(false);
	}
	catch(e){alert(e.message);}
}

//Edit description
function saveDescr(propertyID,language,descriptionCtrl) {
	try {
		if (document.getElementById) {
			document.body.style.cursor = 'wait';
			var description = document.getElementById(descriptionCtrl);
			var msg = document.getElementById('msgDescrEditSave');
			msg.innerHTML = "Saving the description content";
			msg.style.visibility = "visible";
			Ws.General.saveDescr(propertyID,language,description.innerText,SavedDescr);
		}
	}
	catch(e){alert(e.message);}
}

function SavedDescr(result, eventArgs) {
	try {
		var msg = document.getElementById('msgDescrEditSave');
		msg.innerHTML = result;
		if (result != '') {
			msg.style.visibility = "visible";
		}
		else {
			msg.style.visibility = "hidden";
		}
		document.body.style.cursor = 'default';
	}
	catch(e){alert(e.message);}
}

//Avail form
function checkSubmitForm( hashIn, isList, isAutoLookup ) {
	try {
		if (document.getElementById) {
			var centrmap = document.getElementById("centrmap");
			if (centrmap != undefined) centrmap.style.display = "none";
			var frm = document.getElementById('aspnetForm');
			var y = frm.selAvSearchCiyymm.value.substr(0,4);
			var m = new Number(frm.selAvSearchCiyymm.value.substr(5,2));
			var nmd = new Number(frm.selAvSearchCiday.value);
			if (isValidDate(nmd, m-1, y)) {
				var fromDate = ''+y+frm.selAvSearchCiyymm.value.substr(5,2);
				if (nmd <= 9) {fromDate+='0';}
				fromDate+=nmd;
				var avMap = document.getElementById('mapAvailability');
				if (avMap != undefined) {
					avMap.setAttribute("fromDate",fromDate);
					avMap.setAttribute("nights",frm.selAvSearchNights.value);
					avMap.setAttribute("adults",frm.selAvSearchAdults.value);
				}
				if (isList) {
					if (avMap != undefined) magnify(true);
				}
				else {	//property
					document.getElementById('divAvailWait').style.display='block';
					document.getElementById('divAvail').style.display='none';
					document.getElementById('divAvailNoRooms').style.display='none';
					if ( isAutoLookup == null ) {
						isAutoLookup = true;
					}
					misAutoLookup = isAutoLookup;
					Ws.General.GetAvailability(hashIn, fromDate, frm.selAvSearchNights.value, frm.selAvSearchAdults.value, GotAvail);
				}
				return;
			}
			alert('Please note the date is not valid');
		}
	}
	catch(e){alert(e.message);}
}

function submitBookings() {
	var arr = document.getElementsByTagName('select');
	var argsRooms = '';
  var args = document.getElementById('propID').value;
	
	for ( var i = 0; i < arr.length; i++ ) {
		if ( arr[i].className == 'book') {
			if ( arr[i].value != "0" ) {
				argsRooms += arr[i].name + '=' + arr[i].value + '&';
			}
		}
	};
	if ( argsRooms == '' ) {alert ('Please first select the number of rooms required');}
	else {
		var url = 'https://secure.booking.com/book.en.html?aid=307713&label=hw&stage=1&' +  args + '&' + argsRooms;
		var wdwopt = 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=' + screen.width + ',height=' + screen.height + ',left=0,top=0';
		window.location.href=url;
		return;
	}
	for ( var i = 0; i < arr.length; i++ ){
		if ( arr[i].className == 'book') {
			arr[i].focus();
			return;
		}
	};
	return;
}

function GotAvail(result, eventArgs) {
	try {
		document.getElementById('divAvailWait').style.display="none";
		var da;
		if (result.indexOf('availMsg') == -1) {
			da = document.getElementById("divAvail");
			document.getElementById("divAvailNoRooms").style.display='none';
		}
		else {
			da = document.getElementById("divAvailNoRooms");
		}
		da.style.display='block';
		da.innerHTML = result;
		if ( misAutoLookup == true ) {
			document.getElementById("divAvSearch").scrollIntoView(1);
		}
		//
		var centrmap = document.getElementById("centrmap");
		if (centrmap != undefined) {
			if ( result.indexOf('availMsg') == -1 ) {
				centrmap.style.display = "none";
				document.cookie = 'expandMap=0';
			}
			else {
				centrmap.style.display = "block";
				contMagn(true);
				document.cookie = 'expandMap=1';
			}
		}
	}
  catch(e){alert(e.message);}
}

function isValidDate(day,month,year){
  //Purpose: return true if the date is valid, false otherwise. Valid dates should be current date or after
  //Variables: dteDate - date object
  var dteDate;
  //javascript months start at 0 (0-11 instead of 1-12)
  dteDate = new Date(year,month,day);
  var crntDt = new Date();
  var crntdate = new Date(crntDt.getYear(),crntDt.getMonth(),crntDt.getDate());
  var res = (crntdate <= dteDate);
  if (res) res=((day==dteDate.getDate()) && (month==dteDate.getMonth()) && (year==dteDate.getFullYear()));
  return res;
}

function checkDateOrder(ci_day, ci_month_year, co_day, co_month_year) {
	try {
		if (document.getElementById) {
			var frm = document.getElementById('aspnetForm');
			var my = frm[ci_month_year].value.split("-");
			var ci = new Date (my[0], my[1]-1, frm[ci_day].value, 12, 0, 0, 0);
		}
	}
	catch(e){alert(e.message);}
}

function calcDeparture( strDepartDt ){
	try {
		if (document.getElementById) {
			var frm = document.getElementById('aspnetForm');
			var departdt = document.getElementById(strDepartDt);
			var y = frm.selAvSearchCiyymm.value.substr(0,4);
			var m = new Number(frm.selAvSearchCiyymm.value.substr(5,2));
			var nmd = new Number(frm.selAvSearchCiday.value);
			var nmNights = new Number(frm.selAvSearchNights.value);
			var d = nmd + nmNights;
			var dt = new Date(y, m-1, d);
			var days = new Array("Sunday", "Monday", "Tuesday", "Wednesday","Thursday", "Friday", "Saturday");
			var months = new Array("January", "February", "March", "April","May", "June", "July", "August", "September", "October", "November", "December");
			if (isValidDate(nmd, m-1, y)) {
				departdt.innerHTML = days[dt.getDay()] + ' ' + dt.getDate() + ' ' + months[dt.getMonth()] + ' ' + dt.getFullYear();
				return;
			}
			departdt.innerHTML = '';
		}
	}
	catch(e){alert(e.message);}
}

function butBookHi(img) {
	try {
		img.src='/images/submitBook.png';
	}
  catch(e){alert(e.message);}
}

function butBookLi(img) {
	try {
		img.src='/images/submitBookLi.png';
	}
  catch(e){alert(e.message);}
}

function submitBook(nmbr,rateplanID,roomID) {
	try {
		if (document.getElementById){
			var selNmbr = document.getElementById(nmbr);
			if ( selNmbr.value == 0 ) {
				alert('Please first select the number of rooms required');
			}
			else { 
				var domain = document.getElementById('bookurl');
				var availID = document.getElementById('availID');
				//var comingFrom = utf8encode(document.getElementById('comingFrom').value);
				//var comingFrom = document.getElementById('comingFrom').value;
				var comingFrom = document.getElementById('bookurl').getAttribute('comingFrom');
				window.location.href=domain.getAttribute("value") + '?availID=' + availID.getAttribute("value") + '&nmbrRooms=' + selNmbr.value + '&rateplanID=' + rateplanID + '&roomID=' + roomID + '&comingFrom=' + comingFrom;
			}
		}
	}
  catch(e){alert(e.message);}
}

function utf8encode(string) {
	string = string.replace(/\r\n/g,"\n");
	var utftext = "";
	for (var n = 0; n < string.length; n++) {
		var c = string.charCodeAt(n);
		if (c < 128) { utftext += String.fromCharCode(c); }
		else if((c > 127) && (c < 2048)) {
			utftext += String.fromCharCode((c >> 6) | 192);
			utftext += String.fromCharCode((c & 63) | 128);
		}
		else {
			utftext += String.fromCharCode((c >> 12) | 224);
			utftext += String.fromCharCode(((c >> 6) & 63) | 128);
			utftext += String.fromCharCode((c & 63) | 128);
		}
	}
	return utftext;
}

function printDoc() {
	if(window.print) window.print()
	else alert (tr.pressCltP);
}

function addbookmark(){
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(document.title, document.URL,"");
	}
	else if( window.external ) { // IE Favorite		
			window.external.AddFavorite(document.URL,document.title);
	}
}

function switchExpandv2(expandViewRoomsExplainViewAll,expandViewRoomsExplainHideAll,expandViewRooms,additRooms) {
	try {
		var d = document.getElementById(expandViewRooms);
		if (d != undefined && d.className == 'viewAll') {
			d.className = 'noViewAll';
		}
		else {
			d.className = 'viewAll';
		}
		var r = document.getElementById(additRooms);
		if (r != undefined && r.style.display == "none") {
			r.style.display = "block";
			document.getElementById(expandViewRoomsExplainViewAll).style.display = "none";
			document.getElementById(expandViewRoomsExplainHideAll).style.display = "inline";
		}
		else {
			r.style.display = "none";
			document.getElementById(expandViewRoomsExplainViewAll).style.display = "inline";
			document.getElementById(expandViewRoomsExplainHideAll).style.display = "none";
		}
		return false;
  }
  catch(e){alert(e.message);}
}

function showCalendar(img,cal,m,y,d) {
	if (document.getElementById){
		var c = document.getElementById(cal);
		var i = document.getElementById(img);
		var f = document.getElementById('aspnetForm');
		calendar.calfrm = 'aspnetForm';
		calendar.cal = c;
		calendar.calf = f;
		var my = f['selAvSearchCiyymm'].value.split("-");
		y=my[0];m=my[1];d=f['selAvSearchCiday'].value;
		buildCal(y,m,d);
		c.style.display="block";
	}
}

function closeCal() {
  calendar.cal.style.display='none';
  calcDeparture('divAvSearchOutDepartDt');
}

function makeArray() {
	for (i = 0; i<makeArray.arguments.length; i++)
		 this[i] = makeArray.arguments[i];
}

function buildCal(y,m,d){
    var daysInMonth=[31,0,31,30,31,30,31,31,30,31,30,31];
    var monthsNr = new makeArray("01","02","03","04","05","06","07","08","09","10","11","12");
    td=new Date();
    if (!y) y = td.getFullYear();
    if (!m) m = monthsNr[td.getMonth()];
    if (!d) d = td.getDate;
    var frm = calendar.calfrm;
    var mDate = new Date(y, m-1, 1);
    var firstMonthDay = mDate.getDay();
    daysInMonth[1]=(((mDate.getFullYear()%100!=0)
      &&(mDate.getFullYear()%4==0)) || (mDate.getFullYear()%400==0))?29:28;

    var today = (y==td.getFullYear() && m==td.getMonth()+1)? td.getDate() : 0;
    var t='<table class="caltable" cellspacing="0"><tr>';
    var flm=td.getMonth()+1;var flyr=td.getFullYear();
    for(p=0;p<=10;p++){
      if (flm == m) {
          filaMonth = p;
      }
      flm++; if (flm>12) { flm=1;flyr++ }
    }
    t+='<td class="calheader" colspan="7" >';
    if (filaMonth == 0) {
      t+='<img class="calNoPrevMonth" src="' + tr.icons + '/transparent.png" width="24" height="24" alt="'+tr.prevMonth+'">';
    }
    else {
      t+='<a class="calPrevMonth" href="" onclick="prevMonth('+y+','+m+'); return false;" title="'+tr.prevMonth+'"><img src="' + tr.icons + '/transparent.png" width="24" height="24" alt="'+tr.prevMonth+'"></a>';
    }
    t+='&nbsp;<select name="ym" onchange="goMonth(this.options[this.selectedIndex].value)">';
    var mn=td.getMonth()+1;var yr=td.getFullYear();
    for(n=0;n<=10;n++){
      t+='<option value="' + mn + '"';
      if (mn == m) {
          t+=' selected="selected"';
      }
      t+='>' + months[mn-1] + ' ' + yr +'</option>';
      mn++; if (mn>12) { mn=1;yr++ }
    }
    t+= ' </select>&nbsp;';
    if (filaMonth == 10) {
      t+='<img class="calNoNextMonth" src="' + tr.icons + '/transparent.png" width="24" height="24" alt="' + tr.nextMonth + '">';
    }
    else {
      t+='<a class="calNextMonth" href="" onclick="nextMonth('+y+','+m+'); return false;" title="' + tr.nextMonth +'"><img src="' + tr.icons + '/transparent.png" width="24" height="24" alt="' + tr.nextMonth + '"></a>';
    }
    t+='</td></tr>';
    t+='<tr class="dayNames">';
    for(dn=0;dn<7;dn++){
      var cl = '';
      if ((dn%7==5) || (dn%7 == 6)) cl += ' weekend';
      t+='<td class="'+cl+'">'+days[dn]+'</td>';
    }
    t+='</tr><tr class="days">';
    for(i=1;i<=42;i++){
      var x = i - (firstMonthDay+6)%7;
      if (x > daysInMonth[m-1] || x <1) x = '&nbsp;';
      var cl = '';
      var href = 0;
      if ((i%7==0) || (i%7 == 6)) cl += ' weekend';
      if (x>0){
          var xDay = new Date(y, m-1, x);
          if ((xDay.getFullYear() == y) && (xDay.getMonth()+1 == m)
              && (xDay.getDate() == d))
              { cl += ' selected' ; href=1}
          if ((xDay.getFullYear() == td.getFullYear())
              && (xDay.getMonth() == td.getMonth())
              && (xDay.getDate() == td.getDate()))
              { cl += ' today'; href=1;}
          else {
              if (xDay > td){ cl += ' future'; href=1; }
              else {
                  if (xDay < td) { cl += ' past'}
              }
          }
      };
      t+='<td class="'+cl+'">';
      if (href){
          t+='<a href="#rtet" onclick="pickDate('+y+','+m+','+x+',\''+frm+'\'); return false;">'+x+'</a>';
      } else {
          t+=x;
      }
      t+='</td>';
      if(((i)%7==0)&&(i<36)) {
          t+='</tr><tr class="days">';
      }
    }
    t+='</tr><tr><td colspan="7"><a href="#xyz" onclick="closeCal();return(false);">' + tr.closeCalendar + '</a></td></tr></table>';
    document.getElementById("calendar").innerHTML=t;
}

function prevMonth(y,m) {
    if (new Date(y,m-1,1) < td) return;
    if (m > 1) {m--} else {m = 12; y--};
    buildCal(y,m);
}

function nextMonth(y,m) {
    if (m<12){m++;} else {m=1;y++;}
    if (y > td.getFullYear() && m >= td.getMonth() ) return;
    buildCal(y,m);
}

function goMonth(m){
    var y = td.getFullYear();
    if (m < td.getMonth()+1) y++;
    buildCal(y,m);
}

function pickDate(y,m,d,frm){
    // set form values
    var f = calendar.calf;
	var monthsNr = new makeArray("01","02","03","04","05","06","07","08","09","10","11","12");
    f['selAvSearchCiyymm'].value = y + "-"  + monthsNr[m-1];
    f['selAvSearchCiday'].value = d;
    closeCal();
}

//Prep calendar
calendar = new Object();
tr = new Object();
tr.nextMonth = "Next month";
tr.prevMonth = "Previous month";
tr.closeCalendar = "Close";
tr.pressCtlD = "";
tr.pressCtlP = "";
tr.url = "";
tr.title = "Hotels-World Welcome";
tr.icons = "/images";
var months=['January','February','March','April','May','June','July','August','September','October','November','December'];
var days=['Mo','Tu','We','Th','Fr','Sa','Su'];
