/*
# $Id$
*/

/*
# Init UI
*/
window.addEvent('load', function() {

	// Add handlers to all "find a..." selections
	$$('#find-a input[type="radio"]').addEvent('click', function() {
		toggleRoomDetails(this.value.toString().match(/room$/i) ? true : false);
	});
	var cv = false;
	$$('#find-a input').each(function(el) {
		if(el.checked && el.value.match(/room$/)) {
			cv = true;
		}
	});
	toggleRoomDetails(cv);

	// Prepare property location fields
	PropertyLocation.prepareUi({
		jsonField: 'fe-propertylocation'
	});
	PropertyLocation.reload();

	// Convert all "submit" buttons to standard buttons will javascript submitters
	// to prevent form being submitted when pressing ENTER
	$$('#form-search input[type=submit]').each(function(el) {
		var btn = new Element('input', {
			type: 'button',
			'class': 'btn-search',
			value: el.value
		});
		btn.addEvent('click', function() {
			$('form-search').submit();
		});
		btn.replaces(el);
	});

	/*// Add handler to "neighbourhood" field and "postcode" field that will
	// activate the "distance" dropdown if either of these fields are populated
	$$('#loc-postcode input,#loc-neighbourhood select').addEvent('change', function() {
		$('fe-rng').disabled = this.get('value')=='' ? true : false;
	});
	$('fe-rng').disabled = $$('#loc-postcode input').get('value')=='' && $$('#loc-neightbourhood select').get('value')=='' ? true : false;*/
});

/*
# @function void toggleRoomDetails( bool state )
# state	= Toggle state to apply
#
# Activate/deactivate the "room details" form section
*/
function toggleRoomDetails(state) {
	$('room-details').setStyles({
		display: state ? 'block' : 'none'
	});
	$$('#room-details input,#room-details select').set('disabled', !state);
}