//****************************************************************************//
//    Fehler nachricht anzeigen:
// 	  showDisplay({ HCursor: true });
//	  showErrorDisplay('ajax - Fehler', 'Es ist folgender Fehler aufgetreten', 'closeDisplay()');
//****************************************************************************//

var TMP_EXTENS       = {};

var INDIKATOREN      = new Array();
    INDIKATOREN["A"] = {name:"../himage/aj_indi_2.gif", height:128, width:128, position: "cc", cssClass: "", margin: 10 }
    INDIKATOREN["B"] = {name:"../himage/aj_indi_3.gif", height:13, width:208, position: "bl", cssClass: "", margin: 10 }
    INDIKATOREN["C"] = {name:"../himage/aj_indi_1.gif", height:42, width:42, position:"cc", cssClass: "", margin: 10 }
    
// vorladen der indikatoren 
  tmp = new Image(); tmp.src = INDIKATOREN["A"].name;
  tmp = new Image(); tmp.src = INDIKATOREN["B"].name;
  tmp = new Image(); tmp.src = INDIKATOREN["C"].name;
  delete(tmp);
  
	
//****************************************************************************//
//
//****************************************************************************//
function createDisplayBoxes(){
  var obj = document.getElementById("DISPLAY_MESSAGES");

  if (obj != null) {
    var sizes = getPageSize();
    obj.style.height = sizes[1];
    return true;
  }

  obj = document.createElement("DIV");
  obj.id = "DISPLAY_MESSAGES";
  obj.className = "clsDisplayMsg";
  if (TMP_EXTENS && TMP_EXTENS.HCursor == true)
    obj.className = obj.className +  " clsDisplayMsgWithHourGlas";
    
  var sizes = getPageSize();
  obj.style.height = sizes[1];

  var tm2 = document.createElement("DIV");
  tm2.id ="DISPLAY_MESSAGES_BACKGROUND";
  tm2.className = "clsDisplayMsgBackground";
  obj.appendChild(tm2);
  
  var tm2 = document.createElement("DIV");
  tm2.id ="DISPLAY_MESSAGES_ACTION";
  tm2.className = "clsDisplayMsgAction";
  obj.appendChild(tm2);
   
  document.body.appendChild(obj);
  return true;
}
//****************************************************************************//
//
//****************************************************************************//
function toggleDisplayBoxes(vis){
  var obj = document.getElementById("DISPLAY_MESSAGES");
  if (obj == null) return false;
  switch (vis) {
   case true  :  obj.style.visibility =  "visible";
                 obj.style.display = "block";
                 document.body.style.overflow = "hidden";
                 break;
   case false :  obj.style.visibility =  "hidden";
                 obj.style.display = "none";
                 document.body.style.overflow = "";
                 break;
  }
  if (TMP_EXTENS.Progress){
    var obj = document.getElementById("DISPLAY_MESSAGES_INDICATOR");
    if (obj != null)
      switch (vis) {
        case true  :  obj.style.visibility =  "visible";
                      obj.style.display = "block";
                      break;
        case false :  obj.style.visibility =  "hidden";
                      obj.style.display = "none";
                      break;
      }
  }
  if (vis && TMP_EXTENS && TMP_EXTENS.oSw) eval(TMP_EXTENS.oSw);
    else if (!vis && TMP_EXTENS && TMP_EXTENS.oRm) eval(TMP_EXTENS.oRm);
  return true;
}
//****************************************************************************//
//
//****************************************************************************//
function createProgress(){
  if (TMP_EXTENS.Progress) {
    var str = (TMP_EXTENS.margin != null && TMP_EXTENS.margin > 0 ) ? TMP_EXTENS.margin : 10;
    var img = INDIKATOREN[TMP_EXTENS.Progress.toUpperCase()];

    if (img != null) {
      var pos = {right: -1, left: -1, top: -1, bottom: -1};

      var tmp = getPageSize();
      var hg  = tmp[3];
      var wd  = tmp[2];
      
      tmp = (TMP_EXTENS.ProgPos) ? TMP_EXTENS.ProgPos : img.position;
      switch (tmp.toUpperCase()) {
        case "TC": pos = {right: -1, left: ((wd - img.width) / 2), top: str, bottom: -1}
                   break;
        case "CT": pos = {right: -1, left: ((wd - img.width) / 2), top: str, bottom: -1}
                   break;
        case "TL": pos = {right: -1, left: str, top: str, bottom: -1};
                   break;
        case "LT": pos = {right: -1, left: str, top: str, bottom: -1};
                   break;
        case "TR": pos = {right: str, left: -1, top: str, bottom: -1};
                   break;
        case "RT": pos = {right: str, left: -1, top: str, bottom: -1};
                   break;
        case "BL": pos = {right: -1, left: str, top: -1, bottom: str};
                   break;
        case "LB": pos = {right: -1, left: str, top: -1, bottom: str};
                   break;
        case "BR": pos = {right: str, left: -1, top: -1, bottom: str};
                   break;
        case "RB": pos = {right: str, left: -1, top: -1, bottom: str};
                   break;
        case "BC": pos = {right: -1, left: ((wd - img.width) / 2), top: -1, bottom: str};
                   break;
        case "CB": pos = {right: -1, left: ((wd - img.width) / 2), top: -1, bottom: str};
                   break;
        default:   pos = {right: -1, left: ((wd - img.width) / 2), top: ((hg - img.height) / 2), bottom: -1};
                   break;
      } //end switch
      //span finden bzw. ggfs anlegen
      var obj = document.getElementById("DISPLAY_MESSAGES_INDICATOR");
      if (!obj) {
        var dest = document.getElementById("DISPLAY_MESSAGES");
        if (dest == null) return;
        obj = document.createElement('SPAN');
        obj.id = "DISPLAY_MESSAGES_INDICATOR";
        obj.className = "clsDisplayMsgIndicator";
        document.body.appendChild(obj);
      }
      obj.style.backgroundImage = "url(" + img.name + ")";
      obj.style.height =  img.height;
      obj.style.width = img.width;
      if (pos.right > 0) obj.style.right = pos.right;
      if (pos.left > 0) obj.style.left = pos.left;
      if (pos.top > 0) obj.style.top = pos.top;
      if (pos.bottom > 0) obj.style.bottom = pos.bottom;
    } //end if
  }//end if
}
//****************************************************************************//
// showErrorDisplay funktioniert nur wenn vorher der Bildschirm abgedunkelt wurde
//****************************************************************************//
function __closeErrorDisplay(){
  var obj = document.getElementById("DISPLAY_ERRMSGBOX");
  if (obj != null) {
    obj.style.visibility =  "hidden";
    obj.style.display = "none";
  }
  toggleDisplayBoxes(false);
  if (TMP_EXTENS && TMP_EXTENS.oRm) eval(TMP_EXTENS.oRm);
  return true;
}

