/*!
 * jQuery Cookie Plugin v1.4.1
 * https://github.com/carhartl/jquery-cookie
 *
 * Copyright 2006, 2014 Klaus Hartl
 * Released under the MIT license
 */
(function (factory) {
    if (typeof define === 'function' && define.amd) {
        // AMD (Register as an anonymous module)
        define(['jquery'], factory);
    } else if (typeof exports === 'object') {
        // Node/CommonJS
        module.exports = factory(require('jquery'));
    } else {
        // Browser globals
        factory(jQuery);
    }
}(function ($) {

    var pluses = /\+/g;

    function encode(s) {
        return config.raw ? s : encodeURIComponent(s);
    }

    function decode(s) {
        return config.raw ? s : decodeURIComponent(s);
    }

    function stringifyCookieValue(value) {
        return encode(config.json ? JSON.stringify(value) : String(value));
    }

    function parseCookieValue(s) {
        if (s.indexOf('"') === 0) {
            // This is a quoted cookie as according to RFC2068, unescape...
            s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
        }

        try {
            // Replace server-side written pluses with spaces.
            // If we can't decode the cookie, ignore it, it's unusable.
            // If we can't parse the cookie, ignore it, it's unusable.
            s = decodeURIComponent(s.replace(pluses, ' '));
            return config.json ? JSON.parse(s) : s;
        } catch(e) {}
    }

    function read(s, converter) {
        var value = config.raw ? s : parseCookieValue(s);
        return $.isFunction(converter) ? converter(value) : value;
    }

    var config = $.cookie = function (key, value, options) {

        // Write

        if (arguments.length > 1 && !$.isFunction(value)) {
            options = $.extend({}, config.defaults, options);

            if (typeof options.expires === 'number') {
                var days = options.expires, t = options.expires = new Date();
                t.setMilliseconds(t.getMilliseconds() + days * 864e+5);
            }

            return (document.cookie = [
                encode(key), '=', stringifyCookieValue(value),
                options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
                options.path    ? '; path=' + options.path : '',
                options.domain  ? '; domain=' + options.domain : '',
                options.secure  ? '; secure' : ''
            ].join(''));
        }

        // Read

        var result = key ? undefined : {},
            // To prevent the for loop in the first place assign an empty array
            // in case there are no cookies at all. Also prevents odd result when
            // calling $.cookie().
            cookies = document.cookie ? document.cookie.split('; ') : [],
            i = 0,
            l = cookies.length;

        for (; i < l; i++) {
            var parts = cookies[i].split('='),
                name = decode(parts.shift()),
                cookie = parts.join('=');

            if (key === name) {
                // If second argument (value) is a function it's a converter...
                result = read(cookie, value);
                break;
            }

            // Prevent storing a cookie that we couldn't decode.
            if (!key && (cookie = read(cookie)) !== undefined) {
                result[name] = cookie;
            }
        }

        return result;
    };

    config.defaults = {};

    $.removeCookie = function (key, options) {
        // Must not alter options, thus extending a fresh object...
        $.cookie(key, '', $.extend({}, options, { expires: -1 }));
        return !$.cookie(key);
    };

}));

