/***************************************************************************************************************
*
* Attention:	Whenever you create a new Local Predefined Function, make sure you cannot use the function name as listed below:
*		PTTbutton, webCall, webCallBack, webVoicePop, webChatPop, wv_start
*
*
* Notification:	Programmer should update the above list in order to avoid function clashing.
*
*
***************************************************************************************************************/
/***************************************************************************************************************
* Function		: Popup_newBrowser(url, status, location, scroll, mbar, toolbar, resize, width, height, winname)
* Description		: Open a new browser (popup)
* Parameter Usage	: url		:target URL
* 			  status	:the status of the target browser (yes/no)
* 			  location	:has address bar or not (yes/no)
* 			  scroll	:has scroll bar or not (yes/no)
* 			  mbar		:has menu bar or not (yes/no)
* 			  toolbar	:has toolbar or not (yes/no)
* 			  resize	:resizable or not (yes/no)
* 			  height	:height of the target browser
*			  width		:width of the target browser
*			  winname : window name (default is set to "nb")
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Rachel, Tse Wing Yi
* Creation Date		: 16 Dec 2003
* Side effect		: N/A
* Amendment History	:
* Date		By					Description
* ---------	------------	--------------------------------------------------------------------------------
* 01MAR2004 Arnold			Add an optional parameter, window name, at the end of the parameter list
*
***************************************************************************************************************/

function Popup_newBrowser(url, status, location, scroll, mbar, toolbar, resize, width, height, winname)
{
	!winname? winname="nb":winname=winname;
	nb=window.open(url, winname, "status=" + status + ",location=" + location + ",scrollbars=" + scroll + ",menubar=" + mbar + ",toolbar=" + toolbar + ",resizable=" + resize + ",height=" + height + ",width=" + width + ",left=20,top=20");
	nb.focus();

}

/***************************************************************************************************************
* Function		: DoubleClickAdTag(placement, alttext, width, height, secure)
* Description		: Display DoubleClick Ad Tag
* Parameter Usage	: placement	: an id to locate the ad slot
* 			: wide		: width of the ad slot
* 			: height		: height of the ad slot
*			: alttext		: text appear when the image is being loaded or mouseover
*			: secure	: A 'y' or 'n' to indicate whether it is a secure site
* Author		: DoubleClick
* Creation Date		: 2004-02-06
* Side effect		: No
* Amendment History	:
* Date		By		Description
* ---------	------------	--------------------------------------------------------------------------------
***************************************************************************************************************/
function DoubleClickAdTag(placement, alttext, width, height, secure)
{
ord=Math.random();
ord=ord*10000000000000000000;

if (secure == "y")
		{
		// if secure = 'y' then execute tag in secure environment
		document.write('<A HREF="https://ad.doubleclick.net/jump/'+placement+';sz='+width+'x'+height+';ord='+ord+'?" TARGET="_blank">');
		document.write('<IMG SRC="https://ad.doubleclick.net/ad/'+placement+';sz='+width+'x'+height+';ord='+ord+'?" WIDTH="'+width+'" HEIGHT="'+height+'" BORDER="0" ALT="'+alttext+'"></A>');
		}
	else
		{
		// if secure = 'n' then execute tag in public environment
		document.write('<A HREF="http://ad.hk.doubleclick.net/jump/'+placement+';sz='+width+'x'+height+';ord='+ord+'?" TARGET="_blank">');
		document.write('<IMG SRC="http://ad.hk.doubleclick.net/ad/'+placement+';sz='+width+'x'+height+';ord='+ord+'?" WIDTH="'+width+'" HEIGHT="'+height+'" BORDER="0" ALT="'+alttext+'"></A>');
		}
}

/***************************************************************************************************************
* Function		: DoubleClickSpotlightTag(src, type, cat, secure)
* Description		: Display DoubleClick Spotlight Tag
* Parameter Usage	: src		: advertiser ID in DFA
* 			: type		: spotlight group ID in DFA
* 			: cat		: spotlight activity ID in DFA
*			: secure	: A 'y' or 'n' to indicate whether it is a secure site
* Author		: DoubleClick
* Creation Date		: 2004-02-06
* Side effect		: No
* Amendment History	:
* Date		By		Description
* ---------	------------	--------------------------------------------------------------------------------
***************************************************************************************************************/
function DoubleClickSpotlightTag(src, type, cat, secure)
{
/* Start of DoubleClick Spotlight Tag: Please do not remove */
var axel = Math.random()+"";
var a = axel * 10000000000000;

if (secure == "y")
		{
		// if secure = 'y' then execute tag in secure environment
		document.write('<IMG SRC="https://ad.doubleclick.net/activity;src='+src+';type='+type+';cat='+cat+';ord='+ a + '?" WIDTH=1 HEIGHT=1 BORDER=0>');
		}
	else
		{
		// if secure = 'n' then execute tag in public environment
		document.write('<IMG SRC="http://ad.hk.doubleclick.net/activity;src='+src+';type='+type+';cat='+cat+';ord='+ a + '?" WIDTH=1 HEIGHT=1 BORDER=0>');
		}

/* End of DoubleClick Spotlight Tag: Please do not remove */
}

