function select_clear(selectName,FirstOption) 
{

	var selectEle = document.all(selectName) ;
	var i = 0 ;
	while(1 < selectEle.length)
	{
		selectEle.options[selectEle.length - 1] = null ;
	}
	if (FirstOption != null && FirstOption.length > 0)
	{
		selectEle.options[0] =  new Option(FirstOption,"") ;
	}
	else
	{
		selectEle.options[0] = null ;
	}

}
function selectAll(eleId)
{
	var Ele = document.all(eleId);
	if (Ele)
	{
		var i = 0 ;
		while (i < Ele.length)
		{
			Ele.options[i].selected = true ;
			i = i + 1 ;
		}

	}
}
function moveSelect(fromId,toId)
{
	var fromEle = document.all(fromId) ;
	var toEle = document.all(toId) ;
	while (fromEle.selectedIndex >= 0)
	{
		toEle.options[toEle.length] = new Option(fromEle.options[fromEle.selectedIndex].innerHTML,fromEle.options[fromEle.selectedIndex].value)
		fromEle.options[fromEle.selectedIndex] = null ;
	}
}
function RelationSelect(DateArray,ParentId,SonId,FirstOption,matchLen)
{


	var ParentValue = document.all(ParentId).value.toUpperCase() ;
	if (ParentValue.length == 0)
	{
		return ;
	}
	select_clear(SonId,FirstOption)
	var SonEle = document.all(SonId)
	var flag = true ;
	var flag2 = true ;
	var MaxLine = DateArray.length
	var i = 1
	while ( flag && i < MaxLine)
	{
		if (MatchString(DateArray[i][0].toUpperCase() , ParentValue , matchLen))
		{
			flag2 = false ;
			SonEle.options[SonEle.length] = new Option(DateArray[i][1],DateArray[i][2]) ; 
		}
		else
		{
			if (!flag2)
			{
				flag = false ;
			}
		}
		i = i + 1;

	}
}
function MatchString(string1,string2,matchLen)
{
	if (matchLen == null || isNaN(parseFloat(matchLen))  )
	{
		matchLen == -1 
	}
	if (matchLen >= 0 )
	{
		string1 = string1.substring(0,matchLen)
		string2 = string2.substring(0,matchLen)

	}
	
	if (string1.toUpperCase() == string2.toUpperCase())
	{
		return true ;
	}
	else
	{
		return false ;
	}

}
/*
'	功能名称	：relateSelect
'	功能简述	：用于完成WEB页面内容关联的SELECT控件重组
'	调用模块	：无
'	被调用模块	：生成/_inc/relationSelect.inc
'	说明		：减少数组参数创建次数。
'	缺点		：不能按照数据库实时变化更新列表，有待完善
'	程序员		：王炜佳
'	创建时间	：2008-06-06
'	修改时间	：无
'	修改记录	：无
*/
function relateSelect(className,listArray,parentId,relationId,relationValue,firstOption,matchLen)
{
	this.className = className 
	this.listArray = listArray 
	this.parentId = parentId 
	this.relationId = relationId
	this.matchLen = matchLen
	this.firstOption = firstOption
	this.onChange = relateSelect_onChange
	this.onChange() ;
	if (relationValue.length > 0)
	{
		document.all(relationId).value = relationValue ;
	}
	execScript ( "document.all('"+parentId+"').onchange = function(){" + className + ".onChange()}") ;

}
function relateSelect_onChange()
{
	RelationSelect(this.listArray,this.parentId,this.relationId,this.firstOption,this.matchLen)
}