/*----------------------------------------------------------
  Utility function and constants
  isIE:              true for InternetExplorer
  isNN4:             true for Netscape 4
  
  insideCoordinates: x,y coordinates of a mouse click
  attach:            find html object by its id
  stopPropagation:   Stops event to be forwarded to parent object
  getEvent:          gets an event (unify different behaviour IE and FF
  falsefunc: returns false
  
  
  @package NTP 
  @author Arnd Beyer, arnd.beyer@wmdata.fi
  @copyright WM-data Novo 2006
  @version $Id: utilities.php,v 1.0 2005/07/26 12:44:42 arnd Exp $
  ---------------------------------------------------------*/
var isIE = document.all ? true : false;
var isNN4 = document.layers ? true : false;



/*
* Returns the xy-Coordinates of a mouse click within an Object
*/
function insideCoordinates(ev, objectname){
    var mouse = new Point( ev.clientX, ev.clientY);
	var object = attach(objectname);
    for(var node = object; node; node = node.offsetParent) {
        mouse.x -= node.offsetLeft;
        mouse.y -= node.offsetTop;
    }
    
	if(document.body.scrollTop > 0 || document.body.scrollLeft >0 ) {
	    mouse.x += document.body.scrollLeft;
	    mouse.y +=  document.body.scrollTop;
    }else{
    	mouse.x += document.documentElement['scrollLeft'];
    	mouse.y += document.documentElement['scrollTop'];
    }
		    
	return mouse;
}


/*
* Returns document Object with the requested id 
*/
function attach(id) {
  var obj;
  
  if(isIE) 
    obj = document.all[id];
  else if(isNN4)
    obj = document.layers[id]; 
  else
    obj=document.getElementById(id);

  return obj;
}


/*
* Stop event from being forwarded to parent Object
*/
function stopPropagation(ev){
    if (ev.stopPropagation) 
    	ev.stopPropagation();       // DOM Level 2
    else 
    	ev.cancelBubble = true;   // IE
}

/*
* Eventhandling for IE and Other
*/
function getEvent(event) {
    if(!event) {
        return window.event; //IE
    }
    return event;
}

/*
* Returns false
* used to block cascading events
*/
function falsefunc() {
   return false; 
} 




