$(document).ready( function(){

	COOKIE         = "OECD_SEARCH_TERMS";
	SEARCH_BOX     = $("#global-search-input-box");
	SEARCH_FORM    = $(".search-form");
	

	if( $.cookie ){
	//- populate search terms
		if( v = $.cookie(COOKIE) ){
			SEARCH_BOX.val( v );
		}
	
	//- store search terms on blur of search box
		SEARCH_BOX.blur( function(){ 
			$.cookie(COOKIE,$(this).val(),{path:'/'});
		});
	}
	
//- make sure we have something to search for
	SEARCH_FORM.submit(function(){
	//- make sure we set the cookie first
		SEARCH_BOX.blur();
		
		var textBoxes = $(this).find(':text'), firstTextBox = textBoxes[0], foundOne = false;
	
	//- we're looking at a quicksearch form
		if(textBoxes.length == 1 ){
			if( !$.trim($(firstTextBox).val()) ){
				alert('Please enter a search term');
				return false;
			}
			return true;
		}
		
		FORM_ELEMS = $(this).find(':text,#imprint :input[type!="hidden"],#language-options :input[type!="hidden"],#restrictions :input[type!="hidden"]');
		
		FORM_ELEMS.each(function(i,elem){
			var e = $(elem);
			if(e.val()){
				if(e.attr('type')=='checkbox' || e.attr('type')=='radio'){
					foundOne = foundOne || elem.checked;
				}
				else{
					foundOne = true;
				}
			}				
		});
		
		if(!foundOne){
            alert("Please enter a search term, OR select either one of the following: \n - Imprints,\n - Languages,\n - Restrictions");
			$(firstTextBox).focus();
			return false;
		}
	})
	
	if($(".sidebar-input:text,.placeholder").placehold){
		$(".sidebar-input:text,.placeholder").placehold()
	}
	
	// marked list submitting
	$(".marked-list-button").each(function(){
		$(this).click(function(){
			$(this).parents('form').submit();
			return false;
		})
	})
	
});