/* Description: This file has the code to construct the third and fourth level navigation.
*/
function LeftMenu(){
}
LeftMenu.prototype.ht=100; //minimum height of left nav
LeftMenu.prototype.top=188;
LeftMenu.prototype.width=172;
LeftMenu.prototype.bgColor="#d0dde9";
LeftMenu.prototype.lineBgColor="#f9fcff";
LeftMenu.prototype.dotBgColor="#ffffff";
LeftMenu.prototype.bottomImage="4dots.gif";
LeftMenu.prototype.leftNavDiv="leftnavdiv"
LeftMenu.prototype.hiliteColor="#f9fcff"; // bgcolor of an item that is "On" for this page
LeftMenu.prototype.activeColor="#e5edf7"; // when the user clicks on a particular item, the items bgcolor changes to this
LeftMenu.prototype.arrowImg="/img/left_menu_arrow12.gif";
LeftMenu.prototype.topSpc=15;
LeftMenu.prototype.btmSpc=60;
LeftMenu.prototype.tpad=5;
LeftMenu.prototype.fpad=4;
LeftMenu.prototype.currOpt=-1;
LeftMenu.prototype.thirdIndexOn=-1;
LeftMenu.prototype.fourthIndexOn=-1;
LeftMenu.prototype.loadImages=LMloadImages;
LeftMenu.prototype.setMenuHt=LMsetMenuHt;
LeftMenu.prototype.toggleChild=LMtoggleChild;
LeftMenu.prototype.toggle=LMtoggle;
LeftMenu.prototype.arrange=LMarrange;
LeftMenu.prototype.enable=LMenable;
LeftMenu.prototype.build=LMbuild;
LeftMenu.prototype.buildTop=LMbuildTop;
LeftMenu.prototype.buildBottom=LMbuildBottom;
LeftMenu.prototype.buildThird=LMbuildThird;
LeftMenu.prototype.buildFourth=LMbuildFourth;
LeftMenu.prototype.getThirdHtml=LMgetThirdHtml;
LeftMenu.prototype.getFourthHtml=LMgetFourthHtml;

LeftMenu.prototype.NORMAL= 0;
LeftMenu.prototype.ACTIVE= 1;
LeftMenu.prototype.HILITE = 2;

function showDiv(divName){
    var divObj=getDivObj(divName);
    var styleObj=new xbStyle(divObj);
    styleObj.setVisibility("visible");
}
function hideDiv(divName){
    var divObj=getDivObj(divName);
    var styleObj=new xbStyle(divObj);
    styleObj.setVisibility("hidden");
}

function LMloadImages(){
    newImage("/img/plus.gif");
    newImage("/img/minus.gif");
    newImage("/img/plus_grey.gif");
    newImage("/img/4dots.gif");
    newImage("/img/left_menu_arrow.gif");
    newImage("/img/left_menu_arrow_bgf1ede1.gif");
}

function LMsetMenuHt(){
    var i=0;
    var ht=0;
    var childht=0;
    var so=new xbStyle(getDivObj("lm_0"));
    var tht=so.getHeight();
    ht=ht+tht;
    for(i=1;i<=this.menuArray.length;i++){
        so=new xbStyle(getDivObj("lm_"+i));
        tht=so.getHeight();
        ht=ht+tht;
        so=new xbStyle(getDivObj("lm_"+i+"_child"));
        tht=so.getHeight();
        if(childht<tht) childht=tht;
    }
    ht=ht+childht;
    var divObj=getDivObj("lm_"+(this.menuArray.length+1));
    if(divObj){
        so=new xbStyle(divObj);
        ht=ht+so.getHeight();
    }
    so=new xbStyle(getDivObj("leftNav"));
    so.setClipLeft(0);
    so.setClipRight(this.width);
    so.setClipTop(0);
    so.setClipHeight(ht);
    so.setClipWidth(this.width);
    so.setHeight(ht);
}

function LMtoggleChild(i){
    if(this.currOpt!=-1){
        this.toggle(this.currOpt,'false');
        if(this.currOpt==i)this.currOpt=-1;
        else this.currOpt=i;
    }else this.currOpt=i;
    if(this.currOpt!=-1) this.toggle(this.currOpt,'true');
}

