LNJS.SearchManager.prototype._getRetInst = function()
{
	return '<RetrievalInstructions MapMode="' + enNGMapMode + '" MinimumLatitude="' + this.CritMgr.Criteria.GeographicFilter.Radius.MinLatitude + '" MaximumLatitude="' + this.CritMgr.Criteria.GeographicFilter.Radius.MaxLatitude + '" MinimumLongitude="' + this.CritMgr.Criteria.GeographicFilter.Radius.MinLongitude + '" MaximumLongitude="' + this.CritMgr.Criteria.GeographicFilter.Radius.MaxLongitude + '" StartPosition="1" Count="' + this.CritMgr.Criteria.MaxSearchRowCount + '" UOMMoneyCurrency="' + UOMMoneyCurrency + '" UOMListing="' + UOMListing + '"></RetrievalInstructions></PFRequestData>';
};
//hook up checkboxes
LNJS.SearchManager.prototype._syncCheckbox = function(from, to)
{   
    //need our own checking for results and check all etc etc
    //get checkboxes
    var chkFrom = $(from);
    var chkTo = $(to);
    
    //transfer checked
    //check if everything is selected
    var selectAllCheckBox = document.getElementById('llRH-SelectAll');
    
    if ((chkFrom) && 
        (chkTo))
    {
		chkTo.checked = chkFrom.checked;
		if ((!chkTo.checked || !chkFrom.checked) && selectAllCheckBox != null)
		{
			selectAllCheckBox.checked = false;
		}
    }
    else if ((selectAllCheckBox != null) && 
        (selectAllCheckBox.checked))
	{
		if(chkTo)
		{
			chkTo.checked= true;
		}
		
		if(chkFrom)
		{
			chkFrom.checked=true;
		}
	}
	else if (chkFrom)
	{
	    if (isSelectedListing(chkFrom.value))
	    {
	        chkFrom.checked = true;
	    }
	}
	else if (chkTo)
	{
	    if (isSelectedListing(chkTo.value))
	    {
	        chkTo.checked = true;
	    }
	}

    //done kill objects
    chkFrom = null;
    chkTo = null;
};

LNJS.SearchManager.prototype.buildResortOrder = function()
{
    //returns an LNSortFieldList
    var sortFieldList = new LNSortFieldList();
    
    var oSortField = new LNSortField();
	oSortField.Name = this.sortCommand;
	oSortField.Seq = this.sortOrder;
	sortFieldList.add(oSortField);
    
    //add other fields (default sort, based on search type)
    
    return sortFieldList;
};
LNJS.SearchManager.prototype.executeInitialSearch = function()
{
    //alert('executing');
    //alert(ll_search_pinResults);
    //alert(ll_search_listResults);
    
    LNJS.Page.SearchMgr.nonGeocodedListingsPresent = true;
    
    this.searchHasRun = true;
    
    this.adjustMapBasedOnPins = true;
    this.executePinsFromInitialSearch();
    this.executeListFromInitialSearch();
    
    LNJS.Page.SearchMgr.isInitialSearch = false;
};
LNJS.SearchManager.prototype.executeListFromInitialSearch = function()
{
    LNJS.Trace.source(LNJS.Page.SearchMgr.__className+": Starting executeListFromInitialSearch()",LNJS.Page.SearchMgr.__className.toLowerCase()+".getlistings_cb");
		
//		if (this.resultCount > 0)
//		{

        //alert(ll_search_listResults);
        
		var listData = LNJS.Xml.getDomDocument();
		listData = (new DOMParser()).parseFromString(ll_search_listResults, "text/xml");
        
        //alert('found list data');
        
		if(listData.parseError != 0)
		{
			//alert(listData.parseError);
		}	
			
		//alert(listData.xml);
		//check the return code
		
			var sSearchResults = LNJS.Xml.getText(listData.documentElement.selectSingleNode("//SearchResults"));
			
			//alert(sSearchResults);
			if (!LNJS.isNull(sSearchResults))
			{	//clear any existing results
				LNJS.Page.SearchMgr._clearResultList();
				
				//set results on the search manager
				LNJS.Page.SearchMgr._setResults(sSearchResults,"lData");
				
				
				
				//put the results in the list
				LNJS.Page.SearchMgr._renderResultList();
			}
			else
			{	//search results node missing!
				throw LNJS.Page.SearchMgr.Err(LNJS.Page.SearchMgr.__className+": SearchResults node missing!");
			}
		
		    if (LNJS.Page.SearchMgr.lData.resultCount > 0)
				    {
					//set result count
					LNJS.Page.SearchMgr.resultCount.className = "mapSearch-numResults";
					var resulttext = LNJS.Page.SearchMgr.lData.resultCount;
					switch(resulttext)
					{
						case 1:
							resulttext += '</strong> '+(LNJS.Page.SearchMgr._isMLS()?'Result':'RecentSale');
							break;
						case 100:
							resulttext += '+</strong> '+(LNJS.Page.SearchMgr._isMLS()?'Results':'RecentSales');
							break;
						default: 
							resulttext += '</strong> '+(LNJS.Page.SearchMgr._isMLS()?'Results':'RecentSales');
							break;
					}
					Element.innerHTML(LNJS.Page.SearchMgr.resultCount,'<strong>'+resulttext+' Found');
				
					//check if we ran a property id search
					if(LNJS.Page.SearchMgr._isPD())
					{	//move map to property location
						//LNJS.Page.MapMgr.setCenterAndZoom(LNJS.Page.SearchMgr.lData.items[0].lat, LNJS.Page.SearchMgr.lData.items[0].lon, 17);
					}
				}
				else
				{	//no search results!
					LNJS.Page.SearchMgr.resultCount.className = "mapSearch-noResults";
					Element.innerHTML(LNJS.Page.SearchMgr.resultCount,"<strong>No results found.</strong>");
				}
//		}
//		else
//		{	//no search results!
//			LNJS.Page.SearchMgr.resultCount.className = "mapSearch-noResults";
//			Element.innerHTML(LNJS.Page.SearchMgr.resultCount,"<strong>No results found.</strong>");
//		}
		LNJS.Trace.source(LNJS.Page.SearchMgr.__className+": Done executeListFromInitialSearch()",LNJS.Page.SearchMgr.__className.toLowerCase()+".getlistings_cb");
	
};
LNJS.SearchManager.prototype.executePinsFromInitialSearch = function()
{
        LNJS.Trace.source(LNJS.Page.SearchMgr.__className+": Starting executePinsFromInitialSearch",LNJS.Page.SearchMgr.__className.toLowerCase()+".performsearch_cb");
				
		//check the return code
		var pinData = LNJS.Xml.getDomDocument();
		pinData = (new DOMParser()).parseFromString(ll_search_pinResults, "text/xml");
        
		if(pinData.parseError != 0)
		{
			//pinData = "";
		}	
			//alert(pinData.xml);
			
			//loading search is done
			LNJS.Page.loadingSearch = false;
		
		    //need search id for sorting
		    var sSummary = pinData.documentElement.selectSingleNode("//SearchSummary");
		   
		    searchID = parseInt(sSummary.getAttribute("SearchResultID"));
		    
		    this.resultCount = parseInt(sSummary.getAttribute("ResultCount"));
		    
		    var sMapPoints = LNJS.Xml.getText(pinData.documentElement.selectSingleNode("//MapPoints"));
			
			if (!LNJS.isNull(sMapPoints))
			{	//clear any existing pins
				LNJS.Page.SearchMgr._clearPins();

				//set results on the search manager
				LNJS.Page.SearchMgr._setResults(sMapPoints,"pData");

				//put the pins on the map (method does other stuff like hides the updating message as well)
				LNJS.Page.SearchMgr._plotPins();

				//show/hide search result tools (filters / save search etc.)
				LNJS.Page.showSearchResultTools();
				
				//check if we have results
				//TODO need null check for pData and some tracing
				if (LNJS.Page.SearchMgr.pData.resultCount > 0)
				{
					//set result count
					LNJS.Page.SearchMgr.resultCount.className = "mapSearch-numResults";
					var resulttext = LNJS.Page.SearchMgr.pData.resultCount;
					switch(resulttext)
					{
						case 1:
							resulttext += '</strong> '+(LNJS.Page.SearchMgr._isMLS()?'Result':'RecentSale');
							break;
						case 100:
							resulttext += '+</strong> '+(LNJS.Page.SearchMgr._isMLS()?'Results':'RecentSales');
							break;
						default: 
							resulttext += '</strong> '+(LNJS.Page.SearchMgr._isMLS()?'Results':'RecentSales');
							break;
					}
					Element.innerHTML(LNJS.Page.SearchMgr.resultCount,'<strong>'+resulttext+' Found');
				
					//check if we ran a property id search
					if(LNJS.Page.SearchMgr._isPD())
					{	//move map to property location
						//LNJS.Page.MapMgr.setCenterAndZoom(LNJS.Page.SearchMgr.pData.items[0].lat, LNJS.Page.SearchMgr.pData.items[0].lon, 17);
					}
				}
				else
				{	//no search results!
					LNJS.Page.SearchMgr.resultCount.className = "mapSearch-noResults";
					Element.innerHTML(LNJS.Page.SearchMgr.resultCount,"<strong>No results found.</strong>");
				
				}
				
				//set default save search name (max length is 50)
				if (LNJS.Page.EL.criterionName)
				{
				    if(LNJS.Page.EL.criterionName.value.length == 0)
				    {
				        var sName = LNJS.Page.SearchMgr._getSelectedCatNames();
				        switch(LNJS.Page.SearchMgr.searchType){case'FS':sName += ' For Sale';break;case'FL':sName += ' For Lease';break;}
				        if(sName.length > 50)sName = sName.substring(0,50);
				        LNJS.Page.EL.criterionName.value = sName;
				    }
				}
			}
			else
			{	//search results node missing!
				throw LNJS.Page.SearchMgr.Err(LNJS.Page.SearchMgr.__className+": MapPoints node missing!");
			}
		
		
		LNJS.Trace.source(LNJS.Page.SearchMgr.__className+": Done executePinsFromInitialSearch",LNJS.Page.SearchMgr.__className.toLowerCase()+".performsearch_cb");
	
};

LNJS.SearchManager.prototype._setPinNumbers = function()
{
    if ((!LNJS.isNull(this.lData)) &&
        (!LNJS.isNull(this.lData.items)) &&
        (this.lData.items.length > 0) &&
        (!LNJS.isNull(this.pData)) &&
        (!LNJS.isNull(this.pData.items)) &&
        (this.pData.items.length > 0))
    {
        var pinNumber = 1;
        
        for (var i = 0; i < this.pData.items.length; i++)
        {
            pinData = this.pData.items[i];
            
            // Adding check for confidential listings since
            // we will not be plotting those pins (ICP #20977) -BT (SLTC)
            if ((typeof(pinData) != 'undefined') &&
                (typeof(pinData.lat) != 'undefined') &&
                (typeof(pinData.lon) != 'undefined') &&
                (!LNJS.isNull(pinData.lat)) &&
                (!LNJS.isNull(pinData.lon)) &&
                (pinData.lat != 0) &&
                (pinData.lon != 0) &&
                (!pinData.conf))
            {
                for (var j = 0; j < this.lData.items.length; j++)
                {
                    if (this.lData.items[j].lid == pinData.lid)
                    {
                        this.lData.items[j].pinIndex = i;
                        this.lData.items[j].pinNumber = pinNumber;
                        
                        if (this.lData.items[j].type == 'fl')
                        {
                            this.pData.items[i].lRateMo = this.lData.items[j].ratemo;
                            this.pData.items[i].lRateYr = this.lData.items[j].rateyr;
                        }
                        else if (this.lData.items[j].type == 'fs')
                        {
                            this.pData.items[i].lPrice = this.lData.items[j].price;
                        }
                        
                        this.pData.items[i].lType = this.lData.items[j].type;
                        this.pData.items[i].lStatus = this.lData.items[j].status;
                        
                        pinNumber++;
                        
                        break;
                    }
                }
            }
        }
    }
}

