// JavaScript Document

  function toggleSection( theElement )
  {
    var sClkId = theElement.id;
    if ( sClkId )
    {
      var sId = sClkId.replace( /^clk/, '' );
      var sDivId = 'div' + sId;
      var theDiv = getElement( sDivId );
      if ( theDiv )
      {
        var sClass = theDiv.className;
        var sDisplay = theDiv.style.display;
        var fShown = hasStyle( theDiv, 'expanded' )
        swapStyle( theDiv,
                   fShown ? 'expanded'  : 'collapsed',
                   fShown ? 'collapsed' : 'expanded', '' );
        sClass = theDiv.className;
        sDisplay = theDiv.style.display;
        swapStyle( theElement,
                   fShown ? 'collapser' : 'expander',
                   fShown ? 'expander'  : 'collapser', '' );
      }
    }
  }

  function showMail( theAddress, sText )
  {
    var sAddress = [ theAddress.name,   '&#64;',
                     theAddress.domain, '&#46;',
                     theAddress.extension ].join('');
    if ( ! sText ) sText = '%A%';
    var sLabel = sText.replace( /%A%/g, sAddress );
    if (   theAddress.image
        && theAddress.width
        && theAddress.height )
    {
      var sImgTag = '<img src="'
                  + theAddress.image
                  + '" width="'
                  + theAddress.width
                  + '" height="'
                  + theAddress.height
                  + '" alt="e-mail" />'
      sLabel = sLabel.replace( /%I%/g, sImgTag );
    }
    if ( theAddress.args ) sAddress += '&#63'+ theAddress.args;
    var sAnchor = '<a href="mailto:' + sAddress + '">'
                + sLabel + '</a>';
    document.write( sAnchor );
  }

  // JavaScript to show pictures in a separate window.
  // 
  function putThumb( sName ) // ToDo: Implement as a PHP function
  {
    document.write('<a href="javascript:showPicture(\'Pictures\',\''+sName+'\',\''+sName+'\');">');
    document.write('<img src="Thumbs/'+sName+'.gif" hspace="0" vspace="0"');
    document.write(' title="klik hier voor vergroting" alt="klik hier voor vergroting" /></a>');
  }

  function showPicture( sDir, sName, sTitle )
  {
    var sPath = sDir != '' ? sDir + '/' + sName + '.jpg'
                           :              sName + '.jpg';

    var sContent  = '<html><head><title>' + sTitle + '</title></head>';
        sContent += '<body style="margin: 0 0 0 0;">';
        sContent += '<img name="theImage" src="'+sPath+'"';
        sContent += ' title="Klik om te sluiten\nClick to close"';
        sContent += ' onLoad="window.resizeTo(document.theImage.width+20,document.theImage.height+80);window.focus();"';
        sContent += ' onClick="window.close();" alt="' + sTitle + '" />';
        sContent += '</body></html>';

    var sParam  = 'width=200,height=200,left=0,top=0,resizable=yes,';
        sParam += 'toolbar=no,location=no,directories=no,status=no,menuBar=no,scrollbars=no,copyhistory=no';

    var popupImage = window.open( '', 'MezWarezPicture', config=sParam );
    popupImage.document.open();
    popupImage.document.write( sContent );
    popupImage.document.close();
  }
  
  // DatePicker code
  var g_datePickers = new Array();
  var g_iTries      = 0;
  /*
   * Every element of this array is an object with the following members:
   *   { 'id'      : Value of the id="" attribute of the <input> field in th <form>       
   *     'element' : HTML <input> element inside the <form>
   *     'picker'  : the DatePicker object
   *   }   
   */     
  function initDatePickers()
  {
    var iCount = g_datePickers.length;
    if ( iCount < 1 ) return; // Nothing to do.

    // Attempt to grab the datePicker objects
    for ( var iPicker = 0; iPicker < iCount; ++iPicker )
    {
      var aPicker = g_datePickers[iPicker];
      aPicker.picker  = datePickerController.datePickers[aPicker.id];
    }
    // For Internet Explorer: If they are not created then call this function 200 milliseconds later
    for ( var iPicker = 0; iPicker < iCount; ++iPicker )
    {
      var aPicker = g_datePickers[iPicker];
      if ( ! aPicker.picker )
      {
        if ( g_iTries++ < 4 ) // Prevent endless trying.
        {
          setTimeout( 'initDatePickers()', 200 );
        } 
        return;
      }
    }

    // Reset the low ranges to be today for the StartDate datePickers
    var sToday = makeDatePickerDate( new Date());
    for ( var iPicker = 0; iPicker < iCount; ++iPicker )
    {
      var aPicker = g_datePickers[iPicker];
      aPicker.element = getElement( aPicker.id );
      //  aPicker.picker.setRangeLow( sToday );
    }
  }
  
  // SiteMap code:
  var g_siteMapTimer = null;
  function siteMapTimedHide( iSecs )
  {
    if ( g_siteMapTimer ) clearTimeout( g_siteMapTimer );

    g_siteMapTimer = setTimeout( 'hideSiteMap()', iSecs * 1000 );
  }
  function hideSiteMap()
  {
    showToolbox( null, '', '' );
    g_siteMapTimer = null;
  }

