//------------------------------------------------------------------------

HM_DOM = document.getElementById ? true : false;
HM_IE  = document.all ? true : false;
HM_NS4 = document.layers ? true : false;



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>';
 }
}
//------------------------------------------------------------------------
// Ba is location in the page, swi is the switch, arg is the argument, val is the value. duh
// arg = THE CHAPTER ID
function get_data(Ba,swi,arg,val)
{
  // Gets and puts in an editor for targeting information
  IB_Blab = Ba;

  //alert("V:"+val);

  if(swi<3) // Both swi 1 and 2 needs these values
  {
    var age,ed,ge,iq;
    age="";
    ed="";
    iq="";

    if(document.getElementById('age') != null) age=document.getElementById('age').value;
    if(document.getElementById('educ') != null) ed=document.getElementById('educ').value;
    if(document.getElementById('iq') != null) iq=document.getElementById('iq').value;

    var Varname=document.mainfm.Varname.value;
    var Hlabs=document.mainfm.Hlabs.value;
    var srtt = "";
    var vrs = "";
    var gev = "";
    var glen = "";
    var hvals = "";

    if(swi==2) Varname=val; // this is set inside the fn call because it wont get sent via html form vars

    if(document.getElementById('gender') != null) 
    {  ge=document.getElementById('gender');
      glen = ge.options.length;
      for(var i =(glen-1);i>=0;i--) {
        if ((ge.options[i] != null) && (ge.options[i].selected == true)) { gev = ge.options[i].value; }
      }
    }

    dml = document.mainfm;
    for(var i=0;i<dml.elements.length;i++) 
    { 
      if(dml.elements[i].checked) {
        if(dml.elements[i].name == "version") vrs = dml.elements[i].value; 
        else if(dml.elements[i].name == "sortO") srtt = dml.elements[i].value; 
      }
      else if(dml.elements[i].name == "gender") {
        if((dml.elements[i].options[i] != null) && (dml.elements[i].options[i].selected == true)) 
	{ gev = dml.elements[i].options[i].value; }
      }

      if(swi==2) // only caring about this variable being available and set when searching, not form building
      {
        if(dml.elements[i].name.match(Varname)) {
          hvals += dml.elements[i].value + "::";
        }
        fval = hvals;
      }
      else fval=0;
      
    }


    val = age+":"+ed+":"+gev+"+:"+iq+":"+vrs+"kk"+srtt;
  } 
  else if(swi==3)  // add the arg to the clipboard string sitting toClpBrd
  {
    //if(document.getElementById('toClpBrd').value) {
      //alert("it is true that the old one has contents");
    //}
    // if the storing var contains something, add to it with the separator, else make it it
    //else val=arg;

    val = arg + ":::";

  }

  furl = "ajax_work.php?dwrk=1&loc="+Ba+"&swi="+swi+"&arg="+arg+"&val="+val+"&Fvals="+fval;


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


////////////////////////////////////////////////////////////////////////////////////////////////
// The resultsID is required to collect the results but we must also have what the user entered
// All of these go directly into the ClipBoard 
var CL_lab;
function toClipBoard(Hi,Ba,resultsID,demoGraphics,Raws)
{
  CL_lab=Ba; // This location is next to the ClipBoard clicker so it does change
  furl = "ajax_work.php?clipboard=1&resultsID="+resultsID+"&demog="+demoGraphics+"&raw="+Raws;

  // we color the background of the header, reference, for this one to be pastel green
  document.getElementById(Hi).style.background="#a9a9ff";
  
  //alert("in here with "+resultsID);


  document.getElementById(CL_lab).innerHTML = '<i><blink>Working...</blink></i>';
  if(window.XMLHttpRequest) 
  {
    clreq = new XMLHttpRequest();
    clreq.onreadystatechange = CL_processReqChange;
    clreq.open("GET", furl, true);
    clreq.send(null);
  } 
  else if(window.ActiveXObject) 
  {
    clreq = new ActiveXObject("Microsoft.XMLHTTP");
    if(clreq) 
    {
      clreq.onreadystatechange = CL_processReqChange;
      clreq.open("GET", furl, true);
      clreq.send();
    }
  }
}
function CL_processReqChange() 
{
 if(clreq.readyState == 4) 
 {
   if(clreq.status == 200)
   {
     document.getElementById(CL_lab).innerHTML = clreq.responseText;
   }
   else
     document.getElementById(CL_lab).innerHTML = '<font color=red>12 Failed. response:'+clreq.status;
 }
}




////////////////////////////////////////////////////////////////////////////////////////////////
function quickInfo(i)
{



  theElementId = "infoBlock";
  var theElement = document.getElementById(theElementId);
  // the elements name is passed in the funtion, so just show it
  if(!(HM_DOM||HM_IE||HM_NS4)) return true;

  if(!theElement) return true;

  if(HM_DOM||HM_IE) {
    if(theElement.style.visibility == "visible") theElement.style.visibility = "hidden";
    else theElement.style.visibility = "visible";
  }
  else {
    if(theElement.visibility == "visible") theElement.visibility = "hidden";
    else theElement.visibility = "visible";
  }

  /* These are the defined help messages */
  var textBlock = new Array();
  textBlock[0] = "";
  textBlock[1] = "<P><PRE>This indicates whether the data has been \n\tcurated (C)\n\treal (R)\n\tmeasured (M)\n\tnone of the above</PRE></P>";

  theElement.innerHTML = textBlock[i]+"<a href='Javascript:quickInfo(0);'>[close]</a>";

  //return true;
}


