
//Global XMLHTTP Request object
var XmlHttp;
var AjaxServerPageName = "/RPC/HarcourtsPropertyServer.aspx";

var dopopup = true;
if (document.getElementById('infodiv2') != null)
    dopopup = false;

var tableRow
var ewindow;
var first = 0;
var last = 10;
var mynav;

var _priceFrom;
var _priceTo;
var _bedrooms;
var _propertyType;
var _tr;
var _bl;
var timerSecs;
var timerID = null
var timerRunning = false
var delay = 1;
var loadingControl;
var listingId;
var moveTriggeredSearch;
var pControl;
var imageIndex;
var previousImageIndex;
var imageCount;
var listingSearch;
var markers = new Array();
var photoServer = "http://intranet.harcourts.com.au/public/image.asp?ListNo=";


var baseIcon = new GIcon();
baseIcon.iconSize = new GSize(32, 32);
baseIcon.shadowSize = new GSize(56, 32);
baseIcon.iconAnchor = new GPoint(16, 32);
baseIcon.infoWindowAnchor = new GPoint(16, 0);
//Creating and setting the instance of appropriate XMLHTTP Request object to a “XmlHttp” variable  
function CreateXmlHttp() {
    //Creating object of XMLHTTP in IE
    try {
        XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
        try {
            XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (oc) {
            XmlHttp = null;
        }
    }
    //Creating object of XMLHTTP in Mozilla and Safari 
    if (!XmlHttp && typeof XMLHttpRequest != "undefined") {
        XmlHttp = new XMLHttpRequest();
    }

}

//sets the state of the variables (e.g. search criteria, before requerying the ajax server for the data.
function SetStates() {
    _priceFrom = PriceFrom.options[PriceFrom.selectedIndex].value;
    _priceTo = PriceTo.options[PriceTo.selectedIndex].value;
    _bedrooms = Bedrooms.options[Bedrooms.selectedIndex].value;
    _propertyType = PropType.options[PropType.selectedIndex].value;
    _bl = map.getBounds().getSouthWest().toUrlValue();
    _tr = map.getBounds().getNorthEast().toUrlValue();

}


//Gets called when the map search selection changes
function SearchChange(moveSearch, surroundingSearch) {
    setText("Please wait - properties loading", "<img src='/images/indicatorlarge.gif'>");
    //loadingControl = new OverlayControl('Please wait - properties loading', '<img src=\'/images/indicatorlarge.gif\'>', true);
    //map.addControl(loadingControl);
    if (markers.length < 50) {
        var requestUrl;
        if (surroundingSearch == null && (listingSearch == null || listingSearch == "undefined")) {

            //     if (document.getElementById('hsales')!=null)



            showforsale = (document.getElementById('showforsale').checked);
            getharcourtssales = (document.getElementById('showrecentsales').checked);
            //   getothersales=true;


            SearchBtn.disabled = true;
            //set the varible storing whether or not they have searched...
            hasSearched = true;
            SetStates();
            requestUrl = AjaxServerPageName + "?Type=Search&pf=" + _priceFrom + "&pt=" + _priceTo + "&b=" + _bedrooms
    	        + "&prop=" + _propertyType + "&bl=" + _bl + "&tr=" + _tr + "&getrecentsales=" + getharcourtssales + "&getforsale=" + showforsale;


            if (listingId != null)
                requestUrl = AjaxServerPageName + "?Type=Search&id=" + listingId;
        }
        else {
            if (surroundingSearch) {
                _bl = map.getBounds().getSouthWest().toUrlValue();
                _tr = map.getBounds().getNorthEast().toUrlValue();
                requestUrl = AjaxServerPageName + "?Type=Search&pf=All&pt=All&b=All&prop=All&bl=" + _bl + "&tr=" + _tr + "&listingid=" + listingSearch
    	        + "&getharcourtssales" + getharcourtssales + "&getforsale=" + showforsale;
            }
            else {
                requestUrl = AjaxServerPageName + "?Type=Search&id=" + listingSearch;
            }
        }


        CreateXmlHttp();

        //document.getElementById('testdiv').innerHTML = requestUrl;

        // If browser supports XMLHTTPRequest object
        if (XmlHttp) {
            //Setting the event handler for the response

            XmlHttp.onreadystatechange = HandleResponse;
            //alert(requestUrl);

            //Initializes the request object with GET (METHOD of posting), 
            //Request URL and sets the request as asynchronous.
            XmlHttp.open("GET", requestUrl, true);

            //Sends the request to server
            XmlHttp.send(null);
        }
    }
}
function SearchClick() {
    map.clearOverlays();
    markers = new Array();
    listingId = null;
    SearchChange();
}
function Locate(loclat, loclng, locview, listingpk) {
    map.clearOverlays();
    markers = new Array();
    map.setCenter(new GLatLng(loclat, loclng), locview);
    if (listingpk != null && listingpk != "undefined") {
        listingId = listingpk;
    }
    SearchChange();
}

//Called when response comes back from server
function HandleResponse() {

    if (listingSearch == null)
        SearchBtn.disabled = false;
    // To make sure receiving response data from server is completed
    if (XmlHttp.readyState == 3) {
        var d = new Date();
        //InfoSpan.innerText += "\nInteractive - " + d.getSeconds() + " " + d.getMilliseconds().toString();
    }
    if (XmlHttp.readyState == 4) {
        var d1 = new Date();
        //InfoSpan.innerText += "\nGot Response - " + d1.getSeconds() + " " + d1.getMilliseconds().toString();
        // To make sure valid response is received from the server, 200 means response received is OK
        if (XmlHttp.status == 200) {
            // alert(XmlHttp.responseXML.documentElement);
            UpdateMap(XmlHttp.responseXML.documentElement);
        }
        else {
            alert('An error has occurred please try again later. ErrorID: ' + xmlhttp.statusText);
        }
    }

}

function ClearMap() {
    //oControl.updateOverlay("");
    setText("");
    map.clearOverlays();
    hasSearched = false;
    listingId = null;
    closedisplayimage();
}
function closedisplayimage() {
    if (pControl != null)
        pControl.close();
}
//Clears the contents of state combo box and adds the states of currently selected country
function UpdateMap(MapData) {
    // document.getElementById('sidebar-list').innerHTML = '';

    first = 0;
    last = 10;
    tableRow = new Array();

    if (navigator.appName == "Netscape")
        mynav = "NS";
    if (navigator.appName == "Microsoft Internet Explorer")
        mynav = "IE";

    var branches = MapData.getElementsByTagName('Branch');
    var properties = MapData.getElementsByTagName('Property');


    //need to satisfy the fact that there maybe no properties and these need to be handled...
    if (properties.length == 0 && listingSearch == null) {
        setText("No properties that matched your search criteria were found for this map", "<img src='images/critical.gif'>");
    }
    //otherwise the map might be zoomed out too much...
    else if (map.getZoom() < 8 && listingSearch == null) {
        map.clearOverlays();
        setText("There are properties available on this map, however "
            + "the map is zoomed too far out, please <a href='javascript:zoom(8)'>zoom in</a> to view the properties", "<img  src='images/caution.gif'>");
    }
    //otherwise we have properties and we need to overlay them.
    else {
        var i;
        var html = "";
        var lat;
        var lng;
        var b = true;
        var icon;
        var isListing;
        var isRental;
        var isHarcourtsListing;

        //let's overlay the branchinfo firstly...
        for (i = 0; i < branches.length; i++) {
            html = branches[i].getElementsByTagName('Name')[0].childNodes[0].data;
            lat = branches[i].getElementsByTagName('Latitude')[0].childNodes[0].data;
            lng = branches[i].getElementsByTagName('Longitude')[0].childNodes[0].data;
            createMarker(new GLatLng(lat, lng), html, getIcon());
        }


        //if there are more properties availalbe in this selection we need to inform the users...
        if ((MapData.getElementsByTagName('MoreProperties')[0].childNodes[0].data == "True") && listingSearch == null)
            setText("There are more properties available in this selection, please "
                + "<a href='javascript:zoom(1)'>zoom in</a> to view.", "<img src='images/caution.gif'>");
        else
            setText("");

        var harcourtsListing = new Array(0);
        var harcourtsSold = new Array(0);
        var APMListing = new Array(0);
        var APMSold = new Array(0);

        for (i = 0; i < properties.length; i++) {

            //every property must have a latitude and a longitude
            lat = properties[i].getElementsByTagName('Latitude')[0].childNodes[0].data;
            lng = properties[i].getElementsByTagName('Longitude')[0].childNodes[0].data;

            //establish whether this property is for sale or has been listed...
            isListing = properties[i].getAttribute('Type') == "Listing";
            isRental = properties[i].getAttribute('BuyOrRent') == "Rental";
            isHarcourtsListing = properties[i].getAttribute('Company') == "Harcourts";
            html = "";


            //firstly let's look for all the Bedroom, bathroom & garaging informaiton....
            var bedbath = "<table width='100%'>";
            var noImage = properties[i].getElementsByTagName('ImageUrl')[0].childNodes.length == 0;

            if (properties[i].getElementsByTagName('Bedrooms')[0] != null && properties[i].getElementsByTagName('Bedrooms')[0].childNodes.length != 0)
                bedbath += "<TR><td style='text-align: left;'>Bedrooms</TD><td style='text-align: right; padding-left: 10px;'>" +
					parseInt(properties[i].getElementsByTagName('Bedrooms')[0].childNodes[0].data) + "</TD></TR>";

            if (properties[i].getElementsByTagName('Bathrooms')[0] != null && properties[i].getElementsByTagName('Bathrooms')[0].childNodes.length != 0)
                bedbath += "<TR><td style='text-align: left;'>Bathrooms</TD><td style='text-align: right; padding-left: 10px;'>" +
					parseInt(properties[i].getElementsByTagName('Bathrooms')[0].childNodes[0].data) + "</TD></TR>";

            if (properties[i].getElementsByTagName('Garages')[0] != null && properties[i].getElementsByTagName('Garages')[0].childNodes.length != 0)
                bedbath += "<TR><td style='text-align: left;'>Garaging</TD><td style='text-align: right; padding-left: 10px;'>" +
					parseInt(properties[i].getElementsByTagName('Garages')[0].childNodes[0].data) + "</TD></TR>";

            bedbath += "</table>";


            //open the html variable...
            html = "<SPAN class='infowindow'><TABLE class='display' width='200px'><TR><TD><TABLE class='innerdisplay'><TR><TD>";

            var generated_img_tag;
            var generated_div_start_tag;

            //now the image. If it does have an image, then we will write that info to the html varible...
            if (!noImage) {
                var imageWidth = null;
                var imageHeight = null;

                if (properties[i].getElementsByTagName('ImageWidth').length != 0) {
                    imageWidth = parseInt(properties[i].getElementsByTagName('ImageWidth')[0].childNodes[0].data) / 2;
                }

                if (properties[i].getElementsByTagName('ImageHeight').length != 0) {
                    imageWidth = parseInt(properties[i].getElementsByTagName('ImageHeight')[0].childNodes[0].data) / 2;
                }

                var styleAttributes = [];
                if (imageWidth) {
                    styleAttributes.push("width:" + imageWidth + "px");
                }

                if (imageHeight) {
                    styleAttributes.push("height:" + imageHeight + "px");
                }

                generated_div_start_tag = "<div" + ((styleAttributes.length > 0) ? " style='" + styleAttributes.join(";") + "'" : "") + ">";

                generated_img_tag = "<IMG";
                if (imageWidth) {
                    generated_img_tag += " width='" + imageWidth + "'";
                }
                if (imageHeight) {
                    generated_img_tag += " height='" + imageHeight + "'";
                }
                generated_img_tag += " src='" + properties[i].getElementsByTagName('ImageUrl')[0].childNodes[0].data + "'";
                generated_img_tag += ">";

                html += generated_div_start_tag + generated_img_tag + "</div></TD></TR><TR><TD style='text-align: centre;'>";

                //html+= "<div style='width:" + parseInt(properties[i].getElementsByTagName('ImageWidth')[0].childNodes[0].data) / 2 + "px; height:" + 
                //	parseInt(properties[i].getElementsByTagName('ImageHeight')[0].childNodes[0].data) / 2 + "px;'><IMG width='" + 
                //	parseInt(properties[i].getElementsByTagName('ImageWidth')[0].childNodes[0].data) / 2 + "' height='" + 
                //	parseInt(properties[i].getElementsByTagName('ImageHeight')[0].childNodes[0].data) / 2 + "' src='" + 
                //	properties[i].getElementsByTagName('ImageUrl')[0].childNodes[0].data + "'></div></TD></TR><TR><TD style='text-align: centre;'>";                 

                if (isHarcourtsListing && isListing)
                    html += "<A href='#' onclick='javascript:launchpic(\"" + "<img src=" + photoServer + properties[i].getElementsByTagName('ListingNo')[0].childNodes[0].data +
						"&SeqNum=1&Size=large  id=displayimage >" + "\", " + properties[i].getElementsByTagName('ImgCount')[0].childNodes[0].data +
						");'><font style='color: green;'>&#43;</font> more images</A></td></tr><tr><td style='text-align: centre;'>";
            }

            if (properties[i].getElementsByTagName('MoreInfo')[0] != null && properties[i].getElementsByTagName('MoreInfo')[0].childNodes.length != 0 && showmoreinfolink) {
                html += "<a href='" + properties[i].getElementsByTagName('MoreInfo')[0].childNodes[0].data + "' target='_blank'><font style='color: green;'>&#43;</font> more details</a></td></tr><tr><td>";
            }

            html += "</TD></TR></TABLE>" + bedbath
                + "</TD><TD style='text-align: centre;'>";

            //Now the header of the Proerty info - the address.
            if (properties[i].getElementsByTagName('Address')[0].childNodes.length != 0) {
                html += "<BR>" + properties[i].getElementsByTagName('Address')[0].childNodes[0].data;
            }

            //now the price information. if it is sold the price desc will contain the relevant information - which will have been performed
            //on the server-side
            if (properties[i].getElementsByTagName('PriceDesc')[0].childNodes.length != 0) {
                if (isListing) {
                    if (isRental)
                        html += "<br /><div style='white-space: nowrap;'>" + properties[i].getElementsByTagName('PriceDesc')[0].childNodes[0].data + "</div>";
                    else
                        html += "<br /><div style='white-space: nowrap;'>FOR SALE: " + properties[i].getElementsByTagName('PriceDesc')[0].childNodes[0].data + "</div>";
                }
                else
                    html += "<br /><div style='white-space: nowrap;'>SOLD: " + properties[i].getElementsByTagName('PriceDesc')[0].childNodes[0].data + "</div>";
            }

            //add a navigation link, and close the HTML varialble off.
            html += "<div style='width: 100%; text-align: centre;'><A HREF='javascript:Locate(" + lat + "," + lng + ",16);' ><font style='color: green;'>&#43;</font> zoom to property</A>";
            //            if (properties[i].getElementsByTagName('MoreInfo')[0] != null && properties[i].getElementsByTagName('MoreInfo')[0].childNodes.length != 0 && showmoreinfolink)
            //            {
            //                html += "<BR><a href='" + properties[i].getElementsByTagName('MoreInfo')[0].childNodes[0].data + "' target='_blank'><font style='color: green;'>&#43;</font> more info</A>";
            //            }
            html += "</div></TD></TR></TABLE></SPAN>";

            //create the icon and slide the carker into the collection.
            if (isListing) {
                icon = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal3/icon31.png", null, "http://maps.google.com/mapfiles/kml/pal3/icon31s.png");
            }
            else {
                icon = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal2/icon50.png", null, "http://maps.google.com/mapfiles/kml/pal2/icon50s.png");
            }

            createMarker(new GLatLng(lat, lng), html, icon);

            //now create the HTML for the list below...
            var nhtml;
            var imgsrc = '';

            if (!noImage) {
                imgsrc = generated_div_start_tag + generated_img_tag + "</div>";

                //                imgsrc = "<div style='width:" + parseInt(properties[i].getElementsByTagName('ImageWidth')[0].childNodes[0].data) / 2 + "px; height:" + 
                //					parseInt(properties[i].getElementsByTagName('ImageHeight')[0].childNodes[0].data) / 2 + "px;'><IMG width='" + 
                //					parseInt(properties[i].getElementsByTagName('ImageWidth')[0].childNodes[0].data) / 2 + "' height='" + 
                //					parseInt(properties[i].getElementsByTagName('ImageHeight')[0].childNodes[0].data) / 2 + "' src='" +
                //					properties[i].getElementsByTagName('ImageUrl')[0].childNodes[0].data + "'></div>";
                html = "<tr><td>" + generated_div_start_tag + generated_img_tag + "</div></td><td>" + html + "</td></tr>";
                //                html = "<tr><td><div style='width:" + parseInt(properties[i].getElementsByTagName('ImageWidth')[0].childNodes[0].data) / 2 + "px; height:" + 
                //					parseInt(properties[i].getElementsByTagName('ImageHeight')[0].childNodes[0].data) / 2 + "px;'><IMG width='" + 
                //					parseInt(properties[i].getElementsByTagName('ImageWidth')[0].childNodes[0].data) / 2 + "' height='" + 
                //					parseInt(properties[i].getElementsByTagName('ImageHeight')[0].childNodes[0].data) / 2 + "' src='" + 
                //					properties[i].getElementsByTagName('ImageUrl')[0].childNodes[0].data + "'></div></td><td>" + html +  "</td></tr>";
            }

            //work out the formatting for the alternating rows..
            if (i % 2) {
                nhtml = "<tr class='nrow'>";
            }
            else {
                nhtml = "<tr class='altrow'>";
            }

            nhtml += "<td>" + imgsrc + "</td><td style='text-align: left;'><b>";

            if (!isListing)
                nhtml += "SOLD";

            nhtml += "</b></td><td style='text-align: left;'>";

            //address line
            if (properties[i].getElementsByTagName('Address')[0].childNodes.length != 0) {
                nhtml += properties[i].getElementsByTagName('Address')[0].childNodes[0].data;
            }

            //quick-link
            nhtml += "<br/><A HREF='javascript:Locate(" + lat + "," + lng + ",16);' >show on map</A>";

            if (properties[i].getElementsByTagName('MoreInfo')[0] != null && properties[i].getElementsByTagName('MoreInfo')[0].childNodes.length != 0 && showmoreinfolink) {
                nhtml += "<br/><a href='" + properties[i].getElementsByTagName('MoreInfo')[0].childNodes[0].data + "' target='_blank'>more details</a>";
            }

            //$ informaition
            nhtml += "</td><td style='white-space: nowrap;'>";

            if (properties[i].getElementsByTagName('PriceDesc')[0].childNodes.length != 0) {
                nhtml += properties[i].getElementsByTagName('PriceDesc')[0].childNodes[0].data;
            }

            nhtml += "</td><td style='text-align: right; padding-left: 10px;'>";

            //Bedroom
            if (properties[i].getElementsByTagName('Bedrooms')[0] != null && properties[i].getElementsByTagName('Bedrooms')[0].childNodes.length != 0) {
                nhtml += parseInt(properties[i].getElementsByTagName('Bedrooms')[0].childNodes[0].data);
            }

            nhtml += "</td><td style='text-align: right; padding-left: 10px;'>";

            //bathrooms
            if (properties[i].getElementsByTagName('Bathrooms')[0] != null && properties[i].getElementsByTagName('Bathrooms')[0].childNodes.length != 0) {
                nhtml += parseInt(properties[i].getElementsByTagName('Bathrooms')[0].childNodes[0].data);
            }

            nhtml += "</td><td style='text-align: right; padding-left: 10px;'>";

            if (properties[i].getElementsByTagName('Garages')[0] != null && properties[i].getElementsByTagName('Garages')[0].childNodes.length != 0) {
                nhtml += parseInt(properties[i].getElementsByTagName('Garages')[0].childNodes[0].data);
            }
            nhtml += "</td></tr>";

            if (isHarcourtsListing && isListing)
                harcourtsListing.push(nhtml);
            else if (isHarcourtsListing)
                harcourtsSold.push(nhtml);
            else if (isListing)
                APMListing.push(nhtml);
            else
                APMSold.push(nhtml);

            //tableRow.push(nhtml);
        } //for-looop

        for (var i = 0, len = harcourtsListing.length; i < len; ++i)
            tableRow.push(harcourtsListing[i]);

        for (var i = 0, len = harcourtsSold.length; i < len; ++i)
            tableRow.push(harcourtsSold[i]);

        for (var i = 0, len = APMListing.length; i < len; ++i)
            tableRow.push(APMListing[i]);

        for (var i = 0, len = APMSold.length; i < len; ++i)
            tableRow.push(APMSold[i]);
    } //if-else

    // go to the first page of results for the grid.
    nav(0, 'grid');

} //function     
/*
if (properties[i].getElementsByTagName('StateCode')[0].childNodes[0].data  == 'SA')
{
nhtml += "<br/><A HREF='http://www.brockharcourts.com.au/index2.html?id=" + properties[i].getElementsByTagName('Pk')[0].childNodes[0].data + "' target='_blank'>more details</A>"; 
}
else 
{
nhtml += "<br/><A HREF='http://www." + Webserver + "/listing/details.do?id=" + properties[i].getElementsByTagName('Pk')[0].childNodes[0].data + "' target='_blank'>more details</A>";
}
}
else
if (showmoreinfolink && !APM)
nhtml += "<br/><A HREF='" + officesite +  "/ext.aspx?t=l&pk=" + properties[i].getElementsByTagName('Pk')[0].childNodes[0].data + "' target='_blank'>more details</A>";
*/

function open_Window(url, w, h, tb, stb, l, mb, sb, rs, x, y) {
    var t = (document.layers) ? ',screenX=' + x + ',screenY=' + y : ',left=' + x + ',top=' + y; //A LITTLE CROSS-BROWSER CODE FOR WINDOW POSITIONING
    tb = (tb) ? 'yes' : 'no'; stb = (stb) ? 'yes' : 'no'; l = (l) ? 'yes' : 'no'; mb = (mb) ? 'yes' : 'no'; sb = (sb) ? 'yes' : 'no'; rs = (rs) ? 'yes' : 'no';
    var x = window.open(url, 'newWin' + new Date().getTime(), 'scrollbars=auto,width=' + w + ',height=' + h + ',toolbar=' + tb + ',status=' + stb + ',menubar=' + mb + ',links=' + l + ',resizable=' + rs + t);
    x.focus();
}


function UpdateMarkers() {
    var bl = map.getBounds().getSouthWest();
    var tr = map.getBounds().getNorthEast();
    for (var i = 0; i < markers.length; i++)
        if (!(markers[i].getPoint().x > bl.x && markers[i].getPoint().y > bl.y && markers[i].getPoint().y < tr.y && markers[i].getPoint().x < tr.x)) {
        map.removeOverlay(markers[i]);
        markers.splice(i, 1);
        i = 0;
    }
}

function checkMarkerLocation(point) {
    for (var i = 0; i < markers.length; i++)
        if (markers[i].getPoint().equals(point))
        return true;

    return false;
}

function createMarker(point, html, icon) {
    if (!checkMarkerLocation(point)) {
        var marker = new GMarker(point, icon);

        GEvent.addListener(marker, "click", function() {

            //if (!dopopup)
            //document.getElementById('infodiv2').innerHTML= html;
            //else
            marker.openInfoWindowHtml(html);
            //ew.openOnMarker(marker,html);

        });
        markers.push(marker);
        map.addOverlay(marker);
    }
}

function previousImage() {
    previousImageIndex = imageIndex;
    imageIndex = (imageIndex == 1) ? imageCount : imageIndex = imageIndex - 1;
    updateImage();
}
function nextImage() {
    previousImageIndex = imageIndex;
    imageIndex = (imageIndex == imageCount) ? 1 : imageIndex = imageIndex + 1;
    updateImage();
}
function updateImage() {
    var infoimage = document.getElementById('displayimage');
    infoimage.src = infoimage.src.replace('&SeqNum=' + (previousImageIndex), '&SeqNum=' + imageIndex);
}
function launchpic(img, imgnum) {
    if (pControl != null)
        pControl.close();
    imageIndex = 1;
    previousImageIndex = 1;
    imageCount = imgnum;

    var scrollers = (imgnum == 0 || imgnum == null || imgnum == "undefined") ? "" :
         "<TR><TD colspan='2' style='text-align: center; white-space: nowrap;'><A HREF='#' ><img onclick='previousImage();' src='/images/back.gif'></A>"
        + "<A HREF='#' ><img onclick='nextImage();' src='/images/forward.gif'></A></TD></TR>";

    var html = "<TABLE class='displaypic'><TR><TD style='text-align: left; white-space: nowrap;'><STRONG>Image Size: </STRONG><input type='radio'  value='_small' name='picradio' onclick='javascript:changesize();' />Small"
                + "<input type='radio' value='' checked='true' id='largerb' name='picradio' onclick='javascript:changesize();' />Large</TD>"
        + "<TD style='text-align: right;'><a href='#'><img src='/images/close.gif' border='none' onclick='closedisplayimage();'></A></TD></TR>"
        + "<TR><TD colspan='2'>" + img + "</TR>"
        + scrollers
        + "</TABLE>";
    pControl = new PicControl(html);
    map.addControl(pControl);
}

function changesize() {
    var isSmall = document.getElementById('largerb').checked;
    var infoimage = document.getElementById('displayimage');
    if (isSmall)
        infoimage.src = infoimage.src.replace('&Size=medium', '&Size=large');
    else
        infoimage.src = infoimage.src.replace('&Size=large', '&Size=medium');
}

function getIcon() {
    var ic = new GIcon();
    ic.image = "/images/mm_20_red6.png";
    ic.iconSize = new GSize(45, 45);
    ic.iconAnchor = new GPoint(15, 40);
    ic.infoWindowAnchor = new GPoint(5, 1);
    return ic;
}

function StartListening() {
    // Set the length of the timer, in seconds
    secs = 2;
    StopTheClock();
    StartTheTimer();
}

function StopTheClock() {
    if (timerRunning)
        clearTimeout(timerID);
    timerRunning = false;
}

function StartTheTimer() {
    if (secs == 0) {
        StopTheClock();
        // Here's where you put something useful that's
        // supposed to happen after the allotted time.
        // For example, you could display a message:
        SearchChange(true);
        bounds = map.getBounds();
    }
    else {
        self.status = secs;
        secs = secs - 1;
        timerRunning = true;
        timerID = self.setTimeout("StartTheTimer()", delay);
    }
}

function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {

            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1)
                c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return null;
}
function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + encodeURI(value) +
    ((expiredays == null) ? "" : ";expires=" + exdate);
}
function loadFromCookie() {
    var heldLat = getCookie("harcourtsmaps_lat");
    var heldLng = getCookie("harcourtsmaps_lng");
    var heldView = getCookie("harcourtsmaps_view");

    if (heldLat != null && heldLng != null && heldView != null) {
        map.setCenter(new GLatLng(heldLat, heldLng), (heldView * 1));
        return true;
    }
    else {
        return false;
    }
}
function updateHeldView() {
    setCookie("harcourtsmaps_lat", map.getCenter().lat(), 30);
    setCookie("harcourtsmaps_lng", map.getCenter().lng(), 30);
    setCookie("harcourtsmaps_view", map.getZoom(), 30)
}
function formatCurrency(num) {
    num = num.toString().replace(/\$|\,/g, '');
    if (isNaN(num))
        num = "0";


    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num * 100 + 0.50000000001);
    cents = num % 100;
    num = Math.floor(num / 100).toString();
    if (cents < 10)
        cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
        num = num.substring(0, num.length - (4 * i + 3)) + ',' +
