﻿
var binresizeframe = false;

function onmove(e) {
e = (window.event)?event:e;
mx = e.clientX;
my = e.clientY;

if (binresizeframe) {
var local = e.srcElement || e.target;
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;

function onmoveend(e) {
    if (isMoving) {
      writegadgets();
	  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;
	}
	return false;
}

var dx, dy;
var mx, my;
var ow, oh;
var pw, ph;
var lastresizeobj = 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 {
resetZIndex();

var container = getcontainer(destinationObj);

if (container != null) container.style.zIndex = "100";

if (destinationObj.getAttribute("movable") == null) return
if (destinationObj.getAttribute("movable") == "") return;

destinationObj = document.getElementById(destinationObj.getAttribute("movable"));

/*if (destinationObj != null) {
//  destinationObj.style.filter = "Alpha(opacity=100, finishopacity=100, style=2)"; 
  destinationObj.style.zIndex = "100";
} */

isMoving = true;
dx = mx - destinationObj.offsetLeft;
dy = my - destinationObj.offsetTop;
}
setTimeout('domove();',10);
document.body.focus();
return false;
			
}

function domove() {
	if (isMoving) {
	    mx = mx.toString().replace("px","");
	    var oL = destinationObj.offsetLeft.toString().replace("px","");
	    var oT = destinationObj.offsetTop.toString().replace("px","");
	    var oW = destinationObj.offsetWidth.toString().replace("px","");
	    var oH = destinationObj.offsetHeight.toString().replace("px","");       
	    var cW = document.body.clientWidth.toString().replace("px","");
	    if (cW == "0") {
	    	cW = document.body.offsetWidth.toString().replace("px","");
	    }
        
        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; return; }
        
        if (facX < 0) facX = "0";
        if (facY < 0) facY = "0";
        
        destinationObj.style.marginLeft = "0px";
        destinationObj.style.marginTop = "0px";
        destinationObj.style.left = (facX - mL) + "px";
        destinationObj.style.top = (facY - mT) + "px";
        setTimeout('domove();',10);
	}
	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);
	}
	
}

function doclick(e) {
  return true;
}

function init_script() {
	if(window.addEventListener) { // Mozilla, Netscape, Firefox
		document.addEventListener("mousemove", onmove, false);
		document.addEventListener("mouseup", onmoveend, false);
		document.addEventListener("mousedown", onmovestart, false);
		document.addEventListener("click", doclick, false);
	} else { // IE
		document.attachEvent("mousemove", onmove);
		document.attachEvent("mouseup", onmoveend);
		document.attachEvent("mousedown", onmovestart);
		document.attachEvent("click", doclick);
	}
}