﻿jQuery.noConflict();

jQuery(document).ready(function($) {
    $("#tabs-register").show();
    $("#tabs-forgotPassword").show();

    $("#help").click(function() {
        $("#helpbox").slideToggle();
    });

    $("#closehelp").click(function() {
        $("#helpbox").slideUp();
    });


    if (jQuery('.checkboxwrapper').length > 0)
        initCustomCheckbox();


});


function initCustomCheckbox() {
    jQuery('.checkboxwrapper').each(function (index) {
        var container = jQuery(this);
        var inputValue = "";
        jQuery("label,input", container).addClass("checkboxhide");
        if (jQuery('input', container).attr('checked') !== undefined && jQuery('input', container).attr('checked') === true) {
            inputValue = " isChecked";
        }

        container.append('<a href="#" class="checkbox_button' + inputValue + '"><span class="checkbox_button_label">' + (inputValue.length > 0 ? "Ta bort" : "Lägg till") + '</span></a>');
        jQuery('.checkbox_button', container).click(function () {
            var scope = jQuery(this);
            var container = scope.parent();
            var checkbox = jQuery("input", container);
            scope.removeClass("isChecked").addClass(toggleCheck(container));
            return false;
        });
    });

    function toggleCheck(element) {
        var checkbox = jQuery('input', element);
        if (checkbox.attr('checked') === true) {
            checkbox.removeAttr('checked');
            jQuery('.checkbox_button_label', element).html('Lägg till');
            return ""
        } else {
            checkbox.attr('checked', 'checked');
            jQuery('.checkbox_button_label', element).html('Ta bort');
            return "isChecked"
        }
    }

}
