/*
page, zobnew@mail.ru*/

var addAttribute = function(x, attr, value) {
	attr = document.createAttribute(attr);
	attr.value = value;

	x.setAttributeNode(attr);
}

var addCSS = function(str, uri) {
	var _1 = new RegExp('url\\(([\\\'"])', 'ig'), style = document.getElementsByTagName('head')[0].insertBefore(document.createElement('style'), null);

	if (document.all) {
		style = document.styleSheets[document.styleSheets.length - 1];

		addCSS = function(str, uri) {
			str = str.replace(_1, 'url($1' + uri.substring(0, uri.lastIndexOf('/') + 1));

			style.cssText += str;
		}
	} else {
		addCSS = function(str, uri) {
			str = str.replace(_1, 'url($1' + uri.substring(0, uri.lastIndexOf('/') + 1));

//			style.ownerNode.insertBefore(document.createTextNode(str), null);
			style.insertBefore(document.createTextNode(str), null);
		}
	}

	addCSS(str, uri);
}

var addEvent;

if (window.addEventListener) {
	addEvent = function(e, type, f) {
		e.addEventListener(type, f, false);
	}
} else if (window.attachEvent) {
	addEvent = function(e, type, f) {
		e.attachEvent('on' + type, function() {
			f.call(e, window.event);
		});
	}
}

var applyCSSClass = function(x, cName, f) {
	if (!f) {
		x.className = x.className.replace(cName, '');
	} else if (x.className.indexOf(cName) == -1) {
		x.className += ' ' + cName;
	}
}

var applyControlProgress = function(control, f) {
	var progress = new Image();

	progress.className = PROGRESS_CLASS;
	progress.src = THEME_URI + '/' + PROGRESS_IMAGE_IN_THEME_URI;

	return (applyControlProgress = function(control, f) {
		control.loading = f;

		applyPageProgress(f);

		if (control.toProgressHTML) {
			if (f) {
				control.progressHTML = control.toProgressHTML.insertBefore(progress.cloneNode(true), null);

				return control.progressHTML;
			}

			control.toProgressHTML.removeChild(control.progressHTML);
		}
	})(control, f);
}

var applyPageProgress = function(f, _innerCall) {
	var counter = 0, progress = document.createElement('div');

	progress.className = LOADING_CLASS;

	progress.insertBefore(document.createTextNode(Use.locale['loading']), null);

	return (applyPageProgress = function(f, _innerCall) {
		if (!_innerCall) {
			if (f) {
				counter++;
			} else if (counter != 0) {
				counter--;
			}
		}

		if (document.body) {
			if (counter) {
				if (progress.parentNode != document.body) {
					return document.body.insertBefore(progress, null);
				}
			} else if (progress.parentNode == document.body) {
				document.body.removeChild(progress);
			}
		} else if (f) {
			setTimeout(function() {
				applyPageProgress(true, true);
			}, 10);
		}

		return progress;
	})(f, _innerCall);
}

var applyStyle = function(x, style) {
	style = getStyle(style);

	if (!style['']) {
		delete style[''];
	}

	var arr;

	for (var i in style) {
		arr = style.split('-');
		x.style[arr.length == 1 ? arr[0] : arr[0] + arr[1].charAt(0).toUpperCase() + arr[1].substring(1)] = style[i];
	}
}

var cmp = function(a, b) {
	return getArray(a).sort().join('|') == getArray(b).sort().join('|');
}

var esc = function(str) {
	if (str == null || str == undefined) {
		return '';
	}

	return encodeURIComponent(str);
}

var getNewId = function() {
	return 'id' + (++window.num);
}

var getIdById = function(id) {
//	if ([id]) {
	if (!id) {
		return id;
	}

	var ids = id.split(getIdById._1);

	for (var i = 0; i < ids.length; i++) {
		id = ids[i];

//		if ([id]) {
		if (!id) {
			return id;
		}

		if (id == THIS_WIN_NAME) {
			return window.currentWin.id;
		}
	}

	return id;
}

getIdById._1 = new RegExp('\\s*\\|\\s*');
getIdById._2 = new RegExp('\\s*\\:\\s*');

var getName = function(name) {
	if (name) {
		var roole, names = name.split(getIdById._1);

		for (var j, i = 0; i < names.length; i++) {
			roole = names[i].split(getIdById._2);

			if (roole.length == 2) {
				if (window.collection[roole[0]]) {
					return roole[1];
				}
			} else {
				name = names[i];
			}
		}
	}

	return name;
}

