/// <reference path="../../jquery/jquery-1.3.2.js"/>

//global vars
var EPDVEMAPOBJ = null;
var MOUSELOCATION_X = 0;
var MOUSELOCATION_Y = 0;
var MAPISINIT = false;
var IMAGEBASE_URL = "../images/"; /*Temp*/

// EPDMapParams class
// Handles mapping parameters
function EPDMapParams(zoomLevel, mapCenter, polyBounds) {
    this.ZoomLevel = null;
    this.MapCenter = null;
    this.MapPolyBounds = null;
    this.MapBounds = null;
    this.LastSender = "";

    this.UpdateValues(zoomLevel, mapCenter, polyBounds);

    //events
    this.OnChangeValues = null;
}

//EPDMapParams :: UpdateValues :: update my values
EPDMapParams.prototype.UpdateValues = function(zoomLevel, mapCenter, mapBounds, polyBounds, sender) {
    if (zoomLevel != null)
        this.ZoomLevel = zoomLevel;
    if (mapCenter != null)
        this.MapCenter = mapCenter;
    if (polyBounds != null)
        this.MapPolyBounds = polyBounds;
    if (sender != null)
        this.LastSender = sender;
    if (mapBounds != null)
        this.MapBounds = mapBounds;

    if (this.OnChangeValues != null)
        this.OnChangeValues();
};

//EPDMapParams :: PolyBoundsStr :: return poly bounds in a delim string format
EPDMapParams.prototype.PolyBoundsStr = function() {
    if (this.MapPolyBounds == null)
        return "";

    var tmpStr = "";

    for (var i = 0; i < this.MapPolyBounds.length; i++) {
        if (i > 0)
            tmpStr += ",";
        tmpStr += this.MapPolyBounds[i].Latitude + "~" + this.MapPolyBounds[i].Longitude;
    }

    return tmpStr;
};


//EPDMapParams :: _CompareBounds :: static only to compare to bounds arrays
EPDMapParams._CompareBounds = function(bounds1, bounds2) {
    if (bounds1 != null && bounds2 != null) {
        if (bounds1.length != bounds2.length)
            return false;

        for (var i = 0; i < bounds1.length; i++) {
            if (bounds1[i].Latitude != bounds2[i].Latitude || bounds1[i].Longitude != bounds2[i].Longitude)
                return false;
        }
        return true;
    }
    else if ((bounds1 != null && bounds2 == null) || (bounds1 == null && bounds2 != null))
        return false;
};

//EPDMapParams :: CompareValues :: compare values between to objs
EPDMapParams.prototype.CompareValues = function(mapParamObj) {
    if (EPDMapParams._CompareBounds(this.MapPolyBounds, mapParamObj.MapPolyBounds) && this.ZoomLevel == mapParamObj.ZoomLevel && this.MapCenter.Latitude == mapParamObj.MapCenter.Latitude && this.MapCenter.Longitude == mapParamObj.MapCenter.Longitude)
        return true;
    return false;
};

//EPDMapParams :: PopulateVals :: populate instance with other instance values
EPDMapParams.prototype.PopulateVals = function(mapParamObj) {
    if (mapParamObj.MapPolyBounds == null)
        this.MapPolyBounds = null;
    else {
        this.MapPolyBounds = new Array();
        for (var i = 0; i < mapParamObj.MapPolyBounds.length; i++) {
            this.MapPolyBounds[i] = mapParamObj.MapPolyBounds[i];
        }
    }
    this.ZoomLevel = mapParamObj.ZoomLevel;
    this.MapCenter = mapParamObj.MapCenter;
};

//EPDMapParams :: SearchString :: return my params as a URL friendly search string
EPDMapParams.prototype.SearchString = function() {
    var tmpStr = "";

    // Removed special logic for boxes because we want to draw full polygon to
    // make it easier to redraw map when posting back or restoring search params from session

    //if (this._BoundsIsBox()) {
    //    tmpStr += "pb=" + this._BoxBoundsStr();
    //}
    //else

    if (this.MapPolyBounds != null && this.MapPolyBounds.length > 0) {
        tmpStr += "pb=" + this.PolyBoundsStr() + "&mc=&z=";
    }
    else {
        tmpStr += "pb=" + this._MapBoundsStr();
        tmpStr += "&mc=" + this.MapCenter.Latitude + "~" + this.MapCenter.Longitude;
        tmpStr += "&z=" + this.ZoomLevel;
    }
    return tmpStr;
};

//EPDMapParams :: _MapBoundsStr :: return our map bounds as a str
EPDMapParams.prototype._MapBoundsStr = function() {
    if (this.MapBounds == null)
        return "";
    return "" + this.MapBounds.TopLeftLatLong.Latitude + "~" + this.MapBounds.TopLeftLatLong.Longitude + "," + this.MapBounds.BottomRightLatLong.Latitude + "~" + this.MapBounds.BottomRightLatLong.Longitude;
};

//EPDMapParams :: _BoxBoundsStr :: return our box bounds as a str
EPDMapParams.prototype._BoxBoundsStr = function() {
    if (this.MapPolyBounds == null)
        return "";
    //should be topleft/bottomright
    if (this.MapPolyBounds.length == 5)
        return "" + this.MapPolyBounds[0].Latitude + "~" + this.MapPolyBounds[0].Longitude + "," + this.MapPolyBounds[2].Latitude + "~" + this.MapPolyBounds[2].Longitude;
    return "";
};

//EPDMapParams :: _BoundsIsBox :: see if our bounds is really just a box
EPDMapParams.prototype._BoundsIsBox = function() {
    if (this.MapPolyBounds == null)
        return false;

    if (this.MapPolyBounds.length == 5) {
        var uLats = new Array();
        var uLongs = new Array();
        var uLatCount = 0;
        var uLongCount = 0;

        for (var i = 0; i < this.MapPolyBounds.length; i++) {
            if (uLats[this.MapPolyBounds[i].Latitude] == null) {
                uLats[this.MapPolyBounds[i].Latitude] = 1;
                uLatCount++;
                if (uLatCount > 2)
                    return false;
            }
            if (uLongs[this.MapPolyBounds[i].Longitude] == null) {
                uLongs[this.MapPolyBounds[i].Longitude] = 1;
                uLongCount++;
                if (uLongCount > 2)
                    return false;
            }
        }

        if (uLatCount == 2 && uLongCount == 2)
            return true;
    }
    return false;
};

//EPDMapParams :: toString :: overload to string to return useful information
EPDMapParams.prototype.toString = function() {
    var rtrStr = "";
    rtrStr = "<b>Sender: ";
    rtrStr += this.LastSender;
    rtrStr += "</b> Zoom Level: ";
    rtrStr += this.ZoomLevel;
    rtrStr += "\nCenter Latitude: ";
    rtrStr += this.MapCenter.Latitude;
    rtrStr += "\nCenter Longitude: ";
    rtrStr += this.MapCenter.Longitude;
    rtrStr += "\nTop Left Latitude: ";
    rtrStr += this.MapBounds.TopLeftLatLong.Latitude;
    rtrStr += "\nTop Left Longitude: ";
    rtrStr += this.MapBounds.TopLeftLatLong.Longitude;
    rtrStr += "\Bottom Right Latitude: ";
    rtrStr += this.MapBounds.BottomRightLatLong.Latitude;
    rtrStr += "\nBottom Right Longitude: ";
    rtrStr += this.MapBounds.BottomRightLatLong.Longitude;
    rtrStr += "\nPoly Bounds: ";
    rtrStr += this.PolyBoundsStr();
    return rtrStr;
};


// EPDMapSearchHelper class
// Handles ajax calls to web service
function EPDMapSearchHelper() { }

//constants
EPDMapSearchHelper.SearchURL = "/epdzoom/ws/sample.asmx/webservicename";
EPDMapSearchHelper.SearchSource = "1";  // MapSearch
//30 seconds
EPDMapSearchHelper.SearchTimeOut = 30000;
EPDMapSearchHelper.MaxListings = 200;
EPDMapSearchHelper.SearchWaitTimer = null;
EPDMapSearchHelper.SearchRequestH = null;
EPDMapSearchHelper.SearchWaitBNDraws = 0;
EPDMapSearchHelper.SearchWaitBNDrawsViaForm = 350;

//vars
EPDMapSearchHelper.QParamsStr = null;
EPDMapSearchHelper.MParamsStr = null;
EPDMapSearchHelper.Listings = new Array();

//events
EPDMapSearchHelper.OnSearchStart = null;
EPDMapSearchHelper.OnSearchEnd = null;
EPDMapSearchHelper.OnSearchTimeOut = null;
EPDMapSearchHelper.OnSearchError = null;

//EPDMapSearchHelper :: Search :: sets up our search request and gets it rolling
EPDMapSearchHelper.Search = function(qParamsStr, mParamsStr, fromForm) {
    if (EPDMapSearchHelper.QParamsStr != qParamsStr || EPDMapSearchHelper.MParamsStr != mParamsStr) {
        if (EPDD != null) EPDD.SST();

        var waitTimer = 0;
        // if fromForm is null, request is immediate
        if (fromForm != null) waitTimer = fromForm ? EPDMapSearchHelper.SearchWaitBNDrawsViaForm : EPDMapSearchHelper.SearchWaitBNDraws;

        // Abort active request
        if (EPDMapSearchHelper.SearchWaitTimer) {
            window.clearTimeout(EPDMapSearchHelper.SearchWaitTimer);
            if (EPDMapSearchHelper.SearchRequestH != null && EPDMapSearchHelper.SearchRequestH.readyState != null && EPDMapSearchHelper.SearchRequestH.readyState==1) {
                try {
                    EPDMapSearchHelper.SearchRequestH.abort();
                }
                catch (e) { }
                EPDMapSearchHelper.SearchRequestH = null;
            }
        }

        //the set timeout on start search
        EPDMapSearchHelper.SearchWaitTimer = setTimeout(
            function() {
                if (EPDMapSearchHelper.OnSearchStart != null) {
                    if (!EPDMapSearchHelper.OnSearchStart())
                        return;
                }

                if (EPDD != null) EPDD.SS(qParamsStr, mParamsStr, EPDMapSearchHelper.QParamsStr, EPDMapSearchHelper.MParamsStr);

                EPDMapSearchHelper.QParamsStr = qParamsStr;
                EPDMapSearchHelper.MParamsStr = mParamsStr;

                //alert(mParamsStr);
                // jQuery ajax call to web service
                EPDMapSearchHelper.SearchRequestH = $.ajax({ type: "GET",
                    url: EPDMapSearchHelper.SearchURL,
                    dataType: "xml",
                    data: mParamsStr + "&q=" + qParamsStr.replace("'", "\\'") + "&ssrc=" + EPDMapSearchHelper.SearchSource,
                    processData: false,
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        if (EPDMapSearchHelper.SearchReqWaitTimer)
                            window.clearTimeout(EPDMapSearchHelper.SearchReqWaitTimer);

                        //alert("Status=" + textStatus + ", Error=" + errorThrown);
                        if (textStatus == 'timeout')
                            EPDMapSearchHelper.SearchReqTimeout();
                        else
                            EPDMapSearchHelper.SearchReqError(textStatus);
                    },
                    success: function(xml) {
                        EPDMapSearchHelper.SearchEnd(xml);
                    },
                    timeout: EPDMapSearchHelper.SearchTimeOut
                });
            }, waitTimer);
    }
};

//EPDMapSearchHelper :: SearchReqTimeout :: handle a search request timeout
EPDMapSearchHelper.SearchReqTimeout = function() {
    EPDMapSearchHelper.Listings.length = 0;
    if (EPDMapSearchHelper.SearchReqWaitTimer)
        window.clearTimeout(EPDMapSearchHelper.SearchReqWaitTimer);
    try {
        EPDMapSearchHelper.SearchRequestH.abort();
    }
    catch (e) { }
    EPDMapSearchHelper.SearchRequestH = null;
    if (EPDMapSearchHelper.OnSearchTimeOut != null)
        EPDMapSearchHelper.OnSearchTimeOut();
};

//EPDMapSearchHelper :: SearchReqError :: handle a search request error
EPDMapSearchHelper.SearchReqError = function(errorText) {
    if (EPDMapSearchHelper.SearchReqWaitTimer)
        window.clearTimeout(EPDMapSearchHelper.SearchReqWaitTimer);
    if (EPDMapSearchHelper.OnSearchError != null)
        EPDMapSearchHelper.OnSearchError(errorText);
};

