﻿var KBI = (function () {
    var WSURL = "http://cypdss.integration-online.net/cruws/CRU.asmx";
    var KBIURL = "http://cypdss.integration-online.net/mcan/login.aspx";
    function CheckKBIPrivileges(username, password, callback) {
        $.support.cors = true;
        $.ajax({
            type: "GET",
            url: WSURL + "/AuthenticateUserScript",
            contentType: "application/json; charset=utf-8",
            dataType: "jsonp",
            data: "Username='" + Jsonize(username) + "'&Password='" + Jsonize(password) + "'&App=1",
            async: true,
            crossDomain: true,
            success: function (res) {
                var SecUser = res.d || res;
                if (SecUser.SEC_UserId > 0) {
                    window.open(KBIURL + "?etoken=" + SecUser.EToken);
                }
                else {
                    if (callback) callback();
                }
            },
            error: function (xhr, status, error) {
                alert(error);
            }
        });
    }
    function Jsonize(str) {
        return str.replace(new RegExp("'", 'g'), "\\'");
    }
    return {
        CheckKBIPrivileges: CheckKBIPrivileges
    };
})();
