/**
 *	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);
}


/**
 *	Include a JS file with the specified filename
 *	and actively parse it. 
 *
 *	Usefull for including js files from within js 
 *	files - keeps the head nice & clean.
 *
 *	Credits to Michael Sharman for coming up with this :)
**/
function include (file) { 
	var script 		= document.createElement('script'); 
	script.src 		= file; 
	script.type 	= 'text/javascript'; 
	script.defer 	= true; 
	document.getElementsByTagName('head').item(0).appendChild(script); 
}


/**
 *	Assign a console variable for browsers without console logging 
 *	functionality. Doesn't actually do anything, but it prevents
 *	them from choking on the log calls.
**/
var console;
if (console == null) {
	console		  = function () {};
	console.log = function () {};
	console.warn = function () {};
}


/**
 *	Uppercase first letter.
**/
function ucfirst (str) {
    var 		f = str.charAt(0).toUpperCase();
    return  f + str.substr(1);
}


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');
} 
