/*************************************************************/
/*   Key Down Event
/*************************************************************/
document.onkeydown = onKeyDown;
function onKeyDown()
{
	if (window.event) 
	{
		switch(window.event.keyCode)
		{
		case 8:
			{
				//disable backspace
				window.event.cancelBubble = true;
				window.event.returnValue = false;
			}
			break;
		case 13:
			{
				//disable ENTER
				window.event.cancelBubble = true;
				window.event.returnValue = false;
			}
			break;
		default:
			return true;
		}
		
		return false;
	}
  
	return true;
}

/*************************************************************/
/*   Mouse Down Event
/*************************************************************/
function whichElement(e)
{
   var targ
   if (!e) 
      var e = window.event
   if (e.target) 
      targ = e.target
   else if (e.srcElement) 
      targ = e.srcElement
   if (targ.nodeType == 3) 
      targ = targ.parentNode
   
   var type
   type = targ.type
   //alert("You clicked on a " + type + " element.")
   return type;
}

document.onmousedown = mouseDown;
function mouseDown() 
{
    // Disable right-click menu
    if (event.button==2 && whichElement(event) == 'text') 
    {
        document.oncontextmenu=new Function("return true;");
        return true;
    }
    else
    {
        document.oncontextmenu=new Function("return false;");
    
        isdrag = true;
        startDrag.x = window.event.clientX;
        startDrag.y = window.event.clientY;
        document.onmousemove=movemouse;
        
        return false; 
    }
}

/*************************************************************/
/*   Select Event
/*************************************************************/
//Disable select on page.
document.onselectstart=function(){return false;}

/*************************************************************/
/*   Mouse Move Event
/*************************************************************/
function movemouse(e)
{
  if (isdrag)
  {
      dx = window.event.clientX - startDrag.x;
      dy = window.event.clientY - startDrag.y;
      
      MoveTo(dx, dy);
      return false;
  }
  
  return false;
}

/*************************************************************/
/*   Mouse Up Event
/*************************************************************/
document.onmouseup=mouseUp

function mouseUp(e)
{
    if(isdrag)
    {
        isdrag=false;
    }
}

document.onmouseout=mouseUp

/*************************************************************/
/*   Global Gui Variables
/*************************************************************/
isdrag = false;
startDrag = new Object();startDrag.x=null; startDrag.y=null;
