var TXT_BYTE = 1 ;
var TXT_CHAR = 2 ;

// 文本
function UICtrlText()
{
	// 抽象类
	if(arguments.length)
		alert('UICtrlText 作为抽象类，不应被实例化') ;
	return ;
}


UICtrlText.prototype = new UICtrlBase() ;

UICtrlText.prototype.UICtrlTextConstruct = function(Ctrl,UIName)
{
	this.UICtrlBaseConstruct(Ctrl,UIName) ;

	this.VDTxtType = TXT_BYTE ;
	
	this.RepeatTo = null ;
}


UICtrlText.prototype.VerifyData = function()
{
	if( !this.VerifyDataAdv() )
		return false ;
	
	Value = this.GetValue() ;
	
	// 检查重复栏位
	if( this.RepeatTo!=null && this.RepeatTo.GetValue()!=Value )
		return this.OnVDRepeatNomatch() ;
	
	// 检查长度
	return this.VerifyDataLen() ;
}

UICtrlText.prototype.GetValueLen = function()
{
	return (this.VDTxtType==TXT_BYTE)? this.GetStringByteLen(this.Ctrl.value): this.Ctrl.value.Length ;
}

// --- 校验数据 事件 ---

// 太短
UICtrlBase.prototype.OnVDTooShort = function( Len, VDMin )
{
	lenunit = (this.VDTxtType==TXT_BYTE)? '字节':'字符' ;	
	alert( this.UIName + '栏位不能小于' + VDMin + lenunit + ', 输入：'+ Len ) ;	
	return false ;
}

// 太长
UICtrlBase.prototype.OnVDTooLong = function( Len, VDMax )
{
	lenunit = (this.VDTxtType==TXT_BYTE)? '字节':'字符' ;	
	alert( this.UIName + '栏位不能大于' + VDMax + lenunit + ', 输入：'+ Len ) ;	
	return false ;
}

// 不能为空
UICtrlText.prototype.OnVDNotNull = function()
{
	alert( this.UIName + '栏位不允许为空。' ) ;
	return false ;
}

// 重复栏位不匹配
UICtrlText.prototype.OnVDRepeatNomatch = function()
{
	alert( '栏位：“' + this.UIName + '” 输入的内容与栏位：“'+ this.RepeatTo.UIName+'”必须一致' ) ;
	return false ;
}


UICtrlText.prototype.GetStringByteLen = function (str)
{
	if( typeof(str)!='string' )
		return 0 ;

	var len;
	var i;
	len = 0;
	for (i=0;i<str.length;i++)
	{
		if (str.charCodeAt(i)>255)
			len+=3;
		else
			len++;
	}
	return len;
}

UICtrlText.prototype.SetRepeatTo = function(RepeatTo)
{
	if( typeof(RepeatTo)!='object' || typeof(RepeatTo.GetValue)=='undefined' || typeof(RepeatTo.UIName)=='undefined' )
	{
		alert('UICtrlText::SetRepeatTo()必须传入的对象必须实现GetValue()方法') ;
		return false ;
	}
	
	old = this.RepeatTo ;
	this.RepeatTo = RepeatTo ;
	return old ;
}

UICtrlText.prototype.GetRepeatTo = function(RepeatTo)
{	
	return this.RepeatTo ;
}
