
function validatecityorcountyselected()
{
	var countyID = 0;
	var cityID = 0;
	countyID = _oLP_Utility.getSelectedDetails(NRTLP.LandingPage.Search.GlobalObject.ddlCounties());

	cityID = _oLP_Utility.getSelectedDetails(NRTLP.LandingPage.Search.GlobalObject.ddlCities());

	if (countyID == 0 )
	{
		if (cityID == 0)
		{
			var errMsg = NRTLP.LandingPage.Search.GlobalObject.lblCountyCityErrMsg();
			errMsg.innerHTML = 'Please select either a county or city before performing the search';
			return false;
		}
	}

	
	return gotosearchpage(countyID, cityID);
}
function validatecityselected(countyID)
{
    var cityID = 0;
    cityID = _oLP_Utility.getSelectedDetails(NRTLP.LandingPage.Search.GlobalObject.ddlCities());
    
    return gotosearchpage(countyID, cityID);
}

function gotosearchpage(countyID, cityID)
{
	var url = NRTLP.LandingPage.Search.County.getURL();
//	var sProperties = '';
//	sProperties = 'scrollBars=no,resizable=no,toolbar=no,menubar=no,location=no,directories=no,width=500,height=500';
	var searchURL = "";
	searchURL = NRTLP.LandingPage.Search.GlobalObject.getSearchURL(url,countyID, cityID);
	
	window.location = searchURL;
    return false;
}		

function landing_newWindow(url, properties)
{
	var newWindow;
	var sProperties = '';

	if (properties == '')
		{
			sProperties = 'scrollBars=no,resizable=no,toolbar=no,menubar=no,location=no,directories=no,width=500,height=500';
		}
	else
		sProperties = properties;
		
	window.open(url, 'landing', sProperties);
}

// Removes spaces, tabs, and any other non-digit characters.
function removeNonDigits(field) 
{
	if(fieldHasValue(field)) 
	{
		field.value = field.value.replace(/[^0-9,]/gi,"");
	}
}

function fieldHasValue(field)
{
	return (field != null && field.value != null && field.value.length > 0);
}

function highlightrow(oItem,sMode)
{
	try
	{
		var sDefaultClassName = 'lp_tbl_row';
		var sOverClassName = 'lp_tbl_highlight_row';
	
		if(oItem!=null)
		{
			if(sMode=='on')
			{
				//turn 'on' hover class
				oItem.className = sOverClassName;

				
			}else if(sMode=='off'){
			
				//turn 'off' hover class
				oItem.className = sDefaultClassName;
				
				
			}
		}
		return;

	}//end try
	catch(err)
	{
		alert('Error on highlightrow');
		return;
	}//end catch
}

NRTLP.namespace('LandingPage.Search');

NRTLP.LandingPage.Search.County = function()
{
	var _stateCD = '';
	var _URL = '';

	return {
		/*******************************************************************************************************************
		*									P U B L I C   P R O P E R T I E S
		*******************************************************************************************************************/
		


		getStateCD: function()
		{
			return _stateCD;
		},
		
		setStateCD: function(Code)
		{
			_stateCD = Code;
		},
		
		getURL: function()
		{
			return _URL;
		},

		setURL:function(Code)
		{
			_URL = Code;
		},
		/*******************************************************************************************************************
		*									P U B L I C   M E T H O D S
		*******************************************************************************************************************/
		/*==================================================================================
			Method		: getLocations
			Summary		: Gets the locations for the county that was selected.
			Author		: Dale Lawless
			Create Date	: 08/10/2006
		====================================================================================*/														
		getLocations: function() 
		{
			try
			{		
				var countyID = 0;
				var stateCD = NRTLP.LandingPage.Search.County.getStateCD();
				var aLocations = null;
				
				countyID = _oLP_Utility.getSelectedDetails(NRTLP.LandingPage.Search.GlobalObject.ddlCounties());
								
				//Check for Select County
				if (countyID != 0)
				{
					var response = SearchController.GetCities(stateCD, countyID);
					if(NRTLP.Utility.browserType()=="ie")
					{
						aLocations = response.value;
					}
					else
					{
						aLocations = response.request.responseXML;
					}
					this._FillLocationList(aLocations);
				}
				else
				{
					var response = SearchController.GetCities(stateCD, -1);	
					aLocations = response.value;
					this._FillLocationList(aLocations);
				}
			}
			catch(err)
			{
				_oErrorHandler.Error('NRTLP.LandingPage.Search.County.getLocations', _oErrorHandler.ERRORTYPE_JS, err);
				return;
			}				
		},

		/*******************************************************************************************************************
		*								P R I V A T E   M E T H O D S
		*******************************************************************************************************************/		
		/*==================================================================================
			Method		: _FillLocationList
			Summary		: FFills the the location list.
			Author		: Dale Lawless
			Create Date	: 08/10/2006
		====================================================================================*/																
		_FillLocationList: function(aLocations)
		{
			if(aLocations != null)
			{
				_xnCityList=aLocations.childNodes[0];
							
				var ddlCities=NRTLP.LandingPage.Search.GlobalObject.ddlCities();
							
				// Clear location listbox				
				ddlCities.innerHTML = '';
						
				for(var i=0; i<_xnCityList.childNodes.length; i++)
				{
					if(NRTLP.Utility.browserType()=="ie")
					{
						ddlCities.options[ddlCities.length] = new Option(_xnCityList.childNodes[i].text, _xnCityList.childNodes[i].getAttribute("id"), false, false);
					}
					else
					{
						if (_xnCityList.childNodes[i].nodeType==1)
						{
							ddlCities.options[ddlCities.length] = new Option(_xnCityList.childNodes[i].textContent,_xnCityList.childNodes[i].getAttribute("id"), false, false);
						}
					}	
				}	
			}
		}
	};
}();

