function mostrarFiltro() {
	var filtro = document.getElementById('filtro');
	if (filtro.style.display == 'block') {
		filtro.style.display = 'none';
	} else {
		filtro.style.display = 'block';
	}
}

function selectAllLodgingTypes() {
	document.getElementById('lodging_type_all').src = '/images/check.gif';
	pattern = /^lodging\_type\_\d+$/;
	for (i = 0; i < document.images.length; i++) {
		if (pattern.test(document.images[i].id)) {
			document.images[i].src = "/images/no_check.gif";
		}
	}
	pattern = /\d+/g;
	oldCtrlValue = tipoAlojamiento;
	tipoAlojamiento = '';
	while ((matches = pattern.exec(oldCtrlValue)) != null) {
		tipoAlojamiento = tipoAlojamiento + matches[0];
	}
}

function toggleLodgingType(idLodgingType) {
	if (img = document.getElementById('lodging_type_' + idLodgingType)) {
		key = String.fromCharCode(idLodgingType + (97 - 1));
		expr = new RegExp(key);
		if (expr.test(tipoAlojamiento)) {
			img.src = '/images/no_check.gif';
			expr = new RegExp("[^" + key + "]", "g");
			oldCtrlValue = tipoAlojamiento;
			tipoAlojamiento = '';
			while ((matches = expr.exec(oldCtrlValue)) != null) {
				tipoAlojamiento = tipoAlojamiento + matches[0];
			}
		} else {
			img.src = '/images/check.gif';
			tipoAlojamiento = tipoAlojamiento + key;
		}

		if (tipoAlojamiento.search(/[a-z]/) >= 0) {
			document.getElementById('lodging_type_all').src = '/images/no_check.gif';
		} else {
			document.getElementById('lodging_type_all').src = '/images/check.gif';
		}
	}
}

function selectAllLodgingRatings() {
	document.getElementById('lodging_rating_all').src = "/images/check.gif";
	pattern = /^lodging\_rating\_\d+$/;
	for (i = 0; i < document.images.length; i++) {
		if (pattern.test(document.images[i].id)) {
			document.images[i].src = "/images/no_check.gif";
		}
	}
	pattern = /[a-z]+/g;
	oldCtrlValue = tipoAlojamiento;
	tipoAlojamiento = '';
	while ((matches = pattern.exec(oldCtrlValue)) != null) {
		tipoAlojamiento = tipoAlojamiento + matches[0];
	}
}

function toggleLodgingRating(lodgingRating) {
	lodgingRating = lodgingRating.toString();
	if (img = document.getElementById('lodging_rating_' + lodgingRating)) {
		expr = new RegExp(lodgingRating);
		if (expr.test(tipoAlojamiento)) {
			img.src = '/images/no_check.gif';
			expr = new RegExp("[^" + lodgingRating + "]", "g");
			oldCtrlValue = tipoAlojamiento;
			tipoAlojamiento = '';
			while ((matches = expr.exec(oldCtrlValue)) != null) {
				tipoAlojamiento = tipoAlojamiento + matches[0];
			}
		} else {
			img.src = '/images/check.gif';
			tipoAlojamiento = tipoAlojamiento + lodgingRating;
		}

		if (tipoAlojamiento.search(/\d/) >= 0) {
			document.getElementById('lodging_rating_all').src = '/images/no_check.gif';
		} else {
			document.getElementById('lodging_rating_all').src = '/images/check.gif';
		}
	}
}

function applyFilter() {
	matches = window.location.href.match(/([^\?#]+)(\?([^#]*))?/);
	baseAddress = matches[1];
	if (matches[3]) {
		query = matches[3].split('&');
		for (i = 0; i < query.length; i++) {
			matches = query[i].match(/^([^=]+)=/);
			if ((matches[1] == 'tipo_alojamiento') || (matches[1] == 'pag')) {
				query.splice(i, 1);
				i--;
			}
		}
	} else {
		query = new Array();
	}
	if (tipoAlojamiento != '') {
		query[query.length] = 'tipo_alojamiento=' + tipoAlojamiento;
	}
	queryString = query.join('&');
	if (queryString.length > 0) {
		window.location.href = baseAddress + '?' + queryString;
	} else {
		window.location.href = baseAddress;
	}
}
