﻿/// <reference path="jquery-1.3.2.js" />
function CreateButtons() {
    /// <summary>For all browsers that aren't IE6 (because it doesn't submit the correct data for submit buttons), look for all inputs with a button class and replace them with HTML buttons, making sure to keep the attributes and making them work for postbacks.</summary>

    var isIE6 = ($.browser.msie && parseInt(jQuery.browser.version) == 6);

    $("input.button").each(function(i) {
        var input = $(this);
        var button = $("<button type=\"submit\" value=\"" + input.attr("value") + "\"><span>" + input.attr("value") + "</span></button>");
        button.attr("class", input.attr("class"));
        button.attr("id", input.attr("id"));
        button.attr("name", input.attr("name"));
        button.onmouseover = input.attr("onmouseover");
        button.onmouseout = input.attr("onmouseout");

        if (isIE6) {
            button.bind("click", function() {
                DisableButtons(this);
            });
        }

        if (typeof (input.attr("onclick")) == "function") {
            eval("button.bind('click', " + input.attr("onclick") + ")");
        } else {
            eval("button.bind('click', function() { __doPostBack(' " + input.attr("name") + "', '') });");
        }
        input.replaceWith(button);
    });
}

function DisableButtons(clickedButton) {
    // Disabled all buttons except the one that's been clicked. This is to fix a bug in IE6 where all button values are sent to the server, not just the one that's been clicked.
    var buttons = $("button");
    buttons.attr("disabled", "disabled");
    $(clickedButton).removeAttr("disabled");
    setTimeout("EnableButtons();", 2000);
}

function EnableButtons() {
    // Enable all buttons on the page.
    var buttons = $("button");
    buttons.removeAttr("disabled");
}