//------------------------------------------------------------------ //formatDate (date_object, format) var DAY_MILLIS = 1000 * 60 * 60 * 24; var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); var DAY_NAMES=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat'); function getToday() { var today = new Date(); today.setHours(0); today.setMinutes(0); today.setSeconds(0); today.setMilliseconds(0); return today; } function LZ(x) {return(x<0||x>9?"":"0")+x} function formatDate(date,format) { format=format+""; var result=""; var i_format=0; var c=""; var token=""; var y=date.getYear()+""; var M=date.getMonth()+1; var d=date.getDate(); var E=date.getDay(); var H=date.getHours(); var m=date.getMinutes(); var s=date.getSeconds(); var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k; // Convert real date parts into formatted versions var value=new Object(); if (y.length < 4) {y=""+(y-0+1900);} value["y"]=""+y; value["yyyy"]=y; value["yy"]=y.substring(2,4); value["M"]=M; value["MM"]=LZ(M); value["MMM"]=MONTH_NAMES[M-1]; value["NNN"]=MONTH_NAMES[M+11]; value["d"]=d; value["dd"]=LZ(d); value["E"]=DAY_NAMES[E+7]; value["EE"]=DAY_NAMES[E]; value["H"]=H; value["HH"]=LZ(H); if (H==0){value["h"]=12;} else if (H>12){value["h"]=H-12;} else {value["h"]=H;} value["hh"]=LZ(value["h"]); if (H>11){value["K"]=H-12;} else {value["K"]=H;} value["k"]=H+1; value["KK"]=LZ(value["K"]); value["kk"]=LZ(value["k"]); if (H > 11) { value["a"]="PM"; } else { value["a"]="AM"; } value["m"]=m; value["mm"]=LZ(m); value["s"]=s; value["ss"]=LZ(s); while (i_format < format.length) { c=format.charAt(i_format); token=""; while ((format.charAt(i_format)==c) && (i_format < format.length)) { token += format.charAt(i_format++); } if (value[token] != null) { result=result + value[token]; } else { result=result + token; } } return result; } function gup( name ) { name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); var regexS = "[\\?&]"+name+"=([^&#]*)"; var regex = new RegExp( regexS ); var results = regex.exec( window.location.href ); if( results == null ) return ""; else { oStr = results[1].replace(/%20/g, " "); //alert("Returning : " + oStr); return oStr; } } function gup2(iUrl, name) { name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); var regexS = "[\\?&]"+name+"=([^&#]*)"; var regex = new RegExp( regexS ); var results = regex.exec( iUrl ); if( results == null ) return ""; else { oStr = results[1].replace(/%20/g, " "); //alert("Returning : " + oStr); return oStr; } } // I am sorry this is hardcoded... // The current architecture was just // too bad to make something generic with the time I had /*function HotelAmenityList() { var myArray = new Array(6); myArray['1'] = ""; }*/ // Constructor function HotelDetailedInfo() { this.hotelName = ""; this.hotelAddress = ""; this.urlMap = new Array(); this.amenitiesMap = new Array(); this.awardsMap = new Array(); this.hotelDescription = ""; this.calendarViewListObj = ""; } /* function CalendarViewList() { this. }*/ function CalendarViewList(iMinStartDate, iMaxStartDate, iMinEndDate, iMaxEndDate,iCheckInDate, iCheckOutDate) { this.minStartDate = Date.parse(iMinStartDate); this.maxStartDate = Date.parse(iMaxStartDate); this.minEndDate = Date.parse(iMinEndDate); this.maxEndDate = Date.parse(iMaxEndDate); this.checkInDate = Date.parse(iCheckInDate); this.checkOutDate = Date.parse(iCheckOutDate); this.calendarViewList = new Array(); this.startDateLength = ""; this.endDateLength = ""; var DAY_MILLIS = 1000 * 60 * 60 * 24; this.plusMinusDays = ((this.checkInDate - this.minStartDate) / DAY_MILLIS); //alert("Dates : " + iMinStartDate + iMaxStartDate + " <> " +iMinEndDate + iMaxEndDate); var theDateObj = new Date(); //alert("Start date: " + this.minStartDate); theDateObj.setTime(this.minStartDate); var theDateStr = formatDate(theDateObj, "dd NNN yyyy"); //alert(theDateStr); // Convert all dates to Date objects and construct array /*var theStartEarliest = Date.parse(this.minStartDate); var theStartLatest = Date.parse(this.maxStartDate); var theEndEarliest = Date.parse(this.minEndDate); var theEndLatest = Date.parse(this.maxEndDate);*/ //alert("End date min:" + this.minEndDate + " max:" + this.maxEndDate ); // Calculate Dimensions of the matrix...plus 1 to take into account start day this.startDateLength = ((this.maxStartDate - this.minStartDate)/DAY_MILLIS)+1; this.endDateLength = ((this.maxEndDate - this.minEndDate)/DAY_MILLIS)+1; //var theNbElements = this.startDateLength * this.endDateLength ; //alert("We are constructing a matrix of CalendarView elements (" + theNbElements+")"); var theStartDate = this.minStartDate; for (i = 0; i < this.startDateLength;i++){ //alert("Looping on start date " + i); var j = 0; for (j = this.minEndDate; j <= this.maxEndDate;){ //alert("Looping on end date :" + j); //var theStartStr = formatDate(i, "dd NNN yyyy"); //alert("Formatting..."); //var theEndStr = formatDate(j, "dd NNN yyyy"); //alert("New calendarViewStay"); var theIsRequestedDates = 0; if(theStartDate == this.checkInDate && j == this.checkOutDate) { theIsRequestedDates = 1; } var theCalendarViewStay = new CalendarViewStay(theStartDate, j, theIsRequestedDates); this.calendarViewList.push(theCalendarViewStay); //alert("set new time"); //j.setDate(j.getDate() + 1); //alert("new time is set"); j = j + DAY_MILLIS ; } theStartDate += DAY_MILLIS ; //i.setDate(i.getTime() + (1 * DAY_MILLIS)); } //alert("We have constructed a matrix of "+ this.calendarViewList.length + " elements"); //alert("We have constructed a matrix of startlength "+ this.startDateLength); //alert("We have constructed a matrix of endlength "+ this.endDateLength); } /* function CalendarViewStay(){ this.startDate = ""; this.endDate = ""; this.price = ""; }*/ function CalendarViewStay(iStartDate, iEndDate, iIsRequestedDates){ //alert("Adding CV element SD: " + iStartDate + " - ED: " + iEndDate); this.startDate = iStartDate; this.endDate = iEndDate; this.price = 0; this.requestedDates = iIsRequestedDates; } /* function HotelDetailedInfo.prototype.sortCalendarViewArray(a, b) { //Less than 0: Sort "a" to be a lower index than "b" // Zero: "a" and "b" should be considered equal, and no sorting performed. // Greater than 0: Sort "b" to be a lower index than "a". var aStart = Date.parse(a.startDate); var bStart = Date.parse(b.startDate); if(aStart < bStart) { } } */ function AmenityMapping(){ this.code = ""; this.description = ""; } function convertAmenityCodeToText(iCode){ var theAmenityList = new Array(); theAmenityList['33'] = "Elevators"; theAmenityList['66'] = "Swimming Pool"; theAmenityList['68'] = "Car Park"; theAmenityList['221'] = "Internet"; theAmenityList['222'] = "Internet"; for(key in theAmenityList){ if(key == iCode){ return theAmenityList[key]; } } return iCode; } HotelDetailedInfo.prototype.processAmenityMappingRS2 = function (iXml){ //alert("processAmenityMappingRS2"); var theXmlDoc = null; try {//Internet Explorer theXmlDoc = new ActiveXObject("Microsoft.XMLDOM"); theXmlDoc.async = "false"; theXmlDoc.loadXML(iXml); } catch(e) { try { //Firefox, Mozilla, Opera, etc. parser = new DOMParser(); theXmlDoc = parser.parseFromString(iXml, "text/xml"); } catch (ee) { return; } } if(theXmlDoc == null ){ alert("booohooo "); } //alert("loop xml"); var theAmenityNodes = theXmlDoc.documentElement.getElementsByTagName("Amenity"); for(i=0;i < theAmenityNodes.length;i++){ //alert("Adding :" + theAmenityNodes[i].childNodes[0].nodeValue + " on code: " +theAmenityNodes[i].getAttribute("Code") ); for(j=0;j < this.amenitiesMap.length;j++){ if(this.amenitiesMap[j].code == theAmenityNodes[i].getAttribute("Code")){ //alert("Adding :" + theAmenityNodes[i].childNodes[0].nodeValue + " on code: " +theAmenityNodes[i].getAttribute("Code") ); this.amenitiesMap[j].description = theAmenityNodes[i].childNodes[0].nodeValue; //alert("Adding :" + j+"/"+this.amenitiesMap[j].code+"/"+this.amenitiesMap[j].description); } } //this.amenitiesMap[theAmenityNodes[i].getAttribute("Code")] = theAmenityNodes[i].childNodes[0].nodeValue; } } HotelDetailedInfo.prototype.getAmenityCodeMapping = function (){ var xmlhttp = null; if (window.XMLHttpRequest) {// code for IE7, Firefox, Opera, etc. //alert("XMLHttpRequest created"); xmlhttp = new XMLHttpRequest(); } else if (window.ActiveXObject) {// code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } else { //alert("No XMLHttpRequest created"); } if (xmlhttp != null) { //alert("Get the data" +theUrl); //xmlhttp.onreadystatechange = xmlLoad; var theUrl = "/walbrowser/AmenityCodeMapping?"; var first =1; for(a=0;a< this.amenitiesMap.length;a++){ if(first){ first=0; } else{theUrl+="&";} theUrl += "amenity=" +this.amenitiesMap[a].code ; } //alert("Get the data" +theUrl); xmlhttp.open("GET", theUrl, true); xmlhttp.send(null); var theHotelInfoObj = this; xmlhttp.onreadystatechange = function() { if(this.readyState == 2) { //alert("OOOOOOOOOOOOOOOh state == 2"); } if (xmlhttp.readyState==4) { //alert("OOOOOOOOOOOOOOOh state == 4"); //alert("state == 4 :" + xmlhttp.responseText); //this.processAmenityMappingRS(xmlhttp.responseText); theHotelInfoObj.processAmenityMappingRS2(xmlhttp.responseText); //alert("Finished processing"); theHotelInfoObj.outputHotelDetails(); } } } } function loadHotelDetailedInfo(){ loadHotelDetailedInfo(""); } function loadHotelDetailedInfo(iUrl) { //alert(gup("checkInDate")); var theUrl = ""; if(iUrl == ""){ theUrl += "/walbrowser/CalendarView?checkInDate="+gup("checkInDate")+"&checkOutDate="+gup("checkOutDate"); theUrl += "&startDateEarliest="+gup("startDateEarliest")+"&startDateLatest="+gup("startDateLatest")+"&endDateEarliest="+gup("endDateEarliest")+"&endDateLatest="+gup("endDateLatest"); theUrl += "&chainCode="+gup("chainCode")+"&hotelCode="+gup("hotelCode")+"&hotelCityCode="+gup("hotelCityCode"); } else {theUrl = iUrl;} //alert("URL: " + theUrl); //GDownloadUrl(theUrl, processDownloadResponse); var theHotelDetails = new HotelDetailedInfo(); var xmlhttp = null; if (window.XMLHttpRequest) {// code for IE7, Firefox, Opera, etc. //alert("XMLHttpRequest created"); xmlhttp = new XMLHttpRequest(); } else if (window.ActiveXObject) {// code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } else { //alert("No XMLHttpRequest created"); } if (xmlhttp != null) { //alert("Get the data" +theUrl); //xmlhttp.onreadystatechange = xmlLoad; xmlhttp.open("GET", theUrl, true); xmlhttp.send(null); xmlhttp.onreadystatechange = function() { if(this.readyState == 2) { //alert("OOOOOOOOOOOOOOOh state == 2"); } if (xmlhttp.readyState==4) { //alert("state == 4 :" + xmlhttp.responseText); var theCalendarViewList = new CalendarViewList(gup2(theUrl,"startDateEarliest"), gup2(theUrl,"startDateLatest"), gup2(theUrl,"endDateEarliest"), gup2(theUrl,"endDateLatest"),gup2(theUrl,"checkInDate"),gup2(theUrl,"checkOutDate")); //alert("Start date from command " + gup("startDateEarliest")); theHotelDetails.calendarViewListObj = theCalendarViewList; //alert("Sent message and received response...."); theHotelDetails.processCalendarViewRS(xmlhttp.responseText); //alert("Calling AmenityCodeMapping"); theHotelDetails.getAmenityCodeMapping(); } } } //alert("Sent message and received response...."); //return theUrl; } HotelDetailedInfo.prototype.processAmenityMappingRS = function(iXml) { alert("process amentiies xml"); } HotelDetailedInfo.prototype.processCalendarViewRS = function(iXml) { var theXmlDoc = null; try {//Internet Explorer theXmlDoc = new ActiveXObject("Microsoft.XMLDOM"); theXmlDoc.async = "false"; theXmlDoc.loadXML(iXml); } catch(e) { try { //Firefox, Mozilla, Opera, etc. parser = new DOMParser(); theXmlDoc = parser.parseFromString(iXml, "text/xml"); } catch (ee) { return; } } if(theXmlDoc == null ){ alert("booohooo "); } //alert("processCalendarViewRS(iXml) : " + iXml); var theSuccessNode = theXmlDoc.documentElement.getElementsByTagName('Success'); if (!theSuccessNode){ //alert("No success node present"); } //alert("processCalendarViewRS(iXml) : RoomStays"); var theRoomStaysNode = theXmlDoc.documentElement.getElementsByTagName('RoomStays')[0]; // Should only be 1 as only awaiting response of 1 hotel if(!theRoomStaysNode || theRoomStaysNode.length > 1){ //alert("Returned results for more than 1 hotel..bad!"); return "Error"; } //alert("processCalendarViewRS(iXml) : HotelConstructor"); //alert("processCalendarViewRS(iXml) : RoomStay"); // Only 1 Hotel // FOR THE RECORD // I AM ONLY GUESSING AT THE TRUE FORMAT AND FUNCTIONALITY // I HAVE NO SPEC AND NO DETAILED CONTACT POINT WHO CAN GUIDE ME // SO.....THESE ARE NOT BUGS BUT FEATURES.. :) var theRoomStayNode = theRoomStaysNode.getElementsByTagName('RoomStay')[0]; var theRoomRatesNode = theRoomStayNode.getElementsByTagName('RoomRates')[0]; var theRoomRateNodes = theRoomStaysNode.getElementsByTagName('RoomRate'); var thePriceCount = 0; for (theRoomRateIt = 0; theRoomRateIt < theRoomRateNodes.length;theRoomRateIt++){ var theRateNode = theRoomRateNodes[theRoomRateIt].getElementsByTagName('Rate')[0]; //var theCalendarObj = new CalendarView(); // STUPID STUPID Date conventions for the Date object // Have to replace - with / so it works in IE // This is by NO MEANS international proof // I took the ISO standard date format yyyy-mm-dd to yyyy/mm/dd theStartDate = Date.parse(theRateNode.getAttribute("EffectiveDate").replace(/-/g, "/")); theEndDate = Date.parse(theRateNode.getAttribute("ExpireDate").replace(/-/g, "/")); //if(theRoomRateIt == 1){ //alert("Effective date : " + theRateNode.getAttribute("EffectiveDate")); //alert("Expire date : " + theRateNode.getAttribute("ExpireDate")); //alert("Comparing : " + theStartDate + " " + theEndDate );} for(a = 0; a < this.calendarViewListObj.calendarViewList.length;a++){ var theCalendarViewObj = this.calendarViewListObj.calendarViewList[a]; //alert("Comparing : " + theStartDate + " to " + theCalendarViewObj.startDate + " - " + theEndDate + " to " + theCalendarViewObj.endDate); if(theStartDate == theCalendarViewObj.startDate && theEndDate == theCalendarViewObj.endDate){ //alert("Setting price for " + theStartDate + " to " + theCalendarViewObj.startDate + " - " + theEndDate + " to " + theCalendarViewObj.endDate); theCalendarViewObj.price = theRoomRateNodes[theRoomRateIt].getElementsByTagName('Total')[0].getAttribute("AmountBeforeTax"); thePriceCount++; } } //theHotelDetails.calendarViewMap.push(theCalendarObj); }//for (theRoomRateIt = 0; t //alert("# of prices set = " + thePriceCount); // Get Basic PropertyInfo // this can be re-used //alert("processCalendarViewRS(iXml) : PropertyInfo"); var theBasicPropertyInfoNode = theRoomStayNode.getElementsByTagName('BasicPropertyInfo')[0]; // HotelName //alert("processCalendarViewRS(iXml) : HotelName"); this.hotelName = theBasicPropertyInfoNode.getAttribute("HotelName"); // HotelAddress //alert("processCalendarViewRS(iXml) : Address"); this.hotelAddress = theBasicPropertyInfoNode.getElementsByTagName('AddressLine')[0].childNodes[0].nodeValue; // Hotel Images //alert("processCalendarViewRS(iXml) :Urls"); this.urlMap = theBasicPropertyInfoNode.getElementsByTagName('URL'); //alert("This is the hotel description --> "); if(theBasicPropertyInfoNode.getElementsByTagName('Text')[0]){ this.hotelDescription = theBasicPropertyInfoNode.getElementsByTagName('Text')[0].childNodes[0].nodeValue; } //alert("hotel description: " + this.hotelDescription); if(theBasicPropertyInfoNode.getElementsByTagName('HotelAmenity')){ var theAmenityNodes = theBasicPropertyInfoNode.getElementsByTagName('HotelAmenity'); for(i=0;i < theAmenityNodes.length;i++){ var theAmenityObj = new AmenityMapping(); theAmenityObj.code = theAmenityNodes[i].getAttribute("Code"); this.amenitiesMap.push(theAmenityObj); } // alert("Amenity Map size : " + this.amenitiesMap.length); } if(theBasicPropertyInfoNode.getElementsByTagName('Award')){ this.awardsMap = theBasicPropertyInfoNode.getElementsByTagName('Award'); } //alert("Outputting hotel details"); } HotelDetailedInfo.prototype.outputHotelDetails = function () { //alert("Outputting hotel details ("+ this.hotelDescription + " to the approrpriate div"); var hotelDetailedInfoDiv = document.getElementById('hotelDetailedInfo'); if(hotelDetailedInfoDiv){ while(hotelDetailedInfoDiv.lastChild)hotelDetailedInfoDiv.removeChild(hotelDetailedInfoDiv.lastChild); // Add Thumb var newdiv = document.createElement('div'); var divIdName = 'hotelThumb'; newdiv.setAttribute('id',divIdName); var divClassName = 'hotelThumbImage'; newdiv.setAttribute('class',divClassName); for (i=0;i < this.urlMap.length && i < 1;i++){ newdiv.innerHTML += ""; } hotelDetailedInfoDiv.appendChild(newdiv); // Add hotel Name var newdiv = document.createElement('div'); var divIdName = 'hotelName'; newdiv.setAttribute('id',divIdName); newdiv.innerHTML = "

