function User(cwsObj) {
  this.userName = "default";
  this.firstName = "";
  this.lastName = "";
  this.password = "";
  this.kloNum = 0;
  this.kloStatus = new Array();
  this.courseSuspendData = "";
  this.subKloStatus = new Array();
  this.kloLocation = new Array();
  this.kloSuspendData = new Array();
  this.subKloLocation = new Array();
  this.courseParams = new Array();
  this.courseParamKeys = new Array();
  this.courseStatus = "incomplete";
  this.courseScore = -1;
  this.courseMasteryScore = -1;
  this.sessionTime = 0;
  this.objectives = new KartaHash("objectives");
  this.interactions = new KartaHash("interactions");

  this.getUserId = function() {
    return "KU_" + cwsObj.courseId + "_" + this.userName;
  }

  this.setUserData = function(dataList) {
    if (dataList != "") {
      var data = dataList.split(",");
      if (data.length >= 6) {
        this.firstName = data[0];
        this.lastName = data[1];
        this.password = data[2];
        if (!isNaN(data[3]))  {
          this.sessionTime = parseInt(data[3],10);
        }
        this.courseStatus = data[4];
        if (!isNaN(data[5]))  {
          this.courseScore = parseInt(data[5],10);
        }
        if (data.length == 7) {
          if (!isNaN(data[6]))  {
            this.kloNum = parseInt(data[6],10);
          }
        }
      }
    }
    return true;
  }

  this.setKloStatus = function(dataList)  {
    var data = dataList.split(",");
    if (data.length == this.kloStatus.length) {
      for (s=0;s<data.length;s++) {
        this.kloStatus[s] = data[s];
      }
      return true;
    }
    return false;
  }

  this.setCourseSuspendData = function(data)  {
    this.courseSuspendData = CwsUtil.convertStringFromHex(data);
    return true;
  }

  this.setKloLocation = function(dataList,displayType)  {
    var data = dataList.split(",");
    if (data.length == this.kloLocation[displayType].length)  {
      for (k=0;k<data.length;k++) {
        this.kloLocation[displayType][k] = data[k];
      }
      return true;
    }
    return false;
  }

  this.setKloSuspendData = function(dataList,displayType)  {
    var data = dataList.split(",");
    if (data.length == this.kloSuspendData[displayType].length)  {
      for (p=0;p<data.length;p++) {
        this.kloSuspendData[displayType][p] = CwsUtil.convertStringFromHex(data[p]);
      }
      return true;
    }
    return false;
  }

  this.setSubKloStatus = function(dataList,displayType) {
    var data = dataList.split("|");
    if (data.length == cwsObj.kloIds.length)  {
      for (y=0;y<cwsObj.kloIds.length;y++)  {
        var subData = data[y].split(",");
        if (cwsObj.maxSubKloNum > 0)  {
          if (subData.length == cwsObj.maxSubKloNum)  {
            for (o=0;o<subData.length;o++)  {
              this.subKloStatus[displayType][y][o] = subData[o];
            }
          }
          else  {
            return false;
          }
        }
      }
      return true;
    }
    return false;
  }

  this.setSubKloLocation = function(dataList,displayType)  {
    var data = dataList.split("|");
    if (data.length == cwsObj.kloIds.length)  {
      for (q=0;q<cwsObj.kloIds.length;q++)  {
        var subData = data[q].split(",");
        if (cwsObj.maxSubKloNum > 0)  {
          if (subData.length == cwsObj.maxSubKloNum) {
            for (j=0;j<subData.length;j++)  {
              this.subKloLocation[displayType][q][j] = subData[j];
            }
          }
          else  {
            return false;
          }
        }
      }
      return true;
    }
    return false;
  }

  this.setCourseParams = function(dataList,displayType) {
    var data = dataList.split(",");
    for (q=0;q<data.length;q++) {
      var dataItem = CwsUtil.convertStringFromHex(data[q]);
      var keyValue = dataItem.split("=");
      if (keyValue.length == 2) {
        var key = keyValue[0];
        var value = keyValue[1];
        this.courseParamKeys[displayType][this.courseParamKeys[displayType].length] = key;
        this.courseParams[displayType][key] = value;
      }
    }
  }

  this.getUserDataList = function()  {
    return this.firstName + "," + this.lastName + "," + this.password + "," + this.sessionTime + "," + this.courseStatus + "," + this.courseScore + "," + this.kloNum;
  }

  this.getKloStatusList = function()  {
    var list = "";
    for (w=0;w<this.kloStatus.length;w++) {
      list += this.kloStatus[w];
      if (w<this.kloStatus.length-1)  {
        list += ",";
      }
    }
    return list;
  }

  this.getCourseSuspendDataList = function()  {
    return CwsUtil.convertStringToHex(this.courseSuspendData);
  }

  this.getKloLocationList = function(displayType) {
    var list = "";
    for (j=0;j<this.kloLocation[displayType].length;j++)  {
      list += this.kloLocation[displayType][j];
      if (j<this.kloLocation[displayType].length-1) {
        list += ",";
      }
    }
    return list;
  }

  this.getKloSuspendDataList = function(displayType) {
    var list = "";
    for (j=0;j<this.kloSuspendData[displayType].length;j++)  {
      list += CwsUtil.convertStringToHex(this.kloSuspendData[displayType][j]);
      if (j<this.kloSuspendData[displayType].length-1) {
        list += ",";
      }
    }
    return list;
  }

  this.getSubKloStatusList = function(displayType)  {
    return this.getSubList(this.subKloStatus,displayType);
  }

  this.getSubKloLocationList = function(displayType)  {
    return this.getSubList(this.subKloLocation,displayType);
  }

  this.getSubKloStatusListByKlo = function(displayType,kloNum)  {
    return this.getSubListByKlo(this.subKloStatus,displayType,kloNum);
  }

  this.getSubKloLocationListByKlo = function(displayType,kloNum)  {
    return this.getSubListByKlo(this.subKloLocation,displayType,kloNum);
  }

  this.getSubList = function(dataArray,displayType) {
    var list = "";
    for (j=0;j<dataArray[displayType].length;j++)  {
      list += this.getSubListByKlo(dataArray,displayType,j);
      if (j<dataArray[displayType].length-1) {
        list += "|";
      }
    }
    return list;
  }

  this.getSubListByKlo = function(dataArray,displayType,kloNum)  {
    var list = "";
    for (t=0;t<dataArray[displayType][kloNum].length;t++) {
      list += dataArray[displayType][kloNum][t];
      if (t<dataArray[displayType][kloNum].length-1)  {
        list += ",";
      }
    }
    return list;
  }

  this.generateDefaultSubList = function(value) {
    var list = "";
    for (j=0;j<cwsObj.maxSubKloNum;j++) {
      list += value;
      if (j<cwsObj.maxSubKloNum-1)  {
        list += ",";
      }
    }
    return list;
  }

  this.getCourseParamList = function(displayType) {
    var list = "";
    for (j=0;j<this.courseParamKeys[displayType].length;j++)  {
      var key = this.courseParamKeys[displayType][j];
      var value = this.courseParams[displayType][this.courseParamKeys[displayType][j]];
      list += CwsUtil.convertStringToHex(key + "=" + value);
      if (j<this.courseParamKeys[displayType].length-1) {
        list += ",";
      }
    }
    return list;
  }

  //initialize Klo & subKlo arrays
  for (i=0;i<cwsObj.maxDisplayTypeNum;i++)  {
    this.kloLocation[i] = new Array();
    this.kloSuspendData[i] = new Array();
    this.subKloStatus[i] = new Array();
    this.subKloLocation[i] = new Array();
    this.courseParams[i] = new Array();
    this.courseParamKeys[i] = new Array();
    for (y=0;y<cwsObj.kloIds.length;y++)  {
      this.kloStatus[y] = "n";
      this.kloLocation[i][y] = 0;
      this.kloSuspendData[i][y] = "";
      this.subKloStatus[i][y] = new Array();
      this.subKloLocation[i][y] = new Array();
      for (j=0;j<cwsObj.maxSubKloNum;j++) {
        this.subKloStatus[i][y][j] = "n";
        this.subKloLocation[i][y][j] = 0;
      }
    }
  }
}

function Objective(id) {
  this.id = id;
  this.minScore = -1;
  this.maxScore = -1;
  this.score = -1;
  this.status = "";
}

function Interaction(id) {
  this.id = id;
  this.objectiveIds = new Array();
  this.kloNum = "";
  this.interactionType = "";
  this.weighting = "";
  this.correctReponses = new Array();
  this.studentResponse = "";
  this.result = "";
  this.time = "";
  this.latency = "";
}

