xaphoo = function()
{
    return {
//        loadJQuery = function() {
//            //this.loadScript('jquery');
//            alert('loadJQuery');
//        },
//
//        loadScript = function(scriptURL) {
//            var script = document.createElement('script');
//            script.setAttribute("type","text/javascript");
//            script.setAttribute("src", scriptURL);
//            if (typeof script!="undefined")
//                document.getElementsByTagName("head")[0].appendChild(script);
//            }
//        },
        
        getXMLHttpRequest : function () 
        {
            var httpRequest;
            if (window.XMLHttpRequest)
            {
                //El explorador implementa la interfaz de forma nativa
                httpRequest = new XMLHttpRequest();
            } 
            else if (window.ActiveXObject)
            {
                //El explorador permite crear objetos ActiveX
                try {
                    httpRequest = new ActiveXObject("MSXML2.XMLHTTP");
                } catch (e) {
                    try {
                        httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                    } catch (e) {}
                }
            }
            if (!httpRequest)
            {
                alert("No ha sido posible crear una instancia de XMLHttpRequest");
                return null;
            }else{
                return httpRequest;
            }
            
        },

         dump : function (arr,level) {
            var dumped_text = "";
            if(!level) level = 0;
            
            //The padding given at the beginning of the line.
            var level_padding = "";
            for(var j=0;j<level+1;j++) level_padding += "    ";
            
            if(typeof(arr) == 'object') { //Array/Hashes/Objects 
                for(var item in arr) {
                    var value = arr[item];
                    
                    if(typeof(value) == 'object') { //If it is an array,
                        dumped_text += level_padding + "'" + item + "' ...\n";
                        dumped_text += dump(value,level+1);
                    } else {
                        dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
                    }
                }
            } else { //Stings/Chars/Numbers etc.
                dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
            }
            return dumped_text;
        },
        
        getContainerSize : function(containerId)
        {
            var containerSize = {};
            if (containerId != ''){
                var containerHeight = Math.floor(jQuery('#' + containerId).height() * 0.99);
                var containerWidth = Math.floor(jQuery('#' + containerId).width() * 0.99);
            }else{
                var containerHeight = Math.floor(screen.height*0.99);
                var containerWidth = Math.floor(screen.width*0.99);
            }
            containerSize.height = containerHeight;
            containerSize.width = containerWidth;
            return containerSize;
        },
        
        getScreenHeight : function () {
            var screenHeight = 0;
            if( typeof( window.innerHeight ) == 'number' ) {
              //Non-IE
              screenHeight = window.innerHeight;
            } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
              //IE 6+ in 'standards compliant mode'
              screenHeight = document.documentElement.clientHeight;
            } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
              //IE 4 compatible
              screenHeight = document.body.clientHeight;
            }
            return screenHeight;
        },
        
        getScreenWidth : function () {
            var screenWidth = 0;
            if( typeof( window.innerWidth ) == 'number' ) {
              //Non-IE
                screenWidth = window.innerWidth;
            } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
              //IE 6+ in 'standards compliant mode'
                screenWidth = document.documentElement.clientWidth;
            } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
              //IE 4 compatible
                screenWidth = document.body.clientWidth;
            }
            return screenWidth;
        },
        
        type : function(data)
        {
            //return jQuery.type(data);
            return typeof data;
        },

        count : function(data)
        {
            
            switch (this.type(data)){
                case 'array':
                    return data.length;
                    break;
                case 'object':
                    var counter = 0;
                    for (var i in data) counter++;
                    return counter;
                    break;
                default:
                    return 1;
                    break;
            }
        },
        
//        formatDate : function(date, format)
//        {
//            if (!this.isDate(date))
//            {
//                date = new Date();
//            }
//            if (!this.type(format))
//            {
//                format = 'd/m/Y';
//            }
//            return date.format(format);
//        },
//
//        formatDateTime : function(date, format)
//        {
//            if (this.type(date) != 'date')
//            {
//                date = new Date();
//            }
//            if (!this.type(format))
//            {
//                format = 'd/m/Y';
//            }
//            return date.format(format);
//        },
        
        isFunction : function(data)
        {
            if (this.type(data) == 'function'){
                return true;
            }else{
                return false;
            }
        },
        
        isDate : function(data)
        {
            if (this.type(data) == 'date'){
                return true;
            }else{
                return false;
            }
        },
        
        isDefined : function(data)
        {
            if (this.type(data) != 'undefined'){
                return true;
            }else{
                return false;
            }
        },

        isBoolean : function(data)
        {
            if (this.type(data) == 'boolean'){
                return true;
            }else{
                return false;
            }
        },
        
        isInteger : function(data)
        {
            var expression = new RegExp("^[0-9]+$");
            return expression.test(data);
        },

        isReal : function(data)
        {
            var expression = new RegExp("^[-+]?[0-9]+(\.[0-9]+)?$");
            return expression.test(data);
        },
        
        toJSON : function(data)
        {
            return JSON.parse(data);
        },
                
        JSONToString : function(data)
        {
            return JSON.stringify(data);
        },
        
        toBoolean : function(data, defaultValue)
        {
            switch (data)
            {
                case 'true':
                    return true;
                    break;
                case '1':
                    return true;
                    break;
                case 'on':
                    return true;
                    break;
                case '0':
                    return false;
                    break;
                case 'false':
                    return false;
                    break;
                case 'off':
                    return false;
                    break;
                default:
                    if (this.isBoolean(data))
                    {
                        return data;
                    } else
                    {
                        if (this.isBoolean(defaultValue))
                        {
                            return defaultValue;
                        } else
                        {
                            return false;
                        }
                    }
                    break;
            }
        },

        toInteger : function(data, defaultValue)
        {
            data = this.trim(data);
            if (this.isInteger(data))
            {
                returnValue = parseInt(data);
            } else
            {
                if (this.isInteger(defaultValue))
                {
                    returnValue = parseInt(defaultValue);
                } else
                {
                    returnValue = 0;
                }
            }
            return returnValue;
        },

        toReal : function(data, defaultValue)
        {
            data = this.trim(data);
            if (this.isReal(data))
            {
                returnValue = parseFloat(data);
            } else
            {
                if (this.isReal(defaultValue))
                {
                    returnValue = parseFloat(defaultValue);
                } else
                {
                    returnValue = 0;
                }
            }
            return returnValue;
        },

        toExplode : function(data, separator)
        {
            var explode = [];
            if (this.type(data) == 'string'){
                explode = data.split(separator);
            }
            return explode;
        },
        
        lTrim : function(data)
        {
            data = '' + data;
            data = data.replace(/^\s+/, "");
            if (data == 'undefined')
            {
                data = '';
            }
            return data;
        },

        rTrim : function(data)
        {
            data = '' + data;
            data = data.replace(/\s+$/, "");
            if (data == 'undefined')
            {
                data = '';
            }
            return data;
        },

        trim : function(data)
        {
            data = '' + data;
            data = data.replace(/^\s+|\s+$/g, "");
            if (data == 'undefined')
            {
                data = '';
            }
            return data;
        }
    };
}();