function addShowMore () {
    jQuery('.news-content').each(function(){
        if($(this).length){
            var html = jQuery(this).html();
            var newHtml='';
            var addedshowmore=false;
            for (var i=0;i<html.length;i++) {
                newHtml=newHtml+html[i];
                if (i===400) {
                    newHtml += '<a href="" class="showxmore activ"> read more </a><i class="complete hidden">';
                    addedshowmore=true;
                }
                if(addedshowmore===true && i === html.length){
                    newHtml += '</i>';
                }
            }
            newHtml += '<a href="" class="showxmore hidden"> read less </a>';
            jQuery(this).html(newHtml);
        }
    });
}
function getRedirect() {
    var redirect = '';
    jQuery('input[type=radio]:checked').each(function(e) {
        var url = jQuery(this).parent().find('input[type=hidden]').val()
        if(url) {
            redirect = url;
        }
    });
    return redirect;
}
var ajax_w_register = true, ajax_w_unregister = true;
function sticky_basket () {
    $ = jQuery;
    if(!$('.basket').length) {
        return null;
    }
    if($(window).scrollTop()> $('.filters-bar').offset().top && $(window).outerWidth() > 640) {
       //$('.formfields')


        $('.basket').addClass('sticky-top');
    } else if ($(window).scrollTop()> $('.filters-bar').offset().top && $(window).outerWidth() < 640 && !is_empty_cart ) {



        $('.small-devices').show();
    }else {
        $('.basket').removeClass('sticky-top'); 
        $('.small-devices').hide();
    }
}
var ajax_check = [];
jQuery(document).ready(function($) {
    $('.user_info input').on('input change', function() {
        $('.system_msg').remove();
    });
    $('.view_top').on('click', function(e) {
        e.preventDefault();
        $('html, body').animate({
            scrollTop: $('.basket').offset().top
       }, 700);
    });
    $('body').on('click', '.checkout-btn', function( e ){
        e.preventDefault();
        var _self = $(this); _page_id = parseInt(_self.data('page-id'));
        if( !( 'checkout' in ajax_check ) || ajax_check['chekout'] === false  ) {
            $('.system_msg').remove();
            ajax_check['chekout'] = true;
            _self.html('<i class="fa fa-spinner fa-spin"></i>');
            var full_name = $('input[name=user_fullname]').length ? $('input[name=user_fullname]').val() : false;
            var email = $('input[name=user_email]').length ? $('input[name=user_email]').val() : false;

            var user_phone = $('input[name=user_phone]').length ? $('input[name=user_phone]').val() : false;
            var user_last = $('input[name=user_last]').length ? $('input[name=user_last]').val() : false;

            console.log(user_phone);

            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: ROOT + '/wp-admin/admin-ajax.php',
                data: {
                    action: 'ajax_send_cart',
                    page_id: _page_id,
                    email: email,
                    full_name: full_name,
                    user_phone: user_phone,
                    user_last: user_last

                },
                error: function ( response ) {
                     _self.html('Continue');
                     ajax_check['chekout'] = false;
                },
                success: function (response) {
                    
                    if( response.redirect !== '' ) {
                        window.location = response.redirect;
                        return null;
                    } 
                    if( response.error && response.msg ) {
                        $('.user_info').append('<p class="system_msg">' + response.msg + '</p>');
                        $('.sticky-top .errorsfields').append('<p class="system_msg">' + response.msg + '</p>');    
                        
                        _self.html('Continue');
                        ajax_check['chekout'] = false;
                    }
                }
            });
        }
    });
    $('body').on('click', '.remove-item', function(e){
        e.preventDefault();
         var _self = $(this), carrier_id = _self.data('id');
        _self.closest('.item').find('hover').show();
        $.ajax({
            type: 'POST',
            dataType: 'json',
            url: ROOT + '/wp-admin/admin-ajax.php',
            data: {
                action: 'ajax_removeCartItem',
                carrier_id: carrier_id
            },
            success: function (response) {
                if(response.ok) {
                    _self.closest('.item').fadeOut('slow', function () {
                        _self.closest('.col-item').remove();
                        $('._ajax_add2cart[data-id=' + carrier_id+']').closest('.carrier-box').removeClass('in_cart');
                        if(response.count > 0) {
                            $('.contracts_info .left, .contracts_info .right').show();
                            $('.small-devices').show();
                            $('.cart-checkout p').html(response.btn[0]);
                            $('.small-devices p').html(response.btn[1]);
                            is_empty_cart = false;
                        }
                        else {
                            $('.contracts_info .left, .contracts_info .right').hide();
                            $('.small-devices').hide();
                            is_empty_cart = true;
                        }
                    });
                }
                else {
                    _self.closest('.item').find('hover').hide();
                }
            }
        });
    });
    $('body').on('click', '.carrier-box:not(.in_cart)', function(e){
        e.preventDefault();
        var _self = $(this), _btn = _self.find('._ajax_add2cart'), carrier_id = _btn.data('id');
        _btn.html('<i class="fa fa-spinner fa-spin"></i>');
        $.ajax({
            type: 'POST',
            dataType: 'json',
            url: ROOT + '/wp-admin/admin-ajax.php',
            data: {
                action: 'ajax_add2cart',
                carrier_id: carrier_id
            },
            success: function (response) {
                _btn.html('Add Contract');
                if(response.ok) {
                    _self.addClass('in_cart');
                    _self.find('.image').addClass('flip');
                    if(response.count > 0) {
                        $('.contracts_info .left, .contracts_info .right').show();
                        $('.small-devices').show();
                        $('.cart-checkout p').html(response.btn[0]);
                        $('.small-devices p').html(response.btn[1]);
                        $('.contracts-container').append(response.html);
                        is_empty_cart = false;
                    }
                    else {
                       $('.contracts_info .left, .contracts_info .right').hide();
                       $('.small-devices').hide();
                       is_empty_cart = true;
                    }
                }
                else {
                    _self.removeClass('in_cart');
                }
            }
        });
    });
    $('._filter select').on('change', function(){
        var form = $(this).closest('form');
        $('.carriers').html('<div class="loading"></div>');
        $.ajax({
            type: 'POST',
            dataType: 'json',
            url: ROOT + '/wp-admin/admin-ajax.php',
            data: form.serialize() + '&action=filter_carriers',
            success: function (response) {
                $('.carriers-add').html(response);
            }
        });
    });
    
    $('body').on('click', '._ajax_unregister_me', function(e) {
        e.preventDefault();
        var _self = $(this);
        if(ajax_w_unregister === true) {
            ajax_w_unregister = false;
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: ROOT + '/wp-admin/admin-ajax.php',
                data: {
                    action: 'ajax_w_unregister',
                    wkey: _self.data('webinar'),
                    ukey: _self.data('key')
                },
                success: function( response ) {
                    ajax_w_unregister = true;
                }
            });
        }
    });
    $('._ajax_w_submit').on('click', function(e) {
        e.preventDefault();
        var _self = $(this), _form = _self.closest('form'), _tmp = _self.text();
        if(ajax_w_register === true) {
            _self.html('<i class="fa fa-spinner fa-spin"></i>')
            ajax_w_register = false;
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: ROOT + '/wp-admin/admin-ajax.php',
                data: _form.serialize() + '&action=ajax_w_register',
                success: function( response ) {
                    $('.ajax-response').remove();
                    if(response.success == false) {
                        _self.before('<p class="ajax-response error">' + response.msg + '</p>');
                        _self.html(_tmp);
                    }
                    else {
                        var html = '<div class="webinar_form"><div class="logged_in_user"><h2>Reserved</h2>'
                        html+= '<h4>' + response.msg + '</h4></div>';
                        _self.closest('.webinar_register').html(html);
                    }
                    ajax_w_register = true;
                    
                }
            });
        }
    });
    $('.training-new-events select[name=topics]').on('change', function(){
        window.location = vc_current_url + '?filter_topic='+ $(this).val();
    });
    $('.tab_js a').click(function (e) {
        e.preventDefault();
        if (!$(this).parent().hasClass('active')) {
            $('.tab_js a').parent().removeClass('active');
            $('.tab_body .tab_item').removeClass('active');
            $(this).parent().addClass('active');
            $($(this).attr('href')).addClass('active');
        }
    });
    $('.read-more-title').click(function (e) {
        e.preventDefault();
        $($(this).attr('href')).toggleClass('close');
    });
    addShowMore();
    if($('.homepage_tabs').length) {
        onScroll(); 
    }
    if($('.login_form').length) {
        $('.login_form .login_submit').click(function(e) {
            e.preventDefault();
            var $this = $(this);
            $this.prop('disabled', true);
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: ROOT + '/wp-admin/admin-ajax.php',
                data: {
                    action: 'ajax_login',
                    email: $('.login_form input[name=login_email]').val(),
                    password: $('.login_form input[name=login_password]').val(),
                    security: $('.login_form input[name=security]').val()
                },
                success: function(data){
                    if($('.error_msg').length) {
                        $('.error_msg').remove();
                    }
                    if( ( 'loggedin_full' in data ) && data.loggedin_full == true ) {
                        window.location = 'https://whyaim.com/login_redirect/?goto='+document.getElementById('goto').value+'?rand='+Math.floor((Math.random() * 9999999) + 1);
                        return null;
                    }
                    else if(data.loggedin) {
                        /*if(!$.cookie('wordpress_logged_in')){
                            $.cookie('wordpress_logged_in', 'custom', { path: '/' });
                        }*/
                        // OPTION 1 - redirect straight to page
                        //window.location = document.getElementById('goto').value+'?'+Math.floor((Math.random() * 9999999) + 1);
                        //OPTION 2 - redirect through intelliclick
                        window.location = url_authentication;
                        //window.location = 'https://whyaim.com/login_redirect/?goto='+document.getElementById('goto').value+'?rand='+Math.floor((Math.random() * 9999999) + 1);
                    }
                    else {
                        $('.error_msg').remove();
                        if(data.email_error) {
                            $('.login_form .email_field').append(data.email_error);
                        }
                        if(data.password_error) {
                            $('.login_form .password_field').append(data.password_error);
                        }
                    }
                    $this.prop('disabled', false);
                }
            });
        });
    }
    if($('.authentication_form').length) {
        $('.authentication_form .authentication_submit').click(function(e) {
            e.preventDefault();
            var $this = $(this);
            $this.prop('disabled', true);
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: ROOT + '/wp-admin/admin-ajax.php',
                data: {
                    action: 'ajax_authentication',
                    authentication_code: $('.authentication_form input[name=authentication_code]').val( ),
                    security: $('.authentication_form input[name=security]').val(),
                    remember: $('.authentication_form input[name=remember]').is( ':checked' ) ? 1 : 0
                },
                success: function(data){
                    if($('.error_msg').length) {
                        $('.error_msg').remove();
                    }
                    if(data.loggedin) {
                        if(!$.cookie('wordpress_logged_in')){
                            $.cookie('wordpress_logged_in', 'custom', { path: '/' });
                        }
                        // OPTION 1 - redirect straight to page
                        //window.location = document.getElementById('goto').value+'?'+Math.floor((Math.random() * 9999999) + 1);
                        //OPTION 2 - redirect through intelliclick
                        window.location = 'https://whyaim.com/login_redirect/?goto='+document.getElementById('goto').value+'?rand='+Math.floor((Math.random() * 9999999) + 1);
                    }
                    else {
                        $('.error_msg').remove();
                        if(data.error) {
                            $('.authentication_form .email_field').append(data.error);
                        }
                    }
                    $this.prop('disabled', false);
                }
            });
        });
    }
    if($('.user_menu_btn').length) {
        $('.user_menu_btn').click(function(e){
            e.preventDefault();
            $(this).next('.submenu').toggleClass('show');
        });
        $('.logout_btn').click(function(e){
            e.preventDefault();
            $.ajax({
                type: 'GET',
                url: ROOT + '/wp-admin/admin-ajax.php?action=user_logout_action',
                success: function(){
                    $.removeCookie('wordpress_logged_in', { path: '/' });
                    window.location = ROOT+'?'+Math.floor((Math.random() * 9999999) + 1);
                }
            });
        });
    }
    $('.logout_btn2').click(function (e) {
        e.preventDefault();
        $.ajax({
            type: 'GET',
            url: ROOT + '/wp-admin/admin-ajax.php?action=user_logout_action',
            success: function () {
                $.removeCookie('wordpress_logged_in', {path: '/'});
                window.location = ROOT + '?' + Math.floor((Math.random() * 9999999) + 1);
            }
        });
    });
    if($('.signup_form').length) {
        $('.signup_form .submit_btn').click(function(e){
            e.preventDefault();
            var $this = $(this), data = $('.signup_form form').serialize() + '&redirect_uri=' + getRedirect() + '&action=ajax_signup';
            $this.prop('disabled', true);
            $this.addClass('loading').html('');
            
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: ROOT + '/wp-admin/admin-ajax.php',
                data: data,
                success: function(data) {
                    $('.response').html('');
                    $this.removeClass('loading');
                    $('.signup_form .error_msg').remove();
                    $('[name=signup_step]').val(data.step);
                    if($('.signup_form .step_' + data.step).hasClass('hide')) {
                        $('.signup_form .steps').addClass('hide');
                        $('.signup_form .step_' + data.step).removeClass('hide');
                    }
                    if(data.error) {
                        for(var key in data.msgs) {
                            $('.' + key + '_field').append('<p class="error_msg">' + data.msgs[key] + '</p>');
                        }
                        $this.html('Continue <span>(Step 2)</span>');
                    }
                    else if(data.step === 2) {
                        $this.html('Register');
                    }
                    else if(data.step === 3) {
                        if(!data.error) {
                            var redirect = getRedirect();
                            if(redirect !== false && redirect !== '') {
                               window.location = redirect;
                               return;
                            }
                            $('.signup_form form').trigger("reset");
                            $('.signup_form .step_2').addClass('hide');
                            $('.signup_form .step_1').removeClass('hide');
                            $this.html('Continue <span>(Step 2)</span>');
                        }
                        else {
                            $this.html('Register');
                        }
                        $('.response').append(data.msgs);
                        
                    }
                    $this.prop('disabled', false);
                }
            });
        });
    }
    if($('.rpass_form').length) {
        $('.rpass_form .rpass_submit').click(function(e){
            e.preventDefault();
            var $this = $(this);
            $this.prop('disabled', true);
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: ROOT + '/wp-admin/admin-ajax.php',
                data: {
                    action: 'ajax_rpass',
                    email: $('.rpass_form input[name=rpass_email]').val(),
                    security: $('.rpass_form input[name=security]').val()
                },
                success: function(data){
                    if($('.error_msg').length) {
                        $('.error_msg').remove();
                    }
                    if($('.success_msg').length) {
                        $('.sucess_msg').remove();
                    }
                    if(data.success) {
                        $('.rpass_form').prepend(data.success);
                    }
                    else if(data.error) {
                        $('.rpass_form .email_field').append(data.error);
                    }
                    $this.prop('disabled', false);
                }
            });
        });
        $('.rpass_form .chpass_submit').click(function(e){
            e.preventDefault();
            var $this = $(this);
            $this.prop('disabled', true);
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: ROOT + '/wp-admin/admin-ajax.php',
                data: {
                    action: 'ajax_change_pass',
                    sid: $('.rpass_form input[name=sid]').val(),
                    security: $('.rpass_form input[name=security]').val(),
                    password: $('.rpass_form input[name=rpass_pass]').val(),
                    cpassword: $('.rpass_form input[name=rpass_cpass]').val()
                },
                success: function(data){
                    if($('.error_msg').length) {
                        $('.error_msg').remove();
                    }
                    if($('.success_msg').length) {
                        $('.sucess_msg').remove();
                    }
                    if(data.success) {
                        $('.rpass_form').prepend('<p class="success_msg">Your password has been changed.</p>');
                    }
                    else {
                        if(data.pass_error) {
                            $('.password_field').append(data.pass_error);
                        }
                        if(data.cpass_error) {
                            $('.cpassword_field').append(data.cpass_error);
                        }
                    }
                    $this.prop('disabled', false);
                }
            });
        });
    }
    /*if($('.signup_popover_box').length) {
        $('.signup_popover_box .continue_btn').click(function(e){
            e.preventDefault();
            $(this).parent().parent().parent().parent().parent().remove();
        });
    }*/
    $('.more').click(function() { 
		$(this).parent().next().toggle();
		$(this).parent().toggle();
		return false;
	}).next().hide();
	
	$('.less').click(function() { 
		$(this).parent().prev().toggle();
		$(this).parent().toggle();
		return false;
	}).next().hide();
    $(".showxmore").click(function(){
        $(this).parents('.news-content').find('a.hidden').removeClass('hidden').addClass('activ');
        $(this).removeClass('active').addClass('hidden');
        $(this).parents('.news-content').find('.complete').toggleClass('hidden');
        return false;
    });
    $('.home_slider').flexslider({
        controlNav: true,
        directionNav: false
        
    });
    $('.menu_trigger').click(function(e){
        e.preventDefault();
        $('nav.primary_nav').toggleClass('show');
    });
    $('.primary_nav .close_btn').click(function(e){
        e.preventDefault();
        $('nav.primary_nav').toggleClass('show');
    });
    $('.homepage_tabs a').click(function(e){
        e.preventDefault();
        var target = $('.tab_box').eq($(this).parent().index()), offset = $(target).offset(), $this = $(this);
        if (typeof offset !== 'undifined') {
            $('html, body').animate({
                scrollTop: offset.top - $('.homepage_tabs').height() + 1
            }, {
                duration: 700,
                step: function(now, fx){
                    if($('.homepage_tabs').hasClass('scrolling')) {
                        fx.end = offset.top - $('.homepage_tabs').height() + 1;
                    }
                },
                complete: function(){
                    $('.homepage_tabs a').removeClass('active');
                    $this.addClass('active');
                }
            });
        }
    });
    $('.slider_tabs_selectors a').click(function(e){
        e.preventDefault();
        $('.slider_tabs_selectors a').removeClass('active');
        $(this).addClass('active');
        $('.slider_tabs .slider_tab').removeClass('active');
        $('.slider_tabs .slider_tab').eq($(this).index()).addClass('active').flexslider({
            controlNav: false,
            prevText: '<i class="fa fa-angle-left"></i>',
            nextText: '<i class="fa fa-angle-right"></i>',
            slideshow: false
        });
    });
    if($('.resources_slider').length) {
        $('.resources_slider').flexslider({
            animation: "slide",
            animationLoop: false,
            controlNav: false,
            itemWidth: 200,
            prevText: '<i class="fa fa-angle-left"></i>',
            nextText: '<i class="fa fa-angle-right"></i>',
            slideshow: false
        });
    }
});
jQuery(window).on('load',function(){
    var $ = jQuery;
    setTimeout(function(){
        if($('.popover_hover').length) {
            $('html, body').animate({
                scrollTop: 0
            }, 'slow', function(){
                $('.popover_hover').css('display', 'block');
            });
        }
    }, 5000);
    $('.remove_this').on('click',function(){
       $('.popover_hover').hide();
       return false;
    });
    $('.slider_tab.active').flexslider({
        controlNav: false,
        prevText: '<i class="fa fa-angle-left"></i>',
        nextText: '<i class="fa fa-angle-right"></i>',
        slideshow: false
    });
});
jQuery(window).on('scroll',function(){
    $ = jQuery;
    if($('.homepage_tabs').length) {
        onScroll(); 
    }
    sticky_basket();
});
jQuery(window).on('resize',function(){
    $ = jQuery;
    sticky_basket();
});
function onScroll(e) {
    $ = jQuery;
    var pos = $(document).scrollTop();
    if(pos > $('.tabs_home_cont').offset().top && !$('.homepage_tabs').hasClass('scrolling') && $(window).width() > 767) {
        $('.homepage_tabs').addClass('scrolling');
    }
    if(pos < $('.tabs_home_cont').offset().top && $('.homepage_tabs').hasClass('scrolling') && $(window).width() > 767) {
        $('.homepage_tabs').removeClass('scrolling');
    }
    $('.homepage_tabs a').each(function(){
        var $this = $(this), element = $('.tab_box').eq($this.parent().index()), extra = $('.homepage_tabs').height();
        if(element.length && element.css('display') !== 'none' && element.position().top - extra <= pos && element.position().top + element.height() > pos) {
            $('.homepage_tabs a').removeClass('active');
            $this.addClass('active');
        }
    });
}


jQuery(document).ready(function($) {
    var $frm = $('.user_info').html();
    //console.log($frm);  
    $('.formfields .formarea').append($frm); 

    $('.user_row .field input').bind('input', function() {  /* bind for main form */
        var attr = $(this).attr('name');
        $('.basket').find('input[name="'+attr+'"]').val($(this).val());
    });

    $('.basket input').bind('input', function() {  /* bind for sticky form */
        var attr = $(this).attr('name');
        $('.user_row').find('input[name="'+attr+'"]').val($(this).val());
    }); 

    /*$('.checkout-btn').click(function(){
        var msg = $('.system_msg').html();
        console.log(msg); 
        if(msg){
            $('.formfields').append(msg); 
        }
    });*/


});

jQuery(window).on('scroll',function(){
    $ = jQuery;
    var $err = $('.user_info .system_msg').html() ; 
    //console.log($err);
    if( typeof $err != 'undefined' ){
        $('.sticky-top .errorsfields').html("<p class='system_msg'>" + $err + "</p>");
    }
   


});
