/**
** SCCSID : %W% - %E%:%U%
**
**	Description	:	Generic Functions
**	Functions	:	c_Browser()
					c_QueryToken(query, token)
					c_SearchTerm(qry, opt, lang)
					c_ColLst(f)
					c_WriteForm(fname, method)
					c_SubString(str, limt)
					c_GetHistory(frame)
					c_isStaticPage(link)
					c_ChgLang(lang, dynlink)
					c_GetMsg(lang, msg)
					c_ShowHelp(link)
					c_FullScreen(link)
					c_PageInit()
					c_DrawLangBar()
					c_DrawLnk(Lnk, ImgName, ImgDft, ImgOver, nHeight, nWidth, Msg, currLang)
					c_WriteMPLnk(LnkSrc, nHeight, nWidth, hasCtrl)
					c_WriteQTLnk(LnkSrc, nHeight, nWidth, hasCtrl)
					c_WriteVCLnk(LnkSrc, nHeight, nWidth, hasCtrl)
					c_GetJsp(svc, operation)
					c_HistoryBack()

**	
** @version 	 %W% - %E%:%U%
**	
*/

//
//Public Global Functions
//

//Glabol variable for this function
var  colSum;
var KanhanServer = "sc.lcsd.gov.hk";


//To detect the browser version
function c_Browser(){
	this.ver=navigator.appVersion;
	this.dom=document.getElementById?1:0;
	this.ie=(document.all && this.dom)?1:0;
	this.ns=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie || this.ns);
	return this
}
//Initialise
var c_bw = new c_Browser()

//
//function to get a param from the query string by giving a key
// WORKS!
//
function c_QueryToken(query, token)
{
	var result;

	var value = query.split('&');
	var size = value.length;

	for(var i=0; i<size; i++)
	{
		result = value[i].split('=');
		if (result[0] == token)
		{
		/*
			var tmp = result[1].split('+');
			var s = tmp.length;
			if (s > 1)
			{
				result = "";
				for (i=0; i<s; i++)
				{
					result += tmp[i];
					if (i < s-1)
						result += " + ";
				}
				return result;
			}
			else
		*/
				return result[1];
		}
	}
	return null;
}


