// JavaScript Document
var path='http://www.foreclosurelistings.com/';
function change_state()
{
	if(document.getElementById("state_sg").value != '')
		window.location.href = path + 'list/'+document.getElementById("state_sg").value+'/';
	else
		window.location.href = path + 'list-state/';
}

function change_county()
{
	if(document.getElementById("county_name").value != '')
		window.location.href = path + 'list/'+document.getElementById("state_sg").value+'/'+document.getElementById("county_name").value+'/';
	else
		window.location.href = path + 'list/'+document.getElementById("state_sg").value+'/';
}

function change_city()
{
	//if(document.search_box.city.value != '')
	if(document.getElementById("city").value != '')
		window.location.href = path + 'list/'+document.getElementById("state_sg").value+'/'+document.getElementById("county_name").value+'/'+document.getElementById("city").value+'/';
	else
		window.location.href = path + 'list/'+document.getElementById("state_sg").value+'/'+document.getElementById("county_name").value+'/';
}

function change_zipcode()
{
	var pagina;
	if(document.getElementById("zipcode2").value != '')
	{
		pagina = path + 'list/zipcode/'+document.getElementById("zipcode2").value+'/';
	}
	else
	{
		if(document.getElementById("state_sg").value != '')
		{
			pagina = path + 'list/'+document.getElementById("state_sg").value+'/';
			if(document.getElementById("county_name").value != '')
			{
				pagina += document.getElementById("county_name").value+'/';
				if(document.getElementById("city").value != '')
				{
					pagina += document.getElementById("city").value+'/';
				}
			}
		}
		else
		{
			pagina = 'list-state/';
		}
	}
	window.location.href = pagina;
}

function rtrim(str, char) {
	for(var j=str.length-1; j>=0 && str.charAt(j) == char; j--) ;
	return str.substring(0,j+1);
}

function limit_search(state_sg, county_name, city, property_type, order_by, regs_per_page)
{
	var url, x, i;
	
	var zipcode = document.getElementById("zipcode").value;
	if(zipcode != '')
	{
		url = path+'list/zipcode/'+zipcode+'/';
		if(property_type != ''){
			url += property_type+'/';
		}
		url += '?';
	}
	else
	{
		url = path+'list/'+state_sg+'/'+county_name+'/';
		if(city != ''){
			url += city+'/';
		}
		if(property_type != ''){
			url += property_type+'/';
		}
		url += '?';
	}
	
	if(document.getElementById("min_price").value != 0 || document.getElementById("max_price").value != -1)
		url += '&min_price='+document.getElementById("min_price").value+'&max_price='+document.getElementById("max_price").value;
	if(document.limit_box.beds.value != '')
		url += '&beds='+document.limit_box.beds.value;
	if(document.limit_box.baths.value != '')
		url += '&baths='+document.limit_box.baths.value;
	
	x = document.getElementsByName('property_style[]');
	for(i=0; i<x.length; i++)
		if(x[i].checked == true)
			url += '&property_style[]='+x[i].value;
	url = rtrim(url, '?');
	document.location = url;
}
/*
function order(county_name, city, state_sg, property_type, zipcode, miles, ini, regs_per_page, min_price, max_price, beds, baths)
{
	var x, i, url;
	
	url = '';
	x = document.getElementsByName('property_style[]');
	for(i=0; i<x.length; i++)
		if(x[i].checked == true)
			url += '&property_style[]='+x[i].value;
		
	if(document.order_by.ordem.value == '')
		document.order_by.ordem.value = 'asc';
	if(document.order_by.item.value != '')
		window.location.href = path + 'lview.php?county_name='+county_name+'/'+city+'&state_sg='+state_sg+'&property_type='+property_type+'&zipcode='+zipcode+'&miles='+miles+'&order_by='+document.order_by.item.value+' '+document.order_by.ordem.value+'&ini='+ini+'&regs_per_page='+regs_per_page+'&min_price='+min_price+'&max_price='+max_price+'&beds='+beds+'&baths='+baths+url;
	else
		window.location.href = path + 'lview.php?county_name='+county_name+'/'+city+'&state_sg='+state_sg+'&property_type='+property_type+'&zipcode='+zipcode+'&miles='+miles+'&ini='+ini+'&regs_per_page='+regs_per_page+'&min_price='+min_price+'&max_price='+max_price+'&beds='+beds+'&baths='+baths+url;
}*/

function order(state_sg, county_name, city, zipcode, property_type, miles, min_price, max_price, beds, baths, ini, regs_per_page)
{
	var x, i, url;
	
	url = '';
	x = document.getElementById('order_by');
	if(zipcode != '')
	{
		url = path+'list/zipcode/'+zipcode+'/';
		if(property_type != ''){
			url += property_type+'/';
		}
		url += '?';
	}
	else
	{
		url = path+'list/'+state_sg+'/'+county_name+'/';
		if(city != ''){
			url += city+'/';
		}
		if(property_type != ''){
			url += property_type+'/';
		}
		url += '?';
	}
	if(ini != '' && ini != 0)
		url += '&ini='+ini;
	if(regs_per_page != '' && regs_per_page != 25)
		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(x.value != ''&& x.value != 'property_register_date')
		url += '&order_by='+x.value;
	url = rtrim(url, '?');
	window.location.href = url;
	//window.location.href = url + '&ini='+ini+'&regs_per_page='+regs_per_page+'&min_price='+min_price+'&max_price='+max_price+'&beds='+beds+'&baths='+baths+'&order_by='+x.value
}

