var jsvFontSize = 100;
var jsvFMax = 120;
var jsvFMin = 100;
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;
var jsvContractIconUrl = "../images/contact_close.gif";
var jsvExpandIconUrl = "../images/contact_open.gif";
var jsvRotationStop = false;
var jsvTimeoutId;






function setFontSize()
{
	var tempSize = getCookie("fontSize");
	if((tempSize != null) && (tempSize >= 100) && (tempSize <= 120))
	{
		jsvFontSize = tempSize;
	}
	else
	{
		setCookie("fontSize", 100, "", "/");
	}
	document.body.style.fontSize = jsvFontSize + "%";
}





function changeFontSize(increment)
{
	if(increment)
	{
		jsvFontSize=parseInt(jsvFontSize) + parseInt(10);
	}
	else
	{
		jsvFontSize=parseInt(jsvFontSize) - parseInt(10);
	}

	if(jsvFontSize > jsvFMax)
	{
		jsvFontSize = jsvFMax;
	}
	if(jsvFontSize < jsvFMin)
	{
		jsvFontSize = jsvFMin;
	}
	switch(jsvFontSize)
	{
		case 100:
			document.body.style.fontSize = "1em";
			break;
		case 110:
			document.body.style.fontSize = "1.10em";
			break;
		case 120:
			document.body.style.fontSize = "1.20em";
			break;
	}
	setCookie('fontSize', jsvFontSize, "", "/");
}



function incrementFontSize()
{
	changeFontSize(true);
}



function decrementFontSize()
{
	changeFontSize(false);
}












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









function 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 jsfToggleMenu(self)
{
	var n = self;
	var childImg = n.childNodes[0];
	var parentUl = jsvIsIE?n.parentElement:n.parentNode;
	var childUl = parentUl.childNodes[3];
	
	
	if(childUl.style.display == "block" || childUl.style.display == "")
	{
		childUl.style.display = "none";
		childImg.src = jsvExpandIconUrl;
		childImg.alt = "Expand";
		childImg.title = "Expand";
	}
	else
	{
		childUl.style.display = "block";
		childImg.src = jsvContractIconUrl;
		childImg.alt = "Reduce";
		childImg.title = "Reduce";
	}
}

function jsfToggleAll(state)
{
	lists = document.getElementsByTagName('ul');
	
	
	for(i=0;i<lists.length;i++)
	{
		if((jsvIsIE&&lists[i].parentElement.parentElement.tagName=="UL")||lists[i].parentNode.parentNode.tagName=="UL")
		{
			lists[i].style.display=state;
		}
		if(lists[i].parentNode.childNodes[0].tagName=="A")
		{
			
		}
		
		if((jsvIsIE&&lists[i].parentElement.childNodes[0].childNodes[0].tagName=="IMG")||lists[i].parentNode.childNodes[0].tagName=="A")
		{
			if(imgNode = jsvIsIE?lists[i].parentElement.childNodes[0].childNodes[0]:lists[i].parentNode.childNodes[0].childNodes[0])
			{
				if(state=='block')
				{
					imgNode.src = jsvContractIconUrl;
					imgNode.alt = "Reduce";
					imgNode.title = "Reduce";
				}
				else
				{
					imgNode.src = jsvExpandIconUrl;
					imgNode.alt = "Expand";
					imgNode.title = "Expand";
				}
			}
		}
	}
}

function jsfExpandAll()
{
	jsfToggleAll('block');
	jsfSwapjsfShowAlljsfHideAll();
}

function jsfCollapseAll()
{
	jsfToggleAll('none');
	jsfSwapjsfShowAlljsfHideAll();
}

function jsfSwapjsfShowAlljsfHideAll()
{
	if(jsfShowAllDiv = document.getElementById("jsIdShowAll"))
	{
		jsfShowAllDiv.style.display = jsfShowAllDiv.style.display=="block"?"none":"block";
	}
	
	if(jsfHideAllDiv = document.getElementById("jsIdHideAll"))
	{
		jsfHideAllDiv.style.display = jsfHideAllDiv.style.display=="block"?"none":"block";
	}
}

function jsfExpandAllLink()
{
	jsfExpandAll()
	if(document.getElementById("jsIdExpandAll"))
	{
			document.getElementById("jsIdExpandAll").style.display = "none";
	}
	if(document.getElementById("jsIdCollapseAll"))
	{
			document.getElementById("jsIdCollapseAll").style.display = "block";
	}
}

function jsfCollapseAllLink()
{
	jsfCollapseAll()
	if(document.getElementById("jsIdExpandAll"))
	{
			document.getElementById("jsIdExpandAll").style.display = "block";
	}
	if(document.getElementById("jsIdCollapseAll"))
	{
			document.getElementById("jsIdCollapseAll").style.display = "none";
	}
}


function jsfShowHide(id)
{
	divObj = document.getElementById("jsIdShowHideDiv"+id);
	imgObj = document.getElementById("jsIdShowHideImg"+id);
	if(divObj.style.display=="none")
	{
		divObj.style.display = 'block';
		imgObj.src = jsvContractIconUrl;
	}
	else
	{
		divObj.style.display = 'none';
		imgObj.src = jsvExpandIconUrl;
	}
}

function jsfHideAll()
{
	for(i=01;i<20;i++)
	{
		iStr = i<10?"0"+i:i;
		if(divObj = document.getElementById("jsIdShowHideDiv"+iStr))
		{
			imgObj = document.getElementById("jsIdShowHideImg"+iStr);
			divObj.style.display = "none";
			imgObj.src = jsvExpandIconUrl;
		}
	}
	jsfSwapjsfShowAlljsfHideAll();
}

function jsfShowAll()
{
	for(i=01;i<20;i++)
	{
		iStr = i<10?"0"+i:i;
		if(divObj = document.getElementById("jsIdShowHideDiv"+iStr))
		{
			imgObj = document.getElementById("jsIdShowHideImg"+iStr);
			divObj.style.display = "block";
			imgObj.src = jsvContractIconUrl;
		}
	}
	jsfSwapjsfShowAlljsfHideAll();
}

