var binresizeframe = false;

function onmove(e) {
e = (window.event)?event:e;
mx = e.clientX;
my = e.clientY;

var local = e.srcElement || e.target;
if (local != null) {
	if (local.getAttribute("vseparator") != null && local.getAttribute("vseparator") != undefined) {
		local.style.cursor="w-resize";
	} else {
		if (local.style.cursor=="w-resize") local.style.cursor = "default";
	}
}

if (binresizeframe) {
var inst = getcontainer(local);
if (inst != null) {
if (inst.getAttribute("noresize") == "true") {
  local.style.cursor = "default";
}
}
}


return false;
}

var destinationObj;		
var isMoving = false;
var isResizing = false;
var isSeparate = false;

function onmoveend(e) {
    if (isMoving) {
      writegadgets();
	  var container = destinationObj;
	  if (container != null && container != undefined) {
		  var attr = container.getAttribute('onmoveend');
		  if (attr != null && attr != undefined) {
			    try {
			        //var ret = eval(gscripttarget);
			        var newScript = document.createElement('script');
			   	 newScript.type = "text/javascript";
			   	attr = attr.toString().replace("/\n/g","").replace("/\r/g","");
			   	newScript.text = attr;
			   	 document.body.appendChild(newScript);
			   	 if (window.execScript) try { eval('anonymous();') } catch (e) { }; 
			       } catch (e) { alert(e.message); }
			       }
	  };
	  isMoving = false;
	}
	if (isResizing) {
	  writegadgets();
	  var container = lastresizeobj;
	  if (container != null && container != undefined) {
	    var ascript = document.getElementById('scriptpart_' + container.id);
	    if (ascript != null && ascript != undefined) {
	      var vscript = ascript.getAttribute("resizescript");
	      if (vscript != null && vscript != undefined) {
	        eval(vscript);
		  }
	    }
	  }
	  isResizing = false;
	}
	if (isSeparate) {
		
		  var container = getcontainer(destinationObj);
		  if (container != null && container != undefined) {
		    var ascript = document.getElementById('scriptpart_' + container.id);
		    if (ascript != null && ascript != undefined) {
		      var vscript = ascript.getAttribute("resizescript");
		      if (vscript != null && vscript != undefined) {
		        eval(vscript);
			  }
		    }
		  }
		
		isSeparate = false;
	}
	return false;
}

var dx, dy;
var mx, my;
var ow, oh;
var pw, ph;
var lastresizeobj = null;
var sepleft = null;
var sepright = null;

function onmovestart(e) {
e = (window.event)?event:e;
mx = e.clientX;
my = e.clientY;
//var dest = getposobj(e.clientX+Math.max(document.body.scrollLeft,document.documentElement.scrollLeft),e.clientY+Math.max(document.body.scrollTop,document.documentElement.scrollTop));
//		if(dest!==false && dest!='append' && dest!='self'){



destinationObj = e.srcElement || e.target; 


if (isResizing) {
dx = mx;
dy = my;
destinationObj = getcontainer(destinationObj);

if (destinationObj.getAttribute("noresize") == "true") return;

lastresizeobj = destinationObj;

ow = destinationObj.offsetWidth;
oh = destinationObj.offsetHeight;

pw = document.getElementById(destinationObj.id + "_content").offsetWidth;
ph = document.getElementById(destinationObj.id + "_content").offsetHeight;

      var iwidth = destinationObj.getAttribute("initialWidth");
      if (iwidth == null || iwidth == undefined) {
	    destinationObj.setAttribute("initialWidth", destinationObj.offsetWidth);
      }

} else {
var container = getcontainer(destinationObj);
if (container != null) {
	var noz = destinationObj.getAttribute("nozindex");
	if (noz != "true") {
		resetZIndex();
		container.style.zIndex = "100";
	}
}

if (destinationObj.getAttribute("movable") != null && destinationObj.getAttribute("movable") != undefined) {

destinationObj = document.getElementById(destinationObj.getAttribute("movable"));
if (destinationObj == null || destinationObj == undefined) return;
/*if (destinationObj != null) {
//  destinationObj.style.filter = "Alpha(opacity=100, finishopacity=100, style=2)"; 
  destinationObj.style.zIndex = "100";
} */


isMoving = true;

var container = destinationObj;
if (container != null && container != undefined) {
	  var attr = container.getAttribute('onmovestart');
	  if (attr != null && attr != undefined) {
		    try {
		        //var ret = eval(gscripttarget);
		        var newScript = document.createElement('script');
		   	 newScript.type = "text/javascript";
		   	 newScript.text = attr;
		   	 document.body.appendChild(newScript);
		       } catch (e) { alert(e.message); }	  }
};


dx = mx - destinationObj.offsetLeft;
dy = my - destinationObj.offsetTop;

} else if (destinationObj.getAttribute("vseparator") != null && destinationObj.getAttribute("vseparator") != undefined) {
	
	
	var sepb = bounds(destinationObj.id,null,true);
	
	destinationObj = document.getElementById(destinationObj.getAttribute("vseparator"));
	if (destinationObj == null || destinationObj == undefined) return;
	var leftside = null; var rightside = null;
	var mee = destinationObj;
    for (var i = 0; i < mee.childNodes.length; i++) {
    	var node = mee.childNodes[i];
    	if (node.id != null && node.id != undefined) {
    	  var b = bounds(node.id,null,true);
    	  if (b[2] > 0 && b[3] > 0) {
//    		  alert("pruefe " + node.id + " " + b[0] + "top " + b[1] + "left " + b[2] + "width " + b[3] + "height");
    	  if (sepb[1] - (b[1] + b[2]) == 0) {
    		  leftside = node;
    	  } else
    	  if (b[1] - (sepb[1] + sepb[2]) >= 0) {
    		  rightside = node;
    	  }
    	  }
    	  if (leftside != null && rightside != null) break;
    	}
    }

    
    
    if (leftside != null && rightside != null)
    {
    	sepleft = leftside;
    	sepright = rightside;
        isSeparate = true;
    } else {
    	sepleft = null;
    	sepright = null;
    }

    dx = mx;
    dy = my;

}


}

setTimeout('domove();',10);

document.body.focus();
return false;
			
}