LNJS.SearchManager.prototype.attachMapEvents = function(oMapMgr)
{
    /* EVENTS WE HAVE ACCESS TO
    onchangemapstyle Event : Occurs when the map style changes.
    onchangeview Event : Occurs whenever the map view changes.
    onendpan Event : Occurs when a pan of the map ends.
    onendzoom Event : Occurs when the map zoom ends.
    onerror Event : Occurs when there is a map control error.
    oninitmode Event : Occurs after the map mode changes and the map has reloaded.
    onmodenotavailable Event : Occurs when the map mode fails to change to 3D mode.
    onobliquechange Event : Occurs only when the bird's eye image scene ID is changed. This event fires only if the map is currently displaying a bird's eye image and that image is changed.
    onobliqueenter Event : Occurs when bird's eye images are available at the center of the current map.
    onobliqueleave Event : Occurs when bird's eye images are no longer available at the center of the current map.
    onresize Event : Occurs when the map is resized.
    onstartpan Event : Occurs when a pan of the map begins. This event is not supported in 3D mode. 
    onstartzoom Event : Occurs when the map zoom begins.
    */

    //attach to pin events
    //oMapMgr.attachEvent("onmouseout", this._moveShapeBack);
    //oMapMgr.attachEvent("onmouseover", this._moveShapeUp);
    oMapMgr.attachEvent("onclick", this._shapeClick);
    
    //attach to map events
	oMapMgr.attachEvent("onstartpan", this._startPan);
	oMapMgr.attachEvent("onendpan", this._endPan);
	oMapMgr.attachEvent("onobliquechange", this._obliqueChange);
	oMapMgr.attachEvent("onchangeview", this._changeView);
	oMapMgr.attachEvent("onstartzoom", this._startZoom);
	oMapMgr.attachEvent("onendzoom", this._endZoom);
};

	///////////////////////////////////////////////////////////////
	// PRIVATE METHODS
	///////////////////////////////////////////////////////////////

//private method used to check if the map events should re-run the search
LNJS.SearchManager.prototype._validEvent = function(additionalcheck)
{	//default additionalcheck to true if not passed in
	if(LNJS.isNull(additionalcheck))additionalcheck=true;
	
	//check the search manager if we have run at least one search yet
	if(!LNJS.Page.SearchMgr.searchHasRun || !additionalcheck)return false;
	return true;
};

//event binds to the onmouseout of the Virtual Earth map control
LNJS.SearchManager.prototype._moveShapeBack = function(e)
{
    if (e.elementID)
    {   
        //look for pin
        var shape = LNJS.Page.MapMgr.getShapeByID(e.elementID);
        
        if (shape)
        {
            LNJS.Page.SearchMgr._hiliteItem(false);
        }
        
        shape = null;   
           
        return false;
    } 
};

//event binds to the onmouseover of the Virtual Earth map control
LNJS.SearchManager.prototype._moveShapeUp = function(e)
{
    if (e.elementID)
    {   
        //look for pin
        var shape = LNJS.Page.MapMgr.getShapeByID(e.elementID);
        
        if (shape)
        {
            LNJS.Page.SearchMgr._hiliteItem(true);
        }
        
        shape = null;
        
        return false;
    } 
};

//event binds to the onclick of the Virtual Earth map control
LNJS.SearchManager.prototype._shapeClick = function(e)
{
    if (e.elementID)
    {   
        //look for pin
        var currentPin = LNJS.Page.MapMgr.getShapeByID(e.elementID);
        
        if (currentPin)
        {
            //show pin profile
            LNJS.Page.SearchMgr.showPinProfile(currentPin.LN.idx1);
            
            //DO NOT scroll to item in the result list (if it's loaded)
           
            
            /*
            if ((LNJS.Page.SearchMgr.haveResultList) && 
			    (currentPin.LN.idx1 < LNJS.Page.SearchMgr.lData.resultCount))
			{
				new LNJS.Effect.ScrollDivTo(
				    LNJS.Page.SearchMgr.resultcont,
				    ('div' + 
				        currentPin.LN.idx1),
				    {duration:0.9});
			}
			*/
        }
        
        currentPin = null;
        
        return false;
    } 
};

//event binds to the onstartcontinuouspan of the Virtual Earth map control
LNJS.SearchManager.prototype._startPan = function(e)
{	
    if (LNJS.Page.SearchMgr.isInitialSearch)
    {
        LNJS.Page.SearchMgr.isInitialPan = true;
    }
    else
    {
        LNJS.Page.SearchMgr.isInitialPan = false;
    }
    
    LNJS.Page.SearchMgr.isInitialSearch = false;
    
    //check if event is valid
	if(!LNJS.Page.SearchMgr._validEvent())return;
	
	LNJS.Trace.source(LNJS.Page.SearchMgr.__className+": Starting startPan()","onstartpan");

	//hide pin profile (in case it's showing)
	LNJS.Page.SearchMgr.hidePinProfile();

	//clear messages
	LNJS.Page.hideMsg();
	
	//clear location textbox we don't need it if we are panning
	if ((LNJS.Page.EL) &&
	    (LNJS.Page.EL.suggest))
	{
	    LNJS.Page.EL.suggest.value = "";
	}
	
	//set search fired by best view to true
	LNJS.Page.SearchMgr.SearchCalledByBestView = true;
	
	//update last map event if it's already set
	if(!LNJS.Page.SearchMgr.lastMapEvent)
		LNJS.Page.SearchMgr.lastMapEvent = e;

	LNJS.Trace.source(LNJS.Page.SearchMgr.__className+": Done startPan()","onstartpan");
};

//event binds to the onendcontinuouspan of the Virtual Earth map control
LNJS.SearchManager.prototype._endPan = function(e)
{	//check if event is valid
	if(!LNJS.Page.SearchMgr._validEvent(!LNJS.Page.SearchMgr._isPD()))
	{
		//only logging if not valid, otherwise we are tracking with service source code
		LNJS.Page.Log.LogMapPan();
		
		//exit						
		return;
	}
	
	LNJS.Trace.source(LNJS.Page.SearchMgr.__className+": Starting endPan()","onendpan");

	//check if we already have a service source code set
	if (!LNJS.GV(LNJS.ServiceSourceCode,false))
	{
		if ((e.mapStyle == Msn.VE.MapStyle.Oblique) ||
		    (e.mapStyle == Msn.VE.MapStyle.ObliqueHybrid))
		{	
		    //birds eye map pan
			LNJS.ServiceSourceCode = LNJS.ServiceSource.ObliqueMapPan;
		}
		else
		{	//map pan
			LNJS.ServiceSourceCode = LNJS.ServiceSource.MapPan;
		}
	}
	
	if (!LNJS.Page.SearchMgr.isInitialPan)
	{
	    //update criteria and search again
	    LNJS.Page.SearchMgr.updateCriteria(e);
	}
	
	LNJS.Page.SearchMgr.isInitialPan = false;
	
	//clear source code
	LNJS.ServiceSourceCode = LNJS.ServiceSource.Clear;

	LNJS.Trace.source(LNJS.Page.SearchMgr.__className+": Done endPan()","onendpan");
};

//event binds to the onobliquechange of the Virtual Earth map control
LNJS.SearchManager.prototype._obliqueChange = function(e)
{	//check for last map event
	if(!LNJS.Page.SearchMgr.lastMapEvent)
	{	//set last map event (first time)
		LNJS.Page.SearchMgr.lastMapEvent = e;
	}
	else if (LNJS.Page.SearchMgr.lastMapEvent.mapStyle == e.mapStyle)
	{
		//check for orientation change
	    if (LNJS.Page.SearchMgr.lastMapEvent.sceneOrientation != e.sceneOrientation)
		{
			LNJS.ServiceSourceCode = LNJS.ServiceSource.ObliqueMapOrientationChange;
			LNJS.Page.SearchMgr.lastMapEvent = e;
		}
		//check for new map tile loaded
		else if	(LNJS.Page.SearchMgr.lastMapEvent.sceneId != e.sceneId)
		{
			LNJS.ServiceSourceCode = LNJS.ServiceSource.ObliqueMapTileChange;
			LNJS.Page.SearchMgr.lastMapEvent = e;
		}
		else
		{
		     return;
		}
	}

	//check if event is valid
	if(!LNJS.Page.SearchMgr._validEvent(!LNJS.Page.SearchMgr._isPD()))
	{
		//clear source code
		LNJS.ServiceSourceCode = LNJS.ServiceSource.Clear;
	
		//exit
		return;
	}

	LNJS.Trace.source(LNJS.Page.SearchMgr.__className+": Starting obliqueChange()","onobliquechange");

	//clear location textbox we don't need it if we are changing to birds eye
	if ((LNJS.Page.EL) &&
	    (LNJS.Page.EL.suggest))
	{
	    LNJS.Page.EL.suggest.value = "";
	}
	
	//update criteria and search again
	LNJS.Page.SearchMgr.updateCriteria(e);

	//clear source code
	LNJS.ServiceSourceCode = LNJS.ServiceSource.Clear;
	
	LNJS.Trace.source(LNJS.Page.SearchMgr.__className+": Done obliqueChange()","onobliquechange");
};

//event binds to the onchangeview of the Virtual Earth map control
LNJS.SearchManager.prototype._changeView = function(e)
{	//check if event is valid
	if(!LNJS.Page.SearchMgr._validEvent())return;
	
	LNJS.Trace.source(LNJS.Page.SearchMgr.__className+": Starting changeView()","onchangeview");

	//hide pin profile (in case it's showing)
	LNJS.Page.SearchMgr.hidePinProfile();

	if(!LNJS.Page.SearchMgr.lastMapEvent)
	{	//first time
		LNJS.Page.SearchMgr.lastMapEvent = e;
	}
	else
	{
		//check for map style change
		if(LNJS.Page.SearchMgr.lastMapEvent.mapStyle != e.mapStyle)
		{
			LNJS.Page.Log.LogMapStyle(e.mapStyle);
			LNJS.Page.SearchMgr.lastMapEvent = e;
		}
	}

	LNJS.Trace.source(LNJS.Page.SearchMgr.__className+": Done changeView()","onchangeview");
};

//event binds to the onstartzoom of the Virtual Earth map control
LNJS.SearchManager.prototype._startZoom = function(e)
{	
    if (LNJS.Page.SearchMgr.isInitialSearch)
    {
        LNJS.Page.SearchMgr.isInitialZoom = true;
    }
    else
    {
        LNJS.Page.SearchMgr.isInitialZoom = false;
    }
    
    LNJS.Page.SearchMgr.isInitialSearch = false;
    
    //check if event is valid
	if(!LNJS.Page.SearchMgr._validEvent())return;
	
	LNJS.Trace.source(LNJS.Page.SearchMgr.__className+": Starting startZoom()","onstartzoom");

	//clear messages
	LNJS.Page.hideMsg();

	//clear location textbox we don't need it if we are zooming
	if ((LNJS.Page.EL) &&
	    (LNJS.Page.EL.suggest))
	{
	    LNJS.Page.EL.suggest.value = "";
	}

	//set search fired by best view to true
	LNJS.Page.SearchMgr.SearchCalledByBestView = true;
	
	//update last map event if it's already set
	if(!LNJS.Page.SearchMgr.lastMapEvent)
		LNJS.Page.SearchMgr.lastMapEvent = e;

	LNJS.Trace.source(LNJS.Page.SearchMgr.__className+": Done startZoom()","onstartzoom");
};

