// JavaScript Document
function change_state()
{
	if(document.search_box.state.value != '')
		window.location.href = 'http://www.foreclosure1.com/listings/'+document.search_box.state.value+'/';
	else
		window.location.href = 'http://www.foreclosure1.com/listings/';
}

function change_county()
{
	if(document.search_box.county.value != '')
		window.location.href = 'http://www.foreclosure1.com/listings/'+document.search_box.state.value+'/'+document.search_box.county.value+'/';
	else
		window.location.href = 'http://www.foreclosure1.com/listings/'+document.search_box.state.value+'/';
}

function change_city()
{
	if(document.search_box.city.value != '')
		window.location.href = 'http://www.foreclosure1.com/listings/'+document.search_box.state.value+'/'+document.search_box.county.value+'/'+document.search_box.city.value+'/';
	else
		window.location.href = 'http://www.foreclosure1.com/listings/'+document.search_box.state.value+'/'+document.search_box.county.value+'/';
}

function change_zipcode()
{
	var pagina;
	if(document.search_box.zipcode.value != '')
	{
		pagina = 'http://www.foreclosure1.com/listings/zipcode/'+document.search_box.zipcode.value+'/';
	}
	else
	{
		if(document.search_box.state.value != '')
		{
			pagina = 'http://www.foreclosure1.com/listings/'+document.search_box.state.value;
			if(document.search_box.county.value != '')
			{
				pagina += '/'+document.search_box.county.value;
				if(document.search_box.city.value != '')
				{
					pagina += '&city='+document.search_box.city.value;
				}
			}
		}
	}
	window.location.href = pagina;
}
function limit_search(state_sg, county_name, city, property_type, order_by, regs_per_page)
{
	var url, x, i;
	if(document.search_form.zipcode.value != '')
	{
		url = 'http://www.foreclosure1.com/listings/zipcode/'+document.search_form.zipcode.value+'/';
	}
	else
	{
		if(state_sg != '')
		{
			url = 'http://www.foreclosure1.com/listings/'+state_sg+'/';
			if(county_name != '')
			{
				url += county_name+'/';
				if(city != '')
				{
					url += city+'/';
				}
			}
		}
		else
			url = 'http://www.foreclosure1.com/listings/';
	}
	url += '?property_type='+property_type;
	
	if(document.search_form.min_price.value != 0 || document.search_form.max_price.value != -1)
		url += '&min_price='+document.search_form.min_price.value+'&max_price='+document.search_form.max_price.value;
	if(document.search_form.beds.value != '')
		url += '&beds='+document.search_form.beds.value;
	if(document.search_form.baths.value != '')
		url += '&baths='+document.search_form.baths.value;
	
	if(order_by != '')
		url += '&order_by='+order_by;
	
	if(regs_per_page != '')
		url += '&regs_per_page='+regs_per_page;
	
	document.location = url;
}

function order(state_sg, county, city, zipcode, property_type, min_price, max_price, beds, baths, regs_per_page)
{
	var x, i, url;
	
	if(zipcode != '')
	{
		url = 'http://www.foreclosure1.com/listings/zipcode/'+zipcode+'/?';
	}
	else
	{
		if(state_sg != '')
		{
			url = 'http://www.foreclosure1.com/listings/'+state_sg+'/';
			if(county != '')
			{
				url += county+'/';
				if(city != '')
				{
					url += city+'/';
				}
			}
		}
		else
			url = 'http://www.foreclosure1.com/listings/';
	}
	url += '?property_type='+property_type;
	
	if(regs_per_page != '')
		url += '&regs_per_page='+regs_per_page;
	
	if(min_price != '')
		url += '&min_price='+min_price;
	
	if(max_price != '')
		url += '&max_price='+max_price;
	
	if(beds != '')
		url += '&beds='+beds;
	
	if(baths != '')
		url += '&baths='+baths;
	
	if(document.form_order.order_by.value != '')
		 url += '&order_by='+document.form_order.order_by.value;
	
	window.location.href = url;
}

function check_zipcode(){
	var zipcode;
	
	zipcode = document.getElementById("zipcode_search").value;
	
	if(zipcode == "")
		alert("Please fill the zipcode.");
	else 
		document.search_box2.submit();
}