function getElementsByClass(searchClass,node,tag) { var classElements = new Array(); if ( node == null ) node = document; if ( tag == null ) tag = '*'; var els = node.getElementsByTagName(tag); var elsLen = els.length; var pattern = new RegExp("(^|\\\\s)"+searchClass+"(\\\\s|$)"); for (i = 0, j = 0; i < elsLen; i++) { if ( pattern.test(els[i].className) ) { classElements[j] = els[i]; j++; } }return classElements; }
function parseJSON(json){return(/^[\],:{}\s]*$/.test(json.replace(/\\./g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,'')))?eval('('+json+')'):undefined}

var droptargets;
var overrides = {
// Called the instance the element is dragged.
onDoubleClick : function()
{
	alert("Test");
},
b4StartDrag : function() {
    // Cache the drag element
    if (!this.el) {
        this.el = Ext.get(this.getEl());
    }
 
    //Cache the original XY Coordinates of the element, we'll use this later.
    this.originalXY = this.el.getXY();
    // Store the original style of the item
    this.originalPos = this.el.dom.style.position;
},
// Called when element is dropped not anything other than a dropzone with the same ddgroup
onInvalidDrop : function() {
    // Set a flag to invoke the animated repair
    this.invalidDrop = true;
},
onDrag : function(e){
	this.el.dom.style.position = 'absolute';
},
// Called when the drag operation completes
endDrag : function() {
    // Invoke the animation if the invalidDrop flag is set to true
    if (this.invalidDrop === true) {
        // Remove the drop invitation
        this.el.removeClass('dropOK');
 
        // Create the animation configuration object
        var animCfgObj = {
            easing   : 'elasticOut',
            duration : 1,
            scope    : this,
            callback : function() {
                // Remove the position attribute
                this.el.dom.style.position = '';
            }
        };
 
        // Apply the repair animation
        this.el.moveTo(this.originalXY[0], this.originalXY[1], animCfgObj);
        delete this.invalidDrop;
    }
 
},
};

function updateDropTargets(item){

	var items = Ext.get(item).query(".float-inv-item");
	Ext.each(items, function(el){
		var dd = new Ext.dd.DD(el,'dropGroup',{ isTarget:false });
		Ext.apply(dd,overrides);
		Ext.get(el).on('dblclick',function(){alert("you opened up an item, description is supposed to open here")});
	});
}


function logGmView(account_id){
    var windowId = "gmlog" + account_id;
    var win;    
    if(win = Ext.WindowMgr.get(windowId)){
        win.show();
        return;
    }
	dataStore = new Ext.data.Store({
		// id: 'PresidentsDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'ajaxrequest.php',      // File to connect to
			method: 'GET'
		}),
		baseParams:{type: "log", prop: "gm", value: account_id}, // this
																	// parameter
																	// asks for
																	// listing
		reader: new Ext.data.JsonReader({   // we tell the datastore where to
											// get his data from
			root: 'results',
			totalProperty: 'total',
			id: 'atcommand_id'
		},[ 
		{name: 'account_id', type: 'int', mapping: 'account_id'},
		{name: 'atcommand_date', type: 'date', mapping: 'atcommand_date', dateFormat:"timestamp"},
		{name: 'char_id', type: 'int', mapping: 'char_id'},
		{name: 'char_name', type: 'string', mapping: 'char_name'},
		{name: 'command', type: 'string', mapping: 'command'},
		{name: 'map', type: 'string', mapping: 'map'}
		]),
		sortInfo:{field: 'atcommand_date', direction: "DESC"}
	});
	
	columnModel = new Ext.grid.ColumnModel(
		[{
			header: 'Date',
			readOnly: true,
			dataIndex:'atcommand_date',
			renderer: Ext.util.Format.dateRenderer('Y-m-d G:i:s'),
			width: 150,
			
			hidden: false
		},{
			header: 'Account ID',
			readOnly: true,
			dataIndex: 'account_id', // this is where the mapped name is
						// important!
			width: 50,
			hidden: true
		},{
			header: 'Character Name',
			sortable: false,
			dataIndex: 'char_name',
			width: 150
// editor: new Ext.form.TextField({ // rules about editing
	// allowBlank: false,
		// maxLength: 24,
			// maskRe: /([a-zA-Z0-9\s]+)$/ // alphanumeric + spaces allowed
// })
		},{
			header: 'Character ID',
			readOnly: true,
			dataIndex: 'char_id',
			width: 50,
			hidden: true                      // we don't necessarily want to
												// see this...
		},{
			header: 'Map Name',
			dataIndex: 'map',
			width: 150,
			readOnly: true
		},{
			header: 'Command',
			dataIndex: 'command',
			width: 150,
			readonly: true
		
		}]);