function LMtoggle(i,bShowChild){
    var soP = new xbStyle(getDivObj("lm_"+i));
    var soC = new xbStyle(getDivObj("lm_"+i+"_child"));
    if(bShowChild=='true'){
        soC.setTop(soP.getTop());
        soP.setVisibility("hidden");
        soC.setVisibility("visible");
        this.arrange(i,bShowChild);
    }else{
        soP.setTop(soC.getTop());
        soC.setVisibility("hidden");
        soP.setVisibility("visible");
        this.arrange(i,bShowChild);
    }
}
function LMarrange(j,bShowChild){
    var i=0;
    var ht=0;
    var tp=0;
    var so;

    if(bShowChild=='false')so=new xbStyle(getDivObj("lm_"+j));
    else so=new xbStyle(getDivObj("lm_"+j+"_child"));

    tp=so.getTop();
    ht=so.getHeight();
    for(i=j+1;i<=(this.menuArray.length+1);i++){
        var divName="lm_"+i;
        var styleObj=new xbStyle(getDivObj(divName));
        if(styleObj.getVisibility()=='visible'){
            styleObj.setTop(tp+ht);
            ht=ht+styleObj.getHeight();
        }
    }
}

function LMenable(tIndex,fIndex){// Indices are zero based
    this.thirdIndexOn=tIndex;
    this.fourthIndexOn=fIndex;
}

function LMbuild(){
    document.write('<div class="absinv" id="lm_dummy"></div>');
    document.write('<div class="'+this.leftNavDiv+'" id="leftNav">');
    document.write(this.buildTop());
    var i = 0;
    for(i=0;i<this.menuArray.length;i++){
        document.write(this.buildThird(i));
        document.write(this.buildFourth(i));
    }
    document.write(this.buildBottom());
    document.write('</div>');
}

function LMbuildTop(){
    var s="";
    s+='<div class="absinv" id="lm_0">';
    s+='<table width='+this.width+' border=0 cellspacing=0 cellpadding=0 bgcolor="'+this.bgColor+'">';
    s+='<tr><td><img src="/img/s.gif" width="1" height="'+this.topSpc+'"></td></tr>';
    s+='</table>';
    s+='</div>';
    return s;
}

function LMbuildBottom(){
    var s="";
    s+='<div  id="lm_'+(this.menuArray.length+1)+'" class="absinv" >';
    s+='<table width='+this.width+' border=0 cellspacing=0 cellpadding=0 bgcolor="'+this.bgColor+'">';
    s+='<tr><td><img src="/img/s.gif" width="1" height="65"></td></tr>';
    s+='<tr><td bgcolor="'+this.lineBgColor+'"><img src="/img/s.gif" width="1" height="1"></td></tr>';
    s+='<tr><td bgcolor="'+this.dotBgColor+'" align="right"><img border=0 src="/img/'+this.bottomImage+'"></td></tr>';
    s+='</table>';
    s+='</div>';
    return s;

}
function LMbuildThird(tIndex){
    var id=tIndex+1;
    var s="";
    s+='<div class="absinv" id="lm_'+id+'">';
    var bHasChildren=(this.menuArray[tIndex][2].length==0)?('false'):('true');
    if(this.thirdIndexOn==tIndex){
        if((this.fourthIndexOn==-1)&&(bHasChildren=='false')){
            s+=this.getThirdHtml(tIndex,this.HILITE);
        }else{
            s+=this.getThirdHtml(tIndex,this.NORMAL);
        }
    }else{
        s+=this.getThirdHtml(tIndex,this.NORMAL);
    }
    s+='</div>';
    return s;
}

