/********************************************
 *
 *UI related and can be shared by different HTML
 *
 ********************************************/

function nTab(label, func, lnk, sel){
  var s ='' 
  var f = 'onMouseOver="return hint(\'' + 
      (label.indexOf('"') == -1 ? main.i18n_squote(label) : '') +
      '\')" onMouseOut="return hint()" href="javascript:main.' + func +
      '" target="mailFrame">'

  if(main.state == 'msg')
  {
     if(sel)
        s += '<div class=Tab2Sel nowrap><span class=TabLblSel>' +
      label + '</span></div>'
     else
        s += '<div class=Tab2NotSel nowrap><a class=TabLblNormal ' +
      f + label + '</a></div>'
  } else { 
     if(!lnk && sel)
        s += '<div class=Tab2Sel nowrap><span class=TabLblSel>' +
          label + '</span></div>'
     else if (lnk && !sel)
        s += '<div class=Tab2Sel nowrap><span class=TabLblSel><a ' +
            f + label + '</a></span></div>'
     else
        s += '<div class=Tab2NotSel nowrap><a class=TabLblNormal ' +
            f + label + '</a></div>'
  }
  return s;
}

function nWMtoolbar(label, jfunc, imgname, imgoff, imgon) {
  var out = ' onMouseOut="return hint()"'
  var over = ' onMouseOver="return hint()"'
  return '<td class=ToolbarItem nowrap>' +
         '<a href="javascript:' + jfunc + '"' + over + out + '>'+
         '<img name="' + imgname + '" src="' + imgoff +
         '" width="24" height="24" border="0" align="middle" title="' + label + '"' +
         ' onMouseOver="this.src=\'' + imgon + '\';return \'true\';"' +
         ' onMouseOut="this.src=\'' + imgoff + '\';return \'true\';"' +
	       '></a><a class=ToolLbl href="javascript:' + jfunc + '" title="' + label + '"' +
         over + out + '>' + label + '</a></td>';
}

