if (typeof com == "undefined") {com = {};};
if (typeof com.parolemanager == "undefined") {com.parolemanager = {};};
if (typeof com.parolemanager.javascript == "undefined") {com.parolemanager.javascript = {};};

if (typeof com.parolemanager.javascript.Accounts == "undefined") {
 com.parolemanager.javascript.Accounts = function() {} 
 com.parolemanager.javascript.Accounts.prototype = new  com.oclib.javascript.lang.Root();

 com.parolemanager.javascript.Accounts.prototype.className = "Accounts"; 
 com.parolemanager.javascript.Accounts.prototype.classNamespace = "com.parolemanager.javascript.Accounts"; 
 com.parolemanager.javascript.Accounts.prototype.classCreated = "20070213"; 
 com.parolemanager.javascript.Accounts.prototype.classCreator = "http://www.parolemanager.com/"; 
 com.parolemanager.javascript.Accounts.prototype.classLocation = "http://www.parolemanager.com/library/com/parolemanager/javascript/Accounts.js"; 
 com.parolemanager.javascript.Accounts.prototype.classIndexLocation = "http://www.parolemanager.com/library/com/parolemanager/javascript/accounts/"; 
 com.parolemanager.javascript.Accounts.prototype.classVersion = "20070219"; 
 com.parolemanager.javascript.Accounts.prototype.classVersionLocation = "http://www.parolemanager.com/library/com/parolemanager/javascript/20070219/Accounts.js"; 
 com.parolemanager.javascript.Accounts.prototype.classVersionIndexLocation = "http://www.parolemanager.com/library/com/parolemanager/javascript/20070219/"; 

 com.parolemanager.javascript.Accounts.prototype.accounts = new Array();
 
 com.parolemanager.javascript.Accounts.prototype.addAccount = function (account) {
  if(this.mustTrace()) {this.getLog().println("Accounts.addAccountEncryptedName is runing...");};
  var inputLength = this.accounts.length;
  if(this.accounts.length < 2) {
   this.accounts[this.accounts.length] = account;
  } else {
   for(var i = 0; i < this.accounts.length; i++) {
    if(this.accounts[i].getAccountName() > account.getAccountName()) {
     for(var j = this.accounts.length-1; j >= i; j--) {
      this.accounts[j+1] = this.accounts[j];
	 };
     this.accounts[i] = account;
	 i = this.accounts.length;
	};
   };
  };
  if(inputLength == this.accounts.length) {
   this.accounts[this.accounts.length] = account;
  };
  return 1;
 };  
  
 com.parolemanager.javascript.Accounts.prototype.containAccountEncryptedName = function (accountEncryptedName) {
  if(this.mustTrace()) {this.getLog().println("Accounts.containAccountEncryptedName is runing...");};
  if(accountEncryptedName == "" 
	 || typeof this.getAccountByEncryptedName(accountEncryptedName) != "undefined") {
   return 1;
  } else {
   return -1;
  };
 };
  
 com.parolemanager.javascript.Accounts.prototype.deleteAccount = function (deleteAccount) {
  if(this.mustTrace()) {this.getLog().println("Accounts.deleteAccount is runing...");};
  var deleteEncryptedAccountName = deleteAccount.getEncryptedAccountName();
  var newAccounts = new Array();
  var offset = 0;
  for(var i = 0; i < this.accounts.length; i++) {
   if(deleteEncryptedAccountName != this.getAccountByIndex(i).getEncryptedAccountName()) {
	newAccounts[i+offset] = this.getAccountByIndex(i);
   } else {
    offset = -1;
   };
  };
  this.setAccounts(newAccounts);
  return 1;
 };  
  
 com.parolemanager.javascript.Accounts.prototype.editAccount = function (deletedAccountEncryptedName, account) {
  if(this.mustTrace()) {this.getLog().println("Accounts.editAccount is runing... for deletedAccountEncryptedName="+deletedAccountEncryptedName);};
  this.deleteAccount(this.getAccountByEncryptedName(deletedAccountEncryptedName));
  this.addAccount(account);
  return 1;
 };
  
 com.parolemanager.javascript.Accounts.prototype.getAccountByIndex = function (index) {return this.accounts[index];};
 
 com.parolemanager.javascript.Accounts.prototype.getAccountByEncryptedName = function (encryptedName) {
  if(this.mustTrace()) {this.getLog().println("Accounts.getAccountByEncryptedName is runing... for encryptedName="+encryptedName);};
  for(var i = 0; i < this.accounts.length; i++) {
   if(this.mustTrace()) {this.getLog().println("Accounts.getAccountByEncryptedName is runing... for this.getAccountByIndex(i).getEncryptedAccountName()="+this.getAccountByIndex(i).getEncryptedAccountName());};
   if(encryptedName == this.getAccountByIndex(i).getEncryptedAccountName()) {
    return this.getAccountByIndex(i);
   };
  };
  return;
 };
 
 com.parolemanager.javascript.Accounts.prototype.getAccounts = function () {return this.accounts;};
 
 com.parolemanager.javascript.Accounts.prototype.getCount = function () {return this.accounts.length;};
 
 com.parolemanager.javascript.Accounts.prototype.setAccounts = function (a) {
  this.accounts = new Array();
  this.accounts = a; 
  return 1;
 };
};
