// JavaScript Document


function CurrentOptions( value, text ){ 
    this.value    = value; 
    this.text    = text; 
} 
 
catsArray = new Array(); 
var catsIndex = -1; 
var itemsIndex; 
var childItemsIndex; 
 
function NewCategory(){ 
    catsIndex++; 
    catsArray[ catsIndex ] = new Array(); 
    itemsIndex = -1; 
} 
 
function MenuBuild( value, text ) { 
    itemsIndex++; 
    catsArray[ catsIndex ][ itemsIndex ] = new Array(); 
    catsArray[ catsIndex ][ itemsIndex ].value = value; 
    catsArray[ catsIndex ][ itemsIndex ].text = text; 
    subItemsIndex = 0; 
} 
 
function SubMenuBuild( value, text ) { 
    catsArray[ catsIndex ][ itemsIndex ][ subItemsIndex ] = new Array();
    catsArray[ catsIndex ][ itemsIndex ][ subItemsIndex ].value = value; 
    catsArray[ catsIndex ][ itemsIndex ][ subItemsIndex ].text = text; 
    subItemsIndex++; 
} 

function ChildMenuBuild( value, text ) { 
    catsArray[ catsIndex ][ itemsIndex ][ subItemsIndex ] = new CurrentOptions( value, text ); 
    ChildItemsIndex++; 
} 
 
function updateDepartments( formName, optSelected ) { 
         for ( i = formName["select_b"].options.length-1; i > 0; i-- ) { 
             formName["select_b"].options[ i ] = null; 
         } 
         if (catsIndex>=optSelected){
            for ( i = 0; i < catsArray[ optSelected ].length; i++ ) { 
                formName["select_b"].options[ i ] = new Option( catsArray[ optSelected ][ i ].text, catsArray[ optSelected ][ i ].value); 
            } 
         }
         //formName["select_b"].options[ i ] = new Option("所有次類別","");
         formName["select_b"].options[ 0 ].selected = true;
         updateUsers(formName,0);
} 
 
function updateUsers( formName, optSelected ) { 
         var i;
         optFromRelate = formName["select_a"].selectedIndex; 
         if ( optFromRelate < 0) { 
             optFromRelate = 0; 
         } 
         for( i = formName["select_c"].options.length-1; i > 0; i-- ) { 
             formName["select_c"].options[ i ] = null;                // null out in reverse order (bug workarnd) 
         } 
         if (catsIndex>=optFromRelate){
            if (catsArray[ optFromRelate ].length>optSelected){
               for( i = 0; i < catsArray[ optFromRelate ][ optSelected ].length; i++ ) { 
                   formName["select_c"].options[ i ] = new Option( catsArray[ optFromRelate ][ optSelected ][ i ].text, catsArray[ optFromRelate ][ optSelected ][ i ].value ); 
               }
            }
         } 
         //formName["select_c"].options[ i ] = new Option("所有子類別","");
         formName["select_c"].options[ 0 ].selected = true;
} 













//------------------------------------------------------------------>