//event binds to the onendzoom of the Virtual Earth map control
LNJS.SearchManager.prototype._endZoom = function(e)
{
	//check if we already have a service source code set
	if (!LNJS.GV(LNJS.ServiceSourceCode,null))
	{	
	    //check map style
		if ((e.mapStyle == Msn.VE.MapStyle.Oblique) ||
		    (e.mapStyle == Msn.VE.MapStyle.ObliqueHybrid))
		{	//check for map style change
			if(!LNJS.Page.SearchMgr.lastMapEvent)
			{	//first time
				LNJS.Page.SearchMgr.lastMapEvent = e;
			}
			else if(LNJS.Page.SearchMgr.lastMapEvent.mapStyle != e.mapStyle)
			{	//log action code
				LNJS.Page.Log.LogMapStyle(e.mapStyle);
			}
			else if(e.zoomLevel < LNJS.Page.SearchMgr.lastZoomLevel)
			{	//birds eye map zoom out
				LNJS.ServiceSourceCode = LNJS.ServiceSource.ObliqueMapZoomOut;
			}
			else	
			{	//birds eye map zoom in
				LNJS.ServiceSourceCode = LNJS.ServiceSource.ObliqueMapZoomIn;
			}
			//save map event
			LNJS.Page.SearchMgr.lastMapEvent = e;
		}
		else
		{	//map zoom
			if (e.zoomLevel < LNJS.Page.SearchMgr.lastZoomLevel)
			{	//zoom out
				LNJS.ServiceSourceCode = LNJS.ServiceSource.MapZoomOut;
			}
			else	
			{	//zoom in
				LNJS.ServiceSourceCode = LNJS.ServiceSource.MapZoomIn;
			}
		}
	}

	//check if event is valid
	if(!LNJS.Page.SearchMgr._validEvent(!LNJS.Page.SearchMgr._isPD()))
	{	//only logging if we haven't searched, otherwise we are tracking with service source code
		LNJS.Page.Log.LogMapZoom(e.zoomLevel < LNJS.Page.SearchMgr.lastZoomLevel);
		
		//save zoom level
		LNJS.Page.SearchMgr.lastZoomLevel = e.zoomLevel;

		//exit
		return;
	}
	
	LNJS.Trace.source(LNJS.Page.SearchMgr.__className+": Starting endZoom()","onendzoom");
    
    if (!LNJS.Page.SearchMgr.isInitialZoom)
	{
	    //update criteria and search again
	    LNJS.Page.SearchMgr.updateCriteria(e);
	}
	
	LNJS.Page.SearchMgr.isInitialZoom = false;
	
	//clear source code
	LNJS.ServiceSourceCode = LNJS.ServiceSource.Clear;
	
	LNJS.Trace.source(LNJS.Page.SearchMgr.__className+": Done endZoom()","onendzoom");
};

//private method used to hilite a pin, bring it to the top
LNJS.SearchManager.prototype._hilitePin = function(shape, hilite)
{
    if (hilite)
	{
	    //hilite the pin
		//set pin z-index to top of the heap
		if (shape != null)
		{   //use tooltip saved zindex or the one from the pin
	        //LNJS.Trace.source("Setting z-index for pin "+shape.LN.LNID+" from "+shape.orgZIndex+" to "+this.showcaseZ+1);
		    shape.SetZIndex(this.showcaseZ + 1);

            //hilite pin
		    var oPin = $( 'p' + shape.LN.LNID);
		    
		    if(oPin != null)
		    {
		        if(oPin.className.indexOf(' basic') > -1)
		        {   //basic pin
		            oPin.className = "pinBox basicPinHilite";
		        }
		        else if(oPin.className.indexOf(' premium') > -1)
		        {   //premium pin
		            oPin.className = "pinBox premiumPinHilite";
		        }
		        else if(oPin.className.indexOf(' showcase') > -1)
		        {   //showcase pin
		            oPin.className = "pinBox showcasePinHilite";
		        }
		        else if(oPin.className.indexOf(' rs') > -1)
		        {   //resent sales pin
		            oPin.className = "pinBox rsPinHilite";
		        }
		    }
		    
		    oPin = null;	
		}
	}
	else
	{
	    //remove hiliting
		//set pin z-index back where it was
		if (shape != null)
		{
		    //LNJS.Trace.source("Setting z-index for pin "+shape.LN.LNID+" from "+shape.GetZIndex()+" to "+shape.orgZIndex);
		    shape.SetZIndex(shape.orgZIndex);
			
			//remove pin hilite
		    var oPin = $('p' + shape.LN.LNID);
		    
		    if (oPin != null)
		    {
		        if(oPin.className.indexOf(' basic') > -1)
		        {   //basic pin
		            oPin.className = "pinBox basicPin";
		        }
		        else if(oPin.className.indexOf(' premium') > -1)
		        {   //premium pin
		            oPin.className = "pinBox premiumPin";
		        }
		        else if(oPin.className.indexOf(' showcase') > -1)
		        {   //showcase pin
		            oPin.className = "pinBox showcasePin";
		        }
		        else if(oPin.className.indexOf(' rs') > -1)
		        {   //resent sales pin
		            oPin.className = "pinBox rsPin";
		        }
		    }
		    
		    oPin = null;
		}
	}
};

LNJS.SearchManager.prototype.buildCriteria = function()
{    
    if (ll_search_criteria != '')
    {
        //alert('found posted criteria');
        xCriteria = LNJS.Xml.getDomDocument();
		xCriteria = (new DOMParser()).parseFromString(ll_search_criteria, "text/xml");
        
        //RH updated due to FF issues
        if (xCriteria.documentElement == null)
        {
               xCriteria = "";
        }
        else
        {
            xCriteria = xCriteria.documentElement;  
        } 
        
		//MLS Listing Search Criteria
		this.CritMgr.Criteria = new LNPostedCriteria(xCriteria);
		
		//set world wide defaults for lat and long for searching, will override with map mgr
		
		//alert(this.CritMgr.Criteria.toXml());
    }
    else
    {        
        this.CritMgr.Criteria.Editor = 'LL6';
        
        var maxCount = 100;
        
        if (ll_opt760)
        {
            var tempMax = parseInt(ll_opt760value);
            
            if ((tempMax > maxCount) &&
                (tempMax <= 500))
            {
                maxCount = tempMax;
            }
        }
                
        this.CritMgr.Criteria.MaxRowCount = maxCount;
        this.CritMgr.Criteria.MaxSearchRowCount = maxCount;
        
        //set search type
	    this.CritMgr.Criteria.SearchType = this.searchType;
        //add correct status lists
        
	    this.CritMgr.Criteria.StatusList.set("10"); //active
	    this.CritMgr.Criteria.ApprovalStatusList.set("AP,PA");
	    
	    this.CritMgr.Criteria.SortFieldList.removeAll();
	    
	    if (enNGMapMode == 'GalleryNoMap')
	    {
	        oSortField = new LNSortField();
	        
	        oSortField.Name = "ListingType";
	        
	        if ((typeof(displayForLeaseListingsFirst) != 'undefined') &&
	            (displayForLeaseListingsFirst))
            {
                oSortField.Seq = "Desc";
            }
            else
            {
                oSortField.Seq = "Asc";
            }
	        
	        this.CritMgr.Criteria.SortFieldList.add(oSortField);
	    }
	    
	    oSortField = new LNSortField();
	    
	    oSortField.Name = "DateEntered";
	    oSortField.Seq = "Desc";
	    this.CritMgr.Criteria.SortFieldList.add(oSortField);
		
	    // Add default sort fields
	    oSortField = new LNSortField();
		
	    oSortField.Name = "StateProvCode";
	    oSortField.Seq = "Asc";
	    this.CritMgr.Criteria.SortFieldList.add(oSortField);
		
	    oSortField = new LNSortField();
		
	    oSortField.Name = "CityName";
	    oSortField.Seq = "Asc";
	    this.CritMgr.Criteria.SortFieldList.add(oSortField);
		
	    oSortField = new LNSortField();
		
	    oSortField.Name = "SubCategoryName";
	    oSortField.Seq = "Asc";
	    this.CritMgr.Criteria.SortFieldList.add(oSortField);
		
        //check search type
        switch(this.searchType)
        {
	        case "FS": //For Sale
	            //Update Criteria with search type
		        this.CritMgr.Criteria.ListingType.Type = this.searchType;

	          //Set Listing Types
		        this.CritMgr.Criteria.ListingType.ForSaleListing.UseTypeList.set("IN,VO,BU,AU");
		        this.CritMgr.Criteria.ListingType.ForLeaseListing = new LNForLeaseListing();

	          //Set Category List
		        //this.CritMgr.Criteria.CategoryList.set(this._getSelectedCatIds().join(","));

	          //Set Default Sort
		        oSortField = new LNSortField();
		        oSortField.Name = "Price";
		        oSortField.Seq = "Desc";
		        this.CritMgr.Criteria.SortFieldList.add(oSortField);
		        break;

	        case "FL": //For Lease
	          //Update Criteria with search type
		        this.CritMgr.Criteria.ListingType.Type = this.searchType;

	          //Set Listing Types
		        this.CritMgr.Criteria.ListingType.ForLeaseListing.SpaceListing.StatusList.set("10,80"); 
		        this.CritMgr.Criteria.ListingType.ForSaleListing = new LNForSaleListing();

	          //Set Category List
		        this.CritMgr.Criteria.ListingType.ForLeaseListing.SpaceListing.CategoryList.set(this._getSelectedCatIds().join(","));
    			
	          //Exclude Fully Leased Listings
		        this.CritMgr.Criteria.ListingType.ForLeaseListing.FullyLeased.Action = "Exclude";

	          //Set Default Sort
		        oSortField = new LNSortField();
		        //oSortField.Name = "RateMinPerSize";
		        oSortField.Name = "SizeMaxAvail";
		        oSortField.Seq = "Asc";
		        this.CritMgr.Criteria.SortFieldList.add(oSortField);
		        break;

            case "FSFL":
                this.CritMgr.Criteria.ListingType.Type = this.searchType;

	          //Set Listing Types
		        this.CritMgr.Criteria.ListingType.ForSaleListing.UseTypeList.set("IN,VO,BU,AU");
		        this.CritMgr.Criteria.ListingType.ForLeaseListing.SpaceListing.StatusList.set("10,80"); 
		        
	          //Set Category List
		        this.CritMgr.Criteria.ListingType.ForLeaseListing.FullyLeased.Action = "Exclude";

	          //Set Default Sort
		        oSortField = new LNSortField();
		        oSortField.Name = "Price";
		        oSortField.Seq = "Desc";
		        this.CritMgr.Criteria.SortFieldList.add(oSortField);
		        
		        oSortField = new LNSortField();
		        oSortField.Name = "SizeMaxAvail";
		        oSortField.Seq = "Asc";
		        this.CritMgr.Criteria.SortFieldList.add(oSortField);
                break;
	        case "RS":
	          /*TODO*/
		        break;

	        case "PD":  //MLS Property ID Search
	            if ((LNJS.Page.EL) &&
	                (LNJS.Page.EL.suggest))
	            {
	    	        var pid = LNJS.Page.EL.propid.value.trim();
	    	        
		            if (pid.length > 0)
		            {	//add property id into criteria
			            this.CritMgr.Criteria.IncludeListingList.add(pid);
        				
			            //validate criteria
			            this.validateCriteria();
        				
			            LNJS.Page._search();
        				
			            //exit buildCriteria
			            return;
		            }			
		        }	
		        break;

	        default:LNJS.Trace.warn('_buildCriteria() Unknown searchType: '+this.searchType);break;
        }
        //get location
	}
	    
    if (LNJS.Page.MapMgr)
    {
        LNJS.Page.MapMgr.latitude =  LNJS.Page.MapMgr.getCenterLatitude();
        LNJS.Page.MapMgr.longitude = LNJS.Page.MapMgr.getCenterLongitude();
        LNJS.Page.MapMgr.zoomlevel = LNJS.Page.MapMgr.getZoomLevel();
        LNJS.Page.MapMgr.lastZoomLevel = LNJS.Page.MapMgr.zoomlevel;
    }
		
    if ((LNJS.Page.MapMgr) &&
        (enNGMapMode != 'NoMap') &&
        (enNGMapMode != 'GalleryNoMap'))
    {
        this.CritMgr.Criteria.GeographicFilter = new LNGeographicFilter();
	    this.CritMgr.Criteria.GeographicFilter.Radius = new LNRadius();
	    this.CritMgr.Criteria.GeographicFilter.Radius.SearchMode = "Block";
	    
	    oRadius = this.CritMgr.Criteria.GeographicFilter.Radius;		
		
	    oLatLongRect = LNJS.Page.MapMgr.getMapView();
	    oRadius.SearchMode = "Block";
	    oRadius.MinLatitude = oLatLongRect.TopLeftLatLong.Latitude;
	    oRadius.MinLongitude = oLatLongRect.TopLeftLatLong.Longitude;
	    oRadius.MaxLatitude = oLatLongRect.BottomRightLatLong.Latitude;
	    oRadius.MaxLongitude = oLatLongRect.BottomRightLatLong.Longitude; 
		
		/*
        this.CritMgr.Criteria.GeographicFilter.Radius.MinLatitude = LNJS.Page.MapMgr.getLatitude(new VEPixel(0,0));
        this.CritMgr.Criteria.GeographicFilter.Radius.MinLongitude = LNJS.Page.MapMgr.getLongitude(new VEPixel(0,0));
        this.CritMgr.Criteria.GeographicFilter.Radius.MaxLatitude = LNJS.Page.MapMgr.getLatitude(new VEPixel(LNJS.Page.MapMgr.mapHeight());
        this.CritMgr.Criteria.GeographicFilter.Radius.MaxLongitude = LNJS.Page.MapMgr.getLongitude(LNJS.Page.MapMgr.mapWidth()); 
        */
    }
    else
    {
        this.CritMgr.Criteria.GeographicFilter = new LNGeographicFilter();
    }
       
    //validate criteria
	   
    LNJS.Page._search();
};

