// JavaScript Document
var path='http://www.foreclosurelistings.com/';
function change_state()
{
	if($("#state_sg").val() != '')
		window.location.href = path + 'list/'+$("#state_sg").val()+'/';
	else
		window.location.href = path + 'list-state/';
}
function change_county()
{
	if($("#county_name").val() != '')
		window.location.href = path + 'list/'+$("#state_sg").val()+'/'+$("#county_name").val()+'/';
	else
		window.location.href = path + 'list/'+$("#state_sg").val()+'/';
}
function change_city()
{
	if($("#city").val() != '')
		window.location.href = path + 'list/'+$("#state_sg").val()+'/'+$("#county_name").val()+'/'+$("#city").val()+'/';
	else
		window.location.href = path + 'list/'+$("#state_sg").val()+'/'+$("#county_name").val()+'/';
}
function change_zipcode()
{
	if($("#zipcode").val() != '')
	{
		window.location.href = path + 'list/zipcode/'+$("#zipcode").val()+'/';
	}	
}
function limit_search()
{
	var url, x, i;
	
	if($("#zipcode").val() != '')
	{
		url = path+'lview-content.php?zipcode='+$("#zipcode").val();
		if($("#property_type").val() != ''){
			url += '&property_type='+$("#property_type").val();
		}
	}
	else
	{
		url = path+'lview-content.php?state_sg='+$("#state_sg").val()+'&county_name='+$("#county_name").val().replace(' ', '%20');
		if($("#city").val() != ''){
			url += '&city='+$("#city").val().replace(' ', '%20');
		}
		if($("#property_type").val() != ''){
			url += '&property_type='+$("#property_type").val();
		}
	}
	
	if($("#regs_per_page").val() != '' && $("#regs_per_page").val() != 25)
		url += '&regs_per_page='+$("#regs_per_page").val();
	
	if($("#order_by").val() != '' && $("#order_by").val() != 'property_photos')
		url += '&order_by='+$("#order_by").val().replace(' ', '%20');
	
	if($("#min_price").val() != 0 || $("#max_price").val() != -1)
		url += '&min_price='+$("#min_price").val()+'&max_price='+$("#max_price").val();
	if($("#beds").val() != '')
		url += '&beds='+$("#beds").val();
	if($("#baths").val() != '')
		url += '&baths='+$("#baths").val();
	
	x = $('input[name=property_style]');
	for(i=0; i<x.length; i++)
		if(x[i].checked == true)
			url += '&property_style[]='+x[i].value;
	
	if($("#active").is(':checked'))
		url += '&active='+$("#active").val();
	
	url += '&exhibition='+$("#exhibition").val()
	
	reloadContent(url);
}
function order()
{
	url = path+$("#order_url").val();
	if($("#order_by").val() != '' && $("#order_by").val() != 'property_photos')
		url += '&order_by='+$("#order_by").val().replace(' ', '%20');
	reloadContent(url);
}
function order_by(order)
{
	url = path+$("#order_url").val();
	if(order != '' && order != 'property_photos')
		url += '&order_by='+order.replace(' ', '%20');
	reloadContent(url);
}
function jump(page)
{
	url = path+$("#jump_url").val();
	if(page != '' && page != undefined)
	{
		url += '&page='+page;
		reloadContent(url);
	}
	else if($("#jump_page").val() != '' && $("#jump_page").val() != undefined)
	{
		url += '&page='+$("#jump_page").val();
		reloadContent(url);
	}
}
function change_regs_per_page()
{
	url = path+$("#regs_url").val();
	if($("#regs_per_page").val() != '' && $("#regs_per_page").val() != 25)
		url += '&regs_per_page='+$("#regs_per_page").val();
	reloadContent(url);
}
function toogle_view(view)
{
	url = path+$("#exhib_url").val();
	url += '&exhibition='+view;
	reloadContent(url);
	if(view == 0)
	{
		$("#list_view").attr('class', 'list_selected');
		$("#sheet_view").attr('class', 'sheet_unselected');
	}
	else if(view == 1)
	{
		$("#sheet_view").attr('class', 'sheet_selected');
		$("#list_view").attr('class', 'list_unselected');
	}
}
/*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');
}
$(document).ready(function(){
	if(window.location.hash != '')
	{
		var url;
	
		if($("#zipcode").val() != '')
		{
			url = path+'lview-content.php?zipcode='+$("#zipcode").val();
			if($("#property_type").val() != ''){
				url += '&property_type='+$("#property_type").val();
			}
		}
		else
		{
			url = path+'lview-content.php?state_sg='+$("#state_sg").val()+'&county_name='+$("#county_name").val().replace(' ', '%20');
			if($("#city").val() != ''){
				url += '&city='+$("#city").val().replace(' ', '%20');
			}
			if($("#property_type").val() != ''){
				url += '&property_type='+$("#property_type").val();
			}
		}
		url += window.location.hash.replace('#', '&').replace(/ /g,'%20');
		reloadContent(url);
		var qsa = window.location.hash.replace('#', '').split('&');
		for(var i = 0; i < qsa.length; i++)
		{
			param = qsa[i].split('=');
			if(param[0] != 'page' && param[0] != 'order_by' && param[0] != 'regs_per_page')
				$("#"+param[0]).val(param[1]);
			if(param[0] == 'active' && param[1] == 'yes')
				$("#"+param[0]).attr('checked', 'checked');
		}
	}
});
