/*
 * Copyright 2006 OST-SYSTEMS. All rights reserved.
 */

function KeyStorage() {
  this.storage = new Array();
  this.lastId = 0;
    
  this.get = function(group, id, key) {
    var idStorage = this.storage[group];
    if (idStorage != null) {
      var keyStorage = idStorage[id];
      if (keyStorage != null) {
        return keyStorage[key];
      }
    }    
    return null;  
  }
  
  this.getAll = function(group, id) {
    var idStorage = this.storage[group];
    if (idStorage != null) {
      return idStorage[id];
    }    
    return null;  
  }
  
  this.getNewId = function() {
    var id = new Date().getTime();
    if (id <= this.lastId) {
      id = this.lastId + 1;
    }
    this.lastId = id;
    return id;
  }
  
}

KeyStorage.prototype.saveAll = function() {
}
  
KeyStorage.prototype.getStorage = function() {
    return this.storage;
  }
  
KeyStorage.prototype.setStorage = function(array) {
    this.storage = array;
  }
  
KeyStorage.prototype.store = function(group, id, key, value) {
    var idStorage = this.storage[group];
    if (idStorage == null) {
      idStorage = new Array();
      this.storage[group] = idStorage;
    }
    var keyStorage = idStorage[id];
    if (keyStorage == null) {
      keyStorage = new Array();
      idStorage[id] = keyStorage;
    }
    keyStorage[key] = value;
  }

KeyStorage.prototype.removeAll = function(group, id) {
    if (id == null) {
      this.storage[group] = null;
    }
    var idStorage = this.storage[group];
    if (idStorage != null) {
      idStorage[id] = null;
    }  
  }
  
KeyStorage.prototype.removeComplete = function() {
    this.storage = new Array();
  }
  
  
