1
2
3
4function open_window( page )
5{
6        var winoptions = "width=640,height=480,menubar=yes,scrollbars=yes,toolbar=yes,status=yes,location=yes,resizable=yes"
7        window.open(page,null,winoptions);
8
9}
10
11
12
13
14
15
16function show_hidden_help_top_button(help_flag)
17{
18	if(!isIE_or_Opera() || IE_version()==9)
19		Not_IE_show_hidden_help(help_flag);
20
21	else
22	{
23		var frame_height= top.document.getElementById("formframe_div").style.height.replace(/px/,"");
24		if( help_flag % 2 == 0 )
25		{
26			document.getElementById("main").style.height=frame_height-200;//50+30+120
27			document.getElementById("help").style.display="";
28			document.getElementById("help_switch").className="open_help";
29		}
30		else
31		{
32			document.getElementById("help").style.display="none";
33			document.getElementById("help_switch").className="close_help";
34			document.getElementById("main").style.height=frame_height-80;//50+30
35		}
36	}
37}
38
39function port_range_interception(port)
40{
41	port=parseInt(port,10);
42	return port;
43}
44
45function address_parseInt(addr)/*to fix bug 26258*/
46{
47	if( "" == addr )
48		return addr;
49
50	addr_array = addr.split(".");
51	for(i=0; i< 4; i++)
52	{
53		if( "" == addr_array[i] )
54			addr_array[i] = 0;
55		if( 0 == i )
56			addr = parseInt(addr_array[i], 10);
57		else
58			addr = addr + "." +parseInt(addr_array[i], 10);
59	}
60	return addr;
61}
62
63function mtu_change(wanpro)
64{
65	var cf=document.forms[0];//bug 23492:'wan_mtu_now' is a number not a string,so delete '"'
66	if (old_wan_type=="dhcp" && wan_mtu_now!=1500)
67	{	//bug 23546 [L2TP]L2TP MTU Should be 1428
68		if((wanpro=="pptp" && wan_mtu_now<1436) || (wanpro=="l2tp" && wan_mtu_now<1428) || (wanpro=="pppoe" && wan_mtu_now<1492) || (wanpro=="mulpppoe1" && wan_mtu_now<1454) || (wanpro=="bigpond" && wan_mtu_now<1500) || (wanpro=="3g" && wan_mtu_now<1448) || (wanpro=="lte" && wan_mtu_now<1486))
69			cf.hid_mtu_value.value=wan_mtu_now;
70		else
71			default_mtu(wanpro);
72	}
73	else if(old_wan_type=="pptp" && wan_mtu_now!=1436)
74	{
75		if((wanpro=="dhcp" && wan_mtu_now<1500) || (wanpro=="pppoe" && wan_mtu_now<1492) || (wanpro=="l2tp" && wan_mtu_now<1428) || (wanpro=="mulpppoe1" && wan_mtu_now<1454) || (wanpro=="bigpond" && wan_mtu_now<1500) || (wanpro=="3g" && wan_mtu_now<1448) || (wanpro=="lte" && wan_mtu_now<1486))
76			cf.hid_mtu_value.value=wan_mtu_now;
77		else
78			default_mtu(wanpro);
79	}
80	else if(old_wan_type=="pppoe" && wan_mtu_now!=1492)
81	{
82		if((wanpro=="dhcp" && wan_mtu_now<1500) || (wanpro=="pptp" && wan_mtu_now<1436) || (wanpro=="l2tp" && wan_mtu_now<1428) || (wanpro=="mulpppoe1" && wan_mtu_now<1454) || (wanpro=="bigpond" && wan_mtu_now<1500) || (wanpro=="3g" && wan_mtu_now<1448) || (wanpro=="lte" && wan_mtu_now<1486))
83			cf.hid_mtu_value.value=wan_mtu_now;
84		else
85			default_mtu(wanpro);
86	}
87	else if(old_wan_type=="mulpppoe1" && wan_mtu_now!=1454)
88	{
89		if((wanpro=="dhcp" && wan_mtu_now<1500) || (wanpro=="pptp" && wan_mtu_now<1436) || (wanpro=="l2tp" && wan_mtu_now<1428) || (wanpro=="pppoe" && wan_mtu_now<1492) || (wanpro=="bigpond" && wan_mtu_now<1500) || (wanpro=="3g" && wan_mtu_now<1448) || (wanpro=="lte" && wan_mtu_now<1486))
90			cf.hid_mtu_value.value=wan_mtu_now;
91		else
92			default_mtu(wanpro);
93	}
94	else if(old_wan_type=="bigpond" && wan_mtu_now!=1500)
95	{
96		if((wanpro=="dhcp" && wan_mtu_now<1500) || (wanpro=="pptp" && wan_mtu_now<1436) || (wanpro=="l2tp" && wan_mtu_now<1428) || (wanpro=="mulpppoe1" && wan_mtu_now<1454) || (wanpro=="pppoe" && wan_mtu_now<1492) || (wanpro=="3g" && wan_mtu_now<1448) || (wanpro=="lte" && wan_mtu_now<1486))
97			cf.hid_mtu_value.value=wan_mtu_now;
98		else
99			default_mtu(wanpro);
100	}
101	else if(old_wan_type=="static" && wan_mtu_now!=1500)
102	{
103		if((wanpro=="dhcp" && wan_mtu_now<1500) || (wanpro=="pptp" && wan_mtu_now<1436) || (wanpro=="l2tp" && wan_mtu_now<1428) || (wanpro=="mulpppoe1" && wan_mtu_now<1454) || (wanpro=="pppoe" && wan_mtu_now<1492) || (wanpro=="bigpond" && wan_mtu_now<1500) || (wanpro=="3g" && wan_mtu_now<1448) || (wanpro=="lte" && wan_mtu_now<1486))
104			cf.hid_mtu_value.value=wan_mtu_now;
105		else
106			default_mtu(wanpro);
107	}
108	else if(old_wan_type=="l2tp" && wan_mtu_now!=1428)
109	{
110		if((wanpro=="dhcp" && wan_mtu_now<1500) || (wanpro=="pptp" && wan_mtu_now<1436) || (wanpro=="mulpppoe1" && wan_mtu_now<1454) || (wanpro=="pppoe" && wan_mtu_now<1492) || (wanpro=="bigpond" && wan_mtu_now<1500) || (wanpro=="3g" && wan_mtu_now<1448) || (wanpro=="lte" && wan_mtu_now<1486))
111			cf.hid_mtu_value.value=wan_mtu_now;
112		else
113			default_mtu(wanpro);
114	}
115	else if(old_wan_type=="3g" && wan_mtu_now!=1448)
116	{
117		if((wanpro=="dhcp" && wan_mtu_now<1500) || (wanpro=="pptp" && wan_mtu_now<1436) || (wanpro=="l2tp" && wan_mtu_now<1428) || (wanpro=="mulpppoe1" && wan_mtu_now<1454) || (wanpro=="pppoe" && wan_mtu_now<1492) || (wanpro=="bigpond" && wan_mtu_now<1500) || (wanpro=="lte" && wan_mtu_now<1486))
118			cf.hid_mtu_value.value=wan_mtu_now;
119		else
120			default_mtu(wanpro);
121	}
122	else if(old_wan_type=="lte" && wan_mtu_now!=1486)
123	{
124		if((wanpro=="dhcp" && wan_mtu_now<1500) || (wanpro=="pptp" && wan_mtu_now<1436) || (wanpro=="l2tp" && wan_mtu_now<1428) || (wanpro=="mulpppoe1" && wan_mtu_now<1454) || (wanpro=="pppoe" && wan_mtu_now<1492) || (wanpro=="bigpond" && wan_mtu_now<1500) || (wanpro=="3g" && wan_mtu_now<1448))
125			cf.hid_mtu_value.value=wan_mtu_now;
126		else
127			default_mtu(wanpro);
128	}
129	else
130		default_mtu(wanpro);
131}
132
133function default_mtu(wanpro)
134{
135	var cf=document.forms[0];
136	if(wanpro=="pptp")
137		cf.hid_mtu_value.value="1436";
138	else if(wanpro=="pppoe")
139		cf.hid_mtu_value.value="1492";
140	else if(wanpro=="mulpppoe1")
141		cf.hid_mtu_value.value="1454";
142	else if(wanpro=="l2tp")
143		cf.hid_mtu_value.value="1428";
144	else if(wanpro=="lte")
145		cf.hid_mtu_value.value="1486";
146	else if(wanpro=="3g")
147		cf.hid_mtu_value.value="1448";
148	else
149		cf.hid_mtu_value.value="1500";
150}
151
152
153
154function check_RU_DNS(dnsaddr1,dnsaddr2,wan_assign,wan_ip)
155{
156	if(dnsaddr1!="")
157	{
158		if(checkipaddr(dnsaddr1)==false)
159		{
160			alert(bh_invalid_primary_dns);
161			return false;
162		}
163		if( wan_assign == true && isSameIp(dnsaddr1,wan_ip))
164		{
165			alert(bh_invalid_primary_dns);
166			return false;
167		}
168	}
169	if(dnsaddr2!="")
170	{
171		if(checkipaddr(dnsaddr2)==false)
172		{
173			alert(bh_invalid_second_dns);
174			return false;
175		}
176		if( wan_assign == true && isSameIp(dnsaddr2,wan_ip))
177		{
178			alert(bh_invalid_second_dns);
179			return false;
180		}
181	}
182
183	if(dnsaddr1=="" && dnsaddr2=="" )
184	{
185		alert(bh_dns_must_specified);
186		return false;
187	}
188	return true;
189}
190
191/*
192        Saturday, Jan 01, 2000 10:51:13
193*/
194function change_cur_time(old_str,gui_region)
195{
196        each_str=old_str.split(', ');
197
198        week=each_str[0];
199        show_week=change_full_week(week);
200
201        date_info=each_str[1].split(' ');
202        month=date_info[0];
203        show_month=change_month(month);
204        day=date_info[1];
205
206        time=each_str[2];
207
208        if( gui_region == "German" )
209                new_str = show_week+', '+day+'.'+show_month+', '+time;
210        else
211                new_str = show_week+', '+show_month+' '+day+', '+time;
212
213        return new_str;
214}
215
216
217
218/* input ip, if input length = 3 or input '.' , change focus to next text, */
219function SelectionTextLength(text)
220{
221	var select_text="";
222	if (document.selection&& document.selection.createRange)//IE
223		select_text=document.selection.createRange().text;
224	else if(select_text == "" && text.selectionStart != undefined )
225		select_text=text.value.substring(text.selectionStart,text.selectionEnd);
226	return select_text.length;
227}
228function keydown(e,text)
229{
230	if((e.keyCode == 190 || e.keyCode == 110) && text.value.length !=0 && SelectionTextLength(text)==0)
231		text.form[(getIndex(text)+1) % text.form.length].focus();
232}
233function keyup(e,text)
234{
235	if(text.value.length == 3 && ((e.keyCode >47 && e.keyCode <58) ||(e.keyCode >95 && e.keyCode <106)))
236		text.form[(getIndex(text)+1) % text.form.length].focus();
237}
238function keyup_n(e,text,num)
239{
240	if(text.value.length == num && (e.keyCode != 190 && e.keyCode != 110 && e.keyCode != 9))
241		text.form[(getIndex(text)+1) % text.form.length].focus();
242}
243function getIndex(input) {
244    	var index = -1;
245	var i = 0;
246	var found = false;
247    	while (i < input.form.length && index == -1)
248    		if (input.form[i] == input)index = i;
249    			else i++;
250    	return index;
251}
252
253function getObj(name)
254{
255	if (document.getElementById)
256	{
257		return document.getElementById(name).style;
258	}
259	else if (document.all)
260	{
261		return document.all[name].style;
262	}
263	else if (document.layers)
264	{
265		return document.layers[name];
266	}
267}
268
269function check_maxNumAdd(form,nowNum,maxNum,msg,go2href)
270{
271	nowNum=parseInt(nowNum,10);
272	if (nowNum >= maxNum)
273	{
274		alert(msg);
275		return false;
276	}
277	else
278		location.href=go2href;
279}
280
281
282
283function isSameIp(ipstr1,ipstr2)
284{
285	var count = 0;
286	var ip1_array=ipstr1.split('.');
287	var ip2_array=ipstr2.split('.');
288	for(i = 0;i<4;i++)
289	{
290		num1 = parseInt(ip1_array[i], 10);
291		num2 = parseInt(ip2_array[i], 10);
292		if( num1 == num2)
293			count++;
294	}
295	if( count == 4)
296		return true;
297	else
298		return false;
299}
300
301function cp_ip2(from,to)
302	//true invalid from and to ip;  false valid from and to ip;
303{
304	var total1 = 0;
305	var total2 = 0;
306	var from_array=from.split('.');
307	var to_array = to.split('.');
308	var from1=from_array[0];
309	var to1=to_array[0];
310	if(parseInt(from1,10) <= 127 && parseInt(to1,10) >= 127 )
311	{
312		return false;
313	}
314	var from2=from_array[1];
315	var from3=from_array[2];
316	var from4=from_array[3];
317	var to2=to_array[1];
318	var to3=to_array[2];
319	var to4=to_array[3];
320
321	total1 += parseInt(from4,10);
322	total1 += parseInt(from3,10)*256;
323	total1 += parseInt(from2,10)*256*256;
324	total1 += parseInt(from1,10)*256*256*256;
325
326	total2 += parseInt(to4,10);
327	total2 += parseInt(to3,10)*256;
328	total2 += parseInt(to2,10)*256*256;
329	total2 += parseInt(to1,10)*256*256*256;
330	if(total1 <= total2)
331		return true;
332	return false;
333}
334
335function is_sub_or_broad(be_checkip, ip, mask)
336{
337        addr_arr = be_checkip.split('.');
338        var ip_addr=0;
339
340	if(mask == "255.255.255.255")
341		return true;
342
343        for (i = 0; i < 4; i++)
344        {
345                addr_str = parseInt(addr_arr[i],10);
346                ip_addr=ip_addr*256+parseInt(addr_str);
347        }
348        var ip_sub=isSub(ip, mask);
349        var ip_broadcast=isBroadcast(ip, mask)
350	if(ip_addr == ip_sub || ip_addr == ip_broadcast){
351		return false;
352	}
353	return true;
354}
355
356function isGateway(lanIp, lanMask, gtwIp)
357{
358	gtw_arr = gtwIp.split('.');
359        var ip_gtw=0;
360        for (i = 0; i < 4; i++)
361        {
362	        gtw_str = parseInt(gtw_arr[i],10);
363                ip_gtw=ip_gtw*256+parseInt(gtw_str);
364        }
365
366        addr_arr = lanIp.split('.');
367        var ip_addr=0;
368        for (i = 0; i < 4; i++)
369        {
370                addr_str = parseInt(addr_arr[i],10);
371                ip_addr=ip_addr*256+parseInt(addr_str);
372        }
373
374        var ip_sub=isSub(lanIp, lanMask);
375        var ip_broadcast=isBroadcast(lanIp, lanMask)
376        if((parseInt(ip_sub)<parseInt(ip_gtw))&&(parseInt(ip_gtw)<parseInt(ip_broadcast)))
377	        return true;
378        else
379                return false;
380}
381
382function isSub(lanIp, lanMask)
383{
384        ip_arr = lanIp.split('.');
385        mask_arr = lanMask.split('.');
386        var ip_sub=0
387        for (i = 0; i < 4; i++)
388        {
389    	        ip_str = parseInt(ip_arr[i],10);
390                mask_str = parseInt(mask_arr[i],10);
391                ip_sub=ip_sub*256+parseInt(ip_str & mask_str)
392        }
393        return(ip_sub);
394}
395
396function isBroadcast(lanIp, lanMask)
397{
398        ip_arr = lanIp.split('.');
399        mask_arr = lanMask.split('.');
400        var ip_broadcast=0
401        for (i = 0; i < 4; i++)
402        {
403                ip_str = parseInt(ip_arr[i],10);
404                mask_str = parseInt(mask_arr[i],10);
405                n_str = ~mask_str+256;
406                ip_broadcast=ip_broadcast*256+parseInt(ip_str | n_str)
407        }
408        return(ip_broadcast);
409}
410
411function isSameSubNet(lan1Ip, lan1Mask, lan2Ip, lan2Mask)
412{
413	var count = 0;
414	lan1a = lan1Ip.split('.');
415	lan1m = lan1Mask.split('.');
416	lan2a = lan2Ip.split('.');
417	lan2m = lan2Mask.split('.');
418	for (i = 0; i < 4; i++)
419	{
420		l1a_n = parseInt(lan1a[i],10);
421		l1m_n = parseInt(lan1m[i],10);
422		l2a_n = parseInt(lan2a[i],10);
423		l2m_n = parseInt(lan2m[i],10);
424		if ((l1a_n & l1m_n) == (l2a_n & l2m_n))
425			count++;
426	}
427	if (count == 4)
428		return true;
429	else
430		return false;
431}
432function checkipaddr(ipaddr)
433{
434	var form = document.forms[0];
435	var ipArray = ipaddr.split(".");
436	var ipstr = ipArray[0]+ipArray[1]+ipArray[2]+ipArray[3];
437	var i = 0;
438
439	if((ipArray[0]=="")||(ipArray[0]<0)||(ipArray[0]>255)||(ipArray[1]=="")||(ipArray[1]<0)||(ipArray[1]>255)
440			||(ipArray[2]=="")||(ipArray[2]<0)||(ipArray[2]>255)||(ipArray[3]=="")||(ipArray[3]<0)||(ipArray[3]>255))
441	{
442		return false;
443	}
444	for(i=0;i<ipstr.length;i++)
445	{
446		if((ipstr.charAt(i)!='0')&&(ipstr.charAt(i)!='1')&&(ipstr.charAt(i)!='2')
447				&&(ipstr.charAt(i)!='3')&&(ipstr.charAt(i)!='4')&&(ipstr.charAt(i)!='5')
448				&&(ipstr.charAt(i)!='6')&&(ipstr.charAt(i)!='7')&&(ipstr.charAt(i)!='8')
449				&&(ipstr.charAt(i)!='9'))
450		{
451			return false;
452		}
453	}
454	if( ipArray[0] > 223 || ipArray[0] == 0 )
455		return false;
456	if (ipaddr == "0.0.0.0" || ipaddr == "255.255.255.255")
457	{
458		return false;
459	}
460
461	var each=ipaddr.split(".");
462	if (each[0] == "127")
463	{
464		return false;
465	}
466	if (!ipArray || ipArray.length != 4)
467	{
468		return false;
469	}
470	else
471	{
472		for (i = 0; i < 4; i++)
473		{
474			thisSegment = ipArray[i];
475			if (thisSegment != "")
476			{
477				if(i==3){
478					if (!((ipArray[3] > 0) && (ipArray[3] < 255)))
479					{
480						return false;
481					}
482				}
483				else if (!(thisSegment >=0 && thisSegment <= 255))
484				{
485					return false;
486				}
487			}
488			else
489			{
490				return false;
491			}
492		}
493
494	}
495	return true;
496}
497//sometiems it is true to set the netmask 255.255.255.255, so we set a flag for this case
498function checksubnet(subnet, flag)
499{
500	var subnetArray = subnet.split(".");
501	var subnetstr = subnetArray[0]+subnetArray[1]+subnetArray[2]+subnetArray[3];
502	var i = 0;
503	var maskTest = 0;
504	var validValue = true;
505
506	if(flag == 0)
507	{
508		/* to fix bug 23900, if user enter "255.255.255.255" as subnet mask return false.*/
509		if(subnetstr == "255255255255")
510			return false;
511	}
512
513	if((subnetArray[0]=="")||(subnetArray[0]<0)||(subnetArray[0]>255)||(subnetArray[1]=="")||(subnetArray[1]<0)||(subnetArray[1]>255)
514			||(subnetArray[2]=="")||(subnetArray[2]<0)||(subnetArray[2]>255)||(subnetArray[3]=="")||(subnetArray[3]<0)||(subnetArray[3]>255))
515	{
516		return false;
517	}
518	for(i=0;i<subnetstr.length;i++)
519	{
520		if((subnetstr.charAt(i)!='0')&&(subnetstr.charAt(i)!='1')&&(subnetstr.charAt(i)!='2')
521				&&(subnetstr.charAt(i)!='3')&&(subnetstr.charAt(i)!='4')&&(subnetstr.charAt(i)!='5')
522				&&(subnetstr.charAt(i)!='6')&&(subnetstr.charAt(i)!='7')&&(subnetstr.charAt(i)!='8')
523				&&(subnetstr.charAt(i)!='9'))
524		{
525			return false;
526		}
527	}
528	if (!subnetArray || subnetArray.length != 4)
529	{
530		return false;
531	}
532	else
533	{
534		for (i = 0; i < 4; i++) {
535			thisSegment = subnetArray[i];
536			if (thisSegment != "") {
537				if (!(thisSegment >=0 && thisSegment <= 255)) { //check if number?
538
539					return false;
540				}
541			} else {
542				return false;
543			}
544		}
545	}
546	if( subnetArray[0] < 255 )
547	{
548		if( (subnetArray[1] > 0) || (subnetArray[2] > 0) || (subnetArray[3] > 0))
549			validValue = false;
550		else
551			maskTest = subnetArray[0];
552	}
553	else
554	{
555		if( subnetArray[1] < 255 )
556		{
557			if( (subnetArray[2] > 0) || (subnetArray[3] > 0))
558				validValue = false;
559			else
560				maskTest = subnetArray[1];
561		}
562		else
563		{
564			if( subnetArray[2] < 255 )
565			{
566				if( (subnetArray[3] > 0) )
567					validValue = false;
568				else
569					maskTest = subnetArray[2];
570			}
571			else
572				maskTest = subnetArray[3];
573		}
574	}
575	if( validValue ) {
576		switch( maskTest ) {
577			case "0":
578			case "00":
579			case "000":
580				case "128":
581				case "192":
582				case "224":
583				case "240":
584				case "248":
585				case "252":
586				case "254":
587				case "255":
588				case "000":  //bug23797, for input 000
589				break;
590			default:
591			validValue = false;
592		}
593		if( subnet == "0.0.0.0" )
594			validValue = false;
595	}
596	else
597		validValue = false;
598
599
600	return validValue;
601}
602
603function ipNum(ipStr)/* to fix bug 25203 */
604{
605	var total = 0;
606	var ip_array=ipStr.split('.');
607	var ip1=ip_array[0];
608	var ip2=ip_array[1];
609	var ip3=ip_array[2];
610	var ip4=ip_array[3];
611	total += parseInt(ip4);
612	total += parseInt(ip3)*256;
613	total += parseInt(ip2)*256*256;
614	total += parseInt(ip1)*256*256*256;
615	total = parseInt(total);
616	return total;
617}
618
619function isIncludeInvIp(inv_ip, start_ip, end_ip)/* to fix bug 25203 */
620{
621	inv_ip_num = ipNum(inv_ip);
622	start_ip_num = ipNum(start_ip);
623	end_ip_num = ipNum(end_ip);
624
625	if( inv_ip_num >= start_ip_num && inv_ip_num <= end_ip_num)
626		return true;
627
628	return false;
629}
630
631function checkgateway(gateway)
632{
633	var form = document.forms[0];
634	var dgArray = gateway.split(".");
635	var dgstr = dgArray[0]+dgArray[1]+dgArray[2]+dgArray[3];
636	var i = 0;
637
638	if((dgArray[0]=="")||(dgArray[0]<0)||(dgArray[0]>255)||(dgArray[1]=="")||(dgArray[1]<0)||(dgArray[1]>255)
639			||(dgArray[2]=="")||(dgArray[2]<0)||(dgArray[2]>255)||(dgArray[3]=="")||(dgArray[3]<0)||(dgArray[3]>255))
640	{
641		return false;
642	}
643	for(i=0;i<dgstr.length;i++)
644	{
645		if((dgstr.charAt(i)!='0')&&(dgstr.charAt(i)!='1')&&(dgstr.charAt(i)!='2')
646				&&(dgstr.charAt(i)!='3')&&(dgstr.charAt(i)!='4')&&(dgstr.charAt(i)!='5')
647				&&(dgstr.charAt(i)!='6')&&(dgstr.charAt(i)!='7')&&(dgstr.charAt(i)!='8')
648				&&(dgstr.charAt(i)!='9'))
649		{
650			return false;
651		}
652	}
653	if( dgArray[0] > 223 || dgArray[0] == 0 )
654		return false;
655	if (gateway == "0.0.0.0" || gateway == "255.255.255.255")
656	{
657		return false;
658	}
659	if (gateway == "127.0.0.1")
660	{
661		return false;
662	}
663	if (!dgArray || dgArray.length != 4)
664	{
665		return false;
666	}
667	else
668	{
669		for (i = 0; i < 4; i++) {
670			thisSegment = dgArray[i];
671			if (thisSegment != "")
672			{
673				if (!(thisSegment >=0 && thisSegment <= 255))
674				{ //check if number?
675					return false;
676				}
677			}
678			else
679			{
680				return false;
681			}
682		}
683	}
684	return true;
685}
686function loadhelp(fname,anchname)
687{
688	var page="/help/"+fname+"_help.html";
689
690	if(this.help_iframe)
691	{
692		this.help_iframe.location.href=page+"#"+ anchname;
693		this.help_iframe.location.href=page+"#"+ anchname; // to fix bug 29847.
694	}
695	else if(parent.help_iframe)     //dowmload manager
696	{
697		page=parent.help_iframe.location.href.split("#")[0];
698		parent.help_iframe.location.href=page+"#"+ anchname;
699		parent.help_iframe.location.href=page+"#"+ anchname;
700	}
701	return;
702}
703
704function getkeya(e)
705{
706	var keycode;
707	if (window.event)
708	{
709		keycode = window.event.keyCode;
710		if (((keycode>47) && (keycode<58))||(keycode==8)||((keycode>64) && (keycode<71))||((keycode>96) && (keycode<103))) { return true; }
711		else return false;
712	}
713	else if (e)
714	{
715		keycode = e.which;
716		if (((keycode>47) && (keycode<58))||(keycode==8)||(keycode==0)||((keycode>64) && (keycode<71))||((keycode>96) && (keycode<103))) { return true; }
717		else return false;
718	}
719	else
720	{
721		return true;
722	}
723}
724function getkey(type, e)
725{
726	var keycode, event;
727
728	if (window.event)
729	{
730		event = window.event;
731		keycode = window.event.keyCode;
732	}
733	else if (e)
734	{
735		event = e;
736		keycode = e.which;
737	}
738	else return true;
739
740	if(event.ctrlKey && ( keycode==99 || keycode==118 || keycode==120) )
741		return true;
742
743	if(type == "apname")
744	{
745		if ((keycode==34) ||(keycode==39)||(keycode==92)) { return false; }
746		else return true;
747	}
748	else if(type == "ipaddr")
749	{
750		if (((keycode>47) && (keycode<58))||(keycode==8)||(keycode==0)||(keycode==46)) { return true; }
751		else return false;
752	}
753	else if(type == "ssid")
754	{
755		if (keycode==32) return false;
756		else return true;
757	}
758	else if(type == "wep")
759	{
760		if (((keycode>47) && (keycode<58))||((keycode>64) && (keycode<71))||((keycode>96) && (keycode<103))||(keycode == 8)||(keycode == 0))
761			return true;
762		else return false;
763	}
764	else if(type == "num")
765	{
766		if	(((keycode>47) && (keycode<58)) || (keycode==8)||(keycode==0))
767			return true;
768		else return false;
769	}else if(type == "wps_pin")
770	{
771		if(((keycode>47) && (keycode<58)) || (8==keycode)||(0==keycode)||(32==keycode)||(45==keycode)) //38293
772			return true;
773		else return false;
774	}
775	else if(type == "num_letter")
776	{
777		if((keycode>47 && keycode<58)||(keycode>64 && keycode<91)||(keycode>96 && keycode<123)||(keycode==8)||(keycode==0))
778			return true;
779		else
780			return false
781	}
782	else if(type == "hostname")
783	{
784		if (((keycode>47) && (keycode<58))||(keycode==45)||((keycode>64) && (keycode<91))||((keycode>96) && (keycode<123)) || (keycode==8)||(keycode==0)) { return true; }
785		else return false;
786	}
787	else if(type == "ddns_hostname")
788	{
789		if (((keycode>47) && (keycode<58))||(keycode==45)||(keycode==46)||((keycode>64) && (keycode<91))||((keycode>96) && (keycode<123)) || (keycode==8)||(keycode==0)) { return true; }
790		else return false;
791	}
792	else if(type == "mac")
793	{
794		if (((keycode>47) && (keycode<58))||((keycode>64) && (keycode<71))||((keycode>96) && (keycode<103))||(keycode == 8)||(keycode == 0) || (keycode == 58) || (keycode == 45))
795			return true;
796		else return false;
797	}
798	else if(type == "folderPath")// not / * ? " <>
799	{
800		if((keycode==47) || (keycode==42) || (keycode==63) || (keycode==34) || (keycode==60) || (keycode==62) ||(keycode==124))
801			return false;
802		else
803			return true;
804	}
805	else if(type == "shareName")// not / * ? " <> \ :
806	{
807		if((keycode==47) || (keycode==42) || (keycode==63) || (keycode==34) || (keycode==58) || (keycode==60) || (keycode==62) || (keycode==92) || (keycode==93) || (keycode==124))
808			return false;
809		else
810			return true;
811	}
812        else if(type == "mediaServerName")// not / * ? " <> \ :
813        {
814                if((keycode==47) || (keycode==42) || (keycode==63) || (keycode==34)  || (keycode==60) || (keycode==62)  || (keycode==92) || (keycode==93) || (keycode==124)){
815			alert("�z����?�J  ':'�@? ReadyDLNA �C�^�A?���W?");  // || (keycode==58)
816                        return false;
817		}
818                else
819                        return true;
820        }
821	else if(type == "colon_num")
822        {
823                if(((keycode>47) && (keycode<58)) || (keycode==46) || (keycode==8)||(keycode==0))
824                        return true;
825                else return false;
826        }
827	else
828		return false;
829}
830
831
832
833function changesectype(fname)
834{
835	var html_href;
836	if(fname.options[0].selected == true) html_href = "security_off.asp";
837	else if(fname.options[1].selected == true) html_href = "wep.asp";
838	else if(fname.options[2].selected == true) html_href = "wpa.asp";
839	else if(fname.options[3].selected == true) html_href = "wpa2.asp";
840	else if(fname.options[4].selected == true) html_href = "wpas.asp";
841
842	location.href = html_href;
843}
844
845function printableKeyFilter()
846{
847	if (event.keyCode < 32 || event.keyCode > 126)
848		event.returnValue = false;
849}
850
851function checkpsk(passphrase, passphrase_len)
852{
853	var len = passphrase.value.length;
854	if ( len == 64 )
855	{
856		for(i=0;i<len;i++)
857		{
858			if(isValidHex(passphrase.value.charAt(i))==false)
859			{
860				alert("�K?��8~63?ASCII�r����64?�Q��?��?�r?���C�Q��?��?�r?�H�U�����r�����@�G0, 1, 2, ..., 8, 9, A, B, C, D, E, F�C");
861				return false;
862			}
863		}
864	}
865	else
866	{
867		if(len < 8 )
868		{
869	        	alert("�K??�������A����??8?�r���C");
870		        return false;
871		}
872		if(len > 63){
873			alert("�K???�A���j?��??63?�r���C");
874			return false;
875		}
876		for(i=0;i<passphrase.value.length;i++)
877		{
878			if(isValidChar_space(passphrase.value.charCodeAt(i))==false)
879			{
880				alert("�K?��8~63?ASCII�r����64?�Q��?��?�r?���C�Q��?��?�r?�H�U�����r�����@�G0, 1, 2, ..., 8, 9, A, B, C, D, E, F�C");
881				return false;
882			}
883		}
884	}
885	passphrase_len.value=len;
886	return true;
887}
888
889var wep_128="�K??���C\n\n�K??��?? 26 ���Q��?���]0 �� 9 �� A �� F�^�r���� 13 �� ASCII �r���C";
890var wep_64="�K??���C\n\n�K??��?? 10 ���Q��?���]0 �� 9 �� A �� F�^�r���� 5 �� ASCII �r���C";
891
892function show_alert(wep_bit)
893{
894	if(wep_bit == 10)
895		alert(wep_64);
896	else if(wep_bit == 26)
897		alert(wep_128);
898}
899function check_key(key,wep_bit)
900{
901	var ascii_len;
902	var i;
903
904	if(wep_bit == 10)
905		ascii_len = 5;
906	else if(wep_bit == 26)
907		ascii_len = 13;
908
909	if(key.length == wep_bit)
910	{
911		for(i=0;i<key.length;i++)
912		{
913			if(isValidHex(key.charAt(i))==false)
914			{
915				show_alert(wep_bit);
916				return false;
917			}
918		}
919	}
920	else
921	{
922		if(key.length != 0 && key.length != wep_bit && key.length != ascii_len)
923		{
924			show_alert(wep_bit);
925			return false;
926		}
927
928		for(i=0;i<key.length;i++)
929		{
930			if(isValidChar_space(key.charCodeAt(i))==false)
931			{
932				show_alert(wep_bit);
933				return false;
934			}
935		}
936	}
937	return true;
938}
939
940function checkwep(form)
941{
942	form.wep_press_flag.value=0;
943	var KEY1=form.KEY1.value;
944	var KEY2=form.KEY2.value;
945	var KEY3=form.KEY3.value;
946	var KEY4=form.KEY4.value;
947
948	if(form.wepenc.value==13)
949	{
950		if( form.wep_key_no[0].checked == true )
951		{
952			if(form.KEY1.value.length!=26 && form.KEY1.value.length!=13)
953			{
954				alert(wep_128);
955				return false;
956			}
957		}
958		if(check_key(KEY1,26) == false)
959			return false;
960
961		if( form.wep_key_no[1].checked == true )
962		{
963			if(form.KEY2.value.length!=26 && form.KEY2.value.length!=13)
964			{
965				alert(wep_128);
966				return false;
967			}
968		}
969
970		if(check_key(KEY2,26) == false)
971			return false;
972
973		if( form.wep_key_no[2].checked == true)
974		{
975			if(form.KEY3.value.length!=26 && form.KEY3.value.length!=13)
976			{
977				alert(wep_128);
978				return false;
979			}
980		}
981		if(check_key(KEY3,26) == false)
982			return false;
983
984		if( form.wep_key_no[3].checked == true)
985		{
986			if(form.KEY4.value.length!=26 && form.KEY4.value.length!=13)
987			{
988				alert(wep_128);
989				return false;
990			}
991		}
992		if(check_key(KEY4,26) == false)
993			return false;
994	}
995	if(form.wepenc.value==5)
996	{
997		if( form.wep_key_no[0].checked == true)
998		{
999			if(form.KEY1.value.length!=10 && form.KEY1.value.length!=5)
1000			{
1001				alert(wep_64);
1002				return false;
1003			}
1004		}
1005		if(check_key(KEY1,10) == false)
1006			return false;
1007
1008		if( form.wep_key_no[1].checked == true)
1009		{
1010			if(form.KEY2.value.length!=10 && form.KEY2.value.length!=5)
1011			{
1012				alert(wep_64);
1013				return false;
1014			}
1015		}
1016		if(check_key(KEY2,10) == false)
1017			return false;
1018
1019		if( form.wep_key_no[2].checked == true)
1020		{
1021			if(form.KEY3.value.length!=10 && form.KEY3.value.length!=5)
1022			{
1023				alert(wep_64);
1024				return false;
1025			}
1026		}
1027		if(check_key(KEY3,10) == false)
1028			return false;
1029
1030		if( form.wep_key_no[3].checked == true)
1031		{
1032			if(form.KEY4.value.length!=10 && form.KEY4.value.length!=5)
1033			{
1034				alert(wep_64);
1035				return false;
1036			}
1037		}
1038		if(check_key(KEY4,10) == false)
1039			return false;
1040	}
1041	return true;
1042}
1043
1044function checkwep_a(form)
1045{
1046	form.wep_press_flag.value=0;
1047	var KEY1=form.KEY1_an.value;
1048	var KEY2=form.KEY2_an.value;
1049	var KEY3=form.KEY3_an.value;
1050	var KEY4=form.KEY4_an.value;
1051
1052	if(form.Wepenc_an.value==13)
1053	{
1054		if( form.wep_key_no_an[0].checked == true )
1055		{
1056			if(KEY1.length!=26 && KEY1.length!=13)
1057			{
1058				alert(wep_128);
1059				return false;
1060			}
1061		}
1062		if(check_key(KEY1,26) == false)
1063			return false;
1064
1065		if( form.wep_key_no_an[1].checked == true )
1066		{
1067			if(KEY2.length!=26 && KEY2.length!=13)
1068			{
1069				alert(wep_128);
1070				return false;
1071			}
1072		}
1073		if(check_key(KEY2,26) == false)
1074			return false;
1075
1076		if( form.wep_key_no_an[2].checked == true)
1077		{
1078			if(KEY3.length!=26 && KEY3.length!=13)
1079			{
1080				alert(wep_128);
1081				return false;
1082			}
1083		}
1084		if(check_key(KEY3,26) == false)
1085			return false;
1086
1087		if( form.wep_key_no_an[3].checked == true)
1088		{
1089			if(KEY4.length!=26 && KEY4.length!=13)
1090			{
1091				alert(wep_128);
1092				return false;
1093			}
1094		}
1095		if(check_key(KEY4,26) == false)
1096			return false;
1097
1098	}
1099	if(form.Wepenc_an.value==5)
1100	{
1101		if( form.wep_key_no_an[0].checked == true)
1102		{
1103			if(KEY1.length!=10 && KEY1.length!=5)
1104			{
1105				alert(wep_64);
1106				return false;
1107			}
1108		}
1109		if(check_key(KEY1,10) == false)
1110			return false;
1111
1112		if( form.wep_key_no_an[1].checked == true)
1113		{
1114			if(KEY2.length!=10 && KEY2.length!=5)
1115			{
1116				alert(wep_64);
1117				return false;
1118			}
1119		}
1120		if(check_key(KEY2,10) == false)
1121			return false;
1122
1123		if( form.wep_key_no_an[2].checked == true)
1124		{
1125			if(KEY3.length!=10 && KEY3.length!=5)
1126			{
1127				alert(wep_64);
1128				return false;
1129			}
1130		}
1131		if(check_key(KEY3,10) == false)
1132			return false;
1133
1134		if( form.wep_key_no_an[3].checked == true)
1135		{
1136			if(KEY4.length!=10 && KEY4.length!=5)
1137			{
1138				alert(wep_64);
1139				return false;
1140			}
1141		}
1142		if(check_key(KEY4,10) == false)
1143			return false;
1144	}
1145	return true;
1146}
1147
1148/////////////////////////////////////generate wep key by md5////////////////////////////////////////////////////
1149function HexToAscii(wepenc,wep_key_no,I,S,D) {
1150	var temp1="";
1151
1152	S = S.toUpperCase();
1153
1154	var optionindex=wepenc.selectedIndex;
1155
1156	if( wepenc.options[optionindex].value=="13" )
1157	{
1158		wordCount = 26;
1159	}
1160	else {
1161		wordCount = 10;
1162	}
1163
1164	//if(F.keyno_11g[I].checked)
1165	if(1)
1166	{
1167		if( (S.length!=wordCount) )
1168		{
1169			if(wep_key_no[I].checked)
1170			{
1171				var s="Hex type key length must be ";
1172				alert(s + wordCount);
1173			}
1174			D.value="";
1175			S="";
1176			return S;
1177		}
1178		for(i=0;i<wordCount;i+=2)
1179		{
1180			var c=S.charCodeAt(i);
1181			var d=S.charCodeAt(i+1);
1182
1183			if( (c>=48)&&(c<=57) )
1184				c=c-48;
1185			else if( (c>=65)&&(c<=70) )
1186				c=c-55;
1187			else
1188			{
1189				var s="Over Hex range (0~F)";
1190				alert(s);
1191				return S;
1192			}
1193
1194			if( (d>=48)&&(d<=57) )
1195				d=d-48;
1196			else if( (d>=65)&&(d<=70) )
1197				d=d-55;
1198			else
1199			{
1200				var s="Over Hex range (0~F)";
1201				alert(s);
1202				return S;
1203			}
1204			var value=c*16+d;
1205
1206			if( ((value>=0)&&(value<32)) || ((value>128)&&(value<=255)) )
1207			{
1208				temp1+=String.fromCharCode(92);
1209				temp1+=S.substring(i,i+2);
1210
1211			}
1212			else
1213			{
1214				if(value==92)
1215				{
1216					temp1+=String.fromCharCode(value);
1217					temp1+=String.fromCharCode(value);
1218				}
1219				else
1220					temp1+=String.fromCharCode(value);
1221			}
1222		}
1223		D.value=temp1;
1224	}
1225	return S;
1226}
1227
1228function PassPhrase40(passphraseStr, wepenc, wep_key_no, KEY1, KEY2, KEY3, KEY4)
1229{
1230	var seed = 0;
1231	var pseed = new Array(0, 0, 0, 0);
1232	var pkey = new Array(4);
1233	var asciiObj = new Array(4);
1234	Length = passphraseStr.value.length;
1235
1236	if(Length != 0) {
1237		for (i=0; i<Length; i++ ) {
1238			pseed[i%4] ^= passphraseStr.value.charCodeAt(i);
1239		}
1240		seed = pseed[0];
1241		seed += pseed[1] << 8;
1242		seed += pseed[2] << 16;
1243		seed += pseed[3] << 24;
1244	}
1245
1246	KEY1.value = KEY2.value = "";
1247	KEY3.value = KEY4.value = "";
1248
1249	// init key array
1250	pkey[0] = KEY1;
1251	pkey[1] = KEY2;
1252	pkey[2] = KEY3;
1253	pkey[3] = KEY4;
1254
1255	for(j=0; j<4; j++) {
1256		for (i=0; i<5 ;i++ )  {
1257			seed = (214013 * seed) & 0xffffffff;
1258
1259			if(seed & 0x80000000) {
1260				seed = (seed & 0x7fffffff) + 0x80000000 + 0x269ec3;
1261			}
1262			else {
1263				seed = (seed & 0x7fffffff) + 0x269ec3;
1264			}
1265
1266			temp = ((seed >> 16) & 0xff);
1267			if(temp < 0x10) {
1268				pkey[j].value += "0" + temp.toString(16).toUpperCase();
1269			}
1270			else {
1271				pkey[j].value += temp.toString(16).toUpperCase();
1272			}
1273		}
1274	}
1275
1276	asciiObj[0] = "";
1277	asciiObj[1] = "";
1278	asciiObj[2] = "";
1279	asciiObj[3] = "";
1280
1281	for(k=0; k<4; k++) {
1282		HexToAscii(wepenc, wep_key_no, k, pkey[k].value, asciiObj[k]);
1283	}
1284
1285	wepkey1 = pkey[0].value;
1286	wepkey2 = pkey[1].value;
1287	wepkey3 = pkey[2].value;
1288	wepkey4 = pkey[3].value;
1289}
1290
1291/*
1292 * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
1293 * Digest Algorithm, as defined in RFC 1321.
1294 * Copyright (C) Paul Johnston 1999 - 2000.
1295 * Updated by Greg Holt 2000 - 2001.
1296 * See http://pajhome.org.uk/site/legal.html for details.
1297 */
1298
1299/*
1300 * Convert a 32-bit number to a hex string with ls-byte first
1301 */
1302var hex_chr = "0123456789abcdef";
1303function rhex(num)
1304{
1305	str = "";
1306	for(j = 0; j <= 3; j++)
1307		str += hex_chr.charAt((num >> (j * 8 + 4)) & 0x0F) +
1308			hex_chr.charAt((num >> (j * 8)) & 0x0F);
1309	return str;
1310}
1311
1312/*
1313 * Convert a string to a sequence of 16-word blocks, stored as an array.
1314 * Append padding bits and the length, as described in the MD5 standard.
1315 */
1316function str2blks_MD5(str)
1317{
1318	nblk = ((str.length + 8) >> 6) + 1;
1319	blks = new Array(nblk * 16);
1320	for(i = 0; i < nblk * 16; i++) blks[i] = 0;
1321	for(i = 0; i < str.length; i++)
1322		blks[i >> 2] |= str.charCodeAt(i) << ((i % 4) * 8);
1323	blks[i >> 2] |= 0x80 << ((i % 4) * 8);
1324	blks[nblk * 16 - 2] = str.length * 8;
1325	return blks;
1326}
1327
1328/*
1329 * Add integers, wrapping at 2^32. This uses 16-bit operations internally
1330 * to work around bugs in some JS interpreters.
1331 */
1332function add(x, y)
1333{
1334	var lsw = (x & 0xFFFF) + (y & 0xFFFF);
1335	var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
1336	return (msw << 16) | (lsw & 0xFFFF);
1337}
1338
1339/*
1340 * Bitwise rotate a 32-bit number to the left
1341 */
1342function rol(num, cnt)
1343{
1344	return (num << cnt) | (num >>> (32 - cnt));
1345}
1346
1347/*
1348 * These functions implement the basic operation for each round of the
1349 * algorithm.
1350 */
1351function cmn(q, a, b, x, s, t)
1352{
1353	return add(rol(add(add(a, q), add(x, t)), s), b);
1354}
1355function ff(a, b, c, d, x, s, t)
1356{
1357	return cmn((b & c) | ((~b) & d), a, b, x, s, t);
1358}
1359function gg(a, b, c, d, x, s, t)
1360{
1361	return cmn((b & d) | (c & (~d)), a, b, x, s, t);
1362}
1363function hh(a, b, c, d, x, s, t)
1364{
1365	return cmn(b ^ c ^ d, a, b, x, s, t);
1366}
1367function ii(a, b, c, d, x, s, t)
1368{
1369	return cmn(c ^ (b | (~d)), a, b, x, s, t);
1370}
1371
1372/*
1373 * Take a string and return the hex representation of its MD5.
1374 */
1375function calcMD5(str)
1376{
1377	x = str2blks_MD5(str);
1378	a =  1732584193;
1379	b = -271733879;
1380	c = -1732584194;
1381	d =  271733878;
1382
1383	for(i = 0; i < x.length; i += 16)
1384	{
1385		olda = a;
1386		oldb = b;
1387		oldc = c;
1388		oldd = d;
1389
1390		a = ff(a, b, c, d, x[i+ 0], 7 , -680876936);
1391		d = ff(d, a, b, c, x[i+ 1], 12, -389564586);
1392		c = ff(c, d, a, b, x[i+ 2], 17,  606105819);
1393		b = ff(b, c, d, a, x[i+ 3], 22, -1044525330);
1394		a = ff(a, b, c, d, x[i+ 4], 7 , -176418897);
1395		d = ff(d, a, b, c, x[i+ 5], 12,  1200080426);
1396		c = ff(c, d, a, b, x[i+ 6], 17, -1473231341);
1397		b = ff(b, c, d, a, x[i+ 7], 22, -45705983);
1398		a = ff(a, b, c, d, x[i+ 8], 7 ,  1770035416);
1399		d = ff(d, a, b, c, x[i+ 9], 12, -1958414417);
1400		c = ff(c, d, a, b, x[i+10], 17, -42063);
1401		b = ff(b, c, d, a, x[i+11], 22, -1990404162);
1402		a = ff(a, b, c, d, x[i+12], 7 ,  1804603682);
1403		d = ff(d, a, b, c, x[i+13], 12, -40341101);
1404		c = ff(c, d, a, b, x[i+14], 17, -1502002290);
1405		b = ff(b, c, d, a, x[i+15], 22,  1236535329);
1406
1407		a = gg(a, b, c, d, x[i+ 1], 5 , -165796510);
1408		d = gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
1409		c = gg(c, d, a, b, x[i+11], 14,  643717713);
1410		b = gg(b, c, d, a, x[i+ 0], 20, -373897302);
1411		a = gg(a, b, c, d, x[i+ 5], 5 , -701558691);
1412		d = gg(d, a, b, c, x[i+10], 9 ,  38016083);
1413		c = gg(c, d, a, b, x[i+15], 14, -660478335);
1414		b = gg(b, c, d, a, x[i+ 4], 20, -405537848);
1415		a = gg(a, b, c, d, x[i+ 9], 5 ,  568446438);
1416		d = gg(d, a, b, c, x[i+14], 9 , -1019803690);
1417		c = gg(c, d, a, b, x[i+ 3], 14, -187363961);
1418		b = gg(b, c, d, a, x[i+ 8], 20,  1163531501);
1419		a = gg(a, b, c, d, x[i+13], 5 , -1444681467);
1420		d = gg(d, a, b, c, x[i+ 2], 9 , -51403784);
1421		c = gg(c, d, a, b, x[i+ 7], 14,  1735328473);
1422		b = gg(b, c, d, a, x[i+12], 20, -1926607734);
1423
1424		a = hh(a, b, c, d, x[i+ 5], 4 , -378558);
1425		d = hh(d, a, b, c, x[i+ 8], 11, -2022574463);
1426		c = hh(c, d, a, b, x[i+11], 16,  1839030562);
1427		b = hh(b, c, d, a, x[i+14], 23, -35309556);
1428		a = hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
1429		d = hh(d, a, b, c, x[i+ 4], 11,  1272893353);
1430		c = hh(c, d, a, b, x[i+ 7], 16, -155497632);
1431		b = hh(b, c, d, a, x[i+10], 23, -1094730640);
1432		a = hh(a, b, c, d, x[i+13], 4 ,  681279174);
1433		d = hh(d, a, b, c, x[i+ 0], 11, -358537222);
1434		c = hh(c, d, a, b, x[i+ 3], 16, -722521979);
1435		b = hh(b, c, d, a, x[i+ 6], 23,  76029189);
1436		a = hh(a, b, c, d, x[i+ 9], 4 , -640364487);
1437		d = hh(d, a, b, c, x[i+12], 11, -421815835);
1438		c = hh(c, d, a, b, x[i+15], 16,  530742520);
1439		b = hh(b, c, d, a, x[i+ 2], 23, -995338651);
1440
1441		a = ii(a, b, c, d, x[i+ 0], 6 , -198630844);
1442		d = ii(d, a, b, c, x[i+ 7], 10,  1126891415);
1443		c = ii(c, d, a, b, x[i+14], 15, -1416354905);
1444		b = ii(b, c, d, a, x[i+ 5], 21, -57434055);
1445		a = ii(a, b, c, d, x[i+12], 6 ,  1700485571);
1446		d = ii(d, a, b, c, x[i+ 3], 10, -1894986606);
1447		c = ii(c, d, a, b, x[i+10], 15, -1051523);
1448		b = ii(b, c, d, a, x[i+ 1], 21, -2054922799);
1449		a = ii(a, b, c, d, x[i+ 8], 6 ,  1873313359);
1450		d = ii(d, a, b, c, x[i+15], 10, -30611744);
1451		c = ii(c, d, a, b, x[i+ 6], 15, -1560198380);
1452		b = ii(b, c, d, a, x[i+13], 21,  1309151649);
1453		a = ii(a, b, c, d, x[i+ 4], 6 , -145523070);
1454		d = ii(d, a, b, c, x[i+11], 10, -1120210379);
1455		c = ii(c, d, a, b, x[i+ 2], 15,  718787259);
1456		b = ii(b, c, d, a, x[i+ 9], 21, -343485551);
1457
1458		a = add(a, olda);
1459		b = add(b, oldb);
1460		c = add(c, oldc);
1461		d = add(d, oldd);
1462	}
1463	return rhex(a) + rhex(b) + rhex(c) + rhex(d);
1464}
1465
1466function PassPhrase104(passphraseStr, KEY1, KEY2, KEY3, KEY4)
1467{
1468
1469	var     pseed2 = "";
1470	Length2 = passphraseStr.value.length;
1471
1472	for(p=0; p<64; p++) {
1473		tempCount = p % Length2;
1474		pseed2 += passphraseStr.value.substring(tempCount, tempCount+1);
1475	}
1476	md5Str = calcMD5(pseed2);
1477
1478	KEY1.value = md5Str.substring(0, 26).toUpperCase();
1479	KEY2.value = md5Str.substring(0, 26).toUpperCase();
1480	KEY3.value = md5Str.substring(0, 26).toUpperCase();
1481	KEY4.value = md5Str.substring(0, 26).toUpperCase();
1482}
1483
1484function clickgenerate(form)
1485{
1486
1487	if(form.passphraseStr.value.length == 0 )
1488	{
1489	//	alert("�A??�J 1 ��32 ASCII�r������4?�K?�C")
1490			return false;
1491	}
1492	for(i=0;i<form.passphraseStr.value.length;i++)
1493	{
1494		if(isValidChar_space(form.passphraseStr.value.charCodeAt(i))==false)
1495		{
1496			alert("�K?�������F����?���r��");
1497			return false;
1498		}
1499	}
1500	if(form.wepenc.options[0].selected == true)
1501		PassPhrase40(form.passphraseStr, form.wepenc, form.wep_key_no, form.KEY1, form.KEY2, form.KEY3, form.KEY4);
1502	else
1503		PassPhrase104(form.passphraseStr, form.KEY1, form.KEY2, form.KEY3, form.KEY4);
1504	form.generate_flag.value=1;
1505}
1506function clickgenerate_a(form)
1507{
1508	if(form.passphraseStr_an.value.length == 0 )
1509	{
1510	//	alert("�A??�J 1 ��32 ASCII�r������4?�K?�C")
1511			return false;
1512	}
1513	for(i=0;i<form.passphraseStr_an.value.length;i++)
1514	{
1515		if(isValidChar_space(form.passphraseStr_an.value.charCodeAt(i))==false)
1516		{
1517			alert("�K?�������F����?���r��");
1518			return false;
1519		}
1520	}
1521	if(form.Wepenc_an.options[0].selected == true)
1522		PassPhrase40(form.passphraseStr_an, form.Wepenc_an, form.wep_key_no_an, form.KEY1_an, form.KEY2_an, form.KEY3_an, form.KEY4_an);
1523	else
1524		PassPhrase104(form.passphraseStr_an, form.KEY1_an, form.KEY2_an, form.KEY3_an, form.KEY4_an);
1525	form.generate_flag.value=1;
1526}
1527
1528function doPortChange(check)
1529{
1530	if(check == 0)
1531	{
1532		location.href="forwarding.htm";
1533	}
1534	else
1535		location.href="triggering.htm";
1536}
1537
1538function setBlank(OnOffFlag,formFields)
1539{
1540	if(OnOffFlag == true)
1541	{
1542	        for (var i = 1; i < setBlank.arguments.length; i++)
1543                	setBlank.arguments[i].value = "";
1544	}
1545}
1546
1547function setDisabled(OnOffFlag,formFields)
1548{
1549	for (var i = 1; i < setDisabled.arguments.length; i++)
1550		setDisabled.arguments[i].disabled = OnOffFlag;
1551}
1552
1553function change_serv(cf)
1554{
1555/*
1556	if ( cf.login_type[2].selected == true )
1557		location.href="BAS_pppoe.htm";
1558	else if ( cf.login_type[0].selected == true )
1559		location.href="BAS_pptp.htm";
1560	else if (cf.login_type[1].selected == true )
1561		location.href="BAS_bpa.htm";
1562	else if (cf.login_type[3].selected == true )
1563		location.href="BAS_mulpppoe.htm";
1564*/
1565	if( cf.login_type.value == "PPTP" )
1566		location.href="BAS_pptp.htm";
1567	else if( cf.login_type.value == "L2TP" )
1568		location.href="BAS_l2tp.htm";
1569	else if( cf.login_type.value == "Telstra Bigpond" )
1570		location.href="BAS_bpa.htm";
1571	else if( cf.login_type.value == "Other" )
1572		location.href="BAS_pppoe.htm";
1573	else if(cf.login_type.value == "multiPPPoE" )
1574	{
1575		if(top.netgear_region != "JP")
1576			location.href="BAS_mulpppoe.htm";
1577		else
1578			location.href="BAS_mulpppoe_ww.htm";
1579	}
1580}
1581
1582function open_all_browser(form,flag)
1583{
1584	if(flag == 1)
1585		greendl_open = 1;
1586	else
1587		greendl_open = 0;
1588
1589	window.open('BT_browse.htm','browse','resizable=0,scrollvars=yes,width=400,height=400,left=400,top=300').focus();
1590}
1591
1592function change_ipv6(type)
1593{
1594	switch(type)
1595	{
1596		case "disabled":
1597			location.href="IPv6_disabled.htm";
1598			break;
1599		case "autoDetect":
1600			location.href="IPv6_auto.htm";
1601			break;
1602		case "autoConfig":
1603			location.href="IPv6_autoConfig.htm";
1604			break;
1605		case "6to4":
1606			location.href="IPv6_tunnel.htm";
1607			break;
1608		case "bridge":
1609			location.href="IPv6_passThrougth.htm";
1610			break;
1611		case "fixed":
1612			location.href="IPv6_fixed.htm";
1613			break;
1614		case "dhcp":
1615			location.href="IPv6_dhcp.htm";
1616			break;
1617		case "pppoe":
1618			location.href="IPv6_pppoe.htm";
1619			break;
1620		case "6rd":
1621                        location.href="IPv6_6rd.htm";
1622                        break;
1623		default:
1624			location.href="IPv6_disabled.htm";
1625			break;
1626	}
1627}
1628
1629function maccheck_multicast(mac_addr)
1630{
1631	mac_array=mac_addr.split(':');
1632	var mac11 = mac_array[0];
1633	mac11 = mac11.substr(1,1);
1634	if((mac11=="1")||(mac11=="3")||(mac11=="5")||(mac11=="7")||(mac11=="9")||(mac11=="b")||(mac11=="d")||(mac11=="f")||(mac11=="B")||(mac11=="D")||(mac11=="F"))
1635	{
1636		//Reject MAC address like 11:xx:xx:xx:xx:xx
1637		alert("?����MAC�a�}�I");
1638		return false;
1639	}
1640	if(mac_array.length!=6)
1641	{
1642	        alert("?����MAC�a�}�I");
1643		return false;
1644	}
1645	if(( mac_array[0]=="")||( mac_array[1]=="")||( mac_array[2]=="")||( mac_array[3]=="")||( mac_array[4]=="")||( mac_array[5]==""))
1646	{
1647	        alert("?����MAC�a�}�I");
1648		return false;
1649	}
1650	if((( mac_array[0]=="00")&&( mac_array[1]=="00")&&
1651	                        ( mac_array[2]=="00")&&( mac_array[3]=="00")&&
1652				( mac_array[4]=="00")&&( mac_array[5]=="00"))||
1653			(( mac_array[0]=="ff")&&( mac_array[1]=="ff")&&
1654			 ( mac_array[2]=="ff")&&( mac_array[3]=="ff")&&
1655			  ( mac_array[4]=="ff")&&( mac_array[5]=="ff"))||
1656			(( mac_array[0]=="FF")&&( mac_array[1]=="FF")&&
1657			 ( mac_array[2]=="FF")&&( mac_array[3]=="FF")&&
1658			 ( mac_array[4]=="FF")&&( mac_array[5]=="FF")))
1659	{
1660		alert("?����MAC�a�}�I");
1661		return false;
1662	}
1663        if(( mac_array[0].length!=2)||( mac_array[1].length!=2)||
1664                        ( mac_array[2].length!=2)||( mac_array[3].length!=2)||
1665                        ( mac_array[4].length!=2)||( mac_array[5].length!=2))
1666        {
1667                alert("?����MAC�a�}�I");
1668                return false;
1669        }
1670        for(i=0;i<mac_addr.length;i++)
1671        {
1672                if(isValidMac(mac_addr.charAt(i))==false)
1673                {
1674                        alert("?����MAC�a�}�I");
1675                        return false;
1676                }
1677        }
1678        return true;
1679}
1680
1681function maccheck(mac_addr)
1682{
1683	/*if ( mac_addr.indexOf(":")==-1 && mac_addr.length=="12" )
1684	{
1685		var tmp_mac=mac_addr.substr(0,2)+":"+mac_addr.substr(2,2)+":"+mac_addr.substr(4,2)+":"+mac_addr.substr(6,2)+":"+mac_addr.substr(8,2)+":"+mac_addr.substr(10,2);
1686		mac_addr = tmp_mac;
1687	}*/
1688	mac_array=mac_addr.split(':');
1689	var mac11 = mac_array[0];
1690	mac11 = mac11.substr(1,1);
1691	if((mac11=="1")||(mac11=="3")||(mac11=="5")||(mac11=="7")||(mac11=="9")||(mac11=="b")||(mac11=="d")||(mac11=="f")||(mac11=="B")||(mac11=="D")||(mac11=="F"))
1692	{
1693		alert("?����MAC�a�}�I");
1694		return false;
1695	}
1696	if(mac_array.length!=6)
1697	{
1698		alert("?����MAC�a�}�I");
1699		return false;
1700	}
1701	if(( mac_array[0]=="")||( mac_array[1]=="")||( mac_array[2]=="")||( mac_array[3]=="")||( mac_array[4]=="")||( mac_array[5]==""))
1702	{
1703		alert("?����MAC�a�}�I");
1704		return false;
1705	}
1706	if((( mac_array[0]=="00")&&( mac_array[1]=="00")&&
1707				( mac_array[2]=="00")&&( mac_array[3]=="00")&&
1708				( mac_array[4]=="00")&&( mac_array[5]=="00"))||
1709			(( mac_array[0]=="ff")&&( mac_array[1]=="ff")&&
1710			 ( mac_array[2]=="ff")&&( mac_array[3]=="ff")&&
1711			 ( mac_array[4]=="ff")&&( mac_array[5]=="ff"))||
1712			(( mac_array[0]=="FF")&&( mac_array[1]=="FF")&&
1713			 ( mac_array[2]=="FF")&&( mac_array[3]=="FF")&&
1714			 ( mac_array[4]=="FF")&&( mac_array[5]=="FF")))
1715	{
1716		alert("?����MAC�a�}�I");
1717		return false;
1718	}
1719	if(( mac_array[0].length!=2)||( mac_array[1].length!=2)||
1720			( mac_array[2].length!=2)||( mac_array[3].length!=2)||
1721			( mac_array[4].length!=2)||( mac_array[5].length!=2))
1722	{
1723		alert("?����MAC�a�}�I");
1724		return false;
1725	}
1726
1727	for(i=0;i<mac_addr.length;i++)
1728	{
1729		if(isValidMac(mac_addr.charAt(i))==false)
1730		{
1731			alert("?����MAC�a�}�I");
1732			return false;
1733		}
1734	}
1735	return true;
1736}
1737
1738function setMAC(cf,this_mac)
1739{
1740	var dflag;
1741
1742	if (cf.MACAssign[0].checked || cf.MACAssign[1].checked)
1743	{
1744		dflag = true;
1745		cf.Spoofmac.value=this_mac;
1746		setDisabled(dflag,cf.Spoofmac);
1747	}
1748	else
1749	{
1750		dflag = false;
1751		setDisabled(dflag,cf.Spoofmac);
1752		cf.Spoofmac.value=this_mac;
1753	}
1754}
1755
1756function maccheck_wds(mac_addr,num,form)
1757{
1758	var return_num=0;
1759	//if(mac_addr==":::::")
1760	if(mac_addr=="")
1761		return 2;
1762	var mac_array=mac_addr.split(':');
1763	var mac11 = mac_array[0];
1764	mac11 = mac11.substr(1,1);
1765	if((mac11=="1")||(mac11=="3")||(mac11=="5")||(mac11=="7")||
1766			(mac11=="9")||(mac11=="b")||(mac11=="d")||(mac11=="f")||
1767			(mac11=="B")||(mac11=="D")||(mac11=="F"))
1768	{
1769		if( mac11 == "1" && mac_array[0]=="11")
1770		{}
1771		else
1772			return 1;
1773	}
1774	if(mac_addr.length!=17 && mac_addr.length!=0)
1775		return 1;
1776	if((mac_array[0]=="")||(mac_array[1]=="")||(mac_array[2]=="")||(mac_array[3]=="")|| (mac_array[4]=="")||(mac_array[5]==""))
1777	{
1778		if((mac_array[0]=="")&&(mac_array[1]=="")&&(mac_array[2]=="")&&(mac_array[3]=="")&& (mac_array[4]=="")&&(mac_array[5]==""))
1779			return 2;
1780		else
1781			return 1;
1782	}
1783	if(((mac_array[0]=="00")&&(mac_array[1]=="00")&&
1784				(mac_array[2]=="00")&&(mac_array[3]=="00")&&
1785				(mac_array[4]=="00")&&(mac_array[5]=="00"))||
1786			((mac_array[0]=="ff")&&(mac_array[1]=="ff")&&
1787			 (mac_array[2]=="ff")&&(mac_array[3]=="ff")&&
1788			 (mac_array[4]=="ff")&&(mac_array[5]=="ff"))||
1789			((mac_array[0]=="FF")&&(mac_array[1]=="FF")&&
1790			 (mac_array[2]=="FF")&&(mac_array[3]=="FF")&&
1791			 (mac_array[4]=="FF")&&(mac_array[5]=="FF")))
1792		return 1;
1793	if((mac_array[0].length!=2)||(mac_array[1].length!=2)||
1794			(mac_array[2].length!=2)||(mac_array[3].length!=2)||
1795			(mac_array[4].length!=2)||(mac_array[5].length!=2))
1796		return 1;
1797	for(i=0;i<mac_addr.length;i++)
1798		if(isValidMac(mac_addr.charAt(i))==false)
1799			return 1;
1800	if( num != "" && num != 0 && num != 1 )
1801	{
1802		for( k=1;k<num;k++)
1803		{
1804			mac_str=eval('the_mac'+k);
1805			if( mac_str != "" && mac_str.toLowerCase() == mac_addr.toLowerCase())
1806			{
1807				return 3;
1808			}
1809		}
1810	}
1811	return return_num;
1812}
1813
1814function change_sec_to_time(uptime)
1815{
1816	var sec=uptime;
1817	var sec=parseInt(sec);
1818	var day_sec=sec%86400;
1819	if(day_sec!=sec)
1820		new_day=(sec-day_sec)/86400;
1821	else
1822		new_day=0;
1823	var hour_sec=day_sec%3600;
1824	if(hour_sec!=day_sec)
1825		new_hour=(day_sec-hour_sec)/3600;
1826	else
1827		new_hour=0;
1828	var min_sec=hour_sec%60;
1829	if(min_sec!=hour_sec)
1830		new_min=(hour_sec-min_sec)/60;
1831	else
1832		new_min=0;
1833	var new_sec=min_sec;
1834	new_day=new_day.toString();
1835	new_hour=new_hour.toString();
1836	new_min=new_min.toString();
1837	new_sec=new_sec.toString();
1838	if(new_day.length==1)
1839		new_day='0'+new_day;
1840	if(new_hour.length==1)
1841		new_hour='0'+new_hour;
1842	if(new_min.length==1)
1843		new_min='0'+new_min;
1844	if(new_sec.length==1)
1845		new_sec='0'+new_sec;
1846	if(new_day == '00')
1847	{
1848		var new_time=new_hour+':'+new_min+':'+new_sec;
1849	}
1850	else
1851	{
1852		var new_time=new_day+':'+new_hour+':'+new_min+':'+new_sec;
1853	}
1854	return new_time;
1855}
1856
1857function goTestApply()
1858{
1859	var winoptions = "width=640,height=480,menubar=yes,scrollbars=yes,toolbar=yes,status=yes,location=yes,resizable=yes"
1860	if( run_test == "test")
1861	{
1862		if( in_hijack == true)// to fix bug 32600
1863			window.open("BRS_check_manulConfig.html", null, winoptions);
1864		else
1865			window.open("http://www.netgear.com/success/r7500.aspx",null,winoptions);
1866
1867	}
1868}
1869function isValidForwardPort(each_char)
1870{//0-9,',',' ','-'
1871	if (!(((each_char>47) && (each_char<58))||(each_char==45)|| (each_char==32) || (each_char==44)|| (each_char==8)||(each_char==0)))
1872		return false;
1873}
1874function isValidMac(digit)
1875{
1876	var macVals = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9","A", "B", "C", "D", "E", "F", "a", "b", "c", "d", "e", "f",":");
1877	var len = macVals.length;
1878	var i = 0;
1879	var ret = false;
1880	for ( i = 0; i < len; i++ )
1881		if ( digit == macVals[i] ) break;
1882	if ( i < len )
1883		ret = true;
1884	return ret;
1885}
1886
1887function isValidHex(each_char)
1888{
1889	var macVals = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9","A", "B", "C", "D", "E", "F", "a", "b", "c", "d", "e", "f");
1890	var len = macVals.length;
1891	var i = 0;
1892	var ret = false;
1893	for ( i = 0; i < len; i++ )
1894		if ( each_char == macVals[i] ) break;
1895	if ( i < len )
1896		ret = true;
1897	return ret;
1898}
1899
1900function isValidDevName(each_char)
1901{
1902	if(!( each_char == 45 || (each_char > 47 && each_char < 58) || (each_char > 64 && each_char < 91) || (each_char>96 && each_char<123)))
1903		return false;
1904}
1905
1906function isValidChar_space(each_char)
1907{
1908	if( each_char < 32 || each_char > 127)
1909		return false;
1910}
1911
1912function isValidChar(each_char)
1913{
1914	if( each_char < 33 || each_char > 126)
1915		return false;
1916}
1917
1918function isValidCharFolderName(each_char)
1919{
1920	if( each_char < 32 || each_char > 126)
1921		return false;
1922	else if( each_char == 34 || each_char == 42 || each_char == 47 || each_char == 58 || each_char == 60  || each_char == 62 || each_char == 63 || each_char == 92 || each_char == 124)
1923		return false;
1924}
1925
1926function isValidDdnsHost(each_char)
1927{
1928	if (!(((each_char>47) && (each_char<58))||(each_char==45)||(each_char==46)||((each_char>64) && (each_char<91))||((each_char>96) && (each_char<123)) || (each_char==8)||(each_char==0)))
1929		return false;
1930}
1931
1932function isValidDdnsOrayUserName(each_char)
1933{// 0-9, a-z, A-Z, -, _
1934	if (!(((each_char>47) && (each_char<58))||(each_char==45)||(each_char==95)||((each_char>64) && (each_char<91))||((each_char>96) && (each_char<123)) || (each_char==8)||(each_char==0)))
1935		return false;
1936}
1937
1938function isValidDdns3322UserName(each_char)
1939{// 0-9, a-z
1940	if (!(((each_char>47) && (each_char<58))||((each_char>96) && (each_char<123)) || (each_char==8)||(each_char==0) || (each_char==95)))
1941		return false;
1942}
1943
1944function isValidNumLetter(each_char)
1945{
1946	if((each_char>47 && each_char<58)||(each_char>64 && each_char<91)||(each_char>96 && each_char<123))
1947		return true;
1948	else
1949		return false;
1950}
1951
1952function isValidLetter(each_char)
1953{
1954	if((each_char>64 && each_char<91)||(each_char>96 && each_char<123))
1955		return true;
1956	else
1957		return false;
1958}
1959
1960function remove_space(str)
1961{
1962	str = delete_end_space(str);
1963	str = str.replace(/^\s*/, "");
1964
1965	return str;
1966}
1967
1968function printPage()
1969{
1970	if (window.print)
1971		window.print();
1972	else
1973		alert("");
1974}
1975function top_left_nolink()
1976{
1977	if( parent.multi_lang_router_flag == 1 )
1978	{
1979		parent.topframe.document.forms[0].lang_avi.disabled = true;
1980		//parent.topframe.document.forms[0].apply.disabled = true;
1981	}
1982}
1983
1984function wlan_txctrl(form, tx_power_ctrl, tx_power_ctrl_an, wla_channel, country)
1985{
1986        if((netgear_region == "WW" || netgear_region == "") && (country != "3" && country != "10"))
1987        {
1988		if(tx_power_ctrl == "100")
1989                        form.wl_tx_ctrl.value="44";
1990                else if(tx_power_ctrl == "75")
1991                        form.wl_tx_ctrl.value="10.5";
1992                else if(tx_power_ctrl == "50")
1993                        form.wl_tx_ctrl.value="7";
1994                else if(tx_power_ctrl == "25")
1995                        form.wl_tx_ctrl.value="3.5";
1996
1997                //for 5G
1998                if(tx_power_ctrl_an == "100")
1999                        form.wla_tx_ctrl.value="44";
2000                if(parseInt(wla_channel) >= 36 && parseInt(wla_channel) <= 64)
2001                {
2002                        if(tx_power_ctrl_an == "75")
2003                                form.wla_tx_ctrl.value="12.5";
2004                        else if(tx_power_ctrl_an == "50")
2005                                form.wla_tx_ctrl.value="8.5";
2006                        else if(tx_power_ctrl_an == "25")
2007                                form.wla_tx_ctrl.value="4";
2008                }
2009                else if(parseInt(wla_channel) >= 100)
2010                {
2011                        if(tx_power_ctrl_an == "75")
2012                                form.wla_tx_ctrl.value="15.5";
2013                        else if(tx_power_ctrl_an == "50")
2014                                form.wla_tx_ctrl.value="10.5";
2015                        else if(tx_power_ctrl_an == "25")
2016                                form.wla_tx_ctrl.value="5";
2017		}
2018	}
2019        else
2020        {
2021                if(tx_power_ctrl == "100")
2022                        form.wl_tx_ctrl.value="44";
2023                else if(tx_power_ctrl == "75")
2024                        form.wl_tx_ctrl.value="18";
2025                else if(tx_power_ctrl == "50")
2026                        form.wl_tx_ctrl.value="12";
2027                else if(tx_power_ctrl == "25")
2028                        form.wl_tx_ctrl.value="6";
2029
2030		//for 5G
2031                if(tx_power_ctrl_an == "100")
2032                        form.wla_tx_ctrl.value="44";
2033                if(parseInt(wla_channel) >= 36 && parseInt(wla_channel) <= 48)
2034                {
2035                        if(tx_power_ctrl_an == "75")
2036                                form.wla_tx_ctrl.value="10.5";
2037                        else if(tx_power_ctrl_an == "50")
2038                                form.wla_tx_ctrl.value="7";
2039                        else if(tx_power_ctrl_an == "25")
2040                                form.wla_tx_ctrl.value="3.5";
2041                }
2042                else if(parseInt(wla_channel) >= 52 && parseInt(wla_channel) <= 165)
2043                {
2044                        if(tx_power_ctrl_an == "75")
2045                                form.wla_tx_ctrl.value="15.5";
2046                        else if(tx_power_ctrl_an == "50")
2047                                form.wla_tx_ctrl.value="10.5";
2048                        else if(tx_power_ctrl_an == "25")
2049                                form.wla_tx_ctrl.value="5";
2050                }
2051	}
2052
2053	//the current values should be changed to (urrent_value+6)*2.
2054	form.wl_tx_ctrl.value = ( parseFloat(form.wl_tx_ctrl.value) + 6 ) * 2;
2055	form.wla_tx_ctrl.value = ( parseFloat(form.wla_tx_ctrl.value) + 6 ) * 2;
2056	if(tx_power_ctrl_an == "super_wifi"){
2057		form.hid_super_wifi_an.value = "1";
2058	}
2059	if(pr_flag ==1 && super_wifi_flag == "1" && super_wifi_value_an != form.hid_super_wifi_an.value)
2060	{
2061		if( form.hid_super_wifi_an.value == "1")
2062			form.hid_super_wifi_reboot.value="1"; // from disable to enable
2063		else
2064			form.hid_super_wifi_reboot.value="2"; // from enable to disable
2065
2066	}
2067	if(tx_power_ctrl == "super_wifi"){
2068                form.hid_super_wifi.value = "1";
2069	}
2070
2071}
2072
2073function delete_end_space(str) //delete all the space at the end of a sting.
2074{
2075        var i;
2076
2077        for(i=str.length-1; str.charAt(i)==" "; i--)
2078        {
2079                str = str.substring(0, i);
2080        }
2081
2082        return str;
2083}
2084
2085//check if the port input is conflict with the USB ReadyShare port.
2086function check_port_range(input_start_port, input_end_port, port_using)
2087{
2088        if(parseInt(input_start_port)<=parseInt(port_using) && parseInt(input_end_port)>=parseInt(port_using))
2089        {
2090                return false;
2091        }
2092
2093        return true;
2094}
2095function check_readyshare_port(input_start_port, input_end_port, type)
2096{
2097        if(show_enableHTTP == '0' && (type == "LAN" || type == "ALL"))
2098        {
2099                if(check_port_range(input_start_port, input_end_port, 80) == false)
2100                        return false;
2101        }
2102        if(show_enableHvia == '0' && (type == "WAN" || type == "ALL"))
2103        {
2104                if(check_port_range(input_start_port, input_end_port, show_HTTP_via_port) == false)
2105                        return false
2106        }
2107        if(is_ftp == 1)
2108        {
2109                if(show_enableFTP == '0' && (type == "LAN" || type == "ALL"))
2110                {
2111                        if(check_port_range(input_start_port, input_end_port, 21) == false)
2112                                return false;
2113                }
2114                if(show_enableFvia == '0' && (type == "WAN" || type == "ALL") )
2115                {
2116                        if(check_port_range(input_start_port, input_end_port, show_FTP_via_port) == false)
2117                                return false;
2118                }
2119        }
2120
2121        return true;
2122}
2123
2124String.prototype.checkFolder=function()
2125{//test string
2126        var   s   =   ["\\","\"","\'","?",":","<",">","|","*"];
2127        for   (var   i=0;   i<s.length;   i++){
2128                  if   (this.indexOf(s[i])   !=   -1)   return   true;}
2129        return   false;
2130}
2131String.prototype.checkShareName=function()
2132{//test string
2133	var   s   =   ["\\","\"","\/","?",":","<",">","|","*","\]"];
2134	for   (var   i=0;   i<s.length;   i++){
2135		if   (this.indexOf(s[i])   !=   -1)   return   true;}
2136	return   false;
2137}
2138
2139//for bug 23249, format the input value for IP address, change "012" to "12", "000" to "0"
2140function format_IP()
2141{
2142	var argv = format_IP.arguments;
2143	var cf = document.forms[0];
2144
2145	var i;
2146	var input_form;
2147	for(i=0; i<argv.length; i++)
2148	{
2149		input_form = eval("cf." + argv[i]);
2150		if( null == input_form ) continue;
2151
2152		if(input_form.value != "")
2153			input_form.value = parseInt(input_form.value, 10).toString(10);
2154	}
2155
2156	return true;
2157}
2158
2159/* to fix bug 24964 */
2160function close_top_window()
2161{
2162	/* for Chrome, it need to use window.open(), and then use window.close() */
2163	window.open('', '_self', '');
2164
2165	top.window.close();
2166}
2167
2168function ru_wizard()
2169{
2170	if( isIE_or_Opera() && IE_version()!=9 )
2171	{
2172		var frame_height= top.document.getElementById("formframe_div").style.height.replace(/px/,"");
2173		document.getElementsByTagName("div")[0].style.height = frame_height;
2174	}
2175}
2176
2177/* to fix bug */
2178function scroll_show()
2179{
2180	if( top.location.href.indexOf("adv_index.htm") != -1 )
2181	{
2182		var frame_div = top.document.getElementById("formframe_div");
2183		ru_wizard();
2184		if(isIE()){
2185		frame_div.onresize = ru_wizard;
2186		}
2187		if( get_browser() == "Opera"){
2188		window.onresize = ru_wizard;
2189		}
2190	}
2191	else if ( top.location.href.indexOf("BRS_index.htm") != -1 )
2192	{
2193		document.getElementsByTagName("div")[0].style.height = "500";
2194	}
2195}
2196
2197//fixed bug36052[Beta Tester][IR-064]Attached devices screen looks very disorganized
2198function convert(value, dataType) {
2199        switch(dataType) {
2200    case "int":
2201                var each_info = value.split(".");
2202		if(each_info.length!=4)
2203			return 0;
2204                value = parseInt(each_info[0]) + parseInt(each_info[1]) + parseInt(each_info[2]) + parseInt(each_info[3]);
2205                return parseInt(value);
2206                break
2207    default:
2208                return value.toString();
2209  }
2210}
2211
2212function compareCols(col, dataType) {
2213        return function compareTrs(tr1, tr2) {
2214                value1 = convert(tr1.cells[col].innerHTML, dataType);
2215                value2 = convert(tr2.cells[col].innerHTML, dataType);
2216                if (value1 < value2) {
2217                        return -1;
2218                } else if (value1 > value2) {
2219                        return 1;
2220                } else {
2221                        return 0;
2222                }
2223        };
2224}
2225
2226function sortTable(tableId, col, dataType)
2227{
2228	var table = document.getElementById(tableId);
2229	var tbody = table.tBodies[0];
2230	var tr = tbody.rows;
2231	var trValue = new Array();
2232        for (var i=0; i<tr.length; i++ ){
2233		trValue[i] = tr[i];
2234	}
2235	if (tbody.sortCol == col) {
2236		trValue.reverse();
2237	} else {
2238		trValue.sort(compareCols(col, dataType));
2239	}
2240	var fragment = document.createDocumentFragment();
2241	for (var i=0; i<trValue.length; i++ ) {
2242		if( i%2== 1 )
2243			trValue[i].className = "even_line";
2244		else
2245			trValue[i].className = "odd_line";
2246		trValue[i].cells[0].innerHTML = i+1;
2247		trValue[i].cells[0].className = "subhead";
2248		fragment.appendChild(trValue[i]);
2249	}
2250	tbody.appendChild(fragment);
2251	tbody.sortCol = col;
2252}
2253
2254function getElementsByTagAndName(tagName, eName)
2255{//IE not support getElementsByName to find divs, so use this function to find divs
2256	tags = document.getElementsByTagName(tagName);
2257	var elements = new Array();
2258
2259	if(tags!=null && tags.length>0){
2260		for(var z=0; z<tags.length; z++){
2261			if(tags[z].getAttribute("name") == eName){
2262				elements[elements.length] = tags[z];
2263			}
2264		}
2265	}
2266	return elements;
2267}
2268
2269
2270/*router ap extender pages*/
2271function select_type( type)
2272{
2273	if(type === undefined)
2274		type =document.forms[0].operation_type.value;
2275
2276	if(type == 0 )
2277		location.href="WLG_opmode_router_dual_band.htm";
2278	else if(type == 1 )
2279		location.href="WLG_opmode_ap_dual_band.htm";
2280	else if(type == 2 )
2281		location.href="WLG_opmode_bridge_dual_band.htm";
2282	else if(type == 3 )
2283		location.href="WLG_opmode_repeating_dual_band.htm";
2284
2285}
2286
2287function gotto_link(sub, id)
2288{
2289	if(sub != "None")
2290		top.open_or_close_sub(sub);
2291	top.click_adv_action(id);
2292}
2293
2294function sAlert(str, callback_ok, callback_cancel, dwidth, anc){
2295
2296	var mode = "alert";
2297	callback_ok = callback_ok || 0;
2298	callback_cancel = callback_cancel || 0;
2299
2300	var anc_v=anc || 0; // anc�� click apply button, not close div
2301
2302	var msgw,msgh,bordercolor;
2303	msgw=dwidth||420;//warning width
2304	msgh=160;//warning height
2305
2306	//if have cancel callback function, show cancel button
2307	if(typeof(callback_cancel) == "function" )
2308		mode = "confirm";
2309
2310	if(document.getElementById("bgDiv") != undefined)
2311		removeObj();
2312
2313	titleheight=25;//warning title height
2314	var sWidth,sHeight;
2315	sWidth=document.body.offsetWidth;//page width
2316	sHeight=screen.height;//page height
2317	//background div
2318	var bgObj=document.createElement("div");//create a div
2319	//setting div Attribute
2320	bgObj.setAttribute('id','bgDiv');
2321	bgObj.style.position="absolute";
2322	bgObj.style.top="0";
2323	bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
2324	bgObj.style.opacity="0.6";
2325	bgObj.style.left="0";
2326	bgObj.style.width=sWidth + "px";
2327	bgObj.style.height=sHeight + "px";
2328	bgObj.style.zIndex = "10000";
2329	document.body.appendChild(bgObj);//add this div into body
2330	//create warning div
2331	var msgObj=document.createElement("div");
2332	msgObj.setAttribute("id","msgDiv");
2333	msgObj.setAttribute("align","center");
2334	//msgObj.style.background=" url(image/confirm.gif) no-repeat";
2335	msgObj.style.position = "absolute";
2336	msgObj.style.left = "40%";
2337	msgObj.style.top = "30%";
2338	msgObj.style.marginLeft = "-225px" ;
2339	msgObj.style.width = msgw + "px";
2340	//msgObj.style.height = msgh + "px";
2341	msgObj.style.zIndex = "10001";
2342	msgObj.className = msgObj.className+ " pop_box";
2343	var div1=document.createElement("div");//create msg div
2344	//setting msg div
2345	div1.setAttribute("id","msgTitle");
2346	div1.setAttribute("align","left");
2347	//div1.style.marginTop="30px";
2348	div1.style.marginLeft="30px";
2349	div1.style.marginRight="30px";
2350	div1.style.marginBottom="20px";
2351	div1.style.padding="0px";
2352	div1.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);";
2353	div1.style.opacity="0.75";
2354	//div1.style.height="85px";
2355	div1.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif";
2356	div1.style.cursor="pointer";
2357	div1.innerHTML=str;
2358	var button=document.createElement("input");//create ok button
2359	//setting ok button
2360	button.setAttribute("type","button");
2361	button.setAttribute("value","OK");
2362	button.style.width="80px";
2363	button.style.marginLeft="140px";
2364	button.style.marginBottom="10px";
2365	button.style.background=" #702b86";
2366	button.style.border="1px solid "+ " #702b86";
2367	button.style.color="white";
2368	button.onclick=click_ok;
2369	var button1=document.createElement("input");//create cancel button
2370	//setting cancel button
2371	button1.setAttribute("type","button");
2372	button1.setAttribute("value","Cancel");
2373	button1.style.width="80px";
2374	button1.style.marginLeft="10px";
2375	//button1.style.marginBottom="10px";
2376	button1.style.background="#5bb6e5";
2377	button1.style.border="1px solid "+ "#5bb6e5";
2378	button1.style.color="white";
2379	button1.onclick=click_cancel;
2380	function removeObj(){//close warning
2381		document.body.removeChild(document.getElementById("bgDiv"));//delete background div
2382		document.getElementById("msgDiv").removeChild(document.getElementById("msgTitle"));//delete title
2383		document.forms[0].removeChild(document.getElementById("msgDiv"));//delete warning
2384	}
2385	function click_ok(){//for Ok button
2386		if(anc_v == 0 )
2387			removeObj();
2388
2389		if(typeof(callback_ok)== "function")
2390			callback_ok();
2391
2392	}
2393
2394	function click_cancel(){// for cancel button
2395		if(typeof(callback_cancel) == "function")
2396			callback_cancel();
2397		removeObj();
2398	}
2399
2400	document.forms[0].appendChild(msgObj);//add warning div into body
2401	document.getElementById("msgDiv").appendChild(div1);// add title into warning div
2402	var txt=document.createElement("p");//add warning infomation into warning div
2403	document.getElementById("msgDiv").appendChild(div1);
2404	document.getElementById("msgDiv").appendChild(button);//add ok button into warning div
2405	if(mode == "confirm")
2406		document.getElementById("msgDiv").appendChild(button1); //add cancel button into warning div
2407}
2408
2409function check_dev()
2410{
2411	var num;
2412	var cf = document.forms[0];
2413	var space_flag=0;
2414	var dev_name=cf.new_devname.value;
2415	warning=document.getElementById("devn_error");
2416	warning.style.display="none";
2417
2418	if(dev_name == ""){
2419		warning.innerHTML="Device name can not be null.";
2420		warning.style.display="";
2421		return false;
2422	}
2423
2424	if(dev_name.length > 16){
2425		warning.innerHTML="name too long";
2426		warning.style.display="";
2427		return false;
2428	}
2429	for(i=0;i<dev_name.length;i++){
2430		if(dev_name.charCodeAt(i)!=32)
2431			space_flag++;
2432		if(isValidDevName(dev_name.charCodeAt(i))==false)
2433		{
2434			warning.innerHTML="Invalid device name.";
2435			warning.style.display="";
2436			return false;
2437		}
2438	}
2439	if( dev_name.checkShareName()){
2440		warning.innerHTML="Invalid character or characters in "+"Network/Device Name";
2441		warning.style.display="";
2442		return false;
2443	}
2444	if(space_flag == 0){
2445		warning.innerHTML="name too long";
2446		warning.style.display="";
2447		return false;
2448	}
2449
2450	if(typeof(ed_action)!="undefined")
2451		cf.action=ed_action;
2452
2453	cf.submit_flag.value="edit_devname";
2454//	cf.submit();
2455	location.reload();
2456}
2457
2458function edit_devicename(name)
2459{
2460	sAlert('<table cellpadding=0 cellspacing=2  border=0><tr><td colspan=3 nowrap><h3>Edit Router Device Name</h3></td></tr><tr><td colspan=3 >Device Name identifies this router.It is used by many different features on the router including the ReadyShare features.</td></tr><tr><td nowrap style="height:40px">Device Name:</td><td><div id="devn_error" style="display: none;color:red">name too long</div></td>	<td nowrap align=right style="width:100px"><input type="text" name="new_devname" value="'+name+'" size="20" autocomplete="off" maxlength="20" onFocus="this.select();" onKeyPress="return getkey(\'ssid\', event)" ></td> </tr><tr><td colspan=3 >Please use alpha numericals up to 16 characters</td></tr><tr><td  colspan=3 height="20px"></td></tr></table>',check_dev, function(){return false;}, 600, 1)
2461}
2462