/***************************************************************************************************************
* Function		: LPF_MouseOut()
* Description		: Restore original image when mouse out
* Parameter Usage	: N/A
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Arnold (Grey Interactive)
* Creation Date		: 16 Jan 2004
* Side effect		: N/A
* Amendment History	:
* Date		By		Description
* ---------	------------	--------------------------------------------------------------------------------
*
*
****************************************************************************************************************
* Remarks - Exactly the same as function MM_swapImgRestore() in /hk/personal/card/common/js/cs01g.js
*           This function should be generated by Macromedia's application
*				Please check, there is duplicate function in /hk/personal/common/js/common.js
***************************************************************************************************************/
function LPF_MouseOut()
{
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

/***************************************************************************************************************
* Function		: LPF_MouseOver_findObj(n, d)
* Description		: Called by LPF_MouseOver() only. It should be used to find object n in document d
* Parameter Usage	: d : current document (optional)
*                   n : object
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Arnold (Grey Interactive)
* Creation Date		: 16 Jan 2004
* Side effect		: N/A
* Amendment History	:
* Date		By		Description
* ---------	------------	--------------------------------------------------------------------------------
*
*
****************************************************************************************************************
* Remarks - This has the same functionality as function MM_findObj() in /hk/personal/card/common/js/cs01g.js
*           This function should be generated by Macromedia's application
***************************************************************************************************************/
function LPF_MouseOver_findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=LPF_MouseOver_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

/***************************************************************************************************************
* Function		: LPF_Redirect(url)
* Description		: Redirect the current page to a new URL
* Parameter Usage	: url	:target URL
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Arnold (Grey Interactive)
* Creation Date		: 16 Jan 2004
* Side effect		: N/A
* Amendment History	:
* Date		By		Description
* ---------	------------	--------------------------------------------------------------------------------
*
***************************************************************************************************************/
function LPF_Redirect(url)
{
	location.href=url;
}

/***************************************************************************************************************
* Function		: LPF_Print()
* Description		: Print the current window
* Parameter Usage	: N/A
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Arnold (Grey Interactive)
* Creation Date		: 16 Jan 2004
* Side effect		: N/A
* Amendment History	:
* Date		By		Description
* ---------	------------	--------------------------------------------------------------------------------
*
***************************************************************************************************************/
function LPF_Print()
{
	window.print();
}


/***************************************************************************************************************
* Function		: LPF_preloadImages(imgarraystr)
* Description		: Preload the images in imgarray
* Parameter Usage	: imgarray - array of image files
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Kenneth Cheung (Grey Interactive)
* Creation Date		: 12 Feb 2004
* Side effect		: N/A
* Amendment History	:
* Date		By		Description
* ---------	------------	--------------------------------------------------------------------------------
*
***************************************************************************************************************/
function LPF_preloadImages(imgarraystr) {
	var d=document;
	var imgarray = imgarraystr.split(",");

	if(d.images) {
		if(!d.p) d.p=new Array();
		var i=0,j=d.p.length,a=imgarray;

		for(i=0; i<a.length; i++)
			if (a[i].indexOf("#")!=0) {
				d.p[j]=new Image; d.p[j++].src=a[i];
			}
	}
}

/***************************************************************************************************************
* Function		: LPF_writeFlash(swfsrc,swfwidth,swfheight,swfclassid,swfcodebase,swfpluginspage,imgurl,imgwidth,imgheight,imghref,imgtarget,imgalt,imgborder,otherparam)
* Description		: Generate codes for displaying Flash if appropriate plugin is installed.
*			  Otherwise it will display a graphic file with an option of hyperlink.
* Parameter Usage	: swfsrc - Specifies the location (URL) of the movie to be loaded.
*						  swfwidth - Specifies the width of the movie in either pixels or percentage of browser window.
*						  swfheight - Specifies the height of the movie in either pixels or percentage of browser window.
*						  swfclassid - Identifies the ActiveX control for the browser. OBJECT only.
*						  swfcodebase - Identifies the location of the Flash Player ActiveX control so that the browser
*						                can automatically download it if it is not already installed. OBJECT only.
*						  swfpluginspage - Identifies the location of the Flash Player plug-in so that the user can
*						                   download it if it is not already installed. EMBED only.
*						  imgurl - url of the image file to be called
*						  imgwidth - width of the image file (blank if same width as Flash)
*						  imgheight - height of the image file (blank if same height as Flash)
*						  imghref - hyperlink of the image file (no link if blank)
*						  imgtarget - target window of the hyperlink (ignore if hyperlink is blank)
*						  imgalt - alt text of image (default blank)
*						  imgborder - border of image  (default 0)
*						  otherparam - Other optional attributes and possible values. The format of the string is a
*						               set of name,value combinations separated by '|'.
*						               Please read http://www.macromedia.com/support/flash/ts/documents/tag_attributes.htm
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Arnold (Grey Interactive)
* Creation Date		: 24 Feb 2004
* Side effect		: N/A
* Amendment History	:
* Date		By					Description
* ---------	------------	--------------------------------------------------------------------------------
*
***************************************************************************************************************/
function LPF_writeFlash(swfsrc,swfwidth,swfheight,swfclassid,swfcodebase,swfpluginspage,imgurl,imgwidth,imgheight,imghref,imgtarget,imgalt,imgborder,otherparam) {
	var i=0;
	var isOK=false;
	document.returnValue = false;
	plgIn='Shockwave Flash';

	!swfclassid? swfclassid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000":i=i;
	!swfcodebase? swfcodebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0":i=i;
	!swfpluginspage? swfpluginspage="http://www.macromedia.com/go/getflashplayer":i=i;

	!imgwidth? imgwidth=swfwidth:i=i;
	!imgheight? imgheight=swfheight:i=i;
	!imgalt? imgalt="":i=i;
	!imgborder? imgborder=0:i=i;

	with (navigator) if (appName.indexOf('Microsoft')!=-1 && appVersion.indexOf('Mac')==-1)
		document.write(''+'<scr'+'ipt language="VBScript">\nOn error resume next\n'+'dir = IsObject(CreateObject("SWCtl.SWCtl.1"))\n'+'flash = NOT IsNull(CreateObject("ShockwaveFlash.ShockwaveFlash"))\n</scr'+'ipt>');

	with (navigator) if (appName.indexOf('Microsoft')==-1 || (plugins && plugins.length)) {
		isOK=(plugins && plugins[plgIn]);
	} else if (appVersion.indexOf('3.1')==-1) { //not Netscape or Win3.1
		if (plgIn.indexOf("Flash")!=-1 && window.flash!=null)
			isOK=window.flash;
		else if (plgIn.indexOf("Director")!=-1 && window.dir!=null)
			isOK=window.dir;
		else isOK=false;
	}


	if (isOK) {
		document.write('<OBJECT classid="' + swfclassid + '" codebase="' + swfcodebase + '" WIDTH='+swfwidth+' HEIGHT='+swfheight+'>');
		document.write('<PARAM NAME=movie VALUE="'+swfsrc+'">');

		var op = otherparam.split("|");
		var op1;
		var embedStr="";

		for(i=0;i<op.length;i++) {
			op1 = op[i].split(",");
			document.write('<PARAM NAME=' + op1[0] + ' VALUE="' + op1[1] + '">');
			embedStr = embedStr + op1[0] + '="' + op1[1] + '" ';
		}

		document.write('<EMBED src="'+swfsrc+'" WIDTH='+swfwidth+' HEIGHT='+swfheight+' TYPE="application/x-shockwave-flash" PLUGINSPAGE="' + swfpluginspage + '" ');
		document.write(embedStr);
		document.write('></');
		document.write('EMBED>');
		document.write('</');
		document.write('OBJECT>');
	}
	else
	{
		if (imghref) {
			document.write('<a href="'+imghref+'"');
			if (imgtarget) {
				document.write(' target="'+imgtarget+'"');
			}
			document.write('>');
		}

		document.write('<img alt="' + imgalt + '" src="'+imgurl+'" width="'+imgwidth+'" height="'+imgheight+'" border="' + imgborder + '">');
		if (imghref) {
			document.write('</a>');
		}
	}

	op=null;
	op1=null;
}


/***************************************************************************************************************
* Function		   : LPF_DisplayLayer(layerarraystr)
* Description		: Show or Hide a layer by setting the display property
* Parameter Usage	: layerarraystr is in format of "layer1,property1,layer2,property2 ..."
*                   where layer1, layer2 ... = id of the layer
*                         property1, property2 ... = show or hide
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Arnold (Grey Interactive)
* Creation Date		: 13 Feb 2004
* Side effect		: N/A
* Amendment History	:
* Date		By		Description
* ---------	------------	--------------------------------------------------------------------------------
*
***************************************************************************************************************/
function LPF_DisplayLayer(layerarraystr) {
	var a = layerarraystr.split(",");
	if((a.length / 2) != Math.ceil(a.length/2)) {
		alert("Invalid parameters for LPF_DisplayLayer!\nIt must be in format layer1,property1,layer2,property2 ...");
	} else {
		var i,v,obj;
		for (i=0; i<a.length; i+=2) {
			if ((obj=LPF_MouseOver_findObj(a[i]))!=null) {
				v=a[i+1];
				if (obj.style) {
					obj=obj.style;
					v=(v=='show')?'block':(v=='hide')?'none':v;
				}
				obj.display=v;
			}
		}
	}
	a = null;
}

/***************************************************************************************************************
* Function		   : LPF_ShowHideLayer(layerarraystr)
* Description		: Show or Hide a layer by setting the visibility property.
* Parameter Usage	: layerarraystr is in format of "layer1,property1,layer2,property2 ..."
*                   where layer1, layer2 ... = id of the layer
*                         property1, property2 ... = show or hide
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Arnold (Grey Interactive)
* Creation Date		: 17 Feb 2004
* Side effect		: N/A
* Amendment History	:
* Date		By		Description
* ---------	------------	--------------------------------------------------------------------------------
*
***************************************************************************************************************/
function LPF_ShowHideLayer(layerarraystr) {
	var a = layerarraystr.split(",");
	if((a.length / 2) != Math.ceil(a.length/2)) {
		alert("Invalid parameters for ShowHideLayer!\nIt must be in format layer1,property1,layer2,property2 ...");
	} else {
		var i,v,obj;
		for (i=0; i<a.length; i+=2) {
			if ((obj=LPF_MouseOver_findObj(a[i]))!=null) {
				v=a[i+1];
				if (obj.style) {
					obj=obj.style;
					v=(v=='show')?'visible':(v='hide')?'hidden':v;
				}
				obj.visibility=v;
			}
		}
	}
	a = null;
}

/***************************************************************************************************************
* Function		: LPF_SwapImage(imgArrayStr)
* Description		: Change the src property of specified images
* Parameter Usage	: imgArrayStr - in the format of "imgName1,imgPath1,imgName2,imgPath2..."
*                   where imgName1, imgName2 ... = name of image to be changed
*                         imgFullpath1, imgFullpath2 ... = path of the image
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Arnold (Grey Interactive)
* Creation Date		: 13 Feb 2004
* Side effect		: N/A
* Amendment History	:
* Date      By             Description
* ---------	------------   --------------------------------------------------------------------------------
*
***************************************************************************************************************/
function LPF_SwapImage(imgArrayStr)
{
	var a = imgArrayStr.split(",");

	if((a.length / 2) != Math.ceil(a.length/2)) {
		alert("Invalid parameters for LPF_SwapImage!\nIt must be in format of imgName1,imgPath1,imgName2,imgPath2...");
	} else {
		var i,imgObj;
		for(i=0;i<a.length;i+=2) {
			if ((imgObj=LPF_MouseOver_findObj(a[i]))!=null){
				imgObj.src=a[i+1];
			}
		}
	}
	a = null;
}

/***************************************************************************************************************
* Function		: LPF_SetTimeout(fn, t)
* Description		: Run a function after default time
* Parameter Usage		: fn - the function you want to run in window.setTimeout. "|" is used instead of ";" when running
*							       two or more functions as ";" is used as a seperator in LocalPredefinedFunction.
*							  t - the time to wait before run the function in milliseconds
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Arnold (Grey Interactive)
* Creation Date		: 16 Feb 2004
* Side effect		: N/A
* Amendment History	:
* Date      By             Description
* ---------	------------   --------------------------------------------------------------------------------
* 24Feb2004 Arnold			Direct call the function instead of using LocalPredefinedFunction according to IT comment
***************************************************************************************************************/
function LPF_SetTimeout(fn, t)
{
	var rExp = /\|/gi;
	var function_call = fn.replace(rExp, ";");
	document.timeout = window.setTimeout(function_call, t);
}

/***************************************************************************************************************
* Function		: LPF_ClearTimeout()
* Description		: Clear a previously set timeout
* Parameter Usage	: N/A
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Arnold (Grey Interactive)
* Creation Date		: 16 Feb 2004
* Side effect		: N/A
* Amendment History	:
* Date      By             Description
* ---------	------------   --------------------------------------------------------------------------------
*
***************************************************************************************************************/
function LPF_ClearTimeout()
{
	window.clearTimeout(document.timeout);
}

/***************************************************************************************************************
* Function			: LPF_OnChange_Pulldown(formname, elt)
* Description			: This is to handle the onChange event of pulldown menu
* Parameter Usage		: formname - name of Form which contains the pulldown menu (the <select> tag) element
*				  elt - name of the pulldown menu element
*				  The value of that element must be in format of "param||typeOfBrowser", "||" is as the seperator.
*				  typeOfBrowser : popup - popup new browser
*				  - The param has the same format as Popup_newBrowser's parameters
*				  i.e. url;status;location;scroll;mbar;toolbar;resize;width;height
*				  redirect - redirect to other url in current browser
*				  - The param is the url of the page redirect to
*				  displaylayer - call the LPF_DisplayLayer function
*				  - The param is the parameters string that will pass to LPF_DisplayLayer function
* Location			: /hk/personal/common/js/pfscommon.js
* Author			: Arnold (Grey Interactive)
* Creation Date			: 20 Feb 2004
* Side effect			: N/A
* Projects			: Mortgage
* Amendment History		:
* Date		By					Description
* ---------	------------	--------------------------------------------------------------------------------
* 24Feb2004 Arnold      	Remove "anchor" from typeOfBrowser values - IT comment
* 16Nov2004 Arnold      	Add "displaylayer" to typeOfBrowser values
***************************************************************************************************************/

function LPF_OnChange_Pulldown(formname, elt) {

	var idx = document.forms[formname].elements[elt].selectedIndex;
	var v = document.forms[formname].elements[elt][idx].value;

	var p = v.split("||");

	switch(p[1]) {
		case "popup":
			var params = p[0].split(";");
			if(params.length!=10 && params.length!=9)
			{
				alert("Invalid parameters for Popup_newBrowser - LocalPredefinedFunction('Popup_newBrowser;???;???;???;???;???;???;???;???;???;???')");
			}
			else
			{
				Popup_newBrowser(params[0], params[1], params[2], params[3], params[4], params[5], params[6], params[7], params[8], params[9]);
			}
			break;

		case "redirect":
			LPF_Redirect(p[0]);
			break;

		case "displaylayer":
			LPF_DisplayLayer(p[0]);
			break;

		default:
			break;
	}

	p = null;
}


/***************************************************************************************************************
* Function		   : LPF_SetOpacity(obj, n)
* Description		: Change the opacity of an object
* Parameter Usage	: obj - id of the object
*                   n - opacity : from 0 to 100; 0 is invisible; 100 is normal display (no transparency)
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Arnold (Grey Interactive)
* Creation Date		: 17 Feb 2004
* Side effect		: N/A
* Amendment History	:
* Date		By		Description
* ---------	------------	--------------------------------------------------------------------------------
*
***************************************************************************************************************/

function LPF_SetOpacity(obj, n) {
	if(document.all) document.getElementById(obj).filters.alpha.opacity=n;
	else if(document.getElementById) document.getElementById(obj).style.MozOpacity=n+'%';
}

/***************************************************************************************************************
* Function		   : LPF_Fade(obj, speed, direction, endOpacity)
* Description		: Fade in/out effect of an object
*						  The starting opacity should be set by document.opacityValue = ???; before calling this function
* Parameter Usage	: obj - id of the object
*                   speed - the speed for fade in/out. The value must be between 1 and 100
*						  direction - in or out
*						  endOpacity - the value of opacity when the fading effect ends. This must be between 0 and 100
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Arnold (Grey Interactive)
* Creation Date		: 17 Feb 2004
* Side effect		: N/A
* Amendment History	:
* Date		By		Description
* ---------	------------	--------------------------------------------------------------------------------
*
***************************************************************************************************************/

function LPF_Fade(obj, speed, direction, endOpacity) {
	if (direction == "in" ) {
		if (!document.opacityValue) document.opacityValue=0;
		document.opacityValue += speed;
		if (document.opacityValue <= endOpacity) {
			LPF_SetOpacity(obj, document.opacityValue);
			window.setTimeout("LPF_Fade('" + obj + "'," + speed + ",'" + direction + "'," + endOpacity  + ")", 50);
		} else {
			LPF_SetOpacity(obj, endOpacity);
		}
	} else {
		if (!document.opacityValue) document.opacityValue=100;
		document.opacityValue -= speed;
		if (document.opacityValue >= endOpacity) {
			LPF_SetOpacity(obj, document.opacityValue);
			window.setTimeout("LPF_Fade('" + obj + "'," + speed + ",'" + direction + "'," + endOpacity  + ")", 50);
		} else {
			LPF_SetOpacity(obj, endOpacity);
		}
	}
}

/***************************************************************************************************************
* Function				: LPF_SetOpacityValue(v)
* Description			: Set document.opacityValue's value
* Parameter Usage		: v - value you want to set document.opacityValue to
* Location				: /hk/personal/common/js/pfscommon.js
* Author					: Arnold (Grey Interactive)
* Creation Date		: 24 Feb 2004
* Side effect			: N/A
* Amendment History	:
* Date      By             Description
* ---------	------------   --------------------------------------------------------------------------------
*
***************************************************************************************************************
* Remarks: document.opacityValue is used for LPF_Fade function
***************************************************************************************************************/
function LPF_SetOpacityValue(v)
{
	document.opacityValue = v;
}



/***************************************************************************************************************
* Function		: LPF_MouseOver(imgName, imgOther, imgPath, imgControl)
* Description		: Display another image when mouse over
*						  When user only wants to change one image when mouseover (most mouse over effect is this case), set imgControl to 1
*						  When uesr needs to change two images to the same image when mouseover, set imgControl to 2
*						  If user wants to change the image only when it's currently displaying a specific image, use imgControl = "e"
*						  If user wants to change the image only when it's currently not displaying a specific image, use imgControl = "ne"
*						    (eg see www.hsbc.com.hk/hk/personal/bank/waystobank.htm. There are 3 states for the buttons,
*						     on, off and over. Normally it will show the off state. When user moves mouse over it, it will
*						     change to over state. It will return to off when mouse out. When the user clicks the button,
*						     it will change to on state. When the button is at on state, there will be no image change whether
*						     the user mouseover or mouseout the button)
* Parameter Usage	: imgName		: The name of image
*                   imgPath		: Path of the image for display when mouse over
*                   imgOther		: This usage depends on the value of imgControl
*                   imgControl	: If this is 1, then only change the src of the image with name = imgName to imgPath
*													imgOther will have no use in this case.
*											  If this is 2, imgOther should another image name.
*													Both the imgName and imgOther will change to imgPath
*											  If this is "e", imgOther should be an image src.
*													If imgName's src = imgOther, then change imgName's src to imgPath. Otherwise no change.
*											  If this is "ne", imgOther should be an image src.
*													If imgName's src != imgOther, then change imgName's src to imgPath. Otherwise no change.
*											  Other values will be treated as case 1
* Supported browsers : IE 6, Netscape 7
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Arnold (Grey Interactive)
* Creation Date		: 6 Feb 2004
* Side effect		: N/A
* Amendment History	:
* Date      By             Description
* ---------	------------   --------------------------------------------------------------------------------
* 04MAR2004 Arnold			Declare parameters
* 12MAR2004 Arnold			Merge this with LPF_SwapImage_Condition()
* 18MAR2004 Arnold			Add description, amended according to IT comment
* 18APR2004 Vivian 			Fix the javascript error in the default cases
****************************************************************************************************************
*
***************************************************************************************************************/
function LPF_MouseOver(imgName, imgOther, imgPath, imgControl)
{

	switch(imgControl)
	{
		case "1":
			var i,j=0,x;
			document.MM_sr=new Array;
			if ((x=LPF_MouseOver_findObj(imgName))!=null){
				document.MM_sr[j++]=x;
				if(!x.oSrc) x.oSrc=x.src;
				x.src=imgPath;
			}
			break;

		case "2":
			var i,j=0,x;
			document.MM_sr=new Array;
			if ((x=LPF_MouseOver_findObj(imgName))!=null){
				document.MM_sr[j++]=x;
				if(!x.oSrc) x.oSrc=x.src;
				x.src=imgPath;
			}

			if ((x=LPF_MouseOver_findObj(imgOther))!=null){
				document.MM_sr[j++]=x;
				if(!x.oSrc) x.oSrc=x.src;
				x.src=imgPath;
			}
			break;

		case "e":
			var imgSrc = location.protocol + "//" + location.hostname;

			if (!(!location.port || location.port==80)) {
				imgSrc+=":"+location.port;
			}

			if (imgOther.indexOf('/') == 0) {
				imgSrc += imgOther
			} else {
				imgSrc += location.pathname.substr(0,location.pathname.lastIndexOf('/')+1) + imgOther;
			}

			imgObj = LPF_MouseOver_findObj(imgName);
			if (imgObj != null ) {
				if (imgObj.src == imgSrc) {
					imgObj.src = imgPath;
				}
			}
			break;

		case "ne":
			var imgSrc = location.protocol + "//" + location.hostname;

			if (!(!location.port || location.port==80)) {
				imgSrc+=":"+location.port;
			}

			if (imgOther.indexOf('/') == 0) {
				imgSrc += imgOther
			} else {
				imgSrc += location.pathname.substr(0,location.pathname.lastIndexOf('/')+1) + imgOther;
			}

			imgObj = LPF_MouseOver_findObj(imgName);
			if (imgObj != null ) {
				if (imgObj.src != imgSrc) {
					imgObj.src = imgPath;
				}
			}
			break;

		default:
			var i,j=0,x;
			document.MM_sr=new Array;
			if ((x=LPF_MouseOver_findObj(imgName))!=null){
				document.MM_sr[j++]=x;
				if(!x.oSrc) x.oSrc=x.src;
				x.src=imgPath;
			}
			break;
	}
}



/***************************************************************************************************************
* Function		: LPF_addCss(pciefile, maciefile, pcnsfile, macnsfile)
* Description		: Add css file to html
* Parameter Usage	: pciefile - style sheet for PC's IE
*			  pcnsfile - style sheet for PC's Netscape 7 (if not specified, it will use pciefile)
*			  maciefile - style sheet for MAC's IE
*			  macnsfile - style sheet for MAC's Netscape 7 (if not specified, it will use maciefile)
* Supported browsers	: IE6, Netscape 7 for PC; IE, Netscape 6 for mac
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Arnold (Grey Interactive)
* Creation Date		: 22 Mar 2004
* Side effect		: N/A
* Amendment History	:
* Date		By		         Description
* ---------	------------	--------------------------------------------------------------------------------
***************************************************************************************************************
* Remarks: require hsbc.js
***************************************************************************************************************/
function LPF_addCss(pciefile, maciefile, pcnsfile, macnsfile)
{
	if (!mac) {
		if (pcnsfile) {
			if (isNetscape6)  {
				document.write('<link rel=\"stylesheet\" href=\"'+pcnsfile+'\" type=\"text/css\">');
			} else {
				document.write('<link rel=\"stylesheet\" href=\"'+pciefile+'\" type=\"text/css\">');
			}
		} else {
			document.write('<link rel=\"stylesheet\" href=\"'+pciefile+'\" type=\"text/css\">');
		}
	} else {
		if (macnsfile) {
			if (isNetscape6)  {
				document.write('<link rel=\"stylesheet\" href=\"'+macnsfile+'\" type=\"text/css\">');
			} else {
				document.write('<link rel=\"stylesheet\" href=\"'+maciefile+'\" type=\"text/css\">');
			}
		} else {
			document.write('<link rel=\"stylesheet\" href=\"'+maciefile+'\" type=\"text/css\">');
		}
	}
}


		/***************************************************************************************************************
		* Function		: LPF_getParamVal(name, defaultValue)
		* Description		: Get parameters from querystring of URL
		* Parameter Usage	: name - variable name
		*						  defualtValue - defualt value when variable name is not set
		* Supported browsers	: IE6
		* Location		: /hk/personal/common/js/pfscommon.js
		* Author		: Arnold (Grey Interactive)
		* Creation Date		: 19 Apr 2004
		* Side effect		: N/A
		* Amendment History	:
		* Date		By		         Description
		* ---------	------------	--------------------------------------------------------------------------------
		***************************************************************************************************************
		* Remarks: require hsbc.js
		***************************************************************************************************************/

function LPF_getParamVal(name, defaultValue)
{
	s=location.search
	reg=new RegExp('.*'+name+'=([^&]*).*')
	s=s.replace(reg,'$1')
	if (s==location.search) s=defaultValue;
	return s;
}

/*Common Function for Bank*/
/*Common Function for Card*/


/***************************************************************************************************************
* Function		: LPF_Digital_Order(lang, cookievalue)
* Description		: To logon PIB with digital order
* Parameter Usage	: lang		:zh or en or cn
* 			  cookievalue	:cookievalue
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Rachel, Tse Wing Yi (HSBC eCD)
* Creation Date		: 28 Jan 2004
* Side effect		: N/A
* Amendment History	:
* Date		By		Description
* ---------	------------	--------------------------------------------------------------------------------
*
***************************************************************************************************************/
function LPF_Digital_Order(lang, cookievalue)
{
	Popup_newBrowser('', "yes", "no", "yes", "no", "no", "yes", 800, 500);



	LPF_setCookie("FromWebSite", cookievalue, "/", ".hsbc.com.hk", "true", 0);

	if (lang == "en")
		document.digital_order_en.submit();
	else if (lang == "zh")
		document.digital_order_zh.submit();
	else if (lang == "cn")
		document.digital_order_cn.submit();
	else
		document.digital_order_en.submit();
}

/***************************************************************************************************************
* Function		: LPF_setCookie
* Description		: To logon PIB with digital order
* Parameter Usage	: Name:		name
* 			  value:	cookievalue
*			  path:		/
*			  domain:	.hsbc.com.hk
*			  secure:	true/false
*			  expires:	expires
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Henry, Tam Lup Kei (HSBC eCD)
* Creation Date		: 6 Feb 2004
* Side effect		: N/A
* Amendment History	:
* Date		By		Description
* ---------	-------------------------------------------------------------------------------------------
***************************************************************************************************************/

function LPF_setCookie(name, value, path, domain, secure, expires)
{
    document.cookie = name + "=" + value +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? ";secure" : "")+
    ((expires) ? ";expires=" + expires.toGMTString() : "") ;
}


