Number.prototype.formatMoney = function(c, d, t){var n = this, c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "," : d, t = t == undefined ? "." : t, s = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0; return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : ""); };
var hotelPerPage = 30;
var dataLength = 1;
var priceFromArray = new Array('2', '2', '25', '50', '100', '200', '0');
var priceToArray = new Array('999999', '25', '50', '100', '200', '999999', '2');
var starRateArray = new Array('5', '4', '3', '2');
var priceTabArray = new Array();
var starTabArray = new Array();
var hotelArray = new Array();
var hotelFilterArray = new Array();
var hotelSortArray = new Array();
function selectSortBy(sortType) {
location.href = sortType;
}
function clearVariable() {
top.page = 1;
top.alphabet = 'All';
top.price = 0;
top.star = 0;
top.area = 'All';
}
function hotelList(url) {
top.url = url;
var xmlHttp;
try {
xmlHttp=new XMLHttpRequest();
} catch (e) {
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function() {
if(xmlHttp.readyState==4) {
if (xmlHttp.status < 400) {
httext = xmlHttp.responseText;
tempArray=xmlHttp.responseText.split("\n");
top.dataLength = tempArray.length;
for (index = 0; index < top.dataLength; index++) {
top.hotelArray[index] = tempArray[index].split("\t");
}
for (index = 0; index < hotelArray[0].length; index++) {
top.hotelArray[top.dataLength - 1][index] = CRates(2, top.hotelArray[8][index], top.hotelArray[7][index], 0);
}
tabPriceFilter();
tabStarFilter();
setTimeout("hotelPage(top.sortBy)", 0);
}
}
}
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
function tabAlphabet() {
var indexAlphabet = 0;
var alphabetArray = new Array();
alphabetArray[0] = top.hotelArray[0][0].charAt(0).toUpperCase();
for (index = 1; index < top.hotelArray[0].length; index++) {
if (top.hotelArray[0][index].charAt(0).toUpperCase() != alphabetArray[indexAlphabet]) {
indexAlphabet++;
alphabetArray[indexAlphabet] = top.hotelArray[0][index].charAt(0).toUpperCase();
}
}
var displayByAlphabet = '
';
displayByAlphabet += '';
return displayByAlphabet;
}
function printStarRating(starRating) {
var text = '';
for (i = 1; i <= Math.ceil(starRating); i++) {
text += '
';
}
return text;
}
function printHead() {
var text = '';
text += '';
text += '
';
text += '
';
text += '

';
text += ' : Popular Hotel ';
text += '
';
text += '
';
text += '

';
text += ' : Special Promotion ';
text += '
';
text += '
';
text += '

';
text += ' : Instant Confirmation ';
text += '
';
text += '
';
text += '

';
text += ' : New Hotel';
text += '
';
text += '
';
text += '
';
return text;
}
function printTitle() {
var text = '';
/*text += '';
text += '
Hotel Name
';
text += '
';
text += '
Rates
';
text += '
Rating
';
text += '
';*/
return text;
}
function printTable(table, index) {
var text = '';
text += '';
text += '
';
text += '
';
text += '
';
if (eval('top.' + table + '[3][' + index + ']') == 1) {
text += '
![' + eval('top.' + table + '[0][' + index + ']') + ' is popular hotel ' + eval('top.' + table + '[0][' + index + ']') + ' is popular hotel](http://temp.passionasia.com/images/icon/icon-popular.gif)
'
} else {
text += ' ';
}
text += '
';
text += '
';
if (eval('top.' + table + '[4][' + index + ']') == 1) {
text += '

';
} else {
text += ' ';
}
text += '
';
text += '
';
if (eval('top.' + table + '[5][' + index + ']') == 1) {
text += '

';
} else {
text += ' ';
}
text += '
';
text += '
';
if (eval('top.' + table + '[6][' + index + ']') == 1) {
text += '

';
} else {
text += ' ';
}
text += '
';
text += '
';
text += '
';
if (eval('top.' + table + '[7][' + index + ']') == 1) {
text += ' ';
} else {
if(eval('top.' + table + '[8][' + index + ']') == 1){
text +=(parseFloat(eval('top.' + table + '[7][' + index + ']'))).formatMoney(0, '.', ',')+' '+eval('top.' + table + '[11][' + index + ']');
}else{
text +=(parseFloat(eval('top.' + table + '[7][' + index + ']'))).formatMoney(2, '.', ',')+' '+eval('top.' + table + '[11][' + index + ']');
}
}
text += '
';
text += '
';
text += printStarRating(eval('top.' + table + '[9][' + index + ']'));
text += '
';
text += '
';
hotel_id[Index_in_city++]=eval('top.' + table + '[10][' + index + ']');
return text;
}
function divideByAlphabet(text) {
var hotelTotal = top.hotelArray[0].length;
top.alphabet = text;
if (text != 'All') {
var hotelListArray = new Array(1);
var countIndex = 0;
for (subIndex = 0; subIndex < top.dataLength; subIndex++) {
hotelListArray[subIndex] = '';
}
for (index = 0; index < hotelTotal; index++) {
if (top.hotelArray[0][index].charAt(0).toUpperCase() == text) {
for (subIndex = 0; subIndex < top.dataLength; subIndex++) {
hotelListArray[subIndex] += top.hotelArray[subIndex][index] + '\t';
}
countIndex++;
}
}
for (subIndex = 0; subIndex < top.dataLength; subIndex++) {
top.hotelFilterArray[subIndex] = hotelListArray[subIndex].split('\t');
top.hotelFilterArray[subIndex].length = countIndex;
}
}
divideByPageNo(1);
}
function tabPageNo(itemTotal, pageTotal, itemFrom, itemTo) {
if (itemTotal == 0) {
itemFrom = 0;
itemTo = 0;
}
var displayByPageNo = '';
displayByPageNo += '';
displayByPageNo += '';
displayByPageNo += '
';
displayByPageNo += ' Found : ' + itemTotal + ' Hotels';
displayByPageNo += '
';
displayByPageNo += '
';
displayByPageNo += ' Display hotels ' + itemFrom + ' - ' + itemTo + ' of ' + itemTotal;
if (page != 1) {
displayByPageNo += ' ';
displayByPageNo += '
< Previous';
}
if (page != pageTotal && itemTotal != 0) {
displayByPageNo += ' ';
displayByPageNo += '
Next >';
}
displayByPageNo += ' ';
displayByPageNo += '
';
displayByPageNo += '
';
return displayByPageNo;
}
function divideByPageNo(page) {
top.page = page;
var table = '';
var tab = '';
var type = 0;
switch(sortBy) {
case 1 : table = (alphabet != 'All') ? 'hotelFilterArray': 'hotelArray';
tab = tabAlphabet();
type = 0;
break;
case 2 : table = 'hotelFilterArray';
tab = tabPrice();
type = 1;
break;
case 3 : table = 'hotelFilterArray';
tab = tabStar();
type = 2;
break;
case 4 : table = (area != 'All') ? 'hotelFilterArray': 'hotelArray';
tab = tabArea();
type = 0;
break;
case 5 : table = 'hotelFilterArray';
tab = tabPromotion();
type = 0;
break;
}
sortProcess(table, type);
var hotelTotal = eval('top.' + table + '[0].length');
var pageTotal = Math.ceil(hotelTotal / hotelPerPage);
var pageMod = hotelTotal % hotelPerPage;
var hotelFrom = (top.page - 1) * hotelPerPage;
var hotelTo = hotelFrom + hotelPerPage;
if (top.page == pageTotal && hotelTotal != hotelPerPage) {
hotelTo = hotelFrom + pageMod;
}
var displayHotelList = printHead() + tabPageNo(hotelTotal, pageTotal, hotelFrom + 1, hotelTo) + printTitle();
if (hotelTotal != 0) {
hotel_id=new Array(); //from template_hotel-in-city-.cfm
Index_in_city=0; //from template_hotel-in-city-.cfm
for (index = hotelFrom; index < hotelTo; index++) {
displayHotelList += printTable(table, top.hotelSortArray[type][index]);
}
}
/*var hotel_id_list="";
for (i=0;i' + displayHotelList + tabPageNo(hotelTotal, pageTotal, hotelFrom + 1, hotelTo);
ListHotel.innerHTML= '

';
hotel_id_list=hotel_id_list.substring(0,hotel_id_list.length-1);
var url='http://reservation.passionasia.com/hotel_pricefrom_new_ajax.cfm?hotel_id='+hotel_id_list+'&StartingFor='+_StartingFor+'&xHTRATESITE='+xHTRATESITE+'&page='+_page;
loadScript(url ,callback);
}else{*/
ListHotel.innerHTML=tab + '
' + displayHotelList + tabPageNo(hotelTotal, pageTotal, hotelFrom + 1, hotelTo);
//}
if (sortBy == 2) {
var objectName = deleteLastTab('price');
if (eval('document.getElementById("' + objectName + '")') != null) {
eval(objectName + '.style.display=\'none\'');
}
} else if (sortBy == 3) {
var objectName = deleteLastTab('star');
if (eval('document.getElementById("' + objectName + '")') != null) {
eval(objectName + '.style.display=\'none\'');
}
}
}
function deleteLastTab(table) {
var lastTab = 0;
for (index = 0; index < eval(table + 'TabArray.length'); index++) {
if (eval(table + 'TabArray[index]') == 1) {
lastTab = index;
}
}
return table + lastTab;
}
function tabPriceFilter() {
for (index = 0; index < priceFromArray.length; index++) {
var priceFrom = priceFromArray[index];
var priceTo = priceToArray[index];
var isFound = 0;
var subIndex = 0;
while (subIndex < top.hotelArray[0].length && isFound == 0) {
var hotelMinRate = top.hotelArray[top.dataLength - 1][subIndex];
if (hotelMinRate >= priceFrom && hotelMinRate < priceTo) {
isFound = 1;
}
subIndex++;
}
priceTabArray[index] = isFound;
}
}
function tabPrice() {
var priceTitleArray = new Array('All Prices', 'Under 25 USD', '25-50 USD', '50-100 USD', '100-200 USD', '200 USD up', 'Rates upon request');
var divideByPrice = '';
divideByPrice += '';
return divideByPrice;
}
function divideByPrice(price) {
top.price = price;
var priceFrom = priceFromArray[price];
var priceTo = priceToArray[price];
//alert(priceFrom+" "+priceTo);
var hotelTotal = top.hotelArray[0].length;
var hotelListArray = new Array();
var countIndex = 0;
for (subIndex = 0; subIndex < top.dataLength; subIndex++) {
hotelListArray[subIndex] = '';
}
for (index = 0; index < hotelTotal; index++) {
var hotelMinRate = top.hotelArray[top.dataLength - 1][index];
if (hotelMinRate >= priceFrom && hotelMinRate < priceTo) {
for (subIndex = 0; subIndex < top.dataLength; subIndex++) {
hotelListArray[subIndex] += top.hotelArray[subIndex][index] + '\t';
}
countIndex++;
}
}
for (subIndex = 0; subIndex < top.dataLength; subIndex++) {
top.hotelFilterArray[subIndex] = hotelListArray[subIndex].split('\t');
top.hotelFilterArray[subIndex].length = countIndex;
}
if (countIndex != 0) {
divideByPageNo(1);
} else {
price++;
if (price < priceFromArray.length) {
divideByPrice(price);
} else {
divideByPageNo(1);
}
}
}
function tabStarFilter() {
for (index = 0; index < starRateArray.length; index++) {
var starFrom = Math.floor(starRateArray[index]);
var starTo = starFrom + 1;
var isFound = 0;
var subIndex = 0;
while (subIndex < top.hotelArray[9].length && isFound == 0) {
var hotelStar = top.hotelArray[9][subIndex];
if (hotelStar >= starFrom && hotelStar < starTo) {
isFound = 1;
}
subIndex++;
}
starTabArray[index] = isFound;
}
}
function tabStar() {
var divideByStar = '';
divideByStar += '';
return divideByStar;
}
function divideByStar(star) {
var indexStar = 0;
var index = 0;
var isFound = 0;
while (index < starRateArray.length && isFound == 0) {
if (starRateArray[index] == star) {
indexStar = index;
isFound = 1;
}
index++;
}
star = indexStar;
top.star = star;
var starFrom = Math.floor(starRateArray[star]);
var starTo = starFrom + 1;
var hotelTotal = top.hotelArray[0].length;
var hotelListArray = new Array(1);
var countIndex = 0;
for (subIndex = 0; subIndex < top.dataLength; subIndex++) {
hotelListArray[subIndex] = '';
}
for (index = 0; index < hotelTotal; index++) {
var hotelStar = top.hotelArray[9][index];
if (hotelStar >= starFrom && hotelStar < starTo) {
for (subIndex = 0; subIndex < top.dataLength; subIndex++) {
hotelListArray[subIndex] += top.hotelArray[subIndex][index] + '\t';
}
countIndex++;
}
}
for (subIndex = 0; subIndex < top.dataLength; subIndex++) {
top.hotelFilterArray[subIndex] = hotelListArray[subIndex].split('\t');
top.hotelFilterArray[subIndex].length = countIndex;
}
if (countIndex != 0) {
divideByPageNo(1);
} else {
star++;
if (star < starRateArray.length) {
divideByStar(starRateArray[star]);
} else {
divideByPageNo(1);
}
}
}
function tabPromotion() {
var divideByPromotion = '';
//divideByPromotion += '';
//divideByPromotion += '
';
//divideByPromotion += '
';
divideByPromotion += '';
return divideByPromotion;
}
function divideByPromotion() {
var hotelTotal = top.hotelArray[0].length;
var hotelListArray = new Array(1);
var countIndex = 0;
for (subIndex = 0; subIndex < top.dataLength; subIndex++) {
hotelListArray[subIndex] = '';
}
for (index = 0; index < hotelTotal; index++) {
var hotelPromotion = top.hotelArray[4][index];
if (hotelPromotion == 1) {
for (subIndex = 0; subIndex < top.dataLength; subIndex++) {
hotelListArray[subIndex] += top.hotelArray[subIndex][index] + '\t';
}
countIndex++;
}
}
for (subIndex = 0; subIndex < top.dataLength; subIndex++) {
top.hotelFilterArray[subIndex] = hotelListArray[subIndex].split('\t');
top.hotelFilterArray[subIndex].length = countIndex;
}
divideByPageNo(1);
}
function tabArea() {
displayByArea = '';
/*
var indexArea = 0;
var areaArray = new Array(1);
var sortArray = new Array(top.hotelArray[2].length);
for (index = 0; index < top.hotelArray[2].length; index++) {
sortArray[index] = top.hotelArray[2][index];
}
sortArray.sort();
areaArray[0] = '!';
for (index = 1; index < sortArray.length; index++) {
var areaName = sortArray[index];
if (areaName != areaArray[indexArea]) {
indexArea++;
areaArray[indexArea] = areaName;
}
}
var displayByArea = '';
*/
return displayByArea;
}
function divideByArea(area) {
top.area = area;
if (area == 'Other') { area = '!'; }
var hotelTotal = top.hotelArray[2].length;
var hotelListArray = new Array(1);
var countIndex = 0;
for (subIndex = 0; subIndex < top.dataLength; subIndex++) {
hotelListArray[subIndex] = '';
}
for (index = 0; index < hotelTotal; index++) {
var hotelArea = top.hotelArray[2][index];
if (area == hotelArea) {
for (subIndex = 0; subIndex < top.dataLength; subIndex++) {
hotelListArray[subIndex] += top.hotelArray[subIndex][index] + '\t';
}
countIndex++;
}
}
for (subIndex = 0; subIndex < top.dataLength; subIndex++) {
top.hotelFilterArray[subIndex] = hotelListArray[subIndex].split('\t');
top.hotelFilterArray[subIndex].length = countIndex;
}
divideByPageNo(1);
}
function hotelPage(sortNo) {
clearVariable();
switch(sortNo) {
case 1 : top.sortBy = 1; // Sort By Name
divideByAlphabet('All');
break;
case 2 : top.sortBy = 2; // Sort By Price
//alert(byPrice);
if(byPrice > 6){byPrice = 0;}
divideByPrice(byPrice);
break;
case 3 : top.sortBy = 3; // Sort By Star Rating
divideByStar(0);
break;
case 4 : top.sortBy = 4; // Sort By Area
divideByArea('All');
break;
case 5 : top.sortBy = 5; // Sort By Promotion Only
divideByPromotion();
break;
}
}
function sortProcess(table, type) {
top.hotelSortArray[type] = new Array();
if (type == 0) {
for (index = 0; index < eval(table + '[0].length'); index++) {
top.hotelSortArray[0][index] = index + '@' + eval(table + '[0][' + index + ']');
}
} else if (type == 1) {
for (index = 0; index < eval(table + '[0].length'); index++) {
top.hotelSortArray[1][index] = index + '@' + CRates(2, eval(table + '[8][' + index + ']'), eval(table + '[7][' + index + ']'), 0);
}
} else if (type == 2) {
for (index = 0; index < eval(table + '[0].length'); index++) {
top.hotelSortArray[2][index] = index + '@' + eval(table + '[9][' + index + ']');
}
}
switch (type) {
case 0 : hotelSortArray[type].sort(sortByAlphabet); // Sort by Hotel name
break;
case 1 : hotelSortArray[type].sort(sortByNumber); // Sort by Price
break;
case 2 : hotelSortArray[type].sort(sortByNumber); // Sort by Star rating
break;
}
for (index = 0; index < hotelSortArray[type].length; index++) {
top.hotelSortArray[type][index] = top.hotelSortArray[type][index].substring(0, top.hotelSortArray[type][index].indexOf('@'));
}
}
function sortByNumber(first, second) {
first = parseFloat(first.substring(first.indexOf('@') + 1));
second = parseFloat(second.substring(second.indexOf('@') + 1));
return (first - second);
}
function sortByAlphabet(first, second) {
first += '';
second += '';
first = first.substring(first.indexOf('@') + 1);
second = second.substring(second.indexOf('@') + 1);
return first>second?1:first