function c_SearchTerm(qry, opt, lang)
{
	var result = "";
	var operator = "";
	var bparta = "";
	var multi = 0;
	var tmp;
	var pos;
	var sChar;

	if (qry == null)
	{
		alert("javascript error c_SearchTearm::qry is null");
		return "";
	}
	if (opt == null)
	{
		alert("javascript error c_SearchTearm::opt is null");
		return "";
	}

	if (opt == "TERM")
	{
		//Base Search
		if (c_QueryToken(qry, "svc") == c_BasSvc)
		{
			tmp = c_QueryToken(qry, "param");
			tmp2 = c_QueryToken(qry, "stype");

			if (tmp == "title" && tmp2 == "itr")
				result += c_GetMsg(lang, "000023");
			else if (tmp == "title")
				result += c_GetMsg(lang, "000004");
			else if (tmp == "author")
				result += c_GetMsg(lang, "000005");
			else if (tmp == "subject")
				result += c_GetMsg(lang, "000006");
			else if (tmp == "content")
				result += c_GetMsg(lang, "000008");
			else
				alert("javascript error:get param error!");

			tmp = c_QueryToken(qry, "stype");

			if (tmp == "brw")
				tmp = c_GetMsg(lang, "000007") + " : ";
			else if (tmp == "fts" || tmp == "attr")
				tmp = c_GetMsg(lang, "000009") + " : ";
			else if (tmp == "rel")
				tmp = c_GetMsg(lang, "000026") + " : ";
			else
				tmp = " : ";
		}
		//Image Search
		else if (c_QueryToken(qry, "svc") == c_ImgSvc)
		{
			tmp = c_QueryToken(qry, "stype");
			if (tmp == "avg")
				tmp = c_GetMsg(lang, "000010") + " : ";
			else if (tmp == "lay")
			{
				if (c_QueryToken(qry, "doc") != null)
					tmp = c_GetMsg(lang, "000022");
				else
					tmp = c_GetMsg(lang, "000011") + " : ";
			}
			else if (tmp == "hist")
				tmp = c_GetMsg(lang, "000012") + " : ";
			else if (tmp == "txt")
				tmp = c_GetMsg(lang, "000013") + " : ";
			else
				tmp = "";
		}
		// Advance Search
		else if (c_QueryToken(qry, "svc") == c_AdvSvc)
		{
		/*
			tmp = c_QueryToken(qry, "stype");
			if (tmp == "brw")
				tmp = c_GetMsg(lang, "000024") + " : ";
			else if (tmp == "comb")
				tmp = c_GetMsg(lang, "000025") + " : ";
		*/
			tmp = "";
		}
		//Search History
		else if (c_QueryToken(qry, "svc") == null)
		{
			tmp = c_GetMsg(lang, "000021") + " : ";
		}
		else
		{
			tmp = "javascript error:c_SearchTerm() can't find 'svc' from query string";
		}

		result += tmp;
	}
	else if (opt == "TEXT")
	{
		if (c_QueryToken(qry, "svc") == c_BasSvc)
		{
			tmp = c_QueryToken(qry, "stype");

			// Parse the query string 
			if (tmp == "itr")
				tmp="";

			else if (tmp == "brw" || tmp == "attr")
			{
				tmp = c_QueryToken(qry, "schtxt").split("|");
				result = tmp[tmp.length -1];
				if(pos > 0)
				{
					tmp = tmp.substr(pos);
					result += tmp;
				}
				result = result.replace("<","&lt;");
				result = result.replace(">","&gt;");
			}
			else
			{
				result += c_QueryToken(qry, "schtxt");
				// unescape char "="
				sChar = escape("=");
				result = result.replace(sChar, "=");
				// unescape char "%"
				sChar= escape("%");
				result = result.replace(sChar, "%");
				// unescape char "&"
				sChar = escape("&");
				result = result.replace(sChar, "&");
			}

			//	added by Clement Ng to decode all URL-encoded characters on 23 Nov 2007
			result = unescape(result);

		}
		else if (c_QueryToken(qry, "svc") == c_AdvSvc)
		{
			tmp = c_QueryToken(qry, "stype");

			if (tmp == "brw") 
			{
				tmp = c_QueryToken(qry, "schtxt").split("|");
				result = tmp[tmp.length -1];

				if(pos > 0)
				{
					tmp = tmp.substr(pos);
					result += tmp;
				}
			}
			else if (tmp == "comb") 
			{
				tmp  = c_QueryToken(qry, "schtxt");
				if (tmp != "")
				{
					//result += "Part A : ";
					result += c_GetMsg(lang, "000041");
					tmp = c_QueryToken(qry, "param");
					if (tmp == "Title")
						tmp = c_GetMsg(lang, "000004");
					else if (tmp == "Catalog")
						tmp = c_GetMsg(lang, "000027");
					else if (tmp == "Content")
						tmp = c_GetMsg(lang, "000008");

					result += tmp + c_GetMsg(lang, "000009") + " : ";
					result += c_QueryToken(qry, "schtxt");

					tmpa = c_QueryToken(qry, "accy");
					tmpp = c_QueryToken(qry, "pxmy");
					tmps = c_QueryToken(qry, "synm");

					if (tmpa != "0" || tmpp != "0" || tmps != "0")
					{
						result += " ( ";	
						if (tmpa != "0")
						{
							result += c_QueryToken(qry, "accy") * 20 + "% ";
							result += c_GetMsg(lang, "000028");
						}
						if (tmpp != "0")
						{
							result += c_GetMsg(lang, "000029");
							if (tmpp == "1")
								result += c_GetMsg(lang, "000030");
							else if (tmpp == "2")
								result += c_GetMsg(lang, "000031");
							else if (tmpp == "3")
								result += c_GetMsg(lang, "000032");
						}
						if (tmps != "0")
							result += c_GetMsg(lang, "000033");
						result += ")";
					}
					bparta = 1;
				}

				tmp = c_QueryToken(qry, "ro");
				if (tmp == 1)
					operator = c_GetMsg(lang, "000039");
				else if (tmp == 0)
					operator = c_GetMsg(lang, "000040");

				tmp = c_QueryToken(qry, "k0");
				if (tmp != "00")
				{
					if (bparta == 1)
						result += "<br>" + c_GetMsg(lang, "000039") + " " ;
					//result += "Part B : ";
					result += c_GetMsg(lang, "000042");
					result += c_GetFieldId(lang, tmp);
					//result += c_QueryToken(qry, "a0");
					tmp = c_QueryToken(qry, "o0");
					if (tmp == 1)
						result += " = ";
					else if (tmp == 0)
						result += " <> ";
					result += "\"";
					result += c_QueryToken(qry, "t0");
					result += "\" ";
					multi = 1;
				}

				tmp = c_QueryToken(qry, "k1");
				if (tmp != "00")
				{
					if (multi == 1)
						result += operator;
					else if (multi == 0)
					{
						if (bparta == 1)
							result += "<br>" + c_GetMsg(lang, "000039") + " ";
						result += "Part B : ";
					}
							
					//result += c_QueryToken(qry, "a1");
					result += c_GetFieldId(lang, tmp);
					tmp = c_QueryToken(qry, "o1");
					if (tmp == 1)
						result += " = ";
					else if (tmp == 0)
						result += " <> ";
					result += "\"";
					result += c_QueryToken(qry, "t1");
					result += "\" ";
					multi = 1;
				}

				tmp = c_QueryToken(qry, "k2");
				if (tmp != "00")
				{
					if (multi == 1)
						result += operator;
					else if (multi == 0)
					{
						if (bparta == 1)
							result += "<br>" + c_GetMsg(lang, "000039") + " ";
						result += "Part B : ";
					}
							
					//result += c_QueryToken(qry, "a2");
					result += c_GetFieldId(lang, tmp);
					tmp = c_QueryToken(qry, "o2");
					if (tmp == 1)
						result += " = ";
					else if (tmp == 0)
						result += " <> ";
					result += "\"";
					result += c_QueryToken(qry, "t2");
					result += "\" ";
					multi = 1;
				}

				tmp = c_QueryToken(qry, "k3");
				if (tmp != "00")
				{
					if (multi == 1)
						result += operator;
					else if (multi == 0)
					{
						if (bparta == 1)
							result += "<br>" + c_GetMsg(lang, "000039") + " ";
						result += "Part B : ";
					}
							
					//result += c_QueryToken(qry, "a3");
					result += c_GetFieldId(lang, tmp);
					tmp = c_QueryToken(qry, "o3");
					if (tmp == 1)
						result += " = ";
					else if (tmp == 0)
						result += " <> ";
					result += "\"";
					result += c_QueryToken(qry, "t3");
					result += "\" ";
					multi = 1;
				}

				tmp = c_QueryToken(qry, "k4");
				if (tmp != "00")
				{
					if (multi == 1)
						result += operator;
					else if (multi == 0)
					{
						if (bparta == 1)
							result += "<br>" + c_GetMsg(lang, "000039") + " ";
						result += "Part B : ";
					}
							
					//result += c_QueryToken(qry, "a4");
					result += c_GetFieldId(lang, tmp);
					tmp = c_QueryToken(qry, "o4");
					if (tmp == 1)
						result += " = ";
					else if (tmp == 0)
						result += " <> ";
					result += "\"";
					result += c_QueryToken(qry, "t4");
					result += "\" ";
					multi = 1;
				}		

				tmp = c_QueryToken(qry, "k5");
				if (tmp != "00")
				{
					if (multi == 1)
						result += operator;
					else if (multi == 0)
					{
						if (bparta == 1)
							result += "<br>" + c_GetMsg(lang, "000039") + " ";
						result += "Part B : ";
					}
							
					//result += c_QueryToken(qry, "a5");
					result += c_GetFieldId(lang, tmp);
					tmp = c_QueryToken(qry, "o5");
					if (tmp == 1)
						result += " = ";
					else if (tmp == 0)
						result += " <> ";
					result += "\"";
					result += c_QueryToken(qry, "t5");
					result += "\" ";
					multi = 1;
				}

				tmp = c_QueryToken(qry, "dr");
				if (tmp != "0")
				{
					result += "<br>" + c_GetMsg(lang, "000039") + " ";
					result += c_GetMsg(lang, "000034");
					result += c_QueryToken(qry, "fy") + c_GetMsg(lang, "000035");
					tmpfm = c_QueryToken(qry, "fm");
					if (tmpfm != "")
						result += c_GetMsg(lang, "000036") + tmpfm + c_GetMsg(lang, "000037");
					result += c_GetMsg(lang, "000038");
					result += c_QueryToken(qry, "ty") + c_GetMsg(lang, "000035");
					tmptm = c_QueryToken(qry, "tm");
					if (tmptm != "")
						result += c_GetMsg(lang, "000036") + tmpfm + c_GetMsg(lang, "000037");
				}

// added by Clement in Nov 2007 for OS Update
				tmp = c_QueryToken(qry, "ao");
				if (tmp != "0")
				{
					result += "<br>" + c_GetMsg(lang, "000039") + " ";
					result += c_GetMsg(lang, "000044");
				}

				if (result != null)
					result = unescape(result);
			}
		}
		else if (c_QueryToken(qry, "svc") == c_ImgSvc)
		{
			var tmp = c_QueryToken(qry, "stype");

			if (tmp == "avg")
			{
				//Image Search Average
				result += c_GetMsg(lang, "000014") + "=" +
							 c_QueryToken(qry, "r1") + ", ";
				result += c_GetMsg(lang, "000015") + "=" +
							 c_QueryToken(qry, "g1") + ", ";
				result += c_GetMsg(lang, "000016") + "=" +
							 c_QueryToken(qry, "b1") + "<br>";
			}
			else if (tmp == "lay")
			{
				//Search by an image under hit list
				var doc = c_QueryToken(qry, "doc");

				if (doc != null)
				{
/*	<CARE Pleaes move this label to GMsg range
 *	within 000001 to 001000 and remove this command!
 * Andy
*/
//					result += "Image Seacht by Thumbnail";
//					return result;					
				}

				//Image Search Layout
				for (var i=1; i <= 5; i++)
				{
					r = c_QueryToken(qry, "r"+i);
					g = c_QueryToken(qry, "g"+i);
					b = c_QueryToken(qry, "b"+i);
					xa = c_QueryToken(qry, "xa"+i);
					ya = c_QueryToken(qry, "ya"+i);
					xb = c_QueryToken(qry, "xb"+i);
					yb = c_QueryToken(qry, "yb"+i);

					if (r != null && g != null && b != null && 
						 r != "null" && g != "null" && b != "null")
					{
						result += c_GetMsg(lang, "000017") + " " + i + ": ";
						result += c_GetMsg(lang, "000014") + " " + r + ", ";
						result += c_GetMsg(lang, "000015") + " " + g + ", ";
						result += c_GetMsg(lang, "000016") + " " + b + "; ";
						result += c_GetMsg(lang, "000018") + 
										" (" + xa + ", " + ya + "), ";
						result += c_GetMsg(lang, "000019") +
										" (" + xb + ").<br>";
					}
				}
			}
			else if (tmp == "hist")
			{
				//Image Search Histogram

				for (var i=1; i <= 5; i++)
				{
					r = c_QueryToken(qry, "r"+i);
					g = c_QueryToken(qry, "g"+i);
					b = c_QueryToken(qry, "b"+i);
					p = c_QueryToken(qry, "p"+i);

					if (r != "null" && g != "null" && b != "null")
					{
						result += c_GetMsg(lang, "000017") + " " + i + ": ";
						result += c_GetMsg(lang, "000014") + "=" + r + ", ";
						result += c_GetMsg(lang, "000015") + "=" + g + ", ";
						result += c_GetMsg(lang, "000016") + "=" + b + "; ";
						result += c_GetMsg(lang, "000020") + "=" + p + "<br>";
					}
				}

			}
			else if (tmp == "txt")
			{


			}
			else
			{}

			t = c_QueryToken(qry, "schtxt");
			
			if (t != "" && t != " ")
				result += c_GetMsg(lang, "000009") + "=" + t;

		}
		else if (c_QueryToken(qry, "svc") == null)
		{
			re = new RegExp("&", "g");
			tmp=qry.replace(re, " AND ");
			result += tmp;
		}
	}
	
	return result;
}