function folderTab() {
  if (!main.loaded) return ''

  var state = main.state
  var i18n = main.i18n
  var fldr = main.fldr
  var mbox = main.mboxFrame.mbox
  var cfg = main.cfg
  var link = false

  if (state == 'msg') {
    link = true
    if (mbox=='INBOX')
      state = 'Inbox'
    else if (mbox==cfg['meSentFolder'])
      state = 'Sent'
    else if ((mbox==cfg['meTrashFolder']) || (mbox==cfg['mePrevTrash']))
      state = 'Trash'       
    else if (mbox==cfg['meDraftFolder'])
      state = 'Drafts'
    else 
      state = mbox
  }

  var s = ''
  s += '<table width="100%" border="0" cellspacing="0" cellpadding="0">' +
    '<tr>' +
    '<td>' +
    '<table class=Tab2Tbl cellspacing=0 cellpadding=0 width="100%" border=0>' +
    '<tbody>'

  if (state == 'folders')
    s += '<tr>' +
      '<td colspan=17><img height=10 alt="" src="imx/spacer.gif" width=1></td>' +
      '</tr>' +
      '<tr>' +
      '<td width="1%"><img height=1 alt="" src="imx/spacer.gif" width=10></td>' +
      '<td class=Tab2LineBkgd colspan=5><img height=1 alt="" src="imx/spacer.gif" width=1></td>' +
      '<td colspan=11><img height=1 alt="" src="imx/spacer.gif" width=1></td>' +
      '</tr>' +
      '<tr>' +
      '<td width="1%"><img height=1 alt="" src="imx/spacer.gif" width=10></td>' +
      '<td class=Tab2LineBkgd width="0%"><img height=12 alt="" src="imx/spacer.gif" width=1></td>' +
      '<td class=Tab2Sel width="1%"><img height=1 alt="" src="imx/spacer.gif" width=10></td>' +
      '<td class=Tab2Sel nowrap>' + nTab(i18n['folders'], 'main.displayFolders()', link, true)+ '</td>' +
      '<td class=Tab2Sel width="1%"><img height=1 alt="" src="imx/spacer.gif" width=10></td>' +
      '<td class=Tab2LineBkgd width="0%"><img height=12 alt="" src="imx/spacer.gif" width=1></td>' +
      '<td width="1%"><img height=1 alt="" src="imx/spacer.gif" width=10></td>' +
      '<td class=Tab2NotSel nowrap>' + nTab(fldr['INBOX'], 'displaySpecialMbox(\'Inbox\')', link)+ '</td>' +
      '<td width="2%"><img height=20 alt="" src="imx/dividerbar.gif" width=24></td>' +
      '<td class=Tab2NotSel nowrap>' + nTab(fldr['Sent'], 'displaySpecialMbox(\'Sent\')', link)+ '</td>' +
      '<td width="2%"><img alt="" src="imx/dividerbar.gif" width="24" height="20"></td>' +
      '<td class=Tab2NotSel nowrap>' + nTab(fldr['Trash'], 'displaySpecialMbox(\'Trash\')', link)+ '</td>' +
      '<td width="2%"><img height=20 alt="" src="imx/dividerbar.gif" width=24></td>' +
      '<td class=Tab2NotSel width=97%>' + nTab(fldr['Drafts'], 'displaySpecialMbox(\'Drafts\')', link)+ '</td>' +
      '</tr>' +
      '<tr>' +
      '<td class=Tab2LineBkgd colspan=2><img height=1 alt="" src="imx/spacer.gif" width=1></td>' +
      '<td colspan=3><img height=1 alt="" src="imx/spacer.gif" width=1></td>' +
      '<td class=Tab2LineBkgd colspan=12><img height=1 alt="" src="imx/spacer.gif" width=1></td>' +
      '</tr>' 
  else if (state == 'Inbox')
    s += '<tr>' +
      '<td colspan=17><img height=10 alt="" src="imx/spacer.gif" width=1></td>' +
      '</tr>' +
      '<tr>' + 
      '<td colspan=3><img height=1 alt="" src="imx/spacer.gif" width=10></td>' +
      '<td class=Tab2LineBkgd colspan=5><img height=1 alt="" src="imx/spacer.gif" width=1></td>' +
      '<td colspan=9><img height=1 alt="" src="imx/spacer.gif" width=1></td>' +
      '</tr>' +
      '<tr>' + 
      '<td class=Tab2NotSel nowrap><img height=1 alt="" src="imx/spacer.gif" width=10></td>' +
      '<td class=Tab2NotSel nowrap> ' + nTab(i18n['folders'], 'main.displayFolders()', link)+ '</td>' +
      '<td><img height=1 alt="" src="imx/spacer.gif" width=10></td>' +
      '<td class=Tab2LineBkgd><img height=12 alt="" src="imx/spacer.gif" width=1></td>' +
      '<td class=Tab2Sel nowrap><img height=1 alt="" src="imx/spacer.gif" width=10></td>' +
      '<td class=Tab2Sel nowrap>' + nTab(fldr['INBOX'], 'displaySpecialMbox(\'Inbox\')', link, true)+ '</td>' +
      '<td class=Tab2Sel nowrap><img height=1 alt="" src="imx/spacer.gif" width=10></td>' +
      '<td class=Tab2LineBkgd><img height=12 alt="" src="imx/spacer.gif" width=1></td>' +
      '<td><img height=1 alt="" src="imx/spacer.gif" width=10></td>' +
      '<td class=Tab2NotSel nowrap>' + nTab(fldr['Sent'], 'displaySpecialMbox(\'Sent\')', link)+ '</td>' +
      '<td><img alt="" src="imx/dividerbar.gif" width="24" height="20"></td>' +
      '<td class=Tab2NotSel nowrap>' + nTab(fldr['Trash'], 'displaySpecialMbox(\'Trash\')', link)+ '</td>' +
      '<td><img height=20 alt="" src="imx/dividerbar.gif" width=24></td>' +
      '<td class=Tab2NotSel width=96%>' + nTab(fldr['Drafts'], 'displaySpecialMbox(\'Drafts\')', link)+ '</td>' +
      '</tr>' +
      '<tr>' + 
      '<td class=Tab2LineBkgd colspan=4><img height=1 alt="" src="imx/spacer.gif" width=1></td>' +
      '<td colspan=3><img height=1 alt="" src="imx/spacer.gif" width=1></td>' +
      '<td class=Tab2LineBkgd colspan=10><img height=1 alt="" src="imx/spacer.gif" width=1></td>' +
      '</tr>'
  else if (state == 'Sent')
    s += '<tr>' +
      '<td colspan=20><img height=10 alt="" src="imx/spacer.gif" width=1></td>' +
      '</tr>' +
      '<tr>' +
      '<td colspan=5><img height=1 alt="" src="imx/spacer.gif" width=10></td>' +
      '<td class=Tab2LineBkgd colspan=5><img height=1 alt="" src="imx/spacer.gif" width=1></td>' +
      '<td colspan=4><img height=1 alt="" src="imx/spacer.gif" width=1></td>' +
      '</tr>' +
      '<tr>' +
      '<td class=Tab2NotSel nowrap><img height=1 alt="" src="imx/spacer.gif" width=10></td>' +
      '<td class=Tab2NotSel nowrap>' + nTab(i18n['folders'], 'main.displayFolders()', link)+ '</td>' +
      '<td width="1%"><img alt="" src="imx/dividerbar.gif" width="24" height="20"></td>' +
      '<td class=Tab2NotSel nowrap>' + nTab(fldr['INBOX'], 'displaySpecialMbox(\'Inbox\')', link)+ '</td>' +
      '<td><img height=1 alt="" src="imx/spacer.gif" width=10></td>' +
      '<td class=Tab2LineBkgd><img height=12 alt="" src="imx/spacer.gif" width=1></td>' +
      '<td class=Tab2Sel nowrap><img height=1 alt="" src="imx/spacer.gif" width=10></td>' +
      '<td class=Tab2Sel nowrap>' + nTab(fldr['Sent'], 'displaySpecialMbox(\'Sent\')', link, true)+ '</td>' +
      '<td class=Tab2Sel nowrap><img height=1 alt="" src="imx/spacer.gif" width=10></td>' +
      '<td class=Tab2LineBkgd><img height=12 alt="" src="imx/spacer.gif" width=1></td>' +
      '<td><img height=1 alt="" src="imx/spacer.gif" width=10></td>' +
      '<td class=Tab2NotSel nowrap>' +  nTab(fldr['Trash'], 'displaySpecialMbox(\'Trash\')', link)+ '</td>' +
      '<td><img alt="" src="imx/dividerbar.gif" width="24" height="20"></td>' +
      '<td class=Tab2NotSel width=96%>' + nTab(fldr['Drafts'], 'displaySpecialMbox(\'Drafts\')', link)+ '</td>' +
      '</tr>' +
      '<tr>' +
      '<td class=Tab2LineBkgd colspan=6><img height=1 alt="" src="imx/spacer.gif" width=1></td>' +
      '<td colspan=3><img height=1 alt="" src="imx/spacer.gif" width=1></td>' +
      '<td class=Tab2LineBkgd colspan=5><img height=1 alt="" src="imx/spacer.gif" width=1></td>' +
      '</tr>'
  else if (state == 'Trash')
    s += '<tr>' +
      '<td colspan=21><img height=10 alt="" src="imx/spacer.gif" width=1></td>' +
      '</tr>' +
      '<tr>' + 
      '<td colspan=7><img height=1 alt="" src="imx/spacer.gif" width=10></td>' +
      '<td class=Tab2LineBkgd colspan=5><img height=1 alt="" src="imx/spacer.gif" width=1></td>' +
      '<td colspan=2><img height=1 alt="" src="imx/spacer.gif" width=1></td>' +
      '</tr>' +
      '<tr>' + 
      '<td><img height=1 alt="" src="imx/spacer.gif" width=10></td>' +
      '<td class=Tab2NotSel nowrap>' + nTab(i18n['folders'], 'main.displayFolders()', link)+ '</td>' +
      '<td width="1%"><img alt="" src="imx/dividerbar.gif" width="24" height="20"></td>' +
      '<td class=Tab2NotSel nowrap>' + nTab(fldr['INBOX'], 'displaySpecialMbox(\'Inbox\')', link)+ '</td>' +
      '<td><img alt="" src="imx/dividerbar.gif" width="24" height="20"></td>' +
      '<td class=Tab2NotSel nowrap>' + nTab(fldr['Sent'], 'displaySpecialMbox(\'Sent\')', link)+ '</td>' +
      '<td><img height=1 alt="" src="imx/spacer.gif" width=10></td>' +
      '<td class=Tab2LineBkgd><img height=12 alt="" src="imx/spacer.gif" width=1></td>' +
      '<td class=Tab2Sel nowrap><img height=1 alt="" src="imx/spacer.gif" width=10></td>' +
      '<td class=Tab2Sel nowrap>' +  nTab(fldr['Trash'], 'displaySpecialMbox(\'Trash\')', link, true)+ '</td>' +
      '<td class=Tab2Sel nowrap><img height=1 alt="" src="imx/spacer.gif" width=10></td>' +
      '<td class=Tab2LineBkgd><img height=12 alt="" src="imx/spacer.gif" width=1></td>' +
      '<td><img height=1 alt="" src="imx/spacer.gif" width=10></td>' +
      '<td class=Tab2NotSel width=96%>' + nTab(fldr['Drafts'], 'displaySpecialMbox(\'Drafts\')', link)+ '</td>' +
      '</tr>' +
      '<tr>' + 
      '<td class=Tab2LineBkgd colspan=8><img height=1 alt="" src="imx/spacer.gif" width=1></td>' +
      '<td colspan=3><img height=1 alt="" src="imx/spacer.gif" width=1></td>' +
      '<td class=Tab2LineBkgd colspan=3><img height=1 alt="" src="imx/spacer.gif" width=1></td>' +
      '</tr>'
  else if (state == 'Drafts')
    s += '<tr>' +
      '<td colspan=17><img height=10 alt="" src="imx/spacer.gif" width=1></td>' +
      '</tr>' +
      '<tr>' + 
      '<td colspan=9><img height=1 alt="" src="imx/spacer.gif" width=10></td>' +
      '<td class=Tab2LineBkgd colspan=5><img height=1 alt="" src="imx/spacer.gif" width=1></td>' +
      '<td colspan=12><img height=1 alt="" src="imx/spacer.gif" width=1></td>' +
      '</tr>' +
      '<tr>' + 
      '<td class=Tab2NotSel nowrap><img height=1 alt="" src="imx/spacer.gif" width=10></td>' +
      '<td class=Tab2NotSel nowrap>' + nTab(i18n['folders'], 'main.displayFolders()', link)+ '</td>' +
      '<td class=Tab2NotSel nowrap><img alt="" src="imx/dividerbar.gif" width="24" height="20"></td>' +
      '<td class=Tab2NotSel nowrap>' + nTab(fldr['INBOX'], 'displaySpecialMbox(\'Inbox\')', link)+ '</td>' +
      '<td width="1%"><img alt="" src="imx/dividerbar.gif" width="24" height="20"></td>' +
      '<td class=Tab2NotSel nowrap> ' + nTab(fldr['Sent'], 'displaySpecialMbox(\'Sent\')', link)+ '</td>' +
      '<td width="1%"><img alt="" src="imx/dividerbar.gif" width="24" height="20"></td>' +
      '<td class=Tab2NotSel nowrap>' + nTab(fldr['Trash'], 'displaySpecialMbox(\'Trash\')', link)+ '</td>' +
      '<td><img height=1 alt="" src="imx/spacer.gif" width=10></td>' +
      '<td class=Tab2LineBkgd><img height=12 alt="" src="imx/spacer.gif" width=1></td>' +
      '<td class=Tab2Sel nowrap><img height=1 alt="" src="imx/spacer.gif" width=10></td>' +
      '<td class=Tab2Sel nowrap>' + nTab(fldr['Drafts'], 'displaySpecialMbox(\'Drafts\')', link, true)+ '</td>' +
      '<td class=Tab2Sel nowrap><img height=1 alt="" src="imx/spacer.gif" width=10></td>' +
      '<td class=Tab2LineBkgd><img height=12 alt="" src="imx/spacer.gif" width=1></td>' +
      '<td><img height=1 alt="" src="imx/spacer.gif" width=10></td>' +
      '<td class=Tab2NotSel width="96%">&nbsp;</td>' +
      '</tr>' +
      '<tr>' + 
      '<td class=Tab2LineBkgd colspan=10><img height=1 alt="" src="imx/spacer.gif" width=1></td>' +
      '<td colspan=3><img height=1 alt="" src="imx/spacer.gif" width=1></td>' +
      '<td class=Tab2LineBkgd colspan=13><img height=1 alt="" src="imx/spacer.gif" width=1></td>' +
      '</tr>'
    else
     s += '<tr>' +
      '<td colspan=17><img height=10 alt="" src="imx/spacer.gif" width=1></td>' +
      '</tr>' +
      '<tr>' + 
      '<td colspan=28><img height=1 alt="" src="imx/spacer.gif" width=10></td>' + /*
      '<td class=Tab2LineBkgd colspan=5><img height=1 alt="" src="imx/spacer.gif" width=1></td>' +
      '<td colspan=12><img height=1 alt="" src="imx/spacer.gif" width=1></td>' + */
      '</tr>' +
      '<tr>' + 
      '<td class=Tab2NotSel nowrap><img height=1 alt="" src="imx/spacer.gif" width=10></td>' +
      '<td class=Tab2NotSel nowrap>' + nTab(i18n['folders'], 'main.displayFolders()', link)+ '</td>' +
      '<td class=Tab2NotSel nowrap><img alt="" src="imx/dividerbar.gif" width="24" height="20"></td>' +
      '<td class=Tab2NotSel nowrap>' + nTab(fldr['INBOX'], 'displaySpecialMbox(\'Inbox\')', link)+ '</td>' +
      '<td width="1%"><img alt="" src="imx/dividerbar.gif" width="24" height="20"></td>' +
      '<td class=Tab2NotSel nowrap> ' + nTab(fldr['Sent'], 'displaySpecialMbox(\'Sent\')', link)+ '</td>' +
      '<td width="1%"><img alt="" src="imx/dividerbar.gif" width="24" height="20"></td>' +
      '<td class=Tab2NotSel nowrap>' + nTab(fldr['Trash'], 'displaySpecialMbox(\'Trash\')', link)+ '</td>' +
      '<td width="1%"><img alt="" src="imx/dividerbar.gif" width="24" height="20"></td>' +
      '<td class=Tab2NotSel nowrap>' + nTab(fldr['Drafts'], 'displaySpecialMbox(\'Drafts\')', link)+ '</td>' +
      '<td><img height=1 alt="" src="imx/spacer.gif" width=10></td>' +
      '<td class=Tab2NotSel width="96%">&nbsp;</td>' +
      '</tr>' +
      '<tr>' + 
      '<td class=Tab2LineBkgd colspan=12><img height=1 alt="" src="imx/spacer.gif" width=1></td>' +
      '<td colspan=3><img height=1 alt="" src="imx/spacer.gif" width=1></td>' +
      '<td class=Tab2LineBkgd colspan=13><img height=1 alt="" src="imx/spacer.gif" width=1></td>' +
      '</tr>'

  s += '</tbody>' +
    '</table>' +
    '</td>' +
    '</tr>' +
    '</table>'

  return s;
}