LNJS.SearchManager.prototype.zoomToDefaultView = function()
{
    if ((this.zoomToStreetClicked) &&
        (this.pData) &&
        (this.pData.resultCount > 0))
    {
        //check if profile is still visible
	    if (Element.visible(LNJS.Page.SearchMgr.popup))
	    {
		    this.hidePinProfile();
		}
		
        this.temporarySearchHasRun = this.searchHasRun;
	
	    this.searchHasRun = false;
        
        //move map
        var minLat = 0;
        var maxLat = 0;
        var minLong = 0;
        var maxLong = 0;
        
        for (var i = this.pageIndex; i < this.pData.resultCount; i++)
        {
	        p = this.pData.items[i];
	        
	        if (p.lat > maxLat || maxLat == 0) maxLat = p.lat;
            if (p.lat < minLat || minLat == 0) minLat = p.lat;
            if (p.lon > maxLong || maxLong == 0) maxLong = p.lon;
            if (p.lon < minLong || minLong == 0) minLong = p.lon;
            
            //check it's cached and clear it
		    if (p.html)
		    {
		        p.html = null;
		    }
        }
        
        if (LNJS.Page.MapMgr)
        {            
            LNJS.Page.SearchMgr.setBestView(
                minLat, 
                minLong, 
                maxLat, 
                maxLong, 
                true);
        }
        
        this.searchHasRun = this.temporarySearchHasRun;
	}
	
	this.zoomToStreetClicked = false;
};

LNJS.SearchManager.prototype._zoomToStreet = function(index)
{
    //if (typeof(bZoomToStreet) != 'undefined')
    //{
    //    bZoomToStreet = false;
    //}
    
    // Get the 'Zoom to Street' link and change the text
	//var zoomToStreetLink = document.getElementById(
	//    'zoomToStreetLink_' +
	//    index);
	
	//if (zoomToStreetLink)
	//{
    //    zoomToStreetLink.title = 'Zoom Out';
    //    zoomToStreetLink.innerText = 'Zoom Out';
	//}
	
    this.zoomToStreetClicked = true;
    
    this.temporarySearchHasRun = this.searchHasRun;
	
	this.searchHasRun = false;
    
    LNJS.Page.zoomToStreet(index);
    
    if ((LNJS.Page.SearchMgr.pData) &&
        (LNJS.Page.SearchMgr.pData.resultCount > index))
	{
	    //check if profile is still visible
	    if (Element.visible(LNJS.Page.SearchMgr.popup))
	    {
		    this.hidePinProfile();
		}
		
		for (var i = this.pageIndex; i < this.pData.resultCount; i++)
        {
            //check it's cached and clear it
		    if (this.pData.items[i].html)
		    {
		        this.pData.items[i].html = null;
		    }
        }
		
	    this.showPinProfile(index);
	}
	
	this.searchHasRun = this.temporarySearchHasRun;
};

LNJS.SearchManager.prototype._zoomFromStreet = function(index)
{
    //if (typeof(bZoomToStreet) != 'undefined')
    //{
    //    bZoomToStreet = true;
    //}
    
    // Get the 'Zoom from Street' link and change the text
	//var zoomFromStreetLink = document.getElementById(
	//    'zoomFromStreetLink_' +
	//    index);
	
	//if (zoomFromStreetLink)
	//{
    //    zoomFromStreetLink.title = 'Zoom to Street';
    //    zoomFromStreetLink.innerText = 'Zoom to Street';
	//}
    
    //this.tempSearchHasRun = this.searchHasRun;
    
    //this.searchHasRun = false;
    
    //if ((typeof(defaultLat) != 'undefined') &&
    //    (typeof(defaultLon) != 'undefined') &&
    //    (typeof(defaultZoom) != 'undefined'))
    //{
    //    LNJS.Page.MapMgr.setCenterAndZoom(
    //        defaultLat, 
    //        defaultLon, 
    //        defaultZoom);
    //}
    
    //this.searchHasRun = this.tempSearchHasRun;
};

//public method used to show and position the pin profile when a pin is clicked
LNJS.SearchManager.prototype.showPinProfile = function(pinIndex)
{	
    //check if the pin is there
    if ((pinIndex == null) ||
        (pinIndex < 0))
	{
		LNJS.Trace.warn("LNJS.SearchManager.showPinProfile(): could not find pin!");
		
		return;
	}
	
	//check if the current pin profile is the same as the one requested to show
	if ((LNJS.Page.SearchMgr.pinIndex == pinIndex) && 
	    (Element.visible(LNJS.Page.SearchMgr.popup)))
	{
	    return;
	}

	//check if profile is still visible
	if (Element.visible(LNJS.Page.SearchMgr.popup))
	{
		this.hidePinProfile();
	}
	
	if ((this.pData) &&
        (this.pData.resultCount) &&
        (this.pData.resultCount > 0) &&
        (this.pData.resultCount > pinIndex))
    {
        //get pin
        var pin = this.pData.items[pinIndex];
        
        if (pin != null)
        {
            var oPin = pin.pin;
            
            if (oPin)
            {
                //check if the current pin profile is the same as the one requested to show
                if ((LNJS.Page.SearchMgr.pinIndex == pinIndex) && 
                    (Element.visible(LNJS.Page.SearchMgr.popup)))
                {
                    return;
                }

                //check if profile is still visible
                if(Element.visible(LNJS.Page.SearchMgr.popup))
                {
	                this.hidePinProfile();
                }
            	
                //turn off the current pin and result list
                this._hiliteItem(false);
            	
                //reset where we were in the list
                this.pinIndex = pinIndex;
            	
                //hilite the new pin and result list
                this._hiliteItem(true);
        
	            //check if the pin html is cached
	            if(this.pData.items[pinIndex].html)
	            {		
		            //hide profile
		            LNJS.Page.SearchMgr.popup.style.visibility = 'hidden';
            		
		            Element.show(LNJS.Page.SearchMgr.popup);
            		
		            Element.innerHTML(
		                LNJS.Page.SearchMgr.popup, 
		                this.pData.items[pinIndex].html);

		            //double check the rent display if pin profile is open
            		
		            if ((this._isFL()) && 
		                (Element.visible(this.popup)))
		            {
			            if ((this.pinIndex != -1) && 
			                ($('ppprenttype')))
			            {
				            var el = $( 
				                'rate' + 
				                this.rentType.toLowerCase() + 
				                this.pinIndex);
            				    
				            if (el)
				            {
				                $('ppprenttype').innerHTML = el.innerHTML;
				            }
            				
				            el = null;
			            }
		            }
            		
		            //double check if we need to select the checkbox
            		
		            this._syncCheckbox(
		                ('rchk' + 
		                    pinIndex),
		                ('pchk' + 
		                    pinIndex));
		            
		            //set location and show profile
		            LNJS.Page.SearchMgr.pinCallOutNum = LNJS.Page.MapMgr.checkXY({
		                vepin:oPin,
		                popup:LNJS.Page.SearchMgr.popup});

                    //hide tool tip incase its showing
                    if (LNJS.Page.EL.ToolTip)
                    {
                        Element.hide(LNJS.Page.EL.ToolTip);
                    }
            		
		            LNJS.Page.SearchMgr.popup.style.visibility = 'visible'; 
            		
		            //check if we want to show the zoom to street link
		            if ((LNJS.Page.MapMgr.getZoomLevel() >= 16) || 
		                 LNJS.Page.MapMgr.isBirdsEye())
		            {
		                Element.hide('zoomtostreet');   
		            }

                    //var pchk2 = document.getElementById('pchk' + pinIndex);
            	
	                //if (pchk2)
	                //{
	                //    pchk2.checked = checked;
	                //}
                		
		            return;
	            }
            	
	            //set service source code if not already set
	            if (LNJS.GV(LNJS.ServiceSourceCode, true))
	            {
		            LNJS.ServiceSourceCode = LNJS.ServiceSource["MapSearchProfilePin"+(LNJS.User.rPID.x()?"":"Basic")];
	            }
            	
	            //Element.show(LNJS.Page.SearchMgr.popup);
            	
	            //set location and show profile
	            /*
	            LNJS.Page.SearchMgr.pinCallOutNum = LNJS.Page.MapMgr.checkXY({
	                vepin:pin,
	                popup:LNJS.Page.SearchMgr.popup});
	            */
            	
	            LNJS.Page.SearchMgr.pinCallOutNum = LNJS.Page.MapMgr.checkXY({
	                vepin:oPin});
            	
	            //set pin profile class name based on the type
	            if(this._isMLS())
	            {
	                this.popup.className = (
	                    "pinprofile " + 
	                    (((!pin.pl) && (!LNJS.User.rPID.x())) ? "basic" : "premium"));
	            }
	            else
	            {
	                //LNJS.User.rSID.y() true if user is rs sub
	                this.popup.className = "pinprofile recentsale-sub";
	            }
            	
	            //make the call to get the pin profile html
	            var options = new Object();
	            options.SOAPMethod = 'GetProfile';
	            options.SOAPNamespace = 'http://www.loopnet.com/WebServices';
	            options.queueLength = 1;
	            options.groupName = 'getProfile';
	            options.onSuccess = function(req){LNJS.Page.SearchMgr._getProfile_callback(req, oPin.LN.idx1);};
            	
	            var reportControlIncluded = false;
            	
	            if (typeof(enNGReportControlIncluded) != 'undefined')
	            {
	                reportControlIncluded = enNGReportControlIncluded;
	            }
            	
	            var mapPinShownOnPage = false;
            	
	            if (typeof(bMapPinShownOnPage) != 'undefined')
	            {
	                mapPinShownOnPage = bMapPinShownOnPage;
	            }
            	
	            var zoomToStreet = true;
            	
	            if (typeof(bZoomToStreet) != 'undefined')
	            {
	                zoomToStreet = bZoomToStreet;
	            }
	            
	            var isInContract = false;
	            
	            var havePrice = true;
	            
	            if ((typeof(pin.lType) != 'undefined') &&
	                (pin.lType != null) &&
	                (pin.lType == 'fs'))
	            {
                    havePrice = (!LNJS.isNull(pin.lPrice) && 
                        (pin.lPrice != 'Price Not Disclosed'));
	            }
		            
                isInContract = (!LNJS.isNull(pin.status) && pin.status == '60');
		        
	            //use xsl to return the pin profile HTML
	            if (this._isMLS())
	            {   //listing pin profile
            	
	                //set sp name based on the search type - what about pin type?
	                var sSPName = 'spGetSingleListingForMap'; //use new sp which doesn't care about the listing type...
            		
		            //alert(GetSoapInput('<PFRequestData><Listing ListingID="'+lid+'"/><RetrievalInstructions><GetListingsFastPath ProcName="'+sSPName+'" DoAccessCheckInd="Y" UseSearchDatabase="True" /></RetrievalInstructions><XmlStyleSheet XSLUrl="ListingPinProfile-v5.6.xsl"><ParamList><Param Name="callout" Value="'+LNJS.Page.SearchMgr.pinCallOutNum+'"/><Param Name="renttype" Value="'+this.rentType+'"/><Param Name="showcase" Value="'+p.sc+'"/><Param Name="pl" Value="'+p.pl+'"/><Param Name="ContentProviderUrl" Value="'+LNJS.contentProviderUrl+'"/><Param Name="index" Value="'+index+'"/><Param Name="conf" Value="'+p.conf+'"/><Param Name="rpid" Value="'+LNJS.User.rPID+'"/><Param Name="enNGReportControlIncluded" Value="'+reportControlIncluded+'"/><Param Name="enShowMapPinOnPage" Value="'+mapPinShownOnPage+'"/></ParamList></XmlStyleSheet></PFRequestData>',options.SOAPMethod,options.SOAPNamespace));
	                options.postBody = GetSoapInput('<PFRequestData><Listing ListingID="'+oPin.LN.LNID+'"/><IsLoopLink>true</IsLoopLink><RetrievalInstructions UOMMoneyCurrency="' + UOMMoneyCurrency + '" UOMListing="' + UOMListing + '" ><GetListingsFastPath ProcName="'+sSPName+'" DoAccessCheckInd="Y" UseSearchDatabase="True" /></RetrievalInstructions><XmlStyleSheet XSLUrl="LL_ListingPinProfile-v5.6.xsl"><ParamList><Param Name="callout" Value="'+LNJS.Page.SearchMgr.pinCallOutNum+'"/><Param Name="renttype" Value="'+this.rentType+'"/><Param Name="showcase" Value="'+pin.sc+'"/><Param Name="pl" Value="'+pin.pl+'"/><Param Name="ContentProviderUrl" Value="'+LNJS.contentProviderUrl+'"/><Param Name="index" Value="'+pinIndex+'"/><Param Name="conf" Value="'+pin.conf+'"/><Param Name="havePrice" Value="'+havePrice+'"/><Param Name="isInContract" Value="'+isInContract+'"/><Param Name="rpid" Value="'+LNJS.User.rPID+'"/><Param Name="enNGReportControlIncluded" Value="'+reportControlIncluded+'"/><Param Name="enShowMapPinOnPage" Value="'+mapPinShownOnPage+'"/><Param Name="zoomToStreet" Value="'+zoomToStreet+'"/></ParamList></XmlStyleSheet></PFRequestData>',options.SOAPMethod,options.SOAPNamespace);
                    //return raw xml for debuging (view xml in trace)
	                //options.postBody = GetSoapInput('<PFRequestData><Listing ListingID="'+lid+'"/><RetrievalInstructions><GetListingsFastPath ProcName="'+sSPName+'" DoAccessCheckInd="Y" UseSearchDatabase="True" /></RetrievalInstructions></PFRequestData>',options.SOAPMethod,options.SOAPNamespace);
	                LNJS.Ajax.post('/xNet/MainSite/WebServices/Listings/Listing.asmx', options);
	            }
	            else
	            {   //comparable pin profile

		            //set sp name based on the search type
    	            var sSPName = 'spGetSingleComparable'+(this._isFS()?'ForSale':'ForLease')+'Map';
	                if (this._isPD())sSPName = 'spGetSingleComparableForMap'; //if propid search use new sp which doesn't care about the listing type...		
            	    
                    //options.postBody = GetSoapInput('<PFRequestData><Comparable ComparableID="'+lid+'"/><RetrievalInstructions><GetComparablesFastPath ProcName="'+sSPName+'" UseSearchDatabase="True" /></RetrievalInstructions><XmlStyleSheet XSLUrl="ComparablePinProfile-v5.6.xsl"><ParamList><Param Name="callout" Value="'+LNJS.Page.SearchMgr.pinCallOutNum+'"/><Param Name="ContentProviderUrl" Value="'+LNJS.contentProviderUrl+'"/><Param Name="index" Value="'+index+'"/></ParamList></XmlStyleSheet></PFRequestData>',options.SOAPMethod,options.SOAPNamespace);
                    options.postBody = GetSoapInput('<PFRequestData><Comparable ComparableID="'+oPin.LN.LNID+'"/><IsLoopLink>true</IsLoopLink><RetrievalInstructions UOMMoneyCurrency="' + UOMMoneyCurrency + '" UOMListing="' + UOMListing + '" ></RetrievalInstructions><XmlStyleSheet XSLUrl="ComparablePinProfile-v5.6.xsl"><ParamList><Param Name="callout" Value="'+LNJS.Page.SearchMgr.pinCallOutNum+'"/><Param Name="ContentProviderUrl" Value="'+LNJS.contentProviderUrl+'"/><Param Name="index" Value="'+pinIndex+'"/><Param Name="havePrice" Value="'+havePrice+'"/><Param Name="isInContract" Value="'+isInContract+'"/><Param Name="rSID" Value="'+LNJS.User.rSID+'"/><Param Name="enNGReportControlIncluded" Value="'+reportControlIncluded+'" /></ParamList></XmlStyleSheet></PFRequestData>',options.SOAPMethod,options.SOAPNamespace);
	                //return raw xml for debuging (view xml in trace)
	                //options.postBody = GetSoapInput('<PFRequestData><Comparable ComparableID="'+lid+'"/><RetrievalInstructions></RetrievalInstructions></PFRequestData>',options.SOAPMethod,options.SOAPNamespace);
	                LNJS.Ajax.post('/xNet/MainSite/WebServices/Comparables/Comparable.asmx', options);
	            }
            	
	            //clear service source code
	            LNJS.ServiceSourceCode = LNJS.ServiceSource.Clear;
	        }
	    }
	}
};

