/**
* WBSJSBASE Class
*/
var WBSJSUTILS = {
    checkPrototype: function(version)
    {
        if(typeof version == 'undefined') version = 1.5;

        if((typeof Prototype == 'undefined') ||
        (typeof Element == 'undefined') ||
        (typeof Element.Methods == 'undefined') ||
        parseFloat(Prototype.Version.split(".")[0] + "." +
        Prototype.Version.split(".")[1]) < version)
        throw(this.Name+" requires the Prototype JavaScript framework >= "+version);
    },

    getBasePath: function(moduleName)
    {
        var myRegExp = new RegExp(moduleName+"\\.js(\\?.*)?$", "i");
        var mySelf = $A(document.getElementsByTagName("script")).find(function(s){
            return (s.src && myRegExp.test(s.src));
        });

        return (typeof mySelf != 'undefined')?mySelf.src.replace(myRegExp,''):mySelf;
    },

    require: function(libraryName,type) {

        var objHead = document.getElementsByTagName('head');
        if (objHead[0])
        {
            if(type == 'js')
            {
                var objScript = objHead[0].appendChild(document.createElement('script'));
                objScript.src = libraryName;
                objScript.type = 'text/javascript';
            }

            if(type == 'css')
            {
                var objCSS = objHead[0].appendChild(document.createElement('link'));
                objCSS.rel = 'stylesheet';
                objCSS.href = libraryName;
                objCSS.type = 'text/css';
            }
        }
    }
};

WBSJSUTILS.checkPrototype(1.5);

var WBSJSBASE = {
    moduleName: 'WBSJSBASE',
    version: '1.0',
    basePath: null,

    setOptions: function(options){
        Object.extend(this.options, options || {});
    },

    getBasePath: function(){
        if(this.moduleName)
        return WBSJSUTILS.getBasePath(this.moduleName.toLowerCase());
    },

    addCSS: function()
    {
        WBSJSUTILS.require(this.getBasePath()+this.moduleName.toLowerCase()+'.css','css');
    },

    createOverload: function(){
        /* overload div */
        this.overload = document.createElement('div');
        document.body.appendChild(this.overload);
        this.hideOverload();
        if(this.options.oveloadClassName && !Element.hasClassName(this.overload, this.options.oveloadClassName))
        Element.addClassName(this.overload, this.options.oveloadClassName);

        Element.setOpacity(this.overload,0.5);
    },

    showOverload: function(el){
        if(typeof this.overload == 'undefined')
        this.createOverload();

        if ($(el))
        {
            Position.clone(el,this.overload);
            Element.show(this.overload);
        }
    },

    hideOverload: function(){
        if (typeof this.overload != 'undefined')
        Element.hide(this.overload);
    },

    alert: function(msg,opts){
        /* example: this.alert('hello world',{width:300, height:100}); */
        /*
        var options = {className: "alphacube"};
        Object.extend(options, opts || {});
        Dialog.alert(msg,{windowParameters: options, okLabel: "cerrar",buttonClass: "wbs_alert_close"});
        */
        WBSMessage.msg(msg,opts);
    },

    modalAlert: function(msg,opts){
    	/* example: this.alert('hello world',{width:300, height:100}); */
        var options = {className: "alphacube"};
        Object.extend(options, opts || {});
        Dialog.alert(msg,{windowParameters: options, okLabel: "cerrar",buttonClass: "wbs_alert_close"});
    }
};