function __showErrorDisplay(header, msg) {
  var obj = document.getElementById("DISPLAY_ERRMSGBOX");
  if (obj == null) {
    var tm = document.getElementById("DISPLAY_MESSAGES_ACTION");
    if (tm == null) return;
    
    obj = document.createElement("DIV");
    obj.id = "DISPLAY_ERRMSGBOX";
    obj.className = "clsDisplayErrMsgBox";
    tm.appendChild(obj);

    tm = document.createElement("DIV");
    tm.id ="DISPLAY_ERRMSGBOX_HEADER";
    tm.className ="clsDisplayErrMsgBoxHeader";
    tm.innerHTML = header;
    obj.appendChild(tm);
    
    tm = document.createElement("DIV");
    tm.id = "DISPLAY_ERRMSGBOX_CONTENT";
    tm.className = "clsDisplayErrMsgBoxContent";
    tm.innerHTML = msg;
    obj.appendChild(tm);
    
    tm = document.createElement("DIV");
    tm.id = "DISPLAY_ERRMSGBOX_ACTION";
    tm.className ="clsDisplayErrMsgBoxAction";

    var btn = document.createElement("BUTTON")
    btn.id = "DISPLAY_ERRMSGBOX_SUBMIT";
    btn.name = "bntOk";
    btn.onclick = __closeErrorDisplay;
    btn.className = "clsDisplayErrMsgBoxSubmit";
    btn.innerHTML = "Schlie&szlig;en";
    tm.appendChild(btn);
    obj.appendChild(tm);
    
  }
  var hg = getPageSize();
  obj.style.top = (hg[3] - 220) / 2;
  obj.style.left = (hg[2] - 470) / 2;
  obj.style.visibility =  "visible";
  obj.style.display = "block";
}
//****************************************************************************//
// erzeugt ggfs. eine  Anzeige Box für die Bildwiedergabe
//das bild mittels einen callbacks intern geladen un erst dann angezeigt

var callOn = null;
var callImg = "";
var tmpImg = null;

function ImagecallBack(){
  if (tmpImg.complete) {
    window.clearInterval(callOn);
    window.scrollTo(0,0);
    tmp = document.getElementById('DISPLAY_IMAGE');
    tmp.style.backgroundImage = "url(" + callImg + ")";
    tmp = document.getElementById('DISPLAY_IMAGE_BUTTON');
	  tmp.style.display  = 'block';
	  tmp.style.visibility = 'visible';
  }
}

