﻿// JScript 文件

   
HObject = function(){};
var HWQ = new HObject(); 

/*左边菜单的代码*/
KMenu = function(o){
    this.TopIDs = {};
    this.ID = '';

    this.ShowItem = function(index){        
        for(var i = 0 ;i < this.TopIDs.length ;i++){
            
            var id = this.TopIDs[i];
            var txtID = this.ID + "_SUB_" + id;
            var obj = document.getElementById(txtID);
        
            if (id == index){
                obj.style.display = '';
            }
            else {
                obj.style.display = 'none';
            }
        }
    };
        
        
    this.init = function(o){
        this.TopIDs = o.TopIDs;
        this.ID = o.ID;
    };
    
    
    this.init(o);
};


/*主菜单代码*/
KMainMenu = function(o){
    this.TopIDs = {};
    this.ID = '';

    this.ShowItem = function(index){

        for(var i = 0 ;i < this.TopIDs.length ;i++){
            
            var id = this.TopIDs[i];
            
            
            var txtID = this.ID + "_SUB_" + id;
            var obj = document.getElementById(txtID);
        
            if (id == index){
                obj.style.display = '';
            }
            else {
                obj.style.display = 'none';
            }
            
            //改变背景的样式
            var keID = this.ID + "_K_" + id;
            
            //var keID = this.ID + "_" + id;
            
            
            var kObj = document.getElementById(keID);
            
            if(id == index){
                kObj.className = 'MainMenu_ItemSelected';
            }
            else {
                kObj.className = 'MainMenu_Item';
            }
        }
    };
        
        
    this.init = function(o){
        this.TopIDs = o.TopIDs;
        this.ID = o.ID;
    };
    
    
    this.init(o);
};

KDynMenu = function(o){
    var ID = '';            //控件ID
    var TopIDs = {};        //主菜单ID 集合
    var ChildIDs = {};      //弹出的子菜单集合
    var DynamicTop = 33;    //动态弹出菜单的相对高度
    
    var UniteItemIDs = {};  //联合菜单的ID 集合
    
    //显示菜单内容
    this.Show = function(id){
    
        
        for(var i = 0;i < this.TopIDs.length ; i++){

            var txtID = this.ID + "_CPanel_" + this.TopIDs[i];
            
            var objA = document.getElementById(txtID);
            var objB = document.getElementById(  this.ChildIDs[i] );
            
            if( objB == '' || objB == null ){
                return;
            }
            
//            alert(id + "    " + this.ChildIDs[i]);

            if (id == this.ChildIDs[i]) {        
                var t=objA.offsetTop;   
                var l=objA.offsetLeft;   
                var height=objA.offsetHeight;   
                while(objA=objA.offsetParent) {   
                    t+=objA.offsetTop;   
                    l+=objA.offsetLeft;   
                }   
                
                objB.style.top = t + this.DynamicTop;
                objB.style.left = l;
                
                
                objB.style.visibility = 'visible';
            }
            else {
                objB.style.visibility = 'hidden';
            }
        }
    }
    
    //初始化联合控件的事件
    this.initUniteItem = function(){
        
        for(var i = 0;i < this.TopIDs.length ; i++){
            
            var txtID = this.UniteItemIDs[i];
            
            if(txtID == ""){
                continue;
            }
            
            var objA = document.getElementById(txtID);
            
            if(objA == null || objA == ""){
                continue;
            }


            objA.TopID = this.ChildIDs[i];
            

            objA.ClientID = this.ID;
            
            
            objA.onmousemove = function(){
                
                var _tmpID = this.TopID;
                
                var txt = "HWQ." + this.ClientID + ".Show('" + _tmpID + "');";
                
                
                try{
                    eval(txt);
                }
                catch(ex){
                    alert(ex.description);
                }
            };
            
        } 
    };
    
    this.init = function(o){
        this.ID = o.ID;
        this.TopIDs = o.TopIDs;
        this.ChildIDs = o.ChildIDs;
        
        if(o.UniteItemIDs ){
            this.UniteItemIDs = o.UniteItemIDs;
        }
        
        if(o.DynamicTop )
        {
            this.DynamicTop = o.DynamicTop;
        }
    };
    
    this.init(o);
    this.initUniteItem();
};