//EPDMapSearchHelper :: SearchEnd :: actually done with our search request.  process results
EPDMapSearchHelper.SearchEnd = function(xmlDoc) {
    EPDMapSearchHelper.Listings.length = 0;

    //clear time out timer
    if (EPDMapSearchHelper.SearchReqWaitTimer)
        window.clearTimeout(EPDMapSearchHelper.SearchReqWaitTimer);

    if (EPDD != null) EPDD.SE();

    var errorOcc = false;
    var errorStr = "";

    if (EPDMapSearchHelper.SearchReqWaitTimer)
        window.clearTimeout(EPDMapSearchHelper.SearchReqWaitTimer);

    if (xmlDoc != null) {

        var errorInt = xmlDoc.documentElement.getElementsByTagName("E");
        //var errorInt = $(xmlDoc).find("E");
        if (errorInt != null && errorInt.length > 0) {
            //parse error first
            if (errorInt.firstChild != null) {
                if (errorInt.firstChild.data == "1") {
                    errorOcc = true;
                    errorStr = "WS returned error.";
                }
            }
        }
    }

    if (!errorOcc) {
        errorOcc = true;

        //then get count
        var resultCountElem = $(xmlDoc).find("BC");
        var listCountElem = $(xmlDoc).find("LC");

        if (resultCountElem != null && resultCountElem.length > 0 && listCountElem != null && listCountElem.length > 0) {

            //then parse count
            var resultCount = "NA";
            var listCount = "NA";

            if (listCount = listCountElem[0].firstChild != null)
                listCount = listCountElem[0].firstChild.data;
            if (resultCount = resultCountElem[0].firstChild != null)
                resultCount = resultCountElem[0].firstChild.data;
            if (resultCount != "" && listCount != "") {
                if (EPDD != null) EPDD.LC(listCount, resultCount);
                errorOcc = false;

                //finally parse our return set and then populate listing info
                $("LS", xmlDoc).each(function() {
                    EPDMapSearchHelper.Listings[EPDMapSearchHelper.Listings.length] = EPDMapListingHelper.Populate(this);
                });
            }
            else
                errorStr = "WS result count was empty";
        }
        else
            errorStr = "WS result count elem was empty";
    }

    if (errorOcc) {
        //we have an error fire it
        EPDMapSearchHelper.SearchReqError(errorStr);
    }
    else {
        //lastly call our search end on event
        if (EPDMapSearchHelper.OnSearchEnd != null) {
            EPDMapSearchHelper.OnSearchEnd(listCount);
            //EPDMapSearchHelper.OnSearchEnd(resultCount);
        }
    }

    //finally done with our request handler.  handle it.
    EPDMapSearchHelper.SearchRequestH = null;
};
//end EPDMapSearchHelper class/// <reference path="jquery-1.3.2.js"/>

/* EPDPixelRectangle class
by: randy bacon
11/12/07
Used to contain a rectangle based on a pixels - using VEPixel for x,y
*/
function EPDPixelRectangle()
{
    //class members (consider _ members private)
    this._LeftTop = null;
    this._RightBottom = null;
	
    if( arguments.length == 2)
    {
	    //assume we have 2 VE points
	    this._LeftTop = arguments[0];
	    this._RightBottom = arguments[1];
    }
    else if( arguments.length == 4)
    {
	    this._LeftTop = new VEPixel(arguments[0], arguments[1]);
	    this._RightBottom = new VEPixel(arguments[2], arguments[3]);
    }
}

//EPDPixelRectangle :: GetRightBottom :: get for the right bottom member
EPDPixelRectangle.prototype.GetRightBottom = function()
{
    return this._RightBottom;
};

//EPDPixelRectangle :: GetLeftTop :: get for the left top member
EPDPixelRectangle.prototype.GetLeftTop = function()
{
    return this._LeftTop;
};

//EPDPixelRectangle :: toString :: override object toString
EPDPixelRectangle.prototype.toString =  function()
{
    return "LeftTopX: " + this._LeftTop.x + " LeftTopY: " + this._LeftTop.y + " RightBottomX: " + this._RightBottom.x + " RightBottomY: " + this._RightBottom.y;
};

//EPDPixelRectangle :: InBox :: see if a X,Y point is inside this box
//caller is responsible for having box set up correctly
EPDPixelRectangle.prototype.InBox = function(pointX, pointY)
{
    if ( pointX > this._LeftTop.x && pointX < this._RightBottom.x && pointY < this._RightBottom.y && pointY > this._LeftTop.y )
	    return true;
    else
	    return false;
};

//end --------- EPDPixelRectangle
/// <reference path="../../jquery/jquery-1.3.2.js"/>

/*  EPDZoomBox class
by: randy bacon
11/12/07
Zoom box tool and functions
*/

function EPDZoomBox(zoomBoxElem, overlayElem, drawableBounds, mapObj, mapOffset, drawOffset)
{
    //private members
    this._InZoom = false;
    this._ZBoxStart = null;
    this._ZBoxEnd = null;
    //original pixel location
    this._ZStartBoxP = null;	
    this._IsComplete = false;
    this._Width = 0;
    this._Height = 0;
    this._BorderWidth = 2;
    this._ZoomBoxElem = zoomBoxElem;
    this._OverlayElem = overlayElem;
    //public you could change for unique objs or null for none
    this.ZoomKeyCode = 90; 
    this.Overlay = document.getElementById(this._OverlayElem);
     //should be a EPDPixelRectangle obj
    this._DrawableBounds = drawableBounds;
    this._EPDMapObj = mapObj;
    this._FinalLatLngBox = null;
    this._EPDMapOffset = mapOffset;
    this._DrawOffset = drawOffset;
    this._HideOverlayOnUp = false;
    
    //this is an IE fix check for border cause it puts them outside the div
    if( navigator.appName == "Microsoft Internet Explorer")
        this._BorderWidth *= 2;

    //initialize
    this.ZoomBox = document.getElementById(this._ZoomBoxElem);
    //always hide the box on start
    $(this.ZoomBox).hide();
    //this.ZoomBox.style.display = "none";
	
    //properies
    this.MClickEnabled = false;

    //events handlers
    this.OnStartDraw = null;
    this.OnEndDraw = null;
    this.OnReset = null;
    this.OnKeyDown = null;
    this.OnKeyUp = null;   
};

//EPDZoomBox :: WindowResize :: called when window is resized
EPDZoomBox.prototype.WindowResize = function(drawableBounds, mapOffset, drawOffset) {
    this._DrawableBounds = drawableBounds;
    this._EPDMapOffset = mapOffset;
    this._DrawOffset = drawOffset;
};

//EPDZoomBox :: AttachsEHandlers :: add our event handler functions to our overlay
EPDZoomBox.prototype.AttachsEHandlers = function(startDraw, move, endDraw, keyUpEventH, keyDownEventH) {
    $(this.Overlay)
        .mousedown(startDraw)
        .mousemove(move)
        .mouseup(endDraw)
        .mouseover(function() { $(document.body).css({ cursor: "crosshair" }); })
        .mouseout(function() { $(document.body).css({ cursor: "default" }); });

    if (this.ZoomKeyCode != null) $(document).keyup(keyUpEventH)
                                             .keydown(keyDownEventH);

    //handler for our mouseover and out
    //$(document).mouseover(function() { document.body.style.cursor = "crosshair"; })
    //$(document).mouseout(function() { document.body.style.cursor = "default"; });
};   

//EPDZoomBox :: Dispose :: dispose and clean up event handlers
EPDZoomBox.prototype.Dispose = function()
{
};

//EPDZoomBox :: Reset:: method to reset this tool
EPDZoomBox.prototype.Reset = function()
{
    //this.ZoomBox.style.display = "none";
    $(this.ZoomBox).hide();
    this._InZoom = false;
    this._ZBoxStart = null;
    this._ZStartBoxP = null;
    this._ZBoxEnd = null;
    this._Width = 0;
    this._Height = 0;
    this._HideOverlayOnUp = false;
};

//EPDZoomBox :: IsInSearch:: returns search state
EPDZoomBox.prototype.IsInSearch = function()
{
    return this._InZoom;
};

//EPDZoomBox :: IsBoxComplete:: returns true if we have a box on the map
EPDZoomBox.prototype.IsBoxComplete = function()
{
    return this._IsComplete;
};

//EPDZoomBox :: ResetComplete :: reset the complete status to state
EPDZoomBox.prototype.ResetComplete = function(state)
{
    return this._IsComplete = state;
};

//EPDZoomBox :: ClickSearchState :: enable/disable the click zoom function
EPDZoomBox.prototype.ClickSearchState = function(zoomOn)
{
    if(zoomOn)
    {
        this.MClickEnabled = true;
        //this.Overlay.style.display = "block";
        $(this.Overlay).show();
    }
    else
    {
        this.MClickEnabled = false;
        //this.Overlay.style.display = "none";
        $(this.Overlay).hide();
    }
};

//EPDZoomBox :: KeyUp :: handle the key up event
EPDZoomBox.prototype.KeyUp = function(e)
{
    if(this.ZoomKeyCode == null )
        return;
        
    if( this.OnKeyUp != null )
        if( !this.OnKeyUp() )
            return;
    
    //my handlers here
    if (!e) 
        e = window.event;  
          
    //tell zoom to end 
    if (e.keyCode == this.ZoomKeyCode)
        this.EndDraw();
};

//EPDZoomBox :: KeyDown :: handle the key up event
EPDZoomBox.prototype.KeyDown = function(e)
{
    if(this.ZoomKeyCode == null )
        return;
        
    if( this.OnKeyDown != null )
        if( !this.OnKeyDown() )
            return;
    
    //my handlers here
    if (!e) 
        e = window.event;  
          
    //tell zoom to end 
    if (e.keyCode == this.ZoomKeyCode)
        this.StartDraw();
};

//EPDZoomBox :: StartDraw :: starts the box draw if parameters are correct
EPDZoomBox.prototype.StartDraw = function() {
    if (!this._InZoom && this._DrawableBounds.InBox(MOUSELOCATION_X, MOUSELOCATION_Y)) {
        //call our draw event
        if (this.OnStartDraw != null)
            if (!this.OnStartDraw())
            return;
        //reset my needed vars
        this._IsComplete = false;
        this._FinalLatLngBox = null;
        //if all good start the draw 
        this._InZoom = true;
        this._ZBoxStart = this._EPDMapObj.PixelToLatLong(new VEPixel(MOUSELOCATION_X - this._BorderWidth - this._EPDMapOffset.x, MOUSELOCATION_Y - this._BorderWidth - this._EPDMapOffset.y));
        //get our original location
        this._ZStartBoxP = new VEPixel(MOUSELOCATION_X - this._BorderWidth, MOUSELOCATION_Y - this._BorderWidth);
        //set zoom box position
        
        $(this.ZoomBox).css({ left: (MOUSELOCATION_X - this._BorderWidth - this._DrawOffset.x) + "px",
                              top: (MOUSELOCATION_Y - this._BorderWidth - this._DrawOffset.y) + "px",
                              width: "0px",
                              height: "0px"
                            })
                        .show();
                        

        //this.ZoomBox.style.left = (MOUSELOCATION_X - this._BorderWidth - this._DrawOffset.x) + "px";
        //this.ZoomBox.style.top = (MOUSELOCATION_Y - this._BorderWidth - this._DrawOffset.y) + "px";
        //this.ZoomBox.style.width = 0;
        //this.ZoomBox.style.height = 0;
        //show the zoom box
        //this.ZoomBox.style.display = "block";

        if (this.Overlay.style.display == "none") {
            this.Overlay.style.display = "block";
            this._HideOverlayOnUp = true;
        }
    }
};
	
//EPDZoomBox :: EndDraw :: ends the box draw
EPDZoomBox.prototype.EndDraw = function()
{
    if( this._ZBoxStart == null || typeof(this._ZBoxStart) == 'undefined')
        return;
		
    if( this._InZoom )
    {
        if( this._DrawableBounds.InBox( MOUSELOCATION_X, MOUSELOCATION_Y ) )
        {
	        //end the box and draw
	        this._InZoom = false;
	        //get the end of the box
	        this._ZBoxEnd = this._EPDMapObj.PixelToLatLong( new VEPixel(MOUSELOCATION_X - this._BorderWidth - this._EPDMapOffset.x, MOUSELOCATION_Y - this._BorderWidth - this._EPDMapOffset.y) );
	    			
	        //see if our points got inversed
	        if( this._ZBoxStart.latitude < this._ZBoxEnd.latitude )
	        {
		        var tempY = this._ZBoxStart.latitude;
		        this._ZBoxStart.latitude = this._ZBoxEnd.latitude;
		        this._ZBoxEnd.latitude = tempY;
	        }
			
	        if( this._ZBoxStart.longitude > this._ZBoxEnd.longitude )
	        {
		        var tempX = this._ZBoxStart.longitude;
		        this._ZBoxStart.longitude = this._ZBoxEnd.longitude;
		        this._ZBoxEnd.longitude = tempX;
	        }
			
	        //check our box size first
	        if( this._Width > 5 ||  this._Height > 5 )
	        {
		        //tell we are done
		        this._IsComplete = true;
				this._FinalLatLngBox = new VELatLongRectangle(this._ZBoxStart, this._ZBoxEnd);
	
	            //fire our down drawing event
                if( this.OnEndDraw != null )
                    this.OnEndDraw();
	        }
	        if( this._HideOverlayOnUp )
	            this.Overlay.style.display = "none";
        }
        //regardless on end fire our reset event (?) maybe we shouldn't
        this.Reset();
        //fire our reset event
        if(this.OnReset != null )
            this.OnReset();
    }
};

