var fancyboxLoadingInstance; var firstTime = false; // for real time checking var minYear = 1901; var scrollPos; var progressContainerOffsetTop = 0; var keyboardOpened = false; var isiOS = false; $(document).ready(function() { log('----------------------'); log('jQuery Version: ' , $().jquery); log('Bootstrap Version: ' ,$.fn.tooltip.Constructor.VERSION); log('Ready!', is_Mobile() ); //OCCUPATION set ul_occup2_BIZ_NATURE default disabled $('select[name=ul_occup2_BIZ_NATURE]').prop('disabled', true); log('----------------------'); log('$.support.transition: ', $.support.transition); log('$.support: ', $.support); if (detectIE()===false) { } else { log('It is IE! ', detectIE()); $('html').addClass('ie'); } if (debug) { //firstTime = false; } log('BrowserDetect:', BrowserDetect.browser, BrowserDetect.version, BrowserDetect.OS, iOSVersion); isiOS = checkiOS() ; if (isiOS) { if (iOSVersion < 8) { isiOS = false; } } log('isiOS:', isiOS); // Fixed - css fixed when keyboard opened if (isiOS) { //$('html, body').addClass('ios'); $('html, body').addClass('ios'); //$('body').addClass('body-ios'); } initBackToTop(); initProgressBar(); initEvent(); initChecking(); if (typeof step!="undefined") { if ((step>1 && step<4) || (step == 1 && nextpage == 1)) { if (typeof pageaction != "undefined") { if (pageaction != "ACKN") { scrollToForm(); } } } } if (debug) { if (step == 3) { //presetForm(); } } // Intercept Form Submission $("form[name=campaignform]").submit(function(e){ log('submit intercepted', formsubmitted, $("#CRS_HID").val(), $("#CRS_ADDITIONAL_HID").val(), e.originalEvent ); log( e.originalEvent ); if ( e.originalEvent === undefined ) { } else { // human e.preventDefault(); var form = this; if ( submitform(document.forms.campaignform) ) { log('%c NO ERROR! Form submitting...', 'color: green; font-weight: bold;' ); if ($("#console")) $("#console").val(b64EncodeUnicode($("#console").val())); form.submit(); } else { // ERROR } } }); function b64EncodeUnicode(str) { // first we use encodeURIComponent to get percent-encoded UTF-8, // then we convert the percent encodings into raw bytes which // can be fed into btoa. return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function toSolidBytes(match, p1) { return String.fromCharCode('0x' + p1); })); } /* var log2 = log; if ("INPUT" == pageaction.toUpperCase() && "DOCUPLOAD" != tempCD.toUpperCase()) { log = function () { log2(arguments[0]); if (!$("#console").length) { $('').attr({ type: 'hidden', id: 'console', name: 'console' }).appendTo($("form")); } var text = ""; let i = 0; for (i; i < arguments.length; i++) { text += arguments[i] + " "; } $("#console").val($("#console").val() + text + "\n"); } } */ }); function presetForm() { $('input[type=text][name=ul_personal2_EMAIL]').val('test@test.com'); $('select[name=ul_personal2_DOB1]').prop('selectedIndex', 1).trigger('change'); $('select[name=ul_personal2_DOB2]').prop('selectedIndex', 2).trigger('change'); $('select[name=ul_personal2_DOB3]').prop('selectedIndex', 3).trigger('change'); $('select[name=ul_personal2_edu_level]').prop('selectedIndex', 1).trigger('change'); $('select[name=ul_personal2_resid_type]').prop('selectedIndex', 1).trigger('change'); // $('input[type=checkbox][name=ACCEPT_TNC]').prop('checked', true).trigger('change'); $('select[name=ul_personal2_nationality]').prop('selectedIndex', 1).trigger('change'); $('select[name=crs_country_1]').prop('selectedIndex', 3).trigger('change'); $('select[name=crs_reason_1]').prop('selectedIndex', 1).trigger('change'); } // BACK TO TOP // ----------------------------------------------------------------------------------------------------- function initBackToTop() { $('.back-to-top').click(function(e){ e.preventDefault(); log('back-to-top click', isiOS); if (!isiOS) { $(window).scrollTo( 0, 600, {'axis':'y'}); } else { $(window).scrollTo( 0, 600, {'axis':'y'}); } }); $('.go-to-bottom').click(function(e){ e.preventDefault(); log('go-to-bottom click'); $(window).scrollTo( 0, 600, {'axis':'y'}); }); // Show/Hide back-to-top button if ($('.back-to-top').length > 0) { if (!isiOS) { waypoint = new Waypoint({ element: $('body'), handler: function(direction) { log('Name: ', this.group.name, direction, 'body 25%') if (direction == "down") { if (!$('.back-to-top').is(':visible') && !$('.back-to-top').data('animating')) { $('.back-to-top').data('animating', true).fadeIn(500, function() { $(this).data('animating', false); }); } } else { if ($('.back-to-top').is(':visible') && !$('.back-to-top').data('animating')) { //$('.back-to-top').data('animating', true).blur().fadeOut(500, function() { $('.back-to-top').data('animating', true).blur().fadeOut(500, function() { $(this).data('animating', false); }); } } }, group: 'waypoint-group', offset: '-25%' }); } else { var bodyHeight = $('body').outerHeight(true); var percent25 = bodyHeight * 0.25; var siteWrapperHeight = $('#site-wrapper').outerHeight(true); $('#site-wrapper-msg').text(bodyHeight); waypoint = new Waypoint({ element: $('body'), handler: function(direction) { //log('Name: ', this.group.name, direction, 'body 25%') if (direction == "down") { if (!$('.back-to-top').is(':visible') && !$('.back-to-top').data('animating')) { $('.back-to-top').data('animating', true).fadeIn(500, function() { $(this).data('animating', false); }); } } else { if ($('.back-to-top').is(':visible') && !$('.back-to-top').data('animating')) { //$('.back-to-top').data('animating', true).blur().fadeOut(500, function() { $('.back-to-top').data('animating', true).blur().fadeOut(500, function() { $(this).data('animating', false); }); } } }, group: 'waypoint-group', offset: '-25%' }); } } if ($('.back-top').length > 0) { if (!isiOS) { waypoint = new Waypoint({ element: $('.back-top'), handler: function(direction) { log('Name: ', this.group.name, direction, 'back-top toggleClass') if (direction == "down") { $('.back-to-top').addClass('bottom'); } else { $('.back-to-top').removeClass('bottom'); } }, group: 'waypoint-group', offset: 'bottom-in-view' }); } else { log( 'back-top: ', $('.back-top').offset().top ); var bodyHeight = $('body').outerHeight(true); var backTopPos = $('.back-top').offset(); waypoint = new Waypoint({ element: $('.back-top'), handler: function(direction) { log('Name: ', this.group.name, direction, 'back-top toggleClass') if (direction == "down") { $('.back-to-top').addClass('bottom'); } else { $('.back-to-top').removeClass('bottom'); } }, group: 'waypoint-group', offset: 'bottom-in-view' }); } } setTimeout(function(){ Waypoint.refreshAll(); }, 500); } function initProgressBar() { //log( 'totalStep:', $('.progressbar2 li').length ); var totalStep = $('.progressbar2 li').length; var w = ((totalStep * 2) - 2) / (totalStep * 2) * 100; $('.progressbar2 .progress-holder').width(w + '%'); $('.progressbar2 li').each(function(index) { var percent = index/(totalStep - 1) * 100; $(this).data('before', percent); $(this).attr('data-before', percent); //log( index, $(this).data('step'), $(this).data('before'), percent) ; }); calProgressHeight(); if ($('.progress-container').length > 0) { progressContainerOffsetTop = $('.progress-container').offset().top; scrollPos = $(document).scrollTop(); $('#document-scrolltop-msg').text(scrollPos); } /* // METHOD 1 - OK $(window).scroll(function(){ scrollPos = $(document).scrollTop(); log('scrollPos', scrollPos); $('.debug-msg #scroll-msg').text(scrollPos); if (isiOS && keyboardOpened ) { if ( scrollPos - progressContainerOffsetTop > 0) { var offset = (scrollPos - progressContainerOffsetTop); $('.progress-container').css({'top':offset}); } else { $('.progress-container').css({'top':0}); } } }); $('input[type=text], textarea').on('focus', function(){ if (isiOS){ $('.debug-msg #isios-msg').html('YES keyboardOpened'); keyboardOpened = true; $('.progress-container').css({'position':'absolute'}); if ( scrollPos - progressContainerOffsetTop > 0) { var offset = (scrollPos - progressContainerOffsetTop); $('.progress-container').css({'top':offset}); } else { $('.progress-container').css({'top':0}); } } }); $('input[type=text], textarea').on('blur', function(){ if (isiOS){ $('.debug-msg #isios-msg').html('No keyboardClosed'); keyboardOpened = false; $('.progress-container').css({'position':'fixed'}); $('.progress-container').css({'top':0}); } }); */ // METHOD 2 // Fixed fixed position header when keyboard open /* $('input[type=text], textarea').on('focus', function(){ if (isiOS){ $('.debug-msg #isios-msg').html('YES keyboardOpened'); keyboardOpened = true; setTimeout(function(){ scrollPos = $(document).scrollTop(); $('#document-scrolltop-msg').text(scrollPos); if (keyboardOpened && $('.progress-container').hasClass('fixed')) { log('Updated Opened TOP', scrollPos); $('.progress-container').css({'top':scrollPos}); updateProgressPos(); } }, 100); } }); $('input[type=text], textarea').on('blur', function(){ if (isiOS){ $('.debug-msg #isios-msg').html('No keyboardClosed'); keyboardOpened = false; setTimeout(function(){ scrollPos = $(document).scrollTop(); $('#document-scrolltop-msg').text(scrollPos); if (!keyboardOpened && $('.progress-container').hasClass('fixed')) { log('Updated Closed TOP', 0); $('.progress-container').css({'top':0}); updateProgressPos(); } }, 100); } }); */ var context = window; if ($('.progress-container').length > 0) { if (!isiOS){ waypoint = new Waypoint({ element: $('.section-progress'), handler: function(direction) { if (direction == "down") { $('.progress-container').css({'position':'fixed'}); if (isiOS && keyboardOpened){ //$('.progress-container').css({'position':'absolute'}); $('.progress-container').css({'position':'relative'}); } } else { //$('.progress-container').css({'position':'absolute'}); $('.progress-container').css({'position':'relative'}); } }, //context: context }); } else { // Fixed fixed position header scrolling in ios since waypoint is not work & using -webkit-overflow-scrolling : touch /* $('#site-scoller').on('scroll', function(e) { var selected = $("input[type='text']:focus"); //log('selected:', selected); if (selected.length > 0) { //$(selected).trigger('blur'); } updateProgressPos(); }); */ waypoint = new Waypoint({ element: $('.section-progress'), handler: function(direction) { if (direction == "down") { $('.progress-container').css({'position':'fixed'}); if (isiOS && keyboardOpened){ //$('.progress-container').css({'position':'absolute'}); $('.progress-container').css({'position':'relative'}); } } else { //$('.progress-container').css({'position':'absolute'}); $('.progress-container').css({'position':'relative'}); } }, //context: context }); } } } function calProgressHeight() { $('.section-progress').height( $('.progress-container').outerHeight(true) ); } // Fixed fixed position header when keyboard open function updateProgressPos() { log('updateProgressPos'); var offset = ( $('#site-wrapper').offset().top ) * -1; //$('#progress-container-msg').text(progressContainerOffsetTop); //$('#overflow-scrolling-msg').text(offset + ' ' + $('body').scrollTop() + ' ' + $('html').scrollTop() + ' ' + $('#site-wrapper').scrollTop()); //$('#overflow-scrolling-msg').text(offset); if (progressContainerOffsetTop - offset - scrollPos <= 0 ) { //$('.progress-container').css({'position':'fixed'}); $('.progress-container').addClass('fixed'); $('.progress-container').css({'top':scrollPos}); } else { $('.progress-container').removeClass('fixed'); $('.progress-container').css({'top':0}); } } // INIT CHECKING // ----------------------------------------------------------------------------------------------------- function initChecking() { // CARD TYPE - initChecking // ----------------------------------------------------------------------------------------------------- $('input[type=checkbox][name=cardoa_cardtype1_CARDTYPE]').each(function( index ) { if ( !$(this).is(':disabled') ) { if ($(this).is(':checked')) { // $(this).prop('checked', true); // $(this).prop('required',true); // $(this).closest('.card-holder').addClass('active'); // $('input[name=cardoa_cardtype1_CARDTYPE_desc]').val( $(this).data('label') ); $(this).trigger('change'); } else { $(this).removeAttr('required'); $(this).prop('checked', false); $(this).prop('required',false); } } }); // Principal Cardholder Information - initChecking // ----------------------------------------------------------------------------------------------------- $('input[type=radio][name=ul_personal1_gender]').each(function( index ) { if ( !$(this).is(':disabled') ) { if ($(this).is(':checked')) { $(this).trigger('change'); } } }); if ( $('select[name=ul_personal1_ADDR_DISTRICT]').length > 0 ) { $('input[name=ul_personal1_ADDR_DISTRICT_desc]').val( $('select[name=ul_personal1_ADDR_DISTRICT] option:selected').text() ); } if ( $('select[name=ul_personal1_ADDR_REGION]').length > 0 ) { $('input[name=ul_personal1_ADDR_REGION_desc]').val( $('select[name=ul_personal1_ADDR_REGION] option:selected').text() ); } if ( $('select[name=ul_personal1_ADDR_COUNTRY]').length > 0 ) { $('input[name=ul_personal1_ADDR_COUNTRY_desc]').val( $('select[name=ul_personal1_ADDR_COUNTRY] option:selected').text() ); } if ( $('select[name=ul_personal1_ADDR_PERM_COUNTRY]').length > 0 ) { $('input[name=ul_personal1_ADDR_PERM_COUNTRY_desc]').val( $('select[name=ul_personal1_ADDR_PERM_COUNTRY] option:selected').text() ); } $('input[type=radio][name=ul_personal1_addr_home_same]').each(function( index ) { if ( !$(this).is(':disabled') ) { if ($(this).is(':checked') ) { $(this).trigger('change'); } } }); // WELCOME GIFT - initChecking // ----------------------------------------------------------------------------------------------------- if ( $('select[name=cardoa_GIFT]').length > 0 ) { $('input[name=cardoa_GIFT_desc]').val( $('select[name=cardoa_GIFT] option:selected').text() ); } // PERSONAL DATA - initChecking // ----------------------------------------------------------------------------------------------------- if ( $('select[name=ul_personal2_nationality]').length > 0 ) { $('input[name=ul_personal2_nationality_desc]').val( $('select[name=ul_personal2_nationality] option:selected').text() ); } $('input[type=checkbox][name=ul_personal2_multiple_nationality]').each(function( index ) { if ( !$(this).is(':disabled') ) { if ($(this).is(':checked')) { $(this).trigger('change'); } } }); if ( $('select[name=ul_personal2_nationality2]').length > 0 ) { $('input[name=ul_personal2_nationality2_desc]').val( $('select[name=ul_personal2_nationality2] option:selected').text() ); } if ( $('select[name=ul_personal2_nationality3]').length > 0 ) { $('input[name=ul_personal2_nationality3_desc]').val( $('select[name=ul_personal2_nationality3] option:selected').text() ); } if ( $('select[name=ul_personal2_nationality4]').length > 0 ) { $('input[name=ul_personal2_nationality4_desc]').val( $('select[name=ul_personal2_nationality4] option:selected').text() ); } if ( $('select[name=ul_personal2_nationality5]').length > 0 ) { $('input[name=ul_personal2_nationality5_desc]').val( $('select[name=ul_personal2_nationality5] option:selected').text() ); } if ( $('select[name=ul_personal2_edu_level]').length > 0 ) { $('input[name=ul_personal2_edu_level_desc]').val( $('select[name=ul_personal2_edu_level] option:selected').text() ); } if ( $('select[name=ul_personal2_resid_type]').length > 0 ) { $('input[name=ul_personal2_resid_type_desc]').val( $('select[name=ul_personal2_resid_type] option:selected').text() ); } $('input[type=checkbox][name=ul_personal2_mort_install_flag]').each(function( index ) { if ( !$(this).is(':disabled') ) { if ($(this).is(':checked')) { $(this).trigger('change'); } } else { if ($(this).is(':checked')) { // Disable hidden value $(this).prev( 'input[type=hidden][name=ul_personal2_mort_install_flag]' ).prop('disabled', true); } } }); $('input[type=checkbox][name=ul_personal2_air_china_member_flag]').each(function( index ) { if ( !$(this).is(':disabled') ) { if ($(this).is(':checked')) { $(this).trigger('change'); } } }); // FATCA AND CRS SELF CERTIFICATION - initChecking // ----------------------------------------------------------------------------------------------------- $('input[type=checkbox][name=ul_personal2_us_citizen]').each(function( index ) { if ( !$(this).is(':disabled') ) { if ($(this).is(':checked')) { $(this).trigger('change'); } } }); if ( $('select[name=crs_country_1]').length > 0 ) { if ( !$(this).is(':disabled') ) { $('input[name=crs_country_1_desc]').val( $('select[name=crs_country_1] option:selected').text() ); $('input[name=crs_reason_1_desc]').val( $('select[name=crs_reason_1] option:selected').text() ); if( $('select[name=crs_country_1]').val()=='HK' ){ $('input[name=crs_identifi_code_1]').prop('disabled', true); $('select[name=crs_reason_1]').prop('disabled', true); } } } if ( $('select[name=crs_country_2]').length > 0 ) { if ( !$(this).is(':disabled') ) { $('input[name=crs_country_2_desc]').val( $('select[name=crs_country_2] option:selected').text() ); $('input[name=crs_reason_2_desc]').val( $('select[name=crs_reason_2] option:selected').text() ); if( $('select[name=crs_country_2]').val()=='HK' ){ $('input[name=crs_identifi_code_2]').prop('disabled', true); $('select[name=crs_reason_2]').prop('disabled', true); } } } if ( $('select[name=crs_country_3]').length > 0 ) { if ( !$(this).is(':disabled') ) { $('input[name=crs_country_3_desc]').val( $('select[name=crs_country_3] option:selected').text() ); $('input[name=crs_reason_3_desc]').val( $('select[name=crs_reason_3] option:selected').text() ); if( $('select[name=crs_country_3]').val()=='HK' ){ $('input[name=crs_identifi_code_3]').prop('disabled', true); $('select[name=crs_reason_3]').prop('disabled', true); } } } if ( $('select[name=crs_country_4]').length > 0 ) { if ( !$(this).is(':disabled') ) { $('input[name=crs_country_4_desc]').val( $('select[name=crs_country_4] option:selected').text() ); $('input[name=crs_reason_4_desc]').val( $('select[name=crs_reason_4] option:selected').text() ); if( $('select[name=crs_country_4]').val()=='HK' ){ $('input[name=crs_identifi_code_4]').prop('disabled', true); $('select[name=crs_reason_4]').prop('disabled', true); } } } if ( $('select[name=crs_country_5]').length > 0 ) { if ( !$(this).is(':disabled') ) { $('input[name=crs_country_5_desc]').val( $('select[name=crs_country_5] option:selected').text() ); $('input[name=crs_reason_5_desc]').val( $('select[name=crs_reason_5] option:selected').text() ); if( $('select[name=crs_country_5]').val()=='HK' ){ $('input[name=crs_identifi_code_5]').prop('disabled', true); $('select[name=crs_reason_5]').prop('disabled', true); } } } $('input[type=checkbox][name=FATCA_W9_TICK]').each(function( index ) { if ( !$(this).is(':disabled') ) { if ($(this).is(':checked')) { $(this).trigger('change'); } } else { if ($(this).is(':checked')) { // Disable hidden value $(this).prev( 'input[type=hidden][name=FATCA_W9_TICK]' ).prop('disabled', true); } } }); $('input[type=checkbox][name=crs_perm_1]').each(function( index ) { if ( !$(this).is(':disabled') ) { if ($(this).is(':checked')) { $(this).trigger('change'); } } else { if ($(this).is(':checked')) { // Disable hidden value $(this).prev( 'input[type=hidden][name=crs_perm_1]' ).prop('disabled', true); } } }); $('input[type=checkbox][name=crs_perm_2]').each(function( index ) { if ( !$(this).is(':disabled') ) { if ($(this).is(':checked')) { $(this).trigger('change'); } } else { if ($(this).is(':checked')) { // Disable hidden value $(this).prev( 'input[type=hidden][name=crs_perm_2]' ).prop('disabled', true); } } }); $('input[type=checkbox][name=crs_perm_3]').each(function( index ) { if ( !$(this).is(':disabled') ) { if ($(this).is(':checked')) { $(this).trigger('change'); } } else { if ($(this).is(':checked')) { // Disable hidden value $(this).prev( 'input[type=hidden][name=crs_perm_3]' ).prop('disabled', true); } } }); if ( $('input[type=checkbox][name=crs_perm_1]').is(':checked') || $('input[type=checkbox][name=crs_perm_2]').is(':checked') || $('input[type=checkbox][name=crs_perm_3]').is(':checked') || $('input[type=checkbox][name=crs_perm_oth]').is(':checked') ) { $("#CRS_HID").val("2"); $("#CRS_ADDITIONAL_HID").val("2"); $("#additional_infor_table").css("display","block"); if ( $('input[type=checkbox][name=crs_perm_oth]').is(':checked') ) { if ( !$('input[type=checkbox][name=crs_perm_oth]').is(':disabled') ) { $('input[type=checkbox][name=crs_perm_oth]').trigger('change'); } else { // Disable hidden value //$('input[type=hidden][name=crs_perm_oth]').prop('disabled', true); $('input[type=checkbox][name=crs_perm_oth]').prev( 'input[type=hidden][name=crs_perm_oth]' ).prop('disabled', true); } } } // OCCUPATION - initChecking // ----------------------------------------------------------------------------------------------------- $('select[name=ul_occup2_BIZ_NATURE]').each(function( index ) { if ( !$(this).is(':disabled') ) { $(this).trigger('change'); } }); if ( $('select[name=ul_occup2_ADDR_OFF_DISTRICT]').length > 0 ) { $('input[name=ul_occup2_ADDR_OFF_DISTRICT_desc]').val( $('select[name=ul_occup2_ADDR_OFF_DISTRICT] option:selected').text() ); } if ( $('select[name=ul_occup2_ADDR_OFF_REGION]').length > 0 ) { $('input[name=ul_occup2_ADDR_OFF_REGION_desc]').val( $('select[name=ul_occup2_ADDR_OFF_REGION] option:selected').text() ); } if ( $('select[name=ul_occup2_ADDR_OFF_COUNTRY]').length > 0 ) { $('input[name=ul_occup2_ADDR_OFF_COUNTRY_desc]').val( $('select[name=ul_occup2_ADDR_OFF_COUNTRY] option:selected').text() ); } if ( $('select[name=ul_occup2_POSITION]').length > 0 ) { $('input[name=ul_occup2_POSITION_desc]').val( $('select[name=ul_occup2_POSITION] option:selected').text() ); } $('input[type=checkbox][name=ul_occup2_self_employ]').each(function( index ) { if ( !$(this).is(':disabled') ) { if ($(this).is(':checked')) { $(this).trigger('change'); } } else { if ($(this).is(':checked')) { // Disable hidden value $(this).prev( 'input[type=hidden][name=ul_occup2_self_employ]' ).prop('disabled', true); } } }); // REQUEST FOR OPT-OUT OF OVER-THE-CREDIT LIMIT FACILITIES - initChecking // ----------------------------------------------------------------------------------------------------- $('input[type=checkbox][name=UL_OPT_OUT_OVER_LIMIT]').each(function( index ) { if ( !$(this).is(':disabled') ) { if ($(this).is(':checked')) { $(this).trigger('change'); } } else { if ($(this).is(':checked')) { // Disable hidden value $(this).prev( 'input[type=hidden][name=UL_OPT_OUT_OVER_LIMIT]' ).prop('disabled', true); } } }); // ARE YOU A RELATIVE OF ANY DIRECTOR OR EMPLOYEE OF CHINA CITIC BANK INTERNATIONAL LIMITED - initChecking // ----------------------------------------------------------------------------------------------------- $('input[type=radio][name=relative_option_flag]').each(function( index ) { if ( !$(this).is(':disabled') ) { if ($(this).is(':checked')) { $(this).trigger('change'); } } }); if ( $('select[name=relative_relationship_flag]').length > 0 ) { $('input[name=relative_relationship_flag_desc]').val( $('select[name=relative_relationship_flag] option:selected').text() ); } // CHOOSE NOT TO ISSUE PIN - initChecking // ----------------------------------------------------------------------------------------------------- $('input[type=checkbox][name=PIN_OPT_OUT_PC]').each(function( index ) { if ( !$(this).is(':disabled') ) { if ($(this).is(':checked')) { $(this).trigger('change'); } } else { if ($(this).is(':checked')) { // Disable hidden value $(this).prev( 'input[type=hidden][name=PIN_OPT_OUT_PC]' ).prop('disabled', true); } } }); $('input[type=checkbox][name=PIN_OPT_OUT_SC]').each(function( index ) { if ( !$(this).is(':disabled') ) { if ($(this).is(':checked')) { $(this).trigger('change'); } } else { if ($(this).is(':checked')) { // Disable hidden value $(this).prev( 'input[type=hidden][name=PIN_OPT_OUT_SC]' ).prop('disabled', true); } } }); // REQUEST FOR OPT-OUT FROM USE OF PERSONAL DATA IN DIRECT MARKETING - initChecking // ----------------------------------------------------------------------------------------------------- $('input[type=checkbox][name=UL_OPT_OUT_REJECT]').each(function( index ) { if ( !$(this).is(':disabled') ) { if ($(this).is(':checked')) { $(this).trigger('change'); } } else { } }); $('input[type=checkbox][name=UL_OPT_OUT_POST]').each(function( index ) { if ( !$(this).is(':disabled') ) { if ($(this).is(':checked')) { $(this).trigger('change'); } } else { if ($(this).is(':checked')) { // Disable hidden value $(this).prev( 'input[type=hidden][name=UL_OPT_OUT_POST]' ).prop('disabled', true); } } }); $('input[type=checkbox][name=UL_OPT_OUT_EMAIL]').each(function( index ) { if ( !$(this).is(':disabled') ) { if ($(this).is(':checked')) { $(this).trigger('change'); } } else { if ($(this).is(':checked')) { // Disable hidden value $(this).prev( 'input[type=hidden][name=UL_OPT_OUT_EMAIL]' ).prop('disabled', true); } } }); $('input[type=checkbox][name=UL_OPT_OUT_TEL]').each(function( index ) { if ( !$(this).is(':disabled') ) { if ($(this).is(':checked')) { $(this).trigger('change'); } } else { if ($(this).is(':checked')) { // Disable hidden value $(this).prev( 'input[type=hidden][name=UL_OPT_OUT_TEL]' ).prop('disabled', true); } } }); $('input[type=checkbox][name=UL_OPT_OUT_SMS]').each(function( index ) { if ( !$(this).is(':disabled') ) { if ($(this).is(':checked')) { $(this).trigger('change'); } } else { if ($(this).is(':checked')) { // Disable hidden value $(this).prev( 'input[type=hidden][name=UL_OPT_OUT_SMS]' ).prop('disabled', true); } } }); $('input[type=checkbox][name=UL_OPT_OUT_3PARTY]').each(function( index ) { if ( !$(this).is(':disabled') ) { if ($(this).is(':checked')) { $(this).trigger('change'); } } else { if ($(this).is(':checked')) { // Disable hidden value $(this).prev( 'input[type=hidden][name=UL_OPT_OUT_3PARTY]' ).prop('disabled', true); } } }); // CUSTOMER DECLARATION - initChecking // ----------------------------------------------------------------------------------------------------- $('input[type=checkbox][name=NON_HONG_KONG_RESIDENT]').each(function( index ) { if ( !$(this).is(':disabled') ) { if ($(this).is(':checked')) { $(this).trigger('change'); } } else { if ($(this).is(':checked')) { // Disable hidden value $(this).prev( 'input[type=hidden][name=NON_HONG_KONG_RESIDENT]' ).prop('disabled', true); } } }); // TERMS & CONDITIONS - initChecking // ----------------------------------------------------------------------------------------------------- $('input[type=checkbox][name=ACCEPT_TNC]').each(function( index ) { if ( !$(this).is(':disabled') ) { if ($(this).is(':checked')) { $(this).trigger('change'); } } }); // WELCOME GIFT - initChecking // ----------------------------------------------------------------------------------------------------- if ( $('select[name=file_upload_APPTYPE_i]').length > 0 ) { $('input[name=file_upload_APPTYPE_i_desc]').val( $('select[name=file_upload_APPTYPE_i] option:selected').text() ); } } // SWITCH LANGUAGE function switchLang(to) { var currentStr = window.location.href; var currentLang = getUrlParameter('LANG'); log('currentLang:', currentLang, to); if (typeof currentLang != "undefined") { currentStr = currentStr.replace(currentLang, to); } else { var n = currentStr.indexOf("?"); if (n < 0) { currentStr = currentStr + '?LANG=' + to; } else { currentStr = currentStr + '&LANG=' + to; } } window.location.href = currentStr; } var getUrlParameter = function getUrlParameter(sParam) { var sPageURL = decodeURIComponent(window.location.search.substring(1)), sURLVariables = sPageURL.split('&'), sParameterName, i; for (i = 0; i < sURLVariables.length; i++) { sParameterName = sURLVariables[i].split('='); if (sParameterName[0].toUpperCase() === sParam) { return sParameterName[1] === undefined ? true : sParameterName[1]; } } }; // INIT EVENT // ----------------------------------------------------------------------------------------------------- function initEvent() { // testing $('.btn-testing').click(function(evt) { evt.preventDefault(); log('click btn-testing'); resetAllForm(); //var districtId = 1; //var branchId = 11; //log($('#input-district option[data-id="' + districtId + '"]')); }); $('.hahaha-testing').click(function(evt) { evt.preventDefault(); log('click hahaha-testing'); $('#hahaha').removeAttr( "disabled" ); }); $('.btn-lang').click(function(evt) { evt.preventDefault(); var targetLang = $(this).data('toLang'); log('click btn-lang', targetLang); switchLang(targetLang); }); // Principal Cardholder Information // ----------------------------------------------------------------------------------------------------- $('input[type=radio][name=ul_personal1_gender]').on('change', function() { // $('input[type=radio][name=ul_personal1_gender]').removeAttr('required'); $('input[type=radio][name=ul_personal1_gender]').removeAttr('required'); if ($(this).is(':checked')) { $(this).prop('required',true); //$('input[name=ul_personal1_gender_desc]').val( $(this).data('label') ); if ( $(this).data('label') == "" || typeof $(this).data('label') == "undefined" ) { $('input[name=ul_personal1_gender_desc]').val( $(this).val() ); } else { $('input[name=ul_personal1_gender_desc]').val( $(this).data('label') ); } } }); $('input[type=radio][name=ul_personal1_addr_home_same]').on('change', function() { log('ul_personal1_addr_home_same:', $(this).val(), $(this).is(':checked') ); $('input[type=radio][name=ul_personal1_addr_home_same]').removeAttr('required'); $(this).prop('required',true); switch($(this).val()) { case 'Y': if ( !$(this).is(':disabled') ) { $('input[name=ul_personal1_ADDR_PERM1]:not([type=hidden])').val(""); $('input[name=ul_personal1_ADDR_PERM2]:not([type=hidden])').val(""); $('input[name=ul_personal1_ADDR_PERM3]:not([type=hidden])').val(""); $('input[name=ul_personal1_ADDR_PERM4]:not([type=hidden])').val(""); $('input[name=ul_personal1_ADDR_PERM1]:not([type=hidden])').prop('disabled', true); $('input[name=ul_personal1_ADDR_PERM2]:not([type=hidden])').prop('disabled', true); $('input[name=ul_personal1_ADDR_PERM3]:not([type=hidden])').prop('disabled', true); $('input[name=ul_personal1_ADDR_PERM4]:not([type=hidden])').prop('disabled', true); $('input[name=ul_personal1_ADDR_PERM1]:not([type=hidden])').removeAttr('required'); $('input[name=ul_personal1_ADDR_PERM2]:not([type=hidden])').removeAttr('required'); $('input[name=ul_personal1_ADDR_PERM3]:not([type=hidden])').removeAttr('required'); $('input[name=ul_personal1_ADDR_PERM4]:not([type=hidden])').removeAttr('required'); $('select[name=ul_personal1_ADDR_PERM_COUNTRY]').val("").trigger('change'); $('select[name=ul_personal1_ADDR_PERM_COUNTRY]').prop('disabled', true); $('select[name=ul_personal1_ADDR_PERM_COUNTRY]').removeAttr('required'); } $('#permanentAddressDrawer').collapse('hide'); break; case 'N': if ($(this).is(':checked') ) { if ( !$(this).is(':disabled') ) { $('input[name=ul_personal1_ADDR_PERM1]:not([type=hidden])').removeAttr( "disabled" ); $('input[name=ul_personal1_ADDR_PERM2]:not([type=hidden])').removeAttr( "disabled" ); $('input[name=ul_personal1_ADDR_PERM3]:not([type=hidden])').removeAttr( "disabled" ); $('input[name=ul_personal1_ADDR_PERM4]:not([type=hidden])').removeAttr( "disabled" ); $('input[name=ul_personal1_ADDR_PERM1]:not([type=hidden])').prop('required',true); $('input[name=ul_personal1_ADDR_PERM2]:not([type=hidden])').prop('required',true); $('input[name=ul_personal1_ADDR_PERM3]:not([type=hidden])').prop('required',true); $('input[name=ul_personal1_ADDR_PERM4]:not([type=hidden])').prop('required',true); $('select[name=ul_personal1_ADDR_PERM_COUNTRY]').removeAttr( "disabled" ); $('select[name=ul_personal1_ADDR_PERM_COUNTRY]').prop('required',true); } $('#permanentAddressDrawer').collapse('show'); } break; } if ( $(this).data('label') == "" || typeof $(this).data('label') == "undefined" ) { $('input[name=ul_personal1_addr_home_same_desc]').val( $(this).val() ); } else { $('input[name=ul_personal1_addr_home_same_desc]').val( $(this).data('label') ); } }); // CARD TYPE // ----------------------------------------------------------------------------------------------------- $('html').on('click', function(e) { if (typeof $(e.target).data('original-title') == 'undefined' && !$(e.target).parents().is('.popover.show') && $('[data-original-title]').hasClass('shown')) { $('[data-original-title]').popover('hide'); } }); // $('#CNCBI_Credit_Card_label').popover({ // container: 'body', // placement: 'top', // trigger: 'hover' // }); $('.card-holder-popover').each(function( index ) { var popovertext = $(this).data('content'); //log('popovertext:', $(this), popovertext) if ( popovertext != null ) { $(this).popover({ html: true, placement: 'top', trigger: 'manual', }).on('shown.bs.popover', function(e) { }).on('hidden.bs.popover', function(e) { }).on('inserted.bs.popover', function (e) { // do something var target = e.target; if ( $(target).hasClass('card-holder-popover') ) { $('.popover').addClass('popover-card-holder'); } else { } }); } }); /* $('.card-holder-popover').popover({ //container: '#CARD_HOLDER_VISAPLAT', //container: this, html: true, placement: 'top', //trigger: 'hover', trigger: 'manual', //offset: 100 }).on('shown.bs.popover', function(e) { //$('.popover').popover('hide'); }).on('hidden.bs.popover', function(e) { }).on('inserted.bs.popover', function (e) { // do something var target = e.target; //log('1111', $(this), target); //log( $('.popover') ); //$(this).attr('id', 'my-popover'); if ( $(target).hasClass('card-holder-popover') ) { $('.popover').addClass('popover-card-holder'); } else { } }); */ /* $('#VISAPLATCUP_button_label').popover({ //container: 'body', container: '#VISAPLATCUP_label', placement: 'top', trigger: 'manual' }).on('shown.bs.popover', function(e) { log('2222'); $('.popover').removeClass('popover-card-holder'); }).on('inserted.bs.popover', function (e) { }); $('#PAYPASSCUP_button_label').popover({ //container: 'body', container: '#PAYPASSCUP_label', placement: 'top', trigger: 'manual' }).on('shown.bs.popover', function(e) { log('333', $('.popover') ); $('.popover').removeClass('popover-card-holder'); }).on('inserted.bs.popover', function (e) { }); $('#CUPDIAM_button_label').popover({ //container: 'body', container: '#CUPDIAM_label', placement: 'top', trigger: 'manual' }).on('shown.bs.popover', function(e) { log('444'); $('.popover').removeClass('popover-card-holder'); }).on('inserted.bs.popover', function (e) { }); */ $('.popup_button_label').each(function( index ) { var popovertext = $(this).data('content'); //log('popovertext:', $(this), popovertext) if ( popovertext != null ) { $(this).popover({ placement: 'top', trigger: 'manual' }).on('shown.bs.popover', function(e) { log('2222'); $('.popover').removeClass('popover-card-holder'); }).on('inserted.bs.popover', function (e) { }); } }); /* $('.popup_button_label').popover({ //container: 'body', //container: '#VISAPLATCUP_label', placement: 'top', trigger: 'manual' }).on('shown.bs.popover', function(e) { log('2222'); $('.popover').removeClass('popover-card-holder'); }).on('inserted.bs.popover', function (e) { }); */ if ( !Modernizr.touch ) { var attr = $('.card-holder-popover input').attr('disabled'); //if (typeof attr !== typeof undefined && attr !== false) { if (typeof attr != "undefined") { log("append"); if ( attr === true || attr == "disabled") { log("append"); $('.card-holder-popover').each(function( index ) { var popovertext = $(this).data('content'); $(this).find('.no-gutters').append('
'); if (input.length > 0) { return '
' + input + '
'; } else { return input; } } function filterEmpty(arr) { var new_arr = []; for (var i = arr.length-1; i >= 0; i--) { if (arr[i] != "") new_arr.push( (i+1) + ': ' + arr.pop()); else arr.pop(); } return new_arr.reverse(); } function getDateString() { var string = SYS_serverdate; var dateString = ""; var i; for (i = 0; i < string.length; i++) { if ((string.charAt(i)) != "-") dateString += string.charAt(i); } return dateString; } function onOrAfterToday(calyyyy, calmm, caldd) { var diff = dateDiff(calyyyy, calmm, caldd); if(diff == "-") { return false; } else { if(diff > 0) return false; else return true; } } function dateDiff2(calyyyy, calmm, caldd) { var diff = 0; if( caldd != null && calmm != null && calyyyy != null ) { if(calmm.length<2) { calmm = '0' + calmm; } if(caldd.length<2) { caldd = '0' + caldd; } log('getDateString:', getDateString, calyyyy, calmm, caldd); diff = getDateString() - parseInt(calyyyy + calmm + caldd, '10'); return diff; } else return "-"; } function daysInFebruary2(year) { return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 ); } function isDate2(strYear, strMonth, strDay) { var daysInMonth = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; month=parseInt(strMonth, '10'); day=parseInt(strDay, '10'); year=parseInt(strYear, '10'); if (strMonth.length<1 || month<1 || month>12) return false; if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]) return false; if (strYear.length != 4 || year==0 || year