/* InnoKB 2.x (c) 2009 Wjj Software. All rights reserved. The javascript contained in this file is the property of Wjj Software. You may not use the scripts without the express written consent. */ var _xApp = null; var _xFrm = null; var editFrame = null; var editDocument = null; var editWindow = null; $(window).load(function() { _xApp = new _CAppInfo(); _xFrm = new _CMainFrm(document); if (_xFrm) _xFrm._init() }); function _lc(k, def) { return _xApp._lc(k, def) } function _pf(k, v) { return (arguments.length == 2) ? _xApp._pf(k, v) : _xApp._pf(k) } function _pfn(k) { return parseInt(_xApp._pf(k)) } function initFrameDocument() { editFrame = document.getElementById('ID_HtmlIframe'); editDocument = editFrame.contentDocument || editFrame.contentWindow.document; editWindow = editFrame.contentWindow; } function getPreviousNode(node) { let previousSibling = node.previousSibling; if (previousSibling) { // 如果前一个兄弟节点存在,继续向左遍历其最后一个子节点 while (previousSibling.lastChild) { previousSibling = previousSibling.lastChild; } return previousSibling; } else { // 如果前一个兄弟节点不存在,继续向上遍历其父节点的兄弟节点 let parentNode = node.parentNode; while (parentNode && !previousSibling) { previousSibling = parentNode.previousSibling; parentNode = parentNode.parentNode; } if (previousSibling) { // 如果找到了存在的节点,则向右遍历其最后一个子节点 while (previousSibling.lastChild) { previousSibling = previousSibling.lastChild; } } return previousSibling; } } function replaceSelection(range, html) { const previousNode = getPreviousNode(range.startContainer); // editDocument.execCommand('insertHTML', false, "

" + html + "

"); editDocument.execCommand('insertHTML', false, html); const newRange = editDocument.createRange(); newRange.setStartAfter(previousNode); newRange.setEndBefore(editWindow.getSelection().getRangeAt(0).startContainer); editWindow.getSelection().removeAllRanges(); editWindow.getSelection().addRange(newRange); const event = editDocument.createEvent('CustomEvent'); event.initEvent('selectionchange', true, false); editWindow.dispatchEvent(event); } function createNode(html) { const temp = editDocument.createElement("div"); temp.innerHTML = html; const node = temp.firstChild; temp.removeChild(node); return node; } function createBox(bgColor, textColor, leftBgColor, leftColor, icon) { initFrameDocument() const range = editWindow.getSelection().getRangeAt(0); const parentNode = createNode(`
`); parentNode.appendChild(createNode(`
${icon}
`)); const wrapper = createNode('
'); wrapper.firstChild.firstChild.appendChild(range.cloneContents()); parentNode.appendChild(wrapper); replaceSelection(range, parentNode.outerHTML); } function clearFormat() { initFrameDocument(); editDocument.execCommand('removeFormat', false, null); } function createBlock(bgColor) { initFrameDocument(); const range = editWindow.getSelection().getRangeAt(0); const parentNode = createNode(`
`); parentNode.appendChild(range.cloneContents()); replaceSelection(range, parentNode.outerHTML); } function insertNodeAtCaret(node) { var sel, range; if (editWindow.getSelection) { sel = editWindow.getSelection(); if (sel.getRangeAt && sel.rangeCount) { range = sel.getRangeAt(0); range.deleteContents(); range.insertNode(node); range.setStartAfter(node); range.setEndAfter(node); sel.removeAllRanges(); sel.addRange(range); } } else if (editDocument.selection && editDocument.selection.createRange) { editDocument.selection.createRange().innerHTML = node.innerHTML; } } function insertTable() { initFrameDocument(); var xy = prompt("请输入表格行x列数\n例如 5,3 表示插入5行3列的表格", "5,3", null); if (xy == null) return; xy = xy.replaceAll(" ", "").split(","); var table = editDocument.createElement("table"); table.setAttribute("border", 1); for (var i = 0; i < xy[0]; i++) { var row = table.insertRow(); for (j = 0; j < xy[1]; j++) { row.insertCell().innerHTML = "
"; } } insertNodeAtCaret(table); } function highlight(tag) { initFrameDocument(); const range = editWindow.getSelection().getRangeAt(0); const selectedText = editWindow.getSelection().toString() || ""; const textNode = editDocument.createTextNode(selectedText); const codeNode = createNode(``); codeNode.appendChild(textNode); const preNode = createNode(`
`);
	preNode.appendChild(codeNode);
	replaceSelection(range, preNode.outerHTML);
	editWindow.hljs.highlightAll();
}

function _CQuery(sDbid, sSortBy, bIncr, nPageSize) {
	this.sTitle = '';
	this.sDbids = sDbid || '';
	this.sLabels = '';
	this.sCreators = '';
	this.sRevisors = '';
	this.iAttr = 0;
	this.sCreated1 = '';
	this.sCreated2 = '';
	this.sModified1 = '';
	this.sModified2 = '';
	this.sAnd = '';
	this.sOr = '';
	this.sNot = '';
	this.sSortBy = sSortBy || 'DateModified';
	this.bIncr = bIncr;
	this.sCollate = 'UTF8';
	this.bSub = false;
	this.bUnlabelled = false;
	this.iStart = 0;
	this.nLen = nPageSize || 20;
	this.nResMax = 0;
	this.nResSum = 0;
	this.sToHilite = ''
};
_CQuery.prototype = {
	_init: function(xDat) {
		this.sTitle = xDat.sTitle || 'Unknown query';
		this.sDbids = xDat.sDbids || '';
		this.sLabels = xDat.sLabels || '';
		this.sCreators = xDat.sCreators || '';
		this.sRevisors = xDat.sRevisors || '';
		this.iAttr = xDat.iAttr || 0;
		this.sCreated1 = xDat.sCreated1 || '';
		this.sCreated2 = xDat.sCreated2 || '';
		this.sModified1 = xDat.sModified1 || '';
		this.sModified2 = xDat.sModified2 || '';
		this.sAnd = xDat.sAnd || '';
		this.sOr = xDat.sOr || '';
		this.sNot = xDat.sNot || '';
		if (xDat.sSortBy) this.sSortBy = xDat.sSortBy;
		if (xDat.bIncr != undefined) this.bIncr = xDat.bIncr ? true : false;
		if (xDat.sCollate) this.sCollate = xDat.sCollate;
		if (xDat.bSub != undefined) this.bSub = xDat.bSub ? true : false;
		this.bUnlabelled = xDat.bUnlabelled ? true : false;
		if (typeof(xDat.iStart) == 'number') this.iStart = xDat.iStart;
		if (typeof(xDat.nLen) == 'number') this.nLen = xDat.nLen;
		this.sToHilite = xDat.sToHilite || '';
		return this
	},
	_data: function() {
		var xQ = this,
			sCollate = 'NUM',
			xCgi = {};
		if ('ItemTitle|ItemCreator|ItemRevisor'.split('|')._indexOf(xQ.sSortBy) >= 0) {
			sCollate = xQ.sCollate
		}
		var sDbids = xQ.sDbids || '';
		if (sDbids == '*') sDbids = '';
		if (xQ.sDbids) {
			xCgi['dbids'] = xQ.sDbids
		}
		if (xQ.sSortBy) {
			xCgi['sort'] = xQ.sSortBy
		}
		if (sCollate && sCollate != 'NUM') {
			xCgi['collate'] = encodeURIComponent(sCollate)
		}
		if (xQ.bIncr != undefined) {
			xCgi['incr'] = (xQ.bIncr ? '1' : '0')
		}
		if (xQ.iStart && xQ.iStart > 0) {
			xCgi['start'] = xQ.iStart
		}
		if (xQ.nLen && xQ.nLen > 0 && xQ.nLen != parseInt(_xApp.sDefLenOfList)) {
			xCgi['len'] = xQ.nLen
		}
		if (xQ.sAnd) {
			xCgi['and'] = encodeURIComponent(xQ.sAnd)
		}
		if (xQ.bUnlabelled) {
			xCgi['unlabeled'] = '1'
		} else {
			if (xQ.sLabels) {
				xCgi['labels'] = encodeURIComponent(xQ.sLabels);
				if (xQ.bSub) {
					xCgi['sub'] = '1'
				}
			}
		} if (xQ.sCreators) {
			xCgi['creators'] = encodeURIComponent(xQ.sCreators)
		}
		if (xQ.sRevisors) {
			xCgi['revisors'] = encodeURIComponent(xQ.sRevisors)
		}
		var bTimeZone = false;
		if (xQ.sCreated1) {
			bTimeZone = true;
			xCgi['ctime1'] = encodeURIComponent(xQ.sCreated1)
		}
		if (xQ.sCreated2) {
			bTimeZone = true;
			xCgi['ctime2'] = encodeURIComponent(xQ.sCreated2 + '-23-59-59')
		}
		if (xQ.sModified1) {
			bTimeZone = true;
			xCgi['mtime1'] = encodeURIComponent(xQ.sModified1)
		}
		if (xQ.sModified2) {
			bTimeZone = true;
			xCgi['mtime2'] = encodeURIComponent(xQ.sModified2 + '-23-59-59')
		}
		if (bTimeZone) {
			xCgi['tz'] = (new Date()._timezone())
		}
		var sData = '';
		jSel.util.each(xCgi, function(key, val) {
			if (sData) sData += '&';
			sData += (key + '=' + val)
		});
		return sData
	},
	_uri: function() {
		return '_query?' + this._data()
	},
	_descr: function() {
		var xQ = this,
			s = '';
		if (xQ.sToHilite) {
			if (s) s += ', ';
			s += _lc('Info.SearchFor', 'Search: %FindText%').replace(/%FindText%/g, xQ.sToHilite.replace(/\|/g, ' '))
		}
		if (xQ.bUnlabelled) {
			if (s) s += ', ';
			s += _lc('Info.Unlabelled', 'Unlabelled')
		} else {
			if (xQ.sLabels) {
				if (s) s += ', ';
				var sTag = xQ.bSub ? _lc('Info.LabelBranch', 'Label+Sub: %LABELS%') : _lc('Info.WithLabels', 'Label: %LABELS%');
				s += sTag.replace(/%LABELS%/g, xQ.sLabels)
			}
		} if (xQ.sCreators) {
			if (s) s += ', ';
			s += _lc('Info.WithCreator', 'Creator: %ItemCreator%').replace(/%ItemCreator%/g, xQ.sCreators)
		}
		if (xQ.sRevisors) {
			if (s) s += ', ';
			s += _lc('Info.WithRevisor', 'Revisor: %ItemRevisor%').replace(/%ItemRevisor%/g, xQ.sRevisors)
		}
		if (xQ.sCreated1 || xQ.sCreated2) {
			if (s) s += ', ';
			s += _lc('Info.WithDateCreated', 'Created: [%StartDate%, %EndDate%]').replace(/%StartDate%/g, xQ.sCreated1 || '*').replace(/%EndDate%/g, xQ.sCreated2 || '*')
		}
		if (xQ.sModified1 || xQ.sModified2) {
			if (s) s += ', ';
			s += _lc('Info.WithDateModified', 'Modified: [%StartDate%, %EndDate%]').replace(/%StartDate%/g, xQ.sModified1 || '*').replace(/%EndDate%/g, xQ.sModified2 || '*')
		}
		if (xQ.sSortBy) {
			if (s) s += ', ';
			var sTag = xQ.bIncr ? _lc('Info.Increasing', 'Sort: %SortBy%, Order: Increasing') : _lc('Info.Decreasing', 'Sort: %SortBy%, Order: Decreasing');
			var sKey = 'SortBy.' + xQ.sSortBy;
			s += sTag.replace(/%SortBy%/g, _lc(sKey, xQ.sSortBy))
		}
		if (xQ.iStart) {
			if (s) s += ', ';
			s += _lc('Info.StartPos', 'Start: %StartPos%').replace(/%StartPos%/g, xQ.iStart + 1)
		}
		return s
	}
};

function _CCurItem() {
	this.sDbid = '';
	this.sItemID = '';
	this.iAttr = 0;
	this.ctime = 0;
	this.mtime = 0;
	this.stime = 0;
	this.sTitle = '';
	this.sCreator = '';
	this.sRevisor = '';
	this.vLabels = [];
	this.vFiles = [];
	this.vLinks = []
};
_CCurItem.prototype = {
	_clear: function() {
		this.sDbid = '';
		this.sItemID = '';
		this.iAttr = 0;
		this.ctime = 0;
		this.mtime = 0;
		this.stime = 0;
		this.sTitle = '';
		this.sCreator = '';
		this.sRevisor = '';
		this.vLabels.length = 0;
		this.vFiles.length = 0;
		this.vLinks.length = 0
	}
};

function _CMainFrm(doc) {
	this._idAppLoading = 'ID_AppLoading';
	this._idAppFrame = 'ID_AppSafeFrame';
	this._idHeader = 'ID_Header';
	this._idFooter = 'ID_Footer';
	this._idWorkspace = 'ID_Workspace';
	this._idLeftPane = 'ID_LeftPane';
	this._idRightPane = 'ID_RightPane';
	this._idMenuBtnDbList = 'ID_DropDownDbList';
	this._idMenuBtnDbActs = 'ID_DropDownDbActs';
	this._idMenuBtnSort = 'ID_DropDownSort';
	this._idMenuBtnResPages = 'ID_MenuBtnResPages';
	this._idMenuBtnQueryHistory = 'ID_MenuBtnQueryHistory';
	this._idMenuBtnVisited = 'ID_DropDownVisited';
	this._idMenuBtnSelected = 'ID_DropDownSelected';
	this._idMenuBtnMoreLabelTree = 'ID_DropDownMoreLabelTree';
	this._idMenuBtnMoreItemList = 'ID_DropDownMoreItemList';
	this._idMenuBtnMoreHtmlView = 'ID_DropDownMoreHtmlView';
	this._idMenuBtnMoreHtmlEdit = 'ID_DropDownMoreHtmlEdit';
	this._idMenuBtnMoreAttach = 'ID_DropDownMoreAttach';
	this._idMenuBtnMoreUsedLabels = 'ID_DropDownMoreUsedLabels';
	this._idMenuBtnMoreLinks = 'ID_DropDownMoreLinks';
	this._idMenuBtnColumns = 'ID_DropDownColumns';
	this._idMenuBtnFace = 'ID_DropDownFace';
	this._idMenuBtnSize = 'ID_DropDownSize';
	this._idMenuBtnStyle = 'ID_DropDownStyle';
	this._idMenuBtnLanguage = 'ID_DropDownLanguage';
	this._idAppLinkBar = 'ID_AppLinkBar';
	this._idLogin = 'ID_Login';
	this._idLogout = 'ID_Logout';
	this._idLanguage = 'ID_Language';
	this._idChgPwd = 'ID_ChgPwd';
	this._idKbView = 'ID_AppView';
	this._idKbEdit = 'ID_AppEdit';
	this._idKbAdmin = 'ID_AppAdmin';
	this._idTreeView = 'ID_TreeView';
	this._idQueryFormPane = 'ID_QueryFormPane';
	this._idTabsLeft = 'ID_TabsLeft';
	this._idPagesLeft = 'ID_PagesLeft';
	this._idTabsRight = 'ID_TabsRight';
	this._idPagesRight = 'ID_PagesRight';
	this._idPageOverview = 'ID_PageOverview';
	this._idPageLabels = 'ID_PageLabels';
	this._idPageQuery = 'ID_PageQuery';
	this._idPageCalendar = 'ID_PageCalendar';
	this._idPageItems = 'ID_PageItems';
	this._idPageContent = 'ID_PageContent';
	this._idToolBarDB = 'ID_ToolBarDB';
	this._idToolBarLabelTree = 'ID_ToolBarLabelTree';
	this._idToolBarItems = 'ID_ToolBarItems';
	this._idToolBarContent = 'ID_ToolBarContent';
	this._idInfoItemsPane = 'ID_InfoItemsPane';
	this._idInfoItemsTable = 'ID_InfoItemsTable';
	this._idQuickSearchBox = 'ID_QuickSearchBox';
	this._idItemContentPane = 'ID_ItemContentPane';
	this._idItemAddrBar = 'ID_ItemAddrBar';
	this._idItemTitle = 'ID_ItemTitle';
	this._idItemInfo = 'ID_ItemInfo';
	this._idHtmlFrmPane = 'ID_HtmlFrmPane';
	this._idHtmlIframe = 'ID_HtmlIframe';
	this._idMiscInfoPane = 'ID_MiscInfoPane';
	this._idToolBarAttach = 'ID_ToolbarAttach';
	this._idAttachPane = 'ID_AttachPane';
	this._idToolBarUsedLabels = 'ID_ToolbarUsedLabels';
	this._idUsedLabelsPane = 'ID_UsedLabelsPane';
	this._idToolBarLinks = 'ID_ToolbarLinks';
	this._idLinksPane = 'ID_LinksPane';
	this._idStatusIcon = 'ID_StatusIcon';
	this._idStatusText = 'ID_StatusText';
	this._idStatusCustomTitle = 'ID_StatusCustomTitle';
	this._idStatusAjaxIdleSecs = 'ID_StatusAjaxIdleSecs';
	this._idStatusUid = 'ID_StatusUid';
	this._xPopup = null;
	this._xTreeCtrl = null;
	this._xHtmlCtrl = null;
	this._xStatusBar = null;
	this._xTabLeft = null;
	this._xTabRight = null;
	this._vDbItems = [];
	this._vInfoItems = [];
	this._vCheckedItems = [];
	this._sCurDbID = '';
	this._xCurItem = new _CCurItem();
	this._xQuery = null;
	this._xDefLoc = {
		sSortBy: 'DateModified',
		bIncr: false
	};
	this._vVisitedItems = [];
	this._iTimerIdleInfo = null;
	this._xRecentLabel = {};
	this._bEdit = document.location.href.indexOf('/edit') > 0;
	this._vQueryItems = []
}
_CMainFrm.prototype = {
	_TI: function(id) {
		return this._xTreeCtrl._TI(id)
	},
	_init: function() {
		var frm = this,
			xDL = frm._xDefLoc;
		$(window).resize(function() {
			frm._schedule_resize()
		});
		var jLogin = $('#' + frm._idLogin);
		var jLogout = $('#' + frm._idLogout);
		var jLanguage = $('#' + frm._idLanguage);
		var jChgpwd = $('#' + frm._idChgPwd);
		var jKbView = $('#' + frm._idKbView);
		var jKbEdit = $('#' + frm._idKbEdit);
		var jKbAdmin = $('#' + frm._idKbAdmin);
		(frm._bEdit ? jKbEdit : jKbView).css('font-weight', 'bold');
		jLogin.click(function(e) {
			{
				frm._do_login(true, function() {})
			}
			return false
		});
		jChgpwd.click(function(e) {
			frm._do_chgpwd();
			return false
		});
		jLogout.click(function(e) {
			if (frm._check_designmode()) {
				frm._do_logout()
			}
			return false
		});
		jLanguage.click(function(e) {
			if (frm._check_designmode()) {
				xDL.sDbids = frm._curdb();
				xDL.sLabels = frm._curlabel();
				_xApp._select_language()
			}
			return false
		});
		jSel.util.each([jKbView, jKbEdit, jKbAdmin], function(i, jLink) {
			jLink.click(function(e) {
				if (frm._check_designmode()) {
					e = jSel.event.fix(e);
					var href = $(e.target).attr('href');
					window.location.href = href
				}
				return false
			})
		});
		frm._xStatusBar = new _CStatusBar(frm._idFooter);
		frm._xStatusBar._add_band(frm._idStatusText, null, false);
		frm._xStatusBar._add_band(frm._idStatusCustomTitle, null, true);
		frm._xStatusBar._add_band(frm._idStatusUid, null, true);
		frm._xStatusBar._add_band(frm._idStatusAjaxIdleSecs, null, true);
		frm._xStatusBar._add_band('', 10, true);
		frm._xStatusBar._resize(frm._idStatusText);
		frm._iTimerIdleInfo = setInterval(function() {
			var nSecs = Math.floor(jSel.ajax.idleSeconds());
			var nMins = Math.floor(nSecs / 60),
				nSecs = nSecs - nMins * 60;
			var nHurs = Math.floor(nMins / 60),
				nMins = nMins - nHurs * 60;
			var sMsg = '' + nHurs + ':' + nMins + ':' + nSecs;
			frm._xStatusBar._text(frm._idStatusAjaxIdleSecs, sMsg)
		}, 2000);
		var onPrintStatus = function(sMsg, iType) {
			var jMsg = $('#' + frm._idStatusText);
			if (sMsg) {
				iType = 0;
				jMsg.text(sMsg);
				if (iType == 0) {} else if (iType == 1) {} else if (iType == 2) {} else if (iType == -1) {}
			} else {
				var sHtml = '' + (_xApp.sAppTitle + '/' + _xApp.sAppDescription + ' ' + _xApp.sAppVersion)._html_encode() + '';
				jMsg.html(sHtml);
				jMsg.children('a').click(function(e) {
					_xApp._info();
					return false
				})
			}
			jMsg.css('padding-left', '8px')
		};
		frm._xPopup = new _CMenu(document, {
			sClsBox: 'CLS_DropdownBox',
			sClsItem: 'CLS_MenuItemNormal',
			sClsTrack: 'CLS_MenuItemTrack',
			sClsLabel: 'CLS_MenuItemLabel',
			sClsDisabled: 'CLS_MenuItemDisabled',
			sClsRadio: 'CLS_MenuItemRadio',
			sClsCheck: 'CLS_MenuItemCheck',
			sClsSep: 'CLS_MenuItemSep',
			onHint: function(sHint) {
				onPrintStatus(sHint || '', 0)
			},
			onClose: function() {
				onPrintStatus('')
			}
		});
		frm._xTreeCtrl = new _CTreeView(frm._idTreeView);
		var xTV = frm._xTreeCtrl;
		if (frm._bEdit) xTV._onEditing = function(xTV, sLabel) {
			frm._do_labelname(xTV, sLabel)
		};
		xTV._onSelected = function(xTV, sLabel) {
			frm._do_labelselected(xTV, sLabel)
		};
		var xCgi = _get_uri_param();
		if (xCgi) {
			xDL.sDbids = xCgi.dbid;
			xDL.sItemID = xCgi.itemid;
			xDL.sAnd = xCgi.find || xCgi.search || xCgi.query || xCgi.q;
			xDL.sCollate = xCgi.collate;
			xDL.sLabels = xCgi.label || xCgi.labels || xCgi.tag || xCgi.tags;
			xDL.bSub = typeof(xCgi.sub) != 'undefined' ? xCgi.sub : true;
			xDL.bUnlabelled = xCgi.unlabelled;
			xDL.sCreators = xCgi.creator;
			xDL.sRevisors = xCgi.revisor;
			xDL.sSortby = xCgi.sortby;
			xDL.bIncr = xCgi.incr;
			xDL.iStart = xCgi.start;
			xDL.nLen = xCgi.len
		}
		var xAutoLocate = function() {
			var vDBs = frm._vDbItems,
				xQ = frm._xQuery;
			if (vDBs.length > 0) {
				var sDbToSel = frm._curdb() || vDBs._item(0).sID,
					sDbids = xDL.sDbids || '';
				if (sDbids) {
					if (sDbids == '*') {
						xDL.sDbids = ''
					} else {
						var sOkID = '',
							sBadID = '';
						jSel.util.each(sDbids.split(';')._pack(), function(i, sID) {
							var xDb = frm._dbitem_of(sID);
							if (xDb) {
								if (i == 0) sDbToSel = sID;
								if (sOkID) sOkID += ';';
								sOkID += sID
							} else {
								if (sBadID) sBadID += '; ';
								sBadID += sID
							}
						});
						if (sBadID) {
							xDL.sDbids = sDbToSel;
							_warning(_lc('Prompt.DbidUnavailable', 'Could not access to the database [%BadIDs%]. Please consult system administrators.').replace(/%BadIDs%/g, sBadID))
						}
					}
				} else {
					xDL.sDbids = sDbToSel
				}
				frm._curdb(sDbToSel);
				frm._request_labellist(sDbToSel, function(vLines) {
					frm._build_labeltree(xTV, vLines, '');
					xQ._init(xDL);
					var sLabel = xDL.sLabels || '';
					if (sLabel) {
						if (xTV._exists(sLabel)) {
							if (xDL.sAnd) {
								frm._do_query(xQ)
							} else {
								xTV._select(sLabel, true)
							}
						} else {
							_warning('Could not find the label [%LABEL%].'.replace(/%LABEL%/g, sLabel));
							frm._do_query(xQ)
						}
					} else {
						frm._do_query(xQ)
					} if (xDL.sAnd) $('#' + frm._idQuickSearchBox).val(xDL.sAnd)
				})
			} else {
				_info(_lc('Prompt.NoDbAvail', 'No databases currently available to use. Please consult system administrators.'))
			}
		};
		_xApp._init(['common', 'editor'], function() {
			jSel.ajax.onstart = function(req, uri) {
				onPrintStatus(_lc('Info.AjaxReq', 'Ajax requesting ...'), 1)
			};
			jSel.ajax.onsuccess = function(req, uri) {
				onPrintStatus('')
			};
			jSel.ajax.onerror = function(req, uri) {
				var url = document.location;
				url = url.protocol + '/' + '/' + url.host + uri;
				onPrintStatus(_lc('Info.AjaxErr', 'Ajax error requesting [ %URI% ]').replace(/%URI%/g, url), -1)
			};
			jLogin.title(_lc('Link.Relogin', 'Relogin|Logout and then relogin'));
			jLogout.title(_lc('Link.Logout', 'Logout|Logout and exit'));
			jLanguage.title(_lc('Link.Language', 'Language|Choose your language'));
			jChgpwd.title(_lc('Link.Password', 'Password|Change password'));
			jKbView.title(_lc('Link.View', 'View|Switch to viewer interface'));
			jKbEdit.title(_lc('Link.Edit', 'Edit|Switch to editor interface'));
			jKbAdmin.title(_lc('Link.Admin', 'Admin|Switch to administrator interface'));
			frm._update_status_info();
			frm._request_htmltempl(function(sHtmlTempl) {
				frm._xHtmlCtrl = new _CHtmlView(frm._idHtmlFrmPane, frm._idHtmlIframe, 'CLS_HtmlIframe');
				frm._xHtmlCtrl._templ(sHtmlTempl);
				frm._create_tabctrl_left();
				frm._create_tabctrl_right();
				frm._do_login(false, function() {
					frm._nag();
					frm._install_splitters();
					frm._xQuery = new _CQuery('', '', false, _pfn('nItemsPageSize'));
					frm._create_tb_dbs();
					frm._create_tb_labels();
					frm._create_tb_items();
					frm._create_tb_htmlview();
					frm._create_tb_attach();
					frm._create_tb_usedlabels();
					frm._create_tb_links();
					frm._create_query_form();
					frm._clear_curitem(); {
						frm._show();
						frm._resize()
					}
					var vDBs = frm._vDbItems;
					_xApp._request_dbitems(vDBs, function() {
						frm._rebuild_dbmenu(vDBs);
						xAutoLocate()
					})
				})
			})
		});
		$(document).click(function() {
			frm._click()
		});
		if (!jSel.browser.msie) {
			window.onbeforeunload = function(e) {
				if (frm._is_editable()) {
					frm._xTabRight._select(1);
					return _lc('Prompt.Unloading', 'Be sure to exit design mode before unloading.')
				}
			}
		}
	},
	_show: function() {
		$('#' + this._idAppLoading).hide();
		$('#' + this._idAppFrame).show()
	},
	_click: function() {
		if (this._xPopup) this._xPopup._close()
	},
	_get_hilite: function() {
		return this._xQuery.sToHilite || ''
	},
	_install_splitters: function() {
		var frm = this,
			sImgOverlay = '/images/bg_overlay_mask.gif';
		$('#' + frm._idWorkspace).children('.CLS_SplitHori').mousedown(function(e) {
			e = jSel.event.fix(e);
			frm._click();
			$(e.target)._splitter_start(true, e.screenX, _pfn('nNavPaneWidth'), false, sImgOverlay, function(e, nNewSize) {
				if (nNewSize >= 4) {
					_pf('nNavPaneWidth', nNewSize);
					frm._resize()
				}
			})
		});
		$('#' + frm._idItemContentPane).children('.CLS_SplitHori').mousedown(function(e) {
			e = jSel.event.fix(e);
			frm._click();
			$(e.target)._splitter_start(true, e.screenX, _pfn('nAttachPaneWidth'), true, sImgOverlay, function(e, nNewSize) {
				if (nNewSize >= 4) {
					_pf('nAttachPaneWidth', nNewSize);
					frm._resize()
				}
			})
		})
	},
	_sid_changed: function(sid, uid) {
		var frm = this;
		_xApp._sid(sid);
		_xApp._uid(uid);
		if (!_xApp._sid()) {}
		frm._update_status_info()
	},
	_nag: function() {
		var nLic = parseInt(_xApp.nLicensesInstalled);
		if (nLic <= 0) {
			var nDays = 0,
				nLeft = 0;
			nDays = Math.floor((_xApp.tServerClock - _xApp.tAppInstallTime) / 3600 / 24);
			if (nDays < 0) nDays = 30;
			nLeft = (1 + 28 + 1) - nDays;
			if (nDays >= 20) {
				var bExpired = (nLeft <= 0);
				var sMsg = _lc('DlgNag.TrialVer', 'You\'re connecting to the server running an Unregistered version of %AppTitle% %AppVersion%.').replace(/%AppTitle%/g, _xApp.sAppTitle).replace(/%AppVersion%/g, _xApp.sAppVersion);
				if (bExpired) {
					sMsg += ' ' + _lc('DlgNag.Expired', 'Your 30-day trial period has expired. Please register.')
				} else {
					sMsg += ' ' + _lc('DlgNag.LeftDays', 'You have %DAYS_LEFT% day(s) left to evaluate this product.').replace(/%DAYS_LEFT%/g, nLeft)
				}
				var xDlg0 = new _CDialog('ID_Dlg_Nag', _lc('DlgNag.Caption', 'Expiration'), 400, 180, false);
				xDlg0._html(sMsg);
				if (!bExpired) {
					xDlg0._btn(_lc('DlgNag.Continue', 'Continue|Continue evaluating this product'), 'icon_ok.gif', function() {
						if (xDlg0) xDlg0._destroy()
					})
				}
				xDlg0._btn(_lc('DlgNag.Order', 'Order|Order this product online'), 'icon_order.gif', function() {
					_xApp._buy()
				});
				xDlg0._btn(_lc('DlgNag.Register', 'Register|Register with your license key'), 'icon_register.gif', function() {
					_xApp._register()
				});
				if (bExpired) xDlg0._bNoClose = true
			}
		}
	},
	_do_login: function(bRelogin, onSucc) {
		var frm = this;
		var onSucc2 = function(sSid, sUid) {
			frm._sid_changed(sSid, sUid);
			if (onSucc) onSucc(sSid, sUid)
		};
		var _pwdprompt = function() {
			_xApp._login('', '', function(sSid, sUid) {
				onSucc2(sSid, sUid)
			})
		};
		if (bRelogin) {
			_pwdprompt()
		} else {
			var sSid = _xApp._sid();
			if (sSid) {
				_xApp._check_session(sSid, function(sSid, sUid) {
					onSucc2(sSid, sUid)
				}, function(nErr) {
					_pwdprompt()
				})
			} else {
				onSucc2('', '')
			}
		}
	},
	_do_logout: function() {
		var frm = this,
			sSid = _xApp._sid();
		if (sSid) {
			_xApp._logout(sSid, function(nErr) {
				frm._sid_changed('', '');
				window.location.href = '?logout=1'
			}, function(nErr) {
				frm._sid_changed('', '');
				window.location.href = '?logout=1'
			})
		} else {
			window.location.href = '?logout=1'
		}
	},
	_do_chgpwd: function(onSucc) {
		var frm = this;
		var xDlg0 = new _CDialog('ID_Dlg_ChgPwd', _lc('DlgChgPwd.Caption', 'Change login password'), 400, 240, true);
		xDlg0._html('' + '
' + '' + '
' + '' + '
' + '' + '
'); $('#ID_Label1').text(_lc('DlgChgPwd.OldPwd', 'Old password:')); $('#ID_Label2').text(_lc('DlgChgPwd.NewPwd', 'New password:')); $('#ID_Label3').text(_lc('DlgChgPwd.TypeAgain', 'Type again:')); $('#ID_Place0')._tile_vertical(1); var jOld = $('input[@name=oldpwd]'); jOld.focus(); var jNew1 = $('input[@name=newpwd1]'); var jNew2 = $('input[@name=newpwd2]'); xDlg0._ok(function(e) { var oldpwd = jOld.val(), newpwd1 = jNew1.val(), newpwd2 = jNew2.val(); if (newpwd1 == newpwd2) { if (xDlg0) xDlg0._destroy(); var sData = 'oldpwd=' + encodeURIComponent(oldpwd) + '&newpwd=' + encodeURIComponent(newpwd1); _xApp._post('/_pwdchg', sData, _lc('Prompt.ChgPwdFailure', 'Failed to change the login password.'), function(nErr, vFields, vLines) { _info(_lc('Prompt.PwdUpdated', 'Your login password has been successfully updated.')); if (onSucc) onSucc() }) } else { _warning(_lc('Prompt.ChgPwdTypo', 'You might have mistyped the new password.')) } }) }, _request_htmltempl: function(onSucc, onFail) { jSel.ajax.run('GET', '/html/edit_itemcontent.html', '', function(html) { if (onSucc) onSucc(html) }, function(xHttpReq, sErrMsg) { if (onFail) onFail(xHttpReq, sErrMsg); else alert(_lc('Prompt.HtmlTemplFailure', 'Failed to request the HTML template file.')) }) }, _is_editable: function() { return this._xHtmlCtrl ? this._xHtmlCtrl._is_editable() : false }, _is_dirty: function() { return this._xHtmlCtrl ? this._xHtmlCtrl._is_dirty() : false }, _check_designmode: function() { var b = true; if (this._is_editable()) { b = false; this._xTabRight._select(1); _warning(_lc('Prompt.DesignMode', 'Before this operation, please be sure to first save changes and exit the design mode.')) } return b }, _dbitem_of: function(sDbid) { var xDbItem = null; for (var i = 0; i < this._vDbItems.length; ++i) { var db = this._vDbItems[i]; if (db.sID == sDbid) { xDbItem = db; break } } return xDbItem }, _uri_of: function(sDbid, sItemID, sName, iRev) { var sUri = '/' + _xApp.sWebCmdArchive + '/' + encodeURIComponent(sDbid) + '/' + sItemID + '/'; if (sName) sUri += encodeURIComponent(sName); if (iRev) sUri += '?revision=' + iRev; var sExt = _get_file_ext(sName || ''); if (sExt) { var sSid = _xApp._sid(); if (sSid && jSel.browser.msie) { if (_xCfg.sTypeActiveX.split(';')._indexOf(sExt) >= 0) { sUri += '?sid=' + sSid } } } return sUri }, _label_of: function(sLabel, bQualified) { var frm = this, xTV = frm._xTreeCtrl || new _CTreeView(); if (xTV) sLabel = xTV._qualify_path(sLabel, bQualified); return sLabel }, _show_dbtitle: function(sTitle) { window.document.title = sTitle || _lc('Info.Untitled', 'Untitled'); $('#' + this._idMenuBtnDbList).text(sTitle || 'Database List'); this._schedule_resize() }, _update_status_info: function() { var uid = _xApp._uid(); this._xStatusBar._text(this._idStatusUid, (uid ? uid : '--')); this._xStatusBar._text(this._idStatusCustomTitle, _xApp.sCustomAppTitle) }, _schedule_resize: function(nMS) { var frm = this; jSel.util.asynchronize(10, function() { frm._resize() }) }, _resize: function(e) { var frm = this; frm._resize_mainframe(); frm._resize_leftpane(); frm._resize_rightpane() }, _resize_mainframe: function() { var frm = this; $('#' + frm._idWorkspace)._tile_vertical(1); var w = parseInt(_pf('nNavPaneWidth')); if (w > 0) $('#' + frm._idLeftPane).width(w); $('#' + frm._idRightPane)._tile_horizontal(1); if (frm._xStatusBar) frm._xStatusBar._resize(frm._idStatusText) }, _resize_leftpane: function() { var frm = this; $('#' + frm._idPagesLeft)._tile_vertical(1); if (frm._xTabLeft) frm._xTabLeft._resize() }, _resize_rightpane: function() { var frm = this; $('#' + frm._idPagesRight)._tile_vertical(1); if (frm._xTabRight) frm._xTabRight._resize() }, _curdb: function(sDbid) { if (arguments.length != 0) { if (this._sCurDbID != sDbid) { this._sCurDbID = sDbid || ''; var xTV = this._xTreeCtrl; xTV._set_curitem_path(''); var xQ = this._xQuery; xQ.sDbids = sDbid; xQ.sLabels = '' } var xDb = this._dbitem_of(sDbid); this._show_dbtitle(xDb ? xDb.sTitle : '') } return this._sCurDbID }, _curlabel: function(sLabel) { var frm = this; if (arguments.length != 0) { frm._xTreeCtrl._select(sLabel || '') } else { sLabel = frm._xTreeCtrl._get_curitem_path(); sLabel = frm._label_of(sLabel); if (sLabel == '/') sLabel = ''; return sLabel } }, _check_curdb: function(bSilent) { return this._check_dbid(this._curdb(), bSilent) }, _check_dbid: function(sDbid, bSilent) { var bOK = false; if (sDbid) { bOK = true } else { if (!bSilent) _info(_lc('Prompt.CurDbNotSet', 'No database currently selected, please select one and then try again.')) } return bOK }, _check_curitem: function(bSilent) { return this._check_infoitem(this._xCurItem.sDbid, this._xCurItem.sItemID, bSilent) }, _check_infoitem: function(sDbid, sItemID, bSilent) { var bSucc = false; if (sDbid && sItemID) { bSucc = true } else { if (!bSilent) _info(_lc('Prompt.CurItemNotSet', 'No info item currently opened, please select one to open and then try again.')) } return bSucc }, _check_curlabel: function(bSilent) { return this._check_label(this._curlabel(), bSilent) }, _check_label: function(sLabel, bSilent) { var bSucc = false; if (sLabel && sLabel != '/') { bSucc = true } else { if (!bSilent) _info(_lc('Prompt.CurLabelNotSet', 'No label item currently selected, please select one and then try again.')) } return bSucc }, _create_tabctrl_left: function() { var frm = this; frm._xTabLeft = new _CTabSheet(frm._idTabsLeft, 'CLS_TabCtrlBar', 'CLS_TabItem', 'CLS_TabItemSel'); var dbid = frm._curdb(), sCurLabel = frm._curlabel(); var xPages = $('#' + frm._idPagesLeft); xPages.children().hide(); var vTabs = []; vTabs[vTabs.length] = { sTitle: _lc('Tab.Labels', 'Labels'), idTab: 'ID_TabLabelTree', idPage: frm._idPageLabels, sImgFn: '/images/icon_tab_label.gif', xUserData: '', onTabSel: function() {}, onResize: function() { $('#' + frm._idTreeView)._tile_vertical(true) } }; vTabs[vTabs.length] = { sTitle: _lc('Tab.Query', 'Query'), idTab: 'ID_TabQueryForm', idPage: frm._idPageQuery, sImgFn: '/images/icon_tab_query.gif', xUserData: '', onTabSel: function() {}, onResize: function() { $('#' + frm._idQueryFormPane)._tile_vertical(true) } }; jSel.util.each(vTabs, function(i, xTab) { frm._xTabLeft._new_tab(xTab) }); frm._xTabLeft._select(0) }, _create_tabctrl_right: function() { var frm = this; frm._xTabRight = new _CTabSheet(frm._idTabsRight, 'CLS_TabCtrlBar', 'CLS_TabItem', 'CLS_TabItemSel'); var dbid = frm._curdb(), sCurLabel = frm._curlabel(); var xPages = $('#' + frm._idPagesRight); xPages.children().hide(); var vTabs = []; vTabs[vTabs.length] = { sTitle: _lc('Tab.InfoItems', 'Info Items'), idTab: 'ID_TabItems', idPage: frm._idPageItems, sImgFn: '/images/icon_tab_findres.gif', xUserData: '', onTabSel: function() {}, onResize: function() { $('#' + frm._idInfoItemsPane)._tile_vertical(true) } }; vTabs[vTabs.length] = { sTitle: _lc('Tab.ItemContent', 'Item Content'), idTab: 'ID_TabContent', idPage: frm._idPageContent, sImgFn: '/images/icon_tab_article.gif', xUserData: '', onTabSel: function() {}, onResize: function() { $('#' + frm._idItemContentPane)._tile_vertical(true); $('#' + frm._idMiscInfoPane).width(parseInt(_pf('nAttachPaneWidth'))); $('#' + frm._idHtmlFrmPane)._tile_horizontal(true); $('#' + frm._idHtmlIframe)._tile_vertical(true) } }; jSel.util.each(vTabs, function(i, xTab) { frm._xTabRight._new_tab(xTab) }); frm._xTabRight._select(0) }, _create_query_form: function() { var frm = this, xQ = frm._xQuery, jPane = $('#' + frm._idQueryFormPane), jDiv; jPane.html(''); var xHint = function(jLabel, jInp, sMsg) { var p = (sMsg || '').indexOf('|'); if (p >= 0 && jInp) { jLabel.text(sMsg.substr(0, p)) } else { jLabel.text(sMsg) } }; var jDiv, jDescr, jAnd, jCreator, jRevisor, jLabel, jCtm1, jCtm2, jMtm1, jMtm2, jGo; { jDiv = $('