/**
 * 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 2015 Knowband
 * @license   see file: LICENSE.txt
 */
var num_of_component = 0;

function addLayout(a) {
    var id_layout = 0;
    $.ajax({
        url: ajaxaction + "&configure=socialloginizer&getlayoutForm=true",
        data: 'id_layout=' + id_layout,
        type: "post",
        beforeSend: function () {
            $('#kbGDPRDialogueModel .modal-title').html(add_layout_heading);
            $('#kbGDPRDialogueModel .modal-body').html('');
            $('#kbGDPRDialogueModel').modal({
                show: 'true',
            });

        },
        success: function (data)
        {
            var b = JSON.parse(data);
            if (1) {
                $('#kbGDPRDialogueModel .modal-body').html('');
                $('#kbGDPRDialogueModel .modal-body').append(b.html);
                $('#kbGDPRDialogueModel').modal({
                    show: 'true',
                });
                $('#kbGDPRDialogueModel .form-group').css('margin', '15px');
                $('#button_color').closest('.form-group').parent().append($('#social_login_button_colors'));
                $('#enabled_social_login').parent().parent().prev().find('.col-lg-9').addClass('col-lg-7 alert alert-info');
                $('#enabled_social_login').parent().parent().prev().find('.col-lg-9').css('clear', 'none');
                showHideCustomizedColor(a);
                updatePreviewIcons();
            }
        }
    });
}
function showHideCustomizedColor(a) {

    if ($('#button_color').val() == 'default') {
        $('#button_color').closest('.form-group').next().hide();
    } else {
        $('#button_color').closest('.form-group').next().show();
    }

}

function deleteLayout(a) {
    if (confirm(confirmation_txt + '?')) {
        var id_layout = jQuery.trim($(a).closest('tr').find('.td-vss-code').html());
        $(a).closest('tr').hide();
        $.ajax({
            url: ajaxaction + "&configure=socialloginizer&isdeletableLayout=true",
            type: "post",
            success: function (data)
            {
                if (data > 1) {
                    $.ajax({
                        url: ajaxaction + "&configure=socialloginizer&deleteLayout=true",
                        data: 'id_layout=' + id_layout,
                        type: "post",
                        success: function (data)
                        {
                            showSuccessMessage(layout_delete_message);
                            refreshlayoutList();
                            refreshlayoutOptions();
                        }
                    });
                } else {
                    $(a).closest('tr').show();
                    showErrorMessage(layout_delete_error_message);
                }
            }
        });
    } else {
        return false;
    }
}
function editLayout(a)
{
    
    var id_layout = jQuery.trim($(a).closest('tr').find('.td-vss-code').html());
    $.ajax({
        url: ajaxaction + "&configure=socialloginizer&getlayoutForm=true",
        data: 'id_layout=' + id_layout,
        type: "post",
        beforeSend: function () {
            $('#kbGDPRDialogueModel .modal-body').html('');
            $('#kbGDPRDialogueModel .modal-title').html(edit_layout_heading);
            $('#kbGDPRDialogueModel').modal({
                show: 'true',
            });

        },
        success: function (data)
        {
            var b = JSON.parse(data);
            if (1) {
                $('#kbGDPRDialogueModel .control-label .label-tooltip').tooltip();
                $('#kbGDPRDialogueModel .modal-body').html('');
                $('#kbGDPRDialogueModel .modal-body').append(b.html);
                $('#kbGDPRDialogueModel').modal({
                    show: 'true',
                });
                $('#kbGDPRDialogueModel .form-group').css('margin', '15px');
                $('#button_color').closest('.form-group').parent().append($('#social_login_button_colors'));
                $('#enabled_social_login').parent().parent().prev().find('.col-lg-9').addClass('col-lg-7 alert alert-info');
                $('#enabled_social_login').parent().parent().prev().find('.col-lg-9').css('clear', 'none');
                $('.label-tooltip').tooltip();
                showHideCustomizedColor(a);
                updatePreviewIcons();
            }
        }
    });
}

