// The value for TestStr in setRelativeRoot needs to be changed for each language or new site using this script.
// It should be set to the subdirectory on the server that will hold the site for that language.
// The portion of the header() function that switches among languages also needs modification.

function setRelativeRoot()
{
  var TestStr = "/chinese/";
  TestLen = TestStr.length;
  var Pos = 0;
  var PathLen = 0;
  var LPos = 0;
  var LLen = 0;
  var CPath = "";
  CPath = location.href;
  PathLen = CPath.length;
  Pos = CPath.indexOf(TestStr);
  if (Pos < 0)
    { URL = CPath.substr(7, PathLen);
      LPos = URL.indexOf('/') + 8;
    }
  else
    { LPos = Pos + TestLen; }  
  LLen = PathLen - LPos + 1;
  FPath = CPath.substr(LPos, LLen);
  FLen = FPath.length;
  Pos = 1;
  var SlashCnt = 0;
  while (Pos <= FLen)
    {
    if (FPath.substr(Pos, 1) == "/")
      SlashCnt++;
    Pos++;
    }
  if (SlashCnt == 0)
    relativeRoot = "./";
  else
    {
    relativeRoot = "";
    for (LoopCnt = 1; LoopCnt <= SlashCnt; LoopCnt++)
      relativeRoot += "../";
    }
}


function openDir( form ) { 
  var newIndex = form.fieldname.selectedIndex; 
  cururl = form.fieldname.options[ newIndex ].value; 
  window.location.assign( cururl ); 
} 

function header( ExtraLangs )
{
  docURL = document.URL;
  if (relativeRoot == "./")
    { slashCnt = 1 }
  else
    { slashCnt = (relativeRoot.length / 3) + 1; }
  pos = docURL.length;
  while (slashCnt > 0)
    { docChar = docURL.substr(pos, 1);
      if (docChar == "/" || docChar == "\\")
      { slashCnt--;
        if (slashCnt == 0)
          { break; }
      }
      pos--;
    }
  relURL = docURL.substring(pos + 1, docURL.length);

  //general background and text settings
  document.write('<img src="' + relativeRoot + 'graphics/titlebar.gif"><br><br>');
  document.write('<table width="750" border="1" bgcolor="#FFFFE0"><tr>');
  document.write('<td width="625"><p class="leadRcV">羅十六17：弟兄們，那些造成分立和絆跌之事，違反你們所學之教訓的人，我懇求你們要留意，並要避開他們。</p>');
  document.write('<p class="leadRcV2">提後二25：用溫柔規勸那些抵擋的人；或許神給他們悔改的心，得以認識真理。</p></td>');


  //if (!(ExtraLangs == null))
  //  if (ExtraLangs.substr(1, 1) != "X")
//Values for ExtraLangs
// P - Portuguese, E - English, S - Spanish, T - Traditional Chinese, F - French, K - Korean, C - Simplified Chinese, J - Japanese, R - Russian, G - German
  if (!(ExtraLangs == null))
  {
  document.write('</td><td align="center">');
  lenExtra = ExtraLangs.length;
  ColBrk = parseInt(String((lenExtra) / 2));
  for (LoopCnt = 1; LoopCnt <= lenExtra; LoopCnt++)
    {
    Lang = ExtraLangs.substr(LoopCnt - 1, 1);
    switch (Lang)
      {
        case "P":
          document.write('<a href="' + relativeRoot + '../portuguese/' + relURL + '" border="0"><img src="' + relativeRoot + '../graphics/portuguese.jpg" border="0"></a>');
          break;
        case "E":
          document.write('<a href="' + relativeRoot + '../' + relURL + '" border="0"><img src="' + relativeRoot + '../graphics/english.jpg" border="0"></a>');
          break;
        case "S":
          document.write('<a href="' + relativeRoot + '../spanish/' + relURL + '" border="0"><img src="' + relativeRoot + '../graphics/spanish.jpg" border="0"></a>');
          break;
        case "T":
          document.write('<a href="' + relativeRoot + '../chinese/' + relURL + '" border="0"><img src="' + relativeRoot + '../graphics/trad_chin.jpg" border="0"></a>');
          break;
        case "F":
          document.write('<a href="' + relativeRoot + '../french/' + relURL + '" border="0"><img src="' + relativeRoot + '../graphics/french.jpg" border="0"></a>');
          break;
        case "K":
          document.write('<a href="' + relativeRoot + '../korean/' + relURL + '" border="0"><img src="' + relativeRoot + '../graphics/korean.jpg" border="0"></a>');
          break;
        case "C":
          document.write('<a href="' + relativeRoot + '../simpchin/' + relURL + '" border="0"><img src="' + relativeRoot + '../graphics/sim_chin.jpg" border="0"></a>');
          break;
        case "J":
          document.write('<a href="' + relativeRoot + '../japanese/' + relURL + '" border="0"><img src="' + relativeRoot + '../graphics/japanese.jpg" border="0"></a>');
          break;
        case "R":
          document.write('<a href="' + relativeRoot + '../russian/' + relURL + '" border="0"><img src="' + relativeRoot + '../graphics/russian.jpg" border="0"></a>');
          break;
        case "G":
          document.write('<a href="' + relativeRoot + '../german/' + relURL + '" border="0"><img src="' + relativeRoot + '../graphics/german.jpg" border="0"></a>');
          break;
      }
    if (ColBrk == LoopCnt && lenExtra > 4)
      document.write('</td><td valign="center">')
    else
      document.write("<br>");
    }  
  }
  //if (!(ExtraLangs == null))
  //  if (ExtraLangs.substr(1, 1) != "X")
  if ((ExtraLangs == null) || (ExtraLangs.substr(1, 1) != "X"))
      document.write('</td></tr></table><br>');
}