function LMbuildFourth(tIndex){
    var tid=tIndex +1;
    var s="";
    s+='<div class="absinv" id="lm_'+tid+'_child">';
    var bHasChildren=(this.menuArray[tIndex][2].length==0)?('false'):('true');
    if(this.thirdIndexOn==tIndex){
        if((this.fourthIndexOn==-1)&&(bHasChildren=='false')){
            s+=this.getThirdHtml(tIndex,this.HILITE);
        }else{
            s+=this.getThirdHtml(tIndex,this.ACTIVE);
        }
    }else{
        s+=this.getThirdHtml(tIndex,this.ACTIVE);
    }

    var i=0;
    if(bHasChildren=='true'){
        s+='<table width='+this.width+' border=0 cellspacing=0 cellpadding=0 bgcolor="'+this.activeColor+'">';
        for(i=0;i<this.menuArray[tIndex][2].length;i++){
            s+=this.getFourthHtml(tIndex, i);
        }
        s+='<tr><td colspan=3><img src="/img/s.gif" width="1" height="15"></td></tr>';
        s+='</table>';
    }
    s+='</div>';
    return s;

}
function LMgetThirdHtml(tIndex,hiliteState /* NORMAL, ACTIVE, HILITE*/ ){
    var id=tIndex+1;
    var bHasChildren=(this.menuArray[tIndex][2].length==0)?('false'):('true');
    var img="plus";
    var bgClr=this.bgColor;
    var hrefStr='javascript:lm.toggleChild('+id+');';
    var targetStr='';
    if(hiliteState==this.NORMAL){
        if(bHasChildren=='true') {
            img="/img/plus.gif";
        }
        else{
            img="/img/plus_grey.gif";
            hrefStr=this.menuArray[tIndex][1];
            targetStr=' target="_top" ';
        }
        bgClr=this.bgColor;
    }else if(hiliteState==this.ACTIVE){
        if(bHasChildren=='true') img="/img/minus.gif";
        else{
            img="/img/plus_grey.gif";
            hrefStr=this.menuArray[tIndex][1];
            targetStr=' target="_top" ';
        }
        bgClr=this.activeColor;
    }else if(hiliteState==this.HILITE){
        img=this.arrowImg;
        bgClr=this.hiliteColor;
        hrefStr=this.menuArray[tIndex][1];
    }
    var s="";
    s+='<table width='+this.width+' border=0 cellspacing=0 cellpadding=0 bgcolor="'+bgClr+'">';
    s+='<tr>';
    s+='<td colspan=5><img src="/img/s.gif" width="1" height="'+this.tpad+'"></td>';
    s+='</tr>';
    s+='<tr>';
    s+='<td><img src="/img/s.gif" width="3" height="1"></td>';
    s+='<td valign="top"><a href="'+hrefStr+'" class="thirdnav"'+targetStr+'><img src="'+img+'" width="12" height="12" border="0"></a></td>';
    s+='<td><img src="/img/s.gif" width="3" height="1"></td>';
    s+='<td><a href="'+hrefStr+'" class="thirdnav"'+targetStr+'>'+this.menuArray[tIndex][0]+'</a></td>';
    s+='<td><img src="/img/s.gif" width="20" height="1"></td>';
    s+='</tr>';
    s+='<tr>';
    s+='<td><img src="/img/s.gif" width="3" height="'+this.tpad+'"></td>';
    s+='<td><img src="/img/s.gif" width="12" height="1"></td>';
    s+='<td><img src="/img/s.gif" width="3" height="1"></td>';
    s+='<td><img src="/img/s.gif"  width="'+(this.width-38)+'" height="1"></td>';
    s+='<td><img src="/img/s.gif" width="20" height="1"></td>';
    s+='</tr>';
    s+='</table>';
    return s;
}

function LMgetFourthHtml(tIndex, fIndex){
    var bgClr=this.activeColor;
    var imgStr='<img src="/img/s.gif" width="18" height="1">';
    if((tIndex==this.thirdIndexOn) && (fIndex==this.fourthIndexOn)){
        bgClr=this.hiliteColor;
        imgStr='<img src="/img/s.gif" width="5" height="1"><img src="/img/left_menu_arrow.gif" width="9" height="9"><img src="/img/s.gif" width="4" height="1">';
    }
    var s="";
    s+='<tr bgcolor="'+bgClr+'">';
    s+='<td colspan=3><img src="/img/s.gif" width="1" height="'+this.fpad+'"></td>';
    s+='</tr>';
    s+='<tr bgcolor="'+bgClr+'">';
    s+='<td valign="middle">'+imgStr+'</td>';
    s+='<td><a href="'+this.menuArray[tIndex][2][fIndex][1]+'" class="fourthnav" target="_top">'+this.menuArray[tIndex][2][fIndex][0]+'</a></td>';
    s+='<td><img src="/img/s.gif" width="1" height="1"></td>';
    s+='</tr>';
    s+='<tr bgcolor="'+bgClr+'">';
    s+='<td><img src="/img/s.gif" width="18" height="'+this.fpad+'"></td>';
    s+='<td><img src="/img/s.gif" width="'+(this.width-38)+'" height="'+this.fpad+'"></td>';
    s+='<td><img src="/img/s.gif" width="10" height="'+this.fpad+'"></td>';
    s+='</tr>';
    return s;
}

var lm;
function LMbuildLeftMenu(menuArray,tIndex,fIndex){
    // menuArray - contains the elements of the third and fourth level menus
    // tIndex - indicates the index of the third nav element to be highlighted by default; -1 indicates nothing to be highlighted
    // fIndex - indicates the index of the fourth nav element to be highlighted by default; -1 indicates nothing to be highlighted
    lm=new LeftMenu();
    lm.menuArray=menuArray;
    lm.enable(tIndex,fIndex);
    lm.build();
}
function alignLeftMenu(){

    showDiv("lm_0");
    for(id=1;id<=lm.menuArray.length;id++){
        showDiv("lm_"+id);
        hideDiv("lm_"+id+"_child");
    }
    showDiv("lm_"+(lm.menuArray.length+1));
    showDiv("leftNav");
    lm.setMenuHt();
    lm.arrange(0,'false');
    if(lm.thirdIndexOn!=-1) lm.toggleChild(lm.thirdIndexOn+1);
}