//private function used to position the pin profile and set the correct "call-out"
LNJS.SearchManager.prototype.checkXY = function(args)
{
	//bool true false if user is a PM
	
	if (args.pin)
    {   
        //use the element passed in
        pinOffset = Position.cumulativeOffset(args.pin);
    }
    else if(args.vepin)
    {   
        //look up the pin el from the shape
        el = LNJS.Page.MapMgr.getShapeElByID(args.vepin.GetID());
        
        if (el != null)
        {
            pinOffset = Position.cumulativeOffset(el);
        }
        
        el = null;
    }
    else
    {   //invalid data!
        return;
    }
    
    if (pinOffset)
    {
        if (args.popup)
		{
		    var el = $('p' + args.vepin.LN.LNID);
		    
		    if (el)
		    {
	            var top = parseInt(Element.getStyle(el, 'top'));
	            var left = parseInt(Element.getStyle(el, 'left'));
	            var width = parseInt(Element.getStyle(el, 'width'));
    	        
		        el = null;
    		    
		        //calculate pin offsets
		        var rbb = 8;            //offset for box on right below
		        var rba = (top - 3);      //offset for box on right above
		        var lr = (width + left + 4);  //offset for left box on right
		        var lbb = 9;            //offset for box on left below
		        var lba = (top - 2);      //offset for box on left above
		        var ll = -1;            //offset for left box on left
		    }
		}

	    //var x = LNJS.User.rPID.x();

	    var mapOffset = Position.cumulativeOffset(LNJS.Page.MapMgr.container);
	    var mapSize = Element.getDimensions(LNJS.Page.MapMgr.container);
    	
	    if (pinOffset[0] < (mapOffset[0] + (mapSize.width / 2)))
	    {	
	        //box on right
		    if(pinOffset[1] < (mapOffset[1] + (mapSize.height / 2)))
		    {	
		        //box on below
			    LNJS.Page.SearchMgr.pinCallOutNum = 1;
			    
			    if (args.popup)
			    {
			        args.popup.style.top = (
			            pinOffset[1] + 
			            21 + 
			            'px');
			    }
			        
			    if (args.processor)
			    {   
			        args.processor.setParameter(
			            null, 
			            "callout", 
			            "1");
			    }
		    }
		    else
		    {	
		        //box on above
			    LNJS.Page.SearchMgr.pinCallOutNum = 3;
			    
			    if(args.popup)
			    {
			        args.popup.style.top = (
			            (pinOffset[1] + 
			                3 - 
			                args.popup.offsetHeight) + 
			            'px');
			    }
			        
			    if (args.processor)
			    {
			        args.processor.setParameter(
			            null, 
			            "callout", 
			            "3");
			    }
		    }
    		
		    if (args.popup)
		    {
		        args.popup.style.left = (
		            pinOffset[0] + 
		            25 + 
		            'px');
		    }
	    }
	    else
	    {	
	        //box on left
		    if (pinOffset[1] < (mapOffset[1] + (mapSize.height / 2)))
		    {	
		        //box on below
			    LNJS.Page.SearchMgr.pinCallOutNum = 2;
			    
			    if (args.popup)
			    {
			        args.popup.style.top = (
			            pinOffset[1] + 
			            21 + 
			            'px');
			    }
			    
			    if (args.processor)
			    {
			        args.processor.setParameter(
			            null, 
			            "callout", 
			            "2");
			    }
		    }
		    else
		    {	
		        //box on above
			    LNJS.Page.SearchMgr.pinCallOutNum = 4;
			    
			    if (args.popup)
			    {
			        args.popup.style.top = (
			            (pinOffset[1] + 
			                2 - 
			                args.popup.offsetHeight) + 
			            'px');
			    }
			    
			    if (args.processor)
			    {
			        args.processor.setParameter(
			            null, 
			            "callout", 
			            "4");
			    }
		    }
    		
		    if (args.popup)
		    {
		        args.popup.style.left = (
		            (pinOffset[0] + 
		                2 - 
		                args.popup.offsetWidth) +
		             'px');
		    }
	    }
	}
};

//private method that is the call back for showPinProfile
LNJS.SearchManager.prototype._getProfile_callback = function(req, idx1, idx2)
{
	LNJS.Trace.source(LNJS.Page.SearchMgr.__className+": Starting _getProfile_callback()",LNJS.Page.SearchMgr.__className.toLowerCase()+".getprofile_cb");

	//check if there is a search running
	if(LNJS.Ajax.ActiveAjaxGroupRequestsCount["getProfile"] > 0)
	{
		LNJS.Trace.warn('_getProfile_callback() Profile fetch in progress... exiting!');
		return;
	}
	
	//we need the pin data
	if (!LNJS.Page.SearchMgr.pData)
	{
	    return; 
	}
	
	if (idx1 > LNJS.Page.SearchMgr.pData.length)
	{
		LNJS.Trace.error('Error pin index too high ' + idx1);
		
		return;
	}
	
	//check for xml dom
	if (req.responseXML != null)
	{
		//hide profile
		LNJS.Page.SearchMgr.popup.style.visibility = 'hidden';
		
		Element.show(LNJS.Page.SearchMgr.popup);
		
		//processed with xsl SERVER SIDE
		html = LNJS.Xml.getText(
		    req.responseXML.documentElement.selectSingleNode('//XSLTResult'),
		    1);
		
		if (html)
		{
		    Element.innerHTML(
		        LNJS.Page.SearchMgr.popup,
		        html);
		}
		
		//get pin
		//var oPin = LNJS.Page.MapMgr.getShapeByIndex(idx1);
		var oPin = LNJS.Page.SearchMgr.pData.items[idx1].pin;
		
		if (oPin)
		{
		    //set profile location
		    LNJS.Page.MapMgr.checkXY({
		        vepin:oPin,
		        popup:LNJS.Page.SearchMgr.popup});
		        
		    oPin = null;
		}
		
		//give it some time to render then show pin profile
		setTimeout((function()
		{
			//check if we want to show the zoom to street link
			if ((LNJS.Page.MapMgr.getZoomLevel() >= 16) || 
			     LNJS.Page.MapMgr.isBirdsEye())
			{
				Element.hide('zoomtostreet');
			}
		
		    //double check if we need to select the checkbox
		    this._syncCheckbox(
		        document.forms[0][('rchk' + this.pinIndex)],
		        document.forms[0][('pchk' + this.pinIndex)]);

	        //hide tool tip incase its showing
	        if (LNJS.Page.EL.ToolTip)		
	        {	        
			    Element.hide(LNJS.Page.EL.ToolTip);
			}
		
			//show profile
			LNJS.Page.SearchMgr.popup.style.visibility = 'visible';
			
		}).bind(this),10);
		
		//cache pin profile
		//need to not cache if the password is invalid or the listing is confidential
		if ((html) && 
		    (req.ReturnCode != "30"))
		{
		    LNJS.Page.SearchMgr.pData.items[idx1].html = html;
		}
	}
	else
	{	//something went wrong!
		throw LNJS.Page.SearchMgr.Err("Error! No Xml Returned!");
	}
	
	LNJS.Trace.source(LNJS.Page.SearchMgr.__className+": Done _getProfile_callback()",LNJS.Page.SearchMgr.__className.toLowerCase()+".getprofile_cb");
};

