
var MOVE_OBJ_tx;
var MOVE_OBJ_ty;
var Selected = null;
var OnMove = true; 

var MOVE_OBJ_RESIZE_POPUP = null;
var MOVE_OBJ_RESIZE_POPUP_H_ONLY = null;
var MOVE_OBJ_POPUP = null;
var MOVE_OBJ_POPUP_X_MIN  = 0 ; var MOVE_OBJ_POPUP_X_MAX  = 2000 ;
var MOVE_OBJ_POPUP_Y_MIN  = 0 ; var MOVE_OBJ_POPUP_Y_MAX  = 3000 ;
var MOVE_OBJ_MENU = null;
var MOVE_OBJ_MENU_X_MIN  = 0 ; var MOVE_OBJ_MENU_X_MAX  = 2000 ;
var MOVE_OBJ_MENU_Y_MIN  = 0 ; var MOVE_OBJ_MENU_Y_MAX  = 3000 ;
var MOVE_OBJ_IMG = null;
var MOVE_OBJ_SCROLL;
var CurrentCell;

function moveme_onmousedown(e)
{

var el = GetSrc(e);
try {
for (var i=0; i<6; i++) {
tmp = el.getAttribute("handlefor");
if (tmp != null)
break;
el = el.parentNode;
}
if (tmp == null)
return;
}
catch(exception) {
return;
}

var currentObj = (tmp == "self") ? el : document.getElementById(tmp);
if (currentObj == null)
return;


switch(currentObj.className)
{
case "MovePopup" :
MOVE_OBJ_POPUP = currentObj;
MOVE_OBJ_ty = e.clientY - getTopPos(MOVE_OBJ_POPUP);
MOVE_OBJ_tx = e.clientX - getLeftPos(MOVE_OBJ_POPUP);
OnMove = true;
return eventCancelDefault(e);

case "MoveMenu" :
MOVE_OBJ_MENU = currentObj;
MOVE_OBJ_ty = e.clientY - getTopPos(MOVE_OBJ_MENU);
MOVE_OBJ_tx = e.clientX - getLeftPos(MOVE_OBJ_MENU);
return eventCancelDefault(e);

case "scroll" :
MOVE_OBJ_SCROLL = currentObj;
MOVE_OBJ_SCROLL.scroll.BeginScroll(e.clientX, e.clientY, e.shiftKey || e.ctrlKey);
return eventCancelDefault(e);

case "MoveImgV" :
MOVE_OBJ_IMG = currentObj;
MOVE_OBJ_ty = e.clientY - getTopPos(MOVE_OBJ_IMG);
MOVE_OBJ_tx = e.clientX - getLeftPos(MOVE_OBJ_IMG);
return eventCancelDefault(e);

default :
if ( (MOVE_OBJ_POPUP != null) && (typeof(MOVE_OBJ_POPUP.BeginAction) != "undefined") )
MOVE_OBJ_POPUP.BeginAction();
if ( (MOVE_OBJ_RESIZE_POPUP != null) && (typeof(MOVE_OBJ_RESIZE_POPUP.BeginAction) != "undefined") )
MOVE_OBJ_RESIZE_POPUP.BeginAction();
if ( (MOVE_OBJ_RESIZE_POPUP_H_ONLY != null) && (typeof(MOVE_OBJ_RESIZE_POPUP_H_ONLY.BeginAction) != "undefined") )
MOVE_OBJ_RESIZE_POPUP_H_ONLY.BeginAction();

MOVE_OBJ_SCROLL = null;
MOVE_OBJ_POPUP = null;
CurrentCell = null;
}
}

function moveme_onmouseup(e)
{
if (MOVE_OBJ_SCROLL)
{
MOVE_OBJ_SCROLL.scroll.EndScroll();
MOVE_OBJ_SCROLL = null;
}

if (MOVE_OBJ_MENU)
{
MOVE_OBJ_MENU = null;
}

if (MOVE_OBJ_IMG)
{
MOVE_OBJ_IMG = null;
}

if (CurrentCell) {
CurrentCell = null;
ReleaseCell(e.clientX, e.clientY);
}

if(MOVE_OBJ_POPUP)
{
OnMove = false;
if (typeof(MOVE_OBJ_POPUP.EndAction) != "undefined")
MOVE_OBJ_POPUP.EndAction();
MOVE_OBJ_POPUP = null;
}

}

function moveme_onmousemove(e)
{
if (document.all) {
if (e.button == 0)
return;
}

if (MOVE_OBJ_SCROLL)
{
MOVE_OBJ_SCROLL.scroll.SetPosition(e.clientX, e.clientY);
return eventCancelDefault(e);
}

if (MOVE_OBJ_POPUP)
{
l = (e.clientX  - MOVE_OBJ_tx)
t = (e.clientY - MOVE_OBJ_ty)
MOVE_OBJ_POPUP.style.left	= l ;
MOVE_OBJ_POPUP.style.top	= t ;
}

if (MOVE_OBJ_IMG)
{
l = (e.clientX  - MOVE_OBJ_tx)
t = (e.clientY - MOVE_OBJ_ty)
MOVE_OBJ_IMG.style.left	= l ;
MOVE_OBJ_IMG.style.top	= t ;
}

if (MOVE_OBJ_MENU)
{
l = (e.clientX  - MOVE_OBJ_tx)
t = (e.clientY - MOVE_OBJ_ty)

MOVE_OBJ_MENU.style.left	= l ;
MOVE_OBJ_MENU.style.top	    = t ;
return eventCancelDefault(e);
}

if (CurrentCell)
MoveCell(e.clientX, e.clientY);
}


function moveme_onmouseover(e)
{

var el = GetSrc(e);
try {
for (var i=0; i<6; i++) {
tmp = el.getAttribute("handlefor");
if (tmp != null)
break;
el = el.parentNode;
}
if (tmp == null)
return;
}
catch(exception) {
return;
}

var currentObj = (tmp == "self") ? el : document.getElementById(tmp);
if (currentObj == null)
return;

switch(currentObj.className.subStr(0,9))
{
case "Anim_Rond" :
Show_Anim_Rond(e.clientX-18,e.clientY-18,event);
return eventCancelDefault(e);

default :

}
}

function eventHandler(evname, func, el) {

if (!el) el = document;

if (el.addEventListener) {
el.addEventListener(evname, func, false);
}
else if (el.attachEvent) {
el.attachEvent('on' + evname, func);
} else {
el['on'+evname] = func;
}
}

function GetSrc(evt) {
if (evt.srcElement)
return evt.srcElement;
return evt.target;
}

function eventCancelDefault(e) {
e.returnValue = false;
e.cancelBubble = true;
if (e.cancelable) e.preventDefault();
return false;
}

eventHandler('mousedown',moveme_onmousedown);
eventHandler('mouseup',moveme_onmouseup);
eventHandler('mousemove',moveme_onmousemove);

document.oncontextmenu = function (evt) {
if (evt == null) evt = window.event;
if ( (evt.ctrlKey) || (evt.shiftKey) )
return true;
return eventCancelDefault(evt);
};
