function buildTable(tbl,tblname,width,tableType) {
//  the parameter 'tableType' gets the value 'inst' for inst pages and causes the tabbed table to have a straightlined bottom, instead of the stepped bottom as in retail pages
//  alert("buildTable");
    quote="'";
    var isBorderNeeded = (tbl[4][1]!="false")?true:false;
    var border = 0;
//  alert(tblLoc);
    str = '<DIV ID="' + tblname + 'wrapper" style="position:relative; top:0; left:0;">';    
//  for (x=0; x<tbl[1].length;x++) {            // number of different states
        for (y=0; y<tbl[2].length;y++) {        // number of tabs per state (should always be equal per state) i.e. if one state has 2 tabs the second state should also have exactly 2 tabs (tbl[3][0].length==tbl[3][1].length==....)
            str += '<DIV ID="' + tblname + 'TAB' + y + '" class="absinv">';
            str += '    <table cellspacing=0 cellpadding=0 border=0 width=' + width + '>';
        
            str += '        <tr>';
//          str += '            <td width="1"><IMG src="/share/img/s.gif" width=1 height=1></TD>';
            str += '            <td>';
            
            // Header and Instruction Text 
            str += '                <TABLE width=' + width + ' border=0 cellspacing=0 cellpadding=0>';
            str += '                    <TR>';              
            str += '                        <TD width=5><IMG src="/share/img/s.gif" width=5 height=1></TD>';
            str += '                        <TD><SPAN class="head4">' + tbl[0][0] + '</SPAN></TD>';
            str += '                        <TD align="right"><SPAN class="smbodycon">' + tbl[0][1] + '</SPAN></TD>';
            str += '                        <TD width=5><IMG src="/share/img/s.gif" width=5 height=1></TD>';
            str += '                    </TR>';             
            str += '                    <TR>';
            str += '                        <TD colspan=4><IMG src="/share/img/s.gif" width=1 height=5 border=0></TD>';
            str += '                    </TR>';
            str += '                    <TR>';
            str += '                        <TD width=5><IMG src="/share/img/s.gif" width=5 height=1></TD>';
            str += '                        <TD colspan=2><span class="insttext">' + tbl[1][0] + '</span></TD>';
            str += '                        <TD width=5><IMG src="/share/img/s.gif" width=5 height=1></TD>';
            str += '                    </TR>';
            str += '                    <TR>';
            str += '                        <TD colspan=4><IMG src="/share/img/s.gif" width=1 height=5 border=0></TD>';
            str += '                    </TR>';
            str += '                </TABLE>';
            // End of Header and Instruction Text 
            
            // Tabs
            if (tbl[2].length==1) {         // this is for a single tabbed table
                border = (isBorderNeeded)?1:0;
                str += '            <table width=' + width + ' border=0 cellspacing=0 cellpadding=0>';
                str += '                <TR>';
                if(isBorderNeeded){
                str += '                    <td rowspan=3 bgcolor="#99A9C4"><IMG SRC="/share/img/s.gif" WIDTH=1 HEIGHT=22></td>';
                }
                str += '                    <td bgcolor="#99A9C4"><IMG SRC="/share/img/s.gif" WIDTH=165 HEIGHT=1></td>';
                str += '                    <td rowspan=3><IMG SRC="/share/img/rt_tab_on.gif" WIDTH=15 HEIGHT=22></td>';
                var twidth = 180+border;
                str += '                    <td width=' + (width - twidth) + '><IMG SRC="/share/img/s.gif" WIDTH=' + (width - twidth) + ' HEIGHT=1></td>';
                
//              str += '                    <td><IMG SRC="/share/img/s.gif" WIDTH=1 HEIGHT=1></td>';
                str += '                </TR>';
                str += '                <TR>';
                str += '                    <td height=21 rowspan=2 bgcolor="#ffffff"><IMG SRC="/share/img/s.gif" WIDTH=5 HEIGHT=1><span class="head4">' + tbl[2][y][0] + '</span><span class="smbodycon">' + tbl[2][y][1]  + '</span></td>';
                str += '                    <td width=' + (width - twidth) + ' align="right" valign="top"><IMG SRC="/share/img/s.gif" WIDTH=' + (width - twidth) + ' HEIGHT=20></td>';
//              str += '                    <td><IMG SRC="/share/img/s.gif" WIDTH=1 HEIGHT=20 border=0></td>';
                str += '                </TR>';
                str += '                <TR>';
                str += '                    <td bgcolor="#99A9C4"><IMG SRC="/share/img/s.gif" WIDTH=' + (width - twidth) + ' HEIGHT=1></td>';
//              str += '                    <td><IMG SRC="/share/img/s.gif" WIDTH=1 HEIGHT=1></td>';
                str += '                </TR>';
                str += '            </table>';

            } else if (tbl[2].length>1) {       // this is for a multi tabbed table

                if (y==0) { //first div
                    str += '        <table width=' + width + ' border=0 cellspacing=0 cellpadding=0>';
                    str += '            <TR>';
                    // first tab enabled
                    if(isBorderNeeded){
                    str += '                <td rowspan=5 bgcolor="#99A9C4" width="1" height="22"><IMG SRC="/share/img/s.gif" WIDTH=1 HEIGHT=22></td>';
                    }
                    str += '                <td bgcolor="#99A9C4" width="162" height="1"><IMG SRC="/share/img/s.gif" WIDTH=162 HEIGHT=1></td>';
                    str += '              <td rowspan=5 width="15" height="22"><IMG SRC="/share/img/lt_tab_on.gif" WIDTH=15 HEIGHT=22 border="0"></td>';
                    for (z=1;z<tbl[2].length-1;z++) {
                        // middle tabs disabled
                        str += '            <td width="160" height="1"><IMG SRC="/share/img/s.gif" WIDTH=160 HEIGHT=1></td>';
                        str += '            <td rowspan=5 width="15" height="22"><IMG SRC="/share/img/lt_tab_off.gif" WIDTH=15 HEIGHT=22 border="0"></td>';
                    }
                    // last tab disabled
                    str += '                <td width="160" height="1"><IMG SRC="/share/img/s.gif" WIDTH=160 HEIGHT=1></td>';
                    str += '                <td rowspan=5 width="15" height="22"><img src="/share/img/rt_tab_off.gif" WIDTH=15 HEIGHT=22 border="0"></td>';
                    border = (isBorderNeeded)?1:0;
                    var twidth = width - (2+border) - (175*(tbl[2].length));
                    str += '                <td rowspan=4 width=' + (twidth) + ' height=21 align="right" valign="top"><IMG SRC="/share/img/s.gif" WIDTH=' + (twidth) + ' HEIGHT=21></td>';
                    
                    str += '            </TR>';
                    str += '            <TR>';
                    str += '                <td rowspan=4 width=160 bgcolor="#ffffff" height="21"><IMG SRC="/share/img/s.gif"  width=5 HEIGHT=1><span class="head4">' + tbl[2][y][0] + '</span><span class="smbodycon">' + tbl[2][y][1]  + '</span></td>';
                    for (z=1;z<tbl[2].length;z++) {
                        str += '            <td width="160" height="1"><IMG SRC="/share/img/s.gif" WIDTH=160 HEIGHT=1></td>';
                    }                   
                    str += '            </tr>';
                    str += '            <tr>';
                    for (z=1;z<tbl[2].length;z++) {
                        str += '            <td bgcolor="#99A9C4" width="160" height="1"><IMG SRC="/share/img/s.gif" WIDTH=160 HEIGHT=1></td>';
                    }
                    str += '            </tr>';
                    str += '            <tr>';
                    for (z=1;z<tbl[2].length;z++) {
                        // disabled tabs text
                        str += '            <td width=160 height=18 bgcolor="#dde5ec"><IMG SRC="/share/img/s.gif"  width=10 HEIGHT=1><a href="javascript:swap(' + quote + tblname + 'TAB' + y + quote + ',' + quote + tblname + 'TAB' + (z) + quote + ');" class="nounderline"><span class="fundhead5a">' + tbl[2][z][0] + '</span><span class="fundcopy">' + tbl[2][z][1] + '</span></a></td>';
                    }
                    str += '            </TR>';
                    str += '            <TR>';
                    for (z=0;z<tbl[2].length;z++) {
                        str += '                <td bgcolor="#99A9C4"><IMG SRC="/share/img/s.gif"  width=1 HEIGHT=1></td>';
                    }   
                    str += '            </TR>';
                    str += '        </TABLE>';
                } else { //subsequent divs
                    str += '        <table width=' + width + ' border=0 cellspacing=0 cellpadding=0>';
                    str += '            <TR>';
                    var twidth = width - (3) - (175*(tbl[2].length));
                    str += '                <td rowspan=4><IMG SRC="/share/img/s.gif" WIDTH=' + 2 + ' HEIGHT=21></td>';
                    str += '                <td colspan="2"><IMG SRC="/share/img/s.gif" WIDTH=161 HEIGHT=1></td>';
                    
                    for (z=1;z<y;z++) {
                        // disabled tabs
                        str += '            <td rowspan=5 width="15" height="22"><img src="/share/img/lt_tab_off.gif" WIDTH=15 HEIGHT=22></td>';
                        str += '            <td width="160" height="1"><IMG SRC="/share/img/s.gif" WIDTH=160 HEIGHT=1></td>';
                    }

                    str += '                <td rowspan=5><IMG SRC="/share/img/ctr_tab_on.gif" WIDTH=15 HEIGHT=22></td>';
                    str += '                <td bgcolor="#99A9C4"><IMG SRC="/share/img/s.gif" WIDTH=160 HEIGHT=1></td>';
                    
                    // if last tab enabled
                    if (y==tbl[2].length-1) {
                        str += '            <td rowspan=5><img src="/share/img/rt_tab_on.gif" WIDTH=15 HEIGHT=22></td>';
                    } else {
                        str += '            <td rowspan=5 width="15" height="22"><img src="/share/img/lt_tab_on.gif" WIDTH=15 HEIGHT=22></td>';                 
                        str += '            <td><IMG SRC="/share/img/s.gif" WIDTH=160 HEIGHT=1></td>';

                        for (z=y+1;z<tbl[2].length-2;z++) {
                            str += '        <td rowspan=5><img src="/share/img/lt_tab_off.gif" WIDTH=15 HEIGHT=22></td>';
                            str += '        <td><IMG SRC="/share/img/s.gif" WIDTH=160 HEIGHT=1></td>';
                        }
                        str += '            <td rowspan=5 width="15" height="22"><img src="/share/img/rt_tab_off.gif" WIDTH=15 HEIGHT=22></td>';                    
                    }
                    
                    str += '                <td rowspan=4 width=' + (twidth) + ' height=21 align="right" valign="top"><IMG SRC="/share/img/s.gif" WIDTH=' + (twidth) + ' HEIGHT=21></td>';
                    
                    str += '            </TR>';
                    str += '            <TR>';
                    str += '                <td colspan=2><IMG SRC="/share/img/s.gif" WIDTH=161 HEIGHT=1></td>';
                    for (z=1;z<y;z++) {
                        str += '            <td><IMG SRC="/share/img/s.gif" WIDTH=160 HEIGHT=1></td>';              
                    }
                    str += '                <td rowspan=4 width=160 align="center" bgcolor="#ffffff"><span class="head4">' + tbl[2][y][0] + ' </span><span class="smbodycon">' + tbl[2][y][1]  + '</span></td>';
                    for (z=y+1;z<tbl[2].length;z++) {
                        str += '            <td><IMG SRC="/share/img/s.gif" WIDTH=160 HEIGHT=1></td>';              
                    }
                    str += '            </tr>';
                    str += '            <tr>';
                    str += '                <td bgcolor="#99A9C4"><IMG SRC="/share/img/s.gif" WIDTH=1 HEIGHT=1></td>';
                    for (z=0;z<tbl[2].length-1;z++) {
                        str += '            <td bgcolor="#99A9C4"><IMG SRC="/share/img/s.gif" WIDTH=160 HEIGHT=1></td>';                
                    }
                    str += '            </tr>';
                    str += '            <tr>';
                    str += '                <td rowspan=2 bgcolor="#99A9C4"><img src="/share/img/s.gif" width=1 height=19></td>';
                    for (z=0;z<tbl[2].length;z++) {
                        if (z==y)
                            continue;
                        str += '            <td height=18 bgcolor="#dde5ec"><IMG SRC="/share/img/s.gif"  width=10 HEIGHT=1><a href="javascript:swap(' + quote + tblname + 'TAB' + y + quote + ',' + quote + tblname + 'TAB' + z + quote + ');" class="nounderline"><span class="fundhead5a">' + tbl[2][z][0] + ' </span><span class="fundcopy">' + tbl[2][z][1] + '</span></a></td>';
                    }
                    str += '            </TR>';
                    str += '            <TR>';
                    for (z=0;z<tbl[2].length+1;z++) {
                        str += '            <td bgcolor="#99A9C4"><IMG SRC="/share/img/s.gif" width=1 HEIGHT=1></td>';
                    }
                    str += '            </TR>';
                    str += '        </TABLE>';
                }
            }

// data rows            
            str += buildTableData(tbl[3][y],width,tbl[4][0], 44, isBorderNeeded);
//alert("2");
//table bottom
    if((isBorderNeeded) && (tableType == "Inst")){ // Footer needed for tables that are standalone or end of list
        str += '            <table width=' + width + ' border=0 cellspacing=0 cellpadding=0><TR>';
        str += '            <td bgcolor="#99A9C4"><IMG SRC="/share/img/s.gif" width=1 HEIGHT=1></td>';
        str += '            </TR></TABLE>';
    }
    else if(isBorderNeeded){ // Footer needed for tables that are standalone or end of list
        str += buildTableFooter(width,tbl[5][3]);
    }
// end data table
            str += '            </td>';
            str += '        </tr>';
            str += '    </table>';
            str += '</div>';
        }   // end y loop
//  } // end x loop
    str += '</DIV>';
//alert(str);
//  awin = window.open("","newWin");
//  awin.document.writeln(str);
    document.write(str);

    
//alert("4");
}
function buildTableData(tbl,width,links,colWidth,isBorderNeeded) {
// data table
// could have multiple tables stacked one below the other.
// no of cols is assumed to be the same for all tables
//  alert("buildTableData");
    var i=0;
    var border = (isBorderNeeded)?2:0;
    var noOfTables = tbl.length;
    var noOfCols = tbl[0][1].length;    // no of cols
    var noOfTotCols = (noOfCols*2)-2;
    var str="";
    var strErr="The performance data is not available for the date you've selected.";
    str  = '<TABLE bgcolor="#ffffff" width=' + width + ' cellspacing=0 cellpadding=0 border=0>';
    str += '<tr>';
    if(isBorderNeeded){
    str += '    <td width="1" bgcolor="#99A9C4"><IMG src="/share/img/s.gif" width=1 height=1></td>';
    }
    str += '    <td>';
    str += '        <table border="0" cellpadding="0" cellspacing="0" width="' + (width - border) +'">';
    for(i=0;i<noOfTables;i++){ // for every table
        str += '        <TR>';
        str += '        <TD width="5"><IMG src="/share/img/s.gif" width=5 height=1></TD>';
        str += '            <TD width="' + (width - (8+border) - (noOfCols * colWidth) - 10 - ((noOfCols-2)*11)) + '"><IMG src="/share/img/s.gif" width="' + (width - (8+border) - (noOfCols * colWidth) - 10 - ((noOfCols-2)*11)) + '" height=1></TD>';

        a=1;
        for (a=1;a<noOfCols;a++) {
            str += '        <TD width="'+colWidth+'"><IMG src="/share/img/s.gif" width='+colWidth+' height=1></TD>';
            if (a < noOfCols-1)
                str += '        <TD width="1"><IMG src="/share/img/s.gif" width=11 height=10></TD>';
        }
        str += '        <TD width="5"><IMG src="/share/img/s.gif" width=5 height=1></TD>';
        str += '        </TR>';
        //Heading of the table
        if(tbl[i][0]!=""){
            str += '        <TR>';
            str += '        <td colspan="' + (noOfTotCols+2) + '" class="head5"><IMG src="/share/img/s.gif" width=5 height=1>' + tbl[i][0]+'</td>';
            str += '        </TR>';
            str += '    <TR>';
            str += '        <td colspan="' + (noOfTotCols+2) + '"><IMG src="/share/img/s.gif" width=1 height=5></td>';
            str += '    </TR>';
        }

        // first row of table
        str += '        <TR valign="bottom">';
        str += '        <TD width="5"><IMG src="/share/img/s.gif" width=5 height=1></TD>';
        str += '            <TD height="20" class="fundhead5b">' + tbl[i][1][0] + '</TD>'; //first col

        a=1;
        for (a=1;a<noOfCols;a++) {
            str += '        <TD align="right" class="fundhead5">' + tbl[i][1][a] + '</TD>'; //rest of the cols
            if (a < noOfCols-1)
                str += '        <TD width="1"><IMG src="/share/img/s.gif" width=11 height=1></TD>';
        }
        str += '        <TD width="5"><IMG src="/share/img/s.gif" width=5 height=1></TD>';
        str += '        </TR>';
        // end of first row of table
            str += '    <TR>';
            str += '        <td colspan="' + (noOfTotCols+2) + '"><IMG src="/share/img/s.gif" width=1 height=5></td>';
            str += '    </TR>';

       //checking if the rows have any data to display
        if(tbl[i][2][0]!="")
        {
            for (b=2;b<tbl[i].length;b++) {         // second row onwards

                str += '    <TR>';
            str += '        <TD width="5"><IMG src="/share/img/s.gif" width=5 height=1></TD>';
            //added

                if (links=="true") {
                    str += '    <TD height="20" align="left">' + tbl[i][b][0] + '</TD>';    // first column
                } else {
                    str += '    <TD height="20" align="left" class="fundhead5">' + tbl[i][b][0] + '</TD>';  // first column
                }
                c=1;
                for (c=1;c<noOfCols;c++) {  // second column onwards
                    str += '    <TD align="right" class="data1">' + tbl[i][b][c] + '</TD>';
                    if (c < noOfCols-1)
                        str += '        <TD width="1" background="/share/img/bgwhite_greydot_w11.gif"><IMG src="/share/img/s.gif" width=11 height=1></TD>';
                }
                str += '        <TD width="5"><IMG src="/share/img/s.gif" width=5 height=1></TD>';
                str += '    </TR>';
                if (b<(tbl[i].length-1)) {      // if not last row insert black dots row
                    str += '<TR>';
                      str += '    <td colspan="' + (noOfTotCols+2) + '" background="/share/img/black-dot.gif"><IMG src="/share/img/s.gif" width=1 height=1></td>';
                    str += '</TR>';
                } else {                    // if last row insert empty space and table bottom
    /*              str += '<TR>';
                    str += '    <td colspan="' + (noOfTotCols+2) + '"><IMG src="/share/img/s.gif" width=1 height=10></td>';
                    str += '</TR>';
    */          }
           }
        }
        //the error gets displayed if there is no data for display
        else {
            str += '    <TD colspan="' + (noOfTotCols+2) + '" align="center" class="data1">' + strErr + '</TD>';
            str += '    </TR>';
       }
       //added above

        str+= '<tr><td colspan='+ (noOfTotCols+2) +'><IMG src="/share/img/s.gif" width=1 height=10></td></tr>';
    }
    str += '        </table>';
    str += '    </td>';
    //str += '  <td width="4"><IMG src="/share/img/s.gif" width=4 height=1></td>';
    if(isBorderNeeded){
    str += '    <td width="1" bgcolor="#99A9C4"><IMG src="/share/img/s.gif" width=1 height=1></td>';
    }
    str += '</tr>';
    str += '</TABLE>';



    return str;
}

