//окрытие окна посредине экрана
function  openwindows (caption)
{	var my_div = $("<div id=glass class='x'><div class='xy'></div></div><div id=glass2 class='x2'><div class='xy'><div class='xyz'><table class=\"y0\" cellpadding=\"0\" cellspacing=\"0\"><tr class=\"y10\"><td class=\"y1\">"+caption+"</td><td class=\"y2\"><span onclick=close_window()><img src=\"./modules/mod_msg/pic/decros.gif\" alt=\"\" border=\"0\"></span></td></tr><tr><td colspan=\"2\" class=\"y3\" valign=\"top\"><div style='overflow-y:scroll;height:350px;overflow-x:hidden;' id=win_doby></div>																																																																						  </td></tr></table></div></div></div>");		my_div.appendTo("body");	$('#glass2').hide();
	$('#glass2').fadeIn(1000);
}

function close_window()
{	$('#glass').remove();
	$('#glass2').remove();
}


// Функция открытия нового окна, для отправки сообщения
// uid- userid
// tablecomplect - это сообщение ? это коснультация ?
function new_msg_windows (uid,tablecomplect)
{
// #win_doby - пользовательская область окна


	if (tablecomplect==0){
		if (uid!=0)
			openwindows ("Новое сообщение");
		else
			openwindows ("Новое массовое сообщение");

		$.get ("./modules/mod_msg/msg_tree.php?msg_act=1&msg_actt="+tablecomplect+"&to_uid="+uid,
		   	function (data){$('#win_doby').html(data)});
	}
	if (tablecomplect==1)
	{
		openwindows ("Новый вопрос");
		$.get ("./modifier.php?act=5",
		   	function (data){
			$('#win_doby').html(data);
			});
	}


    if (tablecomplect==4)
	{
		openwindows ("Новый горящий вопрос");
		$.get ("./modifier.php?act=12",
		   	function (data){
			$('#win_doby').html(data);
			});
	}



}


function answer_msg_windows (uid,tablecomplect)
{	openwindows ("Ответ");
	$.get ("./modules/mod_msg/msg_tree.php?msg_act=4&msg_actt="+tablecomplect+"&msgid="+uid,
	   	function (data){$('#win_doby').html(data)});

}



// Вывести полный текст сообщения на экран
function show_full_msg (uid,tablecomplect)
{
	openwindows ("Просмотр сообщения");

	$.get ("./modules/mod_msg/msg_tree.php?msg_act=5&msg_actt="+tablecomplect+"&msgid="+uid,
	   	function (data){$('#win_doby').html(data)});

}



function sendmessage (tn,msgactt,isanswerfor)
{	var z=document.getElementById('mod_msg_text');
	//елси это не ответ, а новое, то
	$.post ("./modules/mod_msg/msg_tree.php?msg_act=2&afor="+isanswerfor+"&toid="+tn+"&msg_actt="+msgactt,{msg:	encodeURIComponent(z.value)},function (data){alert ("Ваше сообщение отправлено.");z.value="";}	);

	close_window();
}

function sendconsconcret(dop)
{
	$.post ("./modifier.php?act=16&dop="+dop,
        {msg:	encodeURIComponent(document.getElementById('conrcret_'+dop).value)}, function (data){
            alert('Ваше уточнение отправлено.');
    });

}

function sendcons ()
{
    
	$.post ("./modifier.php?act=6",
        {msg:	encodeURIComponent(document.getElementById('msg_text').value)}, function (data){
            alert('Ваш вопрос отправлен.');
            document.getElementById('msg_text').value="";
        
    });
	//close_window();
}

function sendfirecons()
{   var type=0
    if ($('#fqtype1').attr('checked'))
        type=1;
    if ($('#fqtype2').attr('checked'))
        type=2;
    if ($('#fqtype3').attr('checked'))
        type=3;

    $.post ("./modifier.php?act=13",
        {msg:	encodeURIComponent(document.getElementById('msg_text').value),
         fio:	encodeURIComponent(document.getElementById('fio').value),
         type: type},function(data){
            alert('Ваш вопрос отправлен.') ;
         });
	close_window();
}

$(document).ready(
  function()
  {
		$(".draw_new_message").attr('onclick','');   // создаем пустой атрибут, чтобы потом его заменить на нужный
		$(".write_answer").attr('onclick','');   // создаем пустой атрибут, чтобы потом его заменить на нужный
		$(".show_full_message").attr('onclick','');   // создаем пустой атрибут, чтобы потом его заменить на нужный
		$(".ocenka").attr('onclick','');   // создаем пустой атрибут, чтобы потом его заменить на нужный


	  // привязываем ко всем элементам работы с модулем месседж функции онклик
	  	$(".draw_new_message").each(
	  		function()
			{ $(this).click (function (){new_msg_windows(this.id,this.attributes.getNamedItem ('tcomplect').nodeValue);});   // создаем пустой атрибут, чтобы потом его заменить на нужный
//				this.attributes.getNamedItem('onclick').nodeValue='';
			}
		);


	  	$(".write_answer").each(
	  		function()
			{	$(this).click (function (){answer_msg_windows(this.id,this.attributes.getNamedItem ('tcomplect').nodeValue);});
			}
		);


	  	$(".show_full_message").each(
	  		function()
			{	$(this).click (function (){show_full_msg(this.id,this.attributes.getNamedItem ('tcomplect').nodeValue);});
			}
		);

/*	  	$(".ocenka").each(
	  		function()
			{	$(this).click (function (){make_ocenka(this.id);});
			}
		);
*/

  }
 );



function open_cons_answer_window(qid)
{
	openwindows ();
	$('#win_head').html ("ответ на вопрос");
//	$.get ("./modules/mod_msg/msg_tree.php?msg_act=1&msg_actt="+tablecomplect+"&to_uid="+uid,
//		   	function (data){$('#win_doby').html(data)});

}


// Отправка своего мнения по теме дня
function send_today_opinion (dayid)
{
	var z=document.getElementById('today')	;
//	console.log (z.value);
	$.post ("./modules/mod_msg/msg_tree.php?msg_act=2&toid=0&msg_actt=2&afor="+dayid
		,{msg:	encodeURIComponent(z.value)},function(){alert ("Спасибо за Ваше мнение.");z.value="";});
//	close_window();
}

function  make_ocenka (quid)
{
	openwindows ("Оцените ответ на вопрос");
	$.get ('./modifier.php?act=10&quid='+quid,function (data){$('#win_doby').html(data)});

}

function save_ocenka (quid)
{
	var bal=0;

	z=document.getElementById('bal1');
	 if (z.checked==true) bal=1;
	z=document.getElementById('bal2');
	 if (z.checked==true) bal=2;
	z=document.getElementById('bal3');
	 if (z.checked==true) bal=3;

//	 alert (bal);
	var z=document.getElementById('comment')	;

	$.post ("./modifier.php?act=11",{comment:	encodeURIComponent(z.value),ball:bal,id:quid},
	function (data){alert ("Ваше мнение отправлено. Спасибо.");close_window();}	);

}


function open_msg_page (type,pageid,tcomplect,prfx,uid)
{
	$.get ("./modules/mod_msg/msg_tree.php?msg_act=7&msg_actt="+tcomplect+'&type='+type+'&page='+pageid+'&msg_for_uid='+uid,
	function(data){$("#"+prfx).html(data)});





}
