function g_e(el)
{
	return document.getElementById(el);
}


function vote_for(id, type, vote)
{
	new Ajax.Updater('news_'+id, '/index.php?todo=vote&id='+id+'&type='+type+'&vote='+vote, {asynchronous: true});

	if (Obj = g_e('vote_lnk_'+id))
	{
		Obj.style.visibility = 'hidden';
		Obj.style.position = 'absolute';
	}

	return true;
}


function report_form(n_id, obj_this, obj_event)
{
	fnr_type = 0;
	fnr_comment = "";

	new Ajax.Updater('form_trailer', '/index.php?todo=report&n_id='+n_id, {asynchronous: true});

	if (Obj = g_e('form_trailer'))
	{
		LeftAndTop = GetCenterCoords(380, 250);

		Obj.style.left = LeftAndTop[0];
		Obj.style.top = LeftAndTop[1] + document.body.scrollTop - 100;

		Obj.style.visibility = "visible";

		if (Obj = g_e('nr_comment'))
			Obj.focus();
	}

	if (Obj = g_e('add_comment'))
		Obj.style.visibility = "hidden";

	return true;
}


function report_check(n_id)
{
	if (fnr_type == 3 && !checkVal(fnr_comment, 'Please enter your report into the form or click the `close window` link.'))
		return false;
	else
	if (fnr_type == 0)
	{
		alert('Please select one option');
		return false;
	}

	report_send(n_id);
}


function report_send(n_id)
{
	var params = Form.serialize($('report_form_kk'));
	new Ajax.Updater('form_trailer', '/index.php?todo=report&post_form', {asynchronous: true, parameters: params});

	if (Obj = g_e('rep_'+n_id))
		Obj.style.visibility = "hidden";

	report_close();
}


function report_close()
{
	Obj = g_e('form_trailer');
	Obj.innerHTML = "";
	Obj.style.visibility = "hidden";

	return;
}


function GetCenterCoords (width, height)
{
	sWidth = parseInt(screen.width);
	sHeight = parseInt(screen.height);
	wleft = Math.round(sWidth/2 - width/2);
	wtop = Math.round(sHeight/2 - height/2);

	return new Array(wleft, wtop);
}


function NewWinCenter (width, height)
{
	LeftAndTop = GetCenterCoords(width, height);
	Params = ",left="+LeftAndTop[0]+",top="+LeftAndTop[1];
	return Params;
}


function comment_form(n_id, nc_id, text_msg, mp_id)
{
	if (Obj = g_e('comment_add_form_div'))
		Obj.style.display = "block";

	if (Obj = g_e('add_comment'))
	{
		LeftAndTop = GetCenterCoords(360, 280);

		Obj.style.left = LeftAndTop[0];
		Obj.style.top = LeftAndTop[1] + document.body.scrollTop - 100;
		Obj.style.visibility = "visible";
	}

	if (Obj = g_e("comment_add_form"))
	{
		g_e('comment_to_add').innerHTML = text_msg;
		Obj.n_id.value = n_id;
		Obj.nc_id.value = nc_id;
		Obj.mp_id.value = mp_id;
		Obj.nc_comment.focus();
	}

	if (Obj = g_e('form_trailer'))
		Obj.style.visibility = "hidden";
}


function comment_send(flag)
{
	if (flag == 1)
		return true;

	var params = Form.serialize($('comment_add_form'));
	new Ajax.Updater('', '/index.php?todo=news_comment', {asynchronous: true, parameters: params});

	if (Obj = g_e('comment_add_form_div'))
		Obj.style.display = "none";

	if (Obj = g_e('comment_add_ok'))
		Obj.style.display = "block";

	return false;
}


function comment_close()
{
	if (Obj = g_e('comment_add_ok'))
		Obj.style.display = "none";

	if (Obj = g_e('add_comment'))
		Obj.style.visibility = "hidden";

	if (Obj = g_e("comment_add_form"))
		Obj.nc_comment.value = "";

	return true;
}


function trim(str)
{
	return str.replace(/^\s+|\s+$/g, '');
}


function checkVal(val, msg)
{
	r = trim(val);

	if (r != '')
		return true;
	else
	{
		alert(msg);
		return false;
	}
}


function vote_anon(id, type, vote)
{
	new Ajax.Updater('news_'+id, '/index.php?todo=vote&id='+id+'&type='+type+'&vote='+vote+'&setcookie', {asynchronous: true});

	if (Obj = g_e('vote_lnk_anon_'+id))
	{
		Obj.style.visibility = 'hidden';
		Obj.style.position = 'absolute';
	}

	var date = new Date();
	date.setTime(date.getTime()+(100*24*60*60*1000));
	document.cookie = 'avoted['+id+']=1; expires='+date.toGMTString()+'; path=/';

	return true;
}