var getSettingsById = function(id) {
/*
	Use.ref("Cookies");

	return (getSettingsById = function(id) {*/
		var s = window.settings[id];

		if (s) {
			return s;
		}

		if (s = Cookies.read(id)) {
			try {
				return eval('(' + s + ')');
			} catch (e) {
			}
		}
//	})(id);
}

var getDocumentElement = function(x) {
	if (x) {
		return x.documentElement || x;
	}
}

var getDownloadURI = function(table, field, contentField, contentTypeField, equalityField, value, tableFrom, foreignKeyField, onField) {
	return DOWNLOAD_URI + '?' + getFileRequestParamString(table, field, contentField, contentTypeField, equalityField, value, tableFrom, foreignKeyField, onField);
}

var getFileURI = function(table, field, contentField, contentTypeField, equalityField, value, tableFrom, foreignKeyField, onField) {
	return FILE_URI + '?' + getFileRequestParamString(table, field, contentField, contentTypeField, equalityField, value, tableFrom, foreignKeyField, onField);
}

var getFileRequestParamString = function(table, field, contentField, contentTypeField, equalityField, value, tableFrom, foreignKeyField, onField) {
	if (equalityField) {
		return TABLE_PARAM + '=' + esc(table) + '&' + FIELD_PARAM + '=' + esc(field) + '&' + CONTENT_FIELD_PARAM + '=' + esc(contentField) + '&' + CONTENT_TYPE_FIELD_PARAM + '=' + esc(contentTypeField) + '&' + EQUALITY_FIELD_PARAM + '=' + esc(equalityField) + '&' + EQUALITY_PARAM + '=' + esc(value) + '&' + TABLE_FROM_PARAM + '=' + esc(tableFrom) + '&' + FOREIGN_KEY_FIELD_PARAM + '=' + esc(foreignKeyField) + '&' + ON_FIELD_PARAM + '=' + esc(onField);
	}

	return '';
}

var getFrom = function(x) {
	var from = {
		body: window.contentHTML,

		parent: x.parentNode,
		before: x.nextSibling
	};

	x.parentNode.removeChild(x);

	return from;
}

var getXMLHttpRequest;

if (window.XMLHttpRequest) {
	getXMLHttpRequest = function() {
		return new XMLHttpRequest();
	}
} else {
	(function() {
		for (var objName, XMLHttps = ['Microsoft.XMLHttp', 'MSXML2.XMLHttp', 'MSXML2.XMLHttp.3.0', 'MSXML2.XMLHttp.4.0', 'MSXML2.XMLHttp.5.0'], i = XMLHttps.length - 1; i > -1; i--) {
			try {
				new ActiveXObject(objName = XMLHttps[i]);

				getXMLHttpRequest = function() {
					return new ActiveXObject(objName);
				}
			} catch (e) {
			}
		}
	})();
}

var getMyAttribute = function(x, i) {
	return x.getAttribute(HTML_ATTRIBUTE_PREFIX + i);
}

var getRefreshURI = function(params) {
	return GET_FIELDS_URI + '?' + params.join('&');
}

var getRefreshRequestParams = function(control, from, value, notes, byForm) {
//	try {
		control.setNotesToRefresh(from, value, notes, byForm);
//	} catch (e) {
//	}

	notes[CONTROL_PARAM] = control._class;

	var j, params = [];

	for (var i in notes) {
		if (notes[i] instanceof Array) {
			for (j = notes[i].length - 1; j > -1; j--) {
				params.unshift(control.id + i + '=' + esc(notes[i][j]));
			}
		} else {
			params.push(control.id + i + '=' + esc(notes[i]));
		}
	}

	params.push(PREFIX_PARAM + '=' + esc(control.id));

	return params;
}

var getScriptDirectory = function(uri) {
	for (var scripts = document.getElementsByTagName('script'), i = 0; i < scripts.length; i++) {
		if (scripts[i].src && scripts[i].src.indexOf(uri) != -1) {
			return scripts[i].src.substring(0, scripts[i].src.indexOf(uri));
		}
	}
}

