/* 
 * File ......:  tech.js
 * Description:  
 * Created ...:	 10/06/2009, Buzz Loftus
 */

Ext.onReady(function(){
                 
    Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
	
	//var sessionId = Ext.get('mySessId').dom.value;

    /* ================================================================================ 
     * ???                                                       
     * ================================================================================ */
    Ext.override(Ext.EventObjectImpl, {
        getTarget : function(selector, maxDepth, returnEl){
            var targetElement;
            try {
                targetElement = selector ? Ext.fly(this.target).findParent(selector, maxDepth, returnEl) : this.target;
            } catch(e) {
                targetElement = this.target;
            }
            return targetElement;
        }
    });	

	// Check session variables for logged-in user.  This handles the scenario where
	// a user clicks the refresh icon or presses F5.  Username greeting in upper
	// right is maintained.  Without this the page reverts to 'Login' html upon
	// refresh.
	Ext.Ajax.request({
		url: 'login.php',		
		params: 'task=checksession',
		success: function(resp){
			Ext.get('loginline').update(resp.responseText);
		}
	});

    /* ================================================================================ 
     * Define main viewport layout                                                       
     * ================================================================================ */
    var viewport = new Ext.Viewport({
        layout:'border',
		//id:'extarea',
        items:[
             new Ext.BoxComponent({ // raw
                region:'north',
                el: 'north',
                height:152
				//height:170
             }),{  
                region:'south',
                id: 'southregion',
                contentEl: 'south',
                split:true,
                height: 135,
                minSize: 100,
                maxSize: 200,
                collapsible: true,
                collapsed: true,
                title:'Site Technology',
                margins:'0 0 0 0',
                autoLoad: 'techused.php?session_date='+mySessDate
                //autoLoad: 'techused.php?sessionid=<?php echo htmlspecialchars(SID); ?>'
            }, {
				/*
                region:'east',
                id: 'east-panel',
                title: 'News',
                collapsible: true,
                collapsed: false,
                split:true,
                width: 250,
                minSize: 175,
                maxSize: 400,
                layout:'fit',
                margins:'0 5 0 0',
                items:
                    new Ext.TabPanel({
                        border:false,
                        activeTab:0,
                        tabPosition:'top',
                        items:[{
                            html:'<p>Nothing here yet.</p>',
                            title: 'News',
                            autoScroll:true,
                            id: 'myrssfeeds'
                        },
                        {
                            title: 'Another tab',
                            autoScroll:true,
                            id: 'anothertab'
                        },
                        new Ext.grid.PropertyGrid({
                            title: 'My Statistics',
                            closable: true,
                            source: {
                                // "(name)": "Properties Grid",
                                "Net Worth": "$123,456,789.01",
                                "grouping": false,
                                "autoFitColumns": true,
                                "productionQuality": false,
                                "created": new Date(Date.parse('10/15/2006')),
                                "tested": false,
                                "version": .01,
                                "borderWidth": 1
                            }
                        })]
                    })
            },{
				*/
                region:'west',
                id:'west-panel',
                title:' ',
                split:true,
                width: 275,
                minSize: 175,
                maxSize: 400,
                collapsible: true,
                collapsed: false,
				//bufferResize: 100,
                margins:'0 0 0 5',
                layout:'accordion',
                layoutConfig:{
                    animate:true
                },
				/*
				listeners: {
					bodyresize: function(thisComp){
						//alert( 'bodyresize');
						this.doLayout(true);
						//var myElement = Ext.getCmp("west-panel");
						//myElement.syncSize();
						//alert( 'yo' );
					}
				},
				*/
                items: [{
                    //contentEl: 'west',
                    title:'<b>Hello!</b>',
                    border:false,
                    iconCls:'greeting',
					layout: 'fit',
					items: greeting
				},{
                    title:'Site History',
                    border:false,
                    iconCls:'leaf',
					layout: 'fit',
					items: sitehistGrid
                    //autoLoad: 'sitehist.php'
                /*
                },{
                    title:'Contact Information',
                  //  html:'<p><a href="http://www.hotmail.com" target="_blank">Hotmail</a></p><p><a href="http://www.wachovia.com" target="_blank">Wachovia</a></p><p><a href="http://www.fidelity.com" target="_blank">Fidelity</a></p>',
                    border:false,
                    iconCls:'links',
                    autoLoad: 'links.php'
				*/
				}
                ]
            },{
                region:'center',
                id:'center-panel',
                //title:'Center',
                split:false,
                layout:'fit',
                titlebar: false,
                items: centerPanel
				/*
				listeners: {
					resize: function(){
						//alert( 'bodyresize');
						west-panel.doLayout(true);
					}
				}
				*/
				
			/*
			},{
				//title: 'Main Content',
				width: 150,
				id: 'techgads_x',
				collapsible: false,
				region:'east',
				//autoLoad: 'gads.html',
				//scripts: true
				autoLoad:{url: 'gads.html', scripts:true}
				//margins: '5 0 0 0'
			*/
            }
        ]

    });

	var mgr = new Ext.Updater("bannerDate");
	mgr.startAutoRefresh(900, "getCurrentDate.php");

	//var el = Ext.get("gads"); // Get Ext.Element object
	//if (el === null) {
	//	alert( 'el is null');
	//}
	//var mgr = el.getUpdater();
	//mgr.update({
//			url: "gglads.html",
//			evalScripts: true
//	});

	//var stuff = Ext.get('tech_adsense').value;
	//alert( stuff );
	//var techthing = Ext.get('techgads').update( stuff );
	//var techthing = Ext.get('techgads');
	//if (techthing != null) {
	//	techthing.update( Ext.get('tech_adsense').value );
	//}

	//techContent.init();

   //buzzwashere.RadioGroups.init();
	
});

Ext.layout.BorderLayout.Region.prototype.getCollapsedEl = Ext.layout.BorderLayout.Region.prototype.getCollapsedEl.createSequence(function() 
{
	if ( ( this.position == 'south' ) && !this.collapsedEl.titleEl ) {
		this.collapsedEl.titleEl = this.collapsedEl.createChild({cls: 'x-collapsed-title-south', cn: this.panel.title});
	}
	if ( ( this.position == 'east' ) && !this.collapsedEl.titleEl ) {
		this.collapsedEl.titleEl = this.collapsedEl.createChild({cls: 'x-collapsed-title-east', cn: ' '});
	}
});
//Ext.getCmp('workload-panel').layout.south.getCollapsedEl().titleEl.dom.innerHTML = 'Case Information for #123456';


function ToggleSouth() {
    
    var region = Ext.getCmp('southregion');
    if (region.collapse == true) {
        region.collapse = false;
        alert( 'yo');
    }


}

function changeActiveTab( tabnumber ) {
	if (centerPanel) {
		centerPanel.setActiveTab( tabnumber );
	}
	if (tabnumber == 2) {
		var el = Ext.get("techgads"); // Get Ext.Element object
		//if (el === null) {
		//	alert( 'el is null');
		//} else {
		//	alert( 'el is NOT null');
		//}
		var mgr = el.getUpdater();
		mgr.update({
				url: "tech/techgads3.html"
		});

	}

}