//
//function to add the numbers of collections which selected.
//
function c_ColLst(f)
{

	var num = 0;
	var tmp;

	colSum = 0;

	//check for the collection check boxes

	for (var i=1; i <= 64; i++)
	{
		tmp = eval("f.col" + i);
		if (tmp != null)
		{
			if (tmp.checked)
			{
				num = tmp.value;
				// combine UC/RC
				if (num == 14)
				{
					colSum += Math.pow(2, (num-1));
					colSum += Math.pow(2, (num));
				}
				else
					colSum += Math.pow(2, (num-1));
			}
		}		
	}	

	return colSum;
}


//
//function to add the numbers of collections which selected.
//
function c_WriteForm(fname, method)
{
	var result;
	var link;

	link = c_DominName + c_Service + c_DefGateWay;

	result = "<form name='" + fname + "' method='" + method + "' action='" + link + "' encoding='" + "big5" + "'>";

	return result;
}


//
//function to limite the string in a number and check the last value
//if not ... than add ...
//
function c_SubString(str, limt)
{
	var rst;
	if (str == null)
		return "";

	str = str.replace(/</g, "&lt;");

	if (str.length <= limt)
		return str;
	else
	{
		rst = str.substr(0, limt);
		
		if (rst.substr(limt-3, limt) != "...")
			rst += "...";
	}
	return rst;
}
//
//Get Search History
//
function c_GetHistory()
{
	var qry;

	qry = c_DominName + c_Service + c_DefGateWay;
	qry += "?svc=" + c_HistSvc + "&param=list&ss=" + 
			 c_SSHist + "&magicno=" + Math.random();

	return qry;
}

function c_GetHistoryForBanner(lang)
{
	var qry;

	qry = c_DominName + c_Service + c_DefGateWay;
	qry += "?svc=" + c_HistSvc + "&lang=" + lang +
           "&param=list&ss=" + c_SSHist + "&magicno=" + Math.random();

	top.mainFrame.location.href=qry;
}

// 
// Check static or dynamic
//
function c_isStaticPage(link)
{
	var dynLink='/'+c_DefGateWay;
	var t = new String(link);
	if (t.indexOf(dynLink) == -1) return true; 
	else return false;
}

//
// Change language
//
function c_ChgLang(lang, dynlink)
{
	// add magic no in dynlink for prevent cache
	// replace '&' by escape character of  '&'
	var svcLink="";
	var dyn="";
	var engLink='/'+c_EngLang+'/';
	var chtLink='/'+c_ChtLang+'/';
	var chsLink='/'+c_ChsLang+'/';
	if (lang != c_EngLang && lang != c_ChtLang && lang != c_ChsLang)
		return;

	// IMPORTANT NOTICE
	// Send change lang request to the server with a different number each
	// time. Making sure no caching occurs.

	//var ImgSrc = new Image();
	//IMPORTANT
	//apply switch language service
	//ImgSrc.src = svcLink;

	// Changing to Eng
	if (lang == c_EngLang)
	{
		if (l_CurrLang == c_ChtLang) re = new RegExp(chtLink, 'i');
		else if (l_CurrLang == c_ChsLang) re = new RegExp(chsLink, 'i');
		newLink=engLink;
	}
	// Changing to Trad. Chin
	else if (lang == c_ChtLang)
	{
		if (l_CurrLang == c_EngLang) re = new RegExp(engLink, 'i');
		else if (l_CurrLang == c_ChsLang) re = new RegExp(chsLink, 'i');
		newLink=chtLink;
	}
	// Changing to Simp. Chin
	else if (lang == c_ChsLang)
	{
		if (l_CurrLang == c_EngLang) re = new RegExp(engLink, 'i');
		else if (l_CurrLang == c_ChtLang) re = new RegExp(chtLink, 'i');
		newLink=chsLink;
	}
	svcLink=c_DominName + c_Service + c_DefGateWay +
				'?svc=' + c_SwlSvc + '&lang=' + lang; 
	if (eval("top.mainFrame") != null)
	{
		topLink = new String(top.topFrame.location);
		topLink = topLink.replace(re, newLink);
		bottomLink = new String(top.bottomFrame.location);
		bottomLink = bottomLink.replace(re, newLink);
		
		// refres to an bottom banner, only for the content booking ssl page use !
		if (topLink.match("ssl.jsp"))
		{
			if (topLink.match("internet"))
			{
				topLink = "https://hkclweb.hkpl.gov.hk/" + c_Service + "jsp/top_ban_ssl.jsp?usrType=internet&lang=" + lang;
				bottomLink = "https://hkclweb.hkpl.gov.hk/" + c_Service + "jsp/but_ban_ssl.jsp?usrType=internet&lang=" + lang;
			}
			if (topLink.match("intranet"))
			{
				topLink = "https://hkclweb.hkpl.gov.hk/" + c_Service + "jsp/top_ban_ssl.jsp?usrType=intranet&lang=" + lang;
				bottomLink = "https://hkclweb.hkpl.gov.hk/" + c_Service + "jsp/but_ban_ssl.jsp?usrType=intranet&lang=" + lang;
			}
		}

		// Refresh top and bottom banner
		top.topFrame.location=topLink;
		top.bottomFrame.location=bottomLink;

		if (c_isStaticPage(top.mainFrame.location)) // Static page
		{
			dyn = new String(top.mainFrame.location);
			dyn = dyn.replace(re, newLink);
		}
		else // dynamic page
		{
		    if(dynlink.match("bkws&op") || dynlink.match("bkls&op") || dynlink.match("svc=bkpt"))
            {
				dynlink = dynlink.replace("&op","&lang="+lang+"&op");
                dynlink = dynlink.substring(4);	
                svcLink = svcLink.substring(4);
                svcLink = "https"+svcLink;
                dyn = "https" + dynlink;
            } 
			else if (dynlink.match("asch&op"))
			{
				dyn = dynlink.replace("&op","&lang="+lang+"&op");
			}
			else if (dynlink.match("hist"))
			{
				dyn = dynlink.replace("&ss","&lang="+lang+"&ss");
			}
            else 
            {
                dyn = dynlink;
            }
			dyn = dyn + '&magicno=' + Math.random();
			dyn = dyn.replace(/&/g,escape("&"));
		}
		svcLink =  svcLink + '&doc=' + dyn + '&magicno=' + Math.random();
		top.mainFrame.location=svcLink;
	}
	else
	{
		dyn = dynlink;
		dyn = dyn.replace(/&/g,escape("&"));

		svcLink = svcLink + '&doc=' + dyn;
		top.location=svcLink;
	}
}


//
// Initialization the page
//
function c_PageInit()
{
//document.write('<img src="" name="img_chgLang" width="1" height="1" border="0"/><br>');
	return null;
}

//
// Get message output
//
function c_GetMsg(lang, msg)
{
	var str = eval('msg_'+lang+'_'+msg);
	var newMsg = ' ';

	if (str != null) 
	{
		if (msg <= '001500')
			newMsg = str;
		else
			newMsg = 'WA' + msg + ' : ' + str;
	}

	return newMsg;
}

function c_GetFieldId(lang, id)
{
	var obj = new Object();
	obj.value = new Array("02|06","03","05","01_08","01_09","06_09","02_10","01_22","03_10","02_12","00_17","01");
	obj.text = new Array("作者","主題","出版者","類型","格式","色素","登錄號碼","網址","國際標準書號","語言","類別","標題");
	obj.title = new Array("Author","Subject","Publisher","Type","Format","Colour","Accession no.","URL","ISBN","Language","Category","Title");

	if (lang == "eng")
	{
		n=0;
		while (obj.value[n] != null)
		{
			if (obj.value[n] == id)
			{
				fieldname = obj.title[n];
				break;
			}
			n++;
		}
	}
	else
	{
		n=0;
		while (obj.value[n] != null)
		{
			if (obj.value[n] == id)
			{
				fieldname = obj.text[n];
				break;
			}
			n++;
		}
	}

	return fieldname;
}

function c_ShowHelp(link)
{
	var lnk;
	var currLnk = document.URL;
	lnk = currLnk.substring(0, currLnk.lastIndexOf("/")) + "/" + link;
	var dw = window.open(lnk, 'help');
	dw.focus();
}

function c_FullScreen(link)
{
	var dw=window.open(escToken(link, 'itemid', 16), 'full');
	dw.focus();
}