var getSubmitURI = function(form) {
	var i, uri = SUBMIT_URI + '?' + OPERATION_PARAM + '=' + esc(form.notes.operation) + '&' + FUNCTION_PARAM + '=' + esc(form.notes._function) + '&' + TABLE_FROM_PARAM + '=' + esc(form.notes.tableFrom) + '&' + PRIMARY_KEY_FIELD_PARAM + '=' + esc(form.notes.primaryKeyField) + '&' + PRIMARY_KEY_PARAM_PARAM + '=' + esc(form.notes.primaryKeyParam);

	if (i = form.toQueryString()) {
		uri += '&' + i;
	}

	for (i = 0; i < form.notes.params.length; i++) {
		uri += '&' + PARAM_PARAM + '=' + esc(form.notes.params[i]) + '&' + FIELD_PARAM + '=' + esc(form.notes.fields[i]);
	}

	if (form.notes.operation == 'update') {
		uri += '&' + EQUALITY_PARAM + '=' + esc(form.iValue);
	}

	return uri;
}

var getModalURI = function(content, pref) {
	if (getModalURI._1.test(content)) {
		return MODAL_URI + '?' + URI_PARAM + '=' + esc(content) + '&' + TEMPLATE_URI_PARAM + '=' + esc(MODAL_TEMPLATE_URI) + '&' + PREFIX_PARAM + '=' + esc(pref);
	}
}

getModalURI._1 = new RegExp('^[^\\n\\:\\*\\?"<>\\|]+.xml$');

var getModuleURI = function(control) {
	var uri =  MODULE_URI + '?' + NAME_PARAM + '=' + esc(control.notes.module);
//!!@
	for (var param, i = 0; i < control.notes.requestStringFields.length; i++) {
		param = control.notes.requestStringParams[i];

		uri += '&' + esc(control.notes.requestStringFields[i]) + '=' + esc(window.collection[param] ? window.collection[param].toString() : param);
	}

	return uri;
}

var getURIFromWindow = function(win, uri) {
	if (!win.uri) {
		win.win = window.uri;
	}

	if (uri) {
		if (uri.toString().indexOf('/') == 0) {
			return uri;
		}

		return win.uri.substring(0, win.uri.lastIndexOf('/') + 1) + uri;
	}

	return win.uri;
}

var getHTML;

if (document.importNode) {
	getHTML = function(x) {
		return document.importNode(x, true);
	}
} else {
	getHTML = function(x) {
		var i, attr = '';

		for (i = x.attributes.length - 1; i > -1; i--) {
			attr += ' ' + x.attributes[i].name + '="' + x.attributes[i].value + '"';
		}

		var e = document.createElement('<' + x.tagName + attr + ' />');

		for (i = x.firstChild; i; i = i.nextSibling) {
			e.insertBefore(i.tagName ? getHTML(i) : document.createTextNode(i.nodeValue), null);
		}

		return e;
	}
}

var getZeroString = function(i) {
	return i < 10 ? ('0' + i) : i;
}

var getArray = function(i) {
	return i == undefined || i == null ? [] : i instanceof Array ? i.concat() : [i];
}

var getDate = function(i) {
	if (typeof(i) == 'string') {
		i = i.replace(getDate._1, '/');
	}

	i = new Date(i);

	if (!isNaN(i)) {
		return i;
	}
}

getDate._1 = new RegExp('-', 'g');

var getDateString = function(i) {
	if (i = getDate(i)) {
		i = [i.getFullYear(), getZeroString(i.getMonth() + 1), getZeroString(i.getDate())];

		return i[Use.locale.Maskarad['date'].order[0]] + Use.locale.Maskarad['date']['separator'] + i[Use.locale.Maskarad['date'].order[1]] + Use.locale.Maskarad['date']['separator'] + i[Use.locale.Maskarad['date'].order[2]];
	}
}

var getMonthString = function(i) {
	if (i = getDate(i)) {
		i = [i.getFullYear(), getZeroString(i.getMonth() + 1)];

		return i[Use.locale.Maskarad['month'].order[0]] + Use.locale.Maskarad['month']['separator'] + i[Use.locale.Maskarad['month'].order[1]];
	}
}

var getString = function(i) {
	switch (typeof(i)) {
		case 'string':
			return i;

		case 'object':
			if (i == null) {
				return '';
			}

			if (i instanceof Array) {
				var arr = [];

				for (var j = i.length - 1; j > -1; j--) {
					arr.unshift(getString(i[j]));
				}

				return arr;
			}

		case 'number':
			return i.toString();

		case 'undefined':
			return '';

		case 'boolean':
			return i ? '1' : '0';
	}
}

