//define pseudo-constant containing the root URL
//trailing slash REQUIRED.
var _BASE_URL = 'http://hgchristierentals.com/';


// **** remove Opacity-Filter in ie ****
function removeFilter(element) {
	if(element.style.removeAttribute){
		element.style.removeAttribute('filter');
	}
}

function doConfirm(url1,url2){
    var isOk = confirm("Are you sure you want to delete this")
    if(isOk){
        // They clicked "OK"
        location.href = url1
        // of if on a form..
        // return true
    }
    else{
        // They clicked "Cancel"
        
        location.href = url2
        return false
    }
}

function open_and_move2(){

win3=window.open("page.htm","","width=600,height=500")
win3.moveTo(screen.width/2-300,screen.height/2-250)
}

function mappopUp(pPage) {
	  
win3=window.open(pPage,"","scrollbars=yes,width=690,height=500,menubar=no,resizable=no,status=no,hotkeys=no")
win3.moveTo(screen.width/2-345,screen.height/2-250)

	  
	 // winmap=window.open(pPage,'','scrollbars=yes,width=690,height=500');
	 //winmap.moveTo(screen.width/2-345,screen.height/2-250)
	  }

function mpopUp(pPage) {
	   window.open(pPage,'mywin','resizable=no,scrollbars=yes,left=200,top=20,width=350,height=400');
	  }

 // window.focus('bppopup.asp')
    function bpopUp(pPage) {
	   window.open(pPage,'mybwin','resizable=no,scrollbars=yes,left=200,top=20,width=470,height=400');
	  }

    var winOpts = 'resizable=no,scrollbars=yes,left=200,top=20,width=350,height=400';
    function popUp(pPage) {
	  popUpWin = window.open(pPage,'popWin',winOpts);
	  }



    var winOptsT = 'resizable=1,scrollbars=0,left=20,top=20,width=680,height=480,alwaysRaised=1';
    function TourPopUp(pPage) {
	//alert(pPage);
	  //changed by ryan wong for popup height and width
	  //popUpWin = window.open(pPage,'mywindow','resizable=1,scrollbars=1,width=900,height=550');
	  popUpWin = window.open(pPage,'mywindow','resizable=1,scrollbars=1,width=980,height=900');
	  
	  
	  //window.focus(winOptsT)
	  setTimeout('popUpWin.focus();',250);
    }





var winOptsT = 'resizable=no,scrollbars=yes,left=20,top=20,width=620,height=500,alwaysRaised=1';
function emailPopUp(pPage) {
    popUpWin = window.open(pPage,'popEmail',winOptsT);
    //window.focus(popUpWin)
    setTimeout('popUpWin.focus();',250);
}


// Copyright 1999 - 2001 by Ray Stott, Pop-up Windows Script ver 2.0
// OK to use if this copyright is included
// Script is available at Http://www.crays.com/jsc          

var popWin = null    // use this when referring to pop-up window
var winCount = 0
var winName = "popWin"
function openPopWin(winURL, winWidth, winHeight, winFeatures, winLeft, winTop){
  var d_winLeft = 20  // default, pixels from screen left to window left
  var d_winTop = 20   // default, pixels from screen top to window top
  winName = "popWin" + winCount++ //unique name for each pop-up window
  //closePopWin()           // close any previously opened pop-up window
  if (openPopWin.arguments.length >= 4)  // any additional features? 
    winFeatures = "," + winFeatures
  else 
    winFeatures = "" 
  if (openPopWin.arguments.length == 6)  // location specified
    winFeatures += getLocation(winWidth, winHeight, winLeft, winTop)
  else
    winFeatures += getLocation(winWidth, winHeight, d_winLeft, d_winTop)
  popWin = window.open(winURL, winName, "width=" + winWidth 
           + ",height=" + winHeight + winFeatures)
  }
//function closePopWin(){    // close pop-up window if it is open 
  //if (navigator.appName != "Microsoft Internet Explorer" 
    //  || parseInt(navigator.appVersion) >=4) //do not close if early IE
    //if(popWin != null) if(!popWin.closed) popWin.close() 
 // }
function getLocation(winWidth, winHeight, winLeft, winTop){
  return ""
  }

function getLocation(winWidth, winHeight, winLeft, winTop){
  var winLocation = ""
  if (winLeft < 0)
    winLeft = screen.width - winWidth + winLeft
  if (winTop < 0)
    winTop = screen.height - winHeight + winTop
  if (winTop == "cen")
    winTop = (screen.height - winHeight)/2 - 20
  if (winLeft == "cen")
    winLeft = (screen.width - winWidth)/2
  if (winLeft>0 & winTop>0)
    winLocation =  ",screenX=" + winLeft + ",left=" + winLeft	
                + ",screenY=" + winTop + ",top=" + winTop
  else
    winLocation = ""
  return winLocation
  }

