/**
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
* We offer the best and most useful modules PrestaShop and modifications for your online store.
*
* @category  PrestaShop Module
* @author    knowband.com <support@knowband.com>
* @copyright 2017 Knowband
* @license   see file: LICENSE.txt
*/

$(document).ready(function(){
    
  $('#loginizer_configuration_form table tr td').each(function () {
        var data = $(this).find('.icon-question-sign').prop('attributes');
        $(this).find('.icon-question-sign').remove();
        var this_cus = this;
        for (var ab in data) {
            if (data[ab].name == 'data-toggle' || data[ab].name == 'data-placement' || data[ab].name == 'data-original-title') {
                $(this_cus).find('span').attr(data[ab].name, data[ab].value);
            }
        }
        $(this_cus).find('span').tooltip();
    });
});

$(function() {
    $('#sortable > li').tsort({
        attr:'data-index'
    });
    $('#sortable').sortable({
        placeholder: "portlet-placeholder",
        distance: 5,
        opacity: 0.8,
        update: function(e, ui) {
            $('#sortable').find('li').each(function(i, el) {
                $(this).attr('data-index', $(el).index());
                $(this).find('input').val($(el).index());
            });
        }
    });
    $("#sortable").disableSelection();
});

var check_set = 0;
function submitform(val)
{
    if (!veloValidateConfigForms()) {
        return false;
    }
    $("#submit_form").val(val);
    document.loginizer_form.submit();
}

