﻿/// <reference name="MicrosoftAjax.js"/>

Type.registerNamespace("WebControls");

// This 'element' here should be the inputEl
WebControls.TextInput = function(element) {
    WebControls.TextInput.initializeBase(this, [element]);
    
    this._yuiEditor;        
}

WebControls.TextInput.prototype = {
    initialize: function() {
        WebControls.TextInput.callBaseMethod(this, 'initialize');

        var that = this;

        if (this._watermark) {
//            var elementID = this._element.id;
//            jQuery(function($){
//               $('#' + that._element.id).Watermark(that._watermark, '#777');
//            });

            $("label.overlabel").overlabel();

        }
        
        if (this._richTextEditor) {
                        
            var width = "680px";
            if (this._width) {
                width = this._width;
            }                        
            // var myEditor = new YAHOO.widget.Editor('msgpost', {
            this._yuiEditor = new YAHOO.widget.Editor(this._element.id, {
                height: '200px',
                // width: '680px', // '385px',
                width: width,
                dompath: false,
                animate: true,
                toolbar: {
                    // titlebar: 'My Editor',
                    buttons: [
                        { group: 'textstyle', label: 'Font Style',
                            buttons: [
                                { type: 'push', label: 'Bold', value: 'bold' },
                                { type: 'push', label: 'Italic', value: 'italic' },
                                { type: 'push', label: 'Underline', value: 'underline' },
                                { type: 'separator' },
                                { type: 'select', label: 'Arial', value: 'fontname', disabled: true,
                                    menu: [
                                        { text: 'Arial', checked: true },
                                        { text: 'Arial Black' },
                                        { text: 'Comic Sans MS' },
                                        { text: 'Courier New' },
                                        { text: 'Lucida Console' },
                                        { text: 'Tahoma' },
                                        { text: 'Times New Roman' },
                                        { text: 'Trebuchet MS' },
                                        { text: 'Verdana' }
                                    ]
                                },
                                { type: 'spin', label: '13', value: 'fontsize', range: [ 9, 75 ], disabled: true },
                                { type: 'separator' },
                                { type: 'color', label: 'Font Color', value: 'forecolor', disabled: true },
                                { type: 'color', label: 'Background Color', value: 'backcolor', disabled: true }
                            ]
                        }
                    ]
                }
            });
            this._yuiEditor.render();
        
        }        

    },
    dispose: function() {
        //Add custom dispose actions here
        WebControls.TextInput.callBaseMethod(this, 'dispose');
    },
    
    get_value : function() {
        if (this._richTextEditor) {
            this._yuiEditor.saveHTML();
        }
        var value = this._element.value;        
        return value;
    },
 
    set_value : function(value) {    
        if (value == null) {
            this._element.value = "";
        } else {
            this._element.value = value;
        }
        if (this._richTextEditor) {
            this._yuiEditor.setEditorHTML(value);
        }                
    },
 
    isValid : function() {
    
        var strLength = this._element.value.length;
       
        if (this._element.value == "" && ! this._allowBlankEntry) {
            return false;
        } else if(this._maximumLength != null && (strLength > this._maximumLength)) { // In case users pastes in text exceeding max length
            
            alert("Text exceeds maximumlength of " + this._maximumLength + " characters.");
            return false;
            
        } else {
            return true;
        }    
    }
    
//    isCharAllowed : function(keyChar, htmlInputControl) {
//        if (this._allowCharRegExp != null) {
//            var re = new RegExp(this._allowCharRegExp);
//            if(re.test(keyChar)) {
//                return true;
//            } else {
//                this.blinkInvalidHighlighting();
//                return false;
//            }
//        } else {
//            return true;
//        }    
//    }        

}
WebControls.TextInput.createProperty('watermark');
WebControls.TextInput.createProperty('richTextEditor');
WebControls.TextInput.createProperty('width');
// WebControls.TextInput.createProperty('watermarkLabel');
WebControls.TextInput.registerClass('WebControls.TextInput', WebControls.BaseInput);

if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();