// generated from config/js/yui-traction-docmgt.properties on Fri Jul 30 17:03:23 EDT 2010

//------------------------------------------------------------------------
// yui-traction-docmgt.AbstractDetailsRow

YAHOO.namespace("traction");

YAHOO.traction.AbstractDetailsRow = function(afterTR, colspan, options) {
  
  this.TR = null;
  
  this.TD = null;
  
  this.colspan = colspan ? colspan : 1;
  
  this.setOptions(options);
  this.build();
  this.refresh();
  afterTR.parentNode.insertBefore(this.TR, afterTR.nextSibling);
};
YAHOO.traction.AbstractDetailsRow.prototype.setOptions = function(options) {
  this.options = Object.extend({
    closeButton: true,
    spacerColumn: true
	}, options || {});
};

YAHOO.traction.AbstractDetailsRow.prototype.destroy = function() {
  YAHOO.util.Event.purgeElement(this.TR);
  this.TR.parentNode.removeChild(this.TR);
  this.TR = null;
  this.TD = null;
  this.options = null;
};

YAHOO.traction.AbstractDetailsRow.prototype.build = function() {
  this.TR = document.createElement("TR");
  this.TR.className = "trex";
  this.TR.style.display = "none";
  if (this.options.spacerColumn) {
    var spacer = document.createElement("TD");
    spacer.innerHTML = " ";
    this.TR.appendChild(spacer);
  }
  this.TD = document.createElement("TD");
  this.TD.colSpan = this.colspan;
  this.TR.appendChild(this.TD);
  if (this.options.closeButton) {
    var div = document.createElement("DIV");
    div.className = "x fr";
    var A = document.createElement("A");
    A.href = "javascript:void(0)";
    Events.attach(A, Events.Click, this, this.hide);
    div.appendChild(A);
    this.TD.appendChild(div);
  }
  this.tabs = document.createElement("DIV");
  this.tabs.className = "tabs";
  this.TD.appendChild(this.tabs);
  this.info = document.createElement("DIV");
  this.TD.appendChild(this.info);
  this.desc = document.createElement("DIV");
  this.desc.className = "desc clear";
  this.info.appendChild(this.desc);
  this.status = document.createElement("DIV");
  this.status.className = "status";
  this.TD.appendChild(this.status);
  this.form = document.createElement("FORM");
  this.form.className = "buttons";
  this.TD.appendChild(this.form);
};
YAHOO.traction.AbstractDetailsRow.prototype.show = function() {
  Util.on(this.TR);
};
YAHOO.traction.AbstractDetailsRow.prototype.isVisible = function() {
  return Util.isOn(this.TR);
};
YAHOO.traction.AbstractDetailsRow.prototype.hide = function() {
  Util.off(this.TR);
};
YAHOO.traction.AbstractDetailsRow.prototype.refresh = function() {};

//------------------------------------------------------------------------
// yui-traction-docmgt.AbstractDialog

YAHOO.namespace("traction");
YAHOO.traction.AbstractDialog = function(id, options) {
  this.id = id;
  
  this.DIV = null;
  
  this.t = null;
   
  this.th3 = null;
  
  this.c = null;
  
  this.help = null;
  
  this.container = null;
  
  this.form = null;
  
  this.b = null;
  this.setOptions(options);
  this.build();
};

YAHOO.traction.AbstractDialog.prototype.setOptions = function(options) {
  this.options = Object.extend({
    className: "dialog",
    dialogClassName: "yui-skin-sam",
    formAction: FORM_ACTION_READ_WRITE,
    formMethod: "POST",
    formEnctype: "",
    tClassName: "hd", //"t",
    cClassName: "bd", //"c",
    bClassName: "ft", //"b",
    helpText: "",
    helpKey: "",
    zIndex: 1000000,
    title: "",
    width: "600px",
    close: true,
    fireDOMchangedOnDisplay: true,
    hiddens: {}
    }, options || {});
};
YAHOO.traction.AbstractDialog.prototype.setDialogClassName = function() {
  YAHOO.util.Dom.addClass(this.DIV.parentNode, this.options.dialogClassName);    
};

YAHOO.traction.AbstractDialog.prototype.setTitle = function(title) {
  this.options.title = title;
  this.th3.innerHTML = title;
};
YAHOO.traction.AbstractDialog.prototype.show = function() {
  if (this.options.fireDOMchangedOnDisplay) {
    if (Events && Events.fireCustom) Events.fireCustom(Events.DOMchanged);
  }
  this.panel.center();
  this.panel.show();
};
YAHOO.traction.AbstractDialog.prototype.isVisible = function() {
  return this.panel.cfg.getProperty("visible");
};
YAHOO.traction.AbstractDialog.prototype.hide = function() {
  this.panel.hide();
};
YAHOO.traction.AbstractDialog.prototype.close = function() {
  this.hide();
};
YAHOO.traction.AbstractDialog.prototype.build = function() {
  this.DIV = document.createElement("DIV");
  this.DIV.className = this.options.className;
  this.DIV.style.visibility = "hidden";
  if (this.id) this.DIV.id = this.id;
  if (this.options.zIndex) {
    this.DIV.style.zIndex = this.options.zIndex;
  }
  this.t = document.createElement("DIV");
  this.t.className = this.options.tClassName;
  this.DIV.appendChild(this.t);
  var tdiv = document.createElement("DIV");
  this.t.appendChild(tdiv);
  this.th3 = document.createElement("span"); //("h3");
  this.th3.innerHTML = this.options.title;
  tdiv.appendChild(this.th3);
  this.c = document.createElement("DIV");
  this.c.className = this.options.cClassName;
  this.DIV.appendChild(this.c);
  var ci = document.createElement("DIV");
  ci.className = "ci";
  this.c.appendChild(ci);
  this.container = document.createElement("DIV");
  this.container.className = "container";
  if (this.options.helpText) {
    this.help = document.createElement("DIV");
    this.help.className = "help";
    var p = document.createElement("P");
    p.appendChild(document.createTextNode(this.options.helpText));
    this.help.appendChild(p);
    if (this.options.helpKey) {
    }
    this.container.appendChild(this.help);
  }
  ci.appendChild(this.container);
  var form = document.createElement("FORM");
  form.onsubmit = function() { return false; };
  form.setAttribute("action", this.options.formAction);
  form.setAttribute("method", this.options.formMethod);
  if (this.options.formEnctype) {
    form.setAttribute("enctype", this.options.formEnctype);
  }
  this.form = form;
  this.container.appendChild(this.form);
  var hiddens = this.options.hiddens;
  if (hiddens) {
    for (var k in hiddens) {
      if (hiddens.hasOwnProperty(k)) {
	var h = Form.newInput(k);
	h.type = "hidden";
	h.value = hiddens[k];
	this.form.appendChild(h);
      }
    }
  }
  this.addControls();
  document.body.insertBefore(this.DIV, document.body.firstChild);
  var keys =  new YAHOO.util.KeyListener(document, { keys: 27 },   // esc                            
					 { fn: this.hide, 
					     scope: this, 
					     correctScope: true } );
  this.panel = new YAHOO.widget.Panel(this.DIV, 
				      { modal: true, 
					  width: this.options.width,
					  draggable: true, 
					  close: this.options.close,
					  constraintoviewport: true,
					  underlay: "none", 
					  keylisteners: keys });
  if (this.options.zIndex) {
    this.panel.cfg.setProperty("zIndex", this.options.zIndex);
  }
  this.panel.render();
  this.setDialogClassName();
  this.panel.center();  
};

YAHOO.traction.AbstractDialog.prototype.center = function() {
  this.panel.center();  
};

YAHOO.traction.AbstractDialog.prototype.addControls = function() {};

//------------------------------------------------------------------------
// yui-traction-docmgt.AbstractRow

YAHOO.namespace("traction");
YAHOO.traction.AbstractRow = function(data, index) {
  
  this.TR = null;
  
  this.index = index;  
  
  this.data = data;
  
  this.state = 0;
  
  this.glowTimer = null;
  this.glowAnim = null;
  this.fadeTimer = null; 
  this.fadeAnim = null;
  
  this.createEvent("fadeoutComplete");
};
YAHOO.traction.AbstractRow.prototype = {
  
  destroy: function() {
    this.unsubscribeAll();
    YAHOO.util.Event.purgeElement(this.TR);
    this.TR.parentNode.removeChild(this.TR);
    this.TR = null;
    this.data = null;
    this.glowTimer = null;
    this.glowAnim = null;
    this.fadeTimer = null;
    this.fadeAnim = null;
  },
  
  getTR: function() { return this.TR; },
  
  getKey: function() { return this.data.getKey(); },
  setState: function(newstate) {
    if (this.state != newstate) {
      var oldstate = this.state;
      this.state = newstate;
      if (oldstate == -1) {
	try {
	  if (this.fadeTimer) {
	    clearTimeout(this.fadeTimer);
	    this.fadeTimer = null;
	  }
	  if (this.fadeAnim) {
	    this.fadeAnim.stop();
	    this.fadeAnim = null;
	  }
	} 
	catch (e) {}
	if (this.TR) {
	  this.TR.style.opacity = "";
	  this.TR.style.backgroundColor = "";
	}
      }
      if (oldstate < 0 || newstate < 0) {
	this.setClass();
      }
    }
  },
  
  update: function(data) {},
  
  insert: function(parent, before) {
    parent.insertBefore(this.TR, before ? before.TR : null);
    this.setClass();
  },
  
  moveAfter: function(after) {
    var parent = this.TR.parentNode;
    parent.insertBefore(this.TR, after ? after.TR.nextSibling : parent.firstChild);
  },
  
  isSelected: function() { return false; },
  
  setSelected: function(selected) {},
  
  setIndex: function(index) {
    if (this.TR) {
      if (this.index != index) {
	this.index = index;
	this.setClass();
      }
    }
  },
  
  setClass: function() {
    var add = (this.index % 2 === 0) ? "odd" :  "even";
    var rem = (this.index % 2 !== 0) ? "odd" :  "even";
    YAHOO.util.Dom.replaceClass(this.TR, rem, add);
    if (this.data.isUploading && this.data.isUploading()) {
      YAHOO.util.Dom.addClass(this.TR, "uploading");    
    } else {
      YAHOO.util.Dom.removeClass(this.TR, "uploading");    
    }
    if (this.state < 0) {
      YAHOO.util.Dom.addClass(this.TR, "deleting");
    } else {
      YAHOO.util.Dom.removeClass(this.TR, "deleting");
    }
  },
  
  compareTo: function(other, field, asc) { return -1; },
  
  glow: function(options) {
    if (this.glowTimer) {
      clearTimeout(this.glowTimer);
      this.glowTimer = null;
    }
    if (this.glowAnim != null) {
      this.glowAnim.onComplete.unsubscribeAll();
      this.glowAnim.stop();
      this.glowAnim = null;
    }
    options = Object.extend({
      fromColor: "#ffc",
      toColor: "#ffffff",
      glowDuration: 2.5,
      delay: 3500
	  }, options || {});  
    this.setState(1);
    this.TR.style.backgroundColor = options.fromColor;
    var me = this;
    this.glowTimer = setTimeout(function() {
				  var glow = me.glowAnim = new YAHOO.util.ColorAnim(me.TR, {backgroundColor: { to: options.toColor } }, options.glowDuration, YAHOO.util.Easing.easeIn); 
				  glow.onComplete.subscribe(me.glow_done, me, true);
				  glow.duration = options.glowDuration;
				  glow.animate(); 
				}, options.delay);
  },
  
  glow_done: function() {
    this.glowTimer = null;
    this.glowAnim = null;
    this.TR.style.backgroundColor = "";
    if (this.state == 1) this.setState(0);
  },
  
  fadeout: function(options) {
    if (this.fadeTimer != null || this.fadeAnim != null) return;
    options = Object.extend({
      backgroundColor: "#d8e8f5",
      attributes: { opacity: { from: 0.75, to: 0 } },
      fadeDuration: 1.0,
      delay: 2.0,
      dim: true
	  }, options || {});  
    if (options.dim) {
      this.TR.style.opacity = options.attributes.opacity.from;
    }
    this.TR.style.backgroundColor = options.backgroundColor;
    this.setState(-1);
    var me = this;
    this.fadeTimer = setTimeout(function() {
				  var fade = me.fadeAnim = new YAHOO.util.Anim(me.TR, options.attributes, options.fadeDuration); 
				  fade.onComplete.subscribe(me.fadeout_done, me, true);
				  fade.duration = options.fadeDuration;
				  fade.animate(); 
				}, options.delay*1000);
  },
  
  fadeout_done: function() {
    this.fadeTimer = null;
    this.fadeAnim = null;
    if (this.state < 0) {
      this.fireEvent("fadeoutComplete", this);
    }
  }
};
YAHOO.augment(YAHOO.traction.AbstractRow, YAHOO.util.EventProvider);

//------------------------------------------------------------------------
// yui-traction-docmgt.AbstractGridRow

YAHOO.namespace("traction");
YAHOO.traction.AbstractGridRow = function(data, index) {
  YAHOO.traction.AbstractGridRow.superclass.constructor.call(this, data, index);
  
  this.checkbox = null;
};
YAHOO.extend(YAHOO.traction.AbstractGridRow, YAHOO.traction.AbstractRow);

YAHOO.traction.AbstractGridRow.prototype.draw = function(columns) {
  this.redraw(columns);
};

YAHOO.traction.AbstractGridRow.prototype.redraw = function(columns) {};

YAHOO.traction.AbstractGridRow.prototype.isSelected = function() {
  return (this.checkbox && this.checkbox.checked);
};

YAHOO.traction.AbstractRow.prototype.setSelected = function(selected) {
  if (this.checkbox) {
    this.checkbox.checked = selected;
  }
};

//------------------------------------------------------------------------
// yui-traction-docmgt.AdminController

YAHOO.namespace("traction");

YAHOO.traction.AdminController = {
  
  newProjectDialog: null,
  
  newProject: function() {
    if (this.newProjectDialog) {
      this.newProjectDialog.reset();
    } else {
      this.newProjectDialog = new YAHOO.traction.NewProjectDialog();
    }
    this.newProjectDialog.show();
    return true;
  },
  newAccount: function() {
    if (this.newAccountDialog) {
      this.newAccountDialog.reset();
    } else {
      this.newAccountDialog = new YAHOO.traction.NewAccountDialog();
    }
    this.newAccountDialog.show();
    return true;
  }
};

//------------------------------------------------------------------------
// yui-traction-docmgt.AjaxDialog

YAHOO.namespace("traction");

YAHOO.traction.AjaxDialog = function(id, urlparams, options) {
  
  this.bodydiv = document.createElement("DIV");
  var paramstr = "";
  if (urlparams) {
    for (var p in urlparams) {
      if (urlparams.hasOwnProperty(p)) {
	paramstr = fm_append(paramstr, p+"="+encode_url_parameter(urlparams[p]));	
      }
    }
  }
  var url = FORM_ACTION_READ_ONLY + "?" + paramstr;
  YAHOO.util.Connect.asyncRequest('GET', url, 
				  {
				  success: this.onAjaxSuccess,
				      failure: this.onAjaxFailure,
				      scope: this
				  });
  YAHOO.traction.AjaxDialog.superclass.constructor.call(this, id, options);
};
YAHOO.extend(YAHOO.traction.AjaxDialog, YAHOO.traction.AbstractDialog);
YAHOO.traction.AjaxDialog.prototype.onAjaxSuccess = function(obj) {
  this.bodydiv.innerHTML = obj.responseText;
};
YAHOO.traction.AjaxDialog.prototype.onAjaxFailure = function(obj) {
  this.bodydiv.innerHTML = obj.statusText;
};

//------------------------------------------------------------------------
// yui-traction-docmgt.CheckInDialog

YAHOO.namespace("traction");
YAHOO.traction.CheckInDialog = function(options) {
  options = Object.extend({
    zIndex: 1000000
	}, options || {});  
  this.checkedOutBy = null;
  this.comment = null;
  this.buttons;
  YAHOO.traction.CheckInDialog.superclass.constructor.call(this, "CheckInDialog", options);
};
YAHOO.extend(YAHOO.traction.CheckInDialog, YAHOO.traction.AbstractDialog);
YAHOO.traction.CheckInDialog.prototype.show = function() {
  YAHOO.traction.CheckInDialog.superclass.show.call(this);
  this.comment.focus();
};
YAHOO.traction.CheckInDialog.prototype.addControls = function() {
  var f1 = new YAHOO.traction.ControlGroup({ className: "fields"});
  f1.attach(this.form);
  f1.add(this.checkedOutBy = new YAHOO.traction.CheckedOutBy());
  f1.add(this.comment = new YAHOO.traction.TextControl({
	   label: i18n("cfi_dialog_checkin_comment_field_label", "Comment")
	   }));
  var f2 = new YAHOO.traction.ControlGroup({ className: "fields inline submit"});
  f2.attach(this.form);
  f2.add(this.buttons = new YAHOO.traction.CheckInOrCancel(this));
};

YAHOO.traction.CheckInDialog.prototype.setFileData = function(filedata) {
  var title = (new MessageFormat(i18n("cfi_dialog_checkin_title", "Check In: {0}"))).format(Util.truncate(filedata.getName(), 60));
  this.setTitle(title);
  this.checkedOutBy.refresh(filedata);
  this.comment.refresh(filedata);
  this.buttons.refresh(filedata);
};

YAHOO.traction.CheckInDialog.prototype.getComment = function(filedata) {
  return this.comment.getValue();
};

//------------------------------------------------------------------------
// yui-traction-docmgt.control.AbstractControl

YAHOO.namespace("traction");

YAHOO.traction.AbstractControl = function(options) {
  YAHOO.traction.AbstractControl.controlCount++;
  
  this.DIV = null;
  
  this.label = null;
  
  this.field = null;
  
  this.errorDIV = null;
  
  this.dirty = false;
  
  this.isBusy = false;
  
  this.controlId = null;
  this.setOptions(options);
  this.build();
};

YAHOO.traction.AbstractControl.controlCount = 0;
YAHOO.traction.AbstractControl.prototype.setOptions = function(options) {
  this.options = Object.extend({
    label: '',
    className: "fields",
    fieldClassName: "field",
    fieldTagName: "DIV",
    errorClassName: "errortxt",
    submitButton: i18n("Submit", "Submit"),
    loadingColor: "#ffc",
    defaultColor: "#f5f5f5",
    fadeDuration: 2.5
	}, options || {});
};
YAHOO.traction.AbstractControl.prototype.isSameFile = function(a,b) {
  return (a != null && b != null && a.getUrl() == b.getUrl());  
};
YAHOO.traction.AbstractControl.prototype.isDirty = function() {
  return this.dirty;
};
YAHOO.traction.AbstractControl.prototype.makeDirty = function() {
  this.dirty = true;
};
YAHOO.traction.AbstractControl.prototype.build = function() {
  if (!this.DIV) {
    this.DIV = document.createElement("DIV");
    this.DIV.className = this.options.className;
    this.controlId = "jscid"+(YAHOO.traction.AbstractControl.controlCount++);
    if (this.options.label) {
      this.label = document.createElement("LABEL");    
      this.label.className = "name";
      this.label.setAttribute("for", this.controlId);
      this.label.innerHTML = this.options.label;
      this.DIV.appendChild(this.label);
    }
    this.field = document.createElement(this.options.fieldTagName);
    this.field.className = this.options.fieldClassName;
    this.DIV.appendChild(this.field);
    this.addControls(this.field);
  }
};

