var time;
$(document).ready(TestsInit);
function TestsInit()
{
	var date = new Date();
	time = date.getTime();
}
function TestsAnswer(test_id, count)
{
	var data = {}, cur_count = 0;
	data.test_id = test_id;
	data.answers = [];
	$('a.answer').each(function(index)
	{
		if ($(this).attr('checked') == '1')
		{
			cur_count++;
			data['answers'][index] = $(this).attr('id');
		}
	})
	if (cur_count != count)
	{
		$('.result').css('background-color', '#FF8F8F').html('Вы ответили не на все вопросы').show();
		return;
	}
	var date = new Date();
	data.time_required = date.getTime() - time;
	var data_string = JSON.stringify(data);
	$.post(site_url+'tests/', {func: 'TestsAnswer', data: data_string}, TestsAnswerResult, 'json');
}
function TestsAnswerResult(result)
{
	if (result.error)
		$('.result').css('background-color', '#FF8F8F').html(result.error).show();
	else
	{
		$('.result').css('background-color', '#B2DF99').html(result.win).show();
		$('.submit').hide();
	}
}
function TestsClick(question_id, answer_id)
{
	$('#'+question_id+' a').css('color', 'black');
	$('#'+question_id+' a').css('font', '14px tahoma');
	$('#'+question_id+' a').attr('checked', '0');
	$('#'+answer_id).css('color', '#008800');
	$('#'+answer_id).css('font', 'bold 14px tahoma');
	$('#'+answer_id).attr('checked', '1');
}
function TestsFeedBack(un_id)
{
	var data = {};
	data.name = $('#un_id').attr('value');
	data.un_id = un_id;
	var data_string = JSON.stringify(data);
	$.post(site_url+'tests/', {func: 'TestsFeedBack', data: data_string}, TestsFeedBackResult, 'json');
}
function TestsFeedBackResult(result)
{
	$('.result').css('background-color', '#B2DF99').html(result).show();
}

