// Drop Down Boxes.
var min_drop = '#lower';
var max_drop = '#upper';
var radio = 'input[@name="type"]';

// Get the drop down values.
// This is passed on using JSON created by the xml model.

function replace_drop_values() {

	var range_type = $('input[@name="type"]:checked').val();
	$.getJSON('/index.php/json_data/range', function(json) {

		// Now that we have the json, which has already been formatted into handy HTML.
		// All that we need to do is remove the contents of the current min/max drop
		// down boxes and replace it with the json code.
		if(window.console) console.log('Some message');
		// Remove the options.
		if(range_type == 'buy') {
			$('option', min_drop).remove();
			$(min_drop).replaceWith(json.buy.Min);

			$('option', max_drop).remove();
			$(max_drop).replaceWith(json.buy.Max);
		}
		if(range_type == 'rent') {
			$('option', min_drop).remove();
			$(min_drop).replaceWith(json.rent.Min);

			$('option', max_drop).remove();
			$(max_drop).replaceWith(json.rent.Max);
		}

	});

}

$(radio).change( function () {

	replace_drop_values();

});
