if (!window.console){ console = {log: function() {}} };
// Sets the map on all markers in the array.
function setAllMap(map) {
for (var i = 0; i < markers.length; i++) {
markers[i].setMap(map);
}
}
function getURLParameter(val) {
var result = null,
tmp = [];
var items = location.search.substr(1).split("&");
for (var index = 0; index < items.length; index++) {
tmp = items[index].split("=");
if (tmp[0] === val) result = decodeURIComponent(tmp[1]);
}
return result;
}
// Removes the markers from the map, but keeps them in the array.
function clearMarkers() {
setAllMap(null);
}
//Deletes all markers in the array by removing references to them.
function deleteMarkers() {
clearMarkers();
markers = [];
}
function convertFloorLevelToLabel(floorLevel) {
switch(floorLevel)
{
case "H":
return labelManager["label.search_results.high_floor_level"];
break;
case "M":
return labelManager["label.search_results.medium_floor_level"];
break;
case "L":
return labelManager["label.search_results.low_floor_level"];
break;
default:
return "";
break;
}
}
//TODO: refactor with formatNumber
function intPriceToLabel(value, showCurrency) {
var currencyLabel = showCurrency ? "HK$" : "$";
if(labelManager["locale"] === "en_HK")
{
var inMillions = value / 1000000;
var inThousands = value / 1000;
if (inMillions > 1)
return currencyLabel + numberWithCommas(inMillions.toFixed(2)) + "M";
if (inMillions == 1)
return currencyLabel + numberWithCommas(inMillions.toFixed(0)) + "M";
else
return currencyLabel + numberWithCommas(inThousands.toFixed(2)) + "K";
}
else if (labelManager["locale"] === "zh_HK" || labelManager["locale"] === "zh_CN")
{
var inYik = value / 100000000;
var inMan = value / 10000;
if (inYik > 1)
return currencyLabel + numberWithCommas(inYik.toFixed(2)) + labelManager["label.search_results.second_unit"];
else if (inYik == 1)
return currencyLabel + numberWithCommas(inYik.toFixed(0)) + labelManager["label.search_results.second_unit"];
else
return currencyLabel + numberWithCommas(inMan.toFixed(0)) + labelManager["label.search_results.first_unit"];
}
}
function formatNumber(value, type)
{
var currencyLabel = "$";
var formattedValue = "";
var manChi = "";
if(labelManager["locale"] === "en_HK")
{
var inBillions = value / 1000000000;
var inMillions = value / 1000000;
var inThousands = value / 1000;
if (inBillions >= 1)
formattedValue = currencyLabel + numberWithCommas(inBillions.toFixed(2)) + "B";
else if (inMillions >= 100)
formattedValue = currencyLabel + numberWithCommas(inMillions.toFixed(0)) + "M";
else if (inMillions >= 10)
formattedValue = currencyLabel + numberWithCommas(inMillions.toFixed(1)) + "M";
else if (inMillions >= 1)
formattedValue = currencyLabel + numberWithCommas(inMillions.toFixed(2)) + "M";
else if (inThousands >= 100)
formattedValue = currencyLabel + numberWithCommas(inThousands.toFixed(0)) + "K";
else if (inThousands >= 10)
formattedValue = currencyLabel + numberWithCommas(inThousands.toFixed(1)) + "K";
else if (inThousands >= 1)
formattedValue = currencyLabel + numberWithCommas(inThousands.toFixed(2)) + "K";
else
formattedValue = currencyLabel + numberWithCommas(value);
}
else if (labelManager["locale"] === "zh_HK" || labelManager["locale"] === "zh_CN")
{
var inYik = value / 100000000;
var inMan = value / 10000;
var formattedValue = "";
if (inYik >= 1)
formattedValue = currencyLabel + numberWithCommas(inYik.toFixed(2)) + labelManager["label.search_results.second_unit"];
else if (inMan >= 1000)
formattedValue = currencyLabel + numberWithCommas(inMan.toFixed(0)) + labelManager["label.search_results.first_unit"];
else if (inMan >= 100)
formattedValue = currencyLabel + numberWithCommas(inMan.toFixed(0)) + labelManager["label.search_results.first_unit"];
else if (inMan >= 10)
formattedValue = currencyLabel + numberWithCommas(inMan.toFixed(1)) + labelManager["label.search_results.first_unit"];
else if (inMan >= 1)
formattedValue = currencyLabel + numberWithCommas(inMan.toFixed(2)) + labelManager["label.search_results.first_unit"];
else if (value >= 1000)
formattedValue = currencyLabel + numberWithCommas(value.toFixed(0));
else if (value >= 100)
formattedValue = currencyLabel + numberWithCommas(value.toFixed(0));
else if (value >= 10)
formattedValue = currencyLabel + numberWithCommas(value.toFixed(2));
else if (value >= 1)
formattedValue = currencyLabel + numberWithCommas(value.toFixed(2));
else
formattedValue = currencyLabel + numberWithCommas(value);
}
return formattedValue;
}
function intSearchBarValuesToLabel(min, max, type)
{
if (isNaN(min)) min = 0;
if (isNaN(max)) max = 0;
if (type === "area")
{
if(min > 0 && max > 0)
{
return numberWithCommas(min.toFixed(0))
+ labelManager["label.search_results.ft"]
+ "-"
+ numberWithCommas(max.toFixed(0))
+ labelManager["label.search_results.ft"];
}
else if (min > 0)
return numberWithCommas(min.toFixed(0)) + labelManager["label.search_bar.or_more"] + labelManager["label.search_results.ft"];
else if (max > 0)
return "0" + labelManager["label.search_results.ft"] + "-" + numberWithCommas(max.toFixed(0)) + labelManager["label.search_results.ft"];
else
return "0" + labelManager["label.search_bar.or_more"] + labelManager["label.search_results.ft"];
}
else
{
if(min > 0 && max > 0)
{
var minLabel = formatNumber(min);
var maxLabel = formatNumber(max);
return minLabel + "-" + maxLabel;
}
else if (min > 0)
{
var minLabel = formatNumber(min);
return minLabel + labelManager["label.search_bar.or_more"];
}
else if (max > 0)
{
var maxLabel = formatNumber(max);
return "$0-" + maxLabel;
}
else
{
return formatNumber(0) + labelManager["label.search_bar.or_more"];
}
}
}
function intPriceOverAreaToLabel(value) {
if(!value)
{
return "$-";
}
else
{
if(labelManager["locale"] === "en_HK")
{
var testIfOverMax = value / 100000;
var inThousands = value / 1000;
if (testIfOverMax > 1)
return "$" + numberWithCommas(inThousands.toFixed(0)) + "K";
else
return "$" + numberWithCommas(value.toFixed(0));
}
else if (labelManager["locale"] === "zh_HK" || labelManager["locale"] === "zh_CN")
{
//var inMan = value / 10000;
var testIfOverMax = value / 100000;
var inMan = value / 10000;
//if (inMan > 1)
if (testIfOverMax >= 1)
return "$" + numberWithCommas(inMan.toFixed(1)) + labelManager["label.search_results.first_unit"];
else
return "$" + numberWithCommas(value.toFixed(0));
}
}
/*
var action = window.location.hash ? window.location.hash.substr(1) : 'grid';
var return_val = "";
switch($("#wish").val())
{
case "S":
value = data.price_over_net_area;
break;
case "L":
value = data.rent_over_net_area;
break;
}
if(labelManager["locale"] === "en_HK")
{
var inThousands = value / 1000;
if (inThousands > 1)
return_val = "$" + numberWithCommas(inThousands.toFixed(0)) + "K";
else
return_val = "$" + numberWithCommas(value.toFixed(0));
}
else if (labelManager["locale"] === "zh_HK")
{
var inMan = value / 10000;
if (inMan > 1)
return_val = "$" + numberWithCommas(inMan.toFixed(2)) + "萬";
else
return_val = "$" + numberWithCommas(value.toFixed(0));
}
if (action != "list")
{
return_val = return_val + "";
}
return return_val;
*/
}
//adds comma to numbers, e.g. 12000 -> 12,000
var numberWithCommas = function(x)
{
if (x=='-')
return x;
else if (!x)
return 0;
else
{
var parts = x.toString().split(".");
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
return parts.join(".");
}
}
//Speed up calls to hasOwnProperty
var hasOwnProperty = Object.prototype.hasOwnProperty;
//TODO: isEmpty object function isn't supported for IE8
function isEmpty(obj) {
// null and undefined are "empty"
if (obj == null) return true;
// Assume if it has a length property with a non-zero value
// that that property is correct.
if (obj.length > 0) return false;
if (obj.length === 0) return true;
// Otherwise, does it have any properties of its own?
// Note that this doesn't handle
// toString and valueOf enumeration bugs in IE < 9
for (var key in obj) {
if (hasOwnProperty.call(obj, key)) return false;
}
return true;
}
function generateAreaLabel(data)
{
var areaLabel = "";
areaLabel = "(" + labelManager["label.search_results.gross"] + ")"
+ data.area.toFixed(0) + " " + labelManager["label.search_results.ft"]
+ " (" + labelManager["label.search_results.net"] + ")"
+ data.net_area.toFixed(0) + " " + labelManager["label.search_results.ft"];
return areaLabel;
}
function generateArea(value)
{
var areaLabel = "";
if(value == null || value == 0)
{
areaLabel = convertZeroToDash(value);
}
else
{
areaLabel = numberWithCommas(value);
}
return areaLabel;
}
function generatePriceLabel(data)
{
var priceLabel = "";
if (data.price > 0)
{
var stock_prev_price = parseInt(data.prev_price);
var stock_price = parseInt(data.price);
if (stock_prev_price > stock_price){
priceLabel = priceLabel + generatePrevPriceLabel(data) + " ";
}
priceLabel = priceLabel + "" + labelManager["label.search_results.sell"] + " " + intPriceToLabel(parseInt(data.price), false);
if (data.is_hos)
{
priceLabel = priceLabel + "(" + labelManager["label.search_results.nonhos_label"] + ")";
}
priceLabel = priceLabel + "";
}
return priceLabel;
}
function generatePrevPriceLabel(data)
{
var prevPriceLabel = "";
if (data.prev_price > 0)
{
prevPriceLabel = "" + intPriceToLabel(parseInt(data.prev_price), false)
/*
if (data.is_hos)
{
prevPriceLabel = prevPriceLabel + "(" + labelManager["label.search_results.nonhos_label"] + ")";
}
*/
prevPriceLabel = prevPriceLabel + "";
}
return prevPriceLabel;
}
function generateRentLabel(data)
{
var rentLabel = "";
if (data.rent > 0)
{
var stock_prev_rent_price = parseInt(data.prev_rent);
var stock_rent_price = parseInt(data.rent);
if (stock_prev_rent_price > stock_rent_price){
rentLabel = rentLabel + generatePrevRentLabel(data) + " ";
}
rentLabel = rentLabel + "" + labelManager["label.search_results.rent"] + " $" + numberWithCommas(parseInt(data.rent)) + "";
}
return rentLabel;
}
function generatePrevRentLabel(data)
{
var prevRentLabel = "";
if (data.prev_rent > 0)
{
prevRentLabel = "$" + numberWithCommas(parseInt(data.prev_rent)) + "";
}
return prevRentLabel;
}
function generatePriceHosLabel(data)
{
var priceHosLabel = "";
if (data.price_hos > 0)
{
if ($('#feature').val() == 'reduce_price_stock'){
priceHosLabel = priceHosLabel + generatePrevPriceHosLabel(data) + " ";
}
priceHosLabel = priceHosLabel + "" + labelManager["label.search_results.sell"] + " " + intPriceToLabel(parseInt(data.price_hos), false) + "(" + labelManager["label.search_results.hos_label"] + ")";
}
return priceHosLabel;
}
function generatePrevPriceHosLabel(data)
{
var prevPriceHosLabel = "";
if (data.prev_price_hos > 0)
{
prevPriceHosLabel = "" + intPriceToLabel(parseInt(data.prev_price_hos), false)
// + "(" + labelManager["label.search_results.hos_label"] + ")"
+ "";
}
return prevPriceHosLabel;
}
function generatePriceOverNetAreaLabel(data)
{
var priceOverNetArea = "";
priceOverNetArea = "(" + labelManager["label.search_results.net"] + ")" + labelManager["label.search_results.ft_price"] + " $" + numberWithCommas(data.price_over_net_area) + "";
return priceOverNetArea;
}
function generateRentOverNetAreaLabel(data)
{
var rentOverNetArea = "";
rentOverNetArea = "(" + labelManager["label.search_results.net"] + ")" + labelManager["label.search_results.ft_rent"] + " $" + numberWithCommas(data.rent_over_net_area) + "";
return rentOverNetArea;
}
function generatePriceHosOverNetAreaLabel(data)
{
var priceHosOverNetArea = "";
priceHosOverNetArea = "(" + labelManager["label.search_results.net"] + ")" + labelManager["label.search_results.ft_price"] + " $" + numberWithCommas(data.price_hos_over_net_area) + "";
return priceHosOverNetArea;
}
function generateDetailPriceLabel(data)
{
var priceLabel = "";
if (data.price > 0 || data.rent > 0)
{
switch(data.tx_type)
{
case "S":
priceLabel = generatePriceLabel(data);
break;
case "L":
priceLabel = generateRentLabel(data);
break;
case "B":
priceLabel = generatePriceLabel(data) + " " + generateRentLabel(data);
break;
}
}
if (data.price_hos > 0)
{
switch(data.tx_type)
{
case "S":
if (priceLabel.length > 0)
{
priceLabel = priceLabel + " ";
}
priceLabel = priceLabel + generatePriceHosLabel(data);
break;
}
}
return priceLabel;
}
function generateStockIcon(data)
{
var DEFAULT_LOCATION = typeof google !== 'undefined' ? new google.maps.LatLng(22.319462241096862, 114.10544500000003) : null;
var stockIcon = "";
if (data.photo_360_stock && data.photo_360_source == 'MATTERPORT') {
stockIcon = "photo-360-matterport";
return stockIcon;
}
else if ( ( !/MicroMessenger/i.test(navigator.userAgent) && DEFAULT_LOCATION != null ) && (data.video_360_stock || data.video_stock) ) {
stockIcon = "video-thumbnail";
return stockIcon;
}
else stockIcon = "normal-thumbnail";
return stockIcon;
}
function generatePriceFtPriceLabel(data)
{
var priceLabel = "";
if (data.price > 0 || data.rent > 0)
{
switch(data.tx_type)
{
case "S":
//priceLabel = generatePriceLabel(data) + " / " + generatePriceOverNetAreaLabel(data);
priceLabel = generatePriceLabel(data);
break;
case "L":
//priceLabel = generateRentLabel(data) + " / " + generateRentOverNetAreaLabel(data);
priceLabel = generateRentLabel(data);
break;
case "B":
//priceLabel = generatePriceLabel(data) + " / " + generatePriceOverNetAreaLabel(data) + "
" + generateRentLabel(data) + " / " + generateRentOverNetAreaLabel(data);
priceLabel = generatePriceLabel(data) + "
" + generateRentLabel(data);
break;
}
}
if (data.price_hos > 0)
{
switch(data.tx_type)
{
case "S":
if (priceLabel.length > 0)
{
priceLabel = priceLabel + "
";
}
//priceLabel = priceLabel + generatePriceHosLabel(data) + " / " + generatePriceHosOverNetAreaLabel(data);
priceLabel = priceLabel + generatePriceHosLabel(data);
break;
}
}
return priceLabel;
}
/*
function generateListPriceLabel(data)
{
var priceLabel = "";
if (data.price > 0 || data.rent > 0)
{
switch(data.tx_type)
{
case "S":
priceLabel = generatePriceLabel(data);
break;
case "L":
priceLabel = generateRentLabel(data);
break;
case "B":
priceLabel = generatePriceLabel(data) + "
" + generateRentLabel(data);
break;
}
}
if (data.price_hos > 0)
{
switch(data.tx_type)
{
case "S":
if (priceLabel.length > 0)
{
priceLabel = priceLabel + "
";
}
priceLabel = priceLabel + generatePriceHosLabel(data);
break;
}
}
return priceLabel;
}
/*
/*
function generatePriceFtPriceLabel(data)
{
var action = window.location.hash ? window.location.hash.substr(1) : 'grid';
var priceLabel = "";
switch(action)
{
case "list":
priceLabel = generateListPriceLabel(data);
break;
case "grid":
priceLabel = generateGridMapPriceLabel(data);
break;
case "search":
priceLabel = generateGridMapPriceLabel(data);
break;
}
return priceLabel;
}
*/
function isClusterInSameBuilding(markerArray)
{
var currBuildingId = markerArray[0].data.bldg_id;
for(var i = 0; i < markerArray.length; i++)
{
if (markerArray[i].data.bldg_id !== currBuildingId)
{
return false;
}
}
return true;
}
function generatePhoto(data, width, height)
{
var tempString = "";
if (data.outlook_wan_doc_path != null)
{
tempString = insertDOMAndWatermark(data.outlook_wan_doc_path, width, height);
}
else
{
tempString = insertDOMAndWatermark("http://resources.midland.com.hk/images/common/no_photo.gif", width, height);
}
return tempString;
}
function insertDOMAndWatermark(image, width, height)
{
if (!width) {width = 206;} //default to 180x100 if width and height not provided
if (!height) {height = 154;}
var tempString = '//wm.midland.com.hk/img_wm.php?w=' + width + '&h=' + height + '&wm=mr&crop=N&bg=ffffff&src='
+ image
+ '';
return tempString;
}
function getGoogleMapMarker(pinColor)
{
if(!pinColor) {pinColor = "FFFF00"/*"FE7569"*/;}
var pinImage = new google.maps.MarkerImage("http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|" + pinColor,
new google.maps.Size(21, 34),
new google.maps.Point(0,0),
new google.maps.Point(10, 34));
return pinImage;
}
function generateDate(date, format)
{
var d = new Date(date);
return d.toString(format);
}
function convertZeroToDash(value) {
if(value == null || value == 0)
{
value = "- ";
}
return value;
}
function convertDesc(value){
return (value ? (value.trim() === "" ? " " : value) : " ");
}
/**
* Debounce and throttle function's decorator plugin 1.0.5
*
* Copyright (c) 2009 Filatov Dmitry (alpha@zforms.ru)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
(function($) {
$.extend({
debounce : function(fn, timeout, invokeAsap, ctx) {
if(arguments.length == 3 && typeof invokeAsap != 'boolean') {
ctx = invokeAsap;
invokeAsap = false;
}
var timer;
return function() {
var args = arguments;
ctx = ctx || this;
invokeAsap && !timer && fn.apply(ctx, args);
clearTimeout(timer);
timer = setTimeout(function() {
!invokeAsap && fn.apply(ctx, args);
timer = null;
}, timeout);
};
},
throttle : function(fn, timeout, ctx) {
var timer, args, needInvoke;
return function() {
args = arguments;
needInvoke = true;
ctx = ctx || this;
if(!timer) {
(function() {
if(needInvoke) {
fn.apply(ctx, args);
needInvoke = false;
timer = setTimeout(arguments.callee, timeout);
}
else {
timer = null;
}
})();
}
};
}
});
})(jQuery);