num.substring(num.length - (4 * i + 3));
    return (((sign) ? '' : '-') + '' + num); // + '.' + cents);
}

function nav(iVal, div) {
    // do we want to move forward or backwards?
    if (iVal == 1) {
        first += 10;
        last += 10
    }
    else if (iVal == -1) {
        first -= 10;
        last -= 10;
    }


    var txt = '';
    if (tableRow.length > 0) {
        //document.all['grid'].scrollTop = 0;

        txt += '<table ><tr><td colspan="7"><h1>Property Information</h1></td></tr>';
        txt += '<tr><td></td><td></td><td></td><td></td><td><img src=\'images/bedrooms.gif\'></td><td><img src=\'images/bathrooms.gif\'></td><td><img src=\'images/garaging.gif\'></td></tr>';
        //txt += '<br/>';
        for (var iLoop = first; iLoop < last; iLoop++) {
            //txt += '<table >';
            if (iLoop <= tableRow.length && tableRow[iLoop] != null) txt += tableRow[iLoop] + "";
            //txt += '</table>';
        }
        txt += '</table>';
        if (first > 0) // show prev link
            txt += '<a href="javascript:nav(-1,\'' + div + '\');">Prev 10</a> ';

        if (last < tableRow.length) // show next link
            txt += '<a href="javascript:nav(1,\'' + div + '\');">Next 10</a>';
    }
    // write out the the DIV tag depending on browser...
    if (mynav == "NS") {
        //document.nsgridILAYER.document.nsgridLAYER.document.write(txt);
        //document.nsgridILAYER.document.nsgridLAYER.document.close();
        document.getElementById(div).innerHTML = txt;

    }

    //alert(document.getElementById(div));
    if (mynav == "IE")
        document.getElementById(div).innerHTML = txt;

}
