var GetkeyInner=Class.create({
	initialize :function(){
		this.high = "";
		this.low = "";
		this.rnd = "";
		this.s_simnew31=null;
		try{
			this.s_simnew31=new ActiveXObject("Syunew3A.s_simnew3");
		}catch(e){
			 txt="错误,原因是" + e.description + "\n\n";
			 txt+="请检查是否安装驱动程序，安装成功后请刷新页面。";
			 alert(txt);
			 window.location.href="../driver/driver_pwd.exe";
			 return ;
		}
		new Ajax.Request("../servlet/DistributeServlet",{
	      method     : 'post',
	      onComplete : this.keypass.bind(this)
	    });
 	},
 	keypass:function(ret){
 		var back = ret.responseText.evalJSON();
 		this.high = back.high;
 		this.low = back.low;
 		this.rnd = back.rnd;
 		this.readkey();
 	},
 	readkey:function(){
 		try{
 			var DevicePath,mylen,ret;
 			DevicePath = this.s_simnew31.FindPort(0);
 			if( this.s_simnew31.LastError!= 0 ){
 				window.alert("未发现电子密钥，请插入电子密钥");
 			}
 			else{
 				var keycode = this.s_simnew31.YReadString(0,495, this.high,this.low, DevicePath);
 				$("authcode").value=keycode;
 				$("rnd").value=this.s_simnew31.EncString(this.rnd,DevicePath);
 			}
 		}catch(err){  
 			txt="错误,原因是" + err.description + "\n\n";
 			txt+="请检查是否安装驱动程序，安装成功后请刷新页面。"; 
 			alert(txt);
 		 }
 	}
});
var getkeys =new GetkeyInner();