//EPDZoomBox :: RtnFinalLatLngBox :: returns the final box cords in pixel rectangle
EPDZoomBox.prototype.RtnFinalLatLngBox = function()
{
    return this._FinalLatLngBox;   
};

//EPDZoomBox :: Move :: handles move in the zoom tool
EPDZoomBox.prototype.Move = function() {
    //if(this.MClickEnabled && this._DrawableBounds.InBox( MOUSELOCATION_X, MOUSELOCATION_Y ))
    //document.body.style.cursor = "crosshair";
    //else
    //document.body.style.cursor = "default";

    if (!this._InZoom)
        return;

    if (this._ZBoxStart == null || typeof (this._ZBoxStart) == 'undefined')
        return;

    if (this._DrawableBounds.InBox(MOUSELOCATION_X, MOUSELOCATION_Y)) {

        //move our box
        var w = parseFloat(MOUSELOCATION_X) - parseFloat(this._ZStartBoxP.x);
        var h = parseFloat(MOUSELOCATION_Y) - parseFloat(this._ZStartBoxP.y);


        if (w < 0) $(this.ZoomBox).css({ left: (MOUSELOCATION_X - this._BorderWidth - this._DrawOffset.x) + "px" });
        this._Width = Math.abs(w);

        if ((this._Width - this._BorderWidth) > 0) $(this.ZoomBox).css({ width: (this._Width - this._BorderWidth) + "px" });


        //then set height 
        /*
        if (h < 0) {
        h = Math.abs(h);
        this.ZoomBox.style.top = (MOUSELOCATION_Y - this._BorderWidth - this._DrawOffset.y) + "px";
        }
        */

        if (h < 0) $(this.ZoomBox).css({ top: (MOUSELOCATION_Y - this._BorderWidth - this._DrawOffset.y) + "px" });
        this._Height = Math.abs(h);

        if ((this._Height - this._BorderWidth) > 0) $(this.ZoomBox).css({ height: (this._Height - this._BorderWidth) + "px" });
        /*
        if ((this._Height - this._BorderWidth) > 0) {
        this.ZoomBox.style.height = (this._Height - this._BorderWidth) + "px";

        }
        */
    }
    else {
        if (this._HideOverlayOnUp) $(this.Overlay).hide();
            //this.Overlay.style.display = "none";
        this.Reset();
        //fire our reset event
        if (this.OnReset != null) this.OnReset();
    }
};
//end --------- EPDZoomBox
 /// <reference path="../jquery-1.3.2.js"/>

/*  EPDPolyTool class
    by: randy bacon
    11/13/07
    poly draw tool and functions
*/    
var POLYICONSTART = null;
var POLYPNTRS = new Array();

function EPDPolyTool(overlayElem, mapObj, mapOffset, id)
{
    //private members
    this._StartIcon = null;
    this._IsComplete = false;
    this._PolyPoints = new Array();
    this._PolyAvailAt = 12;
    this._OverlayElem = overlayElem;
    this.Overlay = document.getElementById(this._OverlayElem);
    this._EPDMapObj = mapObj;
    this._EPDMapOffset = mapOffset;
    //set with AdjustLineDisplay
    this._Color = new VEColor(204,2,2,0.55); 
    this._LineWidth = 3;
    //public
    this.MaxPolyLength = 20; 
    //adjust if you change the poly img
    this._ImgOffset = new VEPixel(-8.5, -8.5); 
    //dito same as above
    this._FirstPointOffset = new VEPixel(2.5,2.5); 
    this._LinePointOffset = new VEPixel(0,0);
    
    //IE line offset fix
    if( navigator.appName == "Microsoft Internet Explorer")
        this._LinePointOffset = new VEPixel(this._LineWidth,this._LineWidth);
        
    this.ID = id; 
    //point for final on click YAR JS
    POLYPNTRS[this.ID] = this; 
    this._PolyLine = null;
      	
    //properies
    this.MClickEnabled = false;
    
    //events handlers
    this.OnDraw = null;
    this.OnFirstDraw = null;
    this.OnEndDraw = null;
    this.OnReset = null;
    
}

//EPDPolyTool :: WindowResize :: call when window is resized
EPDPolyTool.prototype.WindowResize = function(mapOffset) {
    this._EPDMapOffset = mapOffset;
}

//EPDPolyTool :: GetColor :: get the poly color
EPDPolyTool.prototype.GetColor = function()
{
    return this._Color;
};

//EPDPolyTool :: GetLineWidth :: get the line width
EPDPolyTool.prototype.GetLineWidth = function()
{
    return this._LineWidth;
};

//EPDPolyTool :: AdjustLineDisplay :: adjust the poly line attribute
EPDPolyTool.prototype.AdjustLineDisplay = function(veColorObj, lineWidth)
{
    if( veColorObj != null )
        this._Color = veColorObj;
    if( lineWidth != this._LineWidth)
        //IE line offset fix
        if( navigator.appName == "Microsoft Internet Explorer")
            this._LinePointOffset = new VEPixel(lineWidth,lineWidth);
    this._LineWidth = lineWidth;
};

//EPDPolyTool :: AttachsEHandlers :: add our event handler functions to our overlay
EPDPolyTool.prototype.AttachsEHandlers = function(DrawPoint, doubleclickh) {
    if (DrawPoint != null) $(this.Overlay).mousedown(DrawPoint);
    if (doubleclickh != null) $(this.Overlay).dblclick(doubleclickh);

    //$(document).mouseover(function() { if (document.body.style.cursor != "crosshair") { glWriteToDebug("crosshair"); document.body.style.cursor = "crosshair"; } });
    //$(document).mouseout(function() { document.body.style.cursor = "default"; });
};

//EPDPolyTool :: DoubleClick :: handler for our double click event
EPDPolyTool.prototype.DoubleClick = function()
{
	this.DrawPoint();
	if( this._PolyPoints.length > 2)
	{
		this.ClosePoly(false);			
	}
};

//EPDPolyTool :: Dispose :: dispose and clean up event handlers
EPDPolyTool.prototype.Dispose = function()
{
    //clear out other pointers
    POLYPNTRS.length = 0;
};

//EPDPolyTool :: RtnFinalPoints :: returns the final points in a VELatLong array
EPDPolyTool.prototype.RtnFinalPoints = function()
{
    if( this._PolyPoints != null )
    {
        var tmpLatLong = new Array();
        for(var i=0;i<this._PolyPoints.length;i++)
        {
            tmpLatLong.push(this._EPDMapObj.PixelToLatLong(this._PolyPoints[i]))
        }
        return tmpLatLong;
    }
    return this._PolyPoints;   
};

//EPDPolyTool :: PolyAvailAt :: returns the value for when available
EPDPolyTool.prototype.PolyAvailAt = function()
{
    return this._PolyAvailAt;   
};

//EPDPolyTool :: PolyIcon :: static method to return our start icon shape
EPDPolyTool.PolyIcon = function(vePixelObj, onclickstart)
{
    if( POLYICONSTART == null )
    {
        POLYICONSTART = document.createElement("div");
	    POLYICONSTART.className = "epdPolyStart";
	    POLYICONSTART.innerHTML = "<a href=\"javascript:" + onclickstart + ";\" ondblclick=\"return;\" style=\"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + IMAGEBASE_URL + "record_16.png');position:relative;width:16px;height:16px;display:inline-block;cursor:hand;\"><img src='" + IMAGEBASE_URL + "record_16.png' border=0 width=16 height=16 style=\"filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);\"></a>";
	    POLYICONSTART.style.left = vePixelObj.x + "px";
	    POLYICONSTART.style.top = vePixelObj.y + "px";
	    return POLYICONSTART;
    }
    else
    {
        POLYICONSTART.style.left = vePixelObj.x + "px";
	    POLYICONSTART.style.top = vePixelObj.y + "px";
        return POLYICONSTART;
    }
};

//EPDPolyTool :: PolyStartClick :: static used to get a pointer to the instance (not the best way JS sometimes stinks)
EPDPolyTool.PolyStartClick = function(plyPTRId)
{
    POLYPNTRS[plyPTRId].ClosePoly(true);
};

//EPDPolyTool :: ClosePoly :: finish drawing (or try to)
EPDPolyTool.prototype.ClosePoly = function(startclick)
{
    if( this._PolyPoints.length > 2)
    {
        this.RemoveStartIcon();
        this._IsComplete = true;
        this._RemovePolyShape();   
		if( startclick )
            this._PolyPoints.pop();            
        this._PolyPoints.push(this._PolyPoints[0]);
        if( this.OnEndDraw != null )
            this.OnEndDraw();         
    }
};

//EPDPolyTool :: DrawPoint :: do the drawing of the points
EPDPolyTool.prototype.DrawPoint = function()
{
    if( this.OnDraw != null )
        if( !this.OnDraw() )
            return;
            
    if( this._IsComplete )
    {
        //alert('is complete on draw point');
        return;
    }
    
    var thisPoint = new VEPixel(MOUSELOCATION_X - this._EPDMapOffset.x - this._LinePointOffset.x, MOUSELOCATION_Y - this._EPDMapOffset.y - this._LinePointOffset.y);
            
    if( this._PolyPoints.length >= this.MaxPolyLength)
    {
        alert('Please create a polygon with ' + this.MaxPolyLength + ' points or less.');
        if( this._PolyPoints[this._PolyPoints.length - 1].x != thisPoint.x || 
			this._PolyPoints[this._PolyPoints.length - 1].y != thisPoint.y )
            this._PolyPoints.push(thisPoint);
        this.ClosePoly(false);
        return;
    }
    
    //and now our map draw - see if we are adding a start point
    if( this._StartIcon == null )
    {
        thisPoint = new VEPixel(MOUSELOCATION_X - this._EPDMapOffset.x - this._FirstPointOffset.x, MOUSELOCATION_Y - this._EPDMapOffset.y - this._FirstPointOffset.y);
        //assume first draw
        if( this.OnFirstDraw != null )
            if( !this.OnFirstDraw() )
                return;
        //add our draw icon
        this._StartIcon = EPDPolyTool.PolyIcon(new VEPixel(MOUSELOCATION_X - this._EPDMapOffset.x + this._ImgOffset.x, MOUSELOCATION_Y - this._EPDMapOffset.y + this._ImgOffset.y), "EPDPolyTool.PolyStartClick(" + this.ID + ")");
        this.Overlay.appendChild(this._StartIcon);
    }
	else
	{
		//we are into it, see if last point was this point
		if( this._PolyPoints[this._PolyPoints.length - 1].x == thisPoint.x && 
			this._PolyPoints[this._PolyPoints.length - 1].y == thisPoint.y )
			return;
	}
    
    this._PolyPoints.push(thisPoint);
 
    if( this._PolyPoints.length > 1 )
        this._DrawPolyLines();   
};

//EPDPolyTool :: _RemovePolyShape:: method to remove poly shape if it is on the map
EPDPolyTool.prototype._RemovePolyShape = function()
{
    if( this._PolyLine != null )
    {
        this._EPDMapObj.DeleteShape(this._PolyLine);
        this._PolyLine = null;
    }
};

//EPDPolyTool :: IsInDraw :: method to see if we are in a draw
EPDPolyTool.prototype.IsInDraw = function()
{
    return this._PolyPoints.length > 0;
};

//EPDPolyTool :: _DrawPolyLines:: method to put our poly lines on the map
EPDPolyTool.prototype._DrawPolyLines = function()
{
    this._RemovePolyShape();
    
    var tmpLatsLongs = new Array();
    for(var i=0;i<this._PolyPoints.length;i++)
    {
        tmpLatsLongs.push(this._EPDMapObj.PixelToLatLong(this._PolyPoints[i]));
    }
    this._PolyLine = new VEShape(VEShapeType.Polyline, tmpLatsLongs);
    this._PolyLine.HideIcon();
    this._PolyLine.SetLineColor(this._Color);
    this._PolyLine.SetLineWidth(this._LineWidth);
	this._PolyLine.SetFillColor(new VEColor(255,255,255,0));
	this._EPDMapObj.AddShape(this._PolyLine);
};

//EPDPolyTool :: Reset:: method to reset this tool
EPDPolyTool.prototype.Reset = function()
{
    if( this.OnReset != null )
        if( !this.OnReset() )
            return;
    this._PolyPoints.length = 0;
    this.RemoveStartIcon();
    this._RemovePolyShape();
};

//EPDPolyTool :: RemoveStartIcon :: method to reset this tool
EPDPolyTool.prototype.RemoveStartIcon = function()
{
    if( this._StartIcon != null )
        this.Overlay.removeChild(this._StartIcon);
    this._StartIcon = null;
};

//EPDPolyTool :: PolyComplete :: return the complete member
EPDPolyTool.prototype.PolyComplete = function()
{
    return this._IsComplete;
};