function jsfAutoSwap()
{
	if(jsvRotationStop==false)
	{
		if(document.getElementById("jsMainBanner01").style.display == "block")
		{
			document.getElementById("jsMainBanner01").style.display = "none";
			document.getElementById("jsMainBanner02").style.display = "block";
			document.getElementById("jsMainBanner03").style.display = "none";
			setTimeout("jsfAutoSwap()", 6000);
			return;
		}
		if(document.getElementById("jsMainBanner02").style.display == "block")
		{
			document.getElementById("jsMainBanner01").style.display = "none";
			document.getElementById("jsMainBanner02").style.display = "none";
			document.getElementById("jsMainBanner03").style.display = "block";
			setTimeout("jsfAutoSwap()", 6000);
			return;
		}
		if(document.getElementById("jsMainBanner03").style.display == "block")
		{
			document.getElementById("jsMainBanner01").style.display = "block";
			document.getElementById("jsMainBanner02").style.display = "none";
			document.getElementById("jsMainBanner03").style.display = "none";
			setTimeout("jsfAutoSwap()", 6000);
			return;
		}
	}
}

function jsfHomepageBannerSwap(swapSection)
{
	switch(swapSection)
	{
		case 1:
			document.getElementById("jsMainBanner01").style.display = "block";
			document.getElementById("jsMainBanner02").style.display = "none";
			document.getElementById("jsMainBanner03").style.display = "none";
			break;
		case 2:
			document.getElementById("jsMainBanner01").style.display = "none";
			document.getElementById("jsMainBanner02").style.display = "block";
			document.getElementById("jsMainBanner03").style.display = "none";
			break;
		case 3:
			document.getElementById("jsMainBanner01").style.display = "none";
			document.getElementById("jsMainBanner02").style.display = "none";
			document.getElementById("jsMainBanner03").style.display = "block";
			break;
	}
	clearTimeout(jsvTimeoutId);
	jsvTimeoutId = setTimeout("jsfAutoSwapStart()", 10000);
	jsvRotationStop = true;
}

function jsfAutoSwapStart()
{
	jsvRotationStop = false;
	jsfAutoSwap();
}




function jsfOnLoad()
{
	setFontSize();
	if(document.getElementById("jsIdShowHideDiv03") || document.getElementById("jsIdShowHideDiv01"))
	{
		for(i=01;i<20;i++)
		{
			iStr = i<10?"0"+i:i;
			if(divObj = document.getElementById("jsIdShowHideDiv"+iStr))
			{
				jsfShowHide(iStr);
			}
		}
	}
	
	if(document.getElementById("jsSiteMap"))
	{
		jsfCollapseAll()
	}
	
	if(hpBanner02 = document.getElementById("jsMainBanner02"))
	{
		hpBanner02.style.display = 'none';
		document.getElementById("jsMainBanner01").style.display = "block";
		setTimeout("jsfAutoSwap()", 5000);
	}
	
	if(hpBanner03 = document.getElementById("jsMainBanner03"))
	{
		hpBanner03.style.display = 'none';
	}
	
	if(pageOptions = document.getElementById("jsIdPageOptions"))
	{
		pageOptions.style.display = 'block';
	}
	
	if((hideAllDiv = document.getElementById("jsIdHideAll")) && (showAllDiv = document.getElementById("jsIdShowAll")))
	{
		hideAllDiv.style.display = "none";
		showAllDiv.style.display = "block";
	}
}

function submitForm (formName, elementName, commandName) {
	document.forms[formName].all[elementName].name = commandName;
	document.forms[formName].submit();
}

if (window.addEventListener)
{
	window.addEventListener("load", jsfOnLoad, false);
}
else
{
	if (window.attachEvent)
	{
		window.attachEvent("onload", jsfOnLoad);
	}
	else
	{
	if (document.getElementById)
		{
			window.onload = jsfOnLoad;
		}
	}
}
/* MYM2021 added */
function jsfOutputDropdownTextRefresh(varx)
{
	if((objReference = document.getElementById(varx))==null)
	{
		return;
	}
	if(objReference.selectedIndex == -1) {
			return;
	}

	document.getElementById(varx+"Output").innerHTML = objReference.options[objReference.selectedIndex].innerHTML;
}


function alertMsg(alertPath)
{  
		if ((alertwin && alertwin.closed) || !alertwin)
		{
			alertwin = window.open(alertPath,"alertmsg","menubar=no,resizable=no,toolbar=no,directories=no,location=no,scrollbars=yes,status=no,screenX=200,screenY=410,dependent=no,width=380,height=280,top=410,left=180");
			alertwin.focus();
		}
		alertTimer = setTimeout("redirect()",1000);
}



// DoubleByteSupport Variable For Browser Checking

// If the site is supporting Single Byte language 
// then
//	the browser type checking is 
//	Net Communicator 4.5
//	IE 4.0
// else if the site is supporting Double Byte National Language
//
//	the browser type checking is 
//	Net Communicator 4.72
//	IE 5.0

// if the site is supporting double byte, set the variable to TRUE.
// if the site is supporting single byte only, set the variable to FALSE;

var DoubleByteSupport = false;



var alertTimer;
var alertwin;

var accHistoryPrintTimer;
var accHistoryPrintWin;

var openPdfFileTimer;
var openPdfFileWin;

function closewin()
{
	killSession();

	if (alertwin)
	{
		alertwin.close();
		alertwin = null;
		clearTimeout(alertTimer);
	}
		
	closeAll();
}

