// Partial Source: CodeLifter.com, for original drag window - modified to support multiple windows
// The rest created by Markavian 2005|08|05
// They told me "Do not remove this header"

isIE=document.all;
isNN=!document.all&&document.getElementById;
isN4=document.layers;
dragHot=false;
var windowElement="window1"; // default, overriden if multiple windows by each element in onmousedown
// Resizable window
var minWidth = 80; // width in pixels to prevent windows being underscaled
var minHeight = 60; // width in pixels to prevent windows being underscaled
var maxWidth = 0; // ignored if 0
var maxHeight = 0; // ignored if 0
// Pannable content
var minX = 0; // ignored if -1
var minY = 0; // ignored if -1
var maxX = -1; // checks against width as well
var maxY = -1; // checks against height as well

function setWindowElement(element) {
  windowElement = element;
}

function ddInit(e){
  topElement=isIE ? "BODY" : "HTML";
  whichElement=isIE ? document.all[windowElement] : document.getElementById(windowElement);  
  dragElement=isIE ? event.srcElement : e.target;  

	if (dragElement.className=="titleBar"){
		offsetx=isIE ? event.clientX : e.clientX;
		offsety=isIE ? event.clientY : e.clientY;
		nowX=parseInt(whichElement.style.left);
		nowY=parseInt(whichElement.style.top);
		ddEnabled=true;
		document.onmousemove=dd;
	} else
	if (dragElement.className=="resize") {
		offsetx=isIE ? event.clientX : e.clientX;
		offsety=isIE ? event.clientY : e.clientY;
		nowWidth=parseInt(whichElement.style.width);
		nowHeight=parseInt(whichElement.style.height);
		ddEnabled=true;
		document.onmousemove=dresize;
	} else
	if (dragElement.className=="pan") {
		offsetx=isIE ? event.clientX : e.clientX;
		offsety=isIE ? event.clientY : e.clientY;
		nowX=parseInt(whichElement.style.left);
		nowY=parseInt(whichElement.style.top);
		nowWidth=parseInt(whichElement.parentNode.offsetWidth);
		nowHeight=parseInt(whichElement.parentNode.offsetHeight);
		maxX = whichElement.scrollWidth;
		maxY = whichElement.scrollHeight;
		ddEnabled=true;
		document.onmousemove=dpan;
	}
	return false;
}

function dd(e) {
  if (!ddEnabled) return;
  whichElement.style.left=isIE ? nowX+event.clientX-offsetx : nowX+e.clientX-offsetx; 
  whichElement.style.top=isIE ? nowY+event.clientY-offsety : nowY+e.clientY-offsety;
  return false;  
}

function dpan(e) {
  if (!ddEnabled) return;
  newX = isIE ? nowX+event.clientX-offsetx : nowX+e.clientX-offsetx; 
  newY = isIE ? nowY+event.clientY-offsety : nowY+e.clientY-offsety;
	if(maxX != -1 && newX < nowWidth-maxX)  newX = nowWidth-maxX;
	if(maxY != -1 && newY < nowHeight-maxY) newY = nowHeight-maxY;
	if(minX != -1 && newX > minX) newX = minX;
	if(minY != -1 && newY > minY) newY = minY;
  whichElement.style.left = newX;
  whichElement.style.top = newY;
  return false;  
}

function dresize(e) {
  if (!ddEnabled) return;
	newWidth = isIE ? nowWidth+event.clientX-offsetx : nowWidth+e.clientX-offsetx; 
	newHeight = isIE ? nowHeight+event.clientY-offsety : nowHeight+e.clientY-offsety;
  if(maxWidth > 0 && newWidth > maxWidth) newWidth = maxWidth;
  if(maxHeight > 0 && newHeight > maxHeight) newHeight = maxHeight;
	if(newWidth < minWidth) newWidth = minWidth;
  if(newHeight < minHeight) newHeight = minHeight;
	whichElement.style.width = newWidth;
	whichElement.style.height = newHeight;
  return false;   
}

function ddN4(whatDog){
  if (!isN4) return;
  N4=eval(whatDog);
  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 (dragHot){
      N4.moveBy(e.x-N4x,e.y-N4y);
      return false;
    }
  }
  N4.onmouseup=function(){
    N4.releaseEvents(Event.MOUSEMOVE);
  }
}

function disableselect() {
	return false;
}

function hideDiv(element){
  if (isIE||isNN) document.getElementById(element).style.visibility="hidden";
  else if (isN4) document.getElementById(element).visibility="hide";
}

function showDiv(element){
  if (isIE||isNN) document.getElementById(element).style.visibility="visible";
  else if (isN4) document.getElementById(element).visibility="show";
}

document.onmousedown=ddInit;
document.onmouseup=Function("ddEnabled=false;");