/**************************************

  deskDo -- todolist on your desktop

  (c) 2005 Pixel-Apes.

 **************************************/


function deskDoEditable_todoAdd( desk, id ) 
{ 
  this.desk = desk; 
  this.id = id;

  this.preset = "default";

  this.defaultColor = wakaDoTodoAdd.prototype.welcomeColor;
  this.defaultText  = wakaDoTodoAdd.prototype.welcomeText;

  this.itemNo = deskDoEditable_todoAdd.prototype.static_nextNo();
}

deskDoEditable_todoAdd.prototype = new deskDoEditable_todo();
deskDoEditable_todoAdd.prototype.constructor = 
deskDoEditable_todoAdd;

deskDoEditable_todoAdd.prototype._setReadonly = function (value)
{
  var selector = document.getElementById( this.id + "_selector" );
  if (value) selector.style.display = "none";
  else       selector.style.display = "block";
}

// no view mode at all!
deskDoEditable_todoAdd.prototype.doView       = function() 
{
  this.t.value = "";
  this.t.blur();
  this.t.style.color = this._token.welcomeColor;
  this.t.value = this._token.welcomeText;
  if (this.desk.currentEditable == this) this.desk.currentEditable = false;
}
deskDoEditable_todoAdd.prototype.drawViewMode = function() {}
deskDoEditable_todoAdd.prototype.removeIfCompleted = function () {};


// will be set to >0 after adding todo
deskDoEditable_todoAdd.prototype._autoFocus = 0;


deskDoEditable_todoAdd.prototype._textareaHeight = 15;
deskDoEditable_todoAdd.prototype.textareaHeight = 15;
deskDoEditable_todoAdd.prototype.rebindWrapper = function()
{
  this._bindEditMode();
  this.t.style.color = this._token.welcomeColor; 
 
  this.wrapper = document.getElementById(this.id + "_wrapper");
  this.wrapper._editable = this;

  if (deskDoEditable_todoAdd.prototype._autoFocus > 0)
  {
    deskDoEditable_todoAdd.prototype._autoFocus--;
    if (deskDoEditable_todoAdd.prototype._autoFocus == 0)
    {
      this.doSelect();
      this.t.focus();
      this.t.focus();
    }
  }

  return this.wrapper;
}

deskDoEditable_todoAdd.prototype.onTextareaFocus = function () 
{ 
  if (this.desk.currentEditable)
    this.desk.currentEditable.doSave();

  if (this.desk.selectedEditable) this.desk.selectedEditable.doDeselect();
  this.desk.currentEditable = this;
  this.doSelect();
  this.t.value = "";
  this.t.style.color = this._token.textColor;

  // do not expire selection if start editing
  window.clearTimeout( this.expireTimeout );
}
deskDoEditable_todoAdd.prototype.onTextareaBlur = function () 
{  
  this.desk.onSurfaceClick();
}

deskDoEditable_todoAdd.prototype._needRebuildHierarchy = function()
{ 
  if (this._token.addContent) return true;
  else                        return false;
}


deskDoEditable_todoAdd.prototype.__super__importDataFromEditMode = deskDoEditable_todoAdd.prototype.importDataFromEditMode;
deskDoEditable_todoAdd.prototype.importDataFromEditMode = function()
{
  var result = this.__super__importDataFromEditMode();

  if (this.t.value.replace(/\s+/g,"") !== "") 
  {
    deskDoEditable_todoAdd.prototype._autoFocus = this.itemNo;
    this._token.addContent = true;
    this.dontSave = false;
  }
  else
  {
    // add nothing
    this._token.addContent = false;
    this.dontSave = true;
    this.wrapper.innerHTML = ""+this.wrapper.innerHTML;
    this.rebindWrapper();
  }

  this.t.style.color = this._token.welcomeColor;
  this.t.value = this._token.welcomeText;
  return result;
}

deskDoEditable_todoAdd.prototype.__super__doSave = deskDoEditable_todo.prototype.doSave;
deskDoEditable_todoAdd.prototype.doSave = function()
{
  this.__super__doSave();
  this._editMode = true;
}




// static add todo count --------------------------------------------------------------
deskDoEditable_todoAdd.prototype.static_itemCount = 0;
deskDoEditable_todoAdd.prototype.static_nextNo = function() 
{
  deskDoEditable_todoAdd.prototype.static_itemCount++;
  return deskDoEditable_todoAdd.prototype.static_itemCount;
}
deskDoEditable_todoAdd.prototype.static_nextNoReset = function() 
{
  deskDoEditable_todoAdd.prototype.static_itemCount = 0;
}
// static add todo count --------------------------------------------------------------

