﻿function EnterKeyHandler(btn) {

    // process only the Enter key

    if (event.keyCode == 13) {

        // cancel the default submit

        event.returnValue = false;

        event.cancel = true;

        // submit the form by programmatically clicking the specified button

        btn.click();

    }

}


function moveRowUp(row) {
    var moveDone = false;
    var thisRow = $(row).closest("tr");
    if (thisRow.prev("tr").length > 0) {
        var thisStyleClass = thisRow.attr('class');
        var prevStyleClass = thisRow.prev("tr").attr('class');
        thisRow.attr('class', prevStyleClass);
        thisRow.prev("tr").attr('class', thisStyleClass);
        thisRow.insertBefore(thisRow.prev("tr"));
        moveDone = true;
    }
    return moveDone;
}

function moveRowDown(row) {
    var moveDone = false;
    var thisRow = $(row).closest("tr");
    if (thisRow.next("tr").length > 0) {
        var thisStyleClass = thisRow.attr('class');
        var prevStyleClass = thisRow.next("tr").attr('class');
        thisRow.attr('class', prevStyleClass);
        thisRow.next("tr").attr('class', thisStyleClass);
        thisRow.insertAfter(thisRow.next("tr"));
        moveDone = true;
    }
    return moveDone;
}



function resetSequence(obj, targetSelector) {
    var targets = $(obj).closest("table").find(targetSelector);
    var i = 0;

    if (targets.length > 0) {
        for (i = 0; i < targets.length; i++) {
            $(targets[i]).val(i + 1);
            $(targets[i]).closest("tr").find("td:first").text(i + 1);
        }
    }
}
