var manu = function() {
    var win;
    var tabs;
    // var button = Ext.get('imageField2');
    //var hidden = Ext.get('hiddenTest')

    // button.on('click', function(){
    //Ext.select('p').on('click', function(){											  
    manu.prototype.paragraphClicked = function(e, ids, titulo) {
        button = e//Ext.get(e.target);
        // create the window on the first click and reuse on subsequent clicks
        if (ids != "") {
            createWindow();
        } else {
            alert("El elemento seleccionado no tiene un vinculo relacionado")
            return;
        }
        function createWindow() {
            //document.getElementById('s').value = 0
            if (!win) {
                win = new Ext.Window({
                    applyTo: 'hello-win',
                    layout: 'fit',
                    width: 960,
                    height: 700,
                    plain: true,
                    collapsible: true,
                    maximizable: true,
                    closeAction: 'hide',
                    y: PS(),
                    //autoScroll: false,
                    //hide: function(){this.restore();},
                    maximize: function() {
                        if (!this.maximized) {
                            this.expand(false);
                            this.restoreSize = this.getSize();
                            this.restorePos = this.getPosition(true);
                            if (this.maximizable) {
                                this.tools.maximize.hide();
                                this.tools.restore.show();
                            }
                            this.maximized = true;
                            this.el.disableShadow();

                            if (this.dd) {
                                this.dd.lock();
                            }
                            if (this.collapsible) {
                                this.tools.toggle.hide();
                            }
                            this.el.addClass('x-window-maximized');
                            //this.container.addClass('x-window-maximized-ct');

                            this.setPosition(0, (PS() - 10));
                            this.fitContainer();
                            this.fireEvent('maximize', this);
                        }
                        return this;
                    },
                    items: tabs = new Ext.TabPanel({
                        resizeTabs: true, // turn on tab resizing
                        minTabWidth: 115,
                        tabWidth: 235,
                        tabHeighth: 1250,
                        enableTabScroll: true,
                        width: 775,
                        height: 1250,
                        //defaults: { autoScroll: true },
                        autoScroll: false,
                        plugins: new Ext.ux.TabCloseMenu()
                    }),
                    getScrollPos: function() {
                        return parseInt(this.stripWrap.dom.scrollLeft, 10) || 0;
                    },
                    buttons: [{
                        text: 'Cerrar',
                        handler: function() {                            
                            win.hide();
                        }
}]
                    });
                } else {
                    try {
                        win.y = PS();
                        win.expand(true);
                    } catch (e) { }
                }

                win.show(button);
            }
            // tab generation code
            /*var index = 0;
            while(index < 7){
            addTab();
            }*/
            addTab();
            function addTab() {
                var esta = false;
                var tabId = 0;
                var k = 0;
                var Title = replaceHtml(titulo);
                for (k = 0; k < tabs.items.length; k++) {
                    if (tabs.items.items[k].title == Title) {
                        tabId = tabs.items.items[k];
                        esta = true
                    }
                }
                if (!esta) {
                    if (tabs.items.length == 0) {
                        tabs.add({
                            title: Title,
                            iconCls: 'tabs',
                            //closable: true,
                            autoScroll: true,
                            html: '<iframe  id="if_img" width="100%" height="1650" scrolling="no" src="' + ids + '" frameborder="0"></iframe>'
                        }).show();
                        tabs.getItem(0).on('activate', function(tabItem, e) { window.top.cuentaConDiv(obtineContadorParaFichas(ids), undefined, ids); });
                    } else {
                        tabs.add({
                            title: Title,
                            iconCls: 'tabs',
                            closable: true,
                            autoScroll: true,
                            html: '<iframe  id="if_img" width="100%" height="1650" scrolling="no" src="' + ids + '" frameborder="0"></iframe>'
                        }).show();
                        tabs.getItem(k).on('activate', function(tabItem, e) { window.top.cuentaConDiv(obtineContadorParaFichas(ids), undefined, ids); });
                    }
                } else {
                    tabs.body.dom.firstChild.firstChild.firstChild.innerHTML = '<iframe  id="if_img" width="100%" height="1650" scrolling="no" src="' + ids + '" frameborder="0"></iframe>'
                    tabs.setActiveTab(tabId);
                    window.top.cuentaConDiv(obtineContadorParaFichas(ids), undefined, ids);
                }
            }

            function PS() {
                var NAV = 0;
                if (document.layers) {
                    NAV = 1;
                } else if (document.all) {
                    NAV = 2;
                }
                var v = 0;
                switch (NAV) {
                    case 0:
                        {
                            v = window.top.pageYOffset;
                        }
                        break;
                    case 1:
                        {
                            v = window.top.document.documentElement.scrollTop;
                        } break;
                    case 2:
                        {
                            v = window.top.document.body.scrollTop;
                        } break;
                    default:
                        {
                            v = 0;
                        }
                }
                return v + 10;
            }
        };

        function obtineContadorParaFichas(url) {
            try {
                var objAjax = new ajax([['url', url]], 'ObtenerContador');
                var xmlDs = objAjax.getData();
                if (xmlDs != undefined) {
                    return xmlDs;
                }
            } catch (e) {

            }
        }

        function replaceHtml(str) {
            var strRet = '';
            while (str.indexOf('&lt;p&gt;') > -1) {
                str = str.replace('&lt;p&gt;', '');
            }
            while (str.indexOf('&lt;/p&gt;') > -1) {
                str = str.replace('&lt;/p&gt;', '');
            }
            while (str.indexOf('<br>') > -1) {
                str = str.replace('<br>', '&nbsp;');
            }       
            while (str.indexOf('<br />') > -1) {
                str = str.replace('<br />', '&nbsp;');
            }                
            while (str.indexOf('<p>') > -1) {
                str = str.replace('<p>', '&nbsp;');
            }        
            while (str.indexOf('</p>') > -1) {
                str = str.replace('</p>', '&nbsp;');
            }    
            while (str.indexOf('<span style="font-size: medium;">') > -1) {
                str = str.replace('<span style="font-size: medium;">', '');
            }
            while (str.indexOf('<span style=font-size: medium;>') > -1) {
                str = str.replace('<span style=font-size: medium;>', '');
            }            
            while (str.indexOf('<span style="font-size: x-small;">') > -1) {
                str = str.replace('<span style="font-size: x-small;">', '');
            }          
            while (str.indexOf('<span style="font-size: xx-small;">') > -1) {
                str = str.replace('<span style="font-size: xx-small;">', '');
            }                 
            while (str.indexOf('<span style=font-size: xx-small;>') > -1) {
                str = str.replace('<span style=font-size: xx-small;>', '');
            }                
            while (str.indexOf('</span>') > -1) {
                str = str.replace('</span>', '');
            }    
            while (str.indexOf('<strong>') > -1) {
                str = str.replace('<strong>', '');
            }               
            while (str.indexOf('</strong>') > -1) {
                str = str.replace('</strong>', '');
            }                                                      
            return str;
        }

        //var ifra = window.frames['if_img'];
        //ifra.document.getElementById('img1').on('click', paragraphClicked);

        //	var ifra = Ext.get('if_img');
        //	ifra.dom.document.getElementById('img1').on('click', paragraphClicked);

        //Ext.select('img').on('click', paragraphClicked);

    }
var clad = new manu();
Ext.onReady(manu);