var server = require('./server');
var uId = getQueryString("uId");
var IsLogin = getQueryString("IsLogin");
var dataPath = decodeURIComponent(getQueryString("dataPath"));
var path = gui.App.dataPath + '/360Data';
var sh = new sqlHelper(gui.App.dataPath, "360doc.db");
var db = new sqlHelper(path, "data_" + uId + ".db");
var Uid;
var UserCode;
var NickName;
var articleTime;
var message;
var delay = 180;
var Intervalunmsg;
var fileData;
var Isforbid;
var clientId;
var sum = 0;
var pushInfoIP = '';
var clickNum = 0;
var tpe;
var messageInitsocket = 0;
var isInitialization;
var address;
var isPublish = 0;
var serverPort;
fs.readFile(process.cwd() + "/server.log", function(err, data) {
	serverPort = data
});
downloadCss("https://css.360doc.com/ueditor/pcclientneweditor.css?" + new Date().getTime() / 100000, function() {
	var cssUrl = process.cwd() + '/app/CommonSet/neweditor_old.css';
	fs.readFile(cssUrl, function(err, cssContent) {
		if (cssContent.indexOf("/*correctfile*/") != -1) {
			$.ajax({
				url: 'http://127.0.0.1:' + serverPort + '/',
				dataType: "jsonp",
				data: {
					"name": "neweditor.css",
					"url": process.cwd() + '/app/CommonSet/neweditor_old.css',
					"fileUrl": process.cwd() + '/app/CommonSet/'
				},
				type: 'POST',
				jsonpCallback: 'callback',
				success: function(data) {
					var ret = jQuery.parseJSON(data)
				}
			})
		}
	})
});
var pcclipper = "http://www.360doc.com/js/pcclipper.js?" + new Date().getTime() / 100000;
request(pcclipper).pipe(fs.createWriteStream(process.cwd() + '/app/CommonSet/pcclipper_old.js')).on("close", function(err) {
	var jsUrl = process.cwd() + '/app/CommonSet/pcclipper_old.js';
	fs.readFile(jsUrl, function(err, jsContent) {
		if (jsContent.indexOf("/*correctfile*/") != -1) {
			$.ajax({
				url: 'http://127.0.0.1:' + serverPort + '/',
				dataType: "jsonp",
				data: {
					"name": "pcclipper.js",
					"url": process.cwd() + '/app/CommonSet/pcclipper_old.js',
					"fileUrl": process.cwd() + '/app/CommonSet/'
				},
				type: 'POST',
				jsonpCallback: 'callback',
				success: function(data) {
					var ret = jQuery.parseJSON(data)
				}
			})
		}
	})
});
_tray = null;
_tray = new gui.Tray({
	title: '个人图书馆',
	tooltip: '个人图书馆',
	icon: 'app/img/logo_16x16.png',
	menu: trayMenu
});
_tray.on('click', function() {
	$("#winTopClose").attr("type", "0");
	win.show()
});
if (GetOSInfo() == "Mac") {
	var tpe = 1
} else {
	var tpe = 0
};
sh.checkData('usersInfo', '*', "UserID = '" + uId + "'", function(info, err) {
	isInitialization = info.newData1
});
sh.userCheckData('Users', '*', " UserID = '" + uId + "'", function(row, err) {
	Uid = row.UserID;
	UserCode = row.Usercode;
	NickName = row.NickName;
	Isforbid = row.Isforbid;
	address = row.address;
	window.addEventListener("online", function() {
		onlineFun()
	});

	function onlineUpgrade() {
		var strRequestUrl = cv.post + "/ajax/users.ashx?ver=0.01&os=windows&op=getrenewmes2&type=" + tpe;
		var sign = "&sign=" + getSign.sign(strRequestUrl);
		ajax_method(strRequestUrl + sign, null, "post", function(result) {
			var data = eval("(" + result + ")");
			var pkg = require('../package.json');
			if (tpe == 1) {
				sh.checkData('UpdateInfo', '*', null, function(row, err) {
					if (data.status == 1 && parseInt(data.versionid) > parseInt(row.versionid)) {
						$("#operation,#upgrade").addClass("NewVersionTips");
						if ($("#winTopClose").attr("type") == 1) {
							var docWindowOptions = {
								frame: false,
								width: 320,
								height: 190,
								max_width: 320,
								max_height: 190,
								min_width: 320,
								min_height: 190,
								always_on_top: true,
								transparent: true,
							};
							var winOpen1 = gui.Window.open("/app/upgradeNotice.html", docWindowOptions, function(nwwin) {
								nwwin.setShowInTaskbar(false);
								nwwin.window.moveTo(screen.availWidth, screen.availHeight);
								nwwin.on('loaded', function() {
									var a = nwwin.window.document;
									$(a).find("html body .details").text("个人图书馆最新版本V" + data.version + "已经发布！");
									$(a).find("html body .colse").click(function() {
										nwwin.close(true)
									});
									$(a).find("html body .button").click(function() {
										$("#winTopClose").attr("type", "0");
										win.show();
										PushUpgrade1();
										nwwin.close(true)
									})
								})
							})
						} else {
							PushUpgrade1()
						}
					}
				})
			} else {
				if (data.status == 1 && parseInt(data.versionid) > parseInt(pkg.versionId)) {
					$("#operation,#upgrade").addClass("NewVersionTips");
					if ($("#winTopClose").attr("type") == 1) {
						var docWindowOptions = {
							frame: false,
							width: 320,
							height: 190,
							max_width: 320,
							max_height: 190,
							min_width: 320,
							min_height: 190,
							always_on_top: true,
							transparent: true,
						};
						var winOpen1 = gui.Window.open("/app/upgradeNotice.html", docWindowOptions, function(nwwin) {
							nwwin.setShowInTaskbar(false);
							nwwin.window.moveTo(screen.availWidth, screen.availHeight);
							nwwin.on('loaded', function() {
								var a = nwwin.window.document;
								$(a).find("html body .details").text("个人图书馆最新版本V" + data.version + "已经发布！");
								$(a).find("html body .colse").click(function() {
									nwwin.close(true)
								});
								$(a).find("html body .button").click(function() {
									$("#winTopClose").attr("type", "0");
									win.show();
									PushUpgrade1();
									nwwin.close(true)
								})
							})
						})
					} else {
						PushUpgrade1()
					}
				}
			};

			function PushUpgrade1() {
				$("#upgrade_title").text(data.title);
				$("#upgrade_Content").html(data.Content);
				$(".upgrade_back").show();
				$("#upgradeClose,#upgrade-cancel").click(function() {
					$(".upgrade_back").hide()
				});
				$("#upgrade-sure").unbind("click").click(function() {
					if (!navigator.onLine) {
						AlertDialog.confirm(0, "网络连接异常，请稍后重试！");
						return false
					};
					var new_win = gui.Window.open("/app/upgrade1.html", {
						position: 'center',
						frame: false,
						width: 455,
						height: 332,
						max_width: 455,
						max_height: 332,
						min_width: 455,
						min_height: 332,
						always_on_top: true,
					});
					win.close(true)
				})
			}
		})
	};

	function onlineFun() {
		$("#signal").addClass("net");
		sh.checkData('clientid', '*', null, function(row, err) {
			if (row.id == '0') {
				var sign = "&sign=" + getSign.sign(cv.post + "/ajax/sync.ashx?op=getguid");
				ajax_online(cv.post + "/ajax/sync.ashx?op=getguid" + sign, null, "post", function(result) {
					onlineUpgrade();
					sh.saveData("clientid(id,newData1,newData2,newData3)", "(?,?,?,?)", result + ',' + null + ',' + null + ',' + null);
					clientId = result;
					ajax_online(cv.post + "/ajax/nodejs.ashx?op=getip", null, "post", function(result) {
						var data = eval("(" + result + ")");
						pushInfoIP = data.ip + ':' + data.port;
						if (messageInitsocket == 0) {
							message.initsocket()
						}
					})
				})
			} else {
				clientId = row.id;
				ajax_online(cv.post + "/ajax/nodejs.ashx?op=getip", null, "post", function(result) {
					onlineUpgrade();
					db.dataNull('ArticleList', function(err, id) {
						if (id == 0) {
							SynchronizeArticleData()
						} else {
							db.checkDataSort('ArticleList', '*', ' articleID desc limit 1', function(data, err) {
								PushArticleList1(2, 100, data.articleID + 1)
							})
						}
					});
					$("#signal").addClass("net");
					var data = eval("(" + result + ")");
					pushInfoIP = data.ip + ':' + data.port;
					if (messageInitsocket == 0) {
						message.initsocket()
					}
				})
			}
		})
	};
	if (navigator.onLine) {
		sh.checkData('clientid', '*', null, function(row1, err) {
			if (row1.id == '0') {
				var sign = "&sign=" + getSign.sign(cv.post + "/ajax/sync.ashx?op=getguid");
				ajax_method(cv.post + "/ajax/sync.ashx?op=getguid" + sign, null, "post", function(result) {
					sh.saveData("clientid(id,newData1,newData2,newData3)", "(?,?,?,?)", result + ',' + null + ',' + null + ',' + null);
					clientId = result;
					ajax_method(cv.post + "/ajax/nodejs.ashx?op=getip", null, "post", function(result) {
						var data = eval("(" + result + ")");
						pushInfoIP = data.ip + ':' + data.port;
						message.initsocket();
						messageInitsocket = 1
					})
				})
			} else {
				clientId = row1.id;
				ajax_method(cv.post + "/ajax/nodejs.ashx?op=getip", null, "post", function(result) {
					var data = eval("(" + result + ")");
					pushInfoIP = data.ip + ':' + data.port;
					message.initsocket();
					messageInitsocket = 1
				})
			}
		})
	};
	var message = {
		socket: null,
		topicfb: "pcclient_fb",
		topicpc: "pcclient_msg",
		connect: function(clientid, usercode) {
			message.socket = io.connect("http://" + pushInfoIP + "?clientid=" + clientId + "&usercode=" + row.Usercode, {
				"force new connection": true,
				reconnect: false
			})
		},
		isconnect: function() {
			return message.socket.connected
		},
		isreconnected: false,
		initsocket: function(clientid, usercode) {
			message.connect(clientid, usercode);
			message.socket.on('connect', function() {
				message.socket.on('disconnect', function(ev) {
					message.socket.disconnect();
					message.socket.destroy();
					if (ev != null && ev.toString().indexOf("client") > -1) {
						return
					};
					message.isreconnected = true;
					setTimeout(function() {
						message.initsocket(clientid, usercode)
					}, 5000)
				});
				message.socket.on(message.topicfb, function(msg) {
					msg = JSON.parse(msg);
					if (msg.status != "1") {
						message.socket.disconnect();
						message.socket.destroy()
					}
				});
				message.socket.on(message.topicpc, function(msg) {
					var data = eval("(" + msg + ")");
					var refreshClass = '';
					if (Initialization == 0) {
						return false
					};
					if (data.type == '935' || data.type == '948' || data.type == '920' || data.type == '921' || data.type == '922' || data.type == '923' || data.type == '924' || data.type == '934' || data.type == '936' || data.type == '950' || data.type == '949' || data.type == '963' || data.type == '964') {
						if ($(".refresh-signal>span.refresh").is(".refresh1")) {
							refreshClass = "refresh1";
							$(".refresh-signal>span.refresh").removeClass("refresh1")
						} else if ($(".refresh-signal>span.refresh").is(".refresh2")) {
							refreshClass = "refresh2";
							$(".refresh-signal>span.refresh").removeClass("refresh2")
						}
					};
					setTimeout(function() {
						if (refreshClass != '') {
							$(".refresh-signal>span.refresh").addClass(refreshClass)
						} else {
							$(".refresh-signal>span.refresh").removeClass("refresh2").addClass("refresh1")
						}
					}, 1000);
					message.socket.emit("pcclient_fb", JSON.stringify({
						userid: data.userid,
						msgid: data.msgid
					}));
					console.log(data);
					if (data.type == "935") {
						if (data.opcode == 1) {
							setTimeout(function() {
								for (var i = 0; i < data.data.length; i++) {
									var obj = data.data[i];
									db.checkData("ArticleList", "*", " articleID = '" + obj.articleid + "'", function(row, err) {}, function(err) {
										if ($(".indexPublishSuccessImg").is(":hidden")) {
											if (err == 0) {
												db.deleteTableSingleData('SearchArticleList', ' articleID = "' + obj.articleid + '"', function() {});
												db.deleteTableSingleData('ArticleList', ' articleID = ' + obj.articleid, function(err) {
													db.saveData("SearchArticleList(ArticleID,ArticleTitle,SaveDate,ArtContent,Arttype,newData1,newData2,newData3)", "(?,?,?,?,?,?,?,?)", obj.articleid + ',' + removeHTMLTag(replaceCharacter(window.decodeURIComponent(obj.title))) + ',' + Number(Date.parse(new Date())) + ',' + null + ',' + Number(obj.arttype) + ',' + null + ',' + null + ',' + null);
													db.saveData("ArticleList(articleID,artType,ArticleTitle,keywords,Abstract,SaveDate,SaverUserID,ArtPermission,Tags,isChecked,FirstArtID,authorName,authorUserID ,resaveAuthorName,resaveAuthorUserID,categoryID,isOriginal,ArtUrl,sourceName,ReadNum,flowersNum,commentNum,saverNum,ArtContent,IsUpload,Logid,IsDelete,PrevCategoryID,IsDownLoad,downloadStatus,localImgUrl,imgDownloadStatus,IsConvert,PageNum,Purtext,Offvalue,Permitdownload,docsize,iscream,savefrom,originalActivityID,newData1,newData2,newData3)", "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", obj.articleid + ',' + obj.arttype + ',' + toTXT(decodeURIComponent(obj.title)) + ',' + null + ',' + null + ',' + Date.parse(new Date()) + ',' + Uid + ',' + obj.permission + ',' + null + ',' + null + ',' + null + ',' + null + ',' + null + ',' + NickName + ',' + Uid + ',' + obj.categoryid + ',' + obj.original + ',' + obj.sourceurl + ',' + obj.sourcename + ',' + obj.readnum + ',' + null + ',' + null + ',' + obj.savenum + ',' + null + ',' + 1 + ',' + null + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + 0 + ',' + 0 + ',' + 0 + ',' + null + ',' + null + ',' + null + ',' + null, function() {
														articleDownload(obj.arttype, obj.articleid, function() {
															if ($(".articleSearchList-div").is(":hidden") || isPublish == 0) {
																db.checkData("ArticleList", "*", " articleID = '" + $("#divartlist>li.con").attr("aid") + "'", function(row, err) {}, function(num) {
																	if (num == 0) {
																		if ($("#TreeId").val() != '') {
																			ArticleList(0, 50, "CategoryID=" + $("#TreeId").val(), null, null, true)
																		} else {
																			ArticleList(0, 50, null, null, null, true)
																		}
																	} else {
																		var where = '';
																		if ($("#TreeId").val() != '') {
																			var where = " categoryID='" + $("#TreeId").val() + "' AND articleID > '" + $("#divartlist>li.con").attr("aid") + "'"
																		} else {
																			var where = " articleID > '" + $("#divartlist>li.con").attr("aid") + "'"
																		};
																		db.SearchQuery("ArticleList", "articleID,artType,ArticleTitle,keywords,Abstract,SaveDate,SaverUserID,ArtPermission,Tags,isChecked,FirstArtID,authorName,authorUserID ,resaveAuthorName,resaveAuthorUserID,categoryID,isOriginal,ArtUrl,sourceName,ReadNum,flowersNum,commentNum,saverNum,ArtContent,IsUpload,Logid,IsDelete,PrevCategoryID,IsDownLoad,downloadStatus,localImgUrl,imgDownloadStatus,IsConvert,PageNum,Purtext,Offvalue,Permitdownload,docsize,iscream,savefrom,originalActivityID,newData1,newData2,newData3", where, null, null, function(row, err) {}, function(num) {
																			var page = (num / 50).toFixed(0) - 1;
																			if ($("#TreeId").val() != '') {
																				ArticleList(page * 50, 50, "CategoryID=" + $("#TreeId").val(), null, null, $("#divartlist>li.con").attr("aid"));
																				if (page > 0) {
																					db.checkDataStripNumber('ArticleList', 'articleID', 50, 0, "CategoryID=" + $("#TreeId").val(), 'SaveDate desc', function(row, err) {}, function(count) {
																						paging(count, 50, Number(page) + 1)
																					})
																				}
																			} else {
																				ArticleList(page * 50, 50, null, null, null, $("#divartlist>li.con").attr("aid"));
																				if (page > 0) {
																					db.checkDataStripNumber('ArticleList', 'articleID', 50, 0, null, 'SaveDate desc', function(row, err) {}, function(count) {
																						paging(count, 50, Number(page) + 1)
																					})
																				}
																			}
																		})
																	}
																})
															}
														});
														$(".articleList-newPrompt i").text("1");
														$(".articleList-newPrompt").show().click(function() {
															$(".app-screen-download span").attr("type", '').text("全部");
															$(".app-screen-type span").attr("type", "").text("全部");
															$("#TreeId").val("");
															var treeObj = $.fn.zTree.getZTreeObj("treelist");
															treeObj.cancelSelectedNode();
															$(".articleList-newPrompt").hide()
														});
														setTimeout(function() {
															$(".articleList-newPrompt").hide()
														}, 2500);
														db.batchData(" dataStorage ", " updateTime='" + getNowFormatDate("-", 0) + "'");
														db.checkData('dataStorage', '*', null, function(row, err) {
															if (row.updateTime.substr(0, 4) == getNowFormatDate("-", 0).substr(0, 4)) {
																$(".refresh-hover .refresh-Result").find("i").text(getNowFormatDate("-", 0).substr(5, 11))
															} else {
																$(".refresh-hover .refresh-Result").find("i").text(getNowFormatDate("-", 0).substr(0, 16))
															}
														})
													})
												})
											} else {
												articleDownload(obj.arttype, obj.articleid, function() {});
												/*if ($(".articleSearchList-div").is(":hidden") || isPublish == 0) {
													db.checkData("ArticleList", "*", " articleID = '" + $("#divartlist>li.con").attr("aid") + "'", function(row, err) {}, function(num) {
														if (num == 0) {
															if ($("#TreeId").val() != '') {
																ArticleList(0, 50, "CategoryID=" + $("#TreeId").val(), null, null, true)
															} else {
																ArticleList(0, 50, null, null, null, true)
															}
														} else {
															var where = '';
															if ($("#TreeId").val() != '') {
																var where = " categoryID='" + $("#TreeId").val() + "' AND articleID > '" + $("#divartlist>li.con").attr("aid") + "'"
															} else {
																var where = " articleID > '" + $("#divartlist>li.con").attr("aid") + "'"
															};
															db.SearchQuery("ArticleList", "articleID,artType,ArticleTitle,keywords,Abstract,SaveDate,SaverUserID,ArtPermission,Tags,isChecked,FirstArtID,authorName,authorUserID ,resaveAuthorName,resaveAuthorUserID,categoryID,isOriginal,ArtUrl,sourceName,ReadNum,flowersNum,commentNum,saverNum,ArtContent,IsUpload,Logid,IsDelete,PrevCategoryID,IsDownLoad,downloadStatus,localImgUrl,imgDownloadStatus,IsConvert,PageNum,Purtext,Offvalue,Permitdownload,docsize,iscream,savefrom,originalActivityID,newData1,newData2,newData3", where, null, null, function(row, err) {}, function(num) {
																var page = (num / 50).toFixed(0) - 1;
																if ($("#TreeId").val() != '') {
																	ArticleList(page * 50, 50, "CategoryID=" + $("#TreeId").val(), null, null, $("#divartlist>li.con").attr("aid"));
																	if (page > 0) {
																		db.checkDataStripNumber('ArticleList', 'articleID', 50, 0, "CategoryID=" + $("#TreeId").val(), 'SaveDate desc', function(row, err) {}, function(count) {
																			paging(count, 50, Number(page) + 1)
																		})
																	}
																} else {
																	ArticleList(page * 50, 50, null, null, null, $("#divartlist>li.con").attr("aid"));
																	if (page > 0) {
																		db.checkDataStripNumber('ArticleList', 'articleID', 50, 0, null, 'SaveDate desc', function(row, err) {}, function(count) {
																			paging(count, 50, Number(page) + 1)
																		})
																	}
																}
															})
														}
													})
												}*/
											}
										}
									})
								};
								folder($("#TreeId").val())
							}, 1000)
						}
					} else if (data.type == "948") {
						var num = 0;
						for (var i = 0; i < data.data.length; i++) {
							var obj = data.data[i];
							db.saveData("ArticleList(articleID,artType,ArticleTitle,keywords,Abstract,SaveDate,SaverUserID,ArtPermission,Tags,isChecked,FirstArtID,authorName,authorUserID ,resaveAuthorName,resaveAuthorUserID,categoryID,isOriginal,ArtUrl,sourceName,ReadNum,flowersNum,commentNum,saverNum,ArtContent,IsUpload,Logid,IsDelete,PrevCategoryID,IsDownLoad,downloadStatus,localImgUrl,imgDownloadStatus,IsConvert,PageNum,Purtext,Offvalue,Permitdownload,docsize,iscream,savefrom,originalActivityID,newData1,newData2,newData3)", "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", obj.articleid + ',' + obj.arttype + ',"' + toTXT(decodeURIComponent(obj.title)) + '",' + null + ',' + null + ',' + obj.savedate + ',' + Uid + ',' + obj.permission + ',' + null + ',' + null + ',' + null + ',' + null + ',' + null + ',' + NickName + ',' + Uid + ',' + obj.categoryid + ',' + obj.original + ',' + obj.sourceurl + ',' + obj.sourcename + ',' + obj.readnum + ',' + null + ',' + null + ',' + obj.savenum + ',' + null + ',' + 1 + ',' + null + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + 0 + ',' + 0 + ',' + 0 + ',' + null + ',' + null + ',' + null + ',' + null, function() {
								articleDownload(obj.arttype, obj.articleid, function() {});
								num++;
								db.checkData('CategoryMyLibrary', '*', ' CategoryID = ' + obj.categoryid, function(row, err) {
									db.modifyData('CategoryMyLibrary', ' ArtNum="' + Number(row.ArtNum + 1) + '"', ' CategoryID = ' + obj.categoryid)
								});
								db.batchData('Category', ' artnum="' + (Number($("#artnum").html()) + 1) + '"', function() {
									$("#artnum").html((Number($("#artnum").html()) + 1))
								});
								if (num == data.data.length) {
									if (!$("#TreeId").val() || $("#TreeId").val() == 1) {
										ArticleList(0, 50, null, null, null, true)
									} else if ($("#TreeId").val() && $("#TreeId").val() != "999999999999") {
										ArticleList(0, 50, "CategoryID=" + $("#TreeId").val(), null, null, true)
									};
									db.batchData(" dataStorage ", " updateTime='" + getNowFormatDate("-", 0) + "'");
									db.checkData('dataStorage', '*', null, function(row, err) {
										if (row.updateTime.substr(0, 4) == getNowFormatDate("-", 0).substr(0, 4)) {
											$(".refresh-hover .refresh-Result").find("i").text(getNowFormatDate("-", 0).substr(5, 11))
										} else {
											$(".refresh-hover .refresh-Result").find("i").text(getNowFormatDate("-", 0).substr(0, 16))
										}
									})
								}
							});
							db.saveData("SearchArticleList(ArticleID,ArticleTitle,SaveDate,ArtContent,Arttype,newData1,newData2,newData3)", "(?,?,?,?,?,?,?,?)", obj.articleid + ',' + removeHTMLTag(replaceCharacter(window.decodeURIComponent(obj.title))) + ',' + Number(Date.parse(new Date())) + ',' + null + ',' + Number(obj.arttype) + ',' + null + ',' + null + ',' + null)
						};
						folder($("#TreeId").val())
					} else if (data.type == "920") {
						var name = window.decodeURIComponent(data.categoryname);
						folder($("#TreeId").val())
					} else if (data.type == "921") {
						db.modifyData('CategoryMyLibrary', ' CategoryName="' + data.categoryname + '"', ' CategoryID = ' + data.categoryid, function() {
							folder($("#TreeId").val())
						})
					} else if (data.type == "922") {
						folder($("#TreeId").val())
					} else if (data.type == "923" || data.type == "924") {
						folder($("#TreeId").val())
					} else if (data.type == "934") {
						for (var i = 0; i < data.data.length; i++) {
							var obj = data.data[i];
							db.modifyData('ArticleList', ' categoryID="' + obj.tocategoryid + '"', ' articleID = ' + obj.articleid, function() {
								db.checkData('CategoryMyLibrary', '*', ' CategoryID = ' + obj.fromcategoryid, function(row, err) {
									db.modifyData('CategoryMyLibrary', ' ArtNum="' + Number(row.ArtNum - 1) + '"', ' CategoryID = ' + obj.categoryid)
								});
								db.checkData('CategoryMyLibrary', '*', ' CategoryID = ' + obj.tocategoryid, function(row, err) {
									db.modifyData('CategoryMyLibrary', ' ArtNum="' + Number(row.ArtNum + 1) + '"', ' CategoryID = ' + obj.categoryid)
								})
							});
							if (i == data.data.length - 1) {

								folder($("#TreeId").val());
								if ($(".articleSearchList-div").is(":hidden")) {
									db.checkData("ArticleList", "*", " articleID = '" + $("#divartlist>li.con").attr("aid") + "'", function(row, err) {}, function(num) {
										if (num == 0) {
											if ($("#TreeId").val() != '') {
												ArticleList(0, 50, "CategoryID=" + $("#TreeId").val(), null, null, true)
											} else {
												ArticleList(0, 50, null, null, null, true)
											}
										} else {
											var where = '';
											if ($("#TreeId").val() != '') {
												var where = " categoryID='" + $("#TreeId").val() + "' AND articleID > '" + $("#divartlist>li.con").attr("aid") + "'"
											} else {
												var where = " articleID > '" + $("#divartlist>li.con").attr("aid") + "'"
											};
											db.SearchQuery("ArticleList", "articleID,artType,ArticleTitle,keywords,Abstract,SaveDate,SaverUserID,ArtPermission,Tags,isChecked,FirstArtID,authorName,authorUserID ,resaveAuthorName,resaveAuthorUserID,categoryID,isOriginal,ArtUrl,sourceName,ReadNum,flowersNum,commentNum,saverNum,ArtContent,IsUpload,Logid,IsDelete,PrevCategoryID,IsDownLoad,downloadStatus,localImgUrl,imgDownloadStatus,IsConvert,PageNum,Purtext,Offvalue,Permitdownload,docsize,iscream,savefrom,originalActivityID,newData1,newData2,newData3", where, null, null, function(row, err) {}, function(num) {
												var page = (num / 50).toFixed(0) - 1;
												if ($("#TreeId").val() != '') {
													ArticleList(page * 50, 50, "CategoryID=" + $("#TreeId").val(), null, null, true);
													if (page > 0) {
														db.checkDataStripNumber('ArticleList', 'articleID', 50, 0, "CategoryID=" + $("#TreeId").val(), 'SaveDate desc', function(row, err) {}, function(count) {
															paging(count, 50, Number(page) + 1)
														})
													}
												} else {
													ArticleList(page * 50, 50, null, null, null, true);
													if (page > 0) {
														db.checkDataStripNumber('ArticleList', 'articleID', 50, 0, null, 'SaveDate desc', function(row, err) {}, function(count) {
															paging(count, 50, Number(page) + 1)
														})
													}
												}
											})
										}
									})
								};
								db.batchData(" dataStorage ", " updateTime='" + getNowFormatDate("-", 0) + "'");
								db.checkData('dataStorage', '*', null, function(row, err) {
									if (row.updateTime.substr(0, 4) == getNowFormatDate("-", 0).substr(0, 4)) {
										$(".refresh-hover .refresh-Result").find("i").text(getNowFormatDate("-", 0).substr(5, 11))
									} else {
										$(".refresh-hover .refresh-Result").find("i").text(getNowFormatDate("-", 0).substr(0, 16))
									}
								})
							}
						}
					} else if (data.type == "936") {
						folder($("#TreeId").val());
						for (var i = 0; i < data.data.length; i++) {
							var obj = data.data[i];
							db.deleteTableSingleData('ArticleList', ' articleID = ' + obj.articleid, function() {
								db.checkData('CategoryMyLibrary', '*', ' CategoryID = ' + obj.categoryid, function(row, err) {
									db.modifyData('CategoryMyLibrary', ' ArtNum="' + Number(row.ArtNum - 1) + '"', ' CategoryID = ' + obj.categoryid)
								});
								db.batchData('Category', ' artnum="' + (Number($("#artnum").html() - 1)) + '"', function() {
									$("#artnum").html((Number($("#artnum").html()) - 1))
								})
							});
							db.deleteTableSingleData('SearchArticleList', ' ArticleID = ' + obj.articleid);
							if (i == data.data.length - 1) {
								if ($(".articleSearchList-div").is(":hidden")) {
									db.checkData("ArticleList", "*", " articleID = '" + $("#divartlist>li.con").attr("aid") + "'", function(row, err) {}, function(num) {
										if (num == 0) {} else {
											var where = '';
											if ($("#TreeId").val() != '') {
												var where = " categoryID='" + $("#TreeId").val() + "' AND articleID > '" + $("#divartlist>li.con").attr("aid") + "'"
											} else {
												var where = " articleID > '" + $("#divartlist>li.con").attr("aid") + "'"
											};
											db.SearchQuery("ArticleList", "articleID,artType,ArticleTitle,keywords,Abstract,SaveDate,SaverUserID,ArtPermission,Tags,isChecked,FirstArtID,authorName,authorUserID ,resaveAuthorName,resaveAuthorUserID,categoryID,isOriginal,ArtUrl,sourceName,ReadNum,flowersNum,commentNum,saverNum,ArtContent,IsUpload,Logid,IsDelete,PrevCategoryID,IsDownLoad,downloadStatus,localImgUrl,imgDownloadStatus,IsConvert,PageNum,Purtext,Offvalue,Permitdownload,docsize,iscream,savefrom,originalActivityID,newData1,newData2,newData3", where, null, null, function(row, err) {}, function(num) {
												var page = (num / 50).toFixed(0) - 1;
												if ($("#TreeId").val() != '') {
													ArticleList(page * 50, 50, "CategoryID=" + $("#TreeId").val(), null, null, $("#divartlist>li.con").attr("aid"));
													if (page > 0) {
														db.checkDataStripNumber('ArticleList', 'articleID', 50, 0, "CategoryID=" + $("#TreeId").val(), 'SaveDate desc', function(row, err) {}, function(count) {
															paging(count, 50, Number(page) + 1)
														})
													}
												} else {
													ArticleList(page * 50, 50, null, null, null, $("#divartlist>li.con").attr("aid"));
													if (page > 0) {
														db.checkDataStripNumber('ArticleList', 'articleID', 50, 0, null, 'SaveDate desc', function(row, err) {}, function(count) {
															paging(count, 50, Number(page) + 1)
														})
													}
												}
											})
										}
									})
								};
								db.batchData(" dataStorage ", " updateTime='" + getNowFormatDate("-", 0) + "'");
								db.checkData('dataStorage', '*', null, function(row, err) {
									if (row.updateTime.substr(0, 4) == getNowFormatDate("-", 0).substr(0, 4)) {
										$(".refresh-hover .refresh-Result").find("i").text(getNowFormatDate("-", 0).substr(5, 11))
									} else {
										$(".refresh-hover .refresh-Result").find("i").text(getNowFormatDate("-", 0).substr(0, 16))
									}
								})
							}
						}
					} else if (data.type == "950") {
						var time = new Date(data.msgtime);
						var aid = data.articleid;
						var artId = '';
						var AstrRequestUrl = cv.post + "/ajax/article.ashx?ver=0.01&os=windows&op=gac&p=1&cid=-100&aid=" + aid;
						var sign = "&sign=" + getSign.sign(AstrRequestUrl + "&UserCode=" + myReplace(UserCode));
						$.ajax({
							url: AstrRequestUrl + sign,
							type: 'POST',
							data: {
								"UserCode": UserCode
							},
							success: function(result) {
								var dataArt = JSON.parse(result);
								if (dataArt.status == 1) {
									var row = dataArt.aInf,
										ArticleTitle = '';
									var permission = row.Permission;
									articleDownload(row.ArtType, aid, function() {});
									if (permission != 0) {
										$("#divartlist li[aid='" + aid + "']").attr("permission", permission).find("em.permissionText").html("私有").show();
										$("#Search-divartlist li[aid='" + aid + "']").attr("permission", permission).find("em.permissionText").html("私有").show()
									} else {
										$("#divartlist li[aid='" + aid + "']").attr("permission", permission).find("em.permissionText").hide();
										$("#Search-divartlist li[aid='" + aid + "']").attr("permission", permission).find("em.permissionText").hide()
									};
									db.batchData(" dataStorage ", " updateTime='" + getNowFormatDate("-", 0) + "'");
									db.checkData('dataStorage', '*', null, function(row, err) {
										if (row.updateTime.substr(0, 4) == getNowFormatDate("-", 0).substr(0, 4)) {
											$(".refresh-hover .refresh-Result").find("i").text(getNowFormatDate("-", 0).substr(5, 11))
										} else {
											$(".refresh-hover .refresh-Result").find("i").text(getNowFormatDate("-", 0).substr(0, 16))
										}
									})
								} else if (data.status == -100) {}
							},
							error: function(error) {}
						})
					} else if (data.type == "955") {
						SynchronizeArticleData()
					} else if (data.type == "949") {
						var aidList = data.articleid.split(",");
						var permission = data.permission;
						webPermissionFun(0);

						function webPermissionFun(num) {
							if (num == aidList.length) {
								db.batchData(" dataStorage ", " updateTime='" + getNowFormatDate("-", 0) + "'");
								db.checkData('dataStorage', '*', null, function(row, err) {
									if (row.updateTime.substr(0, 4) == getNowFormatDate("-", 0).substr(0, 4)) {
										$(".refresh-hover .refresh-Result").find("i").text(getNowFormatDate("-", 0).substr(5, 11))
									} else {
										$(".refresh-hover .refresh-Result").find("i").text(getNowFormatDate("-", 0).substr(0, 16))
									}
								});
								return false
							};
							var aid = aidList[num];
							db.checkData('ArticleList', '*', " articleID = '" + aid + "'", function(row, err) {
								if ((row.isOriginal == 2 || row.isOriginal == 0) && permission != 0) {
									db.modifyData('ArticleList', ' ArtPermission="' + permission + '",isOriginal="0"', ' articleID = ' + aid, function() {
										$("#divartlist li[aid='" + aid + "']").attr("permission", permission).find("em.permissionText").html("私有").show();
										if ($("#SaveArt").attr("aid") == aid) {
											$("#divartlist li[aid='" + aid + "']").trigger("click")
										}
										webPermissionFun(num + 1)
									})
								} else {
									db.modifyData('ArticleList', ' ArtPermission="' + permission + '"', ' articleID = ' + aid, function() {
										if (permission != 0) {
											$("#divartlist li[aid='" + aid + "']").attr("permission", permission).find("em.permissionText").html("私有").show()
										} else {
											$("#divartlist li[aid='" + aid + "']").attr("permission", permission).find("em.permissionText").hide()
										};
										if ($("#SaveArt").attr("aid") == aid) {
											$("#divartlist li[aid='" + aid + "']").trigger("click")
										};
										webPermissionFun(num + 1)
									})
								}
							})
						}
					} else if (data.type == "963") {
						var aidList = data.articleid.split(",");
						var permission = data.permission;
						for (var i = 0; i < aidList.length; i++) {
							var aid = aidList[i];
							db.modifyData('ArticleList', ' ArtPermission="' + permission + '",isOriginal="0"', ' articleID = ' + aid, function() {
								if (permission != 0) {
									$("#divartlist li[aid='" + aid + "']").attr("permission", permission).find("em.permissionText").html("私有").show()
								} else {
									$("#divartlist li[aid='" + aid + "']").attr("permission", permission).find("em.permissionText").hide()
								};
								if ($("#SaveArt").attr("aid") == aid) {
									$("#divartlist li[aid='" + aid + "']").trigger("click")
								};
								db.batchData(" dataStorage ", " updateTime='" + getNowFormatDate("-", 0) + "'");
								db.checkData('dataStorage', '*', null, function(row, err) {
									if (row.updateTime.substr(0, 4) == getNowFormatDate("-", 0).substr(0, 4)) {
										$(".refresh-hover .refresh-Result").find("i").text(getNowFormatDate("-", 0).substr(5, 11))
									} else {
										$(".refresh-hover .refresh-Result").find("i").text(getNowFormatDate("-", 0).substr(0, 16))
									}
								})
							})
						}
					} else if (data.type == "964") {
						var aidList = data.articleid.split(",");
						var permission = data.permission;
						for (var i = 0; i < aidList.length; i++) {
							var aid = aidList[i];
							db.modifyData('ArticleList', ' ArtPermission="' + permission + '",isOriginal="' + data.adopt + '"', ' articleID = ' + aid, function() {
								if (permission != 0) {
									$("#divartlist li[aid='" + aid + "']").attr("permission", permission).find("em.permissionText").html("私有").show()
								} else {
									$("#divartlist li[aid='" + aid + "']").attr("permission", permission).find("em.permissionText").hide()
								};
								if ($("#SaveArt").attr("aid") == aid) {
									$("#divartlist li[aid='" + aid + "']").trigger("click")
								};
								db.batchData(" dataStorage ", " updateTime='" + getNowFormatDate("-", 0) + "'");
								db.checkData('dataStorage', '*', null, function(row, err) {
									if (row.updateTime.substr(0, 4) == getNowFormatDate("-", 0).substr(0, 4)) {
										$(".refresh-hover .refresh-Result").find("i").text(getNowFormatDate("-", 0).substr(5, 11))
									} else {
										$(".refresh-hover .refresh-Result").find("i").text(getNowFormatDate("-", 0).substr(0, 16))
									}
								})
							})
						}
					} else if (data.type == "930") {
						if (data.modifyitems.userhead) {
							var PhotoSmall = decodeURIComponent(data.modifyitems.userhead).lastIndexOf("\/");
							var img_filename = decodeURIComponent(data.modifyitems.userhead).substring(PhotoSmall);
							downloadImg(Uid, decodeURIComponent(data.modifyitems.userhead));
							sh.modifyData('Users', ' userHead="' + img_filename + '"', ' UserID = ' + Uid, function() {})
						};
						if (data.modifyitems.nickname) {
							sh.modifyData('Users', ' NickName="' + decodeURIComponent(data.modifyitems.nickname) + '"', ' UserID = ' + Uid);
							NickName = decodeURIComponent(data.modifyitems.nickname);
							$("#NickName").text(NickName)
						};
						db.batchData(" dataStorage ", " updateTime='" + getNowFormatDate("-", 0) + "'");
						db.checkData('dataStorage', '*', null, function(row, err) {
							if (row.updateTime.substr(0, 4) == getNowFormatDate("-", 0).substr(0, 4)) {
								$(".refresh-hover .refresh-Result").find("i").text(getNowFormatDate("-", 0).substr(5, 11))
							} else {
								$(".refresh-hover .refresh-Result").find("i").text(getNowFormatDate("-", 0).substr(0, 16))
							}
						})
					} else if (data.type == "218") {
						message.socket.disconnect();
						AlertDialog.grayConfirmWrap("下线提示", "你的帐号在其他地方登录，如果这不是你的操作，则密码可能已经泄露，建议修改密码。", "", "确定", null, function() {
							_tray.remove();
							loginWid("app/login.html")
						}, function() {
							_tray.remove();
							loginWid("app/login.html")
						})
					} else if (data.type == "217") {
						message.socket.disconnect();
						AlertDialog.grayConfirm(0, "你的登录密码已修改，为了账号安全，请重新登录！", function() {
							_tray.remove();
							loginWid("app/login.html")
						}, function() {
							_tray.remove();
							loginWid("app/login.html")
						})
					} else if (data.type == "251") {
						AlertDialog.confirmWrap("系统提示", "对不起，该帐号已被冻结！", "你只能阅读和下载正文，无法进行其它操作！", "确定", null);
						sh.modifyData('Users', ' Isforbid="1"', ' UserID = ' + data.userid);
						Isforbid = 1;
						$(".app-edit-fl i.edit1").addClass("edit1-hui");
						$(".app-edit-fl i.edit4").addClass("edit4-hui");
						$(".app-edit-ope i.edit6").addClass("edit6-hui");
						if (!$(".writedocument").is(":hidden")) {
							$('.writedocument').hide().find("iframe").attr("src", "");
							$("#uploadFileBlock").removeClass("con")
						};
						if (!$(".editorWid").is(":hidden")) {
							clearInterval(Intervalunmsg);
							$("#randomArticlesId").val('');
							$(".editorWid").hide();
							var iframeWid = document.getElementById("myEditor").contentWindow;
							iframeWid.document.getElementById("TextBox2").value = '输入标题';
							iframeWid.document.getElementById("editor_body_area").contentWindow.document.body.innerHTML = "";
							iframeWid.document.getElementById("editor_body_textarea").value = '';
							document.getElementById("myEditor").contentWindow.document.getElementById("yctg").checked = false;
							$("#divtags ul").html('<li class="doc-inputwrap"><textarea id="txttags" class="doc-input" onkeyup="confirmtags();" onblur="tagsblur(this);" onfocus="tagsfocuse(this);" style="color: rgb(178, 178, 178); overflow: hidden; height: 25px;">添加关键词，用空格或回车分隔</textarea><div id="divtagtip" style="color: rgb(178, 178, 178); ">每个关键词最长10个字</div></li>');
							$("#txtAbstract").val("添加摘要").css("color", "#b2b2b2");
							$("#TextBox1").val("http://").css("color", "#b2b2b2");
							$(".saveload").hide();
							$(".app-edit a").removeClass("con")
						};
						if (!$(".fileModifyWind").is(":hidden")) {
							var strRequestUrl = cv.post + "/ajax/article.ashx?ver=0.01&os=windows&op=editartlock&aid=" + $("#randomArticlesId").val() + "&type=-1";
							var sign = "&sign=" + getSign.sign(strRequestUrl + "&UserCode=" + myReplace(UserCode));
							$.ajax({
								url: strRequestUrl + sign,
								type: 'POST',
								data: {
									"UserCode": UserCode
								},
								success: function(result) {
									var data = eval("(" + result + ")")
								}
							});
							$("#randomArticlesId").val("");
							$(".fileModifyWind").hide()
						}
					} else if (data.type == "252") {
						AlertDialog.confirmWrap("系统提示", "你的帐号已被解除冻结，可以正常使用！", '', "确定", null);
						sh.modifyData('Users', ' Isforbid="0"', ' UserID = ' + data.userid);
						Isforbid = 0;
						$(".app-edit-fl i.edit1").removeClass("edit1-hui");
						$(".app-edit-fl i.edit4").removeClass("edit4-hui");
						$(".app-edit-ope i.edit6").removeClass("edit6-hui")
					} else if (data.type == "931") {
						if (data.opcode == 1 || data.opcode == 2) {
							sh.modifyData('Users', ' Mobile="' + data.mobile + '",isRealname="1"', ' UserID = ' + data.userid, function() {})
						}
					} else if (data.type == "932") {
						sh.modifyData('Users', ' UNEmail="' + data.email + '"', ' UserID = ' + data.userid, function() {})
					} else if (data.type == "666") {
						var pkg = require('../package.json');
						if (tpe == 1) {
							sh.checkData('UpdateInfo', '*', null, function(row, err) {
								if (data.status == 1 && data.versionid > row.versionid) {
									$("#operation,#upgrade").addClass("NewVersionTips");
									if ($("#winTopClose").attr("type") == 1) {
										var docWindowOptions = {
											frame: false,
											width: 320,
											height: 190,
											max_width: 320,
											max_height: 190,
											min_width: 320,
											min_height: 190,
											always_on_top: true,
											transparent: true,
										};
										var winOpen1 = gui.Window.open("/app/upgradeNotice.html", docWindowOptions, function(nwwin) {
											nwwin.setShowInTaskbar(false);
											nwwin.window.moveTo(screen.availWidth, screen.availHeight);
											nwwin.on('loaded', function() {
												var a = nwwin.window.document;
												$(a).find("html body .details").text("个人图书馆最新版本V" + data.version + "已经发布！");
												$(a).find("html body .colse").click(function() {
													nwwin.close(true)
												});
												$(a).find("html body .button").click(function() {
													$("#winTopClose").attr("type", "0");
													win.show();
													PushUpgrade();
													nwwin.close(true)
												})
											})
										})
									} else {
										PushUpgrade()
									}
								}
							})
						} else {
							if (tpe == data.platform && data.versionid > pkg.versionId) {
								$("#operation,#upgrade").addClass("NewVersionTips");
								if ($("#winTopClose").attr("type") == 1) {
									var docWindowOptions = {
										frame: false,
										width: 320,
										height: 190,
										max_width: 320,
										max_height: 190,
										min_width: 320,
										min_height: 190,
										always_on_top: true,
										transparent: true,
									};
									var winOpen1 = gui.Window.open("/app/upgradeNotice.html", docWindowOptions, function(nwwin) {
										nwwin.setShowInTaskbar(false);
										nwwin.window.moveTo(screen.availWidth, screen.availHeight);
										nwwin.on('loaded', function() {
											var a = nwwin.window.document;
											$(a).find("html body .details").text("个人图书馆最新版本V" + data.version + "已经发布！");
											$(a).find("html body .colse").click(function() {
												nwwin.close(true)
											});
											$(a).find("html body .button").click(function() {
												$("#winTopClose").attr("type", "0");
												win.show();
												PushUpgrade();
												nwwin.close(true)
											})
										})
									})
								} else {
									PushUpgrade()
								}
							}
						};

						function PushUpgrade() {
							var strRequestUrl = cv.post + "/ajax/users.ashx?ver=0.01&os=windows&op=getrenewmes2&type=" + tpe;
							var sign = "&sign=" + getSign.sign(strRequestUrl);
							ajax_method(strRequestUrl + sign, null, "post", function(result) {
								var data = eval("(" + result + ")");
								$("#upgrade_title").text(data.title);
								$("#upgrade_Content").html(data.Content);
								$(".upgrade_back").show();
								$("#upgradeClose,#upgrade-cancel").click(function() {
									$(".upgrade_back").hide()
								});
								$("#upgrade-sure").unbind("click").click(function() {
									if (!navigator.onLine) {
										AlertDialog.confirm(0, "网络连接异常，请稍后重试！");
										return false
									};
									var new_win = gui.Window.open("/app/upgrade1.html", {
										position: 'center',
										frame: false,
										width: 455,
										height: 332,
										max_width: 455,
										max_height: 332,
										min_width: 455,
										min_height: 332,
										always_on_top: true,
									});
									win.close(true)
								})
							})
						}
					}
				})
			})
		}
	};
	db.batchData(" dataStorage ", " privatePopup=0");
	db.GetTable("dataStorage", function(row) {
		if (row == 0) {
			db.CreateTable("dataStorage", "fontSize text,bakColor text,isOpenLog INTEGER,logId INTEGER,key text,privatePopup INTEGER,updateTime text,newData1 text,newData2 text,newData3 text", function(callback) {
				if (callback) {
					db.saveData("dataStorage(fontSize,bakColor,isOpenLog,logId,key,privatePopup,updateTime,newData1,newData2,newData3)", "(?,?,?,?,?,?,?,?,?,?)", '16,5,0,0,null,0,' + getNowFormatDate("-", 0) + ',null,null,null', function() {
						var strRequestUrl = cv.post + "/ajax/Sync.ashx?ver=0.01&os=windows&op=openlog";
						var sign = "&sign=" + getSign.sign(strRequestUrl + "&UserCode=" + myReplace(UserCode));
						$.ajax({
							url: strRequestUrl + sign,
							type: 'POST',
							data: {
								"UserCode": UserCode
							},
							success: function(result) {
								var data = eval("(" + result + ")");
								if (data.status == 1) {
									db.batchData(" dataStorage ", " isOpenLog=1")
								}
							},
							error: function(error) {
								AlertDialog.confirm(0, "系统繁忙，请稍后重试！")
							}
						});
						db.batchData(" dataStorage ", "key='" + clientid + "'");
						message.socket.disconnect();
						message.initsocket(clientid, UserCode)
					})
				}
			})
		} else {
			db.checkData('dataStorage', '*', null, function(row, err) {
				if (row.isOpenLog == 0) {
					var strRequestUrl = cv.post + "/ajax/Sync.ashx?ver=0.01&os=windows&op=openlog";
					var sign = "&sign=" + getSign.sign(strRequestUrl + "&UserCode=" + myReplace(UserCode));
					var permissionName = null;
					$.ajax({
						url: strRequestUrl + sign,
						type: 'POST',
						data: {
							"UserCode": UserCode
						},
						success: function(result) {
							var data = eval("(" + result + ")");
							if (data.status == 1) {
								db.batchData(" dataStorage ", " isOpenLog=1")
							}
						}
					})
				};
				if (row.key == "null") {
					db.batchData(" dataStorage ", "key='" + clientid + "'");
					message.socket.disconnect();
					message.initsocket(clientid, UserCode)
				} else {
					message.socket.disconnect();
					message.initsocket(row.key, UserCode)
				}
			})
		}
	})
});
fs.mkdir(dataPath + '/' + uId + '/file1', function(err) {
	if (err) {
		console.log(err)
	} else {
		console.log("创建成功")
	}
});
$(window).resize(function() {
	$(".writedocument,#writedocument").css("height", $(".app-library").height());
	$("html,body").css("height", $(window).height() - 2);
	sh.modifyData('usersInfo', ' isWinFull="0",winWidth="' + $(window).width() + '",winHeight="' + $(window).height() + '"', ' UserID = ' + uId);
	if ($("#lastart").is(":hidden") && $("#nextart").is(":hidden")) {
		var fileCenterHeight = $(".article_file_container").offset().top + 22
	} else if ((!$("#lastart").is(":hidden") && $("#nextart").is(":hidden")) || ($("#lastart").is(":hidden") && !$("#nextart").is(":hidden"))) {
		var fileCenterHeight = $(".article_file_container").offset().top + 52
	} else if (!$("#lastart").is(":hidden") && !$("#nextart").is(":hidden")) {
		var fileCenterHeight = $(".article_file_container").offset().top + 77
	}
	$(".article_file_container").find("iframe").css("height", $(window).height() - fileCenterHeight + "px");
	$("#article_file_container").css("height", $(window).height() - 42 + "px");
	$(".drag-left").css("width", $(".app-top-fr").offset().left);
	$(".drag-right").css("width", $("body").width() - $(".app-top-tab").offset().left - $(".app-top-tab").width() - 300);
	var width = $(this).width();
	var height = $(this).height();
	if ($("#articlePage").is(":hidden")) {
		$(".app-screen-articleList").css("height", $(window).height() - 170 + "px");
		$(".Search-screen-articleList").css("height", $(window).height() - 190 + "px")
	} else {
		$(".app-screen-articleList").css("height", $(window).height() - 193 + "px");
		$(".Search-screen-articleList").css("height", $(window).height() - 230 + "px")
	};
	if ($(".app-tree-list").height() > ($(window).height() - 170)) {
		$(".app-tree-list").css("height", $(window).height() - 170 + "px")
	} else {
		$(".app-tree-list").css({
			"maxHeight": $(window).height() - 170 + "px",
			"minHeight": "auto",
			"height": "auto"
		})
	};
	if ($(window).width() > $(".app-article-Center").width() + 565) {
		$(".app-article-Center").css("minHeight", $(window).height() - 132 + "px")
	} else {
		$(".app-article-Center").css("minHeight", $(window).height() - 140 + "px")
	};
	$(".previewWid-article-Center").css("height", $(window).height() - 105 + "px");
	$(".app-library").css("height", $(window).height() - 105 + "px");
	$(".wjjsxtree").css("height", $(window).height() - 209 + "px");
	$("#tree-iframe").css("height", $(window).height() - 110 + "px");
	if (($(".app-tree-list").offset().top + $(".app-tree-list").height()) < ($(".app-tree-list").height() + $(".app-tree-list").offset().top)) {
		$("#divhighlights").parent().css("top", -($(window).height() - ($(".app-tree-list").offset().top + $(".app-tree-list").height()) - 75))
	} else {
		$("#divhighlights").parent().css("top", 0)
	};
	$(".app-float-articleList").css("height", $(window).height() - 252 + "px");
	$(".app-float-download-articleList").css("height", $(window).height() - 200 + "px");
	$(".app-article-tree").css("height", $(window).height() - 232 + "px");
	$(".big_wen").css("height", $(window).height() - 103 + "px");
	$("#divabstract").css("height", $(window).height() - 471 + "px");
	$("#modify-txtAbstract").css("height", $(window).height() - 503 + "px");
	if ($(".app-article-Center").width() < 580) {
		$(".article_file_container iframe").contents().find(".file_fileSize").hide()
	} else {
		$(".article_file_container iframe").contents().find(".file_fileSize").show()
	};
	$(".doc-tags").css({
		height: "54px"
	});
	$("#divtree").css({
		height: "" + $(window).height() - 353 + "px"
	});
	$(".doc360ul03").css({
		height: "" + ($(window).height() - 393) + "px"
	})
});
window.ondragover = function(e) {
	e.preventDefault();
	return false
};
window.ondrop = function(e) {
	e.preventDefault();
	e.stopPropagation();
	if (e.dataTransfer.files[0] == undefined) {
		return false
	};
	var fileName = e.dataTransfer.files[0].name;
	var filePath = e.dataTransfer.files[0].path;
	var fileSize = e.dataTransfer.files[0].size;
	var fileData1 = e.dataTransfer.files[0];
	if (!$(".editorWid").is(":hidden")) {
		var iframeWid = document.getElementById("myEditor").contentWindow;
		if ((iframeWid.document.getElementById("TextBox2").value == '' || iframeWid.document.getElementById("TextBox2").value == '输入标题') && iframeWid.document.getElementById("editor_body_area").contentWindow.document.body.innerHTML.length == 0) {
			LogoutEditor1();
			if ($("#TreeId").val() == "999999999999") {
				draftArticleList()
			};
			folder($("#TreeId").val());
			dragDrop();
			return false
		};
		$(".bgpop").show();
		AlertDialog.confirmEdit("你的文章还未保存发表，确定要离开编辑页面吗？", '离开此页', '留在此页', function() {
			LogoutEditor1();
			if ($("#TreeId").val() == "999999999999") {
				draftArticleList()
			};
			folder($("#TreeId").val());
			dragDrop()
		});
		return false
	};
	dragDrop();

	function dragDrop() {
		if ($(".writedocument").is(":hidden")) {
			$(".writedocument,#writedocument").css("height", $(".app-library").height());
			if (lastname(fileName)) {
				if (fileSize > 20971520) {
					AlertDialog.grayConfirm(0, "选择的文档过大，仅支持20M以内的文档上传！", function() {
						$(".writedocument").show().find("iframe").attr("src", "uploadFile.html?uId=" + uId + "&IsLogin=" + IsLogin + "&UserCode=" + UserCode)
					}, function() {
						$(".writedocument").show().find("iframe").attr("src", "uploadFile.html?uId=" + uId + "&IsLogin=" + IsLogin + "&UserCode=" + UserCode)
					});
					return false
				};
				$(".writedocument").show().find("iframe").attr("src", "uploadFile.html?uId=" + uId + "&IsLogin=" + IsLogin + "&UserCode=" + UserCode);
				$("#hidFilePath1").val(filePath);
				$("#hidFileName1").val(fileName);
				$("#hidFileSize1").val(fileSize);
				fileData = fileData1
			} else {
				AlertDialog.grayConfirm(0, "文档格式不正确，上传失败！", function() {
					$(".writedocument").show().find("iframe").attr("src", "uploadFile.html?uId=" + uId + "&IsLogin=" + IsLogin + "&UserCode=" + UserCode)
				}, function() {
					$(".writedocument").show().find("iframe").attr("src", "uploadFile.html?uId=" + uId + "&IsLogin=" + IsLogin + "&UserCode=" + UserCode)
				})
			}
		}
	};
	return false
};
var artTotal = 0,
	Increasing = 0,
	Initialization = 0;

