/**
 * JSONstring v 1.0
 * copyright 2006 Thomas Frank
 * 
 * This program is free software under the terms of the 
 * GNU General Public License version 2 as published by the Free 
 * Software Foundation. It is distributed without any warranty.
 * 
 * Based on Steve Yen's implementation:
 * http://trimpath.com/project/wiki/JsonLibrary
 */
JSONstring={compactOutput:true,includeProtos:false,includeFunctions:false,detectCirculars:false,restoreCirculars:true,make:function(a,b){this.restore=b;this.mem=[];this.pathMem=[];return this.toJsonStringArray(a).join('')},toObject:function(x){eval("this.myObj="+x);if(!this.restoreCirculars||!alert){return this.myObj};this.restoreCode=[];this.make(this.myObj,true);var r=this.restoreCode.join(";")+";";eval('r=r.replace(/\\W([0-9]{1,})(\\W)/g,"[$1]$2").replace(/\\.\\;/g,";")');eval(r);return this.myObj},toJsonStringArray:function(a,b){if(!b){this.path=[]};b=b||[];var u;switch(typeof a){case'object':this.lastObj=a;if(this.detectCirculars){var m=this.mem;var n=this.pathMem;for(var i=0;i<m.length;i++){if(a===m[i]){b.push('"JSONcircRef:'+n[i]+'"');return b}};m.push(a);n.push(this.path.join("."))};if(a){if(a.constructor==Array){b.push('[');for(var i=0;i<a.length;++i){this.path.push(i);if(i>0)b.push(this.compactOutput?',':',\n');this.toJsonStringArray(a[i],b);this.path.pop()}b.push(']');return b}else if(typeof a.toString!='undefined'){b.push('{');var c=true;for(var i in a){if(!this.includeProtos&&a[i]===a.constructor.prototype[i]){continue};this.path.push(i);var d=b.length;if(!c)b.push(this.compactOutput?',':',\n');this.toJsonStringArray(i,b);b.push(':');this.toJsonStringArray(a[i],b);if(b[b.length-1]==u)b.splice(d,b.length-d);else c=false;this.path.pop()}b.push('}');return b}return b}b.push('null');return b;case'unknown':case'undefined':case'function':b.push(this.includeFunctions?a:u);return b;case'string':if(this.restore&&a.indexOf("JSONcircRef:")==0){this.restoreCode.push('this.myObj.'+this.path.join(".")+"="+a.split("JSONcircRef:").join("this.myObj."))};b.push('"');a=a.replace(/\\/gi,"\\\\\\\\");a=a.replace(/\n/gi,"\\\\n");a=a.replace(/\r/gi,"\\\\r");a=a.replace(/\t/gi,"\\\\t");a=a.replace(/\"/gi,"\\\\\"");b.push(a);b.push('"');return b;default:b.push(String(a));return b}}};