function veloValidateConfigForms()
{
    var is_error = false;
    var general_setting_error = false;
    var stats_error = false;
    var facebook_error = false;
    var google_error = false;
    var live_error = false;
    var linkedin_error = false;
    var twitter_error = false;
    var yahoo_error = false;
    var amazon_error = false;
    var paypal_error = false;
    var foursquare_error = false;
    var github_error = false;
    var disqus_error = false;
    var vk_error = false;
    var wordpress_error = false;
    var dropbox_error = false;
    $('input, textarea').removeClass('kb_error_field');
    $('input, textarea').removeClass('mail_kb_error_field');
    $('.kb_error_message').remove();
    $('.mail_kb_error_message').remove();

    /*Knowband validation start*/
    if (!$('input[name="velocity_social[show_popup]"]:checked').val()) {
        var redirect_url_err = velovalidation.checkUrl($('input[name="velocity_social[redirect_url]"]'));
        if (redirect_url_err != true)
        {
            is_error = true;
            general_setting_error = true;
            $('input[name="velocity_social[redirect_url]"]').addClass('kb_error_field');
            $('input[name="velocity_social[redirect_url]"]').after('<span class="kb_error_message">' + redirect_url_err + '</span>');
        }
    }
    /*Knowband validation end*/

    /*Knowband validation start*/
    var css_tags_err = velovalidation.checkHtmlTags($('textarea[name="velocity_social[custom_css]"]'));
    if (css_tags_err != true)
    {
        is_error = true;
        general_setting_error = true;
        $('textarea[name="velocity_social[custom_css]"]').addClass('kb_error_field');
        $('textarea[name="velocity_social[custom_css]"]').after('<span class="kb_error_message">' + css_tags_err + '</span>');
    }
    /*Knowband validation end*/

    if ($('input[name="velocity_social[facebook][enable]"]:checked').val()) {
        /*Knowband validation start*/
        var fb_app_mandatory_err = velovalidation.checkMandatory($('input[name="velocity_social[facebook][app_id]"]'));
        if (fb_app_mandatory_err != true)
        {
            is_error = true;
            facebook_error = true;
            $('input[name="velocity_social[facebook][app_id]"]').addClass('kb_error_field');
            $('input[name="velocity_social[facebook][app_id]"]').parent().append('<span class="kb_error_message">' + fb_app_mandatory_err + '</span>');
        }
        /*Knowband validation end*/

        /*Knowband validation start*/
        var fb_secret_mandatory_err = velovalidation.checkMandatory($('input[name="velocity_social[facebook][app_secret]"]'));
        if (fb_secret_mandatory_err != true)
        {
            is_error = true;
            facebook_error = true;
            $('input[name="velocity_social[facebook][app_secret]"]').addClass('kb_error_field');
            $('input[name="velocity_social[facebook][app_secret]"]').parent().append('<span class="kb_error_message">' + fb_secret_mandatory_err + '</span>');
        }
        /*Knowband validation end*/
    } else {
        /*Knowband validation start*/
        var fb_app_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[facebook][app_id]"]'));
        if (fb_app_tags_err != true)
        {
            is_error = true;
            facebook_error = true;
            $('input[name="velocity_social[facebook][app_id]"]').addClass('kb_error_field');
            $('input[name="velocity_social[facebook][app_id]"]').after('<span class="kb_error_message">' + fb_app_tags_err + '</span>');
        }
        /*Knowband validation end*/

        /*Knowband validation start*/
        var fb_secret_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[facebook][app_secret]"]'));
        if (fb_secret_tags_err != true)
        {
            is_error = true;
            facebook_error = true;
            $('input[name="velocity_social[facebook][app_secret]"]').addClass('kb_error_field');
            $('input[name="velocity_social[facebook][app_secret]"]').after('<span class="kb_error_message">' + fb_secret_tags_err + '</span>');
        }
        /*Knowband validation end*/
    }

    /*Knowband validation start*/
    var fb_mailchimp_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[facebook][mailchimp_api]"]'));
    if (fb_mailchimp_tags_err != true)
    {
        is_error = true;
        facebook_error = true;
        $('input[name="velocity_social[facebook][mailchimp_api]"]').addClass('mail_kb_error_field');
        $('input[name="velocity_social[facebook][mailchimp_api]"]').parent().parent().append('<span class="mail_kb_error_message">' + fb_mailchimp_tags_err + '</span>');
    }
    /*Knowband validation end*/

    if ($('input[name="velocity_social[gplus][enable]"]:checked').val()) {
        /*Knowband validation start*/
        var google_app_mandatory_err = velovalidation.checkMandatory($('input[name="velocity_social[gplus][client_id]"]'));
        if (google_app_mandatory_err != true)
        {
            is_error = true;
            google_error = true;
            $('input[name="velocity_social[gplus][client_id]"]').addClass('kb_error_field');
            $('input[name="velocity_social[gplus][client_id]"]').parent().append('<span class="kb_error_message">' + google_app_mandatory_err + '</span>');
        }
        /*Knowband validation end*/

        /*Knowband validation start*/
        var google_secret_mandatory_err = velovalidation.checkMandatory($('input[name="velocity_social[gplus][client_secret]"]'));
        if (google_secret_mandatory_err != true)
        {
            is_error = true;
            google_error = true;
            $('input[name="velocity_social[gplus][client_secret]"]').addClass('kb_error_field');
            $('input[name="velocity_social[gplus][client_secret]"]').parent().append('<span class="kb_error_message">' + google_secret_mandatory_err + '</span>');
        }
        /*Knowband validation end*/
    } else {
        /*Knowband validation start*/
        var google_app_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[gplus][client_id]"]'));
        if (google_app_tags_err != true)
        {
            is_error = true;
            google_error = true;
            $('input[name="velocity_social[gplus][client_id]"]').addClass('kb_error_field');
            $('input[name="velocity_social[gplus][client_id]"]').after('<span class="kb_error_message">' + google_app_tags_err + '</span>');
        }
        /*Knowband validation end*/

        /*Knowband validation start*/
        var google_secret_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[gplus][client_secret]"]'));
        if (google_secret_tags_err != true)
        {
            is_error = true;
            google_error = true;
            $('input[name="velocity_social[gplus][client_secret]"]').addClass('kb_error_field');
            $('input[name="velocity_social[gplus][client_secret]"]').after('<span class="kb_error_message">' + google_secret_tags_err + '</span>');
        }
        /*Knowband validation end*/
    }
    // changes by rishabh jain
    if ($('input[name="velocity_social[instagram][enable]"]:checked').val()) {
        /*Knowband validation start*/
        var instagram_app_mandatory_err = velovalidation.checkMandatory($('input[name="velocity_social[instagram][client_id]"]'));
        if (instagram_app_mandatory_err != true)
        {
            is_error = true;
            instagram_error = true;
            $('input[name="velocity_social[instagram][client_id]"]').addClass('kb_error_field');
            $('input[name="velocity_social[instagram][client_id]"]').parent().append('<span class="kb_error_message">' + instagram_app_mandatory_err + '</span>');
        }
        /*Knowband validation end*/

        /*Knowband validation start*/
        var instagram_secret_mandatory_err = velovalidation.checkMandatory($('input[name="velocity_social[instagram][client_secret]"]'));
        if (instagram_secret_mandatory_err != true)
        {
            is_error = true;
            instagram_error = true;
            $('input[name="velocity_social[instagram][client_secret]"]').addClass('kb_error_field');
            $('input[name="velocity_social[instagram][client_secret]"]').parent().append('<span class="kb_error_message">' + instagram_secret_mandatory_err + '</span>');
        }
        /*Knowband validation end*/
    } else {
        /*Knowband validation start*/
        var instagram_app_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[instagram][client_id]"]'));
        if (instagram_app_tags_err != true)
        {
            is_error = true;
            google_error = true;
            $('input[name="velocity_social[instagram][client_id]"]').addClass('kb_error_field');
            $('input[name="velocity_social[instagram][client_id]"]').after('<span class="kb_error_message">' + instagram_app_tags_err + '</span>');
        }
        /*Knowband validation end*/

        /*Knowband validation start*/
        var instagram_secret_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[instagram][client_secret]"]'));
        if (instagram_secret_tags_err != true)
        {
            is_error = true;
            instagram_error = true;
            $('input[name="velocity_social[instagram][client_secret]"]').addClass('kb_error_field');
            $('input[name="velocity_social[instagram][client_secret]"]').after('<span class="kb_error_message">' + instagram_secret_tags_err + '</span>');
        }
        /*Knowband validation end*/
    }
    // changes over

    /*Knowband validation start*/
    var google_mailchimp_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[google][mailchimp_api]"]'));
    if (google_mailchimp_tags_err != true)
    {
        is_error = true;
        google_error = true;
        $('input[name="velocity_social[google][mailchimp_api]"]').addClass('mail_kb_error_field');
        $('input[name="velocity_social[google][mailchimp_api]"]').parent().parent().append('<span class="mail_kb_error_message">' + google_mailchimp_tags_err + '</span>');
    }
    /*Knowband validation end*/

    if ($('input[name="velocity_social[live][enable]"]:checked').val()) {
        /*Knowband validation start*/
        var live_app_mandatory_err = velovalidation.checkMandatory($('input[name="velocity_social[live][client_id]"]'));
        if (live_app_mandatory_err != true)
        {
            is_error = true;
            live_error = true;
            $('input[name="velocity_social[live][client_id]"]').addClass('kb_error_field');
            $('input[name="velocity_social[live][client_id]"]').parent().append('<span class="kb_error_message">' + live_app_mandatory_err + '</span>');
        }
        /*Knowband validation end*/

        /*Knowband validation start*/
        var live_secret_mandatory_err = velovalidation.checkMandatory($('input[name="velocity_social[live][client_secret]"]'));
        if (live_secret_mandatory_err != true)
        {
            is_error = true;
            live_error = true;
            $('input[name="velocity_social[live][client_secret]"]').addClass('kb_error_field');
            $('input[name="velocity_social[live][client_secret]"]').parent().append('<span class="kb_error_message">' + live_secret_mandatory_err + '</span>');
        }
        /*Knowband validation end*/
    } else {
        /*Knowband validation start*/
        var live_app_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[live][client_id]"]'));
        if (live_app_tags_err != true)
        {
            is_error = true;
            live_error = true;
            $('input[name="velocity_social[live][client_id]"]').addClass('kb_error_field');
            $('input[name="velocity_social[live][client_id]"]').after('<span class="kb_error_message">' + live_app_tags_err + '</span>');
        }
        /*Knowband validation end*/

        /*Knowband validation start*/
        var live_secret_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[live][client_secret]"]'));
        if (live_secret_tags_err != true)
        {
            is_error = true;
            live_error = true;
            $('input[name="velocity_social[live][client_secret]"]').addClass('kb_error_field');
            $('input[name="velocity_social[live][client_secret]"]').after('<span class="kb_error_message">' + live_secret_tags_err + '</span>');
        }
        /*Knowband validation end*/
    }

    /*Knowband validation start*/
    var live_mailchimp_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[live][mailchimp_api]"]'));
    if (live_mailchimp_tags_err != true)
    {
        is_error = true;
        live_error = true;
        $('input[name="velocity_social[live][mailchimp_api]"]').addClass('mail_kb_error_field');
        $('input[name="velocity_social[live][mailchimp_api]"]').parent().parent().append('<span class="mail_kb_error_message">' + live_mailchimp_tags_err + '</span>');
    }
    /*Knowband validation end*/

    if ($('input[name="velocity_social[linked][enable]"]:checked').val()) {
        /*Knowband validation start*/
        var linked_app_mandatory_err = velovalidation.checkMandatory($('input[name="velocity_social[linked][client_id]"]'));
        if (linked_app_mandatory_err != true)
        {
            is_error = true;
            linkedin_error = true;
            $('input[name="velocity_social[linked][client_id]"]').addClass('kb_error_field');
            $('input[name="velocity_social[linked][client_id]"]').parent().append('<span class="kb_error_message">' + linked_app_mandatory_err + '</span>');
        }
        /*Knowband validation end*/

        /*Knowband validation start*/
        var linked_secret_mandatory_err = velovalidation.checkMandatory($('input[name="velocity_social[linked][client_secret]"]'));
        if (linked_secret_mandatory_err != true)
        {
            is_error = true;
            linkedin_error = true;
            $('input[name="velocity_social[linked][client_secret]"]').addClass('kb_error_field');
            $('input[name="velocity_social[linked][client_secret]"]').parent().append('<span class="kb_error_message">' + linked_secret_mandatory_err + '</span>');
        }
        /*Knowband validation end*/
    } else {
        /*Knowband validation start*/
        var linked_app_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[linked][client_id]"]'));
        if (linked_app_tags_err != true)
        {
            is_error = true;
            linkedin_error = true;
            $('input[name="velocity_social[linked][client_id]"]').addClass('kb_error_field');
            $('input[name="velocity_social[linked][client_id]"]').after('<span class="kb_error_message">' + linked_app_tags_err + '</span>');
        }
        /*Knowband validation end*/

        /*Knowband validation start*/
        var linked_secret_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[linked][client_secret]"]'));
        if (linked_secret_tags_err != true)
        {
            is_error = true;
            linkedin_error = true;
            $('input[name="velocity_social[linked][client_secret]"]').addClass('kb_error_field');
            $('input[name="velocity_social[linked][client_secret]"]').after('<span class="kb_error_message">' + linked_secret_tags_err + '</span>');
        }
        /*Knowband validation end*/
    }

    /*Knowband validation start*/
    var linked_mailchimp_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[linkedin][mailchimp_api]"]'));
    if (linked_mailchimp_tags_err != true)
    {
        is_error = true;
        linkedin_error = true;
        $('input[name="velocity_social[linkedin][mailchimp_api]"]').addClass('mail_kb_error_field');
        $('input[name="velocity_social[linkedin][mailchimp_api]"]').parent().parent().append('<span class="mail_kb_error_message">' + linked_mailchimp_tags_err + '</span>');
    }
    /*Knowband validation end*/

    if ($('input[name="velocity_social[twitter][enable]"]:checked').val()) {
        /*Knowband validation start*/
        var twitter_app_mandatory_err = velovalidation.checkMandatory($('input[name="velocity_social[twitter][client_id]"]'));
        if (twitter_app_mandatory_err != true)
        {
            is_error = true;
            twitter_error = true;
            $('input[name="velocity_social[twitter][client_id]"]').addClass('kb_error_field');
            $('input[name="velocity_social[twitter][client_id]"]').parent().append('<span class="kb_error_message">' + twitter_app_mandatory_err + '</span>');
        }
        /*Knowband validation end*/

        /*Knowband validation start*/
        var twitter_secret_mandatory_err = velovalidation.checkMandatory($('input[name="velocity_social[twitter][client_secret]"]'));
        if (twitter_secret_mandatory_err != true)
        {
            is_error = true;
            twitter_error = true;
            $('input[name="velocity_social[twitter][client_secret]"]').addClass('kb_error_field');
            $('input[name="velocity_social[twitter][client_secret]"]').parent().append('<span class="kb_error_message">' + twitter_secret_mandatory_err + '</span>');
        }
        /*Knowband validation end*/
    } else {
        /*Knowband validation start*/
        var twitter_app_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[twitter][client_id]"]'));
        if (twitter_app_tags_err != true)
        {
            is_error = true;
            twitter_error = true;
            $('input[name="velocity_social[twitter][client_id]"]').addClass('kb_error_field');
            $('input[name="velocity_social[twitter][client_id]"]').after('<span class="kb_error_message">' + twitter_app_tags_err + '</span>');
        }
        /*Knowband validation end*/

        /*Knowband validation start*/
        var twitter_secret_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[twitter][client_secret]"]'));
        if (twitter_secret_tags_err != true)
        {
            is_error = true;
            twitter_error = true;
            $('input[name="velocity_social[twitter][client_secret]"]').addClass('kb_error_field');
            $('input[name="velocity_social[twitter][client_secret]"]').after('<span class="kb_error_message">' + twitter_secret_tags_err + '</span>');
        }
        /*Knowband validation end*/
    }

    /*Knowband validation start*/
    var twitter_mailchimp_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[twitter][mailchimp_api]"]'));
    if (twitter_mailchimp_tags_err != true)
    {
        is_error = true;
        twitter_error = true;
        $('input[name="velocity_social[twitter][mailchimp_api]"]').addClass('mail_kb_error_field');
        $('input[name="velocity_social[twitter][mailchimp_api]"]').parent().parent().append('<span class="mail_kb_error_message">' + twitter_mailchimp_tags_err + '</span>');
    }
    /*Knowband validation end*/

    if ($('input[name="velocity_social[yahoo][enable]"]:checked').val()) {
        /*Knowband validation start*/
        var yahoo_app_mandatory_err = velovalidation.checkMandatory($('input[name="velocity_social[yahoo][consumer_key]"]'));
        if (yahoo_app_mandatory_err != true)
        {
            is_error = true;
            yahoo_error = true;
            $('input[name="velocity_social[yahoo][consumer_key]"]').addClass('kb_error_field');
            $('input[name="velocity_social[yahoo][consumer_key]"]').parent().append('<span class="kb_error_message">' + yahoo_app_mandatory_err + '</span>');
        }
        /*Knowband validation end*/

        /*Knowband validation start*/
        var yahoo_secret_mandatory_err = velovalidation.checkMandatory($('input[name="velocity_social[yahoo][consumer_secret]"]'));
        if (yahoo_secret_mandatory_err != true)
        {
            is_error = true;
            yahoo_error = true;
            $('input[name="velocity_social[yahoo][consumer_secret]"]').addClass('kb_error_field');
            $('input[name="velocity_social[yahoo][consumer_secret]"]').parent().append('<span class="kb_error_message">' + yahoo_secret_mandatory_err + '</span>');
        }
        /*Knowband validation end*/
    } else {
        /*Knowband validation start*/
        var yahoo_app_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[yahoo][consumer_key]"]'));
        if (yahoo_app_tags_err != true)
        {
            is_error = true;
            yahoo_error = true;
            $('input[name="velocity_social[yahoo][consumer_key]"]').addClass('kb_error_field');
            $('input[name="velocity_social[yahoo][consumer_key]"]').after('<span class="kb_error_message">' + yahoo_app_tags_err + '</span>');
        }
        /*Knowband validation end*/

        /*Knowband validation start*/
        var yahoo_secret_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[yahoo][consumer_secret]"]'));
        if (yahoo_secret_tags_err != true)
        {
            is_error = true;
            yahoo_error = true;
            $('input[name="velocity_social[yahoo][consumer_secret]"]').addClass('kb_error_field');
            $('input[name="velocity_social[yahoo][consumer_secret]"]').after('<span class="kb_error_message">' + yahoo_secret_tags_err + '</span>');
        }
        /*Knowband validation end*/
    }

    /*Knowband validation start*/
    var yahoo_mailchimp_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[yahoo][mailchimp_api]"]'));
    if (yahoo_mailchimp_tags_err != true)
    {
        is_error = true;
        yahoo_error = true;
        $('input[name="velocity_social[yahoo][mailchimp_api]"]').addClass('mail_kb_error_field');
        $('input[name="velocity_social[yahoo][mailchimp_api]"]').parent().parent().append('<span class="mail_kb_error_message">' + yahoo_mailchimp_tags_err + '</span>');
    }
    /*Knowband validation end*/

    if ($('input[name="velocity_social[amazon][enable]"]:checked').val()) {
        /*Knowband validation start*/
        var amazon_app_mandatory_err = velovalidation.checkMandatory($('input[name="velocity_social[amazon][client_id]"]'));
        if (amazon_app_mandatory_err != true)
        {
            is_error = true;
            amazon_error = true;
            $('input[name="velocity_social[amazon][client_id]"]').addClass('kb_error_field');
            $('input[name="velocity_social[amazon][client_id]"]').parent().append('<span class="kb_error_message">' + amazon_app_mandatory_err + '</span>');
        }
        /*Knowband validation end*/

        /*Knowband validation start*/
        var amazon_secret_mandatory_err = velovalidation.checkMandatory($('input[name="velocity_social[amazon][client_secret]"]'));
        if (amazon_secret_mandatory_err != true)
        {
            is_error = true;
            amazon_error = true;
            $('input[name="velocity_social[amazon][client_secret]"]').addClass('kb_error_field');
            $('input[name="velocity_social[amazon][client_secret]"]').parent().append('<span class="kb_error_message">' + amazon_secret_mandatory_err + '</span>');
        }
        /*Knowband validation end*/
    } else {
        /*Knowband validation start*/
        var amazon_app_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[amazon][client_id]"]'));
        if (amazon_app_tags_err != true)
        {
            is_error = true;
            amazon_error = true;
            $('input[name="velocity_social[amazon][client_id]"]').addClass('kb_error_field');
            $('input[name="velocity_social[amazon][client_id]"]').after('<span class="kb_error_message">' + amazon_app_tags_err + '</span>');
        }
        /*Knowband validation end*/

        /*Knowband validation start*/
        var amazon_secret_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[amazon][client_secret]"]'));
        if (amazon_secret_tags_err != true)
        {
            is_error = true;
            amazon_error = true;
            $('input[name="velocity_social[amazon][client_secret]"]').addClass('kb_error_field');
            $('input[name="velocity_social[amazon][client_secret]"]').after('<span class="kb_error_message">' + amazon_secret_tags_err + '</span>');
        }
        /*Knowband validation end*/
    }

    /*Knowband validation start*/
    var amazon_mailchimp_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[amazon][mailchimp_api]"]'));
    if (amazon_mailchimp_tags_err != true)
    {
        is_error = true;
        amazon_error = true;
        $('input[name="velocity_social[amazon][mailchimp_api]"]').addClass('mail_kb_error_field');
        $('input[name="velocity_social[amazon][mailchimp_api]"]').parent().parent().append('<span class="mail_kb_error_message">' + amazon_mailchimp_tags_err + '</span>');
    }
    /*Knowband validation end*/

    if ($('input[name="velocity_social[pay][enable]"]:checked').val()) {
        /*Knowband validation start*/
        var paypal_app_mandatory_err = velovalidation.checkMandatory($('input[name="velocity_social[pay][client_id]"]'));
        if (paypal_app_mandatory_err != true)
        {
            is_error = true;
            paypal_error = true;
            $('input[name="velocity_social[pay][client_id]"]').addClass('kb_error_field');
            $('input[name="velocity_social[pay][client_id]"]').parent().append('<span class="kb_error_message">' + paypal_app_mandatory_err + '</span>');
        }
        /*Knowband validation end*/

        /*Knowband validation start*/
        var paypal_secret_mandatory_err = velovalidation.checkMandatory($('input[name="velocity_social[pay][client_secret]"]'));
        if (paypal_secret_mandatory_err != true)
        {
            is_error = true;
            paypal_error = true;
            $('input[name="velocity_social[pay][client_secret]"]').addClass('kb_error_field');
            $('input[name="velocity_social[pay][client_secret]"]').parent().append('<span class="kb_error_message">' + paypal_secret_mandatory_err + '</span>');
        }
        /*Knowband validation end*/
    } else {
        /*Knowband validation start*/
        var paypal_app_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[pay][client_id]"]'));
        if (paypal_app_tags_err != true)
        {
            is_error = true;
            paypal_error = true;
            $('input[name="velocity_social[pay][client_id]"]').addClass('kb_error_field');
            $('input[name="velocity_social[pay][client_id]"]').after('<span class="kb_error_message">' + paypal_app_tags_err + '</span>');
        }
        /*Knowband validation end*/

        /*Knowband validation start*/
        var paypal_secret_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[pay][client_secret]"]'));
        if (paypal_secret_tags_err != true)
        {
            is_error = true;
            paypal_error = true;
            $('input[name="velocity_social[pay][client_secret]"]').addClass('kb_error_field');
            $('input[name="velocity_social[pay][client_secret]"]').after('<span class="kb_error_message">' + paypal_secret_tags_err + '</span>');
        }
        /*Knowband validation end*/
    }

    /*Knowband validation start*/
    var paypal_mailchimp_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[pay][mailchimp_api]"]'));
    if (paypal_mailchimp_tags_err != true)
    {
        is_error = true;
        paypal_error = true;
        $('input[name="velocity_social[pay][mailchimp_api]"]').addClass('mail_kb_error_field');
        $('input[name="velocity_social[pay][mailchimp_api]"]').parent().parent().append('<span class="mail_kb_error_message">' + paypal_mailchimp_tags_err + '</span>');
    }
    /*Knowband validation end*/

    if ($('input[name="velocity_social[foursquare][enable]"]:checked').val()) {
        /*Knowband validation start*/
        var foursquare_app_mandatory_err = velovalidation.checkMandatory($('input[name="velocity_social[foursquare][client_id]"]'));
        if (foursquare_app_mandatory_err != true)
        {
            is_error = true;
            foursquare_error = true;
            $('input[name="velocity_social[foursquare][client_id]"]').addClass('kb_error_field');
            $('input[name="velocity_social[foursquare][client_id]"]').parent().append('<span class="kb_error_message">' + foursquare_app_mandatory_err + '</span>');
        }
        /*Knowband validation end*/

        /*Knowband validation start*/
        var foursquare_secret_mandatory_err = velovalidation.checkMandatory($('input[name="velocity_social[foursquare][client_secret]"]'));
        if (foursquare_secret_mandatory_err != true)
        {
            is_error = true;
            foursquare_error = true;
            $('input[name="velocity_social[foursquare][client_secret]"]').addClass('kb_error_field');
            $('input[name="velocity_social[foursquare][client_secret]"]').parent().append('<span class="kb_error_message">' + foursquare_secret_mandatory_err + '</span>');
        }
        /*Knowband validation end*/
    } else {
        /*Knowband validation start*/
        var foursquare_app_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[foursquare][client_id]"]'));
        if (foursquare_app_tags_err != true)
        {
            is_error = true;
            foursquare_error = true;
            $('input[name="velocity_social[foursquare][client_id]"]').addClass('kb_error_field');
            $('input[name="velocity_social[foursquare][client_id]"]').after('<span class="kb_error_message">' + foursquare_app_tags_err + '</span>');
        }
        /*Knowband validation end*/

        /*Knowband validation start*/
        var foursquare_secret_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[foursquare][client_secret]"]'));
        if (foursquare_secret_tags_err != true)
        {
            is_error = true;
            foursquare_error = true;
            $('input[name="velocity_social[foursquare][client_secret]"]').addClass('kb_error_field');
            $('input[name="velocity_social[foursquare][client_secret]"]').after('<span class="kb_error_message">' + foursquare_secret_tags_err + '</span>');
        }
        /*Knowband validation end*/
    }

    /*Knowband validation start*/
    var foursquare_mailchimp_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[foursquare][mailchimp_api]"]'));
    if (foursquare_mailchimp_tags_err != true)
    {
        is_error = true;
        foursquare_error = true;
        $('input[name="velocity_social[foursquare][mailchimp_api]"]').addClass('mail_kb_error_field');
        $('input[name="velocity_social[foursquare][mailchimp_api]"]').parent().parent().append('<span class="mail_kb_error_message">' + foursquare_mailchimp_tags_err + '</span>');
    }
    /*Knowband validation end*/

    if ($('input[name="velocity_social[github][enable]"]:checked').val()) {
        /*Knowband validation start*/
        var github_app_mandatory_err = velovalidation.checkMandatory($('input[name="velocity_social[github][client_id]"]'));
        if (github_app_mandatory_err != true)
        {
            is_error = true;
            github_error = true;
            $('input[name="velocity_social[github][client_id]"]').addClass('kb_error_field');
            $('input[name="velocity_social[github][client_id]"]').parent().append('<span class="kb_error_message">' + github_app_mandatory_err + '</span>');
        }
        /*Knowband validation end*/

        /*Knowband validation start*/
        var github_secret_mandatory_err = velovalidation.checkMandatory($('input[name="velocity_social[github][client_secret]"]'));
        if (github_secret_mandatory_err != true)
        {
            is_error = true;
            github_error = true;
            $('input[name="velocity_social[github][client_secret]"]').addClass('kb_error_field');
            $('input[name="velocity_social[github][client_secret]"]').parent().append('<span class="kb_error_message">' + github_secret_mandatory_err + '</span>');
        }
        /*Knowband validation end*/
    } else {
        /*Knowband validation start*/
        var github_app_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[github][client_id]"]'));
        if (github_app_tags_err != true)
        {
            is_error = true;
            github_error = true;
            $('input[name="velocity_social[github][client_id]"]').addClass('kb_error_field');
            $('input[name="velocity_social[github][client_id]"]').after('<span class="kb_error_message">' + github_app_tags_err + '</span>');
        }
        /*Knowband validation end*/

        /*Knowband validation start*/
        var github_secret_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[github][client_secret]"]'));
        if (github_secret_tags_err != true)
        {
            is_error = true;
            github_error = true;
            $('input[name="velocity_social[github][client_secret]"]').addClass('kb_error_field');
            $('input[name="velocity_social[github][client_secret]"]').after('<span class="kb_error_message">' + github_secret_tags_err + '</span>');
        }
        /*Knowband validation end*/
    }

    /*Knowband validation start*/
    var github_mailchimp_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[github][mailchimp_api]"]'));
    if (github_mailchimp_tags_err != true)
    {
        is_error = true;
        github_error = true;
        $('input[name="velocity_social[github][mailchimp_api]"]').addClass('mail_kb_error_field');
        $('input[name="velocity_social[github][mailchimp_api]"]').parent().parent().append('<span class="mail_kb_error_message">' + github_mailchimp_tags_err + '</span>');
    }
    /*Knowband validation end*/

    if ($('input[name="velocity_social[disqus][enable]"]:checked').val()) {
        /*Knowband validation start*/
        var disqus_app_mandatory_err = velovalidation.checkMandatory($('input[name="velocity_social[disqus][client_id]"]'));
        if (disqus_app_mandatory_err != true)
        {
            is_error = true;
            disqus_error = true;
            $('input[name="velocity_social[disqus][client_id]"]').addClass('kb_error_field');
            $('input[name="velocity_social[disqus][client_id]"]').parent().append('<span class="kb_error_message">' + disqus_app_mandatory_err + '</span>');
        }
        /*Knowband validation end*/

        /*Knowband validation start*/
        var disqus_secret_mandatory_err = velovalidation.checkMandatory($('input[name="velocity_social[disqus][client_secret]"]'));
        if (disqus_secret_mandatory_err != true)
        {
            is_error = true;
            disqus_error = true;
            $('input[name="velocity_social[disqus][client_secret]"]').addClass('kb_error_field');
            $('input[name="velocity_social[disqus][client_secret]"]').parent().append('<span class="kb_error_message">' + disqus_secret_mandatory_err + '</span>');
        }
        /*Knowband validation end*/
    } else {
        /*Knowband validation start*/
        var disqus_app_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[disqus][client_id]"]'));
        if (disqus_app_tags_err != true)
        {
            is_error = true;
            disqus_error = true;
            $('input[name="velocity_social[disqus][client_id]"]').addClass('kb_error_field');
            $('input[name="velocity_social[disqus][client_id]"]').after('<span class="kb_error_message">' + disqus_app_tags_err + '</span>');
        }
        /*Knowband validation end*/

        /*Knowband validation start*/
        var disqus_secret_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[disqus][client_secret]"]'));
        if (disqus_secret_tags_err != true)
        {
            is_error = true;
            disqus_error = true;
            $('input[name="velocity_social[disqus][client_secret]"]').addClass('kb_error_field');
            $('input[name="velocity_social[disqus][client_secret]"]').after('<span class="kb_error_message">' + disqus_secret_tags_err + '</span>');
        }
        /*Knowband validation end*/
    }

    /*Knowband validation start*/
    var disqus_mailchimp_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[disqus][mailchimp_api]"]'));
    if (disqus_mailchimp_tags_err != true)
    {
        is_error = true;
        disqus_error = true;
        $('input[name="velocity_social[disqus][mailchimp_api]"]').addClass('mail_kb_error_field');
        $('input[name="velocity_social[disqus][mailchimp_api]"]').parent().parent().append('<span class="mail_kb_error_message">' + disqus_mailchimp_tags_err + '</span>');
    }
    /*Knowband validation end*/

    if ($('input[name="velocity_social[vk][enable]"]:checked').val()) {
        /*Knowband validation start*/
        var vk_app_mandatory_err = velovalidation.checkMandatory($('input[name="velocity_social[vk][client_id]"]'));
        if (vk_app_mandatory_err != true)
        {
            is_error = true;
            vk_error = true;
            $('input[name="velocity_social[vk][client_id]"]').addClass('kb_error_field');
            $('input[name="velocity_social[vk][client_id]"]').parent().append('<span class="kb_error_message">' + vk_app_mandatory_err + '</span>');
        }
        /*Knowband validation end*/

        /*Knowband validation start*/
        var vk_secret_mandatory_err = velovalidation.checkMandatory($('input[name="velocity_social[vk][client_secret]"]'));
        if (vk_secret_mandatory_err != true)
        {
            is_error = true;
            vk_error = true;
            $('input[name="velocity_social[vk][client_secret]"]').addClass('kb_error_field');
            $('input[name="velocity_social[vk][client_secret]"]').parent().append('<span class="kb_error_message">' + vk_secret_mandatory_err + '</span>');
        }
        /*Knowband validation end*/
    } else {
        /*Knowband validation start*/
        var vk_app_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[vk][client_id]"]'));
        if (vk_app_tags_err != true)
        {
            is_error = true;
            vk_error = true;
            $('input[name="velocity_social[vk][client_id]"]').addClass('kb_error_field');
            $('input[name="velocity_social[vk][client_id]"]').after('<span class="kb_error_message">' + vk_app_tags_err + '</span>');
        }
        /*Knowband validation end*/

        /*Knowband validation start*/
        var vk_secret_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[vk][client_secret]"]'));
        if (vk_secret_tags_err != true)
        {
            is_error = true;
            vk_error = true;
            $('input[name="velocity_social[vk][client_secret]"]').addClass('kb_error_field');
            $('input[name="velocity_social[vk][client_secret]"]').after('<span class="kb_error_message">' + vk_secret_tags_err + '</span>');
        }
        /*Knowband validation end*/
    }

    /*Knowband validation start*/
    var vk_mailchimp_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[vk][mailchimp_api]"]'));
    if (vk_mailchimp_tags_err != true)
    {
        is_error = true;
        vk_error = true;
        $('input[name="velocity_social[vk][mailchimp_api]"]').addClass('mail_kb_error_field');
        $('input[name="velocity_social[vk][mailchimp_api]"]').parent().parent().append('<span class="mail_kb_error_message">' + vk_mailchimp_tags_err + '</span>');
    }
    /*Knowband validation end*/

    if ($('input[name="velocity_social[wordpress][enable]"]:checked').val()) {
        /*Knowband validation start*/
        var wordpress_app_mandatory_err = velovalidation.checkMandatory($('input[name="velocity_social[wordpress][client_id]"]'));
        if (wordpress_app_mandatory_err != true)
        {
            is_error = true;
            wordpress_error = true;
            $('input[name="velocity_social[wordpress][client_id]"]').addClass('kb_error_field');
            $('input[name="velocity_social[wordpress][client_id]"]').parent().append('<span class="kb_error_message">' + wordpress_app_mandatory_err + '</span>');
        }
        /*Knowband validation end*/

        /*Knowband validation start*/
        var wordpress_secret_mandatory_err = velovalidation.checkMandatory($('input[name="velocity_social[wordpress][client_secret]"]'));
        if (wordpress_secret_mandatory_err != true)
        {
            is_error = true;
            wordpress_error = true;
            $('input[name="velocity_social[wordpress][client_secret]"]').addClass('kb_error_field');
            $('input[name="velocity_social[wordpress][client_secret]"]').parent().append('<span class="kb_error_message">' + wordpress_secret_mandatory_err + '</span>');
        }
        /*Knowband validation end*/
    } else {
        /*Knowband validation start*/
        var wordpress_app_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[wordpress][client_id]"]'));
        if (wordpress_app_tags_err != true)
        {
            is_error = true;
            wordpress_error = true;
            $('input[name="velocity_social[wordpress][client_id]"]').addClass('kb_error_field');
            $('input[name="velocity_social[wordpress][client_id]"]').after('<span class="kb_error_message">' + wordpress_app_tags_err + '</span>');
        }
        /*Knowband validation end*/

        /*Knowband validation start*/
        var wordpress_secret_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[wordpress][client_secret]"]'));
        if (wordpress_secret_tags_err != true)
        {
            is_error = true;
            wordpress_error = true;
            $('input[name="velocity_social[wordpress][client_secret]"]').addClass('kb_error_field');
            $('input[name="velocity_social[wordpress][client_secret]"]').after('<span class="kb_error_message">' + wordpress_secret_tags_err + '</span>');
        }
        /*Knowband validation end*/
    }

    /*Knowband validation start*/
    var wordpress_mailchimp_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[wordpress][mailchimp_api]"]'));
    if (wordpress_mailchimp_tags_err != true)
    {
        is_error = true;
        wordpress_error = true;
        $('input[name="velocity_social[wordpress][mailchimp_api]"]').addClass('mail_kb_error_field');
        $('input[name="velocity_social[wordpress][mailchimp_api]"]').parent().parent().append('<span class="mail_kb_error_message">' + wordpress_mailchimp_tags_err + '</span>');
    }
    /*Knowband validation end*/

    if ($('input[name="velocity_social[dropbox][enable]"]:checked').val()) {
        /*Knowband validation start*/
        var dropbox_app_mandatory_err = velovalidation.checkMandatory($('input[name="velocity_social[dropbox][client_id]"]'));
        if (dropbox_app_mandatory_err != true)
        {
            is_error = true;
            dropbox_error = true;
            $('input[name="velocity_social[dropbox][client_id]"]').addClass('kb_error_field');
            $('input[name="velocity_social[dropbox][client_id]"]').parent().append('<span class="kb_error_message">' + dropbox_app_mandatory_err + '</span>');
        }
        /*Knowband validation end*/

        /*Knowband validation start*/
        var dropbox_secret_mandatory_err = velovalidation.checkMandatory($('input[name="velocity_social[dropbox][client_secret]"]'));
        if (dropbox_secret_mandatory_err != true)
        {
            is_error = true;
            dropbox_error = true;
            $('input[name="velocity_social[dropbox][client_secret]"]').addClass('kb_error_field');
            $('input[name="velocity_social[dropbox][client_secret]"]').parent().append('<span class="kb_error_message">' + dropbox_secret_mandatory_err + '</span>');
        }
        /*Knowband validation end*/
    } else {
        /*Knowband validation start*/
        var dropbox_app_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[dropbox][client_id]"]'));
        if (dropbox_app_tags_err != true)
        {
            is_error = true;
            dropbox_error = true;
            $('input[name="velocity_social[dropbox][client_id]"]').addClass('kb_error_field');
            $('input[name="velocity_social[dropbox][client_id]"]').after('<span class="kb_error_message">' + dropbox_app_tags_err + '</span>');
        }
        /*Knowband validation end*/

        /*Knowband validation start*/
        var dropbox_secret_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[dropbox][client_secret]"]'));
        if (dropbox_secret_tags_err != true)
        {
            is_error = true;
            dropbox_error = true;
            $('input[name="velocity_social[dropbox][client_secret]"]').addClass('kb_error_field');
            $('input[name="velocity_social[dropbox][client_secret]"]').after('<span class="kb_error_message">' + dropbox_secret_tags_err + '</span>');
        }
        /*Knowband validation end*/
    }

    /*Knowband validation start*/
    var dropbox_mailchimp_tags_err = velovalidation.checkHtmlTags($('input[name="velocity_social[dropbox][mailchimp_api]"]'));
    if (dropbox_mailchimp_tags_err != true)
    {
        is_error = true;
        dropbox_error = true;
        $('input[name="velocity_social[dropbox][mailchimp_api]"]').addClass('mail_kb_error_field');
        $('input[name="velocity_social[dropbox][mailchimp_api]"]').parent().parent().append('<span class="mail_kb_error_message">' + dropbox_mailchimp_tags_err + '</span>');
    }
    /*Knowband validation end*/

    if (general_setting_error == true) {
        $('#general_settings_tab span').addClass('red_colored_tab');
    } else {
        $('#general_settings_tab span').removeClass('red_colored_tab');
    }

    if (facebook_error == true) {
        $('#facebook_tab span').addClass('red_colored_tab');
    } else {
        $('#facebook_tab span').removeClass('red_colored_tab');
    }

    if (stats_error == true) {
        $('#stat_graph span').addClass('red_colored_tab');
    } else {
        $('#stat_graph span').removeClass('red_colored_tab');
    }

    if (google_error == true) {
        $('#google_tab span').addClass('red_colored_tab');
    } else {
        $('#google_tab span').removeClass('red_colored_tab');
    }

    if (live_error == true) {
        $('#live_tab span').addClass('red_colored_tab');
    } else {
        $('#live_tab span').removeClass('red_colored_tab');
    }

    if (linkedin_error == true) {
        $('#linkedin_tab span').addClass('red_colored_tab');
    } else {
        $('#linkedin_tab span').removeClass('red_colored_tab');
    }

    if (twitter_error == true) {
        $('#twitter_tab span').addClass('red_colored_tab');
    } else {
        $('#twitter_tab span').removeClass('red_colored_tab');
    }

    if (yahoo_error == true) {
        $('#yahoo_tab span').addClass('red_colored_tab');
    } else {
        $('#yahoo_tab span').removeClass('red_colored_tab');
    }

    if (amazon_error == true) {
        $('#amazon_tab span').addClass('red_colored_tab');
    } else {
        $('#amazon_tab span').removeClass('red_colored_tab');
    }

    if (paypal_error == true) {
        $('#paypal_tab span').addClass('red_colored_tab');
    } else {
        $('#paypal_tab span').removeClass('red_colored_tab');
    }

    if (foursquare_error == true) {
        $('#foursquare_tab span').addClass('red_colored_tab');
    } else {
        $('#foursquare_tab span').removeClass('red_colored_tab');
    }

    if (github_error == true) {
        $('#github_tab span').addClass('red_colored_tab');
    } else {
        $('#github_tab span').removeClass('red_colored_tab');
    }

    if (disqus_error == true) {
        $('#disqus_tab span').addClass('red_colored_tab');
    } else {
        $('#disqus_tab span').removeClass('red_colored_tab');
    }

    if (vk_error == true) {
        $('#vk_tab span').addClass('red_colored_tab');
    } else {
        $('#vk_tab span').removeClass('red_colored_tab');
    }

    if (wordpress_error == true) {
        $('#wordpress_tab span').addClass('red_colored_tab');
    } else {
        $('#wordpress_tab span').removeClass('red_colored_tab');
    }

    if (dropbox_error == true) {
        $('#dropbox_tab span').addClass('red_colored_tab');
    } else {
        $('#dropbox_tab span').removeClass('red_colored_tab');
    }

    if (is_error) {
        return false;
    }

    /*Knowband button validation start*/
    $('#save_post_setting').parent().attr('href', 'javascript:void(0)');
    $('#save_post_setting').parent().attr('disabled', 'disabled');
    $('#save_post_setting').css('background-color', '#b9b9b9');
    $('#save_post_setting').css('border-color', '#b9b9b9');
    /*Knowband button validation end*/

    return true;
}

