function setButtonLog(formObj, buttonName){ var divName="BUTTON_LOG"; var div = document.getElementById(divName); if (div!=null) { formObj.removeChild(div); } div = document.createElement("div"); div.id = divName; div.name = divName; formObj.appendChild(div); var input = document.createElement("input"); input.id = buttonName; input.name = buttonName; input.type = "hidden"; div.appendChild(input); } function removeButtonLog(formObj){ var divName="BUTTON_LOG"; var div = document.getElementById(divName); if (div!=null) { formObj.removeChild(div); } } function changeLang(currentlang, formName) { var formObj = document.getElementById(formName); var changeLang = document.createElement("input"); changeLang.id = "changeLang"; changeLang.name = "changeLang"; changeLang.type = "hidden"; changeLang.value='Y'; formObj.appendChild(changeLang); var lang = document.createElement("input"); lang.id = "lang"; lang.name = "lang"; lang.type = "hidden"; if (currentlang=='zh') { lang.value='en'; } else { lang.value='zh'; } //remove appended lang parameter var url=window.location+""; var loginPage="login.htm"; if (url.indexOf(loginPage)>-1 && url.indexOf('lang=')>-1) { formObj.action=url.substring(0, url.indexOf(loginPage)+loginPage.length); } formObj.appendChild(lang); formObj.submit(); } function AjaxForm(formObj , callback , prevalid){ $(formObj).submit(function(){ if ( prevalid && !prevalid(formObj) ) return false; var data = $(formObj).serialize(); $.ajax({ type: $(this).attr("method"), url: $(this).attr("action"), data: data, //timeout: 1800000, //Set a local timeout (in milliseconds) for the request. success: function(data, textStatus, XMLHttpRequest){ ajaxSuccess(data, textStatus, XMLHttpRequest, callback); }, error: function(xhr, textStatus, errorThrown){ ajaxError(xhr, textStatus, errorThrown); } }); return false; }); } function isNnu(where){ cs = new String(where); for (var i = 0; i < cs.length; i++){ if (cs.charAt(i) < "0" || cs.charAt(i) > "9") return true; } if (cs.length == 0) return true; return false; } //===================handle URL start with http========================================================================= function handleHttpLink(where) { var splitResult = where.split("~|~"); var targetUrl; targetUrl=splitResult[1]; window.open(targetUrl,"menuPopup","resizable=yes,width=1000,height=600,scrollbars=yes"); } //===================disable ctrl+key========================================================================= document.onkeypress=onkeypress; document.onkeydown=onkeydown; function onkeypress(e) { if (!disableCtrlKeyCombination(e)) { return false; } } function onkeydown(e) { if (!disableCtrlKeyCombination(e)) { return false; } } function disableCtrlKeyCombination(e) { //list all CTRL + key combinations you want to disable var forbiddenKeys = new Array("n"); var key; var isCtrl; if(window.event) { key = window.event.keyCode; //IE if(window.event.ctrlKey) { isCtrl = true; } else { isCtrl = false; } } else { key = e.which; //firefox if(e.ctrlKey) { isCtrl = true; } else { isCtrl = false; } } //if ctrl is pressed check if other key is in forbidenKeys array if(isCtrl) { for(i=0; i0&&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:: Bank Consortium Trust Company Limited ::')"; eval(rtnstr); rtnstr = vpWin + '.document.write("")'; eval(rtnstr); } rtnstr = vpWin + ".focus()"; eval(rtnstr); } function isInvalid(where){ var validpass; cs = new String(where); for (var i = 0; i < cs.length; i++){ if ( (cs.charAt(i) < "0" || cs.charAt(i) > "9") && (cs.charAt(i) < "A" || cs.charAt(i) > "Z") && (cs.charAt(i) < "a" || cs.charAt(i) > "z") ) return true; } if (cs.length == 0) return true; return false; } //validate phone number function validatePhone(phone){ //alert((/[^(\d{1,}|/|\-|\(|\)|\s)(\d{1,}|/|\-|\(|\)|\s)(\d{1,}|/|\-|\(|\)|\s)$]/.test(phone))); var pattern = /[^\d\(\)\/\-\s]/; //var pattern=/[^(\d{1,}|/|\-|\(|\)|\s)(\d{1,}|/|\-|\(|\)|\s)(\d{1,}|/|\-|\(|\)|\s)$]/; if(pattern.test(phone) || phone.length<8){ return false; }else{ return true; } } //validate mobile number function validateMobile(mobile){ var pattern = /^[456789]{1}\d{7}$/; if(pattern.test(mobile)==false){ return false; }else{ return true; } } //validate local phone number function validateLocalPhone(phone){ var pattern = /^\d{8}$/; if(pattern.test(phone)==false){ return false; }else{ return true; } } //validate phone number with ext. function validatePhoneWithExt(phone){ var pattern = /^[123]{1}\d{7}$/; if(pattern.test(phone)==false){ return false; }else{ return true; } } //validate phone ext. function validatePhoneExt(ext){ var pattern = /^\d{1,4}$/; if(pattern.test(ext)==false){ return false; }else{ return true; } } //validate number within length function validateNumber(text, length){ var pattern = "^\\d{1,"+length+"}$"; var regExp=new RegExp(pattern); if(regExp.test(text)==false){ return false; }else{ return true; } } function validateEmail(email){ var atIdx = email.indexOf("@"); var errorList =[]; if ( /[^\w@'.-]/.test(email) ){ errorList.push('The e-mail address contains invalid characters.'); } if ( atIdx == -1 ){ errorList.push('The e-mail address must contain an @.'); } if ( atIdx == 0 ){ errorList.push('The e-mail address must not start with @.'); } if (/@.*@/.test(email)){ errorList.push('The e-mail address must contain only one @.'); } if ( ! /@\w+([-]?\w+)\.\w+/.test( email ) ){ errorList.push('The e-mail address must contain a period in the domain name.'); } if ( /@\./.test( email ) ){ errorList.push('Period must not immediately follow @ in the e-mail address.'); } if ( /\.@/.test( email ) ){ errorList.push('Period must not immediately precede @ in the e-mail address.'); } if ( /\.\./.test( email ) ){ errorList.push('Two periods must not be adjacent in the e-mail address.'); } return errorList; } //validate web pin function validateWebPin(pin, webPinFormat){ var pattern=/[0-9]{8}/; if (webPinFormat=='ALPHANUMERIC') { pattern=/^[A-Za-z0-9~!\\@#$%^&*'()\-+=?/<>|\[\]{}_ :;.,"`.]{8,16}$/; } else if (webPinFormat=='STRONG') { pattern=/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[~!\\@#$%^&*'()\-+=?/<>|\[\]{}_ :;.,"`.])[A-Za-z0-9~!\\@#$%^&*'()\-+=?/<>|\[\]{}_ :;.,"`.]{8,16}$/; } return pattern.test(pin); } function errorAlert(error){ var msg=''; if (isArray(error)){ for (i=0;i|]+\\[^\/\\:*?"<>|]+)(\\[^\/\\:*?"<>|]+)+(\.[^\/\\:*?"<>|]+)$/; return pattern.test(input); } /* ================================================================== LTrim(string) : Returns a copy of a string without leading spaces. ================================================================== */ function LTrim(str) /* PURPOSE: Remove leading blanks from our string. IN: str - the string we want to LTrim */ { var whitespace = new String(" \t\n\r"); var s = new String(str); if (whitespace.indexOf(s.charAt(0)) != -1) { // We have a string with leading blank(s)... var j=0, i = s.length; // Iterate from the far left of string until we // don't have any more whitespace... while (j < i && whitespace.indexOf(s.charAt(j)) != -1) j++; // Get the substring from the first non-whitespace // character to the end of the string... s = s.substring(j, i); } return s; } /* ================================================================== RTrim(string) : Returns a copy of a string without trailing spaces. ================================================================== */ function RTrim(str) /* PURPOSE: Remove trailing blanks from our string. IN: str - the string we want to RTrim */ { // We don't want to trip JUST spaces, but also tabs, // line feeds, etc. Add anything else you want to // "trim" here in Whitespace var whitespace = new String(" \t\n\r"); var s = new String(str); if (whitespace.indexOf(s.charAt(s.length-1)) != -1) { // We have a string with trailing blank(s)... var i = s.length - 1; // Get length of string // Iterate from the far right of string until we // don't have any more whitespace... while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) i--; // Get the substring from the front of the string to // where the last non-whitespace character is... s = s.substring(0, i+1); } return s; } /* ============================================================= Trim(string) : Returns a copy of a string without leading or trailing spaces ============================================================= */ function Trim(str) /* PURPOSE: Remove trailing and leading blanks from our string. IN: str - the string we want to Trim RETVAL: A Trimmed string! */ { return RTrim(LTrim(str)); } //============================================================= //Disable mouse right click //============================================================= function showRightClickAlert(){ alert("Right click is not available"); } function clickIE(){ if (event.button==2){ showRightClickAlert(); return false; } } function clickNS(e){ if (document.layers||document.getElementById&&!document.all){ if (e.which==2||e.which==3){ showRightClickAlert(); return false; } } } if (document.layers){ document.captureEvents(Event.MOUSEDOWN); document.onmousedown=clickNS; } else if (document.all&&!document.getElementById){ document.onmousedown=clickIE; } document.oncontextmenu=new Function("showRightClickAlert();return false") function ajaxSuccess(data, textStatus, XMLHttpRequest, callback){ callback(data, textStatus, XMLHttpRequest); } function ajaxError(xhr, textStatus, errorThrown) { if (textStatus=="timeout"){ alert('Request timeout. Please try again later.'); }else if(xhr.status==600) { window.location = xhr.responseText; } } function blockUI() { $.blockUI({ message: "" }); } function unblockUI() { $.unblockUI(); } function attachChangePinBox(changePinUrl){ var boxWidth=("470"=="")?380:"470"; var boxHeight=("280"=="")?250:"280"; //var url='/tpa/admin/forceChangePinMbr.htm'; var url = changePinUrl; var data=''; data+=''; $('body').append(data); $("#highlightFrame").bind('load', loadChangePin); } function loadChangePin(){ $("#highlightFrame").unbind('load'); var boxWidth=("470"=="")?380:"470"; var boxHeight=("280"=="")?250:"280"; var fadeoutTime=15000; var top=(window.innerHeight - boxHeight) /2; var left=(window.innerWidth - boxWidth) /2; //var top=(window.innerHeight - boxHeight) /2; //var left=(($("#bgSpan").offset().left-boxWidth)/2); if (top<0) {top=0;} if (left<0) {left=0;} $.blockUI({ css: { border: '5px solid #FBE48C', //border: '0px', width: boxWidth+'px', height: boxHeight+'px', top: top + 'px', left: left + 'px', backgroundColor: '#FFFFFF' }, overlayCSS: { //disable the blockui layer width: '100%', height: '100%', backgroundColor: '#FFFFFF', opacity:.6 }, //timeout: 10000, fadeIn: 200, fadeOut: 200, message: $('#changePinBox') }); //setTimeout(closePromotion, fadeoutTime); if($("iframe.blockUI").length>0) { $("iframe.blockUI").css("width",0); $("iframe.blockUI").css("height",0); } } function doRefreshDate(formName) { var formObj = document.createElement('form'); $(formObj).attr("action", "/tpa/intranet/common/refreshDateAjax.htm"); $(formObj).attr("method", "post"); AjaxForm(formObj , refreshDateCallback); $(formObj).submit(); } function refreshDateCallback(data, textStatus, XMLHttpRequest){ $.each(data, function(key, value){ if(value==undefined || value.result!=true) { $('#refreshDateResult').html('Error'); } else { $('#refreshDateResult').html('Date Refreshed'); var currentDateMap = value.currentDateStringMap; var currentDateMapHtml = ''; $.each(currentDateMap, function(env,dateMapData) { currentDateMapHtml += env + ' - ' + dateMapData + '
'; }); $('#currentDateMap').html(currentDateMapHtml); } }); } function isChrome() { return (navigator.userAgent.match('CriOS') || navigator.userAgent.toLowerCase().match('chrome')); } function isFirefox(){ return (navigator.userAgent.match('Firefox') || navigator.userAgent.toLowerCase().match('firefox')); } $(document).ready(function(){ $("input").keypress(function (e) { if (e.keyCode == 13){ //skip "enter" -> auto submit e.preventDefault(); } }); }); function popUpLayerCore(url,boxWidth,boxHeight){ var data=''; data+=''; $('body').append(data); $("#highlightFrame").bind('load', {width: boxWidth,height:boxHeight}, loadPopUpLayer); } function loadPopUpLayer(event){ $("#highlightFrame").unbind('load'); var width = event.data.width; var height = event.data.height; var top=(window.innerHeight - height) /2; var left=(window.innerWidth - width) /2; if (top<0) {top=0;} if (left<0) {left=0;} $.blockUI({ css: { border: '5px solid #FBE48C', width:width+'px', height:height+'px', top: top + 'px', left: left + 'px', backgroundColor: '#FFFFFF' }, overlayCSS: { //disable the blockui layer width: '100%', height: '100%', backgroundColor: '#FFFFFF', opacity:.6 }, fadeIn: 200, fadeOut: 200, message: $('#frozenBox') }); if($("iframe.blockUI").length>0) { $("iframe.blockUI").css("width",0); $("iframe.blockUI").css("height",0); } } function popUpPDF(url) { popupWindow(url, '', null, null, true, true); } function ajaxButtonLog(buttonLogName){ var ajaxButtonLogForm = document.createElement('form'); $(ajaxButtonLogForm).attr("action", "/tpa/common/buttonLogAjax.htm"); $(ajaxButtonLogForm).attr("method", "post"); var bottonLogHtml=$(''); $(ajaxButtonLogForm).append(bottonLogHtml); var accessPage=$(''); $(ajaxButtonLogForm).append(accessPage); AjaxForm(ajaxButtonLogForm , function(){}); $(ajaxButtonLogForm).submit(); } function saveOauthStorage(lang){ if(lang === undefined) { lang = "en"; } localStorage.setItem("OAUTH", "OAUTH"); localStorage.setItem("lang", lang); } function loadStorage_isOAuth(){ if (localStorage.getItem("OAUTH")==="OAUTH"){ return true; } return false } function registerConfirmDialogTPA(dialogCallback, dialogCallbackQM){ registerConfirmDialog(dialogCallback); registerConfirmDialogQuickMenu(dialogCallbackQM); } function registerConfirmDialogQuickMenu(dialogCallback){ if ($("#quickMenuSelect").length>0){ $("#quickMenuSelect").removeAttr('onchange'); $("#quickMenuSelect").on('change', function(e) { currentEvent = e; currentEvent.preventDefault(); dialogCallback(currentEvent); }); } } function registerConfirmDialog(dialogCallback, confirmMsg) { $("a").click(function (e) { currentEvent = e; var isExclude=$(this).attr('excludeConfirm'); // fix Issue #44 - this function must ignore "a" with target="_blank" // otherwise both browser and popup window loads the PDF form when clicking on the link if (this.target!='_blank' && (isExclude==undefined || isExclude!='true') ){ currentEvent.preventDefault(); // block default action, i.e. go to the specified URL baseURI = window.location.href; // check if it is a tab click, now no blocking on tab click href = currentEvent.currentTarget.href; if (baseURI!=undefined){ baseURI = baseURI.toString().split("#")[0]; } if (href!=undefined){ href = href.toString().split("#")[0]; } indexOf = href.indexOf(baseURI); if (indexOf<0){ dialogCallback(currentEvent, confirmMsg); } } }); } function isEmpty(input){ if(input=='undefined'||trim(input)==''){ return true; }else{ return false; } } function isValidHkid(hkid,ignoreParentheses){ var result=false; var checkDigit=0; if(!isEmpty(hkid)){ var lowerHkid=hkid.toLowerCase(); if(ignoreParentheses){ lowerHkid= lowerHkid.replace(/[(|[)]/g, ""); } if(lowerHkid.length==8||lowerHkid.length==9){ var lastDigit=lowerHkid.substring(lowerHkid.length-1,lowerHkid.length); lowerHkid=lowerHkid.substring(0,lowerHkid.length-1); if(lowerHkid.length==7){ if((lowerHkid.charCodeAt(0)<'a'.charCodeAt(0))||(lowerHkid.charCodeAt(0)>'z'.charCodeAt(0))){ return result; }else{ checkDigit=8*(lowerHkid.charCodeAt(0)-'a'.charCodeAt(0)+1); for(var i=1; i'9'.charCodeAt(0))){ return result; }else{ checkDigit=checkDigit+(8-i)*(lowerHkid.charCodeAt(i)-'1'.charCodeAt(0)+1); } } } }else{ if ((lowerHkid.charCodeAt(0)<'a'.charCodeAt(0)) || (lowerHkid.charCodeAt(0)>'z'.charCodeAt(0)) || (lowerHkid.charCodeAt(1)<'a'.charCodeAt(0)) || (lowerHkid.charCodeAt(1)>'z'.charCodeAt(0)) ){ return result; }else{ checkDigit=9*(lowerHkid.charCodeAt(0)-'a'.charCodeAt(0)+10); checkDigit+=8*(lowerHkid.charCodeAt(1)-'a'.charCodeAt(0)+10); for (var i=2; i'9')){ return result; }else{ checkDigit+=(9-i)*(lowerHkid.charCodeAt(i)-'1'+1); } } } } if (checkDigit>=0){ var outCheckDigit=""; var reminding=0; reminding=11-(checkDigit % 11); if (reminding==10){ outCheckDigit="a"; }else if (reminding==11){ outCheckDigit="0"; }else{ outCheckDigit=reminding.toString(); } if (outCheckDigit===lastDigit){ result=true; } } } } return result; } function uniqueArray(a){ temp = new Array(); for(var i = 0; i < a.length; i ++){ if(!contains(temp, a[i])){ temp.length+=1; temp[temp.length-1] = a[i]; } } return temp; } function contains(a, e){ for(j=0;j