// These variables are for supporting multilanguage.
var languages=new Array(10);
var languages_size=0;
var Language = "en";
var langdesc=new Array();

// ============================================================
// Uncomment the downloaded languages below.
languages[languages_size++]="en"; // English
languages[languages_size++]="tw"; // Traditional Chinese
languages[languages_size++]="cn"; // Simplified Chinese

// ============================================================
// Languages that are translated by Google.
languages[languages_size++]="kr"; // Korean

// ============================================================
// A description of the language codes.
langdesc["en"] = "English";
langdesc["tw"] = "Traditional Chinese";
langdesc["cn"] = "Simplified Chinese";
langdesc["kr"] = "Korean";

// ============================================================

// ============================================================
// Online Google translations.
var translation_site="http://translate.googleusercontent.com";
var translation_query="/translate_c?";
var translation_codes=new Array();

// Korean
translation_codes["kr"] = "langpair=en%7Cko&u=";
// ============================================================

// These variables are for the web counter
var sc_project=858897; 
var sc_invisible=1; 
var sc_partition=3; 
var sc_security="2963a6eb"; 
var sc_text;

// Web site
var web_site="www.3dbibleproject.com";

// E-mail contact
var email_address="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#115;&#116;&#101;&#112;&#104;&#101;&#110;&#46;&#116;&#97;&#109;&#64;&#51;&#100;&#98;&#105;&#98;&#108;&#101;&#112;&#114;&#111;&#106;&#101;&#99;&#116;&#46;&#99;&#111;&#109;";

var option1 = "scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,width=752,height=650";
var option2 = "scrollbars=yes,toolbar=yes,location=yes,status=yes,menubar=yes,resizable=yes";

var ie4=document.all;
var ns6=document.getElementById&&!document.all;

var Location=unescape(location.href);
var menuPrinterWidth = 150;
var menuType = "vertical";
var level = 0;
var DocRoot = "/";
var OrigDocRoot = "/";
var LanguageIndex = 0;
var studying = true;
var normalView = Location.indexOf("printer=on")<0;
var online = location.protocol=="http:";

function showMenu() {
  return normalView && studying;
}

function chkWindows() {
  var details = navigator.userAgent;
  return details.indexOf("Windows")!=-1;
}

function chkBrowser() {
  var appname = navigator.appName;
  var appversion = navigator.appVersion;

  if (appname == "Microsoft Internet Explorer") {
    var p1 = appversion.indexOf("MSIE") + 5;
    var s1 = appversion.substring(p1, p1+8);
    var p2 = s1.indexOf(";");
    var version = "0";

    if (p2 > 0) 
      version = s1.substring(0,p2);
    return (parseFloat(version) >= 5);
  }
  return false;
}

function openwindow(url,options) {
  if (options == null)
    window.open(url, "t1", option1);
  else
    window.open(url, "t2", options);
}

function resize_table() {
  var textarea=115300;
  var elem=document.getElementById("world");
  var myWidth=0, myHeight=0, textheight=0;
  if (elem) {
    if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
      //IE 6+ in 'standards compliant mode'
      myWidth = document.documentElement.clientWidth;
      myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
      //IE 4 compatible
      myWidth = document.body.clientWidth;
      myHeight = document.body.clientHeight;
    }
    textheight=textarea/myWidth;
    if (textheight<150) textheight=150;
    elem.style.height=myHeight-textheight;
  }
}

function Cortona(elemId, node, field, id, imageId, imageUrl) {
  elem=document.getElementById(elemId);
  if (elem && elem.Engine)
    elem.Engine.Nodes(node).Fields(field)=id;
  else
    document.getElementById(imageId).style.backgroundImage="url("+imageUrl+")";
}

function getDocRoot() {
  var doc=Location;
  var i=doc.length;
  while (i>1) {
    var j=i;
    doc=doc.substring(0,j);
    i=doc.lastIndexOf("/");
    if ((j-i)==3) {
      OrigDocRoot=DocRoot=doc.substring(0,i+1);
      Language=doc.substring(i+1,j+1);
      // If Google translation is on, remove the translation stuff
      j=doc.lastIndexOf("u=http:"); 
      if (j>1) OrigDocRoot=doc.substring(j+2,i+1);
      return i;
    }
  }
  return i;
}

