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: "type=" + $('#page_create_type').val() + "&active=" + active,
		success: function(msg)
		{
			$('#page_create_parent').html(msg);
			$('#page_create_indicator').css('display', 'none');
		}
	});
}
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()
{
	if ($('#change_banner').css('display') == 'none') $('#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 adTypeField(title)
{
	if ($('#ad_type_create_' + title).attr('checked') == true)
	{
		$('#ad_type_create_' + title + '_pos').val(parseInt($('#ad_type_create_count').val()) + 1);
		$('#ad_type_create_count').val(parseInt($('#ad_type_create_count').val()) + 1);
	}
	else
	{
		$('#ad_type_create_' + title + '_pos').val(0);
		$('#ad_type_create_count').val(parseInt($('#ad_type_create_count').val()) - 1);
	}
}
function adPhoto(num)
{
	var i;
	for (i = 0; i < 5; i++)
	{
		$('#ad_thumbnail' + i).removeClass('ad_thumbnail_active');
		$('#ad_thumbnail' + i).addClass('ad_thumbnail');
		$('#ad_photo' + i).css('display', 'none');
	}
	$('#ad_thumbnail' + num).removeClass('ad_thumbnail');
	$('#ad_thumbnail' + num).addClass('ad_thumbnail_active');
	$('#ad_photo' + num).css('display', 'block');
}
function adTypeCreationFix(offset)
{
	$.ajax({
		type: "POST",
		url: "/ad/adTypeCreationAdFix",
		data: "offset=" + offset,
		success: function(msg)
		{
			if (msg != 'done' && msg != 'error')
			{
				$('#processed').html('Taisomi šio tipo skelbimai, pataisyta ' + offset + ', <span style="color: red">laukite</span>.');
				adTypeCreationFix(offset + 1);
			}
			else
			{
				var text = '';
				if (msg == 'error') text = ', <span style="color: red">klaida</span>.';
				if (msg == 'done') text = ', <span style="color: green">baigta</span>.';
				$('#processed').html('Pataisyta ' + offset + text);
			}
		}
	});
}
function adFieldCreationFix(offset)
{
	$.ajax({
		type: "POST",
		url: "/ad/adFieldCreationAdFix",
		data: "offset=" + offset,
		success: function(msg)
		{
			if (msg != 'done' && msg != 'error')
			{
				$('#processed').html('Taisomi skelbimai su šiuo laukeliu, pataisyta ' + offset + ', <span style="color: red">laukite</span>.');
				adFieldCreationFix(offset + 1);
			}
			else
			{
				var text = '';
				if (msg == 'error') text = ', <span style="color: red">klaida</span>.';
				if (msg == 'done') text = ', <span style="color: green">baigta</span>.';
				$('#processed').html('Pataisyta ' + offset + text);
			}
		}
	});
}
function fixAdsFields(i)
{
	$.ajax({
		type: "POST",
		url: "/ad/fix",
		data: "ad_id=" + i,
		success: function(msg)
		{
			if (i < 13090)
			{
				$('#processed').html(i);
				fixAdsFields(i + 1);
			}
			else $('#processed').html(i + ', done.');
		}
	});
}
function importAlytaus(offset)
{
	$.ajax({
		type: "POST",
		url: "/main/importAlytausOne",
		data: "offset=" + offset,
		success: function(msg)
		{
			if (msg != 'done' && msg != 'error')
			{
				$('#processed').html('Importuojami skelbimai, importuota ' + offset + ', <span style="color: red">laukite</span>.');
				importAlytaus(offset + 1);
			}
			else
			{
				var text = '';
				if (msg == 'error') text = ', <span style="color: red">klaida</span>.';
				if (msg == 'done') text = ', <span style="color: green">baigta</span>.';
				$('#processed').html('Importuota ' + offset + text);
			}
		}
	});
}
function fixAdCities(offset)
{
	$.ajax({
		type: "POST",
		url: "/main/fixAdCities",
		data: "offset=" + offset,
		success: function(msg)
		{
			if (msg != 'done' && msg != 'error')
			{
				$('#processed').html('Taisomi skelbimai, pataisyta ' + offset + ', <span style="color: red">laukite</span>.');
				fixAdCities(offset + 1);
			}
			else
			{
				var text = '';
				if (msg == 'error') text = ', <span style="color: red">klaida</span>.';
				if (msg == 'done') text = ', <span style="color: green">baigta</span>.';
				$('#processed').html('Pataisyta ' + offset + text);
			}
		}
	});
}