YAHOO.traction.AbstractControl.prototype.show = function() {
  this.DIV.style.display = "";
};

YAHOO.traction.AbstractControl.prototype.hide = function() {
  this.DIV.style.display = "none";
};

YAHOO.traction.AbstractControl.prototype.isVisible = function() {
  return (this.DIV.style.display != "none");
};

YAHOO.traction.AbstractControl.prototype.getValue = function() {};

YAHOO.traction.AbstractControl.prototype.addControls = function(container) {};

YAHOO.traction.AbstractControl.prototype.focus = function() {};

YAHOO.traction.AbstractControl.prototype.refresh = function(data) {};

YAHOO.traction.AbstractControl.prototype.styleNormal = function() {
  this.isBusy = false;
  YAHOO.util.Dom.removeClass(this.DIV, "loaded");
  YAHOO.util.Dom.removeClass(this.DIV, "loading");
  YAHOO.util.Dom.removeClass(this.DIV, "error");
  this.clearError();
};

YAHOO.traction.AbstractControl.prototype.styleLoading = function() {
  if (this.isBusy) {
    return false;
  } else {
    this.isBusy = true;
    this.clearError();
    YAHOO.util.Dom.removeClass(this.DIV, "loaded");
    YAHOO.util.Dom.addClass(this.DIV, "loading");
    YAHOO.util.Dom.removeClass(this.DIV, "error");
    return true;
  }
};

YAHOO.traction.AbstractControl.prototype.styleError = function(errorMessage) {
  this.isBusy = false;
  YAHOO.util.Dom.removeClass(this.DIV, "loaded");
  YAHOO.util.Dom.removeClass(this.DIV, "loading");
  YAHOO.util.Dom.addClass(this.DIV, "error");
  if (!this.errorDIV) {
    this.errorDIV = document.createElement("DIV");
    this.errorDIV.className = this.options.errorClassName;
    this.errorDIV.innerHTML = errorMessage;
    this.field.appendChild(this.errorDIV);
  } else {
    this.errorDIV.innerHTML = errorMessage;
    this.errorDIV.style.display = "";
  }
};

YAHOO.traction.AbstractControl.prototype.clearError = function() {
  YAHOO.util.Dom.removeClass(this.DIV, "error");
  if (this.errorDIV) {
    this.errorDIV.style.display = "none";
  }
};

YAHOO.traction.AbstractControl.prototype.styleLoaded = function() {
  this.isBusy = false;
  this.DIV.style.backgroundColor = this.options.loadingColor;
  YAHOO.util.Dom.addClass(this.DIV, "loaded");
  YAHOO.util.Dom.removeClass(this.DIV, "loading");
  YAHOO.util.Dom.removeClass(this.DIV, "error");
  var fade = new YAHOO.util.ColorAnim(this.DIV, {backgroundColor: { to: this.options.defaultColor } }, this.options.fadeDuration, YAHOO.util.Easing.easeIn); 
  fade.onComplete.subscribe(this.styleLoaded_animationDone, this, true);
  fade.duration = this.options.fadeDuration;
  fade.animate(); 
};
YAHOO.traction.AbstractControl.prototype.styleLoaded_animationDone = function() {
  this.DIV.style.backgroundColor = "";  
  YAHOO.util.Dom.removeClass(this.DIV, "loading");
  YAHOO.util.Dom.removeClass(this.DIV, "loaded");
  YAHOO.util.Dom.removeClass(this.DIV, "error");
  this.clearError();
};
YAHOO.traction.AbstractControl.prototype.submitCallback = function(args) {
  if (args.result.isSuccess()) {
    this.styleLoaded();
  } else {
    this.styleError(args.result.getErrorMessage());
  }
};

//------------------------------------------------------------------------
// yui-traction-docmgt.control.AbstractButtonOrLink

YAHOO.namespace("traction");
YAHOO.traction.AbstractButtonOrLink = function(options) {
  
  this.button = null;
  
  this.link = null;
  options = Object.extend({
    label: "&nbsp;",
    buttonText: i18n("Submit", "Submit"),
    buttonName: "",
    linkText: i18n("Cancel", "Cancel"),
    callback: null, // { buttonClick: func, linkClick: func, scope: this }
    betweenText: " " + i18n("or", "or") + " "
	}, options || {});
  YAHOO.traction.AbstractButtonOrLink.superclass.constructor.call(this, options);
};
YAHOO.extend(YAHOO.traction.AbstractButtonOrLink, YAHOO.traction.AbstractControl);

YAHOO.traction.AbstractButtonOrLink.prototype.addControls = function(container) {
  if (!this.button) {
    if (this.options.buttonName) {
      if (YAHOO.env.ua.ie) {
	this.button = document.createElement("<INPUT name=\""+this.options.buttonName+"\">");
      } else {
	this.button = document.createElement("INPUT");
	this.button.setAttribute("name", this.options.buttonName);
      }
    } else {
      this.button = document.createElement("INPUT");
    }
    this.button.type = "button";
    this.button.className = "button";
    this.button.value = this.options.buttonText;
    container.appendChild(this.button);
    if (this.options.betweenText) {
      container.appendChild(document.createTextNode(this.options.betweenText));
    }
    this.link = document.createElement("A");
    this.link.href = "javascript:void(0)";
    this.link.innerHTML = this.options.linkText;
    container.appendChild(this.link);
    var cb = this.options.callback;
    if (cb != null) {
      Events.attach(this.button, Events.Click, cb.scope, cb.buttonClick);
      Events.attach(this.link, Events.Click, cb.scope, cb.linkClick);      
    } else {
      Events.attach(this.button, Events.Click, this, this.buttonClick);
      Events.attach(this.link, Events.Click, this, this.linkClick);
    }
  }
};

YAHOO.traction.AbstractButtonOrLink.prototype.hideButton = function() {
  var parent = this.button.parentNode;
  parent.innerHTML = "";
  parent.appendChild(this.link);
};

YAHOO.traction.AbstractButtonOrLink.prototype.buttonClick = function() {};

YAHOO.traction.AbstractButtonOrLink.prototype.linkClick = function() {};

//------------------------------------------------------------------------
// yui-traction-docmgt.control.CheckboxControl

YAHOO.namespace("traction");
YAHOO.traction.CheckboxControl = function(options) {
  
  this.chk = null;
  this.chklabel = options.label;
  options.label = "&nbsp;";
  options = Object.extend({
    label: "&nbsp;",
    id: "",
    name: "",
    textClassName: "text",
    textBefore: "",
    textAfter: "",
    style: "",
    checked: true,
    labelOnLeft: false
	}, options || {});
  YAHOO.traction.CheckboxControl.superclass.constructor.call(this, options);
};
YAHOO.extend(YAHOO.traction.CheckboxControl, YAHOO.traction.AbstractControl);

YAHOO.traction.CheckboxControl.prototype.addControls = function(container) {
  if (!this.chk) {
    this.addPre(container);
    if (this.options.textBefore) {
      container.appendChild(document.createTextNode(this.options.textBefore));
      container.appendChild(document.createElement("BR"));
    }
    this.chk = Form.newInput(this.options.name);
    this.chk.type = "checkbox";
    this.chk.value = "true";
    this.chk.checked = this.options.checked;
    this.chk.id = this.options.id || this.controlId;
    this.chk.className = this.options.textClassName;
    if (this.options.style) {
      this.chk.setAttribute("style", this.options.style);
    }
    container.appendChild(this.chk);
    var label = document.createElement("LABEL");
    label.setAttribute("for", this.options.id || this.controlId);
    label.innerHTML = " "+this.chklabel;
    container.appendChild(label);
    if (this.options.textAfter) {
      container.appendChild(document.createElement("BR"));
      container.appendChild(document.createTextNode(this.options.textAfter));
    }
    this.addPost(container);
  }
};

YAHOO.traction.CheckboxControl.prototype.addPre = function(container) {};
YAHOO.traction.CheckboxControl.prototype.addPost = function(container) {};

YAHOO.traction.CheckboxControl.prototype.focus = function() {
  this.chk.focus();
};

YAHOO.traction.CheckboxControl.prototype.getValue = function() {
  return this.chk.checked;
};

YAHOO.traction.CheckboxControl.prototype.setValue = function(value) {
  this.chk.checked = value;
};

//------------------------------------------------------------------------
// yui-traction-docmgt.control.CheckedOutBy

YAHOO.namespace("traction");

YAHOO.traction.CheckedOutBy = function(options) {
  options = Object.extend({
    label: "&nbsp;"
	}, options || {});
  YAHOO.traction.CheckedOutBy.superclass.constructor.call(this, options);
};
YAHOO.extend(YAHOO.traction.CheckedOutBy, YAHOO.traction.AbstractControl);

YAHOO.traction.CheckedOutBy.prototype.refresh = function(filedata) {
  var co = filedata.getUserHTML('co');
  if (co) {
    if (filedata.isMe('co')) {
      this.field.innerHTML = '<p class=\"work-ver\">' +
	(new MessageFormat(i18n("cfi_filedetails_current_user_checked_out",
				"This file is checked out by you."))).format(co) +
	'</p>';
    } else {
      this.field.innerHTML = '<p class="work-ver">' +
	(new MessageFormat(i18n("cfi_filedetails_other_user_checked_out",
				"This file is checked out by {0}."))).format(co) +
	'</p>';
    }
    this.show();
  } else {
    this.hide();
  }
};

//------------------------------------------------------------------------
// yui-traction-docmgt.control.TextControl

YAHOO.namespace("traction");
YAHOO.traction.TextControl = function(options) {
  
  this.element = null;
  options = Object.extend({
    label: i18n("cfi_control_textarea_label", "Text Area"),
	name: "",
	tagName: "textarea", // or "input"
	textClassName: "text",
	textBefore: "",
	textAfter: "",
	callback: null, // { scope: this, enter: fn }
	rows: "5",
	size: "",
	style: ""
	}, options || {});
  YAHOO.traction.TextControl.superclass.constructor.call(this, options);
};
YAHOO.extend(YAHOO.traction.TextControl, YAHOO.traction.AbstractControl);

YAHOO.traction.TextControl.prototype.addControls = function(container) {
  if (!this.element) {
    this.addPre(container);
    if (this.options.textBefore) {
      container.appendChild(document.createTextNode(this.options.textBefore));
      container.appendChild(document.createElement("BR"));
    }
    if (this.options.tagName === "input") {
      this.element = Form.newInput(this.options.name);
      this.element.type = "text";
      this.element.value = "";
      var cb = this.options.callback;
      if (cb) {
	this.keylistener = new YAHOO.util.KeyListener(this.element, { keys: 13 },   // enter                            
						      { fn: cb.enter, 
							  scope: cb.scope, 
							  correctScope: true } );
	this.keylistener.enable();
      }
      if (this.options.size) {
	this.element.setAttribute("size", this.options.size);	
      }
    } else {
      this.element = Form.newTextarea(this.options.name);
      this.element.setAttribute("rows", this.options.rows);
    }
    this.element.id = this.controlId;
    this.element.className = this.options.textClassName;
    if (this.options.style) {
      this.element.setAttribute("style", this.options.style);
    }
    container.appendChild(this.element);
    if (this.options.textAfter) {
      container.appendChild(document.createElement("BR"));
      container.appendChild(document.createTextNode(this.options.textAfter));
    }
    this.addPost(container);
  }
};

YAHOO.traction.TextControl.prototype.addPre = function(container) {};
YAHOO.traction.TextControl.prototype.addPost = function(container) {};

YAHOO.traction.TextControl.prototype.focus = function() {
  this.element.focus();
};

YAHOO.traction.TextControl.prototype.getValue = function() {
  return this.element.value;
};

YAHOO.traction.TextControl.prototype.setValue = function(value) {
  this.element.value = value;
};

YAHOO.traction.TextControl.prototype.refresh = function(filedata) {
  this.element.value = "";
};

//------------------------------------------------------------------------
// yui-traction-docmgt.control.CheckIn

YAHOO.namespace("traction");
YAHOO.traction.CheckIn = function(options) {
  options = Object.extend({
    label: "&nbsp;",
    name: "checkincomment",
    tagName: "textarea",
    textClassName: "text",
    textBefore: "",
    textAfter: "",
    rows: "5"
	}, options || {});  
  YAHOO.traction.CheckIn.superclass.constructor.call(this, options);
};
YAHOO.extend(YAHOO.traction.CheckIn, YAHOO.traction.TextControl);
YAHOO.traction.CheckIn.prototype.addPre = function(container) {
  var p = document.createElement("P"),
  p2 = document.createElement("P"),
  label = document.createElement("LABEL"),
  ci = Form.newInput("ci");
  ci.id = "ci-on-replace";
  ci.type = "checkbox";
  ci.value = "true";
  label.setAttribute("for", "ci-on-replace");
  label.appendChild(document.createTextNode(" " +i18n("cfi_control_checkin_ci_on_replace_checkbox_label", "Check in document now")));
  p.appendChild(ci);
  p.appendChild(label);
  container.appendChild(p);
  p2.appendChild(document.createTextNode(i18n("cfi_control_checkin_ci_on_replace_ci_comment_field_label", "Add a comment")));
  container.appendChild(p2);
};

//------------------------------------------------------------------------
// yui-traction-docmgt.control.CheckInOrCancel

YAHOO.namespace("traction");

YAHOO.traction.CheckInOrCancel = function(dialog, options) {
  
  this.dialog = dialog;
  
  this.filedata = null;
  options = Object.extend({
    label: "&nbsp;",
	buttonText: i18n("cfi_filedetails_checkin_link_text", "Check In"),
	linkText: i18n("Cancel", "Cancel"),
	betweenText: " " + i18n("or", "or") + " "
	}, options || {});
  YAHOO.traction.CheckInOrCancel.superclass.constructor.call(this, options);
};
YAHOO.extend(YAHOO.traction.CheckInOrCancel, YAHOO.traction.AbstractButtonOrLink);
YAHOO.traction.CheckInOrCancel.prototype.refresh = function(filedata) {
  var isSame = this.isSameFile(this.filedata, filedata);
  if (!isSame) this.styleNormal();
  this.filedata = filedata;
};

YAHOO.traction.CheckInOrCancel.prototype.buttonClick = function() {
  if (this.styleLoading()) {
    YAHOO.traction.FileController.submitCheckIn(this.filedata, this.dialog.getComment(), this.checkin_done.bind(this));  
  }
};
YAHOO.traction.CheckInOrCancel.prototype.checkin_done = function(args) {
  if (args.result.isSuccess()) {
    this.styleLoaded();
    var dialog = this.dialog;
    setTimeout(function() { dialog.hide(); }, 1000);
  } else {
    this.styleError(args.result.getErrorMessage());
  }
};

YAHOO.traction.CheckInOrCancel.prototype.linkClick = function() {
  YAHOO.traction.FileController.hideCheckIn();  
};

//------------------------------------------------------------------------
// yui-traction-docmgt.control.CloseDeleteLinks

YAHOO.namespace("traction");
YAHOO.traction.CloseDeleteLinks = function(options) {
  this.closeLink = null;
  this.deleteLink = null;
  
  this.filedata = null;
  options = Object.extend({
    label: "&nbsp;"
	}, options || {});
  YAHOO.traction.CloseDeleteLinks.superclass.constructor.call(this, options);
};
YAHOO.extend(YAHOO.traction.CloseDeleteLinks, YAHOO.traction.AbstractControl);

YAHOO.traction.CloseDeleteLinks.prototype.addControls = function(container) {
  if (!this.closeLink) {
    this.closeLink = document.createElement("INPUT");
    this.closeLink.type = "button";
    this.closeLink.className = "button";
    this.closeLink.value = i18n("Close", "Close");
    Events.attach(this.closeLink, Events.Click, this, this.closeClick);
    container.appendChild(this.closeLink);
    this.deleteLink = document.createElement("A");
    this.deleteLink.href = "javascript:void(0)";
    this.deleteLink.className = "delete";
    Events.attach(this.deleteLink, Events.Click, this, this.deleteClick);
    container.parentNode.insertBefore(this.deleteLink, container);
  }
};
YAHOO.traction.CloseDeleteLinks.prototype.refresh = function(filedata) {
  this.filedata = filedata;
  if (filedata.isDirectory()) {
    this.deleteLink.innerHTML = i18n("cfi_control_delete_folder_link_text", "Delete Folder");
  } else {
    this.deleteLink.innerHTML = i18n("cfi_control_delete_file_link_text", "Delete Document");
  }
};
YAHOO.traction.CloseDeleteLinks.prototype.closeClick = function() {
  YAHOO.traction.FileController.hideEditInfo();
};
YAHOO.traction.CloseDeleteLinks.prototype.deleteClick = function() {
  if (YAHOO.traction.FileController.deleteSingle(this.filedata, null, true)) {
    YAHOO.traction.FileController.hideEditInfo();    
  }
};

//------------------------------------------------------------------------
// yui-traction-docmgt.control.ControlGroup

YAHOO.namespace("traction");

YAHOO.traction.ControlGroup = function(options) {
  this.setOptions(options);
  
  this.fieldset = document.createElement("FIELDSET");
  
  this.controls = [];
  if (this.options.className) {
    this.fieldset.className = this.options.className;
  }
};

YAHOO.traction.ControlGroup.prototype.setOptions = function(options) {
  this.options = Object.extend({
    className: null
	}, options || {});
};

YAHOO.traction.ControlGroup.prototype.show = function() {
  this.fieldset.style.display = "";
};

YAHOO.traction.ControlGroup.prototype.hide = function() {
  this.fieldset.style.display = "none";
};

YAHOO.traction.ControlGroup.prototype.add = function(control) {
  this.controls[this.controls.length] = control;
  this.fieldset.appendChild(control.DIV);
};
YAHOO.traction.ControlGroup.prototype.refresh = function(data) {
  var hasVisibleChild = false;
  for (var i=0; i<this.controls.length; i++) {
    this.controls[i].refresh(data);
    hasVisibleChild |= this.controls[i].isVisible();
  }
  if (hasVisibleChild) {
    this.show();
  } else {
    this.hide();
  }
};

YAHOO.traction.ControlGroup.prototype.attach = function(elm) {
  elm.appendChild(this.fieldset);
};

//------------------------------------------------------------------------
// yui-traction-docmgt.control.NameControl

YAHOO.namespace("traction");
YAHOO.traction.NameControl = function(options) {
  this.controls = null;
  this.rename = null;
  this.cancel = null;
  
  this.filedata = null;
  options = Object.extend({
    label: i18n("cfi_control_name_label", "Name"),
	submitButton: i18n("cfi_control_name_rename_button_value", "Rename"),
	cancelButton: i18n("Cancel"),
	tagName: "input"
	}, options || {});
  YAHOO.traction.NameControl.superclass.constructor.call(this, options);
};
YAHOO.extend(YAHOO.traction.NameControl, YAHOO.traction.TextControl);

