// reload_searchbox.js

var shownTrValue = "block"; //"table-row";
var shownDivValue = "block";
var shownSpanValue = "inline";

function reload_searchbox() {
	var category = document.getElementById('category').options[document.getElementById('category').selectedIndex].value;
	
	// Real estate subtypes
	if(HAS_REAL_ESTATE_SUBTYPES(category)) {
		document.getElementById('searchbox_real_estate_subtypes').style.display = shownTrValue;
	}
	else {
		document.getElementById('searchbox_real_estate_subtypes').style.display='none';
	}
	
	if(ESTATE_CAN_BE_SOLD(category)) {
		document.getElementById('label_for_subt_buysell').style.display = shownSpanValue;
	}
	else {
		document.getElementById('label_for_subt_buysell').style.display='none';
		if(document.getElementById('subt_all_buys')) {
			document.getElementById('subt_all_buys').checked = true;
		}
		if(document.getElementById('subt_all_sales')) {
			document.getElementById('subt_all_sales').checked = true;
		}
	}

	// Low row
	if(HAS_PRICES(category,0) || DISTINGUISH_INDIVIDUALS_OR_PROS(category)) {
		document.getElementById('searchbox_prices_pros').style.display = shownTrValue;
	}
	else {
		document.getElementById('searchbox_prices_pros').style.display='none';
	}

	// Sort by price
	if(HAS_PRICES(category,0)) {
		document.getElementById('searchbox_sort_price').style.display = shownSpanValue;
	}
	else {
		document.getElementById('searchbox_sort_price').style.display='none';
	}

	// Individuals or professionals
	if(DISTINGUISH_INDIVIDUALS_OR_PROS(category)) {
		document.getElementById('searchbox_individuals_professionals').style.display = shownSpanValue;
	}
	else {
		document.getElementById('searchbox_individuals_professionals').style.display='none';
	}

	// Banner
	if(HAS_FEATURES(category)) {
		// Hide banner
		document.getElementById('searchbox_banner').style.display='none';
	}
	else {
		// Show banner
		document.getElementById('searchbox_banner').style.display = shownTrValue;
	}
	
	// Prices dropdowns
	if(HAS_PRICES(category)) {
		document.getElementById('searchbox_price').style.display = shownTrValue;
	}
	else {
		document.getElementById('searchbox_price').style.display='none';
	}

	// Years
	if(HAS_YEARS(category)) {
		document.getElementById('searchbox_year').style.display =  shownTrValue;
	}
	else {
		document.getElementById('searchbox_year').style.display='none';
	}

	// Km
	if(HAS_KILOMETERS(category)) {
		document.getElementById('searchbox_km').style.display = shownTrValue;
	}
	else {
		document.getElementById('searchbox_km').style.display='none';
	}

	// Bedrooms
	if(HAS_BEDROOMS(category)) {
		document.getElementById('searchbox_bedrooms').style.display = shownTrValue;
	}
	else {
		document.getElementById('searchbox_bedrooms').style.display='none';
	}

	// Surface measure
	if(HAS_SURFACE_MEASURE(category)) {
		document.getElementById('searchbox_surface').style.display = shownTrValue;
	}
	else {
		document.getElementById('searchbox_surface').style.display='none';
	}

	// Terrain surface measure
	if(HAS_TERRAIN_MEASURE(category)) {
		document.getElementById('searchbox_terrain').style.display = shownTrValue;
	}
	else {
		document.getElementById('searchbox_terrain').style.display='none';
	}

	// Employment
	if(IS_EMPLOYMENT(category)) {
		document.getElementById('searchbox_employments').style.display =  shownTrValue;
	}
	else {
		document.getElementById('searchbox_employments').style.display='none';
	}
}

// One day people will stop using IE or IE will try to be standards-compliant
// Till then, I'll have to do this (minimal - hopefully safe) abilities detection
//
// This code is repeated at form_b.js

function init_searchbox_reload() {
	shownTrValue = "block";
	try {
		document.getElementById('searchbox_price').style.display="table-row";
		shownTrValue = "table-row";
	}
	catch(e) {
		shownTrValue = "block";
	}
}