function validateValues(what) {
    var valid = true;
        
    var checkBoxes = false;
    var checkboxChecked = false;
        
    var radioButtons = false;
    var radioChecked = false;

    for (var i=0, j=what.elements.length; i<j; i++) {
        myName = what.elements[i].name;
        if (myName.indexOf('radio') > -1) {
            radioButtons = true;
            if (what.elements[i].checked) radioChecked = true;
        }
        if (myName.indexOf('checkbox') > -1) {
            checkBoxes = true;
            if (what.elements[i].checked) checkboxChecked = true;
        }
        if (myName.indexOf('hidden') > -1 || myName.indexOf('password') > -1 || myName.indexOf('text') > -1)
            if (what.elements[i].value == what.elements[i].defaultValue) valid = false;
        if (myName.indexOf('select') > -1)
            if (what.elements[i].selectedIndex == 0) valid = false;
    }

    if ((checkBoxes && !checkboxChecked) || (radioButtons && !radioChecked)) valid = false;

    if (!valid)
        alert('Form not completely filled 1');

    return valid;
}

function validateValues(what) {
    var valid = true;
        
    var checkBoxes = false;
    var checkboxChecked = false;
        
    var radioButtons = false;
    var radioChecked = false;
        
    for (var i=0, j=what.elements.length; i<j; i++) {
        myType = what.elements[i].type;
        if (myType == 'radio') {
            radioButtons = true;
           if (what.elements[i].checked) radioChecked = true;
        }
        if (myType == 'checkbox') {
            checkBoxes = true;
            if (what.elements[i].checked) checkboxChecked = true;
        }
        if (myType == 'hidden' || myType == 'password' || myType == 'text' || myType == 'textarea')
            if (what.elements[i].value == '') valid = false;
        if (myType == 'select-one' || myType == 'select-multiple')
            if (what.elements[i].selectedIndex == '') valid = false;
    }

    if ((checkBoxes && !checkboxChecked) || (radioButtons && !radioChecked)) valid = false;

    if (!valid)
        alert('Please select product option to continue!');

    return valid;
}

    function printPage() {
	  if (window.print)
		window.print()
	  else
		alert("Sorry, your browser doesn't support this feature.\n Mac Users Type Command P to print.");
	  }

/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08        **
 ** Code licensed under Creative Commons Attribution-ShareAlike License      **
 ** http://creativecommons.org/licenses/by-sa/2.0/                           **/
function XHConn()
{
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();

    try {
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          fnDone(xmlhttp);
        }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}
/*
    json2.js
    2008-02-14

    Public Domain

    No warranty expressed or implied. Use at your own risk.

    See http://www.JSON.org/js.html

    This file creates a global JSON object containing two methods:

        JSON.stringify(value, whitelist)
            value       any JavaScript value, usually an object or array.

            whitelist   an optional array parameter that determines how object
                        values are stringified.

            This method produces a JSON text from a JavaScript value.
            There are three possible ways to stringify an object, depending
            on the optional whitelist parameter.

            If an object has a toJSON method, then the toJSON() method will be
            called. The value returned from the toJSON method will be
            stringified.

            Otherwise, if the optional whitelist parameter is an array, then
            the elements of the array will be used to select members of the
            object for stringification.

            Otherwise, if there is no whitelist parameter, then all of the
            members of the object will be stringified.

            Values that do not have JSON representaions, such as undefined or
            functions, will not be serialized. Such values in objects will be
            dropped; in arrays will be replaced with null.
            JSON.stringify(undefined) returns undefined. Dates will be
            stringified as quoted ISO dates.

            Example:

            var text = JSON.stringify(['e', {pluribus: 'unum'}]);
            // text is '["e",{"pluribus":"unum"}]'

        JSON.parse(text, filter)
            This method parses a JSON text to produce an object or
            array. It can throw a SyntaxError exception.

            The optional filter parameter is a function that can filter and
            transform the results. It receives each of the keys and values, and
            its return value is used instead of the original value. If it
            returns what it received, then structure is not modified. If it
            returns undefined then the member is deleted.

            Example:

            // Parse the text. If a key contains the string 'date' then
            // convert the value to a date.

            myData = JSON.parse(text, function (key, value) {
                return key.indexOf('date') >= 0 ? new Date(value) : value;
            });

    This is a reference implementation. You are free to copy, modify, or
    redistribute.

    Use your own copy. It is extremely unwise to load third party
    code into your pages.
*/

/*jslint evil: true */

/*global JSON */

/*members "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
    charCodeAt, floor, getUTCDate, getUTCFullYear, getUTCHours,
    getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join, length,
    parse, propertyIsEnumerable, prototype, push, replace, stringify, test,
    toJSON, toString
*/

