window.addEvent('load', function() {
	initLang();
});
function initLang() {
	$$('.openLangDialog').each(function(el) {
		el.addEvent('click', function(e) {
			e	=	new Event(e).stop();
			x	=	e.client.x;
			y	=	e.client.y;

			locale	=	el.className.replace(/.*locale_([0-9+]).*/, '$1');
			lbl		=	el.innerHTML.replace(/[\[\]]/ig, '');
			id		=	'lbl_'+lbl;
			if($(id)) {
				$(id).remove();
				return;
			}
			newel	=	document.createElement('div');
			newel.className			=	'langEdit';
			newel.id				=	id;
			newel.style.position	=	'absolute';
			newel.style.top			=	(y + 15) + 'px';
			newel.style.left		=	(x + 0) + 'px';
			newel.style.zIndex		=	1000;
			inner	=	'<form action="'+el.href+'" method="post">';
			inner	+=	'<input type="hidden" name="ajaxReq" value="1" />';
			inner	+=	'<input type="hidden" name="locale_InfoID" value="'+locale+'" />';
			inner	+=	'<input type="hidden" name="data[label]" value="'+lbl+'" />';
			inner	+=	'<input type="text" name="data[value]" value="" />';
			inner	+=	'</form>';
			newel.innerHTML	=	inner;
			if(el.getParent().getChildren().length > 1) {
				newel.injectAfter(el);
			} else {
				newel.injectAfter(el.getParent());
			}

			form = $$('#'+id+' form')[0];
			form.addEvent('submit', function(e) {
				e	=	new Event(e).stop();
				value	=	this.getChildren()[3].value;
				this.send({
					onComplete: function() {
						newel	=	document.createElement('span');
						newel.innerHTML	=	value;
						newel.injectAfter(el);
						el.remove();
						$(id).remove();
					}
				});
			});
		});
	});
}

var Timer = new Class({
	initialize: function (ms, name) {
		this.start_ms	=	0;
		this.ms			=	ms;
		this.name		=	name;
		this.is_started	=	false;
	},

	start: function () {
		d=new Date();
		this.start_ms	=	d.getTime();
		this.is_started	=	true;
		setTimeout(this.name+'.run()', 100);
	},

	run: function () {
		d=new Date();
		t=d.getTime();
		
		if((t - this.start_ms) >= this.ms) {
			this.end();
		} else {
			setTimeout(this.name+'.run()', 100);
		}
	},

	reset: function () {
		d=new Date();
		this.start_ms = d.getTime();
	},
	
	stop: function () {
		this.initialize(this.ms, this.name);
	}
});