function popupNotLoggedIn( elem, textPopup, offsetLeft, offsetTop )
{
  try
  {
    jQuery( '#box-extrainfo .inner' ).html( textPopup );

    var box = jQuery( '#box-extrainfo' );
    var offset = jQuery( elem ).offset();

    if ( !offsetLeft )
    {
      var offsetLeft = 10;
    }

    if ( !offsetTop )
    {
      var offsetTop = 10;
    }

    box.css( { display: 'block',
               width:   '300px',
               top:     ( offset.top  - box.height() + offsetTop ) + 'px' } );

    if ( ( offset.left - box.width() ) < offsetLeft )
    {
      box.css( { left: ( offset.left + jQuery( elem ).width() - offsetLeft ) + 'px' } );
    }
    else
    {
      box.css( { left: ( offset.left - box.width()  + offsetLeft ) + 'px' } );
    }

    box.click( function() { jQuery( this ).css( { width: 'auto' } ).hide(); } );
    box.blur( function() { jQuery( this ).css( { width: 'auto' } ); } );

    return false;
  }
  catch ( e )
  {
//    alert( e );
  }
}

function popupEmos( elem, popupId )
{
  try
  {
    var box = jQuery( popupId );
    var boxEmos = jQuery( '#box-emoticons' );
    var offset = jQuery( elem ).offset();

    boxEmos.css( { top:     ( offset.top + 5 ) + 'px',
                   left:    ( offset.left - box.width() - 2 ) + 'px' } );

    box.click( function() { jQuery( this ).hide(); } );

    box.show();

    return false;
  }
  catch ( e )
  {
//    alert( e );
  }
}

function popupEmosPos( elem, popupId, boxWidth, posLeft, posTop )
{
  try
  {
    var box = jQuery( popupId );
    var offset = jQuery( elem ).offset();

    box.css( { position: 'absolute',
               width:   boxWidth + 'px',
               top:     ( offset.top + posTop ) + 'px' } );

    if ( ( offset.left ) < boxWidth + posLeft )
    {
      box.css( { left:  posLeft + '10px' } );
    }
    else
    {
      box.css( { left: ( offset.left - ( boxWidth + posLeft ) ) + 'px' } );
    }

    box.click( function() { jQuery( this ).hide(); } );

    box.show();

    return false;
  }
  catch ( e )
  {
//    alert( e );
  }
}

try
{
//  jQuery( window ).load( function()
  jQuery( document ).ready( function()
  {
    var inp_username = jQuery( '.ipt-login-username' );
    var inp_password = jQuery( '.ipt-login-password' );

    if ( inp_username )
    {
      inp_username.each( function() {
        addClassIfNotEmpty( this, 'ipt-username' );
      } );

      inp_username.focus( function()
      {
        jQuery( this ).removeClass( 'ipt-username' );
      } );

      inp_username.blur( function()
      {
        addClassIfNotEmpty( this, 'ipt-username' );

//          if ( jQuery( this ).val() == '' )
//          {
//            jQuery( this ).addClass( 'ipt-username' );
//          }
      } );
    }

    if ( inp_password )
    {
      inp_password.each( function() {
        addClassIfNotEmpty( this, 'ipt-password' );
      } );

      inp_password.focus( function()
      {
        jQuery( this ).removeClass( 'ipt-password' );
      } );

      inp_password.blur( function()
      {
        addClassIfNotEmpty( this, 'ipt-password' );
//          if ( jQuery( this ).val() == '' )
//          {
//            jQuery( this ).addClass( 'ipt-password' );
//          }
      } );
    }
  } );
}
catch ( e ) {}

function addClassIfNotEmpty( elem, cssClass )
{
  if ( jQuery( elem ).val() == '' )
  {
    jQuery( elem ).addClass( cssClass );
  }
}

function debug( msg )
{
  try
  {
    var elem = null;

    if ( jQuery )
    {
      elem = jQuery( '#output' );
    }

    if ( window.console && window.console.log )
    {
      console.log( msg );
    }
    else if ( elem.length )
    {
      elem.html( elem.html() + '<br />' + msg );
    }
    else
    {
      alert( msg );
    }
  }
  catch ( e )
  {
//    alert( e );
  }
}

String.prototype.lTrim = function () {
  return ( this.replace( /^\s+/, '' ) );
};
String.prototype.rTrim = function () {
  return ( this.replace( /\s+$/, '' ) );
};
//kombiniert "leftTrim" und "rightTrim";
String.prototype.trim = function () {
  return ( this.lTrim().rTrim() );
};