function closewin()
{
	killSession();

	if (alertwin)
	{
		alertwin.close();
		alertwin = null;
		clearTimeout(alertTimer);
	}

	if(accHistoryPrintWin)
	{
	 	accHistoryPrintWin.close();
		accHistoryPrintWin = null;
	 	clearTimeout(accHistoryPrintTimer);
	}

	if(openPdfFileWin)
	{
	 	openPdfFileWin.close();
		openPdfFileWin = null;
	 	clearTimeout(openPdfFileTimer);
	}

	closeAll();
}

function killSession()
{
	if (window.event)
	{
		if (window.event.clientX < 0 && window.event.clientY < 0)
	      {
	            window.open(contextRoot + "/servlet/com.hsbc.ebank.app.hib.base.KillSessionServlet", "KillSession", "width=1,height=1,resizable=no,menubar=no,toolbar=no,directories=no,location=no,scrollbars=no,status=no, fullscreen=no, titlebar=no, alwaysRaised=no, hotkeys=no");
	      }
	}
}



/*
 * Amendment History:
 * 
 * Version			Date		By				Description
 * -------------	----------	-----------		-------------------------------------------------------
 * P2G1002			22Jan2004	Stephen Yeung	For P2G framework Integration
 * P2G1016			23Apr2004	William Cheng	For new P2G context root
 *	                25Jun2004	Matthew Tse		Standardize file for Portal
 */ 
 
 /*P2G1002*/ var ifSubmitForm = "no";
 /*P2G1016*/ var contextRoot  = "/P2G_PortalWeb";
 /*P2G1016*/ var contextPath  = "/hubpib";
var message="This function is not allowed within HSBC Internet banking.";
 
window.history.forward(1);
document.oncontextmenu = function(){return false}

if (navigator.appName == "Netscape")
{
   document.onkeypress = function(e) {
   	var c = document.layers ? e.which : document.all ? event.keyCode : e.keyCode;		
   	if (c == 116) {
		alert(message);
		return false;
	}
   }
}
else {
	document.onkeydown = function(){
		if(window.event && window.event.keyCode == 116) 
        	{ // Capture and remap F5
			window.event.keyCode = 505;
  		}

		if(window.event && window.event.keyCode == 505) {
			alert(message);
			return false; 
		}
	}
}
//
// ifSubmitFormNoFrame - a no frame version of the ifSubmitForm flag
//
var ifSubmitFormNoFrame = false;


//Reset the Flag that control double click prevention and ensure http request sent one after one
if(parent != null && parent.ifSubmitForm != null) 
{ 
	parent.ifSubmitForm = "no";
} 

//Turn the control flag on to prevent double click and multiple http request at a time
function setHttpReqCrtlFlg()
{
	if(parent != null && parent.ifSubmitForm != null)
	{
		parent.ifSubmitForm = "yes";
	}
}

//When hyperlink is clicked, set control flag and replace location
function chgLocation(link)
{
	setHttpReqCrtlFlg();
	location.replace(link);
	return;
}

/*P2G1016 - new function - removed */
/* no longer used in portal */ 	
function goToNewLocation(link)
{
	//For usage of this function, the context root must be already included inside the link.
	//If the context root is not known at runtime, use chgLocation(link) method.
/*	setHttpReqCrtlFlg();
	location.replace(link);
	return;
*/
}


/*P2G1016 - new function*/	
/* no longer used in portal */
function goToNewLocation2(cRoot, link)
{
	//cRoot is the context root.
	//link is the hyperlink without context root
	//If the context root is not known at runtime, use chgLocation(link) method.
/*
	setHttpReqCrtlFlg();
	location.replace(cRoot + link);
	return;
*/
}


//When a form, inputForm, is about to be sent, set control flag if the reqType is "Y"
//and submit form
/* no longer used in portal */
function formSubmit3(reqType)
{
/*
	if(document != null && document.inputForm != null)
	{
		if(reqType == "Y")
		{
			setHttpReqCrtlFlg();
		}
      	document.inputForm.submit();
	}
      return;
*/
}


//When a form, inputForm, is about to be sent, set control flag and submit form
//function formSubmit()
//{
//	if(document != null && document.inputForm != null)
//	{
//		setHttpReqCrtlFlg();
//      	document.inputForm.submit();
//	}
//      return;
//}
/* P2G1016 new version */ 
function formSubmit(form)
{
	if(!checkIfSubmittedForm())
	{
		setHttpReqCrtlFlg();
		form.submit();
	}
	return;
}



//When a form, inputForm1, is about to be sent, set control flag and submit form
/* no longer used in portal */
function form1Submit() 
{
/*
	if(document != null && document.inputForm1 != null)
	{
		setHttpReqCrtlFlg();
		document.inputForm1.submit();
	}
      return;
*/
}


//When a form, inputForm, is about to be sent, set control flag and submit form
function formSubmit2(id)
{
/* P2G1002 removed
  parent.nav.location="/servlet/com.hsbc.ebank.app.hib.base.MenuServlet?id=" + id + "";
  setHttpReqCrtlFlg(); 
  document.inputForm.submit();
  return;
*/
/*P2G1002*/	alert("The javascript function 'formSubmit2(id)' is obsolete.");
}

//Check the control flag status
function checkIfSubmittedForm()
{
  if(parent != null && parent.ifSubmitForm != null && parent.ifSubmitForm=="yes")
  {
    return true;
  }
  else
  {
    return false;
  }
}


//
// checkIfSubmittedFormNoFrame - check the ifSubmittedForm flag for pages with no frames
//   return - true if the form is submitted, false otherwise
//
/* no longer used in portal 
   use checkIfSubmittedForm*/ 
function checkIfSubmittedFormNoFrame()
{
   // return ifSubmitFormNoFrame;
}


//
// setIfSubmittedFormNoFrame - set the ifSubmittedForm flag value for no frame pages
//   flag - true if the form is submitted, false otherwise
//
/* no longer used in portal 
   use setHttpReqCtrlFlag*/ 
function setIfSubmittedFormNoFrame(flag)
{
//    ifSubmitFormNoFrame = flag;
}


