• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/router/lighttpd-1.4.39/external_file/js_src/
1var g_support_html5 = 0;
2var g_reload_page = 1;
3var m = new lang();
4var g_storage = new myStorage();
5var g_modal_url;
6var g_modal_window_width = 200;
7var g_modal_window_height = 80;
8var timer_idle;
9var g_show_modal = 0;
10var g_time_out = 900000; //- 15min
11var g_time_count = 0;
12var g_select_mode = 0;
13var g_select_array = null;
14var g_select_folder_count = 0;
15var g_select_file_count = 0;
16var g_upload_mode = 0;
17var g_folder_array = null;
18var g_file_array = null;
19var g_opening_uid = '';
20var g_on_rescan_samba = 0;
21//var g_aidisk_name = "usbdisk";
22var g_support_lan = new Array('en-us', 'zh-tw', 'zh-cn', 'cz', 'pl', 'ru', 'de', 'fr', 'tr', 'th', 'ms', 'no', 'fi', 'da', 'sv', 'br', 'jp', 'es', 'it', 'uk');
23var g_current_locktoken = "";
24var g_mouse_x = 0;
25var g_mouse_y = 0;
26var g_fileview_only = 0;
27
28var g_webdav_client = new davlib.DavClient();
29g_webdav_client.initialize();
30
31// Check for the various File API support.
32if (window.File && window.FileReader && window.FileList && window.Blob) {
33	// Great success! All the File APIs are supported.
34  	g_support_html5 = 1;
35} else {
36	g_support_html5 = 0;
37}
38
39function isListView(){
40	return (g_storage.getl('listview') == undefined) ? 1 : g_storage.getl('listview');
41}
42
43function isAiModeView(){
44	return (g_storage.get('aimode') == undefined) ? -1 : g_storage.get('aimode');
45}
46
47function getAiMode(){
48	return (g_storage.get('aimode') == undefined) ? -1 : g_storage.get('aimode');
49}
50
51function openLoginWindow(open_url){
52	var $modalWindow = $("div#modalWindow");
53	var css_display = $modalWindow.css("display");
54	var dologin = function(){
55		var user = $('#table_login input#username').val();
56		var pass = $('#table_login input#password').val();
57		var auth = "Basic " + Base64.encode(user + ":" + pass);
58		closeJqmWindow(0);
59		doLOGIN(open_url, auth);
60	};
61	//g_modal_url = '/smb/css/login.html?v='+open_url;
62	g_modal_url = '';
63	g_modal_window_width = 380;
64	g_modal_window_height = 120;
65
66	if(open_url=='/')
67		$('#jqmTitleText').text(m.getString('title_login') + " - AiCloud");
68	else{
69		var url = mydecodeURI(open_url);
70		$('#jqmTitleText').text(m.getString('title_login') + " - " + url.substring(0, 35));
71	}
72
73	if(css_display == "block"){
74		//- Show username password error!
75		$('#jqmMsgText').text(m.getString('msg_passerror'));
76	}
77
78	$('#jqmMsg').css("display", css_display);
79
80	var login_html = '';
81	login_html += '<table id="table_login" width="100%" height="100%" border="0" align="center" cellpadding="0" cellspacing="0" style="overflow:hidden;table-layout: fixed;">';
82	login_html += '<tr>';
83	login_html += '<td>';
84  	//login_html += '<form id="form_login">';
85	login_html += '<div id="main">';
86	login_html += '<table>';
87	login_html += '<tr>';
88	login_html += '<td><label id="username">' + m.getString('title_username') + ':</label></td><td><input name="username" class="dialog_text_input" type="text" id="username" autocapitalize="off" maxlength="20" style="width:290px"></td>';
89	login_html += '</tr>';
90	login_html += '<tr>';
91	login_html += '<td><label id="password">' + m.getString('title_password') + ':</label></td><td><input name="password" class="dialog_text_input" type="password" id="password" maxlength="16" style="width:290px"></td>';
92	login_html += '</tr>';
93	login_html += '</table>';
94	login_html += '</div>';
95	//login_html += '</form>';
96  	login_html += '</td>';
97 	login_html += '</tr>';
98  	login_html += '<tr style="height:10px"></tr>';
99  	login_html += '<tr>';
100  	login_html += '<td>';
101  	login_html += '<div class="table_block_footer" style="text-align:right">';
102  	login_html += '<button id="ok" class="btnStyle">' + m.getString('btn_ok') + '</button>';
103  	login_html += '<button id="cancel" class="btnStyle">' + m.getString('btn_cancel') + '</button>';
104  	login_html += '</div>';
105  	login_html += '</td>';
106  	login_html += '</tr>';
107	login_html += '</table>';
108
109	$('#jqmContent').empty();
110	$(login_html).appendTo($('#jqmContent'));
111
112	$('#table_login input#password').keydown(function(e){
113		if(e.keyCode==13){
114			dologin();
115		}
116	});
117
118	$("#table_login #ok").click(function(){
119		dologin();
120	});
121
122	$("#table_login #cancel").click(function(){
123		closeJqmWindow(0);
124	});
125
126	if($modalWindow){
127		$modalWindow.jqmShow();
128	}
129}
130
131function doRescanSamba(){
132	var openurl = addPathSlash(g_storage.get('openurl'));
133
134	closeJqmWindow(0);
135	showHideLoadStatus(true);
136
137	g_webdav_client.RESCANSMBPC(openurl, function(error){
138		if(error[0]==2){
139			var rescan_samba_timer = g_storage.getl("rescan_samba_timer");
140			if(rescan_samba_timer!=0) clearInterval(rescan_samba_timer);
141
142			g_storage.setl("onRescanSamba", 1);
143			g_storage.setl("onRescanSambaCount", 0);
144			g_storage.setl("rescan_samba_timer", 0);
145			g_storage.set("HostList", "");
146			doPROPFIND("/");
147		}
148	});
149}
150
151function doMKDIR(name){
152	var openurl = addPathSlash(g_storage.get('openurl'));
153	var this_url = openurl + myencodeURI(name);
154
155	var already_exists = 0;
156
157	$('.wcb').each(function(index) {
158		if($(this).attr("isdir")=="1"){
159			if(name==$(this).attr("data-name")){
160				already_exists = 1;
161				alert(m.getString('folder_already_exist_msg'));
162				return;
163			}
164
165		}
166	});
167
168	if(already_exists==1)
169		return;
170
171	g_webdav_client.MKCOL(this_url, function(error){
172		if(error[0]==2){
173			doPROPFIND(openurl);
174			closeJqmWindow(0);
175		}
176		else
177			alert(m.getString(error));
178	});
179}
180
181function doRENAME(old_name, new_name, callbackHandler){
182
183	var already_exists = 0;
184	var openurl = addPathSlash(g_storage.get('openurl'));
185	var this_url = openurl + new_name;
186
187	$('.wcb').each(function(index) {
188
189		if(new_name==myencodeURI($(this).attr("data-name"))){
190			already_exists = 1;
191
192			if($(this).attr("isdir")=="1")
193				alert(m.getString('folder_already_exist_msg'));
194			else
195				alert(m.getString('file_already_exist_msg'));
196
197			return;
198		}
199	});
200
201	if(already_exists==1){
202		if(callbackHandler)
203			callbackHandler();
204
205		return;
206	}
207
208	//alert(old_name + '-> ' + this_url);
209
210	g_webdav_client.LOCK(old_name, '', function(status, statusstring, content, headers){
211
212		if (status != '201') {
213     		alert(m.getString("msg_already_lock"));
214
215     		if(callbackHandler)
216				callbackHandler();
217
218			return;
219		}
220
221    	var locktoken = getLockToken(content);
222    	//alert(locktoken);
223		g_webdav_client.MOVE(old_name, this_url, function(error){
224			if(error[0]==2){
225				doPROPFIND(openurl);
226				closeJqmWindow(0);
227			}
228			else{
229				alert(m.getString(error));
230
231				if(callbackHandler)
232					callbackHandler();
233			}
234
235			g_webdav_client.UNLOCK(old_name, locktoken, function(error){
236				if(error!=204)
237					alert("Unlock error: " + error);
238
239				if(callbackHandler)
240					callbackHandler();
241			});
242
243		}, null, false, locktoken);
244
245	}, null);
246
247	/*
248	g_webdav_client.MOVE(old_name, this_url, function(error){
249		if(error[0]==2){
250			doPROPFIND(openurl);
251			closeJqmWindow(0);
252		}
253		else
254			alert(m.getString(error) + " : " + decodeURI(old_name));
255	}, null, false);
256	*/
257}
258
259function doCOPYMOVE(action, source, dest, overwrite, callbackHandler){
260
261	g_webdav_client.LOCK(source, '', function(status, statusstring, content, headers){
262
263		if (status != '201') {
264     		alert(m.getString("msg_already_lock"));
265
266     		if(callbackHandler)
267				callbackHandler(status);
268
269			return;
270		}
271
272    	var locktoken = getLockToken(content);
273
274    	if(action=="copy"){
275			g_webdav_client.COPY(source, dest, function(code){
276
277				g_webdav_client.UNLOCK(source, locktoken, function(error){
278					if(error!=204)
279						alert("Unlock error: " + error);
280				});
281
282				if(callbackHandler)
283					callbackHandler(code);
284
285			}, null, (overwrite==true) ? "T" : "F", locktoken);
286		}
287		else if(action=="move"){
288			g_webdav_client.MOVE(source, dest, function(code){
289
290				g_webdav_client.UNLOCK(source, locktoken, function(error){
291					if(error!=204)
292						alert("Unlock error: " + error);
293				});
294
295				if(callbackHandler)
296					callbackHandler(code);
297
298			}, null, (overwrite==true) ? "T" : "F", locktoken);
299		}
300		else{
301			alert("Invalid action specified!");
302		}
303
304	}, null);
305}
306
307function getFileViewHeight(){
308	return $("#fileview").height()-20;
309}
310
311function closeJqmWindow(v){
312	g_reload_page=v;
313	var $modalWindow = $('div#modalWindow');
314
315	var $modalContainer = $('iframe', $modalWindow);
316	$modalContainer.attr('src', '');
317
318	if($modalWindow)
319		$modalWindow.jqmHide();
320
321	showHideLoadStatus(false);
322}
323
324function resizeJqmWindow(w,h){
325	var $modalWindow = $('.jqmWindow');
326	if($modalWindow){
327		$modalWindow.css("width", w + "px");
328		$modalWindow.css("height", h + "px");
329	}
330}
331
332function fullscreenJqmWindow(v){
333	var $modalWindow = $('div#modalWindow');
334	if($modalWindow){
335		$modalWindow.css("left", "0px");
336		$modalWindow.css("top", "0px");
337		$modalWindow.css("width", window.width + "px");
338		$modalWindow.css("height", window.height + "px");
339	}
340}
341
342function doLOGOUT(){
343	doPROPFIND("/", function(){
344
345		var openurl = addPathSlash(g_storage.get('openurl'));
346		g_webdav_client.LOGOUT("/", function(error){
347			if(error[0]==2){
348				g_storage.set('openhostuid', '0');
349				g_storage.set('asus_token', '');
350				$.cookie('asus_token', '');
351				window.location.reload();
352			}
353		});
354	}, 0);
355}
356
357function resetTimer(){
358
359	clearInterval(timer_idle);
360
361	g_time_count = 0;
362
363	timer_idle = setInterval( function(){
364
365		if(g_storage.get('stopLogoutTimer')=="1"||g_show_modal==1){
366			g_time_count = 0;
367			return;
368		}
369
370		g_time_count++;
371		//$("#function_help").text('resetTimer...'+g_time_count+" sec, stopLogoutTimer="+g_storage.get('stopLogoutTimer')+", g_show_modal="+g_show_modal);
372
373		if( (g_time_count*1000) > g_time_out){
374			g_time_count=0;
375			doLOGOUT();
376		}
377	}, 1000 );
378}
379
380function doPROPFINDMEDIALIST(open_url, append_result, complete_handler, media_type, start, end, keyword, orderby, orderrule, parentid){
381	if(g_webdav_client==null)
382		return;
383
384	showHideLoadStatus(true);
385	showHideEditUIRegion(false);
386
387	try{
388		g_webdav_client.PROPFINDMEDIALIST(open_url, function(error, statusstring, content){
389			if(error){
390				if(error==207){
391
392					showHideSelectModeUI(false);
393					closeUploadPanel();
394
395					var xmlDoc = content2XMLDOM(content);
396					var this_query_type = 1; //- 2: query host, 1: query share, 0: query file
397					var this_query_count = 0;
398					var this_query_start = 0;
399					var this_query_end = 0;
400					var this_scan_status = "Idle";
401
402					if(!append_result){
403						g_folder_array = null;
404						g_folder_array = new Array();
405
406						g_file_array = null;
407						g_file_array = new Array();
408					}
409
410					if(xmlDoc){
411						this_query_type = 1; //- 2: query host, 1: query share, 0: query file
412						this_query_count = parseInt(xmlDoc.documentElement.getAttribute('qcount'));
413						this_query_start = parseInt(xmlDoc.documentElement.getAttribute('qstart'));
414						this_query_end = parseInt(xmlDoc.documentElement.getAttribute('qend'));
415						this_scan_status = xmlDoc.documentElement.getAttribute('scan_status');
416						parserPropfindXML(xmlDoc, open_url, append_result);
417					}
418
419					var parent_url = "";
420					if(g_ui_mode.get()==1 || g_ui_mode.get()==2 || g_ui_mode.get()==3){
421						this_query_type = 0;
422					}
423					else if(g_ui_mode.get()==6){
424						this_query_type = 0;
425						parent_url = "goto:music_album";
426					}
427					else if(g_ui_mode.get()==7){
428						this_query_type = 0;
429						parent_url = "goto:music_artist";
430					}
431
432					var list_type = (g_list_view.get()==1) ? "listview" : "thumbview";
433					create_ui_view( list_type, $("#main_right_container #fileview"),
434						            this_query_type, parent_url, g_folder_array, g_file_array, onMouseDownListDIVHandler );
435
436					if( this_query_count > this_query_end ){
437						var next_start = this_query_end + 1;
438						var next_end = next_start + 50;
439						if( next_end > this_query_count )
440							next_end = this_query_count;
441
442						var next_page_html = "<div class='nextDiv' start='" + next_start + "' end='" + next_end + "'><span>";
443						var a = m.getString("title_next_query");
444						a = a.replace("%s", next_start + "-" + next_end);
445						a = a.replace("%s", this_query_count);
446						next_page_html += a;
447						next_page_html += "</span></div>";
448						$("#main_right_container #fileview").append(next_page_html);
449
450						$(".nextDiv").click(function(){
451							doPROPFINDMEDIALIST(open_url, true, null, media_type, $(this).attr("start"), $(this).attr("end"), keyword, orderby, orderrule);
452						});
453					}
454
455					if(this_scan_status=="Scanning"){
456						$("#main_right_container #hintbar").text(m.getString("msg_dms_scanning"));
457						$("#main_right_container #hintbar").show();
458					}
459					else
460						$("#main_right_container #hintbar").hide();
461
462					//- aimode:
463					//- -1: none
464					//- 1: Ai Photo
465					//- 2: Ai Music
466					//- 3: Ai Movie
467					g_storage.set('aimode', media_type);
468
469					$("div#btnUpload").css("display", "none");
470					$("div#btnNewDir").css("display", "none");
471					$("div#btnPlayImage").css("display", (media_type==1) ? "block" : "none");
472					$("div#boxSearch").css("display", "block");
473
474					g_storage.set('openurl', open_url);
475
476					$("div#hostview").scrollTop(g_storage.get('hostviewscrollTop'));
477
478					$('div#fileview').scrollLeft(g_storage.get('contentscrollLeft'));
479					$('div#fileview').scrollTop(g_storage.get('contentscrollTop'));
480
481					$("div#boxSearch").attr("uhref", open_url);
482					$("div#boxSearch").attr("qtype", media_type);
483
484					adjustLayout();
485
486					closeJqmWindow(0);
487
488					if(complete_handler!=undefined){
489						complete_handler();
490					}
491				}
492		  		else if(error==501){
493					doPROPFINDMEDIALIST(open_url);
494				}
495				else if(error==503){
496					show_hint_no_mediaserver();
497				}
498		  		else if(error==401){
499		  			setTimeout( function(){
500						openLoginWindow(open_url)
501					}, 2000);
502				}
503				else{
504					alert(m.getString(error));
505				}
506
507				showHideLoadStatus(false);
508			}
509		}, null, media_type, start, end, keyword, orderby, orderrule, parentid );
510
511		resetTimer();
512	}
513	catch(err){
514		//Handle errors here
515	  alert('catch error: '+ err);
516	}
517
518}
519
520function parserPropfindXML(xmlDoc, open_url, append_result){
521	if(!xmlDoc)
522		return;
523
524	if(append_result==false){
525		g_folder_array = null;
526		g_file_array = null;
527	}
528
529	if(g_folder_array==null) g_folder_array = new Array();
530	if(g_file_array==null) g_file_array = new Array();
531
532	var i, j, k, l, n;
533	var x = xmlDoc.documentElement.childNodes;
534
535	//- D:Response
536	for (i=0;i<x.length;i++){
537		var this_href = "";
538		var this_contenttype = "";
539		var this_uniqueid = "";
540		var this_name = "";
541		var this_short_name = "";
542		var this_online = "";
543		var this_lastmodified = "";
544		var this_contentlength = "";
545		var this_ip = "";
546		var this_mac = "";
547		var this_type = "";
548		var this_attr_readonly = "";
549		var this_attr_hidden = "";
550		var this_uncode_name;
551		var this_user_agent = "";
552		var this_router_sync_folder = "0";
553		var this_matadata_title = "";
554		var this_thumb = "0";
555		var this_thumb_image = "";
556
557		var y = x[i].childNodes;
558		for (j=0;j<y.length;j++){
559			if(y[j].nodeType==1&&y[j].nodeName=="D:propstat"){
560
561				var z = y[j].childNodes;
562
563				for (k=0;k<z.length;k++)
564				{
565					if(z[k].nodeName=="D:prop"){
566
567						var a = z[k].childNodes;
568
569						for (l=0;l<a.length;l++)
570						{
571							if(a[l].childNodes.length<=0)
572								continue;
573
574							if(a[l].nodeName=="D:getcontenttype"){
575								this_contenttype = String(a[l].childNodes[0].nodeValue);
576							}
577							else if(a[l].nodeName=="D:getuniqueid"){
578								this_uniqueid = String(a[l].childNodes[0].nodeValue);
579							}
580							else if(a[l].nodeName=="D:getonline"){
581								this_online = String(a[l].childNodes[0].nodeValue);
582							}
583							else if(a[l].nodeName=="D:getlastmodified"){
584								this_lastmodified = String(a[l].childNodes[0].nodeValue);
585							}
586							else if(a[l].nodeName=="D:getcontentlength"){
587								this_contentlength = String( size_format(parseInt(a[l].childNodes[0].nodeValue)));
588							}
589							else if(a[l].nodeName=="D:getmac"){
590								this_mac = String(a[l].childNodes[0].nodeValue);
591							}
592							else if(a[l].nodeName=="D:getip"){
593								this_ip = String(a[l].childNodes[0].nodeValue);
594							}
595							else if(a[l].nodeName=="D:gettype"){
596								this_type = String(a[l].childNodes[0].nodeValue);
597							}
598							else if(a[l].nodeName=="D:getattr"){
599								var bb = a[l].childNodes;
600								for (n=0;n<bb.length;n++){
601									if(bb[n].nodeName=="D:readonly")
602										this_attr_readonly = bb[n].childNodes[0].nodeValue;
603									else if(bb[n].nodeName=="D:hidden")
604										this_attr_hidden = bb[n].childNodes[0].nodeValue;
605								}
606							}
607							else if(a[l].nodeName=="D:getuseragent"){
608								this_user_agent = String(a[l].childNodes[0].nodeValue);
609								g_storage.set('user_agent', this_user_agent);
610							}
611							else if(a[l].nodeName=="D:getroutersync"){
612								this_router_sync_folder = String(a[l].childNodes[0].nodeValue);
613							}
614							else if(a[l].nodeName=="D:getmetadata"){
615								var bb = a[l].childNodes;
616								for (n=0;n<bb.length;n++){
617									if(bb[n].nodeName=="D:title")
618										this_matadata_title = bb[n].childNodes[0].nodeValue;
619									else if(bb[n].nodeName=="D:thumb")
620										this_thumb = bb[n].childNodes[0].nodeValue;
621									else if(bb[n].nodeName=="D:thumb_image")
622										this_thumb_image = bb[n].childNodes[0].nodeValue;
623								}
624							}
625						}
626					}
627				}
628			}
629			else if(y[j].nodeType==1&&y[j].nodeName=="D:href"){
630				this_href = String(y[j].childNodes[0].nodeValue);
631
632				var cur_host = "";
633
634				if(this_href.match(/^http/))
635					cur_host = window.location.protocol + "//" + window.location.host;
636
637				var cururl = cur_host + addPathSlash(open_url);
638
639				if(this_href!=cururl){
640					var o_url = open_url;
641
642					this_href = this_href.replace(cur_host,"");
643
644					//this_name = this_href.replace( addPathSlash(o_url),"");
645					this_name = this_href.substring( this_href.lastIndexOf("/")+1, this_href.length );
646
647					if(this_name!=""){
648						this_uncode_name = this_name;
649
650						this_name = mydecodeURI(this_name);
651						this_short_name = this_name;
652						/*
653						var len = (g_list_view.get()==0) ? 12 : 45;
654
655						if(this_short_name.length>len){
656							this_short_name = this_short_name.substring(0, len) + "...";
657						}
658						*/
659					}
660					else{
661						this_href="";
662					}
663				}
664				else{
665					this_href="";
666				}
667			}
668		}
669
670		if(this_href!=""){
671			if( this_contenttype=="httpd/unix-directory" ){
672				g_folder_array.push({ contenttype: this_contenttype,
673					                  href: this_href,
674					                  name: this_name,
675					                  uname: this_uncode_name,
676					                  shortname: this_short_name,
677					                  online: this_online,
678					                  time: this_lastmodified,
679					                  size: this_contentlength,
680					                  ip: this_ip,
681					                  mac: this_mac,
682					                  uid: this_uniqueid,
683					                  type: this_type,
684					                  freadonly: this_attr_readonly,
685					                  fhidden: this_attr_hidden,
686					                  routersyncfolder: this_router_sync_folder,
687									  matadatatitle: this_matadata_title,
688									  thumb: this_thumb });
689			}
690			else{
691				g_file_array.push({ contenttype: this_contenttype,
692					                href: this_href,
693					                name: this_name,
694					                uname: this_uncode_name,
695					                shortname: this_short_name,
696					                online: this_online,
697					                time: this_lastmodified,
698					                size: this_contentlength,
699					                ip: this_ip,
700					                mac: this_mac,
701					                uid: this_uniqueid,
702					                type: this_type,
703					                freadonly: this_attr_readonly,
704					                fhidden: this_attr_hidden,
705					                routersyncfolder: this_router_sync_folder,
706									matadatatitle: this_matadata_title,
707									thumb: this_thumb });
708			}
709		}
710	}
711}
712
713function content2XMLDOM(content){
714
715	if(content=="")
716		return null;
717
718	var parser = null;
719	var xmlDoc = null;
720
721	if (window.DOMParser){
722		parser=new DOMParser();
723		xmlDoc=parser.parseFromString(content,"text/xml");
724	}
725	else { // Internet Explorer
726		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
727    	xmlDoc.async="false";
728		xmlDoc.loadXML(content);
729
730		if(!xmlDoc.documentElement){
731			alert("Fail to load xml!");
732			showHideLoadStatus(false);
733			return null;
734		}
735	}
736
737	return xmlDoc;
738}
739
740function doPROPFIND(open_url, complete_handler, auth){
741	if(g_webdav_client==null)
742		return;
743
744	showHideLoadStatus(true);
745
746	try{
747		g_webdav_client.PROPFIND(open_url, auth, function(error, statusstring, content){
748			if(error){
749
750				if(error==207){
751
752					showHideSelectModeUI(false);
753					closeUploadPanel();
754
755					var xmlDoc = content2XMLDOM(content);
756
757					if(xmlDoc){
758
759						var this_query_type = xmlDoc.documentElement.getAttribute('qtype'); //- 2: query host, 1: query share, 0: query file
760						var this_folder_readonly = xmlDoc.documentElement.getAttribute('readonly');
761						var this_router_username = xmlDoc.documentElement.getAttribute('ruser');
762						var this_computer_name = xmlDoc.documentElement.getAttribute('computername');
763						var this_isusb = xmlDoc.documentElement.getAttribute('isusb');
764
765						parserPropfindXML(xmlDoc, open_url, false);
766
767						//- Sort By Name
768						g_folder_array.sort(sortByName);
769						g_file_array.sort(sortByName);
770
771						//- Move the usbdisk to first
772						var index;
773						for(index=0; index<g_folder_array.length; index++){
774							if(g_folder_array[index].type == "usbdisk"){
775								arraymove(g_folder_array, index, 0);
776								//break;
777							}
778						}
779
780						//- parent url
781						var parent_url = addPathSlash(open_url);
782						if(parent_url!="/"){
783							parent_url = parent_url.substring(0, parent_url.length-1);
784							parent_url = parent_url.substring(0, parent_url.lastIndexOf("/"));
785							if( parent_url=="" ) parent_url="/";
786						}
787
788						//- Create host list
789						if(open_url=="/")
790							createHostList(this_query_type, g_folder_array);
791
792						var list_type = (g_list_view.get()==1) ? "listview" : "thumbview";
793						create_ui_view( list_type, $("#main_right_container #fileview"),
794						            	this_query_type, parent_url, g_folder_array, g_file_array, onMouseDownListDIVHandler );
795
796						g_thumb_loader.init($("#main_right_container #fileview"));
797						g_thumb_loader.start();
798
799						//- Refresh UI
800						showHideAiButton( (this_isusb=="1") ? true : false );
801						closeAiMode();
802
803						if(open_url=="/"){
804							$("div#btnThumbView").css("display", "none");
805							$("div#btnListView").css("display", "none");
806						}
807						else{
808							$("div#btnThumbView").css("display", (g_list_view.get()==1) ? "block" : "none");
809							$("div#btnListView").css("display", (g_list_view.get()==1) ? "none" : "block");
810						}
811
812						$("div#btnUpload").css("display", (this_query_type==0&&g_select_mode==0) ? "block" : "none");
813						$("div#btnNewDir").css("display", (this_query_type==0&&g_select_mode==0) ? "block" : "none");
814						$("div#btnPlayImage").css("display", (this_query_type==0&&g_select_mode==0) ? "block" : "none");
815						$("#btnCancelUpload").css("display", (g_upload_mode==1) ? "block" : "none");
816						$("#btnChangeUser").css("display", (this_query_type==1&&this_isusb==0) ? "block" : "none");
817
818						if(open_url=="/"){
819							$("span#username").text(this_router_username);
820							getaccountinfo(this_router_username);
821						}
822
823						g_storage.set('isAidisk', this_isusb);
824						g_storage.set('openurl', open_url);
825
826						$("div#hostview").scrollTop(g_storage.get('hostviewscrollTop'));
827
828						$('div#fileview').scrollLeft(g_storage.get('contentscrollLeft'));
829						$('div#fileview').scrollTop(g_storage.get('contentscrollTop'));
830
831						$("#main_right_container #hintbar").hide();
832
833						adjustLayout();
834
835						closeJqmWindow(0);
836
837						//registerPage(open_url);
838
839						if(complete_handler!=undefined){
840							complete_handler();
841						}
842
843						if( g_storage.get('openhostuid')==undefined||
844							g_storage.get('openhostuid')==0){
845
846							var help_html = "<div id='help_1'>";
847							help_html += "<div id='help_content'>";
848							help_html += m.getString('msg_help');
849							help_html += "</div>";
850							help_html += "<div id='help_image'>";
851							help_html += "</div>";
852							help_html += "</div>";
853
854							$("div#fileview").append(help_html);
855						}
856					}
857		  		}
858		  		else if(error==501){
859					doPROPFIND(open_url);
860				}
861		  		else if(error==401){
862					setTimeout( function(){
863						openLoginWindow(open_url)
864					}, 2000);
865				}
866				else{
867					alert(m.getString(error));
868				}
869
870				showHideLoadStatus(false);
871			}
872		}, null, 1);
873
874		resetTimer();
875	}
876	catch(err){
877		//Handle errors here
878	  alert('catch error: '+ err);
879	}
880}
881
882function registerPage(open_url){
883
884	if( open_url != "/" || isPrivateIP( g_storage.get('wan_ip') ) )
885		return;
886
887	var ddns_name = g_storage.get('ddns_host_name');
888
889	if(ddns_name==""){
890		alert("start ddns process");
891		return;
892	}
893
894	var alcloud_url = "https://" + ddns_name;
895	window.location = "http://140.130.25.39/aicloud?v=" + alcloud_url;
896}
897
898function doLOGIN(path, auth){
899
900	doPROPFIND(path, function(){
901		if( g_opening_uid != '' ){
902			g_storage.set('openhostuid', g_opening_uid);
903			$("#hostview .host_item").each(function(){
904				if($(this).attr("uid") == g_opening_uid){
905					$(this).addClass("select");
906				}
907				else{
908					$(this).removeClass("select");
909				}
910			});
911			g_opening_uid='';
912		}
913	}, auth);
914}
915
916function refreshHostList(){
917	if(g_webdav_client==null)
918		return;
919
920	try{
921		g_webdav_client.PROPFIND('/', null, function(error, statusstring, content){
922			if(error){
923				if(error==207){
924
925					var parser;
926					var xmlDoc;
927
928					var folder_array = new Array();
929
930					if (window.DOMParser){
931						parser=new DOMParser();
932						xmlDoc=parser.parseFromString(content,"text/xml");
933					}
934					else { // Internet Explorer
935						xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
936            			xmlDoc.async="false";
937						xmlDoc.loadXML(content);
938
939						if(!xmlDoc.documentElement){
940							alert("Fail to load xml!");
941							showHideLoadStatus(false);
942							return;
943						}
944					}
945
946					var i, j, k, l, n;
947					var x = xmlDoc.documentElement.childNodes;
948
949					var this_query_type = xmlDoc.documentElement.getAttribute('qtype'); //- 2: query host, 1: query share, 0: query file
950					var this_folder_readonly = xmlDoc.documentElement.getAttribute('readonly');
951					var this_router_username = xmlDoc.documentElement.getAttribute('ruser');
952					var this_computer_name = xmlDoc.documentElement.getAttribute('computername');
953					var this_isusb = xmlDoc.documentElement.getAttribute('isusb');
954
955					//- D:Response
956					for (i=0;i<x.length;i++){
957						var this_href = "";
958						var this_contenttype = "";
959						var this_uniqueid = "";
960						var this_name = "";
961						var this_short_name = "";
962						var this_online = "";
963						var this_lastmodified = "";
964						var this_contentlength = "";
965						var this_ip = "";
966						var this_mac = "";
967						var this_type = "";
968						var this_attr_readonly = "";
969						var this_attr_hidden = "";
970						var this_uncode_name;
971
972						var y = x[i].childNodes;
973						for (j=0;j<y.length;j++){
974							if(y[j].nodeType==1&&y[j].nodeName=="D:propstat"){
975
976								var z = y[j].childNodes;
977
978								for (k=0;k<z.length;k++)
979								{
980									if(z[k].nodeName=="D:prop"){
981
982										var a = z[k].childNodes;
983
984										for (l=0;l<a.length;l++)
985										{
986											if(a[l].childNodes.length<=0)
987												continue;
988
989											if(a[l].nodeName=="D:getcontenttype"){
990												this_contenttype = String(a[l].childNodes[0].nodeValue);
991											}
992											else if(a[l].nodeName=="D:getuniqueid"){
993												this_uniqueid = String(a[l].childNodes[0].nodeValue);
994											}
995											else if(a[l].nodeName=="D:getonline"){
996												this_online = String(a[l].childNodes[0].nodeValue);
997											}
998											else if(a[l].nodeName=="D:getlastmodified"){
999												this_lastmodified = String(a[l].childNodes[0].nodeValue);
1000											}
1001											else if(a[l].nodeName=="D:getcontentlength"){
1002												this_contentlength = String( size_format(parseInt(a[l].childNodes[0].nodeValue)));
1003											}
1004											else if(a[l].nodeName=="D:getmac"){
1005												this_mac = String(a[l].childNodes[0].nodeValue);
1006											}
1007											else if(a[l].nodeName=="D:getip"){
1008												this_ip = String(a[l].childNodes[0].nodeValue);
1009											}
1010											else if(a[l].nodeName=="D:gettype"){
1011												this_type = String(a[l].childNodes[0].nodeValue);
1012											}
1013											else if(a[l].nodeName=="D:getattr"){
1014												var bb = a[l].childNodes;
1015												for (n=0;n<bb.length;n++){
1016													if(bb[n].nodeName=="D:readonly")
1017														this_attr_readonly = bb[n].childNodes[0].nodeValue;
1018													else if(bb[n].nodeName=="D:hidden")
1019														this_attr_hidden = bb[n].childNodes[0].nodeValue;
1020												}
1021											}
1022										}
1023									}
1024								}
1025							}
1026							else if(y[j].nodeType==1&&y[j].nodeName=="D:href"){
1027								this_href = String(y[j].childNodes[0].nodeValue);
1028								//alert(this_href);
1029								var cur_host = "";
1030
1031								if(this_href.match(/^http/))
1032									cur_host = window.location.protocol + "//" + window.location.host;
1033
1034								var open_url = "/";
1035								var cururl = cur_host + addPathSlash(open_url);
1036
1037								if(this_href!=cururl){
1038									var o_url = open_url;
1039
1040									this_href = this_href.replace(cur_host,"");
1041
1042									//this_name = this_href.replace( addPathSlash(o_url),"");
1043									this_name = this_href.substring( this_href.lastIndexOf("/")+1, this_href.length );
1044
1045									if(this_name!=""){
1046
1047										this_uncode_name = this_name;
1048
1049										this_name = mydecodeURI(this_name);
1050										this_short_name = this_name;
1051
1052										var len = (g_list_view.get()==0) ? 12 : 45;
1053
1054										if(this_short_name.length>len){
1055											this_short_name = this_short_name.substring(0, len) + "...";
1056										}
1057									}
1058									else{
1059										this_href="";
1060									}
1061								}
1062								else{
1063									this_href="";
1064								}
1065							}
1066						}
1067
1068						if(this_href!=""){
1069								if( this_contenttype=="httpd/unix-directory" ){
1070									folder_array.push({ contenttype: this_contenttype,
1071										                  href: this_href,
1072										                  name: this_name,
1073										                  uname: this_uncode_name,
1074										                  shortname: this_short_name,
1075										                  online: this_online,
1076										                  time: this_lastmodified,
1077										                  size: this_contentlength,
1078										                  ip: this_ip,
1079										                  mac: this_mac,
1080										                  uid: this_uniqueid,
1081										                  type: this_type,
1082										                  freadonly: this_attr_readonly,
1083										                  fhidden: this_attr_hidden });
1084								}
1085						}
1086					}
1087
1088					//- Sort By Name
1089					folder_array.sort(sortByName);
1090
1091					//- Move the usbdisk to first
1092					var index;
1093					for(index=0; index<folder_array.length; index++){
1094						if(folder_array[index].type == "usbdisk"){
1095							arraymove(folder_array, index, 0);
1096						}
1097					}
1098
1099					//- parent url
1100					//var parent_url = ="/";
1101
1102					//- Create host list
1103					createHostList(this_query_type, folder_array);
1104		  	}
1105			}
1106		}, null, 1);
1107	}
1108	catch(err){
1109		//Handle errors here
1110	  alert('catch error: '+ err);
1111	}
1112}
1113
1114function sortByName(a, b) {
1115	var x = a.name.toLowerCase();
1116  	var y = b.name.toLowerCase();
1117  	return ((x < y) ? -1 : ((x > y) ? 1 : 0));
1118}
1119
1120function arraymove(arr, fromIndex, toIndex) {
1121	var element = arr[fromIndex];
1122  	arr.splice(fromIndex,1);
1123	arr.splice(toIndex,0,element);
1124}
1125
1126function onMouseDownThumbDIVHandler(e, file_item){
1127	if( e.button == 2 ) {
1128		return false;
1129	}
1130
1131	if(g_select_mode==1){
1132
1133		if(file_item.attr("isParent")==1){
1134			showHideSelectModeUI(false);
1135			openSelItem(file_item);
1136			return;
1137		}
1138
1139		return;
1140	}
1141
1142	openSelItem(file_item);
1143}
1144
1145
1146function onMouseDownListDIVHandler(e, file_item){
1147	if( e.button == 2 ) {
1148		return false;
1149	}
1150
1151	if(g_select_mode==1){
1152		if(file_item.attr("isParent")==1){
1153			showHideSelectModeUI(false);
1154			openSelItem(file_item);
1155			return;
1156		}
1157
1158		return;
1159	}
1160
1161	openSelItem(file_item);
1162}
1163
1164function openSelItem(item){
1165
1166	var loc = (item.attr("uhref")==undefined) ? "" : item.attr("uhref");
1167	var qtype = (item.attr("qtype")==undefined) ? 0 : item.attr("qtype");
1168	var isdir = (item.attr("isdir")==undefined) ? 0 : item.attr("isdir");
1169	var isusb = (item.attr("isusb")==undefined) ? 0 : item.attr("isusb");
1170	var this_full_url = loc;
1171	var this_file_name = (item.attr("data-name")==undefined) ? "" : item.attr("data-name");
1172
1173	g_storage.set('opentype', isusb);
1174
1175	if(loc == "goto:music_album"){
1176
1177		if(g_webdav_client==null)
1178			return;
1179
1180		showHideLoadStatus(true);
1181
1182		loc = (g_storage.get('openurl')==undefined) ? "/" : g_storage.get('openurl');
1183
1184		g_webdav_client.GETMUSICCLASSIFICATION(loc, 'album', function(error, statusstring, content){
1185			if(error==200) createClassificationView(content, "album");
1186			else if(error==503) show_hint_no_mediaserver();
1187			showHideLoadStatus(false);
1188		});
1189
1190      	return;
1191	}
1192	else if(loc == "goto:music_artist"){
1193		if(g_webdav_client==null)
1194			return;
1195
1196		showHideLoadStatus(true);
1197
1198		loc = (g_storage.get('openurl')==undefined) ? "/" : g_storage.get('openurl');
1199
1200		g_webdav_client.GETMUSICCLASSIFICATION(loc, 'artist', function(error, statusstring, content){
1201			if(error==200) createClassificationView(content, "artist");
1202			else if(error==503) show_hint_no_mediaserver();
1203			showHideLoadStatus(false);
1204		});
1205
1206		return;
1207	}
1208
1209	if(qtype==2){
1210		var online = item.attr("online");
1211		if(online==0){
1212			var r=confirm(m.getString('wol_msg'));
1213
1214			if (r==true){
1215				var this_mac = item.attr("mac");
1216
1217				g_webdav_client.WOL("/", this_mac, function(error){
1218					if(error==200)
1219						alert(m.getString('wol_ok_msg'));
1220					else
1221						alert(m.getString('wol_fail_msg'));
1222				});
1223			}
1224
1225			return;
1226		}
1227	}
1228
1229	if(isdir=="1"){
1230		doPROPFIND(loc, null, null);
1231		return;
1232	}
1233
1234	var fileExt = getFileExt(loc);
1235
1236	var webdav_mode = g_storage.get('webdav_mode');
1237
1238	if( fileExt=="mp4" ||
1239		fileExt=="m4v" ||
1240		fileExt=="wmv" ||
1241		fileExt=="avi" ||
1242		fileExt=="rmvb"||
1243		fileExt=="rm" ||
1244		fileExt=="mpg" ||
1245		fileExt=="mpeg"||
1246		fileExt=="mkv" ||
1247		fileExt=="mov" ||
1248		fileExt=="flv" ) {
1249
1250		//- webdav_mode=0-->enable http, webdav_mode=2-->both enable http and https
1251		if( webdav_mode==0 || webdav_mode==2 ){
1252
1253			if( isWinOS() ){
1254				if( isIE() && getInternetExplorerVersion() <= 8 ){
1255					//- The VLC Plugin doesn't support IE 8 or less
1256					alert(m.getString('msg_vlcsupport'));
1257					return;
1258				}
1259				else{
1260					var $modalWindow = $("div#modalWindow");
1261
1262					this_file_name = myencodeURI(this_file_name);
1263					this_url = this_full_url.substring(0, this_full_url.lastIndexOf('/'));
1264
1265					var media_hostName = window.location.host;
1266					if(media_hostName.indexOf(":")!=-1){
1267						media_hostName = media_hostName.substring(0, media_hostName.indexOf(":"));
1268					}
1269					media_hostName = "http://" + media_hostName + ":" + g_storage.get("http_port") + "/";
1270
1271					g_webdav_client.OPENSTREAMINGPORT("/", 1, function(error, content, statusstring){
1272						if(error==200){
1273							var matadatatitle = item.attr("matadatatitle");
1274
1275							g_webdav_client.GSL(this_url, this_url, this_file_name, 0, 0, function(error, content, statusstring){
1276								if(error==200){
1277									var data = parseXml(statusstring);
1278									var srt_share_link = "";
1279									var share_link = $(data).find('sharelink').text();
1280									var open_url = "";
1281									open_url = '/smb/css/vlc_video.html?v=' + media_hostName + share_link + '&u=' + this_url;
1282									open_url += '&t=' + matadatatitle;
1283									open_url += '&showbutton=1';
1284
1285									g_modal_url = open_url;
1286									g_modal_window_width = 655;
1287									g_modal_window_height = 580;
1288									$('#jqmMsg').css("display", "none");
1289									$('#jqmTitleText').text(m.getString('title_videoplayer'));
1290									if($modalWindow){
1291										$modalWindow.jqmShow();
1292									}
1293								}
1294							});
1295						}
1296					});
1297
1298					/*
1299					var matadatatitle = item.attr("matadatatitle");
1300
1301					g_webdav_client.GSL(this_url, this_url, this_file_name, 0, 0, function(error, content, statusstring){
1302						if(error==200){
1303							var data = parseXml(statusstring);
1304							var srt_share_link = "";
1305							var share_link = $(data).find('sharelink').text();
1306							var open_url = "";
1307							open_url = '/smb/css/vlc_video.html?v=' + media_hostName + share_link + '&u=' + this_url;
1308							open_url += '&t=' + matadatatitle;
1309							open_url += '&showbutton=1';
1310
1311							g_modal_url = open_url;
1312							g_modal_window_width = 655;
1313							g_modal_window_height = 580;
1314							$('#jqmMsg').css("display", "none");
1315							$('#jqmTitleText').text(m.getString('title_videoplayer'));
1316							if($modalWindow){
1317								$modalWindow.jqmShow();
1318							}
1319						}
1320					});
1321					*/
1322
1323					return;
1324				}
1325			}
1326		}
1327
1328	}
1329
1330	if( fileExt=="mp3" ) {
1331		openAudioPlayer(loc);
1332		return;
1333	}
1334
1335	if( fileExt=="doc" || fileExt=="docx" ||
1336	    fileExt=="ppt" || fileExt=="pptx" ||
1337	    fileExt=="xls" || fileExt=="xlsx" ||
1338	    fileExt=="pdf") {
1339
1340		var location_host = window.location.host;
1341
1342		//- It will open with google doc viewer when OS is window or mac and using public ip.
1343		if( ( isWinOS() || isMacOS() ) && !isPrivateIP() ){
1344
1345		 	this_file_name = myencodeURI(this_file_name);
1346			this_url = this_full_url.substring(0, this_full_url.lastIndexOf('/'));
1347
1348			g_webdav_client.GSL(this_url, this_url, this_file_name, 0, 0, function(error, content, statusstring){
1349				if(error==200){
1350					var data = parseXml(statusstring);
1351					var share_link = $(data).find('sharelink').text();
1352					var open_url = "";
1353
1354					share_link = window.location.protocol + "//" + window.location.host+ "/" + share_link;
1355					open_url = 'https://docs.google.com/viewer?url=' + share_link;
1356
1357					window.open(open_url);
1358				}
1359			});
1360
1361			return;
1362		}
1363	}
1364
1365	if( fileExt=="jpg" ||
1366	    fileExt=="jpeg"||
1367	    fileExt=="png" ||
1368	    fileExt=="gif" ){
1369
1370		var page_size = getPageSize();
1371		g_image_player.show(loc, page_size[0], page_size[1], g_file_array);
1372
1373		return;
1374	}
1375
1376	window.open(loc);
1377}
1378
1379function addtoFavorite(){
1380	var favorite_title = "AiCloud";
1381	var ddns = g_storage.get('ddns_host_name');
1382	var favorite_url = "https://" + ddns;
1383	var isIEmac = false;
1384    var isMSIE = isIE();
1385
1386	if(ddns==""){
1387		favorite_url = window.location.href;
1388	}
1389
1390	if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) {
1391    	window.sidebar.addPanel(favorite_title, favorite_url, "");
1392      	return false;
1393    }
1394    else if (isMSIE && typeof window.external == "object") {
1395    	window.external.AddFavorite(favorite_url, favorite_title);
1396      	return false;
1397    }
1398    else {
1399    	window.location = favorite_url;
1400
1401    	var ua = navigator.userAgent.toLowerCase();
1402      	var str = '';
1403      	var isWebkit = (ua.indexOf('webkit') != - 1);
1404      	var isMac = (ua.indexOf('mac') != - 1);
1405
1406      	if (ua.indexOf('konqueror') != - 1) {
1407      		str = 'CTRL + B'; // Konqueror
1408      	}
1409      	else if (window.home || isWebkit || isIEmac || isMac) {
1410      		str = (isMac ? 'Command/Cmd' : 'CTRL') + ' + D'; // Netscape, Safari, iCab, IE5/Mac
1411      	}
1412
1413      	str = ((str) ? m.getString('msg_add_favorite1') + str + m.getString('msg_add_favorite2') : str);
1414
1415      	alert(str);
1416    }
1417}
1418
1419function getaccountinfo(username){
1420	var client = new davlib.DavClient();
1421	client.initialize();
1422
1423	client.GETACCOUNTINFO( '/', username, function(context, status, statusstring){
1424		if(context==200){
1425
1426			var data = parseXml(statusstring);
1427			var x = $(data);
1428
1429			var username = x.find("username").text();
1430			var type = x.find("type").text();
1431			var permission = x.find("permission").text();
1432			var name = x.find("name").text();
1433
1434			$("span#username").text(name);
1435			g_storage.set('userpermission', permission);
1436		}
1437		else{
1438			g_storage.set('userpermission', 'user');
1439		}
1440
1441		refreshAdminUI();
1442	}, null );
1443}
1444
1445// Detect if the browser is IE or not.
1446// If it is not IE, we assume that the browser is NS.
1447var IE = document.all?true:false
1448
1449// If NS -- that is, !IE -- then set up for mouse capture
1450if (!IE) document.captureEvents(Event.MOUSEMOVE)
1451
1452// Main function to retrieve mouse x-y pos.s
1453function getMouseXY(e) {
1454	if (IE) { // grab the x-y pos.s if browser is IE
1455    	g_mouse_x = event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
1456    	g_mouse_y = event.clientY + document.body.scrollTop + document.documentElement.scrollTop;
1457  	} else {  // grab the x-y pos.s if browser is NS
1458    	g_mouse_x = e.pageX;
1459    	g_mouse_y = e.pageY;
1460  	}
1461
1462  	if (g_mouse_x < 0){g_mouse_x = 0}
1463  	if (g_mouse_y < 0){g_mouse_y = 0}
1464  	return true
1465}
1466
1467$(document).ready(function(){
1468
1469	if( ( navigator.userAgent.match(/iPhone/i)) ||
1470	    ( navigator.userAgent.match(/iPod/i))   ||
1471		( navigator.userAgent.match(/Android/i)) && (navigator.userAgent.match(/Mobile/i)) ) {
1472		var option = window.location.href;
1473		option = option.substr(option.lastIndexOf("?")+1, option.length);
1474
1475		if(option.indexOf("desktop=1")!=0){
1476			var url = window.location.href;
1477			url = url.substr(0, url.lastIndexOf("?"));
1478			window.location = url + '?mobile=1';
1479			return;
1480		}
1481	}
1482
1483	document.oncontextmenu = function() {return false;};
1484	document.onmousedown = function(e) {
1485		resetTimer();
1486	};
1487	document.onmousemove = function(e) {
1488		getMouseXY(e);
1489		resetTimer();
1490	};
1491	$(document).keydown(function(e) {
1492		//- Esc
1493		if (e.keyCode == 27) {
1494
1495			if(g_select_mode==1)
1496				showHideSelectModeUI(false);
1497			else if(g_upload_mode==1){
1498				//if(confirmCancelUploadFile()==0)
1499				//	return;
1500
1501				closeUploadPanel();
1502			}
1503
1504			closeJqmWindow();
1505		}
1506
1507		if(g_image_player){
1508			g_image_player.keydown(e);
1509		}
1510	});
1511
1512	g_storage.set('stopLogoutTimer', '0');
1513  	g_storage.set('isOpenModalWindow', '0');
1514  	g_storage.set('isOnUploadFile', '0');
1515
1516  	createLayout();
1517
1518	showHideLoadStatus(false);
1519
1520	adjustLayout();
1521
1522	getRouterInfo();
1523
1524	if(g_fileview_only==0){
1525		//- Query host list first.
1526		var loc = g_storage.get('openurl');
1527
1528		g_storage.set("HostList", "");
1529
1530		doPROPFIND( "/", function(){
1531			if(loc!=undefined && loc!="/"){
1532				doPROPFIND(loc);
1533			}
1534
1535		}, 0);
1536	}
1537	else{
1538		//- Query host list first.
1539		var loc = g_storage.get('openurl');
1540		doPROPFIND(loc);
1541	}
1542
1543	initAudioPlayer();
1544	///////////////////////////////////////////////////////////////////////////////
1545
1546	function closeModal(hash){
1547		var $modalWindow = $(hash.w);
1548
1549		hash.o.remove();
1550
1551		$modalWindow.fadeOut('200', function(){
1552			g_show_modal = 0;
1553			if(g_reload_page==1){
1554				var openurl = addPathSlash(g_storage.get('openurl'));
1555				doPROPFIND(openurl);
1556			}
1557		});
1558	}
1559
1560	function openModal(hash){
1561		var $modalWindow = $(hash.w);
1562		var $modalContent = $('#jqmContent', $modalWindow);
1563		var $modalTitle = $('#jqmTitle', $modalWindow);
1564		var page_size = getPageSize();
1565		var page_width = page_size[0];
1566		var page_height = page_size[1];
1567		var newLeft = (page_width - g_modal_window_width)/2;
1568		var newTop = 0;
1569		g_show_modal = 1;
1570
1571		var sAgent = navigator.userAgent.toLowerCase();
1572   	 	var getInternetExplorerVersion = function(){
1573		   var rv = -1; // Return value assumes failure.
1574		   if (navigator.appName == 'Microsoft Internet Explorer')
1575		   {
1576		      var ua = navigator.userAgent;
1577		      var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
1578		      if (re.exec(ua) != null)
1579		         rv = parseFloat( RegExp.$1 );
1580		   }
1581		   return rv;
1582		};
1583
1584		if(g_modal_url!=""){
1585			$modalContent.empty();
1586
1587			var iframe_html = "<iframe src='' frameborder='0' width='100%' height='100%'>";
1588			$(iframe_html).appendTo($modalContent);
1589
1590			var $modalContainer = $('iframe', $modalWindow);
1591			$modalContainer.attr('src', g_modal_url);
1592		}
1593
1594		if(isBrowser("msie")&&getInternetExplorerVersion()<=8)
1595			g_modal_window_height+=25;
1596
1597		$modalWindow.css({
1598				width:g_modal_window_width,
1599				height:g_modal_window_height,
1600				left:newLeft,
1601				top:-g_modal_window_height,
1602				opacity:0,
1603				display:"block"
1604			}).jqmShow().animate({
1605				width:g_modal_window_width,
1606				height:g_modal_window_height,
1607				top:newTop,
1608				left:newLeft,
1609				marginLeft:0,
1610				opacity:1
1611			}, 200, function() {
1612	    		// Animation complete.
1613	    		adjustLayout();
1614	    		$(this).css("display","block");
1615	  	} );
1616
1617	}
1618
1619	$("#modalWindow").jqm({
1620		overlay:70,
1621		modal:true,
1622		target: '#jqmContent',
1623		onHide:closeModal,
1624		onShow:openModal
1625	});
1626
1627	function getWindowSize() {
1628	  	var myWidth = 0, myHeight = 0;
1629	  	if( typeof( window.innerWidth ) == 'number' ) {
1630	  		//Non-IE
1631	    	myWidth = window.innerWidth;
1632	    	myHeight = window.innerHeight;
1633	  	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
1634	    	//IE 6+ in 'standards compliant mode'
1635	    	myWidth = document.documentElement.clientWidth;
1636	    	myHeight = document.documentElement.clientHeight;
1637	  	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
1638	   	 	//IE 4 compatible
1639	    	myWidth = document.body.clientWidth;
1640	    	myHeight = document.body.clientHeight;
1641	  	}
1642
1643	  	return [ myWidth, myHeight ];
1644	}
1645
1646	function getScrollXY() {
1647	  	var scrOfX = 0, scrOfY = 0;
1648	  	if( typeof( window.pageYOffset ) == 'number' ) {
1649	    	//Netscape compliant
1650	    	scrOfY = window.pageYOffset;
1651	    	scrOfX = window.pageXOffset;
1652	  	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
1653	    	//DOM compliant
1654	    	scrOfY = document.body.scrollTop;
1655	    	scrOfX = document.body.scrollLeft;
1656	  	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
1657	    	//IE6 standards compliant mode
1658	    	scrOfY = document.documentElement.scrollTop;
1659	    	scrOfX = document.documentElement.scrollLeft;
1660	  	}
1661	  	//window.alert( 'scrOfX = ' + scrOfX );
1662  		//window.alert( 'scrOfY = ' + scrOfY );
1663
1664	  	return [ scrOfX, scrOfY ];
1665	}
1666
1667	function getRouterInfo(){
1668
1669		var loc = g_storage.get('openurl');
1670		loc = (loc==undefined) ? "/" : loc;
1671
1672		g_webdav_client.GETROUTERINFO("/", function(error, statusstring, content){
1673			if(error==200){
1674				var data = parseXml(content);
1675				var x = $(data);
1676
1677    			g_storage.set('webdav_mode', x.find("webdav_mode").text());
1678    			g_storage.set('http_port', x.find("http_port").text());
1679    			g_storage.set('https_port', x.find("https_port").text());
1680    			g_storage.set('http_enable', x.find("http_enable").text());
1681    			g_storage.set('misc_http_enable', x.find("misc_http_enable").text());
1682    			g_storage.set('misc_http_port', String(x.find("misc_http_port").text()).replace("\n",""));
1683    			g_storage.set('misc_https_port', String(x.find("misc_https_port").text()).replace("\n",""));
1684    			g_storage.set('lan_https_port', String(x.find("lan_https_port").text()).replace("\n",""));
1685    			g_storage.set('last_login_info', x.find("last_login_info").text());
1686    			g_storage.set('ddns_host_name', x.find("ddns_host_name").text());
1687    			g_storage.set('router_version', x.find("version").text());
1688				g_storage.set('aicloud_version', x.find("aicloud_version").text());
1689				g_storage.set('smartsync_version', x.find("smartsync_version").text());
1690    			g_storage.set('wan_ip', x.find("wan_ip").text());
1691				g_storage.set('modalname', x.find("modalname").text());
1692				g_storage.set('usbdiskname', x.find("usbdiskname").text());
1693				g_storage.set('dms_enable', x.find("dms_enable").text());
1694				g_storage.set('account_manager_enable', x.find("account_manager_enable").text());
1695				g_storage.set('app_installation_url', x.find("app_installation_url").text());
1696				g_storage.set('https_crt_cn', x.find("https_crt_cn").text());
1697				g_storage.set('max_sharelink', x.find("max_sharelink").text());
1698
1699    			var login_info = g_storage.get('last_login_info');
1700				if(login_info!=""&&login_info!=undefined&&login_info!=null){
1701					var login_info_array = String(login_info).split(">");
1702				  	var info = m.getString('title_logininfo')+ login_info_array[1] + ", " + m.getString('title_ip') + login_info_array[2];
1703				  	$("#login_info").text(info);
1704				}
1705
1706				refreshAdminUI();
1707			}
1708		});
1709	}
1710
1711	function webdav_delfile_callbackfunction(error, statusstring, content){
1712		if(error){
1713			if(error[0]==2){
1714			}
1715			else{
1716				alert(m.getString(error)+" : " + decodeURIComponent(g_selected_files[0]));
1717				return;
1718			}
1719		}
1720
1721		g_selected_files.splice(0,1);
1722
1723		if(g_selected_files.length<=0){
1724			var openurl = addPathSlash(g_storage.get('openurl'));
1725			doPROPFIND(openurl);
1726			return;
1727		}
1728
1729		g_webdav_client.DELETE(g_selected_files[0], webdav_delfile_callbackfunction);
1730	}
1731
1732	$("div#btnDeleteSel").click(function(){
1733		if($(this).hasClass("disable"))
1734			return false;
1735
1736		if(g_select_array.length<=0)
1737			return;
1738
1739		g_selected_files = null;
1740		g_selected_files = new Array();
1741
1742		for(var i=0; i<g_select_array.length;i++){
1743			g_selected_files.push( g_select_array[i].uhref );
1744		}
1745
1746		var r;
1747		if(g_select_array.length==1)
1748			r=confirm(m.getString('del_files_msg') + " - " + decodeURIComponent(g_select_array[0].title));
1749		else
1750			r=confirm(m.getString('del_files_msg'));
1751
1752		if (r!=true){
1753			return;
1754		}
1755
1756		g_webdav_client.DELETE(g_selected_files[0], webdav_delfile_callbackfunction );
1757	});
1758
1759	$("div#btnNewDir").click(function(){
1760		if($(this).hasClass("disable"))
1761			return false;
1762
1763		var $modalWindow = $("div#modalWindow");
1764		g_modal_url = '/smb/css/makedir.html';
1765		g_modal_window_width = 500;
1766		g_modal_window_height = 80;
1767		$('#jqmMsg').css("display", "none");
1768		$('#jqmTitleText').text(m.getString('title_newdir'));
1769		if($modalWindow){
1770			$modalWindow.jqmShow();
1771		}
1772	});
1773
1774	var downloadURL = function downloadURL(url){
1775		var iframe;
1776	    iframe = document.getElementById("hiddenDownloader");
1777	    if (iframe === null)
1778	    {
1779	        iframe = document.createElement('iframe');
1780	        iframe.id = "hiddenDownloader";
1781	        iframe.style.visibility = 'hidden';
1782	        document.body.appendChild(iframe);
1783	    }
1784	    iframe.src = url;
1785	}
1786
1787	var downloadme = function downloadme(x){
1788		myTempWindow = window.open(x);
1789		//myTempWindow.document.execCommand('SaveAs','null','download.pdf');
1790		//myTempWindow.close();
1791	}
1792
1793	$("div#btnDownload").click(function(e){
1794		if($(this).hasClass("disable"))
1795			return false;
1796
1797		if(g_select_array.length<=0)
1798			return;
1799
1800		var array_download_folder = new Array();
1801
1802		for(var i=0; i < g_select_array.length; i++){
1803			var this_file_name = g_select_array[i].title;
1804			var this_full_url = g_select_array[i].uhref;
1805			var this_isdir = g_select_array[i].isdir;
1806			var this_url = window.location.href;
1807
1808			this_url = this_full_url.substring(0, this_full_url.lastIndexOf('/'));
1809			var full_url = this_url + "/" + this_file_name;
1810
1811			if(this_isdir==1){
1812				array_download_folder.push(full_url);
1813				continue;
1814			}
1815
1816			//- Download file
1817			download_file(full_url);
1818		}
1819
1820		//- Download folder
1821		download_folder(array_download_folder);
1822		array_download_folder = null;
1823	});
1824
1825	$("div#btnRename").click(function(){
1826		if($(this).hasClass("disable"))
1827			return false;
1828
1829		if(g_select_array.length!=1)
1830			return;
1831
1832		var file_name = g_select_array[0].title;
1833		var uhref = g_select_array[0].uhref;
1834		var isdir = g_select_array[0].isdir;
1835
1836		open_rename_window(file_name, uhref, isdir);
1837	});
1838
1839	$("div#btnLock").click(function(){
1840		if($(this).hasClass("disable"))
1841			return false;
1842
1843		if(g_select_array.length!=1)
1844			return;
1845
1846		var this_file_name = g_select_array[0].title;
1847		var this_full_url = g_select_array[0].uhref;
1848		var this_isdir = g_select_array[0].isdir;
1849		//var owner = "https://" + window.location.host + this_full_url;
1850		//var owner = "https://" + window.location.host;
1851		var owner = "http://johnnydebris.net/";
1852		//alert("Lock: " + this_full_url + ", " + owner);
1853
1854		g_webdav_client.LOCK(this_full_url, '', function(status, statusstring, content, headers){
1855			if (status != '201') {
1856      			alert('Error unlocking: ' + statusstring);
1857      			return;
1858      		}
1859
1860      		g_current_locktoken = getLockToken(content);
1861      		alert("locktoken: " + g_current_locktoken);
1862		//}, null, 'exclusive', 'write', 0, 60, 'opaquelocktoken:e71d4fae-5dec-22d6-fea5-00a0c91e6be4');
1863		}, null, 'exclusive', 'write', 0, 3);
1864
1865	});
1866
1867	$("div#btnUnLock").click(function(){
1868		if($(this).hasClass("disable"))
1869			return false;
1870
1871		if(g_select_array.length!=1)
1872			return;
1873
1874		var this_file_name = g_select_array[0].title;
1875		var this_full_url = g_select_array[0].uhref;
1876		var this_isdir = g_select_array[0].isdir;
1877		//var owner = "https://" + window.location.host + this_full_url;
1878
1879		//alert("UNLock: " + this_full_url + ", " + owner);
1880
1881		g_webdav_client.UNLOCK(this_full_url, g_current_locktoken, function(error){
1882			alert(error);
1883		});
1884	});
1885
1886	$("div#btnChangeUser").click(function(){
1887
1888		var r=confirm(m.getString('msg_changeuser_confirm'));
1889		if (r!=true){
1890			return;
1891		}
1892
1893		$("#main_right_container #fileview").empty();
1894
1895		var loc = g_storage.get('openurl');
1896		g_webdav_client.LOGOUT(loc, function(error){
1897			if(error==200){
1898				doPROPFIND(loc);
1899			}
1900		});
1901	});
1902
1903	$("#btnThumbView").click(function(){
1904
1905		//if(confirmCancelUploadFile()==0)
1906		//	return;
1907
1908		g_list_view.set(0);
1909
1910		$("#btnThumbView").css("display", "none");
1911		$("#btnListView").css("display", "block");
1912
1913		var loc = g_storage.get('openurl');
1914		loc = (loc==undefined) ? "/" : loc;
1915
1916		var media_type = isAiModeView();
1917		if( media_type < 0 ){
1918			doPROPFIND(loc);
1919		}
1920		else{
1921			var data_id = (g_storage.get('data-id')==undefined)?"":g_storage.get('data-id');
1922			var keyword = myencodeURI($("div#boxSearch input").val());
1923			doPROPFINDMEDIALIST(loc, false, null, media_type, "0", "50", keyword, "TIMESTAMP", "DESC", data_id);
1924		}
1925	});
1926
1927	$("#btnListView").click(function(){
1928		g_list_view.set(1);
1929
1930		$("#btnThumbView").css("display", "block");
1931		$("#btnListView").css("display", "none");
1932
1933		var loc = g_storage.get('openurl');
1934		loc = (loc==undefined) ? "/" : loc;
1935
1936		var media_type = isAiModeView();
1937		if( media_type < 0 ){
1938			doPROPFIND(loc);
1939		}
1940		else{
1941			var data_id = (g_storage.get('data-id')==undefined)?"":g_storage.get('data-id');
1942			var keyword = myencodeURI($("div#boxSearch input").val());
1943			doPROPFINDMEDIALIST(loc, false, null, media_type, "0", "50", keyword, "TIMESTAMP", "DESC", data_id);
1944		}
1945	});
1946
1947	$("#btnUpload2").click(function(){
1948
1949		g_upload_mode = 1;
1950
1951		$("div#btnNewDir").css("display", "none");
1952		$("div#btnUpload").css("display", "none");
1953		$("div#btnPlayImage").css("display", "none");
1954		$("div#boxSearch").css("display", "none");
1955
1956		$("#upload_panel").css("display", "block");
1957
1958		$("#upload_panel").css("left", '1999px');
1959		$("#upload_panel").animate({left:"0px"},"slow");
1960
1961		var this_url = addPathSlash(g_storage.get('openurl'));
1962		$("#upload_panel iframe").attr( 'src', '/smb/css/upload.html?u=' + this_url );
1963
1964		$("#function_help").text(m.getString('msg_uploadmode_help'));
1965
1966		adjustLayout();
1967	});
1968
1969	$("#btnCancelUpload").click(closeUploadPanel);
1970
1971	$(".mediaListDiv").mousedown( function(){
1972		//if(confirmCancelUploadFile()==0)
1973		//	return;
1974		/*
1975		if(g_storage.get('dms_enable')=="0"){
1976			//alert(m.getString("msg_no_mediaserver"));
1977			$("#main_right_container #hintbar").html(m.getString("msg_no_mediaserver"));
1978			$("#main_right_container #hintbar").show();
1979			return;
1980		}
1981		*/
1982		var qtype = $(this).attr("qtype");
1983		var uhref = g_storage.get('openurl');
1984		g_storage.set("data-id", "");
1985		$(".mediaListDiv").removeClass("down");
1986		$(this).addClass("down");
1987
1988		g_ui_mode.set(qtype);
1989
1990		doPROPFINDMEDIALIST(uhref, false, function(){
1991
1992		}, qtype, "0", "50", null, "TIMESTAMP", "DESC");
1993	});
1994
1995	$("div#btnAiMusicPopupMenux").click( function(e){
1996
1997		var popupmeny = "<div class='popupmenu' id='popupmenu'>";
1998
1999		popupmeny += "<div class='menuitem' id='classifyByAlbum'>";
2000		popupmeny += "<div class='menuitem-content' style='-webkit-user-select: none;'>";
2001		popupmeny += "<span class='menuitem-icon a-inline-block' style='-webkit-user-select: none;'>&nbsp;</span>";
2002		popupmeny += "<span class='menuitem-container a-inline-block' style='-webkit-user-select: none;'>";
2003		popupmeny += "<span class='menuitem-caption a-inline-block' style='-webkit-user-select: none;'>";
2004		popupmeny += "<div style='-webkit-user-select: none;'>" + m.getString('title_sort_by_album') + "</div>";
2005		popupmeny += "</span>";
2006		popupmeny += "</span>";
2007		popupmeny += "</div>";
2008		popupmeny += "</div>";
2009
2010		popupmeny += "<div class='menuitem' id='classifyByArtist'>";
2011		popupmeny += "<div class='menuitem-content' style='-webkit-user-select: none;'>";
2012		popupmeny += "<span class='menuitem-icon a-inline-block' style='-webkit-user-select: none;'>&nbsp;</span>";
2013		popupmeny += "<span class='menuitem-container a-inline-block' style='-webkit-user-select: none;'>";
2014		popupmeny += "<span class='menuitem-caption a-inline-block' style='-webkit-user-select: none;'>";
2015		popupmeny += "<div style='-webkit-user-select: none;'>" + m.getString('title_sort_by_artist') + "</div>";
2016		popupmeny += "</span>";
2017		popupmeny += "</span>";
2018		popupmeny += "</div>";
2019		popupmeny += "</div>";
2020
2021		popupmeny += "</div>";
2022
2023		$(popupmeny).appendTo("body");
2024
2025		$(".popupmenu").css("left", ( g_mouse_x - $(".popupmenu").width() ) + "px");
2026		$(".popupmenu").css("top", ( g_mouse_y - $(".popupmenu").height() ) + "px");
2027
2028		$("#classifyByAlbum").click(function(e){
2029			if(g_webdav_client==null)
2030				return;
2031
2032			showHideLoadStatus(true);
2033
2034			var loc = g_storage.get('openurl');
2035			loc = (loc==undefined) ? "/" : loc;
2036
2037			g_webdav_client.GETMUSICCLASSIFICATION(loc, 'album', function(error, statusstring, content){
2038				if(error==200) createClassificationView(content, "album");
2039				else if(error==503) show_hint_no_mediaserver();
2040				showHideLoadStatus(false);
2041			});
2042
2043			e.preventDefault();
2044      		return false;
2045		});
2046
2047		$("#classifyByArtist").click(function(){
2048			if(g_webdav_client==null)
2049				return;
2050
2051			showHideLoadStatus(true);
2052
2053			var loc = g_storage.get('openurl');
2054			loc = (loc==undefined) ? "/" : loc;
2055
2056			g_webdav_client.GETMUSICCLASSIFICATION(loc, 'artist', function(error, statusstring, content){
2057				if(error==200) createClassificationView(content, "artist");
2058				else if(error==503) show_hint_no_mediaserver();
2059				showHideLoadStatus(false);
2060			});
2061		});
2062	});
2063
2064	$("div#hostview").scroll(function(e){
2065		g_storage.set('hostviewscrollTop', $(this).scrollTop());
2066	});
2067
2068	$("div#fileview").scroll(function(e){
2069		g_storage.set('contentscrollLeft', $(this).scrollLeft());
2070		g_storage.set('contentscrollTop', $(this).scrollTop());
2071	});
2072
2073	$(".navigation#lan dd a").click(function(){
2074		if(confirmCancelUploadFile()==0)
2075			return;
2076
2077		var lan = $(this).attr("id");
2078		g_storage.set('lan', lan);
2079		window.location.reload();
2080	});
2081
2082	$(".navigation#setting dd a").click(function(){
2083		var func = $(this).attr("id");
2084
2085		if(func=="logout"){
2086			if(confirmCancelUploadFile()==0)
2087				return;
2088
2089			var r=confirm(m.getString('msg_logout_confirm'));
2090			if (r!=true){
2091				return;
2092			}
2093			doLOGOUT();
2094		}
2095		else if(func=="mobile"){
2096			var url = window.location.href;
2097			url = url.substr(0, url.lastIndexOf("?"));
2098			window.location = url + '?mobile=1';
2099		}
2100		else if(func=="favorite"){
2101			addtoFavorite();
2102		}
2103		else if(func=="config"){
2104			var http_enable = parseInt(g_storage.get('http_enable')); //- 0: http, 1: https, 2: both
2105			var misc_http_enable = parseInt(g_storage.get('misc_http_enable'));
2106	    	var misc_http_port = g_storage.get('misc_http_port');
2107	    	var misc_https_port = g_storage.get('misc_https_port');
2108	    	var lan_https_port = g_storage.get('lan_https_port');
2109	    	var location_host = window.location.host;
2110	    	var misc_protocol = "http";
2111	    	var misc_port = misc_http_port;
2112
2113	    	if(misc_http_enable==0){
2114	    		if( !isPrivateIP() ){
2115	    			alert(m.getString('msg_no_config'));
2116	    			return;
2117	    		}
2118	  		}
2119
2120	  		if(http_enable==1){
2121	  			misc_protocol = "https";
2122	  			misc_port = misc_https_port;
2123	  		}
2124	  		else{
2125	  			misc_protocol = "http";
2126	  			misc_port = misc_http_port;
2127	  		}
2128
2129	  		var url;
2130
2131	  		if( isPrivateIP() ){
2132	  			url = misc_protocol + "://" + location_host.split(":")[0];
2133
2134	  			if(http_enable==1)
2135	  				url += ":" + lan_https_port;
2136	  		}
2137	  		else{
2138	  			url = misc_protocol + "://" + location_host.split(":")[0];
2139
2140	  			if(misc_port!="")
2141	  				url += ":" + misc_port;
2142	  		}
2143
2144	  		window.location = url;
2145		}
2146		else if(func=="rescan_samba"){
2147			if(confirmCancelUploadFile()==0)
2148				return;
2149
2150			var r=confirm(m.getString('title_desc_rescan'));
2151
2152			if (r==true)
2153				doRescanSamba();
2154		}
2155		else if(func=="sharelink"){
2156			var $modalWindow = $("div#modalWindow");
2157			var page_size = getPageSize();
2158			g_modal_url = '/smb/css/setting.html?p=1&s=1';
2159			g_modal_window_width = 800;
2160			g_modal_window_height = page_size[1]-30;
2161			$('#jqmMsg').css("display", "none");
2162			$('#jqmTitleText').text(m.getString('title_setting'));
2163			if($modalWindow){
2164				$modalWindow.jqmShow();
2165			}
2166		}
2167		else if(func=="account"){
2168			var $modalWindow = $("div#modalWindow");
2169			var page_size = getPageSize();
2170			g_modal_url = '/smb/css/setting.html?p=5&s=1';
2171			g_modal_window_width = 800;
2172			g_modal_window_height = page_size[1]-30;
2173			$('#jqmMsg').css("display", "none");
2174			$('#jqmTitleText').text(m.getString('title_setting'));
2175			if($modalWindow){
2176				$modalWindow.jqmShow();
2177			}
2178		}
2179		else if(func=="version"){
2180			var $modalWindow = $("div#modalWindow");
2181			var page_size = getPageSize();
2182			g_modal_url = '/smb/css/setting.html?p=2&s=1';
2183			g_modal_window_width = 800;
2184			g_modal_window_height = page_size[1]-30;
2185			$('#jqmMsg').css("display", "none");
2186			$('#jqmTitleText').text(m.getString('title_setting'));
2187			if($modalWindow){
2188				$modalWindow.jqmShow();
2189			}
2190		}
2191		else if(func=="crt"){
2192			var $modalWindow = $("div#modalWindow");
2193			var page_size = getPageSize();
2194			g_modal_url = '/smb/css/setting.html?p=3&s=1';
2195			g_modal_window_width = 800;
2196			g_modal_window_height = page_size[1]-30;
2197			$('#jqmMsg').css("display", "none");
2198			$('#jqmTitleText').text(m.getString('title_crt'));
2199			if($modalWindow){
2200				$modalWindow.jqmShow();
2201			}
2202		}
2203		else if(func=="community"){
2204			var $modalWindow = $("div#modalWindow");
2205			var page_size = getPageSize();
2206			g_modal_url = '/smb/css/setting.html?p=4&s=1';
2207			g_modal_window_width = 800;
2208			g_modal_window_height = page_size[1]-30;
2209			$('#jqmMsg').css("display", "none");
2210			$('#jqmTitleText').text(m.getString('title_community'));
2211			if($modalWindow){
2212				$modalWindow.jqmShow();
2213			}
2214		}
2215		else if(func=="test_func"){
2216			/*
2217			g_webdav_client.GETCPUUSAGE("/", function(error, statusstring, content){
2218				if(error==200){
2219					var data = parseXml(content);
2220					var x = $(data);
2221					var cpucount = parseInt(x.find("cpucount").text());
2222
2223					for(var i=0; i<cpucount; i++){
2224						var cpu = "cpu"+i;
2225						var usage = x.find(cpu).text();
2226						alert(cpu+"->"+usage);
2227					}
2228				}
2229				else{
2230					alert(error);
2231				}
2232			});
2233
2234			g_webdav_client.GETMEMORYUSAGE("/", function(error, statusstring, content){
2235				if(error==200){
2236					var data = parseXml(content);
2237					var x = $(data);
2238					var nTotal = x.find("Total").text();
2239					var nFree = x.find("Free").text();
2240					var nUsed = x.find("Used").text();
2241					alert(nTotal+", "+nFree+", "+nUsed);
2242				}
2243				else{
2244					alert(error);
2245				}
2246			});
2247			*/
2248			/*
2249			g_webdav_client.GETNOTICE("/", "Dec 31 12:00:20", function(error, statusstring, content){
2250				if(error==200){
2251					var data = parseXml(content);
2252					var x = $(data);
2253					var notice_log = x.find("log").text();
2254					alert(notice_log);
2255				}
2256				else{
2257					alert(error);
2258				}
2259			});
2260			*/
2261			/*
2262			g_webdav_client.APPLYAPP("/", "apply", "", "restart_webdav", function(error, statusstring, content){
2263				if(error==200){
2264					alert("complete");
2265				}
2266				else{
2267					alert(error);
2268				}
2269			});
2270			*/
2271			/*
2272			g_webdav_client.GETROUTERINFO("/AICLOUD306106790/AiCloud", function(error, statusstring, content){
2273				if(error==200){
2274
2275					var data = parseXml(content);
2276					var x = $(data);
2277    				g_storage.set('webdav_mode', x.find("webdav_mode").text());
2278    				g_storage.set('http_port', x.find("http_port").text());
2279    				g_storage.set('https_port', x.find("https_port").text());
2280    				g_storage.set('misc_http_enable', x.find("misc_http_enable").text());
2281    				g_storage.set('misc_http_port', String(x.find("misc_http_port").text()).replace("\n",""));
2282    				g_storage.set('last_login_info', x.find("last_login_info").text());
2283    				g_storage.set('ddns_host_name', x.find("ddns_host_name").text());
2284    				g_storage.set('router_version', x.find("version").text());
2285    				g_storage.set('wan_ip', x.find("wan_ip").text());
2286
2287    				var login_info = g_storage.get('last_login_info');
2288					if(login_info!=""&&login_info!=undefined){
2289						var login_info_array = String(login_info).split(">");
2290				  		var info = m.getString('title_logininfo')+ login_info_array[1] + ", " + m.getString('title_ip') + login_info_array[2];
2291				  		$("#login_info").text(info);
2292					}
2293				}
2294			});
2295			*/
2296			/*
2297			var apply_url = "http://stage615.asuscomm.com:8082/AICLOUD890940472/Santana";
2298			//var apply_url = "http://192.168.1.10:8082/AICLOUD306106790/AiCloud";
2299			var on_request_handler = function(error, content, statusstring){
2300				alert("requset complete!" + error);
2301			};
2302
2303			alert(apply_url);
2304
2305			var request1 = getXmlHttpRequest();
2306			request1.onreadystatechange = wrapHandler(on_request_handler,request1,null);
2307			request1.open('PROPFIND', apply_url, true);
2308			request1.setRequestHeader('Depth', 1);
2309      request1.setRequestHeader('Content-type', 'text/xml; charset=UTF-8');
2310
2311      var xml = '<?xml version="1.0" encoding="UTF-8" ?>' +
2312                '<D:propfind xmlns:D="DAV:">' +
2313                '<D:allprop />' +
2314                '</D:propfind>';
2315			request1.send(xml);
2316			*/
2317			/*
2318			var url = "/AICLOUD1769668842/ASUS";
2319			doPROPFIND( url, function(){
2320				alert("complete");
2321			}, 0);
2322			*/
2323		}
2324		else if(func=="test_func2"){
2325			g_webdav_client.NVRAMGET("/", "rc_support;webdav_last_login_info", function(error, statusstring, content){
2326				if(error==200){
2327					var data = parseXml(content);
2328
2329					$(data).find('nvram').each(function(){
2330						var key = $(this).attr("key");
2331						var value = $(this).attr("value");
2332						alert("key="+key+", value="+value);
2333					});
2334				}
2335				else{
2336					alert(error);
2337				}
2338			});
2339		}
2340	});
2341
2342	$(".navigation#refresh dt a").click(function(){
2343
2344		//if(confirmCancelUploadFile()==0)
2345		//	return;
2346
2347		//- Query host list first.
2348		var loc = g_storage.get('openurl');
2349		g_storage.set("HostList", "");
2350		doPROPFIND( "/", function(){
2351			loc = (loc==undefined) ? "/" : loc;
2352			if(loc!="/")
2353				doPROPFIND(loc);
2354		}, 0);
2355	});
2356
2357	$(".themes_ctrl").click(function(){
2358		if(confirmCancelUploadFile()==0)
2359			return;
2360
2361		var skin = $(this).attr("id");
2362		g_storage.setl('skin', skin);
2363		window.location.reload();
2364	});
2365
2366	$("div#btnPlayImage").click(function(){
2367		var page_size = getPageSize();
2368		g_image_player.show('', page_size[0], page_size[1], g_file_array);
2369	});
2370
2371	$("div#boxSearch").keyup(function(){
2372		var keyword = myencodeURI($("div#boxSearch input").val());
2373		var uhref = $(this).attr("uhref");
2374		var qtype = $(this).attr("qtype");
2375		var data_id = (g_storage.get('data-id')==undefined)?"":g_storage.get('data-id');
2376
2377		doPROPFINDMEDIALIST(uhref, false, function(){
2378
2379		}, qtype, "0", "50", keyword, "TIMESTAMP", "DESC", data_id);
2380
2381	});
2382
2383	/*
2384	$("div#logo").click(function(){
2385		if(g_fileview_only==1)
2386			return;
2387
2388		doPROPFIND( "/", function(){
2389			g_storage.set('openhostuid', '');
2390			window.location.reload();
2391		}, 0);
2392	});
2393	*/
2394
2395	$("#button-select-all").click(function(){
2396
2397		var add_to_select_array = function(input){
2398			var uhref = input.attr("uhref");
2399			var isdir = input.attr("isdir");
2400			var title = myencodeURI(input.attr("data-name"));
2401
2402			if(uhref==undefined)
2403				return false;
2404
2405			if(isdir==1){
2406				g_select_folder_count++;
2407			}
2408			else{
2409				g_select_file_count++;
2410			}
2411
2412			g_select_array.push( { isdir:isdir, uhref:uhref, title:title } );
2413
2414			return true;
2415		};
2416
2417		g_select_array = null;
2418		g_select_array = new Array();
2419		g_select_file_count=0;
2420		g_select_folder_count=0;
2421
2422		$("#fileview .wcb").each(function(){
2423			var ret = false;
2424
2425			ret = add_to_select_array($(this));
2426
2427			if(ret){
2428				$(this).find(".item-check").addClass("x-view-selected");
2429				$(this).find(".item-check").show();
2430				$(this).css("background-color", "#00C2EB");
2431			}
2432		});
2433
2434		refreshSelectWindow();
2435	});
2436
2437	$("#button-unselect-all").click(function(){
2438		g_select_array = null;
2439		g_select_file_count=0;
2440		g_select_folder_count=0;
2441
2442		$("#fileview .wcb").each(function(){
2443			$(this).find(".item-check").removeClass("x-view-selected");
2444			$(this).find(".item-check").hide();
2445			$(this).find(".item-menu").removeClass("x-view-menu-popup");
2446			$(this).find(".item-menu").hide();
2447			$(this).css("background-color", "");
2448		});
2449
2450		refreshSelectWindow();
2451	});
2452
2453	$.contextMenu({
2454        selector: 'div#btnShareLink',
2455		trigger: 'left',
2456		callback: function(key, options) {
2457			if(key=="upload2facebook"){
2458				if(g_select_array.length<=0)
2459					return;
2460
2461				var upload_files = new Array(0);
2462				for(var i=0; i < g_select_array.length; i++){
2463					var this_full_url = g_select_array[i].uhref;
2464					var filext = getFileExt(this_full_url);
2465
2466					if(filext=='jpg'||filext=='jpeg'||filext=='png'||filext=='gif'){
2467						upload_files.push(this_full_url);
2468					}
2469				}
2470
2471				open_upload2service_window("facebook", upload_files);
2472				upload_files = null;
2473			}
2474			else if(key=="upload2flickr"){
2475				if(g_select_array.length<=0)
2476					return;
2477
2478				var upload_files = new Array(0);
2479				for(var i=0; i < g_select_array.length; i++){
2480					var this_full_url = g_select_array[i].uhref;
2481					var filext = getFileExt(this_full_url);
2482
2483					if(filext=='jpg'||filext=='jpeg'||filext=='png'||filext=='gif'){
2484						upload_files.push(this_full_url);
2485					}
2486				}
2487
2488				open_upload2service_window("flickr", upload_files);
2489				upload_files = null;
2490			}
2491			else if(key=="upload2picasa"){
2492				if(g_select_array.length<=0)
2493					return;
2494
2495				var upload_files = new Array(0);
2496				for(var i=0; i < g_select_array.length; i++){
2497					var this_full_url = g_select_array[i].uhref;
2498					var filext = getFileExt(this_full_url);
2499
2500					if(filext=='jpg'||filext=='jpeg'||filext=='png'||filext=='gif'){
2501						upload_files.push(this_full_url);
2502					}
2503				}
2504
2505				open_upload2service_window("picasa", upload_files);
2506				upload_files = null;
2507			}
2508			else if(key=="upload2twitter"){
2509				if(g_select_array.length<=0)
2510					return;
2511
2512				var upload_files = new Array(0);
2513				for(var i=0; i < g_select_array.length; i++){
2514					var this_full_url = g_select_array[i].uhref;
2515					var filext = getFileExt(this_full_url);
2516
2517					if(filext=='jpg'||filext=='jpeg'||filext=='png'||filext=='gif'){
2518						upload_files.push(this_full_url);
2519					}
2520				}
2521
2522				open_upload2service_window("twitter", upload_files);
2523				upload_files = null;
2524			}
2525			else if(key=="share2facebook"){
2526				if(g_select_array.length<=0)
2527					return;
2528
2529				var selectFileArray = new Array(0);
2530				for(var i=0; i < g_select_array.length; i++){
2531					var this_full_url = g_select_array[i].uhref;
2532					selectFileArray.push(this_full_url);
2533				}
2534
2535				open_sharelink_window("facebook", selectFileArray);
2536				selectFileArray = null;
2537			}
2538			else if(key=="share2googleplus"){
2539				if(g_select_array.length<=0)
2540					return;
2541
2542				var selectFileArray = new Array(0);
2543				for(var i=0; i < g_select_array.length; i++){
2544					var this_full_url = g_select_array[i].uhref;
2545					selectFileArray.push(this_full_url);
2546				}
2547
2548				open_sharelink_window("googleplus", selectFileArray);
2549				selectFileArray = null;
2550			}
2551			else if(key=="share2twitter"){
2552				if(g_select_array.length<=0)
2553					return;
2554
2555				var selectFileArray = new Array(0);
2556				for(var i=0; i < g_select_array.length; i++){
2557					var this_full_url = g_select_array[i].uhref;
2558					selectFileArray.push(this_full_url);
2559				}
2560
2561				open_sharelink_window("twitter", selectFileArray);
2562				selectFileArray = null;
2563			}
2564			else if(key=="share2plurk"){
2565				if(g_select_array.length<=0)
2566					return;
2567
2568				var selectFileArray = new Array(0);
2569				for(var i=0; i < g_select_array.length; i++){
2570					var this_full_url = g_select_array[i].uhref;
2571					selectFileArray.push(this_full_url);
2572				}
2573
2574				open_sharelink_window("plurk", selectFileArray);
2575				selectFileArray = null;
2576			}
2577			else if(key=="share2weibo"){
2578				if(g_select_array.length<=0)
2579					return;
2580
2581				var selectFileArray = new Array(0);
2582				for(var i=0; i < g_select_array.length; i++){
2583					var this_full_url = g_select_array[i].uhref;
2584					selectFileArray.push(this_full_url);
2585				}
2586
2587				open_sharelink_window("weibo", selectFileArray);
2588				selectFileArray = null;
2589			}
2590			else if(key=="share2qq"){
2591				if(g_select_array.length<=0)
2592					return;
2593
2594				var selectFileArray = new Array(0);
2595				for(var i=0; i < g_select_array.length; i++){
2596					var this_full_url = g_select_array[i].uhref;
2597					selectFileArray.push(this_full_url);
2598				}
2599
2600				open_sharelink_window("qq", selectFileArray);
2601				selectFileArray = null;
2602			}
2603			else if(key=="sharelink"){
2604				if(g_select_array.length<=0)
2605					return;
2606
2607				var selectFileArray = new Array(0);
2608				for(var i=0; i < g_select_array.length; i++){
2609					var this_full_url = g_select_array[i].uhref;
2610					selectFileArray.push(this_full_url);
2611				}
2612
2613				open_sharelink_window("other", selectFileArray);
2614				selectFileArray = null;
2615			}
2616        },
2617        items: {
2618			"submenu_upload": {
2619				name : m.getString("title_upload2"),
2620				disabled: function(key, opt) {
2621					if(g_select_array.length<=0)
2622						return true;
2623
2624					for(var i=0; i < g_select_array.length; i++){
2625						var this_full_url = g_select_array[i].uhref;
2626						var filext = getFileExt(this_full_url);
2627
2628						if(filext=='jpg'||filext=='jpeg'||filext=='png'||filext=='gif'){
2629							return false;
2630						}
2631					}
2632
2633					return true;
2634				},
2635                items : {
2636                	"upload2facebook": {
2637						name: m.getString("title_facebook")
2638					},
2639					"upload2flickr": {
2640						name: m.getString("title_flickr")
2641					},
2642					"upload2picasa": {
2643						name: m.getString("title_picasa")
2644					},
2645					"upload2twitter": {
2646						name: m.getString("title_twitter")
2647					}
2648                }
2649            },
2650			"submenu_share": {
2651				name : m.getString("title_share2"),
2652                items : {
2653                	"share2facebook": {
2654						name: m.getString("title_facebook")
2655					},
2656					"share2googleplus": {
2657						name: m.getString("title_googleplus")
2658					},
2659					"share2twitter": {
2660						name: m.getString("title_twitter")
2661					},
2662					"share2plurk": {
2663						name: m.getString("title_plurk")
2664					},
2665					"share2weibo": {
2666						name: m.getString("title_weibo")
2667					},
2668					"share2qq": {
2669						name: m.getString("title_qq")
2670					}
2671                }
2672            },
2673			"sharelink": {name: m.getString("title_gen_sharelink")}
2674        }
2675    });
2676
2677	$.contextMenu({
2678        selector: 'div#btnCopyMove',
2679		trigger: 'left',
2680		callback: function(key, options) {
2681
2682			if(key=="copy"||key=="move"){
2683				if(g_select_array.length<=0)
2684					return;
2685
2686				var selectURL = g_storage.get('openurl');
2687				var selectFileArray = new Array();
2688
2689				for(var i=0; i < g_select_array.length; i++){
2690					var this_file = g_select_array[i].title;
2691					selectFileArray.push(this_file);
2692				}
2693
2694				open_copymove_window(key, selectURL, selectFileArray);
2695
2696				selectFileArray = null;
2697			}
2698        },
2699        items: {
2700        	"copy": {
2701				name: m.getString("func_copy")
2702			},
2703			"move": {
2704				name: m.getString("func_move")
2705			}
2706        }
2707    });
2708
2709	$.contextMenu({
2710        selector: 'div#btnUpload',
2711		trigger: 'left',
2712		callback: function(key, options) {
2713			if(key=="uploadfile")
2714				open_uploadfile_window();
2715			else if(key=="uploadfolder")
2716				open_uploadfolder_window();
2717        },
2718        items: {
2719            "uploadfile": {name: m.getString("title_upload_file")},
2720			"uploadfolder": {name: m.getString("title_upload_folder")}
2721        }
2722    });
2723
2724	$.contextMenu({
2725        selector: 'div#btnAiMusicPopupMenu',
2726		trigger: 'left',
2727		callback: function(key, options) {
2728			if(key=="sort_by_album"){
2729				if(g_webdav_client==null)
2730					return;
2731
2732				showHideLoadStatus(true);
2733
2734				var loc = g_storage.get('openurl');
2735				loc = (loc==undefined) ? "/" : loc;
2736
2737				g_webdav_client.GETMUSICCLASSIFICATION(loc, 'album', function(error, statusstring, content){
2738					if(error==200) createClassificationView(content, "album");
2739					else if(error==503) show_hint_no_mediaserver();
2740					showHideLoadStatus(false);
2741				});
2742			}
2743			else if(key=="sort_by_artist"){
2744				if(g_webdav_client==null)
2745					return;
2746
2747				showHideLoadStatus(true);
2748
2749				var loc = g_storage.get('openurl');
2750				loc = (loc==undefined) ? "/" : loc;
2751
2752				g_webdav_client.GETMUSICCLASSIFICATION(loc, 'artist', function(error, statusstring, content){
2753					if(error==200) createClassificationView(content, "artist");
2754					else if(error==503) show_hint_no_mediaserver();
2755					showHideLoadStatus(false);
2756				});
2757			}
2758        },
2759        items: {
2760            "sort_by_album": {name: m.getString("title_sort_by_album")},
2761			"sort_by_artist": {name: m.getString("title_sort_by_artist")}
2762        }
2763    });
2764
2765	$.contextMenu({
2766        selector: '.item-menu',
2767		trigger: 'left',
2768		events: {
2769			show: function(opt){
2770			},
2771  			hide: function(opt){
2772   				$(this).removeClass("x-view-menu-popup");
2773 		 	}
2774		},
2775        callback: function(key, options) {
2776			var select_item = $(this).parents(".wcb");
2777			var uhref = select_item.attr("uhref");
2778			var file_name = encodeURIComponent(select_item.attr("data-name"));
2779			var isdir = select_item.attr("isdir");
2780
2781			if(key=="delete"){
2782
2783				if(uhref=="") return;
2784
2785				var r=confirm(m.getString('del_files_msg') + " - " + decodeURIComponent(file_name));
2786				if (r!=true){
2787					return;
2788				}
2789
2790				g_webdav_client.DELETE(uhref, function(){
2791					var openurl = addPathSlash(g_storage.get('openurl'));
2792					doPROPFIND(openurl);
2793				});
2794			}
2795			else if(key=="copy"){
2796				open_copymove_window(key, g_storage.get('openurl'), file_name);
2797			}
2798			else if(key=="move"){
2799				open_copymove_window(key, g_storage.get('openurl'), file_name);
2800			}
2801			else if(key=="rename"){
2802				open_rename_window(file_name, uhref, isdir);
2803			}
2804			else if(key=="download"){
2805				if(isdir=="1")
2806					download_folder(uhref);
2807				else
2808					download_file(uhref);
2809			}
2810			else if(key=="upload2facebook"){
2811				open_upload2service_window("facebook", uhref);
2812			}
2813			else if(key=="upload2flickr"){
2814				open_upload2service_window("flickr", uhref);
2815			}
2816			else if(key=="upload2picasa"){
2817				open_upload2service_window("picasa", uhref);
2818			}
2819			else if(key=="upload2twitter"){
2820				open_upload2service_window("twitter", uhref);
2821			}
2822			else if(key=="share2facebook"){
2823				open_sharelink_window("facebook", uhref);
2824			}
2825			else if(key=="share2googleplus"){
2826				open_sharelink_window("googleplus", uhref);
2827			}
2828			else if(key=="share2twitter"){
2829				open_sharelink_window("twitter", uhref);
2830			}
2831			else if(key=="share2plurk"){
2832				open_sharelink_window("plurk", uhref);
2833			}
2834			else if(key=="share2weibo"){
2835				open_sharelink_window("weibo", uhref);
2836			}
2837			else if(key=="share2qq"){
2838				open_sharelink_window("qq", uhref);
2839			}
2840			else if(key=="sharelink"){
2841				var selectFileArray = new Array(0);
2842				for(var i=0; i < g_select_array.length; i++){
2843					var this_full_url = g_select_array[i].uhref;
2844					selectFileArray.push(this_full_url);
2845				}
2846
2847				open_sharelink_window("other", selectFileArray);
2848				selectFileArray = null;
2849			}
2850        },
2851        items: {
2852            "delete": {
2853				name: m.getString("func_delete"),
2854				disabled: function(){
2855					if(g_storage.get('aimode')==1||
2856					   g_storage.get('aimode')==2||
2857					   g_storage.get('aimode')==3)
2858					   return true;
2859				}
2860			},
2861			"submenu_copymove": {
2862				name : m.getString("title_copymove"),
2863                items : {
2864                	"copy": {
2865						name: m.getString("func_copy")
2866					},
2867					"move": {
2868						name: m.getString("func_move")
2869					}
2870                }
2871            },
2872			"rename": {
2873				name: m.getString("func_rename"),
2874				disabled: function(){
2875					if(g_storage.get('aimode')==1||
2876					   g_storage.get('aimode')==2||
2877					   g_storage.get('aimode')==3)
2878					   return true;
2879				}
2880			},
2881			"sep1": "---------",
2882            "download": {
2883            	name: m.getString("func_download"),
2884            	disabled: function(){
2885					if(g_select_array.length<=0)
2886						return true;
2887
2888					for(var i=0; i < g_select_array.length; i++){
2889						if(g_select_array[i].isdir=="1"){
2890							//- Disable download folder function before we found the solution.
2891							return true;
2892						}
2893					}
2894
2895					return false;
2896				}
2897			},
2898			"sep2": "---------",
2899			"submenu_upload": {
2900				name : m.getString("title_upload2"),
2901				disabled: function(key, opt) {
2902					if(g_select_array.length<=0)
2903						return true;
2904
2905					for(var i=0; i < g_select_array.length; i++){
2906						var this_full_url = g_select_array[i].uhref;
2907						var filext = getFileExt(this_full_url);
2908
2909						if(filext=='jpg'||filext=='jpeg'||filext=='png'||filext=='gif'){
2910							return false;
2911						}
2912					}
2913
2914					return true;
2915				},
2916                items : {
2917                	"upload2facebook": {
2918						name: m.getString("title_facebook")
2919					},
2920					"upload2flickr": {
2921						name: m.getString("title_flickr")
2922					},
2923					"upload2picasa": {
2924						name: m.getString("title_picasa")
2925					},
2926					"upload2twitter": {
2927						name: m.getString("title_twitter")
2928					}
2929                }
2930            },
2931			"submenu_share": {
2932				name : m.getString("title_share2"),
2933                items : {
2934                	"share2facebook": {
2935						name: m.getString("title_facebook")
2936					},
2937					"share2googleplus": {
2938						name: m.getString("title_googleplus")
2939					},
2940					"share2twitter": {
2941						name: m.getString("title_twitter")
2942					},
2943					"share2plurk": {
2944						name: m.getString("title_plurk")
2945					},
2946					"share2weibo": {
2947						name: m.getString("title_weibo")
2948					},
2949					"share2qq": {
2950						name: m.getString("title_qq")
2951					}
2952                }
2953            },
2954			"sharelink": {name: m.getString("title_gen_sharelink")}
2955        }
2956    });
2957
2958	$(window).resize(adjustLayout);
2959});
2960
2961window.onbeforeunload = function (e) {
2962	var is_onUploadFile = g_storage.get('isOnUploadFile');
2963	if(is_onUploadFile==1){
2964		var msg = m.getString('msg_confirm_cancel_upload');
2965		var e = e || window.event;
2966
2967	  	//IE & Firefox
2968	  	if (e) {
2969	  		e.returnValue = msg;
2970	  	}
2971
2972	  	// For Safari
2973	  	return msg;
2974	}
2975};
2976
2977window.onunload = function (e) {
2978	if(confirmCancelUploadFile()==0){
2979		return;
2980	}
2981	/*
2982	var is_onUploadFile = g_storage.get('isOnUploadFile');
2983
2984	if(is_onUploadFile==1){
2985		stop_upload();
2986	}
2987	*/
2988};
2989
2990function doBackgroundPlay(){
2991	alert("doBackgroundPlay");
2992}
2993