
// This is a list of XMLHttpRequest-creation factory functions to try
_factories = [
    function() { return new XMLHttpRequest(); },
    function() { return new ActiveXObject("Msxml2.XMLHTTP"); },
    function() { return new ActiveXObject("Microsoft.XMLHTTP"); }
];

// When we find a factory that works, store it here.
_factory = null;

// Create and return a new XMLHttpRequest object.
//
// The first time we're called, try the list of factory functions until
// we find one that returns a non-null value and does not throw an
// exception. Once we find a working factory, remember it for later use.
//
newRequest = function() {
    if (_factory != null) return _factory();

    for(var i = 0; i < _factories.length; i++) {
        try {
            var factory = _factories[i];
            var request = factory();
            if (request != null) {
                _factory = factory;
                return request;
            }
        }
        catch(e) {
            continue;
        }
    }
    // If we get here, none of the factory candidates succeeded,
    // so throw an exception now and for all future calls.
    _factory  = function() {
        throw new Error("XMLHttpRequest not supported");
    }
    _factory(); // Throw an error
}

function hideAllContents()
{
 var oBlockquotes = document.getElementsByTagName("BLOCKQUOTE");
 for (var i=0;i<oBlockquotes.length;i++)
 {
  if (oBlockquotes[i].className=="jobBlockquote")
  {
   //elem = getElementById(oBlockquotes[i].id);
   elem = oBlockquotes[i];
   var key = elem.id;
   elem.innerHTML = "";
   closeSpanName = key+'Close';
   closeElem = document.getElementById(closeSpanName);
   if (closeElem) 
   {
    closeElem.innerHTML = '';
   }
   // if necessary, clear the close box
   closeSpanName = key+'Close';
   closeElem = document.getElementById(closeSpanName);
   if (closeElem)
   {
    closeElem.innerHTML = "";
   }
  }
 }
}

function showContents(element)
{
 // first, hide everything
 hideAllContents();
 
 // get the element that we need to change
 elem = document.getElementById(element);

 // let the user know something is happening
 elem.innerHTML = "Retrieving job...";

 // create the XMLHttpRequest object
 req = new newRequest;
 
 // assign the URL for the request from the elemental_array
 the_url = "http://"+document.domain+"/common/retrieve-job.php?guid="+element;
 
 // give the request object the url, use "false" to make the request synchronous
 req.open("GET",the_url,false);
 
 // set the User-Agent header so we know in the server logs that this page requested the include files
 req.setRequestHeader("User-Agent", "XMLHttpRequest"); 	

 // do the request
 req.send(null);

 // create a "close" link
 closeText = '<a href="javascript:hideAllContents();">Close</a>';
 closeSpanName = element+'Close';
 closeElem = document.getElementById(closeSpanName);
 if (closeElem) {
  closeElem.innerHTML = closeText;
 }

 // replace the innerHTML of the element with the response text
 elem.innerHTML = req.responseText;
 //elem.innerHTML = the_url;
}