//	columnModel.defaultSortable= true;
	
	
	editorGrid =  new Ext.grid.EditorGridPanel({
// id: 'gmlog_' + account_id,
		store: dataStore,     // the datastore is defined here
		cm: columnModel,      // the columnmodel is defined here
		enableColLock:false,
		clicksToEdit:2,
		selModel: new Ext.grid.RowSelectionModel({singleSelect:false})
	});

	win = new Ext.Window({
		id: windowId,
		title: 'GM Logs for Account Id ' + account_id,
		closable:true,
		width:700,
		height:350,
		plain:true,
		layout: 'fit',
		items: editorGrid,  // We'll just put the grid in for now...
		bbar: new Ext.PagingToolbar({
			pageSize: 20,
			store: dataStore,
			displayInfo: true
		})

	});

	dataStore.load({params: {start: 0, limit: 15}});      // Load the data
	win.show();   // Display our window



}

function inventoryView(char_id, type, title){
    var windowId = "inventoryView_" + char_id + "_" + type;
    var win;    
    if(win = Ext.WindowMgr.get(windowId)){
        win.show();
        return;
    }
    
    function loadStuff(tcomp){
        var item_layout = ['id','item_name','amount','category','item_id','identify'];
        var store = new Ext.data.JsonStore({ url: 'ajaxrequest.php?type=' + type + '&value=' + char_id + '&prop=' + tcomp.type, fields: item_layout });
        tabs.getEl().mask('Parsing '+ title + '...');
        store.load({callback: addItem,scope:  tcomp});
    }

    function addItem(drecords){
        var tpl = new Ext.XTemplate("<div style='background-image:url(items/{item_id}.png)' class='float-inv-item' id='inv_id_{id}'>{amount}</div>");
        for(i=0; i< drecords.length; i++){
            var item = drecords[i].data;
            this.body.insertHtml('beforeEnd',tpl.apply(item));
            var some = new Ext.ToolTip({
                target:         'inv_id_'   + item.id,
                title:          'Name: '     + item.item_name,
                width:          200,
                html:           'Amount: '    + item.amount,
                trackMouse:     true
            });
        }
        tabs.getEl().unmask(true);
        updateDropTargets(this.body);
    }

    var tabs = new Ext.TabPanel({
        region: 'center',
        margins:'3 3 3 0', 
        activeTab: 0,
        defaults:{autoScroll:true},
        items:[
            new Ext.Panel({ddGroup: "equip_" + char_id, enableDD: true, title: "Equip",type: 'equip', ent_id: char_id    , listeners:{'render':loadStuff}}),
            new Ext.Panel({ddGroup: "item_" + char_id, enableDD: true, title: "Item", type: 'item',  ent_id: char_id    , listeners:{'render':loadStuff}}),
            new Ext.Panel({ddGroup: "etc_" + char_id, enableDD: true, title: "Etc",  type: 'etc',   ent_id: char_id    , listeners:{'render':loadStuff}})
            ]
        });

    // Build the window to get things going... keep it simple and empty
    win = new Ext.Window({
        animateTarget: 'originate',
        id: windowId,
        title: 'Loading ' + title + '...',
        closable:true,
        width:260,
        height:300,
        border:false,
        plain:true,
        layout: 'fit',
        items: [tabs]
        });
        
    win.doLayout();
    win.show();    
    
    var name_url = 'ajaxrequest.php?type=character&value='+ char_id + '&prop=name';
    if(type == 'storage'){name_url = 'ajaxrequest.php?type=account&value='+ char_id + '&prop=name';}
    
   var conn = new Ext.data.Connection().request({
        url: name_url,
        method: 'GET',
        success: function(res) {
            var ret = parseJSON(res.responseText);
            if (ret === undefined)
            {
                Ext.Msg.alert('Status', 'Unable to show '+ title +' info at this time.<br />Unknown result set returned CODE: 001');
                win.close();
                return;                
            }
            win.setTitle(ret + "'s " + title);
            win.getEl().unmask(true);
        },
        failure: function() {
            win.getEl().unmask(true);
            Ext.Msg.alert('Status', 'Unable to show '+ title +' info at this time.');
            win.close();
        }
    });
}

