// global variables
var glob_mobile;
var glob_email;

jQuery(document).ready(function($) { 

    $('.kepro-corner-close').click(function(){
        $('.kepro-corner-box').remove();
    });

    // my account page - copy coupons
    $('.kerasno_copybtn').on('click', function(){
        let copyInput = $(this).siblings('.kerasno_coupon_copyvalue');
        copyInput.select();
        document.execCommand("copy");
        $(this).text("کپی شد");
    });

    // Signout Link Click
    custom_logout_selector = mreeir_js_options.logout_selector;
    if ( custom_logout_selector.trim() ) {
        $(custom_logout_selector).on('click',function(e) {
            e.preventDefault();
            window.location = mreeir_js_options.logout_url;
        });
    }
    
    
    $('.mreeir-singout-user').on('click',function(e) {
        e.preventDefault();
        window.location = mreeir_js_options.logout_url;
    });

    // ================ edit number - get mobile
    $('#editmobile').keypress(function (e) {
        var key = e.which;
        if(key == 13)  // the enter key code
        {
            $('#submit-edit1').click();
            return false;  
        }
    });

    $('#submit-edit1').on( 'click' , function(e){
        
        e.preventDefault();
        var $mobile = $('#editmobile').val();
        var $userisnotauser = $('.mreeir-form-wrapper.edit_getmobilenumber .userisnotauser').val();

        if ( mreeir_is_empty( $mobile ) ) {
            mreeir_notification(force_messeges.MobileNotValid);
            return;
        }
        if( ! mreeir_is_empty($userisnotauser) ) {
            if ( mreeir_is_empty_fake( $userisnotauser ) ) {
                mreeir_notification(force_messeges.wrongInfo);
                return;
            }
        }

        $mobile = mreeir_correct_mobile_number($mobile);

        if ( ! mreeir_is_mobile( $mobile ) ) {
            mreeir_notification(force_messeges.MobileNotValid);
            return;
        }
        
        glob_mobile = $mobile;
        
        jQuery.ajax({
            url: mreeir_js_options.ajaxurl,
            type: 'POST',
            data: {
                action: 'mreeir_edit_number_send_sms',
                mobile : $mobile,
                userisnotauser :  $userisnotauser,
                security: mreeir_js_options.editsendsms,
                userid: mreeir_js_options.currentuserid,
            },
            beforeSend: function() {
                $('.mreeir-element-wrapper.mreeir-loading').removeClass('mreeir-hide');
            },
            success: function(response) {
                
                $('.mreeir-element-wrapper.mreeir-loading').addClass('mreeir-hide');
                if ( response == 'success' ) {
                    jQuery('.mreeir-form-wrapper.edit_getmobilenumber').hide();
                    mreeir_form_controller($('.mreeir-form-wrapper.edit_getverifycode'));
                    jQuery('.mreeir-form-wrapper.edit_getverifycode #editverifycode').focus();
                    mreeir_resend_code_master();
                }
                if ( response == 'duplicate-number' ) {
                    mreeir_notification(force_messeges.duplicateNumber);
                }
                if ( response == 'duplicate-number') {
                    mreeir_notification(force_messeges.duplicateNumber);
                }
                if ( response == 'change-limited-reached' ) {
                    mreeir_notification(force_messeges.changeLimitReached);
                }
                if ( response == 'wrong-info' ) {
                    mreeir_notification(force_messeges.MobileNotValid);
                }
                if ( response == 'send-failed' ) {
                    mreeir_notification(force_messeges.sendFailed);
                }
                if ( response == 'sms-send-time-limit' ) {
                    mreeir_notification(force_messeges.SendTimeLimit);
                }
                if ( response == 'blocked-mobile' ) {
                    mreeir_notification(mreeir_js_options.mobileisblocked);
                }
            },
            complete: function() {
                $('.mreeir-element-wrapper.mreeir-loading').addClass('mreeir-hide');
            }
        });
    
    });

    // ================ edit number - veify code
    $('#editverifycode').keypress(function (e) {
        var key = e.which;
        if(key == 13)  // the enter key code
        {
            $('#submit-edit2').click();
            return false;  
        }
    });

    jQuery('#submit-edit2').on('click',function(e) {
        
        e.preventDefault();
        var verifycode = $('#editverifycode').val();
        verifycode = mreeir_correct_mobile_number(verifycode);
        var $userisnotauser = $('.mreeir-form-wrapper.edit_getverifycode .userisnotauser').val();
        
        if( ! mreeir_is_empty($userisnotauser) ) {
            if ( mreeir_is_empty_fake( $userisnotauser ) ) {
                mreeir_notification(force_messeges.wrongInfo);
                return;
            }
        }
        if ( mreeir_is_empty( glob_mobile ) )  return;
        
        if( jQuery.isNumeric(verifycode) && verifycode.length == mreeir_js_options.verifycodelength ) { 
            
            jQuery.ajax({
                url: mreeir_js_options.ajaxurl,
                type: 'POST',
                data: {
                    action: 'mreeir_verify_code_edit_number',
                    mobile: glob_mobile,
                    userisnotauser :  $userisnotauser,
                    code : verifycode,
                    security: mreeir_js_options.editverifycode,
                    userid: mreeir_js_options.currentuserid,
                },
                beforeSend: function() {
                    $('.mreeir-element-wrapper.mreeir-loading').removeClass('mreeir-hide');
                },
                success: function(response) {

                    if ( response == 'success-edit') {
                        mreeir_notification(force_messeges.successEdit);
                        location.reload();
                    }
                    if ( response == 'failed-edit') {
                        mreeir_notification(force_messeges.errorInEdit);
                    }
                    if ( response == 'wrong-code') {
                        mreeir_notification(force_messeges.wrongCode);
                    }
                    if ( response == 'wrong-mobile') {
                        mreeir_notification(force_messeges.wrongMobile);
                    }
                    if ( response == 'wrong-info') {
                        mreeir_notification(force_messeges.wrongInfo);
                    }
                    if ( response == 'blocked-mobile' ) {
                        mreeir_notification(mreeir_js_options.mobileisblocked);
                    }
                },
                complete: function() {
                    $('.mreeir-element-wrapper.mreeir-loading').addClass('mreeir-hide');
                }
            });
        } else {

        }

    });
    
    // ================ Resend Code in form edit number
    $('.mreeir-form-wrapper.edit_getverifycode a.edit-resend-code').on( 'click' , function(e){
        e.preventDefault();
        var $mobile = glob_mobile;
        $mobile = mreeir_correct_mobile_number($mobile);
        var $userisnotauser = $('.mreeir-form-wrapper.edit_getverifycode .userisnotauser').val();

        if ( mreeir_is_empty( $mobile ) ) {
            mreeir_notification(force_messeges.MobileNotValid);
            return;
        }
        
        if( ! mreeir_is_empty($userisnotauser) ) {
            if ( mreeir_is_empty_fake( $userisnotauser ) ) {
                mreeir_notification(force_messeges.wrongInfo);
                return;
            }
        }
        
        jQuery.ajax({
            url: mreeir_js_options.ajaxurl,
            type: 'POST',
            data: {
                action: 'mreeir_edit_number_send_sms',
                mobile : $mobile,
                userisnotauser :  $userisnotauser,
                security: mreeir_js_options.editsendsms,
                userid: mreeir_js_options.currentuserid,
            },
            beforeSend: function() {
                $('.mreeir-element-wrapper.mreeir-loading').removeClass('mreeir-hide');
            },
            success: function(response) {
                
                if ( response == 'success' ) {
                    $('.mreeir-form-wrapper.edit_getverifycode #editverifycode').focus();
                    mreeir_resend_show_countdown();
                    mreeir_resend_code_master();
                }
                if ( response == 'wrong-info' ) {
                    mreeir_notification(force_messeges.MobileNotValid);
                }
                if ( response == 'send-failed' ) {
                    mreeir_notification(force_messeges.sendFailed);
                }
                if ( response == 'sms-send-time-limit' ) {
                    mreeir_notification(force_messeges.SendTimeLimit);
                }
                
            },
            complete: function() {
                $('.mreeir-element-wrapper.mreeir-loading').addClass('mreeir-hide');
            }
        });
    });

    $edit_back_step2to1 = $('.mreeir-form-wrapper.edit_getverifycode .mreeir-element-wrapper.mreeir-back');
    $edit_back_step2to1.on( 'click', function(e) {
        e.preventDefault();
        mreeir_form_controller($('.mreeir-form-wrapper.edit_getmobilenumber'));
        mreeir_resend_show_send_button();
    });


    // ================ force verify - Get Mobile
    $('#mobile').keypress(function (e) {
        var key = e.which;
        if(key == 13)  // the enter key code
        {
            $('#submit-force1').click();
            return false;  
        }
    });

    $('#submit-force1').on( 'click' , function(e){
        
        e.preventDefault();
        var $mobile = $('#mobile').val();
        var $userisnotauser = $('.mreeir-form-wrapper.force_getmobilenumber .userisnotauser').val();

        if ( mreeir_is_empty( $mobile ) ) {
            mreeir_notification(force_messeges.MobileNotValid);
            return;
        }
        if( ! mreeir_is_empty($userisnotauser) ) {
            if ( mreeir_is_empty_fake( $userisnotauser ) ) {
                mreeir_notification(force_messeges.wrongInfo);
                return;
            }
        }

        $mobile = mreeir_correct_mobile_number($mobile);

        if ( ! mreeir_is_mobile( $mobile ) ) {
            mreeir_notification(force_messeges.MobileNotValid);
            return;
        }
        
        glob_mobile = $mobile;
        
        jQuery.ajax({
            url: mreeir_js_options.ajaxurl,
            type: 'POST',
            data: {
                action: 'mreeir_force_send_sms',
                mobile : $mobile,
                userisnotauser :  $userisnotauser,
                security: mreeir_js_options.forcesendsms,
            },
            beforeSend: function() {
                $('.mreeir-element-wrapper.mreeir-loading').removeClass('mreeir-hide');
            },
            success: function(response) {
                
                $('.mreeir-element-wrapper.mreeir-loading').addClass('mreeir-hide');
                if ( response == 'success' ) {
                    jQuery('.mreeir-form-wrapper.force_getmobilenumber').hide();
                    mreeir_form_controller($('.mreeir-form-wrapper.force_getverifycode'));
                    jQuery('.mreeir-form-wrapper.force_getverifycode #verifycode').focus();
                    mreeir_resend_code_master();
                }
                if ( response == 'repeated-mobile' ) {
                    mreeir_notification(force_messeges.repeatedMobile);
                }
                if ( response == 'wrong-info' ) {
                    mreeir_notification(force_messeges.MobileNotValid);
                }
                if ( response == 'send-failed' ) {
                    mreeir_notification(force_messeges.sendFailed);
                }
                if ( response == 'sms-send-time-limit' ) {
                    mreeir_notification(force_messeges.SendTimeLimit);
                }
                
            },
            complete: function() {
                $('.mreeir-element-wrapper.mreeir-loading').addClass('mreeir-hide');
            }
        });
 
    });

    // ================ force verify - Verify Code
    $('#verifycode').keypress(function (e) {
        var key = e.which;
        if(key == 13)  // the enter key code
        {
            $('#submit-force2').click();
            return false;  
        }
    });

    jQuery('#submit-force2').on('click',function(e) {
        
        e.preventDefault();
        var verifycode = $('#verifycode').val();
        verifycode = mreeir_correct_mobile_number(verifycode);
        var $userisnotauser = $('.mreeir-form-wrapper.force_getverifycode .userisnotauser').val();
     
        if( ! mreeir_is_empty($userisnotauser) ) {
            if ( mreeir_is_empty_fake( $userisnotauser ) ) {
                mreeir_notification(force_messeges.wrongInfo);
                return;
            }
        }
        if ( mreeir_is_empty( glob_mobile ) )  return;
        
        if( jQuery.isNumeric(verifycode) && verifycode.length == mreeir_js_options.verifycodelength ) { 
            
            jQuery.ajax({
                url: mreeir_js_options.ajaxurl,
                type: 'POST',
                data: {
                    action: 'mreeir_verify_code_force',
                    mobile: glob_mobile,
                    userisnotauser :  $userisnotauser,
                    code : verifycode,
                    security: mreeir_js_options.forceverifycode,
                    userid: mreeir_js_options.currentuserid,
                },
                beforeSend: function() {
                    $('.mreeir-element-wrapper.mreeir-loading').removeClass('mreeir-hide');
                },
                success: function(response) {

                    if ( response == 'success-register') {
                        mreeir_notification(force_messeges.successRegister);
                        window.location = mreeir_js_options.force_redirect;
                    }
                    if ( response == 'failed-register') {
                        mreeir_notification(force_messeges.errorInRegister);
                    }
                    if ( response == 'wrong-code') {
                        mreeir_notification(force_messeges.wrongCode);
                    }
                    if ( response == 'wrong-mobile') {
                        mreeir_notification(force_messeges.wrongMobile);
                    }
                    if ( response == 'wrong-info') {
                        mreeir_notification(force_messeges.wrongInfo);
                    }

                },
                complete: function() {
                    $('.mreeir-element-wrapper.mreeir-loading').addClass('mreeir-hide');
                }
            });
        } else {

        }

    });

    // ================ Resend Code in form force verify number
    $('.mreeir-form-wrapper.force_getverifycode a.force-resend-code').on( 'click' , function(e){
            
        e.preventDefault();
        var $mobile = glob_mobile;
        $mobile = mreeir_correct_mobile_number($mobile);
        var $userisnotauser = $('.mreeir-form-wrapper.force_getverifycode .userisnotauser').val();

        if ( mreeir_is_empty( $mobile ) ) {
            mreeir_notification(force_messeges.MobileNotValid);
            return;
        }
        
        if( ! mreeir_is_empty($userisnotauser) ) {
            if ( mreeir_is_empty_fake( $userisnotauser ) ) {
                mreeir_notification(force_messeges.wrongInfo);
                return;
            }
        }

        jQuery.ajax({
            url: mreeir_js_options.ajaxurl,
            type: 'POST',
            data: {
                action: 'mreeir_force_send_sms',
                mobile : $mobile,
                userisnotauser :  $userisnotauser,
                security: mreeir_js_options.forcesendsms,
            },
            beforeSend: function() {
                $('.mreeir-element-wrapper.mreeir-loading').removeClass('mreeir-hide');
            },
            success: function(response) {
                
                if ( response == 'success' ) {
                    $('.mreeir-form-wrapper.force_getverifycode #verifycode').focus();
                    mreeir_resend_show_countdown();
                    mreeir_resend_code_master();
                }
                if ( response == 'wrong-info' ) {
                    mreeir_notification(force_messeges.MobileNotValid);
                }
                if ( response == 'send-failed' ) {
                    mreeir_notification(force_messeges.sendFailed);
                }
                if ( response == 'sms-send-time-limit' ) {
                    mreeir_notification(force_messeges.SendTimeLimit);
                }
                
            },
            complete: function() {
                $('.mreeir-element-wrapper.mreeir-loading').addClass('mreeir-hide');
            }
        });
    });


    
    // ================ force verify - Get Mobile
    $('#email').keypress(function (e) {
        var key = e.which;
        if(key == 13)  // the enter key code
        {
            $('#submit_force_email').click();
            return false;  
        }
    });

    $('#submit_force_email').on( 'click' , function(e){
        
        e.preventDefault();
        var $email = $('#email').val();
        var $userisnotauser = $('.mreeir-form-wrapper.force_getmobilenumber .userisnotauser').val();

        if ( mreeir_is_empty( $email ) ) {
            mreeir_notification(force_messeges.EmailNotValid);
            return;
        }

        if( ! mreeir_is_empty($userisnotauser) ) {
            if ( mreeir_is_empty_fake( $userisnotauser ) ) {
                mreeir_notification(force_messeges.wrongInfo);
                return;
            }
        }

        if ( ! mreeir_is_email( $email ) ) {
            mreeir_notification(force_messeges.EmailNotValid);
            return;
        }
        
        glob_email = $email;
        
        jQuery.ajax({
            url: mreeir_js_options.ajaxurl,
            type: 'POST',
            data: {
                action: 'mreeir_force_send_email_code',
                email : $email,
                userisnotauser :  $userisnotauser,
                security: mreeir_js_options.forcesendemailcode,
            },
            beforeSend: function() {
                $('.mreeir-element-wrapper.mreeir-loading').removeClass('mreeir-hide');
            },
            success: function(response) {
                
                $('.mreeir-element-wrapper.mreeir-loading').addClass('mreeir-hide');
                if ( response == 'success' ) {
                    jQuery('.mreeir-form-wrapper.force_getmobilenumber').hide();
                    mreeir_form_controller($('.mreeir-form-wrapper.force_getverifycode'));
                    jQuery('.mreeir-form-wrapper.force_getverifycode #verifycode').focus();
                    mreeir_resend_code_master();
                }
                if ( response == 'repeated-email' ) {
                    mreeir_notification(force_messeges.repeatedEmail);
                }
                if ( response == 'email-domain-not-allowed' ) {
                    mreeir_notification(mreeir_js_options.email_notvalid_message);    
                }
                if ( response == 'wrong-info' ) {
                    mreeir_notification(force_messeges.EmailNotValid);
                }
                if ( response == 'send-failed' ) {
                    mreeir_notification(force_messeges.sendFailed);
                }
                if ( response == 'sms-code-time-limit' ) {
                    mreeir_notification(force_messeges.SendTimeLimit);
                }
                
            },
            complete: function() {
                $('.mreeir-element-wrapper.mreeir-loading').addClass('mreeir-hide');
            }
        });
    
    });

    // ================ force verify email - Verify Code
    $('#verifycode').keypress(function (e) {
        var key = e.which;
        if(key == 13)  // the enter key code
        {
            $('#verify_force_email').click();
            return false;  
        }
    });

    jQuery('#verify_force_email').on('click',function(e) {
        
        e.preventDefault();
        var verifycode = $('#verifycode').val();
        verifycode = mreeir_correct_mobile_number(verifycode);
        var $userisnotauser = $('.mreeir-form-wrapper.force_getverifycode .userisnotauser').val();
        
        if( ! mreeir_is_empty($userisnotauser) ) {
            if ( mreeir_is_empty_fake( $userisnotauser ) ) {
                mreeir_notification(force_messeges.wrongInfo);
                return;
            }
        }
        if ( mreeir_is_empty( glob_email ) )  return;
        
        if( jQuery.isNumeric(verifycode) && verifycode.length == mreeir_js_options.verifycodelength ) { 
            
            jQuery.ajax({
                url: mreeir_js_options.ajaxurl,
                type: 'POST',
                data: {
                    action: 'mreeir_verify_code_force_email',
                    email: glob_email,
                    userisnotauser :  $userisnotauser,
                    code : verifycode,
                    security: mreeir_js_options.forceverifycode,
                    userid: mreeir_js_options.currentuserid,
                },
                beforeSend: function() {
                    $('.mreeir-element-wrapper.mreeir-loading').removeClass('mreeir-hide');
                },
                success: function(response) {

                    if ( response == 'success-register') {
                        mreeir_notification(force_messeges.emailSuccessRegister);
                        window.location = mreeir_js_options.force_redirect;
                    }
                    if ( response == 'failed-register') {
                        mreeir_notification(force_messeges.emailErrorInRegister);
                    }
                    if ( response == 'wrong-code') {
                        mreeir_notification(force_messeges.wrongCode);
                    }
                    if ( response == 'wrong-mobile') {
                        mreeir_notification(force_messeges.wrongEmail);
                    }
                    if ( response == 'wrong-info') {
                        mreeir_notification(force_messeges.wrongInfo);
                    }

                },
                complete: function() {
                    $('.mreeir-element-wrapper.mreeir-loading').addClass('mreeir-hide');
                }
            });
        } else {

        }

    });

    // ================ Resend Code in form force email address
    $('.mreeir-form-wrapper.force_getverifycode a.force-resend-code').on( 'click' , function(e){
            
        e.preventDefault();
        var $email = glob_email;
        
        var $userisnotauser = $('.mreeir-form-wrapper.force_getverifycode .userisnotauser').val();

        if ( ! mreeir_is_email( $email ) ) {
            mreeir_notification(force_messeges.EmailNotValid);
            return;
        }
        
        if( ! mreeir_is_empty($userisnotauser) ) {
            if ( mreeir_is_empty_fake( $userisnotauser ) ) {
                mreeir_notification(force_messeges.wrongInfo);
                return;
            }
        }

        jQuery.ajax({
            url: mreeir_js_options.ajaxurl,
            type: 'POST',
            data: {
                action: 'mreeir_force_send_email_code',
                email : $email,
                userisnotauser :  $userisnotauser,
                security: mreeir_js_options.forcesendemailcode,
            },
            beforeSend: function() {
                $('.mreeir-element-wrapper.mreeir-loading').removeClass('mreeir-hide');
            },
            success: function(response) {
                
                if ( response == 'success' ) {
                    $('.mreeir-form-wrapper.force_getverifycode #verifycode').focus();
                    mreeir_resend_show_countdown();
                    mreeir_resend_code_master();
                }
                if ( response == 'wrong-info' ) {
                    mreeir_notification(force_messeges.EmailNotValid);
                }
                if ( response == 'send-email-failed' ) {
                    mreeir_notification(force_messeges.sendFailed);
                }
                if ( response == 'sms-send-time-limit' ) {
                    mreeir_notification(force_messeges.SendTimeLimit);
                }
                
            },
            complete: function() {
                $('.mreeir-element-wrapper.mreeir-loading').addClass('mreeir-hide');
            }
        });
    });

    function mreeirsec2human(seconds) {
        sec = seconds % 60;
        min = parseInt(seconds / 60);
        if(sec.toString().length == 1) { // padding
            sec = "0" + sec;
        }
        if(min.toString().length == 1) { // padding
            min = "0" + min;
        }
        return min + ":" + sec;
    }
    
    var mreeir_cd_logged_master = null;
    function mreeir_resend_code_master() {
        var $full_time = mreeir_js_options.resendcodetime;
        if (mreeir_cd_logged_master) {
            clearInterval(mreeir_cd_logged_master);
            mreeir_cd_logged_master = null;
        }
        $('.mreeir-form-wrapper .mreeir-resendtime').text( mreeirsec2human($full_time) );
        $full_time--;
        mreeir_cd_logged_master = setInterval( function(){
            $('.mreeir-form-wrapper .mreeir-resendtime').text( mreeirsec2human($full_time) );
            $full_time--;
            if ( $full_time < 0 ) {
                clearInterval(mreeir_cd_logged_master);
                mreeir_cd_logged_master = null;
                $('.mreeir-form-wrapper .mreeir-resendtime').text('');
                mreeir_resend_show_send_button();
            }
        }, 1000);
    }

    function mreeir_resend_show_send_button() {
        $('.mreeir-form-wrapper .mreeir-resendtime-wrapper').hide();
        $('.mreeir-form-wrapper .mreeir-resendcode-wrapper').show();
    }

    function mreeir_resend_show_countdown() {
        $('.mreeir-form-wrapper .mreeir-resendtime-wrapper').show();
        $('.mreeir-form-wrapper .mreeir-resendcode-wrapper').hide();
    }

    $forceback_step2to1 = $('.mreeir-form-wrapper.force_getverifycode .mreeir-element-wrapper.mreeir-back');

    $forceback_step2to1.on( 'click', function(e) {
        e.preventDefault();
        mreeir_form_controller($('.mreeir-form-wrapper.force_getmobilenumber'));
        mreeir_resend_code_master_sender_off();
    });

    function mreeir_form_controller( destination_form_obj ) {
        $('.mreeir-form-wrapper').removeClass('mreeir-force-show');
        $('.mreeir-form-wrapper').addClass('mreeir-force-hide');
        
        destination_form_obj.removeClass('mreeir-force-hide');
        destination_form_obj.addClass('mreeir-force-show');
    }

    function mreeir_correct_mobile_number( $mobile ) {
        var inputs = "" + $mobile;
        new_val = inputs.replace(/۰/g, '0').replace(/۱/g, '1').replace(/۲/g, '2').replace(/۳/g, '3').replace(/۴/g, '4').replace(/۵/g, '5').replace(/۶/g, '6').replace(/۷/g, '7').replace(/۸/g, '8').replace(/۹/g, '9').replace(/٤/g, '4').replace(/٥/g, '5').replace(/٦/g, '6');
        
        new_val = new_val.replace(/٠/g, '0').replace(/١/g, '1').replace(/٢/g, '2').replace(/٣/g, '3').replace(/٤/g, '4').replace(/۵/g, '5').replace(/٦/g, '6').replace(/٧/g, '7').replace(/٨/g, '8').replace(/٩/g, '9').replace(/٤/g, '4').replace(/٥/g, '5').replace(/٦/g, '6');
        return new_val;   
    }

    // check empty function
    function mreeir_is_empty_fake (data) {
        if (data.indexOf(' ') >= 0) {
            return true;
        }
        if(data.trim()){
            return true;
        }
        return false;
    }

    // check empty function
    var mreeir_is_empty = function (data) {
        if(typeof(data) === 'object'){
            if(JSON.stringify(data) === '{}' || JSON.stringify(data) === '[]'){
                return true;
            }else if(!data){
                return true;
            }
            return false;
        }else if(typeof(data) === 'string'){
            if(!data.trim()){
                return true;
            }
            return false;
        }else if(typeof(data) === 'undefined'){
            return true;
        }else{
            return false;
        }
    }

    function mreeir_notification (message) {
        $.toast({
            text: message,
            showHideTransition: mreeir_js_options.toast_transition,
            textAlign: 'center',
            stack: false,
            position: mreeir_js_options.toast_position,
            bgColor: mreeir_js_options.toast_bgcolor,
            textColor: mreeir_js_options.toast_color, //'#721c24',
            loaderBg: mreeir_js_options.toast_progress_color,
            class: 'mreeir-error-toast',
            hideAfter: mreeir_js_options.toast_time,
            allowToastClose: mreeir_js_options.toast_close,
        });
    }

    function mreeir_is_mobile (mobileNumber) {
        var regex = /^09\d{9}$/;
        return regex.test(mobileNumber);
    }

    function mreeir_is_email (email) {
        var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        return regex.test(email);
    }

    var force_messeges = {
        EmailNotValid:"ایمیل وارد شده معتبر نیست",
        MobileNotValid:"شماره موبایل وارد شده معتبر نیست",
        sendFailed:'خطا در ارسال',
        wrongCode:'کد تایید اشتباه است',
        wrongMobile:'شماره موبایل معتبر نیست',
        wrongEmail:'آدرس ایمیل معتبر نیست',
        wrongInfo:'اطلاعات وارد شده معتبر نیست',
        SendTimeLimit:'لطفاً برای ارسال مجدد کد تایید لحظاتی صبر کنید',
        errorInRegister:'خطایی در فرآیند تایید شماره موبایل رخ داده است',
        emailErrorInRegister:'خطایی در فرآیند تایید آدرس ایمیل رخ داده است',
        emailDomainNotAllowed:'دامنه ایمیل نامعتبر است',
        errorInEdit:'خطایی در فرآیند تغییر شماره موبایل رخ داده است',
        successRegister:'تایید شماره موبایل انجام شد',
        emailSuccessRegister:'تایید آدرس ایمیل انجام شد',
        successEdit:'تغییر شماره موبایل با موفقیت انجام شد',
        duplicateNumber:'شماره موبایل وارد شده تکراری است',
        changeLimitReached:'تعداد دفعات تغییر شماره موبایل شما تمام شده است',
        repeatedMobile : 'این شماره موبایل قبلاً ثبت شده است',
        repeatedEmail : 'این ایمیل قبلاً ثبت شده است',
    };

});