﻿
function chkLogin()
{
	this.passed = false;
	this.checkItems = [ "Account", "Password" , "Code" ];

	this.checkAll = function ()
	{
		for ( var i = 0; i < this.checkItems.length; i ++ )
		{
			var check = eval ( "this.check" + this.checkItems[i] + "()" );
			if(!check)
			    return false;
		}
		return true;
	}

	this.showTip = function ( message )
	{
		var obj;
		if ( obj = document.getElementById ( 'tipSummary' ) )
		{
			obj.style.display = "block";
			obj.innerHTML = message;
		}
	}
	
	this.hideTip = function ()
	{
		var obj;
		if ( obj = document.getElementById ( 'tipSummary' ) )
		{
			obj.style.display = "none";
		}
	}

	this.checkAccount = function()
	{
		var message = '';
		var textbox = document.getElementById("txtAccount");
		if ( textbox.value.length == 0 )
		{
			message = "请填写用户名";
		}
		else if ( textbox.value.length < 4 || textbox.value.length > 20 )
		{
			message = '用户名长度必须为 4 - 20 字符';
		}
		else if ( textbox.value.indexOf (' ') >= 0 || textbox.value.indexOf ('\\') >= 0 || textbox.value.indexOf ('\'') >= 0 || textbox.value.indexOf ('\"') >= 0 )
		{
			message = '用户名包含非法字符';
		}		
		if ( message != '' )
		{
			this.showTip ( message );
			return false;
		}
		return true;
	}
	
	this.checkPassword = function()
	{
		var message = '';
		var account = document.getElementById("txtAccount");
		var textbox = document.getElementById("txtPassword");
		if ( textbox.value.length == 0 )
		{
			message = "请填写密码";
		}
		else if ( textbox.value.length < 6 || textbox.value.length > 20 )
		{
			message = '密码长度必须为 6 - 20 字符';
		}

		if ( message != '' )
		{
			this.showTip ( message );
			return false;
		}
		return true;
	}

	this.checkCode = function()
	{
		var textbox = document.getElementById("txtCode");
		if ( textbox.value.length == 0 )
		{
			this.showTip ( "请填写验证码" );
			return false;
		}
		else
		{
		    var result = Member.GetVerifyCode().value;
            if (textbox.value != result )
            {
	            this.showTip ( '验证码错误,请检查并重新填写' );
	            return false;
            }
	        return true;
		}
	}
	
	this.changeVerifyCode = function()
    {
	    var obj = document.getElementById ( 'imgVerifyCode' );
	    if ( obj )
	    {
		    obj.style.visibility = 'visible';
		    obj.src = 'Resources/VerifyCode.aspx';
	    }
    }
}
