function getDog() {
    try {
        var DamApp = new ActiveXObject("DamApp.DamCtrl.1");
        var bOk = DamApp.isDogInstalled();
    } catch (e) {
        alert("请插入USB密钥");
        window.setTimeout("getDog()", 10);
    }
}

function dogThere() {

    try {
        var DamApp = new ActiveXObject("DamApp.DamCtrl.1");
    } catch(e) {
        if (typeof(window.parent.location) != "undefined") {
            window.parent.location = 'http://' + window.parent.location.host + '/?bkLogout=1';
        } else {
            window.location = 'http://' + window.location.host + '/?bkLogout=1';
        }
    }

    try {
        var bOk = DamApp.isDogInstalled();
    } catch (e) {
        if (typeof(window.parent.location) != "undefined") {
            window.parent.location = 'http://' + window.parent.location.host + '/?bkLogout=1';
        } else {
            window.location = 'http://' + window.location.host + '/?bkLogout=1';
        }
    }
}

function dogIn() {

    var cat = catIn(false);
    if (cat) {
        return true;
    }

    try {
        var DamApp = new ActiveXObject("DamApp.DamCtrl.1");
    } catch (e) {
        alert("您需要安装登录控件");
        return　false;
    }

    try {
        var bOk = DamApp.isDogInstalled();
    } catch (e) {
        alert("请插入USB密钥");
        return false;
    }

    var xand = DamApp.getRandom().toString();
    var name = DamApp.getUserName();
    var xode = DamApp.getMDCode(xand);
    var myid = DamApp.getString(40,4);

    document.getElementById('seed').value = xand;
    document.getElementById('user').value = name;
    document.getElementById('code').value = xode;
    document.getElementById('myid').value = myid;
    document.getElementById('myform').submit();

}

function catIn(chk) {

    if(typeof(CatApp)=="undefined"){
        var div1 = document.createElement("div");
        div1.id = "_damdiv_";
        div1.innerHTML = '<OBJECT ID="CatApp" CLASSID="CLSID:45B66E80-B98E-4A3C-8A6D-721AC2D63B19"></OBJECT>';
        document.body.appendChild(div1);
    }

    try{
        var bOk=CatApp.isDogInstalled();
        if(!bOk){
            if (CatApp.getMDCode(0).length != 32) {
                if (chk) {
                    alert("请插入USB密钥");
                }
                return false;
            }
        }
    }
    catch(e){
        if (chk) {
            alert("您需要安装登录控件");
        }
        return false;
    }

    var xand = CatApp.getRandom().toString();
    var name = CatApp.getUserName();
    var xode = CatApp.getMDCode(xand);
    var myid = CatApp.getString(40,4);

    document.getElementById('seed').value = xand;
    document.getElementById('user').value = name;
    document.getElementById('code').value = xode;
    document.getElementById('myid').value = myid;
    document.getElementById('myform').submit();

    return true;
}