function tablestart()
{
  //size table to screen resolution
  document.write('<table width="750" frame="void" border="2" cellpadding="4">');
//  document.write('<tr><td colspan="2"></td></tr>');
//  document.write('<tr><td valign="top" width="200" bgcolor="#FFE0FF">');
//  document.write('<tr><td></td></tr>');
}

function tablebody()
{
//  document.write('</td>');
  document.write('<td bgcolor="#FFFFFF">');
}

function construct()
{
  document.write('<center><img src=' + relativeRoot + 'graphics/construct.gif></center>');
  document.write('<p>This site is currently under construction. 請前至<a href=' + relativeRoot + 'whatsnew.html>最新消息</a>，查看本站新增的文章。</p>');
}

function acrobat()
{
document.write('<a href="http://www.adobe.com/products/acrobat/readstep2.html" target="_blank">');
document.write('<img src="' + relativeRoot + '../graphics/get_adobe_reader.gif"></a>');
}

// This function inserts a copyright statement with "DCP" as the holder.

function endtable()
{
  document.write('</td></tr></table>');
}

function mailURL()
{ 
  HTMLtitle = document.title;
  docutitle = "";
  pNode = document.getElementById("doctitle");
  if (pNode != null)
    { cNodes = pNode.childNodes;
      for (var i = 0; i < cNodes.length; i++) 
        {
        var child = cNodes[i];
        docutitle = docutitle + child.nodeValue;
        }
    }
  if (HTMLtitle.length > docutitle.length)
    { docutitle = HTMLtitle; }
  docutitle = docutitle.replace(/"/gi, '%22');
  docutitle = docutitle.replace(/'/gi, "%27");
  docutitle = docutitle.replace("?", "%3F");
  docutitle = docutitle.replace("?", "%3F");
  docutitle = docutitle.replace(/&mdash;/gi, "--");
  docutitle = docutitle.replace(/&amp;/gi, "%26");
  docutitle = docutitle.replace(/& /gi, "%26 ");
  docutitle = docutitle.replace(/null/gi, " ");
  docutitle = docutitle.replace("<u>/", "");
  docutitle = docutitle.replace("</u>", "");
  docutitle = docutitle.replace(/Say%3F/gi, "Really Say%3F");
  
  titlepos = docutitle.length;
  while (titlepos >= 0)
    { TestPos = docutitle.substr(titlepos, 1);
      escTestPos = escape(TestPos);
      pt1 = docutitle.substring(0, titlepos);
      pt2 = docutitle.substring(titlepos + 1, docutitle.length);
      if (escTestPos == "%u2014")
        { docutitle = pt1 + "--" + pt2; 
        }
      if (escTestPos == "%0A")
        { docutitle = pt1 + " " + pt2; 
        }

      titlepos--;
    }
  docutitle = docutitle.replace(/  /gi, " ");
  pageloc = escape(location.href);
  mailToURL = "mailto:&subject=A page from afaithfulwitness.org&body=" + docutitle + " (" + pageloc + ")";
//  document.write(docutitle + "<br>");
  window.location = mailToURL;
}

function webml()
{
m1 = "lt";
m2 = "mai";
m3 = "o:";
a1 = "o@af";
a2 = "ness.";
a3 = "fulwit";
a4 = "org";
a5 = "inf";
a6 = "aith";
ml = m2 + m1 + m3 + a5 + a1 + a6 + a3 + a2 + a4;
document.write('<a href="' + ml + '">');
document.write('<center><img src="' + relativeRoot + 'graphics/up_info.jpg" border="0"></a></center>');
}


// This function inserts a copyright statement with "DCP" as the holder.
function footer()
{
  document.write('<table width="750">');
  document.write('<tr><td valign="middle">');
  document.write('<FORM method=GET action="http://www.google.com/search">');
  document.write('<input type=hidden name=ie value=UTF-8>');
  document.write('<input type=hidden name=oe value=UTF-8>');
  document.write('&nbsp;&nbsp;<A HREF="http://www.google.com/"><IMG SRC="' + relativeRoot + '../graphics/Google.gif" border="0" ALT="Google"></A>');
  document.write('</td>');
  document.write('<td valign="middle">');
  document.write('<INPUT TYPE=text name=q size=40 maxlength=255 value="">');
  document.write('</td>');
  document.write('<td valign="middle">');
  document.write('<INPUT type=image name=btnG SRC="' + relativeRoot + 'graphics/search.jpg">');
//  document.write('<INPUT type=submit name=btnG VALUE="Search afaithfulwitness.org">');
  document.write('<input type=hidden name=domains value="afaithfulwitness.org">');
  document.write('<input type=hidden name=sitesearch value="afaithfulwitness.org"><span class="textbody">&nbsp;</span>');
  document.write('<input type=hidden name=lr value="lang_en"><span class="textbody">&nbsp;</span>');
  document.write('</FORM>');
  document.write('</td></tr></table>');
  document.write('<table width="750">');
  document.write('<tr><td rowspan="2"><span class="copyright">版權所有© 2009 DCP. All Rights Reserved.<br>');
  document.write('DCP為一專項服事，辯護並證實倪柝聲和李常受弟兄所盡的新約職事，以及地方召會的實行。');
  document.write('</span></td>');
  document.write('<td colspan="3" align="center"><a onclick="mailURL()"><img border="0" src="' + relativeRoot + 'graphics/up_email.jpg"></a></td></tr>');
  document.write('<tr>');
  document.write('<td align="center"><a href=' + relativeRoot + 'index.html><img border="0" src="' + relativeRoot + 'graphics/up_homepage.jpg"></a></td>');
  document.write('<td align="center"><a href=' + relativeRoot + 'whatsnew.html><img border="0" src="' + relativeRoot + 'graphics/up_whatsnew.jpg"></a></td>');
  document.write('<td align="center"><a href=' + relativeRoot + 'sitemap.html><img border="0" src="' + relativeRoot + 'graphics/up_sitemap.jpg"></a></td>');
  document.write('</tr>');
  document.write('<tr><td colspan="5"><p class="copyright">');
  document.write('本站使用的經文和註解，均出自水流職事站和臺灣福音書房出版的新舊約聖經恢復本。新舊約聖經恢復本，倪柝聲著作，李常受著作之版權，為水流職事站和臺灣福音書房所有，本站經許可後使用。 除特別標示外，著者皆為李常受。</p></td></tr></table>');
}