YAHOO.traction.NameControl.prototype.addPost = function(container) {
  Events.attach(this.element, Events.Click, this, this.elementClick);
  Events.attach(this.element, Events.Focus, this, this.elementClick);
};

YAHOO.traction.NameControl.prototype.refresh = function(filedata) {
  var isSame = this.isSameFile(this.filedata, filedata);
  if (!isSame) {
    this.clearError();
  }
  this.filedata = filedata;
  this.element.value = filedata.getName();
};

YAHOO.traction.NameControl.prototype.elementClick = function() {
  if (!this.controls) {
    this.controls = document.createElement("DIV");
    this.element.parentNode.appendChild(this.controls);
    this.rename = document.createElement("INPUT");
    this.rename.className = "button";
    this.rename.setAttribute("type", "button");
    this.rename.setAttribute("value", this.options.submitButton);
    this.controls.appendChild(this.rename);
    var text = document.createTextNode(" or ");
    this.controls.appendChild(text);
    this.cancel = document.createElement("A");
    this.cancel.href = "javascript:void(0)";
    this.cancel.className = "cancel";
    this.cancel.innerHTML = this.options.cancelButton;
    this.controls.appendChild(this.cancel);
    Events.attach(this.rename, Events.Click, this, this.renameClick);
    Events.attach(this.cancel, Events.Click, this, this.cancelClick);
  }
  this.controls.style.display = "";
};

YAHOO.traction.NameControl.prototype.renameClick = function() {
  var newname = this.element.value;
  if (true && newname == this.filedata.getName()) {
    this.styleNormal();
    this.controls.style.display = "none";
  }
  else {
    if (this.styleLoading()) {
      YAHOO.traction.FileController.rename(this.filedata, newname, this.rename_done.bind(this));
    }
  }
};
YAHOO.traction.NameControl.prototype.rename_done = function(args) {
  if (args.result.isSuccess()) {
    this.controls.style.display = "none";
    this.styleLoaded();
  } else {
    this.styleError(args.result.getErrorMessage());
  }
};

YAHOO.traction.NameControl.prototype.cancelClick = function() {
  this.clearError();
  this.element.value = this.filedata.getName();
  this.controls.style.display = "none";
};

//------------------------------------------------------------------------
// yui-traction-docmgt.control.DescControl

YAHOO.namespace("traction");
YAHOO.traction.DescControl = function(options) {
  options = Object.extend({
    label: i18n("cfi_control_desc_field_label", "Description"),
	submitButton: i18n("cfi_control_desc_set_button_value", "Change"),
	tagName: "textarea"
	}, options || {});
  YAHOO.traction.DescControl.superclass.constructor.call(this, options);
};
YAHOO.extend(YAHOO.traction.DescControl, YAHOO.traction.NameControl);

YAHOO.traction.DescControl.prototype.refresh = function(filedata) {
  var isSame = this.isSameFile(this.filedata, filedata);
  if (!isSame) this.styleNormal();
  this.filedata = filedata;
  this.element.value = filedata.getDescription();
};

YAHOO.traction.DescControl.prototype.renameClick = function() {
  var newdesc = this.element.value;
  if (this.styleLoading()) {
    YAHOO.traction.FileController.updatedesc(this.filedata, newdesc, this.rename_done.bind(this));
  }
};

YAHOO.traction.DescControl.prototype.cancelClick = function() {
  this.clearError();
  this.element.value = this.filedata.getDescription();
  this.controls.style.display = "none";
};

//------------------------------------------------------------------------
// yui-traction-docmgt.control.FileControl

YAHOO.namespace("traction");
YAHOO.traction.FileControl = function(options) {
  
  this.input = null;
  options = Object.extend({
    label: "&nbsp;",
    name: "file00"
	}, options || {});
  YAHOO.traction.FileControl.superclass.constructor.call(this, options);
};
YAHOO.extend(YAHOO.traction.FileControl, YAHOO.traction.AbstractControl);

YAHOO.traction.FileControl.prototype.addControls = function(container) {
  if (!this.input) {
    this.input = Form.newInput(this.options.name);
    this.input.setAttribute("type", "file");
    this.input.className = "text";
    container.appendChild(this.input);
  }
};

YAHOO.traction.FileControl.prototype.refresh = function(data) {
  this.input.value = "";
};

//------------------------------------------------------------------------
// yui-traction-docmgt.control.HtmlControl

YAHOO.namespace("traction");

YAHOO.traction.HtmlControl = function(options) {
  options = Object.extend({
    label: "&nbsp;",
    html: "&nbsp;"
	}, options || {});
  YAHOO.traction.HtmlControl.superclass.constructor.call(this, options);
};
YAHOO.extend(YAHOO.traction.HtmlControl, YAHOO.traction.AbstractControl);

YAHOO.traction.HtmlControl.prototype.addControls = function(container) {
  container.innerHTML = this.options.html;
};
YAHOO.traction.HtmlControl.prototype.setHtml = function(html) {
  container.innerHTML = html;
};

YAHOO.traction.HtmlControl.prototype.refresh = function(data) {
};

//------------------------------------------------------------------------
// yui-traction-docmgt.control.LockControl

YAHOO.namespace("traction");
YAHOO.traction.LockControl = function(options) {
  
  this.filedata = null;
  this.idSuffix = ""+(YAHOO.traction.LockControl.count++);
  
  this.unlockRadio = null;
  this.unlockLabel = null;
  this.lockRadio = null;
  this.lockLabel = null;
  this.stealRadio = null;
  this.stealLabel = null;
  options = Object.extend({
    label: i18n("cfi_control_lock_label", "Lock")
	}, options || {});
  YAHOO.traction.LockControl.superclass.constructor.call(this, options);
};
YAHOO.extend(YAHOO.traction.LockControl, YAHOO.traction.AbstractControl);
YAHOO.traction.LockControl.count = 0;

YAHOO.traction.LockControl.prototype.addControls = function(container) {
  var unlockRadio, unlockLabel, lockRadio, lockLabel, stealRadio, stealLabel, idSuffix = this.idSuffix;
  unlockRadio = Form.newInput("lock");
  unlockRadio.setAttribute("type", "radio");
  unlockRadio.setAttribute("id", "unlock"+idSuffix);
  unlockLabel = document.createElement("LABEL");
  unlockLabel.setAttribute("for", "unlock"+idSuffix);
  unlockLabel.innerHTML = i18n("cfi_control_lock_unlocked_label", "Unlocked") + " ";
  lockRadio = Form.newInput("lock");
  lockRadio.setAttribute("type", "radio");
  lockRadio.setAttribute("id", "lock"+idSuffix);
  lockLabel = document.createElement("SPAN");
  lockLabel.innerHTML = '<label for=\"lock' + idSuffix + '\">' + i18n("cfi_control_lock_locked_label", "Locked") + " </label>";
  stealRadio = Form.newInput("lock")
  stealRadio.setAttribute("type", "radio");
  stealRadio.setAttribute("id", "steal"+idSuffix);
  stealLabel = document.createElement("LABEL");
  stealLabel.setAttribute("for", "steal"+idSuffix);
  stealLabel.innerHTML = i18n("cfi_control_lock_steal_label", "Steal Lock");
  container.appendChild(unlockRadio);
  container.appendChild(unlockLabel);
  container.appendChild(lockRadio);
  container.appendChild(lockLabel);
  container.appendChild(document.createTextNode(" "));
  container.appendChild(stealRadio);
  container.appendChild(stealLabel);
  YAHOO.util.Event.on(unlockRadio, "click", this.unlockClick, this, true);
  YAHOO.util.Event.on(lockRadio, "click", this.lockClick, this, true);
  YAHOO.util.Event.on(stealRadio, "click", this.stealClick, this, true);
  this.unlockRadio = unlockRadio;
  this.unlockLabel = unlockLabel;
  this.lockRadio = lockRadio;
  this.lockLabel = lockLabel;
  this.stealRadio = stealRadio;
  this.stealLabel = stealLabel;
};
YAHOO.traction.LockControl.prototype.unlockClick = function(e) {
  if (this.filedata.isLocked() && this.styleLoading()) {
    YAHOO.traction.FileController.unlock(this.filedata, this.action_done.bind(this));
  }
};
YAHOO.traction.LockControl.prototype.lockClick = function(e) {
  if (!this.filedata.isLocked() && this.styleLoading()) {
    YAHOO.traction.FileController.lock(this.filedata, this.action_done.bind(this));
  }
};
YAHOO.traction.LockControl.prototype.stealClick = function(e) {
  if (this.filedata.isLocked() && this.styleLoading()) {
    YAHOO.traction.FileController.steallock(this.filedata, this.action_done.bind(this));
  }
};

YAHOO.traction.LockControl.prototype.action_done = function(args) {
  if (args.result.isSuccess()) {
    this.styleLoaded();
  } 
  else {
    this.styleError(args.result.getErrorMessage());
  }
};

YAHOO.traction.LockControl.prototype.refresh = function(filedata) {
  var showOwnerAndSteal = false;
  this.filedata = filedata;
  if (filedata.isDirectory()) {
    this.hide();
  } else {
    var lck = filedata.get("lck");
    if (lck) {
      this.unlockRadio.checked = false;
      this.lockRadio.checked = true;
      if (filedata.isMe('lck')) {
	this.lockLabel.innerHTML = '<label for=\"lock' + this.idSuffix + '\">' +
	  (new MessageFormat(i18n("cfi_control_lock_by_current_user", "Locked by You"))).format(lck.name) +
	  "</label> ";
      } else {
	this.lockLabel.innerHTML = (new MessageFormat(i18n("cfi_control_lock_by_other_user",
							   "{0}Locked by{1} {2}"))).format('<label for=\"lock' + this.idSuffix + '\">',
											   '</label>',
											   this.getLockOwnerLink(lck)) + " ";
	showOwnerAndSteal = true;
      }
    } else {
      this.unlockRadio.checked = true;
      this.lockRadio.checked = false;
      this.lockLabel.innerHTML = i18n("cfi_control_lock_locked_label", "Locked") + " ";
    }
    Util.display(this.stealRadio, showOwnerAndSteal);
    Util.display(this.stealLabel, showOwnerAndSteal);
    this.show();
  }
};
YAHOO.traction.LockControl.prototype.getLockOwnerLink = function(lck) {
  return '<a href=\"' + lck.url + '\" target=\"_blank\">' + lck.name + '</a>';
};

//------------------------------------------------------------------------
// yui-traction-docmgt.control.SaveUnder

YAHOO.namespace("traction");
YAHOO.traction.SaveUnder = function(options) {
  options = Object.extend({
    label: i18n("cfi_control_save_under_label", "Save under"),
	name: "path",
	tagName: "input"
	}, options || {});
  YAHOO.traction.SaveUnder.superclass.constructor.call(this, options);
};
YAHOO.extend(YAHOO.traction.SaveUnder, YAHOO.traction.TextControl);

YAHOO.traction.SaveUnder.prototype.setValue = function(value) {
  if (value && value.charAt(value.length-1) != '/') value += '/';
  this.element.value = value;
};

YAHOO.traction.SaveUnder.prototype.getValue = function() {
  var val = this.element.value;
  if (val.charAt(val.length-1) != '/') {
    val += '/';
    this.element.value = val;
  }
  return val;
};

//------------------------------------------------------------------------
// yui-traction-docmgt.control.TabSet

YAHOO.namespace("traction");

YAHOO.traction.TabSet = function(tabs, options) {
  this.tabs = tabs;
  this.setOptions(options);
};
YAHOO.traction.TabSet.prototype = {
  setOptions: function(options) {
    this.options = Object.extend({
      betweenTabs: " | ",
      tabClassName: "tab",
      lastClassName: "last",
      selectedClassName: "selected"
	  }, options || {});
  },
  
  attach: function(container) {
    var i, sz, tab, A;
    for (i=0, sz=this.tabs.length; i<sz; i++) {
      tab = this.tabs[i];
      A = document.createElement("A");
      A.href = "javascript:void(0)";
      YAHOO.util.Dom.addClass(A, this.options.tabClassName);
      A.innerHTML = tab.name;
      container.appendChild(A);
      if (i == sz-1) {
	YAHOO.util.Dom.addClass(A, this.options.lastClassName);	
      } else {
	container.appendChild(document.createTextNode(this.options.betweenTabs));
      }
      tab.A = A;
    }
    Events.attach(container, Events.Click, this, this.onclick);
  },
  onclick: function(e) {
    var target = YAHOO.util.Event.getTarget(e),
    match = this.findTabIndex(target),
    i, sz, tab;
    if (match >= 0) {
      this.select(match);
      return false;
    }
  },
  
  select: function(match) {
    for (i=0, sz=this.tabs.length; i<sz; i++) {
      tab = this.tabs[i];
      if (i === match || tab.name === match) {
	YAHOO.util.Dom.addClass(tab.A, this.options.selectedClassName);
	Util.show(tab.div);
      } else {
	YAHOO.util.Dom.removeClass(tab.A, this.options.selectedClassName);
	Util.hide(tab.div);
      }
    }
  },
  
  findTabIndex: function(el) {
    if (el) {
      var i, sz, tab, tabs=this.tabs;
      for (i=0, sz=tabs.length; i<sz; i++) {
	tab = tabs[i];
	if (tab.A == el || YAHOO.util.Dom.isAncestor(tab.A, el)) {
	  return i;
	}
      }
    }
    return -1;
  }
};

//------------------------------------------------------------------------
// yui-traction-docmgt.control.TrackVersions

YAHOO.namespace("traction");

YAHOO.traction.TrackVersions = function(options) {
  
  this.chk = null;
  options = Object.extend({
    label: "&nbsp;",
    callback: null // { click: func, scope: this }
	}, options || {});
  YAHOO.traction.TrackVersions.superclass.constructor.call(this, options);
};
YAHOO.extend(YAHOO.traction.TrackVersions, YAHOO.traction.AbstractControl);

YAHOO.traction.TrackVersions.prototype.addControls = function(container) {
  this.chk = Form.newInput("vc");
  this.chk.type = "checkbox";
  this.chk.id = "vc-on-replace";
  this.chk.value = "true";
  container.appendChild(this.chk);
  var cb = this.options.callback;
  if (cb) {
    Events.attach(this.chk, Events.Click, cb.scope, cb.click);
  }
  var label = document.createElement("LABEL");
  label.setAttribute("for", "vc-on-replace");
  label.innerHTML = " " + i18n("cfi_control_trackversions_link_text", "Track Versions");
  container.appendChild(label);
};

YAHOO.traction.TrackVersions.prototype.refresh = function(filedata) {
  if (filedata.isVersioned()) {
    this.chk.checked = true;
    this.chk.disabled = true;
  } else {
    this.chk.checked = false;
    this.chk.disabled = false;
  }
};

//------------------------------------------------------------------------
// yui-traction-docmgt.control.VersionControl

YAHOO.namespace("traction");
YAHOO.traction.VersionControl = function(options) {
  
  this.filedata = null;
  this.thead = null;
  this.tbody = null;
  
  this.turnOnTR = null;
  
  this.headerTR = null;
  
  this.workVerTR = null;
  options = Object.extend({
    label: i18n("cfi_control_versions_label", "Version Info"),
	fieldTagName: "TABLE",
	fieldClassName: "version-info",
	maxNameLength: 20
	}, options || {});
  YAHOO.traction.VersionControl.superclass.constructor.call(this, options);
};
YAHOO.extend(YAHOO.traction.VersionControl, YAHOO.traction.AbstractControl);

YAHOO.traction.VersionControl.prototype.refresh = function(filedata) {
  var isSame = this.isSameFile(this.filedata, filedata);
  if (isSame) {
    this.clearError();
  } else {
    this.styleNormal();
  }
  this.filedata = filedata;
  if (!this.thead) {
    this.thead = document.createElement("THEAD");
    this.field.appendChild(this.thead);
  }
  if (!this.tbody) {
    this.tbody = document.createElement("TBODY");
    this.field.appendChild(this.tbody);    
  }
  if (filedata.isDirectory()) {
    this.hide();
  } 
  else {
    if (filedata.isVersioned()) {
      if (this.turnOnTR) show_TR(false, this.turnOnTR);
      if (!this.headerTR) {
	this.headerTR = document.createElement("TR");
	this.newTH(this.headerTR, i18n("cfi_control_versions_column_heading_number", "#"));
	this.newTH(this.headerTR, i18n("cfi_control_versions_column_heading_filename", "Name"));
	this.newTH(this.headerTR, i18n("cfi_control_versions_column_heading_author", "By"));
	this.newTH(this.headerTR, i18n("cfi_control_versions_column_heading_date", "Check in date"));
	this.thead.insertBefore(this.headerTR, this.thead.firstChild);
      }
      show_TR(true, this.headerTR);
      if (!isSame) {
	this.removeVersionRows();
      }
      filedata.refreshVersions(this.getVersions_done.bind(this));
     }
    else {
      if (!this.turnOnTR) {
	this.turnOnTR = document.createElement("TR");
	this.turnOnTR.className = "enable-ver";
	var TD = document.createElement("TD");
	TD.colSpan = "4";
	this.turnOnTR.appendChild(TD);
	var B = document.createElement("B");
	B.innerHTML = i18n("cfi_control_versions_tracking_off", "Version Tracking is off.");
	TD.appendChild(B);
	var P = document.createElement("P");
	P.innerHTML = i18n("cfi_control_versions_note",
			   "Note: You can enable version tracking when replacing or re-uploading the file. Once version tracking is enabled for a file, it cannot be disabled.");
	TD.appendChild(P);
	var A = document.createElement("A");
	A.href = "javascript:void(0)";
	A.innerHTML = i18n("cfi_control_versions_turn_on_link_text",
			   "Turn version tracking on.");
	Events.attach(A, Events.Click, this, this.turnOnClick);
	TD.appendChild(A);
	this.tbody.insertBefore(this.turnOnTR, this.tbody.firstChild);
      }
      if (this.headerTR) show_TR(false, this.headerTR);
      this.removeVersionRows();
      show_TR(true, this.turnOnTR);
    }
    this.show();
  }
};

