function tryLogin() {
    var url = new URL(window.location.href);

    var p = "I9SSTK";

    var c = url.searchParams.get(p);
    var cinovar = url.searchParams.get("inovar");

    if (cinovar != null && cinovar.length > 0) {
        p = "inovar";
        c = cinovar;
    }

    jQuery.ajax({
        url: '../api/login?'+p+'=' + c,
        success: function (result) {
            //console.log(result);
            sessionStorage.setItem('id.cibe.inovar', result.PK_Utilizador);
            sessionStorage.setItem('username.cibe.inovar', result.Username);
            sessionStorage.setItem('tipout.cibe.inovar', result.TipoUt);
            sessionStorage.setItem('CibeAtk', result.Atk);
            sessionStorage.setItem('CibeUltimaEntradaStr', result.UltimaEntradaStr);
            sessionStorage.setItem('CibeUsernameAlt', result.UsernameAlt);
            sessionStorage.setItem('usaProgContabilidade', JSON.stringify(result.UsaProgContabilidade));

            window.location.href = "index.html#/cadastro";
        }
        //async: false
    });
}

function utils_checkTks() {
    var url = new URL(window.location.href);

    var p = url.searchParams.get("I9SSTK");
    if (p != null && p.length > 0) {
        tryLogin();
        return;
    }

    p = url.searchParams.get("inovar");
    if (p != null && p.length > 0) {
        tryLogin();
        return;
    }
    
}