// 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 = "/spanish/";
  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">Tito 1:9 – Retenedor de la palabra fiel, la cual es conforme a la enseñanza de los apóstoles, para que también pueda exhortar con sana enseñanza y convencer a los que se oponen.</p></td>');
//Values for ExtraLangs
// P - Portuguese, E - English, S - Spanish, T - Traditional Chinese, F - French, K - Korean, C - Simplified Chinese, J - Japanese, R - Russian
  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;
      }
    if (ColBrk == LoopCnt && lenExtra > 4)
      document.write('</td><td valign="center">')
    else
      document.write("<br>");
    }  
  }
  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 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>');
}

function construct()
{
  document.write('<center><img src=' + relativeRoot + 'graphics/construct.gif></center>');
  document.write('<p>Este sitio está en construcción. ');
  document.write('Verifique por favor la página "<a href=' + relativeRoot + 'whatsnew.html>Lo nuevo</a>" para encontrar lo que se ha agregado.</p>');
}

// This function inserts the tags to close the main body table.

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("á", "a");
  docutitle = docutitle.replace("é", "e");
  docutitle = docutitle.replace("í", "i");
  docutitle = docutitle.replace("ñ", "n");
  docutitle = docutitle.replace("ó", "o");
  docutitle = docutitle.replace("ú", "u");
  docutitle = docutitle.replace("É", "E");
  docutitle = docutitle.replace("Ñ", "N");
  docutitle = docutitle.replace("¿", "%3F");
  docutitle = docutitle.replace("¡", "%21");

//  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=Una pagina de afaithfulword.org&body=" + docutitle + " (" + pageloc + ")";
//  document.write(docutitle + "<br>");
  window.location = mailToURL;
}

function webml()
{
m1 = "lt";
m2 = "mai";
m3 = "o:";
a1 = "o@af";
a2 = "ord.";
a3 = "fulw";
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="Busque afaithfulword.org">');
  document.write('<input type=hidden name=domains value="afaithfulword.org">');
  document.write('<input type=hidden name=sitesearch value="afaithfulword.org"><span class="textbody">&nbsp;</span>');
  document.write('<input type=hidden name=lr value="lang_es"><span class="textbody">&nbsp;</span>');
  document.write('</FORM>');
  document.write('</td></tr></table>');
  document.write('<table width="750"><tr>');
  document.write('<td rowspan="2"><span class="copyright">&copy; 2006 DCP. Todos los derechos reservados.<br>');
  document.write('DCP es un proyecto destinado a defender y confirmar el ministerio neotestamentario de Watchman Nee y Witness Lee y la práctica de las iglesias locales.');
  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('Todos los versículos y las notas de pie de página fueron tomados del Nuevo Testamento Versión Recobro. La casa publicadora Living Stream Ministry tiene todos los derechos reservados sobre los extractos tomados de la Versión Recobro y del ministerio de Watchman Nee y Witness Lee y fueron utilizados con permiso. Witness Lee es el autor de las citas a menos que este señalado de otra manera. Las citas del Antiguo Testamento fueron tomadas de la versión Reina Valera, 1960 y del Texto Revisado.</p></td></tr></table>');
}
