function Login(){
	this.safecode = null;
	this.err = null;
	this.form = null;
}

Login.prototype.init = function(){
	this.safecode = document.getElementById("safecode");
	this.form = document.loginform;
	this.err = document.getElementById("errinfo");
	this.form.username.focus();
	this.setSafeCode();

	this.form.onsubmit = Delegate.create(this,this.submit);
};

Login.prototype.setSafeCode = function(){
	var rnd = Math.floor(Math.random() * 100000);
	this.safecode.innerHTML = '<a href="javascript:login.setSafeCode();"><img src="textcode/safecode.asp?'+rnd+'" alt="看不清？换一张"/></a>';
};

Login.prototype.showError = function(err){
	this.err.innerHTML = err;
};

Login.prototype.submit = function(){
	if(this.form.username.value==""){
		this.showError("请输入用户名！");
	}else if(this.form.password.value==""){
		this.showError("请输入密码！");
	}else if(this.form.code.value==""){
		this.showError("请输入验证码！");
	}else{
		var ajax = new AJAXRequest;
		ajax.get(
				 "index.asp?action=in&username="+escape(this.form.username.value.replace(/\+/g,"$add"))+"&password="+escape(this.form.password.value)+"&code="+escape(this.form.code.value),
				 Delegate.create(this,this.receive)
		);
	}
	return false;
};

Login.prototype.receive = function(resultObj){
	var r = unescape(resultObj.responseText);
	r = r.split("{$$}");
	if(r[0] == "1") {
		window.location = "data.asp";
	}else{
		this.showError(r[1]);
		this.setSafeCode();
	}
};
var login = new Login();