﻿var Tabs = new (function () {

    function Tabs(tabRoot_, contentRoot_, onClick_) {
        var tabRoot = 0;
        var contentRoot;
        var onClick;
        var that = this;
        var CurrentTab;

        this.Tab = function (tabRoot_, contentRoot_, onClick_) {
            tabRoot = tabRoot_;
            contentRoot = contentRoot_;
            onClick = onClick_
            CurrentTab = $(tabRoot).find('.Selected');

            $(contentRoot).children(':first').show();
            $(contentRoot).delay(100).fadeIn();

            //on click
            $(tabRoot).children().click(function () {
                if ($(this).attr('title') && !$(this).hasClass('Selected')) {

                    CurrentTab = this;
                    var Reference = $(this).attr('title');

                    //current
                    $(tabRoot).children().removeClass('Selected');
                    $(CurrentTab).addClass('Selected');

                    if (typeof onClick == "function") onClick(CurrentTab);

                    //show next
                    $(contentRoot).children().hide();
                    $(contentRoot).children().each(function (i) {
                        if ($(this).attr('title') == Reference) {
                            $(this).fadeIn();
                        }
                    });


                    return false;
                }

            }).filter(':first').click();

        };

        this.Tab(tabRoot_, contentRoot_, onClick_);

    }

    //multiple instances
    this.Start = function (tabRoot_, contentRoot_, onClick_) {
        new Tabs(tabRoot_, contentRoot_, onClick_);
    };
})();

function ClearForms(form) {
    $('input[type="text"]', form).val('');
    $('input[type="password"]', form).val('');

    $(':input', form)
             .not(':button, :submit, :reset, :hidden')
             .removeAttr('checked')
             .removeAttr('selected');

    //ex
    $('#father').val('Selecione uma Categoria');
    $('#editfather').val('Selecione uma Categoria');
};