function updatePreviewIcons() {
    $(".mColorPickerInput").each(function () {
        $(this).change(function () {
            var color = $(this).val();
            if ($(this).hasClass("facebook")) {
                if ($(this).hasClass("iconcolor")) {
                    $(".fa-facebook").css("color", color);
                } else if ($(this).hasClass("textcolor")) {
                    $(".kbazm-facebook").css("color", color);
                } else if ($(this).hasClass("backgroundcolor")) {
                    $(".fa-facebook").each(function () {
                        if ($(this).parent().hasClass('kbazm-facebook')) {
                            $(".kbazm-facebook").css("background", color);
                        } else {
                            $(".fa-facebook").css("background", color);
                        }
                    });
                }
            }

            if ($(this).hasClass("google")) {
                if ($(this).hasClass("iconcolor")) {
                    $(".fa-google").css("color", color);
                } else if ($(this).hasClass("textcolor")) {
                    $(".kbazm-google").css("color", color);
                } else if ($(this).hasClass("backgroundcolor")) {
                    $(".fa-google").each(function () {
                        if ($(this).parent().hasClass('kbazm-google')) {
                            $(".kbazm-google").css("background", color);
                        } else {
                            $(".fa-google").css("background", color);
                        }
                    });
                }
            }

            if ($(this).hasClass("linkedin")) {
                if ($(this).hasClass("iconcolor")) {
                    $(".fa-linkedin").css("color", color);
                } else if ($(this).hasClass("textcolor")) {
                    $(".kbazm-linkedin").css("color", color);
                } else if ($(this).hasClass("backgroundcolor")) {
                    $(".fa-linkedin").each(function () {
                        if ($(this).parent().hasClass('kbazm-linkedin')) {
                            $(".kbazm-linkedin").css("background", color);
                        } else {
                            $(".fa-linkedin").css("background", color);
                        }
                    });
                }
            }

            if ($(this).hasClass("live")) {
                if ($(this).hasClass("iconcolor")) {
                    $(".fa-windows").css("color", color);
                } else if ($(this).hasClass("textcolor")) {
                    $(".kbazm-windows").css("color", color);
                } else if ($(this).hasClass("backgroundcolor")) {
                    $(".fa-windows").each(function () {
                        if ($(this).parent().hasClass('kbazm-windows')) {
                            $(".kbazm-windows").css("background", color);
                        } else {
                            $(".fa-live").css("background", color);
                        }
                    });
                }
            }

            if ($(this).hasClass("twitter")) {
                if ($(this).hasClass("iconcolor")) {
                    $(".fa-twitter").css("color", color);
                } else if ($(this).hasClass("textcolor")) {
                    $(".kbazm-twitter").css("color", color);
                } else if ($(this).hasClass("backgroundcolor")) {
                    $(".fa-twitter").each(function () {
                        if ($(this).parent().hasClass('kbazm-twitter')) {
                            $(".kbazm-twitter").css("background", color);
                        } else {
                            $(".fa-twitter").css("background", color);
                        }
                    });
                }
            }

            if ($(this).hasClass("yahoo")) {
                if ($(this).hasClass("iconcolor")) {
                    $(".fa-yahoo").css("color", color);
                } else if ($(this).hasClass("textcolor")) {
                    $(".kbazm-yahoo").css("color", color);
                } else if ($(this).hasClass("backgroundcolor")) {
                    $(".fa-yahoo").each(function () {
                        if ($(this).parent().hasClass('kbazm-yahoo')) {
                            $(".kbazm-yahoo").css("background", color);
                        } else {
                            $(".fa-yahoo").css("background", color);
                        }
                    });
                }
            }

            if ($(this).hasClass("amazon")) {
                if ($(this).hasClass("iconcolor")) {
                    $(".fa-amazon").css("color", color);
                } else if ($(this).hasClass("textcolor")) {
                    $(".kbazm-amazon").css("color", color);
                } else if ($(this).hasClass("backgroundcolor")) {
                    $(".fa-amazon").each(function () {
                        if ($(this).parent().hasClass('kbazm-amazon')) {
                            $(".kbazm-amazon").css("background", color);
                        } else {
                            $(".fa-amazon").css("background", color);
                        }
                    });
                }
            }

            if ($(this).hasClass("instagram")) {
                if ($(this).hasClass("iconcolor")) {
                    $(".fa-instagram").css("color", color);
                } else if ($(this).hasClass("textcolor")) {
                    $(".kbazm-instagram").css("color", color);
                } else if ($(this).hasClass("backgroundcolor")) {
                    $(".fa-instagram").each(function () {
                        if ($(this).parent().hasClass('kbazm-instagram')) {
                            $(".kbazm-instagram").css("background", color);
                        } else {
                            $(".fa-instagram").css("background", color);
                        }
                    });
                }
            }

            if ($(this).hasClass("paypal")) {
                if ($(this).hasClass("iconcolor")) {
                    $(".fa-paypal").css("color", color);
                } else if ($(this).hasClass("textcolor")) {
                    $(".kbazm-paypal").css("color", color);
                } else if ($(this).hasClass("backgroundcolor")) {
                    $(".fa-paypal").each(function () {
                        if ($(this).parent().hasClass('kbazm-paypal')) {
                            $(".kbazm-paypal").css("background", color);
                        } else {
                            $(".fa-paypal").css("background", color);
                        }
                    });
                }
            }


            if ($(this).hasClass("foursquare")) {
                if ($(this).hasClass("iconcolor")) {
                    $(".fa-foursquare").css("color", color);
                } else if ($(this).hasClass("textcolor")) {
                    $(".kbazm-foursquare").css("color", color);
                } else if ($(this).hasClass("backgroundcolor")) {
                    $(".fa-foursquare").each(function () {
                        if ($(this).parent().hasClass('kbazm-foursquare')) {
                            $(".kbazm-foursquare").css("background", color);
                        } else {
                            $(".fa-foursquare").css("background", color);
                        }
                    });
                }
            }

            if ($(this).hasClass("github")) {
                if ($(this).hasClass("iconcolor")) {
                    $(".fa-github").css("color", color);
                } else if ($(this).hasClass("textcolor")) {
                    $(".kbazm-github").css("color", color);
                } else if ($(this).hasClass("backgroundcolor")) {
                    $(".fa-github").each(function () {
                        if ($(this).parent().hasClass('kbazm-github')) {
                            $(".kbazm-github").css("background", color);
                        } else {
                            $(".fa-github").css("background", color);
                        }
                    });
                }
            }

            if ($(this).hasClass("vkontakte")) {
                if ($(this).hasClass("iconcolor")) {
                    $(".fa-vk").css("color", color);
                } else if ($(this).hasClass("textcolor")) {
                    $(".kbazm-vk").css("color", color);
                } else if ($(this).hasClass("backgroundcolor")) {
                    $(".fa-vk").each(function () {
                        if ($(this).parent().hasClass('kbazm-vk')) {
                            $(".kbazm-vk").css("background", color);
                        } else {
                            $(".fa-vk").css("background", color);
                        }
                    });
                }
            }

            if ($(this).hasClass("wordpress")) {
                if ($(this).hasClass("iconcolor")) {
                    $(".fa-wordpress").css("color", color);
                } else if ($(this).hasClass("textcolor")) {
                    $(".kbazm-wordpress").css("color", color);
                } else if ($(this).hasClass("backgroundcolor")) {
                    $(".fa-wordpress").each(function () {
                        if ($(this).parent().hasClass('kbazm-wordpress')) {
                            $(".kbazm-wordpress").css("background", color);
                        } else {
                            $(".fa-wordpress").css("background", color);
                        }
                    });
                }
            }

            if ($(this).hasClass("dropbox")) {
                if ($(this).hasClass("iconcolor")) {
                    $(".fa-dropbox").css("color", color);
                } else if ($(this).hasClass("textcolor")) {
                    $(".kbazm-dropbox").css("color", color);
                } else if ($(this).hasClass("backgroundcolor")) {
                    $(".fa-dropbox").each(function () {
                        if ($(this).parent().hasClass('kbazm-dropbox')) {
                            $(".kbazm-dropbox").css("background", color);
                        } else {
                            $(".fa-dropbox").css("background", color);
                        }
                    });
                }
            }

//            if ($(this).hasClass("paypal")) {
//                if ($(this).hasClass("iconcolor")) {
//                    $(".fa-paypal").css("color", color);
//                } else if ($(this).hasClass("textcolor")) {
//                    $(".kbazm-paypal").css("color", color);
//                } else if ($(this).hasClass("backgroundcolor")) {
//                    $(".fa-paypal").each(function () {
//                        if ($(this).parent().hasClass('kbazm-paypal')) {
//                            $(".kbazm-paypal").css("background", color);
//                        } else {
//                            $(".fa-paypal").css("background", color);
//                        }
//                    });
//                }
//            }
        })
    });

}
function refreshlayoutList() {
    $.ajax({
    url: ajaxaction + "&configure=socialloginizer&getLayoutList=true",
        type: "post",
        success: function (data)
        {
            var b = JSON.parse(data);
            $('#layout_list').html(b.html);
            $('.dropdown-toggle').dropdown();
        }
    });

}
function refreshlayoutOptions() {
    $.ajax({
        url: ajaxaction + "&configure=socialloginizer&getlayoutoptions=true",
        type: "post",
        success: function (data)
        {
            var b = JSON.parse(data);
            updatelayoutoption(b);
        }
    });
}
function updatelayoutoption(b) {
    var index_selected_layout = $("select[name='velocity_social[index][layout]']").val();
    var category_selected_layout = $("select[name='velocity_social[category][layout]']").val();
    var product_selected_layout = $("select[name='velocity_social[product][layout]']").val();
    var authentication_selected_layout = $("select[name='velocity_social[authentication][layout]']").val();
    var order_selected_layout = $("select[name='velocity_social[order][layout]']").val();
    var cart_selected_layout = $("select[name='velocity_social[cart][layout]']").val();
    var cms_selected_layout = $("select[name='velocity_social[cms][layout]']").val();
    var new_products_selected_layout = $("select[name='velocity_social[new-products][layout]']").val();
    var best_sales_selected_layout = $("select[name='velocity_social[best-sales][layout]']").val();
    var prices_drop_selected_layout = $("select[name='velocity_social[prices-drop][layout]']").val();
    var stores_selected_layout = $("select[name='velocity_social[stores][layout]']").val();
    var contact_selected_layout = $("select[name='velocity_social[contact][layout]']").val();
    var state_html = '';
    for (i = 0; i < b.length; i++) {
        if (b.length - 1 == i) {
            state_html += '<option value="' + b[i]['value'] + '" selected="selected" >' + b[i]['name'] + '</option>';
        } else {
            state_html += '<option value="' + b[i]['value'] + '">' + b[i]['name'] + '</option>';
        }
    }
    $("select[name='velocity_social[index][layout]']").html(state_html);
    $("select[name='velocity_social[category][layout]']").html(state_html);
    $("select[name='velocity_social[product][layout]']").html(state_html);
    $("select[name='velocity_social[authentication][layout]']").html(state_html);
    $("select[name='velocity_social[order][layout]']").html(state_html);
    $("select[name='velocity_social[cart][layout]']").html(state_html);
    $("select[name='velocity_social[cms][layout]']").html(state_html);
    $("select[name='velocity_social[new-products][layout]']").html(state_html);
    $("select[name='velocity_social[prices-drop][layout]']").html(state_html);
    $("select[name='velocity_social[best-sales][layout]']").html(state_html);
    $("select[name='velocity_social[stores][layout]']").html(state_html);
    $("select[name='velocity_social[contact][layout]']").html(state_html);

}
function showHidebackgroundColor() {
    if ($('input[name="is_enabled_background_color"]:checked').val() == "1") {
        $('input[name="timer_background_color"]').parent().parent().show();
    } else {
        $('input[name="timer_background_color"]').parent().parent().hide();
    }
}

