  // global constants
  var BORDER_SIZE = 8;
  var HEADER_SIZE = 125;
  var FOOTER_SIZE = 40;
  var MIN_FRAME_HEIGHT = 70;
  var FRAME_HEADER_HEIGHT = 60;
  var IFRAME_FACTOR = 0;
  var FOLDER_FRAME_WIDTH = 220;
  
  // global variables used to track positions of frames
  var curHeight = 0;
  var curWidth = 0;
  var curPosY = 0;
  var newPosY = 0;
  var curPosX = 0;
  var newPosX = 0;
  var mouseStatus = 'up';
  var curElem = null;
  //var verticalProportion = 0.5;
  //var horizontalProportion = 0.2;

  //this function gets the original div height
  function setPos(e, elem) {
    mouseStatus='down';
    var curevent = (typeof event == 'undefined' ? e : event)
    curElem = elem;
    if(elem == 'ver') {
      //document.body.style.cursor = 's-resize';
      curPosY = curevent.clientY;
      var temp = document.getElementById(LAYOUT == 'R' ? 'list' : 'tree').style.height;
      heightArray = temp.split('p')
      curHeight = parseInt(heightArray[0])
      if(LAYOUT == 'L') {
        curHeight -= HEADER_SIZE;
      }
    } else {
      //document.body.style.cursor = 'e-resize';
      curPosX = curevent.clientX;
      var temp = document.getElementById('tree').style.width;
      heightArray = temp.split('p')
      curWidth = parseInt(heightArray[0])
    }
  }

  //this changes the height of the div while the mouse button is depressed
  
   
  function getWindowSize() {
     var myWidth = 0, myHeight = 0;
     if( typeof( window.innerWidth ) == 'number' ) {
       //Non-IE
       myWidth = window.innerWidth;
       myHeight = window.innerHeight;
     } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
       //IE 6+ in 'standards compliant mode'
       myWidth = document.documentElement.clientWidth;
       myHeight = document.documentElement.clientHeight;
     } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
       //IE 4 compatible
       myWidth = document.body.clientWidth;
       myHeight = document.body.clientHeight;
     }
     var rv = new Array();
     rv[0] = myWidth;
     rv[1] = myHeight;
     return rv;
  }
  
  function windowResized() {
    var ss = getWindowSize();
    var h = ss[1] - HEADER_SIZE;
    var w = ss[0];
    var lh = Math.round(h * verticalProportion);
    var mh = h - lh - BORDER_SIZE;
    var tw = Math.round(w * horizontalProportion);
    w = w - tw - 14;
    
    // if(LAYOUT == 'R') {
      document.getElementById('tree').style.height = (h - 2 - FOOTER_SIZE) + 'px';
      document.getElementById('tree').style.width = (tw - BORDER_SIZE - 2) + 'px';
      document.getElementById('tree').style.top = (HEADER_SIZE) + 'px';
    
      // document.getElementById('list').style.height = (lh - HEADER_SIZE - 1) + 'px';
      document.getElementById('listHeader').style.height = (FRAME_HEADER_HEIGHT) + 'px';
      document.getElementById('listHeader').style.width = w + 'px';
      document.getElementById('listHeader').style.top = (HEADER_SIZE) + 'px';
      document.getElementById('listHeader').style.right = 0 + 'px';
      
      document.getElementById('list').style.height = (h - 1 - FOOTER_SIZE - FRAME_HEADER_HEIGHT) + 'px';
      document.getElementById('list').style.width = w + 'px';
      document.getElementById('list').style.top = (HEADER_SIZE + FRAME_HEADER_HEIGHT) + 'px';
      document.getElementById('list').style.right = 0 + 'px';
      document.getElementById('list').style.left = 'auto';
    
      /*
      document.getElementById('main').style.height = (mh + HEADER_SIZE - 1 - FOOTER_SIZE) + 'px';
      document.getElementById('main').style.width = w + 'px';
      document.getElementById('main').style.bottom = FOOTER_SIZE + 'px';
      */
      /*
      document.getElementById('vh').style.height = (BORDER_SIZE - 2) + 'px';
      document.getElementById('vh').style.width = w + 'px';
      document.getElementById('vh').style.top = (lh + 1) + 'px';
      document.getElementById('vh').style.right = 0 + 'px';
      document.getElementById('vh').style.left = 'auto';
      document.getElementById('vh').style.bottom = 'auto';
      */
    
      document.getElementById('hh').style.height = (h) + 'px';
      document.getElementById('hh').style.width = (BORDER_SIZE - 2) + 'px';
      document.getElementById('hh').style.bottom = FOOTER_SIZE + 'px';
      document.getElementById('hh').style.left = (tw - BORDER_SIZE + 7) + 'px';
    
      /*
      var ifr = document.getElementById('newsFullFrame');
      if(ifr) {
        ifr.style.width = (w - 0) + 'px';
        ifr.style.height = (mh - IFRAME_FACTOR) + 'px';
      }
      */
      if(FULL_NEWS_SELECTED) {
        var l = document.getElementById('list');
        var h = l.style.height.replace('px', '') - 34 * 3;
        var w = l.style.width.replace('px', '') - 70;
        var ifr = document.getElementById('newsFullFrame');
        ifr.style.width = (w) + 'px';
        ifr.style.height = (h) + 'px';
        scrollIntoCurrentNews();
      }
      
      with(document.getElementById('newerNewsAvailable').style) {
        top = '130px';
        right = '25px';
      }
      
    // } else {
      /*
      document.getElementById('tree').style.height = (lh) + 'px';
      document.getElementById('tree').style.width = (tw - BORDER_SIZE - 2) + 'px';
      document.getElementById('tree').style.top = (HEADER_SIZE) + 'px';
    
      document.getElementById('list').style.height = (mh - 2) + 'px';
      document.getElementById('list').style.width = (tw - BORDER_SIZE - 2) + 'px';
      document.getElementById('list').style.bottom = 0 + 'px';
      document.getElementById('list').style.left = 0 + 'px';
      document.getElementById('list').style.top = 'auto';
    
      document.getElementById('main').style.height = (h - 2) + 'px';
      document.getElementById('main').style.width = w + 'px';
    
      document.getElementById('vh').style.height = (BORDER_SIZE - 2) + 'px';
      document.getElementById('vh').style.width = (tw - BORDER_SIZE - 2) + 'px';
      document.getElementById('vh').style.top = (lh + HEADER_SIZE + 2) + 'px';
      document.getElementById('vh').style.left = 0 + 'px';
      document.getElementById('vh').style.right = 'auto';
      document.getElementById('vh').style.bottom = 'auto';
    
      document.getElementById('hh').style.height = (h) + 'px';
      document.getElementById('hh').style.width = (BORDER_SIZE - 2) + 'px';
      document.getElementById('hh').style.bottom = '0px';
      document.getElementById('hh').style.left = (tw - BORDER_SIZE - 2) + 'px';
    
      var ifr = document.getElementById('newsFullFrame');
      if(ifr) {
        ifr.style.width = (w - 0) + 'px';
        ifr.style.height = (h - IFRAME_FACTOR - BORDER_SIZE - 77) + 'px';
      }
      
      with(document.getElementById('newerNewsAvailable').style) {
        top = (lh + HEADER_SIZE + BORDER_SIZE + 10) + 'px';
        right = (w + 35) + 'px';
      }
    }
    */
  }
  