function participate() {
	if ($("#originalActivityID").val() == '') {
		AlertDialog.confirm(0, "请勾选想参加的活动！")
	} else {
		$(".originaltip-win").hide();
		$("#yc__step2").hide();
		$("#yc__step1").show();
		$("#activitylist").html("")
	}
};

function noParticipate() {
	$("#originalActivityID").val("");
	$("#yc__step2 input[name='activities']").removeAttr("checked");
	$(".originaltip-win").hide();
	$("#yc__step2").hide();
	$("#yc__step1").show();
	$("#activitylist").html("")
};
$(function() {
	var strRequestUrl = cv.post + "/ajax/users.ashx?ver=0.01&os=windows&op=getrenewmes2&type=" + tpe;
	var sign = "&sign=" + getSign.sign(strRequestUrl);
	ajax_method(strRequestUrl + sign, null, "post", function(result) {
		var data = eval("(" + result + ")");
		var pkg = require('../package.json');
		if (tpe == 1) {
			sh.checkData('UpdateInfo', '*', null, function(row, err) {
				if (data.status == 1 && parseInt(data.versionid) > parseInt(row.versionid)) {
					$("#operation,#upgrade").addClass("NewVersionTips")
				}
			})
		} else {
			if (data.status == 1 && parseInt(data.versionid) > parseInt(pkg.versionId)) {
				$("#operation,#upgrade").addClass("NewVersionTips")
			}
		}
	});
	$("#yc__step1 a").unbind("click").click(function() {
		if ($(this).attr("data-href")) {
			OpenNewWindow($(this).attr("data-href"))
		}
	});
	$("#yc__step1 .rbtn_confirm_s").click(function() {
		if (!navigator.onLine) {
			$(".originaltip-win").hide();
			$("#activitylist").append("");
			return false
		};
		var strRequestUrl = cv.post + "/ajax/article.ashx?op=getactivitylist";
		var sign = "&sign=" + getSign.sign(strRequestUrl + "&UserCode=" + myReplace(UserCode));
		$.ajax({
			url: strRequestUrl + sign,
			type: 'POST',
			data: {
				"UserCode": UserCode
			},
			success: function(result) {
				if (result != -1 && result != '[]' && result != "") {
					var data = JSON.parse(result);
					if (data != null) {
						activityHtml(data.activitylist);
						$("#yc__step1").hide();
						$("#yc__step2").show()
					}
				} else {
					$(".originaltip-win").hide();
					$("#activitylist").html("")
				}
			},
			error: function() {
				$(".originaltip-win").hide();
				$("#activitylist").html("")
			}
		})
	});
	$("#originaltip .chas,#originaltip #yc__step1 .rbtn_cancel_s").click(function() {
		originaltipColse()
	});

	function activityHtml(jsonArr, num) {
		var i = num || 0;
		if (i >= jsonArr.length) {
			return
		};
		var on = jsonArr[i];
		var lihtm = '';
		lihtm += '<tr><td><input type="radio" name="activities" value="' + on.activityid + '" /></td><td style="text-align: left;padding: 0 8px;"><a data-href="http://www.360doc.com/pages/activity/activity' + on.activityid + '.html" data-id="' + on.activityid + '" >' + decodeURIComponent(on.activityname) + '</a></td><td style="text-align: left;padding: 0 8px;">' + decodeURIComponent(on.activitydesc) + '</td></tr>';
		$("#activitylist").append(lihtm);
		$("#yc__step2 input").unbind("click").click(function() {
			var _this = $(this);
			clickActivity(_this.val())
		});
		$("#yc__step2 a").unbind("click").click(function() {
			$('#yc__step2 input[type=radio][name=activities][value=' + $(this).attr("data-id") + ']').click();
			if ($(this).attr("data-href")) {
				OpenNewWindow($(this).attr("data-href"))
			}
		});
		i++;
		activityHtml(jsonArr, i)
	};

	function clickActivity(activityid, fun) {
		var strRequestUrl = cv.post + "/ajax/article.ashx?ver=0.01&os=windows&op=getactivitypermit&activityid=" + activityid;
		var sign = "&sign=" + getSign.sign(strRequestUrl + "&UserCode=" + myReplace(UserCode));
		$.ajax({
			url: strRequestUrl + sign,
			type: 'POST',
			data: {
				"UserCode": UserCode
			},
			success: function(result) {
				var data = eval("(" + result + ")");
				if (data.status) {
					if (data.permit == -1) {
						$(".winBgpop").show();
						AlertDialog.confirmWrap("系统提示", "该征文活动最多可投" + data.artlimit + "篇原创文章，你的投稿次数已达上限！", "", "我知道了", null, function() {
							$(".winBgpop").hide()
						});
						$("#comClose").click(function() {
							$(".winBgpop").hide()
						});
						$('#activitylist input[type=radio][name=activities][value=' + activityid + ']').attr('checked', false)
					} else {
						$('#activitylist input[type=radio][name=activities][value=' + activityid + ']').attr('checked', 'checked');
						$("#originalActivityID").val(activityid)
					}
				}
			},
			error: function() {
				AlertDialog.confirm(0, "系统繁忙，请稍后重试！")
			}
		})
	};

	function warningFun() {
		var strRequestUrl = cv.post + "/ajax/sysmessage.ashx?ver=0.01&os=windows&op=getalertmessageinfo";
		var sign = "&sign=" + getSign.sign(strRequestUrl + "&UserCode=" + myReplace(UserCode));
		$.ajax({
			url: strRequestUrl + sign,
			type: 'POST',
			data: {
				"UserCode": UserCode
			},
			success: function(result) {
				var data = eval("(" + result + ")");
				if (data.status == 1 && data.alertmessagelist.length > 0) {
					warning(0);

					function warning(list) {
						if (!data.alertmessagelist[list]) {
							var strRequestUrl = cv.post + "/ajax/users.ashx?ver=0.01&os=windows&op=login&c1=" + myEncode(NickName) + "&c2=" + $.md5(address);
							var sign = "&sign=" + getSign.sign(strRequestUrl);
							$.ajax({
								url: strRequestUrl + sign,
								type: 'POST',
								data: {},
								success: function(result) {
									var data = eval("(" + result + ")");
									if (data.status == -2) {
										AlertDialog.confirmWrap("系统提示", "对不起，该帐号已被冻结！", "你只能阅读和下载正文，无法进行其它操作！", "确定", null);
										sh.modifyData('Users', ' Isforbid="1"', ' UserID = ' + Uid);
										Isforbid = 1
									}
								}
							});
							return false
						};
						var AlertContent = "";
						if (data.alertmessagelist[list].content.articleid != '') {
							AlertContent = "根据审核记录和馆友举报，你收藏的 <a data-href='http://www.360doc.com/showweb/0/0/" + decodeURIComponent(data.alertmessagelist[list].content.articleid) + ".aspx'>" + decodeURIComponent(data.alertmessagelist[list].content.articletitle) + "</a> 文章"
						};
						AlertDialog.warning(NickName + "馆友：", AlertContent + decodeURIComponent(data.alertmessagelist[list].content.reason), function() {
							warning(list + 1);
							var strRequestUrl = cv.post + "/ajax/sysmessage.ashx?ver=0.01&os=windows&op=setalertmessagestatus&id=" + data.alertmessagelist[list].id;
							var sign = "&sign=" + getSign.sign(strRequestUrl + "&UserCode=" + myReplace(UserCode));
							$.ajax({
								url: strRequestUrl + sign,
								type: 'POST',
								data: {
									"UserCode": UserCode
								},
								success: function(result) {}
							})
						});
						$(".warning a").unbind("click").click(function() {
							OpenNewWindow($(this).attr("data-href"))
						})
					}
				} else {
					var strRequestUrl = cv.post + "/ajax/users.ashx?ver=0.01&os=windows&op=login&c1=" + myEncode(NickName) + "&c2=" + $.md5(address);
					var sign = "&sign=" + getSign.sign(strRequestUrl);
					$.ajax({
						url: strRequestUrl + sign,
						type: 'POST',
						data: {},
						success: function(result) {
							var data = eval("(" + result + ")");
							if (data.status == -2) {
								AlertDialog.confirmWrap("系统提示", "对不起，该帐号已被冻结！", "你只能阅读和下载正文，无法进行其它操作！", "确定", null);
								sh.modifyData('Users', ' Isforbid="1"', ' UserID = ' + Uid);
								Isforbid = 1
							}
						}
					})
				}
			}
		})
	};

	function originaltipColse() {
		$("#activitylist").html("");
		$("#originalActivityID").val("");
		$("#yc__step2 input[name='activities']").removeAttr("checked");
		$(".originaltip-win").hide();
		$("#yc__step2").hide();
		$("#yc__step1").show();
		document.getElementById("myEditor").contentWindow.document.getElementById("yctg").checked = false;
		document.getElementById("writedocument").contentWindow.document.getElementById("yctg").checked = false
	};
	gui.App.on('open', function(argString) {
		gui.Window.get().show()
	});
	$("#signal").hover(function() {
		if ($("#signal").is(".net")) {
			$(".signal-text").fadeIn("slow").text("网络良好")
		} else {
			$(".signal-text").fadeIn("slow").text("网络异常")
		}
	}, function() {
		$(".signal-text").fadeOut("slow")
	});
	$("html,body").css("height", $(window).height() - 2);
	$("#InitializationStopClose").click(function() {
		$("#InitializationStop").hide()
	});

	function noviceGuidance(type) {
		$("#Initialization").hide();
		if (Initialization == 1) {
			return false
		};
		$(".noviceGuidance").show().find("div").click(function(event) {
			event.stopImmediatePropagation();
			$(this).hide();
			$(this).next().show();
			if ($(this).index() == 4) {
				Initialization = 1;
				$(".noviceGuidance").hide();
				warningFun();
				if (type == 1) {
					$("#InitializationStop").show();
					$("#InitializationStopClose").click(function() {
						$("#InitializationStop").hide()
					});
					if ($("#InitializationStop i").text() == "初始化完成！") {
						setTimeout(function() {
							$("#InitializationStop").hide()
						}, 3000)
					}
				}
			}
		});
		$(".noviceGuidance5 a").unbind("click").click(function(event) {
			event.stopImmediatePropagation();
			$(".noviceGuidance5").hide();
			$(".noviceGuidance1").show()
		})
	};
	$("#divartlist").hover(function() {
		if ($(this).height() > $(".app-screen-articleList").height()) {
			$(this).find("em.IsUpload").addClass("right")
		}
	}, function() {
		$(this).find("em.IsUpload").removeClass("right")
	});
	$("#myEditor").attr("UserCode", UserCode);
	var Sync = null;
	$(".drag-left").css("width", $(".app-top-fr").offset().left);
	$(".drag-right").css("width", $("body").width() - $(".app-top-tab").offset().left - $(".app-top-tab").width() - 300);
	sh.userCheckData('Users', '*', " UserID = '" + uId + "'", function(row, err) {
		if (row.userHead) {
			$("#userHead").attr("src", "file:" + process.cwd() + '/app/img/' + row.userHead)
		} else {
			$("#userHead").attr("src", "/app/img/userHead.png")
		};
		$("#starRank").attr("class", 'score' + row.starRank);
		$("#NickName").html(row.NickName);
		sh.checkData('UpdateInfo', '*', null, function(row, err) {
			$("#statisticsImg").attr("src", "http://eclick.360doc.com/pcclient.jpg?code=37-1&userCode=" + UserCode + "&version=" + row.version)
		})
	});
	showFileDiv();
	db.GetTable("ArticleList", function(row) {
		if (row == 0) {
			db.SearchCreateTable("SearchArticleList", "ArticleID,ArticleTitle=simple,SaveDate ,ArtContent=simple,Arttype INTEGER,newData1 text,newData2 text,newData3 text");
			db.CreateTable("ArticleList", "articleID INTEGER,artType INTEGER,ArticleTitle text,keywords text,Abstract text,SaveDate INTEGER,SaverUserID INTEGER,ArtPermission INTEGER,Tags text,isChecked INTEGER,FirstArtID INTEGER,authorName text,authorUserID text,resaveAuthorName text,resaveAuthorUserID INTEGER,categoryID INTEGER,isOriginal INTEGER,ArtUrl text,sourceName text,ReadNum INTEGER,flowersNum INTEGER,commentNum INTEGER,saverNum INTEGER,ArtContent text,IsUpload INTEGER,Logid  text,IsDelete INTEGER,PrevCategoryID INTEGER,IsDownLoad text,downloadStatus INTEGER,localImgUrl text,imgDownloadStatus INTEGER,IsConvert INTEGER,PageNum INTEGER,Purtext text,Offvalue INTEGER,Permitdownload INTEGER,docsize INTEGER,iscream INTEGER,savefrom INTEGER,originalActivityID text,newData1 text,newData2 text,newData3 text", function() {
				db.tableIndexes("indexName","ArticleList","articleID");
				var strRequestUrl = cv.post + "/ajax/Category.ashx?ver=0.01&os=windows&op=syncCategorynew&t=0";
				var sign = "&sign=" + getSign.sign(strRequestUrl + "&UserCode=" + myReplace(UserCode));
				$.ajax({
					url: strRequestUrl + sign,
					type: 'post',
					data: {
						"UserCode": UserCode
					},
					success: function(result) {
						var data = eval('(' + result + ')');
						if (data.status == 1) {
							artTotal = data.artnum;
							$("#Initialization").show();
							$("#InitializationClose,#InitializationSure").click(function() {
								if ($("#InitializationSure").text() != "初始化完成") {
									$("#InitializationStop").attr("type", 1);
									noviceGuidance(1)
								} else {
									noviceGuidance(0)
								}
							});
							ArticleListDataInt(2, 100, 0)
						}
					}
				})
			})
		} else {
			warningFun();
			Initialization = 1;
			Sync == 0;
			if (isInitialization != 100 && isInitialization != null && isInitialization != "null") {
				$("#InitializationStop").show();
				$("#InitializationStop em").text(isInitialization + "%")
			};
			var strRequestUrl = cv.post + "/ajax/Category.ashx?ver=0.01&os=windows&op=syncCategorynew&t=0";
			var sign = "&sign=" + getSign.sign(strRequestUrl + "&UserCode=" + myReplace(UserCode));
			$.ajax({
				url: strRequestUrl + sign,
				type: 'post',
				data: {
					"UserCode": UserCode
				},
				success: function(result) {
					var data = eval('(' + result + ')');
					if (data.status == 1) {
						artTotal = data.artnum;
						db.checkDataSort('ArticleList', '*', ' articleID desc limit 1', function(data, err) {
							db.dataNull('ArticleList', function(err, id) {
								Increasing = id
							})
						})
					}
				}
			});
			ArticleList(0, 50, null, null, null, true);
			db.dataNull('ArticleList', function(err, id) {
				if (id == 0) {
					SynchronizeArticleData()
				} else {
					if (navigator.onLine) {
						db.checkDataSort('ArticleList', '*', ' articleID desc limit 1', function(data, err) {
							PushArticleList1(2, 100, data.articleID + 1)
						})
					} else {
						$(".refresh").attr("class", "refresh refresh2");
						$(".refresh-hover .refresh-execution").addClass("none");
						$(".refresh-hover .refresh-Result").addClass("block").find("b").html("网络异常，无法同步");
						db.checkData('dataStorage', '*', null, function(row, err) {
							$(".refresh-hover .refresh-Result").find("i").text(row.updateTime.substr(5, 11))
						})
					}
				}
			})
		}
	});
	db.GetTable("publishArticleList", function(row) {
		if (row == 0) {
			db.CreateTable("publishArticleList", "localArticleID INTEGER,ArtPermission INTEGER,URL text,ArticleTitle text,categoryID INTEGER,device text,artType INTEGER,userCode text,ArtContent text,CreateTime INTEGER,LocalPath text,ImagePath text,keywords text,Abstract text,isOriginal INTEGER,docsize INTEGER,docscore INTEGER,docfilename text,docpermitdownload INTEGER,originalActivityID text,newData1 text,newData2 text,newData3 text")
		}
	});
	db.GetTable("logArticleList", function(row) {
		if (row == 0) {
			db.CreateTable("logArticleList", "localArticleID INTEGER,ArtPermission INTEGER,ArticleTitle text,artType INTEGER,ArtContent text,oldcontent text,keywords text,Abstract text,docscore INTEGER,olddocscore INTEGER,docpermitdownload INTEGER,olddocpermitdownload INTEGER,newData1 text,newData2 text,newData3 text")
		}
	});
	db.GetTable("draftCreate", function(row) {
		if (row == 0) {
			db.CreateTable("draftCreate", "articleID INTEGER,artType INTEGER,ArticleTitle text,keywords text,Abstract text,SaveDate INTEGER,SaverUserID INTEGER,ArtPermission INTEGER,Tags text,authorName text,authorUserID text,categoryID INTEGER,isOriginal INTEGER,ArtUrl text,sourceName text,ArtHtml text,Offvalue INTEGER,Permitdownload INTEGER,originalActivityID text,newData1 text,newData2 text,newData3 text")
		}
	});
	EventUtil.addHandler(window, "online", function() {
		$("#signal").addClass("net")
	});
	EventUtil.addHandler(window, "offline", function() {
		$("#signal").removeClass("net");
		message.socket.disconnect();
		message.socket.destroy()
	});
	if (navigator.onLine) {} else {
		$("#signal").removeClass("net")
	};

	function exitAccount() {
		AlertDialog.grayConfirm(1, "你确定要退出，切换其它帐号登录吗？", function() {
			deleteall(dataPath + "/" + uId + "/file1/");
			sh.checkData('AtuoLogin', '*', null, function(data, err) {
				if (data.IsAutoLogin == "1") {
					sh.batchData('AtuoLogin', ' IsAutoLogin="0"')
				};
				loginWid("app/login.html");
				_tray.remove();
				_tray = null
			})
		})
	};
	$("#exitAccount").click(function() {
		if ($("#app-article-download-win-show .edit7").is(".download")) {
			AlertDialog.confirm(1, "你当前有下载任务正在进行，确认退出？点击确定将中断下载。", function() {
				AlertDialog.confirm(1, "你确定要退出，切换其它帐号登录吗？", function() {
					deleteall(dataPath + "/" + uId + "/file1/");
					sh.checkData('AtuoLogin', '*', null, function(data, err) {
						if (data.IsAutoLogin == "1") {
							sh.batchData('AtuoLogin', ' IsAutoLogin="0"')
						};
						loginWid("app/login.html");
						_tray.remove();
						_tray = null
					})
				})
			})
		} else {
			if (!$(".writedocument").is(":hidden")) {
				if (($(window.frames["writedocument"].document).find("#TextBox3").val() == '' || $(window.frames["writedocument"].document).find("#TextBox3").val() == '输入标题') && $(window.frames["writedocument"].document).find("#hidFileName").val() == '') {
					exitAccount();
					return false
				};
				$(".bgpop").show();
				AlertDialog.confirmEdit("你的文档还未保存发表，确定要离开编辑页面吗？", '离开此页', '留在此页', function() {
					folder($("#TreeId").val());
					$('.writedocument').hide().find("iframe").attr("src", "");
					$("#uploadFileBlock").removeClass("con");
					exitAccount()
				});
				return false
			};
			if (!$(".editorWid").is(":hidden")) {
				var iframeWid = document.getElementById("myEditor").contentWindow;
				if ((iframeWid.document.getElementById("TextBox2").value == '' || iframeWid.document.getElementById("TextBox2").value == '输入标题') && iframeWid.document.getElementById("editor_body_area").contentWindow.document.body.innerHTML.length == 0) {
					exitAccount();
					return false
				};
				$(".bgpop").show();
				AlertDialog.confirmEdit("你的文章还未保存发表，确定要离开编辑页面吗？", '离开此页', '留在此页', function() {
					clearInterval(Intervalunmsg);
					LogoutEditor1();
					if ($("#TreeId").val() == "999999999999") {
						draftArticleList()
					};
					folder($("#TreeId").val());
					exitAccount()
				});
				return false
			};
			if (!$(".fileModifyWind").is(":hidden")) {
				AlertDialog.confirmEdit("你的文章还未保存发表，确定要离开编辑页面吗？", '离开此页', '留在此页', function() {
					var strRequestUrl = cv.post + "/ajax/article.ashx?ver=0.01&os=windows&op=editartlock&aid=" + $("#randomArticlesId").val() + "&type=-1";
					var sign = "&sign=" + getSign.sign(strRequestUrl + "&UserCode=" + myReplace(UserCode));
					$.ajax({
						url: strRequestUrl + sign,
						type: 'POST',
						data: {
							"UserCode": UserCode
						},
						success: function(result) {
							var data = eval("(" + result + ")")
						}
					});
					$("#randomArticlesId").val("");
					$(".fileModifyWind").hide();
					exitAccount()
				});
				return false
			};
			if ($("#randomArticlesId").val() != '') {
				if (navigator.onLine) {
					var strRequestUrl = cv.post + "/ajax/article.ashx?ver=0.01&os=windows&op=editartlock&aid=" + $("#randomArticlesId").val() + "&type=-1";
					var sign = "&sign=" + getSign.sign(strRequestUrl + "&UserCode=" + myReplace(UserCode));
					$.ajax({
						url: strRequestUrl + sign,
						type: 'POST',
						data: {
							"UserCode": UserCode
						},
						success: function(result) {
							var data = eval("(" + result + ")");
							exitAccount()
						},
						error: function() {
							exitAccount()
						}
					})
				} else {
					exitAccount()
				}
			} else {
				exitAccount()
			}
		}
	});
	var startOnBoot = require('./startOnBoot');
	sh.checkData('usersInfo', '*', "UserID = '" + uId + "'", function(info, err) {
		if (info.isWinFull == 1) {
			win.maximize();
			$("#winMaximize").attr("maximize", "2")
		} else {
			win.setMaximumSize(screen.availWidth, screen.availHeight);
			win.setMinimumSize(970, 430);
			win.setResizable(true)
		}
		if (info.isLogOn == 1) {
			startOnBoot.disableAutoStart('360doc')
		} else {
			startOnBoot.enableAutoStart('360doc', process.execPath)
		}
	});
	$(".app-library").css("height", $(window).height() - 105 + "px");
	if ($("#articlePage").is(":hidden")) {
		$(".app-screen-articleList").css("height", cv["winH"] - 170 + "px");
		$(".Search-screen-articleList").css("height", cv["winH"] - 190 + "px")
	} else {
		$(".app-screen-articleList").css("height", cv["winH"] - 193 + "px");
		$(".Search-screen-articleList").css("height", cv["winH"] - 220 + "px")
	};
	if ($(".app-tree-list").height() > ($(window).height() - 170)) {
		$(".app-tree-list").css("height", cv["winH"] - 170 + "px")
	} else {
		$(".app-tree-list").css({
			"maxHeight": cv["winH"] - 170 + "px",
			"minHeight": "auto",
			"height": "auto"
		})
	};
	$(".app-article-Center").css("minHeight", $(window).height() - 132 + "px");
	$(".previewWid-article-Center").css("height", cv["winH"] - 105 + "px");
	$("#tree-iframe").css("height", cv["winH"] - 110 + "px");
	$(".app-float-articleList").css("height", cv["winH"] - 252 + "px");
	$(".app-float-download-articleList").css("height", $(window).height() - 200 + "px");
	$(".app-article-tree").css("height", cv["winH"] - 225 + "px");
	$(".big_wen").css("height", $(window).height() - 103 + "px");
	$(".originalRule").unbind("click").click(function() {
		OpenNewWindow($(this).attr("data-href"))
	});
	$(".refresh").click(function() {
		if ($(".refresh").hasClass('refresh1') || $(".refresh").hasClass('refresh2')) {
			db.dataNull('ArticleList', function(err, rowId) {
				if (rowId == 0) {
					$(".refresh-signal>span.refresh").removeClass("refresh1");
					setTimeout(function() {
						$(".refresh-signal>span.refresh").addClass("refresh1")
					}, 500);
					db.batchData(" dataStorage ", " updateTime='" + getNowFormatDate("-", 0) + "'");
					db.checkData('dataStorage', '*', null, function(row, err) {
						if (row.updateTime.substr(0, 4) == getNowFormatDate("-", 0).substr(0, 4)) {
							$(".refresh-hover .refresh-Result").find("i").text(getNowFormatDate("-", 0).substr(5, 11))
						} else {
							$(".refresh-hover .refresh-Result").find("i").text(getNowFormatDate("-", 0).substr(0, 16))
						}
					})
				};
				db.checkDataSort('ArticleList', '*', ' articleID desc limit 1', function(data, err) {
					PushArticleList1(2, 100, data.articleID + 1)
				})
			})
		}
	});
	$(".refresh").hover(function() {
		$(".refresh-hover").fadeIn("slow")
	}, function() {
		$(".refresh-hover").fadeOut("slow")
	});
	$("#home").click(function() {
		if (!$(".indexPublishSuccessImg").is(":hidden")) {
			return false
		};
		if (!$("#app-article-float-download").is(":hidden")) {
			if ($(".downloadList>.downloadList-fr span.state").text().indexOf("正在下载") > -1) {
				AlertDialog.confirm(1, "你当前有下载任务正在进行，确认退出？点击确定将中断下载。", function() {
					$(".app-edit a").removeClass("con");
					$("#app-article-float-download").hide();
					$(".app-float-download-articleList").html("");
					$("#app-article-download-win-show i").removeClass("download")
				})
			} else {
				$(".app-edit a").removeClass("con");
				$("#app-article-float-download").hide();
				$(".app-float-download-articleList").html("");
				$("#app-article-download-win-show i").removeClass("download")
			};
			return false
		};
		$("#app-article-float,#app-article-float-download,.app-article-tree-float").hide();
		$("#app-tree-float").removeClass("block");
		var zTree = $.fn.zTree.getZTreeObj("treelist");
		var zTreeB = zTree.getNodeByParam("id", 1, null);
		zTree.expandNode(zTreeB, true, false, false);
		$("#filetreelist").html("");
		if (!$(".writedocument").is(":hidden")) {
			if (($(window.frames["writedocument"].document).find("#TextBox3").val() == '' || $(window.frames["writedocument"].document).find("#TextBox3").val() == '输入标题') && $(window.frames["writedocument"].document).find("#hidFileName").val() == '') {
				folder($("#TreeId").val());
				$('.writedocument').hide().find("iframe").attr("src", "");
				$("#uploadFileBlock").removeClass("con");
				return false
			};
			$(".bgpop").show();
			AlertDialog.confirmEdit("你的文档还未保存发表，确定要离开编辑页面吗？", '离开此页', '留在此页', function() {
				folder($("#TreeId").val());
				$('.writedocument').hide().find("iframe").attr("src", "");
				$("#uploadFileBlock").removeClass("con")
			});
			return false
		};
		if (!$(".editorWid").is(":hidden")) {
			var iframeWid = document.getElementById("myEditor").contentWindow;
			if ((iframeWid.document.getElementById("TextBox2").value == '' || iframeWid.document.getElementById("TextBox2").value == '输入标题') && iframeWid.document.getElementById("editor_body_area").contentWindow.document.body.innerHTML.length == 0) {
				clearInterval(Intervalunmsg);
				LogoutEditor1();
				if ($("#TreeId").val() == "999999999999") {
					draftArticleList()
				};
				folder($("#TreeId").val());
				return false
			};
			$(".bgpop").show();
			AlertDialog.confirmEdit("你的文章还未保存发表，确定要离开编辑页面吗？", '离开此页', '留在此页', function() {
				clearInterval(Intervalunmsg);
				LogoutEditor1();
				if ($("#TreeId").val() == "999999999999") {
					draftArticleList()
				};
				folder($("#TreeId").val())
			});
			return false
		};
		if (!$("#TreeId").val() || $("#TreeId").val() == 1) {
			$(".app-article .noData").show();
			$("#artContent").html("");
			ArticleList(0, 50, null, null, null, true)
		} else if ($("#TreeId").val() == "999999999999") {
			draftArticleList()
		} else {
			$(".app-article .noData").show();
			$("#artContent").html("");
			ArticleList(0, 50, "CategoryID=" + $("#TreeId").val(), null, null, true)
		};
		if (!$(".articleSearchList-div").is(":hidden")) {
			$("#SearchText").val("");
			$("#Search-divartlist").find("li").remove();
			$(".articleList-div,.app-tree,.articlePage").show();
			$(".articleSearchList-div").hide();
			if ($(".app-tree").offset().left >= 0) {
				$(".app-articleList").css("left", "251px");
				$(".app-article").css("margin-left", "514px")
			} else {
				$(".app-articleList").css("left", "0");
				$(".app-article").css("margin-left", "262px")
			}
			$(".Search-noContent").hide();
			$(".Search-screen-num em").text(0)
		};
		$(".app-edit a").removeClass("con");
		$("#home").addClass("con")
	});
	$(".handPicking").click(function(event) {
		event.stopImmediatePropagation();
		$("#operation").removeClass("h").find("em").hide();
		OpenNewWindow('http://www.360doc.com/helpnew.html')
	});
	$("#help").click(function(event) {
		event.stopImmediatePropagation();
		$("#operation").removeClass("h").find("em").hide();
		var help_win = gui.Window.open("/app/help.html", {
			position: 'center',
			width: 990,
			height: 500,
			min_width: 990,
			min_height: 500
		})
	});
	$(".feedback").click(function(event) {
		event.stopImmediatePropagation();
		$("#operation").removeClass("h").find("em").hide();
		OpenNewWindow('http://www.360doc.com/advice.html')
	});
	$("#functionSetting").click(function(event) {
		event.stopImmediatePropagation();
		if (!$("#app-article-float-download").is(":hidden")) {
			if ($(".downloadList>.downloadList-fr span.state").text().indexOf("正在下载") > -1) {
				AlertDialog.confirm(1, "你当前有下载任务正在进行，确认退出？点击确定将中断下载。", function() {
					$(".app-edit a").removeClass("con");
					$("#app-article-float-download").hide();
					$(".app-float-download-articleList").html("");
					$("#app-article-download-win-show i").removeClass("download");
					settingFun()
				})
			} else {
				$(".app-edit a").removeClass("con");
				$("#app-article-float-download").hide();
				$(".app-float-download-articleList").html("");
				$("#app-article-download-win-show i").removeClass("download");
				settingFun()
			};
			return false
		};
		if (!$(".writedocument").is(":hidden")) {
			if (($(window.frames["writedocument"].document).find("#TextBox3").val() == '' || $(window.frames["writedocument"].document).find("#TextBox3").val() == '输入标题') && $(window.frames["writedocument"].document).find("#hidFileName").val() == '') {
				folder($("#TreeId").val());
				$('.writedocument').hide().find("iframe").attr("src", "");
				$("#uploadFileBlock").removeClass("con");
				settingFun();
				return false
			};
			$(".bgpop").show();
			AlertDialog.confirmEdit("你的文档还未保存发表，确定要离开编辑页面吗？", '离开此页', '留在此页', function() {
				folder($("#TreeId").val());
				$('.writedocument').hide().find("iframe").attr("src", "");
				$("#uploadFileBlock").removeClass("con");
				settingFun()
			});
			return false
		};
		if (!$(".editorWid").is(":hidden")) {
			var iframeWid = document.getElementById("myEditor").contentWindow;
			if ((iframeWid.document.getElementById("TextBox2").value == '' || iframeWid.document.getElementById("TextBox2").value == '输入标题') && iframeWid.document.getElementById("editor_body_area").contentWindow.document.body.innerHTML.length == 0) {
				clearInterval(Intervalunmsg);
				LogoutEditor1();
				if ($("#TreeId").val() == "999999999999") {
					draftArticleList()
				};
				folder($("#TreeId").val());
				settingFun();
				return false
			};
			$(".bgpop").show();
			AlertDialog.confirmEdit("你的文章还未保存发表，确定要离开编辑页面吗？", '离开此页', '留在此页', function() {
				clearInterval(Intervalunmsg);
				LogoutEditor1();
				if ($("#TreeId").val() == "999999999999") {
					draftArticleList()
				};
				folder($("#TreeId").val());
				settingFun()
			});
			return false
		};
		if (!$(".fileModifyWind").is(":hidden")) {
			AlertDialog.confirmEdit("你的文章还未保存发表，确定要离开编辑页面吗？", '离开此页', '留在此页', function() {
				var strRequestUrl = cv.post + "/ajax/article.ashx?ver=0.01&os=windows&op=editartlock&aid=" + $("#randomArticlesId").val() + "&type=-1";
				var sign = "&sign=" + getSign.sign(strRequestUrl + "&UserCode=" + myReplace(UserCode));
				$.ajax({
					url: strRequestUrl + sign,
					type: 'POST',
					data: {
						"UserCode": UserCode
					},
					success: function(result) {
						var data = eval("(" + result + ")")
					}
				});
				$("#randomArticlesId").val("");
				$(".fileModifyWind").hide();
				settingFun()
			});
			return false
		};
		settingFun();

		function settingFun() {
			$("#operation").removeClass("h").find("em").hide();
			$(".functionSetting-list li").removeClass("cur").eq(0).addClass("cur");
			$(".functionSetting-setting>div").hide().eq(0).show();
			$(".functionSetting").show();
			sh.checkData('usersInfo', '*', "UserID = '" + uId + "'", function(info, err) {
				if (info.isLogOn == 1) {
					$("#isBasic").removeClass("isBasic-checkbox2").attr("domin", '1')
				} else {
					$("#isBasic").addClass("isBasic-checkbox2").attr("domin", '2')
				};
				$(".savePath-text").val(info.dataPath);
				$("#fileDialog,#fileDialog1").attr("nwworkingdir", info.dataPath);
				$("#fileDialog-div").attr("path", info.dataPath)
			});
			$("#functionSettingClose,#basic-cancel,#agentTheServer-cancel").unbind("click").click(function() {
				$(".functionSetting").hide()
			})
		}
	});
	
	/*功能设置tab*/
	$(".functionSetting-list li").click(function() {
		$(".functionSetting-list li").removeClass("cur").eq($(this).index()).addClass("cur");
		$(".functionSetting-setting>div").hide().eq($(this).index()).show();
		if($(this).index()==0){
			$("#mobileData-Load span").text("正在更改···");
		}else if($(this).index() == 1){
			$("#mobileData-Load span").text("正在清理···");	
		};
	});
	
	/*清除缓存*/
	$("#cache-sure").click(function(){
		AlertDialog.confirmWrap("系统提示","清空缓存后，待同步、已下载备份的文章将清除，重新","初始化文章。你确定清空缓存吗？","清空缓存","取消",function(){
			$("#InitializationSure").text("初始化进程隐藏到后台");
			$("#mobileData-Load").show();
			var exec = require('child_process').exec,child;
			if (GetOSInfo() == "Mac") {
				child = exec('rm -rf ' + dataPath + '/' + Uid,emptyCache);
			} else {
				child = exec('rd /s /q "' + dataPath + '/' + Uid+'"',emptyCache);
			};
			db.deleteTable("CategoryMyLibrary");
			db.deleteTable("DownLoadProgress");
			function emptyCache(){
				db.deleteTable("ArticleList",function(){
					db.deleteTable("SearchArticleList",function(){	
						$("#mobileData-Load").hide();
						$("#divartlist").text("");
						$(".app-article-Center,#articlePage").hide();
						AlertDialog.confirm(0, "缓存已清空！点击确定，重新开启初始化进程。",function(){
							fs.mkdir(dataPath + '/' + Uid, function(err) {
								if (!err) {
									fs.mkdir(dataPath + '/' + Uid + '/file', function(err) {});
									fs.mkdir(dataPath + '/' + Uid + '/file1', function(err) {});
									fs.mkdir(dataPath + '/' + Uid + '/img', function(err) {})
								}
							});
							$(".functionSetting").hide();
							sum=0;
							showFileDiv();
							db.SearchCreateTable("SearchArticleList", "ArticleID,ArticleTitle=simple,SaveDate ,ArtContent=simple,Arttype INTEGER,newData1 text,newData2 text,newData3 text");
							db.CreateTable("ArticleList", "articleID INTEGER,artType INTEGER,ArticleTitle text,keywords text,Abstract text,SaveDate INTEGER,SaverUserID INTEGER,ArtPermission INTEGER,Tags text,isChecked INTEGER,FirstArtID INTEGER,authorName text,authorUserID text,resaveAuthorName text,resaveAuthorUserID INTEGER,categoryID INTEGER,isOriginal INTEGER,ArtUrl text,sourceName text,ReadNum INTEGER,flowersNum INTEGER,commentNum INTEGER,saverNum INTEGER,ArtContent text,IsUpload INTEGER,Logid  text,IsDelete INTEGER,PrevCategoryID INTEGER,IsDownLoad text,downloadStatus INTEGER,localImgUrl text,imgDownloadStatus INTEGER,IsConvert INTEGER,PageNum INTEGER,Purtext text,Offvalue INTEGER,Permitdownload INTEGER,docsize INTEGER,iscream INTEGER,savefrom INTEGER,originalActivityID text,newData1 text,newData2 text,newData3 text", function() {
								db.tableIndexes("indexName","ArticleList","articleID");
								var strRequestUrl = cv.post + "/ajax/Category.ashx?ver=0.01&os=windows&op=syncCategorynew&t=0";
								var sign = "&sign=" + getSign.sign(strRequestUrl + "&UserCode=" + myReplace(UserCode));
								$.ajax({
									url: strRequestUrl + sign,
									type: 'post',
									data: {
										"UserCode": UserCode
									},
									success: function(result) {
										var data = eval('(' + result + ')');
										if (data.status == 1) {
											artTotal = data.artnum;
											$("#Initialization").show();
											$("#InitializationClose,#InitializationSure").click(function() {
												if ($("#InitializationSure").text() != "初始化完成") {
													$("#Initialization").hide();
													$("#InitializationStop").attr("type", 1).show();
												}
											});
											ArticleListDataInt(2, 100, 0)
										}
									}
								})
							})	
						});
						$("#comClose").remove();
					});
				});
			}
			
			
		})
		
	});
	
	$("#isBasic").click(function() {
		if ($(this).attr("domin") == "1") {
			$(this).attr("domin", '2').addClass("isBasic-checkbox2")
		} else {
			$(this).attr("domin", '1').removeClass("isBasic-checkbox2")
		}
	});
	$("#folderPath").unbind("click").click(function() {
		if (GetOSInfo() == "Windows_XP 32位" || GetOSInfo() == "Windows_XP 64位") {
			var opn = require('opn');
			opn($("#fileDialog1").attr("nwworkingdir"))
		} else {
			OpenNewWindow($("#fileDialog1").attr("nwworkingdir"))
		}
	});
	$("#alternatePath").unbind("click").click(function() {
		document.getElementById('fileDialog').click();
		document.getElementById("fileDialog").addEventListener('change', function(evt) {
			$("#fileDialog").remove();
			$("#fileDialog-div").append('<input id="fileDialog" type="file" nwdirectory nwworkingdir="' + $("#fileDialog-div").attr("path") + '" accept=".html" style="display:none;" />');
			if (this.value != '') {
				$(".savePath-text").val(this.value)
			}
		})
	});

	function mkdirs(p, mode, f, made) {
		if (typeof mode === 'function' || mode === undefined) {
			f = mode;
			mode = 0777 & (~process.umask())
		};
		if (!made) made = null;
		var cb = f ||
		function() {};
		if (typeof mode === 'string') mode = parseInt(mode, 8);
		p = rPath.resolve(p);
		fs.mkdir(p, mode, function(er) {
			if (!er) {
				made = made || p;
				return cb(null, made)
			};
			switch (er.code) {
			case 'ENOENT':
				mkdirs(rPath.dirname(p), mode, function(er, made) {
					if (er) {
						cb(er, made)
					} else {
						mkdirs(p, mode, cb, made)
					}
				});
				break;
			default:
				fs.stat(p, function(er2, stat) {
					if (er2 || !stat.isDirectory()) {
						cb(er, made)
					} else {
						cb(null, made)
					}
				});
				break
			}
		})
	};

	function copyFile(file, toDir, cb) {
		async.waterfall([function(callback) {
			fs.exists(toDir, function(exists) {
				if (exists) {
					callback(null, false)
				} else {
					callback(null, true)
				}
			})
		}, function(need, callback) {
			if (need) {
				mkdirs(rPath.dirname(toDir), callback)
			} else {
				callback(null, true)
			}
		}, function(p, callback) {
			var reads = fs.createReadStream(file);
			var writes = fs.createWriteStream(rPath.join(rPath.dirname(toDir), rPath.basename(file)));
			reads.pipe(writes);
			reads.on("end", function() {
				writes.end();
				callback(null)
			});
			reads.on("error", function(err) {
				console.log("error occur in reads");
				callback(true, err)
			})
		}], cb)
	};

	function _ccoutTask(from, to, cbw) {
		async.waterfall([function(callback) {
			fs.stat(from, callback)
		}, function(stats, callback) {
			if (stats.isFile()) {
				cbw.addFile(from, to);
				callback(null, [])
			} else if (stats.isDirectory()) {
				fs.readdir(from, callback)
			}
		}, function(files, callback) {
			if (files.length) {
				for (var i = 0; i < files.length; i++) {
					_ccoutTask(rPath.join(from, files[i]), rPath.join(to, files[i]), cbw.increase())
				}
			};
			callback(null)
		}], cbw)
	};

	function ccoutTask(from, to, cb) {
		var files = [];
		var count = 1;

		function wrapper(err) {
			count--;
			if (err || count <= 0) {
				cb(err, files)
			}
		};
		wrapper.increase = function() {
			count++;
			return wrapper
		};
		wrapper.addFile = function(file, dir) {
			files.push({
				file: file,
				dir: dir
			})
		};
		_ccoutTask(from, to, wrapper)
	};

	function copyDir(from, to, cb) {
		if (!cb) {
			cb = function() {}
		};
		async.waterfall([function(callback) {
			fs.exists(from, function(exists) {
				if (exists) {
					callback(null, true)
				} else {
					console.log(from + " not exists");
					callback(true)
				}
			})
		}, function(exists, callback) {
			fs.stat(from, callback)
		}, function(stats, callback) {
			if (stats.isFile()) {
				copyFile(from, to, function(err) {
					if (err) {
						callback(true)
					} else {
						callback(null, [])
					}
				})
			} else if (stats.isDirectory()) {
				ccoutTask(from, to, callback)
			}
		}, function(files, callback) {
			async.mapLimit(files, 10, function(f, cb) {
				copyFile(f.file, f.dir, cb)
			}, callback)
		}], cb)
	};

	function deleteFolderRecursive(path) {
		if (fs.existsSync(path)) {
			fs.readdirSync(path).forEach(function(file) {
				var curPath = path + "/" + file;
				if (fs.statSync(curPath).isDirectory()) {
					deleteFolderRecursive(curPath)
				} else {
					fs.unlinkSync(curPath)
				}
			});
			fs.rmdirSync(path)
		}
	};
	$("#basic-sure").click(function() {
		if ($("#isBasic").attr("domin") == 1) {
			startOnBoot.disableAutoStart('360doc')
		} else {
			startOnBoot.enableAutoStart('360doc', process.execPath)
		}
		if ($(".savePath-text").val() == $("#fileDialog-div").attr("path")) {
			sh.modifyData('usersInfo', ' isLogOn="' + $("#isBasic").attr("domin") + '"', ' UserID = ' + uId, function() {
				AlertDialog.confirm(0, "设置成功！")
			})
		} else {
			$("#mobileData-Load").show().find("span");
			fs.exists($(".savePath-text").val() + "/" + uId, function(err) {
				if (err) {
					copyFun()
				} else {
					fs.mkdir($(".savePath-text").val() + "/" + uId, function(err) {
						copyFun()
					})
				}
			})
		};

		function copyFun() {
			copyDir($("#fileDialog-div").attr("path") + '/' + uId + '/', $(".savePath-text").val() + "/" + uId, function(err) {
				if (err) {
					$("#mobileData-Load").hide();
					AlertDialog.confirm(0, "无法更改本地文件的保存路径！")
				} else {
					fs.exists($(".savePath-text").val() + "/" + uId + "/file", function(err) {
						if (!err) {
							fs.mkdir($(".savePath-text").val() + "/" + uId + "/file")
						}
					});
					fs.exists($(".savePath-text").val() + "/" + uId + "/file1", function(err) {
						if (!err) {
							fs.mkdir($(".savePath-text").val() + "/" + uId + "/file1")
						}
					});
					var exec = require('child_process').exec,
						child;
					if (GetOSInfo() == "Mac") {
						child = exec('rm -rf ' + $("#fileDialog-div").attr("path") + '/' + uId)
					} else {
						child = exec('rd /s /q "' + $("#fileDialog-div").attr("path") + '\\' + uId + '\\"')
					}
					sh.modifyData('usersInfo', ' isLogOn="' + $("#isBasic").attr("domin") + '",dataPath="' + $(".savePath-text").val() + '"', ' UserID = ' + uId, function() {
						$("#mobileData-Load").hide();
						AlertDialog.confirm(0, "设置成功！");
						dataPath = $(".savePath-text").val();
						$("#fileDialog-div").attr("path", $(".savePath-text").val());
						$("#fileDialog1").attr("nwworkingdir", $(".savePath-text").val());
						$("#fileDialog").attr("nwworkingdir", $(".savePath-text").val())
					})
				}
			})
		}
	});
	$("#agent-port").keyup(function() {
		var _val = $(this).val().substring($(this).val().length - 1, $(this).val().length);
		if (isNaN($(this).val())) {
			$(this).val($(this).val().substring(0, $(this).val().length - 1));
			$("#port-prompt").show()
		} else {
			if (_val == "." || _val == " ") {
				$(this).val($(this).val().substring(0, $(this).val().length - 1));
				$("#port-prompt").show()
			}
			$("#port-prompt").hide()
		}
	});
	$("#agent-ip").keyup(function() {
		if ($(this).val()) {
			$("#agentTheServer-sure").addClass("l")
		} else {
			$("#agentTheServer-sure").removeClass("l")
		}
	});
	$("#isAgent").click(function() {
		var http = require('http'),
			auth = new Buffer('flyingzl:password').toString('base64'),
			op = {
				host: '121.232.148.220',
				port: 9000,
				method: 'GET',
				path: 'http://www.360doc.com'
			};
		var req = http.request(op, function(res) {
			res.on('data', function(chunk) {
				console.log('BODY:' + chunk)
			})
		});
		req.on('error', function(e) {
			console.log('Error got: ' + e.message)
		});
		req.end();
		if ($(this).attr("domin") == "1") {
			$("#agentTheServer-test").unbind("click").click(function() {
				if (!$("#agent-ip").val()) {
					$("#testError").show().text("代理服务地址不能为空！")
				} else if (!$("#agent-port").val()) {
					$("#testError").show().text("代理服务端口不能为空！")
				} else if (isNaN($("#agent-port").val())) {
					$("#testError").show().text("代理服务端口只能为数字！")
				} else {}
			}); if ($("#agent-ip").val()) {
				$("#agentTheServer-sure").addClass("l")
			} else {
				$("#agentTheServer-sure").removeClass("l")
			}
			$("#agentTheServer-sure").unbind("click").click(function() {
				if (!$("#agent-ip").val()) {
					$("#testError").show().text("代理服务地址不能为空！")
				} else {
					$("#testError").show().text("无法连接到代理服务器！")
				}
			});
			$(".agentTheServer-list input").attr("readonly", false).removeClass("inputState");
			$(this).addClass("isAgent-checkbox2").attr("domin", "2")
		} else {
			$("#agentTheServer-test").unbind("click");
			$("#agentTheServer-sure").unbind("click").addClass("l").click(function() {
				$(".agentTheServer,.whiteBgpop").hide()
			});
			$(".agentTheServer-list input").attr("readonly", true).addClass("inputState");
			$(this).removeClass("isAgent-checkbox2").attr("domin", "1")
		}
	});
	var pkg = require('../package.json');
	var updater = require('node-webkit-updater');
	var upd = new updater(pkg);
	var copyPath, execPath;
	var progressTimer;
	$("#upgrade").click(function() {
		event.stopImmediatePropagation();
		if (!$("#app-article-float-download").is(":hidden")) {
			if ($(".downloadList>.downloadList-fr span.state").text().indexOf("正在下载") > -1) {
				AlertDialog.confirm(1, "你当前有下载任务正在进行，确认退出？点击确定将中断下载。", function() {
					$(".app-edit a").removeClass("con");
					$("#app-article-float-download").hide();
					$(".app-float-download-articleList").html("");
					$("#app-article-download-win-show i").removeClass("download");
					upgradeFun()
				})
			} else {
				$(".app-edit a").removeClass("con");
				$("#app-article-float-download").hide();
				$(".app-float-download-articleList").html("");
				$("#app-article-download-win-show i").removeClass("download");
				upgradeFun()
			};
			return false
		};
		if (!$(".writedocument").is(":hidden")) {
			if (($(window.frames["writedocument"].document).find("#TextBox3").val() == '' || $(window.frames["writedocument"].document).find("#TextBox3").val() == '输入标题') && $(window.frames["writedocument"].document).find("#hidFileName").val() == '') {
				folder($("#TreeId").val());
				$('.writedocument').hide().find("iframe").attr("src", "");
				$("#uploadFileBlock").removeClass("con");
				upgradeFun();
				return false
			};
			$(".bgpop").show();
			AlertDialog.confirmEdit("你的文档还未保存发表，确定要离开编辑页面吗？", '离开此页', '留在此页', function() {
				folder($("#TreeId").val());
				$('.writedocument').hide().find("iframe").attr("src", "");
				$("#uploadFileBlock").removeClass("con");
				upgradeFun()
			});
			return false
		};
		if (!$(".editorWid").is(":hidden")) {
			var iframeWid = document.getElementById("myEditor").contentWindow;
			if ((iframeWid.document.getElementById("TextBox2").value == '' || iframeWid.document.getElementById("TextBox2").value == '输入标题') && iframeWid.document.getElementById("editor_body_area").contentWindow.document.body.innerHTML.length == 0) {
				clearInterval(Intervalunmsg);
				LogoutEditor1();
				if ($("#TreeId").val() == "999999999999") {
					draftArticleList()
				};
				folder($("#TreeId").val());
				upgradeFun();
				return false
			};
			$(".bgpop").show();
			AlertDialog.confirmEdit("你的文章还未保存发表，确定要离开编辑页面吗？", '离开此页', '留在此页', function() {
				clearInterval(Intervalunmsg);
				LogoutEditor1();
				if ($("#TreeId").val() == "999999999999") {
					draftArticleList()
				};
				folder($("#TreeId").val());
				upgradeFun()
			});
			return false
		};
		if (!$(".fileModifyWind").is(":hidden")) {
			AlertDialog.confirmEdit("你的文章还未保存发表，确定要离开编辑页面吗？", '离开此页', '留在此页', function() {
				var strRequestUrl = cv.post + "/ajax/article.ashx?ver=0.01&os=windows&op=editartlock&aid=" + $("#randomArticlesId").val() + "&type=-1";
				var sign = "&sign=" + getSign.sign(strRequestUrl + "&UserCode=" + myReplace(UserCode));
				$.ajax({
					url: strRequestUrl + sign,
					type: 'POST',
					data: {
						"UserCode": UserCode
					},
					success: function(result) {
						var data = eval("(" + result + ")")
					}
				});
				$("#randomArticlesId").val("");
				$(".fileModifyWind").hide();
				upgradeFun()
			});
			return false
		};
		upgradeFun();

		function upgradeFun() {
			$("#upgrade").removeClass("NewVersionTips");
			$("#operation").removeClass("h").find("em").hide();
			if (!navigator.onLine) {
				AlertDialog.grayConfirm(0, "网络连接异常，请稍后重试！");
				return false
			};
			if (GetOSInfo() == "Mac") {
				tpe = 1
			} else {
				tpe = 0
			};
			upd.options.temporaryDirectory = process.cwd();
			upd.checkNewVersion(function(error, newVersionExists, manifest) {
				var strRequestUrl = cv.post + "/ajax/users.ashx?ver=0.01&os=windows&op=getrenewmes2&type=" + tpe;
				var sign = "&sign=" + getSign.sign(strRequestUrl);
				ajax_method(strRequestUrl + sign, null, "post", function(result) {
					var data = eval("(" + result + ")");
					if (tpe == 1) {
						sh.checkData('UpdateInfo', '*', null, function(row, err) {
							if (data.status == 1 && parseInt(data.versionid) > parseInt(row.versionid)) {
								openUpgrade()
							} else {
								AlertDialog.confirmRealname("在线升级", "", "当前你使用的是最新版本的个人图书馆，无需升级。", "确定", null)
							}
						})
					} else {
						if (data.status == 1 && parseInt(data.versionid) > parseInt(pkg.versionId)) {
							openUpgrade()
						} else {
							AlertDialog.confirmRealname("在线升级", "", "当前你使用的是最新版本的个人图书馆，无需升级。", "确定", null)
						}
					};

					function openUpgrade() {
						$("#upgrade_title").text(data.title);
						$("#upgrade_Content").html(data.Content);
						$(".upgrade_back").show();
						$("#upgradeClose,#upgrade-cancel").click(function() {
							$(".upgrade_back").hide()
						});
						$("#upgrade-sure").unbind("click").click(function() {
							if (!navigator.onLine) {
								AlertDialog.confirm(0, "网络连接异常，请稍后重试！");
								return false
							};
							var new_win = gui.Window.open("/app/upgrade1.html", {
								position: 'center',
								frame: false,
								width: 455,
								height: 332,
								max_width: 455,
								max_height: 332,
								min_width: 455,
								min_height: 332,
								always_on_top: true,
							});
							win.close(true)
						})
					}
				})
			})
		}
	});
	$("#aboutUsA").click(function() {
		OpenNewWindow($(this).attr("data-href"))
	});
	$("#aboutUs-win").unbind("click").click(function(event) {
		event.stopImmediatePropagation();
		$("#operation").removeClass("h").find("em").hide();
		var myDate = new Date();
		$(".aboutUs-div .copyright").text("北京六智信息技术股份有限公司 Copyright © 2005-" + myDate.getFullYear() + " 360doc.com , All Rights Reserved");
		$(".aboutUs-div").show();
		$(".aboutUs-info .version").text(pkg.version);
		$(".aboutUs-close").unbind("click").click(function() {
			$(".aboutUs-div").hide()
		})
	});
	$("#articleSearchList-show").unbind("click").click(function() {
		if (!$(".indexPublishSuccessImg").is(":hidden")) {
			return false
		};
		if (!$("#app-article-float-download").is(":hidden")) {
			if ($(".downloadList>.downloadList-fr span.state").text().indexOf("正在下载") > -1) {
				AlertDialog.confirm(1, "你当前有下载任务正在进行，确认退出？点击确定将中断下载。", function() {
					$(".app-edit a").removeClass("con");
					$("#app-article-float-download").hide();
					$(".app-float-download-articleList").html("");
					$("#app-article-download-win-show i").removeClass("download");
					articleSearchListShowFun()
				});
				return false
			} else {
				$(".app-edit a").removeClass("con");
				$("#app-article-float-download").hide();
				$(".app-float-download-articleList").html("");
				$("#app-article-download-win-show i").removeClass("download")
			}
		};
		$("#app-article-float,#app-article-float-download,.app-article-tree-float").hide();
		$("#app-tree-float").removeClass("block");
		var zTree = $.fn.zTree.getZTreeObj("treelist");
		var zTreeB = zTree.getNodeByParam("id", 1, null);
		zTree.expandNode(zTreeB, true, false, false);
		$("#filetreelist").html("");
		if (!$(".writedocument").is(":hidden")) {
			if (($(window.frames["writedocument"].document).find("#TextBox3").val() == '' || $(window.frames["writedocument"].document).find("#TextBox3").val() == '输入标题') && $(window.frames["writedocument"].document).find("#hidFileName").val() == '') {
				folder($("#TreeId").val());
				$('.writedocument').hide().find("iframe").attr("src", "");
				$("#uploadFileBlock").removeClass("con");
				articleSearchListShowFun();
				return false
			};
			$(".bgpop").show();
			AlertDialog.confirmEdit("你的文档还未保存发表，确定要离开编辑页面吗？", '离开此页', '留在此页', function() {
				$('.writedocument').hide().find("iframe").attr("src", "");
				$("#uploadFileBlock").removeClass("con");
				folder($("#TreeId").val());
				articleSearchListShowFun()
			});
			return false
		};
		if (!$(".editorWid").is(":hidden")) {
			var iframeWid = document.getElementById("myEditor").contentWindow;
			if ((iframeWid.document.getElementById("TextBox2").value == '' || iframeWid.document.getElementById("TextBox2").value == '输入标题') && iframeWid.document.getElementById("editor_body_area").contentWindow.document.body.innerHTML.length == 0) {
				LogoutEditor1();
				if ($("#TreeId").val() == "999999999999") {
					draftArticleList()
				};
				folder($("#TreeId").val());
				articleSearchListShowFun();
				return false
			};
			$(".bgpop").show();
			AlertDialog.confirmEdit("你的文章还未保存发表，确定要离开编辑页面吗？", '离开此页', '留在此页', function() {
				LogoutEditor1();
				if ($("#TreeId").val() == "999999999999") {
					draftArticleList()
				};
				folder($("#TreeId").val());
				articleSearchListShowFun()
			});
			return false
		};
		articleSearchListShowFun();

		function articleSearchListShowFun() {
			$(".app-article .noData").show();
			$(".app-article .noData-Load").hide();
			if (!$(".articleSearchList-div").is(":hidden")) {
				return false
			};
			$(".app-articleList .noData").hide();
			$(".Search-screen-time span").attr("time", 0).text("时间");
			$(".Search-screen-type span").attr("type", 0).text("类型");
			$(".app-edit a").removeClass("con");
			$("#articleSearchList-show").addClass("con");
			$(".articleList-div,.app-tree,.articlePage").hide();
			$(".app-articleList").css("left", "0");
			$(".app-article").css("margin-left", "262px");
			$(".articleSearchList-div").show();
			$(".app-article>.noData").show();
			$("#artContent").html("");
			$('#SearchText').unbind("keydown").keydown(function(e) {
				if (e.keyCode == 13) {
					if ($("#SearchText").val() == '') {
						AlertDialog.grayConfirm(0, "请输入搜索内容！");
						return false
					}
					SearchArticleList(0, $(".Search-screen-type span.type").attr("type"), $(".Search-screen-time span.time").attr("time"), 0)
				}
			})
		}
	});
	$(".Search-Return").click(function() {
		$(".app-edit a").removeClass("con");
		$("#SearchText").val("");
		$("#Search-divartlist").find("li").remove();
		$(".articleList-div,.app-tree,.articlePage").show();
		$(".articleSearchList-div").hide();
		if ($(".app-tree").offset().left >= 0) {
			$(".app-articleList").css("left", "251px");
			$(".app-article").css("margin-left", "514px")
		} else {
			$(".app-articleList").css("left", "0");
			$(".app-article").css("margin-left", "262px")
		};
		$(".Search-noContent").hide();
		$(".Search-screen-num em").text(0);
		if ($("#TreeId").val() && $("#TreeId").val() != 1) {
			$(".app-article .noData").show();
			$("#artContent").html("");
			ArticleList(0, 50, "CategoryID=" + $("#TreeId").val(), null, null, true)
		} else {
			$(".app-article .noData").show();
			$("#artContent").html("");
			ArticleList(0, 50, null, null, null, true)
		}
	});
	$(".Search-btn").unbind("click").click(function() {
		if ($("#SearchText").val() == '') {
			AlertDialog.grayConfirm(0, "请输入搜索内容！");
			return false
		};
		SearchArticleList(0, $(".Search-screen-type span.type").attr("type"), $(".Search-screen-time span.time").attr("time"), 0)
	});
	$(".app-tree-article-list").click(function(event) {
		event.stopImmediatePropagation();
		$(".app-screen-download span").attr("type", '').text("全部");
		$(".app-screen-type span").attr("type", "").text("全部");
		$("#TreeId").val("");
		var treeObj = $.fn.zTree.getZTreeObj("treelist");
		treeObj.cancelSelectedNode();
		db.dataNull('ArticleList', function(err, id) {
			ArticleList(0, 50, null, null, null, true)
		})
	});
	$("#divtags>div").unbind("click").click(function() {
		$("#txttags,#txtAbstract").focus()
	});
	$("#modify-divtags").unbind("click").click(function() {
		$("#modify-txttags").focus()
	});
	$("#compose").click(function() {
		if (!$(".editorWid").is(":hidden") && $(".docceng>div").eq(1).is(":hidden")) {
			var iframeWid = document.getElementById("myEditor").contentWindow;
			if ((iframeWid.document.getElementById("TextBox2").value == '' || iframeWid.document.getElementById("TextBox2").value == '输入标题') && iframeWid.document.getElementById("editor_body_area").contentWindow.document.body.innerHTML.length == 0) {
				LogoutEditor1();
				if ($("#TreeId").val() == "999999999999") {
					draftArticleList()
				};
				folder($("#TreeId").val());
				return false
			};
			$(".bgpop").show();
			AlertDialog.confirmEdit("你的文章还未保存发表，确定要离开编辑页面吗？", '离开此页', '留在此页', function() {
				LogoutEditor1();
				if ($("#TreeId").val() == "999999999999") {
					draftArticleList()
				};
				folder($("#TreeId").val());
				composeFun()
			});
			return false
		} else if (!$(".editorWid").is(":hidden")) {
			return false
		};
		if (!$("#app-article-float-download").is(":hidden")) {
			if ($(".downloadList>.downloadList-fr span.state").text().indexOf("正在下载") > -1) {
				AlertDialog.confirm(1, "你当前有下载任务正在进行，确认退出？点击确定将中断下载。", function() {
					$(".app-edit a").removeClass("con");
					$("#app-article-float-download").hide();
					$(".app-float-download-articleList").html("");
					$("#app-article-download-win-show i").removeClass("download");
					composeFun()
				});
				return false
			} else {
				$(".app-edit a").removeClass("con");
				$("#app-article-float-download").hide();
				$(".app-float-download-articleList").html("");
				$("#app-article-download-win-show i").removeClass("download")
			}
		};
		$("#app-article-float,#app-article-float-download,.app-article-tree-float,.middlediv-modify").hide();
		$("#app-tree-float").removeClass("block");
		var zTree = $.fn.zTree.getZTreeObj("treelist");
		var zTreeB = zTree.getNodeByParam("id", 1, null);
		zTree.expandNode(zTreeB, true, false, false);
		$("#filetreelist").html("");
		if (!$(".writedocument").is(":hidden")) {
			if (($(window.frames["writedocument"].document).find("#TextBox3").val() == '' || $(window.frames["writedocument"].document).find("#TextBox3").val() == '输入标题') && $(window.frames["writedocument"].document).find("#hidFileName").val() == '') {
				folder($("#TreeId").val());
				$('.writedocument').hide().find("iframe").attr("src", "");
				$("#uploadFileBlock").removeClass("con");
				composeFun();
				return false
			};
			$(".bgpop").show();
			AlertDialog.confirmEdit("你的文档还未保存发表，确定要离开编辑页面吗？", '离开此页', '留在此页', function() {
				$('.writedocument').hide().find("iframe").attr("src", "");
				$("#uploadFileBlock").removeClass("con");
				folder($("#TreeId").val());
				composeFun()
			});
			return false
		};
		composeFun();

		function composeFun() {
			if (Isforbid == 1) {
				AlertDialog.confirmWrap("系统提示", "对不起，该帐号已被冻结！", "你只能阅读和下载正文，无法进行其它操作！", "确定", null);
				return false
			};
			$("#originalActivityID").val("");
			treeNode_id = 1;
			var iframe = document.getElementById("myEditor").contentWindow;
			$("#editLayout").removeClass("fullScreenStyle");
			$(".app-edit a").removeClass("con");
			$("#compose").addClass("con");
			$("#changePermission,#tdbaocun").show();
			$("#lockPermission").hide();
			$("#randomArticlesId").val("");
			$(".fileModifyWind").hide();
			iframe.document.getElementById("editor_body_area").contentWindow.document.body.focus();
			if ($("#randomArticlesId").val() == '') {
				$(".docceng img").attr("src", "img/bt-6.gif");
				iframe.document.getElementById("yctg").parentNode.style.display = "block";
				iframe.document.getElementById("TextBox2").parentNode.removeAttribute("style");
				iframe.document.getElementById("TextBox2").removeAttribute("style");
				$(".docceng>div").eq(1).show();
				$(".middlediv-modify").hide();
				$(".middlediv-Compose").show();
				$("#tdbaocun").show();
				$("#bottomindiv>div.left").css("width", "395px");
				$("#divmypremi").html("公众公开").attr("type", 0);
				$("#Hidden2").attr("permission", 0);
				$(".editorWid").show();
				$("#nofullscreen").hide();
				$("#fullscreen").show();
				$("#chkcode").attr('checked', false);
				$("#middlediv-Compose>.dagjctop>div").attr("class", "dzaiy").eq(0).attr("class", "dgjc");
				$("#middlediv-Compose>.doc-tags>div").hide().eq(0).show();
				$("#divtree").removeClass("biaoto3");
				db.dataNull('draftCreate', function(err, rowId) {
					if (rowId > 0) {
						db.checkDataSort('draftCreate', '*', ' articleID asc limit 1', function(data, err) {
							$("#randomArticlesId").val(data.articleID - 1)
						})
					} else {
						$("#randomArticlesId").val(-1000)
					}
				});
				Intervalunmsg = setInterval(function() {
					getGroup(4)
				}, delay * 1000);
				$("#Button1").attr("src", "/app/img/dabt6a1.gif").attr("onclick", "return getGroup(0);").hover(function() {
					$(this).attr("src", "/app/img/dabt6a1.gif")
				}, function() {
					$(this).attr("src", "/app/img/dabt61.gif")
				});
				showFileDiv2()
			}
			if (!$(".articleSearchList-div").is(":hidden")) {
				$("#SearchText,#TreeId").val("");
				$("#Search-divartlist").find("li").remove();
				$(".articleList-div,.app-tree,.articlePage").show();
				$(".articleSearchList-div").hide();
				$(".app-articleList,.app-article").attr("style", "");
				$(".Search-noContent").hide();
				$(".Search-screen-num em").text(0)
			};
			sh.userCheckData('Users', '*', " UserID = '" + uId + "'", function(row, err) {
				if (row.isRealname == 1) {
					if (navigator.onLine) {
						var strRequestUrl = cv.post + "/ajax/users.ashx?ver=0.01&os=windows&op=gmyinf&usertype=my&uid=" + uId;
						var sign = "&sign=" + getSign.sign(strRequestUrl + "&UserCode=" + myReplace(UserCode));
						$.ajax({
							url: strRequestUrl + sign,
							type: 'POST',
							data: {
								"UserCode": UserCode
							},
							success: function(result) {
								var data = eval("(" + result + ")");
								sh.modifyData('Users', ' userType="' + data.NAItem[0].originalusertype + '",isRealname="' + data.NAItem[0].isvalid + '"', ' UserID = ' + Uid, function() {});
								if (data.NAItem[0].originalusertype == 0) {
									iframe.document.getElementById("yctgName").innerHTML = "申请原创"
								} else {
									iframe.document.getElementById("yctgName").innerHTML = "声明原创"
								}
							},
							error: function() {
								sh.userCheckData('Users', '*', " UserID = '" + uId + "'", function(row, err) {
									if (row.userType == 0) {
										iframe.document.getElementById("yctgName").innerHTML = "申请原创"
									} else {
										iframe.document.getElementById("yctgName").innerHTML = "声明原创"
									}
								})
							}
						})
					} else {
						sh.userCheckData('Users', '*', " UserID = '" + uId + "'", function(row, err) {
							if (row.userType == 0) {
								iframe.document.getElementById("yctgName").innerHTML = "申请原创"
							} else {
								iframe.document.getElementById("yctgName").innerHTML = "声明原创"
							}
						})
					}
				} else {
					AlertDialog.confirmRealname("身份验证", "根据国家实名制法规要求，请尽快进行手机验证！", "如果未进行手机验证，你发表的文章将不予公开！", "立即验证", "下次再说", function() {
						if (!navigator.onLine) {
							iframe.document.getElementById("yctg").parentNode.style.display = "none";
							$("#divmypremi").html("私有");
							$("#divmypre").hide();
							$("#changePermission").hide();
							$("#lockPermission").show();
							$("#Hidden2").attr("permission", 1)
						}
						OpenNewWindow('http://www.360doc.com/login.aspx?reurl=http://www.360doc.com/myaccount.aspx?app=4');
						AlertDialog.confirmRealname("身份验证", "请在打开的浏览器窗口中进行验证。", "", "完成验证", null, function() {
							var strRequestUrl = cv.post + "/ajax/users.ashx?ver=0.01&os=windows&op=gmyinf&usertype=my&uid=" + uId;
							var sign = "&sign=" + getSign.sign(strRequestUrl + "&UserCode=" + myReplace(UserCode));
							$.ajax({
								url: strRequestUrl + sign,
								type: 'POST',
								data: {
									"UserCode": UserCode
								},
								success: function(result) {
									var data = eval("(" + result + ")");
									sh.modifyData('Users', ' userType="' + data.NAItem[0].originalusertype + '",isRealname="' + data.NAItem[0].isvalid + '"', ' UserID = ' + Uid, function() {});
									if (data.NAItem[0].isvalid == 1) {
										if (data.NAItem[0].originalusertype == 0) {
											iframe.document.getElementById("yctgName").innerHTML = "申请原创"
										} else {
											iframe.document.getElementById("yctgName").innerHTML = "声明原创"
										};
										$("#Hidden2").attr("permission", 0);
										if ($("#Hidden2").val() != -2000) {
											$("#divmypremi").html("公众公开");
											$("#divmypre").hide();
											$("#changePermission").show();
											$("#lockPermission").hide()
										} else {
											$("#Hidden2").attr("permission", 1)
										}
									} else {
										iframe.document.getElementById("yctg").parentNode.style.display = "none";
										$("#divmypremi").html("私有");
										$("#divmypre").hide();
										$("#changePermission").hide();
										$("#lockPermission").show().unbind("click");
										$("#Hidden2").attr("permission", 1)
									}
								}
							})
						}, function() {
							iframe.document.getElementById("yctg").parentNode.style.display = "none";
							$("#divmypremi").html("私有");
							$("#Hidden2").attr("permission", 1);
							$("#divmypre").hide();
							$("#changePermission").hide();
							$("#lockPermission").show().unbind("click")
						})
					}, function() {
						iframe.document.getElementById("yctg").parentNode.style.display = "none";
						$("#divmypremi").html("私有");
						$("#Hidden2").attr("permission", 1);
						$("#divmypre").hide();
						$("#changePermission").hide();
						$("#lockPermission").show().unbind("click")
					})
				}
			})
		}
	});
	$("#uploadFileBlock").unbind("click").click(function() {
		if (!$(".indexPublishSuccessImg").is(":hidden")) {
			return false
		};
		if (!$("#app-article-float-download").is(":hidden")) {
			if ($(".downloadList>.downloadList-fr span.state").text().indexOf("正在下载") > -1) {
				AlertDialog.confirm(1, "你当前有下载任务正在进行，确认退出？点击确定将中断下载。", function() {
					$(".app-edit a").removeClass("con");
					$("#app-article-float-download").hide();
					$(".app-float-download-articleList").html("");
					$("#app-article-download-win-show i").removeClass("download");
					uploadFileBlockFun()
				});
				return false
			} else {
				$(".app-edit a").removeClass("con");
				$("#app-article-float-download").hide();
				$(".app-float-download-articleList").html("");
				$("#app-article-download-win-show i").removeClass("download")
			}
		};
		$("#app-article-float,#app-article-float-download,.app-article-tree-float").hide();
		$("#app-tree-float").removeClass("block");
		var zTree = $.fn.zTree.getZTreeObj("treelist");
		var zTreeB = zTree.getNodeByParam("id", 1, null);
		zTree.expandNode(zTreeB, true, false, false);
		$("#filetreelist").html("");
		if (!$(".editorWid").is(":hidden")) {
			var iframeWid = document.getElementById("myEditor").contentWindow;
			if ((iframeWid.document.getElementById("TextBox2").value == '' || iframeWid.document.getElementById("TextBox2").value == '输入标题') && iframeWid.document.getElementById("editor_body_area").contentWindow.document.body.innerHTML.length == 0) {
				LogoutEditor1();
				if ($("#TreeId").val() == "999999999999") {
					draftArticleList()
				};
				folder($("#TreeId").val());
				uploadFileBlockFun();
				return false
			};
			$(".bgpop").show();
			AlertDialog.confirmEdit("你的文章还未保存发表，确定要离开编辑页面吗？", '离开此页', '留在此页', function() {
				LogoutEditor1();
				if ($("#TreeId").val() == "999999999999") {
					draftArticleList()
				};
				folder($("#TreeId").val());
				uploadFileBlockFun()
			});
			return false
		};
		uploadFileBlockFun();

		function uploadFileBlockFun() {
			if (Isforbid == 1) {
				AlertDialog.confirmWrap("系统提示", "对不起，该帐号已被冻结！", "你只能阅读和下载正文，无法进行其它操作！", "确定", null);
				return false
			};
			$("#originalActivityID").val("");
			if (!$(".fileModifyWind").is(":hidden")) {
				$("#randomArticlesId").val("");
				$(".fileModifyWind").hide()
			};
			$(".app-edit a").removeClass("con");
			$("#uploadFileBlock").addClass("con");
			if ($(".writedocument").is(":hidden")) {
				$(".writedocument,#writedocument").css("height", $(".app-library").height());
				$(".writedocument").show().find("iframe").attr("src", "uploadFile.html?uId=" + uId + "&IsLogin=" + IsLogin + "&UserCode=" + UserCode)
			};
			if (!$(".articleSearchList-div").is(":hidden")) {
				$("#SearchText,#TreeId").val("");
				$("#Search-divartlist").find("li").remove();
				$(".articleList-div,.app-tree,.articlePage").show();
				$(".articleSearchList-div").hide();
				$(".app-articleList,.app-article").attr("style", "");
				$(".Search-noContent").hide();
				$(".Search-screen-num em").text(0)
			}
		}
	});
	$("#app-article-float-show").click(function() {
		if (!$(".indexPublishSuccessImg").is(":hidden")) {
			return false
		};
		if (!navigator.onLine) {
			AlertDialog.grayConfirm(0, "网络连接异常，请稍后重试！");
			return false
		};
		if (!$(".app-article-float").is(":hidden")) {
			return false
		};
		if (!$("#app-article-float-download").is(":hidden")) {
			if ($(".downloadList>.downloadList-fr span.state").text().indexOf("正在下载") > -1) {
				AlertDialog.confirm(1, "你当前有下载任务正在进行，确认退出？点击确定将中断下载。", function() {
					$(".app-edit a").removeClass("con");
					$("#app-article-float-download").hide();
					$(".app-float-download-articleList").html("");
					$("#app-article-download-win-show i").removeClass("download");
					appArticleFloatShowFun()
				});
				return false
			} else {
				$(".app-edit a").removeClass("con");
				$("#app-article-float-download").hide();
				$(".app-float-download-articleList").html("");
				$("#app-article-download-win-show i").removeClass("download")
			}
		};
		$("#app-article-float-download,.app-article-tree-float").hide();
		$("#app-tree-float").removeClass("block");
		var zTree = $.fn.zTree.getZTreeObj("treelist");
		var zTreeB = zTree.getNodeByParam("id", 1, null);
		zTree.expandNode(zTreeB, true, false, false);
		$("#filetreelist").html("");
		if (!$(".writedocument").is(":hidden")) {
			if (($(window.frames["writedocument"].document).find("#TextBox3").val() == '' || $(window.frames["writedocument"].document).find("#TextBox3").val() == '输入标题') && $(window.frames["writedocument"].document).find("#hidFileName").val() == '') {
				folder($("#TreeId").val());
				$('.writedocument').hide().find("iframe").attr("src", "");
				$("#uploadFileBlock").removeClass("con");
				appArticleFloatShowFun();
				return false
			};
			$(".bgpop").show();
			AlertDialog.confirmEdit("你的文档还未保存发表，确定要离开编辑页面吗？", '离开此页', '留在此页', function() {
				$('.writedocument').hide().find("iframe").attr("src", "");
				folder($("#TreeId").val());
				$("#uploadFileBlock").removeClass("con");
				appArticleFloatShowFun()
			});
			return false
		};
		if (!$(".editorWid").is(":hidden")) {
			var iframeWid = document.getElementById("myEditor").contentWindow;
			if ((iframeWid.document.getElementById("TextBox2").value == '' || iframeWid.document.getElementById("TextBox2").value == '输入标题') && iframeWid.document.getElementById("editor_body_area").contentWindow.document.body.innerHTML.length == 0) {
				LogoutEditor1();
				if ($("#TreeId").val() == "999999999999") {
					draftArticleList()
				};
				folder($("#TreeId").val());
				appArticleFloatShowFun();
				return false
			};
			$(".bgpop").show();
			AlertDialog.confirmEdit("你的文章还未保存发表，确定要离开编辑页面吗？", '离开此页', '留在此页', function() {
				LogoutEditor1();
				if ($("#TreeId").val() == "999999999999") {
					draftArticleList()
				};
				folder($("#TreeId").val());
				appArticleFloatShowFun()
			});
			return false
		};
		appArticleFloatShowFun();

		function appArticleFloatShowFun() {
			if (Isforbid == 1) {
				AlertDialog.confirmWrap("系统提示", "对不起，该帐号已被冻结！", "你只能阅读和下载正文，无法进行其它操作！", "确定", null);
				return false
			};
			$(".app-edit a").removeClass("con");
			$("#app-article-float-show").addClass("con");
			$("#managementArticleKeuInput").val(1);
			if (!$("#TreeId").val() || $("#TreeId").val() == 1) {
				$("#articleNumber").text("");
				managementArticleList(0, 50, null)
			} else if ($("#TreeId").val() == 999999999999) {
				$("#articleNumber").html("（<span>本地草稿箱</span>）");
				managementArticleList(0, 50, "999999999999")
			} else {
				$("#articleNumber").text("（" + $("#TreeId").attr("title") + "）");
				managementArticleList(0, 50, " categoryID=" + $("#TreeId").val())
			};
			if ($("#TreeId").val() == 999999999999) {
				db.dataNull('draftCreate', function(err, id) {
					managementArticlePaging(id, 50, 1)
				})
			};
			$("#app-article-float").show();
			$("#managementArticleDelete,#managementArticleMove").attr("type", "0");
			$(".app-article-float-edit span").removeClass("checkbox").attr("isSelect", "0")
		}
	});
	$(".app-article-float-close").click(function() {
		$(".app-edit a").removeClass("con");
		$("#managementArticleId,#TreeIdList").val("");
		$(".app-float-articleList").animate({
			scrollTop: 0
		}, 0);
		$("#app-article-float").hide();
		$("#articleNumber").text("");
		if ($("#TreeId").val() != "999999999999") {
			db.checkData("ArticleList", "*", " articleID = '" + $("#divartlist>li.con").attr("aid") + "'", function(row, err) {}, function(num) {
				if (num == 0) {
					folder($("#TreeId").val());
					var page = Number($("#keuInput").val()) - 1;
					if ($("#TreeId").val() != '') {
						ArticleList(page * 50, 50, "CategoryID=" + $("#TreeId").val(), null, null, true);
						if (page > 0) {
							db.checkDataStripNumber('ArticleList', 'articleID', 50, 0, "CategoryID=" + $("#TreeId").val(), 'SaveDate desc', function(row, err) {}, function(count) {
								paging(count, 50, Number(page) + 1)
							})
						}
					} else {
						ArticleList(page * 50, 50, null, null, null, true);
						if (page > 0) {
							db.checkDataStripNumber('ArticleList', 'articleID', 50, 0, null, 'SaveDate desc', function(row, err) {}, function(count) {
								paging(count, 50, Number(page) + 1)
							})
						}
					}
				} else {
					if ($("#managementArticleDelete").attr("type") == 0 && $("#managementArticleMove").attr("type") == 1) {
						folder($("#TreeId").val());
						var page = Number($("#keuInput").val()) - 1;
						if ($("#TreeId").val() != '') {
							ArticleList(page * 50, 50, "CategoryID=" + $("#TreeId").val(), null, null, true);
							if (page > 0) {
								db.checkDataStripNumber('ArticleList', 'articleID', 50, 0, "CategoryID=" + $("#TreeId").val(), 'SaveDate desc', function(row, err) {}, function(count) {
									paging(count, 50, Number(page) + 1)
								})
							}
						} else {
							ArticleList(page * 50, 50, null, null, null, true);
							if (page > 0) {
								db.checkDataStripNumber('ArticleList', 'articleID', 50, 0, null, 'SaveDate desc', function(row, err) {}, function(count) {
									paging(count, 50, Number(page) + 1)
								})
							}
						}
					} else if (($("#managementArticleDelete").attr("type") == 1 && $("#managementArticleMove").attr("type") == 0) || ($("#managementArticleDelete").attr("type") == 1 && $("#managementArticleMove").attr("type") == 1)) {
						var where = '';
						if ($("#TreeId").val() != '') {
							var where = " categoryID='" + $("#TreeId").val() + "' AND articleID > '" + $("#divartlist>li.con").attr("aid") + "'"
						} else {
							var where = " articleID > '" + $("#divartlist>li.con").attr("aid") + "'"
						}
						db.SearchQuery("ArticleList", "articleID,artType,ArticleTitle,keywords,Abstract,SaveDate,SaverUserID,ArtPermission,Tags,isChecked,FirstArtID,authorName,authorUserID ,resaveAuthorName,resaveAuthorUserID,categoryID,isOriginal,ArtUrl,sourceName,ReadNum,flowersNum,commentNum,saverNum,ArtContent,IsUpload,Logid,IsDelete,PrevCategoryID,IsDownLoad,downloadStatus,localImgUrl,imgDownloadStatus,IsConvert,PageNum,Purtext,Offvalue,Permitdownload,docsize,iscream,savefrom,originalActivityID,newData1,newData2,newData3", where, null, null, function(row, err) {}, function(num) {
							var page = (num / 50).toFixed(0) - 1;
							if ($("#TreeId").val() != '') {
								ArticleList(page * 50, 50, "CategoryID=" + $("#TreeId").val(), null, null, $("#divartlist>li.con").attr("aid"));
								if (page > 0) {
									db.checkDataStripNumber('ArticleList', 'articleID', 50, 0, "CategoryID=" + $("#TreeId").val(), 'SaveDate desc', function(row, err) {}, function(count) {
										paging(count, 50, Number(page) + 1)
									})
								}
							} else {
								ArticleList(page * 50, 50, null, null, null, $("#divartlist>li.con").attr("aid"));
								if (page > 0) {
									db.checkDataStripNumber('ArticleList', 'articleID', 50, 0, null, 'SaveDate desc', function(row, err) {}, function(count) {
										paging(count, 50, Number(page) + 1)
									})
								}
							}
						})
					}
				}
			})
		} else {
			draftArticleList()
		}
	});
	$("#app-article-download-win-show").click(function() {
		if (!$(".indexPublishSuccessImg").is(":hidden")) {
			return false
		};
		if (!navigator.onLine) {
			AlertDialog.grayConfirm(0, "网络连接异常，请稍后重试！");
			return false
		};
		$("#app-article-float,.app-article-tree-float").hide();
		$("#app-tree-float").removeClass("block");
		var zTree = $.fn.zTree.getZTreeObj("treelist");
		var zTreeB = zTree.getNodeByParam("id", 1, null);
		zTree.expandNode(zTreeB, true, false, false);

		function appArticleDownloadWinShowFun() {
			$(".app-edit a").removeClass("con");
			$("#app-article-download-win-show").addClass("con");
			$("#app-article-float-download").show();
			if ($(this).find(">i").is(".download") || $(".app-float-download-articleList>div").length > 0) {
				return false
			};
			if ($("#artnum").text() == 0) {
				$(".float-article-download-noData").show();
				return false
			};
			$(".float-article-download-noData").hide();
			db.checkData('CategoryMyLibrary', '*', null, function(row, err) {
				if (row.FatherCategoryID != 0 && row.ArtNum >= 0 && row.FatherCategoryID == 1) {
					artnum++;
					db.checkData('DownLoadProgress', '*', ' CategoryID="' + row.CategoryID + '"', function(data, err) {
						if (data.progress >= 100) {
							$(".app-float-download-articleList").append('<div class="downloadList clearfix" cid="' + row.CategoryID + '" fcid="' + row.FatherCategoryID + '" artnum="' + row.ArtNum + '" ><div class="downloadList-fl fl downloaded"><a title="' + toTXT(row.CategoryName) + '">' + replaceBrackets(toTXT(row.CategoryName)) + '</a></div><div class="downloadList-fr fr">下载完成</div></div>')
						} else if (data.progress <= 0) {
							if (data.type == 0) {
								$(".app-float-download-articleList").append('<div class="downloadList clearfix" cid="' + row.CategoryID + '" fcid="' + row.FatherCategoryID + '" artnum="' + row.ArtNum + '" ><div class="downloadList-fl fl downloadReady"><a title="' + toTXT(row.CategoryName) + '">' + replaceBrackets(toTXT(row.CategoryName)) + '</a></div><div class="downloadList-fr fr"><div class="downloadList-selected"><div class="downloadList-data"><span class="state">准备下载</span><span class="num"><i>0</i>%</span></div><div class="downloadList-progress"><span class="progress" style="width: ' + data.progress.toFixed(2) + '%;"></span></div></div><img src="img/start.png" class="start" num="0" title="开始下载" is="0"></div></div>');
								$(".downloadList-fl").unbind("click").click(function() {
									var _this = $(this);
									if ($(this).is(".downloadReady")) {
										db.deleteTableSingleData('DownLoadProgress', ' CategoryID = ' + _this.parents("div.downloadList").attr("cid"));
										$(this).removeClass("downloadReady").addClass("pleaseSelect");
										$(this).parent().find(".downloadList-fr").html("")
									} else if ($(this).is(".pleaseSelect")) {
										db.checkData('DownLoadProgress', '*', ' CategoryID="' + _this.parents("div.downloadList").attr("cid") + '"', function(data, err) {}, function(id) {
											if (id == 0) {
												db.saveData("DownLoadProgress(CategoryID,progress,type,newData1,newData2,newData3)", "(?,?,?,?,?,?)", _this.parents("div.downloadList").attr("cid") + ',' + 0 + ',' + 0 + ',' + null + ',' + null + ',' + null, function() {
													DownLoadart(_this.parents("div.downloadList").attr("cid"), _this.parents("div.downloadList").attr("cid"))
												})
											} else {
												DownLoadart(_this.parents("div.downloadList").attr("cid"), _this.parents("div.downloadList").attr("cid"))
											}
										});
										$(this).removeClass("pleaseSelect").addClass("downloadReady");
										$(this).parent().find(".downloadList-fr").html('<div class="downloadList-selected"><div class="downloadList-data"><span class="state">准备下载</span><span class="num"><i>0</i>%</span></div><div class="downloadList-progress"><span class="progress" style="width:0%;"></span></div></div><img src="img/start.png" class="start" num="0" title="开始下载" is="0" >');
										$(".start").unbind("click").click(function() {
											downloadArticleList($(this))
										})
									}
								});
								$(".start").unbind("click").click(function() {
									downloadArticleList($(this))
								})
							} else {
								$(".app-float-download-articleList").append('<div class="downloadList clearfix" cid="' + row.CategoryID + '" fcid="' + row.FatherCategoryID + '" artnum="' + row.ArtNum + '" ><div class="downloadList-fl fl download"><a title="' + toTXT(row.CategoryName) + '">' + replaceBrackets(toTXT(row.CategoryName)) + '</a></div><div class="downloadList-fr fr"><div class="downloadList-selected"><div class="downloadList-data"><span class="state">准备下载</span><span class="num"><i>0</i>%</span></div><div class="downloadList-progress"><span class="progress" style="width: ' + data.progress.toFixed(2) + '%;"></span></div></div><img src="img/start.png" class="start" num="0" title="开始下载" is="0"></div></div>');
								$(".start").unbind("click").click(function() {
									downloadArticleList($(this))
								})
							}
						} else {
							$(".app-float-download-articleList").append('<div class="downloadList clearfix" cid="' + row.CategoryID + '" fcid="' + row.FatherCategoryID + '" artnum="' + row.ArtNum + '" ><div class="downloadList-fl fl download"><a title="' + toTXT(row.CategoryName) + '">' + replaceBrackets(toTXT(row.CategoryName)) + '</a></div><div class="downloadList-fr fr"><div class="downloadList-selected"><div class="downloadList-data"><span class="state">暂停中</span><span class="num"><i>' + data.progress.toFixed(2) + '</i>%</span></div><div class="downloadList-progress"><span class="progress" style="width: ' + data.progress.toFixed(2) + '%;"></span></div></div><img src="img/start.png" class="start" num="0" title="开始下载" is="0"></div></div>');
							$(".start").unbind("click").click(function() {
								downloadArticleList($(this))
							})
						}
					}, function(id) {
						if (id == 0) {
							$(".app-float-download-articleList").append('<div class="downloadList clearfix" cid="' + row.CategoryID + '" fcid="' + row.FatherCategoryID + '" artnum="' + row.ArtNum + '" ><div class="downloadList-fl fl pleaseSelect"><a title="' + toTXT(row.CategoryName) + '">' + replaceBrackets(toTXT(row.CategoryName)) + '</a></div><div class="downloadList-fr fr"></div></div>');
							$(".downloadList-fl").unbind("click").click(function() {
								var _this = $(this);
								if ($(this).is(".downloadReady")) {
									db.deleteTableSingleData('DownLoadProgress', ' CategoryID = ' + _this.parents("div.downloadList").attr("cid"));
									$(this).removeClass("downloadReady").addClass("pleaseSelect");
									$(this).parent().find(".downloadList-fr").html("")
								} else if ($(this).is(".pleaseSelect")) {
									db.checkData('DownLoadProgress', '*', ' CategoryID="' + _this.parents("div.downloadList").attr("cid") + '"', function(data, err) {}, function(id) {
										if (id == 0) {
											db.saveData("DownLoadProgress(CategoryID,progress,type,newData1,newData2,newData3)", "(?,?,?,?,?,?)", _this.parents("div.downloadList").attr("cid") + ',' + 0 + ',' + 0 + ',' + null + ',' + null + ',' + null, function() {
												DownLoadart(_this.parents("div.downloadList").attr("cid"), _this.parents("div.downloadList").attr("cid"))
											})
										} else {
											DownLoadart(_this.parents("div.downloadList").attr("cid"), _this.parents("div.downloadList").attr("cid"))
										}
									});
									$(this).removeClass("pleaseSelect").addClass("downloadReady");
									$(this).parent().find(".downloadList-fr").html('<div class="downloadList-selected"><div class="downloadList-data"><span class="state">准备下载</span><span class="num"><i>0</i>%</span></div><div class="downloadList-progress"><span class="progress" style="width:0%;"></span></div></div><img src="img/start.png" class="start" num="0" title="开始下载" is="0" >');
									$(".start").unbind("click").click(function() {
										downloadArticleList($(this))
									})
								}
							})
						}
					})
				}
			})
		};
		$("#filetreelist").html("");
		if (!$(".writedocument").is(":hidden")) {
			if (($(window.frames["writedocument"].document).find("#TextBox3").val() == '' || $(window.frames["writedocument"].document).find("#TextBox3").val() == '输入标题') && $(window.frames["writedocument"].document).find("#hidFileName").val() == '') {
				appArticleDownloadWinShowFun();
				folder($("#TreeId").val());
				$('.writedocument').hide().find("iframe").attr("src", "");
				$("#uploadFileBlock").removeClass("con");
				return false
			};
			$(".bgpop").show();
			AlertDialog.confirmEdit("你的文档还未保存发表，确定要离开编辑页面吗？", '离开此页', '留在此页', function() {
				appArticleDownloadWinShowFun();
				$('.writedocument').hide().find("iframe").attr("src", "");
				folder($("#TreeId").val());
				$("#uploadFileBlock").removeClass("con")
			});
			return false
		};
		if (!$(".editorWid").is(":hidden")) {
			var iframeWid = document.getElementById("myEditor").contentWindow;
			if ((iframeWid.document.getElementById("TextBox2").value == '' || iframeWid.document.getElementById("TextBox2").value == '输入标题') && iframeWid.document.getElementById("editor_body_area").contentWindow.document.body.innerHTML.length == 0) {
				LogoutEditor1();
				if ($("#TreeId").val() == "999999999999") {
					draftArticleList()
				};
				folder($("#TreeId").val());
				appArticleDownloadWinShowFun();
				return false
			};
			$(".bgpop").show();
			AlertDialog.confirmEdit("你的文章还未保存发表，确定要离开编辑页面吗？", '离开此页', '留在此页', function() {
				LogoutEditor1();
				if ($("#TreeId").val() == "999999999999") {
					draftArticleList()
				};
				folder($("#TreeId").val());
				appArticleDownloadWinShowFun()
			});
			return false
		};
		if (!$(".app-article-float-download").is(":hidden")) {
			return false
		};
		appArticleDownloadWinShowFun()
	});

	function downloadArticleList(_this) {
		var _thisCid = _this.parents("div.downloadList");
		var num = 0;
		var downloadNum = 0;
		var failNum = 0;
		var articleIdArr = new Array();
		var fidNum = 0;
		var CategoryNum = 0;
		db.modifyData('DownLoadProgress', ' type="1"', ' CategoryID = ' + _thisCid.attr("cid"));
		if (_this.attr("is") == '0') {
			if (!navigator.onLine) {
				_this.parent().find(".downloadList-data").addClass("red").html("网络异常，请稍后重试");
				_this.attr("src", "img/start.png").attr("class", "start").attr("title", "开始下载").attr("is", 0);
				$("#app-article-download-win-show .edit7").removeClass("download");
				$(".start").unbind("click").click(function() {
					downloadArticleList($(this))
				});
				for (var i = 0; i < $(".app-float-download-articleList>div").length; i++) {
					if ($(".app-float-download-articleList>div").eq(i).find(".state").text() == "等待下载") {
						$(".app-float-download-articleList>div").eq(i).find(".downloadList-data").addClass("red").html("网络异常，请稍后重试")
					}
				};
				return false
			};
			for (var i = 0; i < $(".downloadList").length; i++) {
				if ($(".downloadList").eq(i).find(">.downloadList-fr span.state").text() == "正在下载") {
					downloadNum = 1
				};
				if (i == $(".downloadList").length - 1) {
					if (downloadNum == 1) {
						_this.attr("is", "1");
						_this.parent().parent().find(".downloadList-fl").removeClass("downloadReady").addClass("download");
						_this.parent().find(".downloadList-selected span.state").html("等待下载");
						_this.attr("src", "img/suspend.png").attr("class", "suspend").attr("title", "暂停下载");
						return false
					} else {
						$("#app-article-download-win-show .edit7").addClass("download");
						_this.attr("is", "1");
						_this.parent().parent().find(".downloadList-fl").removeClass("downloadReady").addClass("download");
						_this.parent().find(".downloadList-selected span.state").html("正在下载");
						_this.attr("src", "img/suspend.png").attr("class", "suspend").attr("title", "暂停下载");
						db.checkData('DownLoadProgress', '*', ' CategoryID="' + _this.parents("div.downloadList").attr("cid") + '"', function(data, err) {}, function(id) {
							if (id == 0) {
								db.saveData("DownLoadProgress(CategoryID,progress,type,newData1,newData2,newData3)", "(?,?,?,?,?,?)", _this.parents("div.downloadList").attr("cid") + ',' + 0 + ',' + 0 + ',' + null + ',' + null + ',' + null, function() {
									DownLoadart(_this.parents("div.downloadList").attr("cid"), _this.parents("div.downloadList").attr("cid"))
								})
							} else {
								DownLoadart(_this.parents("div.downloadList").attr("cid"), _this.parents("div.downloadList").attr("cid"))
							}
						})
					}
				}
			};

			function DownLoadart(cid, fid) {
				db.checkDataStripNumber('ArticleList', '*', 0, 0, " CategoryID=" + cid, ' SaveDate asc ', function(row, err) {
					articleIdArr.push(row.articleID)
				}, function() {
					db.checkData('CategoryMyLibrary', '*', " FatherCategoryID=" + cid, function(row, err) {
						DownLoadart(row.CategoryID, fid)
					}, function(id) {
						fidNum++;
						if (cid == _this.parents("div.downloadList").attr("cid") && id == 0) {
							startDownloading(fid);
							return false
						} else {
							if (id > 0) {
								CategoryNum += id
							};
							if (CategoryNum == fidNum - 1) {
								startDownloading(fid);
								return false
							}
						}
					})
				})
			};

			function startDownloading(CategoryID) {
				if (articleIdArr.length == 0) {
					db.modifyData('DownLoadProgress', ' progress="100"', ' CategoryID = ' + CategoryID);
					_this.parents("div.downloadList-fr").text("下载完成").parent().find(">div.downloadList-fl").removeClass("download").addClass("downloaded");
					db.modifyData('CategoryMyLibrary', ' IsDownLoad="1"', ' CategoryID = ' + _thisCid.attr("cid"));
					for (var i = 0; i < $(".downloadList").length; i++) {
						if ($(".downloadList").eq(i).find(">.downloadList-fr span.state").text() == "等待下载") {
							$(".downloadList").eq(i).find(".downloadList-fr img").attr("src", "img/start.png").attr("class", "start").attr("title", "开始下载").attr("is", 0);
							setTimeout(function() {
								downloadArticleList($(".downloadList").eq(i).find(".downloadList-fr img.start"))
							}, 100);
							$("#app-article-download-win-show .edit7").addClass("download");
							return false
						} else {
							$("#app-article-download-win-show .edit7").removeClass("download")
						}
					};
					return false
				};
				if (_this.attr("num") == 0) {
					downloadArtFun(0)
				} else {
					downloadArtFun(_this.attr("num"))
				};

				function downloadArtFun(idNum) {
					if (!navigator.onLine) {
						_this.parent().find(".downloadList-data").addClass("red").html("网络异常，请稍后重试");
						_this.attr("src", "img/start.png").attr("class", "start").attr("title", "开始下载").attr("is", 0);
						$("#app-article-download-win-show .edit7").removeClass("download");
						$(".start").unbind("click").click(function() {
							downloadArticleList($(this))
						});
						for (var i = 0; i < $(".app-float-download-articleList>div").length; i++) {
							if ($(".app-float-download-articleList>div").eq(i).find(".state").text() == "等待下载") {
								$(".app-float-download-articleList>div").eq(i).find(".downloadList-data").addClass("red").html("网络异常，请稍后重试")
							}
						};
						return false
					};
					db.checkData('ArticleList', '*', ' articleID=' + articleIdArr[idNum], function(row, err) {
						if (row.IsDownLoad == 0) {
							if ($(".app-float-download-articleList>div[cid='" + CategoryID + "']").find(">.downloadList-fr>img").attr("is") == 1) {
								var strRequestUrl = cv.post + "/ajax/article.ashx?ver=0.01&os=windows&op=gac&p=1&cid=-100&aid=" + articleIdArr[idNum];
								var sign = "&sign=" + getSign.sign(strRequestUrl + "&UserCode=" + myReplace(UserCode));
								var data = '';
								$.ajax({
									url: strRequestUrl + sign,
									type: 'POST',
									data: {
										"UserCode": UserCode
									},
									success: function(result) {
										data = JSON.parse(result);
										if (data.status == 1) {
											if (_this.parent().find(".downloadList-data").html() == "网络异常，请稍后重试") {
												num = Number(idNum) + 1;
												downloadNum = Number(idNum) + 1;
												var width = (_this.parent().find("span.progress").width() / _this.parent().find(".downloadList-progress").width() * 100).toFixed(2);
												_this.parent().find(".downloadList-data").removeClass("red").html('<span class="state">正在下载</span><span class="num"><i>' + width + '</i>%</span>')
											};
											if (data.aInf.Tags != '') {
												var Tags = data.aInf.Tags.replace(/\,/g, ";")
											} else {
												var Tags = null
											};
											if (data.aInf.ArtType >= 50) {
												var strRequestUrl = cv.post + "/ajax/document.ashx?ver=0.01&os=windows&op=getinfo&aid=" + articleIdArr[idNum];
												var sign = "&sign=" + getSign.sign(strRequestUrl);
												$.ajax({
													url: strRequestUrl + sign,
													type: 'POST',
													data: {},
													success: function(result) {
														var infoData = eval("(" + result + ")");
														if (!infoData.data[0]) {
															failNum++;
															downloadArtFun(Number(idNum) + 1);
															return false
														};
														if (infoData.status == 1) {
															num++;
															var obj = infoData.data[0];
															if (obj.Filetype == 4) {
																var Purtext = obj.SheetName
															} else {
																var Purtext = null
															};
															var strRequestUrl = cv.post + "/ajax/document.ashx?ver=0.01&os=windows&op=getdocdownloadinfo&aid=" + articleIdArr[idNum];
															var sign = "&sign=" + getSign.sign(strRequestUrl + "&UserCode=" + myReplace(UserCode));
															$.ajax({
																url: strRequestUrl + sign,
																type: 'POST',
																data: {
																	"UserCode": UserCode
																},
																success: function(result) {
																	var _data = eval("(" + result + ")");
																	if (_data.status == 1) {
																		var filename = articleIdArr[idNum] + "." + _data.extension;
																		db.modifyData('ArticleList', ' ArtContent="' + filename + '"', ' articleID = ' + articleIdArr[idNum]);
																		db.modifyData('ArticleList', ' Offvalue="' + _data.artdegreevalue + '",Permitdownload="1"', ' articleID = ' + articleIdArr[idNum]);
																		if (_data.documenturl && _data.documenturl != 'http://') {
																			request(_data.documenturl).pipe(fs.createWriteStream(dataPath + '/' + Uid + '/file/' + filename))
																		}
																	} else if (_data.status == -2) {} else if (_data.status == -100) {}
																},
																error: function(error) {
																	AlertDialog.confirm(0, "系统繁忙，请稍后重试！")
																}
															});
															if (obj.Convertstatus == 2) {
																db.modifyData('ArticleList', ' IsConvert="1", IsDownLoad="1", downloadStatus="1"', ' articleID = ' + articleIdArr[idNum]);
																if (obj.Filetype == 1 || obj.Filetype == 2 || obj.Filetype == 3 || obj.Filetype == 4) {
																	var HttpPath = obj.Httppath;
																	var index = HttpPath.lastIndexOf(".");
																	var HttpName = HttpPath.substring(index, HttpPath.length);
																	HttpPath = HttpPath.substring(0, HttpPath.length - (HttpName.length + 1));
																	var cssName = HttpPath.substring(index, obj.Httppath);
																	var cssPath = HttpPath.substring(0, cssName.length - 1);
																	request(cssPath + "IE9.css").pipe(fs.createWriteStream(dataPath + '/' + Uid + '/file/' + articleIdArr[idNum] + "IE9.css")).on("close", function(err) {
																		pageNumFun(1);

																		function pageNumFun(pagenum) {
																			if (!navigator.onLine) {
																				_this.parent().find(".downloadList-data").addClass("red").html("网络异常，请稍后重试");
																				_this.attr("src", "img/start.png").attr("class", "start").attr("title", "开始下载").attr("is", 0);
																				$("#app-article-download-win-show .edit7").removeClass("download");
																				$(".start").unbind("click").click(function() {
																					downloadArticleList($(this))
																				});
																				for (var i = 0; i < $(".app-float-download-articleList>div").length; i++) {
																					if ($(".app-float-download-articleList>div").eq(i).find(".state").text() == "等待下载") {
																						$(".app-float-download-articleList>div").eq(i).find(".downloadList-data").addClass("red").html("网络异常，请稍后重试")
																					}
																				};
																				return false
																			};
																			var HttppathName = articleIdArr[idNum] + "_" + pagenum + '.html';
																			request(HttpPath + pagenum + ".html", function(error, response, body) {
																				if (!error && response.statusCode == 200) {
																					request(HttpPath + pagenum + ".html").pipe(fs.createWriteStream(dataPath + '/' + Uid + '/file/' + HttppathName)).on("close", function(err) {
																						if (pagenum == obj.Pagenum) {
																							nextFun()
																						} else {
																							pageNumFun(pagenum + 1)
																						}
																					})
																				} else {
																					db.modifyData('ArticleList', ' IsDownLoad="0", downloadStatus="0"', ' articleID = ' + articleIdArr[idNum]);
																					pageNumFun(pagenum + 1)
																				}
																			})
																		}
																	})
																} else if (obj.Filetype == 5 || obj.Filetype == 6) {
																	db.modifyData('ArticleList', ' PageNum="' + obj.Pagenum + '"', ' articleID = ' + articleIdArr[idNum]);
																	var imgPath = obj.Httppath;
																	var index = imgPath.lastIndexOf(".");
																	var imgName = imgPath.substring(index, imgPath.length);
																	imgPath = imgPath.substring(0, imgPath.length - (imgName.length + 1));
																	var localImgUrl = imgName;
																	for (var i = 1; i <= obj.Pagenum; i++) {
																		var url = imgPath + i + imgName;
																		var name = url.lastIndexOf("\/");
																		request(url).pipe(fs.createWriteStream(dataPath + '/' + uId + '/img/' + articleIdArr[idNum] + "_" + i + imgName));
																		if (localImgUrl == "") {
																			localImgUrl = articleIdArr[idNum] + "_" + i + imgName
																		} else {
																			localImgUrl += ';' + articleIdArr[idNum] + "_" + i + imgName
																		}
																	};
																	db.modifyData('ArticleList', ' localImgUrl="' + localImgUrl + '", imgDownloadStatus="1"', ' articleID = ' + articleIdArr[idNum], function() {
																		nextFun()
																	})
																};

																function nextFun() {
																	db.modifyData('ArticleList', ' isOriginal="' + data.aInf.original + '", ArtPermission="' + data.aInf.Permission + '", FirstArtID="' + data.aInf.firstartid + '", saverNum="' + data.aInf.SNum + '",ReadNum="' + data.ReadNum + '", SaveDate="' + data.aInf.SD + '", sourceName="' + data.aInf.source + '", authorUserID="' + data.aInf.firstuserid + '", ArtType="' + data.aInf.ArtType + '", authorName="' + data.aInf.SNName + '",ArtUrl="' + data.aInf.FromUrl + '",resaveAuthorName="' + data.aInf.firstusername + '",resaveAuthorUserID="' + data.aInf.firstuserid + '",Abstract="' + toTXT(data.aInf.Abstract) + '",Tags="' + Tags + '",keywords="' + Tags + '",Purtext="' + Purtext + '"' + ',Pagenum="' + obj.Pagenum + '",savefrom="' + data.aInf.savefrom + '"', ' articleID = ' + articleIdArr[idNum], function() {
																		var width = (num / articleIdArr.length) * 100;
																		if (width >= 100) {
																			width = 100
																		};
																		db.modifyData('DownLoadProgress', ' progress="' + width + '"', ' CategoryID = ' + CategoryID);
																		if (width.toFixed(2) > Number(_this.parent().find("span.num>i").text())) {
																			_this.parent().find("span.num>i").text(width.toFixed(2));
																			_this.parent().find("span.progress").css("width", width + "%")
																		};
																		if (Number(idNum) + 1 < articleIdArr.length) {
																			downloadArtFun(Number(idNum) + 1)
																		}
																	})
																}
															} else if (obj.Convertstatus >= 0 && obj.Convertstatus <= 1) {
																db.modifyData('ArticleList', ' IsConvert="2", IsDownLoad="1", downloadStatus="0"', ' articleID = ' + articleIdArr[idNum]);
																if (Number(idNum) + 1 < articleIdArr.length) {
																	downloadArtFun(Number(idNum) + 1)
																}
															} else if (obj.Convertstatus < 0) {
																db.modifyData('ArticleList', ' IsConvert="3", IsDownLoad="1", downloadStatus="0"', ' articleID = ' + articleIdArr[idNum]);
																if (Number(idNum) + 1 < articleIdArr.length) {
																	downloadArtFun(Number(idNum) + 1)
																}
															}
														} else if (_data.status == -100 || _data.status == -2) {
															failNum++;
															downloadArtFun(Number(idNum) + 1)
														}
													},
													error: function(error) {
														failNum++;
														downloadArtFun(Number(idNum) + 1)
													}
												})
											} else {
												$("#artContentNone").html(decodeHtml(data.aCnt.Cnt).replace("script src", "script src1"));
												imagepath = '';
												domsrc($("#artContentNone")[0]);
												num++;
												if (data.aCnt.Cnt) {
													var Purtext = removeHTMLTag(decodeHtml(decodeHtml(data.aCnt.Cnt)))
												} else {
													var Purtext = null
												};
												var elements = imagepath.split("$");
												var imgPath = null;
												for (var i = 0; i < elements.length; i++) {
													if (elements[i].indexOf(".360doc.com") >= 0 && elements[i] != "" && elements[i].indexOf("&") < 0) {
														downloadImg(uId, imgpathClear(encodeURI(elements[i])));
														var imgName = elements[i];
														var index = imgName.lastIndexOf("\/");
														imgName = imgName.substring(index + 1);
														if (imgPath == null) {
															imgPath = imgName
														} else {
															imgPath += ';' + imgName
														}
													}
												};
												db.modifyData('ArticleList', ' localImgUrl="' + imgPath + '", imgDownloadStatus="1"', ' articleID = ' + articleIdArr[idNum]);
												db.modifyData("SearchArticleList", ' ArtContent="' + Purtext + '"', ' ArticleID =' + articleIdArr[idNum]);
												db.modifyData('ArticleList', ' ArtContent="' + replaceCharacter(data.aCnt.Cnt) + '", isOriginal="' + data.aInf.original + '", ArtPermission="' + data.aInf.Permission + '", FirstArtID="' + data.aInf.firstartid + '", saverNum="' + data.aInf.SNum + '",ReadNum="' + data.ReadNum + '", SaveDate="' + data.aInf.SD + '", sourceName="' + data.aInf.source + '", authorUserID="' + data.aInf.firstuserid + '", ArtType="' + data.aInf.ArtType + '", authorName="' + data.aInf.SNName + '",ArtUrl="' + data.aInf.FromUrl + '",resaveAuthorName="' + data.aInf.firstusername + '",resaveAuthorUserID="' + data.aInf.firstuserid + '",IsDownLoad="1",Abstract="' + toTXT(data.aInf.Abstract) + '",Tags="' + Tags + '",keywords="' + Tags + '",savefrom="' + data.aInf.savefrom + '"', ' articleID = ' + articleIdArr[idNum], function() {
													var width = (num / articleIdArr.length) * 100;
													if (width >= 100) {
														width = 100
													};
													db.modifyData('DownLoadProgress', ' progress="' + width + '"', ' CategoryID = ' + CategoryID);
													if (width.toFixed(2) > Number(_this.parent().find("span.num>i").text())) {
														_this.parent().find("span.num>i").text(width.toFixed(2));
														_this.parent().find("span.progress").css("width", width + "%")
													};
													if (Number(idNum) + 1 < articleIdArr.length) {
														downloadArtFun(Number(idNum) + 1)
													}
												})
											}
										} else if (data.status == -100 || data.status == -2) {
											failNum++;
											downloadArtFun(Number(idNum) + 1)
										}
									},
									error: function(error) {
										setTimeout(function() {
											if (!navigator.onLine) {
												_this.parent().find(".downloadList-data").addClass("red").html("网络异常，请稍后重试");
												_this.attr("src", "img/start.png").attr("class", "start").attr("title", "开始下载").attr("is", 0);
												$("#app-article-download-win-show .edit7").removeClass("download");
												$(".start").unbind("click").click(function() {
													downloadArticleList($(this))
												});
												for (var i = 0; i < $(".app-float-download-articleList>div").length; i++) {
													if ($(".app-float-download-articleList>div").eq(i).find(".state").text() == "等待下载") {
														$(".app-float-download-articleList>div").eq(i).find(".downloadList-data").addClass("red").html("网络异常，请稍后重试")
													}
												};
												return false
											};
											failNum++;
											downloadArtFun(Number(idNum) + 1)
										}, 1000)
									},
									complete: function() {
										if (_this.attr("is") == '1') {
											downloadNum++;
											_this.attr("num", downloadNum);
											if (_this.attr("num") == articleIdArr.length) {
												if (!navigator.onLine) {
													_this.parent().find(".downloadList-data").addClass("red").html("网络异常，请稍后重试");
													_this.attr("src", "img/start.png").attr("class", "start").attr("title", "开始下载").attr("is", 0);
													$("#app-article-download-win-show .edit7").removeClass("download");
													$(".start").unbind("click").click(function() {
														downloadArticleList($(this))
													});
													for (var i = 0; i < $(".app-float-download-articleList>div").length; i++) {
														if ($(".app-float-download-articleList>div").eq(i).find(".state").text() == "等待下载") {
															$(".app-float-download-articleList>div").eq(i).find(".downloadList-data").addClass("red").html("网络异常，请稍后重试")
														}
													};
													return false
												};
												db.modifyData('DownLoadProgress', ' progress="100"', ' CategoryID = ' + CategoryID);
												if (failNum == 0) {
													_this.parents("div.downloadList-fr").text("下载完成").parent().find(">div.downloadList-fl").removeClass("download").addClass("downloaded");
													db.modifyData('CategoryMyLibrary', ' IsDownLoad="1"', ' CategoryID = ' + _thisCid.attr("cid"))
												} else {
													_this.parents("div.downloadList-fr").html('下载完成（<span class="red">' + failNum + ' </span>篇下载失败 <i class="prompt" prompt="文章已被删除"></i>）').parent().find(">div.downloadList-fl").removeClass("download").addClass("downloaded");
													$(".prompt").unbind("hover").hover(function() {
														$("body").append('<div class="promptText" style="top:' + ($(this).offset().top - 13) + 'px;left:' + ($(this).offset().left + 27) + 'px;">' + $(this).attr("prompt") + '</div>')
													}, function() {
														$(".promptText").remove()
													})
												};
												for (var i = 0; i < $(".downloadList").length; i++) {
													if ($(".downloadList").eq(i).find(">.downloadList-fr span.state").text() == "等待下载") {
														$(".downloadList").eq(i).find(".downloadList-fr img").attr("src", "img/start.png").attr("class", "start").attr("title", "开始下载").attr("is", 0);
														setTimeout(function() {
															downloadArticleList($(".downloadList").eq(i).find(".downloadList-fr img.start"))
														}, 100);
														$("#app-article-download-win-show .edit7").addClass("download");
														return false
													} else {
														$("#app-article-download-win-show .edit7").removeClass("download")
													}
												}
											}
										}
									}
								})
							}
						} else {
							if (_this.attr("is") == '1') {
								downloadNum++;
								_this.attr("num", downloadNum);
								if (_this.attr("num") == articleIdArr.length) {
									if (!navigator.onLine) {
										_this.parent().find(".downloadList-data").addClass("red").html("网络异常，请稍后重试");
										_this.attr("src", "img/start.png").attr("class", "start").attr("title", "开始下载").attr("is", 0);
										$("#app-article-download-win-show .edit7").removeClass("download");
										$(".start").unbind("click").click(function() {
											downloadArticleList($(this))
										});
										for (var i = 0; i < $(".app-float-download-articleList>div").length; i++) {
											if ($(".app-float-download-articleList>div").eq(i).find(".state").text() == "等待下载") {
												$(".app-float-download-articleList>div").eq(i).find(".downloadList-data").addClass("red").html("网络异常，请稍后重试")
											}
										};
										return false
									};
									db.modifyData('DownLoadProgress', ' progress="100"', ' CategoryID = ' + CategoryID);
									if (failNum == 0) {
										_this.parents("div.downloadList-fr").text("下载完成").parent().find(">div.downloadList-fl").removeClass("download").addClass("downloaded");
										db.modifyData('CategoryMyLibrary', ' IsDownLoad="1"', ' CategoryID = ' + _thisCid.attr("cid"))
									} else {
										_this.parents("div.downloadList-fr").html('下载完成（<span class="red">' + failNum + ' </span>篇下载失败 <i class="prompt" prompt="文章已被删除"></i>）').parent().find(">div.downloadList-fl").removeClass("download").addClass("downloaded");
										$(".prompt").unbind("hover").hover(function() {
											$("body").append('<div class="promptText" style="top:' + ($(this).offset().top - 13) + 'px;left:' + ($(this).offset().left + 27) + 'px;">' + $(this).attr("prompt") + '</div>')
										}, function() {
											$(".promptText").remove()
										})
									}
									for (var i = 0; i < $(".downloadList").length; i++) {
										if ($(".downloadList").eq(i).find(">.downloadList-fr span.state").text() == "等待下载") {
											$(".downloadList").eq(i).find(".downloadList-fr img").attr("src", "img/start.png").attr("class", "start").attr("title", "开始下载").attr("is", 0);
											setTimeout(function() {
												downloadArticleList($(".downloadList").eq(i).find(".downloadList-fr img.start"))
											}, 100);
											$("#app-article-download-win-show .edit7").addClass("download");
											return false
										} else {
											$("#app-article-download-win-show .edit7").removeClass("download")
										}
									}
								} else {
									num++;
									downloadArtFun(num)
								}
							}
						}
					}, function(id) {
						if (id == 0) {
							failNum++;
							num++;
							if (Number(idNum) + 1 < articleIdArr.length) {
								downloadArtFun(Number(idNum) + 1)
							} else {
								if (_this.attr("is") == '1') {
									if (num == articleIdArr.length) {
										if (!navigator.onLine) {
											_this.parent().find(".downloadList-data").addClass("red").html("网络异常，请稍后重试");
											_this.attr("src", "img/start.png").attr("class", "start").attr("title", "开始下载").attr("is", 0);
											$("#app-article-download-win-show .edit7").removeClass("download");
											$(".start").unbind("click").click(function() {
												downloadArticleList($(this))
											});
											for (var i = 0; i < $(".app-float-download-articleList>div").length; i++) {
												if ($(".app-float-download-articleList>div").eq(i).find(".state").text() == "等待下载") {
													$(".app-float-download-articleList>div").eq(i).find(".downloadList-data").addClass("red").html("网络异常，请稍后重试")
												}
											};
											return false
										};
										db.modifyData('DownLoadProgress', ' progress="100"', ' CategoryID = ' + CategoryID);
										if (failNum == 0) {
											_this.parents("div.downloadList-fr").text("下载完成").parent().find(">div.downloadList-fl").removeClass("download").addClass("downloaded");
											db.modifyData('CategoryMyLibrary', ' IsDownLoad="1"', ' CategoryID = ' + _thisCid.attr("cid"))
										} else {
											_this.parents("div.downloadList-fr").html('下载完成（<span class="red">' + failNum + ' </span>篇下载失败 <i class="prompt" prompt="文章已被删除"></i>）').parent().find(">div.downloadList-fl").removeClass("download").addClass("downloaded");
											$(".prompt").unbind("hover").hover(function() {
												$("body").append('<div class="promptText" style="top:' + ($(this).offset().top - 13) + 'px;left:' + ($(this).offset().left + 27) + 'px;">' + $(this).attr("prompt") + '</div>')
											}, function() {
												$(".promptText").remove()
											})
										};
										for (var i = 0; i < $(".downloadList").length; i++) {
											if ($(".downloadList").eq(i).find(">.downloadList-fr span.state").text() == "等待下载") {
												$(".downloadList").eq(i).find(".downloadList-fr img").attr("src", "img/start.png").attr("class", "start").attr("title", "开始下载").attr("is", 0);
												setTimeout(function() {
													downloadArticleList($(".downloadList").eq(i).find(".downloadList-fr img.start"))
												}, 100);
												$("#app-article-download-win-show .edit7").addClass("download");
												return false
											} else {
												$("#app-article-download-win-show .edit7").removeClass("download")
											}
										}
									}
								}
							}
						}
					})
				}
			}
		} else {
			_this.attr("is", "0");
			_this.parent().find(".downloadList-selected span.state").html("暂停中");
			_this.attr("src", "img/start.png").attr("class", "start").attr("title", "开始下载").attr("num", 0);
			$("#app-article-download-win-show .edit7").removeClass("download");
			for (var i = 0; i < $(".downloadList").length; i++) {
				if ($(".downloadList").eq(i).find(">.downloadList-fr span.state").text() == "等待下载") {
					$(".downloadList").eq(i).find(".downloadList-fr img").attr("src", "img/start.png").attr("class", "start").attr("title", "开始下载").attr("is", 0);
					setTimeout(function() {
						downloadArticleList($(".downloadList").eq(i).find(".downloadList-fr img.start"))
					}, 100);
					$("#app-article-download-win-show .edit7").addClass("download");
					return false
				} else {
					$("#app-article-download-win-show .edit7").removeClass("download")
				}
			}
		}
	};
	$(".app-article-download-float-close").click(function() {
		if ($(".downloadList>.downloadList-fr span.state").text().indexOf("正在下载") > -1) {
			AlertDialog.confirm(1, "你当前有下载任务正在进行，确认退出？点击确定将中断下载。", function() {
				$(".app-edit a").removeClass("con");
				$("#app-article-float-download").hide();
				$(".app-float-download-articleList").html("");
				$("#app-article-download-win-show i").removeClass("download")
			})
		} else {
			$(".app-edit a").removeClass("con");
			$("#app-article-float-download").hide();
			$(".app-float-download-articleList").html("");
			$("#app-article-download-win-show i").removeClass("download")
		}
	});
	$("#backgroundDownload").click(function() {
		if ($(".downloadList>.downloadList-fl").is(".downloadReady") || $(".downloadList>.downloadList-fl").is(".download")) {
			$(".downloadList>.downloadList-fr>.start").trigger("click");
			$("#app-article-download-win-show i").addClass("download");
			$("#app-article-float-download").hide();
			$(".app-edit a").removeClass("con")
		} else {
			AlertDialog.confirm(0, "请勾选要下载的文件夹！")
		}
	});

	function preservationArticleList() {
		db.GetTable("ArticleList", function(row) {
			if (row == 0) {
				db.CreateTable("ArticleList", "articleID INTEGER,artType INTEGER,ArticleTitle text,keywords text,Abstract text,SaveDate INTEGER,SaverUserID INTEGER,ArtPermission INTEGER,Tags text,isChecked INTEGER,FirstArtID INTEGER,authorName text,authorUserID text,resaveAuthorName text,resaveAuthorUserID INTEGER,categoryID INTEGER,isOriginal INTEGER,ArtUrl text,sourceName text,ReadNum INTEGER,flowersNum INTEGER,commentNum INTEGER,saverNum INTEGER,ArtContent text,IsUpload INTEGER,Logid  text,IsDelete INTEGER,PrevCategoryID INTEGER,IsDownLoad text,downloadStatus INTEGER,localImgUrl text,imgDownloadStatus INTEGER,IsConvert INTEGER,PageNum INTEGER,Purtext text,Offvalue INTEGER,Permitdownload  INTEGER,docsize INTEGER,iscream INTEGER,savefrom INTEGER,originalActivityID text,newData1 text,newData2 text,newData3 text", function(callback) {
					if (callback) {
						ArticleListDataInt(2, 500, 0)
					}
				})
			} else {
				db.dataNull('ArticleList', function(err) {
					if (err) {
						db.checkDataSort('ArticleList', '*', ' articleID desc limit 1', function(data, err) {
							ArticleListDataInt(2, 500, Number(data.articleID) + 1)
						})
					} else {
						ArticleListDataInt(2, 500, 0)
					}
				})
			}
		})
	};
	var refreshNum = 0;

	function ArticleListDataInt(ot, dn, aid) {
		if (!navigator.onLine) {
			$("#Initialization").hide();
			$(".refresh").attr("class", "refresh refresh2");
			$(".refresh-hover .refresh-execution").addClass("none");
			$(".refresh-hover .refresh-Result").addClass("block").find("b").html("网络异常，无法同步");
			db.batchData(" dataStorage ", " updateTime='" + getNowFormatDate("-", 0) + "'");
			db.checkData('dataStorage', '*', null, function(row, err) {
				if (row.updateTime.substr(0, 4) == getNowFormatDate("-", 0).substr(0, 4)) {
					$(".refresh-hover .refresh-Result").find("i").text(getNowFormatDate("-", 0).substr(5, 11))
				} else {
					$(".refresh-hover .refresh-Result").find("i").text(getNowFormatDate("-", 0).substr(0, 16))
				}
			});
			AlertDialog.grayConfirm(0, "网络连接异常，请稍后重试！");
			return false
		};
		var strRequestUrl = cv.post + "/ajax/Sync.ashx?ver=0.01&os=windows&op=syncArt&ot=" + ot + "&dn=" + dn + "&aid=" + aid;
		var sign = "&sign=" + getSign.sign(strRequestUrl + "&UserCode=" + myReplace(UserCode));
		var permissionName = null;
		var dataArr = null,
			SearchDataArr = null;
		var aidRecord = 0;
		$.ajax({
			url: strRequestUrl + sign,
			type: 'POST',
			data: {
				"UserCode": UserCode
			},
			success: function(result) {
				if (result == "") {
					Sync == 0;
					$("#Initialization .Initialization_content em,#InitializationStop em").text("100%");
					$("#Initialization .progressBar i").css({
						"width": "100%"
					});
					$("#InitializationStop i").text("初始化完成！");
					$("#InitializationSure").text("初始化完成");
					sh.modifyData('usersInfo', ' newData1=100 ', ' UserID = ' + Uid);
					setTimeout(function() {
						if ($("#InitializationStop").attr("type") == 1) {
							$("#Initialization").hide();
							$("#InitializationStop").hide()
						} else {
							$("#Initialization").hide();
							$("#InitializationStop").hide();
							noviceGuidance(0)
						};
						$(".app-articleList>.noData").text("该图书馆还没有文章！").show();
						$(".app-article .noData").show();
						$("#artContent,#divartlist").html("");
						$(".refresh").attr("class", "refresh refresh1");
						$(".refresh-hover .refresh-execution").addClass("none");
						$(".refresh-hover .refresh-Result").addClass("block").find("b").html("同步成功");
						db.batchData(" dataStorage ", " updateTime='" + getNowFormatDate("-", 0) + "'");
						db.checkData('dataStorage', '*', null, function(row, err) {
							if (row.updateTime.substr(0, 4) == getNowFormatDate("-", 0).substr(0, 4)) {
								$(".refresh-hover .refresh-Result").find("i").text(getNowFormatDate("-", 0).substr(5, 11))
							} else {
								$(".refresh-hover .refresh-Result").find("i").text(getNowFormatDate("-", 0).substr(0, 16))
							}
						})
					}, 3000);
					return false
				};
				var data = JSON.parse(result);
				var dataNumber = 0;
				if (data.status == 1) {
					var dataNum = data.NAItem,
						UID = null,
						UName = null;
					if (dataNum.length > 0) {
						for (var i = 0; i < dataNum.length; i++) {
							if (dataNum[i].UID) {
								UID = dataNum[i].UID
							};
							if (dataNum[i].UName) {
								UName = dataNum[i].UName
							};
							if (aid != dataNum[i].Aid) {
								var num = i;
								dataNumber++;
								sum++;
								Increasing++;
								if (dataArr == null) {
									dataArr = dataNum[i].Aid + ',' + dataNum[i].arttype + ',"' + replaceCharacter(dataNum[i].Tit) + '",' + null + ',' + null + ',' + dataNum[i].SD + ',' + Uid + ',' + dataNum[i].Permission + ',' + null + ',' + dataNum[i].ischecked + ',' + null + ',' + null + ',' + null + ',' + UID + ',"' + UName + '",' + dataNum[i].CategoryID + ',' + dataNum[i].original + ',' + null + ',' + null + ',' + dataNum[i].ReadN + ',' + null + ',' + null + ',' + dataNum[i].SaveN + ',' + null + ',' + 1 + ',' + null + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + 0 + ',' + dataNum[i].iscream + ',' + 0 + ',' + null + ',' + null + ',' + null + ',' + null;
									SearchDataArr = dataNum[i].Aid + ',"' + removeHTMLTag(dataNum[i].Tit) + '","' + Number(dataNum[i].SD) + '",' + null + ',' + dataNum[i].arttype + ',' + null + ',' + null + ',' + null
								} else {
									dataArr += "||" + dataNum[i].Aid + ',' + dataNum[i].arttype + ',"' + replaceCharacter(dataNum[i].Tit) + '",' + null + ',' + null + ',' + dataNum[i].SD + ',' + Uid + ',' + dataNum[i].Permission + ',' + null + ',' + dataNum[i].ischecked + ',' + null + ',' + null + ',' + null + ',' + UID + ',"' + UName + '",' + dataNum[i].CategoryID + ',' + dataNum[i].original + ',' + null + ',' + null + ',' + dataNum[i].ReadN + ',' + null + ',' + null + ',' + dataNum[i].SaveN + ',' + null + ',' + 1 + ',' + null + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + 0 + ',' + dataNum[i].iscream + ',' + 0 + ',' + null + ',' + null + ',' + null + ',' + null;
									SearchDataArr += "||" + dataNum[i].Aid + ',"' + removeHTMLTag(dataNum[i].Tit) + '","' + Number(dataNum[i].SD) + '",' + null + ',' + dataNum[i].arttype + ',' + null + ',' + null + ',' + null
								};
								aidRecord = Number(dataNum[i].Aid);
								if (i == dataNum.length - 1) {
									var dataLength = dataNum.length;
									db.newSaveData("ArticleList (articleID,artType,ArticleTitle,keywords,Abstract,SaveDate,SaverUserID,ArtPermission,Tags,isChecked,FirstArtID,authorName,authorUserID ,resaveAuthorName,resaveAuthorUserID,categoryID,isOriginal,ArtUrl,sourceName,ReadNum,flowersNum,commentNum,saverNum,ArtContent,IsUpload,Logid,IsDelete,PrevCategoryID,IsDownLoad,downloadStatus,localImgUrl,imgDownloadStatus,IsConvert,PageNum,Purtext,Offvalue,Permitdownload,docsize,iscream,savefrom,originalActivityID,newData1,newData2,newData3)", "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", dataArr, function(err) {
										if (((sum + 1) / artTotal * 100) >= 100) {
											if (!$("#Initialization").is(":hidden")) {
												var t1Num = 0;
												var t1 = window.setInterval(function() {
													t1Num++;
													if (t1Num == 10) {
														$("#InitializationStop i").text("初始化完成！");
														$("#InitializationSure").text("初始化完成");
														$("#Initialization .Initialization_content em,#InitializationStop em").text((sum / artTotal * 100).toFixed(0) + "%");
														$("#Initialization .progressBar i").css({
															"width": sum / artTotal * 100 + "%"
														});
														setTimeout(function() {
															if ($("#InitializationStop").attr("type") == 1) {
																$("#Initialization").hide();
																$("#InitializationStop").hide()
															} else {
																$("#Initialization").hide();
																noviceGuidance(0)
															}
														}, 3000);
														window.clearInterval(t1);
														paging(sum, 50, 1);
														ArticleList(0, 50, null, sum, artTotal, true);
														sh.modifyData('usersInfo', ' newData1=100 ', ' UserID = ' + Uid)
													} else {
														db.dataNull('ArticleList', function(err, id) {
															if (id > 0) {
																$("#InitializationStop i").text("初始化完成！");
																$("#InitializationSure").text("初始化完成");
																$("#Initialization .Initialization_content em,#InitializationStop em").text((sum / artTotal * 100).toFixed(0) + "%");
																$("#Initialization .progressBar i").css({
																	"width": sum / artTotal * 100 + "%"
																});
																setTimeout(function() {
																	if ($("#InitializationStop").attr("type") == 1) {
																		$("#Initialization").hide();
																		$("#InitializationStop").hide()
																	} else {
																		$("#Initialization").hide();
																		noviceGuidance(0)
																	}
																}, 3000);
																window.clearInterval(t1);
																paging(sum, 50, 1);
																ArticleList(0, 50, null, sum, artTotal, true);
																sh.modifyData('usersInfo', ' newData1=100 ', ' UserID = ' + Uid)
															}
														})
													}
												}, 2000)
											} else {
												sh.modifyData('usersInfo', ' newData1=100 ', ' UserID = ' + Uid);
												$("#InitializationStop i").text("初始化完成！");
												$("#InitializationSure").text("初始化完成");
												$("#Initialization .Initialization_content em,#InitializationStop em").text((sum / artTotal * 100).toFixed(0) + "%");
												$("#Initialization .progressBar i").css({
													"width": sum / artTotal * 100 + "%"
												});
												setTimeout(function() {
													$("#Initialization").hide();
													$("#InitializationStop").hide()
												}, 3000)
											};
											$(".refresh").attr("class", "refresh refresh1");
											$(".refresh-hover .refresh-execution").addClass("none");
											$(".refresh-hover .refresh-Result").addClass("block").find("b").html("同步成功");
											db.batchData(" dataStorage ", " updateTime='" + getNowFormatDate("-", 0) + "'");
											db.checkData('dataStorage', '*', null, function(row, err) {
												if (row.updateTime.substr(0, 4) == getNowFormatDate("-", 0).substr(0, 4)) {
													$(".refresh-hover .refresh-Result").find("i").text(getNowFormatDate("-", 0).substr(5, 11))
												} else {
													$(".refresh-hover .refresh-Result").find("i").text(getNowFormatDate("-", 0).substr(0, 16))
												}
											});
											return false
										};
										$("#Initialization .Initialization_content em,#InitializationStop em").text((sum / artTotal * 100).toFixed(0) + "%");
										$("#Initialization .progressBar i").css({
											"width": sum / artTotal * 100 + "%"
										});
										sh.modifyData('usersInfo', ' newData1=' + (sum / artTotal * 100).toFixed(0), ' UserID = ' + Uid);
										if (dataLength < 100) {} else {
											if (!$("#Initialization").is(":hidden")) {
												if (refreshNum == 0) {
													refreshNum = 1;
													setTimeout(function() {
														paging(sum, 50, 1);
														ArticleList(0, 50, null, sum, artTotal)
													}, 2000)
												}
											};
											ArticleListDataInt(2, 100, aidRecord + 1)
										}
									});
									db.newSaveData("SearchArticleList(ArticleID,ArticleTitle,SaveDate,ArtContent,Arttype,newData1,newData2,newData3)", "(?,?,?,?,?,?,?,?)", SearchDataArr, function(err) {})
								}
							} else if (dataNum.length == 1 && aid == dataNum[i].Aid) {
								var num = i;
								dataNumber++;
								sum++;
								Increasing++;
								if (dataArr == null) {
									dataArr = dataNum[i].Aid + ',' + dataNum[i].arttype + ',"' + replaceCharacter(dataNum[i].Tit) + '",' + null + ',' + null + ',' + dataNum[i].SD + ',' + Uid + ',' + dataNum[i].Permission + ',' + null + ',' + null + ',' + null + ',' + null + ',' + null + ',' + UID + ',"' + UName + '",' + dataNum[i].CategoryID + ',' + dataNum[i].original + ',' + null + ',' + null + ',' + dataNum[i].ReadN + ',' + null + ',' + null + ',' + dataNum[i].SaveN + ',' + null + ',' + 1 + ',' + null + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + 0 + ',' + dataNum[i].iscream + ',' + 0 + ',' + null + ',' + null + ',' + null + ',' + null;
									SearchDataArr = dataNum[num].Aid + ',"' + removeHTMLTag(dataNum[num].Tit) + '","' + formatDate(Number(dataNum[num].SD)) + '",' + null + ',' + dataNum[num].arttype + ',' + null + ',' + null + ',' + null
								} else {
									dataArr += "||" + dataNum[i].Aid + ',' + dataNum[i].arttype + ',"' + replaceCharacter(dataNum[i].Tit) + '",' + null + ',' + null + ',' + dataNum[i].SD + ',' + Uid + ',' + dataNum[i].Permission + ',' + null + ',' + null + ',' + null + ',' + null + ',' + null + ',' + UID + ',"' + UName + '",' + dataNum[i].CategoryID + ',' + dataNum[i].original + ',' + null + ',' + null + ',' + dataNum[i].ReadN + ',' + null + ',' + null + ',' + dataNum[i].SaveN + ',' + null + ',' + 1 + ',' + null + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + 0 + ',' + dataNum[i].iscream + ',' + 0 + ',' + null + ',' + null + ',' + null + ',' + null;
									SearchDataArr += "||" + dataNum[num].Aid + ',"' + removeHTMLTag(dataNum[num].Tit) + '","' + formatDate(Number(dataNum[num].SD)) + '",' + null + ',' + dataNum[num].arttype + ',' + null + ',' + null + ',' + null
								}
								aidRecord = Number(dataNum[i].Aid);
								var dataLength = dataNum.length;
								db.newSaveData("ArticleList (articleID,artType,ArticleTitle,keywords,Abstract,SaveDate,SaverUserID,ArtPermission,Tags,isChecked,FirstArtID,authorName,authorUserID ,resaveAuthorName,resaveAuthorUserID,categoryID,isOriginal,ArtUrl,sourceName,ReadNum,flowersNum,commentNum,saverNum,ArtContent,IsUpload,Logid,IsDelete,PrevCategoryID,IsDownLoad,downloadStatus,localImgUrl,imgDownloadStatus,IsConvert,PageNum,Purtext,Offvalue,Permitdownload,docsize,iscream,savefrom,originalActivityID,newData1,newData2,newData3)", "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", dataArr, function(err) {
									$("#Initialization .Initialization_content em,#InitializationStop em").text((sum / artTotal * 100).toFixed(0) + "%");
									if (((sum + 1) / artTotal * 100) >= 100) {
										sh.modifyData('usersInfo', ' newData1=100 ', ' UserID = ' + Uid);
										$("#InitializationStop i").text("初始化完成！");
										$("#InitializationSure").text("初始化完成");
										setTimeout(function() {
											if ($("#InitializationStop").attr("type") == 1) {
												$("#Initialization").hide();
												$("#InitializationStop").hide()
											} else {
												$("#Initialization").hide();
												noviceGuidance(0)
											};
											$(".refresh").attr("class", "refresh refresh1");
											$(".refresh-hover .refresh-execution").addClass("none");
											$(".refresh-hover .refresh-Result").addClass("block").find("b").html("同步成功");
											db.batchData(" dataStorage ", " updateTime='" + getNowFormatDate("-", 0) + "'");
											db.checkData('dataStorage', '*', null, function(row, err) {
												if (row.updateTime.substr(0, 4) == getNowFormatDate("-", 0).substr(0, 4)) {
													$(".refresh-hover .refresh-Result").find("i").text(getNowFormatDate("-", 0).substr(5, 11))
												} else {
													$(".refresh-hover .refresh-Result").find("i").text(getNowFormatDate("-", 0).substr(0, 16))
												}
											})
										}, 3000)
									};
									$("#Initialization .progressBar i").css({
										"width": sum / artTotal * 100 + "%"
									});
									sh.modifyData('usersInfo', ' newData1=' + (sum / artTotal * 100).toFixed(0), ' UserID = ' + Uid);
									if (!$("#Initialization").is(":hidden")) {
										if (refreshNum == 0) {
											refreshNum = 1;
											setTimeout(function() {
												paging(sum, 50, 1);
												ArticleList(0, 50, null, sum, artTotal, true);
												if ($("#divartlist li").eq(0).attr("arttype") <= 6) {
													GetArticles($("#divartlist li").eq(0).attr("categoryid"), $("#divartlist li").eq(0).attr("aid"))
												} else {
													GetFileArticles($("#divartlist li").eq(0).attr("categoryid"), $("#divartlist li").eq(0).attr("aid"), $("#divartlist li").eq(0).attr("arttype"))
												}
											}, 2000)
										}
									}
								});
								db.newSaveData("SearchArticleList(ArticleID,ArticleTitle,SaveDate,ArtContent,Arttype,newData1,newData2,newData3)", "(?,?,?,?,?,?,?,?)", SearchDataArr, function(err) {})
							}
						}
					} else {
						Sync == 0
					}
				} else {
					Sync == 0
				}
			},
			error: function(error) {
				Sync == 0;
				$("#Initialization").hide();
				$(".refresh").attr("class", "refresh refresh2");
				$(".refresh-hover .refresh-execution").addClass("none");
				$(".refresh-hover .refresh-Result").addClass("block").find("b").html("网络异常，无法同步");
				db.batchData(" dataStorage ", " updateTime='" + getNowFormatDate("-", 0) + "'");
				db.checkData('dataStorage', '*', null, function(row, err) {
					if (row.updateTime.substr(0, 4) == getNowFormatDate("-", 0).substr(0, 4)) {
						$(".refresh-hover .refresh-Result").find("i").text(getNowFormatDate("-", 0).substr(5, 11))
					} else {
						$(".refresh-hover .refresh-Result").find("i").text(getNowFormatDate("-", 0).substr(0, 16))
					}
				});
				AlertDialog.grayConfirm(0, "网络连接异常，请稍后重试！");
				return false
			}
		})
	};
	$(".app-tree-hide").click(function() {
		$(".app-articleList").animate({
			left: '0'
		});
		$(".app-article").animate({
			marginLeft: '262px'
		});
		$(".app-tree,.app-tree-hide").animate({
			left: '-250px'
		}, function() {
			$(".app-tree-show").show()
		})
	});
	$(".app-tree-show").click(function() {
		$(".app-tree-show").hide();
		$(".app-tree").animate({
			left: '0'
		});
		$(".app-articleList").animate({
			left: '251px'
		});
		$(".app-article").animate({
			marginLeft: '514px'
		});
		$(".app-tree-hide").animate({
			left: '241px'
		})
	});
	$(".app-screen-tit").click(function(event) {
		event.stopImmediatePropagation();
		$("#operation").removeClass("h").find("em").hide();
		$(".articleList-ope").hide();
		$(".app-screen-articleList").removeClass("ovfHiden");
		$(".app-screen-tit").find("ul").hide();
		$(this).find("ul").slideToggle();
		$(".app-screen-download li").click(function(event) {
			event.stopImmediatePropagation();
			$(this).parents("div.app-screen-download").find("span").attr("type", $(this).attr("type")).text($(this).attr("tit"));
			$(this).parents("ul").hide();
			if ($(".app-screen-type span").attr("type") != "0" && $(".app-screen-type span").attr("type") == 1) {
				var artType = "artType<='" + $(".app-screen-type span").attr("type") + "'"
			} else if ($(".app-screen-type span").attr("type") != "0" && $(".app-screen-type span").attr("type") == 50) {
				var artType = "artType>'" + $(".app-screen-type span").attr("type") + "'"
			} else if ($(".app-screen-type span").attr("type") != "0" && $(".app-screen-type span").attr("type") == 2) {
				var artType = "artType='" + $(".app-screen-type span").attr("type") + "'"
			};
			if ($("#TreeId").val()) {
				if ($(".app-screen-download span").attr("type") == "" && $(".app-screen-type span").attr("type") == "") {
					var where = "CategoryID='" + $("#TreeId").val() + "'"
				} else if ($(".app-screen-download span").attr("type") != "" && $(".app-screen-type span").attr("type") != "") {
					var where = "CategoryID='" + $("#TreeId").val() + "' and " + artType + " and IsDownLoad=" + $(".app-screen-download span").attr("type")
				} else if ($(".app-screen-download span").attr("type") != "" && $(".app-screen-type span").attr("type") == "") {
					var where = "CategoryID='" + $("#TreeId").val() + "' and IsDownLoad=" + $(".app-screen-download span").attr("type")
				} else if ($(".app-screen-download span").attr("type") == "" && $(".app-screen-type span").attr("type") != "") {
					var where = "CategoryID='" + $("#TreeId").val() + "' and " + artType
				}
			} else {
				if ($(".app-screen-download span").attr("type") == "" && $(".app-screen-type span").attr("type") == "") {
					var where = null
				} else if ($(".app-screen-download span").attr("type") != "" && $(".app-screen-type span").attr("type") != "") {
					var where = artType + " and IsDownLoad=" + $(".app-screen-download span").attr("type")
				} else if ($(".app-screen-download span").attr("type") != "" && $(".app-screen-type span").attr("type") == "") {
					var where = "IsDownLoad=" + $(".app-screen-download span").attr("type")
				} else if ($(".app-screen-download span").attr("type") == "" && $(".app-screen-type span").attr("type") != "") {
					var where = artType
				}
			};
			ArticleList(0, 50, where, 1, null, true)
		});
		$(".app-screen-type li").click(function(event) {
			event.stopImmediatePropagation();
			$(this).parents("div.app-screen-type").find("span").attr("type", $(this).attr("type")).text($(this).attr("tit"));
			$(this).parents("ul").hide();
			if ($(".app-screen-type span").attr("type") != "0" && $(".app-screen-type span").attr("type") == 1) {
				var artType = "artType<='" + $(".app-screen-type span").attr("type") + "'"
			} else if ($(".app-screen-type span").attr("type") != "0" && $(".app-screen-type span").attr("type") == 50) {
				var artType = "artType>'" + $(".app-screen-type span").attr("type") + "'"
			} else if ($(".app-screen-type span").attr("type") != "0" && $(".app-screen-type span").attr("type") == 2) {
				var artType = "artType='" + $(".app-screen-type span").attr("type") + "'"
			};
			if ($("#TreeId").val()) {
				if ($(".app-screen-download span").attr("type") == "" && $(".app-screen-type span").attr("type") == "") {
					var where = "CategoryID='" + $("#TreeId").val() + "'"
				} else if ($(".app-screen-download span").attr("type") != "" && $(".app-screen-type span").attr("type") != "") {
					var where = "CategoryID='" + $("#TreeId").val() + "' and " + artType + " and IsDownLoad='" + $(".app-screen-download span").attr("type") + "'"
				} else if ($(".app-screen-download span").attr("type") != "" && $(".app-screen-type span").attr("type") == "") {
					var where = "CategoryID='" + $("#TreeId").val() + "' and IsDownLoad='" + $(".app-screen-download span").attr("type") + "'"
				} else if ($(".app-screen-download span").attr("type") == "" && $(".app-screen-type span").attr("type") != "") {
					var where = "CategoryID='" + $("#TreeId").val() + "' and " + artType
				}
			} else {
				if ($(".app-screen-download span").attr("type") == "" && $(".app-screen-type span").attr("type") == "") {
					var where = null
				} else if ($(".app-screen-download span").attr("type") != "" && $(".app-screen-type span").attr("type") != "") {
					var where = artType + " and IsDownLoad='" + $(".app-screen-download span").attr("type") + "'"
				} else if ($(".app-screen-download span").attr("type") != "" && $(".app-screen-type span").attr("type") == "") {
					var where = "IsDownLoad='" + $(".app-screen-download span").attr("type") + "'"
				} else if ($(".app-screen-download span").attr("type") == "" && $(".app-screen-type span").attr("type") != "") {
					var where = artType
				}
			};
			ArticleList(0, 50, where, 1, null, true)
		})
	});
	$(".Search-screen-tit").click(function(event) {
		event.stopImmediatePropagation();
		$("#operation").removeClass("h").find("em").hide();
		if ($(this).index() == 1) {
			$(".Search-screen-time>ul").hide()
		} else {
			$(".Search-screen-type>ul").hide()
		};
		$(this).find("ul").slideToggle();
		$(".Search-screen-type li").click(function(event) {
			event.stopImmediatePropagation();
			$(this).parents("div.Search-screen-type").find("span").attr("type", $(this).attr("type")).text($(this).attr("tit"));
			$(this).parents("ul").hide();
			SearchArticleList(0, $(".Search-screen-type span.type").attr("type"), $(".Search-screen-time span.time").attr("time"), 0)
		});
		$(".Search-screen-time li").click(function(event) {
			event.stopImmediatePropagation();
			$(this).parents("div.Search-screen-time").find("span").attr("time", $(this).attr("time")).text($(this).attr("tit"));
			$(this).parents("ul").hide();
			SearchArticleList(0, $(".Search-screen-type span.type").attr("type"), $(".Search-screen-time span.time").attr("time"), 0)
		})
	});
	$("body,html").click(function(event) {
		event.stopImmediatePropagation();
		$("#operation>em").hide();
		$(".app-screen-tit>ul,.toHide").hide();
		$(".Search-screen-tit>ul").hide();
		$(".articleList-ope").hide().find(".articleList-jur").hide();
		$(".app-screen-articleList").removeClass("ovfHiden");
		$(".draftArticle-open").hide();
		$("#operation").removeClass("h").find("em").hide();
		$(".doc-tags").animate({
			height: "54px"
		}, 500);
		if ($(".doc-tags1").height() >= 150) {
			$(".doc-tags1").animate({
				height: "30px"
			}, 500)
		};
		if ($("#divtags ul li").length == 1) {
			$("#txttags").val("添加关键词，用空格或回车分隔").css("color", "#b2b2b2");
			$("#divtagtip").show()
		};
		var height = $("#middlediv").height();
		var divtreeHeight = height - 99;
		$("#divtree").animate({
			height: "" + divtreeHeight + "px"
		}, 500);
		$(".doc360ul03").animate({
			height: "" + (divtreeHeight - 50) + "px"
		}, 500);
		$("#fenxiangLayer").hide();
		$("#divmypre,#divmypre1").hide()
	});
	document.oncontextmenu = function() {
		return false
	};
	$(".a_bgcolor").hover(function() {
		$(this).find(">div").show().find("span").unbind("click").click(function() {
			var _this = $(this);
			db.batchData(" dataStorage ", "bakColor=" + _this.index(), function(err) {
				if (_this.index() == 0) {
					$(".app-article-Center").css("background", "#e7f4fd")
				} else if (_this.index() == 1) {
					$(".app-article-Center").css("background", "#f5f1e6")
				} else if (_this.index() == 2) {
					$(".app-article-Center").css("background", "#eae8f6")
				} else if (_this.index() == 3) {
					$(".app-article-Center").css("background", "#fef5f0")
				} else if (_this.index() == 4) {
					$(".app-article-Center").css("background", "#ebf4ef")
				} else if (_this.index() == 5) {
					$(".app-article-Center").css("background", "#FFF")
				};
				$(".a_colorlist span").removeClass("cur").eq(_this.index()).addClass("cur")
			})
		})
	}, function() {
		$(this).find(">div").hide()
	});
	$(".a_fontsize").hover(function() {
		$(this).find(">div").show().find("input").unbind("click").click(function() {
			var _this = $(this);
			db.batchData(" dataStorage ", " fontSize=" + _this.val(), function() {
				$("#articlecontent").css("font-size", _this.val() + "px")
			})
		})
	}, function() {
		$(this).find(">div").hide()
	});
	if (Isforbid == 1) {
		$(".app-edit-fl i.edit1").addClass("edit1-hui");
		$(".app-edit-fl i.edit4").addClass("edit4-hui");
		$(".app-edit-ope i.edit6").addClass("edit6-hui")
	}
});
var artTotal2 = 0;
db.checkData('ArticleList', '*', null, function() {}, function(id) {
	artTotal2 = id
});

