//------------------------------------------------------------------------
// requester for the feature changes
var IB_Blab; 
function IB_processReqChange() 
{
 if(req.readyState == 4) 
 {
   if(req.status == 200)
   {
     document.getElementById(IB_Blab).innerHTML = req.responseText;
   }
   else
     document.getElementById(IB_Blab).innerHTML = '<font color=red>11 Failed to retrieve data from server. Try again.</font>';
 }
}
// requester for the search -------------------------------
var sB_Blab; 
function sB_processReqChange() 
{
 if(req.readyState == 4) 
 {
   if(req.status == 200)
   {
     document.getElementById(sB_Blab).innerHTML = Sreq.responseText;
   }
   else
     document.getElementById(sB_Blab).innerHTML = '<font color=red>11 Failed to retrieve data from server. Try again.</font>';
 } 
}




//------------------------------------------------------------------------
// Ba is location in the page, swi is the switch, arg is the argument, val is the value. duh
// =-
// below this, the Search Location is filled with search results, which are done every time
// only results are displayed if the number of results is < 20
function lcl_dataget(Ba,swi,fid,flist,listid)
{
  // Regardless, we must REset fid form vars when clicked
  document.mainfm.featureid.value = fid;

  //var frm = document.getElementById('mainfm');
  var vfi = document.getElementById('featureid').value; 
  var vst; // must be set below because it might be a check box for the bool
  var ven = document.getElementById('fend').value; 
  if(!flist) flist = document.getElementById('flist').value; 

  // ven is the indicator if we have a single binary checkbox form var
  if(ven==99) {
    if(document.getElementById('fstart').checked) vst=1; 
    else vst=0;
    //if(vst == 'on') vst=1; else vst=0;
 //alert("chk radio:"+vst);
    // keep ven at 99 for this case
  }
  else if(ven==77) {  // this is the refresher
    alert("fid="+vfi+" st="+vst+" en="+ven+"  flist="+flist+".");
  }
  else vst = document.getElementById('fstart').value; 

  var edba = document.getElementById('fedit');
  edba.style.background="#ffffff";

  var Sedba = document.getElementById('Sresults');
  Sedba.style.border="1px #dddddd solid";


//alert("fid="+vfi+" st="+vst+" en="+ven+"  flist="+flist+".");

  IB_Blab = Ba;
  //furl = "ajax_getdata.php?loc="+Ba+"&swi="+swi+"&fid="+fid+"&st="+vst+"&en="+ven;
  furl = "ajax_getdata.php?loc="+Ba+"&swi="+swi+"&fid="+fid+"&st="+vst+"&en="+ven+"&flist="+flist+"&listid="+listid;

//alert("furl="+furl);

  sB_Blab = 'Sresults';
  surl = "ajax_search.php?xx=31&fid="+fid+"&st="+vst+"&en="+ven+"&flist="+flist+"&listid="+listid;

//alert("surl="+surl);

  document.getElementById(IB_Blab).innerHTML = '<blink><i>Working...</i></blink>';
  if(swi==2 || swi==77) document.getElementById(sB_Blab).innerHTML = '<H3><blink><i>Searching....</i></blink></H3>';


  if(window.XMLHttpRequest) 
  {
    req = new XMLHttpRequest();
    req.onreadystatechange = IB_processReqChange;
    req.open("GET", furl, true);
    req.send(null);

    // Only re-search if asked to, otherwise it is just changing parameters
    if(swi==2 || swi==77) 
    {
      Sreq = new XMLHttpRequest();
      Sreq.onreadystatechange = sB_processReqChange;
      Sreq.open("GET", surl, true);
      Sreq.send(null);
    }
  } 
  else if(window.ActiveXObject) 
  {
    req = new ActiveXObject("Microsoft.XMLHTTP");
    if(req) 
    {
      req.onreadystatechange = IB_processReqChange;
      req.open("GET", furl, true);
      req.send();
    }

    Sreq = new ActiveXObject("Microsoft.XMLHTTP");
    if(Sreq && (swi==2 || swi==77)) 
    {
      Sreq.onreadystatechange = sB_processReqChange;
      Sreq.open("GET", surl, true);
      Sreq.send();
    }
  }

}



//------------------------------------------------------------------------------------------
// the highlighting functions and preset range selection
function dosbmRl(ci,dow)
{
  document.mainfm.crit_id.value=ci;
  document.mainfm.dowork.value=dow;
  document.mainfm.submit();
}
function hghltspn(elem,w)
{
  var el = document.getElementById(elem);
  if(w==1) {
    el.style.border="1px #009 solid";
    el.style.fontSize="14px";
  }
  else {
    el.style.border="";
    el.style.fontSize="14px";
  }
}
// Selects the clicked preset block and enters to the form fields the values
function qkvalset(w,min,max)
{
  //alert("change min "+min+" to max "+max);
  var chg = document.getElementById('chgtxt');

  if(w==1) { // continuous vars are set in form fields
    document.getElementById('fstart').value=min;
    document.getElementById('fend').value=max;
    chg.style.color="#900";
    chg.style.marginLeft="10px";
    chg.style.fontWeight="bold";
    chg.innerHTML = "&rarr; range changed to "+min+" to "+max;
  }
  else if(w==2) { //binary checkbox checked
    if(min==1) document.getElementById('fstart').checked=true;
    else document.getElementById('fstart').checked=false;
  }
  else alert("no ready for this");
}



//------------------------------------------------------------------------
// returns the details of a saved list for browse
function SnglSavedLst(id)
{
  surl = "ajax_getdata.php?xx=31&svlst=52&svid="+id;

  IB_Blab='ftbox';
  document.getElementById(IB_Blab).innerHTML = '<i>working...</i>';
  if(window.XMLHttpRequest) 
  {
    req = new XMLHttpRequest();
    req.onreadystatechange = IB_processReqChange;
    req.open("GET", surl, true);
    req.send(null);
  } 
  else if(window.ActiveXObject) 
  {
    req = new ActiveXObject("Microsoft.XMLHTTP");
    if(req) 
    {
      req.onreadystatechange = IB_processReqChange;
      req.open("GET", surl, true);
      req.send();
    }
  }
}