/***************************************************************************************************************
* Function		: LPF_digital_order_form
* Description		: output digital order form to htm
* Parameter Usage	: no parameter
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Henry, Tam Lup Kei (HSBC eCD)
* Creation Date		: 6 Feb 2004
* Side effect		: N/A
* Amendment History	:
* Date		By		Description
* ---------	-------------------------------------------------------------------------------------------
***************************************************************************************************************/

function LPF_digital_order_form()
{
//draw the form
document.write("<form name='digital_order_en' method='post' target='nb' action='https://www.ebank.hsbc.com.hk/servlet/onlinehsbc?LANGTAG=en&COUNTRYTAG=US'>")
document.write("<input name='WithCookie' value='true' type='hidden'>")
document.write("</form>")

document.write("<form name='digital_order_zh' method='post' target='nb' action='https://www.ebank.hsbc.com.hk/servlet/onlinehsbc?LANGTAG=zh&COUNTRYTAG=HK'>")
document.write("<input name='WithCookie' value='true' type='hidden'>")
document.write("</form>")

document.write("<form name='digital_order_cn' method='post' target='nb' action='https://www.ebank.hsbc.com.hk/servlet/onlinehsbc?LANGTAG=zh&COUNTRYTAG=CN'>")
document.write("<input name='WithCookie' value='true' type='hidden'>")
document.write("</form>")
}

