﻿var DY = DY ? DY : {};

DY.tab=function(){
    this.title   = new Array();
    this.body    = new Array();
    this.def     = '';
    this.curr    = '';
    this.onCss = '';
    this.offCss  = '';
    this.titleObj;    
    this.bodyObj;
    
    this.$id     = function(id){return document.getElementById(id);};
    this.init    = function(titles, bodys, id)
    {
        this.title = titles.split(',');
        this.body  = bodys.split(',');
        if(this.title.length!=this.body.length)
        {
            alert(this.title.length+'must the same lenght'+this.body.length);
        }else if(id){
            this.select(id);
        }
        
    };
    this.select  = function(id)
    {
        for(var i=0; i<this.title.length; i++){
            this.titleObj = this.$id(this.title[i]);
            this.bodyObj = this.$id(this.body[i]);
            
            if(id!=this.title[i])
            {    
                 if(this.titleObj!=null&&this.bodyObj!=null){
                        this.titleObj.className = this.titleObj.className.replace(this.onCss ,'') + ' '+this.offCss;
                        this.bodyObj.style.display = 'none';
                    }
            }else{
              if(this.titleObj!=null&&this.bodyObj!=null){
                this.titleObj.className = this.titleObj.className.replace(this.offCss,'') + ' '+this.onCss;
                this.bodyObj.style.display = '';
                }
            }
        }
        this.curr = id;
    };
};
DY.Common = {
    Fav:function(title,url){
        if (window.sidebar){    //FF
            window.sidebar.addPanel(title, url,"");
        }else if(document.all ){//IE
            window.external.AddFavorite( url, title);
        }else if(window.opera && window.print ){
            return true;
        }
    },
    CheckNull:function(id, tip, def){
        var obj;
        var def = def?def:'';
        if(typeof id == 'string')
        {
            obj = document.getElementById(id);
        }else{
            obj = id;
        }
        if(!obj.value && (obj.value=='' || obj.value==def)){
            alert(tip);
            obj.focus();
            return false;
        }
    },
    ShowDef:function(id, def, color){
        var obj;
        var def = def?def:'';
        if(typeof id == 'string')
        {
            obj = document.getElementById(id);
        }else{
            obj = id;
        }
        if(!obj.value && obj.value==''){
             obj.value=def;
             if(color){
                obj.style.color=color;
             }
        }
    },
    HideDef:function(id, def, color){
        var obj;
        var def = def?def:'';
        if(typeof id == 'string')
        {
            obj = document.getElementById(id);
        }else{
            obj = id;
        }
        if(obj.value==def){
            obj.value='';
            if(color)
            obj.style.color=color;
        }
    }
};
