function parseStringInsideQuotes(inString) {
	var outString = "";
	var testChar;

	for (var i = 0; i < inString.length; i++) {
		testChar = inString.charAt(i);

		if (testChar == "\\")
			outString += "\\\\";
		else if (testChar == "\"")
			outString += "\\\"";
		else if (testChar == "'")
			outString += "\\'";
		else
			outString += testChar;
	}

	return outString;
}

function windowOpen(inURL) {
	var gotoURL = "/eng/misc/mi_redi_page.jsp?oldURL=" + escape(parseStringInsideQuotes(inURL));
	var wndGoto = window.open(gotoURL, "wndNameGoto", "status,titlebar,width=500,height=325,hotkeys=0");
	if (wndGoto != null)
		wndGoto.focus();
}

function gotoExtURL(inURL) {
	var gotoURL = inURL;
	var wndGoto = window.open(gotoURL, "wndNameGoto");
	if (wndGoto != null)
		wndGoto.focus();
}

function goSection() {
  var temp = document.top_nav.section_name.options[document.top_nav.section_name.selectedIndex].value;
  if (temp != "") {
    location = temp;
  }
}

function click_next() {
  location = next_url;
}

function click_back() {
  location = back_url;
}

function dtextOn(imgNum) {
  if (document.images && isLoaded) {
    document["dtext"].src = "/jpn/images/top_0" + imgNum + "_word.gif";
  }
}

function dtextOff() {
  if (document.images && isLoaded) {
    document["dtext"].src = "/jpn/images/top_spacer.gif";
  }
}

function arrowOn(arType,arPos) {
  if (document.images && isLoaded) {
    document["arrow"].src = "/jpn/images/ar_" + arType + "_" + arPos + "_ov.gif";
    document["artxt_" + arPos].src = "/jpn/images/artxt_" + arPos + "_ov.gif";
  }
}

function arrowOff(arType,arPos) {
  if (document.images && isLoaded) {
    document["arrow"].src = "/jpn/images/ar_" + arType + ".gif";
    document["artxt_" + arPos].src = "/jpn/images/artxt_" + arPos + ".gif";
  }
}

// temperpory for chinese e-zine
function chi_arrowOn(arType,arPos) {
  if (document.images && isLoaded) {
    document["chi_arrow"].src = "/jpn/images/chi_ar_" + arType + "_" + arPos + "_ov.gif";
    document["chi_artxt_" + arPos].src = "/jpn/images/chi_artxt_" + arPos + "_ov.gif";
  }
}

// temperpory for chinese e-zine
function chi_arrowOff(arType,arPos) {
  if (document.images && isLoaded) {
    document["chi_arrow"].src = "/jpn/images/chi_ar_" + arType + ".gif";
    document["chi_artxt_" + arPos].src = "/jpn/images/chi_artxt_" + arPos + ".gif";
  }
}

function changePage(obj) {
  i = obj.pageName.selectedIndex;
  val = obj.pageName.options[i].value;
  if (val != "" && val != "#") {
    parent.location = '' + val + '.jhtml';
  }
}

function changePageJSP(obj) {
  i = obj.pageName.selectedIndex;
  val = obj.pageName.options[i].value;
  if (val != "" && val != "#") {
    parent.location = val;
  }
}

function imgOn(imgname) {
  if (document.images && isLoaded) {
    barOff();
    var src = document[imgname].src;
    var mode = src.lastIndexOf("_off");
	if (mode == -1) mode = src.lastIndexOf("_on");
    if (mode != -1)
      document[imgname].src = src.substring(0,mode) + "_roll.gif";
  }
}

function imgOff(imgname) {
  if (document.images && isLoaded) {
    var src = document[imgname].src;
    var mode = src.lastIndexOf("_on");
    if (mode == -1) mode = src.lastIndexOf("_roll");
    if (mode != -1)
      document[imgname].src = src.substring(0,mode) + "_off.gif";
  }
}

function imgStayOn(imgname) {
  if (document.images && isLoaded) {
    var src = document[imgname].src;
    var mode = src.lastIndexOf("_off");
    if (mode == -1) mode = src.lastIndexOf("_roll");
    if (mode != -1)
      document[imgname].src = src.substring(0,mode) + "_on.gif";
  }
}

function barOn() {
  if (isLoaded && isMenu) {
    block1.visibility = hide;
    block2.visibility = show;
  }
}

function barOff() {
  if (isLoaded && isMenu) {
    block1.visibility = show;
    block2.visibility = hide;
  }
}

rnd.today=new Date();
rnd.seed=rnd.today.getTime();

function rnd() {
  rnd.seed = (rnd.seed*9301+49297) % 233280;
  return rnd.seed/(233280.0);
}

function rand(number) {
  return Math.ceil(rnd()*number);
}

function gotoPrint()
{
  if (isLoaded) {
	document.printTest.printURL.value="http://" + location.host+location.pathname;
    msgWin = window.open("/printFunction/generatePrint2.html","printWindowOpener","HEIGHT=600,WIDTH=600,status=yes,toolbar=yes,directories=yes,menubar=yes,location=no,scrollbars=yes");
    if (!msgWin.opener) msgWin.opener = self;  
	setTimeout("msgWin.focus()",500);
  }
}

function GetCookie (name) {
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;
   while (i < clen) {
      var j = i + alen;
      if (document.cookie.substring(i, j) == arg)
         return getCookieVal (j);
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0) break; 
   }
   return null;
}

function getCookieVal (offset) {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1)
      endstr = document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
}

function SetCookie (name, value) {
   var argv = SetCookie.arguments;
   var argc = SetCookie.arguments.length;
   var expires = (argc > 2) ? argv[2] : null;
   var path = (argc > 3) ? argv[3] : null;
   var domain = (argc > 4) ? argv[4] : null;
   var secure = (argc > 5) ? argv[5] : false;
   document.cookie = name + "=" + escape (value) +
        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
        ((path == null) ? "" : ("; path=" + path)) +
        ((domain == null) ? "" : ("; domain=" + domain)) +
        ((secure == true) ? "; secure" : "");
}

function go2Home() {
	var cookCountry = GetCookie('HKTA_country');
	if (cookCountry == null) { cookCountry = ""; }
  var catsReady = new Array("international","usa");
  var readyFlag = 0;
  for (i=0; i<catsReady.length; i++) {
    if (cookCountry == catsReady[i]) { readyFlag = 1; }
  }
	/*if (cookCountry != "") {
	  if (readyFlag == 1) {
		  if (cookCountry == "international") {
		    window.open("/eng/index.jsp", "_self");
		  } else {
		    window.open("/" + cookCountry, "_self");
		  }
	  } else {
	    window.open("http://www.hkta.org/" + cookCountry, "_self");
	  }
	} else {
	  window.open("/eng/index.jsp", "_self");
	}*/
	window.open("/jpn/index.jsp", "_self");
}

function webcam_quickaccess()
{
	popwebcam=window.open('/eng/popup/webcam/pu_webc_indx.jsp?pic=0', 'PopUp3', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=176,height=218');
	if (!popwebcam.opener) popwebcam.opener = self;
	setTimeout("popwebcam.focus()",500);
}

