function fBrowser(field_name, url, type, win)
{
	var cmsURL = '/upload.php?type=' + type;
	if (type == 'image')
	{
		a_width = 590;
		a_height = 545;
	}
	else
	{
		a_width = 475;
		a_height = 375;
	}
	tinyMCE.activeEditor.windowManager.open({
		file: cmsURL,
		title: 'fBrowser',
		width: a_width,
		height: a_height,
		resizable: 'no',
		inline: 'yes',
		close_previous: 'no'
	}, {
		window: win,
		input: field_name
	});
	return false;
}
function changeParents(active)
{
	$('#page_create_indicator').css('display', 'inline');
	$.ajax({
		type: "POST",
		url: "/page/changeParents",
		data: "page_type_id=" + $('#page_create_type').val() + "&active=" + active,
		success: function(msg)
		{
			$('#page_create_parent').html(msg);
			$('#page_create_indicator').css('display', 'none');
		}
	});
}
function changePerson(val)
{
	if (val == 0) $('#adult').css('display', 'block');
	else $('#adult').css('display', 'none');
}
function changeSecurity(id)
{
	if ($('#' + id).attr('checked')) $('#security').css('display', 'block');
	else $('#security').css('display', 'none');
}
function changeInterestRate()
{
	$.ajax({
		type: "POST",
		url: "/main/changeInterestRate",
		data: "years=" + $('#ad_create_period_years').val() + "&months=" + $('#ad_create_period_months').val(),
		success: function(msg)
		{
			if (parseInt(msg) > 60) $('#interest_rate').css('display', 'block');
			else $('#interest_rate').css('display', 'none');
			$('#ad_create_period').val(parseInt(msg));
			returnSum();
		}
	});
}
function changePhoto(id)
{
	if ($('#change_photo' + id).css('display') == 'none') $('#change_photo' + id).css('display', 'block');
	else $('#change_photo' + id).css('display', 'none');
}
function changeBanner(id)
{
	if ($('#' + id).attr('checked')) $('#change_banner').css('display', 'block');
	else $('#change_banner').css('display', 'none');
}
function reply(comment_id)
{
	$('#comment_create_parent').val(comment_id);
	$('#comment' + comment_id).after($('#comment_form'));
}
function confirmation(link, text)
{
	var answer = confirm(text);
	if (answer) window.location = link;
}
function returnSum()
{
	var sum = parseInt($('#ad_create_sum').val());
	if (isNaN(sum)) sum = 0;
	var interest_rate = parseFloat($('#ad_create_interest_rate').val());
	if (isNaN(interest_rate)) interest_rate = 0;
	$('#return_sum').html(Math.round(sum + sum * interest_rate / 100 * $('#ad_create_period').val() / 30));
}
function popup(id)
{
	window.open('/popup/' + id, 'Skelbimas', 'status = 0, height = 400, width = 550, resizable = 0')
}
function newsletter(users)
{
	for (i = 0; i < users.length; i++)
	{
		$('#newsletter_users_' + users[i]).attr('checked', true);
	}
}
function newsletterUncheck(users)
{
	for (i = 0; i < users.length; i++)
	{
		$('#newsletter_users_' + users[i]).attr('checked', false);
	}
}
function imposeMaxLength(Object, MaxLen)
{
	var text = Object.value;
	var chars = text.length;
	if (chars > MaxLen)
	{
		var new_text = text.substr(0, MaxLen);
		Object.value = new_text;
		return false;
	}
	return true;
}
function months(banner_id)
{
	if ($('.month_' + banner_id).css('display') != 'none')
	{
		$('.month_' + banner_id).hide();
		$('.day_' + banner_id).hide();
	}
	else $('.month_' + banner_id).show();
}
function days(day_class)
{
	$('.day_' + day_class).toggle();
}