YAHOO.traction.VersionControl.prototype.getVersions_done = function(filedata, versions, state) {
  if (filedata == this.filedata) {
    if (versions) {
      this.removeVersionRows();
      for (var i=0; i<versions.length; i++) {
	var version = versions[i];
	var number = version.getVersion();
	var isWorkingVersion = (number == -1);
	var TR = document.createElement("TR");
	if (isWorkingVersion) {
	  TR.className = "work-ver";
	} else {
	  TR.className = "ver "+((i%2===0) ? "even" : "odd");
	}	  
	var TD1 = document.createElement("TD");
	TD1.innerHTML = isWorkingVersion ? "+" : this.nbsp(version.getVersionHTML());
	TR.appendChild(TD1);
	var TD4 = document.createElement("TD");
	TD4.innerHTML = '<a class="ver-dl" href="'+version.getUrl()+'">'+Util.truncate(version.get('n'), this.options.maxNameLength)+'</a>';// '<span class="ver-dl">Download</span>';
	TR.appendChild(TD4);
	var TD2 = document.createElement("TD");
	TD2.innerHTML = this.nbsp(version.getUserHTML('usr'));
	TR.appendChild(TD2);
	var TD3 = document.createElement("TD");
	if (isWorkingVersion) {
	  if (version.isMe('usr')) {
	    TD3.innerHTML = (new MessageFormat(i18n("cfi_control_versions_working_version_checkout_owner_current_user", "Checked Out By You"))).format(version.data['usr']['name']);
	  } else {
	    TD3.innerHTML = (new MessageFormat(i18n("cfi_control_versions_working_version_checkout_owner_other_user", "Checked Out"))).format(version.data['usr']['name']);
	  }
	} else {
	  TD3.innerHTML = this.nbsp(version.getDateHTML('dt'));
	}
	TR.appendChild(TD3);
	this.tbody.appendChild(TR);
	if (isWorkingVersion) {
	  var tr = document.createElement("TR");
	  tr.className = "ver-comment";
	  var td1 = document.createElement("TD");
	  td1.innerHTML = i18n("cfi_control_versions_working_version", "Working Version");
	  td1.colSpan = "2";
	  tr.appendChild(td1);
	  var td3 = document.createElement("TD");
	  td3.colSpan = "2";
	  var A1 = document.createElement("A");
	  A1.href = "javascript:void(0)";
	  A1.innerHTML = i18n("cfi_filedetails_checkin_link_text", "Check In");
	  Events.attach(A1, Events.Click, this, this.checkinClick);
	  td3.appendChild(A1);
	  td3.appendChild(document.createTextNode(" | "));
	  var A2 = document.createElement("A");
	  A2.href = "javascript:void(0)";
	  A2.innerHTML = i18n("cfi_control_versions_cancel_checkout_link_text", "Cancel Checkout");
	  Events.attach(A2, Events.Click, this, this.cancelCheckoutClick);
	  td3.appendChild(A2);
	  tr.appendChild(td3);
	  this.tbody.appendChild(tr);
	}
	if (number > 1) {
	  var desc = version.getDescription();
	  if (desc) {
	    var TR2 = document.createElement("TR");
	    TR2.className = "ver-comment";
	    var TD = document.createElement("TD");
	    TD.colSpan = "4";
	    TD.innerHTML = desc;
	    TR2.appendChild(TD);
	    this.tbody.appendChild(TR2);
	  }
	}
      }
    }
  }
};
YAHOO.traction.VersionControl.prototype.nbsp = function(val) {
  return val ? val : "&nbsp;";
};
YAHOO.traction.VersionControl.prototype.removeVersionRows = function() {
  if (this.turnOnTR) {
    this.removeRemainingRows(this.turnOnTR.nextSibling);
  } else {
    this.removeRemainingRows(this.tbody.firstChild);
  }
};
YAHOO.traction.VersionControl.prototype.removeRemainingRows = function(first) {
  if (first) {
    this.removeRemainingRows(first.nextSibling);
    this.tbody.removeChild(first);
  }
};

YAHOO.traction.VersionControl.prototype.newTH = function(TR, name) {
  var TH = document.createElement("TH");
  TH.innerHTML = name;
  TR.appendChild(TH);
};

YAHOO.traction.VersionControl.prototype.turnOnClick = function() {
  if (this.styleLoading()) {
    YAHOO.traction.FileController.versioncontrol(this.filedata, this.submitCallback.bind(this));
  }
};

YAHOO.traction.VersionControl.prototype.checkinClick = function() {
  YAHOO.traction.FileController.checkin(this.filedata);
};

YAHOO.traction.VersionControl.prototype.cancelCheckoutClick = function() {
  if (this.styleLoading()) {
    YAHOO.traction.FileController.uncheckout(this.filedata, this.submitCallback.bind(this));
  }
};

//------------------------------------------------------------------------
// yui-traction-docmgt.EditInfoDialog

YAHOO.namespace("traction");
YAHOO.traction.EditInfoDialog = function(options) {
  
  this.children = [];
  YAHOO.traction.EditInfoDialog.superclass.constructor.call(this, "EditInfoDialog", options);
};
YAHOO.extend(YAHOO.traction.EditInfoDialog, YAHOO.traction.AbstractDialog);
YAHOO.traction.EditInfoDialog.prototype.addControls = function() {
  var f1 = new YAHOO.traction.ControlGroup();
  f1.attach(this.form);
  f1.add(new YAHOO.traction.NameControl());
  f1.add(new YAHOO.traction.DescControl());
  var f2 = new YAHOO.traction.ControlGroup();
  f2.attach(this.form);
  f2.add(new YAHOO.traction.LockControl());
  f2.add(new YAHOO.traction.VersionControl());
  var f3 = new YAHOO.traction.ControlGroup({ className: "fields inline submit"});
  f3.add(new YAHOO.traction.CloseDeleteLinks());
  f3.attach(this.form);
  this.children = [ f1, f2, f3 ];
};
YAHOO.traction.EditInfoDialog.prototype.closeClick = function() {
  this.hide();
};

YAHOO.traction.EditInfoDialog.prototype.setFileData = function(filedata) {
  var title = (new MessageFormat(i18n("cfi_dialog_editinfo_title", "Edit Info: {0}"))).format(Util.truncate(filedata.getName(), 60));
  this.setTitle(title);
  for (var i=0; i<this.children.length; i++) {
    this.children[i].refresh(filedata);
  }
};

//------------------------------------------------------------------------
// yui-traction-docmgt.FileController

YAHOO.namespace("traction");

YAHOO.traction.FileController = {
  
  userid: -1,
  
  path: null,
  
  webdav: 0,
  
  editInfoDialog: null,
  checkInDialog: null,
  replaceDialog: null,
  uploadDialog: null,
  mkdirDialog: null,
  
  fileResultEvent: new YAHOO.util.CustomEvent("fileResultEvent", this, false, YAHOO.util.CustomEvent.FLAT),
  
  fileUploadEvent: new YAHOO.util.CustomEvent("fileUploadEvent", this, false, YAHOO.util.CustomEvent.FLAT),
  
  fileErrorEvent: new YAHOO.util.CustomEvent("fileErrorEvent", this, false, YAHOO.util.CustomEvent.FLAT),
  
  numUploading: 0,
  
  init: function(options) {
    options = Object.extend({
      userid: -1,
      webdav: 0,
      path: "" // this will be used as the default path for mkdir and upload
	  }, options || {});
    this.userid = options.userid;
    this.path = options.path;
    this.webdav = options.webdav;
    this.mkdirDialog = null;
    this.uploadDialog = null;
  },
  get: function(url, callback, state, options) {
    options = Object.extend({
      brief: true
	  }, options || {});
    this.ajax({ type: "filedata", brief: (options.brief ? "y" : "n"), url: url }, callback, state, options);
  },
  
  getList: function(url, callback, state, options) {
    options = Object.extend({
      brief: false
	  }, options || {});
    this.ajax({ type: "filedata", list: "true", brief: (options.brief ? "y" : "n"), url: url }, callback, state, options);
  },
  getVersions: function(filedata, callback, state, options) {
    this.ajax({ type: "versiondata", url: filedata.getUrl() }, callback, state, options);
  },
  ajax: function(parameters, callback, state, options) {
    var poststring = "";
    options = Object.extend({
      }, options || {});
    if (parameters) {
      for (var p in parameters) {
	if (parameters.hasOwnProperty(p)) {
	  poststring = fm_append(poststring, p+"="+encode_url_parameter(parameters[p]));	
	}
      }
    }
    YAHOO.util.Connect.asyncRequest('POST', FORM_ACTION_READ_WRITE, 
				    {
				    success: this.onAjaxSuccess,
					failure: this.onAjaxFailure,
					scope: this,
					argument: { options: options, state: state, callback: callback }
				    },
				    poststring);
  },
  onAjaxSuccess: function(obj) {
    this.notify_content(obj.responseText, obj.argument);
  },
  onAjaxFailure: function(obj) {
    this.fileErrorEvent.fire({errorMessage: (new MessageFormat(i18n("cfi_file_controls_error_message_operation_failed", "Operation failed: {0}"))).format(obj.statusText)});
  },
  showDownload: function(filedata) { 
    return !filedata.isDirectory();
  },
  showReplace: function(filedata) { 
    return !filedata.isDirectory();
  },
  showCheckout: function(filedata) {
    return filedata.isVersioned() && !filedata.isCheckedOut();
  },
  showCheckin: function(filedata) {
    return filedata.isVersioned() && filedata.isCheckedOut();
  },
  showEditDirect: function(filedata) {
    return filedata.get('dEd') && !filedata.isDirectory();
  },
  showOpenWebFolder: function(filedata) {
    return filedata.get('dEd') && filedata.isDirectory();    
  },
  showEditInfo: function(filedata) {
    return true;
  },
  download: function(filedata) {
    document.location.href = FORM_ACTION_READ_ONLY + "?type=downloadfile&url=" + encode_url_parameter(filedata.getUrl());
  },
  checkout: function(filedata, callback) {
    this.ajaxrpc("filerpc", "checkout", filedata, callback);
  },
  checkin: function(filedata) {
    this.hideEditInfo();
    if (!this.checkInDialog) {
      this.checkInDialog = new YAHOO.traction.CheckInDialog();
    }
    this.checkInDialog.setFileData(filedata);
    this.checkInDialog.show();
  },
  submitCheckIn: function(filedata, comment, callback) {
    this.ajaxrpc("filerpc", "checkin", filedata, callback, { checkincomment: comment });
  },
  hideCheckIn: function() {
    if (this.checkInDialog) this.checkInDialog.hide();
  },
  editDirect: function(filedata) {
    var dEd = filedata.get("dEd"), app = null;
    if (dEd) {      
      switch (dEd.app) {
      case "Word":
	app = Util.EditApps.Word;
	break;
      case "Excel":
	app = Util.EditApps.Excel;
	break;
      case "Powerpoint":
	app = Util.EditApps.Powerpoint;
	break;
      }
      if (app) {
	Util.editDocument(app, dEd.path);
      }
      else {
	alert((new MessageFormat(i18n("cfi_file_controls_error_message_no_matching_app", "Could not find an Application matching {0}."))).format(dEd.app));
      }
    } 
    else {
      alert(i18n("cfi_file_controls_error_message_document_not_editable", "Document not editable."));
    }
  },
  editInfo: function(filedata) {
    if (!this.editInfoDialog) {
      this.editInfoDialog = new YAHOO.traction.EditInfoDialog();
    }
    this.editInfoDialog.setFileData(filedata);
    this.editInfoDialog.show();
  },
  hideEditInfo: function() {
    if (this.editInfoDialog) this.editInfoDialog.hide();
  },
  showMkdir: function() {
    this.hideAddDropDown();
    if (this.mkdirDialog === null) {
      this.mkdirDialog = new YAHOO.traction.MkdirDialog({path: this.path});
    }
    this.mkdirDialog.setFileData(null);
    this.mkdirDialog.show();
    return false;
  },
  showUpload: function() {
    this.hideAddDropDown();
    if (this.uploadDialog === null) {
      this.uploadDialog = new YAHOO.traction.UploadDialog({path: this.path, webdav: this.webdav});
    }
    this.uploadDialog.setFileData(null);
    this.uploadDialog.show();
    return false;
  },
  toggleAddDropDown: function() {
    var ad = document.getElementById("add-drop");
    if (ad) Util.toggle(ad, false, "block");
    return false;
  },
  showAddDropDown: function() {
    var ad = document.getElementById("add-drop");
    if (ad) Util.show(ad, false, "block");
  },
  hideAddDropDown: function() {
    var ad = document.getElementById("add-drop");
    if (ad) Util.hide(ad);    
  },
  replace: function(filedata) {
    if (this.replaceDialog === null) {
      this.replaceDialog = new YAHOO.traction.ReplaceDialog();
    }
    this.replaceDialog.setFileData(filedata);
    this.replaceDialog.show();
  },
  replaceDialog: null,
  
  deleteSingle: function(filedata, callback, doConfirm) {
    var ask;
    if (filedata.isDirectory()) {
      ask = i18n("cfi_file_controls_confirmation_message_delete_folder",
		 "Are you sure you wish to delete this folder and all of its contents?\n\n" +
		 "Click OK to delete the folder.\nClick Cancel to cancel the operation.");
    } else {
      ask = i18n("cfi_file_controls_confirmation_message_delete_file",
		 "Are you sure you wish to delete this file?\n\n" +
		 "Click OK to delete the file.\nClick Cancel to cancel the operation.");
    }
    if (doConfirm && !confirm(ask)) {
      return false;
    }
    this.ajaxrpc("filerpc", "delete", filedata, callback);
    return true;
  },
  
  deleteMultiple: function(filedatas, callback, doConfirm) {
    if (doConfirm && !confirm(i18n("cfi_file_controls_confirmation_message_delete_selected",
				   "Are you sure you wish to delete the selected files?\n\n" +
				   "Click OK to delete the files.\nClick Cancel to cancel the operation."))) {
      return false;
    }
    this.ajaxrpc("filerpc", "delete", filedatas, callback);
    return true;
  },
  
  rename: function(filedata, newname, callback) {
    this.ajaxrpc("filerpc", "rename", filedata, callback, { name: newname });
  },
  mkdir: function(newname, path, callback) {
    if (!path) path = this.path;
    this.ajaxrpc("filerpc", "mkdir", null, callback, { name: newname, path: path });
  },
  updatedesc: function(filedata, desc, callback) {
    this.ajaxrpc("filerpc", "updatedesc", filedata, callback, { description: desc });
  },
  versioncontrol: function(filedata, callback) {
    this.ajaxrpc("filerpc", "versioncontrol", filedata, callback);
  },
  uncheckout: function(filedata, callback) {
    this.ajaxrpc("filerpc", "uncheckout", filedata, callback);
  },
  lock: function(filedata, callback) {
    this.ajaxrpc("filerpc", "lock", filedata, callback);
  },
  unlock: function(filedata, callback) {
    this.ajaxrpc("filerpc", "unlock", filedata, callback);
  },
  steallock: function(filedata, callback) {
    this.ajaxrpc("filerpc", "steallock", filedata, callback);
  },
  ajaxrpc: function(type, method, filedata, callback, parameters, options) {
    var poststring = "";
    options = Object.extend({
      }, options || {});
    poststring = fm_append(poststring, "type="+type);
    poststring = fm_append(poststring, "method="+method);
    if (filedata) {
      if (YAHOO.lang.isArray(filedata)) {
	for (var i=0, sz=filedata.length; i<sz; i++) {
	  poststring = fm_append(poststring, "path"+i+"="+encode_url_parameter(filedata[i].getUrl()));	
	}
      } else {
	poststring = fm_append(poststring, "path="+encode_url_parameter(filedata.getUrl()));
      }
    }
    if (parameters) {
      for (var p in parameters) {
	if (parameters.hasOwnProperty(p)) {
	  poststring = fm_append(poststring, p+"="+encode_url_parameter(parameters[p]));	
	}
      }
    }
    YAHOO.util.Connect.asyncRequest('POST', FORM_ACTION_READ_WRITE, 
				    {
				    success: this.onAjaxRpcSuccess,
					failure: this.onAjaxRpcFailure,
					scope: this,
					argument: { method: method, filedata: filedata, callback: callback }
				    },
				    poststring);
  },
  onAjaxRpcSuccess: function(obj) {
    this.notify_result(obj.responseText, obj.argument);
  },
  onAjaxRpcFailure: function(obj) {
    this.notify_result({success:0,errorMessage:obj.statusText}, obj.argument);
  },
  notify_result: function(responseText, state) {
    var result = YAHOO.traction.FileResult.wrap(responseText),
    oldfiledata = state.filedata;
    if (YAHOO.lang.isArray(result)) {
      for (var i=0; i<result.length; i++) {
	if (YAHOO.lang.isArray(oldfiledata)) {
	  state.filedata = oldfiledata[i];
	}
 	this.notify_single_result(result[i], state);
      }
    } else {
      if (YAHOO.lang.isArray(oldfiledata)) {
	state.filedata = oldfiledata[0];
      }
      this.notify_single_result(result, state);
    }
  },
  
  notify_single_result: function(result, state) {
    if (!result.isSuccess()) {
      state.filedata.setLastError(result.getErrorMessage());
    }
    if (state.callback) {
      state.callback({ oldfiledata: state.filedata, result: result, method: state.method });
    }
    this.fileResultEvent.fire({ oldfiledata: state.filedata, result: result, method: state.method });
    if (result.isSuccess()) {
      var fd = result.getFileData();
      if (fd) {
	if (this.editInfoDialog && this.editInfoDialog.isVisible()) {
	  this.editInfoDialog.setFileData(fd);
	}
      }
    }
  },
  
  notify_content: function(responseText, state) {
    if (state.callback) {
      state.callback(responseText, state.state, state.options);
    }
  },
  upload: function(form, method, tableId) {
    this.numUploading++;
    var url,
    path = form.path.value,
    filename = form.file00.value;
    filename = Util.stripPath(filename);
    if (method == "put") {
      if (path && path.charAt(path.length-1) != '/') {
	path += '/';
      }
      url = path + filename;
    } else {
      url = path;
    }
    this.get(url, this.upload_confirm.bind(this), 
	     {   url: url,
		 filename: filename,
		 form: form,
		 method: method,
		 tableId: tableId
		 });
  },
  upload_confirm: function(responseText, state, options) {
    var result = YAHOO.traction.FileResult.wrap(responseText);
    if (!result.isSuccess()) {
      alert(result.getErrorMessage());
    }
    else if (state.method === "replace" ||  // we're intending to replace
	     !result.getFileData() ||       // there's nothing there
	     confirm(this.upload_confirm_msg(state))) {
      this.upload_exec(state.url, state.form, state.method, state.tableId);
    }
  },
  upload_confirm_msg: function(state) {
    return (new MessageFormat(i18n("cfi_file_controls_confirmation_message_replace_existing_file",
				    "A file already exists with the name:\n\n{0}\n\nAre you sure you want to replace it?"))).format(state.filename);
  },
  upload_exec: function(url, form, method, tableId) {
    var filedata = new YAHOO.traction.FileData({url:url}),
    callback = {
      upload: this.upload_done,
      scope: this,
      argument: { method: method, filedata: filedata } };
    YAHOO.util.Connect.setForm(form, true, true);
    filedata.uploadHandle = YAHOO.util.Connect.asyncRequest('POST', FORM_ACTION_READ_WRITE, callback);
    filedata.uploadCallback = callback;
    this.fileUploadEvent.fire({ form: form, method: method, tableId: tableId, filedata: filedata });
  },
  upload_done: function(result) {
    var args = result.argument;
    var filedata = args.filedata;
    var responseText = result.responseText;
    filedata.uploadHandle = null;
    filedata.uploadCallback = null;
    this.numUploading--;
    this.notify_result(responseText, { filedata: filedata, method: args.method });
  },
  
  abortUpload: function(filedata) {
    return filedata && filedata.uploadHandle && YAHOO.util.Connect.abort(filedata.uploadHandle);
  }
};

