var dataClass = Class.create();

dataClass.prototype = {
/////////////////////////////////////
// %%an initializer 
/////////////////////////////////////
initialize: function(passedObjects){
},
/////////////////////////////////////////////////////////
// Function: --> GENERAL OBJECT HANDLER
// 
// purpose: to split all related data into associated data arrays
// input: obj --> the string object to be parsed
// input: theReturns --> array of unique object types 
////////////////////////////////////////////////////////
parseObjects: function(obj,theReturns){
  //split the obj and the returns strings into large arrays.
  obj = obj.split('@');
  theReturns = theReturns.split(',');

  //cut the objects from the dataGrabObjects array up into an array of active objects
  var Grps = theReturns.length;
  var Rets = obj.length;
  var Objs = Rets/Grps;

  //stop if the objs is not an interger
  var objMod = Objs % 1;
  if (objMod != 0) {
    alert("Critical Error: if the string of objects divided by the object fields is not an integer then you cannot parse the Data.  //the number of fish in each fishbowl must be the same//")
  }

  activeObjects = new Array()
  for(i=0;i<Objs;i++){
    thisObject = new Array();    
    for(j=0;j<Grps;j++){     
      thisObject[j] = obj[Grps*(i)+j];   
    }
  activeObjects[i] = thisObject;
  }
  return activeObjects;
},
////////////////////////////////////////////////////////
// Function: --> GENERAL Data Display
// 
// purpose: A Most General way to Display retrieved data
// input: activeObjects --> an array of unique dataObjects
// input: theReturns -->  for each object (as an array), its constituents
////////////////////////////////////////////////////////
objView: function(activeObjects,theReturns){
var Objs = activeObjects.length;
newLayout = new layoutClass();
newCss = new cssClass();
  for(i=0;i<Objs;i++){
    for(j=0;j<(theReturns.length);j++){  
      newLayout.addElement("div","dataTable"+i+j,"","body","");
      newCss.dimension('dataTable'+i+j,75,20,5);
      newCss.fontStyle('dataTable'+i+j,'times','10','','','black');
      newCss.position('dataTable'+i+j,'absolute',250+50*j,50+20*i);
      newCss.colorBorder('dataTable'+i+j,'','blue','1px solid black');
      $('dataTable'+i+j).innerHTML = activeObjects[i][j];
    }
  }
},
////////////////////////////////////////////////////////
// Function: --> GENERAL Object Return
// 
// purpose: A method to return a list of object names
////////////////////////////////////////////////////////
genReturnObjects: function(responseData,returnsData){
  var responseObjs = new Array();

  // check
  if(responseData && returnsData){
    var numObjs = Math.floor((responseData.length / returnsData.length));
  }
  else{
    numObjs = 0;
  }

  for(var objCount=0;objCount<numObjs;objCount++){
    var indexStart = objCount*returnsData.length;
    var retObj = new Object;
    for(var fieldCount=0;fieldCount<returnsData.length;fieldCount++){
      var jsLeft = "retObj." + returnsData[fieldCount];
      eval(jsLeft + "=''");
      var JS = "var field = " + jsLeft;
      eval(JS);
/* *SAVE**       
  field = "'" + this.responseData[fieldCount + indexStart] + "'"; 
*/
      field = responseData[fieldCount + indexStart]; 
      JS = jsLeft + "=field";
      eval(JS);
    }
    responseObjs[objCount] = retObj;
  }
  return(responseObjs);
},
////////////////////////////////////////////////////////
// Function: --> GENERAL object delete
// 
// purpose: A way to delete the global array of objects
// input: retObjs --> an array of objects that are within the scope of the workspace
////////////////////////////////////////////////////////
freeReturnObjects: function(retObjs){
  for(var i=0;i<retObjs.length;i++){  
    var retObj = retObjs[i];
    delete retObj;
  }
  delete retObjs;
},
////////////////////////////////////////////////////////
// Function: --> GENERAL Object Grouping
// 
// purpose: A Most General way to group together a set of objects.
// input: returnObjects --> an array of objects within the scope of the workspace
// input: field --> name of datastructure child to be appended to object set
////////////////////////////////////////////////////////       
groupObjects: function(returnObjects,field){
  var objectGroups = new Array();
  var boolDone = false;
  while(!boolDone){
    boolDone = true;
    for(var i=0;i<returnObjects.length;i++){
      if(returnObjects[i]){
        var JS = "returnObjects[i]." + field;

        var fieldValue = eval(JS);
        var groupObject = this.getGroupObject(objectGroups,fieldValue);

        if(!groupObject){
          groupObject = new Object;
          groupObject.objs = new Array();
          groupObject.fieldValue = fieldValue; 
          objectGroups[objectGroups.length] = groupObject;
        }
        groupObject.objs[groupObject.objs.length] = returnObjects[i];
        returnObjects[i] = null;
        boolDone = false;
      }
    }
  }
  delete returnObjects;
  return(objectGroups);
},  
////////////////////////////////////////////////////////
// Function: --> GENERAL delete group
// 
// purpose: A Most General way delete groups of objects.
// input: objectGroups --> an array of unique dataGroups
////////////////////////////////////////////////////////
freeObjectGroups: function(objectGroups){
  if(objectGroups){
    for(var i=0;i<objectGroups.length;i++){
      var grpObj = objectGroups[i];
      for(var j=0;j<grpObj.objs.length;j++){
        var obj = grpObj.objs[j];
        delete obj; 
      } 
      delete grpObj.objs;
      delete grpObj;
    }
    delete objectGroups;
  }
},
////////////////////////////////////////////////////////
// Function: --> retreive group of objects
// 
// purpose: A Most General way to Display retrieved data
// input: objectGroups --> an array of unique dataGroups
// input: fieldValue -->  particular fieldvalue of a group to retreive.
////////////////////////////////////////////////////////
getGroupObject: function(objectGroups,fieldValue){
  if(objectGroups){
    for(var i=0;i<objectGroups.length;i++){
      var grpObj = objectGroups[i];
      if(grpObj.fieldValue == fieldValue){
        return(grpObj);
      }
    }
  }
return(null);
}

}
