function MutilWin(){
    this.contentFrame = top.frames["advanced"].frames["ContentFrame"].frames["ContentViewFrame"];
    this.panelFrame = top.frames["advanced"].frames["ContentFrame"].frames["ContentButtomFrame"];
    this.theFrame = top.frames["advanced"].frames["NavFrame"].frames["NavViewFrame"];
    this.preWin = null;//????????????
    this.preWinId=null;//????????????????
    this.currWin=null;//???????? 
    this.lastWin=null;
    this.winNums=5;
    this.currWinTitle=null;
    this.currWinId=null;
    this.openWinNums=0;
}

MutilWin.prototype.getWin=function(wintitle){

    var theRow = this.panelFrame.document.getElementById("winTabPage");
    
    var thewinid=null;
    var bfind=false;
    var index=0;
    if (wintitle==null)
        return;
    while (!bfind &&index<theRow.cells.length){ 
          
        if (theRow.cells[index].getAttribute("MenuId")==null)
            theRow.cells[index].setAttribute("MenuId","");
        if (theRow.cells[index].getAttribute("MenuId").trim()==wintitle.trim()){
            bfind=true;
            thewinid=theRow.cells[index].getAttribute("id");
        }else
            index++;
    }   
    
    return thewinid;
}
String.prototype.trim = function(){
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
/***********************************************
*??????????????????
***********************************************/
MutilWin.prototype.getIdleWin=function(){
    if(this.panelFrame == null){
        alert("please specify the panelFrame");
        return;
    }
    if(this.contentFrame == null){
        alert("please specify the contentFrame");
        return;
    }
    
    var theCell;
    var theRow = this.panelFrame.document.getElementById("winTabPage");
    if (this.openWinNums==this.winNums){
        theCell = theRow.cells[0];
        var theWin = this.contentFrame.document.getElementById("win_"+theCell.id);
        this.contentFrame.document.body.removeChild(theWin);
        theRow.removeChild(theCell);        
        this.openWinNums--; 
    }
    theCell = this.panelFrame.document.createElement("TD");
    theCell.id="panel_"+parseInt((Math.random()*1000))+parseInt((Math.random()*1000));
    theCell.onclick=function(){changeWin(this.id);};
    theCell.oncontextmenu=function(event){changeWin(this.id);top.frames["advanced"].frames["ContentFrame"].frames["ContentButtomFrame"].contextMenuHandler(event,0);return false;};
    //theCell.setAttribute("onClick","alert(this.id)");
    theCell.className="MutilWinNormal";
    theRow.appendChild(theCell);
    
    if(this.contentFrame.document.getElementById("default")!=null){
        this.contentFrame.document.getElementById("default").style.display="none";
    }  
    var thewin=this.contentFrame.document.createElement("IFRAME");
    thewin.id="win_"+theCell.id;
    thewin.width="100%";
    thewin.height="100%";
    thewin.style.display = "none";
    thewin.style.borderStyle = "none";
    thewin.setAttribute("frameBorder","0");
    this.contentFrame.document.body.appendChild(thewin);
    this.openWinNums++;
    return theCell.id;
}
function changeWin(tabid){
    theFrame=top.frames["advanced"].frames["NavFrame"].frames["NavViewFrame"];
    theFrame.mutilwin.changeWin(tabid);   
}
/*******************************************
*??????????????????
*tabid ???????? ??????????id
********************************************/
MutilWin.prototype.changeWin=function(tabid){
    var theRow=this.panelFrame.document.getElementById("winTabPage");
    //alert(theRow.outerHTML+"||"+tabid+"||"+((this.preWin==null)?this.preWin:this.preWin.id)+"||"+this.preWinId);
    if (typeof tabid!="string")
        return;
    if (this.currWinId==tabid)
        return;
    if (this.preWin!=null){
        this.preWin.style.display = "none";
        this.preWin.style.borderStyle = "none";
        try{
            var theCell = this.panelFrame.document.getElementById(this.preWinId)
            theCell.className="MutilWinNormal";  
        }catch(e){}
    }
    this.panelFrame.document.getElementById(tabid).className="MutilWinSelect";     
    this.preWin=this.contentFrame.document.getElementById("win_"+tabid);
    this.preWinId=tabid;
    this.preWin.style.display = "block";
    this.preWin.style.borderStyle = "none";     
    this.currWin=this.preWin;
    this.currWinId=tabid;   
}

/*************************************
*????????wintitle??????
*wintitle ??????????  ????????
*************************************/

MutilWin.prototype.closeCurrent=function(tabId){
    
    var theRow=this.panelFrame.document.getElementById("winTabPage");
    var theCell=this.panelFrame.document.getElementById(tabId);
    var theCellIndex=theCell.cellIndex;
    if (theCell==null)
        return;
    this.openWinNums--;
    var theWin=this.contentFrame.document.getElementById("win_"+theCell.id);
    this.contentFrame.document.body.removeChild(theWin);
    theRow.removeChild(theCell); 
    if (this.currWinId==tabId){
        if (theCellIndex==0)
            theCellIndex=0;
        else 
            theCellIndex--;
    
        this.preWin=null;
        this.preWinId=null;
    }
     if (this.openWinNums==0){   
            this.resetData();
            return ;
     }else{           
        if (this.currWinId==tabId)
            this.changeWin(theRow.cells[theCellIndex].id);
     }          
}
MutilWin.prototype.getDefault=function(){
	this.closeAll();	
}
/************************************************
*??????????????????
*************************************************/
MutilWin.prototype.closeAll=function(){
    var index;  
    var theRow=this.panelFrame.document.getElementById("winTabPage");
    if (this.openWinNums>0){
        for (index=theRow.cells.length-1;index>=0;index--)
            this.closeCurrent(theRow.cells[index].id);
    }   
    this.resetData();
};
MutilWin.prototype.resetData=function(){
    this.preWin=null;//????????????
    this.preWinId=null;//????????????????
    this.currWin=null;//????????
    this.lastWin=null;//????????????
    this.currWinTitle=null;//??????????????
    this.currWinId=null;//????????????????
    if(this.contentFrame.document.getElementById("default")!=null){
        this.contentFrame.document.getElementById("default").style.display="block";
    }  
}
