/* $Id: bob-popup.js,v 1.4 2014/05/19 06:34:05 tessmann Exp $
 *
 * PROJEKT:      K3
 * KOMPONENTE:   Elektronische Betriebsanleitung On-board
 * AUFGABE:      Javascript Stylesheet - Erweiterung fuer Variante
 * ERSTELLER:    DOSCO Document Systems Consulting GmbH
 *               Heidelberg, Tel. 06221-14860
 * ERSTELLDATUM: 03.2011
 * AUTOR:        Franz Fackelmann
 *
 * Copyright (C) 2011 DOSCO GmbH
 *
 */


var top = 4;
var currentPopup = null;
var lastURL = null;
var lastYOffset = 0;
var lastImgSrc = "./images/dummy_image.jpg";
var lastLbl = "";



  /* Initial preparation of a popup should
     be done by CSS in final version! */
function preparePopup()
{
  /* pp.style.top = top + "px"; */
  pp.style.top = top + "px";

  /* hide popup */
  pp.set("opacity", 0);
}


/* Show/hide popup */
function popupImage(imgSrc, ret, lblImg, lblTxt, on)
{
  var id = "popupFrameImg";

  if (lblTxt != "") {
    lastLbl = lblTxt;
  }

  if (imgSrc !="") {
    lastImgSrc = imgSrc;
  }

  if (on) {
    var block = document.getElementById(ret);
    if (block) {
      lastYOffset = (block.offsetTop - window.pageYOffset);
    }
    else {
      lastYOffset = 0;
    }
  }
  
  var img = $("popupImg");
  if (img) {
    img.src = lastImgSrc;
  }
  /* if 'popupImgLbl' exists it will be used for the image label */
  var lbl2 = document.getElementById("popupImgLbl");
  if (lbl2) {
	  lbl2.innerHTML = lastLbl;
  }

  var pp = $(id);
  var pp_exit = $("popupFrameImg_exit");
  $("content").fade(on ? 0.2 : "in");
  
    /* save current popup id */
    currentPopup = id;
  
  if (on) {
    /* save return position */
    lastURL = ret;
    var myFx = new Fx.Tween(id, 
                             { property: "opacity", 
                               onComplete: function(){ 
                                 pp_exit.focus();
                               }
                             });
    myFx.start(1.0); // fade in
  }
  else {
    var myFx = new Fx.Tween(id, 
                             { property: "opacity", 
                               onComplete: function(){ 
                               }
                             });
    myFx.start(0.0); // fade out
    if (ret !=lastURL) {
      scroll_to(lastURL, lastYOffset, false);
    }
    if (block) {block.focus();
  }
}
return false;
}

/* Show/hide popup */
function popupAnm(ret, lblTxt, on)
{
  var id = "popupFrameAnm";

  if (lblTxt != "") {
    lastLbl = lblTxt;
  }

  if (on) {
    var block = document.getElementById(ret);
    if (block) {
      lastYOffset = (block.offsetTop - window.pageYOffset);
    }
    else {
      lastYOffset = 0;
    }
  }
  
  var lbl2 = document.getElementById("popupAnmLbl");
  if (lbl2) {
	  lbl2.innerHTML = lastLbl;
  }

  var pp = $(id);
  var pp_exit = $("popupFrameAnm_exit");
  $("content").fade(on ? 0.2 : "in");
  
    /* save current popup id */
    currentPopup = id;
  
  if (on) {
    /* save return position */
    lastURL = ret;
    var myFx = new Fx.Tween(id, 
                             { property: "opacity", 
                               onComplete: function(){ 
                                 pp_exit.focus();
                               }
                             });
    myFx.start(1.0); // fade in
  }
  else {
    var myFx = new Fx.Tween(id, 
                             { property: "opacity", 
                               onComplete: function(){ 
                               }
                             });
    myFx.start(0.0); // fade out
    if (ret !=lastURL) {
      scroll_to(lastURL, lastYOffset, false);
    }
    if (block) {block.focus();
  }
}
return false;
}

/* Disable/enable tabindex */
function disableTabindex(positions, on)
{
  if (on) {
    for (var i = 0; positions && i < positions.length; ++i) {
      var pos = $(positions[i]);
      if (pos != null)
      {
        pos.setProperty('tabindex', "-1");
      }
    }
  }
  else {
    for (var i = 0; positions && i < positions.length; ++i) {
      var pos = $(positions[i]);
      /* Attribut tabindex setzen, Präfix 'tabpos' 
      'tabpos' aus Positionsangabe entfernen */
      if (pos != null)
      {
        pos.setProperty('tabindex', positions[i].substring(6));
      }
    }
  }
}