function characterListView(account_id){
    var windowId = "charListView_" + account_id;
    var win;    
    if(win = Ext.WindowMgr.get(windowId)){
        win.show();
        return;
    }

    function loadStuff(tcomp){
        var char_layout = ['id','exist','name','slot','class','equips'];
        var store = new Ext.data.JsonStore({ url: 'ajaxrequest.php?type=characterlist&value=' + tcomp.ent_id + '&prop='+tcomp.slot, fields: char_layout });
        tcomp.getEl().mask('Parsing '+ tcomp.title + '...');
        store.load({callback: addChar,scope:  tcomp});
    }
    
    function addChar(drecords){
        var tpl = new Ext.XTemplate("<div style='background:url(imagerequest.php?ent_id={id}&image=char.png) no-repeat center center;' class='char-list-wrap'><div class='char-list-name'>{name}</div></div><div class='char-list-class'>{class}</div>");
        if(drecords[0] && drecords[0].data){
        var item = drecords[0].data;// should ONLY be one answer.. or take the
									// first...
            if(item && item.exist){
                this.body.insertHtml('beforeEnd',tpl.apply(item));
                this.getEl().on('dblclick',function(){characterView(item.id);});
            }
        }
        this.getEl().unmask(true);
    }
    var navHandler = function(direction){
        var i;
        for(i = 0; i<card.items.length; i++){
            if(card.items.items[i] == card.layout.activeItem){
            break;
            }
        }
        // set the new number/index
        i = (i+direction < 0)?i = card.items.length - 1:((i+direction > card.items.length-1)?0:i+direction);
        card.layout.setActiveItem(card.items.keys[i]);
        
    };
    var ps = [
        new Ext.Panel({
            layout:'column',
            items: [
                {title: 'Slot 1',type: 'equip', slot: 0 ,ent_id: account_id    , listeners:{'render':loadStuff},border: false,columnWidth: 0.33},
                {title: 'Slot 2',type: 'equip', slot: 1 ,ent_id: account_id    , listeners:{'render':loadStuff},border: false,columnWidth: 0.33},
                {title: 'Slot 3',type: 'equip', slot: 2 ,ent_id: account_id    , listeners:{'render':loadStuff},border: false,columnWidth: 0.34}
                ]
        }),

        new Ext.Panel({
            layout:'column',
            items: [
                {title: 'Slot 4',type: 'equip', slot: 3 ,ent_id: account_id    , listeners:{'render':loadStuff},border: false,columnWidth: 0.33},
                {title: 'Slot 5',type: 'equip', slot: 4 ,ent_id: account_id    , listeners:{'render':loadStuff},border: false,columnWidth: 0.33},
                {title: 'Slot 6',type: 'equip', slot: 5 ,ent_id: account_id    , listeners:{'render':loadStuff},border: false,columnWidth: 0.34}
                ]
        }),
    
        new Ext.Panel({
            layout:'column',
            items: [
                {title: 'Slot 7',type: 'equip', slot: 6 ,ent_id: account_id    , listeners:{'render':loadStuff},border: false,columnWidth: 0.33},
                {title: 'Slot 8',type: 'equip', slot: 7 ,ent_id: account_id    , listeners:{'render':loadStuff},border: false,columnWidth: 0.33},
                {title: 'Slot 9',type: 'equip', slot: 8 ,ent_id: account_id    , listeners:{'render':loadStuff},border: false,columnWidth: 0.34}
                ]
        })
    ]
    
    var card = new Ext.Panel({
        layout:'card',
        activeItem: 0, // make sure the active item is set on the container
						// config!
        // bodyStyle: 'padding:15px',
        defaults: {
            // applied to each contained panel, not sure why it didn't work
            border:false
        },
        // just an example of one possible navigation scheme, using buttons
        bbar: [
            {
                // id: 'move-prev',
                text: 'Back',
                handler: navHandler.createDelegate(this, [-1])
            },
            '->', // greedy spacer so that the buttons are aligned to each
					// side
            {
                // id: 'move-next',
                text: 'Next',
                handler: navHandler.createDelegate(this, [1])
            }
        ],
// the panels (or "cards") within the layout
        items: ps
    });

    win = new Ext.Window({
        animateTarget: 'originate',
        id: 'character-list_'+account_id,
        title: 'Character Listing',
        closable:true,
        width:600,
        height:260,
        border:false,
        resizable : false,
        plain:true,
        layout: 'fit',
        items: [card]
    });
    
    win.show();   
}
Ext.example = function(){
 var msgCt;

 function createBox(t, s){
 return ['<div class="msg">',
 '<div class="x-box-tl"><div class="x-box-tr"><div class="x-box-tc"></div></div></div>',
 '<div class="x-box-ml"><div class="x-box-mr"><div class="x-box-mc"><h3>', t, '</h3>', s, '</div></div></div>',
 '<div class="x-box-bl"><div class="x-box-br"><div class="x-box-bc"></div></div></div>',
 '</div>'].join('');
 }
 return {
 msg : function(title, format){
 if(!msgCt){
 msgCt = Ext.DomHelper.insertFirst(document.body, {id:'msg-div'}, true);
 }
 msgCt.alignTo(document, 't-t');
 var s = String.format.apply(String, Array.prototype.slice.call(arguments, 1));
 var m = Ext.DomHelper.append(msgCt, {html:createBox(title, s)}, true);
 m.slideIn('t').pause(1).ghost("t", {remove:true});
 },

 init : function(){
 var t = Ext.get('exttheme');
 if(!t){ // run locally?
 return;
 }
 var theme = Cookies.get('exttheme') || 'aero';
 if(theme){
 t.dom.value = theme;
 Ext.getBody().addClass('x-'+theme);
 }
 t.on('change', function(){
 Cookies.set('exttheme', t.getValue());
 setTimeout(function(){
 window.location.reload();
 }, 250);
 });

 var lb = Ext.get('lib-bar');
 if(lb){
 lb.show();
 }
 }
 };
}();
// request to confirm divorce
function confirmDivorce(char_id)
{
	function showResult(btn)
	{
		if(btn == "yes"){
			Ext.example.msg('Divorce Script', 'Processing request', btn);
			Ext.Ajax.request({url: '?act=av&opt=divorce&char_id=' + char_id,method: "POST",params: {finalize: true, char_id: char_id} });
		} else {
			Ext.example.msg('Divorce Script', 'Cancelling request', btn);
		}
	}
	Ext.MessageBox.confirm('Confirm', 'Are you sure you want to divorce this character?', showResult);
}


