$(document).ready(BoardInit);
function BoardInit()
{
}
function BoardCaptchaReload()
{
	$('.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: BoardCaptchaReload()">Обновить</a>');
}
var image;
function BoardFileUpload(id)
{
	$.ajaxFileUpload
	(
		{
			url: site_url+'board/upload/',
			secureuri: false,
			fileElementId: id,
			dataType: 'json',
			success: function (data, status)
			{
				if (data.action == 'ok')
				{
					image = data.name;
					$('#upload').html('Изображение загружено');
				}
				else
					alert(data);
			},
			error: function (data, status, e)
			{
				alert(e);
			}
		}
	)
}
function BoardAdd()
{
	var data = {}, groups = {};
	data.group_id = $('input.radio:checked').attr('group_id');
	data.text1 = $('#text1').attr('value');
	data.text2 = $('#text2').attr('value');
	data.price = $('#price').attr('value');
	data.image = image;
	data.contact = $('#contact').attr('value');
	data.mail = $('#mail').attr('value');
	data.captcha = $('#captcha').attr('value');
	var data_string = JSON.stringify(data);
	$.post(window.location+'/', {func: 'BoardUserAdd', data: data_string}, BoardAddResult, 'json');
}
function BoardAddResult(result)
{
	if (result == 'ok')
	{
		alert("Спасибо\nПосле проверки администрацией сайта Ваше объявление будет опубликовано");
		document.location.href = site_url+'board';
	}
	else
		alert(result);
}
function BoardCheckText1()
{
	count = $('#text1').attr('value').length;
	if (count <= 70)
	{
		$('.text1_count').css('backgroundColor', '#83B108');
		$('.text1_count').css('width', count+'%');
	}
	if (count > 70 && count < 100)
	{
		$('.text1_count').css('backgroundColor', '#f7dc21');
		$('.text1_count').css('width', count+'%');
	}
	if (count >= 100)
	{
		$('.text1_count').css('backgroundColor', 'red');
		$('.text1_count').css('width', '100%');
	}
	$('#text1').attr('value', $('#text1').attr('value').substr(0, 100));
}
function BoardCheckText2()
{
	count = $('#text2').attr('value').length;
	if (count <= 900)
	{
		$('.text2_count').css('backgroundColor', '#83B108');
		$('.text2_count').css('width', count / 10 +'%');
	}
	if (count > 900 && count < 1000)
	{
		$('.text2_count').css('backgroundColor', '#f7dc21');
		$('.text2_count').css('width', count / 10 +'%');
	}
	if (count >= 1000)
	{
		$('.text2_count').css('backgroundColor', 'red');
		$('.text2_count').css('width', '100%');
	}
	$('#text2').attr('value', $('#text2').attr('value').substr(0, 1000));
}

