var key = '';
var t = 0;

$(document).ready( start );

function start()
{
    $("#qs").keyup(
        function(e){
        	clearTimeout( t );
            key = e.charCode || e.keyCode || 0;
		    if ( key == 27 )
        		$("#qs_result").hide();			
			else
	            t = setTimeout("doSearch()", 500 );
	});

	$("body").click(function(){
		$("#qs_result").hide();	
	});
}

function doSearch()
{
	text = $("#qs").val();
	text = text.replace(/[\'\"]/gi, '');
	text = $.trim(text);
	if ( text != '' )
	{
		$("#qs_result").show();
		$("#qs_result").html( 'Search in progress...' );        	
		$.ajax({
			type: "POST",
			url: "/public/qs.php",
			data: "qs="+text+"&lang="+lang,
			success: function( data ){
			$("#qs_result").show();
			$("#qs_result").html( data );
			}
		});
	}
}

