var xmlHttp

// Pauses AJAX call if user submitting search term
var count = 0;
function pauseAJAXCall(intLegalUpdateArea, strSearchText, intYear, strSort, intPage)
{	
	count = count+1;
	setTimeout("continueAJAXCall("+count+", '"+intLegalUpdateArea+"', '"+strSearchText+"', '"+intYear+"', '"+strSort+"', '"+intPage+"')", 750);
}

function continueAJAXCall(currCount, intLegalUpdateArea, strSearchText, intYear, strSort, intPage)
{   
	if(currCount == count) {
		count = 0;      
		updateSearch(intLegalUpdateArea, strSearchText, intYear, strSort, intPage);   
	}
} 
// Pauses AJAX call if user submitting search term

function updateSearch(intLegalUpdateArea, strSearchText, intYear, strSort, intPage)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/_code/_server/_ajax/LegalUpdateSearch.asp";
url=url+"?luaid="+intLegalUpdateArea+"&intYear="+intYear+"&strSort="+strSort+"&p="+intPage+"&st="+strSearchText;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged()
{
	if (xmlHttp.readyState==4)
	{ 
		// split the response into search drop downs and results
		var mySplitResult = xmlHttp.responseText.split("|%^&|%^&");
		// populate divs holding search drop downs and results
		document.getElementById("strSearchForm").innerHTML=mySplitResult[0];
		document.getElementById("strSearchSummary").innerHTML=mySplitResult[1];
		document.getElementById("strResults").innerHTML=mySplitResult[2];
		

		
		var obj=document.getElementById('strSearchText');
		pos = obj.value.length
	    if(obj.createTextRange) { 
	        /* Create a TextRange, set the internal pointer to
	           a specified position and show the cursor at this
	           position
	        */ 
	        var range = obj.createTextRange(); 
			range.move("character", pos); 
	        range.select();
	    } else {	//if(obj.selectionStart) { 
	        /* Gecko is a little bit shorter on that. Simply
	           focus the element and set the selection to a
	           specified position
	        */ 
	        obj.focus(); 
	        obj.setSelectionRange(pos, pos); 
	    } 

	}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}