/**
 *	Draw the language bar
 *	@param	currLang	The current language, usually pass l_CurrLang
 *	@param	LnkDyn	The link for refreshing dynamic pages. null if static page
 *	@param	LnkHlp	The link for showing the help page
 */
function c_DrawLangBar(currLang, LnkDyn, LnkHlp, svc)
{
	var LnkNotAvail = 'javascript:alert(c_GetMsg(l_CurrLang, \'001001\'));';
	var DocSep = '<td><img src="../../images/_.gif" width="24" height="17"/></td>';
	var uri = new String(top.frames[0].location);

  	var Intra = (uri.indexOf("intranet")!=-1)?1:0;

	var sAlt; //Added for Netscape4.76

	document.writeln('<table width="35%" border="0" cellspacing="0" cellpadding="0">');
	document.writeln('<tr>');

	c_DrawLnk(LnkHlp, 'help', 'images/help.gif', 'images/help_f2.gif', 17, 29, "000277", currLang);

	document.write(DocSep);

	if (self.location.host != KanhanServer)	// Traditional Chinese never exists for Kanhan server
	{
		if (currLang != c_ChtLang)
			if (svc == c_BasSvc)
				c_DrawLnk("../cht/html/frm-bas_srch.html", 'Image2', '../../images/T-Chin.gif', '../../images/T-Chin_f2.gif', 17, 26, "000281", currLang, '_top');
			else if (svc == c_ImgSvc)
				c_DrawLnk("../cht/html/frm-img_srch.html", 'Image2', '../../images/T-Chin.gif', '../../images/T-Chin_f2.gif', 17, 26, "000281", currLang, '_top');
			else if (svc == c_ImgSvc2)
				c_DrawLnk("../cht/html/frm-img_srch2.html", 'Image2', '../../images/T-Chin.gif', '../../images/T-Chin_f2.gif', 17, 26, "000281", currLang, '_top');
			else if (svc == c_ImgSvc3)
				c_DrawLnk("../cht/html/frm-img_srch3.html", 'Image2', '../../images/T-Chin.gif', '../../images/T-Chin_f2.gif', 17, 26, "000281", currLang, '_top');
			else if (svc == c_ImgSvc4)
				c_DrawLnk("../cht/html/frm-img_srch4.html", 'Image2', '../../images/T-Chin.gif', '../../images/T-Chin_f2.gif', 17, 26, "000281", currLang, '_top');
			else if (svc == c_ImgSvc5)
				c_DrawLnk("../cht/html/frm-img_srch5.html", 'Image2', '../../images/T-Chin.gif', '../../images/T-Chin_f2.gif', 17, 26, "000281", currLang, '_top');
			else if (svc == c_AdvSvc)
				c_DrawLnk("../cht/html/frm-adv_srch.html", 'Image2', '../../images/T-Chin.gif', '../../images/T-Chin_f2.gif', 17, 26, "000281", currLang, '_top');
			else if (svc == c_BkWsSvc)
				c_DrawLnk("../cht/html/frm-bkg_wks.html", 'Image2', '../../images/T-Chin.gif', '../../images/T-Chin_f2.gif', 17, 26, "000281", currLang, '_top');
			else if (svc == c_BkLsSvc)
				c_DrawLnk("../cht/html/frm-bkg_lst.html", 'Image2', '../../images/T-Chin.gif', '../../images/T-Chin_f2.gif', 17, 26, "000281", currLang, '_top');
			else
				c_DrawLnk("javascript:c_ChgLang(c_ChtLang, " + LnkDyn + ");", 'Image2', '../../images/T-Chin.gif', '../../images/T-Chin_f2.gif', 17, 26, "000281", currLang, null);
		else
		{
			sAlt = c_GetMsg(currLang,'000281');
			document.write('<td><img src="../../images/T-Chin_f3.gif" width="26" height="17" border="0" name="Image2" alt="' + sAlt + '" onLoad="this.alt=c_GetMsg(' + "'" + currLang + "','" + "000281" + "'" + ');"/></td>');
		}

		document.write(DocSep);
	}

	//Simplified Chinese for Intranet user and Kanhan Server only
	if (Intra || self.location.host == KanhanServer)
	{
		if (currLang != c_ChsLang)
		{
			if (svc == c_BasSvc)
				c_DrawLnk("../chs/html/frm-bas_srch.html", 'Image3', '../../images/S-Chin.gif', '../../images/S-Chin_f2.gif', 17, 26, "000282", currLang, '_top');
			else if (svc == c_ImgSvc)
				c_DrawLnk("../chs/html/frm-img_srch.html", 'Image3', '../../images/S-Chin.gif', '../../images/S-Chin_f2.gif', 17, 26, "000282", currLang, '_top');
			else if (svc == c_ImgSvc2)
				c_DrawLnk("../chs/html/frm-img_srch2.html", 'Image3', '../../images/S-Chin.gif', '../../images/S-Chin_f2.gif', 17, 26, "000282", currLang, '_top');
			else if (svc == c_ImgSvc3)
				c_DrawLnk("../chs/html/frm-img_srch3.html", 'Image3', '../../images/S-Chin.gif', '../../images/S-Chin_f2.gif', 17, 26, "000282", currLang, '_top');
			else if (svc == c_ImgSvc4)
				c_DrawLnk("../chs/html/frm-img_srch4.html", 'Image3', '../../images/S-Chin.gif', '../../images/S-Chin_f2.gif', 17, 26, "000282", currLang, '_top');
			else if (svc == c_ImgSvc5)
				c_DrawLnk("../chs/html/frm-img_srch5.html", 'Image3', '../../images/S-Chin.gif', '../../images/S-Chin_f2.gif', 17, 26, "000282", currLang, '_top');
			else if (svc == c_AdvSvc)
				c_DrawLnk("../chs/html/frm-adv_srch.html", 'Image3', '../../images/S-Chin.gif', '../../images/S-Chin_f2.gif', 17, 26, "000282", currLang, '_top');
			else if (svc == c_BkWsSvc)
				c_DrawLnk("../chs/html/frm-bkg_wks.html", 'Image3', '../../images/S-Chin.gif', '../../images/S-Chin_f2.gif', 17, 26, "000282", currLang, '_top');
			else if (svc == c_BkLsSvc)
				c_DrawLnk("../chs/html/frm-bkg_lst.html", 'Image3', '../../images/S-Chin.gif', '../../images/S-Chin_f2.gif', 17, 26, "000282", currLang, '_top');
			else
				c_DrawLnk("javascript:c_ChgLang(c_ChsLang, " + LnkDyn + ");", 'Image3', '../../images/S-Chin.gif', '../../images/S-Chin_f2.gif', 17, 26, "000282", currLang, null);
		}
		else
			document.write('<td><img src="../../images/S-Chin_f3.gif" width="26" height="17" border="0" name="Image3" onLoad="this.alt=c_GetMsg(' + "'" + currLang + "','" + "000282" + "'" + ');"/></td>');

		document.write(DocSep);
	}

	if (currLang != c_EngLang)
    {
		if (svc == c_BasSvc)
			c_DrawLnk("../eng/html/frm-bas_srch.html", 'Image4', '../../images/Eng.gif', '../../images/Eng_f2.gif', 17, 48, "000280", currLang, '_top');
		else if (svc == c_ImgSvc)
			c_DrawLnk("../eng/html/frm-img_srch.html", 'Image4', '../../images/Eng.gif', '../../images/Eng_f2.gif', 17, 48, "000280", currLang, '_top');
		else if (svc == c_ImgSvc2)
			c_DrawLnk("../eng/html/frm-img_srch2.html", 'Image4', '../../images/Eng.gif', '../../images/Eng_f2.gif', 17, 48, "000280", currLang, '_top');
		else if (svc == c_ImgSvc3)
			c_DrawLnk("../eng/html/frm-img_srch3.html", 'Image4', '../../images/Eng.gif', '../../images/Eng_f2.gif', 17, 48, "000280", currLang, '_top');
		else if (svc == c_ImgSvc4)
			c_DrawLnk("../eng/html/frm-img_srch4.html", 'Image4', '../../images/Eng.gif', '../../images/Eng_f2.gif', 17, 48, "000280", currLang, '_top');
		else if (svc == c_ImgSvc5)
			c_DrawLnk("../eng/html/frm-img_srch5.html", 'Image4', '../../images/Eng.gif', '../../images/Eng_f2.gif', 17, 48, "000280", currLang, '_top');
		else if (svc == c_AdvSvc)
			c_DrawLnk("../eng/html/frm-adv_srch.html", 'Image4', '../../images/Eng.gif', '../../images/Eng_f2.gif', 17, 48, "000280", currLang, '_top');
		else if (svc == c_BkWsSvc)
			c_DrawLnk("../eng/html/frm-bkg_wks.html", 'Image4', '../../images/Eng.gif', '../../images/Eng_f2.gif', 17, 48, "000280", currLang, '_top');
		else if (svc == c_BkLsSvc)
			c_DrawLnk("../eng/html/frm-bkg_lst.html", 'Image4', '../../images/Eng.gif', '../../images/Eng_f2.gif', 17, 48, "000280", currLang, '_top');
		else
			c_DrawLnk("javascript:c_ChgLang(c_EngLang, " + LnkDyn + ");", 'Image4', '../../images/Eng.gif', '../../images/Eng_f2.gif', 17, 48, "000280", currLang, null);
    }
	else
	{
		sAlt = c_GetMsg(currLang,'000280');
		document.write('<td><img src="../../images/Eng_f3.gif" width="48" height="17" border="0" name="Image4" alt="' + sAlt + '" onLoad="this.alt=c_GetMsg(' + "'" + currLang + "','" + "000280" + "'" + ');"/></td>');
	}

	document.write('</tr>');
	document.write('</table>');
}