"+this.hotelName+"

"; hotelDetailedInfoDiv.appendChild(newdiv); // Add hotel address var newdiv = document.createElement('div'); var divIdName = 'hotelAddress'; newdiv.setAttribute('id',divIdName); newdiv.innerHTML = "

"+this.hotelAddress+"

"; hotelDetailedInfoDiv.appendChild(newdiv); // Add calendar view var newdiv = document.createElement('div'); var divIdName = 'calendarView'; newdiv.setAttribute('id',divIdName); newdiv.setAttribute('class',divIdName); newdiv.innerHTML = "

Calendar Price View

"; newdiv.innerHTML += this.outputCalendarView(); hotelDetailedInfoDiv.appendChild(newdiv); if(this.urlMap.length > 0){ // Add hotel images var newdiv = document.createElement('div'); var divIdName = 'hotelImages'; newdiv.setAttribute('id',divIdName); //var divClassName = 'hotelThumbImage'; //newdiv.setAttribute('class',divClassName); newdiv.innerHTML = "

Hotel Images

"; var newdivImgHolder = document.createElement('div'); var divIdNameImgHolder = 'hotelImageThumbHolder'; newdivImgHolder.setAttribute('id',divIdNameImgHolder); newdivImgHolder.innerHTML += ""; newdiv.appendChild(newdivImgHolder); var theImgArray = new Array(); for (i=0;i < this.urlMap.length;i++){ //newdiv.innerHTML += ""; var theImgLink = this.urlMap[i].childNodes[0].nodeValue; var theSubStr = theImgLink.substr(0, theImgLink.length - 5); //alert("This is the substr : " + theSubStr); if(!theImgArray[theSubStr]){ //alert("Adding the substr : " + theSubStr); theImgArray[theSubStr] = theImgLink; } //newdiv.innerHTML += ""; //newdiv.innerHTML += "The Image"; //newdiv.innerHTML += ""; } for(key in theImgArray){ newdiv.innerHTML += " "; } //newdiv.innerHTML += ""; hotelDetailedInfoDiv.appendChild(newdiv); } if(this.hotelDescription) { // Add hotel description var newdiv = document.createElement('div'); var divIdName = 'hotelDescription'; newdiv.setAttribute('id',divIdName); newdiv.innerHTML = "

