	GLOBALS = {};
	close_calendar_by_blur_flag = true;
	monthNames = ['Янв', 'Фев', 'Мар', 'Апр', 'Май', 'Июн', 'Июл', 'Авг', 'Сен', 'Окт', 'Ноя', 'Дек'];

	try {
		document.execCommand("BackgroundImageCache", false, true); 
	} catch (err) {}

	function getStageSize(str)
	{
		var x,y;

		if (self.innerHeight) {
			x = self.innerWidth;
			y = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) {
			x = document.documentElement.clientWidth;
			y = document.documentElement.clientHeight;
		} else if (document.body) {
			x = document.body.clientWidth;
			y = document.body.clientHeight;
		}

		if (str == 'x') {
			return parseInt(x);
		} else if (str == 'y') {
			return parseInt(y);
		} else {
			return [parseInt(x), parseInt(y)];
		}
	}

	function showCalendar(prefix, call, date, ignore_blur)
	{
		closeCalendar(prefix);
		var undef;
		var html = '';
		var show = true;

		var d = parseInt($(prefix + 'd').value);
		var m = parseInt($(prefix + 'm').value);
		var y = parseInt($(prefix + 'y').value);

		if (typeof(date) == typeof(undef)) {
			date = new Date();
			if (!isNaN(d)) {
				date.setDate(d);
			}
			if (!isNaN(m)) {
				date.setMonth(m - 1);
			}
			if (!isNaN(y)) {
				date.setYear(y);
			}
		} else {
			var date = date.split('-');
			if (date[2]) {
				d = date[0];
				m = date[1];
				y = date[2];
			} else {
				if (date[0] != m || isNaN(d)) {
					show = false;
					d = 1;
				}
				m = date[0];
				y = date[1];
			}
			date = new Date();
			date.setDate(d);
			date.setMonth(m - 1);
			date.setYear(y);
		}

		html += '<iframe src="/blank.html" width="140" height="163" frameborder="0" style="position: absolute; z-index: 900;"></iframe>';
		html += '<div style="position: absolute; width: 140px; border: solid 1px black; z-index: 901; text-align: center;">';

		var pref_date;
		if (date.getMonth() == 0) {
			pref_date = '12-' + (date.getFullYear() - 1);
		} else {
			pref_date = date.getMonth() + '-' + date.getFullYear();
		}
		html += '<div id="calendar_move_right_box_' + prefix + '" class="calendar_move_right_box" onmouseover="this.style.backgroundColor = \'#666666\'; this.style.color = \'#ffffff\';" onmouseout="this.style.backgroundColor = \'#cccccc\'; this.style.color = \'#000000\';" onclick="showCalendar(\'' + prefix + '\', \'' + call + '\', \'' + pref_date + '\', true); return false;"><</div>';

		html += '<div id="calendar_month_box_' + prefix + '" class="calendar_month_box">' + monthNames[date.getMonth()] + ' ' + date.getFullYear() + '</div>';

		var next_date;
		if (date.getMonth() == 11) {
			next_date = '1-' + (date.getFullYear() + 1);
		} else {
			next_date = (date.getMonth() + 2) + '-' + date.getFullYear();
		}
		html += '<div id="calendar_move_right_box_' + prefix + '" class="calendar_move_right_box" onmouseover="this.style.backgroundColor = \'#666666\'; this.style.color = \'#ffffff\';" onmouseout="this.style.backgroundColor = \'#cccccc\'; this.style.color = \'#000000\';" onclick="showCalendar(\'' + prefix + '\', \'' + call + '\', \'' + next_date + '\', true); return false;">></div>';

		html += '<div id="calendar_week_0_box_' + prefix + '" class="calendar_week_box"><span style="color: #990000;">S</span></div>';
		html += '<div id="calendar_week_1_box_' + prefix + '" class="calendar_week_box">M</div>';
		html += '<div id="calendar_week_2_box_' + prefix + '" class="calendar_week_box">T</div>';
		html += '<div id="calendar_week_3_box_' + prefix + '" class="calendar_week_box">W</div>';
		html += '<div id="calendar_week_4_box_' + prefix + '" class="calendar_week_box">T</div>';
		html += '<div id="calendar_week_5_box_' + prefix + '" class="calendar_week_box">F</div>';
		html += '<div id="calendar_week_6_box_' + prefix + '" class="calendar_week_box"><span style="color: #990000;">S</span></div>';

		var tmp = date.getDate();
		date.setDate(1);
		var cd = date.getDay();

		for (var i = 0; i < cd; i++) {
			html += '<div class="calendar_week_box">&nbsp;</div>';
		}

		for (var i = 1; i < (43 - cd); i++) {
			date.setDate(i);
			if (date.getDate() == i) {
				if (i == d && show) {
					html += '<div id="calendar_days_box_' + i + '_' + prefix + '" class="calendar_days_box" style="background-color: #ffffff;" onmouseover="this.style.backgroundColor = \'#666666\'; this.style.color = \'#ffffff\';" onmouseout="this.style.backgroundColor = \'#ffffff\'; this.style.color = \'#000000\';" onclick="setCalendar(\'' + prefix + '\', \'' + i + '\', \'' + (date.getMonth() + 1) + '\', \'' + date.getFullYear() + '\', \'' + call + '\'); closeCalendar(\'' + prefix + '\');">' + i + '</div>';
				} else {
					html += '<div id="calendar_days_box_' + i + '_' + prefix + '" class="calendar_days_box" onmouseover="this.style.backgroundColor = \'#666666\'; this.style.color = \'#ffffff\';" onmouseout="this.style.backgroundColor = \'#dddddd\'; this.style.color = \'#000000\';" onclick="setCalendar(\'' + prefix + '\', \'' + i + '\', \'' + (date.getMonth() + 1) + '\', \'' + date.getFullYear() + '\', \'' + call + '\'); closeCalendar(\'' + prefix + '\');">' + i + '</div>';
				}
			} else {
				html += '<div class="calendar_week_box">&nbsp;</div>';
			}
		}

		html += '<div id="calendar_close_box_' + prefix + '" class="calendar_close_box" onclick="closeCalendar(\'' + prefix + '\');">Закрыть</div>';

		html += '</div>';

		$('calendar_box_' + prefix).innerHTML = html;
		$(prefix + 'm').focus();

		if (ignore_blur) {
			close_calendar_by_blur_flag = true;
		}
	}

	function setCalendar(prefix, d, m, y, call)
	{
		$(prefix + 'd').value = d;
		$(prefix + 'm').value = m;
		$(prefix + 'y').value = y;

		if (call != '') {
			eval(call);
		}
	}

	function closeCalendar(prefix)
	{
		if (close_calendar_by_blur_flag) {
			close_calendar_by_blur_flag = false;
			return false;
		}
		$('calendar_box_' + prefix).innerHTML = '';
		$(prefix + 'm').blur();
		return false;
	}

	function showPalette(name, foo)
	{
		if ($('box_' + name).innerHTML != '') {
			$('box_' + name).style.display = 'none';
			$('box_' + name).innerHTML = '';
			return;
		}

		var width = 10;
		var height = 10;
		var left = -1;
		var top = -1;
		var undef;

		var h = new Array('00', '33', '66', '99', 'cc', 'ff');
		var hConst = new Array('ff0000', '00ff00', '0000ff', 'ffff00', '00ffff', 'ff00ff');
		var color_pelete_html = '<iframe src="/blank.html" width="210" height="122" frameborder="0" style="position: absolute; left: -1px; top: -1px; z-index: 1;"></iframe>';

		for (var r = 0; r <= 1; r ++) {
			for (var i = 0; i < 6; i++) {
				var color = h[i] + h[i] + h[i];
				color_pelete_html += '<div style="position: absolute; z-index: 2; border: solid 1px #000000; background-color: #' + color + '; left: ' + left + 'px; top: ' + top + 'px;"><img src="/pics/1x1.gif" width="' + width + '" height="' + width + '" onclick="' + (typeof(undef) == typeof(foo) ? 'setColor(\'' + name + '\', \'' + color + '\');' : foo.replace(/\[COLOR\]/, color)) + '"></div>';
				left += width + 1;

				for (var j = (3 * r); j < (3 + (3 * r)); j++) {
					for (var k = 0; k < 6; k++) {

						color = h[j] + h[k] + h[i];
						color_pelete_html += '<div style="position: absolute; z-index: 2; border: solid 1px #000000; background-color: #' + color + '; left: ' + left + 'px; top: ' + top + 'px;"><img src="/pics/1x1.gif" width="' + width + '" height="' + width + '" onclick="' + (typeof(undef) == typeof(foo) ? 'setColor(\'' + name + '\', \'' + color + '\');' : foo.replace(/\[COLOR\]/, color)) + '"></div>';
						left += width + 1;

					}
				}
				left = -1;
				top += height;
			}
		}

		for (i = 0; i < palette.length; i++) {
			$('box_' + palette[i]).style.display = 'none';
			$('box_' + palette[i]).innerHTML = '';
		}
		$('box_' + name).style.display = 'block';
		$('box_' + name).innerHTML = color_pelete_html;
	}

	function setColor(name, color)
	{
		$('div_' + name).style.backgroundColor = "#" + color;
		$(name).value = '#' + color;
		$('box_' + name).style.display = 'none';
		$('box_' + name).innerHTML = '';
	}

	function $(name)
	{
		return document.getElementById(name);
	}

	function $f(name)
	{
		return document.forms[name];
	}

	function $w(name)
	{
		return window.top[name];
	}

	function myParseFloat(num)
	{
		num = parseFloat(num) + '';
		var tmp = num.split('.');

		if (tmp[1]) {
			var ceil = tmp[0];
			tmp = tmp[1] + '';
			if (tmp.length == 1) {
				num = num + '0';
			} else if (tmp.length > 2) {
				var first = tmp.charAt(0);
				var second = tmp.charAt(1);
				var third = tmp.charAt(2);
				if (third >= 5) {
					if (second == '9') {
						if (first == '9') {
							ceil++;
							first = '0';
						} else {
							first++;
						}
						second = '0';
					} else {
						second++;
					}
				}
				num = ceil + '.' + first + second;
			}
		} else {
			num = num + '.00';
		}

		return num;
	}

	function fileName(str)
	{
		var tmp = str.split("/");
		return tmp[(tmp.length - 1)];
	}

	function showError(str)
	{
		alert('Ошибка:' + "\n\n" + str);
	}

	function var_dump(obj, level)
	{
		var out = '';
		var space = '';
		var under;
		if (typeof(level) == typeof(under)) {
			level = 1;
		}
		for (var i = 0; i < level; i++) {
			space += ' ';
		}

		for (var id in obj) {
			if (typeof obj[id] == 'object') {
				out += space + 'OBJECT "' + id + '"' + " \n " + var_dump(obj[id], ++level) + "";
			} else {
				out += space + id + ' = ' + obj[id] + "\n";
			}
		}

		return out + "\n";
	}

	function setCookie(c_name, value, expiredays)
	{
		var exdate = new Date();
		exdate.setDate(exdate.getDate() + expiredays);
		document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
	}

	function getCookie(c_name)
	{
		if (document.cookie.length>0) {
			c_start = document.cookie.indexOf(c_name + "=");
			if (c_start != -1) {
				c_start = c_start + c_name.length + 1; 
				c_end = document.cookie.indexOf(";", c_start);
				if (c_end == -1) {
					c_end = document.cookie.length;
				}
				return unescape(document.cookie.substring(c_start, c_end));
			}
		}
		return '';
	}