function getSocialUser(account,page,email)
{
    $("#account-title").html(' ');
    $("#account-title").html(firstToUpperCase(account));
    var item = $("#socialuseritem").val();
    email = $.trim(email);
    if (email.length)
        email = email;
    else
        email = '';

    $("#set-account").val(account);
    /*Knowband button validation start*/
    $('#social-search-btn').attr("disabled", true);
    /*Knowband button validation end*/
    $.ajax({
        type: "POST",
        url: module_path,
        data: 'ajax=true&method=getSocialUser&item='+item+'&email='+email+'&page_number='+page+'&account_type='+account,
        dataType: 'json',
        success: function(json) {
            if(!json[0])
            {
                var html = '<span style="font-size: 16px;font-weight: 600;">'+no_record_msg+'</span>';
                $('#socialstatsuserdata').html(html);
            }
            else
            {
                html = '<table class="list form alternate pure-table pure-table-bordered">';
                html += '<thead style="background: rgba(224, 224, 224, 0.48);"><tr><td>'+sno+'</td><td>'+username+'</td><td>'+useremail+'</td><td>'+reg_through_lbl+'</td><td>' +user_login_count + '</td></tr></thead>';
                var count = 1 * (page-1) *10;
                for (i in json[0])
                {
                    count = count + 1;
                    html += "<tr><td style='width:80px;'>" + count + "</td><td><a href='"+json[1]+"&updatecustomer&id_customer="+json[0][i]['id_customer']+"' target='_blank'>" + json[0][i]['username'] + "</a></td><td><a href='"+json[1]+"&updatecustomer&id_customer="+json[0][i]['id_customer']+"' target='_blank'>" + json[0][i]['email'] + "</a></td><td>" +firstToUpperCase(json[0][i]['account_type']) + "</td><td>" +json[0][i]['user_login_count'] + "</td></tr>";
                }
                html += "</table><div style='margin-top:2%;'><b style='color:black;'>"+ note + "</b><br> 1. <span style='color:#FF2707'>" + delete_msg + "</span>";
                html += "<br> 2. <span style='color:#FF2707'>" + login_count_msg + "</span></div>";
                $('#socialstatsuserdata').html(html);
            }
            $('#socialstatsdata .paginator-block').html(json[2]);
            if (json[2].length) {
                $('#show_when_pagination').show();
            } else {
                $('#show_when_pagination').hide();
            }
            $('[data-toggle="tooltip"]').tooltip();
            $('#social-search-btn').removeAttr("disabled");
        }
    });
}

