if (!Array.prototype.forEach)
{
  Array.prototype.forEach = function(fun /*, thisp*/)
  {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();

    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this)
        fun.call(thisp, this[i], i, this);
    }
  };
}

if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}

Array.prototype.find = function(isAMatch) {
    var matches = [];
    for (i = 0; i < this.length; i++) {
        if (isAMatch(this[i])) {
            matches.push(this[i]);
        }
    }
    return matches;
}

Array.prototype.findFirst = function(isAMatch) {
    for (i = 0; i < this.length; i++) {
        if (isAMatch(this[i])) {
             return  this[i];
        }
    }
    return null;
}


Array.prototype.first = function() {
    return this[0];
}

Array.prototype.rest = function() {
    return this.slice(1);
}

Array.prototype.isEmpty = function() {
    return this.length == 0;
}


if(!String.prototype.format)
	String.prototype.format = function(){
		var param = arguments.length === 1 && typeof(arguments[0]) == "object" ? arguments[0] : arguments;
		var i = 0, result = "";
		for(var s; (s = this.indexOf("{", i)) !== -1;){
			result += this.slice(i, s);
			if(this[s+1] === "{"){
				i = s + 2;
				result += "{";
				continue;
			}
			var i = this.indexOf("}", s + 1);
			if(i === -1)
				throw "incorrect format: {0}".format(this);
			result += param[this.slice(s + 1, i)];
		}
		return result + this.slice(i);
	}
if(!String.format)
	String.format = function(str){
		return String.prototype.format.apply(str, Array.prototype.slice.call(arguments, 1));
	}

        
function YTLFormat (v) {

    var nStr = parseInt(v);
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
  //  x2 = x.length > 1 ? '.' + x[1] : '';
  //  var rgx = /(\d+)(\d{3})/;
  //  while (rgx.test(x1)) {
 //     x1 = x1.replace(rgx, '$1' + ',' + '$2');
 //   }
    return x1;
}

function log(message) {
    if(console)
        console.log(message);
}
        