function getDog() {
    try {
        var DamApp = new ActiveXObject("DamApp.DamCtrl.1");
        var bOk = DamApp.isDogInstalled();
    } catch (e) {
        alert("请插入USB密钥");
        window.setTimeout("getDog()", 10);
    }
}

function dogThere() {

    return;

    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;
    }

    document.getElementById('mybutt').innerHTML = '请稍等...';
    try {
        var DamApp = new ActiveXObject("DamApp.DamCtrl.1");
    } catch (e) {
        alert("您需要安装登录控件");
        document.getElementById('mybutt').innerHTML = '点击登录';
        return;
    }

    try {
        var bOk = DamApp.isDogInstalled();
    } catch (e) {
        alert("请插入USB密钥");
        document.getElementById('mybutt').innerHTML = '点击登录';
        return;
    }

    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();

    document.getElementById('mybutt').innerHTML = '点击登录';
}

function loadMask2() {

    var sWidth, sHeight;

    // mask
    var maskObj  = document.createElement('div');
    sWidth  = document.body.scrollWidth;
    sHeight = document.body.scrollHeight;
    maskObj.setAttribute('id', 'theMask');
    maskObj.style.position = 'absolute';
    maskObj.style.top  = 0;
    maskObj.style.left = 0;
    maskObj.style.background = '#666';
    maskObj.style.filter  = 'Alpha(opacity=50);';
    maskObj.style.opacity = '0.5';
    maskObj.style.width   = sWidth  + 'px';
    maskObj.style.height  = sHeight + 'px';
    maskObj.style.zIndex  = -100;
    maskObj.style.display = 'none';

    // message
    var maskMsg  = document.createElement('div');
    maskMsg.setAttribute('id', 'theMsg');
    maskMsg.style.position = 'absolute';
    maskMsg.style.top  = 0;
    maskMsg.style.left = 0;
    maskMsg.style.color   = '#fff';
    maskMsg.innerHTML = '<font style="font-size: 120px;">请稍等...</font>';
    maskObj.appendChild(maskMsg);

    document.body.appendChild(maskObj);
}

function showMask() {
    var maskObj = document.getElementById('theMask');

    if (maskObj != null) {
        var maskMsg = document.getElementById('theMsg');
        if (document.documentElement && document.documentElement.clientWidth) {
            var bdy = document.documentElement;
        } else {
            var bdy = document.body;
        }
        maskMsg.style.top  = bdy.scrollTop + 120;
        maskMsg.style.left = window.screen.availWidth/2 - 200;

        maskObj.style.height  = bdy.scrollHeight;
        maskObj.style.width   = bdy.scrollWidth;
        maskObj.style.display = 'block';
        maskObj.style.zIndex  = 10000;
    }
}

function getCat() {

    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){
    		alert("请插入USB密钥");
        	window.setTimeout("getCat()", 10);
    	}
   	} catch(e){
    	alert("请插入USB密钥");
        window.setTimeout("getCat()", 10);
   	}
    
}

function catThere() {

    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 (typeof(window.parent.location) != "undefined") {
            	window.parent.location = 'http://' + window.parent.location.host + '/?bkLogout=1';
        	} else {
            	window.location = 'http://' + window.location.host + '/?bkLogout=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';
        }

   	}    
}

function catIn(chk) {

    document.getElementById('mybutt').innerHTML = '请稍等...';

    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密钥");
	                document.getElementById('mybutt').innerHTML = '点击登录';
                }
                return false;
            }
    	}
   	}
   	catch(e){
        if (chk) {
            alert("您需要安装登录控件");
            document.body.removeChild(div1);
            document.getElementById('mybutt').innerHTML = '点击登录';
        }
        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();

    document.getElementById('mybutt').innerHTML = '点击登录';

    return true;
}
