
$(function() {

	$('#ticket_text').keyup(function(e) {

		if ( typeof TimeOut == "number" )
		{
			clearTimeout(TimeOut);
		}

		TimeOut = setTimeout("getResults($('#ticket_text').val())", 2000);
	});
	
});


function getResults(strSearchTerm)
{

	$("#dLoading").css("display: block !important");

	$('#info-text').html('<h4 style="float: left">Have you looked at our Support Pages?</h4><p class="help-assistant">As you type in the above box, we&rsquo;ll try to find a guide that can answer your question.</p><img id="dLoading" src="/images/support/help_assistant/loader.gif" /><div class="clear"></div>');

	$("#dLoading").show();

	params = {
			 strSearchTerm : strSearchTerm.replace(/\s+$/,"")
			 };

	$.get("search.php", params, function(data)
	{
		$("#dResults").show();	
		$('#dResults').empty();

		$('#info-text').html('<h4>Have you looked at our Support Pages?</h4><p class="help-assistant">As you type in the above box, we&rsquo;ll try to find a guide that can answer your question.</p>');

		if(strSearchTerm != ''){

			if(data == ''){

				$('#info-text').html('');

				strContents = "<h4>We can't find a match for your question, keep typing and we'll try again..</h4>";
				$('#dResults').append('<table class="SearchResults">' + strContents + '</table><br/><br/>');
				setTimeout("$('#dLoading').hide()", 1000);
				return;
			}

			$('#info-text').html('<h4>Have you looked at our Support Pages?</h4><p class="help-assistant">You might find the answer you&rsquo;re looking for below:</p>');

			$('#dResults').append(data);
			setTimeout("$('#dLoading').hide()", 5000);

		}
		else{
			$('#dLoading').hide();
		}
	}
	);

	return false;
}

