﻿$(document).ready(function() {
    if (typeof Sys !== "undefined") {
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_pageLoaded(InovexTextBox_PageLoadedHandler);
    }
});

function InovexTextBox_PageLoadedHandler(sender, args) {
    LoadInovexTextBoxEvents();
}

function LoadInovexTextBoxEvents() {
    var inovexTextbox = $("input.textbox[id$=Textbox], textarea[id$=Textbox]");
    inovexTextbox.each(function(i) {
        var htmlContent = $(this).siblings(".hint").html();

        if (jQuery.trim(htmlContent) != "") {
            $(this).unbind("focus", InovexUserControlHintFocused).bind("focus", { htmlContent: htmlContent }, InovexUserControlHintFocused)
            .unbind("blur", InovexUserControlHintLostFocus).bind("blur", {}, InovexUserControlHintLostFocus);
        }

        var charCountSpan = $(this).siblings("span[id*=span_CharCount]").children("#CharCount");
        if (charCountSpan.length > 0) {
            var maxChars = 1 * $(this).attr("MaxLength");
            $(this).NobleCount('#' + charCountSpan.attr("id"), { on_negative: 'red', on_positive: 'green', max_chars: maxChars });
        }
    });
}

// Fixes the following error:
// Microsoft JScript runtime error: Sys.ScriptLoadFailedException: The script '...' failed to load. Check for: Inaccessible path.
if (typeof Sys !== "undefined") { Sys.Application.notifyScriptLoaded(); }
