/*****************************************************************************
*
* Replaces a small group of characters in this string defined in the HTML
* 4.01 Special Characters Set with their Character Entity References.
*
* @summary             encode subset of HTML special characters
* @author              Stuart Wigley
* @author              Randolph Fielding
* @version             1.1, 08/04/03
* @interface           <code>String.htmlSpecialChars()</code>
* @return              a modified string
* @return              <code>null</code> if an exception is encountered
* @throws              IllegalArgumentException
*
*****************************************************************************/
String.prototype.htmlspecialchars = function() 
{
	var iStringLength = this.length;
	var sModifiedString = '';

	for (var i = 0; i < iStringLength; i++) {
		switch (this.charCodeAt(i)) {
			case 34 : sModifiedString += '&quot;'; break;
			case 38 : sModifiedString += '&amp;' ; break;
			case 39 : sModifiedString += '&#39;' ; break;
			case 60 : sModifiedString += '&lt;'  ; break;
			case 62 : sModifiedString += '&gt;'  ; break;
			default : sModifiedString += this.charAt(i);
		}
	}
	
	return sModifiedString;
}

/*****************************************************************************
*
* http://snipplr.com/view/561/add-event-listener/
*
*****************************************************************************/
function addListener(element, type, expression, bubbling)
{
	bubbling = bubbling || false;
	
	if(window.addEventListener)  // Standard
	{
		element.addEventListener(type, expression, bubbling);
		return true;
	} 
	else if(window.attachEvent) // IE
	{
		element.attachEvent('on' + type, expression);
		return true;
	} 
	else
	{
		return false;
	}
}

/*****************************************************************************
*
* http://www.somacon.com/p355.php
*
*****************************************************************************/
String.prototype.trim = function() 
{
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() 
{
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() 
{
	return this.replace(/\s+$/,"");
}