function downloader( form )
{
  document.getElementById( "downloader_result" ).innerHTML = '<p><img src="./images/spinner.gif" style="vertical-align:middle;"/> generating...</p>';

  // create a random ID so we can retrieve the filename below
  var fileNameKey = Math.ceil( Math.random() * 100000 );
  form["fileNameKey"].value = fileNameKey;
  displayFileName( fileNameKey, form.sid.value );
}

function displayFileName( fileNameKey, sid, tries )
{
  var maxTries = 6;
  if ( tries == null || tries > maxTries )
  {
    tries = maxTries;
  }
  if ( tries < 0 ) return; // give up

  var timeouts = new Array( 1, 1, 2, 3, 5, 8, 13 );
  setTimeout( "displayFileNameWorker(" + fileNameKey + ",'" + sid + "'," + tries + ")", timeouts[maxTries-tries] * 1000 );
}

var httpDownloader = null;
function displayFileNameWorker( fileNameKey, sid, tries )
{
  httpDownloader = createRequestObject();
  if ( !httpDownloader ) return;

  // grab the calendar's filename, if possible
  httpDownloader.open( 'GET', "index.php?action=displayFileNameComponent&sid=" + sid + "&fileNameKey=" + fileNameKey + randomParam() );
  httpDownloader.onreadystatechange = function()
  {
    if ( httpDownloader.readyState != gReadyStateFinished ) return;

    if ( httpDownloader.responseText )
    {
      document.getElementById( "downloader_result" ).innerHTML = httpDownloader.responseText;
    }
    else
    {
      displayFileName( fileNameKey, sid, tries-1 );
    }
  }
  httpDownloader.send( null );
}