function PushArticleList1(ot, dn, aid) {
	var strRequestUrl = cv.post + "/ajax/Sync.ashx?ver=0.01&os=windows&op=syncArt&ot=" + ot + "&dn=" + dn + "&aid=" + aid;
	var sign = "&sign=" + getSign.sign(strRequestUrl + "&UserCode=" + myReplace(UserCode));
	var permissionName = null;
	var dataArr = null,
		SearchDataArr = null;
	var aidRecord = 0;
	$.ajax({
		url: strRequestUrl + sign,
		type: 'POST',
		data: {
			"UserCode": UserCode
		},
		success: function(result) {
			if (result == "") {
				if ($(".articleSearchList-div").is(":hidden")) {};
				SynchronizeArticleData();
				return false
			};
			var data = JSON.parse(result);
			var dataNumber = 0;
			if (data.status == 1) {
				var dataNum = data.NAItem,
					UID = null,
					UName = null;
				if (dataNum.length > 0) {
					for (var i = 0; i < dataNum.length; i++) {
						if (dataNum[i].UID) {
							UID = dataNum[i].UID
						};
						if (dataNum[i].UName) {
							UName = dataNum[i].UName
						};
						if (aid != dataNum[i].Aid) {
							var num = i;
							dataNumber++;
							sum++;
							Increasing++;
							if (dataArr == null) {
								dataArr = dataNum[i].Aid + ',' + dataNum[i].arttype + ',"' + replaceCharacter(dataNum[i].Tit) + '",' + null + ',' + null + ',' + dataNum[i].SD + ',' + Uid + ',' + dataNum[i].Permission + ',' + null + ',' + dataNum[i].ischecked + ',' + null + ',' + null + ',' + null + ',' + UID + ',"' + UName + '",' + dataNum[i].CategoryID + ',' + dataNum[i].original + ',' + null + ',' + null + ',' + dataNum[i].ReadN + ',' + null + ',' + null + ',' + dataNum[i].SaveN + ',' + null + ',' + 1 + ',' + null + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + 0 + ',' + dataNum[i].iscream + ',' + 0 + ',' + null + ',' + null + ',' + null + ',' + null;
								SearchDataArr = dataNum[i].Aid + ',"' + removeHTMLTag(dataNum[i].Tit) + '","' + formatDate(Number(dataNum[i].SD)) + '",' + null + ',' + dataNum[i].arttype + ',' + null + ',' + null + ',' + null
							} else {
								dataArr += "||" + dataNum[i].Aid + ',' + dataNum[i].arttype + ',"' + replaceCharacter(dataNum[i].Tit) + '",' + null + ',' + null + ',' + dataNum[i].SD + ',' + Uid + ',' + dataNum[i].Permission + ',' + null + ',' + dataNum[i].ischecked + ',' + null + ',' + null + ',' + null + ',' + UID + ',"' + UName + '",' + dataNum[i].CategoryID + ',' + dataNum[i].original + ',' + null + ',' + null + ',' + dataNum[i].ReadN + ',' + null + ',' + null + ',' + dataNum[i].SaveN + ',' + null + ',' + 1 + ',' + null + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + 0 + ',' + dataNum[i].iscream + ',' + 0 + ',' + null + ',' + null + ',' + null + ',' + null;
								SearchDataArr += "||" + dataNum[i].Aid + ',"' + removeHTMLTag(dataNum[i].Tit) + '","' + formatDate(Number(dataNum[i].SD)) + '",' + null + ',' + dataNum[i].arttype + ',' + null + ',' + null + ',' + null
							};
							aidRecord = Number(dataNum[i].Aid);
							if (i == dataNum.length - 1) {
								var dataLength = dataNum.length;
								db.newSaveData("ArticleList (articleID,artType,ArticleTitle,keywords,Abstract,SaveDate,SaverUserID,ArtPermission,Tags,isChecked,FirstArtID,authorName,authorUserID ,resaveAuthorName,resaveAuthorUserID,categoryID,isOriginal,ArtUrl,sourceName,ReadNum,flowersNum,commentNum,saverNum,ArtContent,IsUpload,Logid,IsDelete,PrevCategoryID,IsDownLoad,downloadStatus,localImgUrl,imgDownloadStatus,IsConvert,PageNum,Purtext,Offvalue,Permitdownload,docsize,iscream,savefrom,originalActivityID,newData1,newData2,newData3)", "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", dataArr, function(err) {
									if (dataLength < 100) {
										setTimeout(function() {
											db.batchData(" dataStorage ", " updateTime='" + getNowFormatDate("-", 0) + "'", function() {
												SynchronizeArticleData()
											});
											if ($(".articleSearchList-div").is(":hidden")) {
												db.checkData("ArticleList", "*", " articleID = '" + $("#divartlist>li.con").attr("aid") + "'", function(row, err) {}, function(num) {
													if (num == 0) {
														if ($("#TreeId").val() != '') {
															ArticleList(0, 50, "CategoryID=" + $("#TreeId").val(), null, null, true)
														} else {
															ArticleList(0, 50, null, null, null, true)
														}
													} else {
														var where = '';
														if ($("#TreeId").val() != '') {
															var where = " categoryID='" + $("#TreeId").val() + "' AND articleID > '" + $("#divartlist>li.con").attr("aid") + "'"
														} else {
															var where = " articleID > '" + $("#divartlist>li.con").attr("aid") + "'"
														};
														db.SearchQuery("ArticleList", "articleID,artType,ArticleTitle,keywords,Abstract,SaveDate,SaverUserID,ArtPermission,Tags,isChecked,FirstArtID,authorName,authorUserID ,resaveAuthorName,resaveAuthorUserID,categoryID,isOriginal,ArtUrl,sourceName,ReadNum,flowersNum,commentNum,saverNum,ArtContent,IsUpload,Logid,IsDelete,PrevCategoryID,IsDownLoad,downloadStatus,localImgUrl,imgDownloadStatus,IsConvert,PageNum,Purtext,Offvalue,Permitdownload,docsize,iscream,savefrom,originalActivityID,newData1,newData2,newData3", where, null, null, function(row, err) {}, function(num) {
															var page = (num / 50).toFixed(0) - 1;
															if ($("#TreeId").val() != '') {
																ArticleList(page * 50, 50, "CategoryID=" + $("#TreeId").val(), null, null, $("#divartlist>li.con").attr("aid"));
																if (page > 0) {
																	db.checkDataStripNumber('ArticleList', 'articleID', 50, 0, "CategoryID=" + $("#TreeId").val(), 'SaveDate desc', function(row, err) {}, function(count) {
																		paging(count, 50, Number(page) + 1)
																	})
																}
															} else {
																ArticleList(page * 50, 50, null, null, null, $("#divartlist>li.con").attr("aid"));
																if (page > 0) {
																	db.checkDataStripNumber('ArticleList', 'articleID', 50, 0, null, 'SaveDate desc', function(row, err) {}, function(count) {
																		paging(count, 50, Number(page) + 1)
																	})
																}
															}
														})
													}
												})
											};
											if (isInitialization != 100) {
												$("#InitializationStop i").text("初始化完成！");
												sh.modifyData('usersInfo', ' newData1=100 ', ' UserID = ' + Uid)
											};
											$(".articleList-newPrompt i").text(dataNum.length);
											$(".articleList-newPrompt").show().click(function() {
												$(".app-screen-download span").attr("type", '').text("全部");
												$(".app-screen-type span").attr("type", "").text("全部");
												$("#TreeId").val("");
												var treeObj = $.fn.zTree.getZTreeObj("treelist");
												treeObj.cancelSelectedNode();
												if ($(".articleSearchList-div").is(":hidden")) {
													ArticleList(0, 50, null, null, null, "1111")
												};
												$(".articleList-newPrompt").hide()
											});
											setTimeout(function() {
												$(".articleList-newPrompt").hide();
												$("#InitializationStop").hide()
											}, 3000)
										}, 1000)
									} else {
										if ((Increasing / artTotal * 100).toFixed(0) > isInitialization) {
											$("#InitializationStop em").text((Increasing / artTotal * 100).toFixed(0) + "%")
										};
										PushArticleList1(2, 100, aidRecord + 1)
									}
								});
								db.newSaveData("SearchArticleList(ArticleID,ArticleTitle,SaveDate,ArtContent,Arttype,newData1,newData2,newData3)", "(?,?,?,?,?,?,?,?)", SearchDataArr, function(err) {})
							}
						} else if (dataNum.length == 1 && aid == dataNum[i].Aid) {
							var num = i;
							dataNumber++;
							sum++;
							Increasing++;
							if (dataArr == null) {
								dataArr = dataNum[i].Aid + ',' + dataNum[i].arttype + ',"' + replaceCharacter(dataNum[i].Tit) + '",' + null + ',' + null + ',' + dataNum[i].SD + ',' + Uid + ',' + dataNum[i].Permission + ',' + null + ',' + null + ',' + null + ',' + null + ',' + null + ',' + UID + ',"' + UName + '",' + dataNum[i].CategoryID + ',' + dataNum[i].original + ',' + null + ',' + null + ',' + dataNum[i].ReadN + ',' + null + ',' + null + ',' + dataNum[i].SaveN + ',' + null + ',' + 1 + ',' + null + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + 0 + ',' + dataNum[i].iscream + ',' + 0 + ',' + null + ',' + null + ',' + null + ',' + null;
								SearchDataArr = dataNum[num].Aid + ',"' + removeHTMLTag(dataNum[num].Tit) + '","' + formatDate(Number(dataNum[num].SD)) + '",' + null + ',' + dataNum[num].arttype + ',' + null + ',' + null + ',' + null
							} else {
								dataArr += "||" + dataNum[i].Aid + ',' + dataNum[i].arttype + ',"' + replaceCharacter(dataNum[i].Tit) + '",' + null + ',' + null + ',' + dataNum[i].SD + ',' + Uid + ',' + dataNum[i].Permission + ',' + null + ',' + null + ',' + null + ',' + null + ',' + null + ',' + UID + ',"' + UName + '",' + dataNum[i].CategoryID + ',' + dataNum[i].original + ',' + null + ',' + null + ',' + dataNum[i].ReadN + ',' + null + ',' + null + ',' + dataNum[i].SaveN + ',' + null + ',' + 1 + ',' + null + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + 0 + ',' + dataNum[i].iscream + ',' + 0 + ',' + null + ',' + null + ',' + null + ',' + null;
								SearchDataArr += "||" + dataNum[num].Aid + ',"' + removeHTMLTag(dataNum[num].Tit) + '","' + formatDate(Number(dataNum[num].SD)) + '",' + null + ',' + dataNum[num].arttype + ',' + null + ',' + null + ',' + null
							};
							aidRecord = Number(dataNum[i].Aid);
							var dataLength = dataNum.length;
							db.newSaveData("ArticleList(articleID,artType,ArticleTitle,keywords,Abstract,SaveDate,SaverUserID,ArtPermission,Tags,isChecked,FirstArtID,authorName,authorUserID ,resaveAuthorName,resaveAuthorUserID,categoryID,isOriginal,ArtUrl,sourceName,ReadNum,flowersNum,commentNum,saverNum,ArtContent,IsUpload,Logid,IsDelete,PrevCategoryID,IsDownLoad,downloadStatus,localImgUrl,imgDownloadStatus,IsConvert,PageNum,Purtext,Offvalue,Permitdownload,docsize,iscream,savefrom,originalActivityID,newData1,newData2,newData3)", "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", dataArr, function(err) {
								ArticleList(0, 50, null, null, null, true);
								setTimeout(function() {
									db.batchData(" dataStorage ", " updateTime='" + getNowFormatDate("-", 0) + "'", function() {
										SynchronizeArticleData()
									});
									if (isInitialization != 100) {
										$("#InitializationStop i").text("初始化完成！");
										sh.modifyData('usersInfo', ' newData1=100 ', ' UserID = ' + Uid)
									};
									$(".articleList-newPrompt i").text(1);
									$(".articleList-newPrompt").show().click(function() {
										$(".app-screen-download span").attr("type", '').text("全部");
										$(".app-screen-type span").attr("type", "").text("全部");
										$("#TreeId").val("");
										var treeObj = $.fn.zTree.getZTreeObj("treelist");
										treeObj.cancelSelectedNode();
										if ($(".articleSearchList-div").is(":hidden")) {
											ArticleList(0, 50, null, null, null, "1111")
										};
										$(".articleList-newPrompt").hide()
									});
									setTimeout(function() {
										$(".articleList-newPrompt").hide();
										$("#InitializationStop").hide()
									}, 3000)
								}, 1000)
							});
							db.newSaveData("SearchArticleList(ArticleID,ArticleTitle,SaveDate,ArtContent,Arttype,newData1,newData2,newData3)", "(?,?,?,?,?,?,?,?)", SearchDataArr, function(err) {})
						}
					}
				} else {
					SynchronizeArticleData();
					return false
				}
			} else {
				SynchronizeArticleData();
				return false
			}
		},
		error: function(error) {
			SynchronizeArticleData();
			return false
		}
	})
};

