<?php
    include_once('_dirinfo.php');
    include_once(PATH_TO_ROOT . 'init.php');
    $db->ChangeDatabase(DB_WARPIT_MAIN);

    $settings = configLoader::loadConfig('startup_settings');
	//20150625 Tanis added config for codemirror version selection
	$codeMirrorVersion = configLoader::loadConfig('webcati');
	$codeMirrorVersion = $codeMirrorVersion['codemirror_version'];
	//20150625 Tanis END

	if (!$UserSession or !$UserSession->IsLoggedIn()) { echo "attack!"; exit; }
	unset($_SESSION['loadedPlugin']);
	unset($_SESSION['addedTabs']);
	$_SESSION['UserInfo']['mc_rootpath'] = WARPIT_WEBPROJECTS;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">
<html>
<head>
  <title>Warpit</title>

  	<?php if ($_SESSION['UserInfo']['theme'] == 1) {
  		echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"extjs/resources/css/ext-all.css\" />";
  		echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"extjs/resources/css/xtheme-warp-it.css\" />";
  	} else {
  		echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"extjs/resources/css/ext-all.css\" />";
	} ?>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<link rel="stylesheet" type="text/css" href="webhelp/_css/_help.css" />



    <link rel="icon" type="image/png" href="_img_1/favicon.png" />

    <!-- GC -->
    <!-- LIBS -->

    <?php if ($_SESSION['UserInfo']['debugMode'] == 1) { ?>
     <script type="text/javascript" src="extjs/adapter/ext/ext-base-debug.js"></script>
    <script type="text/javascript" src="extjs/ext-all-debug.js"></script>
    <?php } else { ?>
     <script type="text/javascript" src="extjs/adapter/ext/ext-base.js"></script>
    <script type="text/javascript" src="extjs/ext-all.js"></script>
	<?php } ?>

	<script type="text/javascript" src="_support/jquery.js"></script>
	<script type="text/javascript" src="_support/jqueryUI.js"></script>
	<script type="text/javascript" src="_support/JSON2.js"></script>

    <!-- <script type="text/javascript" src="_include/_ExtjsUploader.js"></script> -->
  	 <!-- extensions -->
  	 <!-- WARNING: the CheckColumn.js was edited! the onMouseDown event fires now afterEdit!
  	 	source: http://www.extjs.com/forum/showthread.php?t=27161&page=3
  	 	if at any point this stops working, check if it wasn't replaced-reeditet!
     <script type="text/javascript" src="extjs/examples/ux/CheckColumn.js"></script>-->
     <script type="text/javascript" src="_plugins/uxFixes/CheckColumn.js"></script>
  	 <script type="text/javascript" src="extjs/examples/ux/RowExpander.js"></script>

    <!-- Marko 16.4.2015-->
    <script type="text/javascript" src="extjs/examples/ux/Reorderer.js"></script>
    <script type="text/javascript" src="extjs/examples/ux/ToolbarReorderer.js"></script>
    <script type="text/javascript" src="extjs/examples/ux/ToolbarDroppable.js"></script>
    <!-- !Marko 16.4.2015-->

  	 <!-- for grid filtering! -->
  	<link rel="stylesheet" type="text/css" href="extjs/examples/ux/gridfilters/css/GridFilters.css" />
  	<link rel="stylesheet" type="text/css" href="extjs/examples/ux/gridfilters/css/RangeMenu.css" />

  	<!-- WARNING: ListMenu vas edited (versiont ext303), for combobox filtering...
  	<script type="text/javascript" src="extjs/examples/ux/gridfilters/menu/ListMenu.js"></script>-->
  	<script type="text/javascript" src="_plugins/uxFixes/ListMenu.js"></script>
	<script type="text/javascript" src="extjs/examples/ux/gridfilters/menu/RangeMenu.js"></script>

  	<script type="text/javascript" src="extjs/examples/ux/gridfilters/GridFilters.js"></script>
	<script type="text/javascript" src="extjs/examples/ux/gridfilters/filter/Filter.js"></script>
	<script type="text/javascript" src="extjs/examples/ux/gridfilters/filter/StringFilter.js"></script>
	<script type="text/javascript" src="extjs/examples/ux/gridfilters/filter/DateFilter.js"></script>
	<script type="text/javascript" src="extjs/examples/ux/gridfilters/filter/ListFilter.js"></script>
	<script type="text/javascript" src="extjs/examples/ux/gridfilters/filter/NumericFilter.js"></script>
	<script type="text/javascript" src="extjs/examples/ux/gridfilters/filter/BooleanFilter.js"></script>
	<script type="text/javascript" src="extjs/examples/ux/RowLayout.js"></script>
	<script type="text/javascript" src="extjs/examples/ux/CenterLayout.js"></script>

	<script type="text/javascript" src="extjs/examples/ux/ColorField/Ext.ux.ColorField.js"></script>
	<link rel="stylesheet" type="text/css" href="extjs/examples/ux/ColorField/Ext.ux.ColorField.js">

	<link rel="stylesheet" type="text/css" href="_plugins/Ext.ux.grid.RowActions.css">
	<script type="text/javascript" src="_plugins/Ext.ux.util.js"></script>
	<script type="text/javascript" src="_plugins/Ext.ux.grid.Search.js"></script>
	<script type="text/javascript" src="_plugins/Ext.ux.grid.RowActions.js"></script>
	<script type="text/javascript" src="_plugins/Ext.ux.grid.RecordForm.js"></script>

	<link rel="stylesheet" type="text/css" href="_plugins/Ext.ux.grid.CellActions.css">
	<script type="text/javascript" src="_plugins/Ext.ux.grid.CellActions.js"></script>

	<script type="text/javascript" src="_plugins/Ext.ux.forms.OOSubmit.js"></script>
	<!--  calculator wanabe -->
	<link rel="stylesheet" type="text/css" href="_plugins/Ext.ux.calc.css">
	<script type="text/javascript" src="_plugins/Ext.ux.calc.js"></script>


	<!-- grid drag n drop reorder! -->
	<script type="text/javascript" src="_plugins/Ext.ux.dd.GridDragDropRowOrder.js"></script>
	<!-- grid drag n drop reorder! -->
	<script type="text/javascript" src="_plugins/Ext.ux.grid.GridSetter.js"></script>

	<!-- date time field! -->
	<script type="text/javascript" src="_plugins/Ext.ux.form.DateTimeField.js"></script>

	<!--  SAKI's FILE TREE -->
	  <link rel="stylesheet" type="text/css" href="_plugins/fileTree/css/icons.css">
	<!--    <link rel="stylesheet" type="text/css" href="_plugins/fileTree/css/webpage.css"> -->
	  <link rel="stylesheet" type="text/css" href="_plugins/fileTree/css/filetree.css">
	  <link rel="stylesheet" type="text/css" href="_plugins/fileTree/css/filetype.css">
	  <link rel="stylesheet" type="text/css" href="_plugins/fileTree/css/famflag.css">
	  <link rel="stylesheet" type="text/css" href="_plugins/fileTree/css/Ext.ux.IconCombo.css">
	  <script type="text/javascript" src="_plugins/fileTree/js/WebPage.js"></script>
	  <script type="text/javascript" src="_plugins/fileTree/js/Ext.ux.form.BrowseButton.js"></script>
	  <script type="text/javascript" src="_plugins/fileTree/js/Ext.ux.FileUploader.js"></script>
	  <script type="text/javascript" src="_plugins/fileTree/js/Ext.ux.UploadPanel.js"></script>
	  <script type="text/javascript" src="_plugins/fileTree/js/Ext.ux.FileTreeMenu.js"></script>
	  <script type="text/javascript" src="_plugins/fileTree/js/Ext.ux.FileTreePanel.js"></script>
	  <script type="text/javascript" src="_plugins/fileTree/js/Ext.ux.form.ThemeCombo.js"></script>
	  <script type="text/javascript" src="_plugins/fileTree/js/Ext.ux.form.IconCombo.js"></script>
	  <script type="text/javascript" src="_plugins/fileTree/js/Ext.ux.form.LangSelectCombo.js"></script>
	<!-- Tree Grid -->

		<link rel="stylesheet" type="text/css" href="extjs/examples/ux/treegrid/treegrid.css" rel="stylesheet" />

        <script type="text/javascript" src="extjs/examples/ux/treegrid/TreeGridSorter.js"></script>
        <script type="text/javascript" src="extjs/examples/ux/treegrid/TreeGridColumnResizer.js"></script>
        <script type="text/javascript" src="extjs/examples/ux/treegrid/TreeGridNodeUI.js"></script>
        <script type="text/javascript" src="extjs/examples/ux/treegrid/TreeGridLoader.js"></script>
        <script type="text/javascript" src="extjs/examples/ux/treegrid/TreeGridColumns.js"></script>
        <script type="text/javascript" src="extjs/examples/ux/treegrid/TreeGrid.js"></script>


    <!-- GroupSummary -->

    <script type="text/javascript" src="extjs/examples/ux/GroupSummary.js"></script>


	<!-- Multi select field (combo with checkboxes  -->

	  <link rel="stylesheet" type="text/css" href="_plugins/Ext.ux.form.LovCombo.css">
	  <script type="text/javascript" src="_plugins/Ext.ux.MultiSelectField.js"></script>


	  <script type="text/javascript" src="_plugins/Ext.ux.GridArrowKeys.js"></script>
	<!-- TINY MCE!!!! -->

	<script type="text/javascript" src="_plugins/tinyMCE/jscripts/tiny_mce/tiny_mce_src.js"></script>
	<script type="text/javascript" src="_plugins/tinyMCE/jscripts/tiny_mce/plugins/imagemanager/js/mcimagemanager.js"></script>
	<script type="text/javascript" src="_plugins/tinyMCE/jscripts/tiny_mce/plugins/filemanager/js/mcfilemanager.js"></script>

	<script type="text/javascript" src="_plugins/tinyMCE/Ext.ux.TinyMCE.js"></script>

	<!--  fix for dragdrop over multiple targets!
	<script type="text/javascript" src="_plugins/uxFixes/DragDropMgr.js"></script>-->

	<?php
	//20150625 Tanis added config for codemirror version selection
	if($codeMirrorVersion == 1)
	{?>

		<!-- CodeMirror script editor -->

    	<!-- Marko 16.4.201 -->
		<script type="text/javascript" src="_plugins/CodeMirror/js/codemirror.js"></script>
		<script type="text/javascript" src="_plugins/CodeMirror/js/extjsPlugin.js"></script>
	<?php
	}
	else if($codeMirrorVersion == 2)
	{?>
	 	<script http-equiv="content-script-type" content="text/javascript" src="_plugins/CodeMirror-0.63/js/codemirror.js"></script>
    	<script http-equiv="content-script-type" content="text/javascript" src="_plugins/codemirror/jslint.js"></script>
		<script type="text/javascript" src="_plugins/codemirror/Ext.ux.panel.CodeMirror.js"></script>

    <!-- !Marko 16.4.2015-->
	<?php }

	//20150625 Tanis END
	?>





  <script type="text/javascript" src="extjs/examples/ux/GMapPanel.js"></script>
  <?php
  if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off')
  {?>
    <script src="https://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA" type="text/javascript"></script>

  <?php
  }
  else
  {?>
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA" type="text/javascript"></script>
  <?php
  }
  ?>


	<!-- this functions are required for propert grid
	<script type="text/javascript" src="property-grid.js"></script> -->
	<!-- webcati Build questionare specific functions!!! -->
	<!--  <script type="text/javascript" src="_plugins/Ext.wc.BuildQuest.js"></script>

	 <script type="text/javascript" src="_plugins/Ext.RMmain.js"></script> -->
  	<?php
  	if ($_SESSION['UserInfo']['theme'] == 1) {
		echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"_css/mainWarpit_".$_SESSION['UserInfo']['theme'].".css\" />";
	} else {
		echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"_css/mainWarpit.css\" />";
	}
	?>

	<script type="text/javascript">

	//Nekateri brskalniki ne omogočajo izpisa v console in vrnejo error.  Če consola ne obstaja si definiramo prazno metodo
	 if(console == null)
    {
        var console = {};
        console.log = function()
        {
        }
    }
    window.console = console;
    Ext.onReady(function(){

    	var fileref=document.createElement('script');
    	  fileref.setAttribute("type","text/javascript");
    	  fileref.setAttribute("src", "_plugins/Ext.RMmain.js")

    	   document.getElementsByTagName("head")[0].appendChild(fileref)

    	  fileref=document.createElement('script');
    	  fileref.setAttribute("type","text/javascript");
    	  fileref.setAttribute("src", "_plugins/Ext.wc.BuildQuest.js")

    	  document.getElementsByTagName("head")[0].appendChild(fileref)

         <?php if ($_SESSION[UserInfo][debugMode] == 1) { ?>
         fileref=document.createElement('script');
	   	  fileref.setAttribute("type","text/javascript");
	   	  fileref.setAttribute("src", "_backup/debug.js")

	   	  document.getElementsByTagName("head")[0].appendChild(fileref)
    	<?php }  ?>

    	Ext.ux.IFrameComponent = Ext.extend(Ext.BoxComponent, {
	     onRender : function(ct, position){
	          this.el = ct.createChild({tag: 'iframe', id: 'iframe-'+ this.id, frameBorder: 0, src: this.url});

	     }
		});


		window.onbeforeunload = function(){ return ''; };
       //variables for copy clipboard
		RMcopyClipboardQuestion = false;

    	 Ext.QuickTips.init();

		var viewPort = new Ext.Viewport({
			layout:'fit',

			items:

	       new Ext.Panel({
            layout: 'border',
         	border: false,
         	height: 100,
			<?php
					// checking for flag image....
					if (file_exists('_img/flags/flags_'.$_SESSION['UserInfo']['language'].'.png')) $countryFlag = $_SESSION['UserInfo']['language']; else $countryFlag = 0;
				?>

				<?php if ($_SESSION['UserInfo']['theme'] == 1) {  ?>
					title: ' <table border=0 width="100%" height="20" cellpadding=0 cellspacing=0 class="headerFont"><tr><td width=400> <img class="be-logo" src="_img_1/warpit_logo.png" alt="">'+
		            <?php echo "'"./*$_SESSION['UserInfo']['Firstname']." ".$_SESSION['UserInfo']['Surname'].*/"'"; ?>
		            +'</td><td align=center>  </td><td width="300" align="left" style="padding-right: 0px" height="20"><div class="header-right"><span>User: '+
		             <?php echo "'".$_SESSION['UserInfo']['Firstname']." ".$_SESSION['UserInfo']['Surname']."'"; ?>  +
		             '</span><span><?php echo $_SESSION['UserInfo']['country_code'];?></span></div></td></tr></table>',
				       // unstyled : true,
			    <?php } else { ?>
					title: ' <table border=0 width="100%" height="20" cellpadding=0 cellspacing=0 class="headerFont"><tr><td width=400>&nbsp;<b><?php echo $_SESSION['UserInfo']['country_code'];?></b>&nbsp;<img src="_img/flags/flags_<?php echo $countryFlag; ?>.png">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Login user:</b> '+
		            <?php echo "'".$_SESSION['UserInfo']['Firstname']." ".$_SESSION['UserInfo']['Surname']."'"; ?>
		            +'</td><td align=center><img src=_img/znakec.png>&nbsp;&nbsp;<b>WARP-IT</b></td><td width="300" align="left" style="padding-right: 0px" height="20"><small><b>User:</b> '+
		             <?php echo "'".$_SESSION['UserInfo']['Firstname']." ".$_SESSION['UserInfo']['Surname']."'"; ?> +
		             '</small></td>'+
		             '</tr></table>',
				<?php } ?>

		       tools:[
					{
						  id: 'maximize',
						  qtip: 'Full screen',
					  handler: function(evt, toolEl, panel, tc){
						  	if(toggleFullScreen())
						  	{
						  		if(!Ext.isIE)
						  		{
						  		toolEl.removeClass('x-tool-restore');
					    	  	toolEl.addClass('x-tool-maximize');
					    	  	toolEl.addClass('x-tool-maximize-f');
						  		}
						  	}
						  	else
						  		if(!Ext.isIE)
						  		{
					    	  	toolEl.removeClass('x-tool-maximize');
					    	  	toolEl.addClass('x-tool-restore');
					    	  	toolEl.addClass('x-tool-maximize-f');
						  		}
						  }
					},
					{
						  id: 'close',
						  qtip: 'Log Out',
						  handler: function(){
						  	//CallScript('index.php',{logOut:'1'});
						  	document.location.href='index.php?logOut=1';
						  }
					}
				],
		        tbar: [
		         {

		             xtype:'button',
		             text: 'Panel manager',
		             iconCls: 'iconWebuserspool',
		             <?php if (!$_SESSION['UserRights'][2] ||!file_exists('webuserspool')) echo " disabled: true, \n"; ?>
		             scale: 'large',
		             width: 85,
		             iconAlign: 'top',
		             style: 'padding-left:5px',
	            	 handler : function() {
		             	//addTab('WebUserspool','webuserspool/_forms/tree.groups.php',{treeName : 'PoolMenu', tree:'_ProgramMenu'},Ext.getCmp('west-panel'));
		        	 //CallScript('webuserspool/_forms/tree.groups.php',{treeName : 'PoolMenu', tree:'_ProgramMenu'});
		        	 	addTabAuto('webUserspoolUniqePanel','webuserspool/_forms/tree.groups.php',{treeName : 'PoolMenu', tree:'_ProgramMenu'});
		            	}
		            },
		        {
		             xtype:'button',
		             text: 'Project manager',
		             <?php if (!$_SESSION['UserRights'][1] || !file_exists('webcati')) echo " disabled: true, \n"; ?>
		             iconCls: 'iconWebcati',
		             scale: 'large',
		             width: 85,
		             iconAlign: 'top',
		             style: 'padding-left:5px',
		             handler : function() {
		             	addTabAuto('webCatiUniqePanel','webcati/_forms/tree.groups.php',{treeName:'CatiMenu', tree:'_ProgramMenu'});
		             }

		            },

		     /*   {
		             xtype:'button',
		             text: 'WebRecode',
		             width: 85,
		             iconCls: 'iconWebrecode',
		             scale: 'large',
		             iconAlign: 'top',
	            	 style: 'padding-left:5px',
		             handler : function() {
		            	addTabAuto('webrecodeUniquePanel','webcati/_forms/tree.groups.webrecode.php',{treeName:'WebrecodeMenu', tree:'_webrecode_Menu'});
		             }

		            },*/
		            {
		             xtype:'button',
		             text: 'Report manager',
		             <?php if (!file_exists('webportal')) echo " disabled: true, \n"; ?>
		             iconCls: 'iconWebportal',
		             scale: 'large',
		             iconAlign: 'top',
		             width: 85,
		             style: 'padding-left:5px'

		            },
//		            {
//		             xtype:'button',
//		             text: '&nbsp;&nbsp;&nbsp;&nbsp;CRM&nbsp;&nbsp;&nbsp;',
//		             iconCls: 'iconWebportal',
//		             scale: 'large',
//		             iconAlign: 'top',
//		             width: 85,
//		             style: 'padding-left:5px',
//		             handler : function() {
//		            	addTabAuto('CRMUniqePanel','CRM/_forms/tree.group.php',{treeName:'CRM', tree: '_ProgramMenu'});
//		             }
//		            },
//                    {
//                        xtype:'button',
//                        text: '&nbsp;&nbsp;&nbsp;&nbsp;CapiManager&nbsp;&nbsp;&nbsp;',
//                        iconCls: 'iconWebportal',
//                        scale: 'large',
//                        iconAlign: 'top',
//                        width: 85,
//                        style: 'padding-left:5px',
//                        handler : function() {
//
//                            addTabAuto('CapiManagerUniquePanel','capi_manager/_forms/tree.group.php',{treeName:'CapiManager', tree: '_ProgramMenuManager'});
//                        }
//
//                    },
//                    {
//                        xtype:'button',
//                        text: 'CapiCommon',
//                        iconCls: 'iconWebportal',
//                        scale: 'large',
//                        iconAlign: 'top',
//                        width: 85,
//                        style: 'padding-left:5px',
//                        handler : function() {
//
//                            addTabAuto('CapiManagerCommonUniquePanel','capi_manager_common/_forms/tree.group.php',{treeName:'CapiCommon', tree: '_ProgramMenuManager'});
//                        }
//
//                    },
                    '->',
		            {
		             xtype:'button',
		             text: 'Tools',
		             <?php if (!$_SESSION['UserRights'][12] ) echo " disabled: true, \n"; ?>
		             iconCls: 'iconTools',
		             scale: 'large',
		             width: 70,
		             iconAlign: 'top',
		            // style: 'padding-right:10px',
		            menu:[
		                <?php
			            if($_SESSION['UserRights'][9] || $_SESSION['UserInfo']['id'] == 1):
			            ?>
			           {

			             text:'Permission',
			             iconCls:'RMicon_hardhatmale',
		            	 handler : function() {
			             	    	 addTabAuto('WarpitPermissionPanelUniqe','_forms/forms.permissions.php');
			             }
		            } ,<?php endif;?> {
			            text:'Image Manager',
			            icon:'_plugins/tinyMCE/jscripts/tiny_mce/plugins/imagemanager/pages/im/img/insertimage.gif' ,
	            	 	handler : function() {
		               	//addTab('nima veze','_forms/_examples/forms.treeTEST.php',{},Ext.getCmp('west-panel'));
				          mcImageManager.browse( {} );

		            	}
		                 }
		                 , {
			            text:'File Manager',
			            icon:'_plugins/tinyMCE/jscripts/tiny_mce/plugins/filemanager/pages/fm/img/insertfile.gif' ,
	            	 	handler : function() {
		               	//addTab('nima veze','_forms/_examples/forms.treeTEST.php',{},Ext.getCmp('west-panel'));
		                	 mcFileManager.browse( {path:'{0}files'  });

	            	}  },
	            	 {
			            text:'Check for Updates',
			           // icon:'_plugins/tinyMCE/jscripts/tiny_mce/plugins/filemanager/pages/fm/img/insertfile.gif' ,
	            	 	handler : function() {
		               		 CallScript('_forms/forms.live-update-warpit.php');

	            	}  }


		            ]},
		            {

		             text: 'Options',
		             iconCls: 'iconPropreties',
		             scale: 'large',
		             <?php if (!$_SESSION['UserRights'][13] ) echo " disabled: true, \n"; ?>
		             iconAlign: 'top',
		             width: 70,
		             menu:[
		                 {
			            text:'Web Help',
			            iconCls:'icon-help-tab',
	            	 	handler : function() {
		                	 //addTab('WEBHelp - Admin','webhelp/_forms/forms.treeAdmin.php',{treeName:'HelpMenu', tree:'_HelpMenu'}, Ext.getCmp('west-panel'));
		                	 CallScript('webhelp/_forms/forms.treeAdmin.php',{treeName:'HelpMenu', tree:'_HelpMenu'});

		            			}
		                 },
		                 {
				            text:'Close all tabs',
				            iconCls:'icon-closetabs-tab',
		            	 	handler : function() {
			                	 CallScript('_support/tabManager.php',{action:'remove_all'});
	            			}
		                 },{
                            text:'Clean user tab state',
                            iconCls:'icon-closetabs-tab',
                            handler : function() {
                                 CallScript('_support/tabManager.php',{action:'clean_tabs'});
                            }
                         },
		                 {
			            text:'User properties',
			            iconCls:'icon-userproperty-tab',
	            	 	handler : function() {
		                	 //addTab('WEBHelp - Admin','webhelp/_forms/forms.treeAdmin.php',{treeName:'HelpMenu', tree:'_HelpMenu'}, Ext.getCmp('west-panel'));
		                	 addTabAuto('vUserInfoBox','_forms/forms.userpropreties.php');

		            			}
		                 }
	            	]
		            },
		            {
		             xtype:'button',
		             text: 'Help',
		             <?php if (!$_SESSION['UserRights'][14] ) echo " disabled: true, \n"; ?>
		             iconCls: 'iconHelp',
		             scale: 'large',
		             iconAlign: 'top',
		             width: 70,
		             style: 'padding-right:10px',
	            	 handler : function() {
		             	//addTab('WEBHelp','webhelp/_forms/forms.treeHelp.php',{treeName:'HelpMenu', tree:'_HelpMenu'}, Ext.getCmp('west-panel'));
		            	CallScript('webhelp/_forms/forms.treeHelp.php',{treeName:'HelpMenu', tree:'_HelpMenu'});

		            	}
		            }
		            ],
            items: [
            // create instance immediately

            {

            	region: 'center',
                id: 'north2', // see Ext.getCmp() below
              	border: true,
               // margins: '0 0 0 0',
                layout:'border',
				defaults: {
			  //  collapsible: true,
			    split: true
			    //bodyStyle: 'padding:15px'
				}
				,
			items: [


			{

			    region: 'south',
			    border: true,
			    xtype:'tabpanel',
				collapseMode: 'mini',
			    split:true,
			  //  collapsible: true,
			    collapsed:true,
			    height: 150,

				    id : 'xmlTabPanel',
				    activeTab: 0     // first tab initially active



				}
				,
				   // title: 'Main Content',
				   mainTabPanel = new Ext.TabPanel({

				   	collapsible: false,
				    border: false,
				    id : 'mainTabPanel',
				    enableTabScroll : true,
				    region:'center',
				   // activeTab: 0 ,    // first tab initially active
				    listeners: {
							remove : function(tpan,pan){
								removeSession(pan.id);
							}
					    }

				  })

           ]},

           		new Ext.TabPanel({
           		//{
                region: 'east',
                id: 'west-panel',
                split: true,
                minSize: 200,
                width:300,
               	collapseMode: 'mini',
                border: true,
                listeners: {
					remove : function(tpan,pan){
						removeSession(pan.id);
					}
			    },
             //	margins: '2 0 0 0',


                xtype           : 'tabpanel',
    			//activeTab       : 0,
	    		enableTabScroll : true,
		    	resizeTabs      : false,
				minTabWidth     : 75,

	               items: [
	                /*{
	                	contentEl: 'poolFields',
	                	iconCls: 'TabHelp',
	                	title: 'WEBHelp',
	                	closable: true
	                }*/
	                ]
            })

           ]
        })

        });


          addTabBCK = function(naslov,loadData,parameters){
		        mainTabPanel.add({
		            title		: 	naslov,
		            autoLoad	:  	{
                                		url    : loadData,
                                		params: parameters,
                                		scripts: true
                           			},
		            closable	:	true
		        }).show(); //show the tab
		  }

          addTab = function(naslov,loadData,parameters,tabName,callBack){

			  if(tabName == null)
			  {
				  tabName = mainTabPanel
			  }
			  var tmp = Ext.get('tabTemporary');
			  tmp.load({
            		url    : loadData,
              		params: parameters,
              		scripts: true,
              		callback:function(el,success,response){

              		var elem = Ext.util.Format.trim(document.getElementById('tabTemporary').innerHTML) ;
          			tabName.add(eval(elem)).show(); //show the tab
          			if(callBack!= null)
             		{
                 		callBack();
             		}
              		//alert(Ext.util.Format.trim( document.getElementById('tabTemporary').innerHTML ));
              		}
         			});

		  }

		  addTabAuto = function(tabId,url,parameters,callBack)
		  {
			  //console.log('parameters from Addtabauto before:',parameters);
			  parameters = parameters || {};
			  Ext.apply(parameters,{action:'add',uniqueTabId : tabId ,uniqueTabUrl : url } );
			  //console.log('parameters from Addtabauto after:',parameters);
		  		Ext.Ajax.request({
	         		 url    : '_support/tabManager.php',
	           		params: parameters,
	           		async: false,
	           		success: function(res,opt)
	           		{
	           			eval(res.responseText);
	           			/*
		           		try
		           		{
		             		eval(res.responseText);
		           		}
		           		catch(e)
		           		{
			           		Ext.Msg.alert('Error',tabId+': '+e);
			           		removeSession(tabId);
		           		}*/
		             		if(callBack!= null)
		             		{
		                 		callBack();
		             		}
	           		}
	           		});

		  }

		  CallScript = function(loadData,parameters,callBack){
         	  Ext.Ajax.request({
         		 url    : loadData,
           		params: parameters,
           		async: false,
           		success: function(res,opt)
           		{
             		eval(res.responseText);
             		if(callBack!= null)
             		{
                 		callBack();
             		}
           		}
           		});

		  }
		  CallMultiScripts = function(arr)
		  {
			  var len = arr.length;
			  if(len == 0)
				  return;
			  var count = 0;
			  var fn = function(){
					//the call back function
					count++;
					if(count < len)
					{
						if(count+1 < len)
						{
							arr[count][2].uniqueNotShow = true;
						}
						//for each tab except last we add uniqueNotShow param!
						 addTabAuto( arr[count][0] , arr[count][1],arr[count][2],fn );
					}
				};
				if(len != 1)
					arr[count][2].uniqueNotShow = true;
			  addTabAuto( arr[count][0] , arr[count][1],arr[count][2],fn );
		  }
		  function removeSession(sessId)
		  {
			  Ext.Ajax.request({
					url : '_support/tabManager.php',
					params:{action:'remove',sessId:sessId}
				  });
		  }

		toggleFullScreen = function(){
			root = document.documentElement;
			if(Ext.isIE) // if it's Internet Explorer
            {
            	//var obj = new ActiveXObject("Wscript.shell");
            	//obj.SendKeys("{F11}");
            	Ext.Msg.show({
                	title:'Info',
                	msg: 'You are using a browser, which does not support this function. Please, press \'F11\' button on your keyboard instead.',
                	buttons: Ext.Msg.OK,
                	icon: Ext.MessageBox.INFO
                	});
            	return false;
            }
            else
            {
            	var fullScreenMode = (document.fullScreenElement && document.fullScreenElement !==     null) ||    // alternative standard method
                (document.mozFullScreen || document.webkitIsFullScreen);

				if(!fullScreenMode) {
                	if (root.webkitRequestFullScreen) {
                    	root.webkitRequestFullScreen(window.Element.ALLOW_KEYBOARD_INPUT);
                	} else if (root.mozRequestFullScreen) {
                    	root.mozRequestFullScreen();
                	}
            	}
				else
				{
            		(document.webkitCancelFullScreen||document.mozCancelFullScreen||$.noop).apply(document);
				}

 			}
 			return fullScreenMode;
		}
			var tmpArr = [];
		//	CallScript('_forms/forms.userpropreties.php',{});
	 		//tmpArr.push([ addTab, '','_forms/forms.userpropreties.php',{},Ext.getCmp('west-panel')  ]);


			//tmpArr.push(['panelTipOfTheDay', 'webhelp/_forms/forms.tipOfTheDay.php',{table:'_HelpMenu'} ] );
			<?php
				$sql = "SELECT * FROM ".DB_WARPIT_MAIN."._user_tab_state WHERE id_user = ".$_SESSION['UserInfo']['id'] ." ORDER BY id";
				$res = $db->SQLexecute($sql);
				//echo $db->GetError();
				while ($row = $db->fetchAssoc($res))
				{
					echo "tmpArr.push( ['".$row['id_tab']."', '".$row['url']."',".$row['params']." ] ); ";
					//echo "CallScript('".$row['url']."',".$row['params'].",function(){console.log('aaa');});";
				}
				if(intval($settings['show_tip_of_the_day']) == 1)
                {
                    echo "CallScript('webhelp/_forms/forms.tipOfTheDay.php',{table:'_HelpMenu'}, function() {
                        CallMultiScripts(tmpArr);
                         tmpArr = null;
                     } );
                    ";
                }
                else
                {
                       echo " CallMultiScripts(tmpArr);
                         tmpArr = null;";
                }

			?>

    });
    </script>
    <!-- Empty script file...copy into it any response for easier debuging! -->

</head>
<body>
	<div id="tabTemporary" class="x-hide-display" >
	</div>
</body>
</html>
