// JScript File
// 02-20-2015 Bug 30970 
// Add functionality for tooltips in the popup windows
// repair the wrong functionality in some browsers ff and ie related to bug 31523
// also resolves the problem of the tooltips when the form does a postback
$(function () {
    $('body').tooltip({
        selector: '[rel=tooltip]'
    });
});

// FHF 7/23/2015 This is an event handler will be fired once the user click on Print page on the confirmation page
// it avoids the problem printing form with <fieldset> tag on Firefox
function OnPrint() {
    var fieldSetElement = $("#DesignedDiv fieldset");
    if (fieldSetElement) {
        var fsContent = fieldSetElement.html();
        fieldSetElement.replaceWith('<div class="fieldset">' + fsContent + '</div>');
    }
    self.print();
}
$(function checknumericvalue() {
    var numericvalue = $('input[type="number"]');
    numericvalue.on('keypress', function (evt) {
        var returnValue = false;
        var charCode = (window.Event) ? evt.which : evt.keyCode
        if (((charCode >= 48) && (charCode <= 57)) || (charCode == 8) || (charCode == 13) || (charCode == 46)) {
            returnValue = true;
        }
        return returnValue;
    });
});

function FixFilePath(id) {
    var link = document.getElementById(id);

    if (link) {
        var linkText = link.text.toLowerCase();
        var linkHref = link.href.toLowerCase();
        link.text = linkText.replace("iweb", "eWeb");
        link.href = linkHref.replace("iweb", "eWeb");
    }
}

// This is generic function which handles the __doPostBack aftermath effect on control
// anyone can add there code here if there control status is disturbed by __doPostBack
// 2 Events provided here one when postback event begins and when postback event ends
jQuery(function ($) {
    const checkbox = document.getElementById('reg_waiver_agree_flag');

    //If waiver agree checkbox isn't on the form, exit the method
    if (checkbox === null)
        return;

        var prm = Sys.WebForms.PageRequestManager.getInstance();

        // here we can add code if we wants to initialize/show/handle before post back events begins
        prm.add_beginRequest(function (source, args) {

        });

        // here we can add code if we wants to initialize/show/handle after post back events begins
        prm.add_endRequest(function (source, args) {
            $("#reg_waiver_signed_name").on("keyup",function (e) {
                attachRegNameKeyUpEvent(e);
            });
            WaiverControlEnabled();
        });
});

$(document).ready(function () {
    $("#reg_waiver_signed_name").on('keyup', function (e) {
        attachRegNameKeyUpEvent(e);
    });
    WaiverControlEnabled();
});

function attachRegNameKeyUpEvent(e) {
    var k = e.which;
    if ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 8 || k == 32 || (k >= 48 && k <= 57)) {
        WaiverControlEnabled();
    }
}

function WaiverControlEnabled() {
    const checkbox = document.getElementById('reg_waiver_agree_flag');
    
    //If waiver agree checkbox isn't on the form, exit the method
    if (checkbox === null )
        return;

    //baseline buttons, excluding cancel, are "Bottom_1", "Bottom_2", and "Bottom_3"
    //Dynamically find wizard buttons by attributes instead of name
    //The buttons to continue on the wizard all use "diableSubmitButtons()" in the onclick attribute
    var bottomAddButtons = $(document).find('input[id ^= "Bottom"][onclick *= "WebForm_DoPostBackWithOptions"]');
    const WaiverWarning = document.getElementById("TEXT_WaiverRequired");
    const regSignTextBox = document.getElementById("reg_waiver_signed_name");

    if (checkbox.checked && regSignTextBox != null && regSignTextBox.value != "") {
        bottomAddButtons != null ? bottomAddButtons.each(function (index, button) { button.disabled = false; }) : "";
        WaiverWarning != null ? WaiverWarning.style.display = "none" : "";
    }
    else {
        bottomAddButtons != null ? bottomAddButtons.each(function (index, button) { button.disabled = true; }) : "";
        WaiverWarning != null ? WaiverWarning.style.display = "block" : "";
    }
};
