tab={
panel:document.createElement("div"),
pagesPanel:document.createElement("div"),
pages:[],
tabsPanel:document.createElement("div"),
tabs:[],
create:function(elm,evt){
    this.elm = elm;
    this.elm.style.display = "none";
    this.id = (arguments[2] == undefined) ? 0 : arguments[2];
    this.tabsPanel.className = "tabs";
    this.pagesPanel.className = "pages";
    var cs = this.elm.childNodes;
    for (var i = 0; i < cs.length; i++) {
        if(cs[i].nodeType != 3){
            if(cs[i].nodeName == 'DT'){
                    var newTab = this.createTab(cs[i].innerHTML.replace(/^\s+|\s+$/g,""));
                    newTab.id = this.tabs.length;
                    if(evt)
                    if(typeof evt[newTab.id] == "function") newTab.evtHandle = evt[newTab.id];
                    this.tabs.push(newTab);
                    this.tabsPanel.appendChild(newTab);
            }else{
                    var newPage= this.createPage(cs[i].innerHTML);
                    newPage.id = this.pages.length;
                    this.pages.push(newPage);
                    this.pagesPanel.appendChild(newPage);
            }
            cs[i].style.display = "none";
        }
    }
    this.pages[this.id].style.display = 'block';
    if(evt)
    if(typeof evt[this.id] == "function") evt[this.id](this.pages[this.id]);
    this.tabs[this.id].className = "tab_selected";
    this.panel.appendChild(this.tabsPanel);
    this.panel.appendChild(this.pagesPanel);
    this.elm.parentNode.replaceChild(this.panel,this.elm);
},
createPage:function(w){
    page = document.createElement("div");
    page.innerHTML = w;
    page.style.display="none";
    return page;
},
createTab:function(w){
    var _tb = document.createElement("A");
    _tb.innerHTML = w;
    _tb.className = "tab";
    _tb.master = this;
    _tb.onclick = function (){
        this.master.tabs[this.master.id].className = "tab";
        this.className = "tab_selected";
        this.master.pages[this.master.id].style.display = "none";
        this.master.pages[this.id].style.display = "block";
        this.master.id = this.id;
        if(this.evtHandle)
        this.evtHandle(this.master.pages[this.id]);
        };
    return _tb;}
}