//I know calling it AJAJ is odd, but technically it is NOT ajax.  THere is no XML, instead we use JSON.
function processAjaxResult()
{
  var objReturn="";
  var sTemp;
  var objTarget;
  var x,y,z;

  var selIndex;
  if (xmlHttp.readyState==4 && xmlHttp.status == 200)
  {
    sTemp=xmlHttp.responseText;
    if (sTemp!=="")
    {
      eval('objReturn='+sTemp);
      for (x=0;x<objReturn.Length;x++)
      {
        if (document.getElementById(objReturn.Targets[x]))
        {
          selIndex=0;
          objTarget=document.getElementById(objReturn.Targets[x]);
          while (objTarget.options.length>0)
          {
            objTarget.options[0]=null;
          }
          for (y=0;y<objReturn.options[x].length;y++)
          {
/*          var newOption = document.createElement("OPTION");
            newOption.text = objReturn.options[x][y].Key;
            newOption.value = objReturn.options[x][y].Value;
            objTarget.appendChild(newOption);*/
            var newOption=new Option(objReturn.options[x][y].Key,objReturn.options[x][y].Value);
            selIndex=(objReturn.options[x][y].selected)?y:selIndex;
            objTarget.options[y]=newOption;
          }
          objTarget.selectedIndex=selIndex;
        }
      }
    }
  }
}

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;
}

function ajaxcall(sCallerID, sURL)
{
  var objCaller=document.getElementById(sCallerID);
  if (objCaller)
  {
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp===null)
    {
      alert ("Your browser does not support AJAX!");
      return;
    }
    var params="rel="+objCaller.value;
    var url=sURL;
    xmlHttp.onreadystatechange=processAjaxResult;
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(params);
  }
}

function rel2ajax(sCallerID, sURL)
{
  var objCaller=document.getElementById(sCallerID);
  if (objCaller)
  {
    if (objCaller.value!=="")
    {
      //normal ajax call.
      ajaxcall(sCallerID, sURL);
    }
    else
    {
      ajaxcall('rel_one','/site_include/ajax/rel2.php');
    }
  }
}

function refinecatsearch(sURL)
{
  sTgt=document.getElementById("rel_three");
  if (sTgt.value!=="")
  {
    sURL=sURL+"&rel_three="+sTgt.value
  }
  window.location.href=sURL;
}

function companyajaxcall(sCallerID, sURL, ifkUserID, bPublic)
{
  var objCaller=document.getElementById(sCallerID);
  if (objCaller)
  {
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp===null)
    {
      alert ("Your browser does not support AJAX!");
      return;
    }
    var params="rel="+objCaller.value+"&userid="+ifkUserID+"&public="+bPublic;
    var url=sURL;
    xmlHttp.onreadystatechange=processAjaxResult;
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(params);
  }
}

function relsajaxcall(sCallerID, sURL)
{
  var objCaller=document.getElementById(sCallerID);
  if (objCaller)
  {
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp===null)
    {
      alert ("Your browser does not support AJAX!");
      return;
    }
    var params="ipkCompanyID="+objCaller.value;
    var url=sURL;
    xmlHttp.onreadystatechange=processAjaxResult;
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(params);
  }
}


//RESERVED FOR FUTURE USE
/*function refinerelsearch(sURL)
{
  sTgt=document.getElementById("rel_three");
  sURL=sURL+"&cat="+sTgt.value
  window.location.href=sURL;

}*/