/**
 *	c_DrawLnk
 *	@param	Lnk	Link to lauch when clicked
 *	@param	ImgName	Name of the Image
 *	@param	ImgDft	URL Link of the default image
 *	@param	ImgOver	URL Link of the mouse over image
 *	@param	nHeight	Height of the image
 *	@param	nWidth	Width of the image
 *	@param	Msg		Message Code
 *  @param	currLang	Current language
 */
function c_DrawLnk(Lnk, ImgName, ImgDft, ImgOver, nHeight, nWidth, Msg, currLang, target)
{
	//Added for Netscape4.76
	var sAlt = c_GetMsg(currLang,Msg);

	document.write("<td>");
	//Remarked by tony on 17.08.2001
	//document.write("<a href=\"" + Lnk + "\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('" + ImgName + "','','" + ImgOver + "',1)\"><img src=\"" + ImgDft + "\" width=\"" + nWidth + "\" height=\"" + nHeight + "\" border=\"0\" name=\"" + ImgName + "\" onLoad=\"this.alt=c_GetMsg('" + currLang + "','" + Msg + "');\"" + "/></a>");
	
	//Added for Netscape4.76
	if (target != null)
		document.write("<a href=\"" + Lnk + "\" target=\"" + target + "\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('" + ImgName + "','','" + ImgOver + "',1)\"><img src=\"" + ImgDft + "\" width=\"" + nWidth + "\" height=\"" + nHeight + "\" border=\"0\" name=\"" + ImgName + "\" alt=\"" + sAlt + "\" onLoad=\"this.alt=c_GetMsg('" + currLang + "','" + Msg + "');\"" + "/></a>");
	else
		document.write("<a href=\"" + Lnk + "\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('" + ImgName + "','','" + ImgOver + "',1)\"><img src=\"" + ImgDft + "\" width=\"" + nWidth + "\" height=\"" + nHeight + "\" border=\"0\" name=\"" + ImgName + "\" alt=\"" + sAlt + "\" onLoad=\"this.alt=c_GetMsg('" + currLang + "','" + Msg + "');\"" + "/></a>");
	document.write("</td>");
}

/**
 * write the link for lauching media player on LnkSrc
 * @param   LnkSrc   Location of the movie file
 * @param   nHeight  Height of the control
 * @param   nWidth   Width of the control
 * @param   hasCtrl  true if want to include the control interface
 */
function c_WriteMPLnk(LnkSrc, nHeight, nWidth, hasCtrl)
{
	var AutoStart = 1;
	var ShowDisplay = 0;
	var ShowStatusBar = 1;
	var ShowControls;
	var AnimationAtStart = 1;

	//var tmpLoc = 'http://hkclav.hkpl.gov.hk:8000/preview/audio/';
	var tmpLoc = 'http://hkclweb.hkpl.gov.hk:8000/preview/audio/';
// LnkSrc = 'http://www.streamingasia.com/clients/cityline/genycops.asx';
//	LnkSrc = c_VCLnkPrefix + LnkSrc + '&StreamMode=HTTP&MimeType=audio/x-mpeg';
	LnkSrc = tmpLoc + LnkSrc + '.mp3';
//	LnkSrc = tmpLoc + 'G324100.mp3';

	ShowControls = (hasCtrl) ? '1' : '0';
	document.write('<OBJECT ID="MediaPlayer" WIDTH="' + nWidth +
						'" HEIGHT="' + nHeight + '"' +
						' CLASSID="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95"' +
						' CODEBASE="http://activex.microsoft.com/activex/' +
						'controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715"' +
						' standby="Loading Microsoft Windows Media Player' +
                  ' components..."' + ' TYPE="application/x-oleobject">');
	document.write('<PARAM NAME="FileName" VALUE="' + LnkSrc + '">');
	document.write('<PARAM NAME="AutoStart" VALUE="' + AutoStart + '">');
	document.write('<PARAM NAME="ShowDisplay" VALUE="' + ShowDisplay + '">');
	document.write('<PARAM NAME="ShowStatusBar" VALUE="' + ShowStatusBar + '">');
	document.write('<PARAM NAME="ShowControls" VALUE="' + ShowControls + '">');
	document.write('<PARAM NAME="AnimationAtStart" VALUE="' + AnimationAtStart +'">');
	document.write('<EMBED Type="application/x-mplayer2"' +
						' PLUGINSPAGE=" http://www.microsoft.com/isapi/redir.dll?' +
						'prd=windows&sbp=mediaplayer&ar=Media&sba=Plugin&"' +
						' SRC="' + LnkSrc + '" NAME="MediaPlayer" WIDTH="' +
						nWidth + '" HEIGHT="' + nHeight + '"' +
						' ShowDisplay="' + ShowDisplay + '"' +
						' ShowControls="' + ShowControls + '"' +
						' ShowStatusBar="' + ShowStatusBar + '"' +
						' AnimationAtStart="' + AnimationAtStart + '"' +
						' AutoStart="' + AutoStart + '"></EMBED>');
	document.write('</OBJECT>');
}


/**
 * write the link for lauching quick time player on LnkSrc
 * @param   LnkSrc   Location of the movie file
 * @param   nHeight  Height of the control
 * @param   nWidth   Width of the control
 * @param   hasCtrl  true if want to include the control interface
 */
function c_WriteQTLnk(LnkSrc, nHeight, nWidth, hasCtrl)
{
	var sCtrl;
	var tmpLoc = 'http://hkclweb.hkpl.gov.hk:8000/preview/video/';

	sCtrl = (hasCtrl) ? 'true' : 'false';
	var Lnk =   '<EMBED '
				+  'WIDTH="' + nWidth
				+  '" CONTROLLER="' + sCtrl
				+	'" KIOSKMODE="true" '
				+  '" SRC="' + tmpLoc + LnkSrc + '.mov'
				+  '" BGCOLOR="FFFFFF" '
				+  ' HEIGHT="' + nHeight
				+  '" WIDTH="' + nWidth
				+  '" BORDER="0" '
				+  'pluginspage="http://www.apple.com/quicktime/download/indext.html"></EMBED>';
	document.writeln(Lnk);
}

/**
 * Write the embedded link for video charger player
 * @param   LnkSrc   Location of the movie file
 * @param   nHeight  Height of the control
 * @param   nWidth   Width of the control
 * @param   hasCtrl  true if want to include the control interface
 */
function c_WriteVCLnk(LnkSrc, nHeight, nWidth, hasCtrl)
{
	var sCtrl;

	sCtrl = (hasCtrl) ? 'true' : 'false';
	Lnk = '<EMBED '
		+  'SRC="' + c_VCLnkPrefix + 'videoid=' + LnkSrc
		+  '" WIDTH="' + nWidth
		+  '" HEIGHT="' + nHeight
		+  '"></EMBED>';
	document.writeln(Lnk);
}

