
function getCookie(cname) {
    let name = cname + "=";
    let decodedCookie = decodeURIComponent(document.cookie);
    let ca = decodedCookie.split(';');
    for (let i = 0; i < ca.length; i++) {
        let c = ca[i];
        while (c.charAt(0) == ' ') {
            c = c.substring(1);
        }
        if (c.indexOf(name) == 0) {
            return c.substring(name.length, c.length);
        }
    }
    return "";
}

function setCookie(cname, cvalue, exdays) {
    const d = new Date();
    d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
    let expires = "expires=" + d.toUTCString();
    document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}


function linkother() {
    window.location.assign("https://www.vecteezy.com/")


}
function cleartxt() {

    $("#lblError").html("");
    $("#lblError").hide();
    $("#lblError").removeClass("cssalert");

}

function checktxt() {
    var username = $("#txtUserName").val();
    var password = $("#txtPassword").val();
    if (username == "") {
        alert('กรุณาระบุ Username');
        $("#txtUserName").focus();


    } else if (password == "") {
        alert('กรุณาระบุ Password');
        $("#txtPassword").focus();
    }



}

$(document).ready(function () {
    //$(function () {
    //    $(this).bind("contextmenu", function (e) {
    //        e.preventDefault();
    //    });
    //});

    let userid = getCookie("userid");
    let username = getCookie("fullname");
    let position = getCookie("position");
    $("#lbluserid").html(userid);
    $("#lblfullname").html(username);
    $("#lblposition").html(position);





    $("input").not($(":button")).keypress(function (evt) {
        if (evt.keyCode == 13) {
            evt.preventDefault();
            iname = $(this).val();
            if (iname !== 'Submit') {
                var fields = $(this).parents('form:eq(0),body').find('button,input,textarea,select');
                var index = fields.index(this);
                if (index > -1 && (index + 1) < fields.length) {
                    fields.eq(index + 1).focus();
                }
                return false;
            }
        }
    });
    $("select").not($(":button")).keypress(function (evt) {
        if (evt.keyCode == 13) {
            evt.preventDefault();
            iname = $(this).val();
            if (iname !== 'Submit') {
                var fields = $(this).parents('form:eq(0),body').find('button,input,textarea,select');
                var index = fields.index(this);
                if (index > -1 && (index + 1) < fields.length) {
                    fields.eq(index + 1).focus();
                }
                return false;
            }
        }
    });
    $("textarea").not($(":button")).keypress(function (evt) {
        if (evt.keyCode == 13) {
            evt.preventDefault();
            iname = $(this).val();
            if (iname !== 'Submit') {
                var fields = $(this).parents('form:eq(0),body').find('button,input,textarea,select');
                var index = fields.index(this);
                if (index > -1 && (index + 1) < fields.length) {
                    fields.eq(index + 1).focus();
                }
                return false;
            }
        }
    });
    $("button").not($(":button")).keypress(function (evt) {
        if (evt.keyCode == 13) {
            evt.preventDefault();
            iname = $(this).val();
            if (iname !== 'Submit') {
                var fields = $(this).parents('form:eq(0),body').find('button,input,textarea,select');
                var index = fields.index(this);
                if (index > -1 && (index + 1) < fields.length) {
                    fields.eq(index + 1).focus();
                }
                return false;
            }
        }
    });

    $("#txtUserName").keypress(function (evt) {
        $("#lblError").html("");
        $("#lblError").removeClass("cssalert");
    });


    $("#txtPassword").keypress(function (evt) {
        $("#lblError").html("");
        $("#lblError").removeClass("cssalert");
    });



});