if (!this.JSON) {

    JSON = function () {

        function f(n) {    // Format integers to have at least two digits.
            return n < 10 ? '0' + n : n;
        }

        Date.prototype.toJSON = function () {

// Eventually, this method will be based on the date.toISOString method.

            return this.getUTCFullYear()   + '-' +
                 f(this.getUTCMonth() + 1) + '-' +
                 f(this.getUTCDate())      + 'T' +
                 f(this.getUTCHours())     + ':' +
                 f(this.getUTCMinutes())   + ':' +
                 f(this.getUTCSeconds())   + 'Z';
        };


        var m = {    // table of character substitutions
            '\b': '\\b',
            '\t': '\\t',
            '\n': '\\n',
            '\f': '\\f',
            '\r': '\\r',
            '"' : '\\"',
            '\\': '\\\\'
        };

        function stringify(value, whitelist) {
            var a,          // The array holding the partial texts.
                i,          // The loop counter.
                k,          // The member key.
                l,          // Length.
                r = /["\\\x00-\x1f\x7f-\x9f]/g,
                v;          // The member value.

            switch (typeof value) {
            case 'string':

// If the string contains no control characters, no quote characters, and no
// backslash characters, then we can safely slap some quotes around it.
// Otherwise we must also replace the offending characters with safe sequences.

                return r.test(value) ?
                    '"' + value.replace(r, function (a) {
                        var c = m[a];
                        if (c) {
                            return c;
                        }
                        c = a.charCodeAt();
                        return '\\u00' + Math.floor(c / 16).toString(16) +
                                                   (c % 16).toString(16);
                    }) + '"' :
                    '"' + value + '"';

            case 'number':

// JSON numbers must be finite. Encode non-finite numbers as null.

                return isFinite(value) ? String(value) : 'null';

            case 'boolean':
            case 'null':
                return String(value);

            case 'object':

// Due to a specification blunder in ECMAScript,
// typeof null is 'object', so watch out for that case.

                if (!value) {
                    return 'null';
                }

// If the object has a toJSON method, call it, and stringify the result.

                if (typeof value.toJSON === 'function') {
                    return stringify(value.toJSON());
                }
                a = [];
                if (typeof value.length === 'number' &&
                        !(value.propertyIsEnumerable('length'))) {

// The object is an array. Stringify every element. Use null as a placeholder
// for non-JSON values.

                    l = value.length;
                    for (i = 0; i < l; i += 1) {
                        a.push(stringify(value[i], whitelist) || 'null');
                    }

// Join all of the elements together and wrap them in brackets.

                    return '[' + a.join(',') + ']';
                }
                if (whitelist) {

// If a whitelist (array of keys) is provided, use it to select the components
// of the object.

                    l = whitelist.length;
                    for (i = 0; i < l; i += 1) {
                        k = whitelist[i];
                        if (typeof k === 'string') {
                            v = stringify(value[k], whitelist);
                            if (v) {
                                a.push(stringify(k) + ':' + v);
                            }
                        }
                    }
                } else {

// Otherwise, iterate through all of the keys in the object.

                    for (k in value) {
                        if (typeof k === 'string') {
                            v = stringify(value[k], whitelist);
                            if (v) {
                                a.push(stringify(k) + ':' + v);
                            }
                        }
                    }
                }

// Join all of the member texts together and wrap them in braces.

                return '{' + a.join(',') + '}';
            }
        }

        return {
            stringify: stringify,
            parse: function (text, filter) {
                var j;

                function walk(k, v) {
                    var i, n;
                    if (v && typeof v === 'object') {
                        for (i in v) {
                            if (Object.prototype.hasOwnProperty.apply(v, [i])) {
                                n = walk(i, v[i]);
                                if (n !== undefined) {
                                    v[i] = n;
                                } else {
                                    delete v[i];
                                }
                            }
                        }
                    }
                    return filter(k, v);
                }


// Parsing happens in three stages. In the first stage, we run the text against
// regular expressions that look for non-JSON patterns. We are especially
// concerned with '()' and 'new' because they can cause invocation, and '='
// because it can cause mutation. But just to be safe, we want to reject all
// unexpected forms.

// We split the first stage into 4 regexp operations in order to work around
// crippling inefficiencies in IE's and Safari's regexp engines. First we
// replace all backslash pairs with '@' (a non-JSON character). Second, we
// replace all simple value tokens with ']' characters. Third, we delete all
// open brackets that follow a colon or comma or that begin the text. Finally,
// we look to see that the remaining characters are only whitespace or ']' or
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.

                if (/^[\],:{}\s]*$/.test(text.replace(/\\./g, '@').
replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {

// In the second stage we use the eval function to compile the text into a
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
// in JavaScript: it can begin a block or an object literal. We wrap the text
// in parens to eliminate the ambiguity.

                    j = eval('(' + text + ')');

// In the optional third stage, we recursively walk the new structure, passing
// each name/value pair to a filter function for possible transformation.

                    return typeof filter === 'function' ? walk('', j) : j;
                }

// If the text is not JSON parseable, then a SyntaxError is thrown.

                throw new SyntaxError('parseJSON');
            }
        };
    }();
}
var hgcGMap = null;

var gMapZoomBoundLow = 9;
var gMapZoomBoundHigh = 12;

var gMapLockedInfoWin = 0;

var gMapListingMarkers = new Object();

var gMapDisplayedListings = new Object();

function loadGoogleMap() {
  if (GBrowserIsCompatible()) {
      
    var mapTypes = new Array();
    mapTypes['map'] = 0;
    mapTypes['satellite'] = 1;
    mapTypes['hybrid'] = 2;
    var defaultMapType = mapTypes['satellite'];
  
    var centerLatitude = 24.10664717920179;
    var centerLongitude = -75.73974609375;
    var defaultZoom = 6;
    
    hgcGMap = new GMap2(document.getElementById('googleMapDiv'));
    var markerPoint = new GLatLng(centerLatitude, centerLongitude);
    
    var gMapTypes = hgcGMap.getMapTypes();
    
    hgcGMap.setCenter(markerPoint, defaultZoom);
    
    hgcGMap.addControl(new GLargeMapControl());
    hgcGMap.addControl(new GMapTypeControl());
    hgcGMap.setMapType(gMapTypes[defaultMapType]);
    
    GEvent.addListener(hgcGMap, "zoomend", function(oldzoom, zoom) {
        hgcGMap.closeInfoWindow();
        if (zoom <= gMapZoomBoundLow && oldzoom > gMapZoomBoundLow) {
            clearListingOverlays();
        }
        if (zoom > gMapZoomBoundLow) {
            loadGoogleMapMarkers('listing');
        }

    });

	var lastZoom = hgcGMap.getZoom();
	var lastCenter = hgcGMap.getCenter();
	GEvent.addListener(hgcGMap,"tilesloaded",function() {
		//alert('hit');
		var pcount = hgcGMap.getContainer().childNodes[0].childNodes[0].childNodes[1].getElementsByTagName("p").length;
		var transparenttiles = hgcGMap.getContainer().childNodes[0].childNodes[0].childNodes[1].innerHTML.indexOf("transparent.png");
		//alert(pcount+ ", " + transparenttiles);
	    if (pcount > 0 || transparenttiles != -1) {
			hgcGMap.setCenter(lastCenter, lastZoom);
			//alert('hit');
	    }else{
			lastZoom = hgcGMap.getZoom();	
			lastCenter = hgcGMap.getCenter();
		}
	});

    
    GEvent.addListener(hgcGMap, "dragstart", function() {
        gMapUnlockInfoWin();
        hgcGMap.closeInfoWindow();
    });
    
    //GEvent.addListener(hgcGMap, "dragend", function() {
    //    if (hgcGMap.getZoom() > gMapZoomBoundLow) {
    //        loadGoogleMapMarkers('listing');
    //    }
    //});
    
    loadGoogleMapMarkers('island');
  }
}

function loadGoogleMapMarkers(markerType) {
    
    document.getElementById('gMapLoadingDiv').style.display = 'block';
    
    var bounds = hgcGMap.getBounds();
    var southWest = bounds.getSouthWest();
    var northEast = bounds.getNorthEast();
    var lonMin = southWest.x, latMin = southWest.y
    var lonMax = northEast.x, latMax = northEast.y
    
    var ajaxScript = _BASE_URL +'assets/ajax_engine/mapSearch.php'; //eaf
    var gmAjaxObject = new XHConn();
    var queryString = 'getMarkersInfo=1&markerType=' + markerType + '&zoom=' + hgcGMap.getZoom() 
    + '&latMin=' + latMin 
    + '&latMax=' + latMax
    + '&lonMin=' + lonMin
    + '&lonMax=' + lonMax;
    gmAjaxObject.connect(ajaxScript, 'GET', queryString, loadGoogleMapMarkersResponse);
}

function loadGoogleMapMarkersResponse(ajaxObject) {
    //alert(ajaxObject.responseText);
    var response = JSON.parse(ajaxObject.responseText);
    var i, point = null;
    
    var infoWin = hgcGMap.getInfoWindow();
    
    gMapUnlockInfoWin();
    
    if (response['islandInfoCount'] > 0) {
        var gMapIslandInfo = response['islandInfo'];
        if (gMapIslandInfo) {
            var islandIcon = new GIcon(G_DEFAULT_ICON);
            islandIcon.image = "images/g-map-marker-yellow.png";
            
            // Set up GMarkerOptions object
            markerOptions = { icon: islandIcon };
            
            var markers = new Array(response['islandInfoCount']);
            var infoContents = new Array(response['islandInfoCount']);
            var currentInfoWin = null;
            //var counter = 0;
            for (i in gMapIslandInfo) {
                point = new GLatLng(gMapIslandInfo[i]['latitude'], gMapIslandInfo[i]['longitude']);
                
                infoContents[i] = "<strong>" + gMapIslandInfo[i]['name'] + "</strong><br>" + gMapIslandInfo[i]['count'] + " Listings";
                
                markers[i] = new GMarker(point, markerOptions);
                markers[i].id = i;
                GEvent.addListener(markers[i], 'mouseover', function() {
                    if (infoWin.isHidden() || (!infoWin.isHidden() && currentInfoWin != this.id && !gMapLockedInfoWin)) {
                        gMapUnlockInfoWin();
                        this.openInfoWindowHtml(infoContents[this.id]);
                    }
                    currentInfoWin = this.id;
                });
                GEvent.addListener(markers[i], 'click', function(latlng) {
                    hgcGMap.setCenter(latlng, gMapZoomBoundLow + 1);
                });
                
                hgcGMap.addOverlay(markers[i]);
            }
        }
    }
    
    if (response['propInfoCount'] > 0) {
        for (i in gMapDisplayedListings) {
            if (gMapDisplayedListings[i] && !response['propInfo'][i]) {
                if (gMapListingMarkers[i]) {
                    hgcGMap.removeOverlay(gMapListingMarkers[i]);
                }
                gMapDisplayedListings[i] = false;
			}
        }
        
        var propIcon = new GIcon(G_DEFAULT_ICON);
        propIcon.imageLocked = "images/g-map-marker-green.png";
        
        // Set up GMarkerOptions object
        var markerOptions2 = { icon: propIcon };
        
        //gMapListingMarkers = new Array(response['propInfoCount']);
        var infoContents2 = new Array(response['propInfoCount']);
        var currentInfoWin2 = null;
		var bounds = new GLatLngBounds();

        for (i in response['propInfo']) {
            
            if (gMapDisplayedListings[i]) {
                continue;
            }
            
            point = new GLatLng(response['propInfo'][i]['latitude'], response['propInfo'][i]['longitude']);
            bounds.extend(point);

            infoContents2[i] = makeInfoWinContent(response, i);
            
            gMapListingMarkers[i] = new GMarker(point, markerOptions2);
            gMapListingMarkers[i].id = i;
            GEvent.addListener(gMapListingMarkers[i], 'mouseover', function() {
                if (infoWin.isHidden() || (!infoWin.isHidden() && currentInfoWin2 != this.id && !gMapLockedInfoWin)) {
                    gMapUnlockInfoWin();
                    this.openInfoWindowHtml(infoContents2[this.id]);
                    currentInfoWin2 = this.id;
                }
            });
            GEvent.addListener(gMapListingMarkers[i], 'click', function() {
                if (currentInfoWin2 == this.id) {
                    gMaplockInfoWin = this.id;
				TourPopUp(_BASE_URL+"details/index/Id/" + this.id + ""); //eaf
                    //this.setImage(this.getIcon().imageLocked);
                }
            });
            GEvent.addListener(gMapListingMarkers[i], 'infowindowclose', function() {
                this.setImage(this.getIcon().image);
            });
            
            hgcGMap.addOverlay(gMapListingMarkers[i]);
            
            gMapDisplayedListings[i] = true;
        }
		if(!bounds.isEmpty()){
			hgcGMap.setZoom(hgcGMap.getBoundsZoomLevel(bounds));
			hgcGMap.panTo(bounds.getCenter());
			//alert(hgcGMap.getBoundsZoomLevel(bounds));
		}
    }
    
    document.getElementById('gMapLoadingDiv').style.display = 'none';
}

function gMapUnlockInfoWin() {
    if (gMapLockedInfoWin) {
        if (gMapListingMarkers[gMapLockedInfoWin]) {
            gMapListingMarkers[gMapLockedInfoWin].setImage(gMapListingMarkers[gMapLockedInfoWin].getIcon().image);
        }
        gMapLockedInfoWin = 0;
    }
}

function clearListingOverlays() {
    var i;
    gMapUnlockInfoWin();
    for (i in gMapDisplayedListings) {
        if (gMapDisplayedListings[i]) {
            if (gMapListingMarkers[i]) {
                hgcGMap.removeOverlay(gMapListingMarkers[i]);
            }
            gMapDisplayedListings[i] = false;
        }
    }
}

function makeInfoWinContent(response, i) {
    var content = "<table cellpading='0' cellspacing='0' border='0' class='googleStyle'>";
    //content += "<tr><td align='left' colspan='3'><a href=\"javascript: TourPopUp('details.php?Id=" + i + "')\"><strong>" + response['propInfo'][i]['ref_number'] + "</strong></a></td></tr>";
    content += "<tr><td align='left' colspan='3' class='googleMapRefNumber'><strong>" + response['propInfo'][i]['ref_number'] + "</strong></td></tr>";
    content += "<tr><td align='left' colspan='3' class='googleMapIslandName'><strong>" + response['propInfo'][i]['islandName'] + "</strong></td></tr>";
    content += "<tr><td align='left'>";
    content += "<a href=\"javascript: TourPopUp('"+_BASE_URL+"details/index/Id/" + i + "')\"><img src='" + response['propInfo'][i]['photoUrl'] + "' alt='" + response['propInfo'][i]['photoAlt'] + "' title='" + response['propInfo'][i]['photoAlt'] + "' border='0' width='" + response['propInfo'][i]['photoW'] + "' height='" + response['propInfo'][i]['photoH'] + "' /></a>"; //eaf
    content += "</td><td width='100%' valign='top' align='left' colspan='2'><strong>" + response['propInfo'][i]['price']+"</strong>";
    if ('' != response['propInfo'][i]['bedBathInfo']) {
        content += "<br>" + response['propInfo'][i]['bedBathInfo']
    }
    if ('' != response['propInfo'][i]['propertyType']) {
        content += "<br>" + response['propInfo'][i]['propertyType']
    }
    content += "</td></tr><tr>";
    content += "<td align='left'><a href=\"javascript: TourPopUp('"+_BASE_URL+"details/index/Id/" + i + "')\" style='color: #000080;'>More Details</a></td>"; //eaf
    content += "<td align='right' width='100%'>\
                            <table cellpading='0' cellspacing='0' border='0' width='100%'>\
                                <tr>\
                                    <td width='100%' align='right'><a href='javascript:void(0);' onclick=\"window.open('http://www.hgchristie.net/crossroads/myHGC/index.php?action=favListings&addToFav=" + i + "&reset=1','myHGC','scrollbars=yes,width=800,height=555');\"><img src='" + response['saveIcon'] + "' border='0' width='" + response['saveIconW'] + "' height='" + response['saveIconH'] + "' ></a></td>\
                                    <td><a href='javascript:void(0);' style='color: #000080; text-decoration: underline;' onclick=\"window.open('http://www.hgchristie.net/crossroads/myHGC/index.php?action=favListings&addToFav=" + i + "&reset=1','myHGC','scrollbars=yes,width=800,height=555');\">Save</a>&nbsp;&nbsp;</td>\
                                    <td><a href='javascript:void(0);' onclick=\"window.open('"+_BASE_URL+"details/index/Id/" + i + "/action/email_form/email/enter','','resizable=no,scrollbars=yes,left=20,top=20,width=620,height=500');\"><img src='" + response['shareIcon'] + "' border='0' width='" + response['shareIconW'] + "' height='" + response['shareIconH'] + "' ></a></td>\
                                    <td><a href='javascript:void(0);' style='color: #000080; text-decoration: underline;' onclick=\"window.open('"+_BASE_URL+"details/index/Id/" + i + "/action/email_form/email/enter','','resizable=no,scrollbars=yes,left=20,top=20,width=620,height=500');\">Share</a>&nbsp;&nbsp;</td>\
                                 <tr>\
                              </table></td>";
    content += "</tr></table>";
    
    return content;
}

/*
Search Results on Google Map:
*/

function showSearchResultsInGoogle(url) {
    openPopupWindow('googleMapPopup', "<iframe src='"+_BASE_URL+"map_search' width='100%' height='485' frameborder='0' ></iframe>", '', '157px','231px','580px', '520px'); //eaf
}

function loadSearchResGoogleMap() {
  if (GBrowserIsCompatible()) {
      
    var mapTypes = new Array();
    mapTypes['map'] = 0;
    mapTypes['satellite'] = 1;
    mapTypes['hybrid'] = 2;
    var defaultMapType = mapTypes['satellite'];
  
    var centerLatitude = 24.10664717920179;
    var centerLongitude = -75.73974609375;
    var defaultZoom = 6;
    
    hgcGMap = new GMap2(document.getElementById('googleMapDiv'));
    var markerPoint = new GLatLng(centerLatitude, centerLongitude);
    
    var gMapTypes = hgcGMap.getMapTypes();
    
    hgcGMap.setCenter(markerPoint, defaultZoom);
    
    hgcGMap.addControl(new GLargeMapControl());
    hgcGMap.addControl(new GMapTypeControl());
    hgcGMap.setMapType(gMapTypes[defaultMapType]);

	var lastZoom = hgcGMap.getZoom();
	var lastCenter = hgcGMap.getCenter();
	GEvent.addListener(hgcGMap,"tilesloaded",function() {
		//alert('hit');
		var pcount = hgcGMap.getContainer().childNodes[0].childNodes[0].childNodes[1].getElementsByTagName("p").length;
		var transparenttiles = hgcGMap.getContainer().childNodes[0].childNodes[0].childNodes[1].innerHTML.indexOf("transparent.png");

	    if (pcount > 0 && transparenttiles != -1 && transparenttiles < 1000) {
			hgcGMap.setCenter(lastCenter, lastZoom);
			//alert('hit');
	    }else{
			lastZoom = hgcGMap.getZoom();	
			lastCenter = hgcGMap.getCenter();
		}
	});
    
    loadSearchResMarkers(0);
  }
}

function loadSearchResMarkers(offset) {
    
    document.getElementById('gMapLoadingDiv').style.display = 'block';
    
    var ajaxScript = _BASE_URL+'assets/ajax_engine/mapSearch.php'; //eaf
    var gmAjaxObject = new XHConn();
    var queryString = 'getSearchResMarkersInfo=1&offset=' + offset;
    gmAjaxObject.connect(ajaxScript, 'GET', queryString, loadSearchResMarkersResponse);
}

function loadSearchResMarkersResponse(ajaxObject) {
    //alert(ajaxObject.responseText);
    var response = JSON.parse(ajaxObject.responseText);
    var i, point = null;
    
    var infoWin = hgcGMap.getInfoWindow();
    
    gMapUnlockInfoWin();
    
    if (response['propInfoCount'] > 0) {
        hgcGMap.clearOverlays()
        
        var propIcon = new GIcon(G_DEFAULT_ICON);
        propIcon.imageLocked = "images/g-map-marker-green.png";
        
        // Set up GMarkerOptions object
        var markerOptions2 = { icon: propIcon };
        
        //gMapListingMarkers = new Array(response['propInfoCount']);
        var infoContents2 = new Array(response['propInfoCount']);
        var currentInfoWin2 = null;
		var bounds = new GLatLngBounds();
        for (i in response['propInfo']) {
            
            point = new GLatLng(response['propInfo'][i]['latitude'], response['propInfo'][i]['longitude']);
            bounds.extend(point);

            infoContents2[i] = makeInfoWinContent(response, i);
            
            gMapListingMarkers[i] = new GMarker(point, markerOptions2);
            gMapListingMarkers[i].id = i;
            GEvent.addListener(gMapListingMarkers[i], 'mouseover', function() {
                if (infoWin.isHidden() || (!infoWin.isHidden() && currentInfoWin2 != this.id && !gMapLockedInfoWin)) {
                    gMapUnlockInfoWin();
                    this.openInfoWindowHtml(infoContents2[this.id]);
                    currentInfoWin2 = this.id;
                }
            });
            GEvent.addListener(gMapListingMarkers[i], 'click', function() {
                if (currentInfoWin2 == this.id) {
                    gMapLockedInfoWin = this.id;
					TourPopUp(_BASE_URL+"details/index/Id/" + this.id + ""); //eaf
					//this.setImage(this.getIcon().imageLocked);
                }
            });
            GEvent.addListener(gMapListingMarkers[i], 'infowindowclose', function() {
                this.setImage(this.getIcon().image);
            });
            
            hgcGMap.addOverlay(gMapListingMarkers[i]);
        }
		if(!bounds.isEmpty()){
			hgcGMap.setZoom(hgcGMap.getBoundsZoomLevel(bounds));
			hgcGMap.panTo(bounds.getCenter());
			//alert(hgcGMap.getBoundsZoomLevel(bounds));
		}
    }
    document.getElementById('searchResMessage').innerHTML = response['searchResMessage'];
    document.getElementById('gMapPreviousNextString').innerHTML = response['previousNextString'];
    document.getElementById('gMapLoadingDiv').style.display = 'none';
}

/**
 * jQuery.Preload - Multifunctional preloader
 * Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com
 * Dual licensed under MIT and GPL.
 * Date: 3/12/2008
 * @author Ariel Flesler
 * @version 1.0.7
 */
;(function($){var n=$.preload=function(c,d){if(c.split)c=$(c);d=$.extend({},n.defaults,d);var f=$.map(c,function(a){if(!a)return;if(a.split)return d.base+a+d.ext;var b=a.src||a.href;if(typeof d.placeholder=='string'&&a.src)a.src=d.placeholder;if(b&&d.find)b=b.replace(d.find,d.replace);return b||null}),g={loaded:0,failed:0,next:0,done:0,total:f.length};if(!g.total)return m();var h='<img/>',j=d.threshold;while(--j>0)h+='<img/>';h=$(h).load(k).error(k).bind('abort',k).each(l);function k(e){g.found=e.type=='load';g.image=this.src;var a=g.original=c[this.index];g[g.found?'loaded':'failed']++;g.done++;if(d.placeholder&&a.src)a.src=g.found?g.image:d.notFound||a.src;if(d.onComplete)d.onComplete(g);if(g.done<g.total)l(0,this);else{if(h.unbind)h.unbind('load').unbind('error').unbind('abort');h=null;m()}};function l(i,a,b){if($.browser.msie&&g.next&&g.next%n.gap==0&&!b){setTimeout(function(){l(i,a,1)},0);return!1}if(g.next==g.total)return!1;a.index=g.next;a.src=f[g.next++];if(d.onRequest){g.image=a.src;g.original=c[g.next-1];d.onRequest(g)}};function m(){if(d.onFinish)d.onFinish(g)}};n.gap=12;n.defaults={threshold:2,base:'',ext:'',replace:''};$.fn.preload=function(a){n(this,a);return this}})(jQuery);var popupWinzindex=5000;

function getPosition(obj){
    var curleft = curtop = 0;
    var position = new Array();
    if (obj.offsetParent) {
        do {
    		curleft += obj.offsetLeft;
    		curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
        position['left'] = curleft;        
        position['top'] = curtop;        
        return position;
    }
}

function popupWindow(winName,objId,speed,top,left,width,height){
    var content = $("#"+objId).html();
    openPopupWindow(winName,content,speed,top,left,width,height)
}

function popupWindowAjax(winName,pageUrl,speed,top,left,width,height){
    var content = $.ajax({url: pageUrl,async: false}).responseText;
    openPopupWindow(winName,content,speed,top,left,width,height);
} 

function popupWindowIframe(winName,pageUrl,speed,top,left,width,height){
    var iframeHeight = height.replace('px','') *1 - 60;
    var content = "<iframe src='"+pageUrl+"' width='100%' height='"+iframeHeight+"' frameborder='0'></iframe>";
    openPopupWindow(winName,content,speed,top,left,width,height);
} 


function openPopupWindow(winName,content,speed,valTop,valLeft,valWidth,valHeight){
    if (!$('#'+winName).length > 0){
      $('body').append('<div id="'+winName+'" class="popupWindowContainer"><div class="titleBar"><span class="closeWindow">close [x]</span></div><div class="contentArea"></div></div>');
    }
       popupWinzindex++;
              
       $("#"+winName).css({top:valTop,left:valLeft,width:valWidth,height:valHeight,'z-index':popupWinzindex}).show(speed);
       $(".popupWindowContainer").bgiframe();
       $("#"+winName+" .contentArea").html(content);
       
       if (valHeight != '' && valHeight !=null && valHeight !='undifined') {
           var contentHeight = parseInt(valHeight) - 43;
           $("#"+winName+" .contentArea").css('height',contentHeight+'px');
       }
       $("#"+winName+" .contentArea").mousedown(function(){
           popupWinzindex++;
           $(this).parent().css('z-index',popupWinzindex);
           });
       $(".titleBar").mousedown(function(){
           popupWinzindex++;
            $(this).parent().draggable().css('z-index',popupWinzindex);
       }).mouseup(function(){
            $(this).parent().draggable('destroy');
       });
       
       $(".closeWindow").click(function(){
           $(this).parent().parent().hide(speed,function(){$(this).remove()});
       });
}

function trim(input) {
    return input.replace(/^\s+|\s+$/g, '');
}

function updatePriceRange()
{
    var selectedPriceRange = document.getElementById('price_range_options').value.split(" ");
    document.getElementById('price_from').value = selectedPriceRange[0];
    document.getElementById('price_to').value = selectedPriceRange[1];
}

function checkInputCriteria(currentForm)
{
  
    if (currentForm == null) {
        var searchCriteria = trim(document.getElementById('search_all_text').value);
    } else {
        var searchCriteria = trim(currentForm.search_all_text.value);
    }
   if (searchCriteria == ''){
    return true;   
   }
   var pageUrl ='ajax_engine/quick_search_check_input.php?action=quickSearchCheckInput&input='+searchCriteria;   
   var response = $.ajax({url: pageUrl,async: false}).responseText;
   
   if (trim(response)!='0'){
             TourPopUp(_BASE_URL+'details/index/Id/='+trim(response)); //eaf
       return false;
   }else {
        return true;
   }
}

function onEnterCheckInput(event)
{
   if (event.keyCode == 13) {
      return checkInputCriteria(); 
   }
}

function clicker() {
	$('#services .toplink').click(function() { $(this).css('background','none') });
	$('#info .toplink').click(function() { $(this).css('background','none') });
	$('#about .toplink').click(function() { $(this).css('background','none') });
}


$(document).ready(function(){ 
	clicker();
});

$.preload(['bg2','bg3','bg5'],{base:_BASE_URL+'assets/images/',ext:'.png'});
