﻿
function chkQueryOrder()
{
	this.passed = false;
	this.checkItems = [ "OrderNo", "Consignee" , "Code" ];
	this.className = [ 'boxNormal', 'boxError', 'boxOK', 'boxWaiting' ];
	this.checkItems = [ "OrderNo", "Consignee", "Code" ];
	this.messages = {
		'OrderNo'				: '请输入您要查询的 14 位订单号',
		'Consignee'					: '请输入订单的收货人姓名',
		'Code'					: '输入上图中的数字，若无法辨别请点击图片更换。'
	};
	// 提交信息时验证
	this.checkAll = function ()
	{
		this.passed = true;
		for ( var i = 0; i < this.checkItems.length; i ++ )
		{
			obj = document.getElementById ( "tip" + this.checkItems[i] );
			if ( obj.className != this.className[2] )
			{
				var check = eval ( "this.check" + this.checkItems[i] + "()" );
				if ( check == 'checking' )
				{
					this.passed = false;
				}
				else
				{
					this.passed = this.passed && check;
				}
			}
		}
		return this.passed;
	}

	// 显示所有提示
	this.showAllTips = function ()
	{
		for ( var i in this.checkItems )
		{
			var obj;
			if ( obj = document.getElementById( 'tip' + this.checkItems[i] ) )
			{
				obj.innerHTML = eval ( "this.messages." + this.checkItems[i] );
			}
		}
	}

	this.showTip = function ( chkItem, tipType, message )
	{
		var obj;
		if ( obj = document.getElementById ( 'tip' + chkItem ) )
		{
			if ( tipType == null ) tipType = 0;
			if ( message == null ) message = eval ( "this.messages." + chkItem );
			obj.style.display = "block";
			if ( tipType > 0 || obj.className != this.className[2] || obj.className == '' )
			{
				obj.innerHTML = message;
				obj.className = this.className[tipType];
			}
		}
	}
	
	this.hideTip = function ( chkItem )
	{
		var obj;
		if ( obj = document.getElementById ( 'tip' + chkItem ) )
		{
			if ( obj.className != this.className[2] )
			{
				obj.style.display = "none";
			}
		}
	}

	this.checkOrderNo = function()
	{
		var message = '';
		var textbox = document.getElementById("txtOrderNo");
		if ( textbox.value.length == 0 || textbox.value.length != 14)
		{
			message = "请输入您要查询的 14 位订单号";
		}
		else if(!Edward.Web.Validator.IsNumber(textbox.value))
		{
			message = "您输入的订单号格式错误";
		}
		if ( message != '' )
		{
			this.showTip ( 'OrderNo', 1, message );
			return false;
		}
		else
		{
            this.showTip ( 'OrderNo', 2, '填写正确' );
            return true;
		}
		
		return true;
	}
	
	this.checkConsignee = function()
	{
		var message = '';
		var textbox = document.getElementById("txtConsignee");
		if ( textbox.value.length == 0 )
		{
			message = "请输入订单的收货人姓名";
		}
		if ( message != '' )
		{
			this.showTip ( 'Consignee', 1, message );
			return false;
		}
		else
		{
            this.showTip ( 'Consignee', 2, '填写正确' );
            return true;
		}
		return true;
	}

	this.checkCode = function()
	{
		var textbox = document.getElementById("txtCode");
		if ( textbox.value.length == 0 )
		{
			this.showTip ( 'Code', 1, "请填写验证码" );
			return false;
		}
		else
		{
		    var result = Orders_Query.GetVerifyCode().value;
            if ( textbox.value != result )
            {
	            this.showTip ( 'Code', 1, '验证码不正确, 请检查并重新填写' );
                return false;
            }
            else
            {
	            this.showTip ( 'Code', 2, '填写正确' );
                return true;
            }
		}
	}
	
	this.changeVerifyCode = function()
    {
	    var obj = document.getElementById ( 'imgVerifyCode' );
	    if ( obj )
	    {
		    obj.style.visibility = 'visible';
		    obj.src = 'Resources/VerifyCode.aspx';
	    }
    }
}
