var instantSearches = 0;

/* start of instant search functions */

function instantSearch(str1,str2)
{

document.getElementById('quickSearchGo').innerHTML="<img src='images/?i/progress.gif' />";

  instantSearches++;
  try {
    setTimeout("instantSearch2('"+str1.replace(/'/g,"\\'")+"','"+str2+"')",750);
  } catch (err) {
    document.getElementById('quickSearchGo').innerHTML='&nbsp;<a href="javascript:{}" onClick="javascript:document.getElementById('+String.fromCharCode(39)+'searchedResults'+String.fromCharCode(39)+').style.display='+String.fromCharCode(39)+'none'+String.fromCharCode(39)+';document.getElementById('+String.fromCharCode(39)+'normalRight'+String.fromCharCode(39)+').style.display='+String.fromCharCode(39)+'inline'+String.fromCharCode(39)+';document.getElementById('+String.fromCharCode(39)+'ssearch'+String.fromCharCode(39)+').value='+String.fromCharCode(39)+String.fromCharCode(39)+';" style="font-size: 1.5em; font-weight: bold;">X</a>';
  }
}

function instantSearch2(str1,str2)
{
  if (instantSearches == 1) {
    instantSearches--;
    performInstantSearch(str1,str2);
  } else {
    instantSearches--;
  }
}

function performInstantSearch(str1,str2)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
var url="getajax.asp";
url=url+"?what=instantSearch&data="+str1+"&start="+str2;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChangedInstantSearch;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChangedInstantSearch()
{
if (xmlHttp.readyState==4) {
  try {
    if (xmlHttp.responseText.length > 0) {
      document.getElementById('searchedResults').innerHTML=xmlHttp.responseText;
      document.getElementById('normalRight').style.display='none';
      document.getElementById('searchedResults').style.display='inline';
    } else {
      document.getElementById('normalRight').style.display='block';
      document.getElementById('searchedResults').style.display='none';
    }
    document.getElementById('quickSearchGo').innerHTML='&nbsp;<a href="javascript:{}" onClick="javascript:document.getElementById('+String.fromCharCode(39)+'searchedResults'+String.fromCharCode(39)+').style.display='+String.fromCharCode(39)+'none'+String.fromCharCode(39)+';document.getElementById('+String.fromCharCode(39)+'normalRight'+String.fromCharCode(39)+').style.display='+String.fromCharCode(39)+'inline'+String.fromCharCode(39)+';document.getElementById('+String.fromCharCode(39)+'ssearch'+String.fromCharCode(39)+').value='+String.fromCharCode(39)+String.fromCharCode(39)+';" style="font-size: 1.5em; font-weight: bold;">X</a>';
  } catch (err) {  }
  }
}

/* end of instant search functions */

function setCustomerNumber(str1, str2)
{
if (str1.length==0)
  {
  }
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
  document.getElementById(str1).innerHTML='<img src="images/?i/progress.gif" /><div id="whereToLook" style="visibility: hidden; font-size: 1pt;">'+str1+'</div>';
var url="getajax.asp";
url=url+"?what=addCustomerNumber&customerID="+str1;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChangedCustomerNumber;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function getDel(str1, str2)
{
if (str1.length==0)
  {
  }
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
  document.getElementById("imgProgress").src="images/?i/progress.gif";
var url="getajax.asp";
url=url+"?what=getDel&id="+str1+"&usr="+str2;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function getRForm(str1, str2)
{
if (str1.length==0)
  {
  }
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
  document.getElementById("retailerFormAjax").innerHTML='<img src="images/?i/progress.gif" />';
  document.getElementById("cNumSubmit").innerHTML='';
  document.getElementById("newLink").innerHTML='';
var url="getajax.asp";
url=url+"?what=getRForm&cNum=";
if (str2=="new") {
  url=url+'new';
  document.getElementById("cNum").value='New Company';
} else {
  url=url+document.getElementById(str2).value;
}
url=url+"&usr="+str1+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChangedForm;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function hide3DSlick(str1)
{
if (str1.length==0)
  {
  }
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
  document.getElementById("replace3DSlick").innerHTML='<div id="replace3DSlick2" style="float: left; padding: 5px;"><img src="images/?i/progress.gif" /></div>'+document.getElementById("normalStuff").innerHTML;
  document.getElementById("silverlight3DSlick").innerHTML='';
  try { document.getElementById("silverlightSpacer").innerHTML=''; }
  catch (e) { }
  try { document.getElementById("silverlight3DSlick").display='none'; }
  catch (e) { }
  try { document.getElementById("silverlightSpacer").display='none'; }
  catch (e) { }
  try { document.getElementById("silverlightSpacerExtra").innerHTML=''; }
  catch (e) { }
  try { document.getElementById("packTitlesTitle").style.clear='both'; }
  catch (e) { }
  
var url="getajax.asp";
url=url+"?what=hide3DSlick&id="+str1;
xmlHttp.onreadystatechange=stateChanged3DSlick;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChangedForm() {
  if (xmlHttp.readyState==4) {
    document.getElementById("retailerFormAjax").innerHTML=xmlHttp.responseText;
  }
}

function stateChanged3DSlick() {
  if (xmlHttp.readyState==4) {
    document.getElementById("replace3DSlick2").innerHTML=xmlHttp.responseText;
  }
}

function stateChangedCustomerNumber() {
  if (xmlHttp.readyState==4) {
    document.getElementById(document.getElementById("whereToLook").innerHTML).innerHTML=xmlHttp.responseText;
  }
}

function stateChanged() {
  if (xmlHttp.readyState==4) {
  
//document.getElementById("ajaxDebug").innerHTML='<pre>'+xmlHttp.responseText+'</pre>'
    if (xmlHttp.responseText!="") {
      i=0;
      iEnd=0;
      iStart=0;
      while (i+1<xmlHttp.responseText.length) {
        iStart = xmlHttp.responseText.substr(i+1).indexOf('=');
        iEnd = xmlHttp.responseText.substr(i+1+iStart).indexOf('|')-1;
        document.getElementById(xmlHttp.responseText.substr(i+1,iStart)).value = xmlHttp.responseText.substr(i+1+iStart+1,iEnd);
        i = i+iStart+iEnd+2
      }
    document.getElementById("imgProgress").src="images/?blank.gif";
    }
  }
}

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;
}