/***************************************************************************************************************
* Function		: LPF_Popup_submitToNewBrowser(formname, winname, status, location, scroll, mbar, toolbar, resize, width, height)
* Description		: Submit a form and set its target to a new browser (popup)
* Pre-requisites	: 1) The "target" attribute in the <form> being submitted should be the same as the window name (winname)
*			  2) Should not assign any window name to the HTM in the popup window
* Parameter Usage	: formname	:form name
*			  winname	:window name
*			  status	:the status of the target browser (yes/no)
* 			  location	:has address bar or not (yes/no)
* 			  scroll	:has scroll bar or not (yes/no)
* 			  mbar		:has menu bar or not (yes/no)
* 			  toolbar	:has toolbar or not (yes/no)
* 			  resize	:resizable or not (yes/no)
*			  width		:width of the target browser
* 			  height	:height of the target browser
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Garfield (Rapp Collins Worldwide (HK) Ltd.)
* Creation Date		: 13 Apr 2004
* Side effect		: N/A
* Amendment History	:
* Date		By					Description
* ---------	------------	--------------------------------------------------------------------------------
*
***************************************************************************************************************/

function LPF_Popup_submitToNewBrowser(formname, winname, status, location, scroll, mbar, toolbar, resize, width, height)
{
	if(!document[formname])
	{
		alert("Invalid value for the parameter [formname] in LPF_Popup_submitToNewBrowser");
	}
	else
	{
		nb=window.open("", winname, "status=" + status + ",location=" + location + ",scrollbars=" + scroll + ",menubar=" + mbar + ",toolbar=" + toolbar + ",resizable=" + resize + ",width=" + width + ",height=" + height + ",left=20,top=20");
		nb.focus();
		document[formname].submit();
	}
}

