// -------------------------------- Functions

if( window.jQuery )  // Avoid more errors in IE 5.0
{
  // Directly set flag for CSS to indicate JavaScript is enabled.
  // At this point "HTML" is the only accessable element.
  $(document.documentElement).addClass("jsEnabled");

    $(document).ready( function() {

// -------------------------------- Form input label flip

  // Activate 'overlabels' for compact forms
  $('label.overlabel')
    .each( function()
      {
  // Get field
      var label = $(this);
      var id = this.htmlFor || this.getAttribute('for');
      var field = null;
      if( ! id || ! (field = document.getElementById( id ) ) ) return;

   // Implement show/hide effect
      $(field).addClass("overlabel-js")                 // for setTimeout() below
        .focus( function() { label.hide(); } )
        .blur ( function() { this.value === '' && label.show(); } );

   // Also for mouse click
      label.mousedown( function() { field.focus(); } );
        }
      );

   // Hide overlabels after the form is auto-filled in by the browser.
     setTimeout( function()
     {
       var fields = $("input.overlabel-js");
       var labels = $("label.overlabel");
     fields.each( function() { this.value !== '' && labels.filter("[for=" + this.id + "]").hide(); } );
     }, 50 );


   // print the page
     $("#login .print a").click( function ( event )
     {
       window.print();
      } );

// ------------------------------- Fix links

    // give links with rel="external" target="_blank" attribuut.
      $(document.links).filter('[href][rel=external]').attr("target", "_blank");					

  });
}
