/**
 *	Shortcut to document.getElementById(element) - 
 *	instead you can now use $('element'); for the 
 *	same result.
**/
function $ (elementId) {
	return document.getElementById(elementId);
}


/**
 *	Clear all existing elements (children) from the 
 *	given element.
**/
function clearElement (element) {
	if(!element.hasChildNodes())
		return true;
	while(element.firstChild)
		element.removeChild(element.firstChild);
}


/**
 *	Find the real position of the given object - 
 *	code [s]stolen[/s] borrowed from QuirksMode.
**/
function getPosition (obj) {
	var curleft = curtop = 0;
	do {
		if (obj.offsetLeft)
			curleft += obj.offsetLeft;
		if (obj.offsetTop)
			curtop 	+= obj.offsetTop;
	} while (obj = obj.offsetParent);
	return[curleft, curtop];
}


/**
 *	Get an input field with a specific name and value.
 *
 *	@param	variable	String		Name of the variable.
 *	@param	value			String		Value of the variable.
 *	@return	DOM Obj		Input DOM element with given name and value.
**/
function getInput (variable, value) {
	var	element			=	document.createElement('input');
	element.name		=	variable;
	element.value		=	value;
	return element;
}
		

/**
 *	Obtain the source DOM element of an event - takes into
 *	account browser incompatibilities.
**/
function getEventSource (event) {
	event 			=	event || window.event;
	
	if (!event.originalTarget)
		return event.srcElement;
	else
		return event.originalTarget;
}


/**
 *	Set the opacity for a given block in a cross-browser 
 *	way - tested to work for IE, FF & Chrome.
**/
function setOpacity (element, opacity) {
	element.style.filter 					= "alpha(opacity=" + opacity + ")";
	element.style.MozOpacity			=	opacity / 100;
	element.style.opacity 				=	opacity / 100;
}

// Dutch names for weekdays.
var dutchWeekDays = ['Maandag', 'Dinsdag', 'Woensdag', 'Donderdag', 'Vrijdag', 'Zaterdag', 'Zondag'];

/**
 *	Browser info
**/
var browserInfo = new Object();

browserInfo.chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;

/**
 *	Deselect any and all text that might be selected at the moment
 *	of calling. Most effective in combination with a short timeout.
**/
function deselectAll (event) {
	if (document.selection)
		document.selection.empty();
  else
		window.getSelection().removeAllRanges();
}	

/**
 *	Transform newlines (such as in text input) into linebreak tags.
**/
function nl2br (str, is_xhtml) {
	  var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '' : '<br>';
     return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');
} 

/**
 *  String trim() method.
**/
String.prototype.trim = function () {
    return this.replace(/^\s*([\S\s]*?)\s*$/, '$1');
}