function showImage() {
  window.scrollTo(0,0);
  if (arguments.length <= 0 || !isObject(arguments[0]) || !arguments[0].VImg) return setErrorMsg("Argument fehlt ode rist unvollständig.");

  showDisplay(arguments[0]);

  obj = document.getElementById('DISPLAY_IMAGEBOX');
  tmp = null;
  if (obj == null) {
    obj = document.createElement('div');
    obj.id = 'DISPLAY_IMAGEBOX';
    obj.className = 'clsDisplayImageBox';
    obj.onMouseOver = function (){Statustext('');};
    obj.onMouseOut = function (){Statustext('');};
    document.body.appendChild(obj);
    
	tmp  = document.createElement('span');
	tmp.id = 'DISPLAY_IMAGE_LABEL';
	tmp.className = 'clsDisplayImageLabel';
	obj.appendChild(tmp);
	
    tmp = document.createElement('input');
    tmp.id = 'DISPLAY_IMAGE_BUTTON';
    tmp.type = 'button';
    tmp.className = 'clsDisplayImageButton';
    tmp.value = "X";
    tmp.onmouseover = function () {Statustext('Bildbetrachter schliessen'); }
    tmp.onmouseout = function () { Statustext(''); }
    tmp.onclick = function () {
                                obj = document.getElementById('DISPLAY_IMAGEBOX');
                                obj.style.display = 'none';
                                obj.style.visibility = 'hidden';
                                toggleDisplayBoxes(false);
                                if (TMP_EXTENS && TMP_EXTENS.oRm) eval(TMP_EXTENS.oRm);
                                return true;
                               }

                  
    obj.appendChild(tmp);
    
    tmp = document.createElement('div');
    tmp.id = 'DISPLAY_IMAGE';
    tmp.className = 'clsDisplayImage';
    tmp.onMouseOver = function () {Statustext('');}
    tmp.onMouseOut = function () {Statustext('');}
    obj.appendChild(tmp);
  }
  tmp = (tmp == null) ? document.getElementById('DISPLAY_IMAGE'):tmp;
  tmp.style.backgroundImage = "url(" + INDIKATOREN["C"].name + ")";

  
  //größen berechnen
  a        = getPageSize();
  hoehe    = (a[3] - 40);
  breite   = (hoehe - 20);
  oben     = (a[3] - hoehe) / 2;
  links    = (a[2] - breite) / 2;

  obj.style.height = (hoehe.toString() + 'px');
  obj.style.width = (breite.toString() + 'px');
  obj.style.top = (oben.toString() + 'px');
  obj.style.left = (links.toString() + 'px');

  hoehe   = (hoehe - 40);
  breite  = (breite - 20);
  tmp.style.height = (hoehe.toString() + 'px');
  tmp.style.width = (breite.toString() + 'px');

  tmp = document.getElementById('DISPLAY_IMAGE_BUTTON');
  tmp.style.display = 'none';
  tmp.style.visibility = 'hidden';

  tmp = document.getElementById('DISPLAY_IMAGE_LABEL'); 
  tmp.innerHTML = (TMP_EXTENS && TMP_EXTENS.VName) ? TMP_EXTENS.VName : '';
  
  obj.style.display = "block";
  obj.style.visibility = "visible";

  //bild zuweisen
  callImg = "../hdoc/imgSrv.php5?" + TMP_EXTENS.VSES + ((TMP_EXTENS.VSES != "") ? "&" : "") + "cmd=IMGTHU&pic=" + TMP_EXTENS.VImg + "&h=" + hoehe.toString()  + "&w=" + breite.toString();
  tmpImg = new Image();
  tmpImg.src = callImg;
  callOn = window.setInterval("ImagecallBack()", 1);

  
}
//****************************************************************************//
//  oSw = onShow
//  oRm = onClose
//  STime = timeout (setTimeout)
//  Progress = A|B  -> progressbar anzeigen
//  ProPos = position Progressbar
//  EMsg = Fehlernachricht
//	EMsgHd = EMessage Header
//  HCursor = true/false
//  VImg = uri zu einem bild für die anzeige
//  VSES = sessionName und SessionID als uri teilstück
//  VName = Bildüber-/unterschrift
//****************************************************************************//
function showDisplay(){
  if (arguments.length > 0) {
    TMP_EXTENS = arguments[0];
    createDisplayBoxes();
    createProgress();
    toggleDisplayBoxes(true);
    if (TMP_EXTENS && TMP_EXTENS.STime > 0)
      window.setTimeout("toggleDisplayBoxes(false);", TMP_EXTENS.STime)
  }
  return true;
}

function closeDisplay(){
  toggleDisplayBoxes(false);
}


function CloseErrorDisplay(){
  __closeErrorDisplay();
  toggleDisplayBoxes(false);
}

function ErrorDisplay(){
  var tmpTime = 0;
  if (arguments.length > 0) {
    window.scrollTo(0,0);
	TMP_EXTENS = arguments[0];
	if ((arguments[0].EMsg && arguments[0].EMsgHd) && (arguments[0].EMsg != "" && arguments[0].EMsgHd != "")) { 
	  createDisplayBoxes();
	  toggleDisplayBoxes(true);
	  __showErrorDisplay(arguments[0].EMsgHd, arguments[0].EMsg);
      if (TMP_EXTENS.STime && TMP_EXTENS.STime > 0) 
	    window.setTimeout("CloseErrorDisplay();", TMP_EXTENS.STime)
	}
	
  }  
}

 