function firstToUpperCase( str ) {
    return str.substr(0, 1).toUpperCase() + str.substr(1);
}

function closeModalForm()
{
    $("#account-title").html(' ');
    $("#socialuseritem").val("10");
    $("#social-email-search").val(null);
    $('.modal-backdrop').hide();
    $('#socialstatmodal').modal('hide');
}

function configurationAccordian(id)
{
    $("#"+id+"_accordian").accordion({
      animated: 'bounceslide',
      autoHeight: false,
      collapsible: true,
      event: 'click',
      active: false,
      animate: 100
    });
}

$(document).ready(function(){
    var account_arr = ["facebook", "google", "instagram", "live", "linkedin", "twitter", "amazon", "pay", "yahoo", "foursquare", "github", "disqus", "vk", "wordpress", "dropbox"];
    $.each(account_arr,function(i,val){
            getMailChimpList(val, false);
            getKlaviyoList(val, false);
            getSendinBlueList(val, false);
            
            configurationAccordian(val);
    });
    $("#social-search-btn").click(function(){
        var email = $("#social-email-search").val();
	var account = $("#set-account").val();
	getSocialUser(account,1,email);
    });

    $("#socialuseritem").change(function(){
        var email = $("#social-email-search").val();
        var account = $("#set-account").val();
	getSocialUser(account,1,email);
    });
    $("#stat_graph").live('click', function(){
        if (check_set == 0)
            drawOrderGraph(graphdata);
    });
    if (!$('input#socialloginizer_show_popup').is(':checked')) {
        $('#socialloginizer_redirect_url').show();
    }
    $('#socialloginizer_show_popup').change(function() {
        if($(this).is(":checked")) {
            $('#socialloginizer_redirect_url').hide();
        }
        else
            $('#socialloginizer_redirect_url').show();
    });
    var email = $("#social-email-search").val();
    getSocialUser('facebook',1,email);
});