function order2(state_sg, county_name, city, zipcode, property_type, miles, min_price, max_price, beds, baths, ini, regs_per_page)
{
	var x, i, url, root_url;
	
	root_url = '';
	if(zipcode != '')
	{
		root_url = path+'list/zipcode/'+zipcode+'/';
		if(property_type != ''){
			root_url += property_type+'/';
		}
		root_url += '?';
	}
	else
	{
		root_url = path+'list/'+state_sg+'/'+county_name+'/';
		if(city != ''){
			root_url += city+'/';
		}
		if(property_type != ''){
			root_url += property_type+'/';
		}
		root_url += '?';
	}
	
	if(ini != '' && ini != 0)
		root_url += '&ini='+ini;
	if(regs_per_page != '' && regs_per_page != 25)
		root_url += '&regs_per_page='+regs_per_page;
	if(min_price != '')
		root_url += '&min_price='+min_price;
	if(max_price != '')
		root_url += '&max_price='+max_price;
	if(beds != '')
		root_url += '&beds='+beds;
	if(baths != '')
		root_url += '&baths='+baths;
	
	x = document.getElementById('order_by');
		
	for(i=0; i<x.length; i++)		
		if(x[i].selected == true && x[i].value != 'property_register_date')
			url += '&order_by='+x[i].value;
	url = rtrim(url, '?');
	window.location.href = root_url+url;
	//window.location.href = root_url+'&ini='+ini+'&regs_per_page='+regs_per_page+'&min_price='+min_price+'&max_price='+max_price+'&beds='+beds+'&baths='+baths+url;

}

function change_zipcode2()
{
	if(document.getElementById("zipcode").value != '')
	{
		window.location.href = path + 'list/zipcode/'+document.getElementById("zipcode").value+'/';
	}	
}

function jump(state_sg, county_name, city, zipcode, property_type, miles, min_price, max_price, beds, baths, order_by, regs_per_page, total_rows)
{
	var page = document.getElementById('jump_page').value;
	if(zipcode != '')
	{
		url = path+'list/zipcode/'+zipcode+'/';
		if(property_type != ''){
			url += property_type+'/';
		}
		url += '?';
	}
	else
	{
		url = path+'list/'+state_sg+'/'+county_name+'/';
		if(city != ''){
			url += city+'/';
		}
		if(property_type != ''){
			url += property_type+'/';
		}
		url += '?';
	}
	
	ini = (page-1) * regs_per_page;
	if(ini > total_rows){
		ini = total_rows - total_rows%regs_per_page;
	}
	
	if(ini != '' && ini != 0)
		url += '&ini='+ini;
	if(regs_per_page != '' && regs_per_page != 25)
		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(order_by != '')
		url += '&order_by='+order_by;
	url = rtrim(url, '?');
	window.location.href = url;
}

function change_regs_per_page(state_sg, county_name, city, zipcode, property_type, miles, min_price, max_price, beds, baths, order_by, regs_per_page)
{
	if(zipcode != '')
	{
		url = path+'list/zipcode/'+zipcode+'/';
		if(property_type != ''){
			url += property_type+'/';
		}
		url += '?';
	}
	else
	{
		url = path+'list/'+state_sg+'/'+county_name+'/';
		if(city != ''){
			url += city+'/';
		}
		if(property_type != ''){
			url += property_type+'/';
		}
		url += '?';
	}
	
	if(regs_per_page.options[regs_per_page.selectedIndex].value != '' && regs_per_page.options[regs_per_page.selectedIndex].value != 25)
		url += '&regs_per_page='+regs_per_page.options[regs_per_page.selectedIndex].value;
	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(order_by != '')
		url += '&order_by='+order_by;
	url = rtrim(url, '?');
	window.location.href = url;
}

function openJoin(tracking)
{
//	pageTracker._trackEvent('Lview Popup', 'Hits', tracking);
	openModal('http://www.foreclosurelistings.com/joinus-simple.php',692,228,'no');
}

function goToJoin(property_id, property_type)
{
	var join_property_id = document.getElementById('join_property_id');
	var join_property_type = document.getElementById('join_property_type');
	var form = document.getElementById('form_join');
	join_property_id.value = property_id;
	join_property_type.value = property_type;
	form.submit();
}

function openPreview()
{
//	pageTracker._trackEvent('Property Preview', 'Hits', 'Lview');
	openModal('http://www.foreclosurelistings.com/sample_join.html',740,500,'yes');
}
function toogle_view(view)
{
	var input = document.getElementById('view');
	var form = document.getElementById('form_view');
	input.value = view;
	form.submit();
}