var pv = 0;

var cItemDate = "";
var cNewItem  = "";
var cItemDoc  = "";
var cItemImg  = "";
var cItmMovie = "";
var cItemPath = "";

function item_top(c_ind)
{
  var td_str = "";
  var btn_Dtl_str = '<img src="../images/btn_detail.gif" width="55" height="14" border="0" alt="詳情">';
  var btn_Pic_str = '<img src="../images/btn_photo.gif" width="55" height="14" border="0" alt="圖片">';
  var btn_Non_str = '<img src="../images/btn_none.gif" width="55" height="14" border="0" alt="">';

  document.writeln('<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="FFD9A1">');
  document.writeln('<tr>');
  document.writeln('<td><img src="../images/spacer.gif" width="2" height="2" alt=""></td>');
  document.writeln('<td><img src="../images/spacer.gif" width="2" height="2" alt=""></td>');
  document.writeln('<td><img src="../images/t1_2.gif" alt=""></td>');
  document.writeln('<td bgcolor="FFEFD9"><img src="../images/spacer.gif" width="2" height="2" alt=""></td>');
  document.writeln('<td bgcolor="#FFFFFF"><img src="../images/t1_5.gif" width="16" height="2" alt=""></td>');
  document.writeln('</tr><tr>');
  document.writeln('<td bgcolor="FFA928"><img src="../images/t1_1.gif" width="4" height="14" alt=""></td>');
  document.writeln('<td bgcolor="FFA928" width="100%"><img src="../images/spacer.gif" width="1" height="1" alt=""></td>');
  document.writeln('<td><img src="../images/t1_3.gif" alt=""></td>');

  td_str  = btn_Non_str;
  if (cItemImg > "")
  {
    td_str = photoLink(td_str, cItemImg) + '>' + btn_Pic_str + '</a>';
  }
  if (cItemDoc > "") 
  {
    td_str = docLink(td_str,  cItemDoc) + '>' + btn_Dtl_str + '</a>';
  }
  if (cItemPath > "") 
  {
    td_str = pathLink(td_str, cItemPath) + '>' + btn_Dtl_str + '</a>';
  }
  if (c_ind == "none") 
  {
    td_str  = btn_Non_str;
  }

  document.writeln('<td bgcolor="FFEFD9">', td_str, '</td>');
  document.writeln('<td bgcolor="#FFFFFF"><img src="../images/t1_6.gif" width="16" height="14" alt=""></td>');
  document.writeln('</tr><tr>');
  document.writeln('<td><img src="../images/spacer.gif" width="2" height="2" alt=""></td>');
  document.writeln('<td><img src="../images/spacer.gif" width="2" height="2" alt=""></td>');
  document.writeln('<td><img src="../images/t1_4.gif" alt=""></td>');
  document.writeln('<td bgcolor="FFEFD9"><img src="../images/spacer.gif" width="2" height="2" alt=""></td>');
  document.writeln('<td bgcolor="#FFFFFF"><img src="../images/t1_7.gif" width="16" height="2" alt=""></td>');
  document.writeln('</tr>');
  document.writeln('</table>');
  document.writeln('<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="FFF9F1" vspace="2" hspace="2">');
  document.writeln('<tr bgcolor="#FFFFFF">');
  document.writeln('<td colspan="3"><img src="../images/spacer.gif" width="2" height="2" alt=""></td>');
  document.writeln('</tr><tr>');
  document.writeln('<td><img src="../images/spacer.gif" width="10" height="3" alt=""></td>');
  document.writeln('<td width="100%"><img src="../images/spacer.gif" width="10" height="3" alt=""></td>');
  document.writeln('<td><img src="../images/t2_1.gif" width="14" height="3" alt=""></td>');
  document.writeln('</tr><tr>');
  document.writeln('<td>&nbsp;</td>');
  document.writeln('<td width="100%">');
  document.writeln('<p>');
}

