/**
 *	Extends the original JS array with an extra function "removeItems".
 *	This method is able to remove one or more element from an array.
 *
 *	@param Array itemsToRemove: The array, wich contains the items to remove.
 *
 */
Array.prototype.removeItems = function(itemsToRemove) {

    if (!/Array/.test(itemsToRemove.constructor)) {
        itemsToRemove = [ itemsToRemove ];
    }

    var j;
    for (var i = 0; i < itemsToRemove.length; i++) {
        j = 0;
        while (j < this.length) {
            if (this[j] == itemsToRemove[i]) {
                this.splice(j, 1);
            } else {
                j++;
            }
        }
    }
}

/**
 * Returns a string with the first character capitalized, if that character is alphabetic.
 * @return {String} The string with the first character capitalized
 */
String.prototype.ucFirst = function() 
{
    return this.substr(0, 1).toUpperCase() + this.substr(1);
}

/**
 *	Extends the original JS array with an extra function "inArray".
 *	This method is able to decide if an element is in an array, or not.
 *
 *	@param Mixed value: The value, what we're looking for.
 *	
 *	@return Bool: True if it's in, else otherwise. 
 */
Array.prototype.inArray = function (value) {
	
	var i;
	
	for (i = 0; i < this.length; i++) 
	{
		// Matches identical (===), not just similar (==).
		if (this[i] === value) 
		{
			return true;
		}
	}
	
	return false;
};

/**
 *	Extends the original JS array with an extra function "inArray".
 *	This method is able to find an element in an array.
 *
 *	@param Mixed value: The value, what we're looking for.
 *
 *	@return Int: The index value of the position. It'll returns -1, if the value is not in the array.  
 *
 */
Array.prototype.search = function (value) {
	
	var i;
	
	for (i = 0; i < this.length; i++) 
	{
		// Matches identical (===), not just similar (==).
		if (this[i] === value) 
		{
			return i;
		}
	}
	
	return -1;
};

/**
 *	Extends the original JS String with an extra function "ltrim".
 *	This method is able to eliminate the whitespaces on the given string value's left side.
 *
 *	@param String value: The value we'd like to get trimmed.
 *
 *	@return String: The new, left-side trimmed string value.  
 *
 */
String.prototype.ltrim = function(chars)
{
    chars = chars || "\\s";
	return this.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

/**
 *	Extends the original JS String with an extra function "rtrim".
 *	This method is able to eliminate the whitespaces on the given string value's right side.
 *
 *	@param String value: The value we'd like to get trimmed.
 *
 *	@return String: The new, right-side trimmed string value.  
 *
 */
String.prototype.rtrim = function(chars)
{
    chars = chars || "\\s";
	return this.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

/**
 *	Extends the original JS String with an extra function "trim".
 *	This method is able to eliminate the whitespaces the given string value's both sides.
 *
 *	@param String value: The value we'd like to get trimmed.
 *
 *	@return String: The new, fully trimmed string value.  
 *
 */
String.prototype.trim = function(chars)
{
	return this.ltrim(chars).rtrim(chars);
}

/**
 *	Creates a cookie using JavaScript.
 *
 *	@param String name: The name of the value.
 *	@param String value: The value to store.
 *	@param Int days: The number of days.
 *
 */
function createCookie(name, value, days) 
{
	var expires = "";
	
	if (days) 
	{
		var date = new Date();
		date.setTime(date.getTime()+(days * 24 * 60 * 60 * 1000));
		expires = "; expires=" + date.toGMTString();
	}
	
	document.cookie = name + "=" + value + expires + "; path=/";
}

/**
 *	Deletes a cookie using JavaScript.
 *
 *	@param String name: The name of the value.
 *
 */
function eraseCookie(name) 
{
	createCookie(name, "", -1);
}

/**
 *	Clones an arbitrary object. 
 *
 *	@param String name: The name of the value.
 *
 */
function clone(obj)
{
	if(obj == null || typeof(obj) != 'object')
	{
		return obj;
	}
	
	var temp = new obj.constructor(); // changed (twice)
	
	for(var key in obj)
	{
		temp[key] = clone(obj[key]);
	}
	   
	return temp;
}