﻿// Stepnell Website JavaScript Library


// Go to anchor function
function goToAnchor(pageName, anchorName) {
    location.href = pageName + "#" + anchorName;
}

// Finds a server control on the client side by id
function findObjWithClientId(Id) {
    var ctrls = document.getElementsByTagName("body")[0].getElementsByTagName("*");
    for (var count = 0; count < ctrls.length; count++) {
        var index = ctrls[count].id.indexOf(Id);
        if (index != -1) {
            if ((ctrls[count].id.length - index) == Id.length) {
                return ctrls[count];
            }
        }
    }
    return null;
}

// Checks for enter key and forces a postback to occur with the target event argument to be the same as the actionName parameter
function performPostbackOnEnter(e, actionName) {
    var characterCode;

    if (e && e.which) {
        e = e;
        characterCode = e.which;
    }
    else {
        e = event;
        characterCode = e.keyCode;
    }

    if (characterCode == 13) {
        __doPostBack('__Page', actionName);
        return false;
    }
    else {
        return true;
    }
}


// Submit Postback routine
// (causes a postback for page load to pick up)
function submitPostback(actionName) {
    __doPostBack('__Page', actionName);
}


// Swap Checkbox Checks routine
function swapCheckboxChecked(checkedName, otherName) {
    var checkedCheckBox = findObjWithClientId(checkedName);
    if (checkedCheckBox.checked == false) {
        return;
    }
    var newState = !checkedCheckBox.checked;
    var otherCheckBox = findObjWithClientId(otherName);
    otherCheckBox.checked = newState;
}

