// sObjListID1-源选择框一
// sObjListID2-源选择框二
// tObjListID-目标列表框
// limit-允许向目标列表框添加的项数
// combtype-文本组合类型
// joinchar-连接字符
//hObjValueID-隐藏表单
function AddItemToList(sObjListID1, sObjListID2, tObjListID, limit, combtype, joinchar, hObjValueID)
{
    var sObjList1, sObjList2, tObjList, selectedItem;
    sObjList1 = document.getElementById(sObjListID1);
    sObjList2 = document.getElementById(sObjListID2);
    tObjList  = document.getElementById(tObjListID);
    hObjValue = document.getElementById(hObjValueID);
    
    if( sObjList1 != null && sObjList2 != null && tObjList != null )
    {
        if( sObjList1.selectedIndex >= 0 && sObjList2.selectedIndex >= 0)
        {
            if( tObjList.length < limit || limit == 0 )
            {
                selectedList = sObjList1.options[sObjList1.selectedIndex];
                selectedItem = sObjList2.options[sObjList2.selectedIndex];
                for( i=0; i<tObjList.length; i++ )
                {
                    if( tObjList.options[i].value == selectedList.value+"-"+selectedItem.value )
                    {
                        alert("已经选择有该项！");
                        return;
                    }
                    else if( selectedItem.value.indexOf(tObjList.options[i].value)==0 )
                    {
                        alert("已经选择了该类不限！");
                        return;
                    }
                    else if( tObjList.options[i].value.indexOf(selectedItem.value)==0 )
                    {
                        alert("与已经选择的项有冲突！");
                        return;
                    }
                }
                switch( combtype )
                {
                case 1:// 组合一级类别和二级类别名显示
                    if(selectedList.value == selectedItem.value)
					  tObjList.options[tObjList.length] = new Option(selectedItem.text,selectedList.value+"-"+selectedItem.value);
                    else
                      tObjList.options[tObjList.length] = new Option(selectedList.text + joinchar + selectedItem.text.replace("- ", ""),selectedList.value+"-"+selectedItem.value);
                    tObjList.options[tObjList.length-1].selected = true;
                    break;
                case 2:// 显示二级类别名
                    tObjList.options[tObjList.length] = new Option(selectedItem.text.replace("- ", ""), selectedList.value+"-"+selectedItem.value);
					tObjList.options[tObjList.length-1].selected = true;
					if (document.getElementById('txt_WishJobName').value == "")
					    
					    document.getElementById('txt_WishJobName').value = selectedItem.text.replace("- ", "");
					break;
	            case 3: // 显示二级类别名
	                tObjList.options[tObjList.length] = new Option(selectedItem.text.replace("- ", ""), selectedList.value + "-" + selectedItem.value);
	                tObjList.options[tObjList.length - 1].selected = true;
	                 break;
                }
                
                hObjValue.value = "";
				for( i=0; i<tObjList.options.length; i++)
				{
					if(tObjList.options[i].selected == true)
						hObjValue.value += tObjList.options[i].value + "|";
				}
				//hObjValue.value = hObjValue.value.substring(1);
            }
            else
            {
                alert("最多只能添加" + limit + "项！");
            }
        }
        else
        {
			alert("请选择要添加的项！");
        }
    }
}


function DeleteListSelectedItem(objListID, reserves, hObjValueID)
{
    var objList;
    objList = document.getElementById(objListID);
    hObjValue = document.getElementById(hObjValueID);
    
    if( objList != null )
    {
        if( objList.selectedIndex >= 0 )
        {
            if( objList.length > reserves ) {
				objList.options[objList.selectedIndex] =null;
				hObjValue.value = "";
				for( i=0; i<objList.options.length; i++) {
				    objList.options[i].selected = true;
					if(objList.options[i].selected == true)
						hObjValue.value += objList.options[i].value + "|";
				}
            }
            
        }
        else
        {
			alert("请选择要移除的项！");
        }
    }
}

// sObjListID2-源选择框二
// tObjListID-目标列表框
// limit-允许向目标列表框添加的项数
//hObjValueID-隐藏表单
function AddListItemToList(sObjListID2, tObjListID, limit,hObjValueID)
{
    var sObjList2, tObjList, selectedItem, hObjValue;
    sObjList2 = document.getElementById(sObjListID2);
    tObjList  = document.getElementById(tObjListID);
    hObjValue = document.getElementById(hObjValueID);
    
    if( sObjList2 != null && tObjList != null )
    {
        if( sObjList2.selectedIndex >= 0)
        {
            if( tObjList.length < limit || limit == 0 )
            {
                selectedItem = sObjList2.options[sObjList2.selectedIndex];
                for( i=0; i<tObjList.length; i++ )
                {
                    if( tObjList.options[i].value == selectedItem.value )
                    {
                        alert("已经选择有该项！");
                        return;
                    }
                }
                tObjList.options[tObjList.length] = new Option(selectedItem.text, selectedItem.value);
				tObjList.options[tObjList.length-1].selected = true;
				
				hObjValue.value = "";
				for( i=0; i<tObjList.options.length; i++)
				{
					if(tObjList.options[i].selected == true)
						hObjValue.value += tObjList.options[i].value + "|";
				}
				//hObjValue.value = hObjValue.value.substring(1);
            }
            else
            {
                alert("最多只能添加" + limit + "项！");
            }
        }
        else
        {
			alert("请选择要添加的项！");
        }
    }
}