//------------------------------------------------------------------------
// yui-traction-docmgt.FileData

YAHOO.namespace("traction");

var gwtnav = function(a) { return true; }

YAHOO.traction.FileData = function(data) {
  
  this.data = data;
  
  this.name = null;
  
  this.versions = null;
  
  this.uploadHandle = null;
  this.uploadCallback = null;
  this.lastError = null;
};

YAHOO.traction.FileData.FIELDS = 
  [ 
   "url",
   "href", 
   "dir", 
   "desc",
   "icon",
   "e",
   "v",
   "sz",
   "szB",
   "szFmt",
   "dt",
   "dtFmt",
   "usr",
   "perms",
   "adv",
   "dEd",
   "lck",
   "thm",
   "disk",
   "co",
   "snip",
   "watchurl",
   "proj"
   ];

YAHOO.traction.FileData.COLUMNS = [ "ckbx", "title", "date", "aut", "size", "status", "info" ];
YAHOO.traction.FileData.COMPARATORS = { 
  "ckbx": null,  
  "title": function(a,b) {
    return caseInsensitiveCompare(b.getName(), a.getName());
  }, 
  "date": function(a,b) {
    return b.get('dt') - a.get('dt');
  },
  "aut": function(a,b) {
    if (!a.has('usr')) {
      return (!b.has('usr')) ? 0 : -1;
    }
    else if (!b.has('usr')) {
      return 1;
    }
    else {
      return caseInsensitiveCompare(b.get('usr').name, a.get('usr').name);
    }
  },
  "size": function(a,b) {
    return b.get('sz') - a.get('sz');
  },
  "status": null,
  "info": null
};

YAHOO.traction.FileData.KnownEXTs = {
  doc: "doc",
  gif: "img",
  jpg: "img",
  jpeg: "img",
  png: "img",
  mov: "mov",
  pdf: "pdf",
  ppt: "ppt",
  xls: "xls" 
};
YAHOO.traction.FileData.prototype.getKey = function() {
  return this.getUrl();
};
YAHOO.traction.FileData.prototype.get = function(key) {
  return this.data[key];
};
YAHOO.traction.FileData.prototype.columnKeys = function() {
  return YAHOO.traction.FileData.COLUMNS;
};
YAHOO.traction.FileData.prototype.getVersion = function() {
  if (this.has('v')) {
    return this.data['v'];
  }
  return 0;
};
YAHOO.traction.FileData.prototype.getVersionHTML = function() {
  var version = this.getVersion();
  if (version > 0) {
    return ""+version;
  }
  return "";
};
YAHOO.traction.FileData.prototype.getDateHTML = function(keybase) {
  return this.has(keybase+'Fmt') ? this.get(keybase+'Fmt') : "-";  
};
YAHOO.traction.FileData.prototype.isMe = function(key) {
  if (this.has(key)) {
    var id = this.data[key]['id'];
    return (id == YAHOO.traction.FileController.userid);
  }
  return false;
};
YAHOO.traction.FileData.prototype.getUserHTML = function(key, options) {
  options = Object.extend({
    }, options || {});
  if (this.has(key)) {
    var usr = this.data[key];
    if (usr) {
      if (usr['url']) {
	return '<a href="'+usr['url']+(options.className ? '" class="'+options.className : '') + '">' + usr['name'] + '</a>';
      } else {
	return usr['name'];
      }
    }
  }
  return "";
};
YAHOO.traction.FileData.prototype.isError = function() {
  return this.lastError;
};
YAHOO.traction.FileData.prototype.getLastError = function() {
  return this.lastError;
};
YAHOO.traction.FileData.prototype.setLastError = function(error) {
  this.lastError = error;
};
YAHOO.traction.FileData.prototype.isUploading = function() {
  return (this.uploadHandle !== null);
};
YAHOO.traction.FileData.nowrap = function(key) {
  switch (key) {
    case "date":
    case "size":
    return true;
  }
  return false;
};
YAHOO.traction.FileData.prototype.getHTML = function(key, row) {
  if (this.isUploading()) {
    switch (key) {
      case "title":
      return '<a href="' + this.getHref() + '" class="uploading">' + Util.truncate(this.getName(), 45) + '</a>';
      default:
      return "";
    }
  } 
  else {
    switch (key) {
      case "ckbx":
      return null;
      case "title":
      var ic = this.getIcon(true);
      var icon = '<img src="'+ic.url+'" width="'+ic.w+'" height="'+ic.h+'">';
      return '<a onclick="return gwtnav(this);" href="' + this.getHref() + '" class="' + this.getTitleClass("")  + '">' + icon + Util.truncate(this.getName(), 45) + '</a>';
      case "date":
      return this.getDateHTML('dt');
      case "aut":
      return this.getUserHTML('usr');
      case "size":
      if (this.data['dir']) {
	return "";
      } else {
	return this.has('szFmt') ? this.get('szFmt') : "-";
      }
      case "status":
      return this.getUserHTML('co', this.get('lck') ? {className:'locked'} : {});
      case "info":
      return null;
      default:
      return "";
    }
  }
};
YAHOO.traction.FileData.prototype.getTitleClass = function(notfound) {
  return notfound;
};
YAHOO.traction.FileData.prototype.getDescription = function() {
  return (typeof this.data['desc'] != "undefined") ? this.data['desc'] : "";
};
YAHOO.traction.FileData.prototype.getName = function() {
  if (this.name === null) {
    var url = this.getUrl();
    if (url.charAt(url.length-1) == '/') {
      url = url.substring(0, url.length-1);
    }
    this.name = Util.stripPath(url);
  }
  return this.name;
};
YAHOO.traction.FileData.prototype.getPath = function() {
  var url = this.data['url'];
  if (url.charAt(url.length-1) == '/') {
    url = url.substring(0, url.length-1);
  }
  return Util.getPath(url);
};
YAHOO.traction.FileData.prototype.getIcon = function(defaultToPx) {
  if (this.has('icon')) {
    return this.data['icon'];
  } else {
    return (defaultToPx) ? {url:"/images/modern/px.gif",w:16,h:16} : null;
  }
};
YAHOO.traction.FileData.prototype.isLocked = function() {
  return this.data['lck'];
};
YAHOO.traction.FileData.prototype.isVersioned = function() {
  return this.has('v') && this.data['v'] > 0;
};
YAHOO.traction.FileData.prototype.isCheckedOut = function() {
  return this.has('co') && this.data['co'] != null;
};

YAHOO.traction.FileData.prototype.canVersion = function() {
  var perms = this.get('perms');
  return !this.get('disk') && perms && perms.indexOf("V") != -1;
};
YAHOO.traction.FileData.prototype.isDirectory = function() {
  return this.has('dir') && this.data['dir'];
};
YAHOO.traction.FileData.prototype.getUrl = function() {
  return this.has('url') ? this.data['url'] : "";
};
YAHOO.traction.FileData.prototype.getHref = function() {
  return this.has('href') ? this.data['href'] : this.getUrl();
};
YAHOO.traction.FileData.prototype.getThumbUrl = function() {
  if (this.has('thm')) {
    var thm = this.data['thm'];
    if (thm != null) {
      return this.data['thm']['url'];
    }
  }
  return "";
};
YAHOO.traction.FileData.prototype.getThumbWidthHtml = function() {
  if (this.has('thm')) {
    var thm = this.data['thm'];
    if (thm != null) {
      if (thm['w'] && thm['w'] > 0) {
	return ' width="'+thm['w']+'"';
      }
    }
  }
  return "";
};
YAHOO.traction.FileData.prototype.getThumbHeightHtml = function() {
  if (this.has('thm')) {
    var thm = this.data['thm'];
    if (thm != null) {
      if (thm['h'] && thm['h'] > 0) {
	return ' height="'+thm['h']+'"';
      }
    }
  }
  return "";
};
YAHOO.traction.FileData.prototype.has = function(key) {
  return (typeof this.data[key] != "undefined");
};

YAHOO.traction.FileData.prototype.getVersions = function(callback, state) {
  if (this.versions) {
    callback(this, this.versions, state);
  } else {
    this.refreshVersions(callback, state);
  }
};

YAHOO.traction.FileData.prototype.refreshVersions = function(callback, state) {
  YAHOO.traction.FileController.getVersions(this, this.refreshVersions_done.bind(this), { callback: callback, state: state });
};

YAHOO.traction.FileData.prototype.refreshVersions_done = function(responseText, state, options) {
  if (responseText) {
    var result = YAHOO.traction.FileResult.wrap(responseText);
    this.versions = result.getFileData();
  } else {
    this.versions = null;
  }
  if (state.callback) {
    state.callback(this, this.versions, state.state);
  }
};

YAHOO.traction.FileData.prototype.equals = function(other) {
  return other ? Util.areEqual(this.data, other.data) : false;
};

YAHOO.traction.FileData.prototype.isNearlySame = function(other) {
  var fields = YAHOO.traction.FileData.FIELDS;
  var sz = fields.length;
  for (var i=0; i<sz; i++) {
    if (fields[i] != 'dtFmt' && !Util.areEqual(this.data[fields[i]], other.data[fields[i]])) {
      return false;
    }
  }
  return true;
};

YAHOO.traction.FileData.prototype.findMatchingIndex = function(fds) {
  if (fds) {
    var key = this.getKey();
    var sz = fds.length;
    for (var i=0; i<sz; i++) {
      if (fds[i].getKey() === key) return i;
    }
  }
  return -1;
};

//------------------------------------------------------------------------
// yui-traction-docmgt.FileDetailsRow

YAHOO.traction.FileDetailsRow = function(TR, colspan, options, filedata) {
  this.filedata = filedata;
  this.download = null;
  this.checkin = null;
  this.checkout = null;
  this.editInfo = null;
  this.editDirect = null;
  this.openWebFolder = null;
  this.replace = null;
  YAHOO.traction.FileDetailsRow.superclass.constructor.call(this, TR, colspan, options);
};
YAHOO.extend(YAHOO.traction.FileDetailsRow, YAHOO.traction.AbstractDetailsRow);

YAHOO.traction.FileDetailsRow.prototype.destroy = function() {
  YAHOO.traction.FileDetailsRow.superclass.destroy.call(this);
  this.filedata = null;
  this.download = null;
  this.checkin = null;
  this.checkout = null;
  this.editInfo = null;
  this.editDirect = null;
  this.openWebFolder = null;
  this.replace = null;
};
YAHOO.traction.FileDetailsRow.prototype.update = function(filedata) {
  this.filedata = filedata;
  this.refresh();
};
YAHOO.traction.FileDetailsRow.prototype.build = function() {
  YAHOO.traction.FileDetailsRow.superclass.build.call(this);
  this.versions = document.createElement("DIV");
  this.versions.style.display = "none";
  this.versions.className = "versions";
  this.co = new YAHOO.traction.CheckedOutBy({label:""});
  this.info.appendChild(this.co.DIV);
  this.vc = new YAHOO.traction.VersionControl({label:"", maxNameLength: 45});
  this.versions.appendChild(this.vc.DIV);
  this.TD.insertBefore(this.versions, this.status);
  this.tabset = new YAHOO.traction.TabSet([{ name: i18n("cfi_filedetails_tab_info", "INFO"), div: this.info }, { name: i18n("cfi_filedetails_tab_versions", "VERSIONS"), div: this.versions }], {betweenTabs:""});
  this.tabset.attach(this.tabs);
  this.tabset.select(0);
};
YAHOO.traction.FileDetailsRow.prototype.refresh = function() {
  var desc = this.filedata.getDescription();
  var thumb = this.filedata.getThumbUrl();
  if (!desc) {
    if (this.filedata.isDirectory()) {
      desc = i18n("cfi_filedetails_folder_no_description_message",
		  "No description available for this folder.");
    } else {
      desc = i18n("cfi_filedetails_document_no_description_message",
		  "No description available for this document.");
    }
  }
  if (thumb || desc) {
    if (thumb) {
      thumb += "?" + this.filedata.get('dt');
      this.desc.innerHTML = '<img src="'+thumb+'"'+this.filedata.getThumbWidthHtml()+this.filedata.getThumbHeightHtml()+' class="thumb" />\n'+desc;
    } else {
      this.desc.innerHTML = desc;
    }
    this.desc.style.display = "";
  }
  else {
    this.desc.style.display = "none";
  }
  var watchurl = this.filedata.get('watchurl');
  this.download   = this.createLink(this.status, this.download,   i18n("cfi_filedetails_download_link_text", "Download"), "dload",  this.onDownload);
  this.createEditLink();
  this.createOpenWebFolderLink(this.status);
  this.checkin    = this.createLink(this.status, this.checkin,    i18n("cfi_filedetails_checkin_link_text", "Check In"), "ckin",   this.onCheckin);
  this.checkout   = this.createLink(this.status, this.checkout,   i18n("cfi_filedetails_checkout_link_text", "Check Out"), "ckout", this.onCheckout);
  this.editInfo   = this.createLink(this.status, this.editInfo,   i18n("cfi_filedetails_editinfo_link_text", "Edit Info"), "iedit" + (watchurl ? "" : " last"), this.onEditInfo);
  if (watchurl) {
    if (!this.subscribe) {
      this.subscribe = document.createElement("A");
      this.subscribe.className = "subscribe last";
      this.subscribe.href = "javascript:";
      this.status.appendChild(this.subscribe);
    }
    makeSubscriptionControl(this.subscribe, {type:7,path:watchurl,proj:this.filedata.get('proj')});
  }
  Util.display(this.download, YAHOO.traction.FileController.showDownload(this.filedata));
  Util.display(this.editDirect, YAHOO.traction.FileController.showEditDirect(this.filedata));
  if (this.openWebFolder) Util.display(this.openWebFolder, YAHOO.traction.FileController.showOpenWebFolder(this.filedata));
  Util.display(this.checkin, YAHOO.traction.FileController.showCheckin(this.filedata));
  Util.display(this.checkout, YAHOO.traction.FileController.showCheckout(this.filedata));
  Util.display(this.editInfo, YAHOO.traction.FileController.showEditInfo(this.filedata));
  if (!this.form.hasChildNodes()) {
    if (YAHOO.traction.FileController.showReplace(this.filedata)) {
      var input = document.createElement("INPUT");
      input.className = "button";
      input.setAttribute("type", "button");
      input.setAttribute("value", i18n("cfi_filedetails_replace_button_value", "Replace"));
      Events.attach(input, Events.Click, this, this.onReplace);
      this.replace = input; 
      this.form.appendChild(input);
      this.form.style.display = "";
    } else {
      this.form.style.display = "none";
    }
  } else {
    if (YAHOO.traction.FileController.showReplace(this.filedata)) {
      this.replace.style.display = "";
      this.form.style.display = "";
    } else {
      this.replace.style.display = "none";
      this.form.style.display = "none";
    }
  }
  if (this.filedata.isDirectory()) {
    Util.hide(this.tabs);
    Util.hide(this.versions);
    Util.show(this.desc);
  } else {
    this.co.refresh(this.filedata);
    this.vc.refresh(this.filedata);
  }
};

YAHOO.traction.FileDetailsRow.prototype.createEditLink = function() {
  if (!this.editDirect) {
    var dEd = this.filedata.get("dEd"), text = i18n("edit_file_button_short", "Edit"), cls="msedit";
    if (dEd != null) {
      text = dEd.txt;
      cls += dEd.app;
    }
    this.editDirect = this.createLink(this.status, this.editDirect, text, cls, this.onEditDirect);
  }
};
YAHOO.traction.FileDetailsRow.prototype.createOpenWebFolderLink = function(add) {
  if (!this.openWebFolder && this.filedata.isDirectory()) {
    var dEd = this.filedata.get("dEd");
    if (dEd != null) {
      var A = document.createElement("A");
      A.className = "webfolder";
      A.href = dEd.path;
      A.setAttribute("folder", dEd.path);
      A.target = "_blank";
      A.style.display = "none";
      A.style.behavior = "url(#default#AnchorClick)";
      A.innerHTML = dEd.txt;
      add.appendChild(A);
      this.openWebFolder = A;
    }
  }
};

YAHOO.traction.FileDetailsRow.prototype.createLink = function(add, A, text, className, handler) {
  if (!A) {
    A = document.createElement("A");
    A.style.display = "none";
    A.href = "javascript:void(0)";
    A.className = className;
    A.innerHTML = text;
    A.onclick = handler.bind(this);
    add.appendChild(A);
  }
  return A;
};
YAHOO.traction.FileDetailsRow.prototype.onDownload   = function() { YAHOO.traction.FileController.download(this.filedata); return false;   };
YAHOO.traction.FileDetailsRow.prototype.onCheckin    = function() { YAHOO.traction.FileController.checkin(this.filedata);    };
YAHOO.traction.FileDetailsRow.prototype.onCheckout   = function() { YAHOO.traction.FileController.checkout(this.filedata);   };
YAHOO.traction.FileDetailsRow.prototype.onEditInfo   = function() { YAHOO.traction.FileController.editInfo(this.filedata);   };
YAHOO.traction.FileDetailsRow.prototype.onEditDirect = function() { YAHOO.traction.FileController.editDirect(this.filedata); };
YAHOO.traction.FileDetailsRow.prototype.onReplace    = function() { YAHOO.traction.FileController.replace(this.filedata); };

//------------------------------------------------------------------------
// yui-traction-docmgt.FileGrid

YAHOO.namespace("traction");

YAHOO.traction.FileGrid = function(tableId, url, options) {
  var exist = YAHOO.traction.FileGrid.getGrid(tableId);
  if (exist) {
    exist.setUrl(url);
    return exist;
  }
  YAHOO.traction.FileGrid.registerGrid(tableId, this);
  
  this.tableId = tableId;
  
  this.table = null;
  this.errorDIV = null;
  this.tbody = null;
  this.checkAll = null;
  this.selectAction = null;
  
  this.url = url;
  
  this.rowset = null;
  
  this.dataSource = null;
  this.dataSourceInterval = 0;
  
  this.inRefresh = false;
  
  this.setOptions(options);
  
  YAHOO.util.Event.onDOMReady(this.onDOMReady, this, true);
  
  YAHOO.traction.FileController.fileResultEvent.subscribe(this.onControllerResult, this, true);
  YAHOO.traction.FileController.fileErrorEvent.subscribe(this.onControllerError, this, true);
};
YAHOO.traction.FileGrid.prototype.setOptions = function(options) {
  this.options = Object.extend({
    itemCountId: null,
    checkAllId: this.tableId+"-checkall",
    selectActionId: this.tableId+"-select-action",
    refresh_seconds: 10
	}, options || {});
};

