var jsvMaxcharLengthArray = Array();

var jsvIsIE501 = navigator.userAgent.indexOf("MSIE 5.01") > 0 ? true : false;
var jsvIsNN6 = navigator.userAgent.indexOf("Netscape6") > 0 ? true : false;
var jsvIsIE=document.all&&navigator.userAgent.indexOf("Opera")==-1;

//Event.observe(window, 'load', pws_jsfInit, false);


function pws_jsfTogglePage(self)
{
	if (jsvIsIE) 
	{
		var container = self.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement;
		var element1 = container.nextSibling;
		var element2 = element1.nextSibling;
		
		self.parentElement.parentElement.className="selected";
		if (self.parentElement.parentElement.nextSibling != null)
			self.parentElement.parentElement.nextSibling.className="";
		if (self.parentElement.parentElement.previousSibling != null)
			self.parentElement.parentElement.previousSibling.className="";
		
		
		if (element1.style.display == "none")
		{
			element1.style.display = "";
			element2.style.display = "none";
		} else {
			element1.style.display = "none";
			element2.style.display = "";
		}
	} else {
		var container = self.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
		var element1 = container.nextSibling.nextSibling;
		var element2 = element1.nextSibling.nextSibling;
		
		self.parentNode.parentNode.className="selected";
		if (self.parentNode.parentNode.nextSibling.nextSibling != null)
			self.parentNode.parentNode.nextSibling.nextSibling.className="";
		if (self.parentNode.parentNode.previousSibling.previousSibling != null)
			self.parentNode.parentNode.previousSibling.previousSibling.className="";
		
		if (element1.style.display == "none")
		{
			element1.style.display = "";
			element2.style.display = "none";
		} else {
			element1.style.display = "none";
			element2.style.display = "";
		}
	}
}

function pws_getElementsByName_iefix(tag, name)
{
     var elem = document.getElementsByTagName(tag);
     var arr = new Array();
     for(i = 0,iarr = 0; i < elem.length; i++) {
          att = elem[i].getAttribute("name");
          if(att == name) {
               arr[iarr] = elem[i];
               iarr++;
          }
     }
     return arr;
}

function pws_contractAll()
{
	var togs, contents;
	
	if (jsvIsIE)
	{
		togs = pws_getElementsByName_iefix("div", "reduceToggle");
		contents = pws_getElementsByName_iefix("div", "content");
	}
	else
	{
		togs = document.getElementsByName("reduceToggle");
		contents = document.getElementsByName("content");
	}
	
	for (i=0; i<togs.length; i++)
	{
		togs[i].style.display = "none";
		contents[i].style.display = "none";
	}
}

function pws_jsfToggleMenu(self)
{
	if (jsvIsIE) 
	{
		if (self.parentElement.parentElement.children[0].style.display == "none")
		{
			self.parentElement.parentElement.children[0].style.display = "";
			self.parentElement.parentElement.children[1].style.display = "none";
			self.parentElement.parentElement.parentElement.children[1].children[1].style.display = "none";
		} else {
			self.parentElement.parentElement.children[0].style.display = "none";
			self.parentElement.parentElement.children[1].style.display = "";
			self.parentElement.parentElement.parentElement.children[1].children[1].style.display = "";
		}
	} else {
		if (self.parentNode.parentNode.childNodes[1].style.display == "none")
		{
			self.parentNode.parentNode.childNodes[1].style.display = "";
			self.parentNode.parentNode.childNodes[3].style.display = "none";
			self.parentNode.parentNode.parentNode.childNodes[3].childNodes[3].style.display = "none";
		} else {
			self.parentNode.parentNode.childNodes[1].style.display = "none";
			self.parentNode.parentNode.childNodes[3].style.display = "";
			self.parentNode.parentNode.parentNode.childNodes[3].childNodes[3].style.display = "";
		}
	}
}

function pws_jsfInit()
{
	pws_jsfBalanceTables();
}

function pws_jsfBalanceTables()
{
	tables = document.getElementsByClassName("jsBalanceColumns");
	//exit if there is only one table
	if(tables.length<2)
	{
		return;
	}
	var firstTRFound;
	//count all letters in cells get maxium for each column
	for(a=0;a<tables.length;a++)
	{
		firstTRFound = false;
		//find TBODY
		for(b=0;b<tables[a].childNodes.length;b++)
		{
			if(tables[a].childNodes[b].nodeName=="TBODY")
			{
				//get first TR
				for(c=0;c<tables[a].childNodes[b].childNodes.length;c++)
				{
					if(tables[a].childNodes[b].childNodes[c].nodeName=="TR"&&!firstTRFound)
					{
						firstTRFound = true;
						pws_jsfCollectCellTextLength(tables[a].childNodes[b].childNodes[c]);
					}
				}
			}
		}
	}
	//convert values into percentages
	columnWidthArray = pws_jsfConvertValuesToPercentage(jsvMaxcharLengthArray);
	
	for(a=0;a<tables.length;a++)
	{
		firstTRFound = false;
		//find TBODY
		for(b=0;b<tables[a].childNodes.length;b++)
		{
			if(tables[a].childNodes[b].nodeName=="TBODY")
			{
				//get first TR
				for(c=0;c<tables[a].childNodes[b].childNodes.length;c++)
				{
					if(tables[a].childNodes[b].childNodes[c].nodeName=="TR"&&!firstTRFound)
					{
						//set column widths
						firstTRFound = true;
						pws_setColumnWidths(columnWidthArray,tables[a].childNodes[b].childNodes[c]);
						
					}
				}
			}
		}
	}
}

function pws_jsfConvertValuesToPercentage(theArray)
{
	totalValue = 0;
	for(f=0;f<theArray.length;f++)
	{
		totalValue+=theArray[f];
	}
	percArray = Array();
	for(f=0;f<theArray.length;f++)
	{
		percArray.push(Math.round(theArray[f]/totalValue*100));
	}
	return percArray;
}

function pws_setColumnWidths(widthArray,row)
{
	cell = 0;
	for(g=0;g<row.childNodes.length;g++)
	{
		if(row.childNodes[g].nodeName=="TD"||row.childNodes[g].nodeName=="TH")
		{
			if (row.childNodes[g].colSpan != null && row.childNodes[g].colSpan > 1)
			{
				var tempLength = 0;
				for (i=0; i<row.childNodes[g].colSpan; i++)
				{
					tempLength += widthArray[cell+i];
				}
				row.childNodes[g].style.width=tempLength+"%";
//				row.childNodes[g].style.width=(widthArray[cell]*row.childNodes[g].colSpan)+"%";
				cell+=row.childNodes[g].colSpan;
			}
			else
			{
				row.childNodes[g].style.width=widthArray[cell]+"%";
				cell++;
			}
		}
	}
}

function pws_jsfCollectCellTextLength(row)
{
	if(row==null)
	{
		return;	
	}
	firstPass = jsvMaxcharLengthArray.length==0?true:false;
	
	cell = 0;
	//go through each td/th
	for(d=0;d<row.childNodes.length;d++)
	{
		//find TD or TH
		if((row.childNodes[d].nodeName=="TD"||row.childNodes[d].nodeName=="TH"))
		{
			for(e=0;e<row.childNodes[d].childNodes.length;e++)
			{
				//find text node
				if(row.childNodes[d].childNodes[e].nodeType==3)
				{
					//alert(row.childNodes[d].childNodes[e].nodeValue);
					if(firstPass)
					{
						if (row.childNodes[d].colSpan != null && row.childNodes[d].colSpan > 1)
						{
							for (x=0; x<row.childNodes[d].colSpan; x++)
							{
								jsvMaxcharLengthArray.push((pws_getStringDisplayLength(row.childNodes[d].childNodes[e].nodeValue)/row.childNodes[d].colSpan));
							}
						}
						else
						{
							jsvMaxcharLengthArray.push(pws_getStringDisplayLength(row.childNodes[d].childNodes[e].nodeValue));
						}
					}
					else
					{
						
						if (row.childNodes[d].colSpan != null)
						{
							for (x=0; x<row.childNodes[d].colSpan; x++)
							{
								jsvMaxcharLengthArray[cell+x] = jsvMaxcharLengthArray[cell+x]<(pws_getStringDisplayLength(row.childNodes[d].childNodes[e].nodeValue) / row.childNodes[d].colSpan)?(pws_getStringDisplayLength(row.childNodes[d].childNodes[e].nodeValue) / row.childNodes[d].colSpan):jsvMaxcharLengthArray[cell+x];
							}
							cell+=row.childNodes[d].colSpan;
						} 
						else
						{
							jsvMaxcharLengthArray[cell] = jsvMaxcharLengthArray[cell]<pws_getStringDisplayLength(row.childNodes[d].childNodes[e].nodeValue)?pws_getStringDisplayLength(row.childNodes[d].childNodes[e].nodeValue):jsvMaxcharLengthArray[cell];
							cell++;
						}
					}
				}
			}
		}
	}
	//find the next row in the table and recurse
	pws_jsfCollectCellTextLength(pws_getNextSibling(row,"TR"));
}


