/**
** 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)

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

//
//Public Global Functions
//

//Glabol variable for this function
var  colSum;

//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)
						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") + " : ";
		}
		//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;
				}
			}
			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, "&");
			}
		}
		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 += "PartA Search Key : ";
					result += c_QueryToken(qry, "schtxt");
					bparta = 1;
				}

				tmp = c_QueryToken(qry, "ro");
				if (tmp == 1)
					operator = " and ";
				else if (tmp == 0)
					operator = " or " ;

				tmp = c_QueryToken(qry, "k0");
				if (tmp != "00")
				{
					if (bparta == 1)
						result += " ; ";
					result += "PartB Search Attribute : ";
					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 += " ; ";
						result += "PartB Search Attribute : ";
					}
							
					result += c_QueryToken(qry, "a1");
					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 += " ; ";
						result += "PartB Search Attribute : ";
					}
							
					result += c_QueryToken(qry, "a2");
					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 += " ; ";
						result += "PartB Search Attribute : ";
					}
							
					result += c_QueryToken(qry, "a3");
					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 += " ; ";
						result += "PartB Search Attribute : ";
					}
							
					result += c_QueryToken(qry, "a4");
					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 += " ; ";
						result += "PartB Search Attribute : ";
					}
							
					result += c_QueryToken(qry, "a5");
					tmp = c_QueryToken(qry, "o5");
					if (tmp == 1)
						result += " = ";
					else if (tmp == 0)
						result += " <> ";
					result += "\"";
					result += c_QueryToken(qry, "t5");
					result += "\" ";
					multi = 1;
				}

				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;
				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 "";

	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;
	//frame.location.href = qry;
}

function c_GetHistoryForBanner()
{
	var qry;

	qry = c_DominName + c_Service + c_DefGateWay;

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

	parent.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);

		// 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
		{
			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 <= '001000')
			newMsg = str;
		else
			newMsg = 'WA' + msg + ' : ' + str;
	}

	return newMsg;
}

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)
{
	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 (currLang != c_ChtLang)
		c_DrawLnk("javascript:c_ChgLang(c_ChtLang, " + LnkDyn + ");", 'Image2', '../../images/T-Chin.gif', '../../images/T-Chin_f2.gif', 17, 26, "000281", currLang);
	else
	{
		//Remarked by tony
		//document.write('<td><img src="../../images/T-Chin_f3.gif" width="26" height="17" border="0" name="Image2" onLoad="this.alt=c_GetMsg(' + "'" + currLang + "','" + "000281" + "'" + ');"/></td>');

		//Netscape4.76
		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 only
	if (Intra)
	{
		if (currLang != c_ChsLang)
		{
			c_DrawLnk("javascript:c_ChgLang(c_ChsLang, " + LnkDyn + ");", 'Image3', '../../images/S-Chin.gif', '../../images/S-Chin_f2.gif', 17, 26, "000282", currLang);
		}
		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)
		c_DrawLnk("javascript:c_ChgLang(c_EngLang, " + LnkDyn + ");", 'Image4', '../../images/Eng.gif', '../../images/Eng_f2.gif', 17, 48, "000280", currLang);
	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');
		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)
{
	//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
	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/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/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://hkclav.hkpl.gov.hk/preview/audio/';

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

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

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

function c_GetJsp(svc, operation)
{
	var qryStr;

	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)
{
	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 (currLang != c_ChtLang)
	{
		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);
		else
			c_DrawLnk("javascript:c_ChgLang(c_ChtLang, " + LnkDyn + ");", 'Image2', 'images/T-Chin.gif', 'images/T-Chin_f2.gif', 17, 26, "000281", currLang);
	}
	else
	{
		//Remarked by tony
		//document.write('<td><img src="../images/T-Chin_f3.gif" width="26" height="17" border="0" name="Image2" onLoad="this.alt=c_GetMsg(' + "'" + currLang + "','" + "000281" + "'" + ');"/></td>');
		
		//Netscape4.76
		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 user only
	if (Intra)
	{
		if (currLang != c_ChsLang)
		{
			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);
			else
				c_DrawLnk("javascript:c_ChgLang(c_ChsLang, " + LnkDyn + ");", 'Image3', 'images/S-Chin.gif', 'images/S-Chin_f2.gif', 17, 26, "000282", currLang);
		}
		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 (pathname.indexOf("jsp") >= 0)
			c_DrawLnk("javascript:c_ChgLang(c_EngLang, " + LnkDyn + ");", 'Image4', '../images/Eng.gif', '../images/Eng_f2.gif', 17, 48, "000280", currLang);
		else
			c_DrawLnk("javascript:c_ChgLang(c_EngLang, " + LnkDyn + ");", 'Image4', 'images/Eng.gif', 'images/Eng_f2.gif', 17, 48, "000280", currLang);
	}
	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 = "";
	if (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;
}