function characterView(char_id,activeslot){
    var windowId = "charView_" + char_id;
    var win;
    if(win = Ext.WindowMgr.get(windowId)){win.show();return;}
    function loadStatus(tcomp){
        var runInventory = 'inventoryView( ' + char_id + ',"inventory","Inventory");';
        var runCart = 'inventoryView('+ char_id +  ', "cart","Cart");';
        var statusTpl =
            "<div> \
                <div><div>Strength:</div><div>{str}</div></div>     \
                <div><div>Agility:</div><div>{agi}</div></div>      \
                <div><div>Vitality:</div><div>{vit}</div></div>     \
                <div><div>Intellect:</div><div>{int}</div></div>    \
                <div><div>Dexterity:</div><div>{dex}</div></div>    \
                <div><div>Luck:</div><div>{luk}</div></div>         \
                <div><a href='#' onclick='" + runInventory + "'>Inventory View</a></div>    \
                <div><a href='#' onclick='" + runCart +  "'>Cart View</a></div>             \
            </div>";        
        var statusXTpl = new Ext.XTemplate(statusTpl);
        var statusLayout = ['str','agi','vit','int','dex','luk'];
        var store = new Ext.data.JsonStore({ 
            url: 'ajaxrequest.php?type=character&value=' + char_id + '&prop=stats', fields: statusLayout 
            }).load({
                callback: function(drecords){
                    if(drecords[0])
                    {
                        tcomp.body.insertHtml('beforeEnd', statusXTpl.apply(drecords[0].data));
                    }
                    statusCheck = true;
                    tabs.getEl().unmask(true);
                }
            });
        tabs.getEl().mask('Parsing stats...');
    }
    function loadFamily(tcomp){
        var fatherDone  = false;
        var motherDone  = false;
        var childDone   = false;
        var partnerDone = false;
        var fatherHtml  = "";
        var motherHtml  = "";
        var childHtml   = "";
        var partnerHtml = "";
        var search_url  = "";
        tabs.getEl().mask("Loading Family");
        function cleanup(){
            if(fatherDone && motherDone && childDone && partnerDone){
                tcomp.body.insertHtml('beforeEnd',partnerHtml + fatherHtml + motherHtml + childHtml);
                tabs.getEl().unmask(true);
            }
        }
        
        function getTpl(relstring){
            var plink = "";
            if(relstring == "Partner"){
                plink = "<div><a href='?act=av&opt=divorce&char_id=" + char_id + "' onClick='confirmDivorce(" + char_id + "); return false;'>Divorce</a></div>";
            }
            return new Ext.XTemplate(
                "<div>      \
                    "+ relstring +"\
                    <div><a href='?block=yes&act=av&opt=char_info&char_id={id}' onclick='characterView({id})'>{name}</a></div>\
                    <div>{class}</div>              \
                    " + plink + "                   \
                </div>");
        }

        
        var char_layout = ['id','exist','name','slot','class','equips'];
        var ptpl = getTpl('Partner');
        var ctpl = getTpl('Child');
        var mtpl = getTpl('Mother');
        var ftpl = getTpl('Father');

        search_url = 'ajaxrequest.php?type=character&value=' + char_id + '&prop=partner';
        var store = new Ext.data.JsonStore({
        			url: search_url,
        			fields: char_layout
        			})
        			.load({
        			callback: function(drecords){
        				if(drecords[0] && drecords[0].data.exist){
        					partnerHtml = ptpl.apply(drecords[0].data);
        				}
        				partnerDone = true; cleanup();
        			}});

        search_url = 'ajaxrequest.php?type=character&value=' + char_id + '&prop=child';
        store = new Ext.data.JsonStore({ url: search_url , fields: char_layout }).load({callback: function(drecords){if(drecords[0] && drecords[0].data.exist){childHtml= ctpl.apply(drecords[0].data);} childDone=true; cleanup(); }});

        search_url = 'ajaxrequest.php?type=character&value=' + char_id + '&prop=mother';
        store = new Ext.data.JsonStore({ url: search_url , fields: char_layout }).load({callback: function(drecords){if(drecords[0] && drecords[0].data.exist){motherHtml= mtpl.apply(drecords[0].data);} motherDone=true; cleanup(); }});

        search_url = 'ajaxrequest.php?type=character&value=' + char_id + '&prop=father';
        store = new Ext.data.JsonStore({ url: search_url , fields: char_layout }).load({callback: function(drecords){if(drecords[0] && drecords[0].data.exist){fatherHtml= ftpl.apply(drecords[0].data);} fatherDone=true; cleanup(); }});
    }

    function loadGuild(tcomp){
        tabs.getEl().mask("Loading Guild");

        var tpl = new Ext.XTemplate(
            '<tpl for="."><div>      \
                <div><div>guild_id:</div><div>{id}</div></div>  \
                <div><div>Name:</div><div>{name}</div></div>    \
                <div>   \
                    <div>Leader:</div>',
                      '<tpl for="leader">',
                      '<div><a href="?block=yes&act=av&opt=char_info&char_id={id}" onclick="characterView({id},true)">{name}</a></div>',
                      '</tpl>',
                "</div> \
                <div><div>Level:</div><div>{level}</div></div>  \
                <div><div>Image: </div><div>large_{id}_{emblem_id}.png</div></div> \
                <div><div style='background: transparent url(image/emblem_cache/legend/{id}_{emblem_id}.png) no-repeat scroll center center; width: 25px; height: 25px;'></div></div> \
            </div></tpl>"
            );

        var guild_layout = ['id','exist','name','level','leader','emblem_id'];

        search_url = 'ajaxrequest.php?type=character&value=' + char_id + '&prop=guild';
        var store = new Ext.data.JsonStore({ url: search_url , fields: guild_layout }).load({callback: function(drecords){if(drecords[0] && drecords[0].data.exist) {tcomp.body.insertHtml('beforeEnd',tpl.apply(drecords[0].data));} tabs.getEl().unmask(true); }});
    }
    function loadParty(tcomp){
    }
    function loadCharImage(tcomp)
    {
        chrv.getEl().mask("Loading Image");
        var txt = '<div style="background: transparent url(imagerequest.php?ent_id='+ char_id + '&image=char.png) no-repeat scroll center center; width: 100px; height: 120px;"></div>';
        tcomp.body.insertHtml('beforeEnd',txt);
        
        chrv.getEl().unmask();
    }

    activetab = 1;
    if(activeslot)
    	activetab = activeslot;
    
    var tabs = new Ext.TabPanel({
        region: 'center',
        margins:'3 3 3 0', 
        activeTab: activetab,
		defaults:{autoScroll:true},
        /*
		 * listeners:{ tabchange: function(tp,newTab){ var um =
		 * newTab.getUpdater(); if(um) um.refresh(); } },
		 */
        items:[
            {title: 'Status', listeners:{'render':loadStatus}},
            {title: 'Family', listeners:{'render':loadFamily}},
            {title: 'Guild',  listeners:{'render':loadGuild}},
            {title: 'Party',  listeners:{'render':loadParty}}
            ]
        });

    // Panel for the west
    var chrv = new Ext.Panel({
        title: 'Character Image',
        region: 'west',
        listeners:{'render':loadCharImage},
        split: true,
        width: 100,
        collapsible: true,
        margins:'3 0 3 3',
        cmargins:'3 3 3 3'
    });

    win = new Ext.Window({
        animateTarget: 'originate',
        id: windowId,
        title: 'Character View',
        closable:true,
        width:400,
        height:200,
        // border:false,
        plain:true,
        layout: 'border',
        items: [chrv, tabs]
    });

    win.show();
    // All new windows should disable this, all new windows or links clicked,
	// should run the onclick="" embedded in them
    win.getEl().on('mousedown', function(e,t){  e.stopEvent(); });
    win.getEl().on('click', function(e,t){      e.stopEvent(); });
}