YAHOO.traction.FileGrid.prototype.onDOMReady = function() {
  this.table = document.getElementById(this.tableId);
  this.tbody = getFirstChildByName(this.table, "TBODY");
  this.thead = new YAHOO.traction.Thead(getFirstChildByName(this.table, "THEAD"));
  this.thead.clickEvent.subscribe(this.onHeadingClick, this, true);
  this.thead.setSorted(1, -1);
  this.errorDIV = document.createElement("DIV");
  this.errorDIV.style.display = "none";
  this.errorDIV.className = "errorbox";
  this.table.parentNode.insertBefore(this.errorDIV, this.table);
  this.checkAll = document.getElementById(this.options.checkAllId);
  if (this.checkAll) {
    Events.attach(this.checkAll, Events.Click, this, this.onCheckAllClick);
  }
  this.selectAction = document.getElementById(this.options.selectActionId);
  if (this.selectAction) {
    Events.attach(this.selectAction, Events.Change, this, this.onSelectActionChange);
  }
  this.rowset = new YAHOO.traction.RowSet(YAHOO.traction.FileGridRow, this.tbody, YAHOO.traction.FileData.COLUMNS);
  this.rowset.subscribe("sizeChangeEvent", this.onSizeChange, this, true);
  this.fill();
};
YAHOO.traction.FileGrid.prototype.onHeadingClick = function(arg) {
  try {
    var dir, col = YAHOO.traction.FileData.COLUMNS[arg.index], comp = YAHOO.traction.FileData.COMPARATORS[col], sorted = this.thead.isSorted(arg.index);
    if (comp) {
      if (sorted !== 0) {
	dir = sorted * -1; // reverse
      } else {
	dir = 1;
      }
      this.thead.setSorted(arg.index, dir);
      this.rowset.setComparator(comp, dir, arg.index);
    }
  } catch (e) { alert(e); }
};
YAHOO.traction.FileGrid.prototype.onCheckAllClick = function() {
  this.select(this.checkAll.checked);  
};
YAHOO.traction.FileGrid.prototype.onSelectActionChange = function() {
  var value = currentSelValue(this.selectAction);
  if (value) this.doAction(value);
  selectOptionByValue(this.selectAction,"");
};
YAHOO.traction.FileGrid.prototype.onSizeChange = function(args) {
  this.updateCount(args.size);
};
YAHOO.traction.FileGrid.prototype.updateCount = function(sz) {
  if (this.options.itemCountId) {
    var ic = document.getElementById(this.options.itemCountId);
    if (ic) {
      if (sz == 1) {
	ic.innerHTML = i18n("cfi_filegrid_item_count_singular", "1 item");
      } else {
	ic.innerHTML = (new MessageFormat(i18n("cfi_filegrid_item_count_multiple", "{0} items"))).format(new String(sz));
      }
    }    
  }  
};
YAHOO.traction.FileGrid.prototype.fill = function() {
  YAHOO.traction.FileController.getList(this.url, this.fill_done.bind(this), null, { brief: true });
};
YAHOO.traction.FileGrid.prototype.fds = function(results) {
  var res = YAHOO.traction.FileResult.wrap(results);
  return res.getFileData();
};
YAHOO.traction.FileGrid.prototype.fill_done = function(results, state, options) {
  this.rowset.merge(this.fds(results), false);
  this.setupRefresh();
};

YAHOO.traction.FileGrid.prototype.kill = function() {
  this.stopRefresh();
  this.dataSource = null;
  this.dataSourceInterval = 0;
  this.rowset.clear();
  this.rowset = null;
  this.options = null;
  this.table = null;
  this.errorDIV = null;
  this.tbody = null;
  this.checkAll = null;
  this.selectAction = null;
  YAHOO.traction.FileController.fileResultEvent.unsubscribe(this.onControllerResult, this);
  YAHOO.traction.FileController.fileErrorEvent.unsubscribe(this.onControllerError, this);
};
YAHOO.traction.FileGrid.prototype.setUrl = function(url) {
  this.stopRefresh();
  this.rowset.clear();
  this.url = url;
  this.setupRefresh();
};
YAHOO.traction.FileGrid.prototype.stopRefresh = function() {
  if (this.dataSource) {
    this.dataSource.clearInterval(this.dataSourceInterval);
  }
};
YAHOO.traction.FileGrid.prototype.setupRefresh = function() {
  if (this.dataSource == null) {
    this.dataSource = new YAHOO.util.DataSource(FORM_ACTION_READ_WRITE+"?", 
						{ connMethodPost: false, 
						    connTimeout: 5000, // timeout
						    connXhrMode: "cancelStaleRequests"
						    } );
    this.dataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
    this.dataSource.responseSchema = { fields: YAHOO.traction.FileResult.FIELDS }; // { fields: YAHOO.traction.FileData.FIELDS };
    this.dataSource.maxCacheEntries = 0;
  } 
  this.dataSource.sendRequest("type=filedata&list=true&brief=n&url="+encode_url_parameter(this.url),
			      {
			      success: this.refresh_success,
				  failure: this.refresh_failure,
				  scope: this,
				  argument: { animate: false }
			      });
  if (this.options.refresh_seconds > 0) {
    this.dataSourceInterval = this.dataSource.setInterval(this.options.refresh_seconds*1000,
							  "type=filedata&list=true&brief=n&url="+encode_url_parameter(this.url),
							  {
							  success: this.refresh_success,
							      failure: this.refresh_failure,
							      scope: this,
							      argument: { animate: true }
							  });
  }
};

YAHOO.traction.FileGrid.prototype.refresh_success = function(request, response, state) {
  if (this.inRefresh) return;
  this.inRefresh = true;
  state = Object.extend({
    animate: false
	}, state || {});
  var result = new YAHOO.traction.FileResult.wrap(response.results);
  if (result.isSuccess()) {
    this.setLastError(null);
    this.rowset.merge(result.getFileData(), state.animate);
  } else {
    this.setLastError(result.getErrorMessage());
  }
  this.inRefresh = false;
};
YAHOO.traction.FileGrid.prototype.refresh_failure = function(request, response, state) {
  if (response.statusText) {
    if (response.statusText == "transaction aborted") {
      this.setLastError(null);
    } else {
      this.setLastError((new MessageFormat(i18n("cfi_filegrid_error_message_refresh_failure", "Refresh failed: {0}"))).format(response.statusText));
    }
  } else {
    this.setLastError(i18n("cfi_filegrid_error_message_unknown",
			   "Sorry, but an unknown error occurred. You may need to login again.") +
		      '<br><a href=\"' + this.url + '\">' +
		      i18n("cfi_filegrid_click_to_refresh_link_text",
			   "Click here to refresh this page.") +
		      "</a>")
  }
};
YAHOO.traction.FileGrid.prototype.setLastError = function(error) {
  this.errorDIV.innerHTML = error ? error : "";
  Util.display(this.errorDIV, error);
};
YAHOO.traction.FileGrid.prototype.deleteRow = function(row) {
  if (row && row.TR) {
    row.destroy();
  }
};

YAHOO.traction.FileGrid.prototype.insertRow = function(row, beforeRow) {
  this.tbody.insertBefore(row.TR, beforeRow ? beforeRow.TR : null);
};
YAHOO.traction.FileGrid.prototype.deleteSelected = function() {
  var i, sz, fds = this.rowset.getSelected(-2);
  if (YAHOO.traction.FileController.deleteMultiple(fds, null, true)) {
    this.rowset.setState(fds, -2);    
  } else {
    this.rowset.setState(fds, 0);
  }
  if (this.checkAll) this.checkAll.checked = false;
};

YAHOO.traction.FileGrid.prototype.select = function(allOrNone) {
  this.rowset.select(allOrNone);
  if (this.checkAll) this.checkAll.checked = allOrNone;
};
YAHOO.traction.FileGrid.prototype.onControllerResult = function(args) {
  if (args.result.isSuccess()) {
    this.setLastError(null);
    if (args.method == "delete") {
      this.rowset.remove(args.oldfiledata, true, {delay: 0});
    } else {
      this.rowset.update(args.oldfiledata, args.result.getFileData(), true, 0);
    }
  }
};
YAHOO.traction.FileGrid.prototype.onControllerError = function(args) {
  this.setLastError(args.errorMessage);
};

YAHOO.traction.FileGrid.prototype.doAction = function(action, args) {
  switch(action) {
    case "delete":
    this.deleteSelected();
    break;
    case "selectall":
    this.select(true);
    break;
    case "selectnone":
    this.select(false);
    break;
  }
  return false;
};

YAHOO.traction.FileGrid.registeredGrids = [];
YAHOO.traction.FileGrid.registerGrid = function(tableId, grid) {
  YAHOO.traction.FileGrid.registeredGrids[tableId] = grid;
};
YAHOO.traction.FileGrid.getGrid = function(tableId) {
  return YAHOO.traction.FileGrid.registeredGrids[tableId];
};
YAHOO.traction.FileGrid.action = function(tableId, action, args) {
  var grid = YAHOO.traction.FileGrid.getGrid(tableId);
  return (grid) ? grid.doAction(action, args) : false;
};
YAHOO.traction.FileGrid.unregisterGrid = function(tableId) {
  YAHOO.traction.FileGrid.registeredGrids[tableId] = null;
};
YAHOO.traction.FileGrid.prototype.remove = function() {
  this.stopRefresh();
  this.rowset.clear();
  YAHOO.traction.FileGrid.unregisterGrid(this.tableId);
};

//------------------------------------------------------------------------
// yui-traction-docmgt.FileGridCell

YAHOO.namespace("traction");
YAHOO.traction.FileGridCell = function(filedata) {
};

//------------------------------------------------------------------------
// yui-traction-docmgt.FileGridRow

YAHOO.namespace("traction");

YAHOO.traction.FileGridRow = function(filedata, index) {
  YAHOO.traction.FileGridRow.superclass.constructor.call(this, filedata, index);
  
  this.TR = document.createElement("TR");
  
  this.infoLink = null;
  
  this.titleLink = null;
  
  this.detailsRow = null;
  this.setClass();
};
YAHOO.extend(YAHOO.traction.FileGridRow, YAHOO.traction.AbstractGridRow);

YAHOO.traction.FileGridRow.prototype.destroy = function() {
  YAHOO.traction.FileGridRow.superclass.destroy.call(this);
  if (this.detailsRow) this.detailsRow.destroy();
};

YAHOO.traction.FileGridRow.prototype.update = function(filedata, animate) {
  var oldfiledata = this.data;
  if (filedata.equals(this.data)) {
    return false;
  }
  this.data = filedata;
  this.redraw(YAHOO.traction.FileData.COLUMNS);
  this.setClass();
  if (this.detailsRow) {
    this.detailsRow.update(filedata);
  }
  if (animate) {
    if (!oldfiledata.isNearlySame(filedata)) {
      this.glow();
    }
  }
  return true;
};

YAHOO.traction.FileGridRow.prototype.moveAfter = function(after) {
  var parent = this.TR.parentNode, next = after ? (after.detailsRow ? after.detailsRow.TR.nextSibling : after.TR.nextSibling) : parent.firstChild;
  if (this.detailsRow) {
    parent.insertBefore(this.detailsRow.TR, next);
    parent.insertBefore(this.TR, this.detailsRow.TR);
  } else {
    parent.insertBefore(this.TR, next);
  }
};

YAHOO.traction.FileGridRow.prototype.redraw = function(columns) {
  var i;
  var TDs = this.TR.childNodes;
  if (TDs.length === 0) {
    for (i=0; i<columns.length; i++) {
      var td = this.newTD(this.TR, columns[i]);
      if (YAHOO.traction.FileData.nowrap(columns[i])) {
	td.style.whiteSpace = "nowrap";
      }
    }
    TDs = this.TR.childNodes;
  }
  for (i=0; i<columns.length; i++) {
    var column = columns[i];
    if (column == "info") {
      if (!this.infoLink) {
	var A = document.createElement("A");
	A.href = "javascript:void(0)";
	TDs[i].appendChild(A);
	this.infoLink = A;
	Events.attach(A, Events.Click, this, this.infoClick);
	if (false) {
	  var txt = document.createTextNode(" / ");
	  TDs[i].appendChild(txt);
	  var details = document.createElement("A");
	  details.href = "javascript:void(0)";
	  details.innerHTML = i18n("cfi_filegrid_row_details_link_text", "Details");
	  TDs[i].appendChild(details);	
	  Events.attach(details, Events.Click, this, this.fileDetailsClick);
	}
      }
      Util.setHtml(this.infoLink, this.data.isUploading() ? i18n("cfi_filegrid_row_cancel_upload_link_text", "Cancel") : i18n("cfi_filegrid_row_info_link_text", "Info"));
    } 
    else if (column == "ckbx" && !this.data.isUploading()) {
      if (!this.checkbox) {
	this.checkbox = document.createElement("INPUT");
	this.checkbox.type = "checkbox";
	this.checkbox.checked = false;
	Events.attach(this.checkbox, Events.Click, this, this.checkboxClick);
	TDs[i].appendChild(this.checkbox);
      }
    } else {
      Util.setHtml(TDs[i], this.data.getHTML(column, this));
    }
  }
};
YAHOO.traction.FileGridRow.prototype.newTD = function(TR, className) { 
  var TD = document.createElement("TD");
  TR.appendChild(TD);
  YAHOO.util.Dom.addClass(TD, className);
  return TD;
};
YAHOO.traction.FileGridRow.prototype.fileDetailsClick = function() {
  showdetails(encode_url_parameter(this.data.getUrl()), encode_url_parameter(this.data.getUrl()));
};
YAHOO.traction.FileGridRow.prototype.checkboxClick = function() {
  if (this.checkbox.checked) {
    var dk = document.getElementById("dock");
    Util.show(dk, false, "block");
    YAHOO.util.Dom.addClass(this.TR, "selected");
  } else {
    YAHOO.util.Dom.removeClass(this.TR, "selected");
  }
};

YAHOO.traction.FileGridRow.prototype.infoClick = function() {
  if (false) {
    YAHOO.traction.FileController.editInfo(this.data);
  } else {
    this.displayDetailsRow(!(this.detailsRow && this.detailsRow.isVisible()));
  }
};
YAHOO.traction.FileGridRow.prototype.displayDetailsRow = function(show) {  
  if (show) {
    if (!this.detailsRow) {
      this.detailsRow = new YAHOO.traction.FileDetailsRow(this.TR, this.data.columnKeys().length - 1, {}, this.data);
    }
    this.detailsRow.show();
  } 
  else {
    if (this.detailsRow) {
      this.detailsRow.hide();
    }
  }  
};

YAHOO.traction.FileGridRow.prototype.fadeout = function(options) {
  this.displayDetailsRow(false);
  YAHOO.traction.FileGridRow.superclass.fadeout.call(this, options);
};

YAHOO.traction.FileGridRow.prototype.compareTo = function(other, field, asc) { 
  return -1; 
};
YAHOO.traction.FileGridRow.prototype.toString = function() { 
  return "[FileGridRow]";
};

//------------------------------------------------------------------------
// yui-traction-docmgt.FileResult

YAHOO.namespace("traction");

YAHOO.traction.FileResult = function(result, datatype) {
  if (!datatype) {
    datatype = YAHOO.traction.FileData;
  }
  if (YAHOO.lang.isString(result)) {
    this.data = YAHOO.lang.JSON.parse(result);
  } else {
    this.data = result;
  }
  var fd = this.data['filedata'];
  if (YAHOO.lang.isArray(fd)) {
    this.filedata = [];
    for (var i=0, sz=fd.length; i<sz; i++) {
      this.filedata[i] = new datatype(fd[i]);
    }
  } 
  else if (fd) {
    this.filedata = new datatype(fd);
  }
  else {
    this.filedata = null;
  }
};
YAHOO.traction.FileResult.prototype = {
  
  isSuccess: function() { 
    return this.data['success'];
  },
  getSuccessMessage: function() {
    return this.data['successMessage'];
  },
  getErrorMessage: function() {
    return this.data['errorMessage'];
  },
  getWarningMessage: function() {
    return this.data['warningMessage'];
  },
  
  getFileData: function() {
    return this.filedata;
  }
};

YAHOO.traction.FileResult.wrap = function(result, datatype) {
  var i, sz, ret, json = YAHOO.lang.isString(result) ? YAHOO.lang.JSON.parse(result) : result;
  if (YAHOO.lang.isArray(json)) {
    ret = [];
    for (i=0, sz=json.length; i<sz; i++) {
      ret[i] = new YAHOO.traction.FileResult(json[i], datatype);
    }
    if (ret.length === 1) {
      ret = ret[0];
    }
  } else {
    ret = new YAHOO.traction.FileResult(json, datatype);
  }
  return ret;
};
YAHOO.traction.FileResult.FIELDS = 
  [
   "success",
   "errorMessage",
   "successMessage",
   "warningMessage",
   "filedata"
   ];

//------------------------------------------------------------------------
// yui-traction-docmgt.MkdirDialog

YAHOO.namespace("traction");

YAHOO.traction.MkdirDialog = function(options) {
  
  this.name = null;
  
  this.saveUnder = null;
  
  this.children = [];
  options = Object.extend({
    title: i18n("cfi_dialog_mkdir_title",
		"Create New Folder"),
	helpText: i18n("cfi_dialog_mkdir_help_text",
		       "1. Choose the name of the new folder, 2. Select a location for the new folder to be created"),
	path: ""
	}, options || {});
  YAHOO.traction.MkdirDialog.superclass.constructor.call(this, "MkdirDialog", options);
};
YAHOO.extend(YAHOO.traction.MkdirDialog, YAHOO.traction.AbstractDialog);
YAHOO.traction.MkdirDialog.prototype.addControls = function() {
  var f1 = new YAHOO.traction.ControlGroup();
  f1.attach(this.form);
  f1.add(this.name = new YAHOO.traction.TextControl({tagName: "input", label: i18n("cfi_dialog_mkdir_folder_name_field_label", "New Folder Name"), name: "name", callback: { scope: this, enter: this.createClick } }));
  var f2 = new YAHOO.traction.ControlGroup();
  f2.attach(this.form);
  f2.add(this.saveUnder = new YAHOO.traction.SaveUnder());
  var f3 = new YAHOO.traction.ControlGroup({ className: "fields inline submit"});
  f3.attach(this.form);
  f3.add(new YAHOO.traction.AbstractButtonOrLink({ buttonText: i18n("cfi_dialog_mkdir_button_value", "Create New Directory"),
						     callback: { scope: this, 
						       buttonClick: this.createClick, 
						       linkClick: this.close
						       }
						 }));
  this.children = [ f1, f2, f3 ];
};
YAHOO.traction.MkdirDialog.prototype.show = function() {
  this.saveUnder.setValue(this.options.path);
  YAHOO.traction.MkdirDialog.superclass.show.call(this);
  this.name.focus();  
};

YAHOO.traction.MkdirDialog.prototype.createClick = function() {
  YAHOO.traction.FileController.mkdir(this.form.name.value, this.saveUnder.getValue());
  this.close();
};

YAHOO.traction.MkdirDialog.prototype.setFileData = function(filedata) {
  for (var i=0, sz=this.children.length; i<sz; i++) {
    this.children[i].refresh(filedata);
  }
};