function flagimg(msg) {

  var msgstate = 0
  var s = ''

  if(msg.flags & main.mboxFrame.flag['\\deleted'])
    msgstate = msgstate | 1

  if(msg.flags & main.mboxFrame.flag['\\answered'])
    msgstate = msgstate | 2

  if(msg.flags & main.mboxFrame.flag['\\seen'])
    msgstate = msgstate | 4

  s += '<img src='

  switch(msgstate) {
    case 0 :
      s += 'imx/LrlUnrdMsg_1.gif' + ' alt="' + i18n['msg UnRead'] + '" ';
      break;
    case 1 :
      s += 'imx/LrlUnrdDelMsg_1.gif' + ' alt="' + i18n['msg UnreadDel'] + '" ';
      break;
    case 4 :
      s += 'imx/LrlRdMsg_1.gif' + ' alt="' + i18n['msg Read'] + '" ';
      break;
    case 5 :
      s += 'imx/LrlRdDelMsg_1.gif' + ' alt="' + i18n['msg ReadDel'] + '" ';
      break;
    case 6 :
      s += 'imx/LrlRdAnsMsg_1.gif' + ' alt="' + i18n['msg ReadAns'] + '" ' ;
      break;
    case 7:
      s += 'imx/LrlRdAnsDelMsg_1.gif' + ' alt="' + i18n['msg ReadAnsDel'] + '" ';
      break;
    }
  return s;

}

