/* What we're doing, and why it's better:
 saneAJAX takes three inputs, an action tag, an element ID, and a bool for method of return.
  __tag: The action tag is used to select specific URLs. 
   You do not feed the URL directly through the variable when the function is called;
   due to proto-typing and anonomyous functions, this is a big security hole.
   Rather, you indicate and switch. This also forces you to keep an index in your AJAX function
   of the various different AJAX scripts. This is also a good thing.
  __elemID: The element ID is the ID of the element in which the AJAX script will write to.
   This uses the ever so popular document.getElementById( elementID ).innerHTML = whatever method.
   However, because a person may not necessarily want to write what was returned, this only happens
   when the bool for __write is set to true.
  __write: The write bool triggers whether the information AJAX'd is written via innerHTML (true),
   or if the information is instead returned (false), perhaps to be used in other code.
  
  __saneReq is the AJAX request object, btw.
  
 The reason I call this the "sane" method is that I see many AJAX'd sites which due 1 of 2 bad things:
  1) They write a seperate function for each AJAX script. This creates AJAX bloat, and they repeat themselves horribly.
  2) The write a method that takes a URL and uses it directly. If I need to explain why taking variable input without checking it is bad, then you need to not use AJAX.
*/
function saneAJAX( __tag , __elemID, __write, __loader) {
 if ( window.XMLHttpRequest ) {
  __saneReq = new XMLHttpRequest();
 }
 else {
  __saneReq = new ActiveXObject("Microsoft.XMLHTTP");
 }
 __saneReq.onreadystatechange = function( ) {
  if ( __saneReq.readyState == 4 && __saneReq.status == 200 ) {
   if ( __write ) {
    var __welem = document.getElementById( __elemID );
    __welem.innerHTML = __saneReq.responseText;
    if (__loader) {
     eval(__loader);
    }
    return true;
   } else {
    var __resp = __saneReq.responseText;
    if (__loader) {
     eval(__loader);
    }
    return __resp;
   }
  }
 }
 var __jaxurl = "";
 switch( __tag ) {
  case "cv_roster":
   __jaxurl = "/cventservice/roster.php";
  break;
  case "test":
   __jaxurl = "/cventservice/target.txt";
  break;
  case "cv_newmembers":
   __jaxurl = "/cventservice/newmembers.php";
  break;
  case "cv_memberedit":
   __jaxurl = "/cventservice/memberedit.php";
  break;
  case "cv_memberedit_per":
   __jaxurl = "/cventservice/memberedit.php?cvkey=personal_info";
  break;
  case "cv_memberedit_add":
   __jaxurl = "/cventservice/memberedit.php?cvkey=address_info";
  break;
  default:
   alert('AJAX error 1');
  break;
 }
 __saneReq.open( "GET" , __jaxurl , true );
 __saneReq.send( );
}

//Loading handler
 function jLoad(AJAXtarget, resultsId, statusImageId, statusDivId, statusImageLoadSrc, statusImageBlankSrc) {
  var __iL = document.getElementById(statusImageId);
  __iL.src = statusImageLoadSrc;
  __iL.style.display = "block";
  var lfinish = "document.getElementById('"+statusDivId+"').style.display = 'none'; document.getElementById('"+statusImageId+"').src = '"+statusImageBlankSrc+"';";
  saneAJAX(AJAXtarget, resultsId , true, lfinish);
 }


 function enableInputs(theClass) {
  var allHTMLTags=document.getElementsByTagName("*");
  for(i=0; i<allHTMLTags.length; i++) {
   if(allHTMLTags[i].className==theClass) {
    allHTMLTags[i].disabled=false;
   }
  }
 }