function getMailChimpList(account, clicked)
{
	var key = $("#"+account+"_mailchimp_key").val();
	var listid = $("#"+account+"_mailchimp_list").val();
        $('.mail_kb_error_message').remove();
        $("#"+account+"_mailchimp_key").removeClass('mail_kb_error_field');
        if (clicked) {
            /*Knowband validation start*/
            var mailchimp_empty_err = velovalidation.checkMandatory($("#"+account+"_mailchimp_key"));
            if (mailchimp_empty_err != true)
            {
                $("#"+account+"_mailchimp_key").addClass('mail_kb_error_field');
                $("#"+account+"_mailchimp_key").parent().parent().append('<span class="mail_kb_error_message">' + mailchimp_empty_err + '</span>');
                return false;
            }
            /*Knowband validation end*/
        }
        /*Knowband button validation start*/
        $('#'+account+'_listbtn').attr("disabled", true);
        /*Knowband button validation end*/
	$.ajax({
		type: "POST",
		url: module_path,
		data: 'mailchimpajax=true&method=getMailChimpList&key='+key,
		dataType: 'json',
		beforeSend: function() {
			$("#"+account+"_list").html('');
			$("#"+account+"_loading").show();
		},
		success: function(json) {
			var html = '';

			if (json == 'false')
				html = "<font color='red'>"+no_list_msg+"</font>";
			else
			{
				html += '<select name="velocity_social[' + account + '][mailchimp_list]"';
				if (ps_ver == 15)
					html += 'class="selectpicker vss_sc_ver15"';
				html += 'id="' + account + '_selectlist">';

				for (i in json)
				{
					if (listid == json[i]['id'])
						html += '<option value="' + json[i]['id'] + '" selected>' + json[i]['name'] + '</option>';
					else
						html += '<option value="' + json[i]['id'] + '">' + json[i]['name'] + '</option>';
				}
				html += '</select>';
			}
			$("#"+account+"_loading").hide();
			$("#"+account+"_list").html(html);
			$('select.vss_sc_ver15#'+account+'_selectlist').selectpicker();
                        $('#'+account+'_listbtn').removeAttr("disabled");
		}
	});
}