/**
 * Write the preview link for prelisten audio
 * @param   LnkSrc   Location of the movie file
 */
function c_WriteDLMPLnk(LnkSrc)
{
	var tmpLoc = 'http://hkclweb.hkpl.gov.hk:8000/preview/audio/';
	//var tmpLoc = 'http://hkclav.hkpl.gov.hk:8000/preview/audio/';

	var Lnk	= tmpLoc + LnkSrc + '.mp3';
/*
	var mp3lnk= tmpLoc + LnkSrc + '.mp3';
	var movlnk = 'http://hkclweb.hkpl.gov.hk/preview/video/V49145.mov';
	Lnk = '<EMBED SRC="' + movlnk + 
			'" QTSRC="' + mp3lnk + 
			'" WIDTH="150" HEIGHT="20"></EMBED>';
*/
	//document.writeln(Lnk);
	return (Lnk);
}

/**
 * Write the download link for preview video
 * @param   LnkSrc   Location of the movie file
 */
function c_WriteDLQTLnk(LnkSrc)
{
	var tmpLoc = 'http://hkclweb.hkpl.gov.hk:8000/preview/video/';

	Lnk = tmpLoc + LnkSrc + '.mov';
	return (Lnk);
}

function c_GetJsp(svc, operation, param)
{
	var qryStr;

	if (param != null)
	{
		qryStr = c_DominName + c_Service + c_DefGateWay + "?" + 
					"svc=" + svc + "&op=" + operation + param +  
					"&magicno=" + Math.random(); 
	}
	else
	{
		qryStr = c_DominName + c_Service + c_DefGateWay + "?" + 
					"svc=" + svc + "&op=" + operation + 
					"&magicno=" + Math.random(); 
	}

	if (svc==c_AdvSvc)
	{
		parent.mainFrame.location.href = qryStr;
	}
	else
	// self.location.href = qryStr;
		return qryStr;
}

/**
 *	Draw the language bar for JSP 
 *	@param	currUsrType	The current user type,(i.e.intranet,internet)
 *	@param	currLang	The current language, usually pass l_CurrLang
 *	@param	LnkDyn	The link for refreshing dynamic pages. null if static page
 *	@param	LnkHlp	The link for showing the help page
 */
function c_DrawJspLangBar(currUsrType, currLang, LnkDyn, LnkHlp, svc)
{
	pathname = this.location.pathname;

	var LnkNotAvail = 'javascript:alert(c_GetMsg(l_CurrLang, \'001001\'));';
	var uri = new String(top.frames[0].location);
  	var Intra = (uri.indexOf("intranet")!=-1)?1:0;

	var DocSep;
	if (pathname.indexOf("jsp") >= 0)
		DocSep = '<td><img src="../images/_.gif" width="24" height="17"/></td>';
	else
		DocSep = '<td><img src="images/_.gif" width="24" height="17"/></td>';

	var sAlt; //Netscape4.76
	
	document.writeln('<table width="35%" border="0" cellspacing="0" cellpadding="0">');
	document.writeln('<tr>');

	if (pathname.indexOf("jsp") >= 0)
		c_DrawLnk(LnkHlp, 'help', '../' + currUsrType + '/' + currLang + '/images/help.gif', '../' + currUsrType + '/' + currLang + '/images/help_f2.gif', 17, 29, "000277", currLang);
	else
		c_DrawLnk(LnkHlp, 'help', currUsrType + '/' + currLang + '/images/help.gif', currUsrType + '/' + currLang + '/images/help_f2.gif', 17, 29, "000277", currLang);

	document.write(DocSep);
	
	if (self.location.host != KanhanServer)	// Traditional Chinese never exists for Kanhan server
	{
		if (currLang != c_ChtLang)
		{
			if (svc == c_AdvSvc)
				if (pathname.indexOf("jsp") >= 0)
					c_DrawLnk('../'+currUsrType+'/cht/html/frm-adv_srch.html', 'Image2', '../images/T-Chin.gif', '../images/T-Chin_f2.gif', 17, 26, "000281", currLang, '_top');
				else
					c_DrawLnk('../'+currUsrType+'/cht/html/frm-adv_srch.html', 'Image2', 'images/T-Chin.gif', 'images/T-Chin_f2.gif', 17, 26, "000281", currLang, '_top');
			else if (svc == c_BkWsSvc)
				if (pathname.indexOf("jsp") >= 0)
					c_DrawLnk(currUsrType+'/cht/html/frm-bkg_wks.html', 'Image2', '../images/T-Chin.gif', '../images/T-Chin_f2.gif', 17, 26, "000281", currLang, '_top');
				else
					c_DrawLnk(currUsrType+'/cht/html/frm-bkg_wks.html', 'Image2', 'images/T-Chin.gif', 'images/T-Chin_f2.gif', 17, 26, "000281", currLang, '_top');
			else if (svc == c_BkLsSvc)
				if (pathname.indexOf("jsp") >= 0)
					c_DrawLnk(currUsrType+'/cht/html/frm-bkg_lst.html', 'Image2', '../images/T-Chin.gif', '../images/T-Chin_f2.gif', 17, 26, "000281", currLang, '_top');
				else
					c_DrawLnk(currUsrType+'/cht/html/frm-bkg_lst.html', 'Image2', 'images/T-Chin.gif', 'images/T-Chin_f2.gif', 17, 26, "000281", currLang, '_top');
			else
				if (pathname.indexOf("jsp") >= 0)
					c_DrawLnk("javascript:c_ChgLang(c_ChtLang, " + LnkDyn + ");", 'Image2', '../images/T-Chin.gif', '../images/T-Chin_f2.gif', 17, 26, "000281", currLang, null);
				else
					c_DrawLnk("javascript:c_ChgLang(c_ChtLang, " + LnkDyn + ");", 'Image2', 'images/T-Chin.gif', 'images/T-Chin_f2.gif', 17, 26, "000281", currLang, null);
		}
		else
		{
			sAlt = c_GetMsg(currLang,'000281');

			if (pathname.indexOf("jsp") >= 0)
				document.write('<td><img src="../images/T-Chin_f3.gif" width="26" height="17" border="0" name="Image2" alt="' + sAlt + '" onLoad="this.alt=c_GetMsg(' + "'" + currLang + "','" + "000281" + "'" + ');"/></td>');
			else
				document.write('<td><img src="images/T-Chin_f3.gif" width="26" height="17" border="0" name="Image2" alt="' + sAlt + '" onLoad="this.alt=c_GetMsg(' + "'" + currLang + "','" + "000281" + "'" + ');"/></td>');
		}

		document.write(DocSep);
	}

	//Simplified Chinese for Intranet and Kanhan user only
	if (Intra || self.location.host == KanhanServer)
	{
		if (currLang != c_ChsLang)
		{
			if (svc == c_AdvSvc)
				if (pathname.indexOf("jsp") >= 0)
					c_DrawLnk('../'+currUsrType+'/chs/html/frm-adv_srch.html', 'Image3', '../images/S-Chin.gif', '../images/S-Chin_f2.gif', 17, 26, "000282", currLang, '_top');
				else
					c_DrawLnk('../'+currUsrType+'/chs/html/frm-adv_srch.html', 'Image3', 'images/S-Chin.gif', 'images/S-Chin_f2.gif', 17, 26, "000282", currLang, '_top');
			else if (svc == c_BkWsSvc)
				if (pathname.indexOf("jsp") >= 0)
					c_DrawLnk(currUsrType+'/chs/html/frm-bkg_wks.html', 'Image3', '../images/S-Chin.gif', '../images/S-Chin_f2.gif', 17, 26, "000282", currLang, '_top');
				else
					c_DrawLnk(currUsrType+'/chs/html/frm-bkg_wks.html', 'Image3', 'images/S-Chin.gif', 'images/S-Chin_f2.gif', 17, 26, "000282", currLang, '_top');
			else if (svc == c_BkLsSvc)
				if (pathname.indexOf("jsp") >= 0)
					c_DrawLnk(currUsrType+'/chs/html/frm-bkg_lst.html', 'Image3', '../images/S-Chin.gif', '../images/S-Chin_f2.gif', 17, 26, "000282", currLang, '_top');
				else
					c_DrawLnk(currUsrType+'/chs/html/frm-bkg_lst.html', 'Image3', 'images/S-Chin.gif', 'images/S-Chin_f2.gif', 17, 26, "000282", currLang, '_top');
			else
				if (pathname.indexOf("jsp") >= 0)
					c_DrawLnk("javascript:c_ChgLang(c_ChsLang, " + LnkDyn + ");", 'Image3', '../images/S-Chin.gif', '../images/S-Chin_f2.gif', 17, 26, "000282", currLang, null);
				else
					c_DrawLnk("javascript:c_ChgLang(c_ChsLang, " + LnkDyn + ");", 'Image3', 'images/S-Chin.gif', 'images/S-Chin_f2.gif', 17, 26, "000282", currLang, null);
		}
		else
		{
			if (pathname.indexOf("jsp") >= 0)
				document.write('<td><img src="../images/S-Chin_f3.gif" width="26" height="17" border="0" name="Image3" onLoad="this.alt=c_GetMsg(' + "'" + currLang + "','" + "000282" + "'" + ');"/></td>');
			else
				document.write('<td><img src="images/S-Chin_f3.gif" width="26" height="17" border="0" name="Image3" onLoad="this.alt=c_GetMsg(' + "'" + currLang + "','" + "000282" + "'" + ');"/></td>');
		}
		document.write(DocSep);
	}
	
	if (currLang != c_EngLang)
	{
		if (svc == c_AdvSvc)
			if (pathname.indexOf("jsp") >= 0)
				c_DrawLnk('../'+currUsrType+'/eng/html/frm-adv_srch.html', 'Image4', '../images/Eng.gif', '../images/Eng_f2.gif', 17, 48, "000280", currLang, '_top');
			else
				c_DrawLnk('../'+currUsrType+'/eng/html/frm-adv_srch.html', 'Image4', 'images/Eng.gif', 'images/Eng_f2.gif', 17, 48, "000280", currLang, '_top');
		else if (svc == c_BkWsSvc)
			if (pathname.indexOf("jsp") >= 0)
				c_DrawLnk(currUsrType+'/eng/html/frm-bkg_wks.html', 'Image4', '../images/Eng.gif', '../images/Eng_f2.gif', 17, 48, "000280", currLang, '_top');
			else
				c_DrawLnk(currUsrType+'/eng/html/frm-bkg_wks.html', 'Image4', 'images/Eng.gif', 'images/Eng_f2.gif', 17, 48, "000280", currLang, '_top');
		else if (svc == c_BkLsSvc)
			if (pathname.indexOf("jsp") >= 0)
				c_DrawLnk(currUsrType+'/eng/html/frm-bkg_lst.html', 'Image4', '../images/Eng.gif', '../images/Eng_f2.gif', 17, 48, "000280", currLang, '_top');
			else
				c_DrawLnk(currUsrType+'/eng/html/frm-bkg_lst.html', 'Image4', 'images/Eng.gif', 'images/Eng_f2.gif', 17, 48, "000280", currLang, '_top');
		else
			if (pathname.indexOf("jsp") >= 0)
				c_DrawLnk("javascript:c_ChgLang(c_EngLang, " + LnkDyn + ");", 'Image4', '../images/Eng.gif', '../images/Eng_f2.gif', 17, 48, "000280", currLang, null);
			else
				c_DrawLnk("javascript:c_ChgLang(c_EngLang, " + LnkDyn + ");", 'Image4', 'images/Eng.gif', 'images/Eng_f2.gif', 17, 48, "000280", currLang, null);
	}
	else
	{
		//Remarked by tony
		//document.write('<td><img src="../images/Eng_f3.gif" width="48" height="17" border="0" name="Image4" onLoad="this.alt=c_GetMsg(' + "'" + currLang + "','" + "000280" + "'" + ');"/></td>');
		
		//Netscape4.76
		sAlt = c_GetMsg(currLang,'000280');

		if(pathname.indexOf("jsp") >= 0)
			document.write('<td><img src="../images/Eng_f3.gif" width="48" height="17" border="0" name="Image4" alt="' + sAlt + '" onLoad="this.alt=c_GetMsg(' + "'" + currLang + "','" + "000280" + "'" + ');"/></td>');
		else
			document.write('<td><img src="images/Eng_f3.gif" width="48" height="17" border="0" name="Image4" alt="' + sAlt + '" onLoad="this.alt=c_GetMsg(' + "'" + currLang + "','" + "000280" + "'" + ');"/></td>');
	}

	document.write('</tr>');
	document.write('</table>');
}

