var myLanguage="";
var myVerse="";
var BIG5="big5";
var GB2312="gb2312";
var EN="en";

function setMyLanguage() {
	myLanguage=EN;
	if ( document.URL.indexOf(BIG5, 0)>0 ) myLanguage=BIG5;
	else if ( document.URL.indexOf(GB2312, 0)>0 ) myLanguage=GB2312;
}

function switchLanguage(newLanguage) {
	myHRef=window.location.href;
	myHRef=myHRef.replace("/"+myLanguage+"/", "/"+newLanguage+"/");
	myHRef=myHRef.replace("\\"+myLanguage+"\\", "\\"+newLanguage+"\\");
	window.location=myHRef;
}

/*
function writeLanguageSelect() {
document.write('<table border=0 align="right"><tr>');
// only display language selector if we are using that language
if (myLanguage!=EN)  document.write('<td onMouseOver="bgColor=\'white\'" onMouseOut="bgColor=\'E6DCC7\'"><a href="javascript:switchLanguage(EN)"><img border=0 src="../img/eng.gif"></a></td>');
if (myLanguage!=BIG5)document.write('<td onMouseOver="bgColor=\'white\'" onMouseOut="bgColor=\'E6DCC7\'"><a href="javascript:switchLanguage(BIG5)"><img border=0 src="../img/big5.gif"></a></td>');
if (myLanguage!=GB2312)document.write('<td onMouseOver="bgColor=\'white\'" onMouseOut="bgColor=\'E6DCC7\'"><a href="javascript:switchLanguage(GB2312)"><img border=0 src="../img/gb.gif"></a></td>');
document.write('</tr></table>');
}
*/

function writeLanguageSelect() {
// only display language selector if we are using that language
if (myLanguage!=EN)  document.write('<a class="AA" href="javascript:switchLanguage(EN)"><img border=0 src="../img/eng.gif"></a> ');
if (myLanguage!=BIG5)document.write('<a class="AA" href="javascript:switchLanguage(BIG5)"><img border=0 src="../img/big5.gif"></a> ');
if (myLanguage!=GB2312)document.write('<a class="AA" href="javascript:switchLanguage(GB2312)"><img border=0 src="../img/gb.gif"></a> ');
}


function randomVerse(myVerses) {
 if(!myVerses) return ""
 lng=myVerses.length;
 if (lng==0) return "";
 if (lng<2) return myVerses[0];
 return myVerses[Math.round(Math.random() * (lng - 2))+1];
}

function showemail(a1, a2) {
	document.write("<a href=\"mailto:"+ a1 + "@" + a2 +"\">"+a1+"&#64;<span>"+a2+"</span></a>");
}

function myQueryString() {
 qsParms = new Array();
 query = window.location.search.substring(1);
 parms = query.split('&');
 for (i=0; i<parms.length; i++) {
  pos = parms[i].indexOf('=');
  if (pos > 0) {
   qsParms[parms[i].substring(0,pos)]=unescape(parms[i].substring(pos+1));
  }
 }
 return qsParms;
}

function myPagePath() {
 s = window.location+"";
 pos = s.indexOf("?");
 if (pos>0) s = s.substring(0,pos);
 return unescape(s);
}

function myPageFile() {
 s = myPagePath();
 pos = s.lastIndexOf("/");
 if (pos>0) s = s.substring(pos+1);
 return s;
}

function myContentUrl() {
 f = myPageFile().replace("\.html", "_content\.html");
 s =  myPagePath();
 pos = s.lastIndexOf("/");
 if (pos>0)
   s = s.substring(0,pos+1) + f;
 else
   s = f;
 return s;
}

function mySubContentUrl(subj) {
 return myContentUrl().replace("\.html", "_" + subj + "\.html");
}


function ajaxLoad(divUrl, dynDivId, fn) { 
   var xhr; 
   try {
        xhr = new ActiveXObject('Msxml2.XMLHTTP');
   }
   catch (e1) 
   {
        try {   xhr = new ActiveXObject('Microsoft.XMLHTTP');    }
        catch (e2) 
        {
          try {  xhr = new XMLHttpRequest();     }
          catch (e3) {  xhr = false;   }
        }
   }
  
   xhr.onreadystatechange  = function()
   { 
         if(xhr.readyState == 4)
         {
              if(xhr.status == 200 || xhr.status == 0) {
		 document.getElementById(dynDivId).innerHTML = xhr.responseText;
                 if (fn) {
			eval(fn);
		 }
              }
              else 
		 document.getElementById(dynDivId).innerHTML = "Error code: " + xhr.status+" <="+myContentUrl();
         }
   }; 
   xhr.open("GET", divUrl, true); 
   xhr.send(null); 
}


function includePageContent(dynDivId) {
  document.write('<div id="'+dynDivId+'"></div>');
  ajaxLoad(myContentUrl(), dynDivId);
}

function includePageContentAndRun(dynDivId, fn) {
  document.write('<div id="'+dynDivId+'"></div>');
  ajaxLoad(myContentUrl(), dynDivId, fn);
}



function printPage(divname, autoPrint, PRINT_BUTTON_TEXT)
{
    if (document.getElementById != null)
    {

        html = '<HTML>\n<HEAD>\n';

        if (document.getElementsByTagName != null)
        {
            var headTags = document.getElementsByTagName("head");
            if (headTags.length > 0) html += headTags[0].innerHTML;
        }
        
        html += '\n</HE' + 'AD>\n<BODY>\n';

        if (!autoPrint) {
          if (!PRINT_BUTTON_TEXT || PRINT_BUTTON_TEXT==null) PRINT_BUTTON_TEXT = "Print";
          html += '<div id="printbutton" style="text-align: center; padding: 3px; margin: 3px; border-bottom: 1px solid #999999;">'
           + '<input type="button" value="'+PRINT_BUTTON_TEXT+'" style="font-size:.8em;" '
           + 'onClick="document.getElementById(\'printbutton\').style.display=\'none\'; '
           + 'window.print(); '
           + 'window.close(); '
           + 'return false;"'
           + '/></div>';
        }

        printReadyElem = document.getElementById("pchdg");
        if (printReadyElem != null)
        {
            html += printReadyElem.innerHTML;
        }

        printReadyElem = document.getElementById(divname);
        
        if (printReadyElem != null)
        {
            html += printReadyElem.innerHTML;
        }
        else
        {
            alert("Could not find the printReady section in the HTML");
            return;
        }
          
        html += '\n</BO' + 'DY>\n</HT' + 'ML>';
         
        printWin = window.open("",
        "printSpecial","toolbar=no,location=no,directories=no,menubar=no,copyhistory=no,scroll=yes");
        printWin.document.open();
        printWin.document.write(html);
        printWin.document.close();
        
        if (autoPrint) printWin.print();
    }
    else
    {
        alert("Print Page feature is not supported by your browsers.");
    }
}