//EPDPolyTool :: ResetComplete :: manually set the complete status
EPDPolyTool.prototype.ResetComplete = function(state)
{
    this._IsComplete = state;
};

//EPDPolyTool :: ClickSearchState :: enable/disable the click poly function
EPDPolyTool.prototype.ClickSearchState = function(polyOn)
{
    if(polyOn)
    {
        this.MClickEnabled = true;
        this.Overlay.style.display = "block";
    }
    else
    {
        this.MClickEnabled = false;
        this.Overlay.style.display = "none";
    }
};  

/// <reference path="../../jquery/jquery-1.3.2.js"/>


// EPDMapDVE.js : Microsft Virtual Earth library
// Separated to allow implementing other mapping systems

//epdGloGetObjectOffset :: returns the offset for a select object in VEPixel format (x,y)
function epdGloGetObjectOffset(refobj, useVEPixel) {
    //figure out y
    var y = refobj.offsetTop;
    var obj = refobj.offsetParent;
    while (obj != null) {
        y += obj.offsetTop;
        obj = obj.offsetParent;
    }
    //figure out x
    var x = refobj.offsetLeft;
    var obj = refobj.offsetParent;
    while (obj != null) {
        x += obj.offsetLeft;
        obj = obj.offsetParent;
    }
    //return vepixel point
    if (useVEPixel == null || useVEPixel)
        return new VEPixel(x, y);
    else
        return new Array(x, y);
}

// EPDVEMapTools
// Static enum wrapper for different mapping tools
function EPDVEMapTools() { }

EPDVEMapTools.Drag = 0;
EPDVEMapTools.Draw = 1;
EPDVEMapTools.Poly = 2;
EPDVEMapTools.Clear = 3;
// end EPDVEMapTools

var glEPDOBJs = new Array();

// EPDVEMap
// Virtual Earth map wrapper
function EPDVEMap(mapId, startlat, startlong, startzoom, resetlat, resetlong, resetzoom, zoomBoxDiv, zoomBoxOverlayDiv, polyOverlayDiv, searchHideOverlayDiv)
{
    //members
    glEPDOBJs[0] = this;
	this._LineColor = new VEColor(255,0,0,0.75);
	this._LineWidth = 3;
    this._LBMapModeId = "lbMapMode";
    this._Polybounds = new Array();
    this._IsPolyComplete = false;
    this.MapDrawLayer = null;
    this.SelectedTool = null;
    this.PrevTool = null;
    this.ShapeDrawLayer = null;
    this.InSearch = false;
    this._MapPixelBounds = null;
    this._PanStarted = false;
    this._BVersion = navigator.appVersion.split("MSIE");
    if(this._BVersion.length > 1)
        this._BVersionNum = parseFloat(this._BVersion[1]);
    else
        this._BVersionNum = null;
    
    //ve items
    this._HideSearchOverlay = document.getElementById(searchHideOverlayDiv);
    this._EPDVEMapDivId = mapId;
    this._EPDVEMapObj = new VEMap(this._EPDVEMapDivId);	
            
    this._InitStartPoint = new VELatLong(startlat, startlong);
    this._InitZoom = startzoom;

    this._ResetStartPoint = new VELatLong(resetlat, resetlong);
    this._ResetZoom = resetzoom;

    //set up map params
    this._MapParams = new EPDMapParams(null, null, null);
    this._MapParams.OnChangeValues = function(){glFindEPDMapObj().MapParamsChanged();};
    this._PrevMapParams = new EPDMapParams(null, null, null);
          
    this._EPDVEMapObj.LoadMap(this._InitStartPoint, this._InitZoom);
	this._EPDVEMapObj.HideDashboard();
	//we are using custom styles
	this._EPDVEMapObj.ClearInfoBoxStyles();
		
	
	//set up our tools
	var tmpMapOffset = epdGloGetObjectOffset(document.getElementById(this._EPDVEMapDivId));
    var tmpPoints = this._EPDVEMapObj.LatLongToPixel(this._EPDVEMapObj.GetMapView().BottomRightLatLong);
    this._MapPixelBounds = new EPDPixelRectangle(tmpMapOffset.x, tmpMapOffset.y, tmpMapOffset.x + tmpPoints.x, tmpMapOffset.y + tmpPoints.y);

    var tmpDrawOff = new VEPixel(tmpMapOffset.x, tmpMapOffset.y);
    
    //create our zoom box
    this._EPDZoomBoxObj = new EPDZoomBox(zoomBoxDiv, zoomBoxOverlayDiv, this._MapPixelBounds, this._EPDVEMapObj, tmpMapOffset, tmpDrawOff);
    this._EPDZoomBoxObj.OnStartDraw = function(){return glFindEPDMapObj().StartZoomDraw();};
    this._EPDZoomBoxObj.OnEndDraw = function(){glFindEPDMapObj().EndZoomDraw();};
    //this._EPDZoomBoxObj.OnKeyUp = function(){CropReset();return true;};
    //this._EPDZoomBoxObj.OnKeyDown = function(){CropReset();return true;};
    this._EPDZoomBoxObj.AttachsEHandlers(function(){glFindEPDMapObj().ZoomBoxObj().StartDraw();}, function(){glFindEPDMapObj().ZoomBoxObj().Move();},  function(){glFindEPDMapObj().ZoomBoxObj().EndDraw();}, function(){glFindEPDMapObj().ZoomBoxObj().KeyUp();}, function(){glFindEPDMapObj().ZoomBoxObj().KeyDown();});
 
    //create our poly box
    this._EPDPolyToolObj = new EPDPolyTool(polyOverlayDiv, this._EPDVEMapObj, tmpMapOffset, 0);
    this._EPDPolyToolObj.AttachsEHandlers(function(){glFindEPDMapObj().PolyObj().DrawPoint();}, function(){glFindEPDMapObj().PolyObj().DoubleClick();});
    this._EPDPolyToolObj.OnFirstDraw = function(){return glFindEPDMapObj().PolyFirstDraw();};
    this._EPDPolyToolObj.OnEndDraw = function(){return glFindEPDMapObj().PolyEndDraw();};
    this._EPDPolyToolObj.AdjustLineDisplay(this._LineColor, this._LineWidth);	    
    
    //create our search params or q string or is this outside the obj?

    //bind our map event handlers

    this._EPDVEMapObj.AttachEvent("onendzoom", function(){glFindEPDMapObj()._PanStarted = false;glFindEPDMapObj().ZoomEndE();});
    this._EPDVEMapObj.AttachEvent("onendpan", function(){glFindEPDMapObj()._PanStarted = false;glFindEPDMapObj().PanEndE();});
    //attach our marker events AFTER map click
    this._EPDVEMapObj.AttachEvent("onstartpan", function(){glFindEPDMapObj()._PanStarted = true;EPDMarkerHelper.HideMarkerDetail();});
    this._EPDVEMapObj.AttachEvent("onstartzoom", EPDMarkerHelper.HideMarkerDetail);


    //event handlers
    this.OnPolyAvailChange = null;
    this.OnLineCompleteChange = null;
    this.OnMapParamsChanged = null;
    this.OnSelectedToolChanged = null;
	
	//any random reset here
	document.getElementById(this._LBMapModeId).selectedIndex = 0;
	
	//public props
	this.IsPolyEnabled = false;
	this.HasBoundingLines = false;
	this.HasResults = false;
	
	//internal
	this._iListingCenterPop = null;
	
	//init our markers
	EPDMarkerHelper.Init(this._EPDVEMapObj);

}

//EPDVEMap :: WindowResize :: update the saved bounding container info when window resized
EPDVEMap.prototype.WindowResize = function() {
    var tmpMapOffset = epdGloGetObjectOffset(document.getElementById(this._EPDVEMapDivId));
    var tmpPoints = this._EPDVEMapObj.LatLongToPixel(this._EPDVEMapObj.GetMapView().BottomRightLatLong);
    this._MapPixelBounds = new EPDPixelRectangle(tmpMapOffset.x, tmpMapOffset.y, tmpMapOffset.x + tmpPoints.x, tmpMapOffset.y + tmpPoints.y);

    var tmpDrawOff = new VEPixel(tmpMapOffset.x, tmpMapOffset.y);

    //update zoom box object
    this._EPDZoomBoxObj.WindowResize(this._MapPixelBounds, tmpMapOffset, tmpDrawOff);
    this._EPDPolyToolObj.WindowResize(tmpMapOffset);
};


//EPDVEMap :: GetWidth :: get the map width in pixels
EPDVEMap.prototype.GetWidth = function()
{
    return this._MapPixelBounds.GetRightBottom().x;
};

//EPDVEMap :: GetHeight :: get the map height in pixels
EPDVEMap.prototype.GetHeight = function()
{
    return this._MapPixelBounds.GetRightBottom().y;
};

//EPDVEMap :: ShowMarkerBubble :: show the marker bubble on the map
EPDVEMap.prototype.ShowMarkerBubble = function(listingId)
{
    var tmpKey = this.MarkerKeyByListingId(listingId);
    if(tmpKey != "")
    {
        var markerPoint = EPDMarkerHelper.ReturnMarkerObj(tmpKey).GetVEShape().GetPoints()[0];
        //if we a box try to center the map
        if( this.HasBoundingLines && !this.PointOnMapWPixelPadding(markerPoint, 24))
        {
            this._EPDVEMapObj.SetCenter(markerPoint);
            //use pan end to show our point
            if(this._PanStarted) 
            {
                //this._iListingCenterPop = listingId; //pan way - appears faster in IE?
                //following is "trick" zoom to get the map to "snap" to position
                EPDMarkerHelper.HideMarkerDetail();
                var tmpZoom = this._EPDVEMapObj.GetZoomLevel();
                this._EPDVEMapObj.SetZoomLevel(1);
                this._EPDVEMapObj.SetCenterAndZoom(markerPoint,tmpZoom);
                EPDMarkerHelper.glEPDShowMarkerDetails(tmpKey, EPDMarkerHelper.ReturnMarkerObj(tmpKey).FindLIndex(listingId));
            }
            else
                EPDMarkerHelper.glEPDShowMarkerDetails(tmpKey, EPDMarkerHelper.ReturnMarkerObj(tmpKey).FindLIndex(listingId));
        }
        else
        {
            //just show the bubble 
            EPDMarkerHelper.glEPDShowMarkerDetails(tmpKey, EPDMarkerHelper.ReturnMarkerObj(tmpKey).FindLIndex(listingId));
        }
           
    }
};

//EPDVEMap :: PointOnMapWPixelPadding :: return true if point is shown on the map with a given amount of pixel padding
EPDVEMap.prototype.PointOnMapWPixelPadding = function(latLongPoint, pixelPadding)
{
    var tmpRect = this.BoundingBoxWPixelPadding(pixelPadding);
    //check points against our bounds box
	if( latLongPoint.Latitude < tmpRect.TopLeftLatLong.Latitude && latLongPoint.Latitude > tmpRect.BottomRightLatLong.Latitude && latLongPoint.Longitude > tmpRect.TopLeftLatLong.Longitude && latLongPoint.Longitude < tmpRect.BottomRightLatLong.Longitude)
        return true;	
    return false;
};

//EPDVEMap :: BoundingBoxWPixelPadding :: return a VELatLongRectangle with a pixel padding
EPDVEMap.prototype.BoundingBoxWPixelPadding = function(pixelPadding)
{
    var btmRightPix = this._EPDVEMapObj.LatLongToPixel(this._EPDVEMapObj.GetMapView().BottomRightLatLong);
    var tpLeftPix = this._EPDVEMapObj.LatLongToPixel(this._EPDVEMapObj.GetMapView().TopLeftLatLong);
    btmRightPix.x = btmRightPix.x - pixelPadding;
    btmRightPix.y = btmRightPix.y - pixelPadding;
    tpLeftPix.x = tpLeftPix.x + pixelPadding;
    tpLeftPix.y = tpLeftPix.y + pixelPadding;
    return new VELatLongRectangle(this._EPDVEMapObj.PixelToLatLong(tpLeftPix), this._EPDVEMapObj.PixelToLatLong(btmRightPix), null, null);
};

//EPDVEMap :: MarkerKeyByListingId :: see if I have a marker via a listing ID and return key if found
EPDVEMap.prototype.MarkerKeyByListingId = function(listingId)
{
    if( EPDMapSearchHelper.Listings[listingId] != null)
    {
        var tmpKey = EPDMapSearchHelper.Listings[listingId].Latitude + "~" + EPDMapSearchHelper.Listings[listingId].Longitude;
        if( EPDMarkerHelper.HasMarker(tmpKey) )
            return tmpKey;
    }
    return "";
};

//EPDVEMap :: OnSearchStart :: handle the start of the search request
EPDVEMap.prototype.OnSearchStart = function() {
    this.InSearch = true;

    this.PrevTool = this.SelectedTool;
    if (this.SelectedTool != EPDVEMapTools.Drag)
        this.SelectTool(EPDVEMapTools.Drag);


    //$(this._HideSearchOverlay).show();
    $(this._HideSearchOverlay).css({ display: "block" });
    //this._HideSearchOverlay.style.display = "block";

    EPDMarkerHelper.HideMarkerDetail();
};

