﻿var suppressEnter = false;

//Clicks the specified link button when the enter key is hit within the control
function clickButtonOnEnter(linkButtonID, controlID, e)
{
    var key = keyCodeValue(e);
    if (key == 13 && !suppressEnter) {
        if ((navigator.appName.indexOf("Microsoft") != -1) || (navigator.appName.indexOf("MSIE") != -1)) {
            var control = document.getElementById(controlID);
            try { window.external.AutoCompleteSaveForm(control); }
            catch (err) { }
        }
        clickLinkButton(linkButtonID, e);
    }
}

//Performs the click action of a link button
function clickLinkButton(linkButtonID, e)
{
    var linkButton = document.getElementById(linkButtonID);
    if (linkButton) {
        cancelKeyPress(e);

        if (document.createEvent) {
            eval(unescape(linkButton.href));
        }
        else if (linkButton.click) {
            linkButton.click();
        }
    }
}

//Returns the key code from an event
function keyCodeValue(e)
{
    if (e == null) return null;
    else return window.event ? e.keyCode : e.which;
}

//Cancel key press event unless backspace
function cancelKeyPress(e)
{
    var key = keyCodeValue(e);
    if (key != 8) {
        cancelEventBubble(e);
        cancelReturnValue(e);
    }
}

//Cancel the current event and bubbling
function cancelEventBubble(e)
{
    if (e) {
        if (e.stopPropagation) e.stopPropagation();
        else e.cancelBubble = true;
    }
}

//Cancel the current return value
function cancelReturnValue(e)
{
    if (e) {
        if (e.preventDefault) e.preventDefault();
        else e.returnValue = false;
    }
}