function c_DrawImg(img, width, height, name, currLang, msg)
{
	var sAlt = "";
// fixed by Clement 21 Nov 2007
//	if (checkIsDigit(msg))
	if (msg.length > 0 && checkIsDigit(msg))
		sAlt = c_GetMsg(currLang,msg);
	else
		sAlt = msg;

	document.write('<img src="' + img + '" ');
	if (width != '')
		document.write('width="' + width + '" ');
	if (height != '')
		document.write('height="' + height + '" ');
	document.write('border="0" name="' + name + '" ');
	document.write('alt="' + sAlt + '">');
}

function checkIsDigit(num) 
{
	var digit = "1234567890";
	var i=0;
	var isdigitflag = 1;

	for (i=0; i<num.length; i++)
	{
		if (digit.indexOf(num.charAt(i)) == -1) 
			isdigitflag = 0;
	}

	if (isdigitflag == 1) 
		return true;
	else
		return false;
}

function c_HistoryBack() 
{
	if (document.referrer.indexOf('welcome.html') > -1)
		return parent.history.back();
	else
		return self.history.back();
}

/**
 *	Bookmark input page 
 *	@param	lang	The current language.
 *	@param	page	The current page.
 */
function c_Bookmark(lang, page)
{
    var sURL, sTitle;

    if (lang == c_EngLang)
	{
        if (page == c_BasSvc)
		{
            sURL = c_DominName + c_Service + "internet/eng/html/frm-bas_srch.html";
			sTitle = "Basic Search";
		}
        if (page == c_AdvSvc)
        {
            sURL = c_DominName + c_Service + "internet/eng/html/frm-adv_srch.html";
			sTitle = "Advanced Search";
		}
        if (page == c_ImgSvc)
        {
            sURL = c_DominName + c_Service + "internet/eng/html/frm-img_srch.html";
			sTitle = "Image Search";
		}
        if (page == c_BkWsSvc)
		{
            sURL = "https://hkclweb.hkpl.gov.hk/" + c_Service + "internet/eng/html/frm-bkg_wks.html";
			sTitle = "Workstation Booking";
		}
        if (page == c_BkLsSvc)
		{
            sURL = "https://hkclweb.hkpl.gov.hk/" + c_Service + "internet/eng/html/frm-bkg_lst.html";
			sTitle = "Booking List";
		}
    }
    if (lang == c_ChtLang)
    {
        if (page == c_BasSvc)
        {
            sURL = c_DominName + c_Service + "internet/cht/html/frm-bas_srch.html";
            sTitle = "基本檢索";
        }
        if (page == c_AdvSvc)
        {
            sURL = c_DominName + c_Service + "internet/cht/html/frm-adv_srch.html";
	        sTitle = "進階檢索";
        }
        if (page == c_ImgSvc)
        {
            sURL = c_DominName + c_Service + "internet/cht/html/frm-img_srch.html";
            sTitle = "圖像檢索";
        }
        if (page == c_BkWsSvc)
        {
            sURL = "https://hkclweb.hkpl.gov.hk/" + c_Service + "internet/cht/html/frm-bkg_wks.html";
            sTitle = "預約工作站";
        }
        if (page == c_BkLsSvc)
        {
            sURL = "https://hkclweb.hkpl.gov.hk/" + c_Service + "internet/cht/html/frm-bkg_lst.html";
            sTitle = "預約表";
        }
    }
    if (lang == c_ChsLang)
    {
        if (page == c_BasSvc)
        {
            sURL = "http://" + c_KanHan + "gb/hkclweb.hkpl.gov.hk/" + c_Service + "internet/chs/html/frm-bas_srch.html";
            sTitle = "基本檢索";
        }
        if (page == c_AdvSvc)
        {
            sURL = "http://" + c_KanHan + "gb/hkclweb.hkpl.gov.hk/" + c_Service + "internet/chs/html/frm-adv_srch.html";
            sTitle = "進階檢索";
        }
        if (page == c_ImgSvc)
        {
            sURL = "http://" + c_KanHan + "gb/hkclweb.hkpl.gov.hk/" + c_Service + "internet/chs/html/frm-img_srch.html";
            sTitle = "圖像檢索";
        }
        if (page == c_BkWsSvc)
        {
            sURL = "https://" + c_KanHan + "gb/hkclweb.hkpl.gov.hk/" + c_Service + "internet/chs/html/frm-bkg_wks.html";
            sTitle = "預約工作站";
        }
        if (page == c_BkLsSvc)
        {
            sURL = "https://" + c_KanHan + "gb/hkclweb.hkpl.gov.hk/" + c_Service + "internet/chs/html/frm-bkg_lst.html";
            sTitle = "預約表";
        }
    }
    window.external.AddFavorite(sURL, sTitle);
}

