function doChange(oField,hasParent) //默认取名规则:父下拉框名＝子下拉框名＋“Parent” 隐藏数据列表名＝子下拉框名＋“List”
{
  var field = oField.name;
  var formName = oField.form.name;
  var fieldSonName = field.substring(0,field.length-6);
  var oFieldSon = eval("document." + formName + "."+fieldSonName);
  var oList = eval( "document." + formName + "."+fieldSonName+"List");
  var code = oField.options[oField.selectedIndex].value;

  var tt=oList.value;
  var Funs=tt.split(",");
  oFieldSon.options.length=0;
  if ( code =="" );
    //oFieldSon.options [0]= new Option ("----- 请选择 -----" , "")
  else{
    j=0;
    for (var i=0; i< Funs.length; i++ ){
       var ww=Funs[i].toString().split("=");
      if ( Funs[i].substring(0,4)==code  ){
	  	  if(hasParent!=null&&hasParent==false&&ww[0].length==4)continue;
          oFieldSon.options [j]= new Option( ww[1], ww[0],false,false);
          j++;
      }
    }
  }
}

function deleteItem(oTarget){
  minselected=0;
  if ( oTarget != null ){
    for (i=oTarget.length-1; i>=0; i--){  
		if (oTarget.options[i].selected){ 
          if (minselected==0 || i<minselected)
            minselected=i;
            oTarget.options[i] = null;
       }
    }
    i=oTarget.length;

    if (i>0)  {
        if (minselected>=i)
           minselected=i-1;
        oTarget.options[minselected].selected=true;
    }
  }
}


function addItem(oField, oTarget, oCategory){   

  k=0;
   
  i = oField.options.length;
  if (i==0 )
    return;
  maxselected=0
  for (h=0; h<i; h++)
    if (oField.options[h].selected ) {
      k=k+1;
      maxselected=h+1;
  }
  if (maxselected>=i)
     maxselected=0;
  if (oTarget.length + k >5 ) {
    window.alert("最多可选择5条");
    return;
  }

  if ( oField != null && oTarget != null && oCategory != null ){ 
    jj = oCategory.selectedIndex;
    if ( oCategory != ""){ 
	  CatValue = oCategory.options[jj].text;
      CatCode  = oCategory.options[jj].value;
    }
    else
      CatValue = "";
	  
    i = oField.options.length;
    j = oTarget.options.length;
    for (h=0; h<i; h++){ 
	  if (oField.options[h].selected ){  
	    Code = oField.options[h].value;
        Text = oField.options[h].text;
          j = oTarget.options.length;
          if (Text.indexOf('--')!=-1) {
            for (k=j-1; k>=0; k-- ) {
              oTarget.options[k]=null;
            }
            j=0;
          }
          if (Code.length==4) {
            for (k=j-1; k>=0; k-- ) {
              if (((oTarget.options[k].value).substring(0,4))==(Code.substring(0,4)))
                oTarget.options[k]=null;
            }
            j= oTarget.options.length;
          }
          HasSelected = false;
          for (k=0; k<j; k++ ) {
            if ((oTarget.options[k].text).indexOf('--')!=-1){
            HasSelected = true;
            window.alert('已经包括本选项：'+Text);
            break;
          }else if ((oTarget.options[k].value).length==4 && ((oTarget.options[k].value).substring(0,4)==Code.substring(0,4))){
            HasSelected = true;
            window.alert('已经包括本选项：'+Text);
            break;
          }
          if (oTarget.options[k].value == Code){  
			HasSelected = true;
            break;
          }
        }
        if ( HasSelected == false){ 
		  if (oCategory !=""){ 
		    Location = getLocation(oTarget, CatValue);
            if ( Location == -1 ){ 
			  oTarget.options[j] =  new Option("---"+CatValue+"---",CatCode);
              oTarget.options[j+1] = new Option(Text, Code);
            }//if
            else{ 
			  InsertItem(DesObjID, Location+1);
              oTarget.options[Location+1] = new Option(Text, Code);
            }//else
          }
          else
            oTarget.options[j] = new Option(Text, Code);
			oTarget.options[j].selected=true;
        }//if
        oField.options[h].selected =false;
      }//if
    }//for
    oField.options[maxselected].selected =true;
  }//if
}//end of function

function getLocation(oField, catValue)
{ total=oField.length;
  for (pp=0; pp<total; pp++)
      if (oField.options[pp].text == "---"+catValue+"---")
      {  return (pp);
         break;
      }
  return (-1);
}

function selectTotal(oField)
{
  if (oField != null)
  { for (i=0; i<oField.length; i++)
      oField.options[i].selected = true;
  }
}
