var popupCell = null;
function toggleCell(cellId)
{
	if (null != popupCell && popupCell != cellId)
	{
		$('names_popup_' + popupCell).style.display = 'none';
	}

	if (null == $('names_popup_' + cellId))
	{
		return;
	}

	if ('block' == $('names_popup_' + cellId).style.display)
	{
		$('names_popup_' + cellId).style.display = 'none';
		popupCell = null;
	}
	else
	{
		$('names_popup_' + cellId).style.display = 'block';
		popupCell = cellId;
	}
}

function replaceValue(id, replaceFrom, replaceTo)
{
	if ($(id).value == replaceFrom)
	{
		$(id).value = replaceTo;
	}
	$(id).focus();
}

function showDropMenu(id)
{
	$(id).style.display = 'block';
}


function hideDropMenu(id)
{
	$(id).style.display = 'none';
}


function checkemail(need_to_check) {
	var str = need_to_check;
	var testresults = false;
	var filter = /^.+@.+\..{2,4}$/;

	if (filter.test(str))
		testresults = true;
	else {
		alert(LangMessages['invalid_email']);
		testresults = false;
	}

	return testresults;
}

function checkregistration() {
	var r_email = document.registration.email.value;
	var pass1 = document.registration.password.value;
	var pass2 = document.registration.password2.value;
	var username = document.registration.username.value;

	if (username.length < 1 || pass1.length < 1 || pass2.length < 1
			|| r_email.length < 1) {
		alert(LangMessages['fill_all']);
		return false;
	}

	if (username.length < 3) {
		alert(LangMessages['short_username']);
		return false;
	}

	if (pass1 != pass2) {
		alert(LangMessages['passwords_mismatch']);
		return false;
	}

	return checkemail(r_email);
}

function overStar(id, n, im) {
	if (starOver[id][n] == 1)
		return;
	starOver[id][n] = 1;
	for (i = 1; i <= 5; i++) {
		rateStars[id][i] = $('rateStar_' + i + '_' + id).src;
		if (i <= n)
			$('rateStar_' + i + '_' + id).src = im;
	}
}

function outStar(id) {
	for (i = 1; i <= 5; i++) {
		starOver[id][i] = 0;
		$('rateStar_' + i + '_' + id).src = rateStars[id][i];
	}
}

function makeRate(id, n, im, url) {

	$('stars_container_' + id).innerHTML = '<img src="' + im + '" width="60" height="12">';
	new Ajax.Request(url, {
		method :'post',
		parameters : {
			'id' :id,
			'n' :n
		},
		onSuccess : function(transport) {
			var answer = transport.responseText.evalJSON();
			$('stars_container_' + answer.id).innerHTML = answer.stars;
			// $('cnttd_' + answer.id).innerHTML = answer.cnt;
	}
	});
}

var rateStars = new Array();
var starOver = new Array();

function fillRateArrays(ratingsIds) {

	/*
	 * stars = $$('img.rateStar');
	 *
	 * for (i = 0; i<stars.length; stars++) { }
	 */

	rnp = ratingsIds.split(',');

	starOver = new Array();
	rateStars = new Array();

	for (i = 0; i < rnp.length; i++) {
		for (j = 1; j <= 5; j++) {
			starOver[rnp[i]] = new Array();
			rateStars[rnp[i]] = new Array();
			starOver[rnp[i]][j] = 0;
			rateStars[rnp[i]][j] = '';
		}
	}
}

function setNewDate(newDate) {
	$("Vardadienas").setNewDate(newDate);
}

function tbar(el, pic, txt,fld)
{
	el.src=pic;
	if(txt!='')
	{
		Tip(txt,BGIMG,fld+'images/tip.gif',BORDERCOLOR,'#767573',SHADOW,1,SHADOWWIDTH,2,SHADOWCOLOR,'#a4a49c',FONTCOLOR,'#626262');
	}
	else
	{
		UnTip();
	}

}