/***************************************************************************************************************
* Function		: LPF_pr_timeStop(name, imgsrc, imgsrc2, timelen, flag, frm, field)
* Description		: This is used in the premier public site homepage to rotate the images
* Pre-requisites	: 1) A form and a hidden form field should be defined in the page, and the initial value of the hidden field should be set to 0
* Parameter Usage	: name	:name of the image
* 					imgsrc	:the first image
* 					imgsrc2	:the second image
* 					timelen	:the time inteval for the rotation
* 					flag	:the flag indicated which image should be used
* 					frm		:the name of the form containing the mouse event information
* 					field		:the name of the hidden form field containing the mouse event information
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Vivian Au (Ion Global)
* Creation Date		: 19 May 2004
* Side effect		: N/A
* Amendment History	:
* Date		By					Description
* ---------	------------	--------------------------------------------------------------------------------
*
***************************************************************************************************************/
function LPF_pr_timeStop(name, imgsrc, imgsrc2, timelen, flag, frm, field) {
	var f = LPF_MouseOver_findObj(frm);
	var newflag = flag;
	var timeInt = timelen;
	if (f != null){
		var mseStatusVal = f.elements[field].value;
		if (mseStatusVal == 0) {
			if (flag) {
				LPF_MouseOver(name, '', imgsrc2, '');
				newflag = 0;
			} else {
	
				LPF_MouseOver(name, '', imgsrc, '');
				newflag = 1;
			}
		}
	} else {
		timeInt = 500;
	}
	setTimeout('LPF_pr_timeStop(\''+name+'\', \''+imgsrc+'\', \''+imgsrc2+'\', '+timelen+', '+newflag+', \''+frm+'\', \''+field+'\')', timeInt);
}

/***************************************************************************************************************
* Function		: LPF_pr_chgFrmVal(frm, field, value)
* Description		: This is used in the premier public site homepage to change the value of a hidden form field
* Pre-requisites	: 1) A form should be predefined in the page
* Parameter Usage	: frm	:name of the form
* 					field	:name of the hidden field
* 					value	:the value assign to the hidden form field
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Vivian Au (Ion Global)
* Creation Date		: 19 May 2004
* Side effect		: N/A
* Amendment History	:
* Date		By					Description
* ---------	------------	--------------------------------------------------------------------------------
*
***************************************************************************************************************/
function LPF_pr_chgFrmVal(frm, field, value) {
	var f = LPF_MouseOver_findObj(frm);
	if (f != null) {
		f.elements[field].value = value;
	}
}

/***************************************************************************************************************
* Function			: LPF_getCookie(name)
* Description		: Return value of a specific cookie
* Parameter Usage	: name: cookie name
* Location			: /hk/personal/common/js/pfscommon.js
* Author				: Fai Leung (elight Software Limited)
* Creation Date	: 10 May 2004
* Side effect		: N/A
* Amendment History:
* Date		By					Description
* ---------	------------	--------------------------------------------------------------------------------
***************************************************************************************************************/
function LPF_getCookie(name)
{
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1)
	{
		begin = dc.indexOf(prefix);
		if (begin != 0)
			return null;
	}
	else
		 begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
		end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}

/***************************************************************************************************************
* Function			: LPF_EDI_getDataSource()
* Description		: Retrieve a javascript function from Tools Server as a pre-requisite for LPF_EDI_getValue() and LPF_EDI_displayValue()
* Parameter Usage	: URL - the URL to get data source
*                   para - the parameters to be passed to the URL
* Location			: /hk/personal/common/js/pfscommon.js
* Author				: Ryan Lam (DMI)
* Creation Date	: 21 May 2004
* Side effect		: N/A
* Amendment History	:
* Date		By					Description
* ---------	------------	--------------------------------------------------------------------------------
*
***************************************************************************************************************/
function LPF_EDI_getDataSource(dataSourceURL, parameter)
{
	var ord=Math.random();
	ord=ord*10000000000000000000;
	if (parameter == undefined || parameter == null || parameter.length==0)
		parameter = "";
	else
		parameter = "&" + parameter;
		
	document.write('<SCRIPT LANGUAGE="JavaScript" SRC="' + dataSourceURL + '?ord='+ord+ parameter + '"><\/SCRIPT>');
}

/***************************************************************************************************************
* Function			: LPF_EDI_displayValue()
* Description		: Display the values get from Tools server. Display empty string if no value or invalid value is returned
* Parameter Usage	: index1, index2, index3 - indices to retrieve corresponding value
* Location			: /hk/personal/common/js/pfscommon.js
* Author				: Ryan Lam (DMI)
* Creation Date	: 21 May 2004
* Side effect		: N/A
* Amendment History	:
* Date		By					Description
* ---------	------------	--------------------------------------------------------------------------------
*
***************************************************************************************************************/
function LPF_EDI_displayValue(idx1, idx2, idx3)
{
	var output = "";
	if (arguments.length ==3){
		output = LPF_EDI_getValue(idx1, idx2, idx3);
	} else if (arguments.length == 2){
		output = LPF_EDI_getValue(idx1, idx2);
	} else {
		output = LPF_EDI_getValue(idx1);		
	}

	if (output == "#/#invalid_data#/#"){
		output = "";
	}
	document.write(output);
}

