JsLoader.AddScript("http://www.925.com.tw/shop/public/js/category.js?t=1730427861"); JsLoader.Load(); 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(); var run_time = 0; var max_time = 10; //--------------------------------------------------------------------------------------------------- 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{ if( run_time < max_time ){ run_time ++; window.setTimeout( function(){ TopicDisplay(div_name, oName); } , 100); }else{ return false; } } } function Init_Sel(defName){ var obj = document.getElementById( defName + "1" ); for( var i in MainTopic ){ if( MainTopic[i][0] == 0){ if( !TopicIsInHidden(i) ){ obj.length ++; obj.options[ (obj.length-1) ] = new Option( MainTopic[i][1], i); } } } } //--------------------------------------------------------------------------------------------------- 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 ){ 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(i) ){ next.length ++; next.options[ (next.length-1) ] = new Option( MainTopic[i][1], i); } 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; } if( MainTopic[v][0] != 0){ n = SetTopicValue( MainTopic[v][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; }