if( typeof(Prototype)=='undefined' || typeof(Prototype.Version)=='undefined' || Prototype.Version != '1.5.0' )
{
	alert('未发现 prototype.js ，或并非 1.5.0 版本。网页上的功能可能存在问题。') ;
}

function UICtrlBase()
{
	// 抽象类
	if(arguments.length)
		alert('UICtrlBase 作为抽象类，不应被实例化') ;
	return ;
}

UICtrlBase.prototype.UICtrlBaseConstruct = function(Ctrl,UIName)
{
	if( typeof(Ctrl)=='undefined' )
		return ;

	if( typeof(Ctrl)=='string' )
		this.Ctrl = $(Ctrl) ;
	else
		this.Ctrl = Ctrl ;

	this.bIgnore = false ;

	this.bVDAllowEmpty = true ;
	this.VDMin = '*' ;
	this.VDMax = '*' ;


	if( typeof(UIName)!='undefined' )
		this.UIName = UIName ;

	else if( typeof(Ctrl.id)!='undefined' )
		this.UIName = Ctrl.id ;

	else
		this.UIName = '' ;

	this.bCanFocus = true ;
	
	this.BaseClass = 'UICtrlBase' ;
	
	this.arrVDAdvObs = new Array() ;
}

UICtrlBase.prototype.GetValue = function ()
{
	if(this.Ctrl)
		return this.Ctrl.value ;
	else 
		return '' ;
}

UICtrlBase.prototype.SetValue = function (Value)
{
	if(this.Ctrl)
		this.Ctrl.value = Value ;
}

UICtrlBase.prototype.GetValueLen = null ;

var VD_TOOLONG = 1 ;
var VD_TOOSHORT = 2 ;
var VD_NOTNULL = 3 ;
var VD_AVAILABLE = 0 ;
UICtrlBase.prototype.VerifyDataLen = function ()
{
	if( !this.GetValueLen )
	{
		alert('控件'+(this.UIName?this.UIName:this.Ctrl.id)+'没有实现UICtrlBase::GetValueLen() 方法') ;
		return 0 ;
	}
	
	len = this.GetValueLen() ;
	
	// 检查 不能为空
	if( len==0 )
	{
		if( this.bVDAllowEmpty )
			return true ;
		else
		{
			if( this.OnVDNotNull )
				return this.OnVDNotNull() ;
			else
				return false ;
		}
	}
	
	// 检查 太短
	if( this.VDMin!='*' && len<this.VDMin )
	{
		if( this.OnVDTooShort )
			return this.OnVDTooShort(len,this.VDMin) ;
		else
			return false ;
	}
	
	// 检查 太长
	if( this.VDMax!='*' && len>this.VDMax )
	{
		if( this.OnVDTooLong )
			return this.OnVDTooLong(len,this.VDMax) ;
		else
			return false ;
	}
	
	// 有效
	if( this.OnVDAvailable )
		return this.OnVDAvailable() ;
	else
		return true ;
}

UICtrlBase.prototype.VerifyDataAdv = function ()
{
	for(var idx=0;idx<this.arrVDAdvObs.length;idx++)
	{
		if( !this.OnAdvVerifyData(this.arrVDAdvObs[idx]) )
			return false ;
	}

	return true ;
}

UICtrlBase.prototype.AddVDAdvOb = function (VDAdvOb)
{
	this.arrVDAdvObs.push(VDAdvOb) ;
}



// --- 校验数据 事件 ---

// 有效
UICtrlBase.prototype.OnVDAvailable = null ;

// 太短
UICtrlBase.prototype.OnVDTooShort = null ;

// 太长
UICtrlBase.prototype.OnVDTooLong = null ;

// 不能为空
UICtrlBase.prototype.OnVDNotNull = null ;

// 高级数据检验
UICtrlBase.prototype.OnAdvVerifyData = function ( VDAdvOb, bAlert )
{
	if( typeof(bAlert)=='undefined' )
		bAlert = true ;

	outExcepAlertWord = '' ;
	if( VDAdvOb.VerifyData(this,outExcepAlertWord) )
		return true ;
	else
	{
		if(bAlert)
			alert(VDAdvOb.GetAlert()) ;
		return false ;
	}
}

UICtrlBase.prototype.ToggleIgnore = function()
{
	this.bIgnore = !this.bIgnore ;
}
UICtrlBase.prototype.SetIgnore = function(bIgnore)
{
	this.bIgnore = bIgnore ;
}

UICtrlBase.prototype.ToggleDisabled = function ()
{
	if(this.bCanFocus)
	{
		this.Ctrl.disabled = this.Ctrl.disabled ;
		this.bIgnore = !this.bIgnore ;
	}
}
UICtrlBase.prototype.SetDisabled = function (bDisabled)
{
	if(this.bCanFocus)
	{
		this.Ctrl.disabled = bDisabled ;
		this.bIgnore = bDisabled ;
	}
}
UICtrlBase.prototype.GetDisabled = function ()
{ return this.bCanFocus? this.Ctrl.disabled: true ; }
