/*
 * @__header__@
 *
 * ===== CVS-Server Info =============================================
 *
 * $Id: help.js,v 1.5 2007-02-06 13:03:54 hotzenplotz Exp $
 *
 * ===================================================================
 *
 * Author: Sebastian Rose <sebastian_rose@gmx.de>
 * Copyright © 2007 Sebastian Rose, sebastian_rose@gmx.de
 * Copyright © 2006 Sebastian Rose, sebastian_rose@gmx.de
 */

/**
 * srjshelpToggleVisibility();
 *
 * this.setWidth    ( width )       Breite, wie in style="" Tags. z.B. '120px'
 * this.setX        ( xPosition )   X-Position, wie in style="left:...;" Tags. z.B. '120px'
 * this.setLinkText ( text )
 * this.setImage    ( images_url )
 * this.setTooltip  ( text )
 * this.setHasFixedPosition ( bool ) Blocks fest positionieren (X)?
 *                                   Bei mouseover ist Default ist false, sonst true.
 * this.doHint ( doHint )           'Click to close' anzeigen? default true.
 *
 * this.link
 * this.block ( text )
 *
 * this.add   ( text )        tut beides: link() und block().
 *
 *
 * TODOO:
 * Die divs in eigener Klasse kapseln, so dass sie individuell
 * positioniert werden können.
 */


var SRJSHelpLastID = "";
var SRJSHelpClassID = 0;


function SRJSHelp(mouseover)
{
  // --------------------------------------------------
  this.Tooltip   = "Hilfe anzeigen/ausblenden";
  this.Linkstyle = 'style="font-family:sans-serif;font-weight:normal;font-style:normal;font-variant:normal;font-size:11px;color:blue;text-decoration:none;cursor:pointer;"';
  this.Linktext  = "Hilfe";
  this.Textstyle = 'style="font-family:sans-serif;font-weight:bold;font-style:normal;font-variant:normal;font-size:11px;"';
  this.Helpwidth = "200px";
  this.Leftpos   = "10px";
  this.BottomPos = "80px";
  this.ImgURL    = "";
  this.zIndex    = '5';
  this.Mouseover = mouseover;
  this.position  = "relative"; //"absolute";
  this.hasFixedPosition = (mouseover ? false : true);
  this.doHint    = true;
  this.use_opacity = false;

  // private:
  this.numItems  = 0;
  this.helpIdStr = "srjsHelpId_" + SRJSHelpClassID + '_';

  ++SRJSHelpClassID;
}





// Global, da erzeugte Elemente per onclick="" darauf zugreifen.
function srjshelpToggleVisibility ( idstr, mouseIsIn ) {

  var item = document.getElementById(idstr);

  if ( SRJSHelpLastID != idstr && SRJSHelpLastID.length > 0 ) {
    var lastone = document.getElementById(SRJSHelpLastID);
    if(lastone) {
      lastone.style.visibility = "hidden";
    }
  }

  if ( item.style.visibility == "visible" ) {
    item.style.visibility = "hidden";
  }
  else {
    item.style.visibility = "visible";
  }
  SRJSHelpLastID = idstr;
}



SRJSHelp.prototype.setWidth = function ( width ) {
  this.Helpwidth = "" + width;
}



SRJSHelp.prototype.setX = function ( position ) {
  this.Leftpos = "" + position;
}


SRJSHelp.prototype.setLinkText = function ( text ) {
  this.Linktext = "" + text;
}



SRJSHelp.prototype.setImage = function ( img_url ) {
  this.ImgURL = img_url;
}



SRJSHelp.prototype.link = function( ) {
  this.numItems++;
  SRJSHelpLastID = this.helpIdStr + this.numItems;

  if(this.Mouseover) {
    document.write('<a onmouseover="srjshelpToggleVisibility(\''
                   + SRJSHelpLastID + '\', true);" onmouseout="srjshelpToggleVisibility(\''
                   + SRJSHelpLastID + '\', false);" alt="" '
                   + ' title="" '
                   + this.Linkstyle
                   + '>' + this.Linktext + '</a>');

  }
  else {
    document.write('<a onclick="srjshelpToggleVisibility(\''
                   + SRJSHelpLastID + '\');" alt="' + this.Tooltip + '" '
                   + ' title="' + this.Tooltip + '" '
                   + this.Linkstyle
                   + '>' + this.Linktext + '</a>');
  }

  return SRJSHelpLastID;
}



SRJSHelp.prototype.setTooltip = function ( tooltip )
{
  this.Tooltip = "" + tooltip;
}



SRJSHelp.prototype.block = function ( text ) {
  document.write ( '<div style="width:0px;height:0px;position:absolute;"><div id="' + SRJSHelpLastID
                   + '" onclick="srjshelpToggleVisibility(\''
                   + SRJSHelpLastID + '\');" '
                   + ' style="z-index:'+ this.zIndex+';cursor:pointer;visibility:hidden;'
                   + 'bottom:' + this.BottomPos + ';'
                   + 'position:' + this.position + ';width:'
                   + this.Helpwidth + ';' );
  if( this.hasFixedPosition ) {
    document.write ( 'left:' + this.Leftpos + ';' );
  }
  document.write ( 'background-color:#E5EDF1;color:#FF6600;border:1px solid #b6b7cb;padding:8px 8px 8px 8px;text-align:left;vertical-align:top;');
  if(this.use_opacity) {
    document.write('opacity:0.90;-moz-opacity:0.90;-khtml-opacity:0.9;filter:Alpha(opacity=90);');
  }
  document.write ( '">' );
  if ( this.ImgURL.length > 0 ) {
    document.write ( '<img style="float:left;margin-right:5px;margin-bottom:0px;" src="'
                     + this.ImgURL + '" border="0" title="" alt=""/>' );
  }

  document.write('<span ' + this.Textstyle + '>' + text + '</span>');

  if(! this.Mouseover && this.doHint ) {
    document.write('<div style="text-align:center;margin-top:12px;">'
                   + '<span style="font-size:9px;color:#aaaaaa;font-family:sans-serif;font-weight:normal;">'
                   + '--- klick link or help-display to close ---</span></div>'
                   + '</div>');
  }
  document.write('</div></div>');
  return SRJSHelpLastID;
}



SRJSHelp.prototype.add = function ( text ) {

  if(arguments) {               // JavaScript >= 1.4
    for(var i = 1; i < arguments.length; ++i) {
      switch (i)
        {
        case 1:
          break;
        }
    }
  }
  else {
    for(var i = 1; i < srjshelpAdd.arguments.length; ++i) {
      switch (i)
        {
        case 1:
          break;
        }
    }
  }

  this.link  ( );
  this.block ( text );
}



SRJSHelp.prototype.setHasFixedPosition = function ( hasIt )
{
  this.hasFixedPosition = hasIt;
}



SRJSHelp.prototype.setHint = function (doHint)
{
  this.doHint = doHint;
}