function pws_getStringDisplayLength(theString)
{
	theLength = 0;
	for(i=0;i<theString.length;i++)		
	{
		theLength+=(pws_getCharDisplayLength(theString.charAt(i)));
	}
	return theLength;
}

function pws_getCharDisplayLength(theChar)
{
	switch(theChar)
	{
		case 'i':
		case 'j':
		case 'i':
		case 'j':
		case '.':
		case ',':
			return 1;
		case 'f':
		case 'r':
		case 't':
			return 3;
		case 'k':
		case 's':
		case 'J':
			return 4;
		case 'i':
		case 'j':
		case 'l':
		case 'I':
		case '.':
		case ',':
		case 'f':
		case 'r':
		case 't':
		case 'k':
		case 's':
		case 'J':
		case 'a':
		case 'b':
		case 'c':
		case 'd':
		case 'e':
		case 'g':
		case 'h':
		case 'n':
		case 'o':
		case 'p':
		case 'q':
		case 'u':
		case 'v':
		case 'x':
		case 'Y':
		case 'z':
		case 'E':
		case 'F':
		case 'L':
		case 'P':
		case 'T':
		case '1':
		case '2':
		case '3':
		case '4':
		case '5':
		case '6':
		case '7':
		case '8':
		case '9':
		case '(':
		case ')':
		case '/':
			return 5;
		case 'B':
		case 'C':
		case 'D':
		case 'H':
		case 'K':
		case 'N':
		case 'R':
		case 'S':
		case 'U':
		case 'V':
		case 'X':
		case 'Z':
		case '0':
		case '%':
			return 6;
		case 'm':
		case 'A':
		case 'G':
		case 'M':
		case 'O':
		case 'Q':
		case 'Y':
			return 8;
		case 'w':
		case 'W':
			return 11;
		default:
			return 0;
	}
}

function pws_getNextSibling(object,siblingNodeName)
{
	if(object.nextSibling!=null)
	{
		if(object.nextSibling.nodeName==siblingNodeName)
		{
			return object.nextSibling;
		}
		else
		{
			return pws_getNextSibling(object.nextSibling,siblingNodeName);
		}
	}
}

function pws_hbap_popupWin(helpUrl ,widthSize, heightSize) {
var search_string=location.search;
var rs_url="";
var wedTrends_unit = "";
var reg = /WT.mc_id/;
	if(search_string == null || search_string.length == 0){
		rs_url = helpUrl;
	}
	else{
		var mat_index = search_string.search(reg);
		if (mat_index >= 0) {
			var temp = search_string.substring(mat_index);	
			var index_and = temp.search(/&/);
			if(index_and > 0){
				wedTrends_unit = temp.substring(0, index_and);			
			} else {
				wedTrends_unit = temp;			
			}	
			if (helpUrl.indexOf("?") > 0) {	
				rs_url=helpUrl + "&" + wedTrends_unit ;
			} else {
				rs_url=helpUrl + "?" + wedTrends_unit ;
			}
		
		}else {
			rs_url = helpUrl;
		}	
	}
   if(widthSize != null && heightSize != null){   
   	var popWin = window.open(rs_url,"onlinehsbc","width="+widthSize+",height="+heightSize);   	
   } else {   
   	var popWin = window.open(rs_url);
   }	 
	popWin.focus();		
}

function pws_show_TandC(loc,windoc) {

if(loc==null || windoc==null) {
	return ;
}

var urlpath=loc.hash;

if ( (urlpath == null) || (urlpath == "")) {
	return;
}
<!--urlpath must have at least one word after "#"-->
if ( urlpath.length < 2) {
	return;	
}
var id = urlpath.substring(1);
var show_postfix="_s";
var hide_postfix="_h";
var content_postfix="_c";



if ((windoc.getElementById(id+show_postfix)!= null) && (windoc.getElementById(id+hide_postfix)!= null)
		 && (windoc.getElementById(id+content_postfix)!= null) ){

	if ((windoc.getElementById(id+show_postfix).style!= null) && (windoc.getElementById(id+hide_postfix).style!= null)
			&& (windoc.getElementById(id+content_postfix).style!= null) ) {
			
			if ( (windoc.getElementById(id+show_postfix).style.display!= null) 
				&& (windoc.getElementById(id+hide_postfix).style.display!= null) 
				&& (windoc.getElementById(id+content_postfix).style.display!= null) ) {
				
				windoc.getElementById(id+show_postfix).style.display = "none";
				windoc.getElementById(id+hide_postfix).style.display = "";
				windoc.getElementById(id+content_postfix).style.display = "";
				
			}
	}
}



}

function pws_digitalOrder_en(formname, cookievalue)
{
	pws_popupNewBrowser('', 'yes', 'no', 'yes', 'no', 'no', 'yes', screen.width, screen.height*0.88);

	pws_setCookie('FromWebSite', cookievalue, '/', '.hsbc.com.hk', 'true', 0);

	document.forms[formname].action = 'https://www.ebanking.hsbc.com.hk/1/2/logon?LANGTAG=en&COUNTRYTAG=US';
	document.forms[formname].submit();	
}

function pws_digitalOrder_zh(formname, cookievalue)
{
	pws_popupNewBrowser('', 'yes', 'no', 'yes', 'no', 'no', 'yes', screen.width, screen.height*0.88);

	pws_setCookie('FromWebSite', cookievalue, '/', '.hsbc.com.hk', 'true', 0);

	document.forms[formname].action = 'https://www.ebanking.hsbc.com.hk/1/2/logon?LANGTAG=zh&COUNTRYTAG=HK';
	document.forms[formname].submit();	
}


function pws_popupNewBrowser(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=0,top=0');
	nb.focus();
}

function pws_setCookie(name, value, path, domain, secure, expires)
{
    document.cookie = name + '=' + escape(value) +
    ((path) ? '; path=' + path : '') +
    ((domain) ? '; domain=' + domain : '') +
    ((secure) ? ';secure' : '')+
    ((expires) ? ';expires=' + expires.toGMTString() : '') ;
}

function pws_logon_en() {
	pws_popupNewBrowser('https://www.ebanking.hsbc.com.hk/1/2/logon?LANGTAG=en&COUNTRYTAG=US', 'yes', 'no', 'yes', 'no', 'no', 'yes', screen.width, screen.height*0.88);
}

function pws_logon_zh() {
	pws_popupNewBrowser('https://www.ebanking.hsbc.com.hk/1/2/logon?LANGTAG=zh&COUNTRYTAG=HK', 'yes', 'no', 'yes', 'no', 'no', 'yes', screen.width, screen.height*0.88);
}

function pws_register_en() {
	pws_popupNewBrowser('https://www.ebanking.hsbc.com.hk/1/2/P2GLandingPage?forReg=Y&LANGTAG=en&COUNTRYTAG=US', 'yes', 'no', 'yes', 'no', 'no', 'yes', screen.width, screen.height*0.88);
}

function pws_register_zh() {
	pws_popupNewBrowser('https://www.ebanking.hsbc.com.hk/1/2/P2GLandingPage?forReg=Y&LANGTAG=zh&COUNTRYTAG=HK', 'yes', 'no', 'yes', 'no', 'no', 'yes', screen.width, screen.height*0.88);
}

function pws_popupPdf(pdfUrl ,windowName, winProperties) {

var targetUrl=it_fullContextPath.substring(0,it_fullContextPath.length-1) + pdfUrl;
var hsbcheader='\n'
+ '    <html>\n'
+ '	    <script language="JavaScript" src="' + wt_header_url +'"><\/script>\n'
+ '	    <SCRIPT LANGUAGE="JavaScript">\n'
+ '		HSBC.SITE.rgn="HBAP";\n'
+ '		HSBC.SITE.subrgn="AMH";\n'
+ '		HSBC.SITE.cnty="HKSAR";\n'
+ '	        HSBC.SITE.ent="HSBC";\n'
+ '             HSBC.LOG.dcsuri="' + pdfUrl + '";\n'
+ '		HSBC.SITE.brand="HSBC";\n'
+ '  	  	HSBC.DCS.ID="dcsur62uf00000s5nnzq4hvrl_6i5x";\n'
+ '    <\/SCRIPT>\n'
+ '    <script language="JavaScript" src="' + wt_footer_url + '"><\/SCRIPT>'
+ '     <body onload="window.location=\'' + targetUrl + '\';"><\/body>'
+ '    </html>\n'
+ '    \n';

   var popWin;
   if(winProperties != null && winProperties.length>0){   
   	popWin = window.open('','_blank',winProperties);   	
   } else {   
   	popWin = window.open('');   	
   }
  	popWin.document.write(hsbcheader);
   	popWin.document.close(); 	
   	if(jsvIsIE){
	popWin.history.go(0); 
	}
	popWin.focus();		 	
}

