var xmlHttpRequest = getXMLHttpRequest();
var loadingImageHotelsURI = "/images/routes/ajax-loader-white.gif";
var poiSearchItemCount=0;
function ajaxHotelsReady()
{
if (xmlHttpRequest.readyState != 4)
return;
var nearbyHotelsElement = document.getElementById('nearbyHotels');
// Check that we have a good status code
if (xmlHttpRequest.status < 200 || xmlHttpRequest.status > 299)
{
nearbyHotelsElement.innerHTML = '
Sorry, this service is temporarily unavailable. Please try again later.
';
return;
}
nearbyHotelsElement.innerHTML = xmlHttpRequest.responseText;
}
function populateHotelsBarGaz()
{
if ($("#dbEurope").is(':checked') || $("#dbIreland").is(':checked'))
{
// No hotels lookup for Europe/Ireland
$("#internalAdvert").show();
$("#nearbyHotels").html("")
return;
}
var selectTo = document.getElementById("confirmTo");
var gazLocString = escape(selectTo.value);
// Display EBC ad for specific destinations
if (!checkPortLocation(gazLocString))
{
populateHotelsBarByDestination('','',"overlayMapMessage",gazLocString);
}
}
function populateHotelsBarByDestination(lat,lon,poiMsgID,gazLocString)
{
//poiType 102 and poiType 104=bandb
var nearbyHotelsElement = $('#nearbyHotels');
var padding = 14;
var margin = 20;
var hotelBarWidth = nearbyHotelsElement.outerWidth(true) - padding - margin;
var maxHotelsToDisplay = Math.floor( hotelBarWidth/213 );
var baseRequest = '/aaservlet/poi-search';
var baseParameters = 'poitype=131&lat=' + lat + '&long=' + lon + '&maxresults=' + maxHotelsToDisplay;
if(lat==''&&lon==''&&gazLocString!='')
{
baseParameters = 'poitype=131&gazLocation=' + gazLocString + '&maxresults=' + maxHotelsToDisplay;
}
var bolMarkersOnMap=true;
if(gazLocString!='')
{
//initial route request
bolMarkersOnMap=false;
}
$.ajax({
url:baseRequest,
type: "get",
data: baseParameters,
dataType: "json",
error: function(xhr, desc, exceptionobj) {
//error getting hotels
nearbyHotelsElement.html("");
},
success:function(json)
{
populateHotelsBarFromJson(json,bolMarkersOnMap,poiMsgID,gazLocString); //markers already on map
} //end success
}); //end ajax
}//end function
function populateHotelsBarFromJson(json,bolMarkersOnMap,poiMsgID,gazLocString)
{
var nearbyHotelsElement = $('#nearbyHotels');
var padding = 14;
var margin = 20;
var hotelBarWidth = nearbyHotelsElement.outerWidth(true) - padding - margin;
var maxHotelsToDisplay = Math.floor( hotelBarWidth/213 );
var strHTMLOutput=''
+'';
var hotelCount=0;
//now we have an array of hotels
$.each(json.summaries, function(i,poiItem)
{
//poiTypeID:130 - non AA rated hotels
var strName=poiItem.name;
var strlongitude=poiItem.longitude;
var strSummary=poiItem.summary;
var isRedStars=poiItem.isRedStars;
var imageUrl=isEmpty(poiItem.imageUrl);
var poiTypeID=poiItem.poiType;
var strpercent=isEmpty(poiItem.percent);
var strcategory=isEmpty(poiItem.category);
var strlatitude=poiItem.latitude;
var strqualityRating=isEmpty(poiItem.qualityRating);
var strpriceFrom=isEmpty(poiItem.priceFrom);
var bolaaRated=isEmpty(poiItem.aaRated);
var appointmentCurrent=isEmpty(poiItem.appointmentCurrent);
var strShortName=strName;
if (strShortName.length>20) {
strShortName=strShortName.substring(0,19) + '...';
}
var strPOIid=poiItem.id;
var starImage="star_" + strqualityRating + ".gif";
if (poiTypeID==102) {
if(isRedStars)
{
starImage="redstar_" + strqualityRating + ".gif";
}
}
if (poiTypeID==104) {
if(isRedStars)
{
starImage="yellow-star-" + strqualityRating + ".gif";
}
}
var tmpStrPOIType=getPOITypeFromID(poiTypeID);
strHTMLOutput+='
';
strHTMLOutput+='
';
strHTMLOutput+='
';
strHTMLOutput+='
';
if(bolaaRated && (poiTypeID==102 || poiTypeID==104))
{
strHTMLOutput+='
';
if(appointmentCurrent=='U')
{
//no star ratings if unclassified
strHTMLOutput+='
';
}
else
{
if(strqualityRating!='' && !isNaN(strqualityRating))
{
if(appointmentCurrent=='A')
{
strHTMLOutput+='
';
}
strHTMLOutput+= '
';
}
}
//strHTMLOutput+='
';
}
//end bolaaRated
if(parseInt(strpriceFrom,10)>0)
{
strHTMLOutput+=" from £" + strpriceFrom;
}
strHTMLOutput+='
' + strcategory + '
';
strHTMLOutput+='
';
strHTMLOutput+='
';
//no images
if(imageUrl=='')
{
imageUrl="/images/routes/hotelbar-no-image-48x40.gif";
}
strHTMLOutput+='

';
strHTMLOutput+='
';
strHTMLOutput+='
';
hotelCount++;
if(i==maxHotelsToDisplay-1)
{
return false;
}
hotelCount++;
}); //end each
strHTMLOutput+='
';
//clear loading
hidePOIMsg("#overlayMapMessage")
//update page
if(hotelCount>0)
{
$("#internalAdvert").hide();
nearbyHotelsElement.html(strHTMLOutput);
}
else{
$("#internalAdvert").show();
nearbyHotelsElement.html("")
};
}
function checkPortLocation(gazLocString)
{
//check is a port
var arrPorts = new Array('dover','portsmouth','harwich','folkestone','hull','new haven','poole','plymouth','fishguard','hollyhead','liverpool','stranraer');
if (gazLocString != '')
{
var tmpLoc = gazLocString.toLowerCase();
for (i=0; i < arrPorts.length; i++)
{
if ( (tmpLoc.indexOf('%7c'+arrPorts[i]) > -1) || (tmpLoc.indexOf('%20'+arrPorts[i]) > -1) )
{
//is a port
setInternalAd("/images/routes/european-breakdown-cover.gif","/breakdown-cover/european-breakdown-cover.jsp","Get European breakdown cover");
return true;
}
}
}
return false;
}