Array.prototype.in_array = function(p_val) {
	for(var i = 0, l = this.length; i < l; i++) {
		if(this[i] == p_val) {
			return true;
		}
	}
	return false;
}
Array.prototype.removeAt=function(index){
 if(Number(index)<0 || this.length==0) 
  return false;
 for(var i=index;i<this.length;i++){
  this[i]=this[i+1];
 }
 this.length--;
};
Array.prototype.remove=function(value){
 for(var i = 0; i < this.length; i++)
  if (this[i]==value){
   this.removeAt(i);
   i--;
  }
};
/**
 * Checks if element is in collection
 * @param value Element to check
 * @param {function} {optional} compare Function to compare source value to array elements
 * @return True if element was found
 */
Array.prototype.contains=function(value, compare){
 return this.indexOf(value, compare) != -1;
};

Array.prototype.indexOf = function(value, compare){
    if (!compare) {
        compare = function(v1, v2){
            return v1 == v2;
        };
    }
 for(var i = 0; i < this.length; i++)
  if (compare(this[i], value))
   return i;
 return -1;
};

function formatDate(formatDate, formatString)
{
  		var yyyy = formatDate.getFullYear();
  		var yy = yyyy.toString().substring(2);
  		var m = formatDate.getMonth() + 1;
  		var mm = m < 10 ? "0" + m : m;
  		var d = formatDate.getDate();
 		var dd = d < 10 ? "0" + d : d;

  		var h = formatDate.getHours();
		var hh = h < 10 ? "0" + h : h;
		var n = formatDate.getMinutes();
		var nn = n < 10 ? "0" + n : n;
		var s = formatDate.getSeconds();
		var ss = s < 10 ? "0" + s : s;

		formatString = formatString.replace(/yyyy/i, yyyy);
		formatString = formatString.replace(/yy/i, yy);
		formatString = formatString.replace(/mm/i, mm);
		formatString = formatString.replace(/m/i, m);
		formatString = formatString.replace(/dd/i, dd);
		formatString = formatString.replace(/d/i, d);
		formatString = formatString.replace(/hh/i, hh);
		formatString = formatString.replace(/h/i, h);
		formatString = formatString.replace(/nn/i, nn);
		formatString = formatString.replace(/n/i, n);
		formatString = formatString.replace(/ss/i, ss);
		formatString = formatString.replace(/s/i, s);

		return formatString;
}

Date.prototype.format = function(format)
{
	return formatDate(this, format);
}