function pws_transitPage(transitType, formname, fieldname, targetUrl,  width, height, winname){
	switch(transitType){
		case "TransitPulldown":
			if(formname == null || formname == "") {
				alert("Invalid parameters for TransitPage('transitType',???,'fieldname', 'targetUrl', 'width', 'height')");
			} else if(fieldname == null || fieldname == ""){
				alert("Invalid parameters for TransitPage('transitType','formname',???, 'targetUrl', 'width', 'height')");
			} else{
				var idx = document.forms[formname].elements[fieldname].selectedIndex;
				var v = document.forms[formname].elements[fieldname][idx].value;
				if(v != ""){					
					if (v.indexOf("?targetPage=") > 0){
						!winname? winname="nb":winname=winname;
						nb=window.open(v, winname, "status=no,location=no,scrollbars=no,menubar=no,toolbar=no,resizable=no,height=" + height + ",width=" + width + ",left=20,top=20");
						nb.focus();
					}else{
						alert("Please specify the target page using '?targetPage='.");
					}
					
				}
		
			}
			break;
		case "TransitClickOn":
		
			if(targetUrl == null || targetUrl == ""){
				alert("Invalid parameters for TransitPage('transitType','formname','fieldname', ???, 'width', 'height')");
			}else{
					if (targetUrl.indexOf("?targetPage=") > 0){
						!winname? winname="nb":winname=winname;
						nb=window.open(targetUrl, winname, "status=no,location=no,scrollbars=no,menubar=no,toolbar=no,resizable=no,height=" + height + ",width=" + width + ",left=20,top=20");
						nb.focus();
					}else{
						alert("Please specify the target page using '?targetPage='.");
					}				
			}
			break;
				
		default:
			break;	
		
	}
}

function pws_transitPage_Close()
{
	self.close();
}

function pws_targetPage(){
var search_string=location.search;
var target_page = "";
var indicator = "targetPage=";
var target_ind = search_string.indexOf(indicator);
if( target_ind > 0){
	temp = search_string.substring(indicator.length + 1);	
	var index_and = temp.search(/&/);
	if(index_and > 0){
		target_page = temp.substring(0, index_and) + "?" + temp.substring((index_and+1), temp.length);
	} else {
		target_page = temp;
	}
	
}else{
	target_page = "http://www.hsbc.com.hk";
}
var openwin = window.open(target_page);
openwin.focus();
}

/***************************************************************************************************************
*The following functions are migrated from pfscontrol.js and pfccommon.js in 1G PWS
***************************************************************************************************************/

