// DataOutput.js
// Javascript Behaviour for the DataOutput Control
// Copyright (c) by Matthias Hertel, http://www.mathertel.de
// This work is licensed under a BSD style license. See http://www.mathertel.de/License.aspx
// ----- 
// 10.08.2006 created by Matthias Hertel
// 25.08.2007 registering in OpenAjax added.
// 14.09.2007 eventname attribute added and propname removed.
// 18.12.2007 Simplifications and documentation.
// 02.01.2009 adding new nls support

jcl.DataOutputBehavior = {

// --- Attributes
nosubmit: false, /// <summary>Enable the ENTER Key on input elements without submitting a html-form.</summary>

datatype: "", /// <summary>The datatype of the input element.</summary>
prec: "", /// <summary>Precision for numeric types.</summary>

eventname: "", /// <summary>The local or complete event name that is used for publishing OpenAjax events.</summary>
helptext: "", /// <summary>the helptext is displayed when the field is empty and has no focus.</summary>

init: function () {
  /// <summary>Initialze the JavaScript control.</summary>
  if (this.eventname) {
    OpenAjax.hub.subscribe(jcl.BuildFullEventname(this), this.handleEvent, this);
  } // if

  this.setDatatype(this.datatype);
}, // init


// --- OpenAjax event handler ---
handleEvent: function (eventName, eventData) {
  this.setData(eventData);
}, // handleEvent


setData: function(val) {
  /// <summary>Display a new value.</summary>
  var s = this._toString(val);
  if (this.innerText != s)
    this.innerText = s;
}, // setData


setDatatype: function(newType) {
  /// <summary>If a datatype is given and if the nls functionality is present
  /// use the nls functionality to support the special datatype conversion functions.</summary>
  if (typeof(jcl.nls) != "undefined") {
    if ((newType) && (jcl.nls[newType])) {
      this.datatype = newType;
    } else {
      this.datatype = "string";
    } // if
    this._toString = jcl.nls[this.datatype].toString;
  } // if
}, // setDatatype

_toString: function (v) { return(v); }

} // jcl.DataOutputBehavior
