﻿function chkkeypress(e) {
    var code;
    if (!e) var e = window.event;
    if (e.keyCode) code = e.keyCode;
    else if (e.which) code = e.which;

    if (code == 13) {
        e.keyCode = 9
    }

}


function findobject(objectname) {
    if (document.all) {
        element = document.all[objectname];
    }
    else {
        element = document.getElementById(objectname);
    }
    return element

}

var lastobj

function dokey(obj, controlname, fieldname) {

    code = event.keyCode
    if (code == 13) {
        event.keyCode = 9
    }

    if (event.keyCode == 37 && event.ctrlKey == true) {
        // Left Key
        c = obj.sourceIndex
        found = 0

        for (i = c - 1; i > 0; i--) {
            if (document.all[i].type == 'text' && found == 0) {
                found = 1
                document.all[i].focus();
            }
        }
    }


    if (event.keyCode == 39 && event.ctrlKey == true) {
        //Right Key
        c = obj.sourceIndex
        found = 0

        for (i = c + 1; i < document.all.length; i++) {
            if (document.all[i].type == 'text' && found == 0) {
                found = 1
                document.all[i].focus();
            }
        }

    }

    if (event.keyCode == 38) {
        if (parseInt(obj.row) > 1) {
            r = parseInt(obj.row) - 1
            idname = obj.id
            newname = controlname + '_' + fieldname + r
            document.all[newname].focus();
        }
    }

    if (event.keyCode == 40) {

        r = parseInt(obj.row) + 1
        idname = obj.id
        newname = controlname + '_' + fieldname + r

        try {
            document.all[newname].focus();
        }
        catch (Error) {
        }

    }

}

function changefocus(obj) {
    if (lastobj != null) {
        lastobj.style.background = '#FFFFFF'
    }
    obj.style.background = '#FFFF00'

    lastobj = obj
}


