//------------------------------------------------
// eliminate elements in ArrID from the array Arr
//------------------------------------------------ 
function Eliminate(Arr,ArrID,ArrInd) 
{
	var ArrNew = new Array();
	var j=0;
	var Cond='';
	for (i=0; i<Arr.length;i++)
	{
		Cond =  '1==1 ';
		// build condition 
		for (k=0;k<ArrID.length;k++)
		{
		if (!ArrID[k]) ArrID[k]=0;
		Cond +=  ' && Arr['+i+']['+ArrInd[k]+'] == '+ArrID[k];
		}
        //alert(Cond);
		if ( eval(Cond) ) {ArrNew[j]=Arr[i];j++;}
	}
	return ArrNew;
}
//------------------------------------------------
// Build a list if I have its elements
//------------------------------------------------
function BuildList (SelectName, Arr, indOptionValue, indOptionView, Selected,WithEmpty,OnChange,DivID) 
{
  var Old,str;
  str = "<select name="+SelectName+" onchange="+OnChange+" >";
  if ( WithEmpty == 'Yes') str +="<option value='' >------ÅÎÊÑ-----</option>";
  for (i = 0; i < Arr.length; i++) 
  {
  	if (Selected==Arr[i][indOptionValue]) selected='SELECTED=SELECTED'; else  selected='';
  	if (Old!=Arr[indOptionValue])
  	{
    str += "<option value="+Arr[i][indOptionValue]+" "+selected+">"+Arr[i][indOptionView]+"</option>";
    Old=Arr[i][indOptionValue];
  	}
  }
  str += "</select> *";
  //alert(str);
  document.getElementById(DivID).innerHTML= str;
}
//------------------------------------------------
// Build whole the tree
//------------------------------------------------
function BuildLevels(L1ID,L2ID,Module)
{
oF = document.form1;

BuildList(SelectName     = Module+"Level1ID", 
          Arr            = CellLevel1, 
          indOptionValue = 0, 
          indOptionView  = 1, 
          Selected       = L1ID,
          WithEmpty      = "Yes",
          OnChange       = "BuildLevels(L1ID=oF."+Module+"Level1ID.value,L2ID=\'\',Module)",
          DivID          = "L1" );
CellLevel2_Updated       = eval("Eliminate(Arr=CellLevel2,Array(oF."+Module+"Level1ID.value),Array(\"1\"));");
if (document.getElementById('L2'))
	{
	BuildList(SelectName     = Module+"Level2ID", 
	          Arr            = CellLevel2_Updated, 
	          indOptionValue = 0, 
	          indOptionView  = 2, 
	          Selected       = L2ID,
	          WithEmpty      = "Yes",
	          OnChange       = "BuildLevels(L1ID=oF."+Module+"Level1ID.value,L2ID=oF."+Module+"Level2ID.value,Module)",
	          DivID          = "L2");
	}
if (document.getElementById('L3'))
	{
	CellLevel3_Updated       = eval("Eliminate(Arr=CellLevel3,Array(oF."+Module+"Level1ID.value,oF."+Module+"Level2ID.value),Array(\"1\",\"2\"));");
	BuildList(SelectName     = Module+"Level3ID", 
	          Arr            = CellLevel3_Updated, 
	          indOptionValue = 0, 
	          indOptionView  = 3, 
	          Selected       = "",
	          WithEmpty      = "Yes",
	          OnChange       = "",
	          DivID          ="L3");
	}
	
	
	
	
if (document.getElementById('IsLoaded'))	
	document.getElementById('IsLoaded').style.display='';
if (document.getElementById('Waiting'))	
	document.getElementById('Waiting').style.display='none';
}