﻿isIE = document.all;
isNN = !document.all && document.getElementById;
isN4 = document.layers;
DoIt = false;


function ddInit(e){
  TWD = isIE ? "BODY" : "HTML";
  TWD1 = isIE ? document.all.layerTable : document.getElementById("layerTable");
  TWD2 = isIE ? event.srcElement : e.target;

  while (TWD2.id != "titleBar" && TWD2.tagName != TWD){
    TWD2 = isIE ? TWD2.parentElement : TWD2.parentNode;
  }


  if (TWD2.id == "titleBar"){
    offsetx = isIE ? event.clientX : e.clientX;
    offsety = isIE ? event.clientY : e.clientY;

    nowX = parseInt(TWD1.style.left);
    nowY = parseInt(TWD1.style.top);

    ddEnabled = true;
    document.onmousemove = dd;
  }
}

function dd(e){
  if (!ddEnabled) 
    return;

  TWD1.style.left = isIE ? nowX + event.clientX - offsetx : nowX + e.clientX - offsetx;
  TWD1.style.top = isIE ? nowY + event.clientY - offsety : nowY + e.clientY - offsety;
  return false;
}

function ddN4(TWD3){
  if (!isN4) 
    return;

  N4 = eval(TWD3);
  N4.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP);

  N4.onmousedown = function(e){
    N4.captureEvents(Event.MOUSEMOVE);
    N4x = e.x;
    N4y = e.y;
  }

  N4.onmousemove = function(e){
    if (DoIt){
      N4.moveBy(e.x - N4x, e.y - N4y);
      return false;
    }
  }

  N4.onmouseup = function() {
    N4.releaseEvents(Event.MOUSEMOVE);
  }
}

function hideMe(){
  TWD1 = isIE ? document.all.layerTable : document.getElementById("layerTable");

  if (isIE || isNN) 
    TWD1.style.visibility = "hidden";
  else if (isN4) 
    document.layerTable.visibility = "hide";
}

function showMe(){
  TWD1 = isIE ? document.all.layerTable : document.getElementById("layerTable");
  
  var currentLeft = parseInt(TWD1.style.width);
  var popLeft = (GetBrowserWidth() - currentLeft) / 2;

  if (isIE || isNN) {
    if (parseInt(TWD1.style.top) < 0) {
      TWD1.style.top = parseInt(TWD1.style.top) * -1;      
    }

    TWD1.style.left = popLeft;
    TWD1.style.visibility = "visible";
  }
  else if (isN4) {
    document.layerTable.visibility = "show";
    document.layerTable.style.left = popLeft;
  }
}


function GetBrowserWidth() {
  var browseWidth = 0;
  
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    browseWidth = window.innerWidth;
    
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    browseWidth = document.documentElement.clientWidth;
    
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    browseWidth = document.body.clientWidth;
  }
 
  return browseWidth;
}

document.onmousedown = ddInit;
document.onmouseup = Function("ddEnabled=false");