function domove() {
	if (isMoving) {
	    var oL = destinationObj.offsetLeft;
	    var oT = destinationObj.offsetTop;
	    var oW = destinationObj.offsetWidth;
	    var oH = destinationObj.offsetHeight;

        var minusPos = (mx - oL);
        
        
        var mL = destinationObj.style.marginLeft.toString().replace("px","");
        var mT = destinationObj.style.marginTop.toString().replace("px","");

        var facX = mx - (dx) ;
        var facY = my - (dy);
        
        if (mx < 0 || my < 0) isMoving = false;
        
        if (facX < 0) facX = "0";
        if (facY < 0) facY = "0";
        
        destinationObj.style.marginLeft = "0px";
        destinationObj.style.marginTop = "0px";
        destinationObj.style.left = facX - mL;
        destinationObj.style.top = facY - mT;
        setTimeout('domove();',10);
	} else
	if (isResizing) {       
        var posi = document.getElementById(destinationObj.id + "_content");
        
        var facw = ow - (dx - mx);
        var fach = oh - (dy - my);
        
        if (facw < destinationObj.getAttribute("initialWidth")) facw = destinationObj.getAttribute("initialWidth");
        if (fach < 10) fach = 10;
        
        
        destinationObj.style.width = facw;
        destinationObj.style.height = fach;
        posi.style.width = pw - (ow - facw);
        posi.style.height = ph - (oh - fach);
        //destinationObj.style.height = my - oT;

/*        var oow = destinationObj.style.width.toString().replace("px","");
        var ooh = destinationObj.style.height.toString().replace("px","");

        var mW = posi.style.width.toString().replace("px","");
        var mH = posi.style.height.toString().replace("px","");
*/
        
        
        
        
        //posi.style.width = posi.style.width + (oldw - destinationObj.style.width);      
        
               
        setTimeout('domove();',10);
	} else
		if (isSeparate) {
			
	        var facX = mx - (dx) ;
	        var facY = my - (dy);
	        
	        var bl = bounds(sepleft.id,null,true);
	        var br = bounds(sepright.id,null,true);
	        var bfr = bounds(destinationObj.id,null,true); 
	        
	        
	        
	        if (bl[2] + facX - bfr[1] > 30 && (bfr[1] + bfr[2] - (br[1] + facX)) > 30) {
	        	sepleft.style.width = bl[2] + facX + "px";
	        	sepright.style.width = br[2] - facX + "px";
	        }
	        
	        
	        
	        dx = mx;
	        dy = my;
			
			setTimeout('domove();',10);
		}
	
}

function doclick(e) {
  return true;
}

function init_script() {
		document.body.onmousemove = onmove;
		document.body.onmouseup = onmoveend;
		document.body.onmousedown = onmovestart;
		document.body.onclick = doclick;
}

