/*--------
 * STRING
 *--------*/
if (!String.prototype.trim) {
	String.prototype.trim  = function() { return this.replace(/^\s+|\s+$/g,""); };
}
if (!String.prototype.ltrim) {
	String.prototype.ltrim = function() { return this.replace(/^\s+/,""); };
}
if (!String.prototype.rtrim) {
	String.prototype.rtrim = function() { return this.replace(/\s+$/,""); };
}

/*------
 * DATE
 *------*/
// return the number of days in a month
if (!Date.prototype.daysInMonth) {
	Date.prototype.daysInMonth = function(month, year) {
		return 32 - new Date(year, month, 32).getDate();
	};
}

// return the number value for the month
if (!Date.prototype.monthFromString) {
	Date.prototype.monthFromString = function(month) {
		switch(month.toLowerCase()) { 
			case "january":
			case "jan":
				return 0;
			case "february":
			case "feb":
				return 1;
			case "march":
			case "mar":
				return 2;
			case "april":
			case "apr":
				return 3;
			case "may":
				return 4;
			case "june":
			case "jun":
				return 5;
			case "july":
			case "jul":
				return 6;
			case "august":
			case "aug":
				return 7;
			case "september":
			case "sept":
				return 8;
			case "october":
			case "oct":
				return 9;
			case "november":
			case "nov":
				return 10;
			case "december":
			case "dec":
				return 11;
			default:
				return;
		}
	};
}


/*-------
 * ARRAY
 *-------*/
// remove duplicate values
if (!Array.prototype.unique) {	
	Array.prototype.unique = function() {
		// Array - remove duplicate values
	    for (i=0; i<this.length; i++) {
	        for (j=0; j<this.length-i; j++) {
	            if (this[i] == this[i+j+1]) {
	                this.splice(i+j+1, 1);
	                j--;
	            }
	        }
	    }
	    return this;
	};
}

// make sure values are numbers
if (!Array.prototype.valuesToInts) {	
	Array.prototype.valuesToInts = function() {
		var a = [],
			i,
			l = this.length;
		for (i=0; i<l; i++) {
			a.push(parseInt(this[i]));
		}
		return a;
	};
}

// make indexOf work with arrays
if (!Array.prototype.indexOf) {  
	Array.prototype.indexOf = function(searchElement /*, fromIndex */) {
		"use strict";

		if (this === void 0 || this === null)
			throw new TypeError();

		var t = Object(this);
		var len = t.length >>> 0;
		if (len === 0)
			return -1;

		var n = 0;
		if (arguments.length > 0)
		{
			n = Number(arguments[1]);
			if (n !== n) // shortcut for verifying if it's NaN
				n = 0;
			else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0))
				n = (n > 0 || -1) * Math.floor(Math.abs(n));
		}

		if (n >= len)
		  return -1;

		var k = n >= 0
				? n
				: Math.max(len - Math.abs(n), 0);

		for (; k < len; k++)
		{
			if (k in t && t[k] === searchElement)
				return k;
		}
		return -1;
	};
}
