$.JSON = {
	isArray:function(v){
		return v&&typeof v.length=="number"&&typeof v.splice=="function";
	},
	isDate:function(v){
		return v&&typeof v.getFullYear=="function";
	},
	encodeArray:function(o){
		var a = ["["], b, i, l = o.length, v;
		for (i = 0; i < l; i += 1) {
			v = o[i];
			switch (typeof v) {
				case "undefined":
				case "function":
				case "unknown":
				break;
				default:
					if (b) {
						a.push(',');
					}
					a.push(v === null ? "null" : this.encode(v));
					b = true;
			}
		}
		a.push("]");
		return a.join("");
	},
	pad:function(n) {
		return n < 10 ? "0" + n : n;
	},
	encodeDate:function(o){
		return '"' + o.getFullYear() + "-" +
				this.pad(o.getMonth() + 1) + "-" +
				this.pad(o.getDate()) + "T" +
				this.pad(o.getHours()) + ":" +
				this.pad(o.getMinutes()) + ":" +
				this.pad(o.getSeconds()) + '"';
	},
	encodeString:function(s){
		if (/["\\\x00-\x1f]/.test(s)) {
			return '"' + s.replace(/([\x00-\x1f\\"])/g, function(a, b) {
			var c = m[b];
					if(c){
						return c;
					}
					c = b.charCodeAt();
					return "\\u00" +
						Math.floor(c / 16).toString(16) +
						(c % 16).toString(16);
				}) + '"';
			}
			return '"' + s + '"';
	},
	decode:function(o){
		return eval('('+o+')');
	},
	encode:function(o){
		var useHasOwn = !!{}.hasOwnProperty;
		if(typeof o == "undefined" || o === null){
			return "null";
		}else if(this.isArray(o)){
			return this.encodeArray(o);
		}else if(this.isDate(o)){
			return this.encodeDate(o);
		}else if(typeof o == "string"){
			return this.encodeString(o);
		}else if(typeof o == "number"){
			return isFinite(o) ? String(o) : "null";
		}else if(typeof o == "boolean"){
			return String(o);
		}else {
			var a = ["{"], b, i, v;
			for (i in o) {
				if(!useHasOwn || o.hasOwnProperty(i)) {
					v = o[i];
					switch (typeof v) {
						case "undefined":
						case "function":
						case "unknown":
						break;
						default:
							if(b){
								a.push(',');
							}
							a.push(this.encode(i), ":",v === null ? "null" : this.encode(v));
							b = true;
					}
				}
			}
			a.push("}");
			return a.join("");
		}
	}
};