function LocalPredefinedFunction(functionString)
{
	var params = functionString.split(";");

	switch(params[0])
	{

		/***************************************************************************************************************
		* 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
		*
		***************************************************************************************************************/
		case"Popup_newBrowser":
			if(params.length!=10 && params.length!=11)
			{
				alert("Invalid parameters for Popup_newBrowser - LocalPredefinedFunction('Popup_newBrowser;url;status;location;sbar;mbar;tbar;resize;height;width;winname')");
			}
			else
			{
				Popup_newBrowser(params[1], params[2], params[3], params[4], params[5], params[6], params[7], params[8], params[9], params[10]);
			}
			break;

		/***************************************************************************************************************
		* 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-13
		* Side effect		: No
		* Amendment History	:
		* Date		By		Description
		* ---------	------------	--------------------------------------------------------------------------------
		***************************************************************************************************************/
		case"DoubleClickAdTag":
			if(params.length!=6)
			{
				alert("Invalid parameters for DoubleClickAdTag - LocalPredefinedFunction('DoubleClickAdTag;placement;alttext;width;height;secure')");
			}
			else
			{
				DoubleClickAdTag(params[1], params[2], params[3], params[4], params[5]);
			}
			break;

		/***************************************************************************************************************
		* 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-13
		* Side effect		: No
		* Amendment History	:
		* Date		By		Description
		* ---------	------------	--------------------------------------------------------------------------------
		***************************************************************************************************************/
		case"DoubleClickSpotlightTag":
			if(params.length!=5)
			{
				alert("Invalid parameters for DoubleClickSpotlightTag - LocalPredefinedFunction('DoubleClickAdTag;src;type;cat;secure')");
			}
			else
			{
				DoubleClickSpotlightTag(params[1], params[2], params[3], params[4]);
			}
			break;

		/***************************************************************************************************************
		* Function		: LPF_DoubleClickLayer(layername)
		* Description		: Display DoubleClick Spotlight Tag in layer
		* Parameter Usage	: layername	: id of layer
		*			: 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		: Kenny Ho (XMHK)
		* Creation Date		: 2007-05-16
		* Side effect		: No
		* Amendment History	:
		* Date		By		Description
		* ---------	------------	--------------------------------------------------------------------------------
		***************************************************************************************************************/
		case"LPF_DoubleClickLayer":
			if(params.length!=6)
			{
				alert("Invalid parameters for LPF_DoubleClickLayer - LocalPredefinedFunction('LPF_DoubleClickLayer;layername;src;type;cat;secure')");
			}
			else
			{
				LPF_DoubleClickLayer(params[1], params[2], params[3], params[4], params[5]);
			}
			break;

		/***************************************************************************************************************
		* 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 - LPF_MouseOut() is exactly the same as function MM_swapImgRestore() in /hk/personal/card/common/js/cs01g.js
		***************************************************************************************************************/
		case "LPF_MouseOut":
			LPF_MouseOut();
			break;

		/***************************************************************************************************************
		* 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
		* ---------	------------	--------------------------------------------------------------------------------
		*
		***************************************************************************************************************/
		case "LPF_Print":
			LPF_Print();
			break;

		/***************************************************************************************************************
		* 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
		* ---------	------------	--------------------------------------------------------------------------------
		*
		***************************************************************************************************************/
		case "LPF_Redirect":
			if(params.length!=2)
			{
				alert("Invalid parameters for LPF_Redirect - LocalPredefinedFunction('LPF_Redirect;???')");
			}
			else
			{
				LPF_Redirect(params[1]);
      			}
			break;

		/***************************************************************************************************************
		* 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
		* ---------	------------	--------------------------------------------------------------------------------
		*
		***************************************************************************************************************/
		case"LPF_Digital_Order":
			if(params.length!=3)
			{
				alert("Invalid parameters for LPF_Digital_Order - LocalPredefinedFunction('LPF_Digital_Order;lang;cokkievalue')");
			}
			else
			{
				LPF_Digital_Order(params[1], params[2]);
			}
			break;

		/***************************************************************************************************************
		* 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
		* --------------------------------------------------------------------------------------------------------------
		***************************************************************************************************************/
		case"LPF_setCookie":
			if(params.length!=7)
			{
				alert("Invalid parameters for setCookie - LocalPredefinedFunction('LPF_setCookie;name;value;path;domain;secure;expire')");
			}
			else
			{
				LPF_setCookie(params[1], params[2], params[3],params[4],params[5],params[6]);
			}
			break;

		/***************************************************************************************************************
		* 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
		* Creation Date		: 6 Feb 2004
		* Side effect		: N/A
		* Amendment History	:
		* Date		By		Description
		* ---------	-------------------------------------------------------------------------------------------
		***************************************************************************************************************/
		case"LPF_digital_order_form":
			LPF_digital_order_form();
			break;

		/***************************************************************************************************************
		* 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
		* ---------	------------	--------------------------------------------------------------------------------
		*
		***************************************************************************************************************/
		case "LPF_preloadImages":
			if(params.length!=2)
			{
				alert("Invalid parameters for preloadImages - LocalPredefinedFunction('LPF_preloadImages;???')");
			}
			else
			{
				LPF_preloadImages(params[1]);
			}
			break;


		/***************************************************************************************************************
		* 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		: 12 Feb 2004
		* Side effect		: N/A
		* Amendment History	:
		* Date		By		Description
		* ---------	------------	--------------------------------------------------------------------------------
		*
		***************************************************************************************************************/
		case "LPF_DisplayLayer":
			if(params.length!=2)
			{
				alert("Invalid parameters for LPF_DisplayLayer - LocalPredefinedFunction('LPF_DisplayLayer;???')");
			}
			else
			{
				LPF_DisplayLayer(params[1]);
			}
			break;

		/***************************************************************************************************************
      * Function		: LPF_SwapImage(imgArrayStr)
      * Description		: Show or Hide a layer by setting the display property
      * 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
		* ---------	------------	--------------------------------------------------------------------------------
		*
		***************************************************************************************************************/
		case "LPF_SwapImage":
			if(params.length!=2)
			{
				alert("Invalid parameters for LPF_SwapImage - LocalPredefinedFunction('LPF_SwapImage;???')");
			}
			else
			{
				LPF_SwapImage(params[1]);
			}
			break;

		/***************************************************************************************************************
		* 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
		* ---------	------------   --------------------------------------------------------------------------------
		*
		***************************************************************************************************************/
		case "LPF_ClearTimeout":
			LPF_ClearTimeout();
			break;

		/***************************************************************************************************************
		* 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
		***************************************************************************************************************/
		case "LPF_SetTimeout":
			if(params.length!=3)
			{
				alert("Invalid parameters for LPF_SetTimeout - LocalPredefinedFunction('LPF_SetTimeout;???;???')");
			}
			else
			{
				LPF_SetTimeout(params[1],params[2]);
			}
			break;

		/***************************************************************************************************************
		* 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
		* ---------	------------	--------------------------------------------------------------------------------
		* 23Feb2004 Arnold			add parameters: imgalt, imgborder, swfquality, swfmenu
		***************************************************************************************************************/
		case "LPF_writeFlash":
			if(params.length!=15)
			{
				alert("Invalid parameters for LPF_writeFlash - LocalPredefinedFunction('LPF_writeFlash;???;???;???;???;???;???;???;???;???;???;???;???;???;???')");
			}
			else
			{
				LPF_writeFlash(params[1],params[2],params[3],params[4],params[5],params[6],params[7],params[8],params[9],params[10],params[11],params[12],params[13],params[14]);
			}
			break;

		/***************************************************************************************************************
		* 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
		* ---------	------------	--------------------------------------------------------------------------------
		*
		***************************************************************************************************************/
		case "LPF_ShowHideLayer":
			if(params.length!=2)
			{
				alert("Invalid parameters for LPF_ShowHideLayer - LocalPredefinedFunction('LPF_ShowHideLayer;???')");
			}
			else
			{
				LPF_ShowHideLayer(params[1]);
			}
			break;

		/***************************************************************************************************************
		* 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		: 18 Feb 2004
		* Side effect		: N/A
		* Amendment History	:
		* Date		By		Description
		* ---------	------------	--------------------------------------------------------------------------------
		*
		***************************************************************************************************************/
		case "LPF_Fade":
			if(params.length!=5)
			{
				alert("Invalid parameters for LPF_Fade - LocalPredefinedFunction('LPF_Fade;???;???;???;???')");
			}
			else
			{
				LPF_Fade(params[1],params[2],params[3],params[4]);
			}
			break;

		/***************************************************************************************************************
		* 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
		* ---------	------------	--------------------------------------------------------------------------------
		*
		***************************************************************************************************************/
		case "LPF_SetOpacity":
			if(params.length!=3)
			{
				alert("Invalid parameters for LPF_SetOpacity - LocalPredefinedFunction('LPF_SetOpacity;???;???')");
			}
			else
			{
				LPF_SetOpacity(params[1],params[2]);
			}
			break;

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

		case "LPF_OnChange_Pulldown":
			if(params.length!=3)
			{
				alert("Invalid parameters for LPF_OnChange_Pulldown - LocalPredefinedFunction('LPF_OnChange_Pulldown;???;???')");
			}
			else
			{
				LPF_OnChange_Pulldown(params[1],params[2]);
			}
			break;

		/***************************************************************************************************************
		* 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
		***************************************************************************************************************/
		case "LPF_SetOpacityValue":
			if(params.length!=2)
			{
				alert("Invalid parameters for LPF_SetOpacityValue - LocalPredefinedFunction('LPF_SetOpacityValue;???')");
			}
			else
			{
				LPF_SetOpacityValue(params[1]);
			}
			break;



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

		case "LPF_MouseOver":
			if(params.length!=5)
			{
				alert("Invalid parameters for MouseOver - LocalPredefinedFunction('LPF_MouseOver;???;???;???;???')");
			}
			else
			{
				LPF_MouseOver(params[1], params[2], params[3], params[4]);
			}
			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
		***************************************************************************************************************/
		case "LPF_addCss":
			if(params.length!=5)
			{
				alert("Invalid parameters for LPF_addCss - LocalPredefinedFunction('LPF_AddCSS;???;???;???;???')");
			}
			else
			{
				LPF_addCss(params[1],params[2],params[3],params[4]);
			}
			break;




		/***************************************************************************************************************
		* 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
		* ---------	------------	--------------------------------------------------------------------------------
		*
		***************************************************************************************************************/
		case "LPF_Popup_submitToNewBrowser":
			if(params.length!=11)
			{
				alert("Invalid parameters for LPF_Popup_submitToNewBrowser - LocalPredefinedFunction('LPF_Popup_submitToNewBrowser;formname;winname;status;location;sbar;mbar;tbar;resize;width;height')");
			}
			else
			{
				LPF_Popup_submitToNewBrowser(params[1], params[2], params[3], params[4], params[5], params[6], params[7], params[8], params[9], params[10]);
			}
			break;
		

			
		/***************************************************************************************************************
		* 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
		* ---------	------------	--------------------------------------------------------------------------------
		*
		***************************************************************************************************************/		
		case "LPF_getCookie":
			if(params.length!=2)
			{
				alert("Invalid parameters for LPF_getCookie - LocalPredefinedFunction('LPF_getCookie;name')");
			}
			else
			{
				LPF_getCookie(params[1]);
			}
			break;


		/***************************************************************************************************************
		* 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
		* ---------	------------	--------------------------------------------------------------------------------
		*
		***************************************************************************************************************/
		case "LPF_EDI_displayValue":
			LPF_EDI_displayValue(params[1],params[2],params[3]);
			break;

		/***************************************************************************************************************
		* 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
		* ---------	------------	--------------------------------------------------------------------------------
		*
		***************************************************************************************************************/
		case "LPF_EDI_getValue":
			LPF_EDI_getValue(params[1],params[2],params[3]);
			break;
		/***************************************************************************************************************
		* 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
		* ---------	------------	--------------------------------------------------------------------------------
		*
		***************************************************************************************************************/
		case "LPF_EDI_getDataSource":
			if(params.length!=3)
			{
				alert("Invalid parameters for LPF_EDI_getDataSource - LocalPredefinedFunction('LPF_EDI_getDataSource;URL;para')");
			}
			else
			{
				LPF_EDI_getDataSource(params[1], params[2]);
			}
			break;				


		/***************************************************************************************************************
		* 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		: 27 May 2004
		* Side effect		: N/A
		* Amendment History	:
		* Date		By		         Description
		* ---------	------------	--------------------------------------------------------------------------------
		***************************************************************************************************************
		* Remarks: require hsbc.js
		***************************************************************************************************************/
		case "LPF_getParamVal":
			if(params.length!=3)
			{
				alert("Invalid parameters for LPF_getParamVal - LocalPredefinedFunction('LPF_getParamVal;???;???')");
			}
			else
			{
				LPF_getParamVal(params[1],params[2]);
			}
			break;


		/***************************************************************************************************************
		* 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
		* ---------	------------	--------------------------------------------------------------------------------
		*
		***************************************************************************************************************/
		case "LPF_pr_timeStop":
			if(params.length!=8)
			{
				alert("Invalid parameters for LPF_pr_timeStop - LocalPredefinedFunction('LPF_pr_timeStop;name;imgsrc;imgsrc2;timelen;flag;frm;field')");
			}
			else
			{
				LPF_pr_timeStop(params[1],params[2],params[3],params[4],params[5],params[6],params[7]);
			}
			break;
		
		/***************************************************************************************************************
		* 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
		* ---------	------------	--------------------------------------------------------------------------------
		*
		***************************************************************************************************************/
		case "LPF_pr_chgFrmVal":
			if(params.length!=4)
			{
				alert("Invalid parameters for LPF_pr_chgFrmVal - LocalPredefinedFunction('LPF_pr_chgFrmVal;frm;field;value')");
			}
			else
			{
				LPF_pr_chgFrmVal(params[1],params[2],params[3]);
			}
			break;
		

		/***************************************************************************************************************
		* 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
		* ---------	------------	--------------------------------------------------------------------------------
		***************************************************************************************************************/	
		case "LPF_isCookieEnabled":
			if(params.length!=1)
			{
				alert("Invalid parameters for LPF_isCookieEnabled - LocalPredefinedFunction('LPF_isCookieEnabled')");
			}
			else
			{
				LPF_isCookieEnabled();
			}
			break;

		/***************************************************************************************************************
		* 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
		* ---------	------------	--------------------------------------------------------------------------------
		***************************************************************************************************************/
		case "LPF_deleteCookie":
			if(params.length!==4)
			{
				alert("Invalid parameters for LPF_deleteCookie - LocalPredefinedFunction('LPF_deleteCookie;name;path;domain')");
			}
			else
			{
				LPF_deleteCookie(params[1],params[2],params[3]);
			}
			break;



			
		/***************************************************************************************************************
		* 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
		* ---------	------------	--------------------------------------------------------------------------------
		***************************************************************************************************************/
		case"LPF_YahooBeacon":
			if(params.length!=3)
			{
				alert("Invalid parameters for YahooBeacon - LocalPredefinedFunction('YahooBeacon;secure;beacon_value')");
			}
			else
			{
				LPF_YahooBeacon(params[1],params[2]);
			}
			break;			

		
		/***************************************************************************************************************
		* 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            : LocalPredefinedFunction('LPF_championChallenger;m;http://www.hsbc.com.hk;http://www.hsbc.com.hk/hk/personal;http://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	:
		* Date		By					Description
		* ---------	------------	--------------------------------------------------------------------------------
		*
		***************************************************************************************************************/
		case "LPF_championChallenger":
			if(params.length < 3)
			{
				alert("Invalid parameters for LPF_championChallenger - LocalPredefinedFunction('LPF_championChallenger;unit;url1;url2,......')");
			}
			else
			{
				params.shift();
				LPF_championChallenger(params);
			}
			break;


		/***************************************************************************************************************
		* 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
		* Amendment History	:
		* Date		By					Description
		* ---------	------------	--------------------------------------------------------------------------------
		*
		***************************************************************************************************************/
		case "LPF_championChallengerGetURL":
			if(params.length < 3)
			{
				alert("Invalid parameters for LPF_championChallengerGetURL - LocalPredefinedFunction('LPF_championChallengerGetURL;unit;url1;url2,......')");
			}
			else
			{
				params.shift();
				LPF_championChallengerGetURL(params);
			}
			break;


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

		case "LPF_bannerGo_link":
			if (document.LPF_bannerGo_params.link.value == "")
			{
				alert("Invalid parameter for LPF_bannerGo_link.");
			}
			else
			{
				LPF_bannerGo_link();
			}
			break;
			
		case "LPF_bannerGo":
			if (document.LPF_bannerGo_params.whichimage.value!= 0 || document.LPF_bannerGo_params.whichlink.value!=0)
			{
				document.LPF_bannerGo_params.whichimage.value = 0;
				document.LPF_bannerGo_params.whichlink.value = 0;
				LPF_bannerGo();
			}
			else
			{
				LPF_bannerGo();
			}
			break;	
			
		/***************************************************************************************************************
		* 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
		* ---------	------------	--------------------------------------------------------------------------------
		***************************************************************************************************************/
		case "LPF_bannerRandom":
			if((params.length%2) == 0)
			{
				alert("Invalid parameters for LPF_bannerRandom - LocalPredefinedFunction('LPF_bannerRandom;src1;src2;...;alt1;alt2...')");
			}
			else
			{
				params.shift();
				LPF_bannerRandom(params);
			}
			
			break;
			
		/***************************************************************************************************************
		* 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
		* ---------	------------	--------------------------------------------------------------------------------
		***************************************************************************************************************/
		case"LPF_setKeyword":
			if(params.length!=1 )
			{
				alert("Invalid LPF function : LPF_setKeyword");
			}
			else
			{
				LPF_setKeyword();
			}
			break;
			
		
		/***************************************************************************************************************
		* 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
		*
		***************************************************************************************************************/
		case"LPF_Goto_mthspc":
			if(params.length!=1)
			{
				alert("Invalid parameters for LPF_Goto_mthspc - LocalPredefinedFunction('LPF_Goto_mthspc')");
			}
			else
			{
				LPF_Goto_mthspc(params[1]);
			}
			break;
		
		/***************************************************************************************************************
		* 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
		*
		***************************************************************************************************************/		
		case"LPF_Goto_luckydraw":
			if(params.length!=1)
			{
				alert("Invalid parameters for LPF_Goto_luckydraw - LocalPredefinedFunction('LPF_Goto_luckydraw')");
			}
			else
			{
				LPF_Goto_luckydraw(params[1]);
			}
			break;
		
		/***************************************************************************************************************
		* 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
		* ---------	------------	--------------------------------------------------------------------------------
		***************************************************************************************************************/

		case "LPF_Reset_Form":
			if(params.length!=2)
			{
				alert("Invalid parameters for LPF_Reset_Form - LocalPredefinedFunction('LPF_Reset_Form;formname')");
			}
			else
			{
				LPF_Reset_Form(params[1]);
			}
			break;



		/***************************************************************************************************************
		* 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
		* ---------	------------	--------------------------------------------------------------------------------
		***************************************************************************************************************/
		case "LPF_TextBoxAutoTab":
			if(params.length!=5)
			{
				alert("Invalid parameters for LPF_TextBoxAutoTab - LocalPredefinedFunction('LPF_TextBoxAutoTab;box1;maxlength;box2;maxlength')");
			}
			else
			{
				LPF_TextBoxAutoTab(params[1],params[2],params[3],params[4]);
			}
			break;	


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

		case "LPF_ContainsElement":
			if(params.length!=2)
			{
				alert("Invalid parameters for LPF_ContainsElement - LocalPredefinedFunction('LPF_ContainsElement;arr;ele')");
			}
			else
			{
				LPF_ContainsElement(params[1],params[2]);
			}
			break;	


		
	
		/***************************************************************************************************************
		* Function		: LPF_amhRtPromo(titlecontent, bodycontent, imagepath, landingurl)
		* Description		: Generate HTML code for AMH 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
		* ---------	------------	--------------------------------------------------------------------------------
		***************************************************************************************************************/
		case "LPF_amhRtPromo":
			if(params.length!=5)
			{
				alert("Invalid parameters for LPF_amhRtPromo - LocalPredefinedFunction('LPF_amhRtPromo;titlecontent;bodycontent;imagepath;landingurl')");
			}
			else
			{
				return LPF_amhRtPromo(params[1],params[2],params[3],params[4]);
			}
			break;	

		/***************************************************************************************************************
		* 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
		* ---------	------------	--------------------------------------------------------------------------------
		***************************************************************************************************************/
		case "LPF_htmlRandomizer":
			if(params.length<2)
			{
				alert("Invalid parameters for LPF_htmlRandomizer - LocalPredefinedFunction('LPF_htmlRandomizer;str')");
			}
			else
			{
				params.shift();
				LPF_htmlRandomizer(params.join(";"));
			}
			break;				

		/***************************************************************************************************************
		* Function		: LPF_semicolonUnescape(str)
		* Description		: Change the %59 to semicolon
		* 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
		* ---------	------------	--------------------------------------------------------------------------------
		*
		***************************************************************************************************************/
		case "LPF_semicolonUnescape":
			if(params.length!=2)
			{
				alert("Invalid parameters for LPF_semicolonUnescape - LocalPredefinedFunction('LPF_semicolonUnescape;str')");
			}
			else
			{
				return LPF_semicolonUnescape(params[1]);
			}
			break;



		/***************************************************************************************************************
		* Function		: LPF_amhPromo(title1, body1, image1, url1, title2, body2, image2, url2, ...)
		* Description		: Randomly display 1 chunk of HTML from multiple chunks of promotions.
		* Parameter Usage	: 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
		* ---------	------------	--------------------------------------------------------------------------------
		***************************************************************************************************************/
		case "LPF_amhPromo":
			if(params.length<5)
			{
				alert("Invalid parameters for LPF_amhPromo - LocalPredefinedFunction('LPF_amhPromo;title1;body1;image1;url1;title2;body2;image2;url2;...')");
			}
			else
			{
				params.shift();
				return LPF_amhPromo(params);
			}
			break;
			
			
			
		/***************************************************************************************************************
		* 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
		* ---------	------------	--------------------------------------------------------------------------------
		***************************************************************************************************************/
		case"SiteCensusAdTag":
			if(params.length!=5)
			{
				alert("Invalid parameters for SiteCensusAdTag - LocalPredefinedFunction('SiteCensusAdTag;datanode;media_acct_id;result_id;revenue')");
			}
			else
			{
				SiteCensusAdTag(params[1], params[2], params[3], params[4]);
			}
			break;
			
			


		/***************************************************************************************************************
		* 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
		* ---------	------------	--------------------------------------------------------------------------------
		*
		***************************************************************************************************************/
		case "LPF_Close":
			if(params.length!=1)
			{
				alert("Invalid parameters for LPF_Close - LocalPredefinedFunction('LPF_Close')");
			}
			else
			{
				LPF_Close();
      	}
			break;	



		/***************************************************************************************************************
		* 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
		* ---------	------------	--------------------------------------------------------------------------------
		*
		***************************************************************************************************************/
		case "LPF_CheckParam":
					if(params.length!=4)
					{
						alert("Invalid parameters for LPF_CheckParam - LocalPredefinedFunction('LPF_CheckParam;name;value;poppage')");
					}
					else
					{
						LPF_CheckParam(params[1],params[2],params[3]);
					}
		break;
		
		
			

		/***************************************************************************************************************
		* Function		: LPF_popupRandom(visitsperpopup, url, status, location, scroll, mbar, toolbar, resize, width, height, winname)
		* Description		: Open a new browser (popup) once for every predefined number of visits
		* Parameter Usage	: visitsperpop	:the predefined number of visits for a popup to appear once
		*		          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
		* Location		: /hk/personal/common/js/pfscommon.js
		* Author		: Timothy, Tong King Him
		* Creation Date		: 27 June 2006
		* Side effect		: N/A
		* Amendment History	:
		* Date		By					Description
		* ---------	------------	--------------------------------------------------------------------------------
		* 01MAR2004 	Arnold		Add an optional parameter, window name, at the end of the parameter list
		*
		***************************************************************************************************************/
		case "LPF_popupRandom":
			if(params.length!=11)
			{
				alert("Invalid parameters for LPF_popupRandom - LocalPredefinedFunction('LPF_popupRandom;visitsperpop;url;status;location;sbar;mbar;tbar;resize;height;width')");
			}
			else
			{
				LPF_popupRandom(params[1], params[2], params[3], params[4], params[5], params[6], params[7], params[8], params[9], params[10]);
			}
			break;
			
		/***************************************************************************************************************
		* Function		: LPF_WTUtil(prodline, language, custgrp, busline, site, cg_n, cam)
		* Description		: Setup the parameters for the page for WebTrends 8
		* Parameter Usage	: prodline	: the product line of the page
			  		  language	: the language of the page
			  		  custgrp	: the target customer group of the page
			  		  busline	: the business line of the page
			  		  site		: the site type of the page
			  		  cg_n		: the cg_n of the apge
			  		  cam		: the CAM level of the page
		* Location		: /hk/personal/common/js/pfscommon.js
		* Author		: Timothy, Tong King Him
		* Creation Date		: 25 September 2006
		* Side effect		: N/A
		* Amendment History	: N/A
		***************************************************************************************************************/
		case "LPF_WTUtil":
			if(params.length!=2 && params.length!=3 && params.length!=8)
			{
				alert("Invalid parameters for LPF_WTUtil - LocalPredefinedFunction('LPF_webTrendsUtil;prodline;language;custgrp;busline;site;cg_n,;cam')");
			}
			else
			{
				LPF_WTUtil(params[1], params[2], params[3], params[4], params[5], params[6], params[7]);
			}
			break;

		/***************************************************************************************************************
		* Function		: LPF_WTPageLevelEvent(action, sku)
		* Description		: Setup the parameters for the page for WebTrends 8
		* Parameter Usage	: action	: the action of the tag
					  sku		: the WebTrends SKU of the product
		* Location		: /hk/personal/common/js/pfscommon.js
		* Author		: Timothy, Tong King Him
		* Creation Date		: 25 September 2006
		* Side effect		: N/A
		* Amendment History	: N/A
		***************************************************************************************************************/
		case "LPF_WTPageLevelEvent":
			if(params.length!=3)
			{
				alert("Invalid parameters for LPF_WTPageLevelEvent - LocalPredefinedFunction('LPF_WTPageLevelEvent;action;sku')");
			}
			else
			{
				LPF_WTPageLevelEvent(params[1], params[2]);
			}
			break;

		//Missing function name or Javascript function not found
		default:
			if (params.length < 1)
			{
				alert("Missing function name.");
			}
			else
			{
				alert("Function name: " + params[0] + " not found.");
			}
			break;	
			/***************************************************************************************************************
* 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
* ---------	------------	--------------------------------------------------------------------------------
***************************************************************************************************************/
case "LPF_randomAMHImage":

	if(params.length != 2) {
		alert("Invalid parameters for LPF_randomAMHImage!\nIt must be in format of imgSrc1,altText1,link1,imgSrc2,altText2,link2...");
	}
	else
	{
		LPF_randomAMHImage(params[1]);
	}
	break;	

	}
}

