var lastBounds = null;
var suggestedToFinishPolygon = false;
var windowSuggestedToFinishPolygon = null;
var GRID_X_SIZE = 12;
var GRID_Y_SIZE = 12;
function removeQueryParameter(url, name) {
var idx = url.indexOf('?' + name + '=');
if (idx == -1) {
idx = url.indexOf('&' + name + '=');
}
if (idx == -1) {
return url; // not found
}
var idx1 = url.indexOf('&', idx + 1);
var idx2 = url.indexOf('#', idx + 1);
if (idx2 != -1 && (idx1 == -1 || idx2 < idx1)) {
return url.substring(0, idx) + url.substring(idx2);
}
if (idx1 == -1) {
return url.substring(0, idx);
} else {
return url.substring(0, idx + 1) + url.substring(idx1 + 1);
}
}
function trim(text){
text = text.replace(/^\s+/, "");
text = text.replace(/\s+$/, "");
text = text.replace(/\s+/g, " ");
return text;
}
function checkMouse() {
if (document.activeMarker != null && document.activeBubble != null && !document.activeMarker.mouseOver && !document.activeBubble.mouseOver) {
document.activeMarker = null;
document.activeBubble.hide();
document.activeBubble = null;
if (document.markerOverMouse != null) {
showBubble(document.map,
document.markerOverMouse,
document.markerOverMouse.anchorLatLng,
listingArray[document.markerOverMouse.markerId]);
}
}
document.activeBubbleTimeout = null;
}
function activateBubble(markerId) {
var map = document.map;
var marker = markerArray[markerId];
if (marker == null) {
return;
}
document.markerOverMouse = marker;
if (document.activeBubble == null && map.getInfoWindow().isHidden()) {
showBubble(map, marker, marker.anchorLatLng, listingArray[markerId]);
}
}
function deactivateBubble(markerId) {
var marker = markerArray[markerId];
if (marker == null) {
return;
}
var map = document.map;
marker.mouseOver = false;
document.markerOverMouse = null;
if (document.activeMarker != null && document.activeBubble != null && !document.activeMarker.mouseOver && !document.activeBubble.mouseOver) {
if (document.activeBubbleTimeout != null) {
clearTimeout(document.activeBubbleTimeout);
}
document.activeBubbleTimeout = setTimeout('checkMouse()', 300);
}
}
function setCurrentLoc(uri) {
window.location.hash
uri = uri.replace(/&/g, "&");
if (startsWith(uri, "http://")) {
window.location.href = uri;
} else {
if (startsWith(uri, "/")) {
// absolute path
uri = "http://" + getHost(window.location.href) + uri;
window.location.href = uri;
} else if (!(startsWith(uri, "?") || startsWith(uri, "#"))) {
// relative path
var s = window.location.href;
if (s.indexOf('#') != -1) {
s = s.substring(0, s.indexOf('#'));
}
if (s.indexOf('?') != -1) {
s = s.substring(0, s.indexOf('?'));
}
var pos = s.lastIndexOf('/');
if (pos == -1) {
window.location.href = s + '/' + uri;
} else {
window.location.href = s.substring(0, pos + 1) + uri;
}
} else if (startsWith(uri, "?")) {
var s = window.location.href;
if (s.indexOf('?') != -1) {
s = s.substring(0, s.indexOf('?'));
}
window.location.href = s + uri;
} else {
var s = window.location.href;
if (s.indexOf('#') != -1) {
s = s.substring(0, s.indexOf('#'));
}
window.location.href = s + uri;
}
}
}
function isMaxZoomLevel() {
var map = document.map;
var zoom = map.getZoom();
return zoom >= 18;
}
function showBubble(map, marker, point, listing) {
var pixelPos = map.fromLatLngToDivPixel(point);
var centerPixelPos = map.fromLatLngToDivPixel(map.getCenter());
var diff = new GPoint(centerPixelPos.x - pixelPos.x, centerPixelPos.y - pixelPos.y);
var bubble;
var bubbleSize;
// var offset;
var neighbours = null;
// if( (typeof bubbleMultiListing != 'undefined') && bubbleMultiListing == true)
// neighbours = findMarkerNeighbours(map, marker);
if (marker.multi) {
neighbours = multiArray[marker.markerId];
}
if(neighbours ==null || neighbours.length ==1 )
bubbleSize = new GSize(360, 138);//106 //350,123
else if (neighbours.length < 10 || isMaxZoomLevel()) {
bubbleSize = new GSize(360, 146);
} else {
bubbleSize = new GSize(200, 40);
}
var pointerSize = new GSize(17,18);
var posOffset = new GPoint(0, 0);
var offset = new GPoint(15, -12);
if (isWide() && diff.x > 0) {
// punkt z lewej strony mapy, wyswietlamy chmurke po prawej stronie markera
if (diff.y > 0) {
// punkt na gorze mapy, wyswietlamy chmurke na dole markera
// left-top
bubble = new EBubble(map, "/images/maps/corner-left-top.gif", pointerSize, new GPoint(0+posOffset.x, -17+posOffset.y), bubbleSize, new GPoint(0-20+offset.x,-18+offset.y));
// offset = new GPoint(-15, 15)
} else {
// punkt na dole mapy, wyswietlamy chmurke na gorze markera
// left-bottom
bubble = new EBubble(map, "/images/maps/corner-left-bottom.gif", pointerSize, new GPoint(0+posOffset.x, bubbleSize.height-1+posOffset.y), bubbleSize, new GPoint(0-20+offset.x,bubbleSize.height+18+15+3+offset.y));
// offset = new GPoint(-20, 10)
}
} else {
// punkt z prawej strony mapy, wyswietlamy chmurke po lewej stronie markera
if (diff.y > 0) {
// right-top
bubble = new EBubble(map, "/images/maps/corner-right-top.gif", pointerSize,
new GPoint(bubbleSize.width-pointerSize.width+posOffset.x, -17+posOffset.y), bubbleSize, new GPoint(0-3+bubbleSize.width+offset.x,-18+offset.y));
// offset = new GPoint(-20, 15)
} else {
// right-bottom
bubble = new EBubble(map, "/images/maps/corner-right-bottom.gif", pointerSize,
new GPoint(bubbleSize.width-pointerSize.width+posOffset.x, bubbleSize.height-1+posOffset.y), bubbleSize,
new GPoint(0-12+bubbleSize.width+offset.x,bubbleSize.height+18+15+4+offset.y));
// offset = new GPoint(0, 10)
}
}
var html = '';
var d1 = new Date();
totalTime = 0;
if(neighbours ==null || neighbours.length ==1 ) {
var bool = true;
var sb = new StringBuffer();
getHtmlBubbleForListing(sb, listing, map, bool, null);
html = sb.toString();
} else if (neighbours.length < 10 || isMaxZoomLevel()) {
html = getHtmlBubbleForMultiListings(map, neighbours);
} else {
html = '
';
}
else{
prehtml = '
';
}
html.append(prehtml);
var detailsUrl;
if (detailsUrlPrototype == null) {
detailsUrl = getListingDetailsUrl(map, document.criteria, listing.id);
} else {
detailsUrl = detailsUrlPrototype.replace('{1}', listing.id);
}
if(listing.fullAddress != undefined){
html.append('
');
}
html.append('
');
html.append('
');
if(listing.idxListing && listing.clientId && (listing.clientId == 5048 || listing.clientId == 826893 || listing.clientId == 505743) ){
if (listing.clientId == 5048) {
html.append('

');
}
if (listing.clientId == 826893) {
html.append('

');
}
if (listing.clientId == 505743) {
html.append('

');
}
html.append('
');
}
if(listing.mls != undefined){
html.append('
MLS#: ');
html.append(listing.mls);
html.append('
');
}
if(listing.houseSize != undefined){
html.append('
House size: '
+ formatNumber(listing.houseSize) + ' ' + listing.houseSizeUnit + '
');
}
if(listing.landSize != undefined ){
html.append('
');
html.append('Lot size: ');
html.append(formatNumber(listing.landSize) + ' ' + listing.landSizeUnit + '
');
}
if(listing.beds != undefined){
html.append('
Bedrooms: '
+ ((listing.beds != undefined) ? listing.beds : '') +'
');
}
if(listing.bathsFull != undefined || listing.bathsHalf != undefined){
html.append('
Bathrooms:'
+ ((listing.bathsFull != undefined) ? (' '+listing.bathsFull + ' full') : '')
+ ((listing.bathsHalf != undefined) ? (' '+listing.bathsHalf + ' half') : '')
+'
');
}
html.append('
' + getPriceHtml(listing) + '
');
html.append('
');
html.append('
');
}
function showBubbleWithMultiListings(map, point, neighbours){
alert(showBubbleWithMultiListings);
}
function findMarkerNeighbours(map, marker){
var r = 10; //szuka 10 pixeli w gore i w dol od markera
var neighbours = new Array();
var center = map.fromLatLngToDivPixel(marker.anchorLatLng);
for(var i=0; i < markerArray.length; ++i){
var m = markerArray[i];
if(m!=null){
var pixelPos = map.fromLatLngToDivPixel(m.anchorLatLng);
if(center.x - r < pixelPos.x && pixelPos.x < center.x + r
&& center.y - r < pixelPos.y && pixelPos.y < center.y + r
/*&& m.markerId != marker.markerId*/ ){
neighbours[neighbours.length] = m;
}
}
}
return neighbours;
}
function clickedBubble(markerId) {
var marker = markerArray[markerId];
if (marker != null && marker.multi) {
var listings = multiArray[markerId];
if (listings != null && listings.length >= 10) {
// large markers when clicked zoom in
var map = document.map;
map.zoomIn(marker.anchorLatLng, true, true);
return;
}
}
var listing = listingArray[markerId];
clickedListing(listing.id);
}
function clickedListing(id) {
saveCurrentUriInHistory();
var detailsUrl = getListingDetailsUrl(document.map, document.criteria, id);
setCurrentLoc(detailsUrl);
}
function saveCurrentUriInHistory() {
var url = getHistoryUrl(false);
if (url == null || url == "") {
// nothing to save
return;
}
setCurrentLoc("#" + url);
}
function addCommas(nStr)
{
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}
function startLocationSearch() {
if (!isMapSearch) return;
cancelPolygon(false);
var elem = document.getElementById('polygon');
elem.innerHTML = '';
isMapSearch = false;
var search_option_location = document.getElementById('search_option_location');
var search_option_map = document.getElementById('search_option_map');
search_option_map.style.visibility = 'hidden';
search_option_map.style.display = 'none';
search_option_location.style.visibility = 'visible';
search_option_location.style.display = 'block';
if(document.getElementById('map_controls_expand_shrink'))
document.getElementById('map_controls_expand_shrink').src = '/personal/immobel/images/map_controls_shrink.jpg';
document.getElementById('mapInfoText').innerHTML = '';
clearCoordinates();
clearMarkers();
submitForm(document.getElementById("refine_search"));
}
function startMapSearch(saveInHistory) {
if (!isMapSearch) {
isMapSearch = true;
if (typeof mapSearchStarting == 'function') {
mapSearchStarting();
} else {
// hide and show criteria elements
var search_option_location = document.getElementById('search_option_location');
var search_option_map = document.getElementById('search_option_map');
search_option_location.style.visibility = 'hidden';
search_option_location.style.display = 'none';
search_option_map.style.visibility = 'visible';
search_option_map.style.display = 'block';
var center;
var map = document.map;
center = map.getCenter();
// todo: move to parameters
if (!isWide()) {
expandMap();
map.setCenter(center);
map.checkResize();
}
if(document.getElementById('map_controls_expand_shrink'))
document.getElementById('map_controls_expand_shrink').src = '/images/1px.gif';
}
isMapSearch = true;
clearCoordinates();
clearMarkers();
search(true, true);
if (saveInHistory) {
saveCurrentUriInHistory();
}
var elem = document.getElementById('polygon');
if (elem) {
if (polyTxt == null || polyTxt == '') {
var html = '
Draw your own search area'
+ 'Use this link to set your own area for searching';
elem.innerHTML = html;
} else {
var html = '
Draw different area';
html += '
Remove custom search area';
elem.innerHTML = html;
}
}
}
}
function emptyFunction() {}
function setSearchInfo(map, msg) {
document.getElementById('mapInfoText').innerHTML = msg;
}
function setCenterInfo(map, msg) {
document.getElementById('mapInfoText').innerHTML = msg;
}
function getXmlHttpRequest() {
try {
if (typeof ActiveXObject != "undefined")
{
return new ActiveXObject("Microsoft.XMLHTTP")
} else if (window.XMLHttpRequest) {
return new XMLHttpRequest
}
} catch(exception) {
}
return null
}
function downloadUrl(url, bounds, callback) {
var xmlHttpRequest = getXmlHttpRequest();
if (!xmlHttpRequest)return null;
if (callback) {
xmlHttpRequest.onreadystatechange = function() {
if (xmlHttpRequest.readyState == 4) {
var code = -1, body = null;
try {
code = xmlHttpRequest.status;
body = xmlHttpRequest.responseText
}
catch(exception) {
}
callback(body, code, bounds);
xmlHttpRequest.onreadystatechange = emptyFunction;
}
};
}
xmlHttpRequest.open("GET", url, true);
xmlHttpRequest.send(null);
return xmlHttpRequest;
}
function hideAllMarkers()
{
for (var i = 0; i < markerArray.length; i++) {
if (markerArray[i] != null && markerArray[i].isVisible) {
markerArray[i].setVisible(false);
}
}
document.getElementById("search_content").innerHTML = "";
document.getElementById("search_content2").innerHTML = "";
}
function getBackParameters() {
// todo: add current map location
var params = "?" + getPartAfter(window.location.href, '?');
var queryString = getPartBefore(params, '#');
var location = getPartAfter(params, '#');
queryString = removeQueryParameter(queryString, 'la');
var result = queryString + '#' + location;
return result;
}
function getListingDetailsUrlMapSearch(id) {
return getListingDetailsUrlMapSearchPrototype().replace('{1}', id);
}
function getListingDetailsUrlMapSearchPrototype() {
//var center = map.getCenter();
var params = '?' + getPartAfter(window.location.href, '#');
var query = '?' + getPartBefore(getPartAfter(window.location.href, '?'), '#');
var back = getBackParameters();
back = removeQueryParameter(back, 'shcu');
back = removeQueryParameter(back, 'la');
back = removeQueryParameter(back, 'per');
var p = encodeURIComponent(back);
var result = "listingDetails.do?la=" + document.refine_search.la.value
+ "&per=" + getFormValue(document.refine_search, 'per')
+ "&of={1}";
var value = getParameterValueOrNull(params, 'cu');
if (value != null && value != '') {
result += '&shcu=' + encodeURIComponent(value);
} else if (value == null) {
value = getParameterValueOrNullUnescaped(query, 'cu');
if (value != null) {
result += '&shcu=' + value;
}
}
result += "&back1=" + backPageName + p;
return result;
}
function startPolygon() {
var elem = document.getElementById("polygon");
var html = 'Click on the first point of your custom search area';
html += '
Cancel drawing';
elem.innerHTML = html;
var mapElem = document.getElementById("map");
mapElem.className = mapElem.className.replace("view", "edit");
hideAllMarkers();
var map = document.map;
polygon = new Array();
drawPolygonMode = true;
if (currentPolygon != null) {
map.removeOverlay(currentPolygon);
currentPolygon = null;
}
if (polygonClickHandle != null) {
GEvent.removeListener(polygonClickHandle);
polygonClickHandle = null;
}
if (polygonMoveHandle != null) {
GEvent.removeListener(polygonMoveHandle);
polygonMoveHandle = null;
}
if (polygonMouseOutHandle != null) {
GEvent.removeListener(polygonMouseOutHandle);
polygonMouseOutHandle = null;
}
polygonClickHandle = GEvent.addListener(map, "click",
function(overlay, point, point2) {
if (point == null || point == undefined) {
point = point2;
}
if(suggestedToFinishPolygon == true){
endPolygon();
map.closeInfoWindow();
windowSuggestedToFinishPolygon = null;
suggestedToFinishPolygon = false;
}
else {
// round each coordinate to 5 digits
point = new GLatLng(Math.round(point.lat() * 100000) / 100000, Math.round(point.lng() * 100000) / 100000);
polygon[polygon.length] = point;
if (polygon.length > 1) {
if (currentPolygon != null) {
removeCurrentPolygon();
}
createAndAddPolygon(map, polygon);
if (polygon.length == 2) {
var elem = document.getElementById("polygon");
var html = '
Finish drawing';
html += '
Cancel drawing';
elem.innerHTML = html;
}
} else {
var elem = document.getElementById("polygon");
var html = 'Click on the second point of your custom search area';
html += '
Cancel drawing';
elem.innerHTML = html;
}
}
}
);
polygonMouseOutHandle = GEvent.addListener(map, "mouseout",
function() {
if (polygon.length > 1) {
if (currentPolygon != null) {
removeCurrentPolygon();
}
createAndAddPolygon(map, polygon);
}
}
);
function checkIsSuggestedToFinishPolygon(currentPoint){
if (polygon.length < 3)
return false;
var r = 30;
var currentPointCord = map.fromLatLngToDivPixel(currentPoint);
var startPolygonPoint = map.fromLatLngToDivPixel(polygon[0]);
if(Math.abs(startPolygonPoint.x - currentPointCord.x) < r
&& Math.abs(startPolygonPoint.y - currentPointCord.y) < r)
return true;
else
return false;
}
// todo: handle mouseout and mouseover
polygonMoveHandle = GEvent.addListener(map, "mousemove", function(point) {
if (polygon.length > 0) {
suggestedToFinishPolygon = checkIsSuggestedToFinishPolygon(point);
if(suggestedToFinishPolygon == true){
if(windowSuggestedToFinishPolygon != null ){
// windowSuggestedToFinishPolygon.show();
}
else{
var myHtml = '
'+'Click to finish drawing'+'';//"Click to finish drawing";
map.openInfoWindow(polygon[0], myHtml);
windowSuggestedToFinishPolygon = map.getInfoWindow();
}
}
else {
map.closeInfoWindow();
windowSuggestedToFinishPolygon = null;
//if(windowSuggestedToFinishPolygon != null){
// windowSuggestedToFinishPolygon.hide();
//}
}
if (currentPolygon != null) {
removeCurrentPolygon();
}
var p = polygon.concat(point);
createAndAddPolygon(map, p);
}
}
);
}
function cancelPolygon(searchWhenDone) {
var elem = document.getElementById("polygon");
var html = '
Draw your own search area';
elem.innerHTML = html;
var map = document.map;
drawPolygonMode = false;
if (polygonClickHandle != null) {
GEvent.removeListener(polygonClickHandle);
polygonClickHandle = null;
}
if (polygonMoveHandle != null) {
GEvent.removeListener(polygonMoveHandle);
polygonMoveHandle = null;
}
if (polygonMouseOutHandle != null) {
GEvent.removeListener(polygonMouseOutHandle);
polygonMouseOutHandle = null;
}
if (currentPolygon != null) {
map.removeOverlay(currentPolygon);
currentPolygon = null;
}
polygon = null;
polyTxt = null;
var mapElem = document.getElementById("map");
mapElem.className = mapElem.className.replace("edit", "view");
if (searchWhenDone) {
search(true, true);
}
}
function buildPolyTxt()
{
var str = "";
for (var i = 0; i < polygon.length - 1; i++) {
if (i > 0) str += ";";
str += polygon[i].lat() + ";" + polygon[i].lng();
}
polyTxt = str;
}
function buildPolygonFromText()
{
var arr = polyTxt.split(";");
polygon = new Array();
for (var i = 0; i < arr.length; i+=2) {
point = new GLatLng(arr[i]*1.0, arr[i+1]*1.0);
polygon[polygon.length] = point;
}
}
function endPolygon() {
if (!drawPolygonMode) return;
var elem = document.getElementById("polygon");
var map = document.map;
drawPolygonMode = false;
if (polygonClickHandle != null) {
GEvent.removeListener(polygonClickHandle);
polygonClickHandle = null;
}
if (polygonMoveHandle != null) {
GEvent.removeListener(polygonMoveHandle);
polygonMoveHandle = null;
}
if (polygonMouseOutHandle != null) {
GEvent.removeListener(polygonMouseOutHandle);
polygonMouseOutHandle = null;
}
if (currentPolygon != null) {
map.removeOverlay(currentPolygon);
currentPolygon = null;
}
if (polygon.length >= 3) {
// if the polygon is not properly closed - close it now
if (polygon[0].lat() != polygon[polygon.length-1].lat() || polygon[0].lng() != polygon[polygon.length-1].lng()) {
polygon[polygon.length] = new GLatLng(polygon[0].lat(), polygon[0].lng());
}
currentPolygon = new GPolygon(polygon, "#f33f00", 2, 1, "#808080", 0.2);
map.addOverlay(currentPolygon);
buildPolyTxt();
var html = '
Draw different area';
html += '
Remove custom search area';
elem.innerHTML = html;
centerAndZoomOnBounds(map, currentPolygon.getBounds());
} else {
polyTxt = null;
polygon = null;
var html = '
Draw your own search area';
elem.innerHTML = html;
}
var mapElem = document.getElementById("map");
mapElem.className = mapElem.className.replace("edit", "view");
search(true, true);
}
function setOpacity(elem, opacity) {
if(opacity<0){opacity=0;} if(opacity>100){opacity=100;}
var c=opacity/100;
//var d=document.getElementById(this.id);
if(typeof(elem.style.filter)=='string'){elem.style.filter='alpha(opacity:'+opacity+')';}
if(typeof(elem.style.KHTMLOpacity)=='string'){elem.style.KHTMLOpacity=c;}
if(typeof(elem.style.MozOpacity)=='string'){elem.style.MozOpacity=c;}
if(typeof(elem.style.opacity)=='string'){elem.style.opacity=c;}
}
function search(hideAllCurrentMarkers, forceRefresh, st) {
if (drawPolygonMode) {
// do not search while drawing polygon
return;
}
var map = document.map;
var center = map.getCenter();
var bounds = map.getBounds();
if (lastBounds != null && !forceRefresh) {
if (bounds.getSouthWest().lat() == lastBounds.getSouthWest().lat() &&
bounds.getSouthWest().lng() == lastBounds.getSouthWest().lng() &&
bounds.getNorthEast().lat() == lastBounds.getNorthEast().lat() &&
bounds.getNorthEast().lng() == lastBounds.getNorthEast().lng()) {
return;
}
}
if (activeMapRequest != null) {
// cancel last request
activeMapRequest.onreadystatechange = emptyFunction;
activeMapRequest.abort();
}
lastBounds = bounds;
if (hideAllCurrentMarkers) {
hideAllMarkers();
}
setSearchInfo(map, "
Please wait. Searching...");
try {
var queryUrl = getMapQueryUrl(bounds, st);
var timeStart = new Date();
activeMapRequest = downloadUrl(queryUrl, bounds, function(data, responseCode, requestBounds) {
var map = document.map;
// do not show markers if editing new area
if (editPolygonMode || drawPolygonMode) return;
var t1 = new Date();
var xml = GXml.parse(data);
var t2 = new Date();
var bounds = map.getBounds();
if (bounds.getSouthWest().lat() != requestBounds.getSouthWest().lat() ||
bounds.getSouthWest().lng() != requestBounds.getSouthWest().lng() ||
bounds.getNorthEast().lat() != requestBounds.getNorthEast().lat() ||
bounds.getNorthEast().lng() != requestBounds.getNorthEast().lng()) {
// not our request
return;
}
hideAllMarkers();
var t3 = new Date();
var counter = 0;
var markers = new Array();
if (xml != null && xml.documentElement != null) {
var totalCount = xml.documentElement.getAttribute("totalCount");
totalMapSearchCount = totalCount;
var returned = xml.documentElement.getAttribute("returnedCount");
markers = xml.documentElement.getElementsByTagName("marker");
listingArray = [];
var msg = "";
// todo: dictionary
if (totalCount == null || totalCount == undefined) {
msg = "
An error occured while searching. Please try again later";
} else if (totalCount == 0) {
msg = "
No listings found. Please zoom out or change your search criteria";
} else if (totalCount == 1) {
// toto: escape
msg = "
1 listing found.";
if(isWide()){
msg +=" Scroll down to see search results.
";
}
} else {
var x = "345 listings found";
x = x.replace('345', ""+totalCount);
if(isWide()){
x += ".
Scroll down to see search results.";
}
msg = "
" + x + "
";
}
setSearchInfo(map, msg);
var centerPoint = map.fromLatLngToDivPixel(new GLatLng(0, 0)); // check coordinates of point 0,0
var hash = new Object(); // map holding all markers on the screen
var x1 = 0, x2 = 0, x3 = 0, x4 = 0, x5 = 0;
for (var i = 0; i < markers.length; i++) {
var s1 = new Date();
var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var listing = new Object();
var m = markers[i];
listing.latLng = point;
listing.id = m.getAttribute("id");
listing.mls = m.getAttribute("mls");
listing.pict = m.getAttribute("pict");
listing.price = m.getAttribute("price");
listing.cu = m.getAttribute("cu");
listing.bathsHalf = m.getAttribute("bathsHalf");
listing.bathsFull = m.getAttribute("bathsFull");
listing.beds = m.getAttribute("beds");
listing.status = m.getAttribute("status");
listing.street = m.getAttribute("street");
listing.city = m.getAttribute("city");
listing.state = m.getAttribute("state");
listing.country = m.getAttribute("country");
listing.zip = m.getAttribute("zip");
listing.type = m.getAttribute("type");
listing.subType = m.getAttribute("subType");
var unit = ' sqft';
if (listing.metric != null && listing.metric != undefined && listing.metric == 'true') {
unit = ' m2';
}
listing.houseSize = listing.type != 6 ? m.getAttribute("size") : null; //only if not land
listing.houseSizeUnit = unit;
listing.landSize = (( m.getAttribute("landSize") != undefined )? Math.round(parseFloat(m.getAttribute("landSize"))) : null );
listing.landSizeUnit = unit;
listing.garage = m.getAttribute("garage");
listing.clientId = m.getAttribute("clientId");
listing.idx = (m.getAttribute("idx") == "true");//should be index/number in search results
listing.idxListing = (m.getAttribute("idx") == "true");
var fullAddress = '';
var first = true;
if (isNotEmpty(listing.street)){
first = false;fullAddress += listing.street;
}
if (isNotEmpty(listing.city)){
if(!first)fullAddress += ', ';
first = false;
fullAddress += listing.city;
}
if (isNotEmpty(listing.country) && (isNotEmpty(listing.state) || isNotEmpty(listing.zip))){
if(listing.country == 'USA'){
if(!first)fullAddress += ' ';
first = false;
if(isNotEmpty(listing.state)){
fullAddress += listing.state;
}
if(isNotEmpty(listing.zip)){
if(isNotEmpty(listing.state)){
fullAddress += ' ';
}
fullAddress += listing.zip;
}
}
else {
if(!first){
fullAddress += ', ';
first = false;
}
}
fullAddress += listing.country;
}
listing.fullAddress = fullAddress;
listingArray.push(listing);
var pt = map.fromLatLngToDivPixel(point);
var dx = Math.round((pt.x - centerPoint.x) / GRID_X_SIZE);
var dy = Math.round((pt.y - centerPoint.y) / GRID_Y_SIZE);
var obj = hash[""+dx];
if (obj == undefined) {
obj = new Object();
hash[""+dx] = obj;
}
var o = obj[""+dy];
if (o == undefined) {
o = new Object();
obj[""+dy] = o;
o.array = new Array();
}
o.array.push(i);
counter++;
}
clearMarkers();
markerArray = [];
// find large regions in map - regions that have groupped icons in two adjacent cells
mergeAdjacentRegions(hash);
for (var key in hash) {
var px = (parseInt(key) * GRID_X_SIZE) + centerPoint.x;
var obj = hash[key];
if (obj != null) {
for (var keyy in obj) {
var o = obj[keyy];
if (o != null && o.array.length > 0) {
if (o.array.length == 1) {
// just one marker in this box
var ii = o.array[0];
var label = new TLabel();
label.id = 'marker' + ii;
label.markerId = ii;
label.anchorLatLng = listingArray[ii].latLng;
label.anchorPoint = 'center';
label.content = '
';
map.addTLabel(label);
markerArray[ii] = label;
// create new marker
} else {
/* // multiple listings in the same grid location.
// Merge grids if required
if (o.merged) {
if (!o.displayed) {
// calculate center point for the marker
var center = getCellCenterPoint(o);
//var py = (parseInt(keyy) * GRID_Y_SIZE) + centerPoint.y;
//var latLng = map.fromDivPixelToLatLng(new GPoint(px, py));
//var latLng = map.fromDivPixelToLatLng(center);
addMarkerMulti(map, o.array, center);
o.displayed = true;
}
} else {
var py = (parseInt(keyy) * GRID_Y_SIZE) + centerPoint.y;
var latLng = map.fromDivPixelToLatLng(new GPoint(px, py));
addMarkerMulti(map, o.array, latLng);
}
*/
}
}
}
}
}
for (var key in hash) {
var px = (parseInt(key) * GRID_X_SIZE) + centerPoint.x;
var obj = hash[key];
if (obj != null) {
for (var keyy in obj) {
var o = obj[keyy];
if (o != null && o.array.length > 0) {
if (o.array.length == 1) {
} else {
// multiple listings in the same grid location.
// Merge grids if required
if (o.merged) {
if (!o.displayed && o.array.length < 10) {
// calculate center point for the marker
var center = getCellCenterPoint(o);
//var py = (parseInt(keyy) * GRID_Y_SIZE) + centerPoint.y;
//var latLng = map.fromDivPixelToLatLng(new GPoint(px, py));
//var latLng = map.fromDivPixelToLatLng(center);
addMarkerMulti(map, o.array, center);
o.displayed = true;
}
} else if (o.array.length < 10) {
var py = (parseInt(keyy) * GRID_Y_SIZE) + centerPoint.y;
var latLng = map.fromDivPixelToLatLng(new GPoint(px, py));
addMarkerMulti(map, o.array, latLng);
}
}
}
}
}
}
for (var key in hash) {
var px = (parseInt(key) * GRID_X_SIZE) + centerPoint.x;
var obj = hash[key];
if (obj != null) {
for (var keyy in obj) {
var o = obj[keyy];
if (o != null && o.array.length > 0) {
if (o.array.length == 1) {
// just one marker in this box
/* var ii = o.array[0];
var label = new TLabel();
label.id = 'marker' + ii;
label.markerId = ii;
label.anchorLatLng = listingArray[ii].latLng;
label.anchorPoint = 'center';
label.content = '
';
map.addTLabel(label);
markerArray[ii] = label;
*/
// create new marker
} else {
// multiple listings in the same grid location.
// Merge grids if required
if (o.merged) {
if (!o.displayed && o.array.length >= 10) {
// calculate center point for the marker
var center = getCellCenterPoint(o);
//var py = (parseInt(keyy) * GRID_Y_SIZE) + centerPoint.y;
//var latLng = map.fromDivPixelToLatLng(new GPoint(px, py));
//var latLng = map.fromDivPixelToLatLng(center);
addMarkerMulti(map, o.array, center);
o.displayed = true;
}
} else if (o.array.length >= 10) {
var py = (parseInt(keyy) * GRID_Y_SIZE) + centerPoint.y;
var latLng = map.fromDivPixelToLatLng(new GPoint(px, py));
addMarkerMulti(map, o.array, latLng);
}
}
}
}
}
}
for (var i = markers.length; i < markerArray.length; i++) {
if (markerArray[i] != null) {
markerArray[i].setVisible(false);
}
}
// }
} else {
setCenterInfo(map, "
Search error!");
}
activeMapRequest = null;
var t4 = new Date();
createDetailsPage(typeof st != 'undefined' ? st : 0);
var timeE = new Date();
});
} catch (ee) {
setCenterInfo(map, "
Error! " + ee + "");
}
}
var coordinates = new Array();
var multiArray = new Array();
// var links = new Array();
var currentPolygon = null;
var editPolygonMode = false;
var drawPolygonMode = false;
var polygon = null;
var activeMapRequest = null; // current map search request, null if none
var isMapSearch = false;
var markerArray = [];
var listingArray = [];
var totalMapSearchCount = null;
function clearCoordinates() {
coordinates = new Array();
listingArray = [];
}
function addCoordinates(idx, lat, lng, link, listing) {
if (lat != undefined && lng != undefined) {
coordinates[idx - 1] = new GLatLng(lat, lng);
} else {
coordinates[idx - 1] = undefined;
}
listingArray[idx - 1] = listing;
}
function change_sort_order(select) {
var val = select.options[select.selectedIndex].value;
if (isMapSearch) {
var historyUrl = '?' + getHistoryUrl(false); // get values from request, not form
historyUrl = replaceParameter(historyUrl, 'c_sort', val);
historyUrl = historyUrl.substring(1);
setCurrentLoc("#" + historyUrl);
search(true, true);
} else {
clearCoordinates();
clearMarkers();
var url = getCurrentQueryDirectory() + 'searchResults.do';
url += '?' + getCurrentQueryParameters();
// if((typeof correctMinprice != 'undefined') && correctMinprice == true){
// url = replaceParameter(url, 'minprice', minprice1);
// }
// if((typeof correctMaxprice != 'undefined') && correctMaxprice == true){
// url = replaceParameter(url, 'maxprice', maxprice1);
// }
var params = '?' + getPartAfter(window.location.href, '#');
var rpp = getRpp();//isWide() ? '30' : '15';
var st = 0;
var historyUrl = '?' + getHistoryUrl(false); // get values from request, not form
historyUrl = replaceParameter(historyUrl, 'st', st);
historyUrl = replaceParameter(historyUrl, 'rpp', rpp);
historyUrl = replaceParameter(historyUrl, 'c_sort', val);
historyUrl = historyUrl.substring(1);
setCurrentLoc("#" + historyUrl);
url = addParameter(url, 'rpp', rpp);
url = addParameter(url, 'st', st);
url = addParameter(url, 'mode', listingDisplayMode);
url = replaceParameter(url, 'c_sort', val);
ajaxDisplayUrl(url);
}
}
function startsWith(txt, a) {
return txt.substring(0, a.length) == a;
}
function getHost(href) {
href = href.substring(7);
var pos = href.indexOf('/');
if (pos == -1) return href;
return href.substring(0, pos);
}
function getListingDetailsUrl(map, criteria, id) {
return getListingDetailsUrlMapSearch(id);
}
/***********************************************
* Dynamic Ajax Content- � Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
var bustcachevar = 0 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects = ""
var rootdomain = "http://" + window.location.hostname
var bustcacheparameter = ""
function ajaxpage(url, containerid) {
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject) { // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e) {
try {
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e) {
}
}
}
else
return false;
page_request.onreadystatechange = function() {
loadpage( page_request, containerid );
};
if (bustcachevar) //if bust caching of external page
bustcacheparameter = (url.indexOf("?") != -1) ? "&" + new Date().getTime() : "?" + new Date().getTime();
page_request.open('GET', url + bustcacheparameter, true);
page_request.send(null);
}
function loadpage(page_request, containerid) {
if (page_request.readyState == 4 && (page_request.status == 200 || window.location.href.indexOf("http") == -1)) {
hideAjaxLoading();
//var postProcessAjax = null;
var content = null;
eval(page_request.responseText);
document.getElementById(containerid).innerHTML = content;
if (typeof postProcessAjax != 'undefined' && postProcessAjax != null) {
postProcessAjax();
}
reInitialize();
}
}
function reInitialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
document.map = map;
if(document.getElementById('map_controls_cardinal') == null){
map.addControl(new GLargeMapControl());
map.enableScrollWheelZoom();
}
GEvent.addListener(map, "zoomend", function() {
if (isMapSearch) {
search(true, false);
showCurrentZoom();
} else {
repositionMarkers(map);
showCurrentZoom();
}
});
GEvent.addListener(map, "zooming", function() {
if (isMapSearch) {
hideAllMarkers();
showCurrentZoom();
} else {
repositionMarkers(map);
showCurrentZoom();
}
});
GEvent.addListener(map, "moveend", function() {
if (isMapSearch) {
search(false, false);
}
});
var bounds;
for (var i = 0; i < coordinates.length; i++) {
if (coordinates[i] != undefined) {
if (bounds == undefined) {
bounds = new GLatLngBounds(coordinates[i], coordinates[i]);
} else {
bounds.extend(coordinates[i]);
}
}
}
if (bounds == undefined) {
if(isWide())
map.setCenter(new GLatLng(34.0,-20.0), 2);
else
map.setCenter(new GLatLng(18.0,-35.0), 1);
} else {
var center = bounds.getCenter();
var zoomLevel = map.getBoundsZoomLevel(bounds);
if (typeof maxZoomLevel != 'undefined') {
if (zoomLevel > maxZoomLevel) {
zoomLevel = maxZoomLevel;
}
}
map.setCenter(center, zoomLevel);
}
showCurrentZoom();
addGrouppedMarkers();
}
}
function addGrouppedMarkers()
{
// check all markers and see if they qualify for groupping
var map = document.map;
// check center point of the map
var point = map.fromLatLngToDivPixel(new GLatLng(0, 0)); // check coordinates of point 0,0
var hash = new Object(); // map holding all markers on the screen
for (var i = 0; i < coordinates.length; i++) {
if (coordinates[i] != undefined) {
var p = map.fromLatLngToDivPixel(coordinates[i]);
var dx = Math.round((p.x - point.x) / GRID_X_SIZE);
var dy = Math.round((p.y - point.y) / GRID_Y_SIZE);
var obj = hash[""+dx];
if (obj == undefined) {
obj = new Object();
hash[""+dx] = obj;
}
var o = obj[""+dy];
if (o == undefined) {
o = new Array();
obj[""+dy] = o;
}
// var coordinate = new Object();
// coordinate.latLng = coordinates[i];
// coordinate.i = i;
// coordinate.idx = listingArray[i].idx;
var ii = i;
o.push(ii);
}
}
for (var key in hash) {
var px = (parseInt(key) * GRID_X_SIZE) + point.x;
var obj = hash[key];
if (obj != null) {
for (var keyy in obj) {
var o = obj[keyy];
if (o != null && o.length > 0) {
if (o.length == 1) {
// just one marker in this box
var ii = o[0];
addMarker(map, coordinates[ii], ii, ii);
} else {
var py = (parseInt(keyy) * GRID_Y_SIZE) + point.y;
var latLng = map.fromDivPixelToLatLng(new GPoint(px, py));
addMarkerMulti(map, o, latLng);
// var pxx = px - GRID_X_SIZE;
// var latLng = map.fromDivPixelToLatLng(new GPoint(pxx, py));
}
}
}
}
}
}
function loadobjs() {
if (!document.getElementById)
return
for (i = 0; i < arguments.length; i++) {
var file = arguments[i]
var fileref = ""
if (loadedobjects.indexOf(file) == -1) { //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js") != -1) { //If object is a js file
fileref = document.createElement('script')
fileref.setAttribute("type", "text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css") != -1) { //If object is a css file
fileref = document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref != "") {
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects += file + " " //Remember this object as being already added to page
}
}
}
function initialize(make_wide) {
if (GBrowserIsCompatible()) {
if (make_wide != null && make_wide) {
expandMap();
document.getElementById('map_controls_expand_shrink').src = '/personal/immobel/images/map_controls_shrink.jpg';
}
var map = new GMap2(document.getElementById("map"));
document.map = map;
if(document.getElementById('map_controls_cardinal') == null){
map.addControl(new GLargeMapControl());
map.enableScrollWheelZoom();
}
GEvent.addListener(map, "zoomend", function() {
if (isMapSearch) {
search(true, false);
showCurrentZoom();
} else {
repositionMarkers(map);
showCurrentZoom();
}
});
GEvent.addListener(map, "zooming", function() {
if (isMapSearch) {
hideAllMarkers();
showCurrentZoom();
} else {
repositionMarkers(map);
showCurrentZoom();
}
});
GEvent.addListener(map, "moveend", function() {
if (isMapSearch) {
search(false, false);
}
});
var bounds;
for (var i = 0; i < coordinates.length; i++) {
if (coordinates[i] != undefined) {
if (bounds == undefined) {
bounds = new GLatLngBounds(coordinates[i], coordinates[i]);
} else {
bounds.extend(coordinates[i]);
}
}
}
if (bounds == undefined) {
if(isWide())
map.setCenter(new GLatLng(34.0,-20.0), 2);
else
map.setCenter(new GLatLng(18.0,-35.0), 1);
} else {
var center = bounds.getCenter();
map.setCenter(center, map.getBoundsZoomLevel(bounds));
}
showCurrentZoom();
addGrouppedMarkers();
}
}
function initial_search(have_results, is_wide) {
initialize(is_wide); // this will initialize map
//var url = getPartBefore(window.location.href, '#');
var params = '?' + getPartAfter(window.location.href, '#');
var array = formFieldArray; //.concat(new Array("c_surface_mu", "c_lsurface_mu"));//"size_unit", "lot_size_unit"));
for (var i = 0; i < array.length; i++) {
var name = array[i];
var value = getParameterValueOrNull(params, name);
if (value != null) {
if (name != 'per') {
setFormValue(document.refine_search, name, value);
}
if (name == 'c_location' && document.location_combo) {
var z = document.location_combo;
z.setComboText(value);
z.setComboValue(value);
}
}
}
if (getIPropType) {
getIPropType();
}
var array = mlsNumberFieldArray;
for (var i = 0; i < array.length; i++) {
var name = array[i];
var value = getParameterValueOrNull(params, name);
if (value != null) {
setFormValue(document.refine_search, name, value);
}
}
if (typeof correctPrices == 'function') {
correctPrices();
}
if (getParameterValue(params, 'lat') != '' &&
getParameterValue(params, 'lng') != '' &&
getParameterValue(params, 'zm') != ''
) {
// map search mode
var map = document.map;
var center = new GLatLng(getParameterValue(params, 'lat'), getParameterValue(params, 'lng'));
var zoom = getParameterValue(params, 'zm') * 1;
if (getParameterValue(params,'poly') != '') {
polyTxt = getParameterValue(params,'poly');
var elem = document.getElementById("polygon");
var map = document.map;
buildPolygonFromText();
if (polygon[0].lat() != polygon[polygon.length-1].lat() || polygon[0].lng() != polygon[polygon.length-1].lng()) {
polygon[polygon.length] = new GLatLng(polygon[0].lat(), polygon[0].lng());
}
currentPolygon = new GPolygon(polygon, "#f33f00", 2, 1, "#808080", 0.2);
map.addOverlay(currentPolygon);
centerAndZoomOnBounds(map, currentPolygon.getBounds());
} else {
map.setCenter(center, zoom);
}
startMapSearch(false);
} else {
if (have_results != null && have_results && getPartAfter(window.location.href, '#').length == 0) {
if (is_wide != null && is_wide) {
//alert('expanding map');
}
return;
}
var wide = false;
if (getParameterValue(params, "rpp") == '30') {
wide = true;
// wide display
expandMap();
document.getElementById('map_controls_expand_shrink').src = '/personal/immobel/images/map_controls_shrink.jpg';
}
var url = getCurrentQueryDirectory() + 'searchResults.do';
// var url = getPartBefore(window.location.href, '?').replace('refineSearch.jsp', 'searchResults.do');
url += '?' + getFormParameters(document.refine_search);
// if((typeof correctMinprice != 'undefined') && correctMinprice == true){
// url = replaceParameter(url, 'minprice', minprice1);
// }
// if((typeof correctMaxprice != 'undefined') && correctMaxprice == true){
// url = replaceParameter(url, 'maxprice', maxprice1);
// }
if (!(document.refine_search.c_mls && trim(document.refine_search.c_mls.value).length > 0)) {
var st = getParameterValue(params, "st");
var sort = getParameterValue(params, "c_sort");
if (sort == null || sort.length == 0) {
sort = "li_sort_priced";
}
url = addParameter(url, 'st', st);
url = addParameter(url, 'c_sort', sort);
}
url = addParameter(url, 'mode', listingDisplayMode);
var rpp = getRpp();//wide ? '30' : '15';
url = addParameter(url, 'rpp', rpp);
ajaxDisplayUrl(url);
}
}
function toggleMapSize() {
if (isMapSearch) return; // do not allow map size change in map search mode
var center;
if (document.map) {
center = document.map.getCenter();
}
var params = '?' + getPartAfter(window.location.href, '#');
var url = getCurrentQueryDirectory() + 'searchResults.do';
// var url = getPartBefore(window.location.href, '?').replace('refineSearch.jsp', 'searchResults.do');
url += '?' + getCurrentQueryParameters(document.refine_search);
var st = getParameterValue(params, "st");
if (st == undefined || st == "") {
st = 0;
}
if (st == 0) {
st = 1;
}
if (isWide()) {
// shrinking map
st = (st - 1) * 2 + 1;
rpp = 15;
} else {
st = Math.round((st - 1) / 2 + 1);
rpp = 30;
}
// if((typeof correctMinprice != 'undefined') && correctMinprice == true){
// url = replaceParameter(url, 'minprice', minprice1);
// }
// if((typeof correctMaxprice != 'undefined') && correctMaxprice == true){
// url = replaceParameter(url, 'maxprice', maxprice1);
// }
url = addParameter(url, 'st', st);
url = addParameter(url, 'rpp', rpp);
url = addParameter(url, 'mode', listingDisplayMode);
var sort = getParameterValue(params, 'c_sort');
if (sort == null || sort.length == 0) {
sort = "li_sort_priced";
}
url = addParameter(url, 'c_sort', sort);
var historyUrl = '?' + getHistoryUrl(false); // get values from request, not form
historyUrl = replaceParameter(historyUrl, 'st', st);
historyUrl = replaceParameter(historyUrl, 'rpp', rpp);
historyUrl = replaceParameter(historyUrl, 'c_sort', sort);
historyUrl = historyUrl.substring(1);
// setCurrentLoc("#" + historyUrl);
if (isWide()) {
// shrinking map
//Reset map
shrinkMap();
document.getElementById('map_controls_expand_shrink').src = '/personal/immobel/images/map_controls_expand.jpg';
} else {
// expanding map
//Move search results down
expandMap();
if(document.getElementById('map_controls_expand_shrink'))
document.getElementById('map_controls_expand_shrink').src = '/personal/immobel/images/map_controls_shrink.jpg';
}
if (document.map) {
document.map.checkResize();
document.map.setCenter(center);
repositionMarkers(document.map);
}
clearCoordinates();
clearMarkers();
ajaxDisplayUrl(url);
}
function clearMarkers() {
try {
var map = document.map;
for (var i = 0; i < markerArray.length; i++) {
if (markerArray[i] != null) {
try {
map.removeTLabel(markerArray[i]);
} catch (e) {
}
markerArray[i] = null;
}
}
markerArray = [];
} catch (e) {
}
}
function switchToPage(pageNo) {
if (isMapSearch) {
createDetailsPage(pageNo - 1);
} else {
clearCoordinates();
clearMarkers();
var url = getCurrentQueryDirectory() + 'searchResults.do';
url += '?' + getCurrentQueryParameters();
var params = '?' + getPartAfter(window.location.href, '#');
var rpp = getRpp();//isWide() ? '30' : '15';
var sort = getParameterValue(params, 'c_sort');
var st = pageNo;
url = addParameter(url, 'rpp', rpp);
url = addParameter(url, 'st', st);
if (sort == null || sort.length == 0) {
sort = "li_sort_priced";
}
url = replaceParameter(url, 'c_sort', sort);
url = addParameter(url, 'mode', listingDisplayMode);
var historyUrl = '?' + getHistoryUrl(false); // get values from request, not form
historyUrl = replaceParameter(historyUrl, 'st', st);
// historyUrl = replaceParameter(historyUrl, 'rpp', rpp);
historyUrl = historyUrl.substring(1);
setCurrentLoc("#" + historyUrl);
ajaxDisplayUrl(url);
}
}
function getRpp(){
return isWide() ? '30' : '15';
}
function ajaxDisplayUrl(url) {
showAjaxLoading();
if (isWide()) {
document.getElementById("search_content").innerHTML = "";
document.getElementById("search_content2").innerHTML = "";
ajaxpage(url, "search_content2");
} else {
document.getElementById("search_content2").innerHTML = "";
document.getElementById("search_content").innerHTML = "";
ajaxpage(url, "search_content");
}
}
function getParameterValue(url, name) {
var res = getParameterValueOrNull(url, name);
if (res == null) res = "";
return res;
}
function getParameterValueOrNull(url, name) {
var idx = url.indexOf('?' + name + '=');
if (idx == -1) {
idx = url.indexOf('&' + name + '=');
}
if (idx == -1) {
return null;
}
var idx1 = url.indexOf('&', idx + 1);
if (idx1 == -1) {
return decodeURIComponent(url.substring(idx + name.length + 2));
} else {
return decodeURIComponent(url.substring(idx + name.length + 2, idx1));
}
}
function getParameterValueOrNullUnescaped(url, name) {
var idx = url.indexOf('?' + name + '=');
if (idx == -1) {
idx = url.indexOf('&' + name + '=');
}
if (idx == -1) {
return null;
}
var idx1 = url.indexOf('&', idx + 1);
if (idx1 == -1) {
return url.substring(idx + name.length + 2);
} else {
return url.substring(idx + name.length + 2, idx1);
}
}
function addParameter(url, name, value) {
var idx = url.indexOf('?');
if (idx == -1) {
// no question mark
url += '?';
} else if (idx < url.length - 1) {
url += '&';
}
url += name + '=' + escape(value);
return url;
}
function replaceExistingParameterValue(url, pos, value) {
var idx = url.indexOf('&', pos);
if (idx == -1) {
return url.substring(0, pos) + escape(value);
} else {
return url.substring(0, pos) + escape(value) + url.substring(idx);
}
}
function getFormValue(form, param) {
for (var j = 0; j < form.elements.length; j++) {
var e = form.elements[j];
if (e.type == 'radio' && (e.name == param) ){
if(e.checked){
return e.value;
}
}
else if (param == e.name) {
var value = '';
if (e.selectedIndex && e.selectedIndex != -1) {
value = e.options[e.selectedIndex].value;
} else if (e.value) {
value = e.value;
if (e.name == 'c_location' && ((typeof locationHint != 'undefined' && value == locationHint))) {
value = '';
}
}
return value;
}
}
return '';
}
function setFormValue(form, param, value) {
doSetFormValue(form, param, value);
if (param == 'c_stype') {
doSetFormValue(form, 'tmp_c_stype_1', value);
doSetFormValue(form, 'tmp_c_stype_2', value);
}
}
function doSetFormValue(form, param, value) {
for (var j = 0; j < form.elements.length; j++) {
var e = form.elements[j];
if (param == e.name) {
if (e.selectedIndex) {
for (var i = 0; i < e.options.length; i++) {
if (e.options[i].value == value) {
e.selectedIndex = i;
break;
}
}
} else {
e.value = value;
}
}
}
}
function replaceFormParameters(url, form, params) {
for (var i = 0; i < params.length; i++) {
var param = params[i];
var found = false;
for (var j = 0; j < form.elements.length; j++) {
var e = form.elements[j];
if (param == e.name) {
var value = '';
if (e.selectedIndex) {
value = e.options[e.selectedIndex].value;
} else if (e.value) {
value = e.value;
}
url = replaceParameter(url, param, value);
found = true;
break;
}
}
if (!found) {
url = replaceParameter(url, param, '');
}
}
return url;
}
function replaceParameter(url, paramName, value) {
var idx = url.indexOf('?' + paramName + '=');
if (idx != -1) {
return replaceExistingParameterValue(url, idx + ('?' + paramName + '=').length, value);
} else {
idx = url.indexOf('&' + paramName + '=');
if (idx != -1) {
return replaceExistingParameterValue(url, idx + ('&' + paramName + '=').length, value);
} else {
return addParameter(url, paramName, value);
}
}
}
function getPartBefore(text, character) {
var idx = text.indexOf(character);
if (idx == -1) return text;
return text.substring(0, idx);
}
function getPartAfter(text, character) {
var idx = text.lastIndexOf(character);
if (idx == -1) return "";
return text.substring(idx + 1);
}
var showFirst = 1;
var polyTxt = null;
var polygonClickHandle = null;
var polygonMoveHandle = null;
var polygonMouseOutHandle = null;
function isMlsSearch(params, query) {
var value = getParameterValueOrNull(params, "c_mls");
if (value != null && value != '') {
return true;
} else if (value == null) {
value = getParameterValueOrNullUnescaped(query, name);
if (value != null && value != '') {
return true;
}
}
return false;
}
function getMapQueryUrl(bounds, st) {
var url = '?' + getCurrentQueryParameters();
// ignore location for map search
url = replaceParameter(url, 'c_location', '');
url = replaceParameter(url, 'c_country', '');
var hostName = "http://www.immobel.com"
var host = window.location.href;
var p1 = host.indexOf("//");
if (p1 != -1) {
var p2 = host.indexOf("/", p1 + 2);
if (p2 != -1) {
hostName = host.substr(0, p2);
}
}
url = hostName + "/personal/1/mapSearch.do" + url;
url = replaceParameter(url, 'per', getFormValue(document.refine_search, 'per'));//for old featured properties link parameter per is not in query
url = replaceParameter(url, 'sf', showFirst ? '1' : '0');
url = replaceParameter(url, 'rpp', '200');
if( typeof st != 'undefined'){
url = replaceParameter(url, 'st', st);
}
url = replaceParameter(url, 'op', '2');
url = replaceParameter(url, 'c_w_lat_lo', bounds.getSouthWest().lat());
url = replaceParameter(url, 'c_w_lon_lo', bounds.getSouthWest().lng());
url = replaceParameter(url, 'c_w_lat_hi', bounds.getNorthEast().lat());
url = replaceParameter(url, 'c_w_lon_hi', bounds.getNorthEast().lng());
if (polyTxt != null && polyTxt.length > 0) {
url = replaceParameter(url, 'poly', polyTxt);
} else {
url = replaceParameter(url, 'poly', '');
}
return url;
}
function trunc(v) {
var vv = Math.round(v);
if (vv > v) vv--;
return vv;
}
function createDetailsPage(num) {
var resultsPerPage = 30;
var firstResult = num * resultsPerPage;
var listings = [];
if (firstResult < listingArray.length) {
var lastResult = firstResult + resultsPerPage;
if (lastResult > listingArray.length) {
lastResult = listingArray.length;
}
listings = listingArray.slice(firstResult, lastResult);
}
var totalPages = trunc((listingArray.length + resultsPerPage - 1) / resultsPerPage);
var txt = create_results_page(firstResult + 1, listings, num + 1, totalPages, lastResult, listingArray.length);
document.getElementById("search_content2").innerHTML = txt;
}
function submitForm() {
if (isMapSearch) {
// save parameters in history
var url = getHistoryUrl(true);
setCurrentLoc("#" + url);
search(true, true);
} else {
clearCoordinates();
clearMarkers();
// parameters type, c_location, minprice, maxprice, minbedroom, minbathroom, c_rooms, minsurface, maxsurface,
// minlsurface, maxlsurface, c_yrblt_lo, c_yrblt_hi
// todo: surface unit: sqft/m2/acre/hectar
// todo: property sub-type: condo/apartment/single family house
var wide = isWide();
var url = getCurrentQueryDirectory() + 'searchResults.do';
// var url = getPartBefore(window.location.href, '?').replace('refineSearch.jsp', 'searchResults.do');
url += '?' + getFormParameters(document.refine_search);
var st = '0';
var rpp = getRpp(); //isWide() ? '30' : '15';
url = addParameter(url, 'rpp', rpp);
url = addParameter(url, 'mode', listingDisplayMode);
url = addParameter(url, 'c_sort', 'li_sort_priced');
// if((typeof correctMinprice != 'undefined') && correctMinprice == true){
// url = replaceParameter(url, 'minprice', minprice1);
// }
// if((typeof correctMaxprice != 'undefined') && correctMaxprice == true){
// url = replaceParameter(url, 'maxprice', maxprice1);
// }
// var params = '?' + getPartAfter(window.location.href, '#');
// var sort = getParameterValue(params, 'c_sort');
// var historyUrl = '?' + getHistoryUrl(true);
// historyUrl = replaceParameter(historyUrl, 'st', st);
// historyUrl = replaceParameter(historyUrl, 'rpp', rpp);
// historyUrl = replaceParameter(historyUrl, 'c_sort', sort);
// historyUrl = historyUrl.substring(1);
var historyUrl = getHistoryUrl(true);
setCurrentLoc("#" + historyUrl);
// todo: display: searching box
ajaxDisplayUrl(url);
}
}
/**
* Return current URL, but without the page part and without query parameters.
* For the following url: http://www.server.com/dir1/dir2/page.html the function returns
* http://www.server.com/dir1/dir2/ (trailing slash is included)
*/
function getCurrentQueryDirectory()
{
var url = getPartBefore(window.location.href, '?');
var pos = url.lastIndexOf('/');
if (pos == -1) return url;
return url.substring(0, pos + 1);
}
function repositionMarkers(map) {
if (isMapSearch) return;
for (var i = 0; i < markerArray.length; i++) {
if (markerArray[i] != null) {
map.removeTLabel(markerArray[i]);
markerArray[i] = null;
}
}
addGrouppedMarkers()
}
function addMarkerMulti(map, array, latLng) {
var idx = null;
for (var i = 0; i < array.length; i++) {
var ii = array[i];
if (markerArray[ii] != null) {
map.removeTLabel(markerArray[ii]);
markerArray[ii] = null;
}
if (idx == null) {
idx = ii;
}
}
if(idx != null) {
var label = new TLabel();
label.id = 'marker' + idx;
label.markerId = idx;
label.anchorLatLng = latLng;
label.anchorPoint = 'center';
label.multi = true;
if (array.length >= 10) {
cls = "listingMarkerMultiLarge";
} else {
cls = "listingMarkerMulti";
}
label.content = '
' + array.length + '
';
map.addTLabel(label);
markerArray[idx] = label;
multiArray[idx] = array;
}
}
function addMarker(map, coordinate, i, markerNum) {
if (markerArray[i] != null) {
map.removeTLabel(markerArray[i]);
markerArray[i] = null;
}
var label = new TLabel();
label.id = 'marker' + i;
label.markerId = i;
label.anchorLatLng = coordinate;
label.anchorPoint = 'center';
label.content = '
';
map.addTLabel(label);
markerArray[i] = label;
}
function getWindowHeight() {
var windowHeight = 0;
if (typeof(window.innerHeight) == 'number') {
windowHeight = window.innerHeight;
}
else {
if (document.documentElement && document.documentElement.clientHeight) {
windowHeight = document.documentElement.clientHeight;
}
else {
if (document.body && document.body.clientHeight) {
windowHeight = document.body.clientHeight;
}
}
}
return windowHeight;
}
function getWindowWidth() {
var windowWidth = 0;
if (typeof(window.innerWidth) == 'number') {
windowWidth = window.innerWidth;
}
else {
if (document.documentElement && document.documentElement.clientWidth) {
windowWidth = document.documentElement.clientWidth;
}
else {
if (document.body && document.body.clientWidth) {
windowWidth = document.body.clientWidth;
}
}
}
return windowWidth;
}
function showAjaxLoading() {
if (document.getElementById) {
var windowHeight = getWindowHeight();
var windowWidth = getWindowWidth();
var contentElement = document.getElementById('ajax_loading');
contentElement.style.display = "block";
contentElement.style.visibility = "visible";
}
}
function hideAjaxLoading() {
if (document.getElementById) {
var contentElement = document.getElementById('ajax_loading');
contentElement.style.display = "none";
contentElement.style.visibility = "hidden";
}
}
function removeCurrentPolygon()
{
currentPolygon.hide();
currentPolygon = null;
}
function createAndAddPolygon(map, polygon) {
currentPolygon = new GPolygon(polygon, "#f33f00", 2, 1, "#808080", 0.2);
map.addOverlay(currentPolygon);
var poly = currentPolygon;
GEvent.addListener(poly, "visibilitychanged", function(isVisible) {
if (!isVisible) {
map.removeOverlay(poly);
}
});
}
function editPolygon() {
if (currentPolygon == null) {
return;
}
if (drawPolygonMode) {
// todo: obsluzyc,
} else {
var opt = new Object();
opt.maxVertices = 40;
currentPolygon.enableEditing(opt);
editPolygonMode = true;
hideAllMarkers();
}
}
function endEditPolygon() {
if (!editPolygonMode) {
return;
}
if (currentPolygon == null) return;
currentPolygon.disableEditing();
var vertexCount = currentPolygon.getVertexCount();
polygon = new Array();
for (var i = 0; i < vertexCount; i++) {
polygon[i] = currentPolygon.getVertex(i);
}
if (polygon[0].lat() != polygon[polygon.length-1].lat() || polygon[0].lng() != polygon[polygon.length-1].lng()) {
polygon[polygon.length] = new GLatLng(polygon[0].lat(), polygon[0].lng());
}
buildPolyTxt();
editPolygonMode = false;
search();
}
function centerAndZoomOnBounds(map, bounds) {
// make 10% bigger so all markers show completely
//var span = new GSize((bounds.maxX - bounds.minX) * 1.05, (bounds.maxY - bounds.minY)*1.1);
//var center = new GPoint(bounds.minX + span.width / 2., bounds.minY + span.height / 2.);
var newZoom = map.getBoundsZoomLevel(bounds);
//var newZoom = map.spec.getLowestZoomLevel(center, span, map.viewSize);
map.setCenter(bounds.getCenter(), newZoom);
}
function getParamValue(params, query, name) {
var value = getParameterValueOrNull(params, name);
if (value != null) {
return value;
} else {
value = getParameterValueOrNull(query, name);
return value;
}
}
function convertSizeValue(value, unit) {
if (value == null || value.length == 0) return value;
var size = parseFloat(value);
if (isNaN(size)) {
return "";
}
if (unit == "2") {
value = value * 10.7639;
} else if (unit == "3") {
value = value * 43560;
} else if (unit == "4") {
value = value * 107639.104;
}
return "" + value;
}
/**
* Get current parameters for the query. Parameters are retrived from the location.hash value,
* if not present - then from the URL
*/
function getCurrentQueryParameters() {
var params = '?' + getPartAfter(window.location.href, '#');
var query = '?' + getPartBefore(getPartAfter(window.location.href, '?'), '#');
var array;
if (isMlsSearch(params, query)) {
array = mlsNumberFieldArray;
} else {
array = formFieldArray;
}
var result = "&la=" + document.refine_search.la.value;
for (var i=0; i
0) {
result = result.substring(1);
}
return result;
}
function getFormParameters() {
var array;
if (document.refine_search.c_mls && trim(document.refine_search.c_mls.value).length > 0) {
// search by MLS#
array = mlsNumberFieldArray;
} else {
array = formFieldArray;
}
array[array.length] = 'la'; // add language
var params = "";
for (var i=0; i < array.length; i++) {
var name = array[i];
var value = getFormValue(document.refine_search, name);
if (value != '' || name == 'per') {
/*
if (name == 'minsurface' || name == 'maxsurface' || name == 'minlsurface' || name == 'maxlsurface') {
var unit;
if (name == 'minsurface' || name == 'maxsurface') {
unit = getFormValue(document.refine_search, 'size_unit');
} else {
unit = getFormValue(document.refine_search, 'lot_size_unit');
}
value = convertSizeValue(value, unit);
}
*/
if ((name == 'minprice' || name == 'maxprice') && getFormValue(document.refine_search, 'c_price_freq') == 'annually' ) {
value = 1/12 * value ;
}
params += '&' + name + '=' + encodeURIComponent(value);
}
}
if (params.length > 0) {
params = params.substring(1);
}
return params;
}
function addParameterIfDifferent(query, name, useForm, afterHash) {
var value;
var oldValue = getParameterValue(query, name);
if (useForm) {
value = getFormValue(document.refine_search, name);
if (oldValue != value) {
return "&" + name + "=" + encodeURIComponent(value);
}
} else {
value = getParameterValueOrNull(afterHash, name);
if (value == null) {
value = getParameterValue(query, name);
if (oldValue != value) {
return "&" + name + "=" + getParameterValueOrNullUnescaped(value);
}
} else {
if (oldValue != value) {
return "&" + name + "=" + encodeURIComponent(value);
}
}
}
return "";
}
// gets uri to be saved in history after #
// this includes all parameters that are different from the ones that were passed to the current page
function getHistoryUrl(useForm) {
var array = formFieldArray;//.concat(new Array("size_unit", "lot_size_unit"));
// get just the query string without the part after #
var fullQueryUrl = getPartAfter(window.location.href, '?');
var query = '?' + getPartBefore(fullQueryUrl, '#');
var afterHash = '?' + getPartAfter(fullQueryUrl, '#');
var params = "";
for (var i=0; i < array.length; i++) {
var name = array[i];
params += addParameterIfDifferent(query, name, useForm, afterHash);
}
if (isMapSearch) {
var map = document.map;
var center = map.getCenter();
params += "&lat=" + encodeURIComponent(center.lat()) +
"&lng=" + encodeURIComponent(center.lng()) +
"&zm=" + map.getZoom();
if (polyTxt != null && polyTxt != '' ) {
params += "&poly=" + polyTxt;
}
value = getParameterValue(afterHash, "c_sort");
if (value == null || value.length == 0) {
value = 'li_sort_priced';
}
if (value != '') {
params += "&c_sort=" + value;
}
} else {
params += addParameterIfDifferent(query, "st", useForm, afterHash);
params += addParameterIfDifferent(query, "rpp", useForm, afterHash);
params += addParameterIfDifferent(query, "c_sort", useForm, afterHash);
}
if (startsWith(params, '&')) {
params = params.substring(1);
}
return params;
}
function getExchangeRateValue(currency){
if(exchangeRateArray != 'undefined' && exchangeRateArray != null){
var rate = exchangeRateArray[currency];
if(rate != 'undefined' && rate != null){
return rate;
}
}
return 1;
}
function removeFeaturedParameter(featuredType){
doSetFormValue(document.refine_search, 'featured', '');
var divId = '';
if(featuredType == '1'){
divId = 'myListingsCriterium';
}
if(featuredType == '2'){
divId = 'officeListingsCriterium';
}
var div = document.getElementById(divId);
if(div){
div.style.display = 'none';
}
var elSelect = document.getElementById("type");
if(elSelect){
removeOptionFromSelect(elSelect, "");
if(elSelect.selectedIndex == -1){
elSelect.selectedIndex = 0;
}
getIPropType();
if(typeof jQuery !== "undefined" && isMSDropDown()){
jQuery(elSelect).removeClass("initialized");
jQuery(elSelect).addClass("initialized").msDropDown({mainCSS:'dd'});
}
}
clearCoordinates();
clearMarkers();
div = document.getElementById("search_type_menu");
if(div){
div.style.display = 'block';
}
submitForm(document.refine_search);
}
function removeOptionFromSelect(elSelect, optionValue){
for (i = elSelect.length - 1; i>=0; i--) {
if (elSelect.options[i].value == optionValue) {
elSelect.remove(i);
}
}
}
function f_scrollTop() {
return f_filterResults (
window.pageYOffset ? window.pageYOffset : 0,
document.documentElement ? document.documentElement.scrollTop : 0,
document.body ? document.body.scrollTop : 0
);
}
function f_filterResults(n_win, n_docel, n_body) {
var n_result = n_win ? n_win : 0;
if (n_docel && (!n_result || (n_result > n_docel)))
n_result = n_docel;
return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
/**
* check if given cell can be merged. Returns true if the cell has not been visited, and has more than one listing in it
* @param xGrid
* @param x
* @param y
*/
function canMerge(xGrid, x, y) {
var yGrid = xGrid[""+x];
if (yGrid == null) return false;
var cell = yGrid[""+y];
if (cell == null || cell.visited) return false;
return cell.array.length > 1;
}
function getCell(xGrid, x, y) {
var yGrid = xGrid[""+x];
if (yGrid == null) return null;
return yGrid[""+y];
}
function getCellCenterPoint(o) {
var a = o.array;
var lat = 0, lng = 0;
for (var i = 0; i < a.length; i++) {
var ii = a[i];
var l = listingArray[ii].latLng;
lat += l.lat();
lng += l.lng();
}
return new GLatLng(lat / a.length, lng / a.length);
}
function mergeAdjacentCells(xGrid, x, y)
{
var cell = xGrid[""+x][""+y];
// assert(cell != null && !cell.visited)
// check if there is any adjacent cell with multiple items
cell.visited = true;
var stack = new Array();
// see if there is any unvisited neighbour with more than one listing in the box
if (canMerge(xGrid, x-1, y) || canMerge(xGrid, x+1, y) || canMerge(xGrid, x, y-1) ||
canMerge(xGrid, x, y+1)) {
var merged = new Object();
merged.array = new Array();
merged.merged = true;
merged.visited = true;
xGrid[""+x][""+y] = merged;
stack.push(cell);
cell.x = x;
cell.y = y;
while (stack.length > 0) {
var elem = stack.pop();
merged.array = merged.array.concat(elem.array);
// check adjacent cells
for (var i = 0; i < 4; i++) {
var xx, yy;
xx = elem.x;
yy = elem.y;
if (i == 0) {
xx--;
} else if (i == 1) {
xx++;
} else if (i == 2) {
yy--;
} else if (i == 3) {
yy++;
}
if (canMerge(xGrid, xx, yy)) {
var c = getCell(xGrid, xx, yy);
c.visited = true;
c.x = xx;
c.y = yy;
stack.push(c);
xGrid[""+xx][""+yy] = merged;
}
}
}
}
}
// find large regions in map - regions that have groupped icons in two adjacent cells
function mergeAdjacentRegions(xGrid) {
for (var keyx in xGrid) {
var x = parseInt(keyx);
var yGrid = xGrid[keyx];
if (yGrid != null) {
for (var keyy in yGrid) {
var y = parseInt(keyy);
var o = yGrid[keyy];
if (o != null) {
if (o.visited) {
continue;
}
if (o.array.length <= 1) {
o.visited = true;
} else {
// see if there are adjacent cells with multiple items
mergeAdjacentCells(xGrid, x, y);
}
}
}
}
}
}
function addBubbleWrapperHtml(htmlBubble, bubbleSize){
if(typeof jQuery == "undefined"){
return htmlBubble;
}
var e = jQuery('#map_bubble_wrapper_tmpl');
if(e.size() > 0) {
var elem = e.clone();
elem.removeAttr("id");
elem.css('height', bubbleSize.height + 'px');
elem.css('width', bubbleSize.width + 'px');
var e1 = jQuery('.map_bubble_inner', elem);
e1.html(htmlBubble);
//e1.css('height', (bubbleSize.height) + 'px');
e1.css('height', (bubbleSize.height - 24) + 'px');// 2 * 12px - margin
return jQuery(elem).html();
}
return htmlBubble;
}