function veloValidatelayoutform(a) {
    var error = false;
    if ($('#layout_name').val() == '') {
        showErrorMessage(empty_layout_name);
        error = true;
    }
    var enabled_options = $('#enabled_social_login').val();
    if (enabled_options === null) {
        showErrorMessage(layout_empty_enabled_option);
        error = true;
    }
    if (error) {
        return false;
    }
    submitlayoutform(event);
    return false;
}
function submitlayoutform(a) {
    var id_layout = $('#id_layout').val();
    var enabled_options = $('#enabled_social_login').val();
    var hover_effect = $('#hover_effect').val();
    var alignment_type = $('#alignment_type').val();
    var icon_type = $('#icon_type').val();
    var button_color = $('#button_color').val();
    var layout_name = $('#layout_name').val();

    var fd = new FormData();
    fd.append('id_layout', id_layout);
    fd.append('enabled_options', enabled_options);
    fd.append('hover_effect', hover_effect);
    fd.append('alignment_type', alignment_type);
    fd.append('icon_type', icon_type);
    fd.append('layout_name', layout_name);
    fd.append('button_color', button_color);
    $('#slider2_form input[type="color"]').each(function () {
        var value = $(this).val();
        var name = $(this).attr('name');
        fd.append(name, value);
    });

//    for (i = 0; i < active_languages.length; i++) {
//        fd.append('layout_name_' + active_languages[i], $('#layout_name_' + active_languages[i]).val());
//    }
    $.ajax({
        url: ajaxaction + "&configure=socialloginizer&saveLayoutFormData=true",
        data: fd,
        type: "post",
        processData: false,
        contentType: false,
        beforeSend: function () {
            $('#kbGDPRDialogueModel').modal({
                show: 'true',
            });
            $('button[name="submitOptionsslider2"]').prop('disabled', true);

        },
        success: function (data)
        {
            var b = JSON.parse(data);
            if (1) {
                $.ajax({
                    url: ajaxaction + "&configure=socialloginizer&getLayoutList=true",
                    type: "post",
                    success: function (data)
                    {
                        var b = JSON.parse(data);
                        $('#layout_list').html(b.html);
                        $('.dropdown-toggle').dropdown();
                        if (id_layout == 0) {
                            showSuccessMessage(layout_add_message);
                        } else {
                            showSuccessMessage(layout_update_message);
                        }
                        refreshlayoutOptions();
                        $('#kbGDPRDialogueModel').modal('hide');
                        $('#kbGDPRDialogueModel .modal-body').html('');
                    }
                });

            }
        }
    });
    return false;
}
function showHidePreviewIcons(a) {
    if ($(a).val() == 'small_circular') {
        $("#icon_facebook_small_circular").show();
        $("#icon_facebook_small_rectangular").hide();
        $("#icon_facebook_small_rounded").hide();
        $("#icon_facebook_large_rounded").hide();
        $("#icon_facebook_large_rectangular").hide();
        $("#icon_google_small_circular").show();
        $("#icon_google_small_rectangular").hide();
        $("#icon_google_small_rounded").hide();
        $("#icon_google_large_rounded").hide();
        $("#icon_google_large_rectangular").hide();
        $("#icon_linkedin_small_circular").show();
        $("#icon_linkedin_small_rectangular").hide();
        $("#icon_linkedin_small_rounded").hide();
        $("#icon_linkedin_large_rounded").hide();
        $("#icon_linkedin_large_rectangular").hide();
        $("#icon_live_small_circular").show();
        $("#icon_live_small_rectangular").hide();
        $("#icon_live_small_rounded").hide();
        $("#icon_live_large_rounded").hide();
        $("#icon_live_large_rectangular").hide();
        $("#icon_twitter_small_circular").show();
        $("#icon_twitter_small_rectangular").hide();
        $("#icon_twitter_small_rounded").hide();
        $("#icon_twitter_large_rounded").hide();
        $("#icon_twitter_large_rectangular").hide();
        $("#icon_yahoo_small_circular").show();
        $("#icon_yahoo_small_rectangular").hide();
        $("#icon_yahoo_small_rounded").hide();
        $("#icon_yahoo_large_rounded").hide();
        $("#icon_yahoo_large_rectangular").hide();
        $("#icon_amazon_small_circular").show();
        $("#icon_amazon_small_rectangular").hide();
        $("#icon_amazon_small_rounded").hide();
        $("#icon_amazon_large_rounded").hide();
        $("#icon_amazon_large_rectangular").hide();
        $("#icon_instagram_small_circular").show();
        $("#icon_instagram_small_rectangular").hide();
        $("#icon_instagram_small_rounded").hide();
        $("#icon_instagram_large_rounded").hide();
        $("#icon_instagram_large_rectangular").hide();
        $("#icon_paypal_small_circular").show();
        $("#icon_paypal_small_rectangular").hide();
        $("#icon_paypal_small_rounded").hide();
        $("#icon_paypal_large_rounded").hide();
        $("#icon_paypal_large_rectangular").hide();

        $("#icon_foursquare_small_circular").show();
        $("#icon_foursquare_small_rectangular").hide();
        $("#icon_foursquare_small_rounded").hide();
        $("#icon_foursquare_large_rounded").hide();
        $("#icon_foursquare_large_rectangular").hide();

        $("#icon_github_small_circular").show();
        $("#icon_github_small_rectangular").hide();
        $("#icon_github_small_rounded").hide();
        $("#icon_github_large_rounded").hide();
        $("#icon_github_large_rectangular").hide();

        $("#icon_disqus_small_circular").show();
        $("#icon_disqus_small_rectangular").hide();
        $("#icon_disqus_small_rounded").hide();
        $("#icon_disqus_large_rounded").hide();
        $("#icon_disqus_large_rectangular").hide();

        $("#icon_vkontakte_small_circular").show();
        $("#icon_vkontakte_small_rectangular").hide();
        $("#icon_vkontakte_small_rounded").hide();
        $("#icon_vkontakte_large_rounded").hide();
        $("#icon_vkontakte_large_rectangular").hide();

        $("#icon_dropbox_small_circular").show();
        $("#icon_dropbox_small_rectangular").hide();
        $("#icon_dropbox_small_rounded").hide();
        $("#icon_dropbox_large_rounded").hide();
        $("#icon_dropbox_large_rectangular").hide();

        $("#icon_wordpress_small_circular").show();
        $("#icon_wordpress_small_rectangular").hide();
        $("#icon_wordpress_small_rounded").hide();
        $("#icon_wordpress_large_rounded").hide();
        $("#icon_wordpress_large_rectangular").hide();
    } else if ($(a).val() == 'small_rectangular') {
        $("#icon_facebook_small_circular").hide();
        $("#icon_facebook_small_rectangular").show();
        $("#icon_facebook_small_rounded").hide();
        $("#icon_facebook_large_rounded").hide();
        $("#icon_facebook_large_rectangular").hide();
        $("#icon_google_small_circular").hide();
        $("#icon_google_small_rectangular").show();
        $("#icon_google_small_rounded").hide();
        $("#icon_google_large_rounded").hide();
        $("#icon_google_large_rectangular").hide();
        $("#icon_linkedin_large_rectangular").hide();
        $("#icon_linkedin_small_circular").hide();
        $("#icon_linkedin_small_rectangular").show();
        $("#icon_linkedin_small_rounded").hide();
        $("#icon_linkedin_large_rounded").hide();
        $("#icon_linkedin_large_rectangular").hide();
        $("#icon_live_small_circular").hide();
        $("#icon_live_small_rectangular").show();
        $("#icon_live_small_rounded").hide();
        $("#icon_live_large_rounded").hide();
        $("#icon_live_large_rectangular").hide();
        $("#icon_twitter_small_circular").hide();
        $("#icon_twitter_small_rectangular").show();
        $("#icon_twitter_small_rounded").hide();
        $("#icon_twitter_large_rounded").hide();
        $("#icon_twitter_large_rectangular").hide();
        $("#icon_yahoo_small_circular").hide();
        $("#icon_yahoo_small_rectangular").show();
        $("#icon_yahoo_small_rounded").hide();
        $("#icon_yahoo_large_rounded").hide();
        $("#icon_yahoo_large_rectangular").hide();
        $("#icon_amazon_large_rectangular").hide();
        $("#icon_amazon_small_circular").hide();
        $("#icon_amazon_small_rectangular").show();
        $("#icon_amazon_small_rounded").hide();
        $("#icon_amazon_large_rounded").hide();
        $("#icon_amazon_large_rectangular").hide();
        $("#icon_instagram_small_circular").hide();
        $("#icon_instagram_small_rectangular").show();
        $("#icon_instagram_small_rounded").hide();
        $("#icon_instagram_large_rounded").hide();
        $("#icon_instagram_large_rectangular").hide();
        $("#icon_paypal_small_circular").hide();
        $("#icon_paypal_small_rectangular").show();
        $("#icon_paypal_small_rounded").hide();
        $("#icon_paypal_large_rounded").hide();
        $("#icon_paypal_large_rectangular").hide();


        $("#icon_foursquare_small_circular").hide();
        $("#icon_foursquare_small_rectangular").show();
        $("#icon_foursquare_small_rounded").hide();
        $("#icon_foursquare_large_rounded").hide();
        $("#icon_foursquare_large_rectangular").hide();

        $("#icon_github_small_circular").hide();
        $("#icon_github_small_rectangular").show();
        $("#icon_github_small_rounded").hide();
        $("#icon_github_large_rounded").hide();
        $("#icon_github_large_rectangular").hide();

        $("#icon_disqus_small_circular").hide();
        $("#icon_disqus_small_rectangular").show();
        $("#icon_disqus_small_rounded").hide();
        $("#icon_disqus_large_rounded").hide();
        $("#icon_disqus_large_rectangular").hide();

        $("#icon_vkontakte_small_circular").hide();
        $("#icon_vkontakte_small_rectangular").show();
        $("#icon_vkontakte_small_rounded").hide();
        $("#icon_vkontakte_large_rounded").hide();
        $("#icon_vkontakte_large_rectangular").hide();

        $("#icon_dropbox_small_circular").hide();
        $("#icon_dropbox_small_rectangular").show();
        $("#icon_dropbox_small_rounded").hide();
        $("#icon_dropbox_large_rounded").hide();
        $("#icon_dropbox_large_rectangular").hide();

        $("#icon_wordpress_small_circular").hide();
        $("#icon_wordpress_small_rectangular").show();
        $("#icon_wordpress_small_rounded").hide();
        $("#icon_wordpress_large_rounded").hide();
        $("#icon_wordpress_large_rectangular").hide();
    } else if ($(a).val() == 'small_rounded') {
        $("#icon_facebook_small_circular").hide();
        $("#icon_facebook_small_rectangular").hide();
        $("#icon_facebook_small_rounded").show();
        $("#icon_facebook_large_rounded").hide();
        $("#icon_facebook_large_rectangular").hide();
        $("#icon_google_small_circular").hide();
        $("#icon_google_small_rectangular").hide();
        $("#icon_google_small_rounded").show();
        $("#icon_google_large_rounded").hide();
        $("#icon_google_large_rectangular").hide();
        $("#icon_linkedin_small_circular").hide();
        $("#icon_linkedin_small_rectangular").hide();
        $("#icon_linkedin_small_rounded").show();
        $("#icon_linkedin_large_rounded").hide();
        $("#icon_linkedin_large_rectangular").hide();
        $("#icon_live_small_circular").hide();
        $("#icon_live_small_rectangular").hide();
        $("#icon_live_small_rounded").show();
        $("#icon_live_large_rounded").hide();
        $("#icon_live_large_rectangular").hide();
        $("#icon_twitter_small_circular").hide();
        $("#icon_twitter_small_rectangular").hide();
        $("#icon_twitter_small_rounded").show();
        $("#icon_twitter_large_rounded").hide();
        $("#icon_twitter_large_rectangular").hide();

        $("#icon_yahoo_small_circular").hide();
        $("#icon_yahoo_small_rectangular").hide();
        $("#icon_yahoo_small_rounded").show();
        $("#icon_yahoo_large_rounded").hide();
        $("#icon_yahoo_large_rectangular").hide();

        $("#icon_amazon_small_circular").hide();
        $("#icon_amazon_small_rectangular").hide();
        $("#icon_amazon_small_rounded").show();
        $("#icon_amazon_large_rounded").hide();
        $("#icon_amazon_large_rectangular").hide();
        $("#icon_instagram_small_circular").hide();
        $("#icon_instagram_small_rectangular").hide();
        $("#icon_instagram_small_rounded").show();
        $("#icon_instagram_large_rounded").hide();
        $("#icon_instagram_large_rectangular").hide();
        $("#icon_paypal_small_circular").hide();
        $("#icon_paypal_small_rectangular").hide();
        $("#icon_paypal_small_rounded").show();
        $("#icon_paypal_large_rounded").hide();
        $("#icon_paypal_large_rectangular").hide();

        $("#icon_foursquare_small_circular").hide();
        $("#icon_foursquare_small_rectangular").hide();
        $("#icon_foursquare_small_rounded").show();
        $("#icon_foursquare_large_rounded").hide();
        $("#icon_foursquare_large_rectangular").hide();

        $("#icon_github_small_circular").hide();
        $("#icon_github_small_rectangular").hide();
        $("#icon_github_small_rounded").show();
        $("#icon_github_large_rounded").hide();
        $("#icon_github_large_rectangular").hide();

        $("#icon_disqus_small_circular").hide();
        $("#icon_disqus_small_rectangular").hide();
        $("#icon_disqus_small_rounded").show();
        $("#icon_disqus_large_rounded").hide();
        $("#icon_disqus_large_rectangular").hide();

        $("#icon_vkontakte_small_circular").hide();
        $("#icon_vkontakte_small_rectangular").hide();
        $("#icon_vkontakte_small_rounded").show();
        $("#icon_vkontakte_large_rounded").hide();
        $("#icon_vkontakte_large_rectangular").hide();

        $("#icon_dropbox_small_circular").hide();
        $("#icon_dropbox_small_rectangular").hide();
        $("#icon_dropbox_small_rounded").show();
        $("#icon_dropbox_large_rounded").hide();
        $("#icon_dropbox_large_rectangular").hide();

        $("#icon_wordpress_small_circular").hide();
        $("#icon_wordpress_small_rectangular").hide();
        $("#icon_wordpress_small_rounded").show();
        $("#icon_wordpress_large_rounded").hide();
        $("#icon_wordpress_large_rectangular").hide();
    } else if ($(a).val() == 'large_rectangular') {
        $("#icon_facebook_small_circular").hide();
        $("#icon_facebook_small_rectangular").hide();
        $("#icon_facebook_small_rounded").hide();
        $("#icon_facebook_large_rounded").hide();
        $("#icon_facebook_large_rectangular").show();
        $("#icon_google_small_circular").hide();
        $("#icon_google_small_rectangular").hide();
        $("#icon_google_small_rounded").hide();
        $("#icon_google_large_rounded").hide();
        $("#icon_google_large_rectangular").show();
        $("#icon_linkedin_small_circular").hide();
        $("#icon_linkedin_small_rectangular").hide();
        $("#icon_linkedin_small_rounded").hide();
        $("#icon_linkedin_large_rounded").hide();
        $("#icon_linkedin_large_rectangular").show();
        $("#icon_live_small_circular").hide();
        $("#icon_live_small_rectangular").hide();
        $("#icon_live_small_rounded").hide();
        $("#icon_live_large_rounded").hide();
        $("#icon_live_large_rectangular").show();
        $("#icon_twitter_small_circular").hide();
        $("#icon_twitter_small_rectangular").hide();
        $("#icon_twitter_small_rounded").hide();
        $("#icon_twitter_large_rounded").hide();
        $("#icon_twitter_large_rectangular").show();
        $("#icon_yahoo_small_circular").hide();
        $("#icon_yahoo_small_rectangular").hide();
        $("#icon_yahoo_small_rounded").hide();
        $("#icon_yahoo_large_rounded").hide();
        $("#icon_yahoo_large_rectangular").show();
        $("#icon_amazon_small_circular").hide();
        $("#icon_amazon_small_rectangular").hide();
        $("#icon_amazon_small_rounded").hide();
        $("#icon_amazon_large_rounded").hide();
        $("#icon_amazon_large_rectangular").show();
        $("#icon_instagram_small_circular").hide();
        $("#icon_instagram_small_rectangular").hide();
        $("#icon_instagram_small_rounded").hide();
        $("#icon_instagram_large_rounded").hide();
        $("#icon_instagram_large_rectangular").show();
        $("#icon_paypal_small_circular").hide();
        $("#icon_paypal_small_rectangular").hide();
        $("#icon_paypal_small_rounded").hide();
        $("#icon_paypal_large_rounded").hide();
        $("#icon_paypal_large_rectangular").show();

        $("#icon_foursquare_small_circular").hide();
        $("#icon_foursquare_small_rectangular").hide();
        $("#icon_foursquare_small_rounded").hide();
        $("#icon_foursquare_large_rounded").hide();
        $("#icon_foursquare_large_rectangular").show();

        $("#icon_github_small_circular").hide();
        $("#icon_github_small_rectangular").hide();
        $("#icon_github_small_rounded").hide();
        $("#icon_github_large_rounded").hide();
        $("#icon_github_large_rectangular").show();

        $("#icon_disqus_small_circular").hide();
        $("#icon_disqus_small_rectangular").hide();
        $("#icon_disqus_small_rounded").hide();
        $("#icon_disqus_large_rounded").hide();
        $("#icon_disqus_large_rectangular").show();

        $("#icon_vkontakte_small_circular").hide();
        $("#icon_vkontakte_small_rectangular").hide();
        $("#icon_vkontakte_small_rounded").hide();
        $("#icon_vkontakte_large_rounded").hide();
        $("#icon_vkontakte_large_rectangular").show();

        $("#icon_dropbox_small_circular").hide();
        $("#icon_dropbox_small_rectangular").hide();
        $("#icon_dropbox_small_rounded").hide();
        $("#icon_dropbox_large_rounded").hide();
        $("#icon_dropbox_large_rectangular").show();

        $("#icon_wordpress_small_circular").hide();
        $("#icon_wordpress_small_rectangular").hide();
        $("#icon_wordpress_small_rounded").hide();
        $("#icon_wordpress_large_rounded").hide();
        $("#icon_wordpress_large_rectangular").show();
    } else if ($(a).val() == 'large_rounded') {
        $("#icon_facebook_small_circular").hide();
        $("#icon_facebook_small_rectangular").hide();
        $("#icon_facebook_small_rounded").hide();
        $("#icon_facebook_large_rounded").show();
        $("#icon_facebook_large_rectangular").hide();
        $("#icon_google_small_circular").hide();
        $("#icon_google_small_rectangular").hide();
        $("#icon_google_small_rounded").hide();
        $("#icon_google_large_rounded").show();
        $("#icon_google_large_rectangular").hide();
        $("#icon_linkedin_small_circular").hide();
        $("#icon_linkedin_small_rectangular").hide();
        $("#icon_linkedin_small_rounded").hide();
        $("#icon_linkedin_large_rounded").show();
        $("#icon_linkedin_large_rectangular").hide();
        $("#icon_live_small_circular").hide();
        $("#icon_live_small_rectangular").hide();
        $("#icon_live_small_rounded").hide();
        $("#icon_live_large_rounded").show();
        $("#icon_live_large_rectangular").hide();
        $("#icon_twitter_small_circular").hide();
        $("#icon_twitter_small_rectangular").hide();
        $("#icon_twitter_small_rounded").hide();
        $("#icon_twitter_large_rounded").show();
        $("#icon_twitter_large_rectangular").hide();
        $("#icon_yahoo_small_circular").hide();
        $("#icon_yahoo_small_rectangular").hide();
        $("#icon_yahoo_small_rounded").hide();
        $("#icon_yahoo_large_rounded").show();
        $("#icon_yahoo_large_rectangular").hide();
        $("#icon_amazon_small_circular").hide();
        $("#icon_amazon_small_rectangular").hide();
        $("#icon_amazon_small_rounded").hide();
        $("#icon_amazon_large_rounded").show();
        $("#icon_amazon_large_rectangular").hide();
        $("#icon_instagram_small_circular").hide();
        $("#icon_instagram_small_rectangular").hide();
        $("#icon_instagram_small_rounded").hide();
        $("#icon_instagram_large_rounded").show();
        $("#icon_instagram_large_rectangular").hide();
        $("#icon_paypal_small_circular").hide();
        $("#icon_paypal_small_rectangular").hide();
        $("#icon_paypal_small_rounded").hide();
        $("#icon_paypal_large_rounded").show();
        $("#icon_paypal_large_rectangular").hide();


        $("#icon_foursquare_small_circular").hide();
        $("#icon_foursquare_small_rectangular").hide();
        $("#icon_foursquare_small_rounded").hide();
        $("#icon_foursquare_large_rounded").show();
        $("#icon_foursquare_large_rectangular").hide();

        $("#icon_github_small_circular").hide();
        $("#icon_github_small_rectangular").hide();
        $("#icon_github_small_rounded").hide();
        $("#icon_github_large_rounded").show();
        $("#icon_github_large_rectangular").hide();

        $("#icon_disqus_small_circular").hide();
        $("#icon_disqus_small_rectangular").hide();
        $("#icon_disqus_small_rounded").hide();
        $("#icon_disqus_large_rounded").show();
        $("#icon_disqus_large_rectangular").hide();

        $("#icon_vkontakte_small_circular").hide();
        $("#icon_vkontakte_small_rectangular").hide();
        $("#icon_vkontakte_small_rounded").hide();
        $("#icon_vkontakte_large_rounded").show();
        $("#icon_vkontakte_large_rectangular").hide();

        $("#icon_dropbox_small_circular").hide();
        $("#icon_dropbox_small_rectangular").hide();
        $("#icon_dropbox_small_rounded").hide();
        $("#icon_dropbox_large_rounded").show();
        $("#icon_dropbox_large_rectangular").hide();

        $("#icon_wordpress_small_circular").hide();
        $("#icon_wordpress_small_rectangular").hide();
        $("#icon_wordpress_small_rounded").hide();
        $("#icon_wordpress_large_rounded").show();
        $("#icon_wordpress_large_rectangular").hide();
    }

}

