
$(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">We Recommend ...</h4><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>We Recommend ...</h4><p class="help-assistant">We will offer suggestions for support pages which might help you solve your problems</p>');

		if(strSearchTerm != ''){

			if(data == ''){

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

				strContents = "<br/> <tr><td><strong style='color: #685664'>We've not found any help pages that match your Question.</strong><br /><br /><strong style='color: #685664'>Continue to send your Question to our support team </strong><br/></td></tr>";
				$('#dResults').append('<table class="SearchResults">' + strContents + '</table><br/><br/>');
				setTimeout("$('#dLoading').hide()", 1000);
				return;
			}

			$('#info-text').html('<h4>We Recommend ...</h4><p class="help-assistant">Below is a selection of support pages that we think might help answer your question</p>');

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

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

	return false;
}