var getStyle = function(i) {
	i = stringToArray(i);

	var style = {};

	for (var arr, j = 0; j < i.length; j++) {
		arr = i[j].split(getIdById._2);
		style[arr[0]] = arr[1];
	}

	return style;
}

var getTimeString = function(i) {
	i = getDate(i);

	if (!i) {
		return;
	}

	return getZeroString(i.getHours()) + Use.locale.Maskarad['time']['separator'] + getZeroString(i.getMinutes()) + Use.locale.Maskarad['time']['separator'] + getZeroString(i.getSeconds());
}

var loadScript = function(uri, f, async, noStated) {
	if (getScriptDirectory(uri) != undefined) {
		if (f instanceof Function) {
			f();
		}

		return;
	}

	var l = getXMLHttpRequest();

	l.open('GET', uri, async);
	l.send(null);

	if (l.readyState == 4) {
		runScript(l.responseText);

		if (f instanceof Function) {
			f();
		}

		return;
	}

	if (!noStated) {
		applyPageProgress(true);
	}

	l.onreadystatechange = function() {
		if (l.readyState != 4) {
			return;
		}

		runScript(l.responseText);

		if (f instanceof Function) {
			f();
		}

		if (!noStated) {
			applyPageProgress();
		}
	}
}

var refreshControl = function(control, from, value, notes, disabled, byForm) {
	var s = ++control.sync;

	setTimeout(function() {
		if (s != control.sync || (from && (!from.isValid || from.loading))) {
			return;
		}

		control.iValue = value;

		if (control._class == "Form") {
			for (var i in control.collection) {
				if (control.collection[i].isRefreshed) {//isField) {
					refreshControl(control.collection[i], from, value, {}, disabled, true);
				}
			}

			return;
		}

		if (!control.loading) {
			applyControlProgress(control, true);

			if (disabled) {
				control.disable();
			}
		}

		rX(control, from, value, notes, disabled, byForm);
	}, 500);
}

var rX = function(control, from, value, notes, disabled, byForm) {
	var s = ++window.refreshSync;

	window.refreshList[control.id] = {
		control: control,
		value: value,
		notes: notes,
		disabled: disabled
	};

	setTimeout(function() {
		if (s != window.refreshSync) {
			return;
		}

		var params = [], list = window.refreshList;

		window.refreshList = {};

		for (var i in list) {
			if (window.collection[i]) {
				i = list[i];
				params = params.concat(getRefreshRequestParams(i.control, from, i.value, i.notes, byForm));
			} else {
				rrX(list[i].control, undefined, list[i].disabled, byForm);
			}
		}

		Load.xml(getRefreshURI(params), function(x) {
			x = getDocumentElement(x);

			if (!x) {
				if (DEBUG) {
					console.error('Refresh control error.');
				}

				return;
			}

			var i;

			if (x.tagName.toUpperCase() == 'ERROR') {
				for (i in list) {
					rrX(list[i].control, undefined, list[i].disabled, byForm);
				}

				showError(window.from, x.firstChild ? x.firstChild.nodeValue : 'Get control data unknown error.', getMyAttribute(x, ERROR_STATUS_ATTRIBUTE));

				return;
			}

			for (x = x.firstChild; x; x = x.nextSibling) {
				if (x.tagName && (i = list[getMyAttribute(x, ID_ATTRIBUTE)])) {
					rrX(i.control, x, i.disabled, byForm);
				}
			}
		}, 'POST', true);
	}, 10);
}

var rrX = function(control, x, disabled, byForm) {
	control.renewByXML(x, byForm);

	if (disabled) {
 		control.enable();
	}

	applyControlProgress(control, false);
}

var refreshRelatedFields = function(from) {
	refreshFields(from, from.notes.relatedFields, from.toString());
}

var refreshFields = function(from, f, value) {
	if (!f || (from && (!from.isValid || from.loading))) {
		return;
	}

	for (var control, i = 0; i < f.length; i++) {
		if (control = window.collection[f[i]]) {
			refreshControl(control, from, value, {}, true);
		}
	}
}

var runScript;

if (window.execScript) {
	runScript = function(str) {
		window.execScript(str, 'javascript');
	}
} else {
	runScript = function(str) {
		window.eval(str);
	}
}

