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('
' + popovertext + '
'); }); } } else { $('.card-holder-popover').hover( function() { var popovertext = $(this).data('content'); if (popovertext != null) { $('.popover').popover('hide'); $( this ).popover('show'); } }, function() { var popovertext = $(this).data('content'); if (popovertext != null) { $( this ).popover('hide'); } } ); } } else { $('.card-holder-popover').each(function( index ) { var popovertext = $(this).data('content'); $(this).find('.no-gutters').append('
' + popovertext + '
'); }); } /* $('#VISAPLATCUP').change(function(e) { $('.popover').popover('hide'); $('.popover').removeClass('popover-card-holder'); if(this.checked) { $('#VISAPLATCUP_button_label').popover('show'); } else { $('#VISAPLATCUP_button_label').popover('hide'); } }); $('#PAYPASSCUP').change(function(e) { log('#PAYPASSCUP', $('.popover')); $('.popover').popover('hide'); $('.popover').removeClass('popover-card-holder'); if(this.checked) { $('#PAYPASSCUP_button_label').popover('show'); } else { $('#PAYPASSCUP_button_label').popover('hide'); } }); $('#CUPDIAM').change(function(e) { $('.popover').popover('hide'); $('.popover').removeClass('popover-card-holder'); if(this.checked) { $('#CUPDIAM_button_label').popover('show'); } else { $('#CUPDIAM_button_label').popover('hide'); } }); */ $('input[type=checkbox][name=cardoa_cardtype1_CARDTYPE]').change(function(e) { $('.popover').popover('hide'); $('.popover').removeClass('popover-card-holder'); if ($(this).is(':checked')) { log( 'popup_button_label:', $(this).next('.popup_button_label') ); var popovertext = $(this).next('.popup_button_label').data('content'); //log('popovertextpopovertextpopovertextpopovertext:', $(this), popovertext) if ( popovertext != null ) { $(this).next('.popup_button_label').popover('show'); } } else { log( 'popup_button_label:', $(this).next('.popup_button_label') ); $(this).next('.popup_button_label').popover('hide'); } }); $('input[type=checkbox][name=cardoa_cardtype1_CARDTYPE]').on('change', function() { var target = $(this).data('target'); log('HAHA', $(this).is(':checked'), target, $(this).val(), $(this).closest('.card-holder'), $(this).next('label'), $(this).next('label').data('content') ); if ( Modernizr.touch ) { if ( typeof ( $(this).next('label').data('content')) == "undefined") { $('.popover').popover('hide'); } else { if ($(this).next('label').data('content') == "" ) { $('.popover').popover('hide'); } } } log( $('input[type=checkbox][name=cardoa_cardtype1_CARDTYPE]:not(this)') ); $('.card-holder').removeClass('active'); $('input[type=checkbox][name=cardoa_cardtype1_CARDTYPE]').not(this).removeAttr('required'); $('input[type=checkbox][name=cardoa_cardtype1_CARDTYPE]').not(this).prop('checked', false); if ($(this).is(':checked')) { $(this).prop('checked', true); $(this).prop('required',true); $(this).closest('.card-holder').addClass('active'); } else { $(this).removeAttr('required'); $(this).prop('checked', false); $(this).prop('required',false); } $('input[name=cardoa_cardtype1_CARDTYPE_desc]').val( $(this).data('label') ); //$(target).collapse('toggle'); setCampaignCode(); }); $('.accordion-testing-btn').click(function(evt){ evt.preventDefault(); var target = $(this).data('target'); log( $(this).data('target') ); $(target).collapse('toggle'); }); // WELCOME GIFT // ----------------------------------------------------------------------------------------------------- // PRINCIPAL CARDHOLDER INFORMATION // ----------------------------------------------------------------------------------------------------- /* $('.btn-tnc').click(function(evt) { evt.preventDefault(); log('click btn-tnc'); var link = $(this).attr('href'); var msg = ''; $.ajax({ type: 'GET', url: link, cache: false, success: function(data, status, xhr) { log('data:', data); if ($(data).find('.section-tnc').length > 0) { msg = $(data).find('.section-tnc').html(); } else { msg = data; } showFancyBox(msg); }, error: function(jqXHR, textStatus, errorThrown) { } }); }); */ // PERSONAL DATA // ----------------------------------------------------------------------------------------------------- $('input[type=checkbox][name=ul_personal2_mort_install_flag]').on('change', function() { log('ul_personal2_mort_install_flag change', $(this).is(':checked') ); if ($(this).is(':checked')) { $('input[name=ul_personal2_MORT_INSTALL_AMT]').removeAttr( "disabled" ); $('input[name=ul_personal2_MORT_INSTALL_AMT]').prop('required',true); //$('input[name=ul_personal2_mort_install_flag_desc]').val( $(this).data('label') ); if ( $(this).data('label') == "" || typeof $(this).data('label') == "undefined" ) { $('input[name=ul_personal2_mort_install_flag_desc]').val( $(this).val() ); } else { $('input[name=ul_personal2_mort_install_flag_desc]').val( $(this).data('label') ); } // Disable hidden value // $('input[type=hidden][name=ul_personal2_mort_install_flag]').prop('disabled', true); $(this).prev( 'input[type=hidden][name=ul_personal2_mort_install_flag]' ).prop('disabled', true); } else { $('input[name=ul_personal2_MORT_INSTALL_AMT]').val(''); $('input[name=ul_personal2_MORT_INSTALL_AMT]').prop('disabled', true); $('input[name=ul_personal2_MORT_INSTALL_AMT]').removeAttr('required'); //$('input[name=ul_personal2_mort_install_flag_desc]').val( $('input[type=hidden][name=ul_personal2_mort_install_flag]').data('label') ); if ( $('input[type=hidden][name=ul_personal2_mort_install_flag]').data('label') == "" || typeof $('input[type=hidden][name=ul_personal2_mort_install_flag]').data('label') == "undefined" ) { $('input[name=ul_personal2_mort_install_flag_desc]').val( $('input[type=hidden][name=ul_personal2_mort_install_flag]').val() ); } else { $('input[name=ul_personal2_mort_install_flag_desc]').val( $('input[type=hidden][name=ul_personal2_mort_install_flag]').data('label') ); } // $('input[type=hidden][name=ul_personal2_mort_install_flag]').removeAttr( "disabled" ); $(this).prev( 'input[type=hidden][name=ul_personal2_mort_install_flag]' ).removeAttr( "disabled" ); } }); $('input[type=checkbox][name=ul_personal2_multiple_nationality]').change(function() { if ($(this).is(':checked')) { log('CHECK, then expand'); $('select[name=ul_personal2_nationality2]').prop('required',true); $('#multipleNationalityDrawer').collapse('show'); // Disable hidden value log('eeeeeeeeeeeeeeeee', $('input[type=hidden][name=ul_personal2_multiple_nationality]') ); log( $(this) ); log( $(this).closest( 'input[type=hidden][name=ul_personal2_multiple_nationality]' ) ); log( $(this).prev( 'input[type=hidden][name=ul_personal2_multiple_nationality]' ) ); //$('input[type=hidden][name=ul_personal2_multiple_nationality]').prop('disabled', true); $(this).prev( 'input[type=hidden][name=ul_personal2_multiple_nationality]' ).prop('disabled', true); } else { log('UnCheck'); $('select[name=ul_personal2_nationality2]').removeAttr('required'); $('select[name=ul_personal2_nationality2]').val("").trigger('change'); $('select[name=ul_personal2_nationality3]').val("").trigger('change'); $('select[name=ul_personal2_nationality4]').val("").trigger('change'); $('select[name=ul_personal2_nationality5]').val("").trigger('change'); $('#multipleNationalityDrawer').collapse('hide'); //$('input[type=hidden][name=ul_personal2_multiple_nationality]').removeAttr( "disabled" ); $(this).prev( 'input[type=hidden][name=ul_personal2_multiple_nationality]' ).removeAttr( "disabled" ); } //$('#collapseExample').collapse('toggle'); }); $('input[type=checkbox][name=ul_personal2_air_china_member_flag]').on('change', function() { var target = $(this).data('target'); log('ul_personal2_air_china_member_flag', $(this).is(':checked'), target); if ($(this).is(':checked')) { $(target).collapse('show'); $('input[name=ul_personal2_air_china_member_no]').prop('required',true); // Disable hidden value //$('input[type=hidden][name=ul_personal2_air_china_member_flag]').prop('disabled', true); $(this).prev( 'input[type=hidden][name=ul_personal2_air_china_member_flag]' ).prop('disabled', true); } else { $(target).collapse('hide'); $('input[name=ul_personal2_air_china_member_no]').removeAttr('required'); //$('input[type=hidden][name=ul_personal2_air_china_member_flag]').removeAttr( "disabled" ); $(this).prev( 'input[type=hidden][name=ul_personal2_air_china_member_flag]' ).removeAttr( "disabled" ); } }); // FATCA AND CRS SELF CERTIFICATION // ----------------------------------------------------------------------------------------------------- $('input[type=checkbox][name=ul_personal2_us_citizen]').on('change', function() { // if(this.checked) { if ($(this).is(':checked')) { log('CHECK, then expand'); if ( !$(this).is(':disabled') ) { $('input[name=ul_personal2_tax_ident_no]').removeAttr( "disabled" ); } $('input[name=ul_personal2_tax_ident_no]').prop('required',true); //$('input[name=ul_personal2_us_citizen_desc]').val( $(this).data('label') ); if ( $(this).data('label') == "" || typeof $(this).data('label') == "undefined" ) { $('input[name=ul_personal2_us_citizen_desc]').val( $(this).val() ); } else { $('input[name=ul_personal2_us_citizen_desc]').val( $(this).data('label') ); } // Disable hidden value //$('input[type=hidden][name=ul_personal2_us_citizen]').prop('disabled', true); $(this).prev( 'input[type=hidden][name=ul_personal2_us_citizen]' ).prop('disabled', true); } else { log('UnCheck'); $('input[name=ul_personal2_tax_ident_no]').val(""); $('input[name=ul_personal2_tax_ident_no]').prop('disabled', true); $('input[name=ul_personal2_tax_ident_no]').removeAttr('required'); //$('input[name=ul_personal2_us_citizen_desc]').val( "" ); //$('input[name=ul_personal2_us_citizen_desc]').val( $('input[type=hidden][name=ul_personal2_us_citizen]').data('label') ); if ( $(this).data('label') == "" || typeof $(this).data('label') == "undefined" ) { $('input[name=ul_personal2_us_citizen_desc]').val( $(this).val() ); } else { $('input[name=ul_personal2_us_citizen_desc]').val( $(this).data('label') ); } //$('input[type=hidden][name=ul_personal2_us_citizen]').removeAttr( "disabled" ); $(this).prev( 'input[type=hidden][name=ul_personal2_us_citizen]' ).removeAttr( "disabled" ); } $('#usDeclarationDrawer').collapse('toggle'); }); $('input[type=checkbox][name=FATCA_W9_TICK]').on('change', function() { if ($(this).is(':checked')) { // Disable hidden value // $('input[type=hidden][name=FATCA_W9_TICK]').prop('disabled', true); $(this).prev( 'input[type=hidden][name=FATCA_W9_TICK]' ).prop('disabled', true); } else { // $('input[type=hidden][name=FATCA_W9_TICK]').removeAttr( "disabled" ); $(this).prev( 'input[type=hidden][name=FATCA_W9_TICK]' ).removeAttr( "disabled" ); } }); $('#crs_perm_1, #crs_perm_2, #crs_perm_3').change(function() { if ($(this).is(':checked')) { //$('#crs_perm_oth').removeAttr( "disabled" ); $('#crs_perm_oth_text').val(""); $('#crs_perm_oth_text').prop('disabled', true); $('#crs_perm_oth').attr('checked', false); $('#crs_perm_oth').prop('disabled', true); log("-------------------", $(this), $(this).attr('id') ); // Disable hidden value if ( $(this).attr('id') == 'crs_perm_1' ) { $(this).prev( 'input[type=hidden][name=crs_perm_1]' ).prop('disabled', true); } else if ( $(this).attr('id') == 'crs_perm_2' ) { $(this).prev( 'input[type=hidden][name=crs_perm_2]' ).prop('disabled', true); } else if ( $(this).attr('id') == 'crs_perm_3' ) { $(this).prev( 'input[type=hidden][name=crs_perm_3]' ).prop('disabled', true); } } else { //log($('#crs_perm_1').filter(':checked').val(), $('#crs_perm_2').filter(':checked').val(), $('#crs_perm_3').filter(':checked').val(), $('#crs_perm_1').is(":checked") ); //if ( $('#crs_perm_1').filter(':checked').val() != 'true' && $('#crs_perm_2').filter(':checked').val() != 'true' && $('#crs_perm_3').filter(':checked').val() != 'true' ) { if ( !$('#crs_perm_1').is(":checked") && !$('#crs_perm_2').is(":checked") && !$('#crs_perm_3').is(":checked") ) { $('#crs_perm_oth').removeAttr( "disabled" ); } if ( $(this).attr('id') == 'crs_perm_1' ) { $(this).prev( 'input[type=hidden][name=crs_perm_1]' ).removeAttr( "disabled" ); } else if ( $(this).attr('id') == '#crs_perm_2' ) { $(this).prev( 'input[type=hidden][name=crs_perm_2]' ).removeAttr( "disabled" ); } else if ( $(this).attr('id') == '#crs_perm_3' ) { $(this).prev( 'input[type=hidden][name=crs_perm_3]' ).removeAttr( "disabled" ); } } }); $('input[type=checkbox][name=crs_perm_oth]').change(function() { if ($(this).is(':checked')) { log('crs_perm_oth:', $(this).is(':checked')) $('#crs_perm_oth_text').removeAttr( "disabled" ); // Disable hidden value //$('input[type=hidden][name=crs_perm_oth]').prop('disabled', true); $(this).prev( 'input[type=hidden][name=crs_perm_oth]' ).prop('disabled', true); } else { $('#crs_perm_oth_text').val(""); $('#crs_perm_oth_text').prop('disabled', true); //$('input[type=hidden][name=crs_perm_oth]').removeAttr( "disabled" ); $(this).prev( 'input[type=hidden][name=crs_perm_oth]' ).removeAttr( "disabled" ); } }); // CRS - PART 2 // ----------------------------------------------------------------------------------------------------- // OCCUPATION // ----------------------------------------------------------------------------------------------------- $('select[name=ul_occup2_INDUSTRY]').change(function() { $('#occupationDrawer').collapse('hide'); // 20240101 $('#occupationDrawer2').collapse('hide'); // END 20240101 $('select[name=ul_occup2_BIZ_NATURE]').find('option[value!=\'\']').remove().end(); $('input[name=ul_occup2_BIZ_NATURE_desc]').val(''); if($(this).val() != ""){ $('select[name=ul_occup2_BIZ_NATURE]').removeAttr( "disabled" ); const obj = JSON.parse(BIZ_NATURE_JSON); if(obj != null && obj != undefined){ var arrayList = obj[$(this).val()]; if(arrayList != null && arrayList != undefined ){ for(var i = 0; i < arrayList.length; i++){ $('select[name=ul_occup2_BIZ_NATURE]').append(new Option(arrayList[i][0], arrayList[i][1])); } } } } else{ $('select[name=ul_occup2_BIZ_NATURE]').prop('disabled', true); } }); // 20240101 /* $('select[name=ul_occup2_BIZ_NATURE]').change(function() { log('ul_occup2_BIZ_NATURE:', $(this).val()); if ( $(this).val() == "HWF" || $(this).val() == "RET" || $(this).val() == "STU" || $(this).val() == "UNE") { $('#occupationDrawer').collapse('hide'); //$('select[name=ul_personal2_addr_mailing]').val('H').trigger('change'); $('input[name=ul_occup2_COMPANY]').removeAttr('required'); $('select[name=ul_occup2_POSITION]').removeAttr('required'); // $('input[name=ul_occup2_PHONE_OFF]').removeAttr('required'); $('select[name=ul_occup2_CUR_POSITION_YRS]').removeAttr('required'); $('input[name=ul_occup2_INCOME_MTHS]').removeAttr('required'); // $('input[name=ul_occup2_ADDR_OFF_FLAT]').removeAttr('required'); // $('input[name=ul_occup2_ADDR_OFF_FLOOR]').removeAttr('required'); // $('input[name=ul_occup2_ADDR_OFF_BLOCK]').removeAttr('required'); // $('input[name=ul_occup2_ADDR_OFF_BUILDING]').removeAttr('required'); // $('input[name=ul_occup2_ADDR_OFF_STREET]').removeAttr('required'); // $('select[name=ul_occup2_ADDR_OFF_DISTRICT]').removeAttr('required'); // $('select[name=ul_occup2_ADDR_OFF_REGION]').removeAttr('required'); // $('select[name=ul_occup2_ADDR_OFF_COUNTRY]').removeAttr('required'); switch ($(this).val()) { case "HWF": $('select[name=ul_occup2_POSITION]').val("913").change(); break; case "RET": $('select[name=ul_occup2_POSITION]').val("914").change(); break; case "STU": $('select[name=ul_occup2_POSITION]').val("911").change(); break; case "UNE": $('select[name=ul_occup2_POSITION]').val("915").change(); break; } } else if ( $(this).val() != "" ) { $('#occupationDrawer').collapse('show'); // if ( $('select[name=ul_personal2_addr_mailing]').val() == "H" ) { // // $('select[name=ul_personal2_addr_mailing]').val('').trigger('change'); // } $('input[name=ul_occup2_COMPANY]').prop('required',true); $('select[name=ul_occup2_POSITION]').prop('required',true); // $('input[name=ul_occup2_PHONE_OFF]').prop('required',true); $('select[name=ul_occup2_CUR_POSITION_YRS]').prop('required',true); $('input[name=ul_occup2_INCOME_MTHS]').prop('required',true); // $('input[name=ul_occup2_ADDR_OFF_FLAT]').prop('required',true); // $('input[name=ul_occup2_ADDR_OFF_FLOOR]').prop('required',true); // $('input[name=ul_occup2_ADDR_OFF_BLOCK]').prop('required',true); // $('input[name=ul_occup2_ADDR_OFF_BUILDING]').prop('required',true); // $('input[name=ul_occup2_ADDR_OFF_STREET]').prop('required',true); // $('select[name=ul_occup2_ADDR_OFF_DISTRICT]').prop('required',true); // $('select[name=ul_occup2_ADDR_OFF_REGION]').prop('required',true); // $('select[name=ul_occup2_ADDR_OFF_COUNTRY]').prop('required',true); } }); */ $('select[name=ul_occup2_BIZ_NATURE]').change(function() { log('ul_occup2_BIZ_NATURE:', $(this).val()); if ( $(this).val() == "STU" ) { $('#occupationDrawer').collapse('hide'); $('input[name=ul_occup2_COMPANY]').removeAttr('required'); $('select[name=ul_occup2_POSITION]').removeAttr('required'); $('select[name=ul_occup2_CUR_POSITION_YRS]').removeAttr('required'); $('input[name=ul_occup2_INCOME_MTHS]').removeAttr('required'); switch ($(this).val()) { case "STU": $('select[name=ul_occup2_POSITION]').val("911").change(); break; } // Hide occupationDrawer2 $('#occupationDrawer2').collapse('hide'); $('input[name=ul_occup2_DISPOSABLE_INCOME]').removeAttr('required'); } else if ( $(this).val() == "HWF" || $(this).val() == "RET" || $(this).val() == "UNE") { $('#occupationDrawer').collapse('hide'); $('input[name=ul_occup2_COMPANY]').removeAttr('required'); $('select[name=ul_occup2_POSITION]').removeAttr('required'); $('select[name=ul_occup2_CUR_POSITION_YRS]').removeAttr('required'); $('input[name=ul_occup2_INCOME_MTHS]').removeAttr('required'); switch ($(this).val()) { case "HWF": $('select[name=ul_occup2_POSITION]').val("913").change(); break; case "RET": $('select[name=ul_occup2_POSITION]').val("914").change(); break; case "UNE": $('select[name=ul_occup2_POSITION]').val("915").change(); break; } // Show occupationDrawer2 $('#occupationDrawer2').collapse('show'); $('input[name=ul_occup2_DISPOSABLE_INCOME]').prop('required',true); } else if ( $(this).val() != "" ) { $('#occupationDrawer').collapse('show'); $('input[name=ul_occup2_COMPANY]').prop('required',true); $('select[name=ul_occup2_POSITION]').prop('required',true); $('select[name=ul_occup2_CUR_POSITION_YRS]').prop('required',true); $('input[name=ul_occup2_INCOME_MTHS]').prop('required',true); // Hide occupationDrawer2 $('#occupationDrawer2').collapse('hide'); $('input[name=ul_occup2_DISPOSABLE_INCOME]').removeAttr('required'); } }); // END 20240101 // CREDIT REFERENCE OF OTHER BANKS & FINANCIAL INSTITUTIONS // ----------------------------------------------------------------------------------------------------- $('#ul_bk_ref_OTH_CARD_NUM_HOLD').change(function() { if( $(this).val() != "" && parseInt($(this).val(), '10') > 0) { $('#ul_bk_ref_OTH_CARD_TOTAL_OS_BAL').prop('required',true); $('#ul_bk_ref_OTH_CARD_TOTAL_LMT').prop('required',true); } else { $('#ul_bk_ref_OTH_CARD_TOTAL_OS_BAL').removeAttr('required'); $('#ul_bk_ref_OTH_CARD_TOTAL_LMT').removeAttr('required'); } }); $('input[type=checkbox][name=ul_bk_ref_ckwb_cust]').on('change', function() { if ($(this).is(':checked')) { $('input[name=ul_bk_ref_ckwb_cust_desc]').val( $(this).data('label') ); } else { $('input[name=ul_bk_ref_ckwb_cust_desc]').val( "" ); } }); $('input[type=checkbox][name=ul_bk_ref_oth_bk_chq_acc]').on('change', function() { if ($(this).is(':checked')) { $('input[name=ul_bk_ref_oth_bk_chq_acc_desc]').val( $(this).data('label') ); } else { $('input[name=ul_bk_ref_oth_bk_chq_acc_desc]').val( "" ); } }); $('input[type=checkbox][name=ul_bk_ref_oth_bk_sav_acc]').on('change', function() { if ($(this).is(':checked')) { $('input[name=ul_bk_ref_oth_bk_sav_acc_desc]').val( $(this).data('label') ); } else { $('input[name=ul_bk_ref_oth_bk_sav_acc_desc]').val( "" ); } }); $('input[type=checkbox][name=ul_bk_ref_oth_bk_unsec_od]').on('change', function() { if ($(this).is(':checked')) { $('input[name=ul_bk_ref_oth_bk_unsec_od_desc]').val( $(this).data('label') ); } else { $('input[name=ul_bk_ref_oth_bk_unsec_od_desc]').val( "" ); } }); $('input[type=checkbox][name=ul_bk_ref_oth_bk_per_loan]').on('change', function() { if ($(this).is(':checked')) { $('input[name=ul_bk_ref_oth_bk_per_loan_desc]').val( $(this).data('label') ); } else { $('input[name=ul_bk_ref_oth_bk_per_loan_desc]').val( "" ); } }); $('input[type=checkbox][name=ul_bk_ref_oth_bk_deposit]').on('change', function() { if ($(this).is(':checked')) { $('input[name=ul_bk_ref_oth_bk_deposit_desc]').val( $(this).data('label') ); } else { $('input[name=ul_bk_ref_oth_bk_deposit_desc]').val( "" ); } }); $('input[type=checkbox][name=ul_bk_ref_oth_bk_auto_loan]').on('change', function() { if ($(this).is(':checked')) { $('input[name=ul_bk_ref_oth_bk_auto_loan_desc]').val( $(this).data('label') ); } else { $('input[name=ul_bk_ref_oth_bk_auto_loan_desc]').val( "" ); } }); // REQUEST FOR OPT-OUT OF OVER-THE-CREDIT LIMIT FACILITIES // ----------------------------------------------------------------------------------------------------- $('input[type=checkbox][name=UL_OPT_OUT_OVER_LIMIT]').on('change', function() { if ($(this).is(':checked')) { // Disable hidden value // $('input[type=hidden][name=UL_OPT_OUT_OVER_LIMIT]').prop('disabled', true); $(this).prev( 'input[type=hidden][name=UL_OPT_OUT_OVER_LIMIT]' ).prop('disabled', true); } else { // $('input[type=hidden][name=UL_OPT_OUT_OVER_LIMIT]').removeAttr( "disabled" ); $(this).prev( 'input[type=hidden][name=UL_OPT_OUT_OVER_LIMIT]' ).removeAttr( "disabled" ); } }); // ARE YOU A RELATIVE OF ANY DIRECTOR OR EMPLOYEE OF CHINA CITIC BANK INTERNATIONAL LIMITED // ----------------------------------------------------------------------------------------------------- $('input[type=radio][name=relative_option_flag]').on('change', function() { log($(this).val()); $('input[type=radio][name=relative_option_flag]').removeAttr('required'); $(this).prop('required',true); switch($(this).val()) { case 'true': $('#relativeOptionDrawer').collapse('show'); if ( !$(this).is(':disabled') ) { $('#relative_input_text_name_1').prop('required',true); $('#relative_input_company_name_1').prop('required',true); $('#relative_input_dept_in_company_1').prop('required',true); $('#relative_input_name_of_applicant_1').prop('required',true); $('#relative_relationship_type_1').prop('required',true); } break; case 'false': $('#relativeOptionDrawer').collapse('hide'); if ( !$(this).is(':disabled') ) { $('#relative_input_text_name_1').removeAttr('required'); $('#relative_input_text_name_2').removeAttr('required'); $('#relative_input_text_name_3').removeAttr('required'); $('#relative_input_text_name_4').removeAttr('required'); $('#relative_input_text_name_5').removeAttr('required'); $('#relative_input_company_name_1').removeAttr('required'); $('#relative_input_company_name_2').removeAttr('required'); $('#relative_input_company_name_3').removeAttr('required'); $('#relative_input_company_name_4').removeAttr('required'); $('#relative_input_company_name_5').removeAttr('required'); $('#relative_input_dept_in_company_1').removeAttr('required'); $('#relative_input_dept_in_company_2').removeAttr('required'); $('#relative_input_dept_in_company_3').removeAttr('required'); $('#relative_input_dept_in_company_4').removeAttr('required'); $('#relative_input_dept_in_company_5').removeAttr('required'); $('#relative_input_name_of_applicant_1').removeAttr('required'); $('#relative_input_name_of_applicant_2').removeAttr('required'); $('#relative_input_name_of_applicant_3').removeAttr('required'); $('#relative_input_name_of_applicant_4').removeAttr('required'); $('#relative_input_name_of_applicant_5').removeAttr('required'); $('#relative_relationship_type_1').removeAttr('required'); $('#relative_relationship_type_2').removeAttr('required'); $('#relative_relationship_type_3').removeAttr('required'); $('#relative_relationship_type_4').removeAttr('required'); $('#relative_relationship_type_5').removeAttr('required'); } break; } // $('#relativeOptionDrawer').collapse('toggle'); }); $('input[type=button][name=AddRelationship_person]').on('click', function() { for(i =2; i <= 5 ; i++){ if($('#relative_relationship_person_R'+i).hasClass('collapse') && !$('#relative_relationship_person_R'+i).hasClass('show')){ $('#relative_relationship_person_R'+i).collapse('show'); if(i == 5){ $(this).addClass('invisible'); } break; } } }); // $('#relative_relationship_flag').change(function() { // $('input[name=relative_relationship_flag_desc]').val( $('#relative_relationship_flag option:selected').text() ); // }); // CHOOSE NOT TO ISSUE PIN // ----------------------------------------------------------------------------------------------------- $('input[type=checkbox][name=PIN_OPT_OUT_PC]').on('change', function() { if ($(this).is(':checked')) { // Disable hidden value // $('input[type=hidden][name=PIN_OPT_OUT_PC]').prop('disabled', true); $(this).prev( 'input[type=hidden][name=PIN_OPT_OUT_PC]' ).prop('disabled', true); } else { // $('input[type=hidden][name=PIN_OPT_OUT_PC]').removeAttr( "disabled" ); $(this).prev( 'input[type=hidden][name=PIN_OPT_OUT_PC]' ).removeAttr( "disabled" ); } }); $('input[type=checkbox][name=PIN_OPT_OUT_SC]').on('change', function() { if ($(this).is(':checked')) { // Disable hidden value // $('input[type=hidden][name=PIN_OPT_OUT_SC]').prop('disabled', true); $(this).prev( 'input[type=hidden][name=PIN_OPT_OUT_SC]' ).prop('disabled', true); } else { // $('input[type=hidden][name=PIN_OPT_OUT_SC]').removeAttr( "disabled" ); $(this).prev( 'input[type=hidden][name=PIN_OPT_OUT_SC]' ).removeAttr( "disabled" ); } }); // REQUEST FOR OPT-OUT FROM USE OF PERSONAL DATA IN DIRECT MARKETING // ----------------------------------------------------------------------------------------------------- $('input[type=checkbox][name=UL_OPT_OUT_REJECT]').on('change', function() { if ($(this).is(':checked')) { log('CHECK, then expand'); if ( !$(this).is(':disabled') ) { $('input[type=checkbox][name=UL_OPT_OUT_POST]').removeAttr( "disabled" ); $('input[type=checkbox][name=UL_OPT_OUT_EMAIL]').removeAttr( "disabled" ); $('input[type=checkbox][name=UL_OPT_OUT_TEL]').removeAttr( "disabled" ); $('input[type=checkbox][name=UL_OPT_OUT_SMS]').removeAttr( "disabled" ); } // Disable hidden value //$('input[type=hidden][name=UL_OPT_OUT_REJECT]').prop('disabled', true); $(this).prev( 'input[type=hidden][name=UL_OPT_OUT_REJECT]' ).prop('disabled', true); } else { log('UnCheck'); if ( !$(this).is(':disabled') ) { $('input[type=checkbox][name=UL_OPT_OUT_POST]').prop('checked', false); $('input[type=checkbox][name=UL_OPT_OUT_POST]').prop('disabled', true); $('input[type=hidden][name=UL_OPT_OUT_POST]').removeAttr( "disabled" ); $('input[type=checkbox][name=UL_OPT_OUT_EMAIL]').prop('checked', false); $('input[type=checkbox][name=UL_OPT_OUT_EMAIL]').prop('disabled', true); $('input[type=hidden][name=UL_OPT_OUT_EMAIL]').removeAttr( "disabled" ); $('input[type=checkbox][name=UL_OPT_OUT_TEL]').prop('checked', false); $('input[type=checkbox][name=UL_OPT_OUT_TEL]').prop('disabled', true); $('input[type=hidden][name=UL_OPT_OUT_TEL]').removeAttr( "disabled" ); $('input[type=checkbox][name=UL_OPT_OUT_SMS]').prop('checked', false); $('input[type=checkbox][name=UL_OPT_OUT_SMS]').prop('disabled', true); $('input[type=hidden][name=UL_OPT_OUT_SMS]').removeAttr( "disabled" ); } //$('input[type=hidden][name=UL_OPT_OUT_REJECT]').removeAttr( "disabled" ); $(this).prev( 'input[type=hidden][name=UL_OPT_OUT_REJECT]' ).removeAttr( "disabled" ); } $('#channelDrawer').collapse('toggle'); }); $('input[type=checkbox][name=UL_OPT_OUT_POST]').on('change', function() { if ($(this).is(':checked')) { // Disable hidden value //$('input[type=hidden][name=UL_OPT_OUT_POST]').prop('disabled', true); $(this).prev( 'input[type=hidden][name=UL_OPT_OUT_POST]' ).prop('disabled', true); } else { // $('input[type=hidden][name=UL_OPT_OUT_POST]').removeAttr( "disabled" ); $(this).prev( 'input[type=hidden][name=UL_OPT_OUT_POST]' ).removeAttr( "disabled" ); } }); $('input[type=checkbox][name=UL_OPT_OUT_EMAIL]').on('change', function() { if ($(this).is(':checked')) { // Disable hidden value // $('input[type=hidden][name=UL_OPT_OUT_EMAIL]').prop('disabled', true); $(this).prev( 'input[type=hidden][name=UL_OPT_OUT_EMAIL]' ).prop('disabled', true); } else { // $('input[type=hidden][name=UL_OPT_OUT_EMAIL]').removeAttr( "disabled" ); $(this).prev( 'input[type=hidden][name=UL_OPT_OUT_EMAIL]' ).removeAttr( "disabled" ); } }); $('input[type=checkbox][name=UL_OPT_OUT_TEL]').on('change', function() { if ($(this).is(':checked')) { // Disable hidden value // $('input[type=hidden][name=UL_OPT_OUT_TEL]').prop('disabled', true); $(this).prev( 'input[type=hidden][name=UL_OPT_OUT_TEL]' ).prop('disabled', true); } else { // $('input[type=hidden][name=UL_OPT_OUT_TEL]').removeAttr( "disabled" ); $(this).prev( 'input[type=hidden][name=UL_OPT_OUT_TEL]' ).removeAttr( "disabled" ); } }); $('input[type=checkbox][name=UL_OPT_OUT_SMS]').on('change', function() { if ($(this).is(':checked')) { // Disable hidden value // $('input[type=hidden][name=UL_OPT_OUT_SMS]').prop('disabled', true); $(this).prev( 'input[type=hidden][name=UL_OPT_OUT_SMS]' ).prop('disabled', true); } else { // $('input[type=hidden][name=UL_OPT_OUT_SMS]').removeAttr( "disabled" ); $(this).prev( 'input[type=hidden][name=UL_OPT_OUT_SMS]' ).removeAttr( "disabled" ); } }); $('input[type=checkbox][name=UL_OPT_OUT_3PARTY]').on('change', function() { if ($(this).is(':checked')) { // Disable hidden value // $('input[type=hidden][name=UL_OPT_OUT_3PARTY]').prop('disabled', true); $(this).prev( 'input[type=hidden][name=UL_OPT_OUT_3PARTY]' ).prop('disabled', true); } else { // $('input[type=hidden][name=UL_OPT_OUT_3PARTY]').removeAttr( "disabled" ); $(this).prev( 'input[type=hidden][name=UL_OPT_OUT_3PARTY]' ).removeAttr( "disabled" ); } }); if ( !Modernizr.touch ) { var popovertext = $('#UL_OPT_OUT_REJECT_LABEL').data('content'); //log('popovertext:', popovertext) if ( popovertext != null ) { $('#UL_OPT_OUT_REJECT_LABEL').popover({ container: 'body', placement: 'top', trigger: 'hover' }); } } else { var popovertext = $('#UL_OPT_OUT_REJECT_LABEL').data('content'); log('popovertext:', popovertext); if ( popovertext != null ) { $('#UL_OPT_OUT_REJECT_LABEL').closest('.form-group').append('
' + popovertext + '
'); } } // CUSTOMER DECLARATION // ----------------------------------------------------------------------------------------------------- $('input[type=checkbox][name=NON_HONG_KONG_RESIDENT]').on('change', function() { if ($(this).is(':checked')) { // Disable hidden value //$('input[type=hidden][name=NON_HONG_KONG_RESIDENT]').prop('disabled', true); $(this).prev( 'input[type=hidden][name=NON_HONG_KONG_RESIDENT]' ).prop('disabled', true); $( 'input[type=hidden][name=NON_HONG_KONG_RESIDENT][value=false]' ).prop('disabled', true); } else { //$('input[type=hidden][name=NON_HONG_KONG_RESIDENT]').removeAttr( "disabled" ); $(this).prev( 'input[type=hidden][name=NON_HONG_KONG_RESIDENT]' ).removeAttr( "disabled" ); $( 'input[type=hidden][name=NON_HONG_KONG_RESIDENT][value=false]' ).removeAttr( "disabled" ); $( 'input[type=hidden][name=NON_HONG_KONG_RESIDENT][value=true]' ).prop('disabled', true); } }); // Terms & Conditions // ----------------------------------------------------------------------------------------------------- $('input[type=checkbox][name=ACCEPT_TNC]').on('change', function() { if ($(this).is(':checked')) { // Disable hidden value //$('input[type=hidden][name=ACCEPT_TNC]').prop('disabled', true); $(this).prev( 'input[type=hidden][name=ACCEPT_TNC]' ).prop('disabled', true); } else { //$('input[type=hidden][name=ACCEPT_TNC]').removeAttr( "disabled" ); $(this).prev( 'input[type=hidden][name=ACCEPT_TNC]' ).removeAttr( "disabled" ); } }); // DECLARATIONS // ----------------------------------------------------------------------------------------------------- $('.btn-declarations').click(function(evt) { evt.preventDefault(); log('click btn-declarations'); }); // SUBMIT FORM // ----------------------------------------------------------------------------------------------------- // $('#btn-close').click(function(evt) { // evt.preventDefault(); // log('click btn-close', evt); // winclose(); // }); $('#btn-submit').click(function(evt) { evt.preventDefault(); log('Click btn-submit'); if (mode == "UAT" || mode == "LOCAL") { submitform2(); } else { submitform(document.forms.campaignform); } }); $('#btn-debug-submit').click(function(evt) { evt.preventDefault(); //log('click btn-debug-submit'); if (mode == "UAT" || mode == "LOCAL") { submitform2(); } else { submitform(document.forms.campaignform); } }); // REAL-TIME CHECKING // ----------------------------------------------------------------------------------------------------- //$('input, textarea, select').on('input change focusout', function(){ // $('input[type=text], textarea').on('input', function(e){ $('input[type=text], textarea').on('input', function(e){ var target = e.target; log('%c e: %s', 'color: green; font-weight: bold;', e.type, $(target).attr('name') ); realtimeChecking( this ); }); $('input[type=checkbox], input[type=radio]').on('change', function(e){ var target = e.target; log('%c e: %s', 'color: green; font-weight: bold;', e.type, $(target).attr('name') ); if ( e.originalEvent === undefined ) { } else { realtimeChecking( this ); } }); $('input[type=file]').on('change', function(e){ var target = e.target; log('%c e: %s', 'color: green; font-weight: bold;', e.type, $(target).attr('name') ); if ( e.originalEvent === undefined ) { } else { realtimeChecking( this ); } }); $('select').on('change', function(e){ var isHuman = true; if ( e.originalEvent === undefined ) { isHuman = false; } var target = e.target; log('%c e: %s', 'color: green; font-weight: bold;', e.type, $(target).attr('name'), isHuman ); if (isHuman) { realtimeChecking( this ); } }); $(window).on("throttledresize", function( event ) { debouncedresize(); }); debouncedresize(); updateProgress(); } function realtimeChecking(ele) { if (!firstTime) { log('realtimeChecking input:::change', $(ele), $(ele).attr('name') ); var $form = $('form[name=campaignform]'); var attrName = $(ele).attr('name'); var errormsg = ''; switch (attrName) { case 'ul_personal1_SURNAME': if (typeof checkSurname === "function") { errormsg = checkSurname( $form ); } break; case 'ul_personal1_GIVEN_NAME': if (typeof checkGivenname === "function") { errormsg = checkGivenname( $form ); } break; case 'ul_personal1_gender': if (typeof checkGender === "function") { errormsg = checkGender( $form ); } break; case 'ul_personal1_HKID1': case 'ul_personal1_HKID2': case 'ul_personal1_HKID3': if (typeof checkIdentificationDocumentNumber === "function") { errormsg = checkIdentificationDocumentNumber( $form ); } break; case 'ul_personal1_ADDR_HOME1': case 'ul_personal1_ADDR_HOME2': case 'ul_personal1_ADDR_HOME3': case 'ul_personal1_addr_homearea': case 'ul_personal1_ADDR_FLAT': case 'ul_personal1_ADDR_FLOOR': case 'ul_personal1_ADDR_BLOCK': case 'ul_personal1_ADDR_BUILDING': case 'ul_personal1_ADDR_STREET': case 'ul_personal1_ADDR_DISTRICT': case 'ul_personal1_ADDR_REGION': case 'ul_personal1_ADDR_COUNTRY': if (typeof checkResidentialAddress === "function") { errormsg = checkResidentialAddress( $form ); } break; case 'ul_personal1_addr_home_same': if (typeof checkPermanentAddress === "function") { errormsg = checkPermanentAddress( $form ); } break; case 'ul_personal1_ADDR_PERM1': case 'ul_personal1_ADDR_PERM2': case 'ul_personal1_ADDR_PERM3': case 'ul_personal1_ADDR_PERM4': case 'ul_personal1_addr_permarea': case 'ul_personal1_ADDR_PERM_FLAT': case 'ul_personal1_ADDR_PERM_FLOOR': case 'ul_personal1_ADDR_PERM_BLOCK': case 'ul_personal1_ADDR_PERM_BUILDING': case 'ul_personal1_ADDR_PERM_STREET': case 'ul_personal1_ADDR_PERM_DISTRICT': case 'ul_personal1_ADDR_PERM_REGION': case 'ul_personal1_ADDR_PERM_COUNTRY': if (typeof checkPermanentAddress === "function") { errormsg = checkPermanentAddress( $form ); } break; case 'cardoa_cardtype1_CARDTYPE': if (typeof checkCardType === "function") { errormsg = checkCardType( $form ); } break; case 'cardoa_cardface_cardface': if (typeof checkCardFace === "function") { errormsg = checkCardFace( $form ); } break; case 'cardoa_GIFT': if (typeof checkWelcomeGift === "function") { errormsg = checkWelcomeGift( $form ); } break; case 'ul_personal2_EMAIL': if (typeof checkPersonalEmail === "function") { errormsg = checkPersonalEmail( $form ); } break; case 'ul_personal2_DOB1': case 'ul_personal2_DOB2': case 'ul_personal2_DOB3': if (typeof checkDateOfBirth === "function") { errormsg = checkDateOfBirth( $form ); } break; case 'ul_personal2_nationality': if (typeof checkNationality === "function") { errormsg = checkNationality( $form ); } break; case 'ul_personal2_multiple_nationality': case 'ul_personal2_nationality2': case 'ul_personal2_nationality3': case 'ul_personal2_nationality4': case 'ul_personal2_nationality5': if (typeof checkMultipleNationality === "function") { errormsg = checkMultipleNationality( $form ); } break; case 'ul_personal2_edu_level': if (typeof checkEducationLevel === "function") { errormsg = checkEducationLevel( $form ); } break; case 'ul_personal2_resid_type': if (typeof checkResidentialType === "function") { errormsg = checkResidentialType( $form ); } break; case 'ul_personal2_mort_install_flag': case 'ul_personal2_MORT_INSTALL_AMT': if (typeof checkMonthlyInstallmentRentalPayment === "function") { errormsg = checkMonthlyInstallmentRentalPayment( $form ); } break; case 'ul_personal2_PHONE_MOBILE': if (typeof checkMobileTel === "function") { errormsg = checkMobileTel( $form ); } break; case 'ul_personal2_us_citizen': case 'ul_personal2_tax_ident_no': if (typeof checkTaxpayerIdentificationNumber === "function") { errormsg = checkTaxpayerIdentificationNumber( $form ); } break; case 'crs_country_1': case 'crs_identifi_code_1': case 'crs_reason_1': case 'crs_country_2': case 'crs_identifi_code_2': case 'crs_reason_2': case 'crs_country_3': case 'crs_identifi_code_3': case 'crs_reason_3': case 'crs_country_4': case 'crs_identifi_code_4': case 'crs_reason_4': case 'crs_country_5': case 'crs_identifi_code_5': case 'crs_reason_5': case 'crs_perm_1': case 'crs_perm_2': case 'crs_perm_3': case 'crs_perm_oth': case 'crs_perm_oth_text': if (typeof checkUSCitizen === "function") { errormsg = checkUSCitizen( $form ); } break; case 'ul_occup2_BIZ_NATURE': if (typeof checkBusinessNature === "function") { errormsg = checkBusinessNature( $form ); } break; case 'ul_occup2_COMPANY': if (typeof checkCompanyName === "function") { errormsg = checkCompanyName( $form ); } break; case 'ul_occup2_ADDR_OFF1': case 'ul_occup2_ADDR_OFF2': case 'ul_occup2_ADDR_OFF3': case 'ul_occup2_ADDR_OFF_FLAT': case 'ul_occup2_ADDR_OFF_FLOOR': case 'ul_occup2_ADDR_OFF_BLOCK': case 'ul_occup2_ADDR_OFF_BUILDING': case 'ul_occup2_ADDR_OFF_STREET': case 'ul_occup2_ADDR_OFF_DISTRICT': case 'ul_occup2_ADDR_OFF_REGION': case 'ul_occup2_ADDR_OFF_COUNTRY': if (typeof checkOfficeAddress === "function") { errormsg = checkOfficeAddress( $form ); } break; case 'ul_occup2_POSITION': if (typeof checkPosition === "function") { errormsg = checkPosition( $form ); } break; case 'ul_occup2_PHONE_OFF': if (typeof checkOfficeTel === "function") { errormsg = checkOfficeTel( $form ); } break; case 'ul_occup2_CUR_POSITION_YRS': case 'ul_occup2_CUR_POSITION_MTHS': if (typeof checkYearAtCurrentPosition === "function") { errormsg = checkYearAtCurrentPosition( $form ); } break; case 'ul_occup2_self_employ': if (typeof checkSelfEmployed === "function") { errormsg = checkSelfEmployed( $form ); } break; case 'ul_occup2_INCOME_MTHS': if (typeof checkMonthlyIncome === "function") { errormsg = checkMonthlyIncome( $form ); } break; // case 'ul_personal2_addr_mailing': // if (typeof checkCorrespondenceMailingAddress === "function") { // errormsg = checkCorrespondenceMailingAddress( $form ); // } // break; // 20240101 case 'ul_occup2_DISPOSABLE_INCOME': if (typeof checkDisposableIncome === "function") { errormsg = checkDisposableIncome( $form ); } break; // END 20240101 case 'ul_bk_ref_ckwb_cust': if (typeof checkExistingCustomer === "function") { errormsg = checkExistingCustomer( $form ); } break; case 'ul_bk_ref_oth_bk_chq_acc': if (typeof checkAccountInOtherBank === "function") { errormsg = checkAccountInOtherBank( $form ); } break; case 'ul_bk_ref_oth_bk_sav_acc': if (typeof checkSavingsAccountInOtherBank === "function") { errormsg = checkSavingsAccountInOtherBank( $form ); } break; case 'ul_bk_ref_oth_bk_unsec_od': if (typeof checkUnsecuredOverdraftInOtherBank === "function") { errormsg = checkUnsecuredOverdraftInOtherBank( $form ); } break; case 'ul_bk_ref_oth_bk_per_loan': if (typeof checkPersonalLoanInOtherBank === "function") { errormsg = checkPersonalLoanInOtherBank( $form ); } break; case 'ul_bk_ref_oth_bk_deposit': if (typeof checkOtherDepositsInvestmentsInOtherBank === "function") { errormsg = checkOtherDepositsInvestmentsInOtherBank( $form ); } break; case 'ul_bk_ref_oth_bk_auto_loan': if (typeof checkAutoLoanInOtherBank === "function") { errormsg = checkAutoLoanInOtherBank( $form ); } break; case 'ul_bk_ref_OTH_CARD_NUM_HOLD': if (typeof checkNoOfCreditCardHeld === "function") { errormsg = checkNoOfCreditCardHeld( $form ); } break; case 'ul_bk_ref_OTH_CARD_TOTAL_OS_BAL': if (typeof checkTotalOutstandingBalanceOfCreditCard === "function") { errormsg = checkTotalOutstandingBalanceOfCreditCard( $form ); } break; case 'ul_bk_ref_OTH_CARD_TOTAL_LMT': if (typeof checkTotalCreditLimitOfCreditCard === "function") { errormsg = checkTotalCreditLimitOfCreditCard( $form ); } break; case 'UL_OPT_OUT_OVER_LIMIT': if (typeof checkSelfEmployedLimitOptOut === "function") { errormsg = checkSelfEmployedLimitOptOut( $form ); } break; case 'relative_option_flag': if (typeof checkRelative === "function") { errormsg = checkRelative( $form ); } break; case 'relative_input_text_name_1': if (typeof checkNameOfRelevant === "function") { errormsg = checkNameOfRelevant( $form ); } break; case 'relative_input_text_name_2': if (typeof checkName2OfRelevant === "function") { errormsg = checkName2OfRelevant( $form ); } break; case 'relative_input_text_name_3': if (typeof checkName3OfRelevant === "function") { errormsg = checkName3OfRelevant( $form ); } break; case 'relative_input_text_name_4': if (typeof checkName4OfRelevant === "function") { errormsg = checkName4OfRelevant( $form ); } break; case 'relative_input_text_name_5': if (typeof checkName5OfRelevant === "function") { errormsg = checkName5OfRelevant( $form ); } break; case 'relative_input_company_name_1': if (typeof checkCompanyOfRelevant === "function") { errormsg = checkCompanyOfRelevant( $form ); } break; case 'relative_input_company_name_2': if (typeof checkCompany2OfRelevant === "function") { errormsg = checkCompany2OfRelevant( $form ); } break; case 'relative_input_company_name_3': if (typeof checkCompany3OfRelevant === "function") { errormsg = checkCompany3OfRelevant( $form ); } break; case 'relative_input_company_name_4': if (typeof checkCompany4OfRelevant === "function") { errormsg = checkCompany4OfRelevant( $form ); } break; case 'relative_input_company_name_5': if (typeof checkCompany5OfRelevant === "function") { errormsg = checkCompany5OfRelevant( $form ); } break; case 'relative_input_dept_in_company_1': if (typeof checkDepartmentInCompany === "function") { errormsg = checkDepartmentInCompany( $form ); } break; case 'relative_input_dept_in_company_2': if (typeof checkDepartmentInCompany2 === "function") { errormsg = checkDepartmentInCompany2( $form ); } break; case 'relative_input_dept_in_company_3': if (typeof checkDepartmentInCompany3 === "function") { errormsg = checkDepartmentInCompany3( $form ); } break; case 'relative_input_dept_in_company_4': if (typeof checkDepartmentInCompany4 === "function") { errormsg = checkDepartmentInCompany4( $form ); } break; case 'relative_input_dept_in_company_5': if (typeof checkDepartmentInCompany5 === "function") { errormsg = checkDepartmentInCompany5( $form ); } break; case 'relative_input_name_of_applicant_1': if (typeof checkNameOfApplicant === "function") { errormsg = checkNameOfApplicant( $form ); } break; case 'relative_input_name_of_applicant_2': if (typeof checkNameOfApplicant2 === "function") { errormsg = checkNameOfApplicant2( $form ); } break; case 'relative_input_name_of_applicant_3': if (typeof checkNameOfApplicant3 === "function") { errormsg = checkNameOfApplicant3( $form ); } break; case 'relative_input_name_of_applicant_4': if (typeof checkNameOfApplicant4 === "function") { errormsg = checkNameOfApplicant4( $form ); } break; case 'relative_input_name_of_applicant_5': if (typeof checkNameOfApplicant5 === "function") { errormsg = checkNameOfApplicant5( $form ); } break; // case 'relative_relationship_flag': // if (typeof checkRelationship === "function") { // errormsg = checkRelationship( $form ); // } // break; case 'PIN_OPT_OUT_PC': if (typeof checkIssuePinPrincipalCard === "function") { errormsg = checkIssuePinPrincipalCard( $form ); } break; case 'PIN_OPT_OUT_SC': if (typeof checkIssuePinSupplementaryCard === "function") { //errormsg = checkIssuePinSupplementaryCard( $form ); } break; case 'UL_OPT_OUT_REJECT': case 'UL_OPT_OUT_POST': case 'UL_OPT_OUT_EMAIL': case 'UL_OPT_OUT_TEL': case 'UL_OPT_OUT_SMS': if (typeof checkChannel === "function") { errormsg = checkChannel( $form ); } break; case 'ACCEPT_TNC': if (typeof checkAcceptTNC === "function") { errormsg = checkAcceptTNC( $form ); } break; case 'page_document_type1': case 'page_document_type2': case 'page_document_type3': case 'page_document_type4': case 'page_document_type5': case 'file1': case 'file2': case 'file3': case 'file4': case 'file5': if (typeof checkUploadFiles === "function") { errormsg = checkUploadFiles( $form ); } break; default: log('realtimeChecking no elements checking'); break; } } updateProgress(); } function debouncedresize() { log('debouncedresize'); calProgressHeight(); // Resize middle-strike-line $('.middle-strike-line').each(function( index ) { var $ele = $('
').appendTo($('body')); var $clone = $(this).clone().appendTo($ele); var outer = true; $wrapper = $clone.find('.middle-strike-line-wrapper'); $wrapper.css({'width':'auto'}); $span = $wrapper.find('span'); var width = $span.outerWidth(true)+20; $(this).find('.middle-strike-line-wrapper').css({'width':width }); $ele.remove(); }); if ($('#media-checking').width() <= 1 ) { // < 768 } else { } } function updateProgress() { //log('updateProgress'); var $requiredFields = $('input, textarea, select').filter('[required]'); var totalRequiredFields = $requiredFields.length; var no = 0; log( '$requiredFields:', $requiredFields); log( "updateProgress - totalRequiredFields:", $requiredFields.length ); //log( $('input, textarea, select').filter('[required]:visible').length ); //$requiredFields.css({"border":"2px solid green"}); //$('input, textarea, select').filter('[required]:visible').css({"border":"2px solid green"}); $requiredFields.each(function( index ) { if (!$(this).hasClass('is-invalid')) { if( $(this).is("select")) { //log( index + ": " + $( this ).val() + " " + "select" ); if ( $( this ).val() != "") { no++; } } else if ( $(this).attr('type') == "radio") { //log( index + ": " + $( this ).filter(':checked').val() + " " + "radio" ); if ( $( this ).filter(':checked').val() != "" && $( this ).filter(':checked').length>0) { no++; } } else if ( $(this).attr('type') == "checkbox" ) { //log( index + ": " + $( this ).filter(':checked').val() + " " + "checkbox" ); if ( $( this ).filter(':checked').val() != "" && $( this ).filter(':checked').length>0) { no++; } } else { if ( $( this ).val() != "") { no++; } } } }); var totalStep = $('.progressbar2 li').length - 1; var percent = 0; if (totalRequiredFields > 0) { percent = Math.round( no / totalRequiredFields * 100 ); } if (typeof step == "undefined") { } else { if (step == 4) { percent = 0; } else if (step == 5) { percent = 0; } } if (typeof step == "undefined") { //step = 1; } else if (step<=4) { //log('Before::::::::', step, totalStep, percent, totalRequiredFields); //percent = ( percent/100 * (step)/totalStep ) *100; percent = (percent/100 * 1/totalStep + (step-1) * 1/totalStep) * 100; //log('After::::::::', step, totalStep, percent, totalRequiredFields); } else if (step==5) { percent = (percent/100 * 1/totalStep + (step-1) * 1/totalStep) * 100; } if (typeof nextpage != "undefined") { if (step == 1 && nextpage==1) { percent = 75; } } if (typeof pageaction != "undefined") { if (pageaction == "CONFIRM") { percent = 75; } else if (pageaction == "ACKN") { percent = 100; } } log('updateProgress::::::::::::::::::::', step, totalStep, percent); //log('no:::', no); //log('totalRequiredFields:', totalRequiredFields); //log('percent:', percent); //$('progress').attr('max', totalRequiredFields); //$('progress').attr('value', no); //$('progress').attr('value', percent); //$('.progress-percentage').html(percent + '%' + ' (' + totalRequiredFields + ')'); updateProgressBar(percent); } function updateProgressBar(value) { log('updateProgressBar:', value); log('---------------------------------------------------'); //$('#progressbar').prop('Counter',0).animate({ var currentValue = $('.progressbar-holder').attr('value'); //log('currentValue:', currentValue); $('.progressbar-holder').prop('Counter', currentValue).animate({ //Counter: $(this).text() //Counter: $(this).attr('value') Counter: value }, { duration: 200, easing: 'swing', step: function (now) { $('.progress-percentage').html(Math.ceil(now) + '%'); $(this).attr('value', Math.ceil(now)); }, complete: function() { $('.progressbar2 li').each(function(index) { //$(this).data('before'); if (value >= $(this).data('before') ) { $(this).addClass('visited'); } else { $(this).removeClass('visited'); } }); } }); } // SUBMIT FORM // ----------------------------------------------------------------------------------------------------- function submitform2() { /* var form = document.forms.campaignform; log("Form: ", form); var errorMsg = ""; errorMsg += MGM_REF_FORM(document.forms.campaignform); errorMsg += UL_PERSONAL1(document.forms.campaignform); errorMsg += CardOA_CARDTYPE2(document.forms.campaignform); errorMsg += CardOA_CARDFACE(document.forms.campaignform); errorMsg += CardOA_GIFT(document.forms.campaignform); errorMsg += UL_PERSONAL2_FATCA(document.forms.campaignform); */ if (firstTime) { firstTime = false; } var $form = $('form[name=campaignform]'); var errorMsg = ""; if (!useDeferred) { if (typeof CardOA_CARDTYPE2 === "function") { errorMsg += CardOA_CARDTYPE2( $form ); } if (typeof UL_PERSONAL1 === "function") { errorMsg += UL_PERSONAL1( $form ); } if (typeof CardOA_CARDFACE === "function") { errorMsg += CardOA_CARDFACE( $form ); } if (typeof CardOA_GIFT === "function") { errorMsg += CardOA_GIFT( $form ); } if (typeof UL_PERSONAL2_FATCA === "function") { errorMsg += UL_PERSONAL2_FATCA( $form ); } if (typeof FATCA_W9 === "function") { errorMsg += FATCA_W9( $form ); } if (typeof CRS === "function") { errorMsg += CRS( $form ); } if (typeof UL_OCCUP2 === "function") { errorMsg += UL_OCCUP2( $form ); } if (typeof UL_BK_REF === "function") { errorMsg += UL_BK_REF( $form ); } if (typeof UL_CARD_OVER_LIMIT_OPT_OUT === "function") { errorMsg += UL_CARD_OVER_LIMIT_OPT_OUT( $form ); } if (typeof UL_RELATIVE === "function") { errorMsg += UL_RELATIVE( $form ); } if (typeof PIN_OPT_OUT_REQUEST === "function") { errorMsg += PIN_OPT_OUT_REQUEST( $form ); } if (typeof PIN_OPT_OUT_REQUEST_SUPP === "function") { errorMsg += PIN_OPT_OUT_REQUEST_SUPP( $form ); } if (typeof UL_CARD_OPT_OUT_REQUEST === "function") { errorMsg += UL_CARD_OPT_OUT_REQUEST( $form ); } if (typeof CONFIRM_TC_PRIN === "function") { errorMsg += CONFIRM_TC_PRIN( $form ); } if (typeof LOAN_MGM_REF_FORM === "function") { errorMsg += LOAN_MGM_REF_FORM( $form ); } if (typeof UL_LOAN_PERSONAL2_FATCA === "function") { errorMsg += UL_LOAN_PERSONAL2_FATCA( $form ); } if (typeof LOAN_CRS === "function") { errorMsg += LOAN_CRS( $form ); } if (typeof UL_LOAN_OCCUP2 === "function") { errorMsg += UL_LOAN_OCCUP2( $form ); } if (typeof LOAN_FATCA_W9 === "function") { errorMsg += LOAN_FATCA_W9( $form ); } if (typeof UL_LOAN_CARD_OVER_LIMIT_OPT_OUT === "function") { errorMsg += UL_LOAN_CARD_OVER_LIMIT_OPT_OUT( $form ); } if (typeof LOAN_CONFIRM_TC === "function") { errorMsg += LOAN_CONFIRM_TC( $form ); } if (typeof UL_LOAN_BK_REF === "function") { errorMsg += UL_LOAN_BK_REF( $form ); } log('Number of Errors:', $('.form-group.is-invalid').length); log('Errors:\n %c %s', 'background: #222; color: #bada55', errorMsg); // errorMsg = errorMsg.replace(/(?:\r\n|\r|\n)/g, '
'); errorMsg = replaceBreaksWithParagraphs(errorMsg); var msg = '
' + ERROR + '
'; msg += errorMsg; msg += '
'; if ( $('.form-group.is-invalid').length > 0 ) { scrollToError(); } else { // TO-DO log('Submit form now .........................'); sendToServer(); } } else { var deferreds = []; if (typeof CardOA_CARDTYPE2 === "function") { deferreds.push( CardOA_CARDTYPE2($form) ); } if (typeof UL_PERSONAL1 === "function") { deferreds.push( UL_PERSONAL1($form) ); } if (typeof CardOA_CARDFACE === "function") { deferreds.push( CardOA_CARDFACE($form) ); } if (typeof CardOA_GIFT === "function") { deferreds.push( CardOA_GIFT($form) ); } if (typeof UL_PERSONAL2_FATCA === "function") { deferreds.push( UL_PERSONAL2_FATCA($form) ); } if (typeof FATCA_W9 === "function") { deferreds.push( FATCA_W9($form) ); } if (typeof CRS === "function") { deferreds.push( CRS($form) ); } if (typeof UL_OCCUP2 === "function") { deferreds.push( UL_OCCUP2($form) ); } if (typeof UL_BK_REF === "function") { deferreds.push( UL_BK_REF($form) ); } if (typeof UL_CARD_OVER_LIMIT_OPT_OUT === "function") { deferreds.push( UL_CARD_OVER_LIMIT_OPT_OUT($form) ); } if (typeof UL_RELATIVE === "function") { deferreds.push( UL_RELATIVE($form) ); } if (typeof PIN_OPT_OUT_REQUEST === "function") { deferreds.push( PIN_OPT_OUT_REQUEST($form) ); } if (typeof PIN_OPT_OUT_REQUEST_SUPP === "function") { deferreds.push( PIN_OPT_OUT_REQUEST_SUPP($form) ); } if (typeof UL_CARD_OPT_OUT_REQUEST === "function") { deferreds.push( UL_CARD_OPT_OUT_REQUEST($form) ); } if (typeof CONFIRM_TC_PRIN === "function") { deferreds.push( CONFIRM_TC_PRIN($form) ); } //showFancyBoxLoading(); $.when.apply($, deferreds).then(function() { //errorMsg += r.errormsg; //log('HAHA errorMsg:', errorMsg, errorMsg.length); var objects = arguments; // The array of resolved objects as a pseudo-array for (i = 0; i < objects.length; i++) { log('objects', objects[i]); errorMsg += objects[i].errormsg; } log('HAHA errorMsg:', errorMsg, errorMsg.length); errorMsg = replaceBreaksWithParagraphs(errorMsg); log('errorMsg:', errorMsg); log('Error:\n %c %s', 'background: #222; color: #bada55', errorMsg); if ( $('.form-group.is-invalid').length > 0 ) { log('Number of Error: %c %s', 'background: #222; color: #bada55', $('.form-group.is-invalid').length); //var msg = '
' + ERROR + '
'; var msg = '
' + ERROR + '
'; msg += errorMsg; msg += '
'; scrollToError(); } else { // TO-DO //log('Submit form now .........................', $("form[name=campaignform]").serialize()); log('Submit form now .........................'); sendToServer(); } }); } updateProgress(); } function sendToServer() { var data = { action: 'submit', //action2: 'test2', page: page, step: step }; var dataArray = $("form[name=campaignform]").serializeArray(); //log('dataArray', dataArray); var filteredDataArray = []; $.each(dataArray, function (i, e) { //log(i, e, filteredDataArray); var matchingItems = $.grep(filteredDataArray, function (item, n) { //log(i, item.name, item.value, e.name, e.value); return item.name === e.name; }); //log('matchingItems:', matchingItems); if (matchingItems.length === 0){ filteredDataArray.push(e); } else { $.each(matchingItems, function (index, ele) { //log(index, ele, ele.value); if (ele.value == "") { var indexPos = filteredDataArray.indexOf(ele); log('indexPos:', indexPos); filteredDataArray.splice(indexPos, 1); filteredDataArray.push(e); } }); } }); //log( 'filteredDataArray:', $.param(filteredDataArray) ); data = $.param(filteredDataArray) + '&' + $.param(data); log('sendToServer - Submit form now .........................', data); $.ajax({ url: 'controller.php', type: 'post', dataType: 'json', data: data, success: function(data){ log("After Success:", data); var data = data.data; log("After Success:", data); redirectPage(data); } }); } // function removeDuplicates(arr, key) { // if (!(arr instanceof Array) || key && typeof key !== 'string') { // return false; // } // if (key && typeof key === 'string') { // return arr.filter((obj, index, arr) => { // return arr.map(mapObj => mapObj[key]).indexOf(obj[key]) === index; // }); // } else { // return arr.filter(function(item, index, arr) { // return arr.indexOf(item) == index; // }); // } // } // Testing // function sendToServer(page) { // var redirect = 'index.php'; // $.redirectPost(redirect, {'page': page}); // } function redirectPage(data) { var redirect = 'index.php'; //$.redirectPost(redirect, {'page': page, 'dsadsad': 'dsads'}); $.redirectPost(redirect, data); } // Scroll To Error Field function scrollToError() { log('Scroll To Error Field', $('.is-invalid:not([type=hidden]):first')); var offsetY = $('.section-progress').outerHeight(true) + 20; //$(window).scrollTo( $('.is-invalid:first'), 600, { offset:-offsetY, 'axis':'y'}); if (!isiOS) { setTimeout(function() { $(window).scrollTo( $('.is-invalid:not([type=hidden]):first'), 600, { offset:-offsetY, 'axis':'y'}); }, 300); } else { setTimeout(function() { //$('#site-scoller').scrollTo( $('.is-invalid:not([type=hidden]):first'), 600, { offset:-offsetY, 'axis':'y'}); $(window).scrollTo( $('.is-invalid:not([type=hidden]):first'), 600, { offset:-offsetY, 'axis':'y'}); }, 300); } } // Scroll To Form function scrollToForm() { log('Scroll To Form: ', isiOS); var offsetY = $('.section-progress').outerHeight(true) + 20; if (!isiOS) { setTimeout(function() { $(window).scrollTo( $('form[name=campaignform]'), 600, { offset:-offsetY, 'axis':'y'}); }, 300); } else { setTimeout(function() { //$('#site-scoller').scrollTo( $('form[name=campaignform]'), 600, { offset:-offsetY, 'axis':'y'}); $(window).scrollTo( $('form[name=campaignform]'), 600, { offset:-offsetY, 'axis':'y'}); }, 300); } } function d1() { var defer = $.Deferred(); setTimeout(function(){ defer.resolve( {"msg":"Error d1", "status": 0} ); }, 1000); //defer.resolve( ); return defer.promise(); } function d2() { var defer = $.Deferred(); setTimeout(function(){ defer.resolve( "abc" ); }, 2000); return defer; } function d3() { var defer = $.Deferred(); defer.resolve( [ 1, 2, 3, 4, 5 ] ); return defer; } function d4() { var defer = $.Deferred(); $.when( d5() ).then(function( data ) { defer.resolve( {"d5 return": data}); }); return defer; } function d5() { var defer = $.Deferred(); setTimeout(function(){ defer.resolve( {"msg":"Error d5"} ); }, 5000); //defer.resolve( ); return defer.promise(); } function d6() { var defer = $.Deferred(); /* confirmFancyBox(ADDITIONAL_INFOR_MESSAGE, false, function(resp) { //log("You clicked " + resp); if(resp) { } else { } defer.resolve( {"Clicked": resp} ); }); */ defer.resolve(); return defer.promise(); } function T1(thisform) { return "T1 ERROR\n"; } function T2(thisform) { //return "T2 ERROR\n"; $.when( T3(thisform) ).then(function ( t3 ) { return "T2 ERROR\n" + t3; }); } function T3(thisform) { var defer = $.Deferred(); setTimeout(function(){ defer.resolve("T3 ERROR\n"); }, 2000); return defer.promise(); } // FANCY BOX // ----------------------------------------------------------------------------------------------------- function showFancyBox(msg, canClose, callback) { log('Show showFancyBox showFancyBox showFancyBox showFancyBox showFancyBox showFancyBox showFancyBox showFancyBox'); if (typeof fancyboxLoadingInstance != "undefined") { fancyboxLoadingInstance.close(); } if (typeof msg == "undefined" || msg == "") { msg = 'Error'; } if (typeof canClose == "undefined") { canClose = true; } log('canClose:', canClose); clickOutside = false; clickSlide = false; smallBtn = false; if (canClose) { clickOutside = 'close'; clickSlide = 'close'; smallBtn = true; } var content = '
' + msg + '
'; var opts = { //buttons : ['fullScreen'], keyboard: false, touch: false, clickOutside : clickOutside, clickSlide: clickSlide, smallBtn: smallBtn, dblclickOutside : false, infobar : false, toolbar : false, baseClass: 'fancybox-custom-container', animationEffect: "fade" , animationDuration : 200, afterLoad : function() { }, afterShow : function(instance, current) { }, onComplete : function() { }, afterClose : function() { if (typeof callback != "undefined") { callback(); } } }; $.fancybox.open(content, opts); } function showFancyBoxLoading() { log('Show showFancyBoxLoading showFancyBoxLoading showFancyBoxLoading showFancyBoxLoading showFancyBoxLoading showFancyBoxLoading'); var content = ''; var opts = { keyboard: false, touch: false, clickOutside : false, clickSlide: false, smallBtn: false, dblclickOutside : false, infobar : false, toolbar : false, animationEffect: "fade" , animationDuration : 200, afterLoad : function() { }, afterShow : function(instance, current) { instance.showLoading( current ); }, onComplete : function() { }, afterClose : function() { fancyboxLoadingInstance = undefined; } }; fancyboxLoadingInstance = $.fancybox.open(content, opts); } function confirmFancyBox(msg, modal, callback) { log('Show confirmFancyBox', fancyboxLoadingInstance); if (typeof fancyboxLoadingInstance != "undefined") { fancyboxLoadingInstance.close(); } //$.fancybox.open("#confirmFancyBox", { var instance = $.fancybox.open({ src: '#confirmFancyBox', modal: modal, keyboard: false, touch: false, clickOutside : false, clickSlide: false, smallBtn: false, dblclickOutside : false, infobar : false, toolbar : false, baseClass: 'fancybox-confirm-container', animationEffect: "fade" , animationDuration : 200, beforeShow: function() { $(".title").html(msg); }, afterShow: function() { $(".btn-confirm ").on("click", function(event){ if($(event.target).is("#btn-ok")){ ret = true; } else if ($(event.target).is("#btn-cancel")){ ret = false; } //$.fancybox.close(); instance.close(); }); }, afterClose: function() { callback.call(this, ret); } }); } // GET REAL DIMENSIONS // ----------------------------------------------------------------------------------------------------- $.fn.getRealDimensions = function (outer) { var $this = $(this); if ($this.length == 0) { return false; } var $clone = $this.clone() //.show() //.css('visibility','hidden') //.insertAfter($this); .appendTo($('.footer-bottom-container')); var result = { width: (outer) ? $clone.outerWidth() : $clone.innerWidth(), height: (outer) ? $clone.outerHeight() : $clone.innerHeight(), offsetTop: $clone.offset().top, offsetLeft: $clone.offset().left }; //$clone.remove(); return result; } // $.merge = function(objs) { // var ret = objs.shift(); // while (objs.length) { // ret.add(objs.shift()); // } // return ret; // }; function merge(array_of_jquery_objects) { return $($.map(array_of_jquery_objects, function(el) { return el.get(); })); } function replaceBreaksWithParagraphs(input) { input = filterEmpty(input.split('\n')).join('

'); 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<\.\,\:{}\;\\\\?\\[\\] ]"; //Only allowed A-Z,a-z,0-9 var strANPattern_space = "[\"'~`!@#$%^&*()_\\-+=|/><\.\,\:{}\;\\\\?\\[\\]]"; // Only allowed A-Z,a-z,0-9 and space var strANPattern_adm = "[\"'~`!@#$^&()_\\-+=|/><\.\,\:{}\;\\\\?\\[\\] ]"; //A-Z,a-z,0-9, * and % var strVCPattern = "[\`~!@#$%^*\\+=|><\:{}\;\\\\?\\[\\]]"; //Allowed certain special character -- // '-" &(),./_ var strSCPattern_FileUpload = "[\"*?|/><]"; var strANPattern_ID = "[^A-Za-z0-9]"; //This type will not allow any other languages data except for a-z,A-Z and 0-9. var strANPattern_IDspace = "[^A-Za-z0-9 ]"; //This type will not allow any other languages data except for a-z,A-Z,0-9 and space. var strANPattern_engspace = "[^A-Za-z ]"; //This type will not allow any other languages data except for a-z,A-Z and space. var strADRPattern_nonchi = "[^A-Za-z0-9 \.\,-/']"; //Non-chinese address var strNoPattern_space = "[^0-9 ]"; var strNoPattern = "[^0-9]"; switch(strType){ case "M" : regexp = new RegExp(strANPattern,"g"); break; case "MS" : regexp = new RegExp(strANPattern_space,"g"); break; case "MADM" : regexp = new RegExp(strANPattern_adm,"g"); break; case "MVC" : regexp = new RegExp(strVCPattern,"g"); break; case "MSCF" : regexp = new RegExp(strSCPattern_FileUpload,"g"); break; case "MID" : regexp = new RegExp(strANPattern_ID,"g"); break; case "MNCS" : regexp = new RegExp(strANPattern_IDspace,"g"); break; case "MES" : regexp = new RegExp(strANPattern_engspace,"g"); break; case "MNCADR" : regexp = new RegExp(strADRPattern_nonchi,"g"); break; case "MSC" : regexp = new RegExp(strSCPattern,"g"); break; case "MASC" : regexp = new RegExp(strTFPattern,"g"); break; case "MNO" : regexp = new RegExp(strNoPattern_space,"g"); break; case "NNO" : regexp = new RegExp(strNoPattern,"g"); break; // ------------------------------------- // to be remove case "SC" : regexp = new RegExp(strANPattern,"g"); break; case "ASC" : regexp = new RegExp(strANPattern,"g"); break; } blnResult = !(regexp.test(strInput)); return blnResult; } function isEmailValid2(value){ var isvalid = false; if(value.indexOf('@') > -1) { var emailid = value.substring(0, value.indexOf('@')); var emaildomain = value.substring(value.indexOf('@')+1, value.length); if (/^\w+([\.-]?\w+)+$/.test(emailid)) // check email id { if (/^\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emaildomain)) isvalid = true; else isvalid = false; } else isvalid = false; } else isvalid = false; return isvalid; } function isNonChinese2(str) { var n=true; if (typeof str != "undefined") { var l=str.length; for (var i=0; i= 33 && str.charCodeAt (i) <= 126) && str.charAt(i) != ' ') n = false; } } return n; } function isFirstCharAlphaNum2(strInput) { var isAlphaNum = true; if (typeof strInput != "undefined") { strInput = Trim(strInput); if(strInput.length > 1) isAlphaNum = isValidInput(strInput.substring(0,1), "M"); } return isAlphaNum; } function hasNumber(myString) { return /\d/.test(myString); } function getRadioGrpSelectedValue(object) { var length = object.length; var selectedValue=""; for ( var i = 0; i < length; i++) { if ( object[i].checked ) { selectedValue = object[i].value; } } return selectedValue ; } function validatePhoneNo2(phoneNbr) { if(phoneNbr.length >= 8) { if ( isInt(phoneNbr) ) { return true; } else { return false; } } else { return false; } } function validateHomeTel(phoneNbr) { var patt = /^((?!(0))[0-9]{8})$/g; var result = patt.test( phoneNbr ); return result; } function validateMobile(phoneNbr) { //var patt = /^(4|5|6|9)[0-9]{7}$/g; var patt = /^((?!(0))[0-9]{8})$/g; var result = patt.test( phoneNbr ); return result; } function isInt(value) { return !isNaN(value) && parseInt(Number(value)) == value && !isNaN(parseInt(value, 10)); } /* *http://www.info.gov.hk/td/pdiballot/checkHKID.html *http://www.phpsky.com/home/tools/hkid/index.php *HKID format = A123456(7), where: * - 'A' must be a letter or space. * - The bracket and the checksum digit inside could be 0-9 or A. * - If check digit = 10, then it will be treated as "A" * - If check digit = 11, then it will be treated as "0" *------------------------------------------------------------------------------------- *Oct 2004 - Additional recources found at http://www.excelhelp.net/cgi-bin/forum/topic.cgi?forum=3&topic=5 *a.The format of HKID (2 digit prefix) (6 digit number) (1 check digit) = 9 digits *b.If the prefixes only contain one alphabet, a blank space will be added in front. * Therefore, total length of HKID should be always 9 digits */ function validateHKID(hkId) { log('validateHKID:', hkId); if(hkId.length < 8 || hkId.length > 9) return false; else if(hkId.length == 8) hkId = ' ' + hkId; return checkHKID(hkId); } function checkHKID(hkId) { var reqAddBlankSpace = false; var firstPrex; var secondPrex; hkId = Trim(hkId); newStr = hkId.replace("(" ,""); newStr = newStr.replace(")" ,""); if (hkId.length > 2) { firstPrex = hkId.substring(0,1); secondPrex = hkId.substring(1,2); } if ( !isNaN(secondPrex) ) { reqAddBlankSpace = true; } if(hkId.length < 0 || hkId.length < 7 || !isNaN(firstPrex) ) { return false; } else if ( getHKCheckDigit(reqAddBlankSpace,Trim(newStr)) == false) { return false; } return true ; } /* * user have the option to enter HK ID in format of A123456(7) or A1234567 */ function getHKCheckDigit(reqAddBlankSpace,hkId) { var numericDigit ; var total = 0; var start = hkId.length ; var checkDigit ; var lastDigit = hkId.substring(hkId.length-1,hkId.length) ; var ret; if (reqAddBlankSpace == true) { total += 91 * 9; } for(var i = 0; i < hkId.length-1 ; i++) { numericDigit = hkId.substring(i, i+1); if ( isNaN(numericDigit) ) { numericDigit = numericDigit.toUpperCase(); numericDigit = numericDigit.charCodeAt(0) ;//-64 ; //-64 A=65 } total += numericDigit * start; // alert("strat : " + start + "numericDigit: " + numericDigit +"total -" + total ); start--; } if (total != 0) { ret = parseInt(total) % 11; if (ret < 0) { ret += 11; } checkDigit = 11 - ret; } //HKID is valid,if checkDigit = last digit //If checkDigit = 10, treated it as "A" //If checkDigit = 11, treated it as "0" if ( checkDigit == 11) { checkDigit = 0; } if ( checkDigit == 10) { checkDigit = "A"; } if (checkDigit != lastDigit.toUpperCase() ) { return false; } return true ; } function isEmpty(value) { return typeof value == 'string' && !value.trim() || typeof value == 'undefined' || value === null; } function setCampaignCode() { var checked = $('input[type=checkbox][name=cardoa_cardtype1_CARDTYPE]:checked').val(); var cd; if (tempCD == "CardNADAC" || tempCD == "CardNAPPNC") { if (checked == "VISAPLAT") cd = "CardNADAC"; else if (checked == "PAYPASS") cd = "CardNAPPNC"; } else { if (checked == "VISAPLAT") cd = "CardDAC"; else if (checked == "PAYPASS") cd = "CardPPNFC"; else if (checked == "CUPDIAM") cd = "CardCUP"; else if (checked == "VISAPLAT|CUPDIAM") cd = "CardDACCUP"; else if (checked == "PAYPASS|CUPDIAM") cd = "CardPPNFCCUP"; else if (checked == "GBADCC") cd = "CardGBA"; else if (checked == "VISAPLAT|GBADCC") cd = "CardDACGBA"; else if (checked == "PAYPASS|GBADCC") cd = "CardPPNFCGBA"; else if (checked == "DCHWMC") cd = "CardDCH"; else if (checked == "CFWMC") cd = "CardJWorld"; else if (checked == "CDEMC") cd = "CardJElite"; else if (checked == "HKAWMC") cd = "CardHKA"; } // enable FWC field if necessary var enableInputFWC = checked === 'HKAWMC'; $('#INPUT_FWC_MEM_NO').prop('disabled', !enableInputFWC); if (!enableInputFWC) { $('#INPUT_FWC_MEM_NO').val(''); $('input[name=ul_personal2_fortune_wing_club_member_no][type=hidden]').val(''); } $('input[type=hidden][name=CD]').val(cd); log( 'Set CampaignCode: ', checked, $('input[type=hidden][name=CD]').val()); } function compareCountry(thisform) { var defer = $.Deferred(); log('compareCountry', FATCAYES); var flag = true; var flag1 = true; var flag2 = true; var flag3 = true; var flag4 = true; var flag5 = true; var nationality1 = "", nationality2 = "", nationality3 = "", nationality4 = "", nationality5 = ""; if ( $('[name=ul_personal2_nationality]', thisform).length > 0 ) { nationality1 = Trim( $('[name=ul_personal2_nationality]', thisform).val() ); nationality2 = Trim( $('[name=ul_personal2_nationality2]', thisform).val() ); nationality3 = Trim( $('[name=ul_personal2_nationality3]', thisform).val() ); nationality4 = Trim( $('[name=ul_personal2_nationality4]', thisform).val() ); nationality5 = Trim( $('[name=ul_personal2_nationality5]', thisform).val() ); } var crsCountry = $("select[name ^='crs_country_']"); log('crsCountry:', nationality1, nationality2, nationality3, nationality4, nationality5, crsCountry[0].value, crsCountry.length); if ( nationality1 != "" && nationality1 != null && nationality1 != "US" ) { for(var i = 0; i < crsCountry.length; i++){ log(nationality1, crsCountry[i].value); if(crsCountry[i].value != "" && crsCountry[i].value != null){ if(nationality1 == crsCountry[i].value){ log('same'); flag1 = false; } } } } else { if (!FATCAYES) { flag1 = false; } } if(nationality2 != "" && nationality2 != null && nationality2 != "US"){ for(var i = 0; i < crsCountry.length; i++){ if(crsCountry[i].value != "" && crsCountry[i].value != null){ if(nationality2 == crsCountry[i].value){ flag2 = false; } } } }else{ if (!FATCAYES) { flag2 = false; } } if(nationality3 != "" && nationality3 != null && nationality3 != "US"){ for(var i = 0; i < crsCountry.length; i++){ if(crsCountry[i].value != "" && crsCountry[i].value != null){ if(nationality3 == crsCountry[i].value){ flag3 = false; } } } }else{ if (!FATCAYES) { flag3 = false; } } if(nationality4 != "" && nationality4 != null && nationality4 != "US"){ for(var i = 0; i < crsCountry.length; i++){ if(crsCountry[i].value != "" && crsCountry[i].value != null){ if(nationality4 == crsCountry[i].value){ flag4 = false; } } } }else{ if (!FATCAYES) { flag4 = false; } } if(nationality5 != "" && nationality5 != null && nationality5 != "US"){ for(var i = 0; i < crsCountry.length; i++){ if(crsCountry[i].value != "" && crsCountry[i].value != null){ if(nationality5 == crsCountry[i].value){ flag5 = false; } } } }else{ if (!FATCAYES) { flag5 = false; } } if(flag1 || flag2 || flag3 || flag4 || flag5){ flag = false; } //log('flag:', flag, flag1, flag2, flag3, flag4, flag5); log('%c flag:', 'color: blue; font-weight: bold;', flag, flag1, flag2, flag3, flag4, flag5); if(!flag && isSubmittingForm){ var crs_hid = $("#CRS_HID").val(); if(crs_hid == "1"){ log('%c SHOW CONFIRM BOX!', 'color: blue; font-weight: bold;'); /* if( confirm(ADDITIONAL_INFOR_MESSAGE) ) { $("#CRS_HID").val("2"); $("#CRS_ADDITIONAL_HID").val("2"); $("#additional_infor_table").css("display","block"); errormsg = checkUSCitizen( thisform ); } */ log('1. Before show confirmFancyBox', isSubmittingForm, useDeferred); confirmFancyBox(ADDITIONAL_INFOR_MESSAGE, false, function(resp) { log("You clicked " + resp); if(resp) { // User Click Ok $("#CRS_HID").val("2"); $("#CRS_ADDITIONAL_HID").val("2"); $("#additional_infor_table").css("display","block"); errormsg = checkUSCitizen( thisform ); //setTimeout(function() { scrollToError(); //}, 200); } else { // User Click Cancel log('User Click Cancel:', allError); //setTimeout(function() { scrollToError(); //}, 200); if ( allError == "intercept") { log('--------------------'); log('Cancel Form Submit'); // $("form[name=campaignform]").submit(); } } // RETURN FALSE if (!useDeferred) { return flag; } else { defer.resolve( flag ); } }); // intercept form submission if (!useDeferred) { return "intercept"; } else { defer.resolve( flag ); } } else { // RETURN FALSE if (!useDeferred) { return flag; } else { defer.resolve( flag ); return defer.promise(); } } } else { // RETURN TRUE if (!useDeferred) { return flag; } else { defer.resolve( flag ); return defer.promise(); } } } function checkCRSCountry( thisEle ) { //log( 'crs_identifi_code_1:', $(thisEle), $(thisEle).closest('.row'), $(thisEle).next('#crs_identifi_code_1') ); var crsIdentifiCodeEle = $(thisEle).closest('.row').find( "input[name ^=crs_identifi_code]" ); var crsReasonEle = $(thisEle).closest('.row').find( "select[name ^=crs_reason]" ); // Reset First $(crsIdentifiCodeEle).removeAttr("disabled").val(''); $(crsReasonEle).val('').removeAttr("disabled").trigger('change'); // Check Duplicate var countries = $("select[name ^='crs_country']"); //log('countries:', countries, thisEle); //var selects = document.getElementsByTagName('select'); var values = []; for(i=0 ; i < countries.length; i++) { var selectedValue = countries[i].value; //log("selectedValue", i, selectedValue); if ( values.indexOf(selectedValue) > -1 && selectedValue!="") { log('duplicate exists ' , selectedValue, countries[i] ); // clear selection if duplicate $(thisEle).val("").trigger('change'); var msg = '
'; msg += TAX_RESIDENCY_REPEAT_ERROR; msg += '
'; showFancyBox( msg ); //return true; } else { values.push(selectedValue); } } // return true; // Disable crs_identifi_code, crs_reason when country is HONG KONG if( $(thisEle).val()=='HK' ){ $(crsIdentifiCodeEle).prop('disabled', true); $(crsReasonEle).prop('disabled', true); } // log('1: ', $(thisEle)); // log('2: ', $(thisEle).closest('.row') ); // log('3: ', $(thisEle).closest('.row').find( "input[name ^=crs_identifi_code]" ) ); // log('4: ', $(thisEle).closest('.row').find( "select[name ^=crs_reason]" ) ); } // jquery extend function $.extend( { redirectPost: function(location, args) { var form = ''; $.each( args, function( key, value ) { value = value.split('"').join('\"') form += ''; }); $('
' + form + '
').appendTo($(document.body)).submit(); } });