﻿// JScript File

        self.tabon = 'menu0';
        self.prevtabon = '';

        function tabgroup(){
            var id = '';
            var tabon = '';
            var prevtabon = '';
            var tabs;
            var topbottom = '';
        }        

        function tab(){
            var name;
            var div;
            var jsfunction;
            var id;
            var closeable;
            var bdisabled = false;
            var bOn;
            var parentdiv = '';
        }
        
        //Change to another tab
        function changetab(newtabid, showdiv, ptabgroup){
            var tabgroup = findtabgroup(ptabgroup);
            var tabarray = tabgroup.tabs;
            
        	var tabonhead_class = '';
        	var taboffhead_class = '';
        	var tabon_class = '';
        	var taboff_class = '';
        	
        	if(tabgroup.topbottom.toUpperCase() == 'BOTTOM'){
        	    tabonhead_class = 'tabonhead_bottom';
        	    taboffhead_class = 'taboffhead_bottom';
        	    tabon_class = 'tabon_bottom';
        	    taboff_class = 'taboff_bottom';
        	}
        	else{
        	    tabonhead_class = 'tabonhead';
        	    taboffhead_class = 'taboffhead';
        	    tabon_class = 'tabon';
        	    taboff_class = 'taboff';
        	}
            
            //close all other tabs
            for(i=0; i<tabarray.length; i++){
                if(document.getElementById(tabarray[i].id + '_head').className == tabonhead_class){
                    document.getElementById(tabarray[i].id + '_head').className = taboffhead_class;
                    document.getElementById(tabarray[i].id + '_body').className = taboff_class;
                }
            }
            
            //set new tab to on
            document.getElementById(newtabid + '_head').className = tabonhead_class;
            document.getElementById(newtabid + '_body').className = tabon_class;
            
            //store last tab that was on
            tabgroup.prevtabon = tabgroup.tabon;
            
            tabgroup.tabon = newtabid;
            //display the div associated with the tab
            //or if it is a js tab then let the custom javascript do the work
            if(showdiv != ''){          
                for(i=0; i<tabarray.length; i++){
                    if(tabarray[i].div == showdiv){
                        document.getElementById(tabarray[i].div).style.display = '';
                        tabarray[i].bOn = true;
                    }
                    else{
                        document.getElementById(tabarray[i].div).style.display = 'none';
                        tabarray[i].bOn = false;
                    }
                }
            }
        }   
        
        //Close a tab
        function closetab(name, ptabgroup){
                var tabgroup = findtabgroup(ptabgroup);
                //Mark whether or not we are closing the same tab we are on
                var bCloseSelf = false;
                if(name == findtabbyid(tabgroup.tabon, ptabgroup).name){
                    bCloseSelf = true
                }
                var tabarray = tabgroup.tabs;
                var newtabarray = new Array();
                var prevtab;
                for(i=0; i<tabarray.length; i++){
                    if(tabarray[i].name != name){
                        newtabarray.push(tabarray[i])
                        prevtab = tabarray[i];
                    }
                    else{
                        document.getElementById(tabarray[i].div).style.display = 'none';
                    }
                }
               tabgroup.tabs = newtabarray;
               buildtabmenu(tabgroup);
               
               //if we are on the tab we are closing then go to the previous tab
               //otherwise just close the tab without changing it
               
               if(bCloseSelf){
                   if(findtabbyid(tabgroup.prevtabon, ptabgroup) != null){
                       tabgroup.tabon = tabgroup.prevtabon;
                       document.getElementById(tabgroup.prevtabon).click();
                       //changetab(tabgroup.prevtabon,findtabbyid(tabgroup.prevtabon, ptabgroup).div, ptabgroup);
                   }
                   else{
                       if(findtabbyid(tabgroup.prevtabon, ptabgroup) != null){
                           document.getElementById(tabgroup.tabon).click();
                           //changetab(tabgroup.tabon,findtabbyid(tabgroup.tabon, ptabgroup).div, ptabgroup);
                       }
                       else{
                           document.getElementById(tabarray[0].id).click();
                           changetab(tabarray[0].id,tabarray[0].div, ptabgroup);
                       }
                   }
               }
        }
        
       
        function buildtabmenu(tabgroup){
            	var strtabs = '';
            	var tabline_seperate_class = '';
            	var tabline_class = '';
            	var tabonhead_class = '';
            	var taboffhead_class = '';
            	var tabon_class = '';
            	var taboff_class = '';
            	
            	if(tabgroup.topbottom.toUpperCase() == 'BOTTOM'){
            	    tabline_seperate_class = 'tabline_seperate_bottom';
            	    tabline_class = 'tabline_bottom';
            	    tabonhead_class = 'tabonhead_bottom';
            	    taboffhead_class = 'taboffhead_bottom';
            	    tabon_class = 'tabon_bottom';
            	    taboff_class = 'taboff_bottom';
            	}
            	else{
            	    tabline_seperate_class = 'tabline_seperate';
            	    tabline_class = 'tabline';
            	    tabonhead_class = 'tabonhead';
            	    taboffhead_class = 'taboffhead';
            	    tabon_class = 'tabon';
            	    taboff_class = 'taboff';
            	}
            	
            	
                strtabs = strtabs + '<table class="tabtable" width="100%" border="0" cellpadding="0" cellspacing="0">';
                strtabs = strtabs + '<tr >';
                strtabs = strtabs + '<td class="' + tabline_seperate_class + '"> &nbsp;</td>';

                var tabarray = tabgroup.tabs;
                
                var parentdiv = ''
                for(i=0; i<tabarray.length; i++){
                    var closeabletxt = '';
                    if(tabarray[i].closeable){
                        closeabletxt = '&nbsp;<span class="closetab" onclick="closetab(\'' + tabarray[i].name + '\',\'' + tabarray[i].parentdiv + '\');">x</span>';
                    }
                    else{
                        closeabletxt = '';
                    }
                                        
                    var onjsclicktxt = '';
                    var onclicktxt = '';
                                     
                    if(tabarray[i].jsfunction != '' && tabarray[i].jsfunction != undefined){
                        if(tabarray[i].bdisabled){
                            onjsclicktxt = '';
                        }
                        else{
                            onjsclicktxt = 'onmouseover="this.style.cursor = \'pointer\';" onmouseout="this.style.cursor = \'\';" onclick="changetab(this.id, \'' + tabarray[i].div + '\',\'' + tabarray[i].parentdiv + '\'); ' + tabarray[i].jsfunction + '"';
                        }                      
                        if(tabarray[i].parentdiv + '_menu' + i==tabgroup.tabon){
                            if(tabgroup.topbottom.toUpperCase() == 'BOTTOM'){
                                strtabs = strtabs + '<td id="' + tabarray[i].parentdiv + '_menu' + i + '"' + onjsclicktxt + '><div id="' + tabarray[i].parentdiv + '_menu' + i + '_body" class="' + tabon_class + '">' + tabarray[i].name + '' + closeabletxt + '</div><div id="' + tabarray[i].parentdiv + '_menu' + i + '_head" class="' + tabonhead_class + '"></div></td>';
                            }
                            else{
                                strtabs = strtabs + '<td id="' + tabarray[i].parentdiv + '_menu' + i + '"' + onjsclicktxt + '><div id="' + tabarray[i].parentdiv + '_menu' + i + '_head" class="' + tabonhead_class + '"></div><div id="' + tabarray[i].parentdiv + '_menu' + i + '_body" class="' + tabon_class + '">' + tabarray[i].name + '' + closeabletxt + '</div></td>';
                            }
                            tabarray[i].id = tabarray[i].parentdiv + '_menu' + i;
                        }
                        else{
                            if(tabgroup.topbottom.toUpperCase() == 'BOTTOM'){
                                strtabs = strtabs + '<td id="' + tabarray[i].parentdiv + '_menu' + i + '"' + onjsclicktxt + '><div id="' + tabarray[i].parentdiv + '_menu' + i + '_body" class="' + taboff_class + '">' + tabarray[i].name + '' + closeabletxt + '</div><div id="' + tabarray[i].parentdiv + '_menu' + i + '_head" class="' + taboffhead_class + '"></div></td>'; 
                            }
                            else{
                                strtabs = strtabs + '<td id="' + tabarray[i].parentdiv + '_menu' + i + '"' + onjsclicktxt + '><div id="' + tabarray[i].parentdiv + '_menu' + i + '_head" class="' + taboffhead_class + '"></div><div id="' + tabarray[i].parentdiv + '_menu' + i + '_body" class="' + taboff_class + '">' + tabarray[i].name + '' + closeabletxt + '</div></td>'; 
                            }                            
                            
                            tabarray[i].id = tabarray[i].parentdiv + '_menu' + i;
                        }
                    }
                    else{
                        if(tabarray[i].bdisabled){
                            onclicktxt = '';
                        }
                        else{
                            onclicktxt = 'onmouseover="this.style.cursor = \'pointer\';" onmouseout="this.style.cursor = \'\';" onclick="changetab(this.id, \'' + tabarray[i].div + '\',\'' + tabarray[i].parentdiv + '\'); "';
                        }   
                        if(tabarray[i].parentdiv + '_menu' + i==tabgroup.tabon){
                            if(tabgroup.topbottom.toUpperCase() == 'BOTTOM'){
                                strtabs = strtabs + '<td id="' + tabarray[i].parentdiv + '_menu' + i + '"' + onclicktxt + '><div id="' + tabarray[i].parentdiv + '_menu' + i + '_body" class="' + tabon_class + '">' + tabarray[i].name + '' + closeabletxt + '</div><div id="' + tabarray[i].parentdiv + '_menu' + i + '_head" class="' + tabonhead_class + '"></div></td>';
                            }
                            else{
                                strtabs = strtabs + '<td id="' + tabarray[i].parentdiv + '_menu' + i + '"' + onclicktxt + '><div id="' + tabarray[i].parentdiv + '_menu' + i + '_head" class="' + tabonhead_class + '"></div><div id="' + tabarray[i].parentdiv + '_menu' + i + '_body" class="' + tabon_class + '">' + tabarray[i].name + '' + closeabletxt + '</div></td>';
                            }
                            tabarray[i].id = tabarray[i].parentdiv + '_menu' + i;
                        }
                        else{
                            if(tabgroup.topbottom.toUpperCase() == 'BOTTOM'){
                                strtabs = strtabs + '<td id="' + tabarray[i].parentdiv + '_menu' + i + '"' + onclicktxt + '><div id="' + tabarray[i].parentdiv + '_menu' + i + '_body" class="' + taboff_class + '">' + tabarray[i].name + '' + closeabletxt + '</div><div id="' + tabarray[i].parentdiv + '_menu' + i + '_head" class="' + taboffhead_class + '"></div></td>'; 
                            }
                            else{
                                strtabs = strtabs + '<td id="' + tabarray[i].parentdiv + '_menu' + i + '"' + onclicktxt + '><div id="' + tabarray[i].parentdiv + '_menu' + i + '_head" class="' + taboffhead_class + '"></div><div id="' + tabarray[i].parentdiv + '_menu' + i + '_body" class="' + taboff_class + '">' + tabarray[i].name + '' + closeabletxt + '</div></td>'; 
                            }
                            
                            tabarray[i].id = tabarray[i].parentdiv + '_menu' + i;
                        }
                    }
                    
                    strtabs = strtabs + '<td class="' + tabline_seperate_class + '"> &nbsp;</td>';
                }

                strtabs = strtabs + '<td class="' + tabline_class + '">&nbsp;</td>';
                strtabs = strtabs + '</tr>';
                strtabs = strtabs + '</table>'; 
                document.getElementById(tabgroup.id).innerHTML = strtabs;
                //alert(document.getElementById(tabgroup.id).innerHTML);
        }
        
        function addtab(name, div, bCloseable, bDisabled, parentdiv, topbottom){
                var bfound = false;
                
                var tabgroup1;
                if(self.tabgroups == null){
                    self.tabgroups = new Array();
                }
                
                
                for(i=0; i<self.tabgroups.length; i++){
                    if(self.tabgroups[i].id == parentdiv){
                        bfound = true;
                        tabgroup1 = self.tabgroups[i];
                    }
                }
                
                if(!bfound){
                    tabgroup1 = new tabgroup();
                    tabgroup1.id = parentdiv;
                    tabgroup1.tabon = parentdiv + '_menu0';
                    if(topbottom == undefined){
                        tabgroup1.topbottom = 'TOP';
                    }
                    else{
                        tabgroup1.topbottom = topbottom;
                    }
                    
                }
                
                if(tabgroup1.tabs == null){
                   tabgroup1.tabs = new Array();
                }
                
                self.tabgroups.push(tabgroup1);               
                
            if(findtab(name, parentdiv) == null){
                var tab1 = new tab();
                tab1.name = name;
                tab1.div = div;
                tab1.closeable = bCloseable;
                tab1.bdisabled = bDisabled;
                tab1.parentdiv = parentdiv;

                var curtabgroup = findtabgroup(tabgroup1.id);

                curtabgroup.tabs.push(tab1);
                
                buildtabmenu(curtabgroup);
            }
            
        }
        
       function addjstab(name, jsfunction, div, bCloseable, bDisabled, parentdiv, topbottom){
                var bfound = false;
                
                var tabgroup1;
                if(self.tabgroups == null){
                    self.tabgroups = new Array();
                }
                
                
                for(i=0; i<self.tabgroups.length; i++){
                    if(self.tabgroups[i].id == parentdiv){
                        bfound = true;
                        tabgroup1 = self.tabgroups[i];
                    }
                }
                
                if(!bfound){
                    tabgroup1 = new tabgroup();
                    tabgroup1.id = parentdiv;
                    tabgroup1.tabon = parentdiv + '_menu0';
                    if(topbottom == undefined){
                        tabgroup1.topbottom = 'TOP';
                    }
                    else{
                        tabgroup1.topbottom = topbottom;
                    }
                }
                
                if(tabgroup1.tabs == null){
                   tabgroup1.tabs = new Array();
                }
                
                self.tabgroups.push(tabgroup1); 
                
                
            if(findtab(name, parentdiv) == null){
                var tab1 = new tab();
                tab1.name = name;
                tab1.div = div;
                tab1.jsfunction = jsfunction;
                tab1.closeable = bCloseable;
                tab1.bdisabled = bDisabled;
                tab1.parentdiv = parentdiv;
                
                 var curtabgroup = findtabgroup(tabgroup1.id);

                curtabgroup.tabs.push(tab1);
                
                buildtabmenu(curtabgroup);
            }
            
        }
        
        function findtabgroup(name){
            var tabarray = self.tabgroups;
            
            if(tabarray != null){
                for(i=0; i<tabarray.length; i++){
                    if(tabarray[i].id == name){
                        return tabarray[i];
                    }
                }
            }
            return null;
        }
        
       function findtab(name, parentdiv){
            var tabarray = findtabgroup(parentdiv).tabs;
            if(tabarray != null && tabarray != ''){
                for(i=0; i<tabarray.length; i++){
                    if(tabarray[i].name == name){
                        return tabarray[i];
                    }
                }
            }
            return null;
        }
        
        function findtabbyid(id, parentdiv){
            var tabarray = findtabgroup(parentdiv).tabs;
            if(tabarray != null && tabarray != ''){
                for(i=0; i<tabarray.length; i++){
                    if(tabarray[i].id == id){
                        return tabarray[i];
                    }
                }
            }
            return null;
        }
        
