// DHTML ucontrol
// $Author: Thomas Stolwijk $
// $Date: 2006/12/11 00:00:00 $
// $Revision: 1.0 $
/*global UNIFACE document dojo dijit */

/*******************************************************************************
date   refnum    version who description
090130 c27216    9.ajax  jdk Error tooltip does not have "tundra" style.
090205 c27248    9.ajax  jdk acceskeys do not work & labels etc show the %sign
090305 c27328    9.ajax  fd  Move common code up in widget class inheritance tree
date   refnum    version who description
*******************************************************************************/
if (UNIFACE.loaded) 
{   
    dojo.loaded();
}
///////////////////////////////////////////////////////////////////////////////
// UNIFACE.dijit
// Namespace, as well as he dijit widget base class.
///////////////////////////////////////////////////////////////////////////////
(function(){

var g_themeDefined = false;

UNIFACE.dijit = function(fieldID) {
    // Call base class
    UNIFACE.widget.AbstractWidget.apply(this, arguments);
    // attributes
    this.control = null;
    this.initialAttributes = {};
    this.style =null;
    this.wrapperNode = null;
    // methods
};
//@c27216 UNIFACE.dijit.defaultClass = "tundra";

UNIFACE.dijit.prototype = new UNIFACE.widget.AbstractWidget();

UNIFACE.dijit.prototype.getElement = function() {
    return this.control ? this.control.focusNode : null;
};

UNIFACE.dijit.prototype.getDomNode = UNIFACE.dijit.prototype.getElement;

UNIFACE.dijit.prototype.setHtml_disabled = function(aValue) {
    try {
        var oldValue = this.control.disabled;
        this.control.setAttribute("disabled", aValue === "true");
        return oldValue;
    } catch ( e ) {  // happen for ie6
        // ignore;
    }
};

UNIFACE.dijit.prototype.setHtml_readOnly = function(aValue) {
    try {
        var oldValue = this.control.readOnly;
        this.control.setAttribute("readOnly", aValue === "true");
        return oldValue;
    } catch ( e ) {  // happen for ie6
        // ignore;
    }
};

UNIFACE.dijit.prototype.setHtmlProp = function(aProp, aValue) {
    try {
        var element = this.control.focusNode;
        if ( typeof aValue !== "boolean" && UNIFACE.luv.properties.UDOM_BOOL_PROPS[aProp] != null ) {  // pragma(allow-loose-compare)
            aValue = (aValue === "true");
        }
        var oldValue = element[aProp];
        element[aProp] = aValue;
        return oldValue;
    } catch ( e ) {  // happen for ie6
        // ignore;
    }
};

UNIFACE.dijit.prototype.setStyle_visibility = function(aValue) {  // for editbox
    try {
        var lStyle = this.control.domNode.style;
        this.setCssProperty(lStyle, "visibility", aValue);
        lStyle = this.control.focusNode.style;
        if ( UNIFACE.luv.constants.BROWSER_TYPE === "ff" ) {
            this.setCssProperty(lStyle, "visibility", aValue, "important");
        } else {
            this.setCssProperty(lStyle, "visibility", aValue, "important");
            //this.setCssProperty(lStyle, "display", aValue === "hidden" ? "none" : "");
        }
    } catch ( e ) {  // happen for ie6
        // ignore;
    }
};

UNIFACE.dijit.prototype.setValue = function(aVal) {
    if (this.control) {
        try {
            this.control.setValue(aVal);
        } catch(e) {
        }
    }
};

UNIFACE.dijit.prototype.getValue = function() {
    if (this.control) {
        var val = this.control.getValue();
        if (val != null) { // @pragma(allow-loose-compare)
            return val.toString();
        }
        return "";
    }
};

UNIFACE.dijit.prototype.initialize = function(a_placeholder) {
    
};

UNIFACE.dijit.prototype.preRender = function(a_placeholder) {
    this.wrapperNode = document.createElement("span");
    //@c27216 this.wrapperNode.className = UNIFACE.dijit.defaultClass;
    a_placeholder.parentNode.replaceChild(this.wrapperNode, a_placeholder);
    this.initialize(a_placeholder);
};

UNIFACE.dijit.prototype.doRender = function(a_placeholder) {
    var l_clsname = "";                         //@c27216
    var l_obj = this.callBack.getProperties();  //@c27216
    this.wrapperNode.appendChild(a_placeholder);
    this.control = new this.controlClass( this.initialAttributes, a_placeholder);
    this.control.startup();
    this.copyHtmlAttributes(a_placeholder);
    //@c27216 The following if statement may look weird. However I saw no other way to get it
    //working. Studied it with Ming. The true in front forces a boolean comparison
    //Possibly this is a bug in firefox 3.03 together with firebug 1.2.1
    if (!g_themeDefined ){
        if ( true && ((l_obj.uniface != null) && (l_obj.uniface.theme != null)) ){ /* pragma(allow-loose-compare) */
            if (document.body.className != null ){/* pragma(allow-loose-compare) */
                //Append theme class
                 document.body.className += " " + l_obj.uniface.theme;
            }else{
                //Set theme class
                document.body.className = l_obj.uniface.theme;
            }
            g_themeDefined = true;
        } 
    }
    //@c27216 ends              
};

UNIFACE.dijit.prototype.copyHtmlAttributes = function() {
};

///////////////////////////////////////////////////////////////////////////////
// UNIFACE.dijit.textarea
// The dijit textarea widget.
///////////////////////////////////////////////////////////////////////////////


UNIFACE.dijit.textarea = function(fieldID) {
    dojo.require("dijit.form.SimpleTextarea");
    // Call base class
    UNIFACE.dijit.apply(this, arguments);
    this.controlClass = dijit.form.SimpleTextarea;
};

UNIFACE.dijit.textarea.prototype = new UNIFACE.dijit();

UNIFACE.dijit.textarea.prototype.setStyleProp = function(aProp, aValue) {
    try {
        if (UNIFACE.luv.constants.BROWSER_TYPE === "ie" && (aProp==="backgroundColor" || aProp==="background")) {
            // The default background image under IE is not transparent.
            // Therefore it interferes with the backgroundColor property.
            // Therefore we disable the background image here, if the
            // backgroundColor property is set. 
            var lStyle = this.getStyleNode(aProp).style;
            var lFocusStyle = this.control.focusNode.style;
            this.setCssProperty(lFocusStyle, "backgroundImage", "none");
            this.setCssProperty(lFocusStyle, "backgroundColor", "transparent");
            this.setCssProperty(lStyle, "backgroundImage", "none");
        }
        UNIFACE.dijit.prototype.setStyleProp.apply(this, arguments);
    } catch ( e ) {  // happen for ie6
        // ignore;
    }
};

UNIFACE.dijit.textarea.prototype.postRender = function() {
    UNIFACE.dijit.prototype.postRender.apply(this, arguments);
    // The SimpleTextarea control does not call its setValue method
    // on leaving the field (unlike the ValidationTextBox).
    // As it is the implementation of their setValue function which
    // determines whether or not the onChange is called, it is vital
    // that the SimpleTextarea's setValue is called at appropriate times.
    // The onBlur implementation below is meant to do just that.
    this.control.onBlur = function() {
        this.setValue(this.getValue());
    };
};

UNIFACE.dijit.textarea.prototype.initStyleNodes = function() {
    this.styleNodes.push(this.control.domNode);
    if (UNIFACE.luv.constants.BROWSER_TYPE === "ie") {
         this.styleNodes.push(this.control.focusNode);
    }
};

UNIFACE.dijit.textarea.prototype.mapEvents = function() {
    UNIFACE.eventMapper.map(this.control.domNode, "ondblclick", this, "detail");
    UNIFACE.eventMapper.map(this.control, "onChange", this, "onchange");
};

UNIFACE.addWidgetCreator("UNIFACE.dijit.textarea",
                         function(fieldID, properties) {
                            return new UNIFACE.dijit.textarea(fieldID);
                         });

///////////////////////////////////////////////////////////////////////////////
// UNIFACE.dijit.richtext
// The dijit richtext widget.
///////////////////////////////////////////////////////////////////////////////


UNIFACE.dijit.richtext = function(fieldID) {
    dojo.require("dijit.form.Textarea");
    // Call base class
    UNIFACE.dijit.apply(this, arguments);
    this.controlClass = dijit.form.Textarea;
};

UNIFACE.dijit.richtext.prototype = new UNIFACE.dijit();

UNIFACE.dijit.richtext.prototype.getValue = function() {
    var l_val = UNIFACE.dijit.prototype.getValue.call(this);
    if (this.callBack.getValue() === "" && l_val === "\n") {
       return "";
    }
    return l_val;
};

UNIFACE.dijit.richtext.prototype.mapEvents = function() {
    UNIFACE.eventMapper.map(this.control.domNode, "ondblclick", this, "detail");
    UNIFACE.eventMapper.map(this.control, "onChange", this, "onchange");
};

UNIFACE.addWidgetCreator("UNIFACE.dijit.richtext",
                         function(fieldID, properties) {
                            return new UNIFACE.dijit.richtext(fieldID);
                         });

///////////////////////////////////////////////////////////////////////////////
// UNIFACE.dijit.editbox
// The dijit editbox widget.
///////////////////////////////////////////////////////////////////////////////

UNIFACE.dijit.editbox = function(fieldID, events) {
    dojo.require("dijit.form.ValidationTextBox");
    // Call base class
    UNIFACE.dijit.apply(this, arguments);
    this.controlClass = dijit.form.ValidationTextBox;
    
    // properties
    this.forceMessage = false;
    this.errorText = "";
};

UNIFACE.dijit.editbox.prototype = new UNIFACE.dijit();

UNIFACE.dijit.editbox.prototype.getElement = function() { 
    return this.control.domNode; 
};

UNIFACE.dijit.editbox.prototype.getStyleNode = function(aProp) {
    var styleNode;
    if ("color"===aProp || "cursor"===aProp || "direction"===aProp || "letterSpacing"===aProp || "textAlign"===aProp || "textDecoration"===aProp || "textIndent"===aProp || "textTransform"===aProp || "unicodeBidi"===aProp || "wordSpacing"===aProp ) {
        styleNode = this.control.focusNode;
    } else {
        styleNode = this.control.domNode;
    }
    return styleNode;
};

UNIFACE.dijit.editbox.prototype.setStyleProp = function(aProp, aValue) {  // for editbox
    var theProp = "backgroundColor";
    try {
        var lStyle = this.getStyleNode(aProp).style;
        if (UNIFACE.luv.constants.BROWSER_TYPE === "ie" && (aProp==="backgroundColor" || aProp==="background")) {
            // The default background image under IE is not transparent.
            // Therefore it interferes with the backgroundColor property.
            // Therefore we disable the background image here, if the
            // backgroundColor property (or the more general background
            // property) is set. 
            lStyle = this.getStyleNode(aProp).style;
            var lFocusStyle = this.control.focusNode.style;
            this.setCssProperty(lFocusStyle, "backgroundImage", "none");
            this.setCssProperty(lFocusStyle, "backgroundColor", "transparent");
            this.setCssProperty(lStyle, "backgroundImage", "none");
        }
        /*
        UNIFACE.dijit.prototype.setStyleProp.apply(this, arguments);
        //if ( lStyle[theProp] !== v && UNIFACE.luv.constants.BROWSER_TYPE === "ie" ) {
        if ( UNIFACE.luv.constants.BROWSER_TYPE === "ie" ) {
            if ( true || this.controlClass === dijit.form.NumberTextBox ) {
                this.setCssProperty(this.control.focusNode.parentElement.style, "backgroundImage", "none");
                this.setCssProperty(this.control.focusNode.parentElement.style, theProp, "transparent");
                //this.setCssProperty(this.control.focusNode.style, "backgroundImage", "none");
            }
            this.setCssProperty(lStyle, "backgroundImage", "none");
        }
        */
        if (UNIFACE.luv.constants.BROWSER_TYPE !== "ie" && aProp==="display" && aValue==="inline") {
            aValue = "inline-block";
        }
        this.setCssProperty(this.getStyleNode(aProp).style, aProp, aValue);
    } catch ( e ) {  // happen for ie6
        // ignore;
    }
};

UNIFACE.dijit.editbox.prototype.initStyleNodes = function() {
    this.styleNodes.push(this.control.domNode);
    this.styleNodes.push(this.control.focusNode);
    if ( UNIFACE.luv.constants.BROWSER_TYPE === "ie" ) {
         this.styleNodes.push(this.control.focusNode.parentElement);
    }
};

UNIFACE.dijit.editbox.prototype.mapEvents = function() {
    UNIFACE.eventMapper.map(this.control.domNode, "ondblclick", this, "detail");
    UNIFACE.eventMapper.map(this.control, "onChange", this, "onchange");
};

UNIFACE.dijit.editbox.prototype.showError = function(a_message) {
    this.forceMessage = true;
    this.errorText = a_message;
    this.control._hasBeenBlurred=true;
    this.control.validate(true);
    this.forceMessage = false;
};

UNIFACE.dijit.editbox.prototype.setProperties = function() {
    UNIFACE.dijit.prototype.setProperties.apply(this, arguments);
    if ( UNIFACE.luv.constants.BROWSER_TYPE === "ff" ) { // Workaround for dojo 1.1.1.
        var vNode = this.control.domNode.firstChild;
        vNode.style.overflowY = "visible";
    }
};

UNIFACE.dijit.editbox.prototype.render = function(a_placeholder) {
    UNIFACE.dijit.prototype.render.call(this, a_placeholder);

    // Closure variables for the widget's extension points
    var mySelf = this;
    var l_pRecur = false;
    this.control.isValid = function(isFocused) {
        if (mySelf.forceMessage) {
            return (!mySelf.errorText);
        }
        var lVal = mySelf.callBack.checkValue(this.getDisplayedValue());
        if (lVal.error) {
            mySelf.errorText = lVal.error.toString();
            return false;
        }
        return true;
    };
    this.control.parse = function(aVal) {
        var lVal = mySelf.callBack.checkValue(aVal);
                if (lVal.error) {
                    return aVal;
                }
                return lVal.newValue;
    };    
    this.control.getErrorMessage = function() {
        return mySelf.errorText;
    };
};

UNIFACE.addWidgetCreator("UNIFACE.dijit.editbox",
                         function(fieldID, properties) {
                            if (typeof properties == "object" && properties.multiline == "T") {
                                return new UNIFACE.dijit.textarea(fieldID);
                            } else {
                                return new UNIFACE.dijit.editbox(fieldID);
                            }
                         });

///////////////////////////////////////////////////////////////////////////////
// UNIFACE.dijit.password
// The dijit password widget.
///////////////////////////////////////////////////////////////////////////////

UNIFACE.dijit.password = function(fieldID) {
    // Call base class
    UNIFACE.dijit.editbox.apply(this, arguments);
    this.initialAttributes.type = "password";
};

UNIFACE.dijit.password.prototype = new UNIFACE.dijit.editbox();

UNIFACE.dijit.password.prototype.mapEvents = function() {
    UNIFACE.eventMapper.map(this.control.domNode, "ondblclick", this, "detail");
    UNIFACE.eventMapper.map(this.control, "onChange", this, "onchange");
};

UNIFACE.addWidgetCreator("UNIFACE.dijit.password",
                         function(fieldID, properties) {
                            return new UNIFACE.dijit.password(fieldID);
                         });

///////////////////////////////////////////////////////////////////////////////
// UNIFACE.dijit.checkbox
// The dijit checkbox widget.
///////////////////////////////////////////////////////////////////////////////

UNIFACE.dijit.checkbox = function(fieldID) {
    dojo.require("dijit.form.CheckBox");
    // Call base class
    UNIFACE.dijit.apply(this, arguments);
    // attributes
    this.controlClass = dijit.form.CheckBox;
};

UNIFACE.dijit.checkbox.prototype = new UNIFACE.dijit();

UNIFACE.dijit.checkbox.prototype.getElement = function() {
    return this.control ? this.control.domNode : null;
};

UNIFACE.dijit.checkbox.prototype.setValue = function(aVal) {
    if (this.control) {
        try {
            var l_val = aVal;
            if (typeof(aVal) == "string") {
                l_val =  (aVal.match( /^(on|yes|y|true|t|1)$/i));
            }
            this.control.setAttribute('checked', l_val);
        } catch(e) {
          //  this.calendar.setValue("");
        }
    }
};

UNIFACE.dijit.checkbox.prototype.getValue = function() {
    if (this.control) {
        return this.control.checked ? "1" : "0";
    }
};

UNIFACE.dijit.checkbox.prototype.getStyleNode = function(aProp) {
    if (aProp === "cursor") {
        return this.control.focusNode;
    }
    return this.control.domNode; 
};

UNIFACE.dijit.checkbox.prototype.initStyleNodes = function() {
    this.styleNodes = [this.control.domNode,
                       this.control.focusNode];
};

UNIFACE.dijit.checkbox.prototype.setStyle_width = function(aValue) { // ignore
};

UNIFACE.dijit.checkbox.prototype.setStyle_cursor = function(aValue) {
    try {
        var lStyle = this.control.focusNode.style;
        this.setCssProperty(lStyle, "cursor", aValue);
    } catch ( e ) {  // happen for ie6
        // ignore;
    }
};

UNIFACE.dijit.checkbox.prototype.setStyle_display = function(aValue) {
    try {
        var lStyle = this.control.domNode.style;
        if ( UNIFACE.luv.constants.BROWSER_TYPE !== "ie" && aValue === "inline" ) {
            aValue = "inline-block";
        }
        this.setCssProperty(lStyle, "display", aValue);
    } catch ( e ) {  // happen for ie6
        // ignore;
    }
};

UNIFACE.dijit.checkbox.prototype.setStyleProp = function(aProp, aValue) {
    try {
        if ( aProp.indexOf("padding") !== 0 && aProp.indexOf("background") !== 0 ) {
            UNIFACE.dijit.prototype.setStyleProp.apply(this, arguments);
        }
    } catch ( e ) {  // happen for ie6
        // ignore;
    }
};

UNIFACE.dijit.checkbox.prototype.mapEvents = function() {
    //UNIFACE.eventMapper.map(this.control, "onChange", this, "onchange");
    UNIFACE.eventMapper.map(this.control, "onClick", this, "onchange");
};

UNIFACE.addWidgetCreator("UNIFACE.dijit.checkbox",
                         function(fieldID, properties) {
                            return new UNIFACE.dijit.checkbox(fieldID);
                         });

///////////////////////////////////////////////////////////////////////////////
// UNIFACE.dijit.button
// The dijit button widget.
///////////////////////////////////////////////////////////////////////////////

UNIFACE.dijit.button = function(fieldID) {
    dojo.require("dijit.form.Button");
    // Call base class
    UNIFACE.dijit.apply(this, arguments);
    // attributes
    this.controlClass = dijit.form.Button;
};

UNIFACE.dijit.button.prototype = new UNIFACE.dijit();

UNIFACE.dijit.button.prototype.getElement = function() {
    // Consider using "attributeMap" attribute of a dojo widget
    return this.control.focusNode; 
    //return this.control.domNode; 
};

UNIFACE.dijit.button.prototype.getStyleNode = function(aProp) {
    var node;
    if ("verticalAlign" == aProp) {
        node = this.control.domNode;
    } else if ("direction"===aProp || "lineHeight"===aProp || "textDecoration"===aProp || "textIndent"===aProp || "unicodeBidi"===aProp) {
        node = this.control.focusNode.childNodes[1].firstChild;
    } else {
        node = this.control.focusNode;
    }
    return node;
};

UNIFACE.dijit.button.prototype.setStyleProp = function(aProp, aValue) {
    var strWidth = "width";
    var strHeight = "height";
    try {
        var lStyle = this.getStyleNode(aProp).style;
        var w = lStyle[strWidth];
        var h = lStyle[strHeight];
        this.setCssProperty(lStyle, aProp, aValue);
        if ( lStyle[strWidth] !== w || lStyle[strHeight] !== h ) {
            this.wrapperNode.style[strWidth] = lStyle[strWidth];
            this.wrapperNode.style[strHeight] = lStyle[strHeight];
            if ( false && aValue.indexOf("%") >= 0 ) {
                this.control.domNode.style.display = "block";
            }
        }
        if (aProp==="backgroundImage" || aProp==="backgroundAttachment" || aProp==="backgroundColor") {
            this.setCssProperty(this.control.domNode.style, aProp, aValue);
        } else if (aProp==="display" && aValue==="block") {
            this.setCssProperty(this.control.domNode.style, aProp, aValue);
        }
    } catch ( e ) {  // happen for ie6
        // ignore;
    }
};

UNIFACE.dijit.button.prototype.initStyleNodes = function() {
    this.styleNodes = [this.wrapperNode,
                       this.control.domNode,
                       this.control.focusNode,
                       this.control.focusNode.childNodes[1].firstChild];
};

UNIFACE.dijit.button.prototype.setValue = function(aVal) {
    this.value = aVal;
    if (this.control) {
        try {
            if (this.value != aVal) {
                aVal = this.accesskey(aVal,true,true);
                this.control.setLabel(aVal);
            }
        } catch(e) {
        }
    } else {
        aVal = this.accesskey(aVal,true,true);
        this.initialAttributes.label = aVal;
    }
};

UNIFACE.dijit.button.prototype.getValue = function() {
    return this.value;
};

UNIFACE.dijit.button.prototype.setHtml_readOnly = function(aValue) {
};

UNIFACE.dijit.button.prototype.setStyle_cursor = function(aValue) {
    var lStyle = this.control.focusNode.style;
    this.setCssProperty(lStyle, "cursor", aValue, aValue==="default" ? "" : "important");
};

UNIFACE.dijit.button.prototype.mapEvents = function() {
    UNIFACE.eventMapper.map(this.control, "onClick", this, "detail");
};

UNIFACE.dijit.button.prototype.postRender = function() {
    // @c27248 create invisible label. display should not be "none"!!
    // otherwise accesskey won't work.
    var l_labelElem = document.createElement("label");
    l_labelElem.htmlFor   = this.control.focusNode.id;
    l_labelElem.accessKey = this.ackey;
    this.wrapperNode.appendChild(l_labelElem);
};

UNIFACE.addWidgetCreator("UNIFACE.dijit.button",
                         function(fieldID, properties) {
                            return new UNIFACE.dijit.button(fieldID);
                         });

///////////////////////////////////////////////////////////////////////////////
// UNIFACE.dijit.dropdown
// The dijit dropdown widget.
///////////////////////////////////////////////////////////////////////////////

UNIFACE.dijit.dropdown = function(fieldID) {
    dojo.require("dojo.data.ItemFileWriteStore");
    dojo.require("dijit.form.FilteringSelect");
    // Call base class
    UNIFACE.dijit.apply(this, arguments);
    // attributes
    this.controlClass = dijit.form.FilteringSelect;
    // methods
    this.initialAttributes.store = new dojo.data.ItemFileWriteStore({data: {identifier: 'id', items:[]}});
};

UNIFACE.dijit.dropdown.prototype = new UNIFACE.dijit();

UNIFACE.dijit.dropdown.prototype.validate = function() {
    if (!this.control.isValid()) {
        return this.control.invalidMessage;
    }
};

UNIFACE.dijit.dropdown.prototype.getElement = function() {
    return this.control ? this.control.domNode : null;
};

UNIFACE.dijit.dropdown.prototype.getStyleNode = function(aProp) {
    var styleNode;
    if ("cursor"===aProp || "letterSpacing"===aProp || "textAlign"===aProp || "textDecoration"===aProp || "textIndent"===aProp || "textTransform"===aProp || "wordSpacing"===aProp) {
        styleNode = this.control.focusNode;
    } else if ("display"===aProp) {
        styleNode = this.control.domNode.parentNode;
    } else {
        styleNode = this.control.domNode;
    }
    return styleNode;
};

UNIFACE.dijit.dropdown.prototype.setStyleProp = function(aProp, aValue) {
    try {
        if (UNIFACE.luv.constants.BROWSER_TYPE === "ie" && (aProp==="backgroundColor" || aProp==="background")) {
            // The default background image under IE is not transparent.
            // Therefore it interferes with the backgroundColor property.
            // Therefore we disable the background image here, if the
            // backgroundColor property is set. 
            var lStyle = this.control.downArrowNode.style;
            this.setCssProperty(lStyle, "backgroundImage", "none");
            lStyle = this.getStyleNode(aProp).style;
            this.setCssProperty(lStyle, "backgroundImage", "none");
        }
        UNIFACE.dijit.prototype.setStyleProp.apply(this, arguments);
        if (UNIFACE.luv.constants.BROWSER_TYPE === "ie" && aProp.substring(0,4)==="font") {
            // Under IE some font related style properties also need to be set
            // explicitly on the control's focusNode.
            var domStyle = this.control.domNode.style;
            var focusStyle = this.control.focusNode.style;
            var p = domStyle.fontFamily;
            if (p && p !== "") { focusStyle.fontFamily  = p; }
            p = domStyle.fontStyle;
            if (p && p !== "") { focusStyle.fontStyle   = p; }
            p = domStyle.fontVariant;
            if (p && p !== "") { focusStyle.fontVariant = p; }
            p = domStyle.fontWeight;
            if (p && p !== "") { focusStyle.fontWeight  = p; }
        }
    } catch ( e ) {  // happen for ie6
        // ignore;
    }
};

UNIFACE.dijit.dropdown.prototype.initStyleNodes = function() {
    this.styleNodes.push(this.control.domNode);
    this.styleNodes.push(this.control.focusNode);
    if (UNIFACE.luv.constants.BROWSER_TYPE === "ie") {
         this.styleNodes.push(this.control.downArrowNode);
    }
};

UNIFACE.dijit.dropdown.prototype.setValrep = function(aValrep) {
    if (typeof aValrep == 'object' && aValrep) {
        this.initialAttributes.store = new dojo.data.ItemFileWriteStore({data: {identifier: 'id', items:[]}});
        if (this.control) {
            this.control.store = this.initialAttributes.store;
        }    
        for (var a in aValrep) if (aValrep.hasOwnProperty(a)) {
            try {
                this.initialAttributes.store.newItem({name: this.accesskey(aValrep[a],false,false), id: a});
            } catch(e) {
            }
        }
    }
};

// Get the valrep as it is according to the widget;
// that is: without consulting the callBack.
// This function is only intended for the purpose of testing.
UNIFACE.dijit.dropdown.prototype.getValrep = function() {
    if (!this.initialAttributes.store) {
        return null;
    }
    var valrep = {};
    var items = this.initialAttributes.store._arrayOfAllItems;
    for (var i = 0; i < items.length; i++) {
        valrep[items[i].id] = items[i].name;
    }
    return valrep;
};

UNIFACE.dijit.dropdown.prototype.setProperties = function() {
    UNIFACE.dijit.prototype.setProperties.apply(this, arguments);
    if ( UNIFACE.luv.constants.BROWSER_TYPE == "ff" && this.control.domNode.style.height === "") { // Workaround for dojo 1.1.1.
        var vNode = this.control.domNode.firstChild;
        vNode.style.overflowY = "visible";
    }
};

UNIFACE.dijit.dropdown.prototype.mapEvents = function() {
    UNIFACE.eventMapper.map(this.control, "onChange", this, "onchange");
};

UNIFACE.addWidgetCreator("UNIFACE.dijit.dropdown",
                         function(fieldID, properties) {
                            return new UNIFACE.dijit.dropdown(fieldID);
                         });

UNIFACE.dijit.dropdown.prototype.postRender = function() {
    UNIFACE.dijit.prototype.postRender.apply(this, arguments);
    var self = this;
    var lOpen = this.control.open;
    this.control.open = function() {
        var lRet = lOpen.apply(this, arguments);
        if ( this._popupWidget ) {
            var lPnode = this._popupWidget.domNode.parentNode;
            // Copy some text-related styles to the dropped down items.
            var popupStyle = lPnode.style;
            this._popupWidget.domNode.style.listStyleType = "none";
            var p = self.getStyleNode("color").style.color;
            if (p && p !== "") { popupStyle.color = p; }
            p = self.getStyleNode("cursor").style.cursor;
            if (p && p !== "") { popupStyle.cursor = p; }
            p = self.getStyleNode("letterSpacing").style.letterSpacing;
            if (p && p !== "") { popupStyle.letterSpacing = p; }
            p = self.getStyleNode("textAlign").style.textAlign;
            if (p && p !== "") { popupStyle.textAlign = p; }
            p = self.getStyleNode("textIndent").style.textIndent;
            if (p && p !== "") { popupStyle.textIndent = p; }
            p = self.getStyleNode("textTransform").style.textTransform;
            if (p && p !== "") { popupStyle.textTransform = p; }
            p = self.getStyleNode("wordSpacing").style.wordSpacing;
            if (p && p !== "") { popupStyle.wordSpacing = p; }
            p = self.getStyleNode("textDecoration").style.textDecoration;
            if (p && p !== "") { popupStyle.textDecoration = p; }
         }
         return lRet;
    };
};

UNIFACE.dijit.dropdown.prototype.initialize = function(a_placeholder) {
    if ( a_placeholder && typeof a_placeholder.name === "string" ) {
        this.initialAttributes.name = a_placeholder.name;
    }
    var l_props = this.callBack.getProperties();

    function setBool(a_propname) {
        var l_propName = a_propname.toLowerCase();
        if (typeof l_props[l_propName] === "string") {
            this.initialAttributes[a_propname] = !!(l_props[l_propName].match( /^(on|yes|y|true|t|1)$/i));
        }
    }
    
    setBool.call(this,"autoComplete");
    setBool.call(this,"hasDownArrow");
    setBool.call(this,"ignoreCase");
};

///////////////////////////////////////////////////////////////////////////////
// UNIFACE.dijit.listbox
// The dijit listbox widget.
///////////////////////////////////////////////////////////////////////////////

UNIFACE.dijit.listbox = function(fieldID) {
    dojo.require("dijit.form.MultiSelect");
    // Call base class
    UNIFACE.dijit.apply(this, arguments);
    // attributes
    this.controlClass = dijit.form.MultiSelect;
};

UNIFACE.dijit.listbox.prototype = new UNIFACE.dijit();

UNIFACE.dijit.listbox.prototype.setValue = function(aVal) {
    if (this.control) {
        try {
            this.control.setValue(UNIFACE.luv.util.uListToArray(aVal));
            this.control._handleOnChange(this.control.getValue(), true);            
        } catch(e) {
          //  this.control.setValue("");
        }
    }
};

UNIFACE.dijit.listbox.prototype.getValue = function() {
    if (this.control) {
        return UNIFACE.luv.util.arrayToUList(this.control.getValue());
    }
};

UNIFACE.dijit.listbox.prototype.copyHtmlAttributes = function(a_placeholder) {
    if ( a_placeholder.size != null && a_placeholder.size > 0 ) { // pragma(allow-loose-compare)
        this.getElement().size = a_placeholder.size;
    }
    if ( a_placeholder.multiple != undefined ) { // pragma(allow-loose-compare)
        this.getElement().multiple = a_placeholder.multiple;
    }
};

UNIFACE.dijit.listbox.prototype.setSyntax = function() {
    try {
        var l_syntax = this.callBack.getSyntax();
        if (l_syntax.REP != undefined) { // pragma(allow-loose-compare)
            if (this.getElement() && parseInt(l_syntax.REP.max,10) > 1 ) {
                this.getElement().multiple = (parseInt(l_syntax.REP.max,10) > 1);
            }
        }
    } catch (e) {
    }
};

UNIFACE.dijit.listbox.prototype.setValrep = function(aValrep) {
    //this.valrepData. = [];
    var a;
    if (typeof aValrep == 'object' && aValrep) {
        var vEl = this.getElement();
        if (!vEl) {
            return;
        }
        var vNodes = vEl.childNodes;
        var i = 0;
        var l = vNodes.length;
        for (a in aValrep) if (aValrep.hasOwnProperty(a)) {
            var vEl2;
            if ( i < l ) {
                vEl2 = vNodes[i];
                if (vEl2.nodeName != "option") {
                    // Replace this subnode with a proper "option" node.
                    var newOption = document.createElement("option");
                    vEl2.parentNode.replaceChild(newOption, vEl2);
                    vEl2 = newOption;
                }
                i++;
            } else {
                vEl2 = document.createElement("OPTION");
                vEl.appendChild(vEl2);
            }
            vEl2.value = a;
            vEl2.innerHTML = "";
            vEl2.appendChild(document.createTextNode(this.accesskey(aValrep[a],false,false)));
        }
        if ( i < l ) {
            var vNodes2 = [];
            for ( ; i < vNodes.length; i++) {
                vNodes2.push(vNodes[i]);
            }
            for ( i = 0; i < vNodes2.length; i++) {
                vEl.removeChild(vNodes2[i]);
            }
        }
        if ( UNIFACE.luv.constants.BROWSER_TYPE === "ie" ) {
            try { // force IE repaint
                var size = vEl.size;
                vEl.size = size + 1;
                vEl.size = size;
            } catch (e) {
            }
        }
   }
};

// Get the valrep as it is according to the widget;
// that is: without consulting the callBack.
// This function is only intended for the purpose of testing.
UNIFACE.dijit.listbox.prototype.getValrep = function() {
    var vEl = this.getElement();
    if (!vEl) {
        return null;
    }
    var valrep = {};
    var options = vEl.getElementsByTagName("option");
    for (var i = 0; i < options.length; i++) {
        valrep[options[i].value] = options[i].firstChild.nodeValue; // Value of the TextNode.
    }
    return valrep;
};

UNIFACE.dijit.listbox.prototype.initialize = function(a_placeholder) {
    this.initialAttributes.baseClass = "dijitComboBox";
};

UNIFACE.dijit.listbox.prototype.doRender = function(a_placeholder) {
    UNIFACE.dijit.prototype.doRender.apply(this, arguments);
    this.setValrep.call(this, this.callBack.getValrep());
    this.setSyntax.call(this);
};

UNIFACE.dijit.listbox.prototype.mapEvents = function() {
    UNIFACE.eventMapper.map(this.control, "onChange", this, "onchange");
};

UNIFACE.addWidgetCreator("UNIFACE.dijit.listbox",
                         function(fieldID, properties) {
                            return new UNIFACE.dijit.listbox(fieldID);
                         });

///////////////////////////////////////////////////////////////////////////////
// UNIFACE.dijit.radiogroup
// The dijit radiogroup widget.
///////////////////////////////////////////////////////////////////////////////

UNIFACE.dijit.radiogroup = function(fieldID) {
    dojo.require("dijit.form.CheckBox");
    // Call base class
    UNIFACE.dijit.apply(this, arguments);
    // attributes
    this.controlClass = dijit.form.RadioButton;
    this.initialAttributes = {};
    this.layout = {
        cols : 0,
        rows : 0,
        verticalOrdering : false
    };
    this.controls = null;
    this.wrapperNode = null;
};

UNIFACE.dijit.radiogroup.prototype = new UNIFACE.dijit();

UNIFACE.dijit.radiogroup.prototype.getElement = function() {
    return this.control.domNode;
};

UNIFACE.dijit.radiogroup.prototype.initStyleNodes = function() {
    this.styleNodes.push(this.getElement());
    for (var l_ctrl in this.controls) if (this.controls.hasOwnProperty(l_ctrl)) {
        this.styleNodes.push(this.controls[l_ctrl].domNode);
    }
};

UNIFACE.dijit.radiogroup.prototype.setStyle_cursor = function(aValue) {
    var lStyle = this.getElement().style;
    this.setCssProperty(lStyle, "cursor", aValue);
    try {
        for (var l_ctrl in this.controls) if (this.controls.hasOwnProperty(l_ctrl)) {
            lStyle = this.controls[l_ctrl].focusNode.style;
            this.setCssProperty(lStyle, "cursor", aValue);
            lStyle = this.controls[l_ctrl].labelNode.style;
            this.setCssProperty(lStyle, "cursor", aValue);
        }
    } catch ( e ) {  // happen for ie6
        // ignore;
    }
};

UNIFACE.dijit.radiogroup.prototype.setHtml_disabled = function(aValue) {
    this.setHtmlProp("disabled", aValue);
};

UNIFACE.dijit.radiogroup.prototype.setHtml_readOnly = function(aValue) {
    this.setHtmlProp("readOnly", aValue);
};

UNIFACE.dijit.radiogroup.prototype.setHtmlProp = function(aProp, aValue) {
    var oldValue;
    if ( this.controls === null ) {
        return oldValue;
    }
    var l_ctrl;
    for (l_ctrl in this.controls) if (this.controls.hasOwnProperty(l_ctrl)) {
        try {
            if ( aProp === "disabled" || aProp === "readOnly" ) {
                oldValue = this.controls[l_ctrl][aProp];
                this.controls[l_ctrl].setAttribute('disabled', aValue === "true");
            } else {
                var element = this.controls[l_ctrl].focusNode;
                if ( UNIFACE.luv.properties.UDOM_BOOL_PROPS[aProp] != null ) { // pragma(allow-loose-compare)
                    aValue = (aValue === "true");
                }
                oldValue = element[aProp];
                element[aProp] = aValue;
            }
        } catch ( e ) {  // happen for ie6
            // ignore;
        }
    }
    return oldValue;
};

UNIFACE.dijit.radiogroup.prototype.doRender = function() {
    this.initialAttributes.name = this.callBack.getId();
    this.setValrep(this.callBack.getValrep());
};

    
UNIFACE.dijit.radiogroup.insertRadio = function(aWidget, aValue, aTrElement, aAlign) {
    var l_labelText; //@c27248
    var vTdElem1 = document.createElement("TD");
    vTdElem1.className="unifaceRadioInput";
    aTrElement.appendChild(vTdElem1);
    var vElem = document.createElement("INPUT");
    vElem.value = aValue;
    vTdElem1.appendChild(vElem);
    
    var l_control = new aWidget.controlClass( aWidget.initialAttributes, vElem);
    l_control.domNode.style.cssText += ";display:-moz-inline-block"; // For -moz-inline-box probelm
    aWidget.controls[aValue] = l_control;
    
    var vTdElem2 = document.createElement("TD");
    vTdElem2.className="unifaceRadioLabel";
    aTrElement.appendChild(vTdElem2);
    
    vElem = document.createElement("LABEL");
    vElem.setAttribute("for", l_control.focusNode.id);
    l_labelText = aWidget.accesskey(aWidget.callBack.getValrep()[aValue],true,true); //@c27248
    if (this.ackey !== 0){                  //@c27248
        vElem.accessKey = aWidget.ackey;   //@c27248
    }
    vElem.innerHTML = l_labelText;
//@c27248 vElem.appendChild(document.createTextNode(l_labelText)); //@c27248
    vTdElem2.appendChild(vElem);
    l_control.labelNode = vElem;
    
    if ( aAlign && aAlign === "LEFT" ) {
        //vTdElem2.align="right";
        aTrElement.insertBefore(vTdElem2, vTdElem1);
    } else {
        aTrElement.appendChild(vTdElem2);
    }
};

UNIFACE.dijit.radiogroup.prototype.setValrep = function(a_valrep) {
    if (!this.wrapperNode) {    
        return;
    }
    
    // Kill the children
    this.wrapperNode.innerHTML = "";
    /*while (this.element.firstChild) {
        this.element.removeChild(this.element.firstChild);
    }*/
    this.controls = {};
    var a;
    if (typeof a_valrep !== 'object') {
        a_valrep = {};
    }
    var vValues = [];
    for (a in a_valrep) if (a_valrep.hasOwnProperty(a)) {
        vValues.push(a);
    }
    
    var cols = 0;
    var rows = 0;
    var verticalOrdering = false;
    
    var l_props = this.callBack.getProperties();
    if ( l_props ) {
        l_props = l_props.uniface;
    }
    if ( l_props ) {
        if ( l_props.columns ) {
            try {
                cols = parseInt(l_props.columns,10);
            } catch ( e ) {
                cols = 0;
            }
        }
        if ( l_props.rows ) {
            try {
                rows = parseInt(l_props.rows,10);
            } catch ( e1 ) {
                rows = 0;
            }
        }
        if ( cols > 0 ) {
            if (rows > 0) {
                if (rows * cols < vValues.length) {
                    rows = Math.ceil( vValues.length / cols );
                }
            } else {
                rows = Math.ceil( vValues.length / cols );
            }
        } else if ( rows > 0 ){
            cols = Math.ceil( vValues.length / rows );
        } else {
            cols = 1;
            rows = vValues.length;
        }
        if (l_props.verticalorder === "true") {
            verticalOrdering = true;
        }
    }
    this.layout.cols = cols;
    this.layout.rows = rows;
    this.layout.verticalOrdering = verticalOrdering;
    this.control = {};
    var vElem = document.createElement("TABLE");
    vElem.className = "unifaceRadioGroup";
    this.control.domNode = vElem;
    if ( UNIFACE.luv.constants.BROWSER_TYPE === "ie" ) {
        vElem.style.cssText = "display:inline;";
    } else if ( UNIFACE.luv.constants.BROWSER_TYPE === "ff" ) {
        vElem.style.cssText = "display:inline-block;";
    } else {
        vElem.style.cssText = "display:inline-table;";
    }
    this.wrapperNode.appendChild(vElem);
    vElem = document.createElement("TBODY");
    this.control.domNode.appendChild(vElem);
    
    // Fill the array of indirect indices.
    var indices = new Array(rows*cols);
    var index = 0;
    var i,j,max;
    if (verticalOrdering) {
        var itemsInLastRow = vValues.length % cols;
        if (itemsInLastRow === 0) {
            itemsInLastRow = cols;
        }
        for (j = 0; j < cols; j++) {
            max = rows;
            if (j >= itemsInLastRow) {
                max--;
            }
            for (i = 0; i < max; i++) {
                indices[i*cols+j] = index++;
            }
        }
    } else {
        var itemsInLastColumn = vValues.length % rows;
        if (itemsInLastColumn === 0) {
            itemsInLastColumn = rows;
        }
        for (i = 0; i < rows; i++) {
            max = cols;
            if (i >= itemsInLastColumn) {
                max--;
            }
            for (j = 0; j < max; j++) {
                indices[i*cols+j] = index++;
            }
        }
    }
    
    // Create the rows of radio buttons.
    max = rows*cols;
    var vElem2;
    for (i = 0; i < max; i++) {
        if (i % cols === 0) {
            vElem2 = document.createElement("TR");
            vElem.appendChild(vElem2);
        }
        var vIndex = indices[i];
        if (vIndex != null && vIndex < vValues.length) { //@pragma(allow-loose-compare)
            UNIFACE.dijit.radiogroup.insertRadio(this, vValues[vIndex], vElem2, l_props.align);
        }
    }
    this.control.focusNode = (vValues.length > 0) ? this.controls[vValues[0]].focusNode : this.control.domNode;
    
    // Map events again, because mapping is done on the individual
    // buttons, which have changed as result of this function!
    this.mapEvents();
};

// Get the valrep as it is according to the widget;
// that is: without consulting the callBack.
// This function is only intended for the purpose of testing.
UNIFACE.dijit.radiogroup.prototype.getValrep = function() {
    var valrep = {};
    var labelNode;
    var labelText;
    for (var l_ctrl in this.controls) if (this.controls.hasOwnProperty(l_ctrl)) {
        labelNode = this.controls[l_ctrl].labelNode;
        if (labelNode.textContent) {
            valrep[l_ctrl] = labelNode.textContent;     // FF
        } else if (labelNode.innerHTML) {
            valrep[l_ctrl] = labelNode.innerHTML;       // IE
        } else {
            valrep[l_ctrl] = labelNode.firstChild.nodeValue; // Last resort...
        }
    }
    return valrep;
};

UNIFACE.dijit.radiogroup.prototype.setValue = function(aVal) {
    this.value = aVal;
    if (this.controls) {
        this.applyValue();
    }
};

UNIFACE.dijit.radiogroup.prototype.applyValue = function() {
    if (typeof this.controls[this.value] != 'undefined') {
        this.controls[this.value].setAttribute('checked', true);
    } else {
        var l_ctrl;
        for (l_ctrl in this.controls) if (this.controls.hasOwnProperty(l_ctrl)) {
            this.controls[l_ctrl].setAttribute('checked', false);
        }
    }
};

UNIFACE.dijit.radiogroup.prototype.getValue = function() {
    var l_ctrl;
    var l_val = this.value;
    for (l_ctrl in this.controls) {
        if (this.controls[l_ctrl].checked ) {
            l_val = l_ctrl;
            break;
        }
    }
    return l_val;
};

UNIFACE.dijit.radiogroup.prototype.mapEvents = function() {
    for (var l_ctrl in this.controls) if ( this.controls.hasOwnProperty(l_ctrl) ) {
        UNIFACE.eventMapper.map(this.controls[l_ctrl], "onClick", this, "onchange");
    }
};

UNIFACE.addWidgetCreator("UNIFACE.dijit.radiogroup",
                         function(fieldID, properties) {
                            return new UNIFACE.dijit.radiogroup(fieldID);
                         });

///////////////////////////////////////////////////////////////////////////////
// UNIFACE.dijit.datepicker
// The dijit datepicker widget.
///////////////////////////////////////////////////////////////////////////////

UNIFACE.dijit.datepicker = function(fieldID) {
    dojo.require("dijit.form.DateTextBox");
    // Call base class
    UNIFACE.dijit.apply(this, arguments);
    // attributes
    this.controlClass=dijit.form.DateTextBox;
    // methods

};

UNIFACE.dijit.datepicker.prototype = new UNIFACE.dijit();

UNIFACE.dijit.datepicker.convertUnifaceDatePattern = function(aPattern) {
    // All patterns allowed by Uniface in a date format.
    aPattern = aPattern.replace(/[dz]?d|aa[a\*]?|mmm\*?|[mz]?m|[wz]?w|(:?xx)?xx|(:?yy)?yy|[a-z']|[dh]?h|[dn]?n|[ds]?s/gi, function(aPat) {
            // day
            aPat = aPat.replace(/[zd]d/i, "d");
            // weekday
            aPat = aPat.replace(/aaa/i, "EEE");
            aPat = aPat.replace(/aa\*/i, "EEEE");
            aPat = aPat.replace(/aa/i, "EEEEE");
            // month
            aPat = aPat.replace(/m/gi, "M");
            aPat = aPat.replace(/MMM\*/, "MMMM");
            aPat = aPat.replace(/zM/i, "MM");
            // week number
            aPat = aPat.replace(/[zw]w/i, "w");
            
            // calendar year
            aPat = aPat.replace(/YY/i, "yy");
            aPat = aPat.replace(/YYYY/i, "yyyy");

            // fiscal year
            aPat = aPat.replace(/xxxx/i, "YYYY");
            aPat = aPat.replace(/xx/i, "YY");
            
            // hour
            aPat = aPat.replace(/[zh]h/i, "H");

            // minute
            aPat = aPat.replace(/[zn]n/i, "mm");
            aPat = aPat.replace(/n/i, "m");
            
            // seconds
            aPat = aPat.replace(/[zs]s/i, "ss");
    
            // DOJO does not support quoted alphabetical characters....  :-(                 
            if (aPat === "'") {
                //aPat = "''''";
            } else { 
                // All single characters except d, month, week are illegal..
                if (/^[^dmwhs]$/i.test(aPat)) {
                    aPat = ""; //"'" + aPat + "'";
                }
            }
            return aPat;
            
        }
    );

    return aPattern;
};

UNIFACE.dijit.datepicker.prototype.setValue = function(aVal) {
    if (this.control) {
        var l_isValid = this.control.isValid;
        this.control.isValid = function() { return true; };
        try {
            // Note: a *formatted* value is supplied!
            this.control.setDisplayedValue(aVal, true);
        } catch(e) {
        } finally {
            this.control.isValid = l_isValid;
        }
    }
};

UNIFACE.dijit.datepicker.prototype.getValue = function() {
    if (this.control) {
        return this.control.getDisplayedValue().toString();
    }
};

UNIFACE.dijit.datepicker.prototype.initialize = function(a_placeholder) {
    var pattern = this.callBack.getSyntax().DISpattern;
    if (pattern == undefined) { // pragma(allow-loose-compare)
        pattern = this.callBack.getSyntax().DIS;
        if (pattern == undefined) { // pragma(allow-loose-compare)
            pattern = "dd-MMM-yyyy";
        } else {
            pattern = UNIFACE.dijit.datepicker.convertUnifaceDatePattern(pattern);
        }
        this.callBack.getSyntax().DISpattern = pattern;
    }

    if (this.initialAttributes.constraints == undefined) { // pragma(allow-loose-compare)
        this.initialAttributes.constraints = {};
    }
    this.initialAttributes.constraints.datePattern = pattern;
};

UNIFACE.dijit.datepicker.prototype.postRender = function() {
    UNIFACE.dijit.prototype.postRender.apply(this, arguments);
    
    var lOpen = this.control["_open"];  // pragma(allow-subscript-notation)
    this.control["_open"] = function() { // pragma(allow-subscript-notation)
        lOpen.apply(this, arguments);
        if ( this._picker ) {
            var l_container = document.createElement("span");
            l_container.className = "tundra";
            var lPnode = this["_picker"].domNode; /* pragma(allow-subscript-notation) */
            lPnode.parentNode.replaceChild(l_container, lPnode);
            l_container.appendChild(lPnode);
        }
    };
};

UNIFACE.dijit.datepicker.prototype.mapEvents = function() {
    UNIFACE.eventMapper.map(this.control, "onChange", this, "onchange");
};

UNIFACE.dijit.datepicker.prototype.getStyleNode = function(aProp) {
    var styleNode;
    if ("letterSpacing"===aProp || "textAlign"===aProp || "textDecoration"===aProp || "textIndent"===aProp || "textTransform"===aProp || "wordSpacing"===aProp) {
        styleNode = this.control.focusNode;
    } else {
        styleNode = this.control.domNode;
    }
    return styleNode;
};

UNIFACE.dijit.datepicker.prototype.setStyleProp = function(aProp, aValue) {
    try {
        if (UNIFACE.luv.constants.BROWSER_TYPE === "ie" && (aProp==="backgroundColor" || aProp==="background")) {
            // The default background image under IE is not transparent.
            // Therefore it interferes with the backgroundColor property.
            // Therefore we disable the background image here, if the
            // backgroundColor property is set. 
            var lStyle = this.getStyleNode(aProp).style;
            var lDOMStyle = this.control.domNode.style;
            this.setCssProperty(lDOMStyle, "backgroundImage", "none");
        }
        if (aProp==="cursor") {
            this.setCssProperty(this.control.focusNode.style, aProp, aValue);
        } else if (UNIFACE.luv.constants.BROWSER_TYPE !== "ie" && aProp==="display" && aValue==="inline") {
            aValue = "inline-block";
        }
        UNIFACE.dijit.prototype.setStyleProp.apply(this, arguments);
        if (UNIFACE.luv.constants.BROWSER_TYPE === "ie" && aProp.substring(0,4)==="font") {
            // Under IE some font related style properties also need to be set
            // explicitly on the control's focusNode.
            var domStyle = this.control.domNode.style;
            var focusStyle = this.control.focusNode.style;
            var p = domStyle.fontFamily;
            if (p && p !== "") { focusStyle.fontFamily  = p; }
            p = domStyle.fontStyle;
            if (p && p !== "") { focusStyle.fontStyle   = p; }
            p = domStyle.fontVariant;
            if (p && p !== "") { focusStyle.fontVariant = p; }
            p = domStyle.fontWeight;
            if (p && p !== "") { focusStyle.fontWeight  = p; }
        }
    } catch ( e ) {  // happen for ie6
        // ignore;
    }
};

UNIFACE.dijit.datepicker.prototype.initStyleNodes = function() {
    this.styleNodes.push(this.control.domNode);
    this.styleNodes.push(this.control.focusNode);
};

UNIFACE.addWidgetCreator("UNIFACE.dijit.datepicker",
                         function(fieldID, properties) {
                            return new UNIFACE.dijit.datepicker(fieldID, properties);
                         });

///////////////////////////////////////////////////////////////////////////////
// UNIFACE.errorWidget
// The error widget.
///////////////////////////////////////////////////////////////////////////////

UNIFACE.errorWidget = {
    show: function(a_domNode, a_message) {
        if (a_message) {
            dijit.showTooltip(a_message, a_domNode);
        } else {
            dijit.hideTooltip(a_domNode);
        }    
    },
    hide : function() {   
        if (dijit._masterTT) {
            dijit.hideTooltip(dijit._masterTT.aroundNode);
        }
    }
};

UNIFACE.extension.register("errorWidget", UNIFACE.errorWidget);

}());

