$.fn.reverse = [].reverse;

$.extend($.expr[":"], {
	"containsNC": function(el, i, match, array) {
		return (el.textContent || el.innerText || "").toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
	}
});
$.extend($.validator.messages, {
	creditcard: "Invalid input.",
	digits: "Invalid input.",
	email: "Invalid input.",
	equalTo: "Inputs do not match.",
	required: "Input required.",
	url: "Invalid URL."
});

var oldAbort = XMLHttpRequest.prototype.abort;

XMLHttpRequest.prototype.abort = function() {
	jQuery.proxy(oldAbort, this)();
	if (jQuery.active-- === 1) jQuery.event.trigger("ajaxStop");
};

Array.prototype.forEach = function(callback, thisObj) {
	var scope = thisObj || window;
	for ( var i = 0, ii = this.length; i < ii; ++i)
		callback.call(scope, this[i], i, this);
};

Array.prototype.every = function(callback, thisObj) {
	var scope = thisObj || window;
	for ( var i = 0, ii = this.length; i < ii; ++i)
		if (!callback.call(scope, this[i], i, this)) return false;
	return true;
};

Array.prototype.some = function(callback, thisObj) {
	var scope = thisObj || window;
	for ( var i = 0, ii = this.length; i < ii; ++i)
		if (callback.call(scope, this[i], i, this)) return true;
	return false;
};

Array.prototype.map = function(callback, thisObj) {
	var scope = thisObj || window;
	var a = [];
	for ( var i = 0, ii = this.length; i < ii; ++i)
		a.push(callback.call(scope, this[i], i, this));
	return a;
};

Array.prototype.filter = function(callback, thisObj) {
	var scope = thisObj || window;
	var a = [];
	for ( var i = 0, ii = this.length; i < ii; ++i) {
		if (!callback.call(scope, this[i], i, this)) continue;
		a.push(this[i]);
	}
	return a;
};

Array.prototype.indexOf = function(el, start) {
	start = start || 0;
	for ( var i = start, ii = this.length; i < ii; ++i)
		if (this[i] === el) return i;
	return -1;
};

Array.prototype.lastIndexOf = function(el, start) {
	start = start || this.length;
	if (start >= this.length) start = this.length;
	if (start < 0) start = this.length + start;
	for ( var i = start; i >= 0; --i)
		if (this[i] === el) return i;
	return -1;
};

Array.forEach = function(object, callback, thisObj) {
	Array.prototype.forEach.call(object, callback, thisObj);
};

Array.map = function(object, callback, thisObj) {
	return Array.prototype.map.call(object, callback, thisObj);
};

Array.filter = function(object, callback, thisObj) {
	return Array.prototype.filter.call(object, callback, thisObj);
};

Array.indexOf = function(object, el, start) {
	return Array.prototype.indexOf.call(object, el, start);
};

Number.prototype.toCurrency = function(symbol) {
	return (symbol ? symbol : "$") + this.withCommas();
};

Number.prototype.toSigned = function() {
	return this > 0 ? "+" + this : this;
};

Number.prototype.withCommas = function() {
	var x = 6, y = parseFloat(this).toFixed(2).toString().reverse();
	while (x < y.length) {
		y = y.substring(0, x) + "," + y.substring(x);
		x += 4;
	}
	return y.reverse();
};

String.prototype.reverse = function() {
	return this.split("").reverse().join("");
};

function addslashes(str) {
	return (str + "").replace(/[\\"']/g, "\\$&").replace(/\u0000/g, "\\0");
}

function getPropertyCount(Obj) {
	var i = 0;
	for ( var property in Obj) {
		if (Obj.hasOwnProperty(property)) i++;
	};
	return i;
}

function getPropertyAtIndex(Obj, index) {
	var i = 0;
	for ( var property in Obj) {
		if (Obj.hasOwnProperty(property)) {
			if (i == index) return Obj[property];
			i++;
		}
	}
	return undefined;
}

function queryString(url) {
	var searchLocation = url.indexOf("?");
	if (searchLocation == -1) return [];
	
	function queryString(el) {
		el = el.split("=");
		return [el[0], el[1]];
	}
	
	return url.slice(searchLocation + 1).split("&").map(queryString);
}