var serialize = function(value) {
	switch (typeof(value)) {
		case 'boolean':
			return value ? 1 : 0;

		case 'number':
			return value;

		case 'string':
			return '"' + value.replace(serialize._1, '\\u0022') + '"';

		case 'object':
			if (value == null) {
				return 'null';
			}

			var i, r = [];

			if (value.length == undefined) {
				for (i in value) {
					r.push(i + ':' + serialize(value[i]));
				}

				return '{' + r.join(',') + '}';
			}

			for (i = 0; i < value.length; i++) {
				r.push(serialize(value[i]));
			}

			return '[' + r.join(',') + ']';
	}
}

serialize._1 = new RegExp('"', 'g');

var showConfirm = function(from, content, controlFrom, f, width, height) {
	showModal(from, Use.locale['confirm-title'], content, ['yes', 'no'], controlFrom, function(button) {
		if (button.notes.type == 'yes' && f instanceof Function) {
			f(button);
		}

		return true;
	}, width, height, undefined, true);
}

var showError = function(from, content, stat, controlFrom, f, width, height) {
	var title = Use.locale['error-title'];

	if (stat) {
		title += ' ' + stat;
	}

	showModal(from, title, content, ['close'], controlFrom, function(button) {
		if (f instanceof Function) {
			f(button);
		}

		return true;
	}, width, height, undefined, true);
}

var showForm = function(from, title, content, controlFrom, f, width, height, pref) {
	showModal(from, title, content, [], controlFrom, function(button) {
		switch (button.notes.type) {
			case 'submit':
				if (f instanceof Function) {
					return f(button);
				}

				return false;

			case 'cancel':
			case 'close':
				return true;
		}
	}, width, height, pref);
}

var showMessage = function(from, content, controlFrom, f, width, height) {
	showModal(from, Use.locale['message-title'], content, ['close'], controlFrom, function(button) {
		if (f instanceof Function) {
			f(button);
		}

		return true;
	}, width, height, undefined, true);
}

var showWarning = function(from, content, controlFrom, f, width, height) {
	showModal(from, Use.locale['warning-title'], content, ['close'], controlFrom, function(button) {
		if (f instanceof Function) {
			f(button);
		}

		return true;
	}, width, height, undefined, true);
}

var showModal = function(from, title, content, buttonTypes, controlFrom, f, width, height, pref, _byError) {
	Use.load("Button", true);
	Use.load("Modal", true);

	Use.waitLoading(function() {
		(showModal = function(from, title, content, buttonTypes, controlFrom, f, width, height, pref, _byError) {
			var win = new Modal();

//в Modal уже есть			win.id = win._class + ' ' + getNewId();
			win.win = window.currentWin;

			win.init(from, {
				width: width,
				height: height
			});

			window.collection[win.id] = win;

			if (controlFrom) {
				win.controlFrom = controlFrom;
				win.iValue = controlFrom.toString();

				win.notes.operation = controlFrom.notes.operation;
				win.notes._function = controlFrom.notes._function;
				win.notes.tableFrom = controlFrom.notes.tableFrom;
				win.notes.selectedTable = controlFrom.notes.selectedTable;

				win.onShow = function() {
/*!!
					var f = [], fields = controlFrom.notes.relatedFields;

					for (var i = fields.length - 1; i > -1; i--) {
						if (this.collection[fields[i]]) {
							f.unshift(fields[i]);
						}
					}

					refreshFields(controlFrom, f, this.iValue);*/
					if (!_byError) {
						refreshFields(controlFrom, controlFrom.notes.relatedFields, controlFrom.toString());
					}

					if (controlFrom._class == "Button") {
						controlFrom.enable(true);
					}
				}
			}

			win.onButtonClick = function(button) {
				if (f instanceof Function && f(button)) {
					this.close();
				}
			}

			var buttons = [];

			for (var button, i = buttonTypes.length - 1; i > -1; i--) {
				button = new Button();

				button.init(from, {
					type: buttonTypes[i]
				});

				buttons.unshift(button);
			}

			win.show(title, content, buttons, pref);
		})(from, title, content, buttonTypes, controlFrom, f, width, height, pref, _byError);
	});
}

var stringToArray;

if (document.all) {
	stringToArray = function(i) {
		if (i == undefined || i == null) {
			return [];
		}

		i = trim(i).split(';');

		for (var j = i.length - 1; j > -1; j--) {
			i[j] = trim(i[j]);
		}

		return i;
	}
} else {
	stringToArray = function(i) {
		var _1 = new RegExp('\\s*;\\s*');

		return (stringToArray = function(i) {
			return i == undefined || i == null ? [] : trim(i).split(_1);
		})(i);
	}
}