/***************************************************************************************************************
* Function			: LPF_EDI_getValue()
* Description		: return the values get from Tools server. Return #/#invalid_data#/# if 
* Parameter Usage	: index1, index2, index3 - indices to retrieve corresponding value if no value or invalid value is returned
* Location			: /hk/personal/common/js/pfscommon.js
* Author				: Ryan Lam (DMI)
* Creation Date	: 21 May 2004
* Side effect		: N/A
* Amendment History	:
* Date		By					Description
* ---------	------------	--------------------------------------------------------------------------------
*
***************************************************************************************************************/
function LPF_EDI_getValue(idx1, idx2, idx3)
{
	var output = "#/#invalid_data#/#";
	var paraLength = arguments.length;
	try{
		if (idx3 == undefined || idx3.length == 0){
			paraLength = 2;
		}
		
		if (idx2 == undefined || idx2.length == 0){
			paraLength = 1;
		}

		var dataArray = LPF_EDI_getData();
		if (dataArray != undefined){
			if (paraLength == 3){
				output = dataArray[idx1][idx2][idx3];
			} else if (paraLength == 2){
				output = dataArray[idx1][idx2];	
			} else{
				output = dataArray[idx1];	
			}
		}
		
		if (output == undefined){
			output = "#/#invalid_data#/#";
		}
	} catch (e){
		output = "#/#invalid_data#/#";
	}
	return(output);
}

/***************************************************************************************************************
* Function			: LPF_isCookieEnabled()
* Description		: Check if the browser supports cookies
* Parameter Usage	: N/A
* Location			: /hk/personal/common/js/pfscommon.js
* Author				: Fai Leung (elight Software Limited)
* Creation Date	: 28 Jun 2004
* Side effect		: N/A
* Amendment History:
* Date		By					Description
* ---------	------------	--------------------------------------------------------------------------------
***************************************************************************************************************/
function LPF_isCookieEnabled()
{
	LPF_setCookie("cookieEnabled","true");
	var temp = LPF_getCookie("cookieEnabled");
	if (temp == "true")
		return (true);
	else
		return (false);
}