function item_end(t_ind)
{
  var td_str = "";
  var news_ind_str = '<img src="../images/news.gif" align="absmiddle" alt="最新消息">';
  var diable_str   = "'#999966'";
  diable_str = '<a style="color:' + diable_str + '"';

  var show_ind = ( (t_ind == null) ? "1111001" : t_ind);

  document.writeln('</td>');
  document.writeln('<td valign="bottom"><img src="../images/t2_2.gif" width="14" height="14" alt=""></td>');
  document.writeln('</tr>');
                    
  if (t_ind == "0000000") {
    document.writeln('</table><p>');

    cItemDate = "";
    cNewItem  = "";
    cItemDoc  = "";
    cItemImg  = "";
    cItmMovie = "";
    cItemPath = "";

    return;
  }

  document.writeln('<tr bgcolor="#FFFFFF"><td colspan="3">');
  document.writeln('<table align="center" width="100%"><tr bgcolor="#FFFFFF">');
  document.write(  '<td colspan="3"><img src="../images/spacer.gif" width="2" height="2" alt="">');
  document.write(  '</td></tr><tr>');

  td_str  = '<td align="left"><font class="datefont">';
  td_str += ( ((cItemDate > "") && chkShowInd(show_ind, "date")) ? '( ' + cItemDate + ' )' : '&nbsp');
  td_str += '</font></td>';
  document.writeln(td_str);

  td_str  = '<td align="center">';
  td_str += ( (chkNewItem() && chkShowInd(show_ind, "new")) ? news_ind_str : '&nbsp') + '</td>';
  document.writeln(td_str);

  document.writeln('<td align="right">[&nbsp;');

  if (chkShowInd(show_ind, "dtl")) {
    td_str = docLink(diable_str, cItemDoc);
    td_str = pathLink(td_str   , cItemPath);
    document.writeln(td_str, ' class="smlink">詳情</a>&nbsp;|');
  }

  if (chkShowInd(show_ind, "photo")) {
    td_str = photoLink(diable_str, cItemImg);
    document.writeln(td_str, ' class="smlink">圖片</a>&nbsp;|');
  }

  if (chkShowInd(show_ind, "movie")) {
    td_str = movieLink(diable_str, cItmMovie);
    document.writeln(td_str, ' class="smlink">影片</a>&nbsp;|');
  }

  if (chkShowInd(show_ind, "link")) {
    td_str = pathLink(diable_str, cItemPath);
    document.writeln(td_str, ' class="smlink">連結</a>&nbsp;|');
  }

  td_str  = '<a href="#top" class="smlink">返回頁首</a>&nbsp;]</td>';
  td_str += '</tr></table>';
  document.writeln(td_str);

  document.writeln('</td></tr><tr bgcolor="#FFFFFF">');
  document.writeln('<td colspan="3"><img src="../images/spacer.gif" width="2" height="2" alt=""></td>');
  document.writeln('</tr>');
  document.writeln('</table><p>');

  cItemDate = "";
  cNewItem  = "";
  cItemDoc  = "";
  cItemImg  = "";
  cItmMovie = "";
  cItemPath = "";
}

function docLink(t1, cLinkStr)
{
  var t2 = '<a href="' + hss_exSrvPath() + 'docs/' + cLinkStr + '" target="blank"';
  var t3 = '<a href="../photo/detailPg.htm?pv=' + pv + '#' + cLinkStr + '"';
  t2 = (cLinkStr.lastIndexOf(".txt")==(cLinkStr.length-4) ? t3 : t2);
  return((cLinkStr > "" ? t2 : t1));
}

function photoLink(t1, cLinkStr)
{
  var t2 = '<a href="../photo/photoPg.htm?pv=' + pv + '#' + cLinkStr + '"';
  return((cLinkStr > "" ? t2 : t1));
}

function movieLink(t1, cLinkStr)
{
  var t2 = '<a href="../photo/videoPg.htm?pv=' + pv + '#' + cLinkStr + '"';
  return((cLinkStr > "" ? t2 : t1));
}

function pathLink(t1, cLinkStr)
{
  var t2 = '<a href="' + cLinkStr + '"';
  return((cLinkStr > "" ? t2 : t1));
}

function chkNewItem()
{
  var newInd = (cNewItem.toLowerCase() == "yes");
  var itmDay = new Date();
  var curDay = new Date();

  var nDay = parseInt(cItemDate.substring(0,2),10);
  var nMon = parseInt(cItemDate.substring(3,5),10)-1;
  var n_Yr = parseInt(cItemDate.substring(6,10),10);

  var cSTR = "0";
  if (((n_Yr % 4 == 0) && (n_Yr % 100 != 0)) || (n_Yr % 400 == 0)) cSTR = "1";
  cSTR = "3" + cSTR + "3232332323"

  var nMnD = parseInt(cSTR.charAt(nMon),10) + 28;

  nDay = nDay + 10;
  if (nDay > nMnD) {
    nDay = nDay % nMnD;
    nMon = nMon + 1;
  }
  if (nMon > 11) {
    nMon = nMon % 12;
    n_Yr = n_Yr + 1;
  }

  itmDay.setFullYear(n_Yr);
  itmDay.setMonth(nMon);
  itmDay.setDate(nDay);

  return((curDay < itmDay) && newInd);
}

// show_ind="000000" : date|new|dtl|photo|movie|link|back : 0-hidden, 1-show
function chkShowInd(show_ind, cItemNm)
{
  var nIndPos = -1;

  nIndPos = (cItemNm == "date"  ? 0 : nIndPos);
  nIndPos = (cItemNm == "new"   ? 1 : nIndPos);
  nIndPos = (cItemNm == "dtl"   ? 2 : nIndPos);
  nIndPos = (cItemNm == "photo" ? 3 : nIndPos);
  nIndPos = (cItemNm == "movie" ? 4 : nIndPos);
  nIndPos = (cItemNm == "link"  ? 5 : nIndPos);
  nIndPos = (cItemNm == "back"  ? 6 : nIndPos);

  return((nIndPos > -1 ? (show_ind.charAt(nIndPos) == "1") : false));
}