//private method used to hilite a high light the item in the result list
LNJS.SearchManager.prototype._hiliteItem = function(hilite)
{	
	//LNJS.Trace.source(this.__className+": Starting _hiliteItem()",this.__className.toLowerCase()+".hiliteItem");
	
	//check for results and that a pin is selected
	if(!(!LNJS.isNull(this.pData) && this.pinIndex != -1))return;
	
	//get item
	var p = this.pData.items[this.pinIndex];

    if (p != null)
    {
	    //get pin
	    var shape = p.pin;
    	
	    //get type
	    var type = this._getItemType(p);
	    var item = $('i'+this.pinIndex);
    	
	    //hilite pin
	    this._hilitePin(shape,type,hilite);
    	
	    if(hilite)
	    {
		    //hilite result item
		    if(item)
		    {
			    if(type != "showcase")
			    {	//just use bg color
				    //item.style.backgroundColor = this._isMLS()?'#EFF3FF':'#FEE3E3';
				    item.style.backgroundColor = '#EFF3FF';
			    }
		    }
	    }
	    else
	    {//turn off hiliting
		    item = $('i'+this.pinIndex);
		    //remove result item hilite
		    if(item)
		    {
			    if(type != "showcase")
			    {	//just use bg color
				    item.style.backgroundColor = '#FFFFFF';
			    }
		    }
	    }
	}
	
	//kill objects
	p = shape = type = item = null;
	
	//LNJS.Trace.source(this.__className+": Done _hiliteItem()",this.__className.toLowerCase()+".hiliteItem");
};

//private method used to hilite a pin, bring it to the top
LNJS.SearchManager.prototype._hilitePin = function(shape,type,hilite)
{
    if(hilite)
	{//hilite the pin
		//set pin z-index to top of the heap
		if(shape)
		{   //use tooltip saved zindex or the one from the pin
	        //LNJS.Trace.source("Setting z-index for pin "+shape.LN.LNID+" from "+shape.orgZIndex+" to "+this.showcaseZ+1);
		    shape.SetZIndex(this.showcaseZ+1);
		    //shape.Show();
		    
			//hilite pin
		    //Element.addClassName(pin,type+'PinHilite');
		}
	}
	else
	{//remove hiliting
		//set pin z-index back where it was
		if(shape)
		{
		    //LNJS.Trace.source("Setting z-index for pin "+shape.LN.LNID+" from "+shape.GetZIndex()+" to "+shape.orgZIndex);
		    shape.SetZIndex(shape.orgZIndex);
			//shape.Show();
			
			//pin.innerHTML = pin.style.zIndex;
			
			//remove pin hilite
		    //Element.removeClassName(pin,type+'PinHilite');
		}
	}
};

//public method to set map location and zoom level
LNJS.SearchManager.prototype.setBestView = function(minLat, minLon, maxLat, maxLon, noSearchIfMapDoesntMove)
{	
	LNJS.Trace.source(LNJS.Page.SearchMgr.__className+": Starting setBestView()","setbestview");
		
	//get current coordinates and zoom level
	bCenter = LNJS.Page.MapMgr.getCenter();
	bZoomLevel = LNJS.Page.MapMgr.getZoomLevel();
	
	LNJS.Trace.source("BEFORE Map Center Lat/Lon/Zoom: "+bCenter.Latitude+"/"+bCenter.Longitude+"/"+bZoomLevel);
	
	//reset boolean so we know if set best view is doing the panning
	LNJS.Page.SearchMgr.SearchCalledByBestView = false;
    
    //convert our info to M$ VE class
    var oTopLeft = new VELatLong(minLat, minLon);
    var oBottomRight = new VELatLong(maxLat, maxLon);
	
	LNJS.Trace.source("SET MAP VIEW; Top Left Lat/Lon: "+oTopLeft.Latitude+"/"+oTopLeft.Longitude+" Bottom Right Lat/Lon: "+oBottomRight.Latitude+"/"+oBottomRight.Longitude);

	//call set best map view
	LNJS.Page.MapMgr.setMapView(new VELatLongRectangle(oTopLeft, oBottomRight));
	
	//get current coordinates and zoom level
	nCenter = LNJS.Page.MapMgr.getCenter();
	nZoomLevel = LNJS.Page.MapMgr.getZoomLevel();
	LNJS.Page.SearchMgr.lastZoomLevel = nZoomLevel;
	
	// Check to see if this is zoomed in all the way
	// so we can zoom out
	if (nZoomLevel >= 18)
	{
	    nZoomLevel = 17;
	    
	    LNJS.Page.MapMgr.setCenterAndZoom(nCenter, nZoomLevel);
	}
	
	LNJS.Trace.source("AFTER Map Center Lat/Lon/Zoom: "+nCenter.Latitude+"/"+nCenter.Longitude+"/"+nZoomLevel);
	
	//check if the map coordinates have changed, if NOT call search manually
	if(!LNJS.Page.SearchMgr.SearchCalledByBestView &&
	  ((nCenter.Latitude == bCenter.Latitude && nCenter.Longitude == bCenter.Longitude)||
	  (nZoomLevel == bZoomLevel))) 
	{
	    if (!noSearchIfMapDoesntMove)
	    {
		    LNJS.Trace.source("Nothing changed need to call search manually!");
    		
		    //update criteria and search again
		    LNJS.Page.SearchMgr.updateCriteria();
		}
	}
	
	LNJS.Trace.source(LNJS.Page.SearchMgr.__className+": Done setBestView()","setbestview");
};

LNJS.SearchManager.prototype.setSiteOptionNoResultsView = function(lat, lon, zoomlevel)
{
    var nCenter = new VELatLong(lat, lon);
    
    LNJS.Page.MapMgr.setCenterAndZoom(nCenter, zoomlevel);
};

LNJS.SearchManager.prototype.setDefaultNoResultsView = function()
{
    var nCenter = LNJS.Page.MapMgr.getCenter();
    
    LNJS.Page.MapMgr.setCenterAndZoom(nCenter, 1);
};

//method for ploting the listings on the map as pins
LNJS.SearchManager.prototype._plotPins = function()
{
    this.zoomToStreetClicked = false;
    
    for (var i = 0; i < this.CritMgr.Criteria.SortFieldList.items.length; i++)
    {
        oSortField = new LNSortField();
        
        oSortField = this.CritMgr.Criteria.SortFieldList.items[i];
        
        if ((oSortField) &&
            (oSortField.Name == 'DateEntered'))
        {
            this.CritMgr.Criteria.SortFieldList.remove(i);
            break;
        }
    }
	    
	LNJS.Trace.source(this.__className+": Starting _plotPins()",this.__className.toLowerCase()+".plotpins");
	
	var minLat = 0;
    var maxLat = 0;
    var minLong = 0;
    var maxLong = 0;
        
	var hasResults = false;
	
	//check for results
	if ((!LNJS.isNull(this.pData)) &&
	    (LNJS.Page.MapMgr) &&
	    (!LNJS.isNull(this.pData.items)) &&
	    (this.pData.items.length > 0))
	{
	    hasResults = true;
	    
	    var pinNumber = this.pageIndex;
	    
		for (var i = this.pageIndex; i < this.pData.resultCount; i++)
		{
			p = this.pData.items[i];
			
			if (p != null)
			{
			    id = (p.lid || p.cid);
			    
			    if (this.adjustMapBasedOnPins)
                {
                    if ((LNJS.isNull(p.lat)) || 
				        (LNJS.isNull(p.lon)))
				    {
				        LNJS.Trace.warn('_plotPins() Listing '+id+' does not have a lat/lon!');
				    }
				    else if ((p.lat == 0) &&
				        (p.lon == 0))
				    {
				        LNJS.Trace.warn('_plotPins() Listing '+id+' does not have a lat/lon!');
				    }
				    else
                    { 
                        if ((p.lat > maxLat) || 
                            (maxLat == 0))
                        {
                            maxLat = p.lat;
                        }
    		            
		                if ((p.lat < minLat) || 
		                    (minLat == 0))
		                { 
		                    minLat = p.lat;
		                }
		           
		                if ((p.lon > maxLong) || 
		                    (maxLong == 0)) 
		                {
		                    maxLong = p.lon;
		                }
    		            
		                if ((p.lon < minLong) || 
		                    (minLong == 0))
		                {
		                    minLong = p.lon;
		                }
		            }
                }
    			
			    //plot only if Listing is NOT confidential
			    if (!p.conf)
			    {
				    if ((LNJS.isNull(p.lat)) || 
				        (LNJS.isNull(p.lon)) ||
				        ((p.lat == 0) &&
				            (p.lon == 0)))
				    {
					    LNJS.Trace.warn('_plotPins() Listing '+id+' does not have a lat/lon!');
				    }
				    else
				    {
					    var classname = (this._isMLS() ? "pinBox premiumPin" : "pinBox rsPin");
    					//var imageURL = (this._isMLS() ? "/images/search/map/pins/premium.png" : "/images/search/map/pins/rs-sub.pn");
					    
					    //create new pin
                        var oPin = new VEShape(
                            VEShapeType.Pushpin, 
                            new VELatLong(p.lat, p.lon)); 
                        
                        //set custom properties
                        oPin.LN = new Object();
                        oPin.LN.LNID = id;
                        oPin.LN.idx1 = i;
                        
                        oPin.Id = (
                            'pin_' +
                            pinNumber +
                            '_' +
                            id);
                            
                        oPin.orgZIndex = this._getZIndex(
                            p, 
                            pinNumber);
                        
                        oPin.SetCustomIcon(
                            "<div id='p" + 
                            id + 
                            "' class='" + 
                            classname + 
                            "'>" +
                            (1 + pinNumber) + 
                            "</div>");
                            
                        pinNumber++;
                            
                        //set pin ZIndex
                        oPin.SetZIndex(oPin.orgZIndex);
                        
                        //add pin to map
                        LNJS.Page.MapMgr.addShape(oPin);
                        
                        p.pin = oPin;
                        
                        oPin = null;
				    }
			    }
			}
			
			p = null;
		}
		
		//get REAL result count for bird's eye because the count is no longer accurate. :-(
		/*
        if (LNJS.Page.MapMgr.isBirdsEye())
        {
            LNJS.Trace.info("Current Result Count "+resultCount);
            
            realCount = 0;
            
            items = [];
            
            for (x = 0; x < this.pData.resultCount; x++)
            {
                shapeEl = null;
                
                shape = LNJS.Page.MapMgr.getShapeByIndex(x);
                
		        if(shape)
		        {
		            if (shape.Primitives[0])
		            {
		                shapeEl = $(shape.Primitives[0].iid);
		            }
		        }
		        
                if(shapeEl)
                {
                    //update pin number to be correct
                    classname = this._isMLS()?"pinBox premiumPin":"pinBox rsPin";
                    
                    shape.SetCustomIcon(
                        "<div id='p" + 
                        shape.LN.LNID + 
                        "' class='" + 
                        classname + 
                        "'>" + 
                        (1 + realCount) + 
                        "</div>");
                        
                    shape.LN.idx1 = realCount;                
                    
                    items[realCount] = this.pData.items[x];
                    
                    shape = shapeEl = null;
                    realCount++;
                }
            }
            
            //reset items and count
            LNJS.Trace.info("Real Pin Count "+realCount);
            this.pData.items = items;
            this.pData.resultCount = realCount;
            
            items = null;
        }
        */
	}

    //hide updating map message
	LNJS.Page.hideUpdatingMapMsg();
	
	if ((!LNJS.isNull(this.pData)) &&
	    (LNJS.Page.MapMgr))
	{
	    //check result count
	    if(this.pData.resultCount == 100)
	    {	
	        //show the 100+ results message
		    //LNJS.Page.showMsg(LNJS.Page.Msgs.result100plus);
	    }
	    else if(this.pData.resultCount == 0)
	    {	//set no results message text based on the criteria used
		    var msgText = new StringBuilder();
		    msgText.append('<p>No results found.</p>');
		    //msgText.append('<ul>');
    		
		    //check map style and zoom level
		    if ((LNJS.Page.MapMgr) &&
		        (LNJS.Page.MapMgr.isBirdsEye()) && 
		        (LNJS.Page.MapMgr.getZoomLevel() == 1))
		    {
			    msgText.append('<li><a href="javascript://" onclick="LNJS.Page.MapMgr.setZoomToAerial(16);">Zoom Out to Aerial Street View</a></li>');
		    }
		    else
		    {	//show normal zoom out message
			    msgText.append('<li><a href="javascript://" onclick="LNJS.Page.MapMgr.zoomOut();">Zoom Out</a></li>');
		    }

            if (LNJS.Page.EL.result0text)
            {
		        LNJS.Page.EL.result0text.innerHTML = msgText.toString();
		    }
    		
		    //show the no results message
		    if (LNJS.Page.EL.result0msg)
		    {
		        Element.show(LNJS.Page.EL.result0msg);
		    }
	    }
	}
	
	if (this.adjustMapBasedOnPins)
    {
        this.temporarySearchHasRun = this.searchHasRun;
        
        this.searchHasRun = false;
        
        //move map
        if (LNJS.Page.MapMgr)
        {            
            if (hasResults)
            {
                LNJS.Page.SearchMgr.setBestView(minLat, minLong, maxLat, maxLong, true);
                
                if (LNJS.Modal)LNJS.Modal.fade();
            }
            else if ((typeof(ll_opt1170) != 'undefined') &&
                (ll_opt1170 != null) &&
                (ll_opt1170) &&
                (typeof(ll_opt1170value) != 'undefined') &&
                (ll_opt1170value != null) &&
                (ll_opt1170value != '') &&
                (typeof(ll_opt1180) != 'undefined') &&
                (ll_opt1180 != null) &&
                (ll_opt1180) &&
                (typeof(ll_opt1180value) != 'undefined') &&
                (ll_opt1180value != null) &&
                (ll_opt1180value != '') &&
                (typeof(ll_opt1190) != 'undefined') &&
                (ll_opt1190 != null) &&
                (ll_opt1190) &&
                (typeof(ll_opt1190value) != 'undefined') &&
                (ll_opt1190value != null) &&
                (ll_opt1190value != ''))
            {
                LNJS.Page.SearchMgr.setSiteOptionNoResultsView(
                    ll_opt1170value, 
                    ll_opt1180value, 
                    ll_opt1190value);
            }
            else if ((typeof(mapNoSearchResultsLatitudeVar) != 'undefined') &&
                (mapNoSearchResultsLatitudeVar != null) &&
                (mapNoSearchResultsLatitudeVar != '') &&
                (typeof(mapNoSearchResultsLongitudeVar) != 'undefined') &&
                (mapNoSearchResultsLongitudeVar != null) &&
                (mapNoSearchResultsLongitudeVar != '') &&
                (typeof(mapNoSearchResultsZoomLevel) != 'undefined') &&
                (mapNoSearchResultsZoomLevel != null) &&
                (mapNoSearchResultsZoomLevel != ''))
            {
                LNJS.Page.SearchMgr.setSiteOptionNoResultsView(
                    mapNoSearchResultsLatitudeVar,
                    mapNoSearchResultsLongitudeVar,
                    mapNoSearchResultsZoomLevel);
            }
            else
            {
                LNJS.Page.SearchMgr.setDefaultNoResultsView();
                
                this.isInitialSearch = false;
            }
        }
                
        this.searchHasRun = this.temporarySearchHasRun;
                
        this.adjustMapBasedOnPins = false;
    }
	
	LNJS.Trace.source(this.__className+": Done _plotPins()",this.__className.toLowerCase()+".plotpins");
};

