
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);
}

function createStateURL()
{
	var propHttp = getElementById_s('httpstring').value;
	var minPrice = getElementById_s('minPrice').value;
	var maxPrice = getElementById_s('maxPrice').value;
	var propertyType = getElementById_s('propType').value;
	var minBed = getElementById_s('beds').value;
    var county = getElementById_s('counties').value;
    var countyCity = getElementById_s('cities').value;
    var citytemp;
    var cityvalue;
    
    if((county == null) || (county == '0'))
    {
       propHttp = propHttp.replace(/<county>/gi,'');             
    }
    else
    {
	    propHttp = propHttp.replace(/<county>/gi,county);
    }
   
    if( (countyCity == null) || (countyCity == '0') || (countyCity == 'undefined') )
    {
        propHttp = propHttp.replace(/<city>/gi,'');   
    }
    else
    {
        citytemp = countyCity.split('_')
        if(citytemp.length > 1)
        {
            cityvalue = citytemp[1];
        }
        propHttp = propHttp.replace(/<city>/gi,cityvalue);         
    }

    propHttp = propHttp.replace(/<minPrice>/gi,minPrice);
	propHttp = propHttp.replace(/<maxPrice>/gi,maxPrice);
	propHttp = propHttp.replace(/<minBed>/gi,minBed);
	propHttp = propHttp.replace(/<propType>/gi,propertyType);



	window.location.href = propHttp;
}

function createCountyURL()
{
	var propHttp = getElementById_s('httpstring').value;
	var minPrice = getElementById_s('minPrice').value;
	var maxPrice = getElementById_s('maxPrice').value;
	var propertyType = getElementById_s('propType').value;
	var minBed = getElementById_s('beds').value;
    
    var county = document.getElementById('county');
	if(county == null)
	{ 
		propHttp = propHttp.replace(/<county>/gi,''); 
	}
	else
	{
		county = county.innerText;
		if((county == null) || (county == ''))
	    {
	       propHttp = propHttp.replace(/<county>/gi,'');             
	    }
	    else
	    {
		    propHttp = propHttp.replace(/<county>/gi,county);
	    }
	}

    var city = document.getElementById('cities');
    if( (city == null) || (city == '0') || (city == 'undefined') )
    {
        propHttp = propHttp.replace(/<city>/gi,'');   
    }
    else
    {
        propHttp = propHttp.replace(/<city>/gi,city.value);         
    }

    propHttp = propHttp.replace(/<minPrice>/gi,minPrice);
	propHttp = propHttp.replace(/<maxPrice>/gi,maxPrice);
	propHttp = propHttp.replace(/<minBed>/gi,minBed);
	propHttp = propHttp.replace(/<propType>/gi,propertyType);



	window.location.href = propHttp;
}

function createCityURL()
{
	var propHttp = getElementById_s('httpstring').value;
	var minPrice = getElementById_s('minPrice').value;
	var maxPrice = getElementById_s('maxPrice').value;
	var propertyType = getElementById_s('propType').value;
	var minBed = getElementById_s('beds').value;
    
    var county = document.getElementById('countyname');
	if(county == null)
	{ 
		propHttp = propHttp.replace(/<county>/gi,''); 
	}
	else
	{
		county = county.innerText;
		if((county == null) || (county == ''))
	    {
	       propHttp = propHttp.replace(/<county>/gi,'');             
	    }
	    else
	    {
		    propHttp = propHttp.replace(/<county>/gi,county);
	    }
	}

    var city = document.getElementById('cityname');
    if( (city == null) || (city == '0') || (city == 'undefined') )
    {
        propHttp = propHttp.replace(/<city>/gi,'');   
    }
    else
    {
        propHttp = propHttp.replace(/<city>/gi,city.value);         
    }

    propHttp = propHttp.replace(/<minPrice>/gi,minPrice);
	propHttp = propHttp.replace(/<maxPrice>/gi,maxPrice);
	propHttp = propHttp.replace(/<minBed>/gi,minBed);
	propHttp = propHttp.replace(/<propType>/gi,propertyType);



	window.location.href = propHttp;
}

function getCityList(countyName, citylist)
{
    var i;
	var cityNodes;
	var tempCityNode1;
	var tempCityNode2;
	var optionList;
	var includeCity;
	var cityHtml;
	var displayAll;

	displayAll = false;
	
	optionList = '';
	cityNodes = citylist.split('<city>'); 

	for(i=1; i < cityNodes.length; ++i)
	{
		
		tempCityNode1 = cityNodes[i];
		tempCityNode2 = tempCityNode1.split('</city>');
		cityNode = tempCityNode2[0];
		
		startIndexOfCountyAttr = cityNode.indexOf('cnty');
		startIndexOfValueAttr = cityNode.indexOf('val');
		
		county = cityNode.substring(startIndexOfCountyAttr + 5, startIndexOfValueAttr - 1)			 		

		if((countyName == '0') || (countyName == ''))
		{
			displayAll = true;
		}

		includeCity = false;
		if(county.toLowerCase() == countyName.toLowerCase())
		{
			includeCity = true;
		}

		if ((displayAll == true) || (includeCity == true))
		{
			
    	startIndexOfTextAttr = cityNode.indexOf('txt');
			startIndexOfEndingSlash = cityNode.indexOf('/>');
			
			value = '';
			value = cityNode.substring(startIndexOfValueAttr + 4, startIndexOfTextAttr - 1)
			
			text = ''
			text = cityNode.substring(startIndexOfTextAttr + 4, startIndexOfEndingSlash)
			
			if((displayAll == true) || ( (displayAll == false) && (value !='') && (text !='') )  )
			{
				optionList = optionList + '<option value="' + county + '_' + value + '">' + text + '</option>'
			}
		}
	}
 	
	cityHtml = '<select name="cities" size="1">';
	cityHtml = cityHtml + '<option value="0">All Cities</option>'
	cityHtml = cityHtml + optionList + '</select>';
	cities.outerHTML = cityHtml;
}

function dltypeof( vExpression )
{
    var sTypeOf = vExpression.type

    return sTypeOf;
}


	
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 getElementById_s(id)
{
	var obj = null;
		
	obj = document.getElementsByName(id)[0];

	return obj;
}