function drawOrderGraph(data)
{
    check_set = 1;
    if (parseInt(lcount) == 0 && parseInt(rcount) == 0)
    {
        $("#analysis_graph").css("height","auto");
        return;
    }

    var login_count = [], account = [], color = [], register_count = [];
    var i;

    var length = data.length;


    for (i = 0; i < length; i++)
    {

        account.push([i, String(data[i]['account_type'])]);
        login_count.push([i, parseInt(data[i]['login_count'])]);
        register_count.push([i, parseInt(data[i]['register_count'])]);
    }

    if (login_count.length > 0 || register_count.length > 0)
    {
        var dataset = [
            {
                label: login,
                data: login_count,
                bars: {order:1, lineWidth: 0}
//		color:"red"
            },
            {
                label: register,
                data: register_count,
                bars: {order:2, lineWidth: 0}
//		color:"red"
            }

        ];

        var options = {

            series: {
		grow: {active:true}
            },
	    bars: {
                    show:true,
                    barWidth: 0.3,
                    fill:1
            },
            xaxis: {
                ticks: account,
                axisLabel: account_type,
		tickColor: "#fff",
		axisLabelPadding: 10,
		axisLabelUseCanvas: true,
		autoscaleMargin: 0.01

            },
	    yaxis: {
                axisLabel: count,
		tickColor: "#e6e6e6",
		//axisLabelPadding: 10,
		axisLabelUseCanvas: true
            },
            legend: {
//		     container:$("#legendContainer"),
		noColumns: 0,
                backgroundColor: null,
                backgroundOpacity: 0.9,
                labelBoxBorderColor: null,
                position: "ne"
            },
            grid: {
                hoverable: true,
                borderWidth: 1,
                borderColor: '#EEEEEE',
                mouseActiveRadius: 10,
                backgroundColor: "#ffffff",
                axisMargin: 20
            },
	    colors: ["rgb(219, 68, 55)", "rgb(56, 113, 207)"]
        };

        $.plot($("#analysis_graph"), dataset, options);
        $("#analysis_graph").CreateVerticalGraphToolTip();
    }
    else
    {
        $('#analysis_graph').html('<div class="no_chart"><span>' + empty_list_msg + '</span></div>');
    }

}

