/**
* Filename................: mel.js
* Project.................: web pages SDK
* Last Modified...........: $Date: 08/05/2010 21:22:12 $
* CVS Revision............: $Revision: 0.0.45 $
* Idea and Developed by...: Maxim Bulygin (sailormax@gmail.com)
*/

if (typeof MEL != "object") var MEL = {};

// aliases
	MEL.d = document;
	MEL.de = MEL.d.documentElement;
	MEL.ds = MEL.d.selection;
	MEL.dc = MEL.d.cookie;
	MEL.w = window;

	MEL.d.getEl = MEL.d.getElementById;
	MEL.d.getEls = MEL.d.getElementsByName;
	MEL.d.getTags = MEL.d.getElementsByTagName;
//

	MEL.now = new Date();

// browser name and version
	var ua = MEL.ua = {
		str:		navigator.userAgent,
		other:		true,
		is_crawler:	(null != navigator.userAgent.match(/(Yahoo!|Crawler|Google|MSNBot|Slurp|Teoma|Gigabot|Scrubby|Robozilla|BecomeBot|Nutch|Yandex|Rambler|Aport|Spider|MJ12bot|KalamBot|genieBot|Latnet-search-engine|Letonika.lv|ia_archiver|findlinks|Mail.Ru|Snapbot|PycURL|psbot|larbin|Exabot|libwww-perl|Jakarta|voyager|MSRBOT|Jyxobot|Scooter|accelobot|yetibot|Yeti\/|heritrix|eBolot)/i))
	}
//

// small init
	new function()
	{
		// detect browser
		var i, tmp, uas = [["opera"], ["safari"], ["konqueror", "konq"], ["msie", "ie"], ["mozilla"]];
		for (i in uas)
		{
			i = uas[i];
			if (tmp = ua.str.match(new RegExp(i[0]+".([0-9\.]+)", "i")))
			{
				ua[i[1] || i[0]] = parseFloat(tmp[1]);
				ua.other = false;
				break;
			}
			else
				ua[i[1] || i[0]] = false;
		}
		//

		// detect timeshift + daylight time
//		var locale_date = new Date(2010, 8, 7, 19, 6, 5);
		var locale_date = new Date(2010, 4, 13, 19, 6, 5);
		var locale_str = locale_date.toLocaleString();
		var re_time = /[0-9]{1,2}:[0-9]{1,2}/;
		var delim_pos = locale_str.search(re_time);
		// time
			var time_mask = "";
			var hour = locale_str.substr(delim_pos).split(':', 2)[0];
			if (hour == "19")
			{
				var tmp_date = locale_date;
				tmp_date.setHours(7);
				hour = tmp_date.toLocaleString().substr(delim_pos).split(':', 2)[0];
				time_mask += (hour == "7" ? 'H:mm' : "HH:mm");
			}
			else
				time_mask += (hour == "7" ? 'h:mm' : "hh:mm");
		//

		// date
			var item, words = [];
			var short_weekday = false;
			var date_mask = locale_str.substr(0, delim_pos);
			var re_word = /[^,\.\- 0-9][^,\.\-0-9]+/g;
			while ((item = re_word.exec(date_mask)) != null) words.push(item);

			// remove week day
				var shift = 0;
				while (words.length > 1)
				{
					item = words.shift();
					item[0] = item[0].replace(/[ ,\.\-]+$/, "");
					if ((item.index > 0) && (!isNaN(parseInt(date_mask.substr(shift+item.index-1, 1)))))	// japan dates
					{
						date_mask = date_mask.substring(0, shift+item.index) + "/" + date_mask.substr(shift+item.index+item[0].length);
						shift -= item[0].length-1;
					}
					else
					{
						short_weekday = (item[0].length <= 3);
						date_mask = date_mask.substring(0, shift+item.index) + date_mask.substr(shift+item.index+item[0].length+1);
						shift -= item[0].length+1;
					}
				}
			//

			if (words.length)
			{
				if (!isNaN(parseInt(date_mask.substr(shift+words[0].index-1, 1))))	// japan dates
					date_mask = date_mask.substring(0, shift+words[0].index) + date_mask.substr(shift+words[0].index+words[0][0].length);
				else
					date_mask = date_mask.replace(words[0][0].replace(/[ ,\.\-]+$/, ""), (short_weekday ? "MMM" : "MMMM"));
			}

			date_mask = date_mask.replace(/([0-9]+)/g, function(num)
				{
					inum = num-0;
					if (num == locale_date.getFullYear())
						return "yyyy";
					else if (num == (locale_date.getFullYear()+"").substr(-2))
						return "yy";
					else if (inum == (locale_date.getMonth()+1))
						return (num.length > 1 ? "MM" : "M");
					else if (inum == locale_date.getDate())
						return (num.length > 1 ? "dd" : "d");
					return "";
				});
		//
		date_mask = date_mask.replace(/^[ ,.-]+/, "").replace(/[ ,.-]+$/, "");

		if (/[^dMy ,\.\-]/.test(date_mask))	// exception
			date_mask = "d.MM.yyyy";

		var exp = new Date();
		exp.setFullYear(MEL.now.getFullYear()+10);
		document.cookie = "MEL_UTC=" + escape(-MEL.now.getTimezoneOffset()) + ";expires="+exp.toGMTString()+";path=/";
		var winter = new Date(MEL.now.getFullYear(), 1, 1);
		var summer = new Date(MEL.now.getFullYear(), 6, 1);
		document.cookie = "MEL_DST=" + escape((MEL.now.getTimezoneOffset()!=winter.getTimezoneOffset())-0) + ";expires="+exp.toGMTString()+";path=/";
		document.cookie = "MEL_DTS=" + escape(-(summer.getTimezoneOffset()-winter.getTimezoneOffset())) + ";expires="+exp.toGMTString()+";path=/";
		document.cookie = "MEL_DATE_FORMAT=" + escape(date_mask) + ";expires="+exp.toGMTString()+";path=/";
		document.cookie = "MEL_TIME_FORMAT=" + escape(time_mask) + ";expires="+exp.toGMTString()+";path=/";
	}();
//

// cross browser debug
	if (opera && !console)
		var console = { log: opera.postError };
	else if (console && !opera)
		var opera = { postError: console.log };
	else if (!console)
	{
		var console = { }, opera = { };
		console.log = opera.postError = function(str)
		{
			var el = MEL.d.createElement("DIV");
			el.className = "debug";
			el.style.zIndex = 1000;
			el.style.position = "relative";
			el.style.backgroundColor = "white";
			el.innerHTML = str;
			MEL.d.body.appendChild(el);
		}
	}
//