/***************************************************************************************************************
* 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_DoubleClickLayer(layername)
* Description		: Display DoubleClick Spotlight Tag in layer
* Parameter Usage	: layername	: id of layer
*			: 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		: Kenny Ho (XMHK)
* Creation Date		: 2007-05-16
* Side effect		: No
* Amendment History	:
* Date		By		Description
* ---------	------------	--------------------------------------------------------------------------------
***************************************************************************************************************/
function LPF_DoubleClickLayer(layername, src, type, cat, secure)
{
var axel = Math.random()+"";
var a = axel * 10000000000000;

if (secure == "y")
		{
		// if secure = 'y' then execute tag in secure environment
		document.getElementById(layername).innerHTML = "<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.getElementById(layername).innerHTML = "<IMG SRC='http://ad.doubleclick.net/activity;src="+src+";type="+type+";cat="+cat+";ord="+ a + "?' WIDTH=1 HEIGHT=1 BORDER=0>";
		}
}

/***************************************************************************************************************
* 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.ebanking.hsbc.com.hk/1/2/logon?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.ebanking.hsbc.com.hk/1/2/logon?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.ebanking.hsbc.com.hk/1/2/logon?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 (typeof(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 (typeof(idx3) == "undefined" || idx3.length == 0){
			paraLength = 2;
		}
		
		if (typeof(idx2) == "undefined" || idx2.length == 0){
			paraLength = 1;
		}

		var dataArray = LPF_EDI_getData();
		if (typeof(dataArray) != "undefined"){
			if (paraLength == 3){
				output = dataArray[idx1][idx2][idx3];
			} else if (paraLength == 2){
				output = dataArray[idx1][idx2];	
			} else{
				output = dataArray[idx1];	
			}
		}
		
		if (typeof(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;
}

/***************************************************************************************************************
* Function		: LPF_popupRandom
* Description		: Open a new browser (popup) once for every predefined number of visits
* Parameter Usage	: visitsperpop	:the predefined number of visits for a popup to appear once
			  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
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Timothy, Tong King Him
* Creation Date		: 27 June 2006
* Side effect		: N/A
* Amendment History:
* Date		By					Description
* ---------	------------	--------------------------------------------------------------------------------
***************************************************************************************************************/