var previousPoint = null, previousLabel = null;
$.fn.CreateVerticalGraphToolTip = function () {
    $(this).bind("plothover", function (event, pos, item) {
        if (item) {
            if ((previousLabel != item.series.label) || (previousPoint != item.dataIndex)) {
                previousPoint = item.dataIndex;
                previousLabel = item.series.label;
                $("#tooltip").remove();

                var x = item.dataIndex;
                var y = item.datapoint[1];

                var color = item.series.color;
                sfl_graph_showTooltip(item.pageX, item.pageY, color,
                            "<strong>" + item.series.xaxis.ticks[x].label +" "+ item.series.label +  "</strong> : <strong>" + y + "</strong> ");
            }
        } else {
            $("#tooltip").remove();
            previousPoint = null;
        }
    });
};

function sfl_graph_showTooltip(x, y, color, contents) {
    $('<div id="tooltip">' + contents + '</div>').css({
        position: 'absolute',
        display: 'none',
        top: y - 40,
        left: x - 20,
        border: '1px solid ' + color,
        padding: '3px',
        'font-size': '11px',
        'border-radius': '5px',
        'background-color': '#fff',
        'font-family': 'Verdana, Arial, Helvetica, Tahoma, sans-serif',
        opacity: 0.9
    }).appendTo("body").fadeIn(200);
}

