
   /*
      return an AJAX request object, suitable of IE and otherwise
   */
   function getRequest()
   {
      var req = false;
      // branch for native XMLHttpRequest object
      if (window.XMLHttpRequest)
      {
    	   try {
            //alert('try native');
			   req = new XMLHttpRequest();
         } catch(e) {
            alert('unable to get xmlHttpRequest object for native support.');
         }
      // branch for IE/Windows ActiveX version
      }
      else if(window.ActiveXObject)
      {
         //alert('try activex');
       	try {
        	   req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	   try {
               //alert('try activex after catch');
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	   } catch(e) {
               alert('unable to get xmlHttpRequest object for activex');
        	   }
		   }
      }
      return req;
   }

   /**

   Submit the request and return immediately

   @param pXHRRequest
   @param pUurl
   @param pOnReadyFunction The actual function (not just the name) of the onReadyFunction.  
   */
   function makeAsynchronousAjaxRequest(pXHRRequest, pUrl, pOnReadyFunction)
   {
       if (window.opDebugWindow) debug("ajax.js:makeAsynchronouslyAjaxRequest - pUrl=" + pUrl);

	   if (pXHRRequest)
	   {

		   pXHRRequest.open("GET", pUrl, true);
		   pXHRRequest.onreadystatechange = pOnReadyFunction;
		   pXHRRequest.send("");
	   }
	   else
	   {
   	   alert('pXHRRequest has not been adequately set');
      }
   }

   /**

   Submit the request and return an XML object
   @param pUrl
   @param pOnReadyFunction The actual function (not just the name) of the onReadyFunction
   */
   function makeSynchronousAjaxRequest(pXHRRequest, pUrl)
   {
      var responseText = "[not set]";
//      alert('SynchAjaxRequest - about to make ajax request for url=' + pUrl);
	   if (pXHRRequest)
	   {
		   pXHRRequest.open("GET", pUrl, false);
		   pXHRRequest.send("");
//         alert('3makeAjaxRequest: responseXML=' + pXHRRequest.responseXML);
//         responseText = pXHRRequest.responseText;
         responseXML = pXHRRequest.responseXML;
	   }
	   else
	   {
//   	   alert('pXHRRequest has not been adequately set');
      }
  //    alert("about to return responseXML=" + responseXML);
      return responseXML;
   }


   /**
     Find out if if the user is logged out, in which case you should probably
     redirect to the logout page.  Makes a *synchronous* Ajax call to get the info
     If visitor is allowed, let it through, though the user will only have a visitor object
     in the session
     @return true if it appears that the user is logged out
   */
   function isLoggedOut()
   {
      if (window.opDebugWindow) debug("isLoggedOut: top");
      var urlToLoad = "/pe/kv/include/statusdata.jsp?timeStamp=" + new Date().getTime();
      loggedOutRequest = getRequest();
      if (window.opDebugWindow) debug("isLoggedOut: about to make SYNCH request with url=" + urlToLoad);
      // This call will not return until it's all done
      var xml = makeSynchronousAjaxRequest(loggedOutRequest, urlToLoad);
      if (window.opDebugWindow) debug("isLoggedOut: after SYNCH request");
      var redirectFlag = xml.getElementsByTagName("redirectFlag")[0].firstChild.nodeValue;
      var isLoggedOut = ("true" == redirectFlag);
      if (window.opDebugWindow) debug('isLoggedOut: redirectFlag=' + redirectFlag + ' and isLoggedOut=' + isLoggedOut);
      return isLoggedOut;
   }

/**
  Find out if if the user is logged out, in which case you should probably
  redirect to the logout page.  Makes a *synchronous* Ajax call to get the info.
  Do not allow visitor to qualify
  @return true if it appears that the user is logged out
*/
function isLoggedOutAvoidVisitor()
{
   if (window.opDebugWindow) debug("isLoggedOut: top");
   var urlToLoad = "/pe/kv/include/statusdata.jsp?avoidVisitor=T&timeStamp=" + new Date().getTime();
   loggedOutRequest = getRequest();
   if (window.opDebugWindow) debug("isLoggedOut: about to make SYNCH request with url=" + urlToLoad);
   // This call will not return until it's all done
   var xml = makeSynchronousAjaxRequest(loggedOutRequest, urlToLoad);
   if (window.opDebugWindow) debug("isLoggedOut: after SYNCH request");
   var redirectFlag = xml.getElementsByTagName("redirectFlag")[0].firstChild.nodeValue;
   var isLoggedOut = ("true" == redirectFlag);
   if (window.opDebugWindow) debug('isLoggedOut: redirectFlag=' + redirectFlag + ' and isLoggedOut=' + isLoggedOut);
   return isLoggedOut;
}

 /**
    Remove all the contents of the given object.
    @return a clone of the given object, with no children
 */
function clearInnerHTML(pGivenObject)
{
   // perform a shallow clone on obj (false means don't clone the contents)
   // insert the cloned object into the DOM before the original one
   // remove the original object
 
   newEmptyObject = pGivenObject.cloneNode(false);
   pGivenObject.parentNode.insertBefore(newEmptyObject, pGivenObject);
   pGivenObject.parentNode.removeChild(pGivenObject);
   //alert("clearInnerHtml: after remove child");
   return newEmptyObject;
}