var trim = function(i) {
	try {
		return i.replace(trim._1, '');
	} catch (e) {
//!!
alert('try-catch trim(' + i + ')');
		return '';
	}
}

trim._1 = new RegExp('^\\s+|\\s+$', 'g');

var uploadFiles = function(formHTML, ids, f) {
	var iframeId = getNewId(), formOnSubmit = formHTML.onsubmit, params = [];

	for (var hidden, i = ids.length - 1; i > -1; i--) {
		hidden = document.createElement('input');

		hidden.name = UPLOAD_PARAM;
		hidden.value = ids[i];
		hidden.type = 'hidden';

//		addAttribute(hidden, 'type', 'hidden');
		params.push(formHTML.insertBefore(hidden, null));
	}

	formHTML.action = UPLOAD_URI;
	formHTML.target = iframeId;
	formHTML.method = 'post';

	addAttribute(formHTML, 'enctype', 'multipart/form-data');

	formHTML.onsubmit = function() {
	}

	var container = document.body.insertBefore(document.createElement('div'), null);

	container.innerHTML = '<iframe name="' + iframeId + '" onload="this.' + "_onload" + '();" style="display: none;"></iframe>';

	var iframe = container.firstChild, frame = window.frames[window.frames.length - 1];

	iframe._onload = function() {
		for (var i = params.length - 1; i > -1; i--) {
			formHTML.removeChild(params[i]);
		}

		formHTML.onsubmit = formOnSubmit;

		f(frame.document.body || frame.document);
		applyPageProgress();

		setTimeout(function() {
			document.body.removeChild(container);
		}, 1);
	}

	applyPageProgress(true);
	formHTML.submit();
}

var init = function() {
	if (!document.body) {
//		document.body = document.getElementsByTagName('body')[0];
		var body = document.getElementsByTagName('body')[0];

		if (body) {
			document.body = body;
		}
	}

	window.contentHTML = document.getElementById('content');

	if (!window.contentHTML) {
		window.contentHTML = document.body;
	}

	if (!window.contentHTML) {
		setTimeout(init, 10);

		return;
	}

	var themeURI = getMyAttribute(window.contentHTML, THEME_URI_ATTRIBUTE);

	if (themeURI) {
		THEME_URI = themeURI;
	}

	window.from = {
		body: window.contentHTML,

		parent: window.contentHTML,
		before: null
	};

	window.onbeforeunload = function() {
//		Use.ref("Cookies");

		var expires = new Date().getTime() + 456 * 24 * 60 * 60 * 1000;

		for (var i in window.settings) {
			Cookies.write(i, serialize(window.settings[i]), undefined, undefined, expires);
		}
	}
/*
	if (!DEBUG) {
		window.onerror = function (err, file, line) {
			try {
				if (confirm(Use && Use.locale && Use.locale['error'] ? Use.locale['error']['impart-confirm'] + err + Use.locale['error']['impart-confirm1'] : 'Clent error on the page: ' + err + '. Impart by exception on the server?')) {
					location.href = ERROR_URI + '?' + ERROR_PARAM + '=' + esc(err) + '&' + FILE_PARAM + '=' + esc(file) + '&' + LINE_PARAM + '=' + esc(line) + '&' + USER_AGENT_PARAM + '=' + esc(window.navigator ? navigator.userAgent : '');
				}
			} catch (e) {
			}

			return false;
		}
	}*/

	Load.css(THEME_URI + '/' + STYLE_FILE_NAME, undefined, 'GET', true);
	Use.parse(window.contentHTML, undefined, window, undefined, true);
}

window._class = 'Window';
window.uri = new RegExp('.+?\\/\\/.+?(\\/.*)').exec(document.location.href)[1];
window.currentWin = window;
window.contentHTML = undefined;

window.notes = {};
window.settings = {};

window.num = 0;
window.collection = {};

window.refreshList = {};
window.refreshSync = 0;

var JS_URI = getScriptDirectory('page.js');

(function () {
	var i = 0, f = function() {
		if (++i == 4) {
			Use.locale.init();
			init();
		}
	};

	loadScript(JS_URI + '/const.js', f, true, true);//1

	loadScript(JS_URI + '/lib/' + "Cookies" + '.js', f, true, true);//2
	loadScript(JS_URI + '/lib/' + "Load" + '.js', f, true, true);//3
	loadScript(JS_URI + '/lib/' + "Use" + '.js', f, true, true);//4
})();