function createModalDialog(id, title, w, h, close, className) {
  var rv = document.createElement('div');
  rv.id = id;
  var ss = getWindowSize();
  with(rv.style) {
    display = 'none';
    position = 'absolute';
    width = w + 'px';
    height = h + 'px';
    left = Math.round((ss[0] - w) / 2) + 'px';
    top = Math.round((ss[1] - h) / 2) + 'px';
  }
  if(className) {
    rv.className = className;
  } else {
    rv.className = 'defaultDialog';
  }
  var html = '';
  
  if(title) {
    html += '<div style="background-color: White; color: Black; font-weight: bold; font-size: 14px; padding: 3px">' + title;
    if(close) {
      html += '<div style="position: absolute; right: 6px; top: 0px"><a href="javascript: hideModalDialog(\'' + id + '\'); destroyModalDialog(\'' + id + '\');">x</a></div>';   
    }
    html += '</div>';
  }
  html += '<div id="' + id + '_body' + '" style="padding: 6px;"></div>';
  
  rv.innerHTML = html;
  document.body.appendChild(rv);
}

function showModalDialog(id) {
  // The most stupid Firefox bug workaround... https://bugzilla.mozilla.org/show_bug.cgi?id=167801
  var elems = {a1: 'tree', a2: 'list', a3: 'main' };
  for( var i in  elems) {
    var el = document.getElementById(elems[i]);
    el.style.overflow = 'hidden';
    el.style.zIndex = 0;
  }
  
  document.getElementById('modalLayer').style.zIndex = '9';
  document.getElementById('modalLayer').style.display = 'block';
  document.getElementById(id).style.zIndex = '10';
  document.getElementById(id).style.display = 'block';
  
  var e = document.getElementById('error_log');
  if(e) {
    e.style.zIndex = 2;
  }
  
  KEYBOARD_ENABLED = false;
}

function hideModalDialog(id) {
  document.getElementById('modalLayer').style.display = 'none';
  var el = document.getElementById(id);
  if(el) {
    el.style.display = 'none';
  } else {
    alert('Trying to close non-existing dialog ' + id + '\n(Ignore this message)');
  }
  
  // The most stupid Firefox bug workaround... https://bugzilla.mozilla.org/show_bug.cgi?id=167801
  var elems = {a1: 'tree', a2: 'list', a3: 'main' };
  for(var i in  elems) {
    var el = document.getElementById(elems[i]);
    el.style.overflow = 'auto';
    el.style.zIndex = 0;
  }
  
  var e = document.getElementById('error_log');
  if(e) {
    e.style.zIndex = 2;
  }
  
  KEYBOARD_ENABLED = true;
}

function destroyModalDialog(id) {
  document.body.removeChild(document.getElementById(id));
}

function showBusyPane() {
  createModalDialog('busyPane', null, 300, 100, false, 'busyDialog');
  var e = document.getElementById('busyPane_body');
  e.innerHTML = '<p style="text-align: center"><br/><br/><img src="loading4.gif" align="absmiddle"/>&nbsp;&nbsp;' + MESSAGES['pleaseWait'] + '</p>';
  showModalDialog('busyPane');
}

function hideBusyPane() {
  hideModalDialog('busyPane');
  destroyModalDialog('busyPane');
}

function getElementPosition(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}