/**
*	Hook an object into an event, allowing objects to act as DOM multi event handlers
*
*	@access public
*	@param The object to act as the handler
*	@param The object method to handle the event
*	@return Returns a function to handle the event, by calling SyObj.SyMethod
*/
function SycuseHookObjEvent(SyObj, SyMethod)
{
	return (function (evt)
	{
		// IE compatible hack
		if (!evt)
			evt = window.event;

		return SyObj[SyMethod](evt, this);
	});
}




/**
*	Sycuse JS Event Handler
*
*	Abstraction layer to provide cross platform event handling
*
*	@access public
*	@deprecated
*/
function SycuseJSEvents(evt)
{
	this.event = evt;

	/**
	*	Stop event propagation, and prevent default action
	*
	*	@access public
	*	@return void
	*/
	this.haltEvent = function ()
	{
		if (window.event)
		{
			window.event.cancelBubble = true;
			window.event.returnValue = false;
		}

		if (this.event)
		{
			if (this.event.stopPropagation)
				this.event.stopPropagation();

			if (this.event.preventDefault)
				this.event.preventDefault();
		}
	}


	/**
	*	Return the element that fired the event
	*
	*	@access public
	*	@return element The element, or null if it cannot be retrieved
	*/
	this.getTarget = function ()
	{
		if (window.event && window.event.srcElement)
		{
			return window.event.srcElement;
		}

		if (this.event.target)
		{
			return this.event.target;
		}

		return null;
	}

}



/**
*	Add DOM event listener
*
*	@access public
*	@param obj DOM object to add event to
*	@param evtName Name of trigger event
*	@param fHandler Handler function
*	@param doCapt Bool, whether to capture event
*/
function SycuseAddEvent (obj, evtName, fHandler, doCapt)
{
	if (obj.addEventListener)
	{
		obj.addEventListener(evtName, fHandler, doCapt);
		return true;
	}
	else if (obj.attachEvent)
	{
		var r = obj.attachEvent("on"+evtName, fHandler);
		return r;
	}
	else
		return false;
}


/**
 * Determine whether a node's text content is entirely whitespace.
 * Courtesy of Mozilla Foundation; http://www.mozilla.org/docs/dom/technote/whitespace/
 */
function Sycuseis_all_ws( nod )
{
  // Use ECMA-262 Edition 3 String and RegExp features
  return !(/[^\t\n\r ]/.test(nod.data));
}

/**
 * Determine if a node should be ignored by the iterator functions.
 * Courtesy of Mozilla Foundation; http://www.mozilla.org/docs/dom/technote/whitespace/
 */

function Sycuseis_ignorable( nod )
{
  return ( nod.nodeType == 8) || // A comment node
         ( (nod.nodeType == 3) && Sycuseis_all_ws(nod) ); // a text node, all ws
}


/**
*	Wrapper for node.firstChild which ignores whitespace nodes
*	Courtesy of Mozilla Foundation; http://www.mozilla.org/docs/dom/technote/whitespace/
*/
function SycuseFirstChild( par )
{
	var res=par.firstChild;
	while (res) {
	if (!Sycuseis_ignorable(res)) return res;
	res = res.nextSibling;
	}
	return null;
}


// Courtesy of quirksmode.org
function SycuseWindowSize()
{
	var x,y;
	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}

	this.x = x;
	this.y = y;
}

SycuseWindowSize.prototype.getX = function () { return this.x; }
SycuseWindowSize.prototype.getY = function () { return this.y; }


/* For attaching confirmations to buttons */
function SycuseAttachConfirm(elemid)
{
	var elem;
	if (elem = $(elemid))
		elem.onclick = SycuseHookObjEvent(this, "validate");

}

SycuseAttachConfirm.prototype.validate = function (evt, elem)
{
	return confirm("Are you sure you want to delete this item?");
}

function SycuseBind(what, obj, handler, event)
{
	if (event == undefined)
		event = "click";

	Event.observe(what, event, handler.bindAsEventListener(obj), false);
}