function accountView(account_id){
    // This should have more information, and incorporate a characterlist view
	// of all the characters with more information.
    // This will make it easier for GMs/Admins to check information available.
}

function searchEngine(){
    // This function brings up a popup with the search text box,
    
    // search field (text box)
    // type of search (character ID, name, Account ID, or name...)
    // type of results (character results, account results, etc)
    
    // This should doesn't have to remember anything that was type, just a
	// gateway into the results
    function searchResults(term,type){
        // This functions shows a window with icons to click, similar to that of
		// the inventory view, with info
        // through a tooltip about the account/character
        // all button clicks in this should bring up a character view, or
		// account view of some sort.
        // results are searched here and filled out as needed, this can
		// incorporate the search engine, but I rather seperate them for the
		// meantime
        // all results are obtained via ajax requests
    }
}

function showServices(){
    // This is the shop window for the current account,
    // This will bring up the services available, and the current amount of DP
	// on the account
    // This will be auto refreshed every 30 seconds, or when requested after a
	// donation of sorts
}

function addFunds(){
    // Paypal donation script, brings up a screen for login, and sends the user
	// to the paypal site to log into.
    // This will make it much easier for things to work out in the end. Since
	// all transactions
    // will go through this site in the future.
}

function statCalc(){
    // Stats calculator, anything more?
}

