var mfTextarea = function (id,formData) {

    /*
        inherit from base-class
    */
    var baseClass = new mariaForm_fieldBase(id,formData);
    
    for (var i in baseClass) {
        if (typeof(baseClass[i]) == "function") {
            this[i] = baseClass[i];
        }
    }
    
    //clEditor sets disabled to false on init
    var disable = false;
    if ($("#"+id).attr('disabled')) {
        disable = true;
    }
    
    if (!formData.fields[id].noWysiwyg) {
    
        //wysiwyg is enabled..
        
        var clConfig = {
            width:$("#"+id).width(),
            height:$("#"+id).height()
        };
        
        for (var i in formData.fields[id].clConfig) {
            clConfig[i] = formData.fields[id].clConfig[i];
        }
        
        //make the textarea wysiwyg
        $("#"+id).cleditor(clConfig);

        //override getter and setter to update before doing anything..
        this.setValue = function (newVal) {
            baseClass.setValue(newVal);
            $("#"+id).cleditor()[0].updateFrame();
        }
        
        this.getValue = function () {
            $("#"+id).cleditor()[0].updateTextArea();
            return baseClass.getValue();
        }
        
        //automatically create links onchange
        if (formData.fields[id].clAutoCreateLinks) {
            var txt2A = function (rawText) {
                //URLs starting with http://, https://, or ftp://
                var replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
                var replacedText = rawText.replace(replacePattern1, '<a href="$1" target="popup">$1</a>');

                //URLs starting with www. (without // before it, or it'd re-link the ones done above)
                var replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
                var replacedText = replacedText.replace(replacePattern2, '$1<a href="http://$2" target="popup">$2</a>');

                //Change email addresses to mailto:: links
                var replacePattern3 = /(\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})/gim;
                var replacedText = replacedText.replace(replacePattern3, '<a href="mailto:$1">$1</a>');

                return replacedText;
            }
            
            $("#"+id).cleditor().change(partial(function (parent) {
                parent.setValue(txt2A(parent.getValue()));
            },this));
        }

        //for easier css-styling, add the field-id as class to the container:
        $("#"+id).parent().addClass(id);

        $("#"+id).cleditor()[0].disable(disable);
        $("#"+id).attr('disabled',disable);
        
        
        //trigger the events when click or blur the wysiwyg iframe
        var ff = $('.cleditorMain.'+id).find('iframe').contents().find('body');
                
        var focusHandler = function(){
            $('#'+id).trigger('focus');            
            $(ff).focus();                        
        };
        
        $(ff).click(focusHandler);
        
        $(ff).blur(function(){
            $("#"+id).cleditor()[0].updateTextArea();
            $('#'+id).trigger('blur');            
        });
   
    }
    

    
    //override default property setter
    this.setDisabled = function (newVal) {
        if (!formData.fields[id].noWysiwyg) {
            $("#"+id).disable(newVal);
        }
        baseClass.setDisabled(newVal);
    }
    
}