//public method used to update the search criteria from the page
LNJS.SearchManager.prototype.updateCriteria = function(event)
{

	LNJS.Page.SearchMgr.nonGeocodedListingsPresent = true;
    var geocodedOnly = true;
    
    if (this.isInitialSearch)
    {
        this.isInitialSearch = false;
        
        geocodedOnly = false;
        //return;
    }
    
    var newevent = (event)?event:window.event;
    
	LNJS.Trace.source(this.__className+": Starting updateCriteria()",this.__className.toLowerCase()+".updatecriteria");

	//clear messages
	LNJS.Page.hideMsg();
	
	//get lat/lon and zoom
	/*
	if(LNJS.isNull(newevent))
	{
		latitude = LNJS.Page.MapMgr.getCenterLatitude();
		longitude = LNJS.Page.MapMgr.getCenterLongitude();
		zoomLevel = LNJS.Page.MapMgr.getZoomLevel();
	}
	else
	{
	    if (LNJS.isNull(newevent.view))
	    {	    
		    latitude = LNJS.Page.MapMgr.getCenterLatitude();
		    longitude = LNJS.Page.MapMgr.getCenterLongitude();
		    zoomLevel = LNJS.Page.MapMgr.getZoomLevel();
	    }
	    else
	    {
	        if (LNJS.isNull(newevent.view.latlong))
	        {	    
		        latitude = LNJS.Page.MapMgr.getCenterLatitude();
		        longitude = LNJS.Page.MapMgr.getCenterLongitude();
		        zoomLevel = LNJS.Page.MapMgr.getZoomLevel();
	        }
	        else
	        {
		        latitude = newevent.view.latlong.latitude;
		        longitude = newevent.view.latlong.longitude;
		        zoomLevel = newevent.view.zoomLevel;
		    }
		}
	}
	
	LNJS.Trace.debug("Lat: "+latitude+"; Lon: "+longitude+"; Zoom: "+zoomLevel+";");
	*/
	
	this.CritMgr.Criteria.GeographicFilter = new LNGeographicFilter();
	
	this.CritMgr.Criteria.GeographicFilter.GeocodedOnly = geocodedOnly;
	this.CritMgr.Criteria.GeographicFilter.Radius = new LNRadius();
	this.CritMgr.Criteria.GeographicFilter.Radius.SearchMode = "Block";
	
    oRadius = this.CritMgr.Criteria.GeographicFilter.Radius;		
	
	if (LNJS.Page.MapMgr.isBirdsEye())
	{
	    oLatLongRect = LNJS.Page.MapMgr.getBirdseyeScene().GetBoundingRectangle();
	}
	else
	{
	    oLatLongRect = LNJS.Page.MapMgr.getMapView();
	}
    
    oRadius.SearchMode = "Block";
    oRadius.MinLatitude = oLatLongRect.TopLeftLatLong.Latitude;
    oRadius.MinLongitude = oLatLongRect.TopLeftLatLong.Longitude;
    oRadius.MaxLatitude = oLatLongRect.BottomRightLatLong.Latitude;
    oRadius.MaxLongitude = oLatLongRect.BottomRightLatLong.Longitude;
    
    this.CritMgr.Criteria.GeographicFilter.Radius = oRadius;

	//validate the criteria
	this.CritMgr.Criteria.Editor = 'LL6';
	
	//run the search!
	LNJS.Page.SearchMgr.performSearch();
	LNJS.Page.SearchMgr.IsUpdate=true;
	
	LNJS.Trace.source(this.__className+": Done updateCriteria()",this.__className.toLowerCase()+".updatecriteria");
};

//public method used to open the listing profile in a new window (when a confidential result item is clicked)
LNJS.SearchManager.prototype.llShowListingProfile = function(lid, stid)
{	
    var url = (
        '/xNet/Looplink/Profile/Profile.aspx?stid=' + 
        stid + 
        '&LID=' + 
        lid + 
        '&LL=true' +
        '&UOMListing=' +
        UOMListing +
        '&UOMMoneyCurrency='+
        UOMMoneyCurrency +
        '&RentPer=' + 
        sCurRentShowAs +
        '&SearchResultID=' + searchID);
	
	var w_height = (screen.height ? screen.height : 620);	
	var w_newHeight = (w_height > 620 ? w_height : 620);	
	
	LNJS.Page.openWindow(
	{
	    url:url,
	    features:
	        'width=1000,' +
	        ('height=' + 
	            w_newHeight +
	            ',') +	            
	        'top=30,' +
	        'left=30,' +
	        'toolbar=no,' +
	        'location=no,' +
	        'directories=no,' +
	        'status=yes,' + 
	        'scrollbars=yes,' +
	        'resizable=yes,' +
	        'menubar=no,' +
	        'screenX=200,' +
	        'screenY=200'
	});
};
//public method used to open the listing profile in a new window (when a confidential result item is clicked)
LNJS.SearchManager.prototype.llShowBrokerProfile = function(lid, stid, seqnum)
{	
    var url = (
        '/xNet/Looplink/Profile/EmailBrokerLL.aspx?stid=' + 
        stid + 
        '&LID=' + 
        lid + 
        '&seqnum=' + 
        seqnum + 
        '&LL=true');
	
	var w_height = (screen.height ? screen.height : 620);	
	var w_newHeight = (w_height > 620 ? w_height : 620);	
	
	LNJS.Page.openWindow(
	{
	    url:url,
	    features:
	        'width=800,' +
	        ('height=' + 
	            w_newHeight +
	            ',') +	            
	        'top=30,' +
	        'left=30,' +
	        'toolbar=no,' +
	        'location=no,' +
	        'directories=no,' +
	        'status=yes,' + 
	        'scrollbars=yes,' +
	        'resizable=yes,' +
	        'menubar=no,' +
	        'screenX=200,' +
	        'screenY=200'
	});
};

var __CurrentPropertyIsSpotlight = false;