//
// inputFormSubmitNoFrame - no frame version of formSubmit. It checks if the form is submited
//                          if not, set the flag and trigger the inputForm submission. 
//
/* no longer used in portal 
   use inputFormSubmitNoForm*/ 
function inputFormSubmitNoFrame()
{
/*
    if (!checkIfSubmittedFormNoFrame())
    {
        setIfSubmittedFormNoFrame(true);
        document.inputForm.submit();
    }

    return;       // this to avoid any redirection of the hyperlink
*/
}


//
// formSubmitNoFrame - form submit with an argument. This one should be used in forms that are
//                     not named inputForm and no frame situation
//   form - the form to carry out the submission
//
/* no longer used in portal 
   use formSubmit*/ 
function formSubmitNoFrame(form)
{
/*
    if (!checkIfSubmittedFormNoFrame())
    {
        setIfSubmittedFormNoFrame(true);       
        form.submit();
    }
*/
}


//
// chgLocationNoFrame - this is for hyperlinks on no frame pages. It checks the form submit
//                      flag before doing the redirection.
//   link - the link to be redirected to
//
/* no longer used in portal 
   use chgLocation*/ 
   
function chgLocationNoFrame(link)
{
/*
    if (!checkIfSubmittedFormNoFrame())
    {
        setIfSubmittedFormNoFrame(true);
//P2G1016        location.replace(link);
*/
/*P2G1016*/ /*      location.replace(contextRoot + link);
    }

    return;       // this to avoid any redirection of the hyperlink
*/
}


//
// showPopupNoFrame - check the form submit flag and carry out a function
//                    in a frameless page
//   popup - the name of the popup function
//   args - the rest of the arguments will be used to call that popup function
//   return - true if the form is not previously submitted, false otherwise
//
/* no longer used in portal 
   use functions in Popups.js*/ 
function showPopupNoFrame(popup)
{
/*
    if (!checkIfSubmittedFormNoFrame())
    {
        var args = showPopupNoFrame.arguments;
        var popupArgs = new Array(args.length);

        // trim the first argument from the argument list
        for (i = 0; i < args.length - 1; i++)
        {
            popupArgs[i] = args[i + 1];
        }

        // apply the popup function if with the argument list
        popup.apply(this, popupArgs);
     
        return true;
    }
    return false;
*/
}



function click1(e)
{
	if (document.all)
	{
		if (event.button == 2)
		{ 
			alert(message); 
			return false; 
		} 
	} 
	if (document.layers) 
	{ 
		if (e.which == 3 || e.which == 2) 
		{ 
			alert(message); submitForm = "no"; 
 			return false; 
		} 
	} 
}

function click2(e) 
{ 
	if (e.which == 3 || e.which == 2) 
	{ 
		alert(message); 
		return false; 
	} 
} 

var s = navigator.appVersion; 
var len = s.length; 
var t = s.substring (0, 3); 
var ver = parseFloat(t); 

if ( (navigator.appName == "Netscape") && (ver >=5)) 
	document.onmouseup=click2; 
else 
	document.onmousedown=click1;

// code for disabling Enter Key
if (navigator.appName == "Netscape")
{
    window.onfocus = function()
    {
        if (document.inputForm)
        {
            for (var i = 0; i < document.inputForm.length; i++)
            {
                document.inputForm[i].onkeypress = function(e)
                {
                    var c = document.layers ? e.which : document.all ? event.keyCode : e.keyCode;		
                    if (document.inputForm[i].type != "textarea" && (c == 13 || c == 3)) return false;
                };
            }
        }
        window.onfocus = null;
    };
}
else
{
    document.onkeypress = function(e)
    {
        var c = document.layers ? e.which : document.all ? event.keyCode : e.keyCode;
        if ((document.activeElement.type == "text" || document.activeElement.type == "password") && (c == 13 || c == 3)) return false;
    };
}



if (navigator.childWin == null)
{
   navigator.childWin = new Array();
}
var childWin = navigator.childWin;


function showChild(ID, ChildHTMLFile, Rules)
{
  if (!Rules)
    childWin[ID] = window.open(ChildHTMLFile,ID,'dependent=yes,resizable=yes,width=640,height=500,screenX=0,screenY=0,left=0,top=0,titlebar=yes,scrollbars=yes');
  else
    childWin[ID] = window.open(ChildHTMLFile,ID,Rules);
	
  return childWin[ID];
}

function closeChild(ID)
{
  if (childWin[ID] != null)
  {
    childWin[ID].close();
    childWin[ID] = null;
  }
}

function closeAll()
{
  closeChild(1);
  closeChild(2);
  closeChild(3);
  closeChild(4);
  closeChild(5);
  closeChild(6);
  closeChild(7);
  closeChild(8);
  closeChild(9);
  closeChild(10);
  closeChild('help');
  closeChild('Timer'); 
  closeChild('Alert');  

}


function showProductSpecificInterestRateInquiry(url, productType, currency)
{
	if ((currency > 0) && (productType > 0))
	{

   	showChild(1, (url+'&accountType='+productType+'&depositCurrency='+currency), 'dependent=yes,width=480,height=510,screenX=0,screenY=0,left=0,top=0,titlebar=yes');
	return false;
	}
	else
	{

		return true;
	}
}

function showInterestRateInquiry(url)
{
	showChild(1, url, 'scrollbars=yes,dependent=yes,width=600,height=500,screenX=0,screenY=0,left=0,top=0,titlebar=yes');
}


function showCheckBalance(url, debitAccountIndex)
{ 
  return showChild(6, url+'&debitAccountIndex='+debitAccountIndex, 'dependent=yes,width=480,height=510,screenX=0,screenY=0,left=0,top=0,titlebar=yes');
}  


function showAcHistoryPrint(url)
{
  return showChild(9, url, 'scrollbars=yes,dependent=yes,width=700,height=500,screenX=0,screenY=0,left=0,top=0');
}

