function createPortlet(pObj) { 
 
	var pconfig ='';
	var tp;
	
 
    // create the data store
    var store = new Ext.data.JsonStore({
		data: pObj.docs,
        fields: [
			{name: 'title'},
			{name: 'desc' },
			{name: 'hash' }
        ]
    });



 
 

    function renderDoc(value, p, record){
        return String.format(
                "<table cellpadding='2' cellspacing='0'><tr><td rowspan='2' width='34'><img src='img/icons/pdf.gif'></td><td><b>{0}</b></td></tr><tr><td>{1}</td></tr></table>", value, record.data.desc);
			}

    // create the Grid
    var dgrid = new Ext.grid.GridPanel({
        store: store,
        columns: [
            {id:'doc', sortable: false, renderer: renderDoc, dataIndex: 'title'}
        ],
        stripeRows: true,
        height:100,
		width:300,
		autoExpandColumn: 'doc',
		hideHeaders: true,
		sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
		listeners: {
		    rowclick: function(g, idx, e) {
		       var dh = store.getAt(idx).data.hash;
				document.location = 'http://motorola.mychannelportal.com/downlink.php?id='+dh;
		    }
		}
		
    });


 
	
	if (pObj.tabs.length >1) {
		 
		
		// LOAD TABS
		
		var xp = new Ext.TabPanel({
		        activeTab: 0,
		        frame:true,
				plain:true,
				border:true
				
		    });
		
		for (var i=0; i < pObj.tabs.length; i++) {
			cc = pObj.tabs[i].sc;
			tt = pObj.tabs[i].tabtitle;
			bs = pObj.tabs[i].tabstyle;
			vv = pObj.tabs[i].docs;
			tbid = pObj.tabs[i].tabid;
			
			var dlist = "<table border='0' width='100%' style='font-size:10px'>";
			for (var j=0; j < vv.length; j++) {
			
				if (vv[j].hash == 0) {
			dlist +=  "<tr><td width='18' style='border-bottom:1px dotted #555'><a href='"+ vv[j].url +"'><img src='img/icons/page_go.png' width='16' height='16'></td><td style='border-bottom:1px dotted #555'> " + vv[j].title + "</td></tr>";	
				}else{
			dlist +=  "<tr><td width='18' style='border-bottom:1px dotted #555'><a href='downlink.php?id="+ vv[j].hash +"'><img src='img/icons/"+ vv[j].doctype +".gif' width='16' height='16'></td><td style='border-bottom:1px dotted #555'> " + vv[j].title + "</td></tr>";
				}
			
			};
			dlist+= "</table>";
			
			var fbs = 'padding:8px;';
			if (bs != null) {
				fbs = bs;
			} 
			
			var bh = true;
			var pp = new Ext.Panel({
					id : 'panel' + tbid,
					title: tt,
					autoScroll: true,
					isOpen: false,
					plugins: new Ext.ux.PanelBlind({
					        html: dlist
					    }),
					
					bodyStyle: fbs,
					html: cc,
					listeners: {
						'activate':function(p){
					 	 
					
							Ext.Ajax.request({
								url: "/spp/inc/functions/logger.php",
								method: "POST",
								 
								disableCaching: true,
								params: {
									action : 'VIEW',
									data: p.id
								} ,
								success: function(response, options) {
									return true;
								},
								failure: function(response, options) {
									return true;
								},
								callback: function(response, options) {
									return true;
								}	
							});
							
						}
					
					}
					 
				});
			pp.addClass('undoreset');
			
			xp.add(pp);
			 
		};
		
		pconfig = {
				id: pObj.pid,
				tools: [{id:'left',handler:hidePortlet}],
				title: pObj.title,
				layout: 'fit',
				height:200,
				
				items : [xp]
				
		};
		
 			if (vv.length > 0) {
				bh = false;
			}
		
			pconfig.bbar = [{
				text:'Show Documents',
				hidden: bh,
				handler: function(b) {
				
			 
					if (Ext.getCmp(pObj.pid).items.items[0].getActiveTab().isOpen) {
						Ext.getCmp(pObj.pid).items.items[0].getActiveTab().dismissBlind(0);
						Ext.getCmp(pObj.pid).items.items[0].getActiveTab().isOpen = false;
						 this.setText('Show Documents');
					}else{
						Ext.getCmp(pObj.pid).items.items[0].getActiveTab().showBlind(0);
						Ext.getCmp(pObj.pid).items.items[0].getActiveTab().isOpen = true;
					 	this.setText('Hide Documents');
					};
		 
 	        		}
				}];
	 
		
		
		
		
		tp = Ext.ComponentMgr.create(pconfig, 'portlet');
		
 
		
	}else{
		
		// THIS IS FOR SINGLE TAB PORTLETS ONLY!!!
		var vv = pObj.tabs[0].docs;
		tbid = pObj.tabs[0].tabid;
		
		var dlist = "<table border='0' width='100%' style='font-size:10px'>";
		for (var j=0; j < vv.length; j++) {
				if (vv[j].hash == 0) {
			dlist +=  "<tr><td width='18' style='border-bottom:1px dotted #555'><a href='"+ vv[j].url +"'><img src='img/icons/page_go.png' width='16' height='16'></td><td style='border-bottom:1px dotted #555'> " + vv[j].title + "</td></tr>";	
				}else{
			dlist +=  "<tr><td width='18' style='border-bottom:1px dotted #555'><a href='downlink.php?id="+ vv[j].hash +"'><img src='img/icons/"+ vv[j].doctype +".gif' width='16' height='16'></td><td style='border-bottom:1px dotted #555'> " + vv[j].title + "</td></tr>";
				}

		};
		dlist+= "</table>";
		
		var fbs = 'padding:8px;';
		if (pObj.tabs[0].tabstyle != null) {
			fbs = pObj.tabs[0].tabstyle;
		}
		
		var bh = (vv.length > 0) ? false : true ;
		
		
		 pconfig= {
				id: pObj.pid,
				title: pObj.title,
				tools: [{id:'left',handler:hidePortlet}],
				height: 200,
	 			isOpen: false,
				layout: 'fit',			
				items:[ new Ext.Panel({
							id : 'panel' + tbid,
							autoScroll: true,
							plugins: new Ext.ux.PanelBlind({
							        html: dlist
							    }),

							bodyStyle: fbs,
							html: pObj.tabs[0].sc,
							listeners: {
								'render':function(p){
							 		Ext.Ajax.request({
										url: "/spp/inc/functions/logger.php",
										method: "POST",

										disableCaching: true,
										params: {
											action : 'VIEW',
											data: p.id
										} ,
										success: function(response, options) {
											return true;
										},
										failure: function(response, options) {
											return true;
										},
										callback: function(response, options) {
											return true;
										}	
									});
								}

							}
							
						}) 
 	 
				],
			 
				bbar:[{
					text:'Show Documents',
					hidden : bh,
					handler: function(b) {
					 
						if (Ext.getCmp(pObj.pid).isOpen) {
							Ext.getCmp(pObj.pid).items.items[0].dismissBlind(0);
							Ext.getCmp(pObj.pid).isOpen = false;
							 this.setText('Show Documents');
						}else{
							Ext.getCmp(pObj.pid).items.items[0].showBlind(0);
							Ext.getCmp(pObj.pid).isOpen = true;
						 	this.setText('Hide Documents');
						};
						
					 
		        	}
				}]
		};
		tp = Ext.ComponentMgr.create(pconfig, 'portlet');
	};
	
	
 	var stb = Ext.getCmp('stable');

	var sconfig = {
		id: tp.id +'rep',
		title: tp.title,
		repID : tp.id,
		collapsed:true,
		tools: [{id:'right',handler:showPortlet}],
		hidden:true
	};
	
	spanel = Ext.ComponentMgr.create(sconfig, 'panel');
	stb.add(spanel);
	stb.doLayout();
	
	return tp;

 
} // end createPortlet