if (typeof Error == 'undefined') {
	Error = {};
	
	Error.debug = function (obj, sep)
	{
		var message = "";
		var type = typeof obj;
		if (! sep) {
			sep = "";
		}
		message += "(" + type + ")";
		if (type === "object" || type === "array") {
			message += "\n{\n";
			var sep2 = sep + "    ";
			for (var key in obj) {
				//message += sep2 + ((type === "array") ? "[" + key + "]" : "->" + key) + " = " + Error.debug(obj[key], sep2) + "\n";
				message += sep2 + ((type === "array") ? "[" + key + "]" : "->" + key) + " = " + obj[key] + "\n";
			}
			message += "}";
		} else {
			message += " " + obj;
		}
		return message;
	}
}


if (typeof System == 'undefined' || ! System.defined) {
	System = {'defined': true};
	
	System.debugMessage = function (message) {
		messageWindow = window.top;
		if (! isset(messageWindow.frameworkMessage)
		|| ! isset(messageWindow.frameworkMessage.length)) {
			messageWindow.frameworkMessage = [];
		}
		messageWindow.frameworkMessage.push(message);
		if (! messageWindow.debugWindow) {
			var
			dialogWidth = screen.availWidth * 0.50
			dialogHeight = screen.availHeight,
			dialogLeft = screen.availWidth - dialogWidth,
			dialogTop = 0;
			messageWindow.debugWindow = true;
			if (! isset(window.showModelessDialog)) {
				window.attachEvent("onload", new Function('var w = window.open('
				+ '"' + SERVER_BASE + INDEX_NAME + '_dialogs/debug.php", "debugDialog", "'
				+ 'width=' + dialogWidth + 'px, height=' + dialogHeight + 'px, '
				+ 'left=' + dialogLeft + 'px, top=' + dialogTop + 'px, '
				+ 'resizable, scrollbars, dependent, modal, dialog"); '
				+ 'w.dialogArguments = messageWindow; return true;'));
			} else {
				window.attachEvent("onload", new Function('showModelessDialog('
				+ '"' + SERVER_BASE + INDEX_NAME + '_dialogs/debug.php", messageWindow, "'
				+ 'dialogWidth: ' + dialogWidth + 'px; '
				+ 'dialogHeight: ' + dialogHeight + 'px; '
				+ 'dialogLeft: ' + dialogLeft + 'px; '
				+ 'dialogTop: ' + dialogTop + 'px; center: no; dialogHide: yes; '
				+ 'edge: raised; help: no; resizable: yes; scroll: auto; '
				+ 'status: no; unadorned: no;"); return true;'));
			}
		} else if (messageWindow.debugWindow !== true) {
			messageWindow.debugWindow.Refresh();
		}
	}
	
	System.errorMessage = function (container) {
		var message = (container.length) ? (container[container.length-1].innerHTML) : (container.innerHTML);
		var rgx = new RegExp('^<br\s*\/?><b>([^<]*)<\/b>:\s*([^\s].*[^\s])\s*in\s*<b>([^<]*)<\/b>.*<b>([^<]*)<\/b><br\s*\/?>$', 'i');
		var res = rgx.exec(message);
		if (rgx != null && res != null) {
			title = res[1];
			title = title.toLowerCase();
			if (title === 'fatal error') {
				title = 'system error';
				endline = 'Script was terminated';
			} else {
				title = 'system ' + title;
				endline = '';
			}
			message = '<table class="error" cellspacing="0" cellpadding="0" border="0" width="100%" height="100%" align="center">'
			+ '<tr valign="top"><th height="10" colspan="2"><p><b>' + title + ':</b> ' + res[2] + '</p></th></tr>'
			+ '<tr valign="top"><td height="10"><p><b>File:&nbsp;</b></p></td><td width="100%"><p>' + res[3] + '</p></td></tr>'
			+ '<tr valign="top"><td height="10"><p><b>Line:&nbsp;</b></p></td><td width="100%"><p>' + res[4] + '</p></td></tr>'
			+ '<tr valign="top"><td height="10" colspan="2"><p>' + endline + '</p></td></tr></table>';
		} else {
			if (message.substr(1, 3) == '<br') {
				message = message.substr(message.indexOf('>'));
			}
			message = '<table class="error" cellspacing="0" cellpadding="0" border="0" width="100%" height="100%" align="center">'
			+ '<tr valign="top"><th height="10" colspan="2"><p>' + message + '</p></th></tr></table>';
		}
		System.debugMessage(message);
	}
	
	System.__error = function (e) {
		Dialogs.error(e.name + ': ' + e.message);
	}
	
	System.parentWindow = function (w) {
		if (! isset(w)) {
			w = window;
		}
		w = w.top;
		if (w.opener) {
			return w.opener;
		}
		if (w.dialogArguments && w.dialogArguments.caller) {
			return w.dialogArguments.caller;
		}
		return window.parent;
	}
	
	System.reloadWindow = function (w) {
		if (! isset(w)) {
			w = window;
		}
		//w = w.top;
		if (w.name && w.name !== '[object]') {
			w.open(w.location.href, w.name);
		} else {
			w.location = w.location.href;
		}
	}
	
	System.closeWindow = function (w) {
		if (! isset(w)) {
			w = window;
		}
		w = w.top;
		if (! isset(w.opener)) {
			w.opener = w;
		}
		w.close();
	}
	
	System.returnValue = function (v, w) {
		if (! isset(w)) {
			w = window;
		}
		w = w.top;
		w.returnValue = v;
	}
	
	System.openLink = function (url, target, params, win) {
		if (! isset(win)) {
			win = window;
		}
		if (target == null || target == '') {
			target = win.name;
		}
		if (target == '' || target === '[object]') {
			target = '_self';
		}
		if (params) {
			return win.open(url, target, params);
		} else {
			return win.open(url, target);
		}
	}
}