function showCheckBalance(url)
{
  return showChild(6, url, 'scrollbars=yes,dependent=yes,width=600,height=500,screenX=0,screenY=0,left=0,top=0');
}



function showProductFeatures(nextPage)
{
	showChild(2, nextPage, 'scrollbars=yes,width=600,height=500,screenX=0,screenY=0,left=0,top=0,titlebar=yes');
}


function showHelp(url)
{
	showChild('help', url, ' width=650, height=400, menubar=no, resizable-no, toolbar=no,directories=no,location=no,scrollbars=yes,status=yes,copyhistory=0');
}

function showTimeout(url)
{

	showChild('Timer', url, 'dependent=yes,width=390,height=300,resizable=no,menubar=no,toolbar=no,directories=no,location=no,scrollbars=no,status=no, fullscreen=no, titlebar=no, alwaysRaised=yes, hotkeys=no');
}

function showAlert(url)
{
	return showChild('Alert', url, 'dependent=yes,resizable=no,screenX=0,screenY=0,left=0,top=0,titlebar=yes,scrollbars=no');
}


function showPdf(pdfIndex, form)
{
	var id = 10;
	form.pdfDwnldIndex.value = pdfIndex;
	form.target=id;
	var rules = 'menubar=no, toolbar=no,directories=no,location=no,scrollbars=no,status=yes,copyhistory=0, height=700,width=700,left=300,top=10';
	childWin[id] = window.open("", id, rules);

}

function showLogonHelp(Lang)
{
  if (Lang)
    showChild('help', contextRoot + contextPath + '/Helptext/en/Logon.htm', 'width=650, height=400, menubar=no, resizable-no, toolbar=no,directories=no,location=no,scrollbars=yes,status=yes,copyhistory=0');
  else
    showChild('help', contextRoot + contextPath + '/Helptext/zh/Logon.htm', 'width=650, height=400, menubar=no, resizable-no, toolbar=no,directories=no,location=no,scrollbars=yes,status=yes,copyhistory=0');
}

function showOrAckHelp(Lang)
{
  if (Lang)
    showChild('help', contextRoot + contextPath + '/Helptext/en/OrAck.htm', 'width=650, height=400, menubar=no, resizable-no, toolbar=no,directories=no,location=no,scrollbars=yes,status=yes,copyhistory=0');
  else
    showChild('help', contextRoot + contextPath + '/Helptext/zh/OrAck.htm', 'width=650, height=400, menubar=no, resizable-no, toolbar=no,directories=no,location=no,scrollbars=yes,status=yes,copyhistory=0');
}

function showTermsAndConditionsHelp(Lang)
{
  if (Lang)
    showChild('help', contextRoot + contextPath + '/Helptext/en/TermsAndConditions.htm', 'width=650, height=400, menubar=no, resizable-no, toolbar=no,directories=no,location=no,scrollbars=yes,status=yes,copyhistory=0');
  else
    showChild('help', contextRoot + contextPath + '/Helptext/zh/TermsAndConditions.htm', 'width=650, height=400, menubar=no, resizable-no, toolbar=no,directories=no,location=no,scrollbars=yes,status=yes,copyhistory=0');
}

function showCalendar()
{
//P2G5002#2647  top.newWin=showChild(4,  contextRoot + contextPath + '/jsp/calendar.html', 'dependent=yes,width=280,height=700,screenX=0,screenY=0,left=0,top=0,titlebar=yes');
//SGH2G-L&F remove top.newWin=showChild(4, 'javascript:document.write(parent.opener.calDocAll);self.focus();', 'dependent=yes,width=280,height=700,screenX=0,screenY=0,left=0,top=0,titlebar=yes');
//SGH2G-L&F modify height 
//SGH2G-L&F modify width
top.newWin=showChild(4, 'javascript:document.write(parent.opener.calDocAll);self.focus();', 'dependent=yes,width=330,height=470,screenX=0,screenY=0,left=0,top=0,titlebar=yes');
  return top.newWin;
}

function showCalendarPortlet(url)
{
  //SGH2G-L&F remove top.newWin=showChild(4, url, 'dependent=yes,width=280,height=700,screenX=0,screenY=0,left=0,top=0,titlebar=yes');
  //SGH2G-L&F modify height 
  //SGH2G-L&F modify width
  top.newWin=showChild(4, url, 'dependent=yes,width=330,height=470,screenX=0,screenY=0,left=0,top=0,titlebar=yes');
  return top.newWin;
}

function showDisclaimer(disclaimerPath)
{
    return showChild(5, disclaimerPath, 'resizable=yes,width=700,height=500,left=0,top=0,scrollbars=yes');
}

function toLogon(url) 
{
  if (confirm('You have decided to reject the terms and conditions for using the Internet Banking service.  Click OK to exit from the registration process or click Cancel to resume your registration process.'))
    {
		window.open(url,'PreLogon');
    }
}

function logonAgain(url) 
{
	window.open(url,'PreLogon');
}




var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1);

//
// print the page located in a certain frame
//
function printPage(frame, arg)
{
	if (frame == window)
	{
		printThis();
	}
	else
	{
		link = arg;  // a global variable
		printFrame(frame);
	}
}

//
// print this current window
//
function printThis()
{
	if (pr)
	{
		window.print();
	}
	else if (da && !mac)
	{
		// IE4 (Windows)
		vbPrintPage();
	}
	else
	{
		// other browsers
		if(mac)
		{
			alert("Please press your Print button on your iMac computer to print.");
		}
		else
		{
			alert("Sorry, your browser doesn't support this feature.");
		}
	}
}


