
// 菜单、 列表
function UICtrlMenu(Ctrl,UIName)
{
	// 被继承 而非实例化
	if(!arguments.length)
		return ;

	this.UICtrlMenuConstruct(Ctrl,UIName) ;
}

UICtrlMenu.prototype = new UICtrlBase() ;

// 构造函数
UICtrlMenu.prototype.UICtrlMenuConstruct = function(Ctrl,UIName)
{
	this.UICtrlBaseConstruct(Ctrl,UIName) ;	
	
	this.$bVDIgnoreEmpty = false ;
}


UICtrlMenu.prototype.SetValue = function(ValueStr)
{
	while(1)
	{
		idx = ValueStr.indexOf(',') ;
		if(idx<0)
		{
			Value = ValueStr ;
			ValueStr = '' ;
		}
		else
		{
			Value = ValueStr.slice (idx) ;
			ValueStr = ValueStr.slice (idx+1) ;
		}
		
		for(var idx=0;idx<this.Ctrl.options.length;idx++)
		{
			if( this.Ctrl.options[idx].value==Value )
			{
				this.Ctrl.options[idx].selected = true ;
				if( typeof(this.Ctrl.multiple)=='undefined' || !this.Ctrl.multiple )
					break ;
			}
			else
				this.Ctrl.options[idx].selected = false ;
				
		}
		
		if(ValueStr.length==0)
			break ;
	}
}

UICtrlMenu.prototype.GetValue = function()
{
	if( this.Ctrl.multiple )
	{
		Ret = '' ;
		for(var idx=0;idx<this.Ctrl.options.length;idx++)
		{
			if(this.Ctrl.options[idx].selected)
			{
				if(Ret.length)
					Ret+="," ;
				Ret+= this.Ctrl.options[idx].value ;
			}
		}
		
		return Ret ;
	}
	else
		return this.Ctrl.selectedIndex<0? '': this.Ctrl.options[this.Ctrl.selectedIndex].value ;
}

UICtrlMenu.prototype.GetValueLen = function()
{
	len = 0 ;
	for(var idx=0;idx<this.Ctrl.options.length;idx++)
	{
		// 忽略空值选项
		if( this.bVDIgnoreEmpty && this.Ctrl.options[idx].value=='' )
			continue ;

		if(this.Ctrl.options[idx].selected)
		{
			len ++ ;
			if( !this.Ctrl.multiple )
				break ;
		}
	}
	
	return len ;
}

UICtrlMenu.prototype.VerifyData = function()
{
	if( !this.VerifyDataAdv() )
		return false ;

	return this.VerifyDataLen() ;
}


// --- 校验数据 事件 ---

// 太短
UICtrlMenu.prototype.OnVDTooShort = function( Len, VDMin )
{
	if(this.Ctrl.multiple)
	{
		alert( this.UIName + '栏位最少只能选择' + VDMin + '项, 已选：'+ Len ) ;	
		return false ;
	}
	else
		return this.OnVDNotNull() ;
}

// 太长
UICtrlMenu.prototype.OnVDTooLong = function( Len, VDMax )
{
	alert( this.UIName + '栏位最多只能选择' + VDMax + '项, 已选：'+ Len ) ;	
	return false ;
}

// 不能为空
UICtrlMenu.prototype.OnVDNotNull = function()
{
	alert( '请选择' + this.UIName + '，此栏位不允许为空' ) ;
	return false ;
}

UICtrlMenu.prototype.InsertItem = function(Txt,Value)
{
	this.AddOpt(Txt,Value) ;
}
UICtrlMenu.prototype.AddOpt = function(Txt,Value,bSel)
{
	if( typeof(Value)=='undefined' )
		Value = '' ;
	if( typeof(bSel)=='undefined' )
		bSel = false ;

	opt = new Option(Txt,Value) ;
	opt.selected = bSel ;
	this.Ctrl.options[ this.Ctrl.options.length ] = opt ;
}