function KeyPress () {
	var e = window.event, k = (KeyPress.keys[e.keyCode] !== undefined) ? KeyPress.keys[e.keyCode] : String.fromCharCode(e.keyCode).toUpperCase();
	if (e.shiftKey) k = 'Shift+' + k;
	if (e.altKey) k = 'Alt+' + k;
	if (e.ctrlKey) k = 'Ctrl+' + k;
	return k;
}
KeyPress.keys = {0x0D:'Enter', 0x1B:'Esc', 0x20:'Space'};

function KeyPressDelegate () {
	var f = function (event) {
		try {
			var e, s;
			if (window.event === undefined) {
				e = event;
				s = e.currentTarget;
			} else {
				e = window.event;
				s = e.srcElement;
			}
			if (s === null) {
				s = window;
			}
			var k = KeyPress(), p = s['on' + e.type].keys[k];
			for (var i in p) {
				var f = p[i];
				if (typeof f === 'function') f();
			}
		} catch (x) {
			system.__error(x);
		}
	}
	f.keys = {};
	return f;
}

function KeyUpDown () {
	var e = window.event, k = (KeyUpDown.keys[e.keyCode] !== undefined) ? KeyUpDown.keys[e.keyCode] : String.fromCharCode(e.keyCode).toUpperCase();
	if (k === 'Shift' || k === 'Alt' || k === 'Ctrl') k = '';
	if (e.shiftKey) k = 'Shift+' + k;
	if (e.altKey) k = 'Alt+' + k;
	if (e.ctrlKey) k = 'Ctrl+' + k;
	if (k.charAt(k.length - 1) === '+') k = k.substr(0, k.length - 1);
	return k;
}
KeyUpDown.keys = {
	0x03:'Break', 0x08:'BackSpace', 0x09:'Tab', 0x0C:'Center'/*Shift+Num5*/,
	0x0D:'Enter', 0x10:'Shift', 0x11:'Ctrl', 0x12:'Alt', 0x13:'Pause', 0x14:'CapsLock',
	0x1B:'Esc', 0x20:'Space', 0x21:'PgUp', 0x22:'PgDn', 0x23:'End', 0x24:'Home',
	0x25:'Left', 0x26:'Up', 0x27:'Right', 0x28:'Down', 0x2D:'Insert', 0x2E:'Delete',
	0x5B:'Win'/*LeftWin*/, 0x5C:'Win'/*RightWin*/, 0x5D:'Menu',
	0x60:'Num0', 0x61:'Num1', 0x62:'Num2', 0x63:'Num3', 0x64:'Num4', 0x65:'Num5', 0x66:'Num6', 0x67:'Num7',
	0x68:'Num8', 0x69:'Num9', 0x6A:'Num*', 0x6B:'Num+', 0x6D:'Num-', 0x6E:'Num.', 0x6F:'Num/',
	0x70:'F1', 0x71:'F2', 0x72:'F3', 0x73:'F4', 0x74:'F5', 0x75:'F6', 0x76:'F7', 0x77:'F8', 0x78:'F9',
	0x79:'F10', 0x7A:'F11', 0x7B:'F12', 0x90:'NumLock', 0x91:'ScrLock',
	0xBA:';', 0xBB:'=', 0xBC:',', 0xBD:'-', 0xBE:'.', 0xBF:'/', 0xC0:'`', 0xDB:'[', 0xDD:']', 0xDE:"'",
	0xDC:'\\'/*Right\*/, 0xE2:'\\'/*Left\*/
};

function KeyUpDownDelegate () {
	var f = function (event) {
		/*try {*/
			var e, s;
			if (window.event === undefined) {
				e = event;
				s = e.currentTarget;
			} else {
				e = window.event;
				s = e.srcElement;
			}
			if (s === null) {
				s = window;
			}
			var k = KeyUpDown(), p = s['on' + e.type].keys[k];
			for (var i in p) {
				var f = p[i];
				if (typeof f === 'function') f();
			}
		/*} catch (x) {
			system.__error(x);
		}*/
	}
	f.keys = {};
	return f;
}

