var iStep = 1;

$(document).ready(function()
{
   $("#Loading")
	 .ajaxStart(function()
	   {
		  $(this).show();
	   })
	 .ajaxStop(function()
	   {
		  $(this).hide();
	   });

});

GetMarkedResults = function()
{
   if ($("#PalavraChave").val()=='') 
	  {
		alert('Entre com alguma palavra chave');
		$("#PalavraChave").focus();
	  }
   else
      {
		$("#Resultado").html('<div class="PalavraProcurada">Ocorr&ecirc;ncias para: <strong>' + $("#PalavraChave").val() + '</strong></div>');
		$('.chkTribunais:checked').each(function()
		{
		  $.ajax({
			   url:'action.php',
			   data:'PalavraChave=' + $("#PalavraChave").val() + '&Tribunal=' + $(this).val(),
			   cache:false,
			   success:function(htmlContent)
			   {
  				  $("#Resultado").append(htmlContent);
			   },
			   error:function(XMLHttpRequest, textStatus, errorThrown)
			   {
				   alert(textStatus); 
			   }
		   });
		});
	  }
	  return false;
}


GetNextResults = function()
{
   if ($("#PalavraChave").val()=='') 
	  {
		alert('Entre com alguma palavra chave');
		$("#PalavraChave").focus();
	  }
   else
	  $.ajax({
		   url:'action.php',
		   data:'PalavraChave=' + $("#PalavraChave").val() + '&Step=' + iStep.toString(),
		   cache:false,
		   success:function(htmlContent)
		   {
			   if (htmlContent != '__Finish__')
				 {
				   if (iStep==1)
					 $("#Resultado").html('<div class="PalavraProcurada">Ocorr&ecirc;ncias para: <strong>' + $("#PalavraChave").val() + '</strong></div>');
					 
				   $("#Resultado").append(htmlContent);
				   iStep++;
				   GetNextResults();
				 }
			   else
				 iStep = 1;
		   },
		   error:function(XMLHttpRequest, textStatus, errorThrown)
		   {
			   alert(textStatus); 
		   }
	   });
	  return false;
}

