1function check_DNS(dnsaddr1,dnsaddr2,wan_assign,wan_ip)
2{
3	if(dnsaddr1!="")
4	{
5		if(checkipaddr(dnsaddr1)==false)
6		{
7			alert("<%518%>");
8			return false;
9		}
10		if( wan_assign == true && isSameIp(dnsaddr1,wan_ip))
11		{
12			alert("<%518%>");
13			return false;
14		}
15	}
16	if(dnsaddr2!="")
17	{
18		if(checkipaddr(dnsaddr2)==false)
19		{
20			alert("<%518%>");
21			return false;
22		}
23		if( wan_assign == true && isSameIp(dnsaddr2,wan_ip))
24		{
25			alert("<%518%>");
26			return false;
27		}
28	}
29
30	if(dnsaddr1=="" && dnsaddr2=="" )
31	{
32		alert("<%518%>");
33		return false;
34	}
35	return true;
36}
37/*
38	Saturday, Jan 01, 2000 10:51:13
39*/
40function change_cur_time(old_str,gui_region)
41{
42	each_str=old_str.split(', ');
43
44	week=each_str[0];
45	show_week=change_full_week(week);
46
47	date_info=each_str[1].split(' ');
48	month=date_info[0];
49	show_month=change_month(month);
50	day=date_info[1];
51
52	time=each_str[2];
53
54	if( gui_region == "German" )
55		new_str = show_week+', '+day+'.'+show_month+', '+time;
56	else
57		new_str = show_week+', '+show_month+' '+day+', '+time;
58
59	return new_str;
60}
61
62function change_week(week)
63{
64	var show_week;
65	if(week == "Mon")
66		show_week="Monday";
67	else if(week == "Tue")
68		show_week="Tuesday";
69	else if(week == "Wed")
70		show_week="Wednesday";
71	else if(week == "Thu")
72		show_week="Thursday";
73	else if(week == "Fri")
74		show_week="Friday";
75	else if(week == "Sat")
76		show_week="Saturday";
77	else if(week == "Sun")
78		show_week="Sunday";
79	else
80		show_week=week;
81
82	return show_week;
83}
84
85function change_full_week(week)
86{
87	var show_week;
88	if(week == "Monday")
89		show_week="Monday";
90	else if(week == "Tuesday")
91		show_week="Tuesday";
92	else if(week == "Wednesday")
93		show_week="Wednesday";
94	else if(week == "Thursday")
95		show_week="Thursday";
96	else if(week == "Friday")
97		show_week="Friday";
98	else if(week == "Saturday")
99		show_week="Saturday";
100	else if(week == "Sunday")
101		show_week="Sunday";
102	else
103		show_week=week;
104
105	return show_week;
106}
107
108function change_month(month)
109{
110	var show_month;
111	if( month == "Jan" )
112		show_month="Jan";
113	else if( month == "Feb" )
114		show_month="Feb";
115	else if( month == "Mar" )
116		show_month="Mar";
117	else if( month == "Apr" )
118		show_month="Apr";
119	else if( month == "May" )
120		show_month="May";
121	else if( month == "Jun" )
122		show_month="Jun";
123	else if( month == "Jul" )
124		show_month="Jul";
125	else if( month == "Aug" )
126		show_month="Aug";
127	else if( month == "Sep" )
128		show_month="Sep";
129	else if( month == "Oct" )
130		show_month="Oct";
131	else if( month == "Nov" )
132		show_month="Nov";
133	else if( month == "Dec" )
134		show_month="Dec";
135	else
136		show_month=month;
137	return show_month;
138}
139
140function change_month2num(month)
141{
142	var show_month;
143	if( month == "Jan" )
144		show_month="1";
145	else if( month == "Feb" )
146		show_month="2";
147	else if( month == "Mar" )
148		show_month="3";
149	else if( month == "Apr" )
150		show_month="4";
151	else if( month == "May" )
152		show_month="5";
153	else if( month == "Jun" )
154		show_month="6e";
155	else if( month == "Jul" )
156		show_month="7";
157	else if( month == "Aug" )
158		show_month="8";
159	else if( month == "Sep" )
160		show_month="9";
161	else if( month == "Oct" )
162		show_month="10";
163	else if( month == "Nov" )
164		show_month="11";
165	else if( month == "Dec" )
166		show_month="12";
167	else
168		show_month=month;
169	return show_month;
170}
171
172/* input ip, if input length = 3 or input '.' , change focus to next text, */
173function keydown(e,text)
174{
175	if((e.keyCode == 190 || e.keyCode == 110) && text.value.length !=0)
176		text.form[(getIndex(text)+1) % text.form.length].focus();
177}
178function keyup(e,text)
179{
180	if(text.value.length == 3 && (e.keyCode != 190 && e.keyCode != 110 && e.keyCode != 9))
181		text.form[(getIndex(text)+1) % text.form.length].focus();
182}
183function getIndex(input)
184{
185	var index = -1;
186	var i = 0;
187	var found = false;
188	while (i < input.form.length && index == -1)
189		if (input.form[i] == input)
190			index = i;
191		else
192			i++;
193	return index;
194}
195
196function getObj(name)
197{
198	if (document.getElementById)
199	{
200		return document.getElementById(name).style;
201	}
202	else if (document.all)
203	{
204		return document.all[name].style;
205	}
206	else if (document.layers)
207	{
208		return document.layers[name];
209	}
210}
211
212function check_maxNumAdd(form,nowNum,maxNum,msg,go2href)
213{
214	nowNum=parseInt(nowNum,10);
215	if (nowNum >= maxNum)
216	{
217		alert(msg);
218		return false;
219	}
220	else
221		location.href=go2href;
222}
223
224function checkIPMain(ip,max)
225{
226	if (isNumeric(ip, max) == false)
227		return false;
228}
229
230function checkIP(ip1, ip2, ip3, ip4,max)
231{
232	if(checkIPMain(ip1,255)==false) return false;
233	if(checkIPMain(ip2,255)==false) return false;
234	if(checkIPMain(ip3,255)==false) return false;
235	if(checkIPMain(ip4,max)==false) return false;
236	if((parseInt(ip1)==0)||(parseInt(ip1)==0)&&(parseInt(ip2)==0)&&(parseInt(ip3)==0)&&(parseInt(ip4)==0))
237		return false;
238	if ( ip1 == 0 )
239		return false;
240	return true;
241}
242
243/* Check Numeric*/
244function isNumeric(str, max)
245{
246	if(str.length == 0 || str == null || str == "")
247		return false;
248	for(i=0; i<str.length; i++)
249	{
250		var c = str.substring(i, i+1);
251		if("0" <= c && c <= "9")
252			continue;
253		else
254			return false;
255	}
256	var i = parseInt(str);
257	if(i>max)
258		return false;
259
260	return true;
261}
262
263function isIE()
264{
265	var browser = new Object();
266	browser.version = parseInt(navigator.appVersion);
267	browser.isNs = false;
268	browser.isIe = false;
269	if(navigator.appName.indexOf("Netscape") != -1)
270		browser.isNs = true;
271	else if(navigator.appName.indexOf("Microsoft") != -1)
272		browser.isIe = true;
273
274	if(browser.isNs)
275		return false;
276	else if (browser.isIe)
277		return true;
278	else
279		return false;
280}
281
282function get_browser()
283{
284	if(navigator.userAgent.indexOf("MSIE") != -1)
285		return "IE";
286	else if(navigator.userAgent.indexOf("Firefox") != -1)
287		return "Firefox";
288	else if(navigator.userAgent.indexOf("Safari") != -1 )
289		return "Safari";
290	else if(navigator.userAgent.indexOf("Camino") != -1)
291		return "Camino";
292	else if(navigator.userAgent.indexOf("Gecko/") != -1)
293		return "Gecko";
294	else
295		return "";
296}
297
298function load_default(step)
299{
300	if (parent.frames['IA_menu'])
301	{
302		for(var i=1;i<=3;i++)
303		{
304			var element = parent.frames['IA_menu'].document.getElementById("IA_menu_" + i);
305			element.className="left_nav_headers";
306		}
307		var element_current = parent.frames['IA_menu'].document.getElementById("IA_menu_" + step);
308		element_current.className="left_nav_headers_current_state";
309	}
310}
311
312function _isNumeric(str)
313{
314	var i;
315	for(i = 0; i<str.length; i++)
316	{
317		var c = str.substring(i, i+1);
318		if("0" <= c && c <= "9")
319		{
320			continue;
321		}
322		return false;
323	}
324	return true;
325}
326
327function isSameIp(ipstr1,ipstr2)
328{
329	var count = 0;
330	var ip1_array=ipstr1.split('.');
331	var ip2_array=ipstr2.split('.');
332	for(i = 0;i<4;i++)
333	{
334		num1 = parseInt(ip1_array[i]);
335		num2 = parseInt(ip2_array[i]);
336		if( num1 == num2)
337			count++;
338	}
339	if( count == 4)
340		return true;
341	else
342		return false;
343}
344
345function cp_ip2(from,to)
346//true invalid from and to ip;  false valid from and to ip;
347{
348	var total1 = 0;
349	var total2 = 0;
350	var from_array=from.split('.');
351	var to_array = to.split('.');
352	var from1=from_array[0];
353	var from2=from_array[1];
354	var from3=from_array[2];
355	var from4=from_array[3];
356	var to1=to_array[0];
357	var to2=to_array[1];
358	var to3=to_array[2];
359	var to4=to_array[3];
360
361	total1 += parseInt(from4);
362	total1 += parseInt(from3)*256;
363	total1 += parseInt(from2)*256*256;
364	total1 += parseInt(from1)*256*256*256;
365
366	total2 += parseInt(to4);
367	total2 += parseInt(to3)*256;
368	total2 += parseInt(to2)*256*256;
369	total2 += parseInt(to1)*256*256*256;
370	if(total1 <= total2)
371		return true;
372	return false;
373}
374
375function is_sub_or_broad(be_checkip, ip, mask)
376{
377	var addr_arr = be_checkip.split('.');
378	var ip_addr=0;
379	for (i = 0; i < 4; i++)
380	{
381		addr_str = parseInt(addr_arr[i],10);
382		ip_addr=ip_addr*256+parseInt(addr_str);
383	}
384	var ip_sub=isSub(ip, mask);
385	var ip_broadcast=isBroadcast(ip, mask);
386	if(ip_addr == ip_sub || ip_addr == ip_broadcast)
387	{
388		return false;
389	}
390	return true;
391}
392
393function isGateway(lanIp, lanMask, gtwIp)
394{
395	var gtw_arr = gtwIp.split('.');
396	var ip_gtw=0;
397	for (i = 0; i < 4; i++)
398	{
399		gtw_str = parseInt(gtw_arr[i],10);
400		ip_gtw=ip_gtw*256+parseInt(gtw_str);
401	}
402
403	var addr_arr = lanIp.split('.');
404	var ip_addr=0;
405	for (i = 0; i < 4; i++)
406	{
407		addr_str = parseInt(addr_arr[i],10);
408		ip_addr=ip_addr*256+parseInt(addr_str);
409	}
410
411	var ip_sub=isSub(lanIp, lanMask);
412	var ip_broadcast=isBroadcast(lanIp, lanMask);
413	if((parseInt(ip_sub)<parseInt(ip_gtw))&&(parseInt(ip_gtw)<parseInt(ip_broadcast)))
414		return true;
415	else
416		return false;
417}
418
419function isSub(lanIp, lanMask)
420{
421	var ip_arr = lanIp.split('.');
422	var mask_arr = lanMask.split('.');
423	var ip_sub=0
424	for (i = 0; i < 4; i++)
425	{
426		ip_str = parseInt(ip_arr[i],10);
427		mask_str = parseInt(mask_arr[i],10);
428		ip_sub=ip_sub*256+parseInt(ip_str & mask_str)
429	}
430	return(ip_sub);
431}
432
433function isBroadcast(lanIp, lanMask)
434{
435	var ip_arr = lanIp.split('.');
436	var mask_arr = lanMask.split('.');
437	var ip_broadcast=0;
438	for (i = 0; i < 4; i++)
439	{
440		ip_str = parseInt(ip_arr[i],10);
441		mask_str = parseInt(mask_arr[i],10);
442		n_str = ~mask_str+256;
443		ip_broadcast=ip_broadcast*256+parseInt(ip_str | n_str);
444	}
445	return(ip_broadcast);
446}
447
448function isSameSubNet(lan1Ip, lan1Mask, lan2Ip, lan2Mask)
449{
450	var count = 0;
451	var lan1a = lan1Ip.split('.');
452	var lan1m = lan1Mask.split('.');
453	var lan2a = lan2Ip.split('.');
454	var lan2m = lan2Mask.split('.');
455	for (i = 0; i < 4; i++)
456	{
457		l1a_n = parseInt(lan1a[i],10);
458		l1m_n = parseInt(lan1m[i],10);
459		l2a_n = parseInt(lan2a[i],10);
460		l2m_n = parseInt(lan2m[i],10);
461		if ((l1a_n & l1m_n) == (l2a_n & l2m_n))
462			count++;
463	}
464	if (count == 4)
465		return true;
466	else
467		return false;
468}
469function checkipaddr(ipaddr)
470{
471	var form = document.forms[0];
472	var ipArray = ipaddr.split(".");
473	var ipstr = ipArray[0]+ipArray[1]+ipArray[2]+ipArray[3];
474	var i = 0;
475
476	if((ipArray[0]=="")||(ipArray[0]<0)||(ipArray[0]>255)||(ipArray[1]=="")||(ipArray[1]<0)||(ipArray[1]>255)
477			||(ipArray[2]=="")||(ipArray[2]<0)||(ipArray[2]>255)||(ipArray[3]=="")||(ipArray[3]<0)||(ipArray[3]>255))
478	{
479		return false;
480	}
481	for(i=0;i<ipstr.length;i++)
482	{
483		if((ipstr.charAt(i)!='0')&&(ipstr.charAt(i)!='1')&&(ipstr.charAt(i)!='2')
484			&&(ipstr.charAt(i)!='3')&&(ipstr.charAt(i)!='4')&&(ipstr.charAt(i)!='5')
485			&&(ipstr.charAt(i)!='6')&&(ipstr.charAt(i)!='7')&&(ipstr.charAt(i)!='8')
486			&&(ipstr.charAt(i)!='9'))
487		{
488			return false;
489		}
490	}
491	if( ipArray[0] > 223 || ipArray[0] == 0 )
492		return false;
493	if (ipaddr == "0.0.0.0" || ipaddr == "255.255.255.255")
494	{
495		return false;
496	}
497
498	var each=ipaddr.split(".");
499	if (each[0] == "127")
500	{
501		return false;
502	}
503	if (!ipArray || ipArray.length != 4)
504	{
505		return false;
506	}
507	else
508	{
509		for (i = 0; i < 4; i++)
510		{
511			thisSegment = ipArray[i];
512			if (thisSegment != "")
513			{
514				if(i==3)
515				{
516					if (!((ipArray[3] > 0) && (ipArray[3] < 255)))
517					{
518						return false;
519					}
520				}
521				else if (!(thisSegment >=0 && thisSegment <= 255))
522				{
523					return false;
524				}
525			}
526			else
527			{
528				return false;
529			}
530		}
531
532	}
533	return true;
534}
535
536function checksubnet(subnet)
537{
538	var subnetArray = subnet.split(".");
539	var subnetstr = subnetArray[0]+subnetArray[1]+subnetArray[2]+subnetArray[3];
540	var i = 0;
541	var maskTest = 0;
542	var validValue = true;
543
544	if((subnetArray[0]=="")||(subnetArray[0]<0)||(subnetArray[0]>255)||(subnetArray[1]=="")||(subnetArray[1]<0)||(subnetArray[1]>255)
545		||(subnetArray[2]=="")||(subnetArray[2]<0)||(subnetArray[2]>255)||(subnetArray[3]=="")||(subnetArray[3]<0)||(subnetArray[3]>255))
546	{
547		return false;
548	}
549	for(i=0;i<subnetstr.length;i++)
550	{
551		if((subnetstr.charAt(i)!='0')&&(subnetstr.charAt(i)!='1')&&(subnetstr.charAt(i)!='2')
552			&&(subnetstr.charAt(i)!='3')&&(subnetstr.charAt(i)!='4')&&(subnetstr.charAt(i)!='5')
553			&&(subnetstr.charAt(i)!='6')&&(subnetstr.charAt(i)!='7')&&(subnetstr.charAt(i)!='8')
554			&&(subnetstr.charAt(i)!='9'))
555		{
556			return false;
557		}
558	}
559	if (!subnetArray || subnetArray.length != 4)
560	{
561		return false;
562	}
563	else
564	{
565		for (i = 0; i < 4; i++)
566		{
567			thisSegment = subnetArray[i];
568			if (thisSegment != "")
569			{
570				if (!(thisSegment >=0 && thisSegment <= 255))
571				{ //check if number?
572					return false;
573				}
574			}
575			else
576			{
577				return false;
578			}
579		}
580	}
581	if( subnetArray[0] < 255 )
582	{
583		if( (subnetArray[1] > 0) || (subnetArray[2] > 0) || (subnetArray[3] > 0))
584			validValue = false;
585		else
586			maskTest = subnetArray[0];
587	}
588	else
589	{
590		if( subnetArray[1] < 255 )
591		{
592			if( (subnetArray[2] > 0) || (subnetArray[3] > 0))
593				validValue = false;
594			else
595				maskTest = subnetArray[1];
596		}
597		else
598		{
599			if( subnetArray[2] < 255 )
600			{
601				if( (subnetArray[3] > 0) )
602					validValue = false;
603				else
604					maskTest = subnetArray[2];
605			}
606			else
607				maskTest = subnetArray[3];
608		}
609	}
610	if( validValue )
611	{
612		switch( maskTest )
613		{
614			case "0":
615			case "128":
616			case "192":
617			case "224":
618			case "240":
619			case "248":
620			case "252":
621			case "254":
622			case "255":
623				break;
624			default:
625				validValue = false;
626		}
627		if( subnet == "0.0.0.0" )
628			validValue = false;
629	}
630	else
631		validValue = false;
632
633	return validValue;
634}
635
636function checkgateway(gateway)
637{
638	var form = document.forms[0];
639	var dgArray = gateway.split(".");
640	var dgstr = dgArray[0]+dgArray[1]+dgArray[2]+dgArray[3];
641	var i = 0;
642
643	if((dgArray[0]=="")||(dgArray[0]<0)||(dgArray[0]>255)||(dgArray[1]=="")||(dgArray[1]<0)||(dgArray[1]>255)
644		||(dgArray[2]=="")||(dgArray[2]<0)||(dgArray[2]>255)||(dgArray[3]=="")||(dgArray[3]<0)||(dgArray[3]>255))
645	{
646		return false;
647	}
648	for(i=0;i<dgstr.length;i++)
649	{
650		if((dgstr.charAt(i)!='0')&&(dgstr.charAt(i)!='1')&&(dgstr.charAt(i)!='2')
651			&&(dgstr.charAt(i)!='3')&&(dgstr.charAt(i)!='4')&&(dgstr.charAt(i)!='5')
652			&&(dgstr.charAt(i)!='6')&&(dgstr.charAt(i)!='7')&&(dgstr.charAt(i)!='8')
653			&&(dgstr.charAt(i)!='9'))
654		{
655			return false;
656		}
657	}
658	if( dgArray[0] > 223 || dgArray[0] == 0 )
659		return false;
660	if (gateway == "0.0.0.0" || gateway == "255.255.255.255")
661	{
662		return false;
663	}
664	if (gateway == "127.0.0.1")
665	{
666		return false;
667	}
668	if (!dgArray || dgArray.length != 4)
669	{
670		return false;
671	}
672	else
673	{
674		for (i = 0; i < 4; i++)
675		{
676			thisSegment = dgArray[i];
677			if (thisSegment != "")
678			{
679				if (!(thisSegment >=0 && thisSegment <= 255))
680				{ //check if number?
681					return false;
682				}
683			}
684			else
685			{
686				return false;
687			}
688		}
689	}
690	return true;
691}
692function loadhelp(fname,anchname)
693{
694	if(parent.parent.help_info)
695		parent.parent.help_info = fname;
696	if ((loadhelp.arguments.length == 1 ) || (anchname == "" ))
697		top.helpframe.location.href="/help.htm";
698	else
699		top.helpframe.location.href="/help.htm#" + 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)))
711		{
712			return true;
713		}
714		else
715			return false;
716	}
717	else if (e)
718	{
719		keycode = e.which;
720		if (((keycode>47) && (keycode<58))||(keycode==8)||(keycode==0)||((keycode>64) && (keycode<71))||((keycode>96) && (keycode<103)))
721		{
722			return true;
723		}
724		else
725			return false;
726	}
727	else
728	{
729		return true;
730	}
731}
732function getkey(type, e)
733{
734	var keycode, event;
735
736	if (window.event)
737	{
738		event = window.event;
739		keycode = window.event.keyCode;
740	}
741	else if (e)
742	{
743		event = e;
744		keycode = e.which;
745	}
746	else
747		return true;
748
749	if(event.ctrlKey && ( keycode==99 || keycode==118 || keycode==120) )
750		return true;
751
752	if(type == "apname")
753	{
754		if ((keycode==34) ||(keycode==39)||(keycode==92))
755		{
756			return false;
757		}
758		else
759			return true;
760	}
761	else if(type == "ipaddr")
762	{
763		if (((keycode>47) && (keycode<58))||(keycode==8)||(keycode==0)||(keycode==46))
764		{
765			return true;
766		}
767		else
768			return false;
769	}
770	else if(type == "ssid")
771	{
772		//if (keycode==32)
773		//	return false;
774		//else
775		//	return true;
776		return true;
777	}
778	else if(type == "wep")
779	{
780		if (((keycode>47) && (keycode<58))||((keycode>64) && (keycode<71))||((keycode>96) && (keycode<103))||(keycode == 8)||(keycode == 0))
781			return true;
782		else
783			return false;
784	}
785	else if(type == "num")
786	{
787		if (((keycode>47) && (keycode<58)) || (keycode==8)||(keycode==0))
788			return true;
789		else
790			return false;
791	}
792	else if(type == "hostname")
793	{
794		if (((keycode>47) && (keycode<58))||(keycode==45)||((keycode>64) && (keycode<91))||((keycode>96) && (keycode<123)) || (keycode==8)||(keycode==0))
795		{
796			return true;
797		}
798		else
799			return false;
800	}
801	else if(type == "ddns_hostname")
802	{
803		if (((keycode>47) && (keycode<58))||(keycode==45)||(keycode==46)||((keycode>64) && (keycode<91))||((keycode>96) && (keycode<123)) || (keycode==8)||(keycode==0))
804		{
805			return true;
806		}
807		else
808			return false;
809	}
810	else if(type == "mac")
811	{
812		if (((keycode>47) && (keycode<58))||((keycode>64) && (keycode<71))||((keycode>96) && (keycode<103))||(keycode == 8)||(keycode == 0) || (keycode == 58) || (keycode == 45))
813			return true;
814		else
815			return false;
816	}
817	else if(type == "folderPath")// not / * ? " <>
818	{
819		if((keycode==47) || (keycode==42) || (keycode==63) || (keycode==34) || (keycode==60) || (keycode==62) ||(keycode==124))
820			return false;
821		else
822			return true;
823	}
824	else if(type == "shareName")// not / * ? " <> \ :
825	{
826		if((keycode==47) || (keycode==42) || (keycode==63) || (keycode==34) || (keycode==60) || (keycode==62) ||(keycode==58) || (keycode==92) || (keycode==93) || (keycode==124))
827			return false;
828		else
829			return true;
830	}
831	else if(type == "ascii")
832	{
833		if ((keycode<32) || (keycode>126))
834			return false;
835		else
836			return true;
837	}
838	else
839		return false;
840}
841
842
843
844function changesectype(fname)
845{
846	var html_href;
847	if(fname.options[0].selected == true)
848		html_href = "security_off.asp";
849	else if(fname.options[1].selected == true)
850		html_href = "wep.asp";
851	else if(fname.options[2].selected == true)
852		html_href = "wpa.asp";
853	else if(fname.options[3].selected == true)
854		html_href = "wpa2.asp";
855	else if(fname.options[4].selected == true)
856		html_href = "wpas.asp";
857
858	location.href = html_href;
859}
860
861function printableKeyFilter()
862{
863	if (event.keyCode < 32 || event.keyCode > 126)
864		event.returnValue = false;
865}
866
867function checkpsk(passphrase, passphrase_len)
868{
869	var len = passphrase.value.length;
870	if ( len == 64 )
871	{
872		//Don't enable Hex passphrase support
873		alert("<%1590%>");
874		return false;
875
876		for(i=0;i<len;i++)
877		{
878			if(isValidHex(passphrase.value.charAt(i))==false)
879			{
880				alert("<%61%>");
881				return false;
882			}
883		}
884	}
885	else
886	{
887		if(len < 8 )
888		{
889			alert("<%1589%>");
890			return false;
891		}
892		if(len > 63)
893		{
894			alert("<%1590%>");
895			return false;
896		}
897		for(i=0;i<passphrase.value.length;i++)
898		{
899			if(isValidChar_space(passphrase.value.charCodeAt(i))==false)
900			{
901				alert("<%61%>");
902				return false;
903			}
904		}
905	}
906	passphrase_len.value=len;
907	return true;
908}
909
910var wep_128="<%48%>";
911var wep_64="<%47%>";
912
913function checkwep(form)
914{
915	form.wep_press_flag.value=0;
916	var KEY1=form.KEY1.value;
917	var KEY2=form.KEY2.value;
918	var KEY3=form.KEY3.value;
919	var KEY4=form.KEY4.value;
920	if(form.wepenc.value==13)
921	{
922		if( form.wep_key_no[0].checked == true )
923		{
924			if(form.KEY1.value.length!=26)
925			{
926				alert(wep_128);
927				return false;
928			}
929		}
930		else if( form.KEY1.value.length!=0 && form.KEY1.value.length!=26)
931		{
932			alert(wep_128);
933			return false;
934		}
935		if(form.KEY1.value.length!=0)
936			for(i=0;i<KEY1.length;i++)
937			{
938				if(isValidHex(KEY1.charAt(i))==false)
939				{
940					alert(wep_128);
941					return false;
942				}
943			}
944
945		if( form.wep_key_no[1].checked == true )
946		{
947			if(form.KEY2.value.length!=26)
948			{
949				alert(wep_128);
950				return false;
951			}
952		}
953		else if( form.KEY2.value.length!=0 && form.KEY2.value.length!=26)
954		{
955			alert(wep_128);
956			return false;
957		}
958		if(form.KEY2.value.length!=0)
959			for(i=0;i<KEY2.length;i++)
960			{
961				if(isValidHex(KEY2.charAt(i))==false)
962				{
963					alert(wep_128);
964					return false;
965				}
966			}
967		if( form.wep_key_no[2].checked == true)
968		{
969			if(form.KEY3.value.length!=26)
970			{
971				alert(wep_128);
972				return false;
973			}
974		}
975		else if( form.KEY3.value.length!=0 && form.KEY3.value.length!=26)
976		{
977			alert(wep_128);
978			return false;
979		}
980		if(form.KEY3.value.length!=0)
981			for(i=0;i<KEY3.length;i++)
982			{
983				if(isValidHex(KEY3.charAt(i))==false)
984				{
985					alert(wep_128);
986					return false;
987				}
988			}
989		if( form.wep_key_no[3].checked == true)
990		{
991			if(form.KEY4.value.length!=26)
992			{
993				alert(wep_128);
994				return false;
995			}
996		}
997		else if( form.KEY4.value.length!=0 && form.KEY4.value.length!=26)
998		{
999			alert(wep_128);
1000			return false;
1001		}
1002		if(form.KEY4.value.length!=0)
1003			for(i=0;i<KEY4.length;i++)
1004			{
1005				if(isValidHex(KEY4.charAt(i))==false)
1006				{
1007					alert(wep_128);
1008					return false;
1009				}
1010			}
1011	}
1012	if(form.wepenc.value==5)
1013	{
1014		if( form.wep_key_no[0].checked == true)
1015		{
1016			if(form.KEY1.value.length!=10)
1017			{
1018				alert(wep_64);
1019				return false;
1020			}
1021		}
1022		else if( form.KEY1.value.length!=0 && form.KEY1.value.length!=10)
1023		{
1024			alert(wep_64);
1025			return false;
1026		}
1027		if(form.KEY1.value.length!=0)
1028			for(i=0;i<KEY1.length;i++)
1029			{
1030				if(isValidHex(KEY1.charAt(i))==false)
1031				{
1032					alert(wep_64);
1033					return false;
1034				}
1035			}
1036		if( form.wep_key_no[1].checked == true)
1037		{
1038			if(form.KEY2.value.length!=10)
1039			{
1040				alert(wep_64);
1041				return false;
1042			}
1043		}
1044		else if( form.KEY2.value.length!=0 && form.KEY2.value.length!=10)
1045		{
1046			alert(wep_64);
1047			return false;
1048		}
1049		if(form.KEY2.value.length!=0)
1050			for(i=0;i<KEY2.length;i++)
1051			{
1052				if(isValidHex(KEY2.charAt(i))==false)
1053				{
1054					alert(wep_64);
1055					return false;
1056				}
1057			}
1058
1059		if( form.wep_key_no[2].checked == true)
1060		{
1061			if(form.KEY3.value.length!=10)
1062			{
1063				alert(wep_64);
1064				return false;
1065			}
1066		}
1067		else if( form.KEY3.value.length!=0 && form.KEY3.value.length!=10)
1068		{
1069			alert(wep_64);
1070			return false;
1071		}
1072		if(form.KEY3.value.length!=0)
1073			for(i=0;i<KEY3.length;i++)
1074			{
1075				if(isValidHex(KEY3.charAt(i))==false)
1076				{
1077					alert(wep_64);
1078					return false;
1079				}
1080			}
1081		if( form.wep_key_no[3].checked == true)
1082		{
1083			if(form.KEY4.value.length!=10)
1084			{
1085				alert(wep_64);
1086				return false;
1087			}
1088		}
1089		else if( form.KEY4.value.length!=0 && form.KEY4.value.length!=10)
1090		{
1091			alert(wep_64);
1092			return false;
1093		}
1094		if(form.KEY4.value.length!=0)
1095			for(i=0;i<KEY4.length;i++)
1096			{
1097				if(isValidHex(KEY4.charAt(i))==false)
1098				{
1099					alert(wep_64);
1100					return false;
1101				}
1102			}
1103	}
1104	return true;
1105}
1106
1107function checkwep_a(form)
1108{
1109	form.wep_press_flag.value=0;
1110	var KEY1=form.KEY1_a.value;
1111	var KEY2=form.KEY2_a.value;
1112	var KEY3=form.KEY3_a.value;
1113	var KEY4=form.KEY4_a.value;
1114	if(form.wepenc_a.value==13)
1115	{
1116		if( form.wep_key_no_a[0].checked == true )
1117		{
1118			if(KEY1.length!=26)
1119			{
1120				alert(wep_128);
1121				return false;
1122			}
1123		}
1124		else if( KEY1.length!=0 && KEY1.length!=26)
1125		{
1126			alert(wep_128);
1127			return false;
1128		}
1129		if(KEY1.length!=0)
1130			for(i=0;i<KEY1.length;i++)
1131			{
1132				if(isValidHex(KEY1.charAt(i))==false)
1133				{
1134					alert(wep_128);
1135					return false;
1136				}
1137			}
1138
1139		if( form.wep_key_no_a[1].checked == true )
1140		{
1141			if(KEY2.length!=26)
1142			{
1143				alert(wep_128);
1144				return false;
1145			}
1146		}
1147		else if( KEY2.length!=0 && KEY2.length!=26)
1148		{
1149			alert(wep_128);
1150			return false;
1151		}
1152		if(KEY2.length!=0)
1153			for(i=0;i<KEY2.length;i++)
1154			{
1155				if(isValidHex(KEY2.charAt(i))==false)
1156				{
1157					alert(wep_128);
1158					return false;
1159				}
1160			}
1161		if( form.wep_key_no_a[2].checked == true)
1162		{
1163			if(KEY3.length!=26)
1164			{
1165				alert(wep_128);
1166				return false;
1167			}
1168		}
1169		else if( KEY3.length!=0 && KEY3.length!=26)
1170		{
1171			alert(wep_128);
1172			return false;
1173		}
1174		if(KEY3.length!=0)
1175			for(i=0;i<KEY3.length;i++)
1176			{
1177				if(isValidHex(KEY3.charAt(i))==false)
1178				{
1179					alert(wep_128);
1180					return false;
1181				}
1182			}
1183		if( form.wep_key_no_a[3].checked == true)
1184		{
1185			if(KEY4.length!=26)
1186			{
1187				alert(wep_128);
1188				return false;
1189			}
1190		}
1191		else if( KEY4.length!=0 && KEY4.length!=26)
1192		{
1193			alert(wep_128);
1194			return false;
1195		}
1196		if(KEY4.length!=0)
1197			for(i=0;i<KEY4.length;i++)
1198			{
1199				if(isValidHex(KEY4.charAt(i))==false)
1200				{
1201					alert(wep_128);
1202					return false;
1203				}
1204			}
1205	}
1206	if(form.wepenc_a.value==5)
1207	{
1208		if( form.wep_key_no_a[0].checked == true)
1209		{
1210			if(KEY1.length!=10)
1211			{
1212				alert(wep_64);
1213				return false;
1214			}
1215		}
1216		else if( KEY1.length!=0 && KEY1.length!=10)
1217		{
1218			alert(wep_64);
1219			return false;
1220		}
1221		if(KEY1.length!=0)
1222			for(i=0;i<KEY1.length;i++)
1223			{
1224				if(isValidHex(KEY1.charAt(i))==false)
1225				{
1226					alert(wep_64);
1227					return false;
1228				}
1229			}
1230		if( form.wep_key_no_a[1].checked == true)
1231		{
1232			if(KEY2.length!=10)
1233			{
1234				alert(wep_64);
1235				return false;
1236			}
1237		}
1238		else if( KEY2.length!=0 && KEY2.length!=10)
1239		{
1240			alert(wep_64);
1241			return false;
1242		}
1243		if(KEY2.length!=0)
1244			for(i=0;i<KEY2.length;i++)
1245			{
1246				if(isValidHex(KEY2.charAt(i))==false)
1247				{
1248					alert(wep_64);
1249					return false;
1250				}
1251			}
1252
1253		if( form.wep_key_no_a[2].checked == true)
1254		{
1255			if(KEY3.length!=10)
1256			{
1257				alert(wep_64);
1258				return false;
1259			}
1260		}
1261		else if( KEY3.length!=0 && KEY3.length!=10)
1262		{
1263			alert(wep_64);
1264			return false;
1265		}
1266		if(KEY3.length!=0)
1267			for(i=0;i<KEY3.length;i++)
1268			{
1269				if(isValidHex(KEY3.charAt(i))==false)
1270				{
1271					alert(wep_64);
1272					return false;
1273				}
1274			}
1275		if( form.wep_key_no_a[3].checked == true)
1276		{
1277			if(KEY4.length!=10)
1278			{
1279				alert(wep_64);
1280				return false;
1281			}
1282		}
1283		else if( KEY4.length!=0 && KEY4.length!=10)
1284		{
1285			alert(wep_64);
1286			return false;
1287		}
1288		if(KEY4.length!=0)
1289			for(i=0;i<KEY4.length;i++)
1290			{
1291				if(isValidHex(KEY4.charAt(i))==false)
1292				{
1293					alert(wep_64);
1294					return false;
1295				}
1296			}
1297	}
1298	return true;
1299}
1300
1301/////////////////////////////////////generate wep key by md5////////////////////////////////////////////////////
1302function HexToAscii(wepenc,wep_key_no,I,S,D) {
1303	var temp1="";
1304
1305	S = S.toUpperCase();
1306
1307	var optionindex=wepenc.selectedIndex;
1308
1309	if( wepenc.options[optionindex].value=="13" )
1310	{
1311		wordCount = 26;
1312	}
1313	else
1314	{
1315		wordCount = 10;
1316	}
1317
1318	//if(F.keyno_11g[I].checked)
1319	if(1)
1320	{
1321		if( (S.length!=wordCount) )
1322		{
1323			if(wep_key_no[I].checked)
1324			{
1325				var s="Hex type key length must be ";
1326				alert(s + wordCount);
1327			}
1328			D.value="";
1329			S="";
1330			return S;
1331		}
1332		for(i=0;i<wordCount;i+=2)
1333		{
1334			var c=S.charCodeAt(i);
1335			var d=S.charCodeAt(i+1);
1336
1337			if( (c>=48)&&(c<=57) )
1338				c=c-48;
1339			else if( (c>=65)&&(c<=70) )
1340				c=c-55;
1341			else
1342			{
1343				var s="Over Hex range (0~F)";
1344				alert(s);
1345				return S;
1346			}
1347
1348			if( (d>=48)&&(d<=57) )
1349				d=d-48;
1350			else if( (d>=65)&&(d<=70) )
1351				d=d-55;
1352			else
1353			{
1354				var s="Over Hex range (0~F)";
1355				alert(s);
1356				return S;
1357			}
1358			var value=c*16+d;
1359
1360			if( ((value>=0)&&(value<32)) || ((value>128)&&(value<=255)) )
1361			{
1362				temp1+=String.fromCharCode(92);
1363				temp1+=S.substring(i,i+2);
1364			}
1365			else
1366			{
1367				if(value==92)
1368				{
1369					temp1+=String.fromCharCode(value);
1370					temp1+=String.fromCharCode(value);
1371				}
1372				else
1373					temp1+=String.fromCharCode(value);
1374			}
1375		}
1376		D.value=temp1;
1377	}
1378	return S;
1379}
1380
1381function PassPhrase40(passphraseStr, wepenc, wep_key_no, KEY1, KEY2, KEY3, KEY4)
1382{
1383	var seed = 0;
1384	var pseed = new Array(0, 0, 0, 0);
1385	var pkey = new Array(4);
1386	var asciiObj = new Array(4);
1387	Length = passphraseStr.value.length;
1388
1389	if(Length != 0)
1390	{
1391		for (i=0; i<Length; i++ )
1392		{
1393			pseed[i%4] ^= passphraseStr.value.charCodeAt(i);
1394		}
1395		seed = pseed[0];
1396		seed += pseed[1] << 8;
1397		seed += pseed[2] << 16;
1398		seed += pseed[3] << 24;
1399	}
1400
1401	KEY1.value = KEY2.value = "";
1402	KEY3.value = KEY4.value = "";
1403
1404	// init key array
1405	pkey[0] = KEY1;
1406	pkey[1] = KEY2;
1407	pkey[2] = KEY3;
1408	pkey[3] = KEY4;
1409
1410	for(j=0; j<4; j++)
1411	{
1412		for (i=0; i<5 ;i++ )
1413		{
1414			seed = (214013 * seed) & 0xffffffff;
1415
1416			if(seed & 0x80000000)
1417			{
1418				seed = (seed & 0x7fffffff) + 0x80000000 + 0x269ec3;
1419			}
1420			else
1421			{
1422				seed = (seed & 0x7fffffff) + 0x269ec3;
1423			}
1424
1425			temp = ((seed >> 16) & 0xff);
1426			if(temp < 0x10)
1427			{
1428				pkey[j].value += "0" + temp.toString(16).toUpperCase();
1429			}
1430			else
1431			{
1432				pkey[j].value += temp.toString(16).toUpperCase();
1433			}
1434		}
1435	}
1436
1437	asciiObj[0] = "";
1438	asciiObj[1] = "";
1439	asciiObj[2] = "";
1440	asciiObj[3] = "";
1441
1442	for(k=0; k<4; k++)
1443	{
1444		HexToAscii(wepenc, wep_key_no, k, pkey[k].value, asciiObj[k]);
1445	}
1446
1447	wepkey1 = pkey[0].value;
1448	wepkey2 = pkey[1].value;
1449	wepkey3 = pkey[2].value;
1450	wepkey4 = pkey[3].value;
1451}
1452
1453/*
1454 * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
1455 * Digest Algorithm, as defined in RFC 1321.
1456 * Copyright (C) Paul Johnston 1999 - 2000.
1457 * Updated by Greg Holt 2000 - 2001.
1458 * See http://pajhome.org.uk/site/legal.html for details.
1459 */
1460
1461/*
1462 * Convert a 32-bit number to a hex string with ls-byte first
1463 */
1464var hex_chr = "0123456789abcdef";
1465function rhex(num)
1466{
1467	str = "";
1468	for(j = 0; j <= 3; j++)
1469		str += hex_chr.charAt((num >> (j * 8 + 4)) & 0x0F) +
1470			hex_chr.charAt((num >> (j * 8)) & 0x0F);
1471	return str;
1472}
1473
1474/*
1475 * Convert a string to a sequence of 16-word blocks, stored as an array.
1476 * Append padding bits and the length, as described in the MD5 standard.
1477 */
1478function str2blks_MD5(str)
1479{
1480	nblk = ((str.length + 8) >> 6) + 1;
1481	blks = new Array(nblk * 16);
1482	for(i = 0; i < nblk * 16; i++) blks[i] = 0;
1483	for(i = 0; i < str.length; i++)
1484		blks[i >> 2] |= str.charCodeAt(i) << ((i % 4) * 8);
1485	blks[i >> 2] |= 0x80 << ((i % 4) * 8);
1486	blks[nblk * 16 - 2] = str.length * 8;
1487	return blks;
1488}
1489
1490/*
1491 * Add integers, wrapping at 2^32. This uses 16-bit operations internally
1492 * to work around bugs in some JS interpreters.
1493 */
1494function add(x, y)
1495{
1496	var lsw = (x & 0xFFFF) + (y & 0xFFFF);
1497	var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
1498	return (msw << 16) | (lsw & 0xFFFF);
1499}
1500
1501/*
1502 * Bitwise rotate a 32-bit number to the left
1503 */
1504function rol(num, cnt)
1505{
1506	return (num << cnt) | (num >>> (32 - cnt));
1507}
1508
1509/*
1510 * These functions implement the basic operation for each round of the
1511 * algorithm.
1512 */
1513function cmn(q, a, b, x, s, t)
1514{
1515	return add(rol(add(add(a, q), add(x, t)), s), b);
1516}
1517function ff(a, b, c, d, x, s, t)
1518{
1519	return cmn((b & c) | ((~b) & d), a, b, x, s, t);
1520}
1521function gg(a, b, c, d, x, s, t)
1522{
1523	return cmn((b & d) | (c & (~d)), a, b, x, s, t);
1524}
1525function hh(a, b, c, d, x, s, t)
1526{
1527	return cmn(b ^ c ^ d, a, b, x, s, t);
1528}
1529function ii(a, b, c, d, x, s, t)
1530{
1531	return cmn(c ^ (b | (~d)), a, b, x, s, t);
1532}
1533
1534/*
1535 * Take a string and return the hex representation of its MD5.
1536 */
1537function calcMD5(str)
1538{
1539	x = str2blks_MD5(str);
1540	a =  1732584193;
1541	b = -271733879;
1542	c = -1732584194;
1543	d =  271733878;
1544
1545	for(i = 0; i < x.length; i += 16)
1546	{
1547		olda = a;
1548		oldb = b;
1549		oldc = c;
1550		oldd = d;
1551
1552		a = ff(a, b, c, d, x[i+ 0], 7 , -680876936);
1553		d = ff(d, a, b, c, x[i+ 1], 12, -389564586);
1554		c = ff(c, d, a, b, x[i+ 2], 17,  606105819);
1555		b = ff(b, c, d, a, x[i+ 3], 22, -1044525330);
1556		a = ff(a, b, c, d, x[i+ 4], 7 , -176418897);
1557		d = ff(d, a, b, c, x[i+ 5], 12,  1200080426);
1558		c = ff(c, d, a, b, x[i+ 6], 17, -1473231341);
1559		b = ff(b, c, d, a, x[i+ 7], 22, -45705983);
1560		a = ff(a, b, c, d, x[i+ 8], 7 ,  1770035416);
1561		d = ff(d, a, b, c, x[i+ 9], 12, -1958414417);
1562		c = ff(c, d, a, b, x[i+10], 17, -42063);
1563		b = ff(b, c, d, a, x[i+11], 22, -1990404162);
1564		a = ff(a, b, c, d, x[i+12], 7 ,  1804603682);
1565		d = ff(d, a, b, c, x[i+13], 12, -40341101);
1566		c = ff(c, d, a, b, x[i+14], 17, -1502002290);
1567		b = ff(b, c, d, a, x[i+15], 22,  1236535329);
1568
1569		a = gg(a, b, c, d, x[i+ 1], 5 , -165796510);
1570		d = gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
1571		c = gg(c, d, a, b, x[i+11], 14,  643717713);
1572		b = gg(b, c, d, a, x[i+ 0], 20, -373897302);
1573		a = gg(a, b, c, d, x[i+ 5], 5 , -701558691);
1574		d = gg(d, a, b, c, x[i+10], 9 ,  38016083);
1575		c = gg(c, d, a, b, x[i+15], 14, -660478335);
1576		b = gg(b, c, d, a, x[i+ 4], 20, -405537848);
1577		a = gg(a, b, c, d, x[i+ 9], 5 ,  568446438);
1578		d = gg(d, a, b, c, x[i+14], 9 , -1019803690);
1579		c = gg(c, d, a, b, x[i+ 3], 14, -187363961);
1580		b = gg(b, c, d, a, x[i+ 8], 20,  1163531501);
1581		a = gg(a, b, c, d, x[i+13], 5 , -1444681467);
1582		d = gg(d, a, b, c, x[i+ 2], 9 , -51403784);
1583		c = gg(c, d, a, b, x[i+ 7], 14,  1735328473);
1584		b = gg(b, c, d, a, x[i+12], 20, -1926607734);
1585
1586		a = hh(a, b, c, d, x[i+ 5], 4 , -378558);
1587		d = hh(d, a, b, c, x[i+ 8], 11, -2022574463);
1588		c = hh(c, d, a, b, x[i+11], 16,  1839030562);
1589		b = hh(b, c, d, a, x[i+14], 23, -35309556);
1590		a = hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
1591		d = hh(d, a, b, c, x[i+ 4], 11,  1272893353);
1592		c = hh(c, d, a, b, x[i+ 7], 16, -155497632);
1593		b = hh(b, c, d, a, x[i+10], 23, -1094730640);
1594		a = hh(a, b, c, d, x[i+13], 4 ,  681279174);
1595		d = hh(d, a, b, c, x[i+ 0], 11, -358537222);
1596		c = hh(c, d, a, b, x[i+ 3], 16, -722521979);
1597		b = hh(b, c, d, a, x[i+ 6], 23,  76029189);
1598		a = hh(a, b, c, d, x[i+ 9], 4 , -640364487);
1599		d = hh(d, a, b, c, x[i+12], 11, -421815835);
1600		c = hh(c, d, a, b, x[i+15], 16,  530742520);
1601		b = hh(b, c, d, a, x[i+ 2], 23, -995338651);
1602
1603		a = ii(a, b, c, d, x[i+ 0], 6 , -198630844);
1604		d = ii(d, a, b, c, x[i+ 7], 10,  1126891415);
1605		c = ii(c, d, a, b, x[i+14], 15, -1416354905);
1606		b = ii(b, c, d, a, x[i+ 5], 21, -57434055);
1607		a = ii(a, b, c, d, x[i+12], 6 ,  1700485571);
1608		d = ii(d, a, b, c, x[i+ 3], 10, -1894986606);
1609		c = ii(c, d, a, b, x[i+10], 15, -1051523);
1610		b = ii(b, c, d, a, x[i+ 1], 21, -2054922799);
1611		a = ii(a, b, c, d, x[i+ 8], 6 ,  1873313359);
1612		d = ii(d, a, b, c, x[i+15], 10, -30611744);
1613		c = ii(c, d, a, b, x[i+ 6], 15, -1560198380);
1614		b = ii(b, c, d, a, x[i+13], 21,  1309151649);
1615		a = ii(a, b, c, d, x[i+ 4], 6 , -145523070);
1616		d = ii(d, a, b, c, x[i+11], 10, -1120210379);
1617		c = ii(c, d, a, b, x[i+ 2], 15,  718787259);
1618		b = ii(b, c, d, a, x[i+ 9], 21, -343485551);
1619
1620		a = add(a, olda);
1621		b = add(b, oldb);
1622		c = add(c, oldc);
1623		d = add(d, oldd);
1624	}
1625	return rhex(a) + rhex(b) + rhex(c) + rhex(d);
1626}
1627
1628function PassPhrase104(passphraseStr, KEY1, KEY2, KEY3, KEY4)
1629{
1630
1631	var pseed2 = "";
1632	Length2 = passphraseStr.value.length;
1633
1634	for(p=0; p<64; p++)
1635	{
1636		tempCount = p % Length2;
1637		pseed2 += passphraseStr.value.substring(tempCount, tempCount+1);
1638	}
1639	md5Str = calcMD5(pseed2);
1640
1641	KEY1.value = md5Str.substring(0, 26).toUpperCase();
1642	KEY2.value = md5Str.substring(0, 26).toUpperCase();
1643	KEY3.value = md5Str.substring(0, 26).toUpperCase();
1644	KEY4.value = md5Str.substring(0, 26).toUpperCase();
1645}
1646
1647function clickgenerate(form)
1648{
1649	if(form.passphraseStr.value.length == 0 )
1650	{
1651		alert("Empty!")
1652		return false;
1653	}
1654	for(i=0;i<form.passphraseStr.value.length;i++)
1655	{
1656		if(isValidChar_space(form.passphraseStr.value.charCodeAt(i))==false)
1657		{
1658			alert("<%61%>");
1659			return false;
1660		}
1661	}
1662	if(form.wepenc.options[0].selected == true)
1663		PassPhrase40(form.passphraseStr, form.wepenc, form.wep_key_no, form.KEY1, form.KEY2, form.KEY3, form.KEY4);
1664	else
1665		PassPhrase104(form.passphraseStr, form.KEY1, form.KEY2, form.KEY3, form.KEY4);
1666	form.generate_flag.value=1;
1667}
1668function clickgenerate_a(form)
1669{
1670	/*
1671	if(form.passphraseStr_a.value.length == 0 )
1672	{
1673		alert("You should input 1 to 32 ASCII characters to generate 4 keys.")
1674		return false;
1675	}
1676	*/
1677	for(i=0;i<form.passphraseStr_a.value.length;i++)
1678	{
1679		if(isValidChar_space(form.passphraseStr_a.value.charCodeAt(i))==false)
1680		{
1681			alert("<%61%>");
1682			return false;
1683		}
1684	}
1685	if(form.wepenc_a.options[0].selected == true)
1686		PassPhrase40(form.passphraseStr_a, form.wepenc_a, form.wep_key_no_a, form.KEY1_a, form.KEY2_a, form.KEY3_a, form.KEY4_a);
1687	else
1688		PassPhrase104(form.passphraseStr_a, form.KEY1_a, form.KEY2_a, form.KEY3_a, form.KEY4_a);
1689	form.generate_flag.value=1;
1690}
1691
1692function doPortChange(check)
1693{
1694	if(check == 0)
1695		location.href="forwarding.htm";
1696	else
1697		location.href="triggering.htm";
1698}
1699
1700function setDisabled(OnOffFlag,formFields)
1701{
1702	for (var i = 1; i < setDisabled.arguments.length; i++)
1703		setDisabled.arguments[i].disabled = OnOffFlag;
1704}
1705
1706function change_serv(cf)
1707{
1708	if ( cf.login_type[1].selected == true )
1709	{
1710		location.href="BAS_pppoe.htm";
1711		loadhelp('_BAS_pppoe');
1712	}
1713	else if ( cf.login_type[0].selected == true )
1714	{
1715		location.href="BAS_pptp.htm";
1716		loadhelp('_BAS_pptp');
1717	}
1718	else if (cf.login_type[2].selected == true )
1719	{
1720		location.href="BAS_l2tp.htm";
1721		loadhelp('_BAS_l2tp');
1722	}
1723	else if (cf.login_type[3].selected == true )
1724		location.href="BAS_mulpppoe.htm";
1725}
1726
1727function maccheck_multicast(mac_addr)
1728{
1729	mac_array=mac_addr.split(':');
1730	var mac11 = mac_array[0];
1731	mac11 = mac11.substr(1,1);
1732	if((mac11=="1")||(mac11=="3")||(mac11=="5")||(mac11=="7")||(mac11=="9")||(mac11=="b")||(mac11=="d")||(mac11=="f")||(mac11=="B")||(mac11=="D")||(mac11=="F"))
1733	{
1734		//Reject MAC address like 11:xx:xx:xx:xx:xx
1735		alert("<%0%>");
1736		return false;
1737	}
1738	if(mac_array.length!=6)
1739	{
1740		alert("<%0%>");
1741		return false;
1742	}
1743	if(( mac_array[0]=="")||( mac_array[1]=="")||( mac_array[2]=="")||( mac_array[3]=="")||( mac_array[4]=="")||( mac_array[5]==""))
1744	{
1745		alert("<%0%>");
1746		return false;
1747	}
1748	if((( mac_array[0]=="00")&&( mac_array[1]=="00")&&
1749		( mac_array[2]=="00")&&( mac_array[3]=="00")&&
1750		( mac_array[4]=="00")&&( mac_array[5]=="00"))||
1751		(( mac_array[0]=="ff")&&( mac_array[1]=="ff")&&
1752		 ( mac_array[2]=="ff")&&( mac_array[3]=="ff")&&
1753		 ( mac_array[4]=="ff")&&( mac_array[5]=="ff"))||
1754		(( mac_array[0]=="FF")&&( mac_array[1]=="FF")&&
1755		 ( mac_array[2]=="FF")&&( mac_array[3]=="FF")&&
1756		 ( mac_array[4]=="FF")&&( mac_array[5]=="FF")))
1757	{
1758		alert("<%0%>");
1759		return false;
1760	}
1761	if(( mac_array[0].length!=2)||( mac_array[1].length!=2)||
1762		( mac_array[2].length!=2)||( mac_array[3].length!=2)||
1763		( mac_array[4].length!=2)||( mac_array[5].length!=2))
1764	{
1765		alert("<%0%>");
1766		return false;
1767	}
1768	for(i=0;i<mac_addr.length;i++)
1769	{
1770		if(isValidMac(mac_addr.charAt(i))==false)
1771		{
1772			alert("<%0%>");
1773			return false;
1774		}
1775	}
1776	return true;
1777}
1778
1779function maccheck(mac_addr)
1780{
1781	/*
1782	if ( mac_addr.indexOf(":")==-1 && mac_addr.length=="12" )
1783	{
1784		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);
1785		mac_addr = tmp_mac;
1786	}
1787	*/
1788	mac_array=mac_addr.split(':');
1789	var mac11 = mac_array[0];
1790	mac11 = mac11.substr(1,1);
1791	if((mac11=="1")||(mac11=="3")||(mac11=="5")||(mac11=="7")||(mac11=="9")||(mac11=="b")||(mac11=="d")||(mac11=="f")||(mac11=="B")||(mac11=="D")||(mac11=="F"))
1792	{
1793		if(mac11=="1" && mac_array[0] == "11")
1794		{
1795		}
1796		else
1797		{
1798			alert("<%0%>");
1799			return false;
1800		}
1801	}
1802	if(mac_array.length!=6)
1803	{
1804		alert("<%0%>");
1805		return false;
1806	}
1807	if(( mac_array[0]=="")||( mac_array[1]=="")||( mac_array[2]=="")||( mac_array[3]=="")||( mac_array[4]=="")||( mac_array[5]==""))
1808	{
1809		alert("<%0%>");
1810		return false;
1811	}
1812	if((( mac_array[0]=="00")&&( mac_array[1]=="00")&&
1813		( mac_array[2]=="00")&&( mac_array[3]=="00")&&
1814		( mac_array[4]=="00")&&( mac_array[5]=="00"))||
1815		(( mac_array[0]=="ff")&&( mac_array[1]=="ff")&&
1816		 ( mac_array[2]=="ff")&&( mac_array[3]=="ff")&&
1817		 ( mac_array[4]=="ff")&&( mac_array[5]=="ff"))||
1818		(( mac_array[0]=="FF")&&( mac_array[1]=="FF")&&
1819		 ( mac_array[2]=="FF")&&( mac_array[3]=="FF")&&
1820		 ( mac_array[4]=="FF")&&( mac_array[5]=="FF")))
1821	{
1822		alert("<%0%>");
1823		return false;
1824	}
1825	if(( mac_array[0].length!=2)||( mac_array[1].length!=2)||
1826		( mac_array[2].length!=2)||( mac_array[3].length!=2)||
1827		( mac_array[4].length!=2)||( mac_array[5].length!=2))
1828	{
1829		alert("<%0%>");
1830		return false;
1831	}
1832
1833	for(i=0;i<mac_addr.length;i++)
1834	{
1835		if(isValidMac(mac_addr.charAt(i))==false)
1836		{
1837			alert("<%0%>");
1838			return false;
1839		}
1840	}
1841	return true;
1842}
1843
1844function setMAC(cf,this_mac)
1845{
1846	var dflag;
1847	if (cf.MACAssign[0].checked || cf.MACAssign[1].checked)
1848	{
1849		dflag = true;
1850		cf.Spoofmac.value=this_mac;
1851		setDisabled(dflag,cf.Spoofmac);
1852	}
1853	else
1854	{
1855		dflag = false;
1856		setDisabled(dflag,cf.Spoofmac);
1857		cf.Spoofmac.value=this_mac;
1858	}
1859}
1860
1861function maccheck_wds(mac_addr,num,form)
1862{
1863	var return_num=0;
1864	//if(mac_addr==":::::")
1865	if(mac_addr=="")
1866		return 2;
1867	var mac_array=mac_addr.split(':');
1868	var mac11 = mac_array[0];
1869	mac11 = mac11.substr(1,1);
1870	if((mac11=="1")||(mac11=="3")||(mac11=="5")||(mac11=="7")||
1871		(mac11=="9")||(mac11=="b")||(mac11=="d")||(mac11=="f")||
1872		(mac11=="B")||(mac11=="D")||(mac11=="F"))
1873	{
1874		if( mac11 == "1" && mac_array[0]=="11")
1875		{
1876		}
1877		else
1878			return 1;
1879	}
1880	if(mac_addr.length!=17 && mac_addr.length!=0)
1881		return 1;
1882	if((mac_array[0]=="")||(mac_array[1]=="")||(mac_array[2]=="")||(mac_array[3]=="")|| (mac_array[4]=="")||(mac_array[5]==""))
1883	{
1884		if((mac_array[0]=="")&&(mac_array[1]=="")&&(mac_array[2]=="")&&(mac_array[3]=="")&& (mac_array[4]=="")&&(mac_array[5]==""))
1885			return 2;
1886		else
1887			return 1;
1888	}
1889	if(((mac_array[0]=="00")&&(mac_array[1]=="00")&&
1890		(mac_array[2]=="00")&&(mac_array[3]=="00")&&
1891		(mac_array[4]=="00")&&(mac_array[5]=="00"))||
1892		((mac_array[0]=="ff")&&(mac_array[1]=="ff")&&
1893		 (mac_array[2]=="ff")&&(mac_array[3]=="ff")&&
1894		 (mac_array[4]=="ff")&&(mac_array[5]=="ff"))||
1895		((mac_array[0]=="FF")&&(mac_array[1]=="FF")&&
1896		 (mac_array[2]=="FF")&&(mac_array[3]=="FF")&&
1897		 (mac_array[4]=="FF")&&(mac_array[5]=="FF")))
1898		return 1;
1899	if((mac_array[0].length!=2)||(mac_array[1].length!=2)||
1900		(mac_array[2].length!=2)||(mac_array[3].length!=2)||
1901		(mac_array[4].length!=2)||(mac_array[5].length!=2))
1902		return 1;
1903	for(i=0;i<mac_addr.length;i++)
1904		if(isValidMac(mac_addr.charAt(i))==false)
1905			return 1;
1906	if( num != "" && num != 0 && num != 1 )
1907	{
1908		for( k=1;k<num;k++)
1909		{
1910			mac_str=eval('the_mac'+k);
1911			if( mac_str != "" && mac_str.toLowerCase() == mac_addr.toLowerCase())
1912			{
1913				return 3;
1914			}
1915		}
1916	}
1917	return return_num;
1918}
1919
1920function change_sec_to_time(uptime)
1921{
1922	var sec=uptime;
1923	var sec=parseInt(sec);
1924	var hour_sec=sec%3600;
1925	if(hour_sec!=sec)
1926		new_hour=(sec-hour_sec)/3600;
1927	else
1928		new_hour=0;
1929	var min_sec=hour_sec%60;
1930	if(min_sec!=hour_sec)
1931		new_min=(hour_sec-min_sec)/60;
1932	else
1933		new_min=0;
1934	var new_sec=min_sec;
1935	new_hour=new_hour.toString();
1936	new_min=new_min.toString();
1937	new_sec=new_sec.toString();
1938	if(new_hour.length==1)
1939		new_hour='0'+new_hour;
1940	if(new_min.length==1)
1941		new_min='0'+new_min;
1942	if(new_sec.length==1)
1943		new_sec='0'+new_sec;
1944	var new_time=new_hour+':'+new_min+':'+new_sec;
1945	return new_time;
1946}
1947
1948function goTestApply()
1949{
1950	var winoptions = "width=640,height=480,menubar=yes,scrollbars=yes,toolbar=yes,status=yes,location=yes,resizable=yes"
1951	if( run_test == "test")
1952		window.open('http://www.netgear.com/success/<%485%>',null,winoptions);
1953		//window.open('BAS_testpage.htm',null,winoptions);
1954}
1955
1956function xssprotect(str,flag)
1957{
1958	var xss_str;
1959	if(flag==1)
1960		xss_str = str.replace(/\&/g, "&amp;").replace(/\#/g, "&#35;").replace(/\</g, "&lt;").replace(/\>/g, "&gt;").replace(/\(/g, "&#40;").replace(/\)/g, "&#41;").replace(/\"/g, "&#34;").replace(/\'/g, "&#39;");
1961	else
1962		xss_str = str.replace(/\&/g, "&amp;").replace(/\#/g, "&#35;").replace(/ /g,"&nbsp;").replace(/\</g, "&lt;").replace(/\>/g, "&gt;").replace(/\(/g, "&#40;").replace(/\)/g, "&#41;").replace(/\"/g, "&#34;").replace(/\'/g, "&#39;");
1963	return xss_str;
1964}
1965
1966function isValidMac(digit)
1967{
1968	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",":");
1969	var len = macVals.length;
1970	var i = 0;
1971	var ret = false;
1972	for ( i = 0; i < len; i++ )
1973		if ( digit == macVals[i] )
1974			break;
1975	if ( i < len )
1976		ret = true;
1977	return ret;
1978}
1979
1980function isValidHex(each_char)
1981{
1982	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");
1983	var len = macVals.length;
1984	var i = 0;
1985	var ret = false;
1986	for ( i = 0; i < len; i++ )
1987		if ( each_char == macVals[i] )
1988			break;
1989	if ( i < len )
1990		ret = true;
1991	return ret;
1992}
1993
1994function isValidChar_space(each_char)
1995{
1996	if( each_char < 32 || each_char > 127)
1997		return false;
1998}
1999
2000function isValidChar(each_char)
2001{
2002	if( each_char < 33 || each_char > 126)
2003		return false;
2004}
2005
2006function isValidChar_all(each_char)
2007{
2008	if( each_char < 32 || each_char > 126)
2009		return false;
2010}
2011
2012function isValidCharFolderName(each_char)
2013{
2014	if( each_char < 32 || each_char > 126)
2015		return false;
2016	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)
2017		return false;
2018}
2019
2020function isValidDdnsHost(each_char)
2021{
2022	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)))
2023		return false;
2024}
2025function printPage()
2026{
2027	if (window.print)
2028		window.print();
2029	else
2030		alert("<%2378%>");
2031}
2032function top_left_nolink()
2033{
2034	parent.topframe.document.forms[0].lang_avi.disabled = true;
2035	parent.topframe.document.forms[0].apply.disabled = true;
2036}
2037
2038function wlan_txctrl(form, tx_power_ctrl, tx_power_ctrl_a, wla_channel, country)
2039{
2040	if((netgear_region == "WW" || netgear_region == "") && (country != "3" && country != "10"))
2041	{
2042		if(tx_power_ctrl == "0")
2043			form.wl_tx_ctrl.value="0";
2044		else if(tx_power_ctrl == "1")
2045			form.wl_tx_ctrl.value="1";
2046		else if(tx_power_ctrl == "2")
2047			form.wl_tx_ctrl.value="2";
2048		else if(tx_power_ctrl == "3")
2049			form.wl_tx_ctrl.value="3";
2050
2051		//for 5G
2052		if(tx_power_ctrl_a == "0")
2053			form.wla_tx_ctrl.value="44";
2054		if(parseInt(wla_channel) >= 36 && parseInt(wla_channel) <= 64)
2055		{
2056			if(tx_power_ctrl_a == "1")
2057				form.wla_tx_ctrl.value="12.5";
2058			else if(tx_power_ctrl_a == "2")
2059				form.wla_tx_ctrl.value="8.5";
2060			else if(tx_power_ctrl_a == "3")
2061				form.wla_tx_ctrl.value="4";
2062		}
2063		else if(parseInt(wla_channel) >= 100)
2064		{
2065			if(tx_power_ctrl_a == "1")
2066				form.wla_tx_ctrl.value="15.5";
2067			else if(tx_power_ctrl_a == "2")
2068				form.wla_tx_ctrl.value="10.5";
2069			else if(tx_power_ctrl_a == "3")
2070				form.wla_tx_ctrl.value="5";
2071		}
2072	}
2073	else
2074	{
2075		if(tx_power_ctrl == "0")
2076			form.wl_tx_ctrl.value="0";
2077		else if(tx_power_ctrl == "1")
2078			form.wl_tx_ctrl.value="1";
2079		else if(tx_power_ctrl == "2")
2080			form.wl_tx_ctrl.value="2";
2081		else if(tx_power_ctrl == "3")
2082			form.wl_tx_ctrl.value="3";
2083
2084		//for 5G
2085		if(tx_power_ctrl_a == "0")
2086			form.wla_tx_ctrl.value="44";
2087		if(parseInt(wla_channel) >= 36 && parseInt(wla_channel) <= 48)
2088		{
2089			if(tx_power_ctrl_a == "1")
2090				form.wla_tx_ctrl.value="10.5";
2091			else if(tx_power_ctrl_a == "2")
2092				form.wla_tx_ctrl.value="7";
2093			else if(tx_power_ctrl_a == "3")
2094				form.wla_tx_ctrl.value="3.5";
2095		}
2096		else if(parseInt(wla_channel) >= 52 && parseInt(wla_channel) <= 165)
2097		{
2098			if(tx_power_ctrl_a == "1")
2099				form.wla_tx_ctrl.value="15.5";
2100			else if(tx_power_ctrl_a == "2")
2101				form.wla_tx_ctrl.value="10.5";
2102			else if(tx_power_ctrl_a == "3")
2103				form.wla_tx_ctrl.value="5";
2104		}
2105	}
2106
2107	//the current values should be changed to (urrent_value+6)*2.
2108	//form.wl_tx_ctrl.value = ( parseFloat(form.wl_tx_ctrl.value) + 6 ) * 2;
2109	//form.wla_tx_ctrl.value = ( parseFloat(form.wla_tx_ctrl.value) + 6 ) * 2;
2110
2111}
2112
2113String.prototype.checkFolder=function()
2114{//test string
2115	var s = ["\\","\"","\'","?",":","<",">","|","*"];
2116	for (var i=0; i<s.length; i++)
2117	{
2118		if (this.indexOf(s[i]) != -1)
2119			return true;
2120	}
2121
2122	return false;
2123}
2124String.prototype.checkShareName=function()
2125{//test string
2126	var s = ["\\","\"","\/","?",":","<",">","|","*","\]"];
2127	for (var i=0; i<s.length; i++)
2128	{
2129		if (this.indexOf(s[i]) != -1)
2130			return true;
2131	}
2132
2133	return false;
2134}
2135
2136
2137function pop()
2138{
2139	if(navigator.userAgent.indexOf("MSIE") != -1)
2140		window.open('thank_login.htm','thankspage','width=460,height=420,top=240,left=300,status=yes');
2141	else
2142		window.open('thank_login.htm','thankspage','width=380,height=380,screenY=250,screenX=300,status=yes');
2143
2144}
2145