function viewJailed(){}

function unjail(char_id){}

function jail(char_id){}

function castleStatus(){}

function ipLinker(ip){
    // search functions for searching for IP links to people
    // options should be for IP only, from searchEngine account link
    // or directly from searchEngine
}

function viewLog(s_id,type){
// search ID
// type of logs
// search functions for showing logs,
// trade logs, gm logs, etc, all here... similar design as searchEngine
}

function itemLookup(){}

function buildMenu(perms){
    // Build a menu from the core outwards, circles and such...
    // make it easy to navigate, and such
    // yay~
}

var openTab = true;
var tabButtons;
var inventoryWindow;
var charList;

function openWindow(winTitle, targetUrl, bogus, winWidth, winHeight){
	var newId = Ext.id();
	var wind = new Ext.Window({
        animateTarget: 'originate',
    	id: newId,
    	title: winTitle,
    	layout: 'fit',
    	width: winWidth,
    	height: winHeight,
    	closeAction: 'close',
    	plain: true,
    	modal: false,
    	shim: false,
    	animCollapse: true,
    	constraintHeader: true,
    	autoLoad:{url: targetUrl + "&window=" + newId, scope: wind, params:{ param1: newId, param2: "testParam2" }, scripts: true}
	});
	
	
	wind.show();
}

Ext.onReady(function(){
	var tabs = new Ext.TabPanel({
	    applyTo: document.getElementById('my-tabs'),
	    activeTab: 0,
	    deferredRender: false,
	    autoTabs: true
	});

   tabButtons = new Ext.Panel({
    	frame:true,
    	collapsed:true,
    	collapsible:true,
    	applyTo:document.getElementById('testTd'),
    	titleCollapse: true
    });

    if(getElementsByClass('jail_btm').length)
    {
        charList = [];
        var so = getElementsByClass('jail_btm');
        for(ro in so)
        {
            if(so[ro]){
                charList.push(new Ext.Panel({
                    collapsed: true,
                    baseCls: 'x-test',
                    layout: 'fit',
                    applyTo: so[ro]  // ID of the object... not an element
                }));
            }
        }
    }
	

 
});