// JavaScript Document
$(document).ready(function()	{
	$('.close_div').click(function(){	    
	    $(this).parents("div:first").hide("slow");
	}); 
	
	$('#id_filter_type').change(function(){
		val = $(this).val();
	    if(val != '0')
	    {
		if(val == '1')
		{
		    $('#div_district').show("slow");
		    $(this).children("option:first").attr('selected', 'selected');
		}
		
		if(val == '2')
		{
		    $('#div_location').show("slow");
		    $(this).children("option:first").attr('selected', 'selected');
		}   
		
		if(val == '3')
		{
		    $('#div_property_type').show("slow");
		    $(this).children("option:first").attr('selected', 'selected');
		}
		
		if(val == '4')
		{
		    $('#div_community_features').show("slow");
		    $(this).children("option:first").attr('selected', 'selected');
		}
		
		if(val == '5')
		{
		    $('#div_property_features').show("slow");
		    $(this).children("option:first").attr('selected', 'selected');
		}
		
		if(val == '6')
		{
		    $('#div_size').show("slow");
		    $(this).children("option:first").attr('selected', 'selected');
		}
		
		if(val == '7')
		{
		    $('#div_max_price').show("slow");
		    $(this).children("option:first").attr('selected', 'selected');
		}
		
		if(val == '8')
		{
		    $('#div_title').show("slow");
		    $(this).children("option:first").attr('selected', 'selected');
		}
		
		if(val == '9')
		{
		    $('#div_agent').show("slow");
		    $(this).children("option:first").attr('selected', 'selected');
		}
		
		if(val == '10')
		{
		    $('#div_bedrooms').show("slow");
		    $(this).children("option:first").attr('selected', 'selected');
		}
		
		if(val == '11')
		{
		    $('#div_bathrooms').show("slow");
		    $(this).children("option:first").attr('selected', 'selected');
		}
	    }
	});
	
	$('#advanced_search_submit').click(function() {
 		d = $('#id_district').val()
		t = $('#id_property_type').val()
 		l = $('#id_location').val()
		bath = $('#id_bathrooms').val()
		bed = $('#id_bedrooms').val()
		agent = $('#id_agent').val()
		title = $('#id_title').val()
		price = $('#id_max_price').val()
		size = $('#id_size').val()
		p_feat = $('#id_property_features').val()
		c_feat = $('#id_community_features').val()
 		
 		if(d != '0' || t || l || bath != '0'|| bed != '0' || agent || title || price || size || p_feat || c_feat)
 		{
 		  $('#advanced_search_form').submit();		  
 		}
 		else
 		{
		    alert('Please fill at least one field to search'); 		   
 		}
	});
	
});