function LPF_popupRandom(visitsperpop, url, status, location, scroll, mbar, toolbar, resize, width, height)
{	var num = Math.floor(Math.random() * visitsperpop);
	
	if(num == 0)
	{	Popup_newBrowser(url, status, location, scroll, mbar, toolbar, resize, width, height);
	}		
}

/***************************************************************************************************************
* Function		: LPF_WTUtil(prodline, language, custgrp, busline, site, cg_n, cam)
* Description		: Setup the parameters for the page for WebTrends 8
* Parameter Usage	: prodline	: the product line of the page
			  language	: the language of the page
			  custgrp	: the target customer group of the page
			  busline	: the business line of the page
			  site		: the site type of the page
			  cg_n		: the cg_n of the page
			  cam		: the CAM level of the page
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Timothy, Tong King Him
* Creation Date		: 25 September 2006
* Side effect		: N/A
* Amendment History:
* Date		By					Description
* ---------	------------	--------------------------------------------------------------------------------
***************************************************************************************************************/

function LPF_WTUtil(prodline, language, custgrp, busline, site, cg_n, cam)
{	
	HSBC.SITE.prodline=prodline;
	!language? HSBC.SITE.language="en":HSBC.SITE.language=language;
	!custgrp? HSBC.SITE.custgrp="PFS":HSBC.SITE.custgrp=custgrp;
	!busline? HSBC.SITE.busline="General":HSBC.SITE.busline=busline;
	!site? HSBC.SITE.site="Public":HSBC.SITE.site=site;
	!cg_n? HSBC.PAGE.cg_n="Public":HSBC.PAGE.cg_n=cg_n;
	!cam? HSBC.SITE.cam="0":HSBC.SITE.cam=cam;
}

/***************************************************************************************************************
* Function		: LPF_WTPageLevelEvent(action, sku)
* Description		: Function call for WebTrends 8 Page Level Event tagging 
* Parameter Usage	: action	: the action of the tag
			  sku		: the WebTrends SKU of the product
* Location		: /hk/personal/common/js/pfscommon.js
* Author		: Timothy, Tong King Him
* Creation Date		: 5 October 2006
* Side effect		: N/A
* Amendment History:
* Date		By					Description
* ---------	------------	--------------------------------------------------------------------------------
***************************************************************************************************************/

