//=================================
//Document: filters.js
//Author: W.Onis
//Date: 17-12-2002
//=================================


//=================================
//Load data in array
//=================================
function Filter(fID,iName,iLink,iNextlevelname){
 this.filterid = fID;
 this.filtername = iName;
 this.filterlink = iLink;
 this.nextlevelname = iNextlevelname;
 }

//=================================
//Get parents
//=================================
function GetParents(iChild){
 for (var i=0;i<Filters.length;i++){
     if (Filters[i].filterid == iChild){
   arrParents[arrParents.length] = Filters[i].filterlink;
   GetParents(Filters[i].filterlink);
  }
 }
 return arrParents;//return array with parents of an element
}

//=================================
//Get Children
//=================================
function GetChildren(iParentID,iSelectedID){
  strChildren = '<select name="" onChange="RefreshMenu(this.value);" class="FilterListbox">\n';
   //set nextlevelname in selectbox
 for (i=0;i<Filters.length;i++){
  if (Filters[i].filterid == iParentID){
     strChildren = strChildren + '<option value=\''+ iParentID +'\'>'+Filters[i].nextlevelname+'</options>\n';
  }
 }
 //construct selectbox options
 for (var i=0;i<Filters.length;i++){
     if (Filters[i].filterlink == iParentID){
   if (Filters[i].filterid == iSelectedID){//show selected option
    strChildren = strChildren + '<option value='+Filters[i].filterid+' selected>'+Filters[i].filtername+'</options>\n';
   }
   else {
     strChildren = strChildren + '<option value='+Filters[i].filterid+'>'+Filters[i].filtername+'</options>\n';
   }
  }
 } 
  strChildren = strChildren + '</select>\n';
  return strChildren;
}

//=================================
//Has Children
//function to check if an element has children
//=================================
function HasChildren(iParentID){
 for (i=0;i<Filters.length;i++){
  if (Filters[i].filterlink == iParentID){
     return true;
  }
 }
}

//=================================
//Print dropdowns
//=================================
function PrintDropDowns(iParentArray,iLastDropDownSelection){
iParentArray.reverse();
strTmp = '';
 for (i=1;i<iParentArray.length;i++){
  if (iParentArray[i+1]){//if iParentArray[i+1] exists
   strTmp = strTmp + GetChildren(iParentArray[i],iParentArray[i+1]);
  }
  else {//last dropdown
   strTmp = strTmp + GetChildren(iParentArray[i],iLastDropDownSelection);
  }
 }
iParentArray.reverse();
return strTmp;
}

//=================================
//Refresh Menu
//=================================Falert
function RefreshMenu(iFilterID){
 if (iFilterID != '-'){
  arrParents = new Array;
  document.all.divDropDownBox.innerHTML = '';
  document.all.divDropDownBox.innerHTML = PrintDropDowns(GetParents(iFilterID),iFilterID);
  
  //print children selectbox
  if (HasChildren(iFilterID) == true){//show selectbox if there are children
   document.all.divDropDownBox.innerHTML += GetChildren(iFilterID);
  }
  else {//show start button if there are no children
   if (document.all.divDropDownBox.innerHTML.length > 0){
    document.all.divDropDownBox.innerHTML += '<input type="button" class="ListBoxButton" value="verder &raquo;" OnClick="document.location.href=\'index.aspx?ChapterID=' + ntb_int_StartChapterID + '&FilterID=' + iFilterID + '\';">';
   }
  }
 }
}