$(document).ready(ConferencInit);
function ConferencInit()
{
	$('body').append('<div class="conferenc_window" id="conferenc_window"></div>');
	$('#conferenc_window').dialog
	({
		autoOpen: false ,
		width: 700,
		minHeight: 1,
		modal: true,
		resizable: false,
		draggable: false,
		zIndex: 1000
	});
}
function ConferencCaptchaReload()
{
	$('.captcha').empty();
	$('.captcha').append('<img src="'+site_url+'captcha/'+Math.round(Math.random() * 1000)+'" alt="Защита от роботов" title="Защита от роботов" width="100" height="60" /><br /><br /><a href="javascript: ConferencCaptchaReload()">Обновить</a>');
}
function ConferencAdd()
{
	var data = {};
	data.name = $('#name').attr('value');
	data.question = $('#question').attr('value');
	data.captcha = $('#captcha').attr('value');
	var data_string = JSON.stringify(data);
	$.post(window.location+'/', {func: 'ConferencAdd', data: data_string}, ConferencAddResult, 'json');
}
function ConferencAddResult(result)
{
	if (result['status'] == 'ok')
	{
		alert('Спасибо! Ваш вопрос добавлен в конференцию');
		document.location.href = result['url'];
	}
	else
		alert(result['error']);
}
function ConferencDeleteQuestion(question_id)
{
	var data = {};
	data.question_id = question_id;
	var data_string = JSON.stringify(data);
	if (confirm('Удалить вопрос?'))
		$.post(window.location+'/', {func: 'ConferencDeleteQuestion', data: data_string}, ConferencDeleteQuestionResult, 'json');
}
function ConferencDeleteQuestionResult(result)
{
	if (result)
	{
		alert('Вопрос удален');
		document.location.reload();
	}
	else
		alert('Вопрос удалить невозможно');
}
function ConferencDeleteAnswer(question_id)
{
	var data = {};
	data.question_id = question_id;
	var data_string = JSON.stringify(data);
	if (confirm('Удалить ответ?'))
		$.post(window.location+'/', {func: 'ConferencDeleteAnswer', data: data_string}, ConferencDeleteAnswerResult, 'json');
}
function ConferencDeleteAnswerResult(result)
{
	if (result)
	{
		alert('Ответ удален');
		document.location.reload();
	}
	else
		alert('Ответ удалить невозможно');
}
function ConferencShowForm(question_id)
{
	$('#conferenc_window').empty();
	$("#conferenc_window").dialog('close');
	$('#conferenc_window').append('<div class="answer_answer"><textarea class="answer input" id="answer"></textarea></div>');
	$('#conferenc_window').append('<div class="answer_submit"><a href="javascript: ConferencAnswer(\''+question_id+'\')">Ответить</a></div>');
	$('#conferenc_window').dialog('option', 'title', 'Ответить');
	$('#conferenc_window').dialog('open');
}
function ConferencAnswer(question_id)
{
	var data = {};
	data.question_id = question_id;
	data.answer = $('#answer').attr('value');
	var data_string = JSON.stringify(data);
	$.post(window.location+'/', {func: 'ConferencAnswer', data: data_string}, ConferencAnswerResult, 'json');
}
function ConferencAnswerResult(result)
{
	if (result)
	{
		$("#conferenc_window").dialog('close');
		document.location.reload();
	}
	else
		alert('Ответ не принят');
}