function translate_me() {
  if (online) {
    var doc=Location;
    if (translation_codes[Language]==undefined) return;
    if (doc.indexOf("http://translate.")<0) location.replace(translate_url(doc,Language));
  }
}

function dont_translate_me() {
  if (online) {
    var doc=Location;
    var i;
    i=doc.lastIndexOf("http:");
    if (i>0) location.replace(doc.substring(i));
  }
}


function translate_url(myurl, language_id) {
  if (online) {
    if (translation_codes[language_id]==undefined) return myurl;
    myurl=translation_site+translation_query+translation_codes[language_id]+myurl;
  }
  return myurl;
}

function language(language_id) {
  var doc=Location;
  if (language_id==Language) return doc+"#";
  if (LanguageIndex>1) {
    doc=OrigDocRoot+language_id+doc.substring(LanguageIndex+3);
  }
  return doc;
}

function languageMenu(language_id,printVersionWidth) {
  document.writeln('<table border="0" cellpadding="0" cellspacing="0">');
  document.writeln('<tr><td><table width="170" border="0" cellpadding="0" cellspacing="0"><tr><td align="right">');
  document.writeln('<img src="'+OrigDocRoot+language_id+'/images/languages.gif" border="0" style="vertical-align:middle;"></a>');
  document.writeln('</td></tr></table></td>');
  document.writeln('<td><table width="500" border="0" cellpadding="0" cellspacing="0"><tr>');
  for (var i=0; i<languages_size; i++) {
    var image='<img src="'+OrigDocRoot+'images/'+languages[i]+'.gif" border="0" width="16" height="11" style="margin:2px; vertical-align:bottom;">';
    document.writeln('<td width="30"><a class="language" href="'+language(languages[i])+'"'+' title="'+langdesc[languages[i]]+'">'+image+'</a></td>');
  }
  document.writeln('<td>&nbsp;</td>');
  document.writeln('</tr></table></td>');
  document.writeln('<td><table width="'+printVersionWidth+'" border="0" cellpadding="0" cellspacing="0"><tr><td>');
  document.writeln('<a class="printer" href="javascript:printerVersion()">');
  document.writeln('<img src="'+OrigDocRoot+'images/print.gif" border="0" style="vertical-align:middle;"> ');
  document.writeln('<img src="'+OrigDocRoot+language_id+'/images/printer_version.gif" border="0" style="vertical-align:middle;"></a>');
  document.writeln('</td></tr></table></td></tr></table>');
}

function fullpath(filename) {
  var doc=DocRoot+Language+"/"+filename;
  if (doc==Location) doc+="#";
  return doc;  
}

function getpath(filename) {
  var doc=Location;

  // Check if Google translation is currently on
  var i=doc.lastIndexOf("u=http:");
  if (i==-1) return filename; // Don't care if no translation

  doc=doc.substring(i+2);
  i=doc.lastIndexOf("/");
  while (i>0) {
    doc=doc.substring(0,i);
    if ((i=filename.indexOf("../"))==0) {
      filename=filename.substring(i+3);
      i=doc.lastIndexOf("/");
    }
    else {
      i=-1;
    }
  }
  return doc+"/"+filename;
}

var fifo = new Array();
var top = 0;

function queue(thing) {
  fifo[top++]=thing;
}

function unqueue() {
  if (top>0) {
    var thing=fifo[0];
    --top;
    for (var i=0; i<top; i++) fifo[i]=fifo[i+1];
    return thing;
  }
  else return null;
}

function remove(thing) {
  for (var i=0; i<top; i++) {
    if (fifo[i]==thing) {
      fifo[i]=null;
      return true;
    }
  }
  return false;
}

function contact(link_label) {
  document.write('<a href="' + email_address + '">'+link_label+'</a>');
}

function email() {
  location.href=email_address;
}

function displayItem(node) {
  var child;

  if (remove(node)) return;

  for (var i=0; i<node.childNodes.length; i++) {
    child = node.childNodes[i];
    if (child.nodeName=="UL") {
      child.style.display = "block";
      return;
    }
  }
}

function hideMenu() {
  var hideNode=unqueue();
  if (hideNode==null) return;
  for (var i=0; i<hideNode.childNodes.length; i++) {
    var child = hideNode.childNodes[i];
    if (child.nodeName=="UL" && child.className.length>0) {
      child.style.display = "none";
      return;
    }
  }
}

