/*
if("aa".replace(/\w/g,function(){return arguments[1]+" "})!=="0 1 "){
String.prototype.replace=function(replace){return function(reg,func){
	String.prototype.__replace__=replace;
	if(func.constructor!==Function)
		var r=this.__replace__(reg,func);
	else {
		function getMatches(reg,pos,a) {
			function io() {
				var a=reg.indexOf("(",pos),b=a;
				while(a>0&&reg.charAt(--a)==="\\"){};
				pos=b!==-1?b+1:b;
				return (b-a)%2===1?1:0;
			};
			do{a+=io()}while(pos!==-1);
			return a;
		};
		var p=-1,i=getMatches(""+reg,0,0),r="",args=[],matches=this.match(reg);
		while(i)args[--i]='"$'+(i+1)+'"';
		if(!args.length)r="matches[i],(p=this.indexOf(matches[i++],p+1)),this";
		else		r="matches[i],"+args.join(",")+",(p=this.indexOf(matches[i++],p+1)),this";
		r=eval('["'+this.__replace__(/(\\|"|')/g,'\\$1').__replace__(reg,'",func('+r+'),"').__replace__(/\r/g,'\\r').__replace__(/\n/g,'\\n')+'"].join("")');
	};
	delete String.prototype.__replace__;
	return r;
}}(String.prototype.replace)};
*/

(function(){
  var default_replace = String.prototype.replace;
  String.prototype.my_replace = function(search,replace){
	// replace is not function
	if(typeof replace != "function"){
		return default_replace.apply(this,arguments)
	}
	var str = "" + this;
	var callback = replace;
	// search string is not RegExp
	if(!(search instanceof RegExp)){
		var idx = str.indexOf(search);
		return (
			idx == -1 ? str :
			default_replace.apply(str,[search,callback(search, idx, str)])
		)
	}
	var reg = search;
	var result = [];
	var lastidx = reg.lastIndex;
	var re;
	while((re = reg.exec(str)) != null){
		var idx  = re.index;
		var args = re.concat(idx, str);
		result.push(
			str.slice(lastidx,idx),
			callback.apply(null,args).toString()
		);
		if(!reg.global){
			lastidx += RegExp.lastMatch.length;
			break
		}else{
			lastidx = reg.lastIndex;
		}
	}
	result.push(str.slice(lastidx));
	return result.join("")
  }
})();

(function ($) {
    var m = {
            '\b': '\\b',
            '\t': '\\t',
            '\n': '\\n',
            '\f': '\\f',
            '\r': '\\r',
            '"' : '\\"',
            '\\': '\\\\'
        },
        s = {
            'array': function (x) {
                var a = ['['], b, f, i, l = x.length, v;
                for (i = 0; i < l; i += 1) {
                    v = x[i];
                    f = s[typeof v];
                    if (f) {
                        v = f(v);
                        if (typeof v == 'string') {
                            if (b) {
                                a[a.length] = ',';
                            }
                            a[a.length] = v;
                            b = true;
                        }
                    }
                }
                a[a.length] = ']';
                return a.join('');
            },
            'boolean': function (x) {
                return String(x);
            },
            'null': function (x) {
                return "null";
            },
            'number': function (x) {
                return isFinite(x) ? String(x) : 'null';
            },
            'object': function (x) {
                if (x) {
                    if (x instanceof Array) {
                        return s.array(x);
                    }
                    var a = ['{'], b, f, i, v;
                    for (i in x) {
                        v = x[i];
                        f = s[typeof v];
                        if (f) {
                            v = f(v);
                            if (typeof v == 'string') {
                                if (b) {
                                    a[a.length] = ',';
                                }
                                a.push(s.string(i), ':', v);
                                b = true;
                            }
                        }
                    }
                    a[a.length] = '}';
                    return a.join('');
                }
                return 'null';
            },
            'string': function (x) {
                if (/["\\\x00-\x1f]/.test(x)) {
                   
                   x = x.my_replace(/([\x00-\x1f\\"])/g, function(a, b) {
                        var c = m[b];
                        if (c) {
                            return c;
                        }
                        c = b.charCodeAt();
                        if (c < 32)
                                return '';

                        return '\\u00' +
                            Math.floor(c / 16).toString(16) +
                            (c % 16).toString(16);
                    });
                    

                }
                return '"' + x + '"';
            }
        };

	$.toJSON = function(v) {
		var f = isNaN(v) ? s[typeof v] : s['number'];
		if (f) return f(v);
	};
	
	$.parseJSON = function(v, safe) {
		if (safe === undefined) safe = $.parseJSON.safe;
		if (safe && !/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.test(v))
			return undefined;
		return eval('('+v+')');
	};
	
	$.parseJSON.safe = false;

})(jQuery);
