1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
|
/* Generated Date : 2010-07-20 */
var sArr = [
{txt:'',val:''},
{txt:'Database name',val:'1'},
{txt:'ID number of trait',val:'2'},
{txt:'Symbol, Gene, Phenotype',val:'3'},
{txt:'Chr and Mb',val:'4'},
{txt:'LRS or LOD',val:'5'},
{txt:'Mean Value',val:'6'}
];
var gArr = [
{txt:'',val:''},
{txt:'Database name',val:'1'},
{txt:'ID number of trait',val:'2'},
{txt:'Symbol, Gene, Phenotype',val:'3'},
{txt:'Chr and Mb',val:'4'},
{txt:'LRS or LOD',val:'5'},
{txt:'Mean Value',val:'6'}];
var tArr = [
{txt:'',val:''},
{txt:'Database name',val:'1'},
{txt:'ID number of trait',val:'2'},
{txt:'Symbol, Gene, Phenotype',val:'3'},
{txt:'Chr and Mb',val:'4'},
{txt:'LRS or LOD',val:'5'},
{txt:'Mean Value',val:'6'}];
var lArr = [
null,
[1,2,3],
[1,2,4],
[1,2,5],
[1,2,6],
[1,3,2],
[1,3,4],
[1,3,5],
[1,3,6],
[1,4,2],
[1,4,3],
[1,4,5],
[1,4,6],
[1,5,2],
[1,5,3],
[1,5,4],
[1,5,6],
[1,6,2],
[1,6,3],
[1,6,4],
[1,6,5],
[2,1,3],
[2,1,4],
[2,1,5],
[2,1,6],
[2,3,1],
[2,3,4],
[2,3,5],
[2,3,6],
[2,4,1],
[2,4,3],
[2,4,5],
[2,4,6],
[2,5,1],
[2,5,3],
[2,5,4],
[2,5,6],
[2,6,1],
[2,6,3],
[2,6,4],
[2,6,5],
[3,1,2],
[3,1,4],
[3,1,5],
[3,1,6],
[3,2,1],
[3,2,4],
[3,2,5],
[3,2,6],
[3,4,1],
[3,4,2],
[3,4,5],
[3,4,6],
[3,5,1],
[3,5,2],
[3,5,4],
[3,5,6],
[3,6,1],
[3,6,2],
[3,6,4],
[3,6,5],
[4,1,2],
[4,1,3],
[4,1,5],
[4,1,6],
[4,2,1],
[4,2,3],
[4,2,5],
[4,2,6],
[4,3,1],
[4,3,2],
[4,3,5],
[4,3,6],
[4,5,1],
[4,5,2],
[4,5,3],
[4,5,6],
[4,6,1],
[4,6,2],
[4,6,4],
[4,6,5],
[5,1,2],
[5,1,3],
[5,1,4],
[5,1,6],
[5,2,1],
[5,2,3],
[5,2,4],
[5,2,6],
[5,3,1],
[5,3,2],
[5,3,4],
[5,3,6],
[5,4,1],
[5,4,2],
[5,4,3],
[5,4,6],
[5,6,1],
[5,6,2],
[5,6,3],
[5,6,4],
[6,1,2],
[6,1,3],
[6,1,4],
[6,1,5],
[6,2,1],
[6,2,3],
[6,2,4],
[6,2,5],
[6,3,1],
[6,3,2],
[6,3,4],
[6,3,5],
[6,4,1],
[6,4,2],
[6,4,3],
[6,4,5],
[6,5,1],
[6,5,2],
[6,5,3],
[6,5,4]];
/*
* input: selectObjId (designated select menu, such as sort1, sort2, etc... )
* function: setting options value for select menu dynamically based on linkage array(lArr)
* output: null
*/
function fillOptions(selectObjId)
{
if(selectObjId==null)
{
var sort1Obj = document.getElementsByName('sort1')[0];
var len = sArr.length;
for (var i=1; i < len; i++) {
// setting sort1' option
sort1Obj.options[i-1] = new Option(sArr[i].txt, sArr[i].val);
}
fillOptions('sort1');
}else if(selectObjId=='sort1')
{
var sort1Obj = document.getElementsByName('sort1')[0];
var sort2Obj = document.getElementsByName('sort2')[0];
var len = lArr.length;
var arr = [];
var idx = 0;
for (var i=1; i < len; i++) {
//get sort2 info from lArr
if(lArr[i][0]==(getIndexByValue('sort1',sort1Obj.value)).toString()&&!Contains(arr,lArr[i][1]))
{
arr[idx++]=lArr[i][1];
}
}
idx=0;
len = arr.length;
removeOptions("sort2");
for (var i=0; i < len; i++) {
// setting sort2's option
sort2Obj.options[idx++] = new Option(gArr[arr[i]].txt, gArr[arr[i]].val);
}
fillOptions('sort2');
}else if(selectObjId=='sort2')
{
var sort1Obj = document.getElementsByName('sort1')[0];
var sort2Obj = document.getElementsByName('sort2')[0];
var sort3Obj = document.getElementsByName('sort3')[0];
var len = lArr.length;
var arr = [];
var idx = 0;
for (var i=1; i < len; i++) {
//get sort2 info from lArr
if(lArr[i][0]==(getIndexByValue('sort1',sort1Obj.value)).toString()&&lArr[i][1]==(getIndexByValue('sort2',sort2Obj.value)).toString()&&!Contains(arr,lArr[i][2]))
{
arr[idx++]=lArr[i][2];
}
}
idx=0;
len = arr.length;
removeOptions("sort3");
for (var i=0; i < len; i++) {
// setting sort3's option
sort3Obj.options[idx++] = new Option(tArr[arr[i]].txt, tArr[arr[i]].val);
}
fillOptions('sort3');
}
}
/*
* input: arr (targeted array); obj (targeted value)
* function: check whether targeted array contains targeted value or not
* output: return true, if array contains targeted value, otherwise return false
*/
function Contains(arr,obj) {
var i = arr.length;
while (i--) {
if (arr[i] == obj) {
return true;
}
}
return false;
}
updateChocie();
/*
* input: selectObj (designated select menu, such as sort1, sort2, etc... )
* function: clear designated select menu's option
* output: null
*/
function removeOptions(selectObj) {
if (typeof selectObj != 'object'){
selectObj = document.getElementsByName(selectObj)[0];
}
var len = selectObj.options.length;
for (var i=0; i < len; i++) {
// clear current selection
selectObj.options[0] = null;
}
}
/*
* input: selectObjId (designated select menu, such as sort1, sort2, etc... )
* Value: target value
* function: retrieve Index info of target value in designated array
* output: index info
*/
function getIndexByValue(selectObjId,val)
{
if(selectObjId=='sort1')
{
for(var i=1;i<sArr.length;i++)
if(sArr[i].val==val)
return i;
}else if(selectObjId=='sort2')
{
for(var i=1;i<gArr.length;i++)
if(gArr[i].val==val)
return i;
}else if(selectObjId=='sort3')
{
for(var i=1;i<tArr.length;i++)
if(tArr[i].val==val)
return i;
}
else return;
}
function setDefault(thisform){
setCookie('cookieTest', 'cookieTest', 1);
var cookieTest = getCookie('cookieTest');
delCookie('cookieTest');
if (cookieTest){
var defaultSort1 = thisform.sort1.value;
setCookie('defaultSort1', defaultSort1, 10);
var defaultSort2 = thisform.sort2.value;
setCookie('defaultSort2', defaultSort2, 10);
var defaultSort3 = thisform.sort3.value;
setCookie('defaultSort3', defaultSort3, 10);
updateChocie();
}
}
/*
* input: objId (designated select menu, such as sort1, sort2, etc... )
* val(targeted value)
* function: setting option's selected status for designated select menu based on target value, also update the following select menu
* output: return true if selected status has been set, otherwise return false.
*/
function setChoice(objId,val)
{
var Obj = document.getElementsByName(objId)[0];
var idx=-1;
for(i=0;i<Obj.options.length;i++){
if(Obj.options[i].value==val){
idx=i;
break;
}
}
if(idx>=0){
//setting option's selected status
Obj.options[idx].selected=true;
//update the following select menu
fillOptions(objId)
return true;
}else{
return false;
}
}
// setting option's selected status based on default setting or cookie setting for sort1, sort2, and sort3 select menu
function updateChocie(){
fillOptions(null);
//define default value
var defaultSort1 = 1
var defaultSort2 = 3
var defaultSort3 = 4
//if cookie exists, then use cookie value, otherwise use default value
var cookieSort1 = getCookie('defaultSort1');
if(cookieSort1) defaultSort1= cookieSort1
var cookieSort2 = getCookie('defaultSort2');
if(cookieSort2) defaultSort2 = cookieSort2;
var cookieSort3 = getCookie('defaultSort3');
if(cookieSort3 ) defaultSort3 = cookieSort3;
//setting option's selected status
if(!setChoice('sort1',defaultSort1)){return;}
if(!setChoice('sort2',defaultSort2)){return;}
if(!setChoice('sort3',defaultSort3)){return;}
}
|