//EPDVEMap :: _DrawResultPoints :: draw the markers on the map
EPDVEMap.prototype._DrawResultPoints = function()
{
    this.ClearShapeDrawLayer();
    
    if( EPDMapSearchHelper.Listings.length > 0 )
    {		
        this.ShapeDrawLayer = new VEShapeLayer();
        this._EPDVEMapObj.AddShapeLayer(this.ShapeDrawLayer);
        
        //clear out old markers
        EPDMarkerHelper.ClearMarkers();
                    
        for(var keyVar in EPDMapSearchHelper.Listings)
        {            
            var tmpKey = EPDMapSearchHelper.Listings[keyVar].Latitude + "~" + EPDMapSearchHelper.Listings[keyVar].Longitude;
           
            if( !EPDMarkerHelper.HasMarker(tmpKey) )
            {
                var ghMarker = new EPDMarker(new VELatLong(EPDMapSearchHelper.Listings[keyVar].Latitude, EPDMapSearchHelper.Listings[keyVar].Longitude), tmpKey);
                //IE check for png trans
                if( this._BVersionNum != null && this._BVersionNum < 7 ) 
                {
                    ghMarker.SetIcon("<img src='" + IMAGEBASE_URL + "spacer.gif' border=0 width=22 height=24 style=\"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + IMAGEBASE_URL + EPDIconHelper.FindIcon(EPDMapSearchHelper.Listings[keyVar].SpaceType) + "');position:relative;width:22px;height:24px;display:inline-block;cursor:hand;\">");
                }
                else
                {
                    ghMarker.SetIcon("<img src='" + IMAGEBASE_URL + EPDIconHelper.FindIcon(EPDMapSearchHelper.Listings[keyVar].SpaceType) + "' border=0 width=22 height=24 style='cursor:hand'>");
                }
                ghMarker.SetAnchorOffset(-4,15);	                
                ghMarker.AddMarker();
                this.ShapeDrawLayer.AddShape(ghMarker.GetVEShape());	
            }
            //push listing on marker stack
            EPDMarkerHelper.ReturnMarkerObj(tmpKey).AddListing(EPDMapSearchHelper.Listings[keyVar]);
        }
        this.HasResults = true;
    }        
};

//EPDVEMap :: OnSearchEnd :: handle the end of the search request
EPDVEMap.prototype.OnSearchEnd = function(searchResultCount)
{
    EPDMarkerHelper.HideMarkerDetail();    
    
    this.HasResults = false;
    if( searchResultCount > 0 )
    {
        this._DrawResultPoints();
    }
    else if( searchResultCount == 0 )
        this.ClearShapeDrawLayer();
    
    
    if( EPDMapSearchHelper.Listings.length == 0 )
    {
        if(this.SelectedTool != this.PrevTool)
        {
            this.SelectTool(this.PrevTool);
            this.PrevTool = this.SelectTool;
        }
    }
    
    if(this.SelectTool != this.PrevTool)
    {
        if(this.OnSelectedToolChanged != null )
            this.OnSelectedToolChanged();
        this.PrevTool = this.SelectTool;
    }

    //$(this._HideSearchOverlay).hide();
    $(this._HideSearchOverlay).css({ display: "none" });

    //this._HideSearchOverlay.style.display = "none";
    
    this.InSearch = false;
};

//EPDVEMap :: ClearShapeDrawLayer :: call when you are all set up and ready to roll
EPDVEMap.prototype.ClearShapeDrawLayer = function()
{
    if( this.ShapeDrawLayer != null )
    {
        this._EPDVEMapObj.DeleteShapeLayer(this.ShapeDrawLayer);
        this.ShapeDrawLayer = null;
    }
};

//EPDVEMap :: LoadComplete :: call when you are all set up and ready to roll
EPDVEMap.prototype.LoadComplete = function()
{
    this._MapParams.UpdateValues(this._InitZoom, this._InitStartPoint, this._EPDVEMapObj.GetMapView(), null, "LoadComplete");
};

//EPDVEMap :: MapParamsChanged :: handle the map params event changed
EPDVEMap.prototype.MapParamsChanged = function()
{
    if(EPDD!= null) EPDD.MPC(EPDVEMAPOBJ.GetMapParams());
    //do work - //we ignore clear poly events
    if( this._MapParams.LastSender != "ClearPoly" ) 
    {
        if( !this._MapParams.CompareValues(this._PrevMapParams) )
        {
            //reset prev vals
            this._PrevMapParams.PopulateVals(this._MapParams);
            if(EPDD!= null) EPDD.PU();
            //update our event if we need to
            if( this.OnMapParamsChanged != null )
                this.OnMapParamsChanged();
        }
        else if (EPDD!= null) EPDD.PI();
    }
};

//EPDVEMap :: GetMapParams :: return the map params obj
EPDVEMap.prototype.GetMapParams = function()
{
    return this._MapParams;
};

//EPDVEMap :: ZoomEndE :: handle the zoom end event
EPDVEMap.prototype.ZoomEndE = function()
{
    //update our map params
    this._MapParams.UpdateValues(this._EPDVEMapObj.GetZoomLevel(), this._EPDVEMapObj.GetCenter(), this._EPDVEMapObj.GetMapView(), null, "ZoomEndE");
    
    //poly state handling
    var alertPoly = false;
    if( this._EPDPolyToolObj.PolyAvailAt() <= this._EPDVEMapObj.GetZoomLevel() && !this.IsPolyEnabled )
    {
        this.IsPolyEnabled = true;
        alertPoly = true;                
    }
    else if( this._EPDPolyToolObj.PolyAvailAt() > this._EPDVEMapObj.GetZoomLevel()&& this.IsPolyEnabled )
    {
        this.IsPolyEnabled = false;
        alertPoly = true; 
    }
    if( alertPoly && this.OnPolyAvailChange != null )
    {
        this.OnPolyAvailChange();
    }  
    
    if( this.HasBoundingLines && EPDMapSearchHelper.Listings.length > 0 )
    {
        //EPDMarkerHelper.HideMarkerDetail();
        this._DrawResultPoints();        
    }
};  

//EPDVEMap :: PanEndE :: handle the pan end event
EPDVEMap.prototype.PanEndE = function()
{
    this._MapParams.UpdateValues(this._EPDVEMapObj.GetZoomLevel(), this._EPDVEMapObj.GetCenter(), this._EPDVEMapObj.GetMapView(), null, "PanEndE");
    //see if we are on the end of a show on map bubble pan
    if( this._iListingCenterPop != null )
    {
        var tmpKey = this.MarkerKeyByListingId(this._iListingCenterPop);
        if(tmpKey != "")
        {
            EPDMarkerHelper.glEPDShowMarkerDetails(tmpKey, EPDMarkerHelper.ReturnMarkerObj(tmpKey).FindLIndex(this._iListingCenterPop));          
        }
        //reset listing center pop
        this._iListingCenterPop = null;        
    }
};

//EPDVEMap instance helper
function glFindEPDMapObj()
{
    return glEPDOBJs[0];
};

//EPDVEMap :: ZoomBoxObj :: return our zoom box obj
EPDVEMap.prototype.ZoomBoxObj = function()
{
    return this._EPDZoomBoxObj;
};

//EPDVEMap :: PolyObj :: return our poly obj
EPDVEMap.prototype.PolyObj = function()
{
    return this._EPDPolyToolObj;
};

//EPDVEMap :: SelectTool :: method to select a specific tool
EPDVEMap.prototype.SelectTool = function(toolId)
{
    if( !MAPISINIT || (!this.IsPolyEnabled && toolId == EPDVEMapTools.Poly) || (!this.HasBoundingLines && toolId == EPDVEMapTools.Clear) )
        return false;
    if( toolId == EPDVEMapTools.Clear )
    {
        EPDMarkerHelper.HideMarkerDetail();
        this.ClearPoly(true);
        return true;
    }
    
    //select map tool based on selection
    if( toolId == EPDVEMapTools.Draw )
        this._EPDZoomBoxObj.ClickSearchState(true);
    else
    {
        this._EPDZoomBoxObj.Reset();
        this._EPDZoomBoxObj.ClickSearchState(false);        
    }

    if( toolId == EPDVEMapTools.Poly )
        this._EPDPolyToolObj.ClickSearchState(true);
    else
    {
        //we assume we are done with the poly draw and nuke any hanging points
        this._EPDPolyToolObj.Reset();
        this._EPDPolyToolObj.ResetComplete(false);
        this._EPDPolyToolObj.ClickSearchState(false);
    }
    
    this.SelectedTool = toolId;

    return true;
};

//EPDVEMap :: StartZoomDraw :: method fired on start zoom box draw
EPDVEMap.prototype.StartZoomDraw = function()
{
    EPDMarkerHelper.HideMarkerDetail();
    
    if( this.InSearch )
        return false;
    //put in alert for poly here based on this._IsPolyComplete && has listings?
    
    //then clear the poly box
    this.ClearPoly(false);
    
    return true;
};

//EPDVEMap :: ClearLines :: method clear out our lines
EPDVEMap.prototype.ClearPoly = function(wasClearLines)
{
    this._IsPolyComplete = false;
    
    if( this.MapDrawLayer != null )
		this._EPDVEMapObj.DeleteShapeLayer(this.MapDrawLayer);
    
    this.MapDrawLayer = null;
    this._Polybounds.length = 0;
    
    //update our map params
    this._MapParams.UpdateValues(this._EPDVEMapObj.GetZoomLevel(), this._EPDVEMapObj.GetCenter(), this._EPDVEMapObj.GetMapView(), this._Polybounds, wasClearLines ? "ClearLines" : "ClearPoly");
    
    this.HasBoundingLines = false;
    
    //fire on line complete event
    if( this.OnLineCompleteChange != null )
        this.OnLineCompleteChange();
};

//EPDVEMap :: SetPoly :: preset poly bounds for postback or restoring search
EPDVEMap.prototype.SetPoly = function(polybounds) {
    if (EPDD != null) EPDD.WR("SetPoly");
    this._IsPolyComplete = false;

    if (this.MapDrawLayer != null)
        this._EPDVEMapObj.DeleteShapeLayer(this.MapDrawLayer);

    this.MapDrawLayer = null;
    this._Polybounds = polybounds;

    this._MapParams.UpdateValues(null, null, null, this._Polybounds, null);

    this.HasBoundingLines = false;


    //fire on line complete event
    if (this.OnLineCompleteChange != null)
        this.OnLineCompleteChange();

    this._DrawComplete();
    if (EPDD != null) EPDD.WR("SetPoly complete");
};

//EPDVEMap :: EndZoomDraw :: method fired on end zoom box draw
EPDVEMap.prototype.EndZoomDraw = function()
{
    this._Polybounds.length = 0;
    this._Polybounds.push(this._EPDZoomBoxObj.RtnFinalLatLngBox().TopLeftLatLong);
    this._Polybounds.push(new VELatLong(this._EPDZoomBoxObj.RtnFinalLatLngBox().TopLeftLatLong.Latitude, this._EPDZoomBoxObj.RtnFinalLatLngBox().BottomRightLatLong.Longitude));
    this._Polybounds.push(this._EPDZoomBoxObj.RtnFinalLatLngBox().BottomRightLatLong);
    this._Polybounds.push(new VELatLong(this._EPDZoomBoxObj.RtnFinalLatLngBox().BottomRightLatLong.Latitude, this._EPDZoomBoxObj.RtnFinalLatLngBox().TopLeftLatLong.Longitude));
    this._Polybounds.push(this._EPDZoomBoxObj.RtnFinalLatLngBox().TopLeftLatLong);
    
    //done finish our draw
    this._DrawComplete();
};

//EPDVEMap :: _DrawComplete :: shared between poly drawers to finish up drawing tasks
EPDVEMap.prototype._DrawComplete = function()
{
    //draw lines
    this.DrawBox();
    
    this.HasBoundingLines = true;
    
    //fire on line complete event
    if( this.OnLineCompleteChange != null )
        this.OnLineCompleteChange();
    
    //center and zoom map
    this._EPDVEMapObj.SetMapView(this._Polybounds);
    
    //update our map params
    this._MapParams.UpdateValues(this._EPDVEMapObj.GetZoomLevel(), this._EPDVEMapObj.GetCenter(), this._EPDVEMapObj.GetMapView(), this._Polybounds, "_DrawComplete");
};

//EPDVEMap :: DrawBox :: method fired on end zoom box draw
EPDVEMap.prototype.DrawBox = function()
{
    //clear out our shape drawing layer
	if( this.MapDrawLayer != null )
	{
		this._EPDVEMapObj.DeleteShapeLayer(this.MapDrawLayer);
	}
    
    if( this._Polybounds != null )
    {
        //create our new shape
        var tmpShape = new VEShape(VEShapeType.Polyline, this._Polybounds);
        tmpShape.HideIcon();
        tmpShape.SetLineColor(this._LineColor);
        tmpShape.SetLineWidth(this._LineWidth);
        tmpShape.SetFillColor(new VEColor(255,255,255,0));	
	    //shape layer here
	    this.MapDrawLayer = new VEShapeLayer();
	    this._EPDVEMapObj.AddShapeLayer(this.MapDrawLayer);
	    this.MapDrawLayer.AddShape(tmpShape); 
	}
};

//EPDVEMap :: PolyFirstDraw :: method fired on start poly draw
EPDVEMap.prototype.PolyFirstDraw = function()
{
    EPDMarkerHelper.HideMarkerDetail();
    this.ClearPoly(false);
    return true;
};

//EPDVEMap :: PolyEndDraw :: method fired on end poly draw
EPDVEMap.prototype.PolyEndDraw = function()
{
    this._Polybounds.length = 0;
    this._Polybounds = this._EPDPolyToolObj.RtnFinalPoints();
    
    //say we have a complete poly
    this._IsPolyComplete = false;
    
    //done finish our draw
    this._DrawComplete();
    
    //tell poly tool you can draw again
    this._EPDPolyToolObj.Reset();
    this._EPDPolyToolObj.ResetComplete();
};

//EPDVEMap :: ResetToInit :: reset the map to init state
EPDVEMap.prototype.ResetToInit = function(isZoomIn) {
    this.ClearPoly(false);
    this._EPDVEMapObj.SetCenterAndZoom(this._ResetStartPoint, this._ResetZoom);
};

//EPDVEMap :: ZoomMap :: handle the map zoom in/out requests
EPDVEMap.prototype.ZoomMap = function(isZoomIn)
{
    //reset our poly draw to avoid weirdness
    if( this._EPDPolyToolObj.IsInDraw() ) 
        this._EPDPolyToolObj.Reset();
    isZoomIn ? this._EPDVEMapObj.ZoomIn() : this._EPDVEMapObj.ZoomOut();
};

//EPDVEMap :: ChangeType :: change the map type
EPDVEMap.prototype.ChangeType = function()
{
    switch(document.getElementById(this._LBMapModeId).selectedIndex)
	{
		case 0:
			this._EPDVEMapObj.SetMapStyle(VEMapStyle.Road);
			break;
		case 1:
			this._EPDVEMapObj.SetMapStyle(VEMapStyle.Aerial);
			break;
		case 2:
			this._EPDVEMapObj.SetMapStyle(VEMapStyle.Hybrid);
			break;
	}
};

//EPDVEMap :: Dispose :: dispose and clean up event handlers
EPDVEMap.prototype.Dispose = function()
{
    if( this._EPDZoomBoxObj != null )
        this._EPDZoomBoxObj.Dispose();
    if( this._EPDPolyToolObj != null )
        this._EPDPolyToolObj.Dispose();
    if( this._EPDVEMapObj != null )
        this._EPDVEMapObj.Dispose();
    glEPDOBJs.length = 0;
};
/* EPDIconHelper
by: randy bacon
12/04/07
help determine icon for a prop cat - static only
*/
function EPDIconHelper() { }

EPDIconHelper.FindIcon = function(spaceType) {
    //office
    if (spaceType == 2)
        return "icons/epdO.png";
    //industrail
    if (spaceType == 3)
        return "icons/epdI.png";
    //retail
    if (spaceType == 1)
        return "icons/epdR.png";
    //land
    if (spaceType == 6)
        return "icons/epdL.png";
    //multi
    if (spaceType == 4)
        return "icons/epdMF.png";
    //hotel / motel
    if (spaceType == 5)
        return "icons/epdHM.png";
    //farm
    if (spaceType == 7)
        return "icons/epdF.png";
    //mobile home park
    if (spaceType == 8)
        return "icons/epdMH.png";
    //"specialty" is default
    return "icons/epdS.png";
};



/* ===== START EPDMarkerHelper ===== */

/*  EPDMarkerHelper class
by: randy bacon
11/09/07
Static only method to help with marker functions and handling (more like google)
*/
function EPDMarkerHelper(){};

//EPDMarkerHelper :: Init :: static - set me up for some use
EPDMarkerHelper.Init = function(mapObj)
{
	this.MarkerGUIDHash = new Array();
	this.EPDMarkerDivO = document.getElementById("epdMapBubbleContainer");
	this.EPDMarkerBGDivO = document.getElementById("epdMapBubbleBG");
	this.EPDMarkerHTMLDivO = document.getElementById("epdMapBubbleCon");
	this.EPDMBTOPOFF = -6;
	this.EPDMBLOFF = 0;
	this.EPDMBWidth = 285;
	this.EPDMBHeight = 100;
	this.EPDMBBOTTMOFF = -26;
	this.EPDMapObj = mapObj;
};

//EPDMarkerHelper :: HideMarkerDetail :: hides our marker details
EPDMarkerHelper.HideMarkerDetail = function(e)
{
	EPDMarkerHelper.glEPDHideMarkerDetails();
};

//EPDMarkerHelper :: FindPosition :: find the position of the bubble
EPDMarkerHelper.FindPosition = function(markerXY) {
    //default to right top
    var pos = 1;
    var rtnPixelPoint;
    var mapRightBottom = this.EPDMapObj.LatLongToPixel(this.EPDMapObj.GetMapView().BottomRightLatLong);

    //alert( ( markerXY.x + EPDMarkerHelper.EPDMBWidth) + " and bounds x " + mapRightBottom.x + " y width " + (markerXY.y + EPDMarkerHelper.EPDMBHeight) + " and bounds y " + mapRightBottom.y);

    //right top default
    if ((markerXY.x + EPDMarkerHelper.EPDMBWidth) < mapRightBottom.x && (markerXY.y + EPDMarkerHelper.EPDMBHeight) < mapRightBottom.y) {
        pos = 1;
        rtnPixelPoint = new VEPixel((markerXY.x + EPDMarkerHelper.EPDMBLOFF), (markerXY.y - EPDMarkerHelper.EPDMBTOPOFF));
    }
    //left top
    else if ((markerXY.x + EPDMarkerHelper.EPDMBWidth) > mapRightBottom.x && (markerXY.y + EPDMarkerHelper.EPDMBHeight) < mapRightBottom.y) {
        pos = 2;
        rtnPixelPoint = new VEPixel((markerXY.x - EPDMarkerHelper.EPDMBLOFF - EPDMarkerHelper.EPDMBWidth), (markerXY.y - EPDMarkerHelper.EPDMBTOPOFF));
    }
    //right bottom
    else if ((markerXY.x + EPDMarkerHelper.EPDMBWidth) < mapRightBottom.x && (markerXY.y + EPDMarkerHelper.EPDMBHeight) > mapRightBottom.y) {
        pos = 3;
        rtnPixelPoint = new VEPixel((markerXY.x + EPDMarkerHelper.EPDMBLOFF), (markerXY.y - EPDMarkerHelper.EPDMBTOPOFF + EPDMarkerHelper.EPDMBBOTTMOFF));
    }
    //left bottom
    else {
        pos = 4;
        rtnPixelPoint = new VEPixel((markerXY.x - EPDMarkerHelper.EPDMBLOFF - EPDMarkerHelper.EPDMBWidth), (markerXY.y - EPDMarkerHelper.EPDMBTOPOFF + EPDMarkerHelper.EPDMBBOTTMOFF));
    }

    var rtnArray = new Array();
    rtnArray[0] = rtnPixelPoint;
    rtnArray[1] = pos;
    return rtnArray;
};

//EPDMarkerHelper.BubbleNextButton :: put the next on the bubble for more then one item
EPDMarkerHelper.BubbleNextButton = function()
{
	return "<div class=\"epdMapBubbleNextProperty\"><a href=\"javascript:EPDMarkerHelper.MoveNextItem();\" onmouseover='window.status=\"\";'><img src=\"" + IMAGEBASE_URL + "spacer.gif\" class=\"epdMapBubbleNextPropertyImage\"></a></div>";
};

//EPDMarkerHelper.MoveNextItem :: handle the more then one item next click
EPDMarkerHelper.MoveNextItem = function()
{
	if( EPDMarkerHelper.SelectedGUID != null && EPDMarkerHelper.SelectedGUID != "" )
	{
        EPDMarkerHelper.SelectedIndex = this.MarkerGUIDHash[EPDMarkerHelper.SelectedGUID].RtnNextListingIndex(EPDMarkerHelper.SelectedIndex);
        this.EPDMarkerHTMLDivO.innerHTML = glFormatListingHTML(this.MarkerGUIDHash[EPDMarkerHelper.SelectedGUID].RtnListing(EPDMarkerHelper.SelectedIndex), EPDMarkerHelper.SelectedIndex, this.MarkerGUIDHash[EPDMarkerHelper.SelectedGUID].ListingsC);
	}
};

//EPDMarkerHelper :: RtnBackgroundDiv :: find the background of the bubble
EPDMarkerHelper.RtnBackgroundDiv = function(pos, itemCount)
{
	if( itemCount > 1 )
		pos *= 10;
	switch(pos)
	{
		case 20:
			return EPDMarkerHelper.BubbleNextButton() + "<div class=\"epdMapBubbleBottomLeftNext\"><img src=\"" + IMAGEBASE_URL + "epdMapBubbleBottomLeftNext.png\" width=\"281\" height=\"84\" border=\"0\" style=\"width: 281px;\"></div>";
		case 2:
			return "<div class=\"epdMapBubbleBottomLeft\"><img src=\"" + IMAGEBASE_URL + "epdMapBubbleBottomLeft.png\" width=\"281\" height=\"84\" border=\"0\" style=\"width: 281px;\"></div>";
		case 30:
			return EPDMarkerHelper.BubbleNextButton() + "<div class=\"epdMapBubbleTopRightNext\"><img src=\"" + IMAGEBASE_URL + "epdMapBubbleTopRightNext.png\" width=\"281\" height=\"84\" border=\"0\" style=\"width: 281px;\"></div>";
		case 3:
			return "<div class=\"epdMapBubbleTopRight\"><img src=\"" + IMAGEBASE_URL + "epdMapBubbleTopRight.png\" width=\"281\" height=\"84\" border=\"0\" style=\"width: 281px;\"></div>";
		case 40:
			return EPDMarkerHelper.BubbleNextButton() + "<div class=\"epdMapBubbleTopLeftNext\"><img src=\"" + IMAGEBASE_URL + "epdMapBubbleTopLeftNext.png\" width=\"281\" height=\"84\" border=\"0\" style=\"width: 281px;\"></div>";
		case 4:
			return "<div class=\"epdMapBubbleTopLeft\"><img src=\"" + IMAGEBASE_URL + "epdMapBubbleTopLeft.png\" width=\"281\" height=\"84\" border=\"0\" style=\"width: 281px;\"></div>";
		case 10:
			return EPDMarkerHelper.BubbleNextButton() + "<div class=\"epdMapBubbleBottomRightNext\"><img src=\"" + IMAGEBASE_URL + "epdMapBubbleBottomRightNext.png\" width=\"281\" height=\"84\" border=\"0\" style=\"width: 281px;\"></div>";
	    //this is 1		
		default: 
			return "<div class=\"epdMapBubbleBottomRight\"><img src=\"" + IMAGEBASE_URL + "epdMapBubbleBottomRight.png\" width=\"281\" height=\"84\" border=\"0\" style=\"width: 281px;\"></div>";
	}
};

EPDMarkerHelper.SelectedGUID = "";
EPDMarkerHelper.SelectedIndex = 0;

//EPDMarkerHelper :: glEPDShowMarkerDetails :: static - show a marker details by id
EPDMarkerHelper.glEPDShowMarkerDetails = function(markerGUID, lIndex)
{
	if( this.MarkerGUIDHash[markerGUID] != null)
	{
	    EPDMarkerHelper.SelectedGUID = markerGUID;
	    if( lIndex == null )
	        EPDMarkerHelper.SelectedIndex = 0;
		//we determine position of bubble here
		var tmpPixel = this.EPDMapObj.LatLongToPixel(this.MarkerGUIDHash[markerGUID].VEShapeO.GetIconAnchor());
		var locationPos = EPDMarkerHelper.FindPosition(tmpPixel);
		this.EPDMarkerDivO.style.left = locationPos[0].x + this.MarkerGUIDHash[markerGUID].BubbleOffsetX + "px";
		this.EPDMarkerDivO.style.top = locationPos[0].y + this.MarkerGUIDHash[markerGUID].BubbleOffsetY + "px";
		//figure out what background to use here
		this.EPDMarkerBGDivO.innerHTML = EPDMarkerHelper.RtnBackgroundDiv(locationPos[1], this.MarkerGUIDHash[markerGUID].NumberHTMLElements, markerGUID);
		//set the HTML here
		if( lIndex == null )
		    lIndex = 0;
		
		//this.EPDMarkerHTMLDivO.innerHTML = "<div class=\"epdMapBubbleInfo\">" + this.MarkerGUIDHash[markerGUID].GetInnerHTML() + "</div>";
		
		this.EPDMarkerHTMLDivO.innerHTML = glFormatListingHTML(this.MarkerGUIDHash[markerGUID].RtnListing(lIndex), lIndex, this.MarkerGUIDHash[markerGUID].ListingsC);
		this.EPDMarkerDivO.style.display = "block";
		return true;
	}
};

//EPDMarkerHelper :: glEPDHideMarkerDetails :: static - hide current marker details
EPDMarkerHelper.glEPDHideMarkerDetails = function()
{
	this.EPDMarkerDivO.style.display = "none";
	EPDMarkerHelper.SelectedGUID = "";
	EPDMarkerHelper.SelectedIndex = 0;
};

//EPDMarkerHelper :: AddMarker :: static - add marker to our marker hash and map - will replace a marker if need be
EPDMarkerHelper.AddMarker = function(markerGUID, markerObj)
{
	if(this.MarkerGUIDHash[markerGUID] != null )
		EPDMarkerHelper.RemoveMarker(markerGUID);
	this.MarkerGUIDHash[markerGUID] = markerObj;
	//this.EPDMapObj.AddShape(markerObj.GetVEShape());
};

//EPDMarkerHelper :: RemoveMarker :: static - remove marker to our marker hash and map
EPDMarkerHelper.RemoveMarker = function(markerGUID)
{
	if(this.MarkerGUIDHash[markerGUID] != null )
	{
		this.EPDMapObj.DeleteShape(this.MarkerGUIDHash[markerGUID].GetVEShape());
		//delete this.MarkerGUIDHash[markerGUID];
	}
};

//EPDMarkerHelper :: HasMarker :: static - see if our hash has this marker by guid
EPDMarkerHelper.HasMarker = function(markerGUID)
{
    if(this.MarkerGUIDHash[markerGUID] != null )
        return true;
    return false;
};

//EPDMarkerHelper :: ClearMarkers :: static - remove all markers from our hash
EPDMarkerHelper.ClearMarkers = function()
{
    if(this.MarkerGUIDHash != null )
    {
        for(var keyVar in this.MarkerGUIDHash)
        {
            delete this.MarkerGUIDHash[keyVar];
        }
    }
    EPDMarkerHelper.SelectedGUID = "";
    EPDMarkerHelper.SelectedIndex = 0;
};

//EPDMarkerHelper :: FindOffsetInLatLong :: static - find pixel offset in lat/long
EPDMarkerHelper.FindOffsetInLatLong = function(x,y)
{
    var tmpOffset = EPDVEMAPOBJ._EPDVEMapObj.PixelToLatLong(new VEPixel(x,y));
    var tmpOffsetMap = EPDVEMAPOBJ._EPDVEMapObj.PixelToLatLong(new VEPixel(0,0));
    return new VELatLong((tmpOffset.Latitude - tmpOffsetMap.Latitude), (tmpOffset.Longitude - tmpOffsetMap.Longitude));
};

//EPDMarkerHelper :: ReturnMarkerObj :: static - return a marker object if need be
EPDMarkerHelper.ReturnMarkerObj = function(markerGUID)
{
	if(this.MarkerGUIDHash[markerGUID] != null )
		return this.MarkerGUIDHash[markerGUID];
	else
		return null;
};

/* ===== END EPDMarkerHelper ===== */

/* ===== START EPDMarker ===== */

/*  EPDMarker class
by: randy bacon
11/09/07
Instance class for an EPD marker
*/
function EPDMarker(VELatLongPoint, GUID)
{
	this.GUID = GUID;
	this.IconHTML = "";
	this.AnchorOffsetX = 0;
	this.AnchorOffsetY = 0;
	this.InnerHTML = "";
	this.BubbleOffsetX = 0;
	this.BubbleOffsetY = 0;
	//set our lat/long point
	this.Point = VELatLongPoint;
	//we need a VE shape so we have something to attach to the map
	this.VEShapeO = null;
	this.NumberHTMLElements = 0;
	this.Listings = new Array();
	this.ListingsC = 0;
	this.ListingsIds = new Array();
};

//EPDMarker :: SetIcon :: set the icon image HTML
EPDMarker.prototype.SetIcon = function(iconImgHTML) {
    //alert(iconImgHTML);
    this.IconHTML = iconImgHTML;
};

//EPDMarker :: GetIcon :: get the icon image HTML
EPDMarker.prototype.GetIcon = function()
{
	return this.IconHTML;
};

//EPDMarker :: SetAnchorOffset :: set the icon image offset
EPDMarker.prototype.SetAnchorOffset = function(x,y)
{
    var tmpOffset = EPDMarkerHelper.FindOffsetInLatLong(x,y);    
	this.AnchorOffsetX = tmpOffset.Latitude;
	this.AnchorOffsetY = tmpOffset.Longitude;
};

//EPDMarker :: FindLIndex :: find index of an ln
EPDMarker.prototype.FindLIndex = function(listingId)
{
    if( this.ListingsIds && this.ListingsIds.length > 0 )
    {
        for(var i=0;i<this.ListingsIds.length;i++)
            if(this.ListingsIds[i] == listingId )
                return i;
    }
};

//EPDMarker :: AddListing :: add listing to our listing collection
EPDMarker.prototype.AddListing = function(listObj)
{
    this.Listings[listObj.ListingId] = listObj;
    this.ListingsIds[this.ListingsC] = listObj.ListingId;
    this.ListingsC++;
    this.NumberHTMLElements++;
};

//EPDMarker :: RtnListing :: return listing object by the index in the array
EPDMarker.prototype.RtnListing = function(index)
{
    return this.Listings[this.ListingsIds[index]];
};

//EPDMarker :: RtnNextListing :: return the next listing in the hash
EPDMarker.prototype.RtnNextListingIndex = function(index)
{
    if( this.ListingsC > 1 )
    {
        index++;
        if( index < this.ListingsC )
        {
            return index;
        }
    }
    return 0; 
};

//EPDMarker :: SetInnerHTML :: set the marker inner html
EPDMarker.prototype.SetInnerHTML = function(htmlTxt)
{
	this.InnerHTML = htmlTxt;
};

//EPDMarker :: GetInnerHTML :: set the marker inner html
EPDMarker.prototype.GetInnerHTML = function()
{
    return this.InnerHTML;
};

//EPDMarker :: GetPoint :: get the marker VE lat/long point
EPDMarker.prototype.GetPoint = function()
{
	return this.Point;
};

//EPDMarker :: SetBubbleOffset :: set the bubble offset
EPDMarker.prototype.SetBubbleOffset = function(x,y)
{
    var tmpOffset = EPDMarkerHelper.FindOffsetInLatLong(x,y);
	this.BubbleOffsetX = tmpOffset.Latitude;
	this.BubbleOffsetY = tmpOffset.Longitude;
};

//EPDMarker :: AddMarker :: when you are FINALLY done setting up your marker, this will add it to the map
EPDMarker.prototype.AddMarker = function()
{
	this.VEShapeO = new VEShape(VEShapeType.Pushpin, new VELatLong(this.Point.Latitude - this.AnchorOffsetX, (this.Point.Longitude - this.AnchorOffsetY)));
	this.VEShapeO.SetCustomIcon("<div class='epdVEMarker' id='epdVEMarker_" + this.GUID + "' onClick='EPDMarkerHelper.glEPDShowMarkerDetails(\"" + this.GUID + "\")' onmouseover=\"return true;\">" + this.IconHTML + "</div>");
	EPDMarkerHelper.AddMarker(this.GUID, this);
};

//EPDMarker :: GetVEShape :: get the shape obj to add to maps or whatever
EPDMarker.prototype.GetVEShape = function ()
{
	return this.VEShapeO;
};


function CommaFormat(nStr) {
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    x2 = x2.length > 2 ? Math.round(x2 * Math.pow(10, 2)) / Math.pow(10, 2) : x2;
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
};

//display of listing items here
// TODO - It may make sense to replace this with a defined element in the html so that it can be designed easier
function glFormatListingHTML(listingObj, vrCount, vrTotal) {
    var rtnStr = "";

    if (listingObj.PhotoU != "") {
        rtnStr += "<div class=\"epdMapBubbleImageBlock\"><a href=\"javascript:glShowDetail('" + listingObj.ListingId + "')\">";
        rtnStr += "<img src=\"" + listingObj.PhotoU + "\" class=\"epdMapBubbleImage\"></a>";
        rtnStr += "<img src=\"" + IMAGEBASE_URL + "epdMapImageRight.png\" class=\"epdMapBubbleImageRight\"></div>";
    }

    rtnStr += "<div class=\"epdMapBubbleInfo\">";

    //start heading
    rtnStr += "<div class=\"epdMapBubbleInfoHeading\"><span class=\"epdMapBubbleInfoHeadingTxt\"><a href=\"javascript:glShowDetail('" + listingObj.ListingId + "')\">" + listingObj.PropName + "</a></span><br>";
    rtnStr += "<span class=\"epdMapBubbleInfoPropCat\">" + (listingObj.PropCat == 2 ? "For Sale" : "For Lease") + "</span>";
    if (vrTotal > 1)
        rtnStr += " <span class=\"epdMapBubbleInfoHeadingCount\">(" + (vrCount + 1) + " of " + vrTotal + ")</span>";
    rtnStr += "</div><div class=\"epdMapBubbleInfoClear\"></div>";

    if (listingObj.PropCat == 2) {
        if (listingObj.LP != "") {
            rtnStr += "<div class=\"epdMapBubbleInfoText\">Price: " + ((listingObj.LP == "" || listingObj.LP == 0) ? "CALL" : "$" + CommaFormat(listingObj.LP)) + "</div>";
            rtnStr += "<div class=\"epdMapBubbleInfoClear\"></div>";
        }
        if (listingObj.TotBldgSF > 0)
            rtnStr += "<div class=\"epdMapBubbleInfoText\">SqFt: " + CommaFormat(listingObj.TotBldgSF) + "</div>";
        if ((listingObj.SpaceType & 2) == 2 && listingObj.Class != "" && listingObj.Class != "-")
            rtnStr += "<div class=\"epdMapBubbleInfoTextRight\">Class: " + listingObj.Class + "</div>";
        else if (listingObj.YearBuilt > 0)
            rtnStr += "<div class=\"epdMapBubbleInfoTextRight\">Yr Built: " + listingObj.YearBuilt + "</div>";
        else if ((listingObj.SpaceType & 16) == 16 && listingObj.TotalLandAcres > 0)
            rtnStr += "<div class=\"epdMapBubbleInfoTextRight\">Acres: " + listingObj.TotalLandAcres + "</div>";
    }
    else {
        if (listingObj.RentAsk > 0 && listingObj.RentMax > 0 && listingObj.RentAsk != listingObj.RentMax) {
            rtnStr += "<div class=\"epdMapBubbleInfoText\">$(" + CommaFormat(listingObj.RentAsk) + " - " + CommaFormat(listingObj.RentMax) + ") per SF/Yr</div>";
            rtnStr += "<div class=\"epdMapBubbleInfoClear\"></div>";
        }
        else if (listingObj.RentAsk > 0 && listingObj.RentMax == 0 || (listingObj.RentAsk > 0 && listingObj.RentAsk == listingObj.RentMax)) {
            rtnStr += "<div class=\"epdMapBubbleInfoText\">$" + CommaFormat(listingObj.RentAsk) + " per SF/Yr</div>";
            rtnStr += "<div class=\"epdMapBubbleInfoClear\"></div>";
        }
        else if (listingObj.RentAsk == 0) {
            rtnStr += "<div class=\"epdMapBubbleInfoText\">$(CALL) per SF/Yr</div>";
            rtnStr += "<div class=\"epdMapBubbleInfoClear\"></div>";
        }
        if (listingObj.SFAvail > 0)
            rtnStr += "<div class=\"epdMapBubbleInfoText\">Avail SqFt: " + CommaFormat(listingObj.SFAvail) + "</div>";
        if ((listingObj.SpaceType & 2) == 2 && listingObj.Class != "" && listingObj.Class != "-")
            rtnStr += "<div class=\"epdMapBubbleInfoTextRight\">Class: " + listingObj.Class + "</div>";
    }

    //close info
    rtnStr += "</div>";

    return rtnStr;
}// EPDMapListing.js

// EPDMapListing class
// Represents a single listing result
function EPDMapListing()
{
    this.ListingId = "";
    this.Latitude = null;
    this.Longitude = null;
    this.PPTYId = null;
    this.PropName = "";
    this.PropCat = 0;
    this.SpaceType = -1;
    this.PhotoU = "";
    this.LP = "";
    this.TotBldgSF = 0;
    this.YearBuilt = 0;
    this.RentAsk = 0;
    this.RentMax = 0;
    this.SFAvail = 0;
    this.TotalLandAcres = 0;
    this.Class = "";
}
//end EPDMapListing


// EPDMapListingHelper
// Helper class for EPDMapListing
function EPDMapListingHelper() { }

EPDMapListingHelper.Populate = function(listingElem) {
    var tmpObj = new EPDMapListing();

    tmpObj.ListingId = listingElem.getElementsByTagName("LI")[0].firstChild.nodeValue;
    tmpObj.PPTYId = listingElem.getElementsByTagName("PY")[0].firstChild.nodeValue;
    tmpObj.Latitude = listingElem.getElementsByTagName("LA")[0].firstChild != null ? listingElem.getElementsByTagName("LA")[0].firstChild.nodeValue : -1;
    tmpObj.Longitude = listingElem.getElementsByTagName("LO")[0].firstChild != null ? listingElem.getElementsByTagName("LO")[0].firstChild.nodeValue : -1;
    tmpObj.PropName = listingElem.getElementsByTagName("PN")[0].firstChild != null ? listingElem.getElementsByTagName("PN")[0].firstChild.nodeValue : "";
    tmpObj.PropCat = listingElem.getElementsByTagName("PC")[0].firstChild != null ? listingElem.getElementsByTagName("PC")[0].firstChild.nodeValue : 0;
    tmpObj.SpaceType = listingElem.getElementsByTagName("ST")[0].firstChild != null ? listingElem.getElementsByTagName("ST")[0].firstChild.nodeValue : 0;
    tmpObj.PhotoU = listingElem.getElementsByTagName("PU")[0].firstChild != null ? listingElem.getElementsByTagName("PU")[0].firstChild.nodeValue : "";
    tmpObj.LP = listingElem.getElementsByTagName("LP")[0].firstChild != null ? listingElem.getElementsByTagName("LP")[0].firstChild.nodeValue : "";
    tmpObj.TotBldgSF = listingElem.getElementsByTagName("TB")[0].firstChild != null ? listingElem.getElementsByTagName("TB")[0].firstChild.nodeValue : 0;
    tmpObj.YearBuilt = listingElem.getElementsByTagName("YB")[0].firstChild != null ? listingElem.getElementsByTagName("YB")[0].firstChild.nodeValue : 0;
    tmpObj.RentAsk = listingElem.getElementsByTagName("RA")[0].firstChild != null ? listingElem.getElementsByTagName("RA")[0].firstChild.nodeValue : 0;
    tmpObj.RentMax = listingElem.getElementsByTagName("RM")[0].firstChild != null ? listingElem.getElementsByTagName("RM")[0].firstChild.nodeValue : 0;
    tmpObj.SFAvail = listingElem.getElementsByTagName("PS")[0].firstChild != null ? listingElem.getElementsByTagName("PS")[0].firstChild.nodeValue : 0;
    tmpObj.TotalLandAcres = listingElem.getElementsByTagName("TLA")[0].firstChild != null ? listingElem.getElementsByTagName("TLA")[0].firstChild.nodeValue : 0;
    tmpObj.Class = listingElem.getElementsByTagName("CL")[0].firstChild != null ? listingElem.getElementsByTagName("CL")[0].firstChild.nodeValue : "";

    return tmpObj;
};
//end EPDMapListingHelper/// <reference path="../../jquery/jquery-1.3.2.js"/>
var QParams = new Array();

//disable select start in all for IE6 mostly
$(document).ready(function() {
    document.onselectstart = glDocSelStart;

    $(QParams).each(function() {
        var c = $("#" + this[0]);
        if (c != null) {
            if (c.is("input:checkbox"))
                c.click(function() { glMapParamsChanged(true); });
            else
                c.change(function() { glMapParamsChanged(true); });

            if ((c.is("input:text") || c.is("textarea")) && this.length > 2 && this[2] != null && this[2] != "") {
                var expr = this[2];
                c.keypress(function(e) {
                    var key;
                    if (window.event)
                        key = window.event.keyCode;
                    else
                        key = e.charCode;

                    if (key != null) {
                        var r = new RegExp(expr);
                        return r.test(String.fromCharCode(key));
                    }
                });
            }
        }
    });
});


function glDocSelStart(e) {
    if (!e)
        e = window.event;
    //see if we are text box
    if (e != null && e.srcElement != null && e.srcElement.type != null)
        return true;
    return false;
}


function glGetQParamStr() {
    var p = new Array();

    $(QParams).each(function() {
        var c = $("#" + this[0]);
        if (c != null) {
            var v = c.is("input:checkbox") ? (c.attr("checked") == true ? "1" : "") : c.val();
            if (v != null && v != "") p.push(this[1] + "=" + $.trim(v));
        }
    });

    return p.join(",");
}

function loadMap() {
    //set nav
    InitNav();

    //then set up our map and tools
    EPDVEMAPOBJ = new EPDVEMap('epdMap', _STARTPOS.split("~")[0], _STARTPOS.split("~")[1], _STARTZ, _RESETPOS.split("~")[0], _RESETPOS.split("~")[1], _RESETZ, 'epdZoomBox', 'epdMapOverlay', 'epdMapPolyOverlay', 'epdBLOCKMapOverlay');

    //bind some events
    EPDVEMAPOBJ.OnPolyAvailChange = glPolyChange;
    EPDVEMAPOBJ.OnMapParamsChanged = glMapParamsChanged;
    EPDVEMAPOBJ.OnLineCompleteChange = glLineCompleteChanged;
    EPDVEMAPOBJ.OnSelectedToolChanged = glSelectedToolChanged;

    //config our search helper
    EPDMapSearchHelper.SearchURL = _WSURL;
    EPDMapSearchHelper.SearchSource = _SSRC;
    EPDMapSearchHelper.OnSearchStart = glSearchStart;
    EPDMapSearchHelper.OnSearchEnd = glSearchEnd;
    EPDMapSearchHelper.OnSearchTimeOut = glSearchTimeout;
    EPDMapSearchHelper.OnSearchError = glSearchError;


    //bind event for mouse movement
    $(document).mousemove(function(e) {
        MOUSELOCATION_X = e.pageX;
        MOUSELOCATION_Y = e.pageY;
    });

    //finally say map is done init and enable zoom
	MAPISINIT = true;
	EPDVEMAPOBJ.LoadComplete();

    // If starting poly shape specified, parse and fill in points
	if (_STARTPOLY != null && _STARTPOLY.length > 0) {
	    var tmpLatLong = new Array();
	    var tmpPoints = _STARTPOLY.split(",");
	    if (tmpPoints.length >= 2) {
	        for (var i = 0; i < tmpPoints.length; i++) {
	            tmpLatLong.push(new VELatLong(tmpPoints[i].split("~")[0], tmpPoints[i].split("~")[1]));
	        }
	    }
	    if (tmpLatLong.length > 2) {
	        EPDVEMAPOBJ.SetPoly(tmpLatLong);
	        EnableNav(EPDVEMapTools.Clear);
	    }
    }
	
	useMapTool(1);
	ResetNav();

	$(window).resize(glWindowResize);
}

function glWindowResize() {
    EPDVEMAPOBJ.WindowResize();
}


function glLineCompleteChanged() {
    if (EPDVEMAPOBJ.HasBoundingLines && document.getElementById(toolDivArray[3]).style.display == "none") 
        EnableNav(EPDVEMapTools.Clear);
    else if (!EPDVEMAPOBJ.HasBoundingLines && document.getElementById(toolDivArray[3]).style.display == "block") 
        DisableNav(EPDVEMapTools.Clear);
}

function glMapParamsChanged() {
    if(EPDD!= null) EPDD.MPCH(EPDVEMAPOBJ.GetMapParams().SearchString());
    
    //start search
    EPDMapSearchHelper.Search(glGetQParamStr(), EPDVEMAPOBJ.GetMapParams().SearchString(), arguments[0] != null ? true : false);
}

function glTrySearchAgain() {
    $("#epdMapErrorBox").hide();

    EPDMapSearchHelper.MParamsStr = null;
    EPDMapSearchHelper.QParamsStr = null;
    EPDMapSearchHelper.Search(glGetQParamStr(), EPDVEMAPOBJ.GetMapParams().SearchString(), false);
}

function glSearchTimeout() {
    $("#epdMapErrorBox").show();

    EPDVEMAPOBJ.OnSearchEnd(0);
}

function glSearchError(errorStr)
{
    if(EPDD!= null) EPDD.ER(errorStr);
    $("#epdMapErrorBox").show();

    EPDVEMAPOBJ.OnSearchEnd(0);
}

function glSearchEnd(resultCount) 
{
    if (resultCount > 10000)
        $("#epdListingCountTxt").html("<div class=\"epdListingCountNum\">10,000+ Listings Found");
    else
        $("#epdListingCountTxt").html("<div class=\"epdListingCountNum\"><span>" + resultCount + " </span>Listings Found</div>");
  
    if(  EPDMapSearchHelper.Listings.length > 0 )
        $(".results_button").attr("disabled", false);
    else
        $(".results_button").attr("disabled", true);
        
    EPDVEMAPOBJ.OnSearchEnd(resultCount);        
}

function glSearchStart()
{
    if( resultsShowing )
        SelectSearchNav(0);
    EPDVEMAPOBJ.OnSearchStart();
    $("#epdListingCountTxt").html("<div class=\"epdResLoading\">Loading...</div>");

    return true;
}

function glSelectedToolChanged()
{
    selectToolNav(EPDVEMAPOBJ.SelectedTool);
}

function glPolyChange()
{
    if( EPDVEMAPOBJ.IsPolyEnabled )
        EnableNav(EPDVEMapTools.Poly);
    else
    {
        DisableNav(EPDVEMapTools.Poly);
        if( EPDVEMAPOBJ.SelectedTool == EPDVEMapTools.Poly )
        {
            useMapTool(EPDVEMapTools.Draw);
        }
    }
}

//globals here        
function useMapTool(toolId)
{
    if( EPDVEMAPOBJ.SelectTool(toolId)) {
        if (toolId != EPDVEMapTools.Clear)
            selectToolNav(toolId);
        else
            DisableNav(EPDVEMapTools.Clear);
    }
}

function selectToolNav(toolId) {
    // Reset previous selection
    $("#" + selectedNavItem + "Active").attr("id", selectedNavItem);
    
    selectedNavItem = toolDivArray[toolId];
    selectedNav(toolId);
    //search snyc calling adjustmnet
    if( toolId == EPDVEMapTools.Drag)
        EPDMapSearchHelper.SearchWaitBNDraws = 800;
    else
        EPDMapSearchHelper.SearchWaitBNDraws = 0;
}

function mapReset()
{
    EPDVEMAPOBJ.ResetToInit();        
    useMapTool(EPDVEMapTools.Draw);
}

function DisposeMap()
{
    if(EPDVEMAPOBJ != null)
        EPDVEMAPOBJ.Dispose();        
}

//nav items
var selectedNavItem = "epdMTDraw";
var toolDivArray = new Array();

function InitNav() {
    toolDivArray.push("epdMTDrag");
    toolDivArray.push("epdMTDraw");
    toolDivArray.push("epdMTPoly");
    toolDivArray.push("epdMTLinesClear");
}

function ResetNav() {
    //$("#" + selectedNavItem).css({ "background-color": "#263f77" });
    //document.getElementById(selectedNavItem).style.backgroundColor = "#263f77";
    if (!EPDVEMAPOBJ.IsPolyEnabled) {
        $("#" + toolDivArray[2]).hide();  //.css({ "background-color": "transparent" }) ??
        $("#" + toolDivArray[2] + "Dis").show();
    }
    if (!EPDVEMAPOBJ.HasBoundingLines) {
        $("#" + toolDivArray[3] + "Dis").show();
        $("#" + toolDivArray[3]).hide();
    }
}

function EnableNav(toolId) {
    $("#" + toolDivArray[toolId] + "Dis").hide();
    $("#" + toolDivArray[toolId]).show();
}

function DisableNav(toolId) {
    $("#" + toolDivArray[toolId] + "Dis").show();
    $("#" + toolDivArray[toolId]).hide();
}

function selectedNav(toolId) {
    var newID = toolDivArray[toolId] + "Active";
    $("#" + toolDivArray[toolId]).attr("id", newID);
}

var resultsTab = 1;
var resultsShowing = false;


//end nav// Map Menu Tips

function setMapTips() {
    
    //$("#epdMapTipBox").hide();
    
    // Delay popup
    /*var timer = null;
    $("#epdMTPolyDis").mouseover(function() {
        timer = setTimeout(function() {
            $(".tipBox").show();
        }, 800);
    }).mouseout(function() {
        clearTimeout(timer);
    });*/

    // Click Popup
    $("#epdMTPolyDis").mousedown(function() {
        $(".tipBox").show();
    });

    // Override cursor & close
    $(".tipClose,.tipCloseX,.tipBox").mouseover(function() {
        $(this).css("cursor", "pointer");
    }).mousedown(function() {
        $(".tipBox").hide();
    });

}