﻿

Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = "side";

function onSubmit() {
    if (formPanel.getForm().isValid()) {
        try {
            formPanel.buttons[1].disable();
            var pwd = formPanel.getForm().findField("password").getValue();
            caOcx.userPWD = pwd;
            caOcx.verifyPassWD();

            if (caOcx.nResult != 0) {
                Ext.Msg.alert("登陆失败", "错误：" + caOcx.strResult + "<BR>请确保报关员IC卡或企业法人卡、电子口岸IKey卡已经正确连接到电脑，并且已经对应安装读卡器驱动程序或IKey卡驱动。如有疑问请联系客服电话：0756-8125566。");
                caOcx.CloseCpuCard();
                formPanel.buttons[1].enable();
                return;
            }
            else {
//                Ext.Ajax.request({
//                    url: "Service/RandomNumber.aspx",
//                    method: "POST",
//                    params: {},
//                    success: function(A) {
//                        caOcx.strInputDecodePEM = A.responseText;
//                        caOcx.identifyFirstStep();
//                        //caOcx.DeclareData();
//                        alert(caOcx.nResult);
//                        alert(caOcx.strOutputSignData);
//                        alert(caOcx.strDclOutputSignData);
//                        alert(caOcx.strRandomClient);
//                    }
//                });
            
                caOcx.getItemUserInfo();
                var userInfo = caOcx.multiUserCertInfo;
                var items = new Array();
                items = userInfo.split("||");
                Ext.Ajax.request({
                    url: "Action/LoginChk.aspx",
                    method: "POST",
                    params: { CardId: items[5], Pwd: pwd, UName: items[1], OrgCode: items[8] },
                    success: function(A) {
                        var B = Ext.decode(A.responseText);
                        if ((typeof B.success == "undefined") || (B.success == "customs")) {
                           
                            location.replace("Customs.aspx")
                        }
                        else if ((typeof B.success == "undefined") || (B.success == "company")) {
                        //alert(Math.random());
                            location.replace("Company.aspx")
                        }
                        else {
                            Ext.Msg.alert("提示信息", "登陆失败，您的企业未开通E线通或网络连接失败!");
                            formPanel.buttons[1].enable();
                        }
                    }
                });
                
                
                
                caOcx.CloseCpuCard();
            }
        }
        catch (e) {
            Ext.Msg.alert("提示信息", "您的电脑还没有安装<b>电子口岸IC/IKey卡登陆控件</b><br><a href='ExtUploads/usercard.rar'>>>>点击下载电子口岸IC/IKey卡登陆控件<<<</a><br>下载完请解压缩后安装，并刷新本网页！");
            formPanel.buttons[1].enable();
        }
    }
}

function reset() {
    formPanel.getForm().reset()
}

var formPanel = new Ext.form.FormPanel({
    defaults: { width: 140 },
    bodyStyle: "padding-top:50px;padding-left:20px;",
    buttonAlign: "right",
    defaultType: "textfield",
    frame: false, border: false, height: 120,
    id: "login-form",
    formId: "loginForm",
    items: [
         { fieldLabel: "请输入密码", cls: "loginField", name: "password", allowBlank: false, blankText: "请输入密码", inputType: "password" }
    ],
    buttons: [
        { minWidth: 60, handler: reset, text: "重填" },
        { minWidth: 60, handler: onSubmit, text: "登陆" }
    ],
    keys: {
        key: [13], fn: onSubmit, scope: this
    },
    labelWidth: 70
});

formPanel.on("render", function() {
    var A = formPanel.getForm().findField("password");
    if (A) { A.focus() }
}, this, { delay: 200 });

Ext.onReady(function() {
    setTimeout(function() {
        Ext.get("loading").remove(); Ext.get("loading-mask").fadeOut({ remove: true })
    }, 250);
    Ext.fly("loginDialogId").center(Ext.getBody(), "c-c");
    formPanel.render(Ext.fly("loginFormContainer"));
    formPanel.footer.applyStyles("padding-right:62px;");
    Ext.fly("loginDialogId").fadeIn({ easing: "easeInStrong", duration: 0.25 });
    if (Ext.isIE === true) {
        Ext.fly("close-window").fadeIn({ endOpacity: 0.9, easing: "easeInStrong", duration: 0.25 })
    } else { Ext.fly("close-window").hide() }

    if (window.screen.height < 768 || window.screen.width < 1024) {
        Ext.Msg.alert("提示信息","系统检测到您当前电脑桌面分辨率设置太小，这将有可能导致有些窗口无法显示完整！<br>本系统要求分辨率在 1024 x 768 或以上，请对电脑桌面分辨率进行调整。");
    }
});