function hideItem(node) {
  queue(node);
  setTimeout("hideMenu()", 10);
}

function menu(mType) {
  menuType = mType;
  document.writeln('<ul class="' + menuType + '">');
}

function endMenu() {
  document.writeln('</ul>');
}

function menuItem(title, link) {
  document.writeln('<li><a href="'+link+'">' + title + '</a></li>');
}

function subMenu(title) {
  level++;
  document.writeln('<li class="' + menuType + '" onmouseover="displayItem(this)" onmouseout="hideItem(this)">');
  document.write('<a href="' + Location + '#">'+title);
  if (menuType == "vertical" || level > 1) document.write('<span><img src="'+OrigDocRoot+'images/arrow.gif" border="0" style="vertical-align:middle;"></span>');
  document.writeln('</a><ul class="' + menuType + '">');
}

function endSubMenu() {
  level--;
  document.writeln('</ul></li>');
}

function printerVersion() {
  window.open(Location+"?printer=on", "PrinterVersion");
}

function resizeIFrame(myFrame) {
  if (myFrame.contentWindow) {
    myFrame.height = myFrame.contentWindow.document.body.scrollHeight + 10;
  }
}

function webCounter(invisible) {
  if (!online) return;
  sc_invisible=invisible;
  if (!invisible) sc_text=2;
  document.writeln('<script type="text/javascript" src="http://www.statcounter.com/counter/counter.js"></script>');
}

function googleAdsense() {
  if (!online || !showMenu()) return;

  // These variables are for Google Adsense
  google_ad_client = "pub-5708090644259766";
  google_ad_width = 160;
  google_ad_height = 600;
  google_ad_format = "160x600_as";
  google_ad_type = "text_image";
  google_ad_channel = "3417335150";
  google_color_border = "227295";
  google_color_bg = "FFFFFF";
  google_color_link = "227295";
  google_color_text = "000000";
  google_color_url = "0000FF";
  document.writeln('<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>');
}

function googleAdsense2() {

}

function googleAdsense4() {
  // Google Adsense and Translation

  if (!online || !showMenu()) return;

  // These variables are for Google Adsense
  google_ad_client = "pub-5708090644259766";
  google_ad_width = 728;
  google_ad_height = 90;
  google_ad_format = "728x90_as";
  google_ad_type = "text_image";
  // 2007-03-09: top
  google_ad_channel = "9566537543";
  google_color_border = "227295";
  google_color_bg = "FFFFFF";
  google_color_link = "227295";
  google_color_text = "000000";
  google_color_url = "0000FF";
  document.writeln('<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>');

  //document.writeln('<script src="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>');
}

function googleTranslateElementInit() {
  new google.translate.TranslateElement({
    pageLanguage: 'en'
  }, 'google_translate_element');
}

function enableGoogleAdsense() {
  // Turn on Google Adsense
  var adsense = document.getElementById("adsense");
  if (adsense) adsense.style.visibility = "visible";
  adsense = document.getElementById("adsense2");
  if (adsense) adsense.style.visibility = "visible";
  adsense = document.getElementById("adsense4");
  if (adsense) adsense.style.visibility = "visible";
}

// These functions are to be override by local language routines.
function fixLinks() {};
function showMessage() {};
function topMenu() {};
function leftMenu() {};
function googleSearch() {};
function copyright() {};
function description() {};

function copyrightNotice() {
  var currentTime = new Date();
  var currentYear = currentTime.getFullYear();
  document.writeln('<table border="0" cellpadding="5" cellspacing="0" width="100%">');
  document.writeln('<tr><td><span style="color: #CCCCFF;"><small>');
  document.writeln("&copy; 2003-"+currentYear+" by ");
  document.write('<a href="' + email_address + '" style="color: #CCCCFF;">Stephen Tam</a>');
  document.write(", " + web_site + ". All rights reserved.");
  document.writeln(' | <a href="license.htm" target="copyright" style="color: #CCCCFF;">COPYRIGHT POLICY</a>');
  document.writeln('</small></span>');
  document.writeln('</td></tr>');
  document.writeln('</table>');
}

