var MainTopic = new Array(); MainTopic["6@"] = [0, "Tactile Perception"]; MainTopic["7@"] = [0, "Motor Skills Development"]; MainTopic["46@"] = [0, "Fine Motor Skills"]; MainTopic["8@"] = [0, "Balance Co-ordination"]; MainTopic["9@"] = [0, "Creative Play Interaction"]; MainTopic["10@"] = [0, "Let\'s Play Ball"]; MainTopic["11@"] = [0, "Weplay Trikes"]; MainTopic["2@"] = [0, "Education Products"]; MainTopic["30@"] = [0, "USER\'S GUIDE"]; MainTopic["31@"] = [30, "Tactile Perception"]; MainTopic["32@"] = [30, "Motor Skills Development"]; MainTopic["33@"] = [30, "Balance Co-ordination"]; MainTopic["34@"] = [30, "Creative Play Interaction"]; MainTopic["35@"] = [30, "Let\'s Play Ball"]; MainTopic["36@"] = [30, "Weplay Trikes"]; MainTopic["37@"] = [30, "Education Products"]; var MainTopic_level = 2; var DEF_NAME = "MT"; var DEF_FIRST_OPTION = true; var DEF_TEXT = "請選擇"; var DEF_TEXT_ARR = new Array(); var DEF_FUNC = ""; var DEF_FUNC_ARR = new Array(); var DEF_SIZE = 1; var DEF_STYLE = ""; var AUTO_SEL = true; var HIDDEN_VALUE = new Array(); //--------------------------------------------------------------------------------------------------- function GetDefDataByName(name, val){ return ( eval("typeof(" + name + "_" + val + ")") != "undefined" )? eval(name + "_" + val ) : eval("DEF_" + val); } function TopicDisplay(div_name, oName){ var defName = ( oName )? oName : DEF_NAME; var FIRST_OPTION = GetDefDataByName(defName, "FIRST_OPTION"); var TEXT = GetDefDataByName(defName, "TEXT"); var TEXT_ARR = GetDefDataByName(defName, "TEXT_ARR"); var FUNC = GetDefDataByName(defName, "FUNC"); var FUNC_ARR = GetDefDataByName(defName, "FUNC_ARR"); var SIZE = GetDefDataByName(defName, "SIZE"); var STYLE = GetDefDataByName(defName, "STYLE"); if( typeof(MainTopic_level) != "undefined" ){ if( div_name && MainTopic_level > 0 ){ var div = document.getElementById(div_name); if( div == null ) return false; var write = ""; for(var i=1; i <= MainTopic_level; i++){ write += "\n"; } div.innerHTML = write; Init_Sel(defName); }else return false; }else return false; } function Init_Sel(defName){ var obj = document.getElementById( defName + "1" ); for( var i in MainTopic ){ if( MainTopic[i][0] == 0){ var NID = i.substring(0, (i.length-1)); if( !TopicIsInHidden(NID) ){ obj.length ++; obj.options[ (obj.length-1) ] = new Option( MainTopic[i][1], NID); } } } } //--------------------------------------------------------------------------------------------------- function TopicMakeData(now, flag, defName){ var obj = document.getElementById( defName + now ); var next = document.getElementById( defName + (parseInt(now)+1).toString() ); var FIRST_OPTION = GetDefDataByName(defName, "FIRST_OPTION"); var TEXT = GetDefDataByName(defName, "TEXT"); var TEXT_ARR = GetDefDataByName(defName, "TEXT_ARR"); if( flag ) //依AUTO_SEL 決定是否自動選擇 var do_sel = AUTO_SEL; else //不選擇 var do_sel = false; if( obj && next ){ if( obj.value != "" ){ next.length = 0; var p = parseInt(obj.value); var found = true; for( var i in MainTopic ){ var NID = i.substring(0, (i.length-1)); if( MainTopic[i][0] == p){ if( FIRST_OPTION && found ){ next.length ++; if( TEXT_ARR.length >= now && TEXT_ARR[now] ) next.options[ (next.length-1) ] = new Option( TEXT_ARR[now], ""); else next.options[ (next.length-1) ] = new Option( TEXT, ""); } if( !TopicIsInHidden( NID) ){ next.length ++; next.options[ (next.length-1) ] = new Option( MainTopic[i][1], NID); } if( found ){ if( do_sel ) next.options[ (next.length-1) ].selected = true; found = false; } } } }else{ next.length = 0; } } } function TopicSelData(now, defName){ TopicMakeData(now, true, defName); if( now < MainTopic_level ){ TopicSelData( (now+1), defName ); } } function SetTopicValue(v, n, oName, func_start){ var defName = ( oName )? oName : DEF_NAME; var FUNC = GetDefDataByName(defName, "FUNC"); var FUNC_ARR = GetDefDataByName(defName, "FUNC_ARR"); if(!n) n = 1; if( v == 0 ){ //重設資料時 var obj = document.getElementById( defName + "1" ); obj.selectedIndex = 0; TopicSelData(1, defName); return false; } RID = v + "@"; if( MainTopic[RID][0] != 0){ n = SetTopicValue( MainTopic[RID][0], n, oName ); } var obj = document.getElementById( defName + n ); var func = ""; for(var i=0; i < obj.options.length; i++){ if( obj.options[i].value == v){ //obj.options[i].selected; obj.selectedIndex = i; TopicMakeData(n, false, defName); if( func_start == true ){ func = ""; if( FUNC_ARR.length >= n && FUNC_ARR[(n-1)] ){ func = FUNC_ARR[(n-1)]; }else if(FUNC != ""){ func = FUNC; } if( func != "" ){ eval(func); } } break; } } return (n+1); } function TopicIsInHidden(id){ var flag = false; if( HIDDEN_VALUE.length > 0 ){ for(var i=0; i < HIDDEN_VALUE.length; i++){ if( HIDDEN_VALUE[i] == id){ flag = true; break; } } } return flag; } //--------------------------------------------------------------------------------------------------- function SetTopicHidden(val){ //增加 隱藏不顯示的資料 if( !TopicIsInHidden(val) ){ HIDDEN_VALUE[ HIDDEN_VALUE.length ] = val; } } function SetAutoSel(val){ //設定是否自動選擇資料 請於TopicDisplay前設定 AUTO_SEL = val; } function IsSelectChild(oName){ //是否已選擇資料 var defName = ( oName )? oName : DEF_NAME; var FIRST_OPTION = GetDefDataByName(defName, "FIRST_OPTION"); var have_first = (FIRST_OPTION)? 1 : 0; for(var i=1; i <= MainTopic_level; i++){ var obj = document.getElementById( defName + i); if( obj.length > 0 ){ if( obj.selectedIndex < have_first ){ return false; break; } } } return true; } function getTopicValue(oName){ //取得目前選擇的Topic的值 var defName = ( oName )? oName : DEF_NAME; var FIRST_OPTION = GetDefDataByName(defName, "FIRST_OPTION"); var val = 0; var have_first = (FIRST_OPTION)? 1 : 0; for(var i=1; i <= MainTopic_level; i++){ var obj = document.getElementById( defName + i); if( obj.length > 0 ){ if( obj.selectedIndex >= have_first ){ val = obj.value; } } } return val; }