function buildTableDataInst(tbl,width,links,colWidth,isBorderNeeded) {
// data table
// could have multiple tables stacked one below the other.
// no of cols is assumed to be the same for all tables
//  alert("buildTableData");
    var i=0;
    var border = (isBorderNeeded)?2:0;
    var noOfTables = tbl.length;
    var noOfCols = tbl[0][1].length;    // no of cols
    var noOfTotCols = (noOfCols*2)-2;
    var str="";
    var strErr="The performance data is not available for the date you've selected.";
    str  = '<TABLE bgcolor="#ffffff" width=' + width + ' cellspacing=0 cellpadding=0 border=0>';
    str += '<tr>';
    if(isBorderNeeded){
    str += '    <td width="1" bgcolor="#99A9C4"><IMG src="/share/img/s.gif" width=1 height=1></td>';
    }
    str += '    <td>';
    str += '        <table border="0" cellpadding="0" cellspacing="0" width="' + (width - border) +'">';
    for(i=0;i<noOfTables;i++){ // for every table
        str += '        <TR>';
        str += '        <TD width="5"><IMG src="/share/img/s.gif" width=5 height=1></TD>';
        str += '            <TD width="' + (width - (8+border) - (noOfCols * colWidth) - 10 - ((noOfCols-2)*11)) + '"><IMG src="/share/img/s.gif" width="' + (width - (8+border) - (noOfCols * colWidth) - 10 - ((noOfCols-2)*11)) + '" height=1></TD>';

        a=1;
        for (a=1;a<noOfCols;a++) {
            str += '        <TD width="'+colWidth+'"><IMG src="/share/img/s.gif" width='+colWidth+' height=1></TD>';
            if (a < noOfCols-1)
                str += '        <TD width="1"><IMG src="/share/img/s.gif" width=11 height=10></TD>';
        }
        str += '        <TD width="5"><IMG src="/share/img/s.gif" width=5 height=1></TD>';
        str += '        </TR>';
        //Heading of the table
        if(tbl[i][0]!=""){
            str += '        <TR>';
            str += '        <td colspan="' + (noOfTotCols+2) + '" class="head4"><IMG src="/share/img/s.gif" width=5 height=1>' + tbl[i][0]+'</td>';
            str += '        </TR>';
            str += '    <TR>';
            str += '        <td colspan="' + (noOfTotCols+2) + '"><IMG src="/share/img/s.gif" width=1 height=5></td>';
            str += '    </TR>';
        }

        // first row of table
        str += '        <TR valign="bottom">';
        str += '        <TD width="5"><IMG src="/share/img/s.gif" width=5 height=1></TD>';
        str += '            <TD height="20" class="data1">' + tbl[i][1][0] + '</TD>'; //first col

        a=1;
        for (a=1;a<noOfCols;a++) {
            str += '        <TD align="center" class="fundhead5">' + tbl[i][1][a] + '</TD>'; //rest of the cols
            if (a < noOfCols-1)
                str += '        <TD width="1"><IMG src="/share/img/s.gif" width=11 height=1></TD>';
        }
        str += '        <TD width="5"><IMG src="/share/img/s.gif" width=5 height=1></TD>';
        str += '        </TR>';
        // end of first row of table
            str += '    <TR>';
            str += '        <td colspan="' + (noOfTotCols+2) + '"><IMG src="/share/img/s.gif" width=1 height=5></td>';
            str += '    </TR>';

       //checking if the rows have any data to display
        if(tbl[i][2][0]!="")
        {
            for (b=2;b<tbl[i].length;b++) {         // second row onwards

                str += '    <TR>';
            str += '        <TD width="5"><IMG src="/share/img/s.gif" width=5 height=1></TD>';
            //added

                if (links=="true") {
                    str += '    <TD height="20" align="left">' + tbl[i][b][0] + '</TD>';    // first column
                } else {
                    str += '    <TD height="20" align="left" >' + tbl[i][b][0] + '</TD>';  // first column
                }
                c=1;
                for (c=1;c<noOfCols;c++) {  // second column onwards
                    str += '    <TD align="right" class="data1">' + tbl[i][b][c] + '</TD>';
                    if (c < noOfCols-1)
                        str += '        <TD width="1" background="/share/img/bgwhite_greydot_w11.gif"><IMG src="/share/img/s.gif" width=11 height=1></TD>';
                }
                str += '        <TD width="5"><IMG src="/share/img/s.gif" width=5 height=1></TD>';
                str += '    </TR>';
                if (b<(tbl[i].length-1)) {      // if not last row insert black dots row
                    str += '<TR>';
                    str += '    <td colspan="' + (noOfTotCols+2) + '" bgcolor="#cccccc" ><IMG src="/share/img/s.gif" width=1 height=1></td>';
                    str += '</TR>';
                } else {                    // if last row insert empty space and table bottom
    /*              str += '<TR>';
                    str += '    <td colspan="' + (noOfTotCols+2) + '"><IMG src="/share/img/s.gif" width=1 height=10></td>';
                    str += '</TR>';
    */          }
           }
        }
        //the error gets displayed if there is no data for display
        else {
            str += '    <TD colspan="' + (noOfTotCols+2) + '" align="center" class="data1">' + strErr + '</TD>';
            str += '    </TR>';
       }
       //added above

        str+= '<tr><td colspan='+ (noOfTotCols+2) +'><IMG src="/share/img/s.gif" width=1 height=10></td></tr>';
    }
    str += '        </table>';
    str += '    </td>';
    //str += '  <td width="4"><IMG src="/share/img/s.gif" width=4 height=1></td>';
    if(isBorderNeeded){
    str += '    <td width="1" bgcolor="#99A9C4"><IMG src="/share/img/s.gif" width=1 height=1></td>';
    }
    str += '</tr>';
    str += '</TABLE>';



    return str;
}



















