/*
 * Handles events from the ddl that picks range/series
 * also refered to as dependent/independent variables
 */
function SeriesManager(axisddlID,dim_browserID,seriesPrefix){
    var AxisDDL;
    var SeriesCount;
    var DBrowser;
    var SeriesPrefix;
    var Buff;
        
    this.Cnt = 0;
    this.SeriesCount = 0;
    this.AxisDDL = axisddlID;
    this.DBrowser = dim_browserID;
    this.SeriesPrefix = seriesPrefix;
    
    this.NewSeries = NewSeries;    
    this.SetNewSeries = SetNewSeries;
    this.SetSelected = SetSelected;
    this.UpdateAxis = UpdateAxis;
    this.Reset = Reset;
    
    function NewSeries(){
        var addl = document.getElementById(this.AxisDDL);  
        this.SeriesCount = this.SeriesCount+1;        
        var prefix = seriesPrefix+this.SeriesCount;       
        this.Buff = window.bf.NewBuffer('load_members.aspx?loadseries=true&prefix='+prefix);
    }
    function SetNewSeries(prefix){   
        var newSeries = frames[this.Buff.name].document.getElementsByTagName('div')[0];        
        newSeries  = document.importNode(newSeries,true);
        var header = newSeries.getElementsByTagName('h5')[0];
        var bd = newSeries.getElementsByTagName('div')[0];        
        var dbrow = document.getElementById('dim_browser');
        dbrow.style.height = document.getElementById('ltd').offsetHeight - document.getElementById('dim_browser_title').offsetHeight - 25;             
        document.getElementById('dim_browser_title').appendChild(header);        
        dbrow.appendChild(bd);       
        SetSelected(newSeries.id);        
        document.body.style.cursor = this.lastCursor;
        window.pb.TogglePButton(true);
        window.bf.DisposeBuffer(this.Buff);
    }
    function SetSelected(id){
        var dbpane =document.getElementById('dim_browser'); 
        var panes = dbpane.getElementsByTagName('div');
        var pane_id = id+'_pane';
        for(i=0;i<panes.length;i++){
            if(panes[i].parentNode != dbpane)continue;//only divs at top level
            var headerid = panes[i].id.substring(0,panes[i].id.length-4)+'title';
            if(panes[i].id == pane_id){
                panes[i].style.display = 'block';
                document.getElementById(headerid).parentNode.parentNode.parentNode.parentNode.className = 'cvsb';
            }else{
                panes[i].style.display = 'none';                
                document.getElementById(headerid).parentNode.parentNode.parentNode.parentNode.className = '';            
            }
        }
    }
    function UpdateAxis(){       
       //var addl = document.getElementById(this.AxisDDL);
       //this.SetSelected(addl[addl.selectedIndex].value);
    }
    function Reset(axisddlID, dim_browserID){
        this.AxisDDL = axisddlID;
        this.DBrowser = dim_browserID;
    }
    function load_new_series(prefix){
       n = document.getElementById('dim_'+prefix);
       frames['sframe'].location = 'load_members.aspx?newseries=true&prefix='+prefix;
    } 
}