var mainContentObject;

function getContent(AURL,ALoadingMessage)
{
  return getFrameContent(mainContentObject,'mainContentFrame','mainContentDiv',AURL,ALoadingMessage);
}

function getFrameContent(AFrameObject,AFrameID,ADivID,AURL,AResponseMessage)
{
  if (!document.createElement)
  {
    return true;
  }

  //provide a "loading" message
  var responseMessageDiv=document.getElementById(ADivID);
  if(responseMessageDiv)
  {
    if(!AResponseMessage)
    {
      var vResponseMessage='Retrieving data...<br />';
    }
    else
    {
      var vResponseMessage=AResponseMessage;
    }

    responseMessageDiv.style.display='inline';
    responseMessageDiv.innerHTML=vResponseMessage;//+responseMessageDiv.innerHTML;
  }

  var vIFrameDoc;

  if(!AFrameObject&&document.createElement)
  {
    // Create the IFrame and assign a reference to the object to our global variable AFrameObject.
    // This will only happen the first time getFrameContent() is called:
    try
    {
      var tempIFrame=document.createElement('iframe');
      tempIFrame.setAttribute('id',AFrameID);
      tempIFrame.style.border='0px';
      tempIFrame.style.width='0px';
      tempIFrame.style.height='0px';
      AFrameObject=document.body.appendChild(tempIFrame);

      if (document.frames)
      {
        // this is for IE5 Mac, because it will only allow access to the document object of the
        // IFrame if we access it through the document.frames array
        AFrameObject=document.frames[AFrameID];
      }
    }
    catch(exception)
    {
      alert('exception');
      // This is for IE5 PC, which does not allow dynamic creation and manipulation of an iframe object.
      // Instead, we'll fake it up by creating our own objects.
      iframeHTML='<iframe id="'+AFrameID+'" style="border:0px;width:0px;height:0px;"><\/iframe>';
      document.body.innerHTML+=iframeHTML;
      AFrameObject=new Object();
      AFrameObject.document=new Object();
      AFrameObject.document.location=new Object();
      AFrameObject.document.location.iframe=document.getElementById(AFrameID);
      AFrameObject.document.location.replace=function(location)
      {
        this.iframe.src=location;
      }
    }
  }

  if (navigator.userAgent.indexOf('Gecko')!=-1&&!AFrameObject.contentDocument)
  {
    // we have to give NS6 a fraction of a second to recognize the new IFrame
    setTimeout(AURL,10);
    return false;
  }

  if (AFrameObject.contentDocument)
  {
    // For NS6
    vIFrameDoc=AFrameObject.contentDocument;
  }
  else if (AFrameObject.contentWindow)
  {
    // For IE5.5 and IE6
    vIFrameDoc=AFrameObject.contentWindow.document;
  }
  else if (AFrameObject.document)
  {
    // For IE5
    vIFrameDoc=AFrameObject.document;
  }
  else
  {
    return true;
  }
  vIFrameDoc.location.replace(AURL);
  return false;
}

// handleResponse is passed two parameters when called from the 
// onload event of the pages loaded in the hidden IFRAME:
// doc: the document object of the page loaded in the IFRAME
function handleResponse(doc,ASourceDivID,ADestinationDivID)
{
  var vSourceDiv = doc.getElementById(ASourceDivID);
  var vSourceDivResponse = vSourceDiv.innerHTML;  
  var vDestinationDiv = document.getElementById(ADestinationDivID);
  vDestinationDiv.style.display = 'inline';
  vDestinationDiv.innerHTML = vSourceDivResponse;
}