function buildTableFooter(width,bgColor){
    var str="";
    var tabposition = 0;
    var remainder = 0;
    var balance = 0;
    var total = 0;
    remainder = (width % 4);
    tabposition = (width-remainder)/4; 
    balance = (width - (tabposition + 19));
    
//  str += '<TABLE width=' + width + ' cellspacing=0 cellpadding=0 border=0>';
//  str += '<tr>';
//  str += '    <td>';
    str += '        <TABLE width=' + width + ' cellspacing=0 cellpadding=0 border=0>';
    str += '            <tr>';
    str += '                <TD width=' + tabposition + ' height=1 bgcolor="#99A9C4"><IMG src="/share/img/s.gif" width=' + tabposition + ' height=1></TD>';
    str += '                <td width=18 height=15 rowspan=3 bgcolor="'+bgColor+'"><IMG src="/share/img/tbl_btm.gif" width=18 height=15></td>';
    str += '                <TD width=' + balance + ' bgcolor="#ffffff"><IMG src="/share/img/s.gif" width=' + balance + ' height=1></TD>';
    str += '                <TD width=1 rowspan=3 bgcolor="#99A9C4"><IMG src="/share/img/s.gif" width=1 height=15></TD>';
    str += '            </tr>';
    str += '            <tr ' + (bgColor?('bgcolor="'+bgColor+'"'):"") +'>';
    str += '                <TD width=' + tabposition + ' rowspan=2><IMG src="/share/img/s.gif" width=' + tabposition + ' height=14></TD>';
    str += '                <TD width=' + balance + ' bgcolor="#ffffff"><IMG src="/share/img/s.gif" width=1 height=13></TD>';
    str += '            </tr>';
    str += '            <tr>';
    str += '                <TD width=' + balance + ' height=1 bgcolor="#99A9C4"><IMG src="/share/img/s.gif" width=' + balance + ' height=1></TD>';
    str += '            </tr>';
    str += '        </table>';
//  str += '    </td>';
//  str += '</tr>';         
//  str += '</TABLE>';
    return str;
}