NRTLP.LandingPage.Search.GlobalObject = function() 
{

    return {  

		/*******************************************************************************************************************
		*			D R O P D O W N   L I S T   C O N T R O L S
		*******************************************************************************************************************/	
		ddlCounties: function()
		{
			return NRTLP.Utility.getElementByTagNameAndID('ddlCounties','SELECT');
		},

		ddlCities: function()
		{
			return NRTLP.Utility.getElementByTagNameAndID('ddlCities','SELECT');
		},
	
		lblCountyCityErrMsg: function()
		{
			return NRTLP.Utility.getElementByTagNameAndID('lblCountyCityErrMsg','DIV');
		},
		
		ddlProptype: function()
		{
			return NRTLP.Utility.getElementByTagNameAndID('lstPropType','SELECT');
		},
		
		ddlMinPrice: function()
		{
			return NRTLP.Utility.getElementByTagNameAndID('ddlMinPrice','SELECT');
		},

		txtMinPrice: function()
		{
			return NRTLP.Utility.getElementByTagNameAndID('txtMinPrice','INPUT');
		},

		ddlMaxPrice: function()
		{
			return NRTLP.Utility.getElementByTagNameAndID('ddlMaxPrice','SELECT');
		},

		txtMaxPrice: function()
		{
			return NRTLP.Utility.getElementByTagNameAndID('txtMaxPrice','INPUT');
		},

		ddlMinBeds: function()
		{
			return NRTLP.Utility.getElementByTagNameAndID('ddlMinBeds','SELECT');		
		},

		txtMinBeds: function()
		{
			return NRTLP.Utility.getElementByTagNameAndID('txtMinBeds','INPUT');
		},

        getSearchURL: function(url, countyid, cityid)
        {
        	var s;
        	var countyname;
        	var cityname;
        	///property/propertyresults.aspx?CallingPage=6&PropSearch=0&CountyIDList={CountyID}&MinPrice={MinPrice}&MaxPrice={MaxPrice}&MinBed={MinBed}&page=1&rpp=10&CityIDList={CityID}
        	s = url;
        	
        	if (countyid == 0)
        	{
        	    countyid = "";
        	    countyname = "";
        	}
        	else
        	{
        	    countyname = _oLP_Utility.getSelectedText(NRTLP.LandingPage.Search.GlobalObject.ddlCounties());
	        }
	            
	        s = NRTLP.LandingPage.Search.GlobalObject.replaceInUrl( s, '{CountyID}', countyid);
	        s = NRTLP.LandingPage.Search.GlobalObject.replaceInUrl( s, '{CountyName}', countyname);
	        
	        if (cityid == 0)
	        {
	            cityid = "";
	            cityname = "";
	        }
	        else
	        {
    	        cityname = _oLP_Utility.getSelectedText(NRTLP.LandingPage.Search.GlobalObject.ddlCities());
    	    }
    	            

	        s = NRTLP.LandingPage.Search.GlobalObject.replaceInUrl( s, '{CityID}', cityid);
	        s = NRTLP.LandingPage.Search.GlobalObject.replaceInUrl( s, '{CityName}', cityname);
	        
	        
            var proptypeddl = NRTLP.LandingPage.Search.GlobalObject.ddlProptype();
	        var proptype = _oLP_Utility.getSelectedDetails(proptypeddl);
            var proptypedesc = _oLP_Utility.getSelectedText(proptypeddl);
	        if ( proptypedesc == null )
	        {
    	        proptypedesc = "";    
    	    }

    	    if ( proptype == null )
    	    {
    	        proptype = "";
            }           

            s = NRTLP.LandingPage.Search.GlobalObject.replaceInUrl( s, '{PropTypeDesc}', proptypedesc); 
            s = NRTLP.LandingPage.Search.GlobalObject.replaceInUrl( s, '{PropType}', proptype); 

            var minprice;
            var minpricevalue;
            var minpriceddl = NRTLP.LandingPage.Search.GlobalObject.ddlMinPrice()
            if (minpriceddl == null)
            {
	            minprice = _oLP_Utility.getTextValue(NRTLP.LandingPage.Search.GlobalObject.txtMinPrice());
	            if (minprice != null)
	            {
	                minpricevalue = minprice[0];
	            }
	        }
	        else
	        {
	            minpricevalue = _oLP_Utility.getSelectedDetails(minpriceddl);
	            var minpricedesc = _oLP_Utility.getSelectedText(minpriceddl);
	        }

            if (minpricevalue == null )
            {
                minpricevalue = "";
            }    	    
    	    if ( minpricedesc == null )
	        {
    	        minpricedesc = "";
    	    }
	        
	        s = NRTLP.LandingPage.Search.GlobalObject.replaceInUrl( s, '{MinPrice}', minpricevalue); 
            s = NRTLP.LandingPage.Search.GlobalObject.replaceInUrl( s, '{MinPriceDesc}', minpricedesc); 
	        
	        var maxprice;
	        var maxpricevalue;
	        var maxpriceddl = NRTLP.LandingPage.Search.GlobalObject.ddlMaxPrice();
	        
	        if (maxpriceddl == null)
	        {
	            maxprice = _oLP_Utility.getTextValue(NRTLP.LandingPage.Search.GlobalObject.txtMaxPrice());
	            if (maxprice != null)
	            {
	                maxpricevalue = maxprice[0];
	             }
	        }
	        else
	        {
	            maxpricevalue = _oLP_Utility.getSelectedDetails(maxpriceddl);
	        	var maxpricedesc = _oLP_Utility.getSelectedText(maxpriceddl);
	        }

	         if (maxpricedesc == null)
	         {
	            maxpricedesc = "";
	         }
	         if (maxpricevalue == null)
	         {
	            maxpricevalue = "";
	         }
	         
	         s = NRTLP.LandingPage.Search.GlobalObject.replaceInUrl( s, '{MaxPriceDesc}', maxpricedesc); 
	         s = NRTLP.LandingPage.Search.GlobalObject.replaceInUrl( s, '{MaxPrice}', maxpricevalue); 

	        
	        var minbed;
	        var minbedvalue;
	        var minbedddl = NRTLP.LandingPage.Search.GlobalObject.ddlMinBeds();
	        if (minbedddl == null)
        	{
        	    minbed = _oLP_Utility.getTextValue(NRTLP.LandingPage.Search.GlobalObject.txtMinBeds());
        	    if (minbed != null)
        	    {
        	        minbedvalue = minbed[0];
        	    }
        	        
        	}
        	else
        	{
        	    minbedvalue = _oLP_Utility.getSelectedDetails(minbedddl);
        	    var minbedsdesc = _oLP_Utility.getSelectedText(minbedddl);
        	}


	        if (minbedsdesc == null)
	        {
	            minbedsdesc = "";
    	    } 
    	    
    	    if (minbedvalue == null)
    	    {
    	        minbedvalue = "";
    	    }
	        s = NRTLP.LandingPage.Search.GlobalObject.replaceInUrl( s, '{MinBedsDesc}', minbedsdesc);
	        s = NRTLP.LandingPage.Search.GlobalObject.replaceInUrl( s, '{MinBed}', minbedvalue);         
	        
	        
	        return s;
        },

        replaceInUrl: function(s, search, replace)
        {
            var proptypefound = s.indexOf(search);
    
            if (proptypefound > 1)
            {
                if (replace != null)
                {
	                s = s.substring(0,proptypefound) + replace + s.substring(proptypefound+search.length);
	            }
	            else
	            {
	                s = s.substring(0,proptypefound) + '' + s.substring(proptypefound+search.length);
	            }
        	}
            return s;
        }    
			
	};	
}();

