$(function() {
	 
		$( "#SearchField" ).autocomplete({
		
			source: function( request, response ) {
				 	
					$.getJSON("search.php", request, function(data) {
							
							response(data); 
							if(data=="") {
								$("#SearchField").addClass("error", "normal"); //turn background red on no results
								$("#errorText").css("visibility", "visible"); //make visible the error string
						    } 
							else { removeError(); }
							return;
					});
					
			},

			minLength: 1,
						 
			select: function( event, ui ) {
				window.open("http://www.articleshack.net/" + ui.item.id,'_self');
			}
		});
				
		$('#SearchField').keyup(function() {
  			if(this.value.length==0){
  			 	removeError(); //remove an error screen if the input is 0
  			 }
		});
		
	});
	
	function removeError(){
				$("#SearchField").removeClass("error", "normal"); //turn background back to default white
				$("#errorText").css("visibility", "hidden");  //hide the error string on success
				return;
		}
	