function c_DrawBookmark(lang, page)
{
    var temp;
	document.write('&nbsp;');

//    if (navigator.appName == "Netscape")
//    {
//        temp = "<a href=javascript:alert(msg_eng_000298); onMouseOut=MM_swapImgRestore(); onMouseOver=MM_swapImage('button-bookmark','','images/button-bookmark_net_f2.gif',1); onMouseDown=MM_swapImage('button-bookmark','','images/button-bookmark_net_f3.gif',1); onMouseUp=MM_swapImgRestore();>";
//
//        document.write(temp);
//        c_DrawImg('images/button-bookmark_net.gif', '', '29', 'button-bookmark', l_CurrLang, '000296');
//        document.write('</a>');
//    }
//    else
//    {
//        temp = "<a href=javascript:c_Bookmark('"+lang+"','"+page+"'); onMouseOut=MM_swapImgRestore(); onMouseOver=MM_swapImage('button-bookmark','','images/button-bookmark_ie_f2.gif',1); onMouseDown=MM_swapImage('button-bookmark','','images/button-bookmark_ie_f3.gif',1); onMouseUp=MM_swapImgRestore();>";
//
//        document.write(temp);
//        c_DrawImg('images/button-bookmark_ie.gif', '', '29', 'button-bookmark', l_CurrLang, '000297');
//        document.write('</a>');
//    }
}

function c_kanhan()
{
	if(location.href.toString().search('/gb/')!=-1)
	{
		movie.SetVariable("lang2",lang2);
	}
	else 
	{
		movie.SetVariable("lang2",lang4);
	}
}
//function c_kanhan(){
//	if(location.href.toString().search('/gb/')!=-1){
//		movie.SetVariable("lang2",lang2)
//	}else {
//		movie.SetVariable("lang2",lang4);
//	};
//}


function c_GetHistoryForBanner_ssl(lang,InOutNet)
{
	var qry;
	https_DominName = "http://hkclweb.hkpl.gov.hk/";
	qry = https_DominName + c_Service + c_DefGateWay;

	qry += "&svc=" + c_HistSvc + "&lang=" + lang +
		   "&param=list&ss=" + c_SSHist + "&magicno=" + Math.random();
	if(InOutNet =="internet"){
	if(lang == "cht"){
	parent.location = c_DominName + c_Service + "internet/cht/html/frm1.jsp"+"?DName=" + qry;
	}
	if(lang == "eng"){
	parent.location = c_DominName + c_Service + "internet/eng/html/frm1.jsp"+"?DName=" + qry;
	}
	if((lang == "chs") || (self.location.host == KanhanServer)) {
	parent.location = "http://" + c_KanHan + "gb/hkclweb.hkpl.gov.hk/" + c_Service + "internet/chs/html/frm1.jsp"+"?DName=" + qry;
	}	
	}
	if(InOutNet =="intranet"){
	if(lang == "cht"){
	parent.location = c_DominName + c_Service + "intranet/cht/html/frm1.jsp"+"?DName=" + qry;
	}
	if(lang == "eng"){
	parent.location = c_DominName + c_Service + "intranet/eng/html/frm1.jsp"+"?DName=" + qry;
	}
	if(lang == "chs"){
	parent.location = c_DominName + c_Service + "intranet/chs/html/frm1.jsp"+"?DName=" + qry;
	}
	}
}

// function added by Foung to facilitate
// passing parameters by html
function c_ParseLocation(queryStr) {

	if(queryStr == null || queryStr.length == 0)
	{
		query = window.location.search.substring(1);
	}
	else
	{
		query = queryStr;
	}

	var parmAry = new Array();
	var parms = query.split('&');

	for (var i=0; i<parms.length; i++) {
		var pos = parms[i].indexOf('=');
		if (pos > 0)
		{
			var key = parms[i].substring(0,pos);
			var val = parms[i].substring(pos+1);
			parmAry[key] = val;
		}
	}

	return parmAry;
}


function c_Dec2Bin(dec)
{
	var chr="1234567890";
	count=0;
	var ex;
	var h;var hasil=0;
	for(i=0;i<dec.length;i++)
	{ 
		ex=dec.charAt(i);
		for(f=0;f<10;f++)
		{
			h=chr.charAt(f);
			if(h==ex)
			{
				hasil=hasil+1;
			}
		}
	}

	return bnr(dec);
}

function bnr(dec)
{
	var i=dec;
	var hit="";
	while(i >= 1)
	{
		var m=(i*10)/4;
		while(m > 1){m=m-5;};
		if(m < 0)
		{
			i=(i-1)/2;hit+="1";
		}
		else
		{
			i=i/2;hit+="0";
		}
	}

	var b ="";
	var col = "";
	var bin;
	bin=hit.length;

	for(a=hit.length;a>=0;a--)
	{
		b += hit.substring(a-1,a);
		if (hit.substring(a-1,a)==1)
			col += a +",";
	}
	if (col.length != 0)
		col=col.substring(0, col.length-1);

	return col;
} 

// Extract the search text by eliminating
// the browse subject/title/author appended
// after the last delimiter '|'
function c_extractSchTxt(schtxt)
{
	var value = schtxt.split('|');
	var size = value.length;
	var newschtxt = "";

	if(size == 0)
	{
		newschtxt = schtxt;
	}

	for(var i = 0; i < size; i++)
	{
		if(i == size - 1)
			break;

		newschtxt += value[i];
	}

	return newschtxt;
}

// Remove leading articles ("a", "an" and "the")
function c_trimArticles(schtxt, isBSch)
{
	// remove double quote from input string
	schtxt = schtxt.replace(/\"/g, "");
/*
	// trim multiple articles
	var reLeadingArticle = new RegExp("^\\s*((a|an|the)\\s+)+", "i");
	var reArticleOnly = new RegExp("^\\s*((a|an|the)\\s+)*(a|an|the)\\s*$", "i");
*/

	// trim leading articles
	var reLeadingArticle = new RegExp("^\\s*(a|an|the)\\s+", "i");
	var reArticleOnly = new RegExp("^\\s*(a|an|the)\\s*$", "i");
  	var m = reLeadingArticle.exec(schtxt);
  	if (reArticleOnly.exec(schtxt) != null)
  	{
//		alert("a, an ,the only");
	}
	else if (m != null)
	{
		schtxt = schtxt.substr(m[0].length);

		if (isBSch)
		{
			var reLeadingOperator = new RegExp("^.*(and|or|not|\\+|-).*", "i");
			if (reLeadingOperator.exec(schtxt) != null)
				schtxt = "\"" + schtxt + "\"";
		}
	}
	else 
	{
		var reLeadingOperator = new RegExp("^.*(and|or|not|\\+|-).*", "i");
		if (reLeadingOperator.exec(schtxt) != null)
			schtxt = "\"" + schtxt + "\"";
  	}

  	return schtxt;
}


function c_showHelpTextWindow(doc, name, width, height)
{
	var documentURL = document.URL;
	var helpURL = documentURL.substring(0, documentURL.lastIndexOf("/")) + "/" + doc;

	var helpWin = window.open(helpURL, name, navigator.appVersion.indexOf(" MSIE 5.5; ") == -1 ? "height=" + height + ", width=" + width + ", top=" + ((screen.height-height)/2) + ", left=" + ((screen.width-width)/2) + ", toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no" : "");
	if (helpWin == null)
	{
		return; 
	}
	helpWin.focus();	
}
