// ===============================================================================================================================
// drag_drop Drag & Drop Internet Explorer 4+ und Netscape 6.x
// ===============================================================================================================================
function drag_drop(e) {
  var lleft = -1;
  var ltop  = -1;

  if ( isIE && dragapproved ) {
    lleft = tempx + event.clientX - offsetx;
    ltop  = tempy + event.clientY - offsety;
  }
  else if ( isW3C && dragapproved ) {
    if (isW3C) {
      document.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP | Event.MOUSEMOVE);
    }

    lleft = tempx + e.clientX - offsetx;
    ltop  = tempy + e.clientY - offsety;
  }

  if ( dragapproved ) {
    if (lleft >= 0 ) {
      crossobj.style.left = lleft;
    }

    if (ltop >= 0 ) {
      crossobj.style.top = ltop;
    }
  }
  else {
    if (isW3C) {
      document.releaseEvents(Event.MOUSEDOWN | Event.MOUSEUP | Event.MOUSEMOVE);
    }
  }

  return false;
}

// ===============================================================================================================================
// initializedrag
// ===============================================================================================================================
function initializedrag(e) {
  crossobj= GetObjDiv("showimage");

  var firedobj= isW3C ? e.target : event.srcElement
  var topelement= isW3C ? "HTML" : "BODY"

  
  if ( firedobj.tagName != null ) {
    while ( firedobj.tagName != topelement && firedobj.id != "dragbar" ) {
      firedobj= isW3C ? firedobj.parentNode : firedobj.parentElement
    }
  }

  if ( firedobj.id == "dragbar" ) {
    offsetx = isIE ? event.clientX : e.clientX
    offsety = isIE ? event.clientY : e.clientY

    tempx = parseInt( crossobj.style.left )
    tempy = parseInt( crossobj.style.top )
 
    dragapproved=true

    if (isW3C) {
      document.captureEvents(Event.MOUSEMove);
    }

    document.onmousemove = drag_drop
  }
}


// ===============================================================================================================================
// hidebox()
// ===============================================================================================================================
function hidebox() {
  lobj= GetObjDiv("showimage");
  if (lobj != null) {
    lobj.style.visibility="hidden";
    // bei NS 6.2 gab es bei Selectboxen Probleme, die Scrollbar blieb stehen,
    // daher leeren des Content
    GetObjDiv("InnerHTMLContent").innerHTML = "";
  }
}

// ===============================================================================================================================
// showbox()
// ===============================================================================================================================
function showbox() {
  lobj = GetObjDiv("showimage");
  lobj.style.visibility = "visible";

  if (lobj.style.display.toLowerCase() == "none") {
    lobj.style.display = "block";
  }
}

// ===============================================================================================================================
// SetPopUpWindow
// ===============================================================================================================================
function setpopupwindow(asourceID, aLeftPosCorrection, aTopPosCorrection) {
  ActivateDragDrop();

  lobj = GetObjDiv("showimage");
  lobj.style.visibility = "visible";

  if (lobj.style.display.toLowerCase() == "none") {
    lobj.style.display = "block";
  }

  var lsource = GetObjDiv(asourceID).innerHTML;
  linnerHTMLDiv = GetObjDiv("InnerHTMLContent");
  linnerHTMLDiv.innerHTML = lsource;
  
  if ( ( CurrentMousePosX > -1 ) || ( CurrentMousePosY > -1 ) ) {
    lobj.style.left = CurrentMousePosX - linnerHTMLDiv.offsetWidth / 2 + aLeftPosCorrection;
    lobj.style.top = CurrentMousePosY - 20 + aTopPosCorrection;
  }
}

// ===============================================================================================================================
// Startet die Verschiebefunktion für das POPUP-Window
// ===============================================================================================================================
function ActivateDragDrop() {
  if (isW3C) {
    document.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP);
  }

  // Drag & Drop Ende
  document.onmousedown=initializedrag
  document.onmouseup=new Function("dragapproved=false")
}

// ===============================================================================================================================
// setHeadline
// ===============================================================================================================================
function setHeadline(asourceID) {
  var lsource = GetObjDiv(asourceID).innerHTML;
  GetObjDiv("InnerHTMLHeadline").innerHTML = lsource;
}

// ===============================================================================================================================
// setCustomBtnContent
// ===============================================================================================================================
function setCustomBtnContent(asourceID) {
  var lsource = GetObjDiv(asourceID).innerHTML;
  GetObjDiv("InnerCloseBtnContent").innerHTML = lsource;
}

// ===============================================================================================================================
// setIFrameDimensions
// ===============================================================================================================================
function setIFrameDimensions(aFrameID, aDivID) {
  ldivobj = GetObjDiv(aDivID);
  liframeobj = GetObjDiv(aFrameID);

  liframeobj.style.height = ldivobj.offsetHeight;
  liframeobj.style.width = ldivobj.offsetWidth;
}

// ===============================================================================================================================
// setMaxHeight
// ===============================================================================================================================
function setMaxHeight(aDivID, aTableID, amaxheight) {
  var ltableobj = GetObjDiv(aTableID);
  var lheight = ltableobj.offsetHeight;
  if ( lheight > amaxheight) {
    ldivobj = GetObjDiv(aDivID);
    ldivobj.style.height = amaxheight +"px";
  }
}

// ===============================================================================================================================
// Setzt die Breite des PopUpWindows
// ===============================================================================================================================
function setPopUpWidth(aInfoTableID, awidth) {
  lobj = GetObjDiv(aInfoTableID);
  if ( lobj != null ) {
    lobj.style.width = awidth;
  }
}

// ===============================================================================================================================
// Setzt die Src eines IFrames
// ===============================================================================================================================
function setIFrameSrc(aIframeID, asrc) {
  var liframe = GetObjDiv(aIframeID);

  if (liframe != null) {
    liframe.src = asrc;
  }
}