var win;
var stat = 0;
function openWinToMessage(id, to)
{
	if (stat != 0)
		win.close();

	win = window.open('/consspec/vb/show/form/id/' + id, 'Cообщение', 'width=300,height=200, top=300, left=400, resize=0');
   /* win = window.open('/contrib/empty.html', 'Cообщение', 'width=300,height=200, top=300, left=400, resize=0');

	win.document.write('<script language="JavaScript" type="text/javascript" src="/res/js/prototype.js"></script>');
	win.document.write('<script language="JavaScript" type="text/javascript" src="/res/js/consult.js"></script>');
	win.document.write('<style type="text/css">div.consult_form{font-family: Arial, sans-serif;font-size: 11px;}</style>');
	win.document.write('<div class="consult_form">');
	win.document.write('<form name="form1" action="#">');
	win.document.write('<div>Кому: ' + to + '</div>');
	win.document.write('<textarea name="message" id="message" style="width: 280px; height: 120px; border: solid 1px #777777"></textarea>');
	win.document.write('<input type="submit" value="Отправить" onclick="return SendMessage(' + id + ');" />');

	win.document.write('</div>');*/
	stat = 1;
	return false;
}

function SendMessage(id)
{
// 	alert(id);
	if (document.getElementById('message').value == '')
	{
		alert('Нельзя отправить пустое сообщение!');
	}
	else
	{	new Ajax.Request('/message/ajax/action/send/to/' + id, {
			method: 'post',
			parameters: { msg_text: '' +  document.getElementById('message').value}
		});

		alert('Сообщение отправлено!');
		self.close();
	}

	return false;
}

function goToMessagePage(id)
{
   	window.opener.location.href = '/message/send/to/' + id;
   	window.close();
}