function LPF_WTPageLevelEvent(action, sku)
{	document.write("<script>wt_" + action + "(\"" + sku + "\");</script>");
}

/*
----------------------------------------------------------------------------------------------
Applications and Tools Centre
---------------------------------------------------------------------------------------------- */
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
var requiredMajorVersion = 6;
var requiredMinorVersion = 0;
var requiredRevision = 0;

document.actionQueueRunning = false;

// gets an array of elements with a specific class name within a specific type of tag, and element.
document.getElementsByClassName = function(cls,n,t)
{
	var rtn = [];
	n=n===null?document:n;
	t=t===null?'*':t;
	var els = n.getElementsByTagName ? n.getElementsByTagName(t) : document.all;
	els = (!els||!els.length ) && document.all ? document.all : els;
	if(cls==null){return els;}
	for (var i=0,j=0; i < els.length; i++)
	{
		if(els[i].className.match("(^|\\s)"+cls+"(\\s|$)"))
		{
			rtn[j++] = els[i];
		}
	}
	return rtn;
};

// attaches events to objects
function jsfAttachEvent(obj,evt,fnc)
{
	if(window.addEventListener)
	{
		obj.addEventListener(evt, fnc, false);
	}
	else if(window.attachEvent)
	{
		obj.attachEvent('on'+evt, fnc);
	}
	else if (obj.getElementById && evt=='load')
	{
		obj.onload = fnc;
	}
}

jsfAttachEvent(window,'load',jsfOnLoad);

// the onload function below sets up all the events on the page.  In this case it hides all the details divs, and then adds 
// trigger events on to the title areas.  These triggers add an event to the custom event queue described below.
function jsfOnLoad()
{   
	var detailAreas = document.getElementsByClassName("jstWidgetArea", document, "DIV");
	onFontResize();
	
	for (var i=0; i<detailAreas.length; i++)
	{
		// reposition first
		detailAreas[i].style.left = "982px";
		detailAreas[i].style.top = "117px";
		
		// make sure the element is visible so the height attribute is valid
		detailAreas[i].maxHeight = detailAreas[i].offsetHeight;
		detailAreas[i].maxWidth = detailAreas[i].offsetWidth;
		detailAreas[i].style.overflow = "hidden";
		detailAreas[i].style.height = "0px";
		detailAreas[i].content = detailAreas[i].innerHTML;
		detailAreas[i].innerHTML = "";
		detailAreas[i].style.display = "none";
		
		jsfAttachEvent(detailAreas[i], 'mouseover', function(event)
		 {
			// now open the active element
			var srcElm = getEventSource(event);
			
			 // lock the element so it can't be closed
			 document.mouseOver = true;
		 });
		
		jsfAttachEvent(detailAreas[i], 'mouseout', function(event)
		 {
			// now open the active element
			var srcElm = getEventSource(event);
			
			 // unlock the element so it can be closed
			 document.mouseOver = false;
			 
			setTimeout("delayedAddQueuedAction()", 500);
		 });
	}
	
	var linkAreas = document.getElementsByClassName("jstWidgetLink", document, "A");
	
	for (var i=0; i<linkAreas.length; i++)
	{
		jsfAttachEvent(linkAreas[i], 'mouseover', function(event) 
		{
			document.mouseOver = true;
			
			// first close any open elements
			for (var j=0; j<detailAreas.length; j++)
			{
				if (detailAreas[j].offsetHeight == 0)
					addQueuedAction("expand", detailAreas[j].maxHeight, 0, detailAreas[j].maxWidth, 0, detailAreas[j]);
			}		
			
			// now open the active element
			var srcElm = getEventSource(event);
			
			var detailsElements = document.getElementsByClassName("jstWidgetArea", document.body, "DIV");
			
			detailsElements[0].linkElement = srcElm;
			
			addQueuedAction("expand", 0, detailsElements[0].maxHeight, 100, detailsElements[0].maxWidth, detailsElements[0]);
			
			if (!document.actionQueueRunning)
				peformQueuedActions();
			
		});
		
		jsfAttachEvent(linkAreas[i], 'mouseout', function(event) 
		{			
			document.mouseOver = false;
			
			// now open the active element
			var srcElm = getEventSource(event);
			
			var detailsElements = document.getElementsByClassName("jstWidgetArea", document.body, "DIV");

			setTimeout("delayedAddQueuedAction()", 500);
			/*addQueuedAction("contract", detailsElements[0].maxHeight, 0, detailsElements[0].maxWidth, 100, detailsElements[0]);
		
			if (!document.actionQueueRunning)
				peformQueuedActions();*/
			
		});

	}
}

function delayedAddQueuedAction()
{
	if (!document.mouseOver)
	{
		var detailsElements = document.getElementsByClassName("jstWidgetArea", document.body, "DIV");
	
		if (detailsElements[0] != null)
		{
			addQueuedAction("contract", detailsElements[0].maxHeight, 0, detailsElements[0].maxWidth, 100, detailsElements[0]);
		
			if (!document.actionQueueRunning)
				peformQueuedActions();
		}
	}
}

// This adds a custom event to a queue of uncompleted events.  To ensure that the user doesn't see all the details 
// areas jumping around everywhere this will queue all the events so that they are performed sequentially
function addQueuedAction(type, originalHeight, targetHeight, originalWidth, targetWidth, element)
{
	if (!document.actionList)
	{
		document.actionList = new Array();
	}
	
	var newObject = new Object();
	newObject.type = type;
	newObject.originalHeight = originalHeight;
	newObject.targetHeight = targetHeight;
	newObject.originalWidth = originalWidth;
	newObject.targetWidth = targetWidth;
	newObject.element = element;
		
	document.actionList.push(newObject);
	
	checkActionList();
}

// The function below ensures that the action list is stripped of any redundant actions 
// (such as an open followed by a close on the same element
function checkActionList()
{
	// first check for redundant open+closes
	for (var i=1; i<document.actionList.length; i++)
	{
		var initialAction = document.actionList[i];
		for (var j=2; j<document.actionList.length; j++)
		{
			var subsequentAction = document.actionList[j];
			
			if (initialAction.element == subsequentAction.element && 
				((initialAction.type == "expand" && subsequentAction.type == "contract") || 
				 (initialAction.type == "contract" && subsequentAction.type == "expand")))
			{
				// remove the actions
				document.actionList.splice(j, 1);
				document.actionList.splice(i, 1);				
			}
		}
	}
}

// Runs through all the queued actions until there are no more actions to run.
function peformQueuedActions()
{
	document.actionQueueRunning = true;
	
	if (document.actionList.length > 0)
	{
		var actionObject = document.actionList[0];
	
		actionObject.element.style.display = "";
		
		if (actionObject.element.style.height == actionObject.targetHeight + "px")
		{
			actionObject.actionCompleted = true;
			if (actionObject.element.style.height != "0px")
			{
				actionObject.element.innerHTML = actionObject.element.content;
			}
			else
			{
				var detailsElements = document.getElementsByClassName("extWidgetTab", document.body, "P");
				detailsElements[0].className = "extWidgetTab"
	
				//if(actionObject.element.linkElement.parentNode.tagName == "LI")
				//	actionObject.element.linkElement.parentNode.className = "extWidgetTab";
					
				actionObject.element.style.display = "none";
			}
			
			var completedAction = document.actionList.shift();
			
			// if there are any actions left, process the next one
			if (document.actionList.length > 0)
			{
				peformQueuedActions();
			}
			else
			{
				document.actionQueueRunning = false;	
			}
		}
		else
		{
			if (actionObject.element.style.height == actionObject.originalHeight + "px")
			{
				actionObject.element.innerHTML = "";
				
				var detailsElements = document.getElementsByClassName("extWidgetTab", document.body, "P");
				detailsElements[0].className = "extWidgetTab extWidgetTabSelected"
				
				//if(actionObject.element.linkElement.parentNode.tagName == "LI")
				//	actionObject.element.linkElement.parentNode.className = "extWidgetTab extWidgetTabSelected";
			}
				
			var curHeight = actionObject.element.style.height;
			curHeight = curHeight.substr(0, curHeight.length - 2);
			
			var curWidth = actionObject.element.style.width;
			curWidth = curWidth.substr(0, curWidth.length - 2);
		
			if (actionObject.element.style.left == "")
			{
				if (isIE)
				{
					actionObject.element.style.left = actionObject.element.offsetLeft + (actionObject.targetWidth - curWidth) - 3 + "px";
				}
				else
				{
					actionObject.element.style.left = actionObject.element.offsetLeft + (actionObject.targetWidth - curWidth) - 2 + "px";
				}
			}

			var curXPos = actionObject.element.offsetLeft;
			
			var x = 90;
			var y = 120;
			
			//alert(actionObject.originalHeight + "|" + actionObject.targetHeight + "|" + curHeight);
			if (actionObject.originalHeight > actionObject.targetHeight)
			{
				if ((curHeight-actionObject.targetHeight) < x)
					x = curHeight-actionObject.targetHeight;
					
				actionObject.element.style.height = (Number(curHeight) - x) + "px";
			}
			else
			{
				if ((actionObject.targetHeight-curHeight) < x)
					x = actionObject.targetHeight-curHeight;
					
				actionObject.element.style.height = (Number(curHeight) + x) + "px";
			}
			
			if (actionObject.originalWidth > actionObject.targetWidth)
			{
				if ((curWidth-actionObject.targetWidth) < y)
					y = curWidth-actionObject.targetWidth-3;
					
				actionObject.element.style.width = (Number(curWidth) - y) + "px";
				actionObject.element.style.left = (Number(curXPos) + y) + "px";
				
			}
			else
			{
				if ((actionObject.targetWidth-curWidth) < y)
					y = actionObject.targetWidth-curWidth-3;
					
				actionObject.element.style.width = (Number(curWidth) + y) + "px";
				actionObject.element.style.left = (Number(curXPos) - y) + "px";
			}
				
			setTimeout("peformQueuedActions()", 10);
		}
	} 
}