//------------------------------------------------------------------------
// yui-traction-docmgt.NewAccountDialog

YAHOO.namespace("traction");
YAHOO.traction.NewAccountDialog = function(options) {
  
  this.children = [];
  
  this.name = null;
  this.dispname = null;
  this.activate = null;
  this.desc = null;
  options = Object.extend({
    title: i18n("create_new_project_tool_Create_New_Account_button_value", "Create New Account"),
    width: "440px",
    close: false
	}, options || {});
  YAHOO.traction.NewAccountDialog.superclass.constructor.call(this, "NewAccountDialog", {type:"newaccountctrls"}, options);
};
YAHOO.extend(YAHOO.traction.NewAccountDialog, YAHOO.traction.AjaxDialog);
YAHOO.traction.NewAccountDialog.prototype.onAjaxSuccess = function(obj) {
  this.bodydiv.innerHTML = obj.responseText;
  Settings.People.Creator.init(null, this.form, true, true,  
				 {
				 scope: this,
				     success: this.onSuccess,
				     failure: this.onFailure,
				     moreOptions: this.moreOptions
				     } );
  this.center();
  this.form.newuser.focus();  
};
YAHOO.traction.AjaxDialog.prototype.onAjaxFailure = function(obj) {
  this.bodydiv.innerHTML = obj.statusText;
  this.buttons.hideButton();
};
YAHOO.traction.NewAccountDialog.prototype.addControls = function() {
  this.bodydiv.innerHTML = "loading...";
  this.form.appendChild(this.bodydiv);
  this.buttons = new YAHOO.traction.AbstractButtonOrLink({ buttonText: i18n("create_new_project_tool_Create_New_Account_button_value", "Create New Account"),
							    buttonName: "createuser",
							    callback: { scope: this, 
							      buttonClick: this.createClick, 
							      linkClick: this.close
							      }
							});
  var div = document.createElement("DIV");
  div.className = "ajaxbuttons";
  div.appendChild(this.buttons.DIV);
  this.form.appendChild(div);
};
YAHOO.traction.NewAccountDialog.prototype.show = function() {
  YAHOO.traction.NewAccountDialog.superclass.show.call(this);
  if (this.form.newuser) {
    this.form.newuser.focus();
  }
};
YAHOO.traction.NewAccountDialog.prototype.reset = function() {
  Settings.People.Creator.reset();
  this.buttons.styleNormal();  
};

YAHOO.traction.NewAccountDialog.prototype.createClick = function() {
  this.buttons.styleLoading();
  Settings.People.Creator.createNewUser();
};

YAHOO.traction.NewAccountDialog.prototype.onSuccess = function(obj) {
  this.buttons.styleLoaded();
  var userinfo = obj.userinfo;
  var userid = userinfo.id;
  var url = "/traction/profile/"+userid;
  window.location = url;
};

YAHOO.traction.NewAccountDialog.prototype.onFailure = function(obj) {
  if (obj.error != null) {
    this.buttons.styleError(obj.error);
  } else {
    this.buttons.styleNormal();
  }
};

//------------------------------------------------------------------------
// yui-traction-docmgt.NewProjectDialog

YAHOO.namespace("traction");
YAHOO.traction.NewProjectDialog = function(options) {
  
  this.children = [];
  
  this.name = null;
  this.dispname = null;
  this.activate = null;
  this.desc = null;
  options = Object.extend({
    title: i18n("create_new_project_tool_Create_New_Project_button_value", "Create New Project"),
    width: "440px",
    close: false
	}, options || {});
  YAHOO.traction.NewProjectDialog.superclass.constructor.call(this, "NewProjectDialog", {type:"newprojectctrls"}, options);
};
YAHOO.extend(YAHOO.traction.NewProjectDialog, YAHOO.traction.AjaxDialog);
YAHOO.traction.NewProjectDialog.prototype.onAjaxSuccess = function(obj) {
  this.bodydiv.innerHTML = obj.responseText;
  Settings.Projects.Creator.init(null, this.form, true, true,  
				 {
				 scope: this,
				     success: this.onSuccess,
				     failure: this.onFailure,
				     moreOptions: this.moreOptions
				     } );
  template_change(this.form.newproj_template);
  Settings.Projects.Creator.syncProjectSettingSourceFieldDisplay();
  this.center();
  this.form.newproj_displayname.focus();  
};
YAHOO.traction.AjaxDialog.prototype.onAjaxFailure = function(obj) {
  this.bodydiv.innerHTML = obj.statusText;
  this.buttons.hideButton();
};
YAHOO.traction.NewProjectDialog.prototype.addControls = function() {
  this.bodydiv.innerHTML = "loading...";
  this.form.appendChild(this.bodydiv);
  this.buttons = new YAHOO.traction.AbstractButtonOrLink({ buttonText: i18n("create_new_project_tool_Create_New_Project_button_value", "Create New Project"),
							    buttonName: "newproj_add",
							    callback: { scope: this, 
							      buttonClick: this.createClick, 
							      linkClick: this.close
							      }
							});
  var div = document.createElement("DIV");
  div.className = "ajaxbuttons";
  div.appendChild(this.buttons.DIV);
  this.form.appendChild(div);
};
YAHOO.traction.NewProjectDialog.prototype.show = function() {
  YAHOO.traction.NewProjectDialog.superclass.show.call(this);
  if (this.form.newproj_displayname) {
    this.form.newproj_displayname.focus();
  }
};
YAHOO.traction.NewProjectDialog.prototype.reset = function() {
  Settings.Projects.Creator.reset();
  this.buttons.styleNormal();  
};

YAHOO.traction.NewProjectDialog.prototype.createClick = function() {
  this.buttons.styleLoading();
  Settings.Projects.Creator.createNewProject();
};

YAHOO.traction.NewProjectDialog.prototype.moreOptions = function() {
};

YAHOO.traction.NewProjectDialog.prototype.onSuccess = function(obj) {
  this.buttons.styleLoaded();
  var pinfo = obj.projectinfo;
  var pname = pinfo.name;
  var url = "/traction/project/"+pname;
  window.location = url;
};

YAHOO.traction.NewProjectDialog.prototype.onFailure = function(obj) {
  if (obj.error != null) {
    this.buttons.styleError(obj.error);
  } else {
    this.buttons.styleNormal();
  }
};

//------------------------------------------------------------------------
// yui-traction-docmgt.panel.AbstractBox

YAHOO.namespace("traction");
YAHOO.traction.AbstractBox = function(options) {
  
  this.DIV = null;
  
  this.container = null;
  
  this.titleContainer = null;
  this.setOptions(options);
};
YAHOO.traction.AbstractBox.prototype = {
  
  setOptions: function(options) {
    this.options = Object.extend({
      className: "box",
      tClassName: "t",
      cClassName: "content",
      bClassName: "b",
      toggle: false,
      title: ""
	  }, options || {});
  },
  build: function() {
    this.DIV = document.createElement("DIV");
    this.DIV.className = this.options.className;
    this.DIV.style.display = "none";
    this.t = document.createElement("DIV");
    this.t.className = this.options.tClassName;
    this.DIV.appendChild(this.t);
    var tdiv = document.createElement("DIV");
    this.t.appendChild(tdiv);
    if (this.options.title) {
      var h2 = document.createElement("h2");
      this.titleContainer = h2;
      this.titleContainer.innerHTML = this.options.title;
      this.DIV.appendChild(h2);
    }    
    this.container = document.createElement("DIV");
    this.container.className = "content";
    this.DIV.appendChild(this.container);
    this.b = document.createElement("DIV");
    this.b.className = this.options.bClassName;
    this.DIV.appendChild(this.b);
    var bdiv = document.createElement("DIV");
    this.b.appendChild(bdiv);
    this.addControls(this.container);
  },
  setTitle: function(title) {
    this.options.title = title;
    Util.setHtml(this.titleContainer, title);
  },
  show: function() {
    Util.show(this.DIV);
  },
  hide: function() {
    Util.hide(this.DIV);
  },
  isVisible: function() {
    return Util.isVisible(this.DIV);
  },
  
  addControls: function(container) {},
  
  toggleClick: function() {},
  toString: function() {
    return "[AbstractBox]";
  }
};

//------------------------------------------------------------------------
// yui-traction-docmgt.panel.UploadsBox

YAHOO.namespace("traction");
YAHOO.traction.UploadsBox = function(afterId, options) {
  if (YAHOO.traction.UploadsBox.singleton) {
    YAHOO.traction.UploadsBox.singleton.kill();
  }
  YAHOO.traction.UploadsBox.singleton = this;
  
  this.afterId = afterId;
  
  this.rowset = null;
  
  this.table = null;
  this.tbody = null;
  options = Object.extend({
    title: i18n("cfi_panel_uploads_label", "Uploads"),
	toggle: true
	}, options || {});
  YAHOO.traction.UploadsBox.superclass.constructor.call(this, options);
  
  YAHOO.traction.FileController.fileResultEvent.subscribe(this.onControllerResult, this, true);
  YAHOO.traction.FileController.fileUploadEvent.subscribe(this.onControllerUpload, this, true);  
  
  YAHOO.util.Event.onDOMReady(this.onDOMReady, this, true);
};
YAHOO.extend(YAHOO.traction.UploadsBox, YAHOO.traction.AbstractBox);
YAHOO.traction.UploadsBox.prototype.kill = function() {
  this.DIV = null;
  this.container = null;
  this.titleContainer = null;
  this.rowset = null;
  this.table = null;
  this.tbody = null;
  this.options = null;
  YAHOO.traction.FileController.fileResultEvent.unsubscribe(this.onControllerResult, this);
  YAHOO.traction.FileController.fileUploadEvent.unsubscribe(this.onControllerUpload, this);    
};
YAHOO.traction.UploadsBox.prototype.onDOMReady = function() {
  this.build();
  this.rowset = new YAHOO.traction.RowSet(YAHOO.traction.UploadsBoxRow, this.tbody);
  this.rowset.setFadeoutOptions({backgroundColor:"",delay:4.0,dim:false});
  this.rowset.subscribe("sizeChangeEvent", this.onSizeChange, this, true);
  this.rowset.subscribe("closeRowEvent", this.onCloseRow, this, true);
  this.position();
};
YAHOO.traction.UploadsBox.prototype.position = function() {
  var afterElement = document.getElementById(this.afterId);
  if (afterElement) {
    afterElement.parentNode.insertBefore(this.DIV, afterElement.nextSibling);
  }      
};
YAHOO.traction.UploadsBox.prototype.addControls = function(container) {
  this.table = document.createElement("TABLE");
  this.table.className = "uploads";
  this.tbody = document.createElement("TBODY");
  this.table.appendChild(this.tbody);
  container.appendChild(this.table);
};
YAHOO.traction.UploadsBox.prototype.onControllerResult = function(args) {
  var operation = args.method;
  if (operation == "put" || operation == "replace") {
    if (args.result.isSuccess()) {
      var newfiledata = args.result.getFileData();
      this.rowset.update(args.oldfiledata, newfiledata, false);
      this.rowset.remove(newfiledata, true);
    } else {
      this.rowset.update(args.oldfiledata);
    }
  }
};
YAHOO.traction.UploadsBox.prototype.onControllerUpload = function(args) {
  this.rowset.add(args.filedata, false);
};
YAHOO.traction.UploadsBox.prototype.onSizeChange = function(args) {
  if (args.rows > 0) {
    this.show();
  } else {
    this.hide();
  }
};

YAHOO.traction.UploadsBox.prototype.onCloseRow = function(filedata) {
  if (filedata && filedata.uploadHandle) {
    YAHOO.traction.FileController.abortUpload(filedata);
    filedata.setLastError(i18n("cfi_panel_uploads_error_message_cancelled", "Cancelled"));
    filedata.uploadHandle = null;
    this.rowset.update(filedata);
    this.rowset.remove(filedata, true);
  } else {
    this.rowset.remove(filedata, false);    
  }
};
YAHOO.traction.UploadsBox.prototype.fake = function() {
  this.fakerow("/db/share/automobiles/armedinfo.gif");
  this.fakerow("/db/share/pharmafun/cjnssh.txt");
  this.fakerow("/db/share/welcome/this file has spaces.txt");
  this.fakerow("/db/share/automobiles/webdavlogo.jpg");
  this.show();
};
YAHOO.traction.UploadsBox.prototype.fakerow = function(url) {
  var fd = new YAHOO.traction.FileData({url:url});
  fd.uploadHandle = {};
  this.rowset.add(fd, false);
};
YAHOO.traction.UploadsBox.prototype.toString = function() {
  return "[UploadsBox]";
};

YAHOO.traction.UploadsBox.singleton = null;

//------------------------------------------------------------------------
// yui-traction-docmgt.panel.UploadsBoxRow

YAHOO.namespace("traction");

YAHOO.traction.UploadsBoxRow = function(filedata, index) {
  YAHOO.traction.UploadsBoxRow.superclass.constructor.call(this, filedata, index);
  
  this.TR = null;
  this.TD = null;
  
  this.icon = null;
  this.nameLink = null;
  this.pathLink = null;
  
  this.closeIcon = null;
  this.build();
  this.createEvent("closeEvent");
};
YAHOO.traction.UploadsBoxRow_overrides = {
  
  update: function(data) {
    this.data = data;
    this.draw();
  },
  build: function() {
    this.TR = document.createElement("TR");
    this.TR.style.display = "none";
    var td1 = document.createElement("TD");
    this.icon = document.createElement("IMG");
    td1.appendChild(this.icon);
    var td2 = document.createElement("TD");
    var div = document.createElement("DIV");
    div.style.display = "none";
    div.className = "x fr";
    var A = document.createElement("A");
    A.href = "javascript:void(0)";
    Events.attach(A, Events.Click, this, this.close);
    div.appendChild(A);
    td2.appendChild(div);
    this.closeIcon = div;
    this.nameLink = document.createElement("A");
    this.nameLink.className = "name";
    this.nameLink.target = "_blank";
    this.pathLink = document.createElement("A");
    this.pathLink.className = "path";
    this.pathLink.target = "_blank";
    td2.appendChild(this.nameLink);
    td2.appendChild(document.createElement("BR"));
    td2.appendChild(this.pathLink);
    this.TR.appendChild(td1);
    this.TR.appendChild(td2);
    this.TD = td2;
  },
  draw: function() {
    Util.show(this.closeIcon);
    if (this.data.isError()) {
      YAHOO.util.Dom.addClass(this.TR, "error");
      YAHOO.util.Dom.removeClass(this.TR, "uploading");
      this.icon.src = "/images/modern/px.gif";
      if (!this.errorDIV) {
	this.errorDIV = document.createElement("DIV");
	this.errorDIV.className = "error";
	this.TD.appendChild(this.errorDIV);
      }
      this.errorDIV.innerHTML = this.data.getLastError();
      Util.show(this.errorDIV);
    }
    else {
      if (this.errorDIV) Util.hide(this.errorDIV);
      YAHOO.util.Dom.removeClass(this.TR, "error");
      if (this.data.isUploading()) {
	YAHOO.util.Dom.addClass(this.TR, "uploading");
	this.icon.src = "/images/proteus/loading.gif";
      }
      else {
	YAHOO.util.Dom.removeClass(this.TR, "uploading");
	var ic = this.data.getIcon(true);
	this.icon.src = ic.url;
	this.icon.setAttribute("width", ic.w ? ic.w : "16");
	this.icon.setAttribute("height", ic.h ? ic.h : "16");
      }
    }
    var url = this.data.getUrl();
    var path = this.data.getPath();
    var name = this.data.getName();
    Util.setHtml(this.nameLink, Util.truncate(name, 23));
    Util.setHtml(this.pathLink, Util.truncate(path, 30));
    this.nameLink.href = url;
    this.pathLink.href = path;
    Util.show(this.TR);
  },
  close: function() {
    this.fireEvent("closeEvent", this);
  },
  toString: function() {
    return "[UploadsBoxRow]";
  }
};
YAHOO.extend(YAHOO.traction.UploadsBoxRow, YAHOO.traction.AbstractRow, YAHOO.traction.UploadsBoxRow_overrides);

//------------------------------------------------------------------------
// yui-traction-docmgt.ReplaceDialog

YAHOO.namespace("traction");

YAHOO.traction.ReplaceDialog = function(options) {
  
  this.children = [];
  this.trackVersions = null;
  this.checkInControls = null;
  options = Object.extend({
    formEnctype: "multipart/form-data",
    hiddens: { type: "filerpc", path: "", method: "replace" },
    tableId: "multi"
	}, options || {});
  YAHOO.traction.ReplaceDialog.superclass.constructor.call(this, "ReplaceDialog", options);
};
YAHOO.extend(YAHOO.traction.ReplaceDialog, YAHOO.traction.AbstractDialog);
YAHOO.traction.ReplaceDialog.prototype.addControls = function() {
  this.trackVersions = new YAHOO.traction.TrackVersions({ callback: { scope: this, click: this.trackClick }});
  var f1 = new YAHOO.traction.ControlGroup();
  f1.attach(this.form);
  f1.add(new YAHOO.traction.FileControl({label:i18n("cfi_dialog_replace_file_chooser_label", "Replace with"), name:"file00"}));
  f1.add(this.trackVersions);
  var f2 = new YAHOO.traction.ControlGroup();
  f2.attach(this.form);
  f2.add(new YAHOO.traction.CheckedOutBy());
  f2.add(new YAHOO.traction.CheckIn());
  var f3 = new YAHOO.traction.ControlGroup({ className: "fields inline submit"});
  f3.attach(this.form);
  f3.add(new YAHOO.traction.AbstractButtonOrLink({ buttonText: i18n("cfi_dialog_replace_button_value", "Replace"),
						     callback: { scope: this,
						       buttonClick: this.replaceClick,
						       linkClick: this.close
						       }
						 }));
  this.children = [ f1, f2, f3 ];
  this.checkInControls = f2;
};
YAHOO.traction.ReplaceDialog.prototype.trackClick = function(e) {
  if (this.form.vc.checked) {
    this.checkInControls.show();
  } else {
    this.checkInControls.hide();
  }
};
YAHOO.traction.ReplaceDialog.prototype.replaceClick = function(e) {
  YAHOO.traction.FileController.upload(this.form,'replace',this.options.tableId);
  this.close();
};

YAHOO.traction.ReplaceDialog.prototype.setFileData = function(filedata) {
  this.filedata = filedata;
  var title = (new MessageFormat(i18n("cfi_dialog_replace_title", "Replace: {0}"))).format(Util.truncate(filedata.getName(), 60));
  this.setTitle(title);
  this.form.path.value = filedata.getUrl();
  for (var i=0, sz=this.children.length; i<sz; i++) {
    this.children[i].refresh(filedata);
  }
  if (filedata.canVersion()) {
    this.trackVersions.show();
    if (filedata.isVersioned()) {
      this.checkInControls.show();
    } else {
      this.checkInControls.hide();
    }
  } else {
    this.trackVersions.hide();
    this.checkInControls.hide();
  }
};