function PushArticleList(ot, dn, aid) {
	db.checkData("ArticleList", "*", " articleID = '" + obj.articleid + "'", function(row, err) {}, function(err) {
		if (err == 0) {
			var strRequestUrl = cv.post + "/ajax/Sync.ashx?ver=0.01&os=windows&op=syncArt&ot=" + ot + "&dn=" + dn + "&aid=" + aid;
			var sign = "&sign=" + getSign.sign(strRequestUrl + "&UserCode=" + myReplace(UserCode));
			var permissionName = null;
			$.ajax({
				url: strRequestUrl + sign,
				type: 'POST',
				data: {
					"UserCode": UserCode
				},
				success: function(result) {
					var data = JSON.parse(result);
					var dataNumber = 0;
					if (data.status == 1) {
						var dataNum = data.NAItem,
							UID = null,
							UName = null;
						if (dataNum.length > 0) {
							db.batchData('Category', ' artnum="' + (Number($("#artnum").html() + dataNum.length)) + '"', function() {
								$("#artnum").html((Number($("#artnum").html()) + dataNum.length))
							});
							for (var i = 0; i < dataNum.length; i++) {
								if (data.articleID == dataNum[i].Aid) {
									return false
								};
								dataNumber++;
								if (dataNum[i].UID) {
									UID = dataNum[i].UID
								};
								if (dataNum[i].UName) {
									UName = dataNum[i].UName
								};
								if (aid != dataNum[i].Aid) {
									db.saveData("ArticleList(articleID,artType,ArticleTitle,keywords,Abstract,SaveDate,SaverUserID,ArtPermission,Tags,isChecked,FirstArtID,authorName,authorUserID ,resaveAuthorName,resaveAuthorUserID,categoryID,isOriginal,ArtUrl,sourceName,ReadNum,flowersNum,commentNum,saverNum,ArtContent,IsUpload,Logid,IsDelete,PrevCategoryID,IsDownLoad,downloadStatus,localImgUrl,imgDownloadStatus,IsConvert,PageNum,Purtext,Offvalue,Permitdownload,docsize,iscream,savefrom,originalActivityID,newData1,newData2,newData3)", "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", dataNum[i].Aid + ',' + dataNum[i].arttype + ',' + replaceCharacter(dataNum[i].Tit) + ',' + null + ',' + null + ',' + dataNum[i].SD + ',' + Uid + ',' + dataNum[i].Permission + ',' + null + ',' + null + ',' + null + ',' + null + ',' + null + ',' + UID + ',' + UName + ',' + dataNum[i].CategoryID + ',' + dataNum[i].original + ',' + null + ',' + dataNum[i].source + ',' + dataNum[i].ReadN + ',' + null + ',' + null + ',' + dataNum[i].SaveN + ',' + null + ',' + 1 + ',' + null + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + 0 + ',' + null + ',' + 0 + ',' + 0 + ',' + 0 + ',' + 0 + ',' + 0 + ',' + null + ',' + null + ',' + null + ',' + null);
									db.saveData("SearchArticleList(ArticleID,ArticleTitle,SaveDate,ArtContent,Arttype,newData1,newData2,newData3)", "(?,?,?,?,?,?,?,?)", dataNum[i].Aid + ',' + removeHTMLTag(dataNum[i].Tit) + ',' + Number(dataNum[i].SD) + ',' + null + ',' + Number(dataNum[i].arttype) + ',' + null + ',' + null + ',' + null);
									db.checkData('CategoryMyLibrary', '*', ' CategoryID = ' + dataNum[i].CategoryID, function(row, err) {
										db.modifyData('CategoryMyLibrary', ' ArtNum="' + Number(row.ArtNum + 1) + '"', ' CategoryID = ' + dataNum[i].CategoryID)
									})
								}
							}
						} else {
							return false
						}
					}
				},
				error: function(error) {}
			})
		}
	})
}
function replaceCharacter(str) {
	var text = str.replace(/[\,]/g, "，");
	text = text.replace(/\\\//g, '/');
	return text
}