// URL
	MEL.url = MEL.d.location;
	MEL.url.URI = MEL.url.href.replace(/#.*$/, ""),
	MEL.url.anchors_arr = [],
	MEL.url.anchors_of = "";
	MEL.url.getAnchors = function()
	{
		if (this.anchors_of != this.href)
		{
			var str = this.href.replace("##", "#");
			this.anchors_arr = str.search(/#.+/) > 0 ? str.replace(/^[^#]+#?/, "").split("#") : [];
		}
		return this.anchors_arr;
	}
	MEL.url.appendAnchor = function(name)
	{
		if (MEL.inArray(name, this.getAnchors()) < 0)
			this.replace(MEL.url.URI + "#" + this.getAnchors().concat([name]).join("#"));
	}
	MEL.url.removeAnchor = function(name)
	{
		var i = MEL.inArray(name, this.getAnchors());
		if (i >= 0)
		{
			var new_list = this.getAnchors();
			new_list.splice(i, 1);
			this.replace(MEL.url.URI + "#" + new_list.join("#"));	// keep empty "#" for deny reloading
		}
	}
//

// DOM functions
	MEL.dom = {

		getStyle: function(el, name)
		{
			if (name)
			{
				if (MEL.d.defaultView && MEL.d.defaultView.getComputedStyle)
					return MEL.d.defaultView.getComputedStyle(el, "").getPropertyValue(name);
				else if (el.currentStyle)
				{
					name = name.replace(/-(\w)/g, function(){ return arguments[1].toUpperCase(); });
					return el.currentStyle[name];
				}
			}
			else
			{
				var style;
				if (el.style.getAttribute)
					style = el.style.getAttribute("cssText");
				else
					style = el.getAttribute("style");

				if (style)
					return style;
			}
			return "";
		},


		setStyle: function(el, str)
		{
			if (el.style.setAttribute)
				el.style.setAttribute("cssText", str);
			else
				el.setAttribute("style", str);
		},


		hasClass: function(el, name)
		{
			return ((" "+el.className+" ").search(" "+name+" ") > -1);
		},

		appendClass: function(el, name)
		{
			if ((" "+el.className+" ").search(" "+name+" ") < 0)
				el.className += " " + name;
		},

		removeClass: function(el, name)
		{
			el.className = (" "+el.className+" ").replace(" "+name+" ", " ").replace(/^ +/, "").replace(/ +$/, "").replace(/ +/, " ");
		},

		replaceClass: function(el, name, new_name)
		{
			el.className = (" "+el.className+" ").replace(" "+name+" ", " "+new_name+" ").replace(/^ +/, "").replace(/ +$/, "");
		},


		setAttribute: function(el, name, val)
		{
			if (val-0 == val) val -= 0;
			var items = name.split('.');
			if (items.length == 1)
			{
				if (el.setAttribute)
					el.setAttribute(name, val);
				else
					el[name] = val;
			}
			else
			{
				if (items[0] == "filter") items[0] = "filters";
				if (items[0] == "filters" && el.filters)
				{
					if (!el[items[0]][items[1]])
					{
						var filter = " " + items[1] + "(" + items[2] + "=" + val + ")";
						var re = new RegExp(" " + items[1] + "\\(" + items[2] + "=([^\\)]+)\\)", "i");
						if (el.style.filter.search(re) >= 0)
							el.style.filter = el.style.filter.replace(re, filter);
						else
							el.style.filter += filter;
					}

					if (/^filters?\.alpha\.opacity$/.test(name.toLowerCase()))
					{
						if (el.filters.alpha)
							el.filters.alpha.enabled = (val >= 100 ? "false" : "true");
						if (val >= 100)
							el.style.filter = el.style.filter.replace(/ alpha\([^\)]+\)/, "");
					}
				}

				var i = 0;
				while (el[items[i]] && (i < (items.length-1)))
					el = el[items[i++]];
				if (i == (items.length-1))
					el[items[i]] = val;
			}
		},


		getSelectedText: function()
		{
			return window.getSelection ? window.getSelection().toString() : MEL.ds.createRange().text;
		},


		getAbsolutePos: function(el)
		{
			var pnt = {x:0, y:0, ox:0, oy:0, oxoyParent:null};
			var start_el = el;
			var next_el, prev_el, deep = 0;
			while (el)
			{
				pnt.x += el.offsetLeft;
				pnt.y += el.offsetTop;
				prev_el = el;

				// minus all scrolls
				next_el = el.offsetParent;
				if (next_el)
				{
					while ((el = el.parentNode) && (el != next_el))
					{
						pnt.x -= el.pageXOffset || el.scrollLeft;
						pnt.y -= el.pageYOffset || el.scrollTop;
					}
				}
				else
					el = null;

				if (!pnt.oxoyParent)
				{
					var is_rel = (MEL.inArray(this.getStyle(prev_el, "position"), ["fixed", "relative", "absolute"]) >= 0);

					// stop offer coords, if we have not static element
					if (deep && is_rel)
						pnt.oxoyParent = prev_el;
					else
					{
						pnt.ox = pnt.x;
						pnt.oy = pnt.y;
					}

					if (is_rel && !next_el && (MEL.ua.ie == 8))			// ie8 fix
					{
						el = prev_el.parentNode;
						while (el)
						{
							if (MEL.inArray(this.getStyle(el, "position"), ["fixed", "relative", "absolute"]) >= 0)
							{
								pnt.x += el.offsetLeft;
								pnt.y += el.offsetTop;
							}
							el = el.parentNode;
						}
					}
//					else if (is_rel && !next_el && (MEL.ua.opera >= 9.8))			// opera 10 beta fix
//					{
//						pnt.y -= MEL.d.getTags("html")[0].scrollTop;
//					}
//					else if (is_rel && !next_el && MEL.ua.safari)			// safari and chrome
//					{
//						pnt.y += MEL.d.getTags("body")[0].scrollTop;
//					}
				}
				deep++;
			}

			if (this.getStyle(pnt.oxoyParent||start_el, "position") == "fixed")
			{
				pnt.x += MEL.de.scrollLeft;
				pnt.y += MEL.de.scrollTop;
			}

			return pnt;
		},


		getElementSize: function(el, with_borders, content_size)
		{
			if (!el) return [];
			var wnd = ((el.tagName == "BODY") || (el == MEL.w) ? MEL.w : null);
			var de = MEL.de;

			var res = {
				sw: el.scrollWidth,
				sh: el.scrollHeight,	// + (wnd ? wnd.scrollMaxY || 0 : 0)
				sx: -1, sy: -1,
				w: -1, h: -1
			};

			if (el.tagName == "SCRIPT" || el.tagName == "STYLE")
				return { sw:0, sh:0, sx:0, sy:0, w:0, h:0 };

			if (wnd)
			{
				if (de && de.clientHeight)
				{
					res.w = de.clientWidth;		res.h = de.clientHeight;
					res.sx = de.scrollLeft || self.pageXOffset;
					res.sy = de.scrollTop || self.pageYOffset;
				}
				else if (self.innerHeight)									// IE6 (Strict)
				{
					res.w = self.innerWidth;	res.h = self.innerHeight;
					res.sx = self.pageXOffset;	res.sy = self.pageYOffset;
				}

				// !MEL.ua.ie && !MEL.ua.safari && 
				if ((window != parent))	// if iframe, fix bug of Firefox, Opera or... web standarts ;)
				{
					res.h = 0;
					var i, size, root_childs = wnd.document.body.childNodes;
					for (i=0; i<root_childs.length; i++) if (root_childs[i].tagName)
						res.h += this.getElementSize(root_childs[i]).h;
				}
			}
			if (res.h < 0)
			{
				if (MEL.ua.safari)
				{
					res.w = el.offsetWidth;
					res.h = el.offsetHeight;
				}
				else
				{
					if (with_borders === false)
					{
						res.w = el.clientWidth || el.offsetWidth;
						res.h = el.clientHeight || el.offsetHeight;
					}
					else

					{
						res.w = el.offsetWidth || el.clientWidth;
						res.h = el.offsetHeight || el.clientHeight;
					}
				}
				res.sx = el.scrollLeft;		res.sy = el.scrollTop;
			}

			if (res.sw < res.w) res.sw = res.w;
			if (res.sh < res.h) res.sh = res.h;
			if (wnd && (window != parent)) res.sh = res.h;

			if (content_size)
			{
				res.w -= (parseInt(MEL.dom.getStyle(el, "padding-left")) + parseInt(MEL.dom.getStyle(el, "padding-right")));
				res.h -= (parseInt(MEL.dom.getStyle(el, "padding-top")) + parseInt(MEL.dom.getStyle(el, "padding-bottom")));
			}

			return res;
		},

		getOpenedTags: function(node)
		{
			var tags = [];
			while (node)
			{
				tags.push(node);
				var node = node.parentNode;
			}
			return tags;
		},
		
		insertRow2Table: function(tbl, row, idx, cp_attrs)
		{
			var i, nr = tbl.insertRow(idx);
			nr.className = row.className;
			this.setStyle(nr, this.getStyle(row));
			if (typeof cp_attrs == "undefined" || cp_attrs)		// IE very strange copy attrs of TR and other tags...
				MEL.copyElAttrs(nr, row);
			var cln, arr = row.childNodes;
			for (i=0; i<arr.length; i++)
				nr.appendChild(arr[i].cloneNode(true));
			return nr;
		},

		getInnerText: function(el)
		{
			var res = "";
			var childs = el.childNodes;
			var i, cnt = childs.length;
			for (i=0; i<cnt; i++) if (childs[i].nodeValue) res += childs[i].nodeValue;
			return res;
		}
	}
//


// MEL events
	MEL.event = {

		__onmouseinout: [],

		addListener: function(el, evtType, func)
		{
			if (el.addEventListener)
				el.addEventListener(evtType, func, false);
			else if (el.attachEvent)
				return el.attachEvent("on"+evtType, func);
			else
				return false;
			return true;
		},


		removeListener: function(el, evtType, func)
		{
			if (el.removeEventListener)
				el.removeEventListener(evtType, func, false);
			else if (el.detachEvent)
				return el.detachEvent("on"+evtType, func);
			else
				return false;
			return true;
		},


		addMouseInOut: function(obj, over, out)
		{
			var i, list = this.__onmouseinout;
			for (i in list) if (list[i][0] === obj) return;
			if (!list.length)
			{
				this.addListener(MEL.d, "mouseout", this.__hMouseInOut);
				this.addListener(MEL.d, "mouseover", this.__hMouseInOut);
			}
			for (i in list) if (list[i] === null)
			{
				list[i] = [obj, true, out, over];
				return;
			}
			list.push([obj, true, out, over]);
		},

		removeMouseInOut: function(obj)
		{
			var i, list = this.__onmouseinout;
			for (i in list) if (list[i][0] === obj) { list[i] = null; return; }
		},


		__hMouseInOut: function(e)
		{
			e = e || event;
			var i, pos, size, out, list = MEL.event.__onmouseinout;
			for (i in list) if (list[i])
			{
				pos = MEL.dom.getAbsolutePos(list[i][0]);
				size = MEL.dom.getElementSize(list[i][0]);
				out = ((e.clientX < pos.x) || (e.clientY < pos.Y) || (e.clientX > pos.x+size.sw) || (e.clientY > pos.y+size.sh));
				if (out != list[i][1])
				{
					MEL.exec(list[i][(out ? 2 : 3)], list[i][0], e);
					list[i][1] = out;
				}
			}
		},


		cancel: function(e)
		{
			if (e.stopPropagation) e.stopPropagation();
			if (e.preventDefault) e.preventDefault();
			e.cancelBubble = true;
			e.returnValue = false;
			return false;
		}
	}
//

// selection functions
MEL.selection = {

	setSelectedText: function(el, start, end)
	{
		if (el.setSelectionRange)
			el.setSelectionRange(start, end);
		else if (el.createTextRange)
		{
			var rng = el.createTextRange();
			rng.collapse(true);
			rng.moveEnd("character", end);
			rng.moveStart("character", start);
			rng.select();
		}
	},

	
	getStartSelection: function(el)
	{
		if (el.setSelectionRange)
		{
			return el.selectionStart;
		}
		else if (MEL.ds.createRange)
		{
			var rng = MEL.ds.createRange();
			if (rng.parentElement() != el)
				return -1;

			var rng2 = rng.duplicate();
			if (el.tagName == "TEXTAREA")
				rng2.moveToElementText(el)
			else
				rng2.expand("textedit");
			rng2.setEndPoint("EndToStart", rng);
			var pos = rng2.text.length;
			if (MEL.ua.ie && (el.value.substr(pos, 2) == "\r\n")) pos += 2;	// ie bug fix
			if (pos > el.value.length)
				return -1;
			return pos;
		}
		else
			return el.value.length;
	},


	getCaretPosition: function(el)
	{
		return this.getStartSelection(el);
	},


	setCaretPosition: function(el, pos)
	{
		this.setSelectedText(el, pos, pos);
	},


	getEndSelection: function(el)
	{
		if (el.setSelectionRange)
		{
			return el.selectionEnd;
		}
		else if (MEL.ds.createRange)
		{
			var rng = MEL.ds.createRange();
			if (rng.parentElement() != el)
				return -1;

			var rng2 = rng.duplicate();
			if (el.tagName == "TEXTAREA")
				rng2.moveToElementText(el)
			else
				rng2.expand("textedit");

			rng2.setEndPoint("EndToEnd", rng);
			var pos = rng2.text.length;
			if (MEL.ua.ie && (el.value.substr(pos, 2) == "\r\n")) pos += 2;	// ie bug fix
			if (pos > el.value.length)
				return -1;
			return pos;
		}
		else
			return el.value.length;
	},

	getParentElement: function(oWnd)
	{
		var sel, range;
		if (oWnd.getSelection)
			sel = oWnd.getSelection();
		else
			sel = oWnd.document.selection;

		if (sel.getRangeAt)
			range = sel.getRangeAt(0);
		else if (sel.createRange)
			range = sel.createRange();
		else
			range = sel;

		if (sel.type)
		{
			switch (sel.type)
			{
				case "Text":
				case "None":
					return range.parentElement();
				case "Control":
					return range.item(0);
				default:
					return oWnd.document.body;
			}
		}
		else
			try
			{
				var p = range.commonAncestorContainer;
				if (!range.collapsed && range.startContainer == range.endContainer
					&& range.startOffset - range.endOffset <= 1 && range.startContainer.hasChildNodes()
					)
					p = range.startContainer.childNodes[range.startOffset];

				while (p.nodeType == 3)
					p = p.parentNode;
				return p;
			}
			catch (e)
			{
				return null;
			}
	},

	getOpenedTags: function(node)
	{
		var tags = [];
		while (node)
		{
			tags.push(node);
			var node = node.parentNode;
		}
		return tags;
	}

}
//

// date functions
	MEL.date = {

		getFormatted: function(dt, tpl)
		{
			tpl = tpl.replace(/j/, dt.getDate());
			tpl = tpl.replace(/d/, (dt.getDate() < 10 ? "0" : "") + dt.getDate());
			tpl = tpl.replace(/m/, (dt.getMonth() < 9 ? "0" : "") + (dt.getMonth()+1));
			tpl = tpl.replace(/y/, dt.getYear());
			tpl = tpl.replace(/Y/, dt.getFullYear());

			tpl = tpl.replace(/s/, (dt.getSeconds() < 10 ? "0" : "") + dt.getSeconds());
			tpl = tpl.replace(/i/, (dt.getMinutes() < 10 ? "0" : "") + dt.getMinutes());
			tpl = tpl.replace(/H/, (dt.getHours() < 10 ? "0" : "") + dt.getHours());
			return tpl;
		},


		getUTC: function(dt)
		{
			return new Date(dt-dt.getTimezoneOffset()*60000);
		}
	}
//


// timer functions
	MEL.timer = {

		in_use: [],

		__cb: function(i)
		{
			if (MEL.timer.in_use[i][1])
				MEL.timer.in_use[i][1][MEL.timer.in_use[i][2]]();
			else
				MEL.timer.in_use[i][2]();
		},


		setTimer: function(interval, obj, func_name, msec)
		{
			var i = -1; while (this.in_use[++i]);
			var fb = new Function("MEL.timer.__cb(" + i + ")");
			this.in_use[i] = [null, obj, func_name, interval];
			this.in_use[i][0] = ( interval ? window.setInterval(fb, msec) : window.setTimeout(fb, msec) );
			return this.in_use[i][0];
		},


		clearTimer: function(timer)
		{
			for (var i=0; i<this.in_use.length; i++)
				if (this.in_use[i] && (this.in_use[i][0] == timer))
				{
					if (this.in_use[i][3])
						window.clearInterval(timer);
					else
						window.clearTimeout(timer);
					this.in_use[i] = null;
					return;
				}
		},


		setTimeout: function(obj, func_name, msec)
		{
			return this.setTimer(false, obj, func_name, msec);
		},

		setInterval: function(obj, func_name, msec)
		{
			return this.setTimer(true, obj, func_name, msec);
		}
	}
	MEL.timer.clearTimeout = MEL.timer.clearTimer;
	MEL.timer.clearInterval = MEL.timer.clearTimer;
//


// Popup functions
	MEL.popup = {

		cfg: {
			X: false,
			Y: false,
			MOVE2CENTER: true,
			WIDTH: "320px",
			HEIGHT: "200px",
			Z_INDEX: 11000,
			PARENT: null,

			BACKGROUND: "#000",
			OPACITY: 0.5,
			FIXED: true,
			DRAGDROP: true,
			MODAL: true,
			SCROLLING: "auto",

			CLOSE: "X"
		},

		show: function(div, cfg, funcInit, funcParams)
		{
			var i, tmp, url;

			if (cfg && (cfg != null))
			{
				for (i in this.cfg)
					if (typeof cfg[i] == "undefined") cfg[i] = this.cfg[i];
			}
			else
				cfg = this.cfg;
			if (!cfg.PARENT) cfg.PARENT = MEL.d.body;
			if (cfg.FIXED && MEL.ua.ie) cfg.FIXED = false;


			if (div && (typeof div != "object"))
			{
				if (div.search && (div.search(/:\/\//) > 0))
				{
					url = div;
					div = MEL.d.createElement("DIV");
					MEL.dom.setStyle(div, "width:" + cfg.WIDTH + "; background-color:white; border:1px solid gray; padding:3px;");

					tmp = MEL.d.createElement("P");
					MEL.dom.setStyle(tmp, "float:right; font-color:red; font-size:12px; margin:3px; height:12px; cursor:pointer;");
					tmp.appendChild(MEL.d.createTextNode(cfg.CLOSE));
					tmp.onclick = MEL.popup.close;
					div.appendChild(tmp);

					tmp = MEL.d.createElement("IFRAME");
					MEL.dom.setStyle(tmp, "clear:both; width:" + cfg.WIDTH + "; height:" + (parseInt(cfg.HEIGHT)-12) + ";");
					tmp.scrolling = cfg.SCROLLING;
					tmp.frameBorder = "0";
					tmp.src = url;
					div.appendChild(tmp);
				}
				else
					div = MEL.d.getEl(div);
			}
			if (!div) return false;

  			var psize = MEL.dom.getElementSize(cfg.PARENT);
			var pos = MEL.dom.getAbsolutePos(cfg.PARENT);

			if (cfg.MODAL)
			{
				var popup_div = MEL.d.createElement("DIV");
				popup_div.onmousedown = function() { return false; }

				var ss = "z-index:"+cfg.Z_INDEX+"; position:"+(cfg.FIXED ? "fixed" : "absolute")+"; top:" + pos.y + "px; left:" + pos.x + "px; width:" + psize.sw + "px; height:" + psize.sh + "px; background:" + cfg.BACKGROUND + ";";
				MEL.dom.setStyle(popup_div, ss);
				popup_div.className = "popup_div";

				if (cfg.OPACITY < 1)
				{
					if (MEL.ua.ie)
						popup_div.style.filter = "alpha(opacity=" + (cfg.OPACITY*100) + ")";
					else
						popup_div.style.opacity = cfg.OPACITY;
				}

				if (MEL.ua.ie && MEL.ua.ie < 7)
				{
					var sels = MEL.d.getTags("SELECT");
					for (i=0; i<sels.length; i++)
					{
						MEL.dom.appendClass(sels[i], "hide_from_popup");
						sels[i].style.visibility = "hidden";
					}
				}
			}
			else
				var popup_div = false;


			var popup_form = div;
			if (!url)
			{
				if ((popup_form.style.display == "none") && (!div.offsetWidth || !div.offsetHeight))
					throw "popup:\n Source element shouldn't have 'display: none'! Use 'visibility: hidden'.";

				// fix selected in IE
					var tmp = div.getElementsByTagName("SELECT");
					var tmp2 = popup_form.getElementsByTagName("SELECT");
					for (i=0; i<tmp.length; i++) tmp2[i].selectedIndex = tmp[i].selectedIndex;
				//
			}

			if (cfg.DRAGDROP && MEL.dragdrop)
				MEL.dragdrop.init(popup_form);

			if (!popup_form.parentNode || !popup_form.parentNode.tagName)
			{
				if (popup_div)
					MEL.d.body.appendChild(popup_div);
				MEL.d.body.appendChild(popup_form);
			}
			else if (popup_div)
				popup_form.parentNode.insertBefore(popup_div, popup_form);

			var ss = "; visibility:visible; position:"+(cfg.FIXED ? "fixed" : "absolute")+"; z-index:"+cfg.Z_INDEX+";";
			if (cfg.MOVE2CENTER)
			{
				var top = (cfg.Y !== false ? cfg.Y : Math.round((psize.h / 2) - ((div.offsetHeight || parseInt(MEL.dom.getStyle(div, "height"))) / 2) + psize.sy));
				var left = (cfg.X !== false ? cfg.X : Math.round((psize.w / 2) - ((div.offsetWidth || parseInt(MEL.dom.getStyle(div, "width"))) / 2) + psize.sx));
				ss += " top:" + top + "px; left:" + left + "px;"
			}
			MEL.dom.setStyle(popup_form, MEL.dom.getStyle(popup_form) + ss);

			if (typeof funcInit == "function") funcInit(popup_form, funcParams);
			return popup_form;
		},


		hide: function(el)
		{
			if (!el || !el.tagName)
			{
				var e = el || event;
				el = e.target || e.srcElement;
			}
			while (el && el.style.zIndex < 1000) el = el.parentNode;

			if (el.previousSibling && (el.previousSibling.className == "popup_div"))
				el.parentNode.removeChild(el.previousSibling);

			el.style.visibility = "hidden";
			if (MEL.ua.ie && MEL.ua.ie < 7)
			{
				var sels = MEL.d.getTags("SELECT");
				for (i=0; i<sels.length; i++)
					if (MEL.dom.hasClass(sels[i], "hide_from_popup"))
						sels[i].style.visibility = "visible";
			}
		}

	}
	MEL.popup.close = MEL.popup.hide;						// back compatibility
//


// Status bar
	MEL.statusBar = {

		cfg: {
			IMG: "",

			BAR_STYLE: "position:absolute; top:0; right:50px; width:50px; height:13px; overflow:hidden; background-color:yellow; padding:3px; text-align:center; font-size:9px;",
			BAR_CLASS: "status_bar",
			ANIMATE: true
		},
		__hBar: null,
		__hAnimate: null,

		show: function(text, owner)
		{
			if (typeof owner == "undefined") owner = this;
			if (typeof owner.cfg == "undefined") owner.cfg = {};
			if (typeof owner.cfg.ANIMATE == "undefined") owner.cfg.ANIMATE = this.cfg.ANIMATE;

			if (!this.__hBar)
			{
				var bar = MEL.d.createElement("DIV");
				MEL.dom.setStyle(bar, this.cfg.BAR_STYLE);
				MEL.dom.setAttribute(bar, "class", this.cfg.BAR_CLASS);
				if (this.cfg.IMG)
				{
					var img = MEL.d.createElement("IMG");
					MEL.dom.setAttribute(img, "src", this.cfg.IMG);
					bar.appendChild(img);
				}
				else
					bar.appendChild(MEL.d.createTextNode(text || "Loading..."));
			}
			else
				var bar = this.__hBar;

			if (owner.cfg.ANIMATE)
			{
				if (owner.cfg.ANIMATE.tagName)
					MEL.dom.appendClass(owner.cfg.ANIMATE, "active");
				else if (MEL.animation)
				{
					if (!owner.__hAnimate)
					{
						var dot = MEL.d.createElement("DIV");
						MEL.dom.setStyle(dot, "float:left; width:5px; height:2px; background-color:#ff9191; border-left:5px solid #FFE1E1; border-right:5px solid red; margin-right:20px;");
						bar.appendChild(dot);
						MEL.d.body.appendChild(bar);

						var anim = MEL.animation.Create(dot, 0, 50);
						anim.addParam("style.marginLeft", -15, MEL.dom.getStyle(bar, "width"), "3px");
						anim.onFinish = function()
						{
							if (!this.__status)
								this.start();
							else
								this.__status = 0;
						}
						owner.__hAnimate = anim;
					}
					bar.style.visibility = "visible";
					owner.__hAnimate.start();
				}
			}
			this.__hBar = bar;
		},


		hide: function(owner)
		{
			if (typeof owner == "undefined") owner = this;
			if (typeof owner.cfg == "undefined") owner.cfg = {};
			if (typeof owner.cfg.ANIMATE == "undefined") owner.cfg.ANIMATE = this.cfg.ANIMATE;

			if (owner.cfg.ANIMATE.tagName)
				MEL.dom.removeClass(owner.cfg.ANIMATE, "active");
			if (owner.__hAnimate)
				owner.__hAnimate.stop();
			if (this.__hBar)
				this.__hBar.style.visibility = "hidden";
		},


		free: function()
		{
			this.hide();
			this.__hAnimate = null;
			if (this.__hBar)
				this.__hBar.parentNode.removeChild(this.__hBar);
			this.__hBar = null;
		}
	}
//


// Utils
	MEL.exec = function(func, obj, e)
	{
		var t = typeof func;
		if (t == "function") return func(obj, e);
		else if (t == "string") return eval(func);
	}

	MEL.getCopy = function(obj, ignProp, withHTML, replaceKeys)
	{
		var i, ret = obj;
		if (obj && (typeof obj == "object"))
		{
			ret = (obj.pop ? [] : {} );
			for (i in obj)
				if ((!ignProp || (MEL.inArray(i, ignProp) < 0)) && (withHTML || !obj[i] || !obj[i].tagName))
				{
					if (replaceKeys && (typeof replaceKeys == "object") && replaceKeys[i])
						ret[replaceKeys[i]] = MEL.getCopy(obj[i], ignProp, withHTML);
					else
						ret[i] = MEL.getCopy(obj[i], ignProp, withHTML);
				}
		}
		return ret;
	}

	MEL.toArray = function(list)
	{
		var i, arr = [], len = list ? (list.length || 0) : 0;
		for (i=0; i<len; i++) arr.push(list.charAt ? list.charAt(i) : list[i]);
		return arr;
	}
	MEL.to_array = MEL.toArray;		// back compatibility

	MEL.copyElSize = function(el, source)
	{
		var size = MEL.dom.getElementSize(source || el);
		el.style.width = (size.w - parseInt(0+MEL.dom.getStyle(el, "padding-left")) - parseInt(0+MEL.dom.getStyle(el, "padding-right")) - parseInt(0+MEL.dom.getStyle(el, "border-left-width")) - parseInt(0+MEL.dom.getStyle(el, "border-right-width"))) + "px";
		el.style.height = (size.h - parseInt(0+MEL.dom.getStyle(el, "padding-top")) - parseInt(0+MEL.dom.getStyle(el, "padding-bottom")) - parseInt(0+MEL.dom.getStyle(el, "border-top-width")) - parseInt(0+MEL.dom.getStyle(el, "border-bottom-width"))) + "px";
		el.style.padding = MEL.dom.getStyle(el, "padding");
	}
	MEL.setupElSize = MEL.copyElSize;						// back compatibility

	MEL.copyElAttrs = function(el, source)
	{
		for (var i=0; i<source.attributes.length; i++)
			if ((source.attributes[i].value != "") && (source.attributes[i].value != "null"))
				MEL.dom.setAttribute(el, source.attributes[i].name, source.attributes[i].value);
	}

	MEL.findPopupBestPosition = function(btn, popup)
	{
		var pos = MEL.dom.getAbsolutePos(btn);

		btn			= {x:pos.x,	y:pos.y,	width:btn.offsetWidth,		height:btn.offsetHeight};	// + (btn.offsetHeight < 20 ? 10 : 0)
		popup		= {x:btn.x,	y:0,		width:popup.offsetWidth,	height:popup.offsetHeight};
		var pg_size = MEL.dom.getElementSize(MEL.d.body);

		// find X
			if (pg_size.w < (btn.x + popup.width))
				popup.x = pg_size.w - popup.width;
			if (popup.x < 0) popup.x = 0;
		//

		// find Y
			if ((pg_size.h < (btn.y + btn.height + popup.height)) && (pg_size.sy < (btn.y - popup.height)))
				popup.y = btn.y - popup.height;
			else if (((btn.y - popup.height) >= 0) && (pg_size.sh > (btn.y + btn.height + popup.height)))
			{
				if ((pg_size.h < (btn.y + btn.height + popup.height)) && ((btn.y - pg_size.sy) > (pg_size.h + pg_size.sy - btn.y - btn.height)))
					popup.y = btn.y - popup.height;
				else
					popup.y = btn.y + btn.height;
			}
			if (popup.y <= 0) popup.y = btn.y + btn.height;
		//

		return {x:popup.x, y:popup.y, dir:(popup.y<btn.y ? 0 : 2)};
	}

	MEL.setPopupBestPosition = function(btn, popup, type2class)
	{
		var pos = this.findPopupBestPosition(btn, popup);
		popup.style.top	= pos.y + "px";
		popup.style.left= pos.x + "px";

		if (typeof type2class == "undefined") type2class = true;
		if (type2class)
		{
			var cl = popup.className.replace(/ (top|bottom)/i, "");
			cl += (pos.dir == 0 ? " top" : (pos.dir == 2 ? " bottom" : ""));
			MEL.dom.setAttribute(popup, "class", cl);
		}
	}

	MEL.isCursorOverEl = function(e, el)
	{
		var pos = MEL.dom.getAbsolutePos(el);
		var size = MEL.dom.getElementSize(el);

		var sx = e.clientX + MEL.de.scrollLeft;
		var sy = e.clientY + MEL.de.scrollTop;
		var res = ((sx >= pos.x) && (sx < pos.x + size.w) && (sy >= pos.y) && (sy < pos.y + size.h));

		if (res) return {mx:sx, my:sy, ex:pos.x, ey:pos.y, ew:size.w, eh:size.h};
		return false;
	}

	MEL.rgba2arr = function(rgba)
	{
		var i, arr=[], len = rgba.length;
		var piece = (len > 6 ? 2 : 1);
		for (i=0; i<len; i+=piece)
			arr.push(parseInt(rgba.substr(i, piece) + (piece<2 ? rgba.substr(i, piece) : ""), 16));
		return arr;
	}

	MEL.arr2rgba = function(arr)
	{
		var i, rgba = "";
		for (i in arr)
			rgba += (Math.round(arr[i])<16 ? "0" : "") + Math.round(arr[i]).toString(16);
		return rgba;
	}

	MEL.inArray = function(el, arr)
	{
		for (var i in arr) if (arr[i] == el) return i-0;		// convert to number
		return -1;
	}

	MEL.searchSomethingUpTheTree = function(el, func)
	{
		while (el && !func(el)) el = el.parentNode;
		if (el && func(el)) return el;
		return false;
	}

	MEL.searchAttrUpTheTree = function(el, attr, value)
	{
		while (el && (el[attr] != value)) el = el.parentNode;
		if (el && (el[attr] == value))
			return el;
		return false;
	}

	MEL.searchClassUpTheTree = function(el, clName)
	{
		while (el && !MEL.dom.hasClass(el, clName)) el = el.parentNode;
		if (el && MEL.dom.hasClass(el, clName))
			return el;
		return false;
	}

	MEL.searchFirstTag = function(box, tags)
	{
		var els;
		if (typeof tags == "string")
		{
			els = box.getElementsByTagName(tags);
			return els.length ? els[0] : false;
		}

		els = box.childNodes;
		var res, i, cnt = els.length;
		for (i=0; i<cnt; i++)
			if (els[i].tagName)
			{
				if (MEL.inArray(els[i].tagName, tags) >= 0)
					return els[i];
				else
				{
					res = MEL.searchFirstTag(els[i], tags);
					if (res) return res;
				}
			}
		return false;
	}

	MEL.searchAllTags = function(box, tags)
	{
		var els, res = [];
		if (typeof tags == "string")
			return MEL.toArray(box.getElementsByTagName(tags));

		els = box.childNodes;
		var i, cnt = els.length;
		for (i=0; i<cnt; i++)
			if (els[i].tagName)
			{
				if (MEL.inArray(els[i].tagName, tags) >= 0)
					res.push(els[i]);
				else
					res = res.concat(MEL.searchAllTags(els[i], tags));
			}
		return res;
	}


	MEL.selects_status = true;
	MEL.switchSelects = function()
	{
		MEL.selects_status = !MEL.selects_status;
		var i, els = MEL.d.getTags("SELECT");
		for (i=0; i<els.length; i++)
		{
			if (MEL.selects_status)
			{
				if (MEL.dom.hasClass(els[i], "tmpHide"))
				{
					MEL.dom.removeClass(els[i], "tmpHide");
					els[i].style.visibility = "visible";
				}
			}
			else if (els[i].style.visibility != "hidden")
			{
				MEL.dom.appendClass(els[i], "tmpHide");
				els[i].style.visibility = "hidden";
			}
		}
	}


	MEL.joinObjects = function(trg, src)
	{
		for (var i in src)
			if (typeof trg[i] == "undefined")
				trg[i] = src[i];
	}


	MEL.removeAttrs = function(el, attrs, recur)
	{
		if (!attrs.join) attrs = [attrs];
		var i, cnt = attrs.length;
		for (i=0; i<cnt; i++)
			if (typeof el[attrs[i]] != "undefined")
				el[attrs[i]] = null;
		if (recur && el.childNodes)
		{
			cnt = el.childNodes.length;
			for (i=0; i<cnt; i++)
				arguments.callee(el.childNodes[i], attrs, true);
		}
	}


	MEL.swapElements = function(el1, el2)
	{
		// el2 -> before el1 (don't need it, if el2 already before el1)
		// el1 -> before el2_before
		var el1_box = el1.parentNode;
		var el2_box = el2.parentNode;
		var el2_before = el2.nextSibling;
		if (el2_before != el1)
			el1_box.insertBefore(el2_box.removeChild(el2), el1);
		else
			el2_before = el2;

		el1 = el1_box.removeChild(el1);
		if (el2_before)
			el2_box.insertBefore(el1, el2_before);
		else
			el2_box.appendChild(el1);
	}


	MEL.moveColumnBefore = function(col1, col2, tbl)
	{
		if ((typeof col1 == "number") && !tbl) return;
		if (!tbl) tbl = MEL.searchAttrUpTheTree(col1, "tagName", "TABLE");
		if (typeof col1 != "number") col1 = col1.cellIndex;
		if (col2 && typeof col2 != "number") col2 = col2.cellIndex;
		if (col2 > col1) col2--;

		var rows = tbl.rows;
		var row, cell;
		var i, cnt = rows.length;
		for (i=0; i<cnt; i++) if (rows[i].cells.length >= col1)
		{
			row = rows[i];
			cell = row.cells[col1];

			if (col2 < 0)
				row.appendChild( row.removeChild(cell) );
			else
				row.insertBefore( row.removeChild(cell), row.cells[col2] );
		}
	}
//
/**
* Filename................: mel.xhr.js
* Project.................: web pages SDK
* Last Modified...........: $Date: 12/3/2008 12:18:06 $
* CVS Revision............: $Revision: 0.0.6 $
* Idea and Developed by...: Maxim Bulygin (sailormax@gmail.com)
*/

if (typeof MEL == "undefined") var MEL = {};

MEL.xhr = {

	cfg: {
		STATUS_MSG: "Loading...",
		NOTFOUND_MSG: "URL doesn't exist!",
		CACHE: false
	},
	CACHE: {},
	__sending: [],
	__lastId: 0,

	createXHR: function()
	{
		var res = null;
		if (typeof XMLHttpRequest == "undefined")
		{
			var i, objs = ["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"];
			for (i in objs)
				try { if (res = new ActiveXObject(objs[i])) break; } catch (e) {}
		}
		else
			res = new XMLHttpRequest();

		return res;
	},


	__sendXHR: function()
	{
		if (this.cfg.CACHE)
		{
			var cached = MEL.xhr.CACHE[this.url + "\t" + this.method + "\t" + this.vars];
			if (cached)
			{
				if (typeof this.resp_func == "function")
					this.resp_func(cached, this.resp_param);
				return cached;
			}
		}

		if (this.request)
		{
			var curr = [this.id, this.url, this.method, this.vars];
			for (var i in MEL.xhr.__sending)
				if (MEL.xhr.__sending[i]+"" == curr+"")
					return this.request;
			MEL.xhr.__sending.push(curr);

			var self = this;
			this.request.onreadystatechange = function()
			{
				//	self.request.readyState: 0 = uninitialized, 1 = loading, 2 = loaded, 3 = interactive, 4 = complete
				if (self.request.readyState == 4)
				{
					if (MEL.statusBar)
					{
//						console.log("--", self.cfg.ANIMATE);
						MEL.statusBar.hide(self);
					}

					for (var i in MEL.xhr.__sending)
						if (MEL.xhr.__sending[i]+"" == curr+"")
						{
							MEL.xhr.__sending.splice(i, 1);
							break;
						}

					if (self.request.status == 200)
					{
						if (self.cfg.CACHE)
							MEL.xhr.CACHE[curr[1] + "\t" + curr[2] + "\t" + curr[3]] = self.request.responseText;
						if (typeof self.resp_func == "function")
							self.resp_func(self.request.responseText, self.resp_param);
						self.request.abort();
					}
					else if (typeof self.error_func == "function")
						self.error_func(self.request.status, self.request.statusText);
					else if (console && console.log)
					{
						if (self.request.status == 404)
							console.log("Error: " + self.cfg.NOTFOUND_MSG);
						else
							console.log("Error: " + self.request.statusText);
					}
				}
			};

			if (this.method.toLowerCase() == "get")
			{
				if ((typeof this.vars != "undefined") && this.vars.length)
					this.url += (this.url.search(/\?/) > 0 ? "&amp;" : "?") + this.vars;
				this.vars = null;
			}

			this.request.open(this.method, this.url, this.async);

			if (this.method.toLowerCase() == "post")
				this.request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

//			new browsers don't need this...
//			this.request.setRequestHeader("Content-length", (typeof this.vars == "string" ? this.vars.length : 0));
//			this.request.setRequestHeader("Connection", "close");	// Slowdown IE6

			try
			{
				if (this.cfg.STATUS_MSG && MEL.statusBar)
					MEL.statusBar.show(this.cfg.STATUS_MSG, self);
				this.request.send(this.vars);
			}
			catch (e)
			{
				if (typeof this.error_func == "function")
					this.error_func(e.name, e.message);
				else if (console && console.log)
					console.log(e.name + ": " + e.message);
			}
			return 0;
		}
		return this.request;
	},


	Create: function(url, method, vars, resp_func, error_func)
	{
		if (typeof method == "undefined") method = "GET";
		var obj = {};

		obj.id			= ++this.__lastId;
		obj.cfg			= MEL.getCopy(this.cfg);

		obj.url			= url;
		obj.resp_func	= resp_func;
		obj.error_func	= error_func;

		obj.async		= true;
		obj.method		= method;
		obj.vars		= vars;
		obj.resp_param	= null;

		obj.request		= this.createXHR();
		obj.send		= this.__sendXHR;

		return obj;
	}

}/**
* Filename................: mel.animation.js
* Project.................: web pages SDK
* Last Modified...........: $Date: 15/6/2009 17:48:45 $
* CVS Revision............: $Revision: 0.0.18 $
* Idea and Developed by...: Maxim Bulygin (sailormax@gmail.com)
*/

if (typeof MEL == "undefined") var MEL = {};

MEL.animation = {

	in_use: [],
	cfg: {
		TIME: 150,
		DELAY: 15,
		PARAMS: []
	},

	__addParam: function()	// [obj], name, from, till, step, counter
	{
		var i, piece_step, args = MEL.to_array(arguments);
		var obj = (typeof args[0] == "object" ? args.shift() : this.obj);
		var name = args[0],
			from = args[1],
			till = args[2],
			step = args[3] || "1px",
			counter = args[4],
			cps = MEL.to_array(args[5]);
		var params = this.cfg.PARAMS;
		if (!from.match && isNaN(from)) return;

		var prefix = "", postfix = "";
		if (from.match)
		{
			if (from.match(/^#(.+)$/))
			{
				from = MEL.rgba2arr(RegExp.$1);
				if (till.match && till.match(/^#(.+)$/)) till = RegExp.$1;
				till = MEL.rgba2arr(till);

				for (i in from)
					this.addParam(obj, (i=="0"?"+":""), from[i], till[i], step, counter, cps);
				params.push({obj:obj, name:name, from:0, cur:0, till:0, step:0, counter:null, cps:null, prefix:"#", postfix:""});
				return this;
			}
			else if (from.match(/^([a-z]+\()([^\)]+)\)$/i))
			{
				prefix = RegExp.$1;
				from = RegExp.$2.split(/[, ]+/);
				if (till.match && (till.match(/^[a-z]+\(([^\)]+)\)$/i))) till = RegExp.$1;
				till = till.split(/[, ]+/);

				for (i in from)
					this.addParam(obj, (i=="0"?"+":""), from[i], till[i], step, counter, cps);
				params.push({obj:obj, name:name, from:0, cur:0, till:0, step:0, counter:null, cps:null, prefix:prefix, postfix:")"});
				return this;
			}
		}

		var re = new RegExp("^(-?[0-9]+)([a-z%]+)$", "i");
		if (step.match && step.match(re)) {	step = RegExp.$1; postfix = RegExp.$2; }
		step -= 0;
		if (from.match && from.match(re)) { from = RegExp.$1; postfix = RegExp.$2; }
		from -= 0;
		if (till.match && till.match(re)) { till = RegExp.$1; postfix = RegExp.$2; }
		till -= 0;

		if (((from < till) && (step < 0)) || (from > till) && (step > 0)) step *= -1;
		if (typeof counter != "function")
		{
			if (!cps.length && counter && counter.pop) cps = counter;
			counter = MEL.animation.__counter;
		}
		params.push({obj:obj, name:name, from:from, cur:from, till:till, step:step, counter:counter, cps:cps, prefix:"", postfix:postfix});
		return this;
	},

	__clearParams: function()
	{
		this.cfg.PARAMS = [];
		this.scenes = [this.cfg];
	},

	__recognizeArgs: function(args)
	{
		if (typeof args[0] == "object")
			this.obj = args.shift();

		if (isNaN(this.__idx))
			animate = this.Create(this.obj);
		else
			animate = this;

		return animate;
	},

	animateOpacity: function()	// [obj], from, to, step
	{
		var args = MEL.to_array(arguments);
		var animate = this.__recognizeArgs(args);
		var obj = this.obj;

		var from = args[0];	if (isNaN(from)) from = 0;
		var to = args[1];	if (isNaN(to)) to = 1;
		var step = args[2];	if (isNaN(step)) step = 0.1;
		if ((from > 1) || (to > 1))
		{
			from /= 100;
			to /= 100;
			step /= 100;
		}

		if (MEL.ua.ie)
			animate.addParam(obj, "filters.alpha.opacity", from*100, to*100, step*100);
		else
			animate.addParam(obj, "style.opacity", from, to, step);
		return animate;
	},

	animateSize: function()	// [obj], w_from, h_from, w_to, h_to, step
	{
		var params, i, from, to, step, sh = 0;
		var args = MEL.to_array(arguments);
		var animate = this.__recognizeArgs(args);
		var obj = this.obj;

		step = args[4] || "5px";
		params = ["width", "height"];
		for (i in params)
		{
			i-=0;
			from = args[0+sh];
			to = args[2+sh];

			if (from != to)
			{
				if (isNaN(from)) from = (i ? obj.scrollHeight : obj.scrollWidth);
				if (isNaN(to)) to = (i ? obj.scrollHeight : obj.scrollWidth);
				animate.addParam(obj, "style." + params[i], from, to, step);
			}
			sh++;
		}
		return animate;
	},

	animatePosition: function()	// [obj], x_from, y_from, x_to, y_to, step, x_cps, y_cps
	{
		var params, i, from, to, step, sh = 0;
		var args = MEL.to_array(arguments);
		var animate = this.__recognizeArgs(args);
		var obj = this.obj;

		step = args[4] || "5px";
		if (MEL.dom.getStyle(obj, "position") == "absolute")
			params = ["left", "top"];
		else
			params = ["marginLeft", "marginTop"];

		for (i in params)
		{
			from = args[0+sh];
			to = args[2+sh];

			if (isNaN(from)) from = MEL.dom.getStyle(obj, params[i]);
			if (isNaN(to)) to = MEL.dom.getStyle(obj, params[i]);

			if ((from != to) || args[5+sh])
				animate.addParam(obj, "style." + params[i], from, to, step, args[5+sh]);
			sh++;
		}
		return animate;
	},


	__newScene: function()
	{
		if (this.cfg.PARAMS.length)
		{
			this.cfg = { TIME: this.cfg.TIME, DELAY: this.cfg.DELAY, PARAMS: [] };
			this.scenes.push(this.cfg);
		}
	},

	__reverse: function()
	{
		var i, j, tmp, params, scenes = this.scenes;
		for (i in scenes)
		{
			params = scenes[i].PARAMS;
			for (j in params)
			{
				tmp = params[j].from;
				params[j].from = params[j].till;
				params[j].till = tmp;
			}
		}
		this.scenes = scenes.reverse();
	},

	__start: function()
	{
		var i, j, steps, attr, val_el, vals, max_steps = 0;
		if (this.__status > 0) this.stop();
//		if (!this.__scene_idx && this.cfg.PARAMS.length) this.newScene();
		this.cfg = this.scenes[this.__scene_idx++];
		if (!this.cfg)
		{
			this.__scene_idx = 0;
			this.cfg = { TIME: 150, DELAY: 15, PARAMS: [] };
			if (this.onFinish) this.onFinish();
			return;
		}
		if (this.onStart) this.onStart();
		var params = this.cfg.PARAMS;
		this.__start_time = new Date()-0;
		var prev_name = "-";

		for (i=0; i<params.length; i++)
		{
			attr = params[i];
			attr.cur = attr.from;
			steps = (attr.step ? Math.abs((attr.till - attr.cur) / attr.step) : 0);
			attr.next_step = 0;
			attr.left_steps = Math.floor(steps) || -1;
			if (steps > max_steps) max_steps = steps;
		}
		this.__max_steps = this.__elapsed = Math.round(max_steps);
		this.__interval = (this.cfg.TIME ? Math.round(this.cfg.TIME / max_steps) : this.cfg.DELAY);

		this.__status = 1;
		this.__step(true);
	},

	__stop: function()
	{
		MEL.timer.clearTimeout(this.__timer);
		this.__timer = null;
		this.__status = -1;
		this.__scene_idx = 0;

		var params = this.cfg.PARAMS;
		for (i=0; i<params.length; i++)
			params[i].cur = params[i].from;
		if (this.onFinish) this.onFinish();
	},

	__counter: function(prms, t)
	{
		if (prms.cps.length)
		{
			if (prms.cps.length > 1)
				prms.cur = Math.pow(1-t, 3)*prms.from + 3*t*Math.pow(1-t, 2)*prms.cps[0] + 3*Math.pow(t,2)*(1-t)*prms.cps[1] + Math.pow(t, 3)*prms.till;
			else
				prms.cur = Math.pow(1-t, 2)*prms.from + 2*t*(1-t)*prms.cps[0] + Math.pow(t, 2)*prms.till;
		}
		else
			prms.cur = (1-t)*prms.from + t*prms.till;
	},


	__step: function(first)
	{
		if (this.onStep) this.onStep();

		var i, j, attr, left_steps = 0;
		var val_el, vals, updated = 0;
		var prev_name = "-";
		var params = this.cfg.PARAMS;
		var finish = Math.ceil(--this.__elapsed) < 1;
		var ela = this.__elapsed;
		var now = new Date()-0;
		var t, time = this.cfg.TIME;
		if (time)
			t = (now - this.__start_time) / time;
		else
			t = (this.__max_steps - ela) / this.__max_steps;
		if (t >= 1) finish = t = 1;

		for (i=0; i<params.length; i++)
		{
			attr = params[i];
			if (time || (attr.left_steps && ((attr.next_step >= ela) || first)))
			{
				if (!first && attr.counter) attr.counter(attr, t);
				if (attr.name && (attr.name != "+") && prev_name && (prev_name != "+"))
					MEL.dom.setAttribute(attr.obj, attr.name, attr.prefix + (finish ? attr.till : attr.cur) + attr.postfix);

				if (!time) attr.left_steps--;
				updated++;

				if (!time && ((attr.left_steps > 0) || ela))
					attr.next_step = ela - (ela / (attr.left_steps > 0 ? attr.left_steps : ela));
			}

			if (updated && i && attr.name && (attr.name != "+") && (!prev_name || prev_name == "+"))
			{
				vals = [];
				j = i;
				if (val_el = params[--j])
				do { vals.push(val_el.prefix + (finish ? val_el.till : val_el.cur) + val_el.postfix) } while ((val_el.name != "+") && (val_el = params[--j]));
				MEL.dom.setAttribute(attr.obj, attr.name, attr.prefix + (attr.prefix=="#" ? MEL.arr2rgba(vals.reverse()) : vals.reverse().join(", ")) + attr.postfix);
				updated = 0;
			}

			if (attr.left_steps) left_steps++;
			prev_name = attr.name;
		}

		finish = finish || !left_steps || !this.__status;
		if (finish)
		{
			MEL.timer.clearTimer(this.__timer);
			this.__timer = null;

			if (this.__status > 0)
			{
				this.__status = 0;
				this.start();
			}
			else
				if (this.onFinish) this.onFinish();
		}
		else if (!this.__timer)
			this.__timer = MEL.timer.setInterval(this, "__step", this.__interval+1);	// IE interval = 0 bug
	},


	Create: function(obj, time, delay)
	{
		var anim = {};

		if (typeof obj == "string") obj = MEL.d.getEl(obj);
		anim.obj = obj;
		anim.cfg = MEL.getCopy(this.cfg);

		if (typeof time != "undefined") anim.cfg.TIME = time;
		if (typeof delay != "undefined") anim.cfg.DELAY = delay;

		anim.scenes = [anim.cfg];
		anim.__recognizeArgs = this.__recognizeArgs;

		var i;
		var h_func = ["stop", "start", "addParam", "clearParams", "reverse", "newScene"];
		var p_func = ["animateOpacity", "animateSize", "animatePosition"];
		var p_null = ["event_args", "onStart", "onStep", "onFinish"];
		for (i in h_func) anim[h_func[i]] = this["__"+h_func[i]];
		for (i in p_func) anim[p_func[i]] = this[p_func[i]];
		for (i in p_null) anim[p_null[i]] = null;

		anim.__step = this.__step;

		var h_zero = ["__interval", "__max_steps", "__elapsed", "__timer", "__start_time", "__scene_idx", "__status"];
		for (i in h_zero) anim[h_zero[i]] = 0;

		anim.__idx = MEL.animation.in_use.length;
		MEL.animation.in_use.push(anim);

		return anim;
	}
}
function ShowAuthForm()
{
	if (!MEL.d.getEl("user.auth.login")) return false;

	var head = MEL.d.getEl("pgHeader");
	var marginTop = head.style.marginTop;
	if ((marginTop == "") || (marginTop == "-117px"))
	{
		var anim = MEL.animation.Create(head).addParam("style.marginTop", -117, 0, "1px");
		anim.onFinish = function()
		{
			MEL.url.appendAnchor("auth");
		}
		anim.start();
		MEL.d.getEl("user.auth.login").focus();
	}
}

function HideAuthForm()
{
	if (!MEL.d.getEl("user.auth.login")) return false;

	var anim = MEL.animation.Create(MEL.d.getEl("pgHeader")).addParam("style.marginTop", 0, -117, "-1px");
	anim.onFinish = function()
	{
		MEL.url.removeAnchor("auth");
	}
	anim.start();
	MEL.d.getEl("user.auth.pass").value = "";
}


function regShowFizForm()
{
	if (!MEL.dom.hasClass(MEL.d.getEl("ctrlFizForm"), "active"))
	{
		MEL.dom.removeClass(MEL.d.getEl("ctrlJurForm"), "active");
		var anim = MEL.animation.Create();
		anim.animateOpacity(MEL.d.getEl("jurForm"), 100, 0);
		anim.onFinish = function()
		{
			MEL.d.getEl("jurForm").style.display = "none";
			MEL.d.getEl("fizForm").style.display = "block";

			MEL.dom.appendClass(MEL.d.getEl("ctrlFizForm"), "active");
			this.clearParams();
			this.animateOpacity(MEL.d.getEl("fizForm"), 0, 100);
			this.onFinish = function() { };
			this.start();
		}
		anim.start();
	}
}

function regShowJurForm()
{
	if (!MEL.dom.hasClass(MEL.d.getEl("ctrlJurForm"), "active"))
	{
		MEL.dom.removeClass(MEL.d.getEl("ctrlFizForm"), "active");
		var anim = MEL.animation.Create();
		anim.animateOpacity(MEL.d.getEl("fizForm"), 100, 0);
		anim.onFinish = function()
		{
			MEL.d.getEl("fizForm").style.display = "none";
			MEL.d.getEl("jurForm").style.display = "block";

			MEL.dom.appendClass(MEL.d.getEl("ctrlJurForm"), "active");
			this.clearParams();
			this.animateOpacity(MEL.d.getEl("jurForm"), 0, 100);
			this.onFinish = function() { };
			this.start();
		}
		anim.start();
	}
}

function showLinksOf(el, name)
{
	var divs = MEL.d.getTags("DIV");
	var re = new RegExp("relSubtab_([^ \t]*)", "i");
	var i, cnt = divs.length;
	for (i=0; i<cnt; i++)
	{
		if ((arr = re.exec(divs[i].className)) != null)
			divs[i].style.display = (arr[1] == name ? "block" : "none");
	}

	var tab = MEL.searchClassUpTheTree(el, "item");
	divs = tab.parentNode.childNodes;
	cnt = divs.length
	for (i=0; i<cnt; i++)
		if (MEL.dom.hasClass(divs[i], "item"))
		{
			if (divs[i] == tab)
				MEL.dom.appendClass(divs[i], "active");
			else
				MEL.dom.removeClass(divs[i], "active");
		}
}

function MoveVisualFocus(elFrom, elTo, blink_cnt)
{
	if (!elFrom.tagName) elFrom = MEL.d.getEl(elFrom);
	if (!elTo.tagName) elTo = MEL.d.getEl(elTo);
	if (typeof blink_cnt == "undefined") blink_cnt = 1;

	var elFrom_size = MEL.dom.getElementSize(elFrom);
	var elFrom_pos = MEL.dom.getAbsolutePos(elFrom);

	var div = MEL.d.createElement("DIV");
	div.className = "highight_border";
	MEL.dom.setStyle(div, "position:absolute; width:"+elFrom_size.w+"px; height:"+elFrom_size.h+"px; left:"+elFrom_pos.x+"px; top:"+elFrom_pos.y+"px");
	MEL.d.body.appendChild(div);

	var elTo_size = MEL.dom.getElementSize(elTo);
	var elTo_pos = MEL.dom.getAbsolutePos(elTo);

	var anim = MEL.animation.Create(div);
	anim.cfg.TIME = 300;
	var leftShift = MEL.dom.getStyle(elTo, "padding-left").replace("px", "")-0;
	anim.animateSize("auto", "auto", elTo_size.w - leftShift + 20, elTo_size.h + 20);
	anim.animatePosition("auto", "auto", elTo_pos.x + leftShift - 10, elTo_pos.y - 10);

	for (var i=0; i<blink_cnt; i++)
	{
		anim.newScene();
		anim.animateOpacity(100, 0);
		anim.newScene();
		anim.animateOpacity(0, 100);
	}
	anim.newScene();
	anim.animateOpacity(100, 0);
	anim.onFinish = function() { MEL.d.body.removeChild(div); };
	anim.start();
}

function SwitchActiveRadio(el, chDependences)
{
	var inp, dep, els = el.parentNode.childNodes;
	var i, cnt = els.length;
	for (i=0; i<cnt; i++)
		if (els[i].tagName == "LABEL")
		{
			inp = els[i].getElementsByTagName("INPUT")[0];
			if (els[i] == el)
			{
				MEL.dom.appendClass(els[i], "active");
				inp.checked = true;
			}
			else
				MEL.dom.removeClass(els[i], "active");
		}


	var publicResInps = MEL.d.getEls("form.publicres");
	var respUniqInps = MEL.d.getEls("form.respuniqtype");
	if (respUniqInps.length)
	{
		var publicRes, respUniq;
		for (i=0; i<publicResInps.length; i++) if (publicResInps[i].checked) publicRes = publicResInps[i].value;
		for (i=0; i<respUniqInps.length; i++) if (respUniqInps[i].checked) respUniq = respUniqInps[i].value;

		dep = MEL.d.getEl("cfgForm4anyone");
		if ((publicRes != "0") && (respUniq == "1"))
		{
			MEL.dom.removeClass(dep, "disabled");
			dep.getElementsByTagName("INPUT")[0].disabled = false;
		}
		else
		{
			MEL.dom.appendClass(dep, "disabled");
			dep.getElementsByTagName("INPUT")[0].disabled = true;
		}
	}
	else if (chDependences)
	{
		var publicRes;
		for (i=0; i<publicResInps.length; i++) if (publicResInps[i].checked) publicRes = publicResInps[i].value;

		dep = MEL.d.getEl("cfgForm4anyone");
		if (publicRes == "0")
		{
			MEL.dom.appendClass(dep, "disabled");
			dep.getElementsByTagName("INPUT")[0].disabled = true;
		}
		else
		{
			MEL.dom.removeClass(dep, "disabled");
			dep.getElementsByTagName("INPUT")[0].disabled = false;
		}
	}
}


function ShowHidePublicSettings(link)
{
	var p = link.parentNode;
	var publSet = MEL.d.getEl("publicSettings");
	var publSetHeight = 176;
	if (MEL.dom.hasClass(p, "closed"))
	{
		MEL.dom.removeClass(p, "closed");
		MEL.dom.appendClass(p, "opened");
		var anim = MEL.animation.Create(p).addParam("style.marginBottom", 0, publSetHeight, "1px");
		anim.onFinish = function()
		{
			p.style.marginBottom = "0";
			MEL.dom.removeClass(publSet, "hide");
			MEL.d.getEls("with_public_settings")[0].value = 1;
		}
		anim.start();
	}
	else
	{
		MEL.dom.removeClass(p, "opened");
		MEL.dom.appendClass(p, "closed");
		MEL.dom.appendClass(publSet, "hide");
		MEL.d.getEls("with_public_settings")[0].value = 0;
		MEL.animation.Create(p).addParam("style.marginBottom", publSetHeight, 0, "1px").start();
	}
}

function inlineEditPubPass()
{
	MEL.d.getEl("publicFormPass").readOnly = false;
	MEL.d.getEl("publicFormPass").focus();
	MEL.d.getEl("link2changePass").style.display = "none";
	MEL.d.getEl("btn2changePass").style.visibility = "visible";
}

function ChangeFormTab(el)
{
	if ((typeof formWasModified == "boolean") && formWasModified && WORDS && !confirm(WORDS.form_was_modified))
	{
		return false;
	}
	return true;
}


function CheckAnchors()
{
	if (MEL.d.location.href.search(/#.+?/) > 0)
	{
		if (MEL.inArray("auth", MEL.url.getAnchors()) >= 0)
		{
			if (MEL.dom.getStyle(MEL.d.getEl("pgHeader"), "margin-top") != "0px")
			{
				if (MEL.d.getEl("pgHeader").style.marginTop != "0px") ShowAuthForm();
			}
		}
		else
			if (MEL.d.getEl("pgHeader").style.marginTop == "0px") HideAuthForm();
	}
	else
	{
		if (MEL.d.getEl("pgHeader").style.marginTop == "0px") HideAuthForm();
	}
}

MEL.event.addListener(MEL.w, "load", function()
{
	MEL.timer.setInterval(null, CheckAnchors, 100);
//	MEL.d.getTags("BUTTON")[12].tagName = "zzz";
});

/*
MEL.event.addListener(MEL.w, "error", function(sMsg, sUrl, sLine)
{
	console.log(sMsg);
	alert(sMsg + "1\n" + sUrl + "\n" + sLine);
	return false;
});
*/
/*
 * A JavaScript implementation of the Secure Hash Algorithm, SHA-512, as defined
 * in FIPS 180-2
 * Version 2.2 Copyright Anonymous Contributor, Paul Johnston 2000 - 2009.
 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
 * Distributed under the BSD License
 * See http://pajhome.org.uk/crypt/md5 for details.
 */
var hexcase=0;function hex_sha512(a){return rstr2hex(rstr_sha512(str2rstr_utf8(a)))}function hex_hmac_sha512(a,b){return rstr2hex(rstr_hmac_sha512(str2rstr_utf8(a),str2rstr_utf8(b)))}function sha512_vm_test(){return hex_sha512("abc").toLowerCase()=="ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f"}function rstr_sha512(a){return binb2rstr(binb_sha512(rstr2binb(a),a.length*8))}function rstr_hmac_sha512(c,f){var e=rstr2binb(c);if(e.length>32){e=binb_sha512(e,c.length*8)}var a=Array(32),d=Array(32);for(var b=0;b<32;b++){a[b]=e[b]^909522486;d[b]=e[b]^1549556828}var g=binb_sha512(a.concat(rstr2binb(f)),1024+f.length*8);return binb2rstr(binb_sha512(d.concat(g),1024+512))}function rstr2hex(c){try{hexcase}catch(g){hexcase=0}var f=hexcase?"0123456789ABCDEF":"0123456789abcdef";var b="";var a;for(var d=0;d<c.length;d++){a=c.charCodeAt(d);b+=f.charAt((a>>>4)&15)+f.charAt(a&15)}return b}function str2rstr_utf8(c){var b="";var d=-1;var a,e;while(++d<c.length){a=c.charCodeAt(d);e=d+1<c.length?c.charCodeAt(d+1):0;if(55296<=a&&a<=56319&&56320<=e&&e<=57343){a=65536+((a&1023)<<10)+(e&1023);d++}if(a<=127){b+=String.fromCharCode(a)}else{if(a<=2047){b+=String.fromCharCode(192|((a>>>6)&31),128|(a&63))}else{if(a<=65535){b+=String.fromCharCode(224|((a>>>12)&15),128|((a>>>6)&63),128|(a&63))}else{if(a<=2097151){b+=String.fromCharCode(240|((a>>>18)&7),128|((a>>>12)&63),128|((a>>>6)&63),128|(a&63))}}}}}return b}function rstr2binb(b){var a=Array(b.length>>2);for(var c=0;c<a.length;c++){a[c]=0}for(var c=0;c<b.length*8;c+=8){a[c>>5]|=(b.charCodeAt(c/8)&255)<<(24-c%32)}return a}function binb2rstr(b){var a="";for(var c=0;c<b.length*32;c+=8){a+=String.fromCharCode((b[c>>5]>>>(24-c%32))&255)}return a}var sha512_k;function binb_sha512(p,A){if(sha512_k==undefined){sha512_k=new Array(new int64(1116352408,-685199838),new int64(1899447441,602891725),new int64(-1245643825,-330482897),new int64(-373957723,-2121671748),new int64(961987163,-213338824),new int64(1508970993,-1241133031),new int64(-1841331548,-1357295717),new int64(-1424204075,-630357736),new int64(-670586216,-1560083902),new int64(310598401,1164996542),new int64(607225278,1323610764),new int64(1426881987,-704662302),new int64(1925078388,-226784913),new int64(-2132889090,991336113),new int64(-1680079193,633803317),new int64(-1046744716,-815192428),new int64(-459576895,-1628353838),new int64(-272742522,944711139),new int64(264347078,-1953704523),new int64(604807628,2007800933),new int64(770255983,1495990901),new int64(1249150122,1856431235),new int64(1555081692,-1119749164),new int64(1996064986,-2096016459),new int64(-1740746414,-295247957),new int64(-1473132947,766784016),new int64(-1341970488,-1728372417),new int64(-1084653625,-1091629340),new int64(-958395405,1034457026),new int64(-710438585,-1828018395),new int64(113926993,-536640913),new int64(338241895,168717936),new int64(666307205,1188179964),new int64(773529912,1546045734),new int64(1294757372,1522805485),new int64(1396182291,-1651133473),new int64(1695183700,-1951439906),new int64(1986661051,1014477480),new int64(-2117940946,1206759142),new int64(-1838011259,344077627),new int64(-1564481375,1290863460),new int64(-1474664885,-1136513023),new int64(-1035236496,-789014639),new int64(-949202525,106217008),new int64(-778901479,-688958952),new int64(-694614492,1432725776),new int64(-200395387,1467031594),new int64(275423344,851169720),new int64(430227734,-1194143544),new int64(506948616,1363258195),new int64(659060556,-544281703),new int64(883997877,-509917016),new int64(958139571,-976659869),new int64(1322822218,-482243893),new int64(1537002063,2003034995),new int64(1747873779,-692930397),new int64(1955562222,1575990012),new int64(2024104815,1125592928),new int64(-2067236844,-1578062990),new int64(-1933114872,442776044),new int64(-1866530822,593698344),new int64(-1538233109,-561857047),new int64(-1090935817,-1295615723),new int64(-965641998,-479046869),new int64(-903397682,-366583396),new int64(-779700025,566280711),new int64(-354779690,-840897762),new int64(-176337025,-294727304),new int64(116418474,1914138554),new int64(174292421,-1563912026),new int64(289380356,-1090974290),new int64(460393269,320620315),new int64(685471733,587496836),new int64(852142971,1086792851),new int64(1017036298,365543100),new int64(1126000580,-1676669620),new int64(1288033470,-885112138),new int64(1501505948,-60457430),new int64(1607167915,987167468),new int64(1816402316,1246189591))}var q=new Array(new int64(1779033703,-205731576),new int64(-1150833019,-2067093701),new int64(1013904242,-23791573),new int64(-1521486534,1595750129),new int64(1359893119,-1377402159),new int64(-1694144372,725511199),new int64(528734635,-79577749),new int64(1541459225,327033209));var s=new int64(0,0),r=new int64(0,0),J=new int64(0,0),I=new int64(0,0),G=new int64(0,0),F=new int64(0,0),E=new int64(0,0),D=new int64(0,0),C=new int64(0,0),B=new int64(0,0),m=new int64(0,0),l=new int64(0,0),t=new int64(0,0),o=new int64(0,0),z=new int64(0,0),w=new int64(0,0),u=new int64(0,0);var v,y;var n=new Array(80);for(y=0;y<80;y++){n[y]=new int64(0,0)}p[A>>5]|=128<<(24-(A&31));p[((A+128>>10)<<5)+31]=A;for(y=0;y<p.length;y+=32){int64copy(J,q[0]);int64copy(I,q[1]);int64copy(G,q[2]);int64copy(F,q[3]);int64copy(E,q[4]);int64copy(D,q[5]);int64copy(C,q[6]);int64copy(B,q[7]);for(v=0;v<16;v++){n[v].h=p[y+2*v];n[v].l=p[y+2*v+1]}for(v=16;v<80;v++){int64rrot(z,n[v-2],19);int64revrrot(w,n[v-2],29);int64shr(u,n[v-2],6);l.l=z.l^w.l^u.l;l.h=z.h^w.h^u.h;int64rrot(z,n[v-15],1);int64rrot(w,n[v-15],8);int64shr(u,n[v-15],7);m.l=z.l^w.l^u.l;m.h=z.h^w.h^u.h;int64add4(n[v],l,n[v-7],m,n[v-16])}for(v=0;v<80;v++){t.l=(E.l&D.l)^(~E.l&C.l);t.h=(E.h&D.h)^(~E.h&C.h);int64rrot(z,E,14);int64rrot(w,E,18);int64revrrot(u,E,9);l.l=z.l^w.l^u.l;l.h=z.h^w.h^u.h;int64rrot(z,J,28);int64revrrot(w,J,2);int64revrrot(u,J,7);m.l=z.l^w.l^u.l;m.h=z.h^w.h^u.h;o.l=(J.l&I.l)^(J.l&G.l)^(I.l&G.l);o.h=(J.h&I.h)^(J.h&G.h)^(I.h&G.h);int64add5(s,B,l,t,sha512_k[v],n[v]);int64add(r,m,o);int64copy(B,C);int64copy(C,D);int64copy(D,E);int64add(E,F,s);int64copy(F,G);int64copy(G,I);int64copy(I,J);int64add(J,s,r)}int64add(q[0],q[0],J);int64add(q[1],q[1],I);int64add(q[2],q[2],G);int64add(q[3],q[3],F);int64add(q[4],q[4],E);int64add(q[5],q[5],D);int64add(q[6],q[6],C);int64add(q[7],q[7],B)}var k=new Array(16);for(y=0;y<8;y++){k[2*y]=q[y].h;k[2*y+1]=q[y].l}return k}function int64(b,a){this.h=b;this.l=a}function int64copy(b,a){b.h=a.h;b.l=a.l}function int64rrot(c,a,b){c.l=(a.l>>>b)|(a.h<<(32-b));c.h=(a.h>>>b)|(a.l<<(32-b))}function int64revrrot(c,a,b){c.l=(a.h>>>b)|(a.l<<(32-b));c.h=(a.l>>>b)|(a.h<<(32-b))}function int64shr(c,a,b){c.l=(a.l>>>b)|(a.h<<(32-b));c.h=(a.h>>>b)}function int64add(g,b,f){var d=(b.l&65535)+(f.l&65535);var c=(b.l>>>16)+(f.l>>>16)+(d>>>16);var a=(b.h&65535)+(f.h&65535)+(c>>>16);var e=(b.h>>>16)+(f.h>>>16)+(a>>>16);g.l=(d&65535)|(c<<16);g.h=(a&65535)|(e<<16)}function int64add4(j,m,l,k,i){var h=(m.l&65535)+(l.l&65535)+(k.l&65535)+(i.l&65535);var g=(m.l>>>16)+(l.l>>>16)+(k.l>>>16)+(i.l>>>16)+(h>>>16);var f=(m.h&65535)+(l.h&65535)+(k.h&65535)+(i.h&65535)+(g>>>16);var e=(m.h>>>16)+(l.h>>>16)+(k.h>>>16)+(i.h>>>16)+(f>>>16);j.l=(h&65535)|(g<<16);j.h=(f&65535)|(e<<16)}function int64add5(l,o,n,m,k,j){var i=(o.l&65535)+(n.l&65535)+(m.l&65535)+(k.l&65535)+(j.l&65535);var h=(o.l>>>16)+(n.l>>>16)+(m.l>>>16)+(k.l>>>16)+(j.l>>>16)+(i>>>16);var g=(o.h&65535)+(n.h&65535)+(m.h&65535)+(k.h&65535)+(j.h&65535)+(h>>>16);var f=(o.h>>>16)+(n.h>>>16)+(m.h>>>16)+(k.h>>>16)+(j.h>>>16)+(g>>>16);l.l=(i&65535)|(h<<16);l.h=(g&65535)|(f<<16)};