﻿var UIUtils = function() {
    var prefixRightContentPlaceHolder = 'ctl00_RigthContentPlaceHolder_';
    var prefixLeftContentPlaceHolder = 'ctl00_LeftContentPlaceHolder_';

    return {
        Get: function(id) {
            var e = Ext.get(id) || Ext.get(prefixRightContentPlaceHolder + id) || Ext.get(prefixLeftContentPlaceHolder + id);
            return e;
        },
        
        Show: function (id) {
            var element = this.Get(id);
            if (element != null)
            {
                element.enableDisplayMode("block");
                element.show(true);
            }
        },
        
        Hide: function (id) {
            var element = this.Get(id);
            if (element != null)
            {
                element.enableDisplayMode("block");
                element.hide(true);
            }
        },
        
        Trim: function(str, chars) {
            return this.LTrim(this.RTrim(str, chars), chars);
        },

        LTrim: function(str, chars) {
            chars = chars || "\\s";
            return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
        },

        RTrim: function(str, chars) {
            chars = chars || "\\s";
            return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
        },
        
        UnescapeText: function(text) {
            return text.replace(/&apos;/g, "'").replace(/&quot;/g, '"');
        },
        
        ToProperCase: function(s) {
          return s.toLowerCase().replace(/^(.)|\s(.)/g, 
                  function($1) { return $1.toUpperCase(); });
        },
        
        CreateToolTip: function(targetId, titleText, htmlText) {
            new Ext.ToolTip({
                target: targetId,
                title: titleText,
                width: 180,
                html: htmlText,
                autoHeight: true,
                trackMouse: true,
                showDelay: 0,
                dismissDelay: 0
            });
        },
        
        ClearTextField: function(element)
        {
            element.value = '';            
        }     
    }
}();