function callAHAHStandardNested(url, pageElement, callMessage, tag, id) {
/* Author: Jarrod Oberto
 * Date: 03-April-07
 * Purpose: AJAX processing for PHP scripts
 * Passes in: URL: The PHP test field script
 *            pageElement: The <div> element to update
 *            callMessage: The image or message to display (in the <div>
 *                         element) while waiting for processing to complete. 
 *            
 */  

     document.getElementById(pageElement).innerHTML = callMessage;

     try {
     req = new XMLHttpRequest(); /* e.g. Firefox */
     } catch(e) {
       try {
       req = new ActiveXObject("Msxml2.XMLHTTP");
  /* some versions IE */
       } catch (e) {
         try {
         req = new ActiveXObject("Microsoft.XMLHTTP");
  /* some versions IE */
         } catch (E) {
          req = false;
         }
       }
     }
 
     var myRandom=parseInt(Math.random()*99999999);
     req.onreadystatechange = function() {responseAHAHStandardNested(pageElement, tag, id);};
     req.open("GET",url  + "&rand=" + myRandom,true);
     req.send(null);

  }

function responseAHAHStandardNested(pageElement, tag, id) {

   var output = '';

   if(req.readyState == 4) {
      if(req.status == 200) {
           output = req.responseText;
		   
		   var displayOutput = true;


//*  ===  USER MANAGEMENT ===============================================  */

                   if (tag == "displayAccess")
                   {
                       callAHAHStandard('ajax/processum.php?p=DisplayAccess&id='+id,'DisplayAccess', '<img src=\'site_images/anim.gif\'>');
                   }
              
                // *** ___________________________________

                   if (tag == "displayUserList")
                   {
                       
                         /* *** Could be replaced by 'reloadUserPage'. Still not sure which 
                                method is the best.
                                                    */

                         /* *** This block is the same code in the 'reset()' function.
                                However, when using the reset function the loading
                                image does not dissapear.
                                                          */
                         resetGallery();
/*
                         document.getElementById('DisplayAccess').innerHTML = '';  
                         document.getElementById('login').value = '';
                         document.getElementById('pass').value = '';
                         document.getElementById('pripub1').checked = false;
                         document.getElementById('pripub2').checked = false;
*/                
                         callAHAHStandard('ajax/processum.php?p=DisplayUserList','userList', '<img src=\'site_images/anim.gif\'>');                        
                                                
                   }

                // *** ___________________________________

                   if (tag == "reloadUserPage")
                   {
                       location = "index.php?gotopage=usermanagement.php";

                   }

                // *** ___________________________________

                   if (tag == "adminStatus")
                   {

                       /* ***  Output comes from the function 'DisplayAccess' in the file 'processum.php'  */
                       if (output == "<div style=\"padding: 20px 0px 0px 80px; color:red;\">User is an Administrator</div>")
                       {
                           document.getElementById('pripub1').checked = true;
                           document.getElementById('pripub2').checked = false;
                       }else{
                           document.getElementById('pripub1').checked = false;
                           document.getElementById('pripub2').checked = true;                      
                       }
                   }

//*  ===  GALLERY MANAGEMENT ============================================  */
 
                   if (tag == "onGallerySelect")
                   {
                       displayOutput = false;

                       var results = output.split("|");
                        
                       /* ***
                           The following is an example(s) of the string that is
                           returned: 
                                        n|0 or n|1 or y|0 or y|1  

                           n = private             0 = section
                           y = public              1 = event

                           See 'onGallerySelect' from the processgm.php page
                       *** */


                       if (results[0] == "n")  //*** private
                       {
                           document.getElementById('pripub1').checked = true;
                           document.getElementById('pripub2').checked = false;
                       }else if (results[0] == "y") { //*** public 
                           document.getElementById('pripub1').checked = false;
                           document.getElementById('pripub2').checked = true;                      
                       }

                       if (results[1] == "0") //*** section 
                       {
                           document.getElementById('seceve1').checked = true;
                           document.getElementById('seceve2').checked = false;
                       }else if (results[1] == "1") { //*** event
                           document.getElementById('seceve1').checked = false;
                           document.getElementById('seceve2').checked = true;                      
                       }

                       callAHAHStandard('ajax/processgm.php?p=DisplayAccess&galid='+id,'DisplayAccess', '<img src=\'site_images/anim.gif\'>');        
                   }   

                // *** ___________________________________

                   if (tag == "displayAccessToGal")
                   {
                       callAHAHStandard('ajax/processgm.php?p=DisplayAccess&galid='+id,'DisplayAccess', '<img src=\'site_images/anim.gif\'>');        
                   }

                // *** ___________________________________

                   if (tag == "reloadGalPage")
                   {
                       location = "index.php?gotopage=gallerymanagement.php";
                   }

//*  ===  IMAGE MANAGEMENT ==============================================  */

                   if (tag == "setInfoChkBox")
                   {
                       callAHAHStandard('ajax/processim.php?p=SetInfoChkBox&galid='+id,'ItemsHere', '<img src=\'site_images/anim.gif\'>');        
                   }


//*  ===  DISPLAY OUTPUT     ============================================  */

                   if (displayOutput)
                   {
                       document.getElementById(pageElement).innerHTML = output;
                   }else{
                       document.getElementById(pageElement).innerHTML = '';
                       displayOutput = true;
                   }


//*  ====================================================================  */

      }
   }
}

