window.addEvent('domready', function() {
	
	if($$('#search_form')) {
		
		$$('#search_form').addEvent('submit', function(e) {
			e.preventDefault();
			
			save_search_and_submit();
		});

	}
	
});

function save_search_and_submit() // its a function, so we can call it from another place
{
	var data = {
		'search_string': $$('#search_form').getElement('.form_search_string').get('value')
	};
	
	var jsonRequest = new Request.JSON({
		url: $$('#search_form').getElement('.form_search_url').get('value'),
		data : data,
		onSuccess: function(responseJSON, responseText) {
			window.location = $$('#search_form').get('action')+responseJSON.search_hash;
		}
	}).send();
}