/***************************************************************************************************************
* Function			: LPF_deleteCookie(name, path, domain)
* Description		: To delete a specific cookie
* Parameter Usage	: name: name of the cookie
*						: path: path of the cookie (must be same as path used to create cookie)
*						: domain: domain of the cookie (must be same as domain used to create cookie)
* Location			: /hk/personal/common/js/pfscommon.js
* Author				: Fai Leung (elight Software Limited)
* Creation Date	: 5 Jul 2004
* Side effect		: N/A
* Amendment History:
* Date		By					Description
* ---------	------------	--------------------------------------------------------------------------------
***************************************************************************************************************/
function LPF_deleteCookie(name, path, domain)
{
	if (LPF_getCookie(name))
	{
		document.cookie = name + "=" + 
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}


	
/***************************************************************************************************************
* Function		: LPF_YahooBeacon(secure, beacon)
* Description		: Yahoo beacon for page tracking
* Parameter Usage	: secure	: A 'y' or 'n' to indicate whether it is a secure site
*			: Beacon value  : provided by Yahoo e.g. 96665605		
* Location		: /hk/personal/common/pfscommon.js
* Author		: Herman
* Creation Date		: 9 Jul 2004
* Side effect		: No
* Amendment History	:
* Date		By		Description
* ---------	------------	--------------------------------------------------------------------------------
***************************************************************************************************************/
function LPF_YahooBeacon(secure,beacon)
{
var b=beacon;	
var r=Math.random();
var temp = "<img width=1 height=1 border=0 ";
document.write(temp);
if (secure == "y")
		{
		// if secure = 'y' then execute tag in secure environment
		var temp1 = "src=\"https://pclick.yahoo.com/p/s="+b+"/lng=b5/rand="+r+"\">";
		document.write(temp1);
		}
	else
		{
		// if secure = 'n' then execute tag in public environment
		var temp2 = "src=\"http://pclick.yahoo.com/p/s="+b+"/lng=b5/rand="+r+"\">";
		document.write(temp2);
		}
}

/***************************************************************************************************************
* Function		: LPF_championChallengerGetURL(unit, url1, url2, url3, url4...)
* Description		: Depends on the current time to display different URLs.
* Parameter Usage	: unit - "s" for second, "m" for minute, "h" for hour. This variable specify which component
*                                of current time is used to determine which URL will be directed.
*                         url1 - first URL 
*                         url2 - second URL
*                         url3 - third URL
*                         urln - nth URL
* Sample use            : LocalPredefinedFunction('LPF_championChallengerGetURL;m;http://www.hsbc.com.hk;http://www.hsbc.com.hk/hk/personal;http://www.hsbc.com.hk/hk/chinese/personal')
*                         This will return the URL http://www.hsbc.com.hk as a string if the current minute modulus 3 is equal to 0.
*                         or return the URL www.hsbc.com.hk/hk/personal if current minute modulus 3 is equal to 1.
*                         or return the URL www.hsbc.com.hk/hk/chinese/personal if current minute modulus 3 is equal to 2.
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Ryan Lam (DMI)
* Creation Date	: 21 Jul 2004
* Side effect		: N/A
* Remarks			: To call this function directly without using LocalPredefinedFunction, 
*						  You will need to create an array to store all the parameters and then pass
*                   the array as the only parameter into this function.
* Amendment History	:
* Date		By					Description
* ---------	------------	--------------------------------------------------------------------------------
*
***************************************************************************************************************/
function LPF_championChallengerGetURL()
{
	var params = arguments[0];
	var unit = params[0];
	var argLength = params.length;
		
	var currDate = new Date();
	var mod = 0;
	
	switch (unit){
		case "s":
			mod = currDate.getSeconds();
			break;
		case "h":
			mod = currDate.getHours();
			break;
		case "m":
			mod = currDate.getMinutes();
			break;
		//default case
		default:
			mod = currDate.getMinutes();
			break;
	}
	return String(params[(mod % (argLength - 1) + 1)]);
}

/***************************************************************************************************************
* Function		: LPF_championChallenger(unit, url1, url2, url3, url4...)
* Description		: Depends on the current time to display different URLs.
* Parameter Usage	: unit - "s" for second, "m" for minute, "h" for hour. This variable specify which component
*                                of current time is used to determine which URL will be directed.
*                         url1 - first URL 
*                         url2 - second URL
*                         url3 - third URL
*                         urln - nth URL
* Sample use            : LPF_championChallenger("m", "www.hsbc.com.hk", "www.hsbc.com.hk/hk/personal", "www.hsbc.com.hk/hk/chinese/personal")
*                         This will direct the current page to www.hsbc.com.hk if the current minute modulus 3 is equal to 0.
*                         or direct the current page to www.hsbc.com.hk/hk/personal if current minute modulus 3 is equal to 1.
*                         or direct the current page to www.hsbc.com.hk/hk/chinese/personal if current minute modulus 3 is equal to 2.
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Ryan Lam (DMI)
* Creation Date	: 21 Jul 2004
* Side effect		: N/A
* Amendment History	:
* Pre-requisite	: LPF_championChallengerGetURL()
* Remarks			: To call this function directly without using LocalPredefinedFunction, 
*						  You will need to create an array to store all the parameters and then pass
*                   the array as the only parameter into this function.
* Date		By					Description
* ---------	------------	--------------------------------------------------------------------------------
*
***************************************************************************************************************/	
function LPF_championChallenger()
{
	window.location = LPF_championChallengerURL(arguments);
}


/***************************************************************************************************************
* Function		: LPF_bannerGo(), 
*			  LPF_bannerGo_link()
* Description		: To add a rotational linked banner
*			  LPF_bannerGo() - To change the image soure, link and the alt-tag according to the speed in the banner
*			  LPF_bannerGo_link() - To point the link of the corresponding banner to the current window
* Pre-requisite		: Must add the following code in the htm after the <body> tag:
*			  <form name="LPF_bannerGo_params" action="" style="margin:0pt">
*			  <input type="hidden" name="src" value="imgsrc1,imgsrc2,imgsrc3,...">
*			  <input type="hidden" name="link" value="link1,link2,link3,...">
*			  <input type="hidden" name="alt" value="alt1,alt2,alt3,...">
*			  <input type="hidden" name="speed" value="speed">
*			  <input type="hidden" name="whichimage" value="0">
*			  <input type="hidden" name="whichlink" value="0">
*			  </form>
* Parameter Usage	: src (mandatory) - image sources
*      			  link (mandatory) - the corresponding links of the specific images
*			  alt (mandatory) - corresponding alt tags of the images
*			  speed (mandatory) - the rotational speed of the banners (in millisecond, default = 2000)
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Anthony, Chan Yin Leung
* Creation Date		: 10 Aug 2004
* Side effect		: N/A
* Sample Function Call	: <a href="javascript:LocalPredefinedFunction('LPF_bannerGo_link')">
*			  <img src="http://www.hsbc.com.hk/regional/images/transpixel.gif" name="slide" border=0 height=100 width=400>
*			  </a>
*			  <script><!--LocalPredefinedFunction('LPF_bannerGo');//--></script>
* Remarks		: Must set the height and width of the banner in the img tag to ensure proper display in different browsers
* Amendment History:
* Date		By					Description
* ---------	------------	--------------------------------------------------------------------------------
***************************************************************************************************************/

function LPF_bannerGo_link()
{	
	var link = document.LPF_bannerGo_params.link.value;
	var link_params = link.split(",");
	window.open(link_params[document.LPF_bannerGo_params.whichlink.value]);
}

function LPF_bannerGo()
{	
	var src = document.LPF_bannerGo_params.src.value;
	var src_params = src.split(",");
	
	var alt = document.LPF_bannerGo_params.alt.value;
	var alt_params = alt.split(",");
	
	document.images.slide.src=src_params[document.LPF_bannerGo_params.whichimage.value];
	document.images.slide.alt=alt_params[document.LPF_bannerGo_params.whichimage.value];
	
	document.LPF_bannerGo_params.whichlink.value = document.LPF_bannerGo_params.whichimage.value;
	
	if (document.LPF_bannerGo_params.whichimage.value<src_params.length-1)
		document.LPF_bannerGo_params.whichimage.value++;
	else
		document.LPF_bannerGo_params.whichimage.value=0;
	
	setTimeout("LPF_bannerGo()",document.LPF_bannerGo_params.speed.value);
}
/***************************************************************************************************************
* Function		: LPF_bannerRandom
* Description		: To generate a different banner each time when visiting a page. 
* Pre-requisite		: The number of arguments must be even. The order should be <src1> <src2> <src3> <alt1> <alt2> <alt3>
*			  The first SRC is referring to the (length/2+1) th ALT. The second one is referring to the (length/2+2) th ALT,
*			  so on and so forth.
* Parameter Usage	: params (mandatory) - holding all the arguments (described in Pre-requisite)
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Arnold, Chow Kwok Cheong
* Creation Date		: 13 Oct 2004
* Side effect		: N/A
* Sample Function Call	: <a href="/hk/personal/pushtotalk/redirect_ptt.htm?wtfrom=afford_c" target="_blank">
*		  	  <img src="/regional/images/transpixel.gif" name="target_slide" border="0" height="90" width="150">
*		          </a>		   
*		          <script language="JavaScript" type="text/javascript">LocalPredefinedFunction
*			  ('LPF_bannerRandom;/hk/personal/pushtotalk/ptt_image1_chi.gif;/hk/personal/pushtotalk/ptt_image2_chi.gif;
*			  /hk/personal/pushtotalk/ptt_image3_chi.gif;PTTimage1;PTTimage2;PTTimage3')</script>		                  
* Remarks		: Must set the height and width of the banner in the img tag to ensure proper display in different browsers
*			  There are some limitations that this function does not support multiple hyperlinks on multple images. Also, 
*			  this function can only be used once in a page.
* Amendment History:
* Date		By					Description
* ---------	------------	--------------------------------------------------------------------------------
***************************************************************************************************************/

function LPF_bannerRandom()
{
	var params=new Array();
	params = arguments[0];
	var num = Math.ceil(Math.random() * params.length/2);
	document.images.target_slide.src=params[num-1];
	document.images.target_slide.alt=params[num-1+params.length/2];	
	
}

/***************************************************************************************************************
* Function			: LPF_setKeyword()
* Description		: Appends the keyword onto the Search url
* Parameter Usage	: 
* destURL			: URL of the Search url
* Location			: /hk/personal/common/js/pfscommon.js
* Author				: Keith Mak (DMI)
* Creation Date	: 19 Nov 2004
* Side effect		: N/A
* Amendment History:
* Date		By					Description
* ---------	------------	--------------------------------------------------------------------------------
***************************************************************************************************************/
function LPF_setKeyword()
{
	var endAction = "";	
	var keyword = String(document.searchform.keyword2.value);
	var action = String(document.searchform.action);

	if (keyword != null || keyword.length != 0 || keyword != ""){	
		if (action.indexOf("search_keyword=") != -1){
			var params = action.split("&");
			endAction = params[0];
			for (var i = 1; i<params.length; i++)
			{							
				if (params[i].indexOf("search_keyword=") == -1)
					endAction = endAction + "&" + params[i];
			 	else
					endAction = endAction + "&search_keyword=" + keyword;
			}
		}
		else 
		{
			endAction = action + "&search_keyword=" + keyword ;
		}
	}
	document.searchform.action = endAction;
}


/***************************************************************************************************************
* Function		: Goto_mthspc()
* Description		: Go to the Special of the Month page
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Angela Mak
* Creation Date		: 9 Nov 2004
* Side effect		: N/A
*
***************************************************************************************************************/
function LPF_Goto_mthspc()
{
	document.special.submit();
}

/***************************************************************************************************************
* Function		: Goto_luckydraw()
* Description		: Go to the Super Rewards Lucky Draw page
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Angela Mak
* Creation Date		: 9 Nov 2004
* Side effect		: N/A
*
***************************************************************************************************************/
function LPF_Goto_luckydraw()
{
	document.lucky.submit();
}


/***************************************************************************************************************
* Function			: LPF_Reset_Form(formname)
* Description		: Reset a form
* Parameter Usage	: formname - name of the form
* Location			: /hk/personal/common/js/pfscommon.js
* Author				: Arnold Chan (Gray Interactive)
* Creation Date	: 29 Nov 2004
* Side effect		: N/A
* Projects			: Mortgage
* Amendment History:
* Date		By	 				Description
* ---------	------------	--------------------------------------------------------------------------------
***************************************************************************************************************/
function LPF_Reset_Form(formname)
{
	document.forms[formname].reset();
}






/***************************************************************************************************************
* Function		: LPF_TextBoxAutoTab(formName, box1, box1MaxLength, box2)
* Description		: Auto tab to next text box when the parent text box reach its maxlength, this function
*                     doesn't support Netscape
* Parameter Usage	: formName - the name of the involved form
*                     box1 - the first box
*                     box1MaxLength - the maxlength of box1
*                     box2 - the second box
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: XM HK
* Creation Date		: 30 November 2004
* Side effect		: N/A
* Amendment History:
* Date		By					Description
* ---------	------------	--------------------------------------------------------------------------------
***************************************************************************************************************/
function LPF_TextBoxAutoTab(formName, box1, box1MaxLength, box2)
{
	var objForm = document.forms[formName];
	var objBox1 = objForm.elements[box1];
	var objBox2 = objForm.elements[box2];
	
	var isNN = (navigator.appName.indexOf("Netscape") != -1);

	if (!isNN) {
		var keyCode = window.event.keyCode;
		var filter = [0,8,9,16,17,18,37,38,39,40,46];
		if(objBox1.value.length >= box1MaxLength && !LPF_ContainsElement(filter, keyCode)) {
			objBox1.value = objBox1.value.slice(0, box1MaxLength);
			objBox2.focus();
		}
	}

	return true;
}


/***************************************************************************************************************
* Function		: LPF_ContainsElement()
* Description		: check element 
* Parameter Usage	: arr - the filter array, self define delimiter
*                     ele - the client character
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: XM HK
* Creation Date		: 30 November 2004
* Side effect		: N/A
* Amendment History:
* Date		By					Description
* ---------	------------	--------------------------------------------------------------------------------
***************************************************************************************************************/
function LPF_ContainsElement(arr, ele) {
	var found = false, index = 0;
	while(!found && index < arr.length)
		if(arr[index] == ele)
			found = true;
		else
			index++;
	return found;
}




/***************************************************************************************************************
* Function		: LPF_amhRtPromo(titlecontent, bodycontent, imagepath, landingurl)
* Description		: Generate HTML code for AMH Hope Page right promotion chunks
* Parameter Usage	: titlecontent: Promotion title in HTML
			: bodycontent: Promotion body in HTML
			: imagepath: Path to the promotion picture
			: landingurl: URL of the Promotion detail page
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Joseph Chan (XM)
* Creation Date		: 19 July 2005
* Side effect		: N/A
* Amendment History	:
* Date		By					Description
* ---------	------------	--------------------------------------------------------------------------------
***************************************************************************************************************/
function LPF_amhRtPromo(titlecontent, bodycontent, imagepath, landingurl) {
	var str = '';

	str = str + '<table border="0" cellspacing="0" cellpadding="0">';
	str = str + '<tr valign="top">';
	str = str + '<td><img src="/regional/images/transpixel.gif" width="1" height="10" alt=""></td>';
	str = str + '<td><img src="/regional/images/transpixel.gif" width="7" height="1" alt=""></td>';
	str = str + '<td width="100%"></td>';
	str = str + '</tr>';
	str = str + '<tr valign="top"> ';
	str = str + '<td> <a href="' + landingurl + '">' + imagepath + '</a></td>';
	str = str + '<td rowspan="2"><img src="/regional/images/transpixel.gif" width="7" height="1" alt=""></td>';
	str = str + '<td><span class="special_title">' + titlecontent + '</span><br>';
	str = str + '<span class="special">' + bodycontent + '</span></td>';
	str = str + '</tr>';
	str = str + '</table>';
	return str;
}

/***************************************************************************************************************
* Function		: LPF_htmlRandomizer(str)
* Description		: Randomly display 1 chunk of HTML from a number of chunks (delimited by semicolon)
* Parameter Usage	: str: a number of HTML chunks delimited by semicolon, in the format of "html1;html2;..."
			  (note: it is assumed that an HTML chunk must not contain any semicolon characters,
			   but it may contain the string "%59" which will be converted to a semicolon later)
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Joseph Chan (XM)
* Creation Date		: 19 July 2005
* Side effect		: N/A
* Amendment History	:
* Date		By					Description
* ---------	------------	--------------------------------------------------------------------------------
***************************************************************************************************************/
function LPF_htmlRandomizer(htmlarraystr) {
	var htmlarray = htmlarraystr.split(";");
	var num = Math.ceil(Math.random() * htmlarray.length) -1;
	document.write(LPF_semicolonUnescape(htmlarray[num]));
}

/***************************************************************************************************************
* Function		: LPF_semicolonUnescape(str)
* Description		: Change %59 to the semicolon character
* Parameter Usage	: str: an input string
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Joseph Chan (XM)
* Creation Date		: 20 July 2005
* Side effect		: N/A
* Amendment History	:
* Date		By					Description
* ---------	------------	--------------------------------------------------------------------------------
*
***************************************************************************************************************/
function LPF_semicolonUnescape(str)
{
	var strarray = str.split("%59");
	var result = strarray.join(";");
	return result;
}


/***************************************************************************************************************
* Function		: LPF_amhPromo(strarray)
* Description		: Randomly display 1 chunk of HTML from multiple chunks of promotions.
* Parameter Usage	: strarray: a string of parameters in format of "title1;body1;image1;url1;title2;body2;image2;url2;...",
			 where  titlex: Promotion title in HTML
				bodyx: Promotion body in HTML
				imagex: Path to the promotion picture
				urlx: URL of the Promotion detail page
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Joseph Chan (XM)
* Creation Date		: 26 July 2005
* Side effect		: N/A
* Amendment History	:
* Date		By					Description
* ---------	------------	--------------------------------------------------------------------------------
***************************************************************************************************************/
function LPF_amhPromo(strarray)
{
	var num = Math.floor(strarray.length/4);
	var str = '';
	var i;
	for (i=0; i<num; i++)
	{
		str = str + LPF_amhRtPromo(strarray[i*4],strarray[i*4+1],strarray[i*4+2],strarray[i*4+3]);
		if (i<num-1)
		{
			str = str + ";";
		}
	}

	LPF_htmlRandomizer(str);
}


/***************************************************************************************************************
* Function		: SiteCensusAdTag(datanode, media_acct_id, result_id, revenue)
* Description		: Display SiteCensus Ad-Intelligence Tag
* Parameter Usage	: datanode	: an id to locate the company for the tracking
			  media_acct_id	: an id to identify the account
			  result_id	: text appear when the image is being loaded or mouseover
			  revenue	: a revenue id
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Rongen Cheng
* Creation Date		: 07 September 2005
* Side effect		: N/A
* Amendment History	:
* Date		By					Description
* ---------	------------	--------------------------------------------------------------------------------
***************************************************************************************************************/
function SiteCensusAdTag(datanode, media_acct_id, result_id, revenue)
{
	var _rsRD=0;
        if (parseInt(navigator.appVersion)>=4) {
        _rsRD=(new Date()).getTime();
        }
        document.write('<img src="//'+datanode+'.imrworldwide.com/cgi-bin/a/ci_'+media_acct_id+'/et_3/ri_'+result_id+'/rv_'+revenue+'/rd_'+_rsRD+'" width="1" height="1" alt="'+result_id+'">');
}

/***************************************************************************************************************
* Function		: LPF_Close()
* Description		: Close Current Windows
* Parameter Usage	: 
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Johnny Mak (TribalDDB HK)
* Creation Date		: 24 Dec 2005
* Side effect		: N/A
* Amendment History	:
* Date		By		Description
* ---------	------------	--------------------------------------------------------------------------------
*
***************************************************************************************************************/
function LPF_Close()
{
	self.close();
}
/***************************************************************************************************************
* Function		: 	LPF_CheckParam(name, value, poppage)
* Description	: 	Get the parameter from querystring of URL, popup a new 
						window if parameter equals certain value
* Parameter Usage	: 	name - name of the parameter
							value - checking value 
							poppage - the url of the pop up page
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Wendy Iu
* Creation Date		: 22 Feb 2006
* Side effect		: N/A
* Amendment History	:
* Date		By		Description
* ---------	------------	--------------------------------------------------------------------------------
*
***************************************************************************************************************/
function LPF_CheckParam(name,value,poppage)
		{
			var s=location.search;
			var reg=new RegExp('.*'+name+'=([^&]*).*');
			s=s.replace(reg,'$1');
			if(s.toLowerCase()==value) 
				{
					window.open(poppage,'','toolbar=no, location=no, menubar=no, left=191, top=177,resizable=yes, width=622, height=307');	
				}
			reg=null;
		}

/***************************************************************************************************************
* Function				:	LPF_randomAMHImage(imgArrayStr)
* Description			:	HK Homepage random banner
* Parameter Usage	:	imgArrayStr - in the format of "imgSrc1,altText1,link1,imgSrc2,altText2,link2..."
*										where	imgSrc1, imgSrc2 ... 		= image path
*													altText1, altText2 ... 	= image's alt text
*													link1, link2 ...				= destination of the image. If link1="", no hyperlink
*																										will be assigned to that image
* Location				: /hk/personal/common/js/pfscommon.js
* Author					: Lau Ching Yee, Katie
* Creation Date		: 1 June 2006
* Side effect			: N/A
* Amendment History	:
* Date      By             Description
* ---------	------------   --------------------------------------------------------------------------------
*
***************************************************************************************************************/
function LPF_randomAMHImage(imgArrayStr)
{
	var imgArray = imgArrayStr.split(",");

	if((imgArray.length / 3) != Math.ceil(imgArray.length/3)) {
		alert("Invalid parameters for LPF_randomAMHImage!\nIt must be in format of imgSrc1,altText1,link1,imgSrc2,altText2,link2...");
	} else {
		var num = ((Math.ceil(Math.random() * (imgArray.length / 3)))-1)*3;
		if(imgArray[num+2] != ""){
			document.write("<a href=\"javascript:LocalPredefinedFunction('Popup_newBrowser;"+imgArray[num+2]+";yes;no;yes;no;no;yes;650;450;topbanner');\"><img src=\""+imgArray[num]+"\" border=\"0\" alt=\""+imgArray[num+1]+"\" width=407 height=100></a>");
		} else {
			document.write("<img src=\""+imgArray[num]+"\" border=\"0\" alt=\""+imgArray[num+1]+"\" width=407 height=100>");
		}
	}
	imgArray = null;
}