﻿// JScript File
var MenuArrayMain = new Array();
function CreateMenuMain()
{
    var Index = 0;
    var ItemMain = new Array();
    for(var i=0;i<menuArray.length;i++)
    {
        var name = menuArray[i][0];
        var type = menuArray[i][1];
        var icon = menuArray[i][2];
        var Item = menuArray[i][3];
        
        switch(type)
        {
            case "TREE":
                var treeTemp = new Ext.tree.TreePanel({
                        xtype: 'treepanel',				
                        split:true,
                        autoHeight:true,
                        viewConfig: {
                            forceFit: true
                        }
                 });           
                 var noderoot = new Ext.tree.TreeNode({  
                       text : name,
                       iconCls: icon,
                       expanded:true
                 });
                 treeTemp.setRootNode(noderoot);
                 for(var j=0;j<Item.length;j++)
                 {                    
                    var itype = Item[j][1];                    
                    var iurl = Item[j][3];                  
                    var nodeTemp = new Ext.tree.TreeNode({ 
                        id : Item[j][2],                               
                        text : Item[j][0],
                        iconCls:Item[j][4],
                        expanded:true
                    });
                    var subItem = Item[j][5];
                    if(subItem != null)
                    {
                        ReTreeFunction(subItem,nodeTemp);
                    }
                    else
                    {
                        MenuArrayMain[Item[j][0]] = iurl+"$"+itype;                  
                        nodeTemp.on('click', function(node,e){
                            OnClick(node.text,node.attributes.iconCls,node.id);
                        });
                    }
                    noderoot.appendChild(nodeTemp);   
                 }
                 ItemMain[Index] = new Ext.Panel({
                        id:name,                        
                        title:'<font style="font-weight:bold;font-size:12px;font-family:Tahoma">'+name+'</font>',
                        iconCls: icon,
                        autoScroll:true,                       
                        border:1,
                        autoheight: true,
                        collapsed:true,
                        collapsible:true,       
                        animCollapse:true,
                        hideBorders:true,                          
                        items:treeTemp                        
                    });
                
                 if(this.menuHome == null){ this.menuHome = [ItemMain[Index]];}
                 else{this.menuHome[Index] = ItemMain[Index];}
                 Index++;
             break;    
             case "MENU":
                var shtml="";
                for(var j=0;j<Item.length;j++)
                {     
                    var Name = Item[j][0];
                    var Icon = Item[j][4];
                    var Url = Item[j][3];
                    var Type = Item[j][1];
                    var sicon = '<span onclick="menuClick(\''+Url+'\',\''+Name+'\')" onmouseover="mouseOver(this)" onmouseleave="mouseleft(this)" class="SMChild" classout="SMChildOver" classover="SMChildOver">'+
                                        '<table align="center" cellpadding="0" cellspacing="0" align="center" width="100%" ><tr><td><table><tr><td width="16" valign="top"><img class="SMChildImage" width="16" height="16" src="../iconmenu/'+Icon+'"/></td>'+
                                        '<td align="left" valign="top"><label id="'+Name+'" style="font-size:12px;font-family:Tahoma" >'+Name+'</label></td></tr></table>'+                                                           
                                        '</td></tr></table>'+
                                '</span>';
                    shtml = shtml + sicon;           
                 }              
                
                 ItemMain[Index] = new Ext.Panel({ 
                        id:i+'_'+j,    
                        iconCls: icon,                                      
                        title:'<font style="font-weight:bold;font-size:12px;font-family:Tahoma">'+name+'</font>',                
                        hideBorders:true,
                        autoScroll:true,     
                        autoheight: true,
                        collapsed:true,
                        collapsible:true,       
                        animCollapse:true,
                        html:shtml
                 });                    
                 if(this.menuHome == null){ this.menuHome = [ItemMain[Index]];}
                 else{this.menuHome[Index] = ItemMain[Index];}
                 Index++;     
             break;
             case "HOME":
               var shtml="";
               for(var j=0;j<Item.length;j++)
               {    
                    var Name = Item[j][0];
                    var Icon = Item[j][4];
                    var Url = Item[j][3];
                    var Type = Item[j][1];
                
                    var sicon = '<span onclick="menuClick(\''+Url+'\',\''+Name+'\')" onmouseover="mouseOver(this)" onmouseleave="mouseleft(this)" class="SMChild" classout="SMChildOver" classover="SMChildOver">'+
                                        '<table align="center" cellpadding="0" cellspacing="0" align="center" width="100%" ><tr><td><table><tr><td width="16" valign="top"><img class="SMChildImage" width="16" height="16" src="../iconmenu/'+Icon+'"/></td>'+
                                        '<td align="left" valign="top">&nbsp;<label id="'+Name+'" style="font-size:12px;font-family:Tahoma" >'+Name+'</label></td></tr></table>'+                                                           
                                        '</td></tr></table>'+
                                '</span>';
                    shtml = shtml + sicon;           
                 }
                                 
                 ItemMain[Index] = new Ext.Panel({ 
                        id:i+'_'+j,    
                        iconCls: icon,                                      
                        title:'<font style="font-weight:bold;font-size:12px;font-family:Tahoma">'+name+'</font>',                
                        hideBorders:true,
                        autoScroll:true,     
                        autoheight: true,
                        collapsible:true,       
                        animCollapse:true,                                  
                        html:shtml
                 });
                    
                 if(this.menuHome == null){ this.menuHome = [ItemMain[Index]];}
                 else{this.menuHome[Index] = ItemMain[Index];}
                 Index++;  
        }        
    }
}

