
function Parser(pObjects)
{
if (new String(pObjects)!="undefined"){
if (pObjects.join) {
this.values = pObjects; } else {
this.values = eval(pObjects); }
}
this.collectionCt = 0;
this.chars = new String(",][\'\"");
}
Parser.loaded = false;
Parser.prototype.changeChars=function(pString,pDebug){
if((isNaN(pString))&&(new String(pString)!="true")&&(new String(pString)!="false"))
{
var i,str=new String(pString);
var re=new RegExp(escape('\n'),"g");
str=str.replace(re,'\n');
for(i=0;i<this.chars.length;i++){ 
try{
re=new RegExp(escape(this.chars.charAt(i)),"g");
}catch(e){
debug("this.chars.charAt("+i+"): "+this.chars.charAt(i)
+"\ne: "+_objToStr([e])
,"_Parser_changeChars");
}
str=str.replace(re,this.chars.charAt(i));
}
return unescape(str);
} else {
return pString;
}
}
Parser.prototype.createInstance=function(pArr,pClass,pCollCt,p) {
if (pClass && pClass.substring){
pClass = window[pClass];
}
try {
var obj = new pClass();
} catch (e) {
alert("Parser error:\nnew Class() couldn't be initialized: "+pClass+"\n\ncreateInstances params:\n"
+"pSender: "+p[4]+"\npClass: "+p[1]+"\npCollCt: "+p[2]+"\ni:"+p[3]+"\npArray: "+_viewObj(p[0]));
}
if (pClass == Object) {
for (prop in pArr) { if(typeof pArr[prop]=="string"){
obj[prop]=this.changeChars(pArr[prop]);
}else{
obj[prop]=pArr[prop];
}
}
} else {
if (typeof pCollCt=="undefined") {
pCollCt = 0;
}
var j = 0;
for (prop in obj) { try {
if (pArr.length > j - 1) {
if (typeof obj[prop] != "function") {
if (typeof obj[prop] == "object"){ if(new String(pArr[j])!="undefined") {
obj[prop] = this.createInstances(pArr[j],pClass.colecao[pCollCt],0);
pCollCt++;
}
} else {
if(typeof pArr[j]=="string"){
obj[prop]=this.changeChars(pArr[j]);
}else{
obj[prop]=pArr[j];
}
}
j++;
}
}
} catch (e) {
}
}
}
return obj;
}
Parser.prototype.createInstances=function(pArray,pClass,pCollCt,pSender) {
var i,j,prop;
var obj = new Array();
if (typeof pCollCt=="undefined") {
pCollCt = 0;
}
if (pClass && pClass.substring){
pClass = window[pClass];
}
if (pArray.length==0) {
return obj;
}
var i=0;
do {
obj[i]=this.createInstance(pArray[i],pClass,pCollCt,[pArray,pClass,pCollCt,i,pSender]);
} while (++i < pArray.length);
return obj;
}
Parser.filterToSerialized=function(pStr) {
if((isNaN(pStr) && (pStr != "true") && (pStr != "false")) || (pStr == "")) {
pStr=new String(pStr).replace(/\"/g,escape("\""));
pStr=new String(pStr).replace(/\'/g,escape("\'")); pStr=new String(pStr).replace(/\n/g,"\\n");
pStr=new String(pStr).replace(/\f|\r/g,"");
return "\""+pStr+"\"";
}else{
return ""+pStr+"";
}
}
Parser.prototype.getString=function(pArray) {
var i,ct=0;
var str = "[";
for (i = 0; i < pArray.length; i++) {
str += "[";
ct=0;
for (prop in pArray[i]) {
if (typeof pArray[i][prop]!="function") {
if (typeof pArray[i][prop] == "object") {
str+=""+this.getString(pArray[i][prop])+",";
} else {
str+=""+pArray[i][prop] + ",";
}
ct++;
}
}
if(ct>0)
str = str.slice(0,str.length-1);
str += "],";
}
if(i>0)
str = str.slice(0,str.length-1);
str += "]";
return str;
}
Parser.getSerialized=function(pArray)
{
function getSerializedObj(pObj)
{
var ct=0,str="[";
for (prop in pObj)
{
if (typeof pObj[prop]!="function") {
if(typeof pObj[prop]=="object" && pObj[prop].join) {
if (pObj[prop].length==0) {
str+="[],";
}else {
str+=""+Parser.getSerialized(pObj[prop])+",";
}
}else{
str+=Parser.filterToSerialized(pObj[prop])+",";
}
ct++;
}
}
if(ct>0)
str = str.slice(0,str.length-1);
str += "]";
return str;
}
var i;
var str = "[";
if(pArray.length)
for (i = 0; i < pArray.length; i++)
{
str+=getSerializedObj(pArray[i])+",";
}
else 
str+=getSerializedObj(pArray);
if(i>0)
str = str.slice(0,str.length-1);
str += "]";
return str;
}
Parser.getSerializedObjectLiteral=function(pValue,pLevels){
if (pLevels == "undefined")
pLevels = -1; 
var str="";
if (typeof pValue != "function") { if ((typeof pValue == "object" && !!pValue) && (typeof pValue.length != "undefined") && (!pValue.substring)) { str+="[";
try {
for (var i=0;i<pValue.length;i++) {
if (pLevels==0) {
}else{
str+=Parser.getSerializedObjectLiteral(pValue[i],pLevels-1)+"";
}
if (i<pValue.length-1) {
str+=","
}
}
} catch (e) {
str+="\"Not an array\"";
}
str+="]"
} else if (typeof pValue == "object" && !!pValue && (!pValue.substring)){ str+="{";
try {
for (var prop in pValue) {
if (pLevels==0) {
}else{
str+=""+prop+": "+Parser.getSerializedObjectLiteral(pValue[prop],pLevels-1);
}
str+=","
}
str = str.slice(0,str.length-1);
} catch (e) {
str+="x: \"Not an object\"";
}
str+="}";
} else{ str+=Parser.filterToSerialized(pValue);
}
}
return str;
}
Parser.getString=Parser.prototype.getString;