function topBorder(titleImage) {
  var adsense;

  if (showMenu()) {

    if (titleImage == undefined) titleImage = "images/title.jpg";

    // ==============================================================
    document.writeln('<table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">');
    document.writeln('<tr><td colspan="2" width="100%" valign="top">');
    // ==============================================================

    // --------- Top border ----------
    document.writeln('<table border="0" width="100%" cellpadding="0" cellspacing="0" bgcolor="#005F81">');
    document.writeln('  <tr><td width="700" bgcolor="#000000" colspan="3">');
    languageMenu(Language, menuPrinterWidth);
    document.writeln('  </td></tr>');
    document.writeln('  <tr>');
    document.writeln('    <td align="left" valign="top" width="321">');
    document.writeln('      <img src="'+titleImage+'" width="321" height="62">');
    document.writeln('    </td>');
    document.writeln('    <td>');
    document.writeln('      <font color="#CCCCFF" size="1"><b>');
    description();
    document.writeln(' <font color="#005F81" size="1">' + Location + '</span>');
    document.writeln('    </td>');
    document.writeln('    <td width=10>');
    document.writeln('    </td>');
    document.writeln('  </tr>');
    document.writeln('  <tr>');
    document.writeln('    <td bgcolor="#000000" colspan="3">');
    document.writeln('      <table border="0" cellpadding="0" cellspacing="0"><tr>');
    document.writeln('        <td width="170">&nbsp;</td>');
    document.writeln('        <td>');
    topMenu();
    document.writeln('        </td></tr></table></td>');
    document.writeln('  </tr>');
    document.writeln('</table>');
    // ------ End of Top border -------

    // ==============================================================
    document.writeln('</td></tr>');
    document.writeln('<tr><td width="170" valign="top">');
    // ==============================================================

    // ---------- Left menu -----------
    document.writeln("<table border=0 width=170 height=100% cellpadding=0 cellspacing=0>");
    document.writeln('  <tr><td bgcolor="#227295" valign="top">');
    leftMenu();
    if (online) { // Google Translation gadget and Adsense space holder
      document.writeln('<div id="google_translate_element" style="height:50px;"></div>');
      document.writeln('<div style="height:640px;"></div>');
   }
    document.writeln('  </td></tr>');
    document.writeln('</table>');
    // ------- End of left menu -------

    // ==============================================================
    document.writeln('</td>');
    document.writeln('<td height="90%" width="90%" valign="top">');
    // ==============================================================

  //------------ Message ------------
  showMessage();
  //---------------------------------

    webCounter(1);
  }
  document.writeln('<table border="0" cellpadding="5" width="100%">');
  document.writeln('<tr><td id="content" valign="top">');
}

function bottomBorder(nocopyright) {

  document.writeln('</td></tr>');
  document.writeln('</table>');

  if (showMenu()) {

    enableGoogleAdsense();
    if (studying) fixLinks();

    // ==============================================================
    document.writeln('</td></tr>');
    document.writeln('<tr><td colspan="2" width="100%" valign="bottom">');
    // ==============================================================

    // -------- Bottom border ---------
    document.writeln('<table border="0" width="100%" cellpadding="0" cellspacing="0" bgcolor="#005F81">');
    document.writeln('  <tr><td bgcolor="#000000">');
    document.writeln('    <table border="0" cellpadding="0" cellspacing="0"><tr><td width="170">&nbsp;</td>');
    document.writeln('       <td>');
    topMenu();
    document.writeln('       </td></tr>');
    document.writeln('    </table></td>');
    document.writeln('  </tr>');

    if (nocopyright == undefined) {
      document.writeln('  <tr>');
      document.writeln('    <td>');
      copyrightNotice();
      document.writeln('    </td>');
      document.writeln('  </tr>');
    }

    document.writeln('</table>');
    // ----- End of bottom border -----

    // ==============================================================
    document.writeln('</td></tr>');
    document.writeln('</table>');
    // ==============================================================
  } else {
    if (nocopyright==undefined && studying) {
      document.writeln('<table border="0" cellpadding="5" width="100%">');
      document.writeln('<tr><td><hr>');
      copyright();
      document.writeln('</td></tr>');
      document.writeln('</table></td>');
    }
  }
}

if (Location.charAt(Location.length-1) == "#") Location=Location.substring(0,Location.length-1);

// Get rid of the extra characters added by Google translation
i=Location.lastIndexOf(".htm&");
if (i>0) Location=Location.substring(0,i+4);

LanguageIndex=getDocRoot();
