﻿$(function () {

    $(".rc-input-error .input").each(function () {

        var hasFocus = false;

        $(this).keydown(function () {
            $(this).parents(".rc-input-error").removeClass("rc-input-error").addClass("rc-input-active");
            $(this).parents(".input-container").find(".input-error-tooltip").hide();
        });

        $(this).change(function () {
            $(this).parents(".rc-input-error").removeClass("rc-input-error").addClass("rc-input-active");
            $(this).parents(".input-container").find(".input-error-tooltip").hide();
        });

        $(this).focus(function () {
            if ($(this).is(".rc-input-error .input")) {
                $(".input-error-tooltip").hide();
                $(this).parents(".input-container").find(".input-error-tooltip").show();
            }
            hasFocus = true;
        });

        $(this).blur(function () {
            $(this).parents(".input-container").find(".input-error-tooltip").hide();
            hasFocus = false;
        });

        $(this).hover(
            function () {
                if ($(this).is(".rc-input-error .input")) {
                    $(".input-error-tooltip").hide();
                    $(this).parents(".input-container").find(".input-error-tooltip").show();
                }
            },
            function () {
                if (!hasFocus) $(this).parents(".input-container").find(".input-error-tooltip").hide();
            }
        );

    });

});