//------------------------------------------------------------------------
// yui-traction-docmgt.RowSet

YAHOO.namespace("traction");

YAHOO.traction.RowSet = function(cls, parent, columns) {
  this.cls = cls;
  this.parent = parent;
  this.columns = columns;
  
  this.inMerge = false;
  
  this.rows = [];
  
  this.fadeoutOptions = null;
  
  this.comparator = null;
  this.sortchain = null;
  
  this.createEvent("sizeChangeEvent");
  this.createEvent("closeRowEvent");
};
YAHOO.traction.RowSet.prototype = {
  
  setFadeoutOptions: function(fadeoutOptions) {
    this.fadeoutOptions = fadeoutOptions;
  },
  
  setColumns: function(columns) {
    this.columns = columns;
  },
  
  size: function() { 
    var i, count=0, sz=this.rows.length;
    for (i=0; i<sz; i++) {
      if (this.rows[i].state !== -1) count++;
    }
    return count;
  },
  
  keys: function(all) {
    var i, ret=[], sz=this.rows.length;
    for (i=0; i<sz; i++) {
      if (all || this.rows[i].state !== -1){ 
	ret.push(this.rows[i].getKey());
      }
    }
    return ret;
  },
  
  states: function() {
    var i, ret=[], sz=this.rows.length;
    for (i=0; i<sz; i++) {
      ret[i] = this.rows[i].state;
    }
    return ret;
  },
  
  getRow: function(data) {
    if (YAHOO.lang.isNumber(data)) {
      return this.rows[data];
    } else {
      var index = this.findRow(data);
      return (index >= 0) ? this.rows[index] : null;
    }
  },
  
  getSelected: function(newState) {
    var i, sz, row, ret = [], setState = YAHOO.lang.isNumber(newState);
    for (i=0, sz=this.rows.length; i<sz; i++) {
      row = this.rows[i];
      if (row.isSelected()) {
	if (setState) row.setState(newState);
	ret.push(row.data);
      }
    }
    return ret;
  },
  
  setState: function(data, newState) {
    var i, sz, row;
    if (YAHOO.lang.isArray(data)) {
      for (i=0, sz=data.length; i<sz; i++) {
	row = this.getRow(data[i]);
	if (row) row.setState(newState);
      }
    }
    else {
      row = this.getRow(data);
      if (row) row.setState(newState);
    }
  },
  
  setComparator: function(comp, dir, columnIndex) {
    if (dir === -1) {
      this.comparator = function(a,b) { return -1*comp(a,b); };
    } else {
      this.comparator = comp;
    }
    if (this.sortchain === null) this.sortchain = new YAHOO.traction.SortChain();
    this.sortchain.add(comp, columnIndex);
    this.sort();
  },
  
  sort: function() {
    if (this.comparator) {
      var comp = this.comparator;
      this.rows.sort(function(a,b) { return comp(a.data,b.data); });
      for (var i=0, sz=this.rows.length; i<sz; i++) {
	this._orderRow(this.rows[i], i);
      }
    }
    this.stripe();
  },
  
  select: function(allOrNone) {
    for (var i=0, sz=this.rows.length; i<sz; i++) {
      this.rows[i].setSelected(allOrNone);
    }
  },
  
  add: function(data, animate, addindex) {
    return this.update(data, data, animate, addindex);
  },
  
  update: function(olddata, newdata, animate, addindex) {
    if (!olddata) olddata = newdata;
    if (!newdata) newdata = olddata;
    var row, 
    oldindex = this.findRow(olddata), 
    newindex = (olddata.getKey() === newdata.getKey()) ? oldindex : this.findRow(newdata);
    if (oldindex >= 0) {
      row = this.rows[oldindex];
      if (row.state == -1 && animate) {
	row.glow();
      }
      row.update(newdata, animate);
      if (newindex >= 0 && newindex != oldindex) {
	this._removeRow(newindex, true);
      }
      if (YAHOO.lang.isNumber(addindex)) {
	this._moveRow(row, oldindex, addindex);
	newindex = addindex;
      } 
      else {
	newindex = oldindex;
      }
    } 
    else if (newindex >= 0) {
      row = this.rows[newindex];
      if (row.state == -1 && animate) {
	row.glow();
      }
      row.update(newdata, animate);
      if (YAHOO.lang.isNumber(addindex)) {
	this._moveRow(row, newindex, addindex);
	newindex = addindex;
      }
    } 
    else {
      newindex = YAHOO.lang.isNumber(addindex) ? addindex : this.rows.length;
      row = new this.cls(newdata, newindex);
      this._addRow(row, newindex);
      if (animate) {
	row.glow();
      }
    }
    return newindex;
  },
  
  merge: function(datalist, animate) {
    this.inMerge = true;
    var i, sz, row, data, index, lastindex = -1;
    if (this.sortchain) {
      datalist.sort(this.sortchain.comparator());
    }
    for (i=0,sz=datalist.length; i<sz; i++) {
      lastindex = this.add(datalist[i], animate, lastindex+1);
    }
    for (i=0,sz=this.rows.length; i<sz; i++) {
      row = this.rows[i];
      data = row.data;
      index = data.findMatchingIndex(datalist);
      if (index < 0) {
	this.remove(data, animate);
      }
    }
    this.inMerge = false;
    this.stripe();
  },
  
  remove: function(data, animate, options) {
    var row, index;
    if (YAHOO.lang.isNumber(data)) {
      index = data;
    } else {
      index = this.findRow(data);
    }
    if (index >= 0) {
      row = this.rows[index];
      if (animate) {
	if (row.state != -1) {
	  row.state = -1;
	  row.subscribe("fadeoutComplete", this._removeRow, this, true);
	  row.fadeout(options || this.fadeoutOptions);
	  if (!this.inMerge) {
	    this.fireEvent("sizeChangeEvent",{size:this.size(),rows:this.rows.length});
	  }
	}
      } else {
	row.state = -1;
	this._removeRow(index);
      }
      return true;
    } else {
      return false;
    }
  },
  
  clear: function() {
    for (var i=0, sz=this.rows.length; i<sz; i++) {
      this._destroyRow(i,true);
    }
    this.rows.length = 0;
  },
  
  stripe: function() {
    if (!this.inMerge) {
      var i=0, rows=this.rows, sz=rows.length;
      for (; i<sz; i++) {
	rows[i].setIndex(i);
      }
      this.fireEvent("sizeChangeEvent",{size:this.size(),rows:sz});
    }
  },
  
  _addRow: function(row, index) {
    row.draw(this.columns);
    row.insert(this.parent, this.rows[index]);
    row.subscribe("closeEvent", this._closeRow, this, true);
    this.rows.splice(index, 0, row);
    this.stripe();
  },
  
  _moveRow: function(row, oldindex, newindex) {
    if (oldindex != newindex) {
      this.rows.splice(oldindex, 1);
      this.rows.splice(newindex, 0, row);
      this._orderRow(row, newindex);
      return true;
    } else {
      return false;
    }
  },
  _orderRow: function(row, newindex) {
    row.moveAfter((newindex > 0) ? this.rows[newindex-1] : null);
  },
  
  _closeRow: function(row) { 
    if (!row.data || !row.data.uploadHandle) {
      this._removeRow(row, true);
    }
    this.fireEvent("closeRowEvent", row.data);
  },
  
  _removeRow: function(row, force) {
    try {
    var index = this._destroyRow(row, force);
    if (index >= 0) {
      this.rows.splice(index, 1);
      this.stripe();
    }
    } catch (e) { alert(e); }
  },
  
  _destroyRow: function(row, force) { 
    var match, index;
    if (YAHOO.lang.isNumber(row)) {
      index = row;
    } else {
      index = this.findRow(row.data);
    }
    if (index >= 0) {
      match = this.rows[index];
      if (force || match.state == -1) {
	match.destroy();
	return index;
      }
    }
    return -1;
  },
  
  findRow: function(data) {
    return data ? data.findMatchingIndex(this.rows) : -1;
  }
  
  
  
  
};

YAHOO.lang.augmentProto(YAHOO.traction.RowSet, YAHOO.util.EventProvider);

//------------------------------------------------------------------------
// yui-traction-docmgt.SortChain

YAHOO.namespace("traction");

YAHOO.traction.SortChain = function() {
  
  this.chain = [];
};
YAHOO.traction.SortChain.prototype = {
  add: function(comp, columnIndex) {
    var i, sz, chain = this.chain, match = -1;
    for (i=0, sz=chain.length; i<sz; i++) {
      if (chain[i].ci === columnIndex) {
	match = i;
	break;
      }
    }
    if (match >= 0) {
      this.chain.splice(match, 1);
    }
    this.chain.unshift({ci:columnIndex,comp:comp});
  },
  comparator: function() {
    var chain = this.chain;
    return function(a,b) {
      for (var cur, i=0, sz=chain.length; i<sz; i++) {
	cur = chain[i].comp(a,b);
	if (cur !== 0) {
	  return cur;
	} 
      }
      return 0;
    };
  }
};

//------------------------------------------------------------------------
// yui-traction-docmgt.Thead

YAHOO.namespace("traction");

YAHOO.traction.Thead = function(thead) {
  this.thead = thead;
  this.ths = thead.getElementsByTagName("TH");
  Events.attach(thead, Events.Click, this, this.onclick);
  
  this.sorted = -1;
  
  this.direction = 0;
  
  this.clickEvent = new YAHOO.util.CustomEvent("clickEvent", this, false, YAHOO.util.CustomEvent.FLAT);
};
YAHOO.traction.Thead.prototype = {
  destroy: function() {
    YAHOO.util.Event.purgeElement(this.thead);
    this.thead = null;
    this.ths = null;
    this.clickEvent = null;
  },
  onclick: function(e) {
    var target = YAHOO.util.Event.getTarget(e),
    match = this.findTabIndex(target),
    i, sz, tab;
    if (match >= 0) {
      this.clickEvent.fire({index:match});
    }
  },
  
  findTabIndex: function(el) {
    if (el) {
      var i, sz, th, ths=this.ths;
      for (i=0, sz=ths.length; i<sz; i++) {
	th = ths[i];
	if (th == el || YAHOO.util.Dom.isAncestor(th, el)) {
	  return i;
	}
      }
    }
    return -1;
  },
  
  isSorted: function(index) {
    return (index === this.sorted) ? this.direction : 0;
  },
  
  setSorted: function(index, direction) {
    if (this.sorted >= 0) {
      YAHOO.util.Dom.removeClass(this.ths[this.sorted], "asc");
      YAHOO.util.Dom.removeClass(this.ths[this.sorted], "desc");
    }
    YAHOO.util.Dom.addClass(this.ths[index], direction === -1 ? "asc" : "desc");    
    this.sorted = index;
    this.direction = direction;
  }
};

//------------------------------------------------------------------------
// yui-traction-docmgt.UploadDialog

YAHOO.namespace("traction");

YAHOO.traction.UploadDialog = function(options) {
  
  this.desc = null;
  
  this.saveUnder = null;
  
  this.children = [];
  options = Object.extend({
    title: i18n("cfi_dialog_upload_title", "Upload"),
	helpText: "",
	formEnctype: "multipart/form-data",
	tableId: "multi",
	hiddens: { type: "filerpc", method: "put" },
	webdav: 0,
	path: ""
	}, options || {});
  if (!options.helpText) {
    if (options.webdav) {
      options.helpText = i18n("cfi_dialog_upload_help_text_webdav",
			      "1. Choose a document to upload, 2. Optionally describe and add tags, 3. Select a location and upload");
    } else {
      options.helpText = i18n("cfi_dialog_upload_help_text_fs",
			      "1. Choose a document to upload, 2. Select a location and upload");
    }
  }
  YAHOO.traction.UploadDialog.superclass.constructor.call(this, "UploadDialog", options);
};
YAHOO.extend(YAHOO.traction.UploadDialog, YAHOO.traction.AbstractDialog);
YAHOO.traction.UploadDialog.prototype.addControls = function() {
  var f1 = new YAHOO.traction.ControlGroup();
  f1.attach(this.form);
  f1.add(new YAHOO.traction.FileControl({label:i18n("cfi_dialog_upload_file_chooser_label", "Document"), name:"file00"}));
  if (this.options.webdav) {
    f1.add(this.desc = new YAHOO.traction.TextControl({tagName: "input", textBefore: i18n("cfi_dialog_upload_description_field_label", "Description (optional)"), name: "description0", label: "&nbsp;"}));
  }
  var f2 = new YAHOO.traction.ControlGroup();
  f2.attach(this.form);
  f2.add(this.saveUnder = new YAHOO.traction.SaveUnder());
  var f3 = new YAHOO.traction.ControlGroup({ className: "fields inline submit"});
  f3.attach(this.form);
  f3.add(new YAHOO.traction.AbstractButtonOrLink({ buttonText: i18n("cfi_dialog_upload_button_value", "Upload"),
						     callback: { scope: this, 
						       buttonClick: this.uploadClick, 
						       linkClick: this.close
						       }
						 }));
  this.children = [ f1, f2, f3 ];
};
YAHOO.traction.UploadDialog.prototype.show = function() {
  this.saveUnder.setValue(this.options.path);
  YAHOO.traction.UploadDialog.superclass.show.call(this);
};

YAHOO.traction.UploadDialog.prototype.uploadClick = function(e) {
  YAHOO.traction.FileController.upload(this.form, "put", this.options.tableId);
  this.close();
};

YAHOO.traction.UploadDialog.prototype.setFileData = function(filedata) {
  for (var i=0, sz=this.children.length; i<sz; i++) {
    this.children[i].refresh(filedata);
  }
};

//------------------------------------------------------------------------
// yui-traction-docmgt.UploadingBanner

YAHOO.namespace("traction");

YAHOO.traction.UploadingBanner = function(table, options) {
  this.div = document.createElement("div");
  this.div.style.display = "none";
  table.parentNode.insertBefore(this.div, table);
};
YAHOO.traction.UploadingBanner.prototype = {
  display: function(count) {
    if (count > 0) {
      var msg;
      if (count > 1) {
	msg = (new MessageFormat(i18n("cfi_uploading_banner_multi", "Uploading {0} files..."))).format(count);
      } else {
	msg = i18n("cfi_uploading_banner_one", "Uploading...");
      }
      this.div.innerHTML = msg;
      this.div.className = "uploading";
      this.div.style.display = "block";
    } else {
      if (this.isVisible()) {
	this.div.innerHTML = i18n("cfi_uploading_banner_complete", "Upload Complete");
	this.div.className = "uploaded";
	var me = this;
	setTimeout(function() {
		     me.div.style.display = "none";
		   }, 2000);
      }
    }
  },
  isVisible: function() {
    return this.div.style.display != "none";
  }
};

//------------------------------------------------------------------------
// yui-traction-docmgt.Util


if (!Util.areEqual) {
Util.areEqual = function(x,y) {
  var i;
  var t = typeof x;
  if (t != typeof y) return false;
  if (x === null) {
    return (y === null);
  }
  else if (y === null) {
    return false;
  }
  if (YAHOO.lang.isArray(x)) {
    if (x.length != y.length) return false;
    for (i=0; i<x.length; i++) {
      if (!Util.areEqual(x[i],y[i])) return false;
    }
    return true;
  }
  else if (t === 'object') {
    for (i in x) {
      if (YAHOO.lang.hasOwnProperty(x,i) && !Util.areEqual(x[i],y[i])) return false;
    }
    for (i in y) {
      if (YAHOO.lang.hasOwnProperty(x,i) && !Util.areEqual(x[i],y[i])) return false;
    }
    return true;
  }
  else {
    return (x == y);
  }
};}
if (!Util.stripPath) {
Util.stripPath = function(url) {
  var slash = url.lastIndexOf('/');
  return (slash >= 0) ? url.substring(slash+1) : url;
};}
if (!Util.getPath) {
Util.getPath = function(url) {
    var slash = url.lastIndexOf('/');
    return (slash >= 0) ? url.substring(0, slash + 1) : url;
};}
if (!Util.getExtension) {
Util.getExtension = function(url,notfound) {
  if (url === null) return null;
  var name = Util.stripPath(url);
  var period = name.lastIndexOf('.');
  return (period != -1) ? name.substring(period+1) : notfound;
};}
if (!Util.truncate) {
Util.truncate = function(str, maxlength, append) {
  if (str.length > maxlength) {
    if (!append) append = "...";
    return str.substring(0,maxlength-append.length) + append;
  } else {
    return str;
  }
};}

if (!Util.setHtml) {
Util.setHtml = function(elm, html) {
  if (elm.innerHTML != html) {
    elm.innerHTML = html;
    return true;
  } else {
    return false;
  }
};}

if (!Util.show) {
Util.show = function(elm, force, display) {
  if (force || elm.style.display == "none") {
    elm.style.display = display || "";
    return true;
  } else {
    return false;
  }  
};}
if (!Util.on) Util.on = Util.show;

if (!Util.hide) {
Util.hide = function(elm, force) {
  if (force || elm.style.display != "none") {
    elm.style.display = "none";
    return true;
  } else {
    return false;
  }
};}
if (!Util.off) Util.off = Util.hide;

if (!Util.display) {
Util.display = function(elm, show, force, display) {
  return show ? Util.show(elm, force, display) : Util.hide(elm, force);
};}
if (!Util.isVisible) {
Util.isVisible = function(elm) {
  return (elm && elm.style.visibility != "hidden" && elm.style.display != "none");
};}
if (!Util.isOn) {
Util.isOn = function(elm) {
  return (elm && elm.style.visibility != "hidden" && elm.style.display != "none");
};}
if (!Util.toggle) {
Util.toggle = function(elm, force, display) {
  return Util.isOn(elm) ? Util.off(elm, force, display) : Util.on(elm, force, display);
};}
if (!Form.newInput) {
Form.newInput = function(name) {
  if (YAHOO.env.ua.ie && name) {
    return document.createElement("<input name=\"" + name + "\" >");
  } else {
    var ret = document.createElement("input");
    if (name) ret.name = name;
    return ret;
  }
};}
if (!Form.newSelect) {
Form.newSelect = function(name) {
  if (YAHOO.env.ua.ie && name) {
    return document.createElement("<select name=\"" + name + "\" ></select>");
  } else {
    var ret = document.createElement("select");
    if (name) ret.name = name;
    return ret;
  }
};}
if (!Form.newTextarea) {
Form.newTextarea = function(name) {
  if (YAHOO.env.ua.ie && name) {
    return document.createElement("<textarea name=\"" + name + "\" ></textarea>");
  } else {
    var ret = document.createElement("textarea");
    if (name) ret.name = name;
    return ret;
  }
};}

//------------------------------------------------------------------------
// yui-traction-docmgt.VersionData

YAHOO.namespace("traction");

YAHOO.traction.VersionData = function(data) {
  YAHOO.traction.VersionData.superclass.constructor.call(this, data);
};
YAHOO.extend(YAHOO.traction.VersionData, YAHOO.traction.FileData);
YAHOO.traction.VersionData.prototype.getUploadName = function() {
  return this.get('n');
};