function getNearestClass(srcElm, className)
{
	var curElm = srcElm;
	while (curElm != document && curElm.className != className)
	{
		if (curElm.parentElement)
			curElm = curElm.parentElement;
		else
			curElm = curElm.parentNode;
	}
	if (curElm != document)
		return curElm;
	else
		return "undefined";
}

function getEventSource(event)
{
	if (event.srcElement)
		return event.srcElement;
	else
		return event.target;
}

/* TEXT RESIZE DECTECTOR */

TextResizeDetector = function() { 
    var el  = null;
	var iIntervalDelay  = 200;
	var iInterval = null;
	var iCurrSize = -1;
	var iBase = -1;
 	var aListeners = [];
 	var createControlElement = function() {
	 	el = document.createElement('span');
		el.id='textResizeControl';
		el.innerHTML=' ';
		el.style.position="absolute";
		el.style.left="-9999px";
		var elC = document.getElementById(TextResizeDetector.TARGET_ELEMENT_ID);
		// insert before firstChild
		if (elC)
			elC.insertBefore(el,elC.firstChild);
		iBase = iCurrSize = TextResizeDetector.getSize();
 	};

 	function _stopDetector() {
		window.clearInterval(iInterval);
		iInterval=null;
	};
	function _startDetector() {
		if (!iInterval) {
			iInterval = window.setInterval('TextResizeDetector.detect()',iIntervalDelay);
		}
	};
 	
 	 function _detect() {
 		var iNewSize = TextResizeDetector.getSize();
		
 		if(iNewSize!== iCurrSize) {
			for (var 	i=0;i <aListeners.length;i++) {
				aListnr = aListeners[i];
				var oArgs = {  iBase: iBase,iDelta:((iCurrSize!=-1) ? iNewSize - iCurrSize + 'px' : "0px"),iSize:iCurrSize = iNewSize};
				if (!aListnr.obj) {
					aListnr.fn('textSizeChanged',[oArgs]);
				}
				else  {
					aListnr.fn.apply(aListnr.obj,['textSizeChanged',[oArgs]]);
				}
			}

 		}
 		return iCurrSize;
 	};
	var onAvailable = function() {
		
		if (!TextResizeDetector.onAvailableCount_i ) {
			TextResizeDetector.onAvailableCount_i =0;
		}

		if (document.getElementById(TextResizeDetector.TARGET_ELEMENT_ID)) {
			TextResizeDetector.init();
			if (TextResizeDetector.USER_INIT_FUNC){
				TextResizeDetector.USER_INIT_FUNC();
			}
			TextResizeDetector.onAvailableCount_i = null;
		}
		else {
			if (TextResizeDetector.onAvailableCount_i<600) {
	  	 	    TextResizeDetector.onAvailableCount_i++;
				setTimeout(onAvailable,200)
			}
		}
	};
	setTimeout(onAvailable,500);

 	return {
		 	init: function() {
		 		
		 		createControlElement();		
				_startDetector();
 			},
			
 			addEventListener:function(fn,obj,bScope) {
				aListeners[aListeners.length] = {
					fn: fn,
					obj: obj
				}
				return iBase;
			},
			
 			detect:function() {
 				return _detect();
 			},
			
 			getSize:function() {
	 				var iSize;
			 		return el.offsetHeight;
		 		
		 		
 			},
			
 			stopDetector:function() {
				return _stopDetector();
			},
			
 			startDetector:function() {
				return _startDetector();
			}
 	}
 }();
 
function init(){
	var iBase = TextResizeDetector.addEventListener(onFontResize,null );
}


TextResizeDetector.TARGET_ELEMENT_ID = 'doc';
TextResizeDetector.USER_INIT_FUNC = null;

function getLastChild(element)
{
	if (element != null)
	{
		for (i=element.childNodes.length-1; i>= 0; i--)
		{
			if (element.childNodes[i].nodeType == 1)
				return element.childNodes[i];
		}
	}
}
function getPreviousChild(element)
{
	if (element != null)
	{
		var resultEl = element;
		var i = 0;
		while (i<1000)
		{
			resultEl = resultEl.previousSibling;
			
			if (resultEl.nodeType == 1)
				return resultEl;
				
			i++;
		}
	}
}

function getFirstChild(element)
{
	if (element != null)
	{
		for (i=0; i<element.childNodes.length; i++)
		{
			if (element.childNodes[i].nodeType == 1)
				return element.childNodes[i];
		}
	}
}

function onFontResize(e,args) {
	// if the position of the last tab in the top navigation is over the threshold stop displaying the tab
	var navArea = document.getElementsByClassName("hsbcDivletTabMenuInner", document, "DIV");
	
	var parentEl = getFirstChild(navArea[0]);
	var lastChildEl = getLastChild(parentEl);
	var lastTabEl = getPreviousChild(lastChildEl);
	var detailAreas = document.getElementsByClassName("extWidgetTab", document, "P");
	if(detailAreas[0])
	{
		if ((lastTabEl.offsetLeft + lastTabEl.offsetWidth) > 800) 
		{
			detailAreas[0].style.display = "none";
		}
		else
		{
			detailAreas[0].style.display = "";
		}
	}
}

//id of element to check for and insert control
TextResizeDetector.TARGET_ELEMENT_ID = 'resizeTest';
//function to call once TextResizeDetector has init'd
TextResizeDetector.USER_INIT_FUNC = init;

function pws_hbap_popupEmailUS(emailUsUrl ,widthSize, heightSize) {
var search_string=location.search;
var rs_url="";
var wedTrends_unit = "";
var paraLink = "";
var reg = /WT.ac/;
var reg2 = /WT.mc_id/;
	if(search_string == null || search_string.length == 0){
		rs_url = emailUsUrl;
	}
	else{
		var mat_index = search_string.search(reg);
		var mat_index2 = search_string.search(reg2);
		if (mat_index >= 0 || mat_index2 >= 0) {
			var temp = "";
			if(mat_index >= 0){
				temp = search_string.substring(mat_index);
			}else{
				temp = search_string.substring(mat_index2);
			}
			var index_and = temp.search(/&/);
			if(index_and > 0){
				wedTrends_unit = temp.substring(0, index_and);			
			} else {
				wedTrends_unit = temp;			
			}
			var campaignID = "";
			if(wedTrends_unit != null){
				var equInx = 	wedTrends_unit.indexOf("=");
				if(equInx > 0){
						campaignID = wedTrends_unit.substring(equInx);
				}
			}
			paraLink = "amhpwsemailus.Campaign_ID" + campaignID + "&amhpwsemailus.serviceunit=4&WABFormEntryCommand=cmd_init";
			if(mat_index2 >= 0){
					paraLink = paraLink + "&WT.ac" + campaignID;
			}
			if (emailUsUrl.indexOf("?") > 0) {	
				rs_url=emailUsUrl + "&" + paraLink ;
			} else {
				rs_url=emailUsUrl + "?" + paraLink ;
			}
		
		}else {
			rs_url = emailUsUrl;
		}	
	}
   if(widthSize != null && heightSize != null){   
   	var popWin = window.open(rs_url,"EmailUs","width="+widthSize+",height="+heightSize);   	
   } else {   
   	var popWin = window.open(rs_url);
   }	 
	popWin.focus();		
}

