var x,y;
var tx, ty;
var isDrag=false;
var firefox=document.getElementById&&!document.all;
document.onmousemove=mouseMove;
document.onmousedown=selectMouse;
document.onmouseup=function(){
isDrag=false;
}
function selectMouse(e)
{
if (firefox){
//verify that user clicked the 'titlebar' element
var p=e.target;
if (p.attributes['id'] && p.attributes['id'].value=="titlebar"){
isDrag=true;
x=e.clientX;
y=e.clientY;
//get the widget coordinates from the root, 'widget1' element
tx=parseInt(document.getElementById('widget1').style.left);
ty=parseInt(document.getElementById('widget1').style.top);
}
}
else{ //IE
//verify that user clicked the 'titlebar' element
var p=event.srcElement;
if (p.attributes['id'] && p.attributes['id'].value=="titlebar"){
isDrag=true;
x=event.clientX;
y=event.clientY;
//get the widget coordinates from the root, 'widget1' element
tx=parseInt(document.getElementById('widget1').style.left);
ty=parseInt(document.getElementById('widget1').style.top);
}
}
}
function mouseMove(e)
{
if (isDrag) //only move the box if the user is dragging it
{
var box=document.getElementById("widget1");
if (firefox){
box.style.left = e.clientX + (tx - x);
box.style.top = e.clientY + (ty - y);
}
else{ //IE
box.style.left = event.clientX + (tx - x);
box.style.top = event.clientY + (ty - y);
}
}
}