var search_help_text = 'Search resources'


function redirect_to_url(url){
	matches = String(document.location).match(/https?:\/\/[^\/]+/);
	document.location = matches[0] + url
}

$(document).ready(
	function(){
		//add help text to the search <input>
		$("#resources_search_form input[type=text]").focus(
			function(){
				jq_this = $(this);
				jq_this.removeClass('help');
				if(jq_this.val() == search_help_text){
					jq_this.val('');
				}
			}
		);
		$("#resources_search_form input[type=text]").blur(
			function(){
				jq_this = $(this);
				jq_this.removeClass('help');
				if(jq_this.val().match(/^\s*$/)){
					jq_this.val(search_help_text);
				}
				if(jq_this.val() == search_help_text){
					jq_this.addClass('help');
				}
			}
		);
		$("#resources_search_form input[type=text]").blur();
		
		//set redirect stuff when 'select category' form is changed
		$("#resources_category_select_form select").change(
			function(){
				jq_this = $(this);
				if(jq_this.val() != ''){ //so long as it's not the empty top one
					redirect_to_url(jq_this.val());
				}
			}
		);
	}
);