function rgb2hsb(r, g, b)
{
    r /= 255;
    g /= 255;
    b /= 255; // Scale to unity.
    var minVal = Math.min(r, g, b),
        maxVal = Math.max(r, g, b),
        delta = maxVal - minVal,
        HSB = {hue: 0, sat: 0, bri: maxVal},
    del_R, del_G, del_B;

    if (delta !== 0)
    {
        HSB.sat = delta / maxVal;
        del_R = (((maxVal - r) / 6) + (delta / 2)) / delta;
        del_G = (((maxVal - g) / 6) + (delta / 2)) / delta;
        del_B = (((maxVal - b) / 6) + (delta / 2)) / delta;

        if (r === maxVal) {
            HSB.hue = del_B - del_G;
        } else if (g === maxVal) {
            HSB.hue = (1 / 3) + del_R - del_B;
        } else if (b === maxVal) {
            HSB.hue = (2 / 3) + del_G - del_R;
        }

        if (HSB.hue < 0) {
            HSB.hue += 1;
        }
        if (HSB.hue > 1) {
            HSB.hue -= 1;
        }
    }

    HSB.hue *= 360;
    HSB.sat *= 100;
    HSB.bri *= 100;
    return HSB;
}
function hexToRgb(hex) {
    // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
    var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
    hex = hex.replace(shorthandRegex, function (m, r, g, b) {
        return r + r + g + g + b + b;
    });

    var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
    return result ? {
        r: parseInt(result[1], 16),
        g: parseInt(result[2], 16),
        b: parseInt(result[3], 16)
    } : null;
}

function changeColor(wheel_color)
{
    velsofWheelHexCode = wheel_color;
    var colorRGB = hexToRgb(velsofWheelHexCode);
    var hslColorCode = rgb2hsb(colorRGB.r, colorRGB.g, colorRGB.b);
    //   document.getElementById("kbsw_preview_img").style.filter = 'hue-rotate(' + hslColorCode.hue + 'deg) saturate(' + hslColorCode.sat + '%) contrast(1.1)';

}

function setDate() {
    $('.datetimepicker').click(function () {
        $('.ui-datepicker').css('z-index', '99999999');
    });
}

function closeLayoutForm()
{
    $('.layout_add_edit_form').slideUp("fast", function () {

    });
}