Hotel Description

" + this.hotelDescription; hotelDetailedInfoDiv.appendChild(newdiv); } if(this.amenitiesMap.length > 0){ // Add hotel amenities var newdiv = document.createElement('div'); var divIdName = 'hotelAmenities'; newdiv.setAttribute('id',divIdName); newdiv.innerHTML = "

Hotel Amenities

"; newdiv.innerHTML += ""; } if(this.awardsMap.length > 0){ // Add hotel awards var newdiv = document.createElement('div'); var divIdName = 'hotelAwards'; newdiv.setAttribute('id',divIdName); newdiv.innerHTML = "

Hotel Awards

"; newdiv.innerHTML += ""; hotelDetailedInfoDiv.appendChild(newdiv); } } } HotelDetailedInfo.prototype.outputCalendarView = function() { var theOutputHtml = "+/- "+ this.calendarViewListObj.plusMinusDays +" days"; theOutputHtml += ""; //theOutputHtml += ""; // Loop through calendar view map theOutputHtml += ""; /*for (i = 0; i < this.calendarViewListObj.startDateLength; i++){ theOutputHtml += 1000 * 60 * 60 * 24; }*/ //alert ("Starting matrix...."); var theDateMs = this.calendarViewListObj.minEndDate; do { //alert("Looping on matrix with date : " + theDateMs); var theDateObj = new Date(); theDateObj.setTime(theDateMs); var theDateStr = formatDate(theDateObj, "dd-MM-yy"); theOutputHtml += ""; theDateMs += 1000 * 60 * 60 * 24; } while(theDateMs <= this.calendarViewListObj.maxEndDate); theOutputHtml += ""; // var theDateMs = this.calendarViewListObj.minStartDate; // do { var theDateMs = this.calendarViewListObj.minStartDate; var totalArray = 0; for(i=0;i"; theDateMs += 1000 * 60 * 60 * 24; for(j = 0;j" + thePrice + ""; totalArray++; } theOutputHtml += ""; }//while(theDateMs <= this.calendarViewListObj.maxStartDate); theOutputHtml += "
Calendar View
" + theDateStr + "
" //alert ("Calendar view has " + this.calendarViewMap.length + " elements"); return theOutputHtml; //return '
Calendar View
AverageRed
Males1.90.00340%
Females1.70.00243%
'; }