//
// print a frame
//
function printFrame(frame)
{
	if (pr && da)
	{
		// IE5
		frame.focus();
		window.print();
		link.focus();
	}
	else if (pr)
	{
		// NS4
		frame.print();
	}
	else if (da && !mac)
	{
		// IE4 (Windows)
		frame.focus();
		setTimeout("vbPrintPage(); link.focus();", 100);
	}
	else
	{
		// other browsers
		if (mac)
		{
			alert("Please press your Print button on your iMac computer to print.");
		}
		else
		{
			alert("Sorry, your browser doesn't support this feature.");
		}
	}
}


if (da && !pr && !mac) with (document)
{
	writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
	writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
	writeln('Sub window_onunload');
	writeln('  On Error Resume Next');
	writeln('  Set WB = nothing');
	writeln('End Sub');
	writeln('Sub vbPrintPage');
	writeln('  OLECMDID_PRINT = 6');
	writeln('  OLECMDEXECOPY_DONTPROMPTUSER = 2');
	writeln('  OLECMDEXECOPT_PROMPTUSER = 1');
	writeln(' On Error Resume Next');
	writeln(' WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DOTPROMPTUSER');
	writeln('End Sub');
	writeln('<' + '/SCRIPT>');
}



//
// Setup global variables
//
// fontSize - default value
// fMax - largest font size
// fMin - smallest font size
// isIE501 - is the user agent MSIE 5.01
//
var fontSize = 100;
var fMax = 120;
var fMin = 100;
var isIE501 = navigator.userAgent.indexOf("MSIE 5.01") > 0 ? true : false;
var isNN6 = navigator.userAgent.indexOf("Netscape6") > 0 ? true : false;
var isIE=document.all&&navigator.userAgent.indexOf("Opera")==-1;
var SKIP_VISIBLE = "#000";			//value is black
var SKIP_INVISIBLE = "#fff";		//value is white
//
// setFontSize
//
// Retrieves cookie value and applies to font size
//
function setFontSize() {
	var tempSize = getCookie("fontSize");
	if((tempSize != null) && (tempSize >= 100) && (tempSize <= 120)) {
		fontSize = tempSize;
	} else {
		setCookie("fontSize", 100, "", "/");
	}
	document.body.style.fontSize = fontSize + "%";
}


//
// changeFontSize(bool increment)
//
// changes document font size and records size value in cookie
//
function changeFontSize(increment) {
	if(increment) {
		fontSize=parseInt(fontSize) + parseInt(10);
	} else {
		fontSize=parseInt(fontSize) - parseInt(10);
	}

	if(fontSize > fMax) {
		fontSize = fMax;
	}
	if(fontSize < fMin) {
		fontSize = fMin;
	}
	switch(fontSize) {
		case 100:
			document.body.style.fontSize = "1em";
			break;
		case 110:
			document.body.style.fontSize = "1.10em";
			break;
		case 120:
			document.body.style.fontSize = "1.20em";
			break;
	}
	setCookie('fontSize', fontSize, "", "/");
}
//
// incrementFontSize
//
function incrementFontSize() {
	changeFontSize(true);
}

//
// decrementFontSize
//
function decrementFontSize() {
	changeFontSize(false);
}


//
// Sets a Cookie with the given name and value.
//
// name       Name of the cookie
// value      Value of the cookie
// [expires]  Expiration date of the cookie (default: end of current session)
// [path]     Path where the cookie is valid (default: path of calling document)
// [domain]   Domain where the cookie is valid
//              (default: domain of calling document)
// [secure]   Boolean value indicating if the cookie transmission requires a
//              secure transmission
//
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}


//
// Gets the value of the specified cookie.
//
// name  Name of the desired cookie.
//
// Returns a string containing value of specified cookie,
//   or null if cookie does not exist.
//
function 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));
}

/*used for automaticaly jumping from one input to the next*/
var count = 0;
function checkInput(theInputBox, maxChars, previousId, nextId) {
	if(nextId != "") {
		nextInputBox = document.getElementById(nextId);
		if((count == (maxChars-1)) && (theInputBox.value.length == maxChars)) {
			if(nextInputBox.value.length == 0) {
				count = 1;
			} else {
				count = nextInputBox.value.length;
			}
			nextInputBox.select();
			return;
		}
	}
	if(count == 0 && theInputBox.value.length == 0) {
		PreviousInputBox = document.getElementById(previousId);
		if(PreviousInputBox.value.length == 0) {
			count = 1;
		} else {
			count = PreviousInputBox.value.length;
		}
		PreviousInputBox.select();
		return;
	}
	count = theInputBox.value.length;
}
//onKeyPress
function previous(theInputBox) {
	count = theInputBox.value.length;
}
//onfocus
function current(theInputBox) {
	count = 999;
	theInputBox.select();
}

function hideAccounts() {
	switchAccountDisplay("none", "block", true);
/*	document.getElementById("balance-top").style.background = "url(../images/show-balance.gif) no-repeat";*/
}

function showAccounts() {
	switchAccountDisplay("block", "none", true);
/*	document.getElementById("balance-top").style.background = "url(../images/hide-balance-top.gif) no-repeat";*/
}
function hideDetails() {
	switchDetailDisplay("none", "block");
}

function showDetails() {
	switchDetailDisplay("block", "none");
}

function switchDetailDisplay(state1, state2) {
	if(document.getElementById("detail-switch")) {
		document.getElementById("detail-switch").style.display = state1;
		document.getElementById("hide-detail-switch").style.display = state1;
		document.getElementById("show-detail-switch").style.display = state2;
	}
}

//
//	These functions wraps the variables in HTML code for placement in the page
//
function displayTag(address,text,title) {
	if(title==null) {
		title = text;
	}
	document.write('<div class=\"hsbcButtonLeft\"></div> <div class=\"hsbcButtonCenter\"><a href=\"',address,'\" title=\"',title,'\">',text,'</a><i>.</i></div><div class=\"hsbcButtonRight\"></div>');
}