function getKlaviyoList(account, clicked)
{
    var key = $("#"+account+"_klaviyo_key").val();
	var listid = $("#"+account+"_klaviyo_select_list").val();
        $('.mail_kb_error_message').remove();
        $("#"+account+"_klaviyo_key").removeClass('mail_kb_error_field');
        if (clicked) {
            /*Knowband validation start*/
            var klaviyo_empty_err = velovalidation.checkMandatory($("#"+account+"_klaviyo_key"));
            if (klaviyo_empty_err != true)
            {
                $("#"+account+"_klaviyo_key").addClass('mail_kb_error_field');
                $("#"+account+"_klaviyo_key").parent().parent().append('<span class="mail_kb_error_message">' + klaviyo_empty_err + '</span>');
                return false;
            }
            /*Knowband validation end*/
        }
        if(key != ""){
        /*Knowband button validation start*/
        $('#'+account+'_klaviyo_listbtn').attr("disabled", true);
        /*Knowband button validation end*/
         $.ajax({
		type: "POST",
		url: module_path,
		data: 'klaviyoajax=true&method=getKlaviyoLists&key='+key,
		dataType: 'json',
		beforeSend: function() {
			$("#"+account+"_klaviyo_list").html('');
			$("#"+account+"_klaviyo_loading").show();
		},
		success: function(json) {
                    var html = '';

			if (json == 'false' || json == null)
				html = "<font color='red'>"+no_list_msg+"</font>";
			else
			{
				html += '<select name="velocity_social[' + account + '][klaviyo_list]"';
				if (ps_ver == 15)
					html += 'class="selectpicker vss_sc_ver15"';
				html += 'id="' + account + '_selectlist">';

				for (i in json)
				{
					if (listid == json[i]['value'])
						html += '<option value="' + json[i]['value'] + '" selected>' + json[i]['label'] + '</option>';
					else
						html += '<option value="' + json[i]['value'] + '">' + json[i]['label'] + '</option>';
				}
				html += '</select>';
			}
			$("#"+account+"_klaviyo_loading").hide();
			$("#"+account+"_klaviyo_lists").html(html);
			$('select.vss_sc_ver15#'+account+'_selectlist').selectpicker();
                        $('#'+account+'_klaviyo_listbtn').removeAttr("disabled");
		}
	});
    }
    else{
            var html = '';
            html = "<font color='red'>"+no_list_msg+"</font>";
            $("#"+account+"_klaviyo_lists").html(html);
    }
}

function getSendinBlueList(account, clicked)
{
    var key = $("#"+account+"_sendinblue_key").val();
	var listid = $("#"+account+"_sendinblue_select_list").val();
        $('.mail_kb_error_message').remove();
        $("#"+account+"_sendinblue_key").removeClass('mail_kb_error_field');
        if (clicked) {
            /*Knowband validation start*/
            var sendinblue_empty_err = velovalidation.checkMandatory($("#"+account+"_sendinblue_key"));
            if (sendinblue_empty_err != true)
            {
                $("#"+account+"_sendinblue_key").addClass('mail_kb_error_field');
                $("#"+account+"_sendinblue_key").parent().parent().append('<span class="mail_kb_error_message">' + sendinblue_empty_err + '</span>');
                return false;
            }
            /*Knowband validation end*/
        }
        if(key != ""){
        /*Knowband button validation start*/
        $('#'+account+'_sendinblue_listbtn').attr("disabled", true);
        /*Knowband button validation end*/
         $.ajax({
		type: "POST",
		url: module_path,
		data: 'sendinblueajax=true&method=getSendinBlueLists&key='+key,
		dataType: 'json',
		beforeSend: function() {
			$("#"+account+"_sendinblue_list").html('');
			$("#"+account+"_sendinblue_loading").show();
		},
		success: function(json) {
                    var html = '';

			if (json == 'false')
				html = "<font color='red'>"+no_list_msg+"</font>";
			else
			{
				html += '<select name="velocity_social[' + account + '][sendinblue_list]"';
				if (ps_ver == 15)
					html += 'class="selectpicker vss_sc_ver15"';
				html += 'id="' + account + '_selectlist">';

				for (i in json)
				{
					if (listid == json[i]['id'])
						html += '<option value="' + json[i]['id'] + '" selected>' + json[i]['name'] + '</option>';
					else
						html += '<option value="' + json[i]['id'] + '">' + json[i]['name'] + '</option>';
				}
				html += '</select>';
			}
			$("#"+account+"_sendinblue_loading").hide();
			$("#"+account+"_sendinblue_lists").html(html);
			$('select.vss_sc_ver15#'+account+'_selectlist').selectpicker();
                        $('#'+account+'_sendinblue_listbtn').removeAttr("disabled");
		}
	});
    }
    else{
            var html = '';
            html = "<font color='red'>"+no_list_msg+"</font>";
            $("#"+account+"_sendinblue_lists").html(html);
    }
}