• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src/router/lighttpd-1.4.39/external_file/js_src/
1var m = new lang();
2var g_storage = new myStorage();
3var server_url = "http://oauth.asus.com/aicloud/";
4var g_bLoginFacebook = false;
5var g_bLoginGoogle = false;
6var g_key_file = null;
7var g_crt_file = null;
8var g_intermediate_crt_file = null;
9var g_create_account_dialog = null;
10var g_account_info_dialog = null;
11var g_invite_token = "";
12
13$("document").ready(function() {
14	//document.oncontextmenu = function() {return false;};
15
16	var vars = getUrlVars();
17	var loc_lan = String(window.navigator.userLanguage || window.navigator.language).toLowerCase();
18	var lan = ( g_storage.get('lan') == undefined ) ? loc_lan : g_storage.get('lan');
19	m.setLanguage(lan);
20
21	var init_page = ( vars["p"] == undefined ) ? 0 : vars["p"];
22	var only_show_init_page = ( vars["s"] == undefined ) ? 0 : vars["s"];
23
24	// 預設顯示第一個 Tab
25	var _showTabIndex = init_page;
26	$('ul.tabs li').eq(_showTabIndex).addClass('active');
27	$('.tab_content').hide().eq(_showTabIndex).show();
28
29	if(only_show_init_page){
30		$('ul.tabs li').each(function(i){
31			if(i!=_showTabIndex)
32				$('ul.tabs li').eq(i).hide();
33		});
34	}
35
36	// 當 li 頁籤被點擊時...
37	// 若要改成滑鼠移到 li 頁籤就切換時, 把 click 改成 mouseover
38	$('ul.tabs li').click(function() {
39		// 找出 li 中的超連結 href(#id)
40		var $this = $(this),
41			_clickTab = $this.find('a').attr('href');
42		// 把目前點擊到的 li 頁籤加上 .active
43		// 並把兄弟元素中有 .active 的都移除 class
44		$this.addClass('active').siblings('.active').removeClass('active');
45		// 淡入相對應的內容並隱藏兄弟元素
46		$(_clickTab).stop(false, true).fadeIn().siblings().hide();
47
48 		//if(_clickTab=="#tab3")
49 		//	getLatestVersion();
50
51		return false;
52	}).find('a').focus(function(){
53		this.blur();
54	});
55
56	$("button#btn_rescan").click(function(){
57		$("button#btn_rescan").attr("disabled", true);
58		$("button#btn_rescan").text("Wait");
59		parent.doRescanSamba();
60	});
61
62	$("button#btn_gen_crt").click(function(){
63		var client = new davlib.DavClient();
64		client.initialize();
65
66		var keylen = 2048;
67		var caname = "AiCloud";
68		var email = "";
69		var country = "TW";
70		var state = "Taiwan";
71		var ln = "Hsinchu";
72		var orag = "ASUS";
73		var ounit = "RD";
74		var cn = window.location.hostname;
75
76		var msg = m.getString("msg_gen_crt_confirm");
77		msg = msg.replace("%s", cn);
78
79		if(confirm(msg)){
80			$("#crt_creating").show();
81
82			client.GENROOTCERTIFICATE("/", keylen,caname,email,country,state,ln,orag,ounit,cn, function(error, content, statusstring){
83				if(error==200){
84					$("#crt_creating").hide();
85					alert(m.getString("msg_gen_crt_complete"));
86
87					client.APPLYAPP("/", "apply", "", "restart_webdav", function(error, statusstring, content){
88						if(error==200){
89							setTimeout( function(){
90								parent.location.reload(false);
91							}, 6000 );
92						}
93
94						client = null;
95					});
96				}
97			});
98		}
99	});
100
101	$("button#btn_import_crt").click(function(){
102
103		$("#import_crt").show();
104		$("#import_crt").css("left", tempX );
105
106		if( tempY + $("#filelink").height() > $("body").height() )
107			$("#import_crt").css("top", $("body").height() - $("#filelink").height() );
108		else
109			$("#import_crt").css("top", tempY );
110	});
111
112	$("button#btn_export_crt").click(function(){
113		window.open("/aicloud.crt");
114	});
115
116	$("button#btn_create_account").click(function(){
117		g_create_account_dialog.data("action", "new").dialog("open");
118	});
119
120	$("button#btn_create_invite").click(function(){
121		g_create_account_dialog.data("action", "invite").dialog("open");
122	});
123
124	$('li#rescan a').text(m.getString('title_rescan'));
125	$('li#sharelink a').text(m.getString('title_sharelink'));
126	$('li#version a').text(m.getString('title_version'));
127	$('li#settings a').text(m.getString('title_crt'));
128	$('li#account a').text(m.getString('title_account'));
129	$('button#ok').text(m.getString('btn_ok'));
130	$('button#cancel').text(m.getString('btn_close'));
131	$('#btn_rescan').text(m.getString('btn_rescan'));
132	$('span#desc_rescan').text(m.getString('title_desc_rescan'));
133	$('span#aicloud_desc_version').text("AiCloud " + m.getString('title_version'));
134	$('span#aicloud_version').text(g_storage.get('aicloud_version'));
135	$('span#smartsync_desc_version').text("SmartSync " + m.getString('title_version'));
136	$('span#smartsync_version').text(g_storage.get('smartsync_version'));
137
138	$('span#desc_version').text("FW " + m.getString('title_version'));
139	$('span#version').text(g_storage.get('router_version'));
140
141	$("p.desc_share_link").text(m.getString('title_copy_string'));
142
143	$("#label_gen_crt").text(m.getString("title_gen_crt"));
144	$("#btn_gen_crt").text(m.getString("title_gen_crt"));
145	$("#btn_import_crt").text(m.getString("title_import_crt"));
146	$("#desc_gen_crt").text(m.getString("title_desc_gen_crt"));
147	$("#label_server_crt").text(m.getString("title_server_crt"));
148	$("#label_crt_type").text(m.getString("title_crt_type"));
149	$("#label_self_crt_type").text(m.getString("title_self_crt_type"));
150	$("#label_crt_to").text(m.getString("title_crt_to"));
151	$("#label_crt_from").text(m.getString("title_crt_from"));
152	$("#label_crt_end_date").text(m.getString("title_crt_end_date"));
153	$("#btn_export_crt").text(m.getString("title_export_crt"));
154	$("#label_https_crt_cn").text(m.getString('https_crt_cn'));
155	$("#crt_creating").text(m.getString('msg_gen_crt_creating'));
156
157	$("#desc_import_crt").text(m.getString('desc_import_crt'));
158	$("#label_select_private_key").text(m.getString('title_select_private_key'));
159	$("#label_select_certificate").text(m.getString('title_select_certificate'));
160	$("#label_select_intermediate_certificate").text(m.getString('title_select_intermediate_certificate'));
161	$("#import").text(m.getString('title_import_crt'));
162
163	//- account manager
164	$("#label_create_account").text(m.getString('title_create_account'));
165	$("#desc_create_account").text(m.getString('title_desc_create_account'));
166	$("#btn_create_account").text(m.getString('title_create_account'));
167	$("#btn_create_invite").text(m.getString('title_invite_account'));
168	$("#label_username").text(m.getString('title_username'));
169	$("#label_password").text(m.getString('title_password'));
170	$("#label_password_confirm").text(m.getString('title_password_confirm'));
171	$("#label_size_limit").text(m.getString('title_size_limit'));
172	$("#label_access_permission").text(m.getString('title_access_permission'));
173	$("#label_account_list").text(m.getString('title_account_list'));
174	$("#table_account_list td[field=username]").text(m.getString('title_username'));
175	$("#table_account_list td[field=type]").text(m.getString('title_type'));
176	$("#table_account_list td[field=edit]").text(m.getString('title_edit'));
177	$("#table_account_list td[field=delete]").text(m.getString('title_delete'));
178	$("#label_account_invite_list").text(m.getString('title_account_invite_list'));
179	$("#table_account_invite_list td[field=invite]").text(m.getString('title_invite'));
180	$("#table_account_invite_list td[field=createtime]").text(m.getString('title_create_time'));
181	$("#table_account_invite_list td[field=edit]").text(m.getString('title_edit'));
182	$("#table_account_invite_list td[field=delete]").text(m.getString('title_delete'));
183
184	$("#label_security_code").text(m.getString('title_security_code'));
185	$("#select_security_code option[value=0]").text(m.getString('title_security_code_type_none'));
186	$("#select_security_code option[value=1]").text(m.getString('title_security_code_type_manually'));
187	$("#select_security_code option[value=2]").text(m.getString('title_security_code_type_auto'));
188
189	$("#label_smart_access").text(m.getString('title_smart_access'));
190	$("#span_smart_access").text(m.getString('title_enable'));
191
192	if(_showTabIndex==1)
193		refreshShareLinkList();
194	else if(_showTabIndex==3)
195		refreshCertificateInfo();
196
197	$(".abgne_tab").css("height", $(window).height()-80);
198
199	$("#facebook .user_login_option").click(function(){
200
201		if(g_bLoginFacebook)
202			return;
203
204		facebook_login();
205	});
206
207	$("#google .user_login_option").click(function(){
208
209		if(g_bLoginGoogle)
210			return;
211
212		google_login();
213	});
214
215	$("#btn_select_key").change(function(evt){
216
217		if(evt.target.files.length!=1){
218			alert("Please select a key file!");
219			return;
220		}
221
222		g_key_file = evt.target.files[0];
223	});
224
225	$("#btn_select_crt").change(function(evt){
226		if(evt.target.files.length!=1){
227			alert("Please select a key file!");
228			return;
229		}
230
231		g_crt_file = evt.target.files[0];
232	});
233
234	$("#btn_select_intermediate_crt").change(function(evt){
235		if(evt.target.files.length!=1){
236			return;
237		}
238
239		g_intermediate_crt_file = evt.target.files[0];
240	});
241
242	$("#select_security_code").change(function() {
243		if($(this).val()==1){
244			$("#input_security_code").show();
245		}
246		else{
247			$("#input_security_code").hide();
248		}
249	});
250
251	g_create_account_dialog = $("#dialog_create_account").dialog({
252    	autoOpen: false,
253      	height: 500,
254      	width: 600,
255      	modal: true,
256      	buttons: {
257        	OK: function(){
258
259        		var username = myencodeURI(String($("#input_username").val()).trim());
260        		var password = String($("#input_password").val()).trim();
261        		var password_confirm = String($("#input_password_confirm").val()).trim();
262        		var type = "aicloud";
263        		var action = $(this).data('action');
264        		var user_id = -1;
265
266        		if(action!="invite" && action!="modify_invite"){
267	        		if(username==""){
268	        			//- 帳號不可空白
269	        			alert(m.getString('msg_err_account_blank'));
270	        			return;
271	        		}
272
273	        		if(password!=password_confirm){
274	        			//- 密碼輸入不正確
275	        			alert(m.getString('msg_err_password_matched'));
276	        			return;
277	        		}
278        		}
279
280        		var client = new davlib.DavClient();
281				client.initialize();
282
283      			if(action=="modify"){
284      				user_id = parseInt($(this).data('id'));
285      			}
286
287      			var result_folder_permission = "";
288      			for (var key_partion in g_folder_permission_info){
289	  				if (g_folder_permission_info.hasOwnProperty(key_partion)) {
290	  					for (var key_folder in g_folder_permission_info[key_partion]){
291	  						if (g_folder_permission_info[key_partion].hasOwnProperty(key_folder)) {
292	  							var folder_permission = g_folder_permission_info[key_partion][key_folder];
293	  							result_folder_permission += myencodeURI(key_partion)+","+myencodeURI(key_folder)+","+folder_permission;
294	  							result_folder_permission += ";";
295	  							//alert(key_partion + " -> " + key_folder + " -> " + folder_permission);
296	  						}
297	  					}
298	  				}
299	  			}
300
301	  			username = encodeURIComponent(username);
302	  			password = encodeURIComponent(password);
303	  			type = encodeURIComponent(type);
304	  			result_folder_permission = encodeURIComponent(result_folder_permission);
305
306	  			if(action=="invite" || action=="modify_invite"){
307
308	  				var security_code = "";
309
310					if($("#select_security_code").val()==0){
311						security_code = "";
312					}
313					else if($("#select_security_code").val()==1){
314						security_code = $("#input_security_code").val();
315
316						if(security_code==""){
317							alert("Please input security code!");
318							return;
319						}
320					}
321					else if($("#select_security_code").val()==2){
322						security_code = Math.floor(1000 + Math.random() * 9000);
323					}
324
325					var enable_smart_access = ($("#input_smart_access").prop("checked")==true) ? 1 : 0;
326
327	  				client.UPDATEACCOUNTINVITE( '/', g_invite_token, result_folder_permission, enable_smart_access, security_code, function(error, statusstring, content){
328						if(error==200){
329
330							var data = parseXml(content);
331							var x = $(data);
332
333							var invite_token = x.find("token").text();
334
335							g_create_account_dialog.dialog( "close" );
336
337							query_account_invite_list();
338
339							//- show invite info
340							if(action=="invite"){
341								g_account_info_dialog
342					  				.data("action", "invite")
343					  				.data("invite_token", invite_token)
344					  				.data("enable_smart_access", enable_smart_access)
345					  				.data("security_code", security_code)
346					  				.dialog("open");
347					  		}
348						}
349						else{
350							//- Fail to create account, please check and try again.
351							alert(m.getString("msg_err_account_create"));
352						}
353					}, null );
354
355	  				return;
356	  			}
357
358      			client.UPDATEACCOUNT( '/', user_id, username, password, type, result_folder_permission, function(error, statusstring, content){
359					if(error==200){
360						if(content=="ACCOUNT_IS_EXISTED"){
361							//- Account is already existed!;
362							alert(m.getString("msg_err_account_existed"));
363							return;
364						}
365
366						set_account_input_default_val();
367
368						g_create_account_dialog.dialog( "close" );
369
370						query_account_list();
371					}
372					else{
373						//- Fail to create account, please check and try again.
374						alert(m.getString("msg_err_account_create"));
375					}
376				}, null );
377
378        	},
379        	CANCEL: function() {
380          		g_create_account_dialog.dialog( "close" );
381        	}
382      	},
383      	close: function() {
384
385      	},
386      	open: function() {
387
388      		$("#dialog_create_account .ui-button-text:contains(OK)").text(m.getString('btn_ok'));
389      		$("#dialog_create_account .ui-button-text:contains(CANCEL)").text(m.getString('btn_cancel'));
390
391      		var action = $(this).data('action');
392
393      		if(action=="modify"){
394      			var user_id = parseInt($(this).data('id'));
395      			var user_name = $(this).data('username');
396      			var user_type = $(this).data('usertype');
397
398      			$("#dialog_create_account").dialog("option", "title", m.getString('title_update_account'));
399      			$("#input_username").attr("disabled", true);
400
401				var client = new davlib.DavClient();
402				client.initialize();
403
404				client.GETACCOUNTINFO( '/', user_name, function(context, status, statusstring){
405					if(context==200){
406
407						var data = parseXml(statusstring);
408						var x = $(data);
409
410						var username = x.find("username").text();
411						var type = x.find("type").text();
412						var permission = x.find("permission").text();
413						var password = x.find("password").text();
414
415						$(".option_account").show();
416						$(".option_invite").hide();
417						$("#input_username").val(username);
418					    $("#input_password").val(password);
419					    $("#input_password_confirm").val(password);
420					    $("#table_share_folder").css("height", 220);
421
422					    query_partition_share_folder(type, username, g_storage.get('usbdiskname'), g_storage.get('usbdiskname'), "table_share_folder", 0);
423					}
424				}, null );
425      		}
426      		else if(action=="new"){
427      			$("#dialog_create_account").dialog("option", "title", m.getString('title_create_account'));
428      			$(".option_account").show();
429      			$(".option_invite").hide();
430      			$("#input_username").attr("disabled", false);
431      			$("#input_username").val("");
432				$("#input_password").val("");
433				$("#input_password_confirm").val("");
434				$("#input_name").val("");
435				$("#table_share_folder").css("height", 220);
436
437      			query_partition_share_folder('', '', g_storage.get('usbdiskname'), g_storage.get('usbdiskname'), "table_share_folder", 0);
438      		}
439      		else if(action=="invite"){
440      			$("#dialog_create_account").dialog("option", "title", m.getString('title_invite_account'));
441      			$(".option_account").hide();
442      			$(".option_invite").show();
443      			$("#table_share_folder").css("height", 280);
444
445      			g_invite_token = "";
446
447				query_partition_share_folder('', '', g_storage.get('usbdiskname'), g_storage.get('usbdiskname'), "table_share_folder", 0);
448      		}
449      		else if(action=="modify_invite"){
450      			var token = $(this).data('token');
451      			var client = new davlib.DavClient();
452				client.initialize();
453
454				client.GETACCOUNTINVITEINFO( '/', token, function(context, status, statusstring){
455					if(context==200){
456
457						var data = parseXml(statusstring);
458						var x = $(data);
459
460						var permission = x.find("permission").text();
461						var smart_access = parseInt(x.find("smart_access").text());
462						var security_code = x.find("security_code").text();
463
464						g_invite_token = token;
465
466						$(".option_account").hide();
467						$(".option_invite").show();
468					    $("#table_share_folder").css("height", 280);
469
470					    $("#input_smart_access").prop("checked", (smart_access==1) ? true : false);
471
472					    if(security_code==""){
473					    	$("#select_security_code").val(0);
474					    	$("#input_security_code").hide();
475					    }
476					    else{
477					    	$("#select_security_code").val(1);
478					    	$("#input_security_code").show();
479					    	$("#input_security_code").val(security_code);
480					    }
481
482					    query_partition_share_folder('', '', g_storage.get('usbdiskname'), g_storage.get('usbdiskname'), "table_share_folder", 0);
483					}
484				}, null );
485      		}
486      	}
487    });
488
489    g_account_info_dialog = $("#dialog_account_info").dialog({
490    	autoOpen: false,
491      	height: 500,
492      	width: 600,
493      	modal: true,
494      	buttons: {
495      		OK: function() {
496          		g_account_info_dialog.dialog( "close" );
497        	}
498      	},
499      	open: function(){
500      		var action = $(this).data('action');
501      		var invite_token = $(this).data('invite_token');
502      		var enable_smart_access = $(this).data('enable_smart_access');
503      		var security_code = $(this).data('security_code');
504
505      		if(action=="invite"){
506
507      			var invite_url = "";
508				if(g_storage.get('ddns_host_name')==""){
509					var b = window.location.href.indexOf("/",window.location.protocol.length+2);
510					invite_url = window.location.href.slice(0,b) + "/" + invite_token;
511				}
512				else{
513					invite_url = "https://" + g_storage.get('ddns_host_name');
514
515					if(g_storage.get("https_port")!="443")
516						invite_url += ":" + g_storage.get("https_port");
517
518					invite_url += "/" + invite_token;
519				}
520
521				var invitation_desc = m.getString("msg_invitation_desc1");
522				var smartaccess_desc = m.getString("title_smart_access") + ": " + ((enable_smart_access==1) ? m.getString("title_enable") : m.getString("title_disable"));
523				var securitycode_desc = m.getString("title_security_code") + ": " + ((security_code==""||security_code=="none") ? m.getString("title_security_code_type_none") : security_code);
524
525				var account_info = invitation_desc.replace(/\n/g, "<br><br>");
526				account_info += "<a style=\"color:#ff0000\" href=\"" + invite_url + "\" target=\"_blank\">" + invite_url + "</a>";
527				account_info += "<br><br>" + smartaccess_desc;
528				account_info += "<br><br>" + securitycode_desc;
529
530				$("#account_info").html(account_info);
531
532				var mail_content = "mailto:?subject=Welcome to my AiCloud";
533      			mail_content += "&body=";
534      			mail_content += encodeURIComponent(invitation_desc);
535      			mail_content += encodeURIComponent(invite_url);
536      			mail_content += encodeURIComponent("\n" + smartaccess_desc);
537      			mail_content += encodeURIComponent("\n" + securitycode_desc);
538
539				$("#mail_invitation").attr("href", mail_content);
540      		}
541      	}
542    });
543
544    query_account_list();
545    query_account_invite_list();
546});
547
548var g_folder_permission_info = Array();
549
550function query_partition_share_folder(account_type, account, path, folder, table_name, level){
551
552	if(level>1)
553		return;
554
555	var param = {};
556    param.action = "query_disk_folder";
557    param.id = "#";
558    param.path = path;
559    param.type = account_type;
560    param.account = account;
561
562    $.ajax({
563		url: '/query_field.json',
564	  	data: param,
565	  	type: 'GET',
566	  	dataType: 'json',
567	  	timeout: 20000,
568	  	error: function(){
569			alert('Error loading json data!');
570	  	},
571	  	success: function(json_data){
572	  		var html_data = "<table class='tree_table'>";
573
574	  		level+=1;
575
576	  		for(var i=0; i<json_data.length; i++){
577	  			var folder_name = json_data[i].text;
578	  			var folder_permission = parseInt(json_data[i].permission);
579	  			var random_seed = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 5);
580	  			var the_id = random_seed + "_" + i;
581
582	  			if(level==1){
583	  				html_data += "<tr class='partion_table_tr' style='background-color:#989898;color:#ffffff'>";
584	  				html_data += "<td>";
585	  				html_data += folder_name;
586	  				html_data += "</td>";
587	  				html_data += "<td></td>";
588	  				html_data += "</tr>";
589
590	  				g_folder_permission_info[folder_name] = Array();
591	  			}
592	  			else if(level==2){
593	  				html_data += "<tr class='folder_table_tr' style='border-bottom:1px solid #989898'>";
594
595	  				html_data += "<td style='padding-left:10px'>";
596		  			html_data += folder_name;
597		  			html_data += "</td>";
598
599	  				html_data += "<td style='width:150px;'>";
600	  				html_data += "<div id='f" + the_id + "' data-id='" + the_id + "' class='FileStatus' data-partition='" + folder + "' data-folder='" + folder_name + "'>";
601	  				html_data += "<table>";
602	  				html_data += "<tr data-permission='" + folder_permission + "'>";
603	  				html_data += "<td><input type='radio' class='radio_permission' name='g" + the_id + "' id='g" + the_id + "' value='3'" + ((folder_permission==3) ? " checked" : "") + ">R/W</td>";
604					html_data += "<td><input type='radio' class='radio_permission' name='g" + the_id + "' id='g" + the_id + "' value='1'" + ((folder_permission==1) ? " checked" : "") + ">R</td>";
605					html_data += "<td><input type='radio' class='radio_permission' name='g" + the_id + "' id='g" + the_id + "' value='0'" + ((folder_permission==0||folder_permission==-1) ? " checked" : "") + ">N</td>";
606					html_data += "</tr>";
607					html_data += "</table>";
608					html_data += "</div>";
609					html_data += "</td>";
610
611					html_data += "</tr>";
612
613					g_folder_permission_info[folder][folder_name] = folder_permission;
614				}
615
616	  			var sub_table_name = "table_" + random_seed;
617	  			html_data += "<tr><td colspan='2'><div id='" + sub_table_name + "'></div></td></tr>";
618	  			query_partition_share_folder(account_type, account, path + "/" + folder_name, folder_name, sub_table_name, level);
619	  		}
620
621	  		html_data += "</table>";
622
623	  		$("#"+ table_name).html(html_data);
624
625	  		$(".folder_table_tr").mouseenter(function(){
626	  			$(this).css("background-color", "#cccccc");
627	  		});
628
629	  		$(".folder_table_tr").mouseleave(function(){
630	  			$(this).css("background-color", "transparent");
631	  		});
632
633	  		$(".radio_permission").change(function(){
634	  			var data_id = $(this).closest('.FileStatus').attr("data-id");
635	  			var partion_name = $(this).closest('.FileStatus').attr("data-partition");
636	  			var folder_name = $(this).closest('.FileStatus').attr("data-folder");
637	  			var folder_permission = parseInt($(this).val());
638
639	  			g_folder_permission_info[partion_name][folder_name] = folder_permission;
640
641	  			//console.log(g_folder_permission_info);
642	  		});
643	 	}
644	});
645}
646
647function set_account_input_default_val(){
648	$("#input_username").val("");
649    $("#input_password").val("");
650    $("#input_password_confirm").val("");
651    $("#input_name").val("");
652}
653
654function query_account_list(){
655
656	var client = new davlib.DavClient();
657	client.initialize();
658
659	client.GETACCOUNTLIST( '/', function(context, status, statusstring){
660		if(context==200){
661
662			var data = parseXml(statusstring);
663			var x = $(data);
664
665			var account_list = x.find("account");
666
667			var html_data = "";
668
669	  		for(var i=0; i<account_list.length; i++){
670
671	  			var data_account = parseXml(account_list[i]);
672				var y = $(data_account);
673
674	  			var id = y.find("id").text();
675	  			var username = y.find("username").text();
676	  			var type = y.find("type").text();
677
678	  			html_data += "<tr data-acid='" + id + "' data-username='" + username + "' data-usertype='" + type + "'>";
679	  			html_data += "<td>";
680	  			html_data += username;
681	  			html_data += "</td>";
682	  			html_data += "<td>";
683	  			html_data += type;
684	  			html_data += "</td>";
685	  			html_data += "<td align='center'>";
686
687	  			if(type=="aicloud")
688	  				html_data += "<input class='edit_account' type='button' value='" + m.getString('title_edit') + "'/>";
689
690	  			html_data += "</td>";
691	  			html_data += "<td align='center'>";
692
693	  			if(type=="aicloud")
694	  				html_data += "<input class='delete_account' type='button' value='" + m.getString('title_delete') + "'/>";
695
696	  			html_data += "</td>";
697	  			html_data += "</tr>";
698	  		}
699
700
701	  		$("#table_account_list tbody").empty();
702	  		$("#table_account_list tbody").append(html_data);
703
704	  		$(".edit_account").click(function(){
705	  			var item_info = $(this).closest("tr");
706	  			var account_id = item_info.attr("data-acid");
707	  			var account_username = item_info.attr("data-username");
708	  			var account_usertype = item_info.attr("data-usertype");
709
710	  			g_create_account_dialog
711	  				.data("action", "modify")
712	  				.data("id", account_id)
713	  				.data("username", account_username)
714	  				.data("usertype", account_usertype)
715	  				.dialog("open");
716	  		});
717
718	  		$(".delete_account").click(function(){
719	  			var item_info = $(this).closest("tr");
720	  			var account_id = item_info.attr("data-acid");
721	  			var account_username = item_info.attr("data-username");
722	  			var msg = m.getString("msg_delete_account");
723				msg = msg.replace("%s", account_username);
724
725	  			if(confirm(msg)){
726		  			var client = new davlib.DavClient();
727					client.initialize();
728					client.DELETEACCOUNT( '/', account_username, function(error, statusstring, content){
729						if(error==200){
730							query_account_list();
731						}
732						else{
733							alert("Fail to delete account.");
734						}
735					}, null );
736				}
737	  		});
738		}
739
740	}, null );
741
742}
743
744function query_account_invite_list(){
745
746	var b = window.location.href.indexOf("/",window.location.protocol.length+2);
747	var window_url = window.location.href.slice(0,b);
748
749	var window_url = "";
750	if(g_storage.get('ddns_host_name')==""){
751		var b = window.location.href.indexOf("/",window.location.protocol.length+2);
752		window_url = window.location.href.slice(0,b);
753	}
754	else{
755		window_url = "https://" + g_storage.get('ddns_host_name');
756	}
757
758	var client = new davlib.DavClient();
759	client.initialize();
760
761	client.GETACCOUNTINVITELIST( '/', function(context, status, statusstring){
762		if(context==200){
763
764			var data = parseXml(statusstring);
765			var x = $(data);
766
767			var invite_list = x.find("invite");
768
769			var html_data = "";
770
771	  		for(var i=0; i<invite_list.length; i++){
772
773	  			var data_invite = parseXml(invite_list[i]);
774				var y = $(data_invite);
775
776	  			var id = y.find("id").text();
777	  			var token = y.find("token").text();
778	  			var timestamp = y.find("timestamp").text();
779	  			var smart_access = y.find("smart_access").text();
780	  			var security_code = y.find("security_code").text();
781
782	  			html_data += "<tr data-aciid='" + id + "' data-token='" + token + "' data-smart-access='" + smart_access + "' data-security-code='" + security_code + "'>";
783	  			html_data += "<td>";
784	  			html_data += "<a href='#' class='show_account_invite_info'>"
785	  			html_data += token;
786	  			html_data += "</a>";
787	  			html_data += "</td>";
788	  			html_data += "<td>";
789	  			html_data += timestamp;
790	  			html_data += "</td>";
791	  			html_data += "<td align='center'>";
792
793	  			html_data += "<input class='edit_account_invite' type='button' value='" + m.getString('title_edit') + "'/>";
794
795	  			html_data += "</td>";
796	  			html_data += "<td align='center'>";
797
798	  			html_data += "<input class='delete_account_invite' type='button' value='" + m.getString('title_delete') + "'/>";
799
800	  			html_data += "</td>";
801	  			html_data += "</tr>";
802	  		}
803
804
805	  		$("#table_account_invite_list tbody").empty();
806	  		$("#table_account_invite_list tbody").append(html_data);
807
808	  		$(".edit_account_invite").click(function(){
809	  			var item_info = $(this).closest("tr");
810	  			var invite_id = item_info.attr("data-aciid");
811	  			var invite_token = item_info.attr("data-token");
812
813	  			g_create_account_dialog
814	  				.data("action", "modify_invite")
815	  				.data("token", invite_token)
816	  				.dialog("open");
817	  		});
818
819	  		$(".delete_account_invite").click(function(){
820	  			var item_info = $(this).closest("tr");
821	  			var invite_id = item_info.attr("data-aciid");
822	  			var invite_token = item_info.attr("data-token");
823	  			var msg = m.getString("msg_delete_account_invite");
824
825	  			if(confirm(msg)){
826		  			var client = new davlib.DavClient();
827					client.initialize();
828					client.DELETEACCOUNTINVITE( '/', invite_token, function(error, statusstring, content){
829						if(error==200){
830							query_account_invite_list();
831						}
832						else{
833							alert("Fail to delete account invite.");
834						}
835					}, null );
836				}
837	  		});
838
839	  		$(".show_account_invite_info").click(function(){
840	  			var item_info = $(this).closest("tr");
841	  			var invite_id = item_info.attr("data-aciid");
842	  			var invite_token = item_info.attr("data-token");
843	  			var enable_smart_access = item_info.attr("data-smart-access");
844	  			var security_code = item_info.attr("data-security-code");
845
846	  			//- show invite info
847				g_account_info_dialog
848					.data("action", "invite")
849				  	.data("invite_token", invite_token)
850				  	.data("enable_smart_access", enable_smart_access)
851				  	.data("security_code", security_code)
852				  	.dialog("open");
853	  		});
854		}
855
856	}, null );
857
858}
859
860function onFacebookLogin( token, uid ){
861
862	alert(token+", "+uid);
863
864	/*
865	g_token = token,
866	g_uid = uid;
867
868	g_storage.sett("facebook_access_token", g_token);
869	g_storage.sett("facebook_uid", uid);
870
871	facebook_get_userprofile();
872	*/
873}
874
875function facebook_login(){
876	var app_id = "697618710295679";
877	window._onFacebookLogin = this.onFacebookLogin;
878	var b = window.location.href.indexOf("/",window.location.protocol.length+2);
879	var callback_function = "_onFacebookLogin";
880
881	var auth_url = server_url + "fb_authorize.html?callback=" + callback_function + "&ps5host=";
882	var redirect_url = window.location.href.slice(0,b) + "/smb/css/service/callback.html&response_type=token";
883	var url = "http://www.facebook.com/dialog/oauth/?scope=publish_stream%2Cuser_photos%2Coffline_access&client_id=" + app_id + "&display=popup&redirect_uri=" + encodeURIComponent(auth_url) + redirect_url;
884
885	window.open(url,"mywindow","menubar=1,resizable=0,width=630,height=250, top=100, left=300");
886}
887
888function onGoogleLogin( token, uid ){
889
890	alert(token+", "+uid);
891
892	/*
893	g_token = token,
894	g_uid = uid;
895
896	g_storage.sett("facebook_access_token", g_token);
897	g_storage.sett("facebook_uid", uid);
898
899	facebook_get_userprofile();
900	*/
901}
902
903function google_login(){
904	var app_id = "103584452676-oo7gkbh8dg7nm07lao9a0i3r9jh6jfra.apps.googleusercontent.com";
905	var b = window.location.href.indexOf("/",window.location.protocol.length+2);
906	var callback_function = "onGoogleLogin";
907
908	var auth_url = server_url + "google_authorize.html";
909	var redirect_url = window.location.href.slice(0,b) + "/smb/css/service/callback.html";
910
911	var url = "https://accounts.google.com/o/oauth2/auth?" +
912			  "response_type=token" +
913			  "&redirect_uri=" + encodeURIComponent(auth_url) +
914			  "&client_id=" + app_id +
915			  "&scope=https://www.googleapis.com%2Fauth%2Fuserinfo.email+https://www.googleapis.com%2Fauth%2Fuserinfo.profile+https://picasaweb.google.com%2Fdata" +
916			  "&state=/callback=" + callback_function + "+ps5host=" + redirect_url;
917
918	window.open(url,"mywindow","menubar=1,resizable=0,width=630,height=250, top=100, left=300");
919}
920
921function getLatestVersion(){
922	var client = new davlib.DavClient();
923	client.initialize();
924
925	$("#update").text(m.getString('msg_check_latest_ver'));
926
927	client.GETLATESTVER("/", function(error, content, statusstring){
928		if(error==200){
929			var data = parseXml(statusstring);
930			var x = $(data);
931
932			var ver = x.find("version").text();
933			var a = ver.split("_");
934			var build_no = a[1];
935
936			var cur_ver = g_storage.get('router_version');
937			var b = cur_ver.split(".");
938			var cur_build_no = b[3];
939
940			if(build_no>cur_build_no)
941				$("#update").text(m.getString('msg_update_latest_ver'));
942			else
943				$("#update").text(m.getString('msg_latest_ver'));
944		}
945		else{
946			$("#update").text(m.getString('msg_check_latest_ver_error'));
947		}
948
949		client = null;
950	});
951}
952
953function refreshShareLinkList(){
954	var webdav_mode = g_storage.get('webdav_mode');
955	var ddns_host_name = g_storage.get('ddns_host_name');
956	var cur_host_name = window.location.host;
957	var hostName = "";
958
959	if(!isPrivateIP(cur_host_name))
960		hostName = cur_host_name;
961	else
962		hostName = (ddns_host_name=="") ? cur_host_name : ddns_host_name;
963
964	if(hostName.indexOf(":")!=-1)
965		hostName = hostName.substring(0, hostName.indexOf(":"));
966
967	if( webdav_mode == 0 ) //- Only enable http
968		hostName = "http://" + hostName + ":" + g_storage.get("http_port");
969	else{
970		hostName = "https://" + hostName;
971
972		if(g_storage.get("https_port")!="443")
973			hostName += ":" + g_storage.get("https_port");
974	}
975
976	var client = new davlib.DavClient();
977	client.initialize();
978	client.GSLL("/", function(error, content, statusstring){
979		if(error==200){
980			var data = parseXml(statusstring);
981
982			$("#tab2").empty();
983
984			var table_html = "<table id='sharelink' width='100%' border='0' style='table-layout:fixed'>";
985			table_html += "<thead><tr>";
986     		table_html += "<th scope='col' class='check' style='width:5%'>";
987			table_html += "<input type='checkbox' id='select_all' name='select_all' class='select_all'>";
988			table_html += "</th>";
989
990			table_html += "<th scope='col' class='filename' style='width:20%'>" + m.getString('table_filename') + "</th>";
991      		table_html += "<th scope='col' class='createtime' style='width:25%'>" + m.getString('table_createtime') + "</th>";
992      		table_html += "<th scope='col' class='expiretime' style='width:25%'>" + m.getString('table_expiretime') + "</th>";
993      		table_html += "<th scope='col' class='lefttime' style='width:15%'>" + m.getString('table_lefttime') + "</th>";
994      		table_html += "<th scope='col' class='remove' style='width:10%'>" + m.getString('func_delete') + "</th>";
995    		table_html += "</tr></thead>";
996
997    		table_html += "<tbody id='ntb'>";
998
999			var encode_filename = parseInt($(data).find('encode_filename').text());
1000
1001    		var i = 0;
1002			$(data).find('sharelink').each(function(){
1003
1004				try{
1005					var filename = "";
1006					var filetitle = "";
1007
1008					if(encode_filename==1){
1009						filename = $(this).attr("filename");
1010						filetitle = decodeURIComponent(filename);
1011					}
1012					else{
1013						filetitle = $(this).attr("filename");
1014						filename = encodeURIComponent($(this).attr("filename"));
1015					}
1016
1017					var url = hostName + "/" + $(this).attr("url") + "/" + filename;
1018					var createtime = $(this).attr("createtime");
1019					var expiretime = $(this).attr("expiretime");
1020					var lefttime = parseFloat($(this).attr("lefttime"));
1021					var hour = parseInt(lefttime/3600);
1022					var minute = parseInt(lefttime%3600/60);
1023
1024					table_html += "<tr nid='" + i + "' class='even'>";
1025
1026					table_html += "<td fid='check' align='center'><input type='checkbox' id='check_del' name='check_del' class='check_del' link=\"" + $(this).attr("url") + "\"></td>";
1027
1028					table_html += "<td fid='filename' align='center'><div style='overflow:hidden;'>";
1029					table_html += "<a class='share_link_url' uhref=\"" + url + "\" href='#' title=\"" + filetitle + "\" style='white-space:nowrap;'>" + filetitle + "</a>";
1030					table_html += "</div></td>";
1031					table_html += "<td fid='createtime' align='center'>" + createtime + "</td>";
1032					if(expiretime==0){
1033						table_html += "<td fid='expiretime' align='center'>" + m.getString('title_unlimited') + "</td>";
1034						table_html += "<td fid='lefttime' align='center'>" + m.getString('title_unlimited') + "</td>";
1035					}
1036					else{
1037						table_html += "<td fid='expiretime' align='center'>" + expiretime + "</td>";
1038						table_html += "<td fid='lefttime' align='center'>" + hour + " hours " + minute + " mins" + "</td>";
1039					}
1040					table_html += "<td fid='remove' align='center'><a>";
1041					table_html += "<div class='dellink' title='remove' link=\"" + $(this).attr("url") + "\" style='cursor:pointer'></div>";
1042					table_html += "</a></td>";
1043
1044					table_html += "</tr>";
1045			  	}
1046				catch(err){
1047					//Handle errors here
1048				}
1049
1050				i++;
1051			});
1052
1053			table_html += "</tbody>";
1054			table_html += "</table>";
1055
1056			table_html += "<div class='delcheck_block'>";
1057			table_html += "<span>刪除選取連結</span>";
1058			table_html += "</div>";
1059
1060			$(table_html).appendTo($("#tab2"));
1061
1062			$("div.delcheck_block").css("visibility", "hidden");
1063
1064			$("a.share_link_url").click(function(){
1065				$("#filelink").css("display","block");
1066				$("#filelink").css("left", tempX );
1067
1068				if( tempY + $("#filelink").height() > $("body").height() )
1069					$("#filelink").css("top", $("body").height() - $("#filelink").height() );
1070				else
1071					$("#filelink").css("top", tempY );
1072
1073				$("#resourcefile").attr("value",$(this).attr("uhref"));
1074				$("#resourcefile").focus();
1075				$("#resourcefile").select();
1076			});
1077
1078			$(".dellink").click(function(){
1079
1080				var r=confirm(m.getString('msg_confirm_delete_sharelink'));
1081
1082				if (r==true){
1083					client.REMOVESL("/", $(this).attr("link"), function(error, content, statusstring){
1084						if(error==200){
1085							refreshShareLinkList();
1086						}
1087					});
1088				}
1089			});
1090
1091			$(".check_del").change(function(){
1092
1093				var del_count = 0;
1094
1095				$("input:checkbox.check_del").each(function(){
1096					if($(this).prop("checked")){
1097						del_count++;
1098					}
1099				});
1100
1101				if(del_count<=0){
1102
1103					var newTop = tempY+10;
1104					var newLeft = 0;
1105					$("div.delcheck_block").animate({
1106						top: newTop,
1107						left: newLeft
1108					},
1109					'fast',
1110					function(){
1111						$("div.delcheck_block").css("visibility", "hidden");
1112					});
1113				}
1114				else{
1115
1116					$("div.delcheck_block").css("visibility", "");
1117
1118					var newTop = tempY+10;
1119					var newLeft = tempX+10;
1120					$("div.delcheck_block").animate({
1121						top: newTop,
1122						left: newLeft
1123					}, 'fast');
1124				}
1125			});
1126
1127			$(".delcheck_block").click(function(){
1128
1129				var r=confirm(m.getString('msg_confirm_delete_sharelink'));
1130
1131				if (r==true){
1132
1133					$("div.delcheck_block").css("visibility", "hidden");
1134
1135					$("input:checkbox.check_del").each(function(){
1136						if($(this).prop("checked")){
1137
1138							client.REMOVESL("/", $(this).attr("link"), function(error, content, statusstring){
1139								if(error==200){
1140									refreshShareLinkList();
1141								}
1142							});
1143						}
1144					});
1145				}
1146			});
1147
1148			$("input.select_all").change(function(){
1149				if($(this).prop("checked")){
1150					$('input:checkbox.check_del').prop('checked', true);
1151					$("div.delcheck_block").css("visibility", "");
1152
1153					var newTop = tempY+10;
1154					var newLeft = tempX+10;
1155					$("div.delcheck_block").animate({
1156						top: newTop,
1157						left: newLeft
1158					}, 'fast');
1159				}
1160				else{
1161					$('input:checkbox.check_del').prop('checked', false);
1162
1163					var newTop = tempY+10;
1164					var newLeft = 0;
1165					$("div.delcheck_block").animate({
1166						top: newTop,
1167						left: newLeft
1168					},
1169					'fast',
1170					function(){
1171						$("div.delcheck_block").css("visibility", "hidden");
1172					});
1173				}
1174			});
1175		}
1176	});
1177}
1178
1179function refreshCertificateInfo(){
1180
1181	var userpermission = (g_storage.get('userpermission')==undefined) ? "" : g_storage.get('userpermission');
1182	if(userpermission=="admin"){
1183		$("#field_import_crt").show();
1184	}
1185	else{
1186		$("#field_import_crt").hide();
1187	}
1188
1189	var client = new davlib.DavClient();
1190	client.initialize();
1191	client.GETX509CERTINFO("/", function(error, content, statusstring){
1192		if(error==200){
1193
1194			var data = parseXml(statusstring);
1195
1196			var issuer = $(data).find('issuer').text();
1197			var subject = $(data).find('subject').text();
1198			var crt_start_date = $(data).find('crt_start_date').text();
1199			var crt_end_date = $(data).find('crt_end_date').text();
1200
1201			if(subject!=""){
1202				subject = subject.substring( subject.indexOf("CN=")+3, subject.length );
1203
1204				if(subject.indexOf("/")!=-1){
1205					subject = subject.substring( 0, subject.indexOf("/") );
1206				}
1207			}
1208
1209			if(issuer!=""){
1210				issuer = issuer.substring( issuer.indexOf("CN=")+3, issuer.length );
1211
1212				if(issuer.indexOf("/")!=-1){
1213					issuer = issuer.substring( 0, issuer.indexOf("/") );
1214				}
1215			}
1216
1217			//crt_end_date = "160607080028Z";
1218			if(crt_end_date!=""){
1219
1220				var mydate = new Date( 2000+parseInt(crt_end_date.substring(0, 2)),
1221				                       parseInt(crt_end_date.substring(2, 4)),
1222				                       parseInt(crt_end_date.substring(4, 6)));
1223
1224				crt_end_date = mydate.getFullYear() + "-" + mydate.getMonth() + "-" + mydate.getDate();
1225
1226				//alert(crt_end_date.substring(0, 2)+", "+crt_end_date.substring(2, 4) + ", " + crt_end_date.substring(4, 6));
1227				//alert(mydate.toISOString().slice(0, 10).replace(/-/g, '-'));
1228				//alert(mydate.getFullYear() + " - " + mydate.getMonth() + " - " + mydate.getDate());
1229			}
1230
1231			if(issuer==subject){
1232				$("#label_self_crt_type").text(m.getString("title_self_crt_type"));
1233			}
1234			else{
1235				$("#label_self_crt_type").text(m.getString("title_third_crt_type"));
1236			}
1237
1238			$("#label_https_crt_cn").text(subject);
1239			$("#label_https_crt_issuer").text(issuer);
1240			$("#label_https_crt_end_date").text(crt_end_date);
1241			//alert(content + ", " + statusstring);
1242
1243			if(issuer==""){
1244				$("#btn_export_crt").attr("disabled", true);
1245			}
1246			else{
1247				$("#btn_export_crt").attr("disabled", false);
1248			}
1249		}
1250
1251		client = null;
1252	});
1253}
1254
1255function doOK(e) {
1256	parent.closeJqmWindow();
1257};
1258
1259function doCancel(e) {
1260	parent.closeJqmWindow();
1261};
1262
1263function onCloseShareLink(){
1264	$("#filelink").css("display","none");
1265}
1266
1267function onCloseImportCrt(){
1268	$('#import_crt').hide();
1269}
1270
1271function read_file(the_file, onReadCompleteHandler){
1272	if(the_file==null)
1273		return;
1274
1275	var start = 0;
1276	var stop = the_file.size-1;
1277	var bSliceAsBinary = 0;
1278	var reader = new FileReader();
1279	reader.onloadend = function(evt) {
1280		if (evt.target.readyState == FileReader.DONE) { // DONE == 2
1281			if(onReadCompleteHandler)
1282				onReadCompleteHandler(evt, bSliceAsBinary);
1283		}
1284	};
1285
1286	if (the_file.webkitSlice) {
1287		var blob = the_file.webkitSlice(start, stop+1);
1288		//reader.readAsArrayBuffer(blob);
1289		reader.readAsText(blob);
1290		bSliceAsBinary = 1;
1291	}
1292	else if (the_file.mozSlice) {
1293		var blob = the_file.mozSlice(start, stop+1);
1294		reader.readAsBinaryString(blob);
1295		bSliceAsBinary = 0;
1296	}
1297	else {
1298		var blob = the_file.slice(start, stop+1);
1299		//reader.readAsArrayBuffer(blob);
1300		reader.readAsText(blob);
1301		bSliceAsBinary = 1;
1302    }
1303}
1304
1305function onDoImportCrt(){
1306
1307	if(g_key_file==null){
1308		alert("Please select a key file.");
1309		return;
1310	}
1311
1312	if(g_crt_file==null){
1313		alert("Please select a crt file.");
1314		return;
1315	}
1316
1317	var key_pem = "";
1318	var crt_pem = "";
1319	var intermediate_crt_pem = "";
1320	var set_pem_content = function(){
1321
1322		if(g_key_file!=null && key_pem=="")
1323			return;
1324
1325		if(g_crt_file!=null && crt_pem=="")
1326			return;
1327
1328		if(g_intermediate_crt_file!=null && intermediate_crt_pem=="")
1329			return;
1330
1331		var client = new davlib.DavClient();
1332		client.initialize();
1333
1334		client.SETROOTCERTIFICATE( '/', key_pem, crt_pem, intermediate_crt_pem, function(context, status, statusstring){
1335			if(context=="200"){
1336				$('#import_crt').hide();
1337
1338				alert(m.getString("msg_import_crt_complete"));
1339
1340				client.APPLYAPP("/", "apply", "", "restart_webdav", function(error, statusstring, content){
1341					if(error==200){
1342						setTimeout( function(){
1343							parent.location.reload(false);
1344						}, 6000 );
1345					}
1346
1347					client = null;
1348				});
1349			}
1350			else{
1351				alert("Fail to import certificate file! Maybe the imported file is invalid, please check and try again.");
1352			}
1353		}, null );
1354	}
1355
1356	read_file(g_key_file, function(evt, bSliceAsBinary){
1357		//alert("done: " + evt.target.result.byteLength + ", " + bSliceAsBinary + ", " + evt.target.result);
1358		var content = evt.target.result;
1359		/*
1360		if(content.indexOf("-----BEGIN RSA PRIVATE KEY-----")!=0){
1361			alert("Invalid key file format!");
1362			return;
1363		}
1364		*/
1365		key_pem = content;
1366
1367		set_pem_content();
1368	});
1369
1370	read_file(g_crt_file, function(evt, bSliceAsBinary){
1371		var content = evt.target.result;
1372		/*
1373		if(content.indexOf("-----BEGIN CERTIFICATE-----")!=0){
1374			alert("Invalid cert file format!");
1375			return;
1376		}
1377		*/
1378		crt_pem = content;
1379
1380		set_pem_content();
1381	});
1382
1383	read_file(g_intermediate_crt_file, function(evt, bSliceAsBinary){
1384		var content = evt.target.result;
1385		/*
1386		if(content.indexOf("-----BEGIN CERTIFICATE-----")!=0){
1387			alert("Invalid intermediate cert file format!");
1388			return;
1389		}
1390		*/
1391		intermediate_crt_pem = content;
1392
1393		set_pem_content();
1394	});
1395}
1396
1397// Detect if the browser is IE or not.
1398// If it is not IE, we assume that the browser is NS.
1399var IE = document.all?true:false
1400
1401// If NS -- that is, !IE -- then set up for mouse capture
1402if (!IE) document.captureEvents(Event.MOUSEMOVE)
1403
1404// Set-up to use getMouseXY function onMouseMove
1405document.onmousemove = getMouseXY;
1406
1407// Temporary variables to hold mouse x-y pos.s
1408var tempX = 0
1409var tempY = 0
1410
1411// Main function to retrieve mouse x-y pos.s
1412
1413function getMouseXY(e) {
1414	if (IE) { // grab the x-y pos.s if browser is IE
1415    	tempX = event.clientX + document.body.scrollLeft
1416    	tempY = event.clientY + document.body.scrollTop
1417  	} else {  // grab the x-y pos.s if browser is NS
1418    	tempX = e.pageX
1419    	tempY = e.pageY
1420  	}
1421  	// catch possible negative values in NS4
1422  	if (tempX < 0){tempX = 0}
1423  	if (tempY < 0){tempY = 0}
1424  	return true
1425}