function displayResetTag(text) {
		document.write('<div class=\"hsbcButtonLeft\"></div> <div class=\"hsbcButtonCenter\"><a href=\"#\"  onclick=\"document.forms[0].reset()\" onkeypress=\"document.forms[0].reset()\">',text,'</a><i>.</i></div><div class=\"hsbcButtonRight\"></div>');
}

function displayPrintTag() {
	document.write('&nbsp;-&nbsp;<a href=\"#\" class=\"important\">print this page</a>');
}
//
// switchAccountDisplay(string state1,string state2)
// restore show/hide account details from cookie
//
function switchAccountDisplay(state1, state2, browserReload) {
	if(document.getElementById("jsAccountDetails")) {
		document.getElementById("jsAccountDetails").style.display = state1;
		document.getElementById("jsHideAccounts").style.display = state1;
		document.getElementById("jsShowAccounts").style.display = state2;
		setCookie("state1", state1, "", "/");
		setCookie("state2", state2, "", "/");
		if((browserReload == true) && ((isIE501 == true) || (isNN6==true))) {
			location.reload();
		}
	}
}



//
// restoreAccountDisplay
// restore show/hide list of account details from cookie
//
function restoreAccountDisplay() {
	state1 = getCookie("state1") == null ? "none" : getCookie("state1");
	state2 = getCookie("state2") == null ? "block" : getCookie("state2");
	switchAccountDisplay(state1, state2, false);
}

function setJSFunctionality() {
	if(document.getElementById("jsSecondaryFunctionality")) {
		document.getElementById("jsSecondaryFunctionality").style.display = "block";
	}
}



function expandAll() {
	toggleAll('block');
}

function collapseAll() {
	toggleAll('none');
}

function expandAllLink() {
	expandAll()
	if(document.getElementById("jsExpandAll")) {
			document.getElementById("jsExpandAll").style.display = "none";
	}
	if(document.getElementById("jsCollapseAll")) {
			document.getElementById("jsCollapseAll").style.display = "block";
	}
}

function collapseAllLink() {
	collapseAll()
	if(document.getElementById("jsExpandAll")) {
			document.getElementById("jsExpandAll").style.display = "block";
	}
	if(document.getElementById("jsCollapseAll")) {
			document.getElementById("jsCollapseAll").style.display = "none";
	}
}


function skipLinkFocus(skipLinkName) {
	skipLinkName.style.color = SKIP_VISIBLE;
}

function skipLinkBlur(skipLinkName) {
	skipLinkName.style.color = SKIP_INVISIBLE;
}


//
// do_onload
//
function do_onload() {
	setFontSize();
	setJSFunctionality();
	restoreAccountDisplay();

	if(document.getElementById("jsSiteMap")) {
		collapseAll()
	}
	
	if(document.getElementById("jsSiteMapBar")) {
		document.getElementById("jsSiteMapBar").style.display = "block";
	}
	
	if(document.getElementById("detail-switch")) {
		document.getElementById("detail-switch").style.display = "none";
		document.getElementById("show-detail-switch").style.display = "block";
		document.getElementById("hide-detail-switch").style.display = "none";
		document.getElementById("nojs-detail-switch").style.display = "none";
	}
}



//
// trigger onLoad function (do_onload)
//
if (window.addEventListener) {
	window.addEventListener("load", do_onload, false);
} else {
	if (window.attachEvent) {
		window.attachEvent("onload", do_onload);
	} else {
		if (document.getElementById) {
			window.onload = do_onload;
		}
	}
}



<!--

function OnClickHandler()
{
	var agent = navigator.userAgent.toLowerCase();
	
	if ( (agent.indexOf("msie") == -1) || (agent.indexOf("mac") == -1) )
	{	
		var el=null;
		var flag=true;
		el = event.srcElement;
		while (flag && el)   
		{
		  if (el.tagName == "A")
		  { 
		    flag=false;
		    if (el.protocol == "javascript:")
		    {
		      execScript(unescape(el.href), "javascript");
		      window.event.returnValue = false; 
		    }
		  } 
		  else 
		    el = el.parentElement; 
		}
	}
} // end OnClickHandler()

document.onclick = OnClickHandler; // set the On click handler for the document 
//-->




/*
 * Amendment History:
 * 
 * Version			Date		By				Description
 * -------------	----------	------------	-------------------------------------------------------
 * P2GCMD018		15Feb2006	Carrie Lu		Fix accounts selected changes even without focus when mouse scrolling wheel is used 
 */
function foo(px,py,pw,ph,baseElement,fid)
{
		var win = document.getElementById(this.fid);
}