//private method for filling the result list
LNJS.SearchManager.prototype._renderResultList = function() {
    LNJS.Page.SearchMgr._setPinNumbers();

    for (var i = 0; i < this.CritMgr.Criteria.SortFieldList.items.length; i++) {
        oSortField = new LNSortField();

        oSortField = this.CritMgr.Criteria.SortFieldList.items[i];

        if ((oSortField) &&
            (oSortField.Name == 'DateEntered')) {
            this.CritMgr.Criteria.SortFieldList.remove(i);
            break;
        }
    }

    LNJS.Trace.source(this.__className + ": Starting _renderResultList()", this.__className.toLowerCase() + ".renderresultlist");

    var rlist = new StringBuilder();
    var count = LNJS.isNull(this.lData) ? 0 : this.lData.resultCount;
    //check if everything is selected

    var selectAllCheckBox = document.getElementById('llRH-SelectAll');
    if (selectAllCheckBox != null && selectAllCheckBox.checked) {
        selectAll(selectAllCheckBox);
    }
    //check for result length
    var listingListEventBuilder = new StringBuilder();
    var searchType = LNJS.Page.SearchMgr.CritMgr.Criteria.SearchType;
    if (searchType == "FSFL")
        searchType = "SL";
    searchType = "W" + searchType;
    if (LNJS.Page.SearchMgr.CritMgr.Criteria.Editor == 'LL6')
        searchType = searchType.replace('W', 'M');
    listingListEventBuilder.append('<EventData SearchID="' + searchID + '" ListingCount="' + count + '" SearchType="' + searchType + '">')
    listingListEventBuilder.append('<SearchResultsSummary SearchID="' + searchID + '">');
    listingListEventBuilder.append('<ListingList>');

    if (count > 0) {
        //check for MLS search
        if (this._isMLS()) {	//loop through the list of results and add each selecting the proper template

            //bool true false if user is a PM
            var x = LNJS.User.rPID.x();

            var startIndex = this.pageIndex;
            var endIndex = count;

            if (typeof pagerControlSupported != "undefined") {
                if ((pagerControlSupported) &&
			        (!ll_opt1010)) {
                    pager(LNJS.Page.SearchMgr.currentPage, count);
                    this.pagingSupported = pagerControlSupported;
                    startIndex = this.pageStartIndex;
                    endIndex = (this.pageSize + startIndex) > count ? count : (this.pageSize + startIndex);
                }
            }

            if (enNGMapMode == 'GalleryNoMap') {
                if (typeof (resultsSorted) != 'undefined') {
                    if (!resultsSorted) {
                        if ((startIndex <= this.lData.items.length) &&
		                    (this.lData.items[startIndex].type == 'fs')) {
                            rlist.append('<div class="llRD-data llRD-tableTitle">');

                            rlist.append('<h3>For Sale</h3>');
                            rlist.append('</div>');
                        }
                        else if ((startIndex <= this.lData.items.length) &&
	                        (this.lData.items[startIndex].type == 'fl')) {

                            rlist.append('<div class="llRD-data llRD-tableTitle">');

                            rlist.append('<h3>For Lease</h3>');
                            rlist.append('</div>');
                        }
                    }
                }

                if (typeof (forSaleForLeaseSort) != 'undefined') {
                    if (forSaleForLeaseSort) {
                        if ((startIndex <= this.lData.items.length) &&
		                    (this.lData.items[startIndex].type == 'fs')) {
                            rlist.append('<div class="llRD-data llRD-tableTitle">');
                            rlist.append('<h3>For Sale</h3>');
                            rlist.append('</div>');
                        }
                        else if ((startIndex <= this.lData.items.length) &&
	                        (this.lData.items[startIndex].type == 'fl')) {
                            rlist.append('<div class="llRD-data llRD-tableTitle">');
                            rlist.append('<h3>For Lease</h3>');
                            rlist.append('</div>');
                        }
                    }
                }
            }

            if ((typeof (resultsTableWidth) != 'undefined') &&
	            (resultsTableWidth != '')) {
                rlist.append('<table id="mapResultsTable" cellspacing="0" cellpadding="0" class="llRD-data" style="width: ' + resultsTableWidth + ';">');
            }
            else {
                rlist.append('<table id="mapResultsTable" cellspacing="0" cellpadding="0" class="llRD-data">');
            }

            for (var i = startIndex; i < endIndex; i++) {
                p = this.lData.items[i];
                type = this._getItemType(p);

                listingListEventBuilder.append('<Listing ListingID="' + p.lid + '"/>');

                var listingIsNonGeocoded = false;

                if (LNJS.Page.SearchMgr.nonGeocodedListingsPresent && !LNJS.Page.SearchMgr.IsUpdate) {
                    if ((LNJS.isNull(p.lat)) ||
			            (LNJS.isNull(p.lon)) ||
			            ((p.lat == 0) &&
			                (p.lon == 0))) {
                        listingIsNonGeocoded = true;
                    }
                }

                // Adding check for confidential listings since those
                // will not be plotted (ICP #20911) -BT (SLTC)
                if (p.conf) {
                    listingIsNonGeocoded = true;
                }

                if (ll_opt1280) {
                    // add header for spotlight properties.
                    if (!resultsSorted)  // only if not yet sorted
                    {
                        // We have to get this info from the pin items
                        var pinPointItem = LNJS.Page.SearchMgr.pData.items.find(function(value, index) { if (value.lid == p.lid) return true; else return false; });
                        if (pinPointItem && pinPointItem.sfl && !__CurrentPropertyIsSpotlight) {
                            // this is a spotlight property and currently we have not had spotlights
                            // create SpotLight header
                            rlist.append("<tr class='llSearchResultsSpotlightPropertiesHeaderRow'><td colspan='50'>Spotlight Properties</td></tr>");

                            __CurrentPropertyIsSpotlight = pinPointItem.sfl;
                        }
                        else if (pinPointItem && !pinPointItem.sfl && __CurrentPropertyIsSpotlight) {
                            // not spotlight and we've been getting spotlights
                            rlist.append("<tr class='llSearchResultsPropertiesHeaderRow'><td colspan='50'>Properties</td></tr>");

                            __CurrentPropertyIsSpotlight = pinPointItem.sfl;
                        }
                    }
                }



                if ((enNGMapMode == 'MapOnly') ||
			        (enNGMapMode == 'MapResultsToSide') ||
			        (enNGMapMode == 'MapResultsBelow')) {
                    this._buildHTML(
		                i,
		                type,
		                p,
		                rlist,
		                x,
		                LNJS.Page.SearchMgr.nonGeocodedListingsPresent,
		                listingIsNonGeocoded);
                }
                else if ((enNGMapMode == 'NoMap') ||
		            (enNGMapMode == 'GalleryNoMap')) {
                    this._buildHTML(
		                i,
		                type,
		                p,
		                rlist,
		                x);
                }

                if (enNGMapMode == 'GalleryNoMap') {
                    if (typeof (resultsSorted) != 'undefined') {
                        if (!resultsSorted) {
                            if ((p.type == 'fs') &&
		                        ((i + 1) < this.lData.items.length) &&
		                        (this.lData.items[(i + 1)].type == 'fl')) {
                                rlist.append('</table>');
                                rlist.append('<div class="llRD-data llRD-tableTitle">');
                                rlist.append('<h3>For Lease</h3>');
                                rlist.append('</div>');
                                rlist.append('<table cellspacing="0" cellpadding="0" class="llRD-data">');
                            }
                            else if ((p.type == 'fl') &&
		                        ((i + 1) < this.lData.items.length) &&
		                        (this.lData.items[(i + 1)].type == 'fs')) {
                                rlist.append('</table>');
                                rlist.append('<div class="llRD-data llRD-tableTitle">');
                                rlist.append('<h3>For Sale</h3>');
                                rlist.append('</div>');
                                rlist.append('<table cellspacing="0" cellpadding="0" class="llRD-data">');
                            }
                        }
                    }

                    if (typeof (forSaleForLeaseSort) != 'undefined') {
                        if (forSaleForLeaseSort) {
                            if ((p.type == 'fs') &&
		                        ((i + 1) < this.lData.items.length) &&
		                        (this.lData.items[(i + 1)].type == 'fl')) {
                                rlist.append('</table>');
                                rlist.append('<div class="llRD-data llRD-tableTitle">');
                                rlist.append('<h3>For Lease</h3>');
                                rlist.append('</div>');
                                rlist.append('<table cellspacing="0" cellpadding="0" class="llRD-data">');
                            }
                            else if ((p.type == 'fl') &&
		                        ((i + 1) < this.lData.items.length) &&
		                        (this.lData.items[(i + 1)].type == 'fs')) {
                                rlist.append('</table>');
                                rlist.append('<div class="llRD-data llRD-tableTitle">');
                                rlist.append('<h3>For Sale</h3>');
                                rlist.append('</div>');
                                rlist.append('<table cellspacing="0" cellpadding="0" class="llRD-data">');
                            }
                        }
                    }
                }
            }

            rlist.append('</table>');
        }
        else {   //add message for non-subs
            if (!LNJS.User.rSID.y())
                rlist.append("<br>Select the records you would like to view<br><br>");

            rlist.append('<table cellspacing="0" cellpadding="0" class="llRD-data">');
            //build result list for comparables
            for (var i = this.pageIndex; i < count; i++) {
                p = this.lData.items[i];
                type = this._getItemType(p);
                listingListEventBuilder.append('<Listing ListingID="' + p.lid + '"/>');
                this._buildHTML(i, type, p, rlist, x);
            }

            rlist.append('</table>');
        }
    }
    else if ((typeof (pagerControlSupported) != 'undefined') &&
	    (pagerControlSupported) &&
	    (!ll_opt1010)) {
        pager(LNJS.Page.SearchMgr.currentPage, count);
        this.pagingSupported = pagerControlSupported;
    }
    else if ((((typeof (pagerControlSupported) != 'undefined') &&
	    (!pagerControlSupported)) ||
	    (typeof (pagerControlSupported) == 'undefined') ||
	    (ll_opt1010)) &&
	    ((ll_search_criteria != '') &&
	    (document.getElementById('resultCount') == null))) {
        LNJS.Page.Msgs.add(
        {
            title: "",
            text: "No Results Found",
            x: "92px",
            y: "245px"
        },
        {
            name: "noResultsFound"
        });

        LNJS.Page.showMsg(LNJS.Page.Msgs.noResultsFound);
    }

    listingListEventBuilder.append('</ListList>');
    listingListEventBuilder.append('</SearchResultSummary>');
    listingListEventBuilder.append('</EventData>');

    LNJS.Page.Log.__LogEvent({ eventclass: 90, eventtype: 30, eventdata: listingListEventBuilder.toString() });

    //check search type
    if (this._isMLS() && !LNJS.Page.searchMode) {
        if (this.supportsSavedSearch) {
            //last item is save search
            rlist.append('<div id="resultSaveSearchMsg" class="results-saveSearch">');
            rlist.append('    <img src="' + LNJS.contentProviderUrl + '/images/search/map/saveSearch-results-title.gif" />');
            rlist.append('    <p>Save this search to get email alerts of new listings in this area that match your criteria.</p>');
            rlist.append('    <table cellspacing="0">');
            rlist.append('	    <tr>');
            rlist.append('		    <th>Name Search</th>');
            rlist.append('		    <td colspan="6" class="nameSearch"><input type="text" id="criterionName2" name="criterionName2" maxlength="50" autocomplete="off" value="' + LNJS.Page.EL.criterionName.value + '" /></td>');
            rlist.append('	    </tr>');
            rlist.append('	    <tr>');
            rlist.append('		    <th>Alert Setting</th>');
            rlist.append('		    <td>&nbsp;<label for="alertWeekly2" onmousedown="LNJS.Page.setSaveOption($(\'alertWeekly2\'));"><input type="radio" class="alert-radio" name="alertSetting2" id="alertWeekly2" checked="checked" value="WK" onmousedown="LNJS.Page.setSaveOption(this);" />Weekly</label></td><td><label for="alertDaily2" onmousedown="LNJS.Page.setSaveOption($(\'alertDaily\'));"><input type="radio" name="alertSetting2" id="alertDaily2" value="DA" class="alert-radio" />Daily</label></td><td><label for="alertNone2" onmousedown="LNJS.Page.setSaveOption($(\'alertNone2\'));"><input type="radio" name="alertSetting2" id="alertNone2" value="OFF" class="alert-radio" />None</label></td>');
            rlist.append('	    </tr>');
            rlist.append('    </table>');
            rlist.append('    <a href="javascript:void(0);" onmousedown="LNJS.Page.saveSearchCriteria(true);" title="Save Search"><img src="' + LNJS.contentProviderUrl + '/images/search/map/saveSearch-button.gif" title="Save Search" style="float: right; margin: 5px 0 0 0;" /></a>');
            rlist.append('    <label for="contactInfo2"><input type="checkbox" name="contactInfo" id="contactInfo2" value="Y" checked="checked" class="alert-checkbox" />Release my contact info to brokers with matching listings</label>');
            rlist.append('</div>');
        }
    }

    //now that we have the content, put it in the container element
    Element.innerHTML(this.resultcont, rlist.toString());

    //reset the result list scroll location to the top
    this.resultcont.scrollTop = 0;

    //give it time to render
    setTimeout((function() {
        this.haveResultList = true;

        //if(this.profileZoomLock)
        //{	//find the item in the result list
        //var item = this._findItemByLatLon(this.profileZoomLock.lat,this.profileZoomLock.lon);

        //if(item)
        //{
        //show profile
        //this.showPinProfile(item.pin);
        //}

        //kill it
        //item = null;
        //this.profileZoomLock = null;
        //}
    }).bind(this), 10);

    if (enNGReportControlIncluded) {
        preserveSelections();
    }

    LNJS.Trace.source(this.__className + ": Done _renderResultList()", this.__className.toLowerCase() + ".renderresultlist");


    if (document.getElementById('NoResultsAlert')) {
        if (count > 0)
            document.getElementById('NoResultsAlert').style.display = 'none';
        else
            document.getElementById('NoResultsAlert').style.display = '';



    }
};


var LNPostedCriteria = Class.create();
LNPostedCriteria.prototype = (new LNJS.Xml.Base()).extend({
  initialize: function(initDoc){
	this.__className = "LNPostedCriteria";
	this.__nodeName = "SearchCriteria";
	this.__initDoc = initDoc;
	this.SearchType = "FS";
	this.MaxCount = "100";
	this.UseSearchDatabase = "Y";
	this.MaxSearchRowCount = "100";
	this.Editor = LNJS.DataType.NullString;
	this.SearchCriterionID = LNJS.DataType.NullNumber;
	this.StatusList = new LNStatusList();
	this.ApprovalStatusList = new LNApprovalStatusList();
	this.CategoryList = new LNCategoryList();
    this.GeographicFilter = new LNGeographicFilter();
    this.SizeRange = new LNSizeRange();
    this.YearBuiltRange = new LNYearBuiltRange();
    this.SortFieldList = new LNSortFieldList();
    this.SortOrder = new LNSortOrder();
    this.IncludeListingList = new LNIncludeListingList();
    this.ListingKeywords = new LNListingKeywords();
    this.DateEnteredRange = new LNDateEnteredRange();
    this.ListingType = new LNListingTypeList();
    
    var maxCount = 100;
    
    if (ll_opt760)
    {
        var tempMax = parseInt(ll_opt760value);
        
        if ((tempMax > maxCount) &&
            (tempMax <= 500))
        {
            maxCount = tempMax;
        }
    }
            
    this.MaxCount = maxCount;
    this.MaxSearchRowCount = maxCount;
  },
  toXml: function(){
    //alert(this.GeographicFilter.toXml());
    //alert(this.__initDoc.xml);
    var xml = this.__initDoc.xml.replace(new RegExp("<GeographicFilter/>", "" ), this.GeographicFilter.toXml());
    //alert(xml);
    return xml;
  }  
});

LNJS.MapManager.prototype.clearPushpins = function()
{
	this.deleteAllShapeLayers();
};

//paging function
//DO NOT DELETE or it will break the page -- JS
LNJS.SearchManager.prototype.setupPager = function(curPg, resCnt)
{
	return;
};
