
var parcheHorrible = 1;
globalContainer = Ext.extend(globalContainerUi, {
    initComponent: function () {
        globalContainer.superclass.initComponent.call(this);
        this.content.home.setIconClass("home");
        /* Ext.getCmp("header").el.dom.innerHTML+="<div style='position:absolute; border:1px solid black; padding:5px;'>USUARIO</div>";
        un plugin parqa renderizar chekbox en grid*/
        Ext.util.Format.checkColumn = function (aValue, aMetadata, aRecord, aRowInderx, aColIndex, aStore) {
            aMetadata.css += ' x-grid3-check-col-td';
            return '<div class="x-grid3-check-col' + (aValue != null && aValue == true ? '-on' : '') + '"> </div>';
        }
        /*importante este codigo es para sobreescribir Field para q atrake el evento keypress d txtfiltro*/
        Ext.override(Ext.form.Field, {
            fireKey: function (e) {
                this.fireEvent(e.type, this, e);
            },
            initEvents: function () {
                this.el.on("focus", this.onFocus, this);
                this.el.on("blur", this.onBlur, this);
                this.el.on("keydown", this.fireKey, this);
                this.el.on("keypress", this.fireKey, this);
                this.el.on("keyup", this.fireKey, this);
                this.originalValue = this.getValue();
            }
        });

        /*---------------------------------------------------------------------------------------
        activamos las validaciones perzonalizadas.*/
        this.validacionesPersonalizadas();
        eval(activarMenuPrincipalIzquierda);

        //Ext.getCmp("mni_administration").collapse();


        Ext.get("msgbox_cargando_general_negro").setVisible(false);
        Ext.get("msgbox_cargando_general_dad").setVisible(false);

        //   Ext.select("#session_cerrarsession").on('click', function () {
        //           alert("asdsad");
        //           document.location = 'Default.aspx';
        //      });
    },
    cerrarSesion: function () {
        document.location = 'index.aspx';
    },
    onNodeClick: function (node) {
        var titulo = node.text;


        //        Ext.Ajax.request({
        //            url: '/funciones.ashx?function=getMenusContent',
        //            success: function (response, request) {
        //                var data = Ext.util.JSON.decode(response.responseText).rows[0];

        //                if (titulo == data.texto) {
        //                    var cmp = new dlgContent();
        //                    cmp.setIconClass("pestana");
        //                    this.content.add(cmp);
        //                    cmp.show();
        //                    cmp.init(data.idContent);
        //                }

        //            }
        //        });

        //eval(mniContent);
        
        mniContent(titulo);
        if (titulo == "menu") {
            var cmp = new panel_menu();
            cmp.setIconClass("pestana");
            this.content.add(cmp);
            cmp.show();
        }

        if (titulo == "menuItem") {
            var cmp = new panel_menuItem();
            cmp.setIconClass("pestana");
            this.content.add(cmp);
            cmp.show();
        }

        if (titulo == "contentType") {
            var cmp = new panel_contentType();
            cmp.setIconClass("pestana");
            this.content.add(cmp);
            cmp.show();
        }

        if (titulo == "content") {
            var cmp = new panel_content();
            cmp.setIconClass("pestana");
            this.content.add(cmp);
            cmp.show();
        }
        if (titulo == "news") {
            var cmp = new panel_news();
            cmp.setIconClass("pestana");
            this.content.add(cmp);
            cmp.show();
        }
        if (titulo == "slide") {
            var cmp = new panel_slide();
            cmp.setIconClass("pestana");
            this.content.add(cmp);
            cmp.show();
        }

        if (titulo == "user") {
            var cmp = new panel_user();
            cmp.setIconClass("pestana");
            this.content.add(cmp);
            cmp.show();
        }


    },
    validacionesPersonalizadas: function () {

        Ext.apply(Ext.form.VTypes, {

            noMayorFechaActual: function (val, field) {
                try {
                    var factual = field.getValue();
                    var fnow = new Date();
                    var tiempo = factual - fnow;

                    dia = factual.getDate();
                    mes = factual.getMonth() + 1;
                    anno = factual.getYear();
                    dia1 = fnow.getDate();
                    mes1 = fnow.getMonth() + 1;
                    anno1 = fnow.getYear();

                    return (tiempo > -1 || (dia == dia1 && mes == mes1 && anno == anno1));
                } catch (e) {
                    return false;
                }
            },
            noMayorFechaActualText: 'Debe ser una fecha mayor o igual a la actual', //mensaje de error
            noMayorFechaActualMask: / /  //regexp para filtrar los caracteres permitidos
        });
        Ext.apply(Ext.form.VTypes, {
            mayorEdad: function (val, field) {
                try {
                    var birth = field.getValue();
                    var now = new Date();
                    //numero de milisegundos en un año
                    var ONE_YEAR = 1000 * 60 * 60 * 24 * 365;
                    // convertir datos a tiempo
                    var date1_ms = birth.getTime()
                    var date2_ms = now.getTime()
                    // calcular diferencia de milisegundos
                    var difference_ms = Math.abs(date1_ms - date2_ms)
                    // convertir a años la diferencia
                    var years = difference_ms / ONE_YEAR;
                    return years >= 18;
                } catch (e) {
                    return false;
                }
            },
            mayorEdadText: 'Debe ser mayor de edad',
            mayorEdadMask: / /
        });
        Ext.apply(Ext.form.VTypes, {
            numero: function (val, field) {

            },
            numeroTex: 'Debe ser un numero',
            numeroMask: /^\d+$/
        });


        Ext.apply(Ext.form.VTypes, {
            numerodeRuc: function (val, field) {
                try {
                    if (field.getValue().length == 11) return true;
                    else return false;

                } catch (e) {
                    return false;
                }
            },
            numerodeRucText: 'Tiene que tener mas de 0 y menos de 11 caracteres',
            numerodeRucMask: /^\d+$/
        });

        Ext.apply(Ext.form.VTypes, {
            numerodeDni: function (val, field) {
                try {
                    if (field.getValue().length == 8) return true;
                    else return false;

                } catch (e) {
                    return false;
                }
            },
            numerodeDniText: 'Tiene que tener mas de 0 y menos de 9 caracteres',
            numerodeDniMask: /^\d+$/
        });
        //para passwords iguales
        Ext.apply(Ext.form.VTypes, {
            password: function (val, field) {
                if (field.initialPassField) {
                    var login = Ext.getCmp(field.initialPassField);
                    return (val == login.getValue());
                }
                return true;
            },
            passwordText: 'Contraseñas no son iguales!'
        });

    }


});

