﻿var InputBoxId = "";
var ScrollBoxes = new Array();

function ImgOver(img)
{
    NewImgSrc = "images/" + img.id + "_a.gif";
    img.src = NewImgSrc;
}
function ImgOut(img)
{
    NewImgSrc = "images/" + img.id + "_i.gif";
    img.src = NewImgSrc;
}
function resizeIFrameWidthHeight(IFrameID, Width, Height)
{
    document.getElementById(IFrameID).style.width = Width + "px";
    document.getElementById(IFrameID).style.height = Height + "px";
}

function showMedia(ParentElement, MT_ID, WO_ID, WO_MEDIA_PATH)
{
    if(MT_ID == 4)
    {
        window.open(WO_MEDIA_PATH, "bp_extern");
    } else {
        theFrame = document.getElementById("GB_POPUP_IFRAME");
        theFrame.src = "MediaPlayer.aspx?WO_ID=" + WO_ID;
        theFrame.className="GB_IFRAME_ACTIVE";
    
        setInputBoxAbsolute(ParentElement, "GB_POPUP");
    }
}
function closeMediaPlayer()
{
    theFrame = document.getElementById("GB_POPUP_IFRAME");
    theFrame.src = "PleaseWait.aspx";
    theFrame.className = "GB_IFRAME_INACTIVE";
    
    unsetInputBox();
}

function setInputBoxAbsolute(ParentObject, NewInputBoxId)
{
    if(InputBoxId != "")
        unsetInputBox();
        
    InputBoxIdPannding = NewInputBoxId;
    InputBoxId = InputBoxIdPannding;
    
    obj = document.getElementById(InputBoxId);
    //ParentObject = document.getElementById(ParentObjectId);
    
    obj.className = "MEM_INPUTBOX_ACTIVE";
    obj.style.visibility = "visible";
    
    posX = findPosX(ParentObject) + (obj.offsetWidth / 2);
    posY = findPosY(ParentObject) + (ParentObject.offsetHeight / 2);
    
    if(navigator.appVersion.indexOf("MSIE") != -1)
    {
        posX += getScrollXY().X;
        posY += getScrollXY().Y;
    }

    //Check the bounds of the BOX in browser window and reset
    if (posX + obj.offsetWidth > BrowserDimensions().width)
        posX = posX - (posX + obj.offsetWidth - BrowserDimensions().width) - 20;
        
    if (posX < 10)
        posX = 10;
        
    if (posY + obj.offsetHeight - getScrollXY().Y > BrowserDimensions().height)
        posY = posY - ((posY + obj.offsetHeight - getScrollXY().Y) - BrowserDimensions().height) - 20;
    
    obj.style.left = posX + "px";
    obj.style.top = posY + "px";
    
    //Disable Scrollbars für Firefox
    for(i = 0; i < ScrollBoxes.length; i++){
        ScrollObj = document.getElementById(ScrollBoxes[i]);
        ScrollBoxesType[i] = ScrollObj.style.overflow;
        ScrollObj.style.overflow = "hidden";
    }
    
}

function checkBounds(objectID)
{
    obj = document.getElementById(objectID);
    
    posX = obj.offsetLeft;
    posY = obj.offsetTop;

    if (posX + obj.offsetWidth > BrowserDimensions().width)
        posX = posX - (posX + obj.offsetWidth - BrowserDimensions().width) - 20;
        
    if (posX < 10)
        posX = 10;
        
    if (posY + obj.offsetHeight - getScrollXY().Y > BrowserDimensions().height)
        posY = posY - ((posY + obj.offsetHeight - getScrollXY().Y) - BrowserDimensions().height) - 20;
        
    obj.style.left = posX + "px";
    obj.style.top = posY + "px";
}

function unsetInputBox(obj)
{
    if(obj == null)
        obj = document.getElementById(InputBoxId);
        
    obj.className = "MEM_INPUTBOX_INACTIVE";
    obj.style.visibility = "hidden";
    InputBoxId = "";
    
    //Disable Scrollbars für Firefox
    for(i = 0; i < ScrollBoxes.length; i++){
        ScrollObj = document.getElementById(ScrollBoxes[i]);
        ScrollObj.style.overflow = ScrollBoxesType[i];
    }
}

function findPosX(obj) {
   var curleft = 0;
   if(navigator.appVersion.indexOf("MSIE") != -1) {
     curleft = obj.getBoundingClientRect().left - 2;
   }
   else if(obj.offsetParent) {
      while(obj.offsetParent) {
         curleft += obj.offsetLeft
         obj = obj.offsetParent;
      }
   }

   return curleft;
}
 
function findPosY(obj) {
   var curtop = 0;
   if(navigator.appVersion.indexOf("MSIE") != -1) {
      curtop = obj.getBoundingClientRect().top - 2;
   }
   else if(obj.offsetParent) {
      while(obj.offsetParent) {
         curtop += obj.offsetTop
         obj = obj.offsetParent;
      }
   }

   return curtop;
}

function getScrollXY() {
  var scrOf = {X:0, Y:0};
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOf.Y = window.pageYOffset;
    scrOf.X = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOf.Y = document.body.scrollTop;
    scrOf.X = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOf.Y = document.documentElement.scrollTop;
    scrOf.X = document.documentElement.scrollLeft;
  }
  return scrOf;
}

function pageOffset(win)
{
    if(!win) win = window;
    var pos = {left:0,top:0};

    if(typeof win.pageXOffset != 'undefined')
    {
         // Mozilla/Netscape
         pos.left = win.pageXOffset;
         pos.top = win.pageYOffset;
    }
    else
    {
         var obj = (win.document.compatMode && win.document.compatMode == "CSS1Compat") ?
         win.document.documentElement : win.document.body || null;

         pos.left = obj.scrollLeft;
         pos.top = obj.scrollTop;
    }
    return pos;
}

function BrowserDimensions(){
    var Dimension = {width:0,height:0};

    // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

    if (typeof window.innerWidth != 'undefined')
    {
      Dimension.width = window.innerWidth;
      Dimension.height = window.innerHeight;
    }

    // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

    else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
    {
       Dimension.width = document.documentElement.clientWidth;
       Dimension.height = document.documentElement.clientHeight;
    }

    // older versions of IE

    else
    {
       Dimension.width = document.getElementsByTagName('body')[0].clientWidth;
       Dimension.height = document.getElementsByTagName('body')[0].clientHeight;
    }
    return Dimension;
}