function buildTableInst(tbl,tblname,width,tableType) {
//  the parameter 'tableType' gets the value 'inst' for inst pages and causes the tabbed table to have a straightlined bottom, instead of the stepped bottom as in retail pages
//  alert("buildTable");
    quote="'";
    var isBorderNeeded = (tbl[4][1]!="false")?true:false;
    var border = 0;
//  alert(tblLoc);
    str = '<DIV ID="' + tblname + 'wrapper" style="position:relative; top:0; left:0;">';    
//  for (x=0; x<tbl[1].length;x++) {            // number of different states
        for (y=0; y<tbl[2].length;y++) {        // number of tabs per state (should always be equal per state) i.e. if one state has 2 tabs the second state should also have exactly 2 tabs (tbl[3][0].length==tbl[3][1].length==....)
            str += '<DIV ID="' + tblname + 'TAB' + y + '" class="absinv">';
            str += '    <table cellspacing=0 cellpadding=0 border=0 width=' + width + '>';
        
            str += '        <tr>';
//          str += '            <td width="1"><IMG src="/share/img/s.gif" width=1 height=1></TD>';
            str += '            <td>';
            
            // Header and Instruction Text 
            str += '                <TABLE width=' + width + 'border=0 cellspacing=0 cellpadding=0>';
            str += '                    <TR>';              
            str += '                        <TD width=5><IMG src="/share/img/s.gif" width=5 height=1></TD>';
            str += '                        <TD><SPAN class="head4">' + tbl[0][0] + '</SPAN></TD>';
            str += '                        <TD align="right"><SPAN class="smbodycon">' + tbl[0][1] + '</SPAN></TD>';
            str += '                        <TD width=5><IMG src="/share/img/s.gif" width=5 height=1></TD>';
            str += '                    </TR>';             
            str += '                    <TR>';
            str += '                        <TD colspan=4><IMG src="/share/img/s.gif" width=1 height=5 border=0></TD>';
            str += '                    </TR>';
            str += '                </TABLE>';
            // End of Header and Instruction Text 
            
            // Tabs
            if (tbl[2].length==1) {         // this is for a single tabbed table
                border = (isBorderNeeded)?1:0;
                str += '            <table width=' + width + 'border=0 cellspacing=0 cellpadding=0>';
                str += '                <TR>';
                if(isBorderNeeded){
                str += '                    <td rowspan=3 bgcolor="#99A9C4"><IMG SRC="/share/img/s.gif" WIDTH=1 HEIGHT=22></td>';
                }
                str += '                    <td bgcolor="#99A9C4"><IMG SRC="/share/img/s.gif" WIDTH=165 HEIGHT=1></td>';
                str += '                    <td rowspan=3><IMG SRC="/share/img/rt_tab_on.gif" WIDTH=15 HEIGHT=22></td>';
                var twidth = 180+border;
                str += '                    <td width=' + (width - twidth) + '><IMG SRC="/share/img/s.gif" WIDTH=' + (width - twidth) + ' HEIGHT=1></td>';
                
//              str += '                    <td><IMG SRC="/share/img/s.gif" WIDTH=1 HEIGHT=1></td>';
                str += '                </TR>';
                str += '                <TR>';
                str += '                    <td height=21 rowspan=2 bgcolor="#ffffff"><IMG SRC="/share/img/s.gif" WIDTH=5 HEIGHT=1><span class="head4">' + tbl[2][y][0] + '</span><span class="smbodycon">' + tbl[2][y][1]  + '</span></td>';
                str += '                    <td width=' + (width - twidth) + ' align="right" valign="top"><IMG SRC="/share/img/s.gif" WIDTH=' + (width - twidth) + ' HEIGHT=20></td>';
//              str += '                    <td><IMG SRC="/share/img/s.gif" WIDTH=1 HEIGHT=20 border=0></td>';
                str += '                </TR>';
                str += '                <TR>';
                str += '                    <td bgcolor="#99A9C4"><IMG SRC="/share/img/s.gif" WIDTH=' + (width - twidth) + ' HEIGHT=1></td>';
//              str += '                    <td><IMG SRC="/share/img/s.gif" WIDTH=1 HEIGHT=1></td>';
                str += '                </TR>';
                str += '            </table>';

            } else if (tbl[2].length>1) {       // this is for a multi tabbed table

                if (y==0) { //first div
                    str += '        <table width=' + width + 'border=0 cellspacing=0 cellpadding=0>';
                    str += '            <TR>';
                    // first tab enabled
                    if(isBorderNeeded){
                    str += '                <td rowspan=5 bgcolor="#99A9C4" width="1" height="22"><IMG SRC="/share/img/s.gif" WIDTH=1 HEIGHT=22></td>';
                    }
                    str += '                <td bgcolor="#99A9C4" width="162" height="1"><IMG SRC="/share/img/s.gif" WIDTH=162 HEIGHT=1></td>';
                    str += '              <td rowspan=5 width="15" height="22"><IMG SRC="/share/img/lt_tab_on.gif" WIDTH=15 HEIGHT=22 border="0"></td>';
                    for (z=1;z<tbl[2].length-1;z++) {
                        // middle tabs disabled
                        str += '            <td width="160" height="1"><IMG SRC="/share/img/s.gif" WIDTH=160 HEIGHT=1></td>';
                        str += '            <td rowspan=5 width="15" height="22"><IMG SRC="/share/img/lt_tab_off.gif" WIDTH=15 HEIGHT=22 border="0"></td>';
                    }
                    // last tab disabled
                    str += '                <td width="160" height="1"><IMG SRC="/share/img/s.gif" WIDTH=160 HEIGHT=1></td>';
                    str += '                <td rowspan=5 width="15" height="22"><img src="/share/img/rt_tab_off.gif" WIDTH=15 HEIGHT=22 border="0"></td>';
                    border = (isBorderNeeded)?1:0;
                    var twidth = width - (2+border) - (175*(tbl[2].length));
                    str += '                <td rowspan=4 width=' + (twidth) + ' height=21 align="right" valign="top"><IMG SRC="/share/img/s.gif" WIDTH=' + (twidth) + ' HEIGHT=21></td>';
                    
                    str += '            </TR>';
                    str += '            <TR>';
                    str += '                <td rowspan=4 width=160 bgcolor="#ffffff" height="21"><IMG SRC="/share/img/s.gif"  width=5 HEIGHT=1><span class="head4">' + tbl[2][y][0] + '</span><span class="smbodycon">' + tbl[2][y][1]  + '</span></td>';
                    for (z=1;z<tbl[2].length;z++) {
                        str += '            <td width="160" height="1"><IMG SRC="/share/img/s.gif" WIDTH=160 HEIGHT=1></td>';
                    }                   
                    str += '            </tr>';
                    str += '            <tr>';
                    for (z=1;z<tbl[2].length;z++) {
                        str += '            <td bgcolor="#99A9C4" width="160" height="1"><IMG SRC="/share/img/s.gif" WIDTH=160 HEIGHT=1></td>';
                    }
                    str += '            </tr>';
                    str += '            <tr>';
                    for (z=1;z<tbl[2].length;z++) {
                        // disabled tabs text
                        str += '            <td width=160 height=18 bgcolor="#dde5ec"><IMG SRC="/share/img/s.gif"  width=10 HEIGHT=1><a href="javascript:swap(' + quote + tblname + 'TAB' + y + quote + ',' + quote + tblname + 'TAB' + (z) + quote + ');" class="nounderline"><span class="fundhead5a">' + tbl[2][z][0] + '</span><span class="fundcopy">' + tbl[2][z][1] + '</span></a></td>';
                    }
                    str += '            </TR>';
                    str += '            <TR>';
                    for (z=0;z<tbl[2].length;z++) {
                        str += '                <td bgcolor="#99A9C4"><IMG SRC="/share/img/s.gif"  width=1 HEIGHT=1></td>';
                    }   
                    str += '            </TR>';
                    str += '        </TABLE>';
                } else { //subsequent divs
                    str += '        <table width=' + width + 'border=0 cellspacing=0 cellpadding=0>';
                    str += '            <TR>';
                    var twidth = width - (3) - (175*(tbl[2].length));
                    str += '                <td rowspan=4><IMG SRC="/share/img/s.gif" WIDTH=' + 2 + ' HEIGHT=21></td>';
                    str += '                <td colspan="2"><IMG SRC="/share/img/s.gif" WIDTH=161 HEIGHT=1></td>';
                    
                    for (z=1;z<y;z++) {
                        // disabled tabs
                        str += '            <td rowspan=5 width="15" height="22"><img src="/share/img/lt_tab_off.gif" WIDTH=15 HEIGHT=22></td>';
                        str += '            <td width="160" height="1"><IMG SRC="/share/img/s.gif" WIDTH=160 HEIGHT=1></td>';
                    }

                    str += '                <td rowspan=5><IMG SRC="/share/img/ctr_tab_on.gif" WIDTH=15 HEIGHT=22></td>';
                    str += '                <td bgcolor="#99A9C4"><IMG SRC="/share/img/s.gif" WIDTH=160 HEIGHT=1></td>';
                    
                    // if last tab enabled
                    if (y==tbl[2].length-1) {
                        str += '            <td rowspan=5><img src="/share/img/rt_tab_on.gif" WIDTH=15 HEIGHT=22></td>';
                    } else {
                        str += '            <td rowspan=5 width="15" height="22"><img src="/share/img/lt_tab_on.gif" WIDTH=15 HEIGHT=22></td>';                 
                        str += '            <td><IMG SRC="/share/img/s.gif" WIDTH=160 HEIGHT=1></td>';

                        for (z=y+1;z<tbl[2].length-2;z++) {
                            str += '        <td rowspan=5><img src="/share/img/lt_tab_off.gif" WIDTH=15 HEIGHT=22></td>';
                            str += '        <td><IMG SRC="/share/img/s.gif" WIDTH=160 HEIGHT=1></td>';
                        }
                        str += '            <td rowspan=5 width="15" height="22"><img src="/share/img/rt_tab_off.gif" WIDTH=15 HEIGHT=22></td>';                    
                    }
                    
                    str += '                <td rowspan=4 width=' + (twidth) + ' height=21 align="right" valign="top"><IMG SRC="/share/img/s.gif" WIDTH=' + (twidth) + ' HEIGHT=21></td>';
                    
                    str += '            </TR>';
                    str += '            <TR>';
                    str += '                <td colspan=2><IMG SRC="/share/img/s.gif" WIDTH=161 HEIGHT=1></td>';
                    for (z=1;z<y;z++) {
                        str += '            <td><IMG SRC="/share/img/s.gif" WIDTH=160 HEIGHT=1></td>';              
                    }
                    str += '                <td rowspan=4 width=160 align="center" bgcolor="#ffffff"><span class="head4">' + tbl[2][y][0] + ' </span><span class="smbodycon">' + tbl[2][y][1]  + '</span></td>';
                    for (z=y+1;z<tbl[2].length;z++) {
                        str += '            <td><IMG SRC="/share/img/s.gif" WIDTH=160 HEIGHT=1></td>';              
                    }
                    str += '            </tr>';
                    str += '            <tr>';
                    str += '                <td bgcolor="#99A9C4"><IMG SRC="/share/img/s.gif" WIDTH=1 HEIGHT=1></td>';
                    for (z=0;z<tbl[2].length-1;z++) {
                        str += '            <td bgcolor="#99A9C4"><IMG SRC="/share/img/s.gif" WIDTH=160 HEIGHT=1></td>';                
                    }
                    str += '            </tr>';
                    str += '            <tr>';
                    str += '                <td rowspan=2 bgcolor="#99A9C4"><img src="/share/img/s.gif" width=1 height=19></td>';
                    for (z=0;z<tbl[2].length;z++) {
                        if (z==y)
                            continue;
                        str += '            <td height=18 bgcolor="#dde5ec"><IMG SRC="/share/img/s.gif"  width=10 HEIGHT=1><a href="javascript:swap(' + quote + tblname + 'TAB' + y + quote + ',' + quote + tblname + 'TAB' + z + quote + ');" class="nounderline"><span class="fundhead5a">' + tbl[2][z][0] + ' </span><span class="fundcopy">' + tbl[2][z][1] + '</span></a></td>';
                    }
                    str += '            </TR>';
                    str += '            <TR>';
                    for (z=0;z<tbl[2].length+1;z++) {
                        str += '            <td bgcolor="#99A9C4"><IMG SRC="/share/img/s.gif" width=1 HEIGHT=1></td>';
                    }
                    str += '            </TR>';
                    str += '        </TABLE>';
                }
            }

// data rows            
            str += buildTableDataInst(tbl[3][y],width,tbl[4][0], 44, isBorderNeeded);
//alert("2");
//table bottom

// end data table
            str += '            </td>';
            str += '        </tr>';
            str += '    </table>';
            str += '</div>';
        }   // end y loop
//  } // end x loop
    str += '</DIV>';
//alert(str);
//  awin = window.open("","newWin");
//  awin.document.writeln(str);
    document.write(str);

    
//alert("4");
}


