$j(document).ready(function() {
	// I'm suspending this for now -- I don't think the Ajax is necessary. It was designed to only show relevant values in the dropdown -- for example, if we select "Serviced", only locations with "Serviced" space would be displayed in the dropdown -- but in fact, we have a pretty broad range of properties, and there's no need to try and filter dropdowns in this way:
	initSearch();

	$j('a.shortlist').click(function() {
		var href = $j(this).attr('href');
		var details = href.substr(1);
		var s = details.split('_');
		var id = s[0];
		var type = s[1];
		
		var inputs = new Object;
		inputs['id'] = id;
		inputs['type'] = type;
		
		$j.ajax({
			data: inputs,
			url: "/ajax/shortlist.php",
			type: "POST",
			timeout: 2000,
			error: function() {
				console.log("Failed to submit");
			},
			success: function(xml) { 
				var status = $j("status",xml).text();	
				var message = $j("status",xml).text();								
				var html = $j("html",xml).text();		
				if (status != 0) {
					$j('#shortlist').replaceWith(html)
				}		
				else {
					console.log("Zero status: "+message);
				}
			}
		});
		
		return false;
	});
	
});

function initSearch() {
	
	/*
		Rewritten search so its now non linear.
		i.e. user can search on type and size, missing out location	
		(older version can be retrieved from SVN)
	*/
	$j('#SearchServiceType').change(function() {	

		var inputs = new Object;
		inputs['type'] = $j('#SearchServiceType').val();
		$j.ajax({
			data: inputs,
			url: "/ajax/search.php",
			type: "POST",
			timeout: 2000,
			error: function() {
				console.log("Failed to submit");
			},
			success: function(xml) { 
				var status = $j("status",xml).text();	
				var message = $j("status",xml).text();								
				var html = $j("html",xml).text();		
				if (status != 0) {
					$j('#SearchServiceSize').replaceWith(html);
					initSearch(); // See above
				}		
				else {
					console.log("Zero status: "+message);
				}
			}
		});
	});

}