function ReTreeFunction(subItem,nodeTempMain)
{
    for(var k=0;k<subItem.length;k++)
    {
        var itype = subItem[k][1];                    
        var iurl = subItem[k][3];                  
        var nodeTemp = new Ext.tree.TreeNode({ 
            id : subItem[k][2],                               
            text : subItem[k][0],
            iconCls:subItem[k][4],
            expanded:true
        });
        var subItem2 = subItem[k][5];
        if(subItem2 != null)
        {
            ReTreeFunction(subItem2,nodeTemp);
        }
        else
        {
            MenuArrayMain[subItem[k][0]] = iurl+"$"+itype;                  
            nodeTemp.on('click', function(node,e){
                OnClick(node.text,node.attributes.iconCls,node.id);
            });
        }
        nodeTempMain.appendChild(nodeTemp);
    }
}
function OnClick(text,icon,id)
{
    var sLength = MenuArrayMain[text].split('$');
    var URL = sLength[0];
    var TYPE = sLength[1];
    menuTreeClick(URL,text,icon);
}




function CreateSpan(Url,Name,Icon)
{
     var sicon = '<span onclick="menuClick(\''+Url+'\',\''+Name+'\')" onmouseover="mouseOver(this)" onmouseleave="mouseleft(this)" class="SMChild" classout="SMChildOver" classover="SMChildOver">'+
                                        '<table align="center" cellpadding="0" cellspacing="0" align="center" width="100%" ><tr><td><table><tr><td width="16" valign="top"><img class="SMChildImage" width="16" height="16" src="../iconmenu/'+Icon+'"/></td>'+
                                        '<td align="left" valign="top">&nbsp;<label id="'+Name+'" style="font-size:12px;font-family:Tahoma" >'+Name+'</label></td></tr></table>'+                                                           
                                        '</td></tr></table>'+
                 '</span>';
     return sicon;
}
function mouseOver(span)
{
    span.className = "SMChildOver";
}
function mouseleft(span)
{
    span.className = "SMChild";
}
function menuClick(Url,tabName)
{    
    var tabInformation =  Ext.getCmp('tabinfomation');
    
    var iindex = tabInformation.items.length;
    var bbool = true;
    for(var i=0; i<iindex; i++)
    {        
        if(tabInformation.items.items[i].title==tabName){ 
                bbool = false; 
                tabInformation.items.items[i].show();               
                break;
        }
    }
    if(bbool){
        enableAddTabManagement = true;
        tabInformation.add({
            title: tabName,           
            autoScroll:true,       
            html: '<iframe src="'+Url+'" width="100%" height="100%" frameborder="0"></iframe>',
            closable:true
            }).show();            
     }
}
function menuTreeClick(Url,tabName,tabIcon)
{    
    var tabInformation =  Ext.getCmp('tabinfomation');
    
    var iindex = tabInformation.items.length;
    var bbool = true;
    for(var i=0; i<iindex; i++)
    {        
        if(tabInformation.items.items[i].title==tabName){ 
                bbool = false; 
                tabInformation.items.items[i].show();               
                break;
        }
    }
    if(bbool){
        enableAddTabManagement = true;
        tabInformation.add({
            title: tabName,
            iconCls: tabIcon,            
            autoScroll:true,       
            html: '<iframe src="'+Url+'" width="100%" height="100%" frameborder="0"></iframe>',
            closable:true
            }).show();            
     }
}