// JavaScript Document
function select_highlight(object) {
	if ($(object).val() != 'none') {
		$(object).addClass('selected_highlight');
	} else {
		$(object).removeClass('selected_highlight');
	}
}

function check_highlight(object) {
	if ($(object).attr('checked')) {
		$(object).parent('div').children('label').addClass('selected_highlight');
	} else {
		$(object).parent('div').children('label').removeClass('selected_highlight');
	}
}

$(document).ready(function() {
	var shown = false;
	
	$('#busqueda_avanzada').hide();
	$('a.busqueda_avanzada').hide();
	
	if ($('#buscador select').val() != 'none') {
		$('ul.order').css('top', '310px');
	}
	
	$('#buscador select[name=tipo_propiedad]').change(function() {
		if ($(this).val() != 'none') {
			$('.sub_busqueda').hide();
			
			$(this).parent('#buscador').addClass('mas_grande');
			$('#busqueda_avanzada').fadeIn();
			$('ul.order').css('top', '310px');
			
			$('#busqueda_'+$(this).children('option[selected]').html()).show();
		} else {
			$('#busqueda_avanzada').fadeOut('slow', function() {
				$(this).parent('#buscador').removeClass('mas_grande');
				$('ul.order').css('top', '230px');
			});
		}
	});
	
	$('#buscador').submit(function() {
		/*$('#buscador select[value=none]').removeAttr('name');
		$('#buscador select[value=none] option').removeAttr('value');*/
		
		
			//return false;
		
		$('.sub_busqueda').each(function() {
			//alert($(this).attr('id') + '---' + 'busqueda_'+$('select[name=tipo_propiedad]').html()));
			//removeAttr('name');
			
			
			if ($(this).attr('id') != 'busqueda_'+$('select[name=tipo_propiedad] option[selected]').html()) {
				$(this).remove();
			}
		});
		
		/*$('#buscador select[value=none]').attr('disabled', 'disabled');
		$('#buscador input[type=checkbox]').attr('disabled', 'disabled');
		$('#buscador input[type=checkbox][checked]').attr('disabled', '');*/
		
		//$('#buscador select[value=none]').removeAttr('value');
	});
	
	
	$('#buscador select').change(function() {
		select_highlight(this);
	});
	
	$('#buscador select').each(function () {
		select_highlight(this)
	});
	
	
	
	$('#buscador input[type=checkbox]').change(function() {
		check_highlight(this);
	});
	
	$('#buscador input[type=checkbox]').each(function () {
		check_highlight(this)
	});
});

function cambiar_select(select_item, opcion) {
	$('select[name='+select_item+'] option[value='+opcion+']').attr('selected', 'selected');
	$('select[name='+select_item+']').change();
}