﻿$(function() {

    /*
    * $(".QToolTip").each()
    * Run through each QToolTip object and apply
    * the wToolTip jQuery Plugin Component.
    *
    * Note:    This applies a Common looking tooltip to all pages that
    *          allow pages to reflect the same across all browsers.
    *
    *          This component plugin also allows more control over
    *          generic tooltips by replacing it with this control.
    */
    $(".QToolTip").each(function() {

        $(this).click(function(event) {
            event.preventDefault();
            return false;
        });

        var tttext = $(this).attr('tooltip');
        $(this).wTooltip({
            content: tttext,
            style: {
                fontSize: 11,
                backgroundColor: "InfoBackground",
                padding: "2px",
                marginTop: "8px",
                zIndex: "1000",
                color: "#000000"
            },
            fadeIn: "fast",
            fadeOut: "fast"
        });
    });

    $("a").each(function() {
        var atooltip = new String($(this).attr('tooltip'));
        if (atooltip != '' && atooltip != 'undefined') {
            $(this).click(function(event) {
                event.preventDefault();
                return false;
            });

            var tttext = $(this).attr('tooltip');
            $(this).wTooltip({
                content: tttext,
                style: {
                    fontSize: 11,
                    backgroundColor: "InfoBackground",
                    padding: "2px",
                    marginTop: "8px",
                    zIndex: "1000",
                    color: "#000000"
                },
                fadeIn: "fast",
                fadeOut: "fast"
            });
        }
    });

    $("MultipleFieldsValidator.ORValidator").each(function() {

        var tttext = "<span style='color:red'><strong>Important<em>!</em></strong></span>&nbsp;&nbsp;This is a required field.";

        $(this).wTooltip({
            content: tttext,
            style: {
                fontSize: 11,
                backgroundColor: "InfoBackground",
                padding: "2px",
                marginTop: "8px",
                zIndex: "1000",
                color: "#000000"
            },
            fadeIn: "fast",
            fadeOut: "fast"
        });
    });
    
    $("label.ImportantRequired").each(function() {

        var tttext = "<span style='color:red'><strong>Important<em>!</em></strong></span>&nbsp;&nbsp;This is a required field.";

        $(this).wTooltip({
            content: tttext,
            style: {
                fontSize: 11,
                backgroundColor: "InfoBackground",
                padding: "2px",
                marginTop: "8px",
                zIndex: "1000",
                color: "#000000"
            },
            fadeIn: "fast",
            fadeOut: "fast"
        });
    });

    $("span.ImportantRequired").each(function() {

        var tttext = $(this).attr('tooltip');

        var isError = new String($(this).attr('IsError'));

        if (tttext == "") // if empty, use default text
        {
            tttext = "<span style='color:red'><strong>Important<em>!</em></strong></span>&nbsp;&nbsp;This is a required field.";
        }
        else {

            if (isError.toLowerCase() == 'true') {
                tttext = "<span style='color:red'><strong>Important<em>!</em></strong></span>&nbsp;&nbsp;" + tttext;
            }
        }

        $(this).wTooltip({
            content: tttext,
            style: {
                fontSize: 11,
                backgroundColor: "InfoBackground",
                padding: "2px",
                marginTop: "8px",
                zIndex: "1000",
                color: "#000000"
            },
            fadeIn: "fast",
            fadeOut: "fast"
        });
    });

    /*
    * Assign Tooltip to Tooltip LinkButton
    */
    $("div.QuestionToolTip span").each(function() {
        var tttext = $(this).attr('tooltip');
        if (tttext != '') {
            $(this).wTooltip({
                content: tttext,
                style: {
                    fontSize: 11,
                    backgroundColor: "InfoBackground",
                    padding: "2px",
                    marginTop: "8px",
                    zIndex: "1000",
                    color: "#000000"
                },
                fadeIn: "fast",
                fadeOut: "fast"
            });
        }
    });
});