function dropdown_menu_hack(el)
{
	if(el.runtimeStyle.behavior.toLowerCase()=="none"){return;}
	el.runtimeStyle.behavior="none";

	var ie5 = (document.namespaces==null);
	el.ondblclick = function(e)
	{
		window.event.returnValue=false;
		return false;
	}
	
	if(window.createPopup==null)
	{
		
		var fid = "dropdown_menu_hack_" + Date.parse(new Date());
	
		window.createPopup = function()
		{
			if(window.createPopup.frameWindow==null)
			{
					el.insertAdjacentHTML("AfterEnd","<iframe   id='"+fid+"' name='"+fid+"' src='about:blank'  frameborder='1' scrolling='no'></></iframe>");
					var f = document.frames[fid];
					f.document.open();
					f.document.write("<html><body></body></html>");
					f.document.close();
					f.fid = fid; 
					

					var fwin = document.getElementById(fid);
					fwin.style.cssText="position:absolute;top:0;left:0;display:none;z-index:99999;";
				
					
					f.show = function(px,py,pw,ph,baseElement)
					{							
						py = py + baseElement.getBoundingClientRect().top + Math.max( document.body.scrollTop, document.documentElement.scrollTop) ;
						px = px + baseElement.getBoundingClientRect().left + Math.max( document.body.scrollLeft, document.documentElement.scrollLeft) ;
						fwin.style.width = pw + "px";
						fwin.style.height = ph + "px";						
						fwin.style.posLeft =px ;
						fwin.style.posTop = py ;		
						fwin.style.display="block";						
					}

					
					f_hide = function(e)
					{ 
						if(window.event && window.event.srcElement	&& window.event.srcElement.tagName && window.event.srcElement.tagName.toLowerCase()=="select"){return true;}
						fwin.style.display="none";
					} 
					f.hide = f_hide;
					document.attachEvent("onclick",f_hide);		
					document.attachEvent("onkeydown",f_hide);		
					
			}
			return f;
		}
	}

	function showMenu()
	{
		
		function selectMenu(obj)
			{				
				var o = document.createElement("option");
				o.value = obj.value;
				o.innerHTML = obj.innerHTML;			
				while(el.options.length>0){el.options[0].removeNode(true);}
				el.appendChild(o);
				el.title =  o.innerHTML; 
				el.contentIndex = obj.selectedIndex  ;
				el.menu.hide();
				document.getElementById(el.id+"Output").innerHTML = el.options[el.selectedIndex].innerHTML;
				el.onchange();
				
			}		
		
		
		el.menu.show(0 , el.offsetHeight , 10,  10, el); 
		var mb = el.menu.document.body;
		
		mb.style.cssText ="border:solid 1px black;margin:0;padding:0;overflow-y:auto;overflow-x:auto;background:white;text-aligbn:center;font-family:Verdana;font-size:12px;";
		var t = el.contentHTML;
		t = t.replace(/<select/gi,'<ul');
		t = t.replace(/<option/gi,'<li');
		t = t.replace(/<\/option/gi,'</li');
		t = t.replace(/<\/select/gi,'</ul');
		mb.innerHTML = t;	
	
		
		el.select = mb.all.tags("ul")[0];
		el.select.style.cssText="list-style:none;margin:0;padding:0;";
		mb.options = el.select.getElementsByTagName("li");
		
		for(var i=0;i<mb.options.length;i++)
		{
			mb.options[i].selectedIndex = i;
			mb.options[i].style.cssText = "list-style:none;margin:0;padding:1px 2px;width/**/:100%;cursor:hand;cursor:pointer;white-space:nowrap;"
//disable tool tips	mb.options[i].title =mb.options[i].innerHTML;
			mb.options[i].innerHTML =" " + mb.options[i].innerHTML + "</nobr>";
			mb.options[i].onmouseover = function()
				{
					if( mb.options.selected ){mb.options.selected.style.background="white";mb.options.selected.style.color="black";}
					mb.options.selected = this;
					this.style.background="#333366";this.style.color="white";
				}
			
			mb.options[i].onmouseout = function(){this.style.background="white";this.style.color="black";}
			mb.options[i].onmousedown = function(){selectMenu(this);	}
			mb.options[i].onkeydown = function(){selectMenu(this);	}
				

			if(i == el.contentIndex)
			{
				mb.options[i].style.background="#333366";
				mb.options[i].style.color="white";	
				mb.options.selected = mb.options[i];
			}
		}
	
		
		var mw = Math.max(   ( el.select.offsetWidth + 22 ), el.offsetWidth + 22  );
			 mw = Math.max(  mw, ( mb.scrollWidth+22) );
		var mh =  mb.options.length * 15  + 8 ; 
			 
		var mx = (ie5)?-3:0;
		var my = el.offsetHeight -2;
		var docH =   document.documentElement.offsetHeight ;
		var bottomH = docH  - el.getBoundingClientRect().bottom ; 

		mh = Math.min(mh, Math.max(( docH - el.getBoundingClientRect().top - 50),100)		);
		
		if(( bottomH < mh) )
		{
			
			mh = Math.max( (bottomH - 12),10);
			if( mh <100 ) 
			{
				my = -100 ;

			}
			mh = Math.max(mh,100);			
		}

		
		self.focus(); 
		
		el.menu.show( mx , my ,  mw, mh , el); 
		sync=null;
		if(mb.options.selected)
		{
			mb.scrollTop = mb.options.selected.offsetTop;
		}
	

		
		
		window.onresize = function(){el.menu.hide()};		
	}

	function switchMenu()
	{
		if(event.keyCode)
		{
			if(event.keyCode==40){ el.contentIndex++ ;}
			else if(event.keyCode==38){ el.contentIndex--; }
		}
		else if(event.wheelDelta )
		{
			if (event.wheelDelta >= 120)
			el.contentIndex++ ;
			else if (event.wheelDelta <= -120)
			el.contentIndex-- ;
		}else{return true;}




		if( el.contentIndex > (el.contentOptions.length-1) ){ el.contentIndex =0;}
		else if (el.contentIndex<0){el.contentIndex = el.contentOptions.length-1 ;}

		var o = document.createElement("option");
			 o.value = el.contentOptions[el.contentIndex].value;
			 o.innerHTML = el.contentOptions[el.contentIndex].text;
			 while(el.options.length>0){el.options[0].removeNode(true);}
			 el.appendChild(o);
			 el.title =  o.innerHTML; 
	}
	
	if(dropdown_menu_hack.menu ==null)
	{
		dropdown_menu_hack.menu =  window.createPopup();
		document.attachEvent("onkeydown",dropdown_menu_hack.menu.hide);
	}
	el.menu = dropdown_menu_hack.menu ;
	el.contentOptions = new Array();
	el.contentIndex = el.selectedIndex;
	el.contentHTML = el.outerHTML;

	for(var i=0;i<el.options.length;i++)
	{	
		el.contentOptions [el.contentOptions.length] = 
		{
			"value": el.options[i].value,
			"text": el.options[i].innerHTML
		}

		if(!el.options[i].selected){el.options[i].removeNode(true);i--;};
	}

	
	el.onkeydown = switchMenu;
	el.onclick = showMenu;
//P2GCMD018	el.onmousewheel= switchMenu;

}

