$('#install').ajaxForm({
	dataType: 'json',
	success: function(data)
	{
		$.each(data, function(i, val)
		{
			if(i == 'e')
				bootbox.dialog('<h3 class="red">Ошибка</h3>'+val,
					[{
						"label" : "OK",
						"class" : "btn-small btn-primary",
					}]
				);

			if(i == 'i')
				bootbox.dialog('<h3 class="red">Ошибка</h3>'+val,
					[{
						"label" : "Перейти",
						callback: function(){
							location.href=home+'servers/id/'+server+'/section/web/subsection/'+data['type']+'/action/manage';
						}
					}]
				);

			if(i == 's')
				location.href=home+'servers/id/'+server+'/section/web/subsection/bp/action/manage';
		});

		loading(0)
	}
});

$('#settings').ajaxForm({
	dataType: 'json',
	success: function(data)
	{
		$.each(data, function(i, val)
		{
			if(i == 'e')
				bootbox.dialog('<h3 class="red">Ошибка</h3>'+val,
					[{
						"label" : "OK",
						"class" : "btn-small btn-primary",
					}]
				);

			if(i == 's')
				bootbox.dialog('<h3 class="green">Внимение</h3>Внесенные изменения сохранены',
					[{
						"label" : "OK",
						"class" : "btn-small btn-primary",
					}]
				);
		});

		loading(0)
	}
});

function passwd()
{
	loading(1);

	$.getJSON(home+'servers/id/'+server+'/section/web/subsection/bp/action/passwd/go', function(arr)
	{
		$.each(arr, function(i, val)
		{
			if(i == 'e')
				bootbox.dialog('<h3 class="red">Ошибка</h3>'+val,
					[{
							"label" : "Продолжить",
					}]
				);

			if(i == 's')
				location.reload();
		});

		loading(0)
	});
}

function update()
{
	loading(1);

	$.getJSON(home+'servers/id/'+server+'/section/web/subsection/bp/action/update/go', function(arr)
	{
		$.each(arr, function(i, val)
		{
			if(i == 'e')
				bootbox.dialog('<h3 class="red">Ошибка</h3>'+val,
					[{
							"label" : "Продолжить",
					}]
				);

			if(i == 's')
				bootbox.dialog('<h3 class="green">Внимание</h3>Запрос на обновление отправлен.',
					[{
							"label" : "Продолжить",
					}]
				);
		});

		loading(0)
	});
}

function delweb()
{
	loading(1);

	$.getJSON(home+'servers/id/'+server+'/section/web/subsection/bp/action/delete/go', function(arr)
	{
		$.each(arr, function(i, val)
		{
			if(i == 'e')
				bootbox.dialog('<h3 class="red">Ошибка</h3>'+val,
					[{
							"label" : "Продолжить",
					}]
				);

			if(i == 'i')
				bootbox.dialog('<h3 class="blue">Внимание</h3>'+val,
					[{
							"label" : "Продолжить",
					}]
				);

			if(i == 's')
				location.href=home+'servers/id/'+server+'/section/web';
		});

		loading(0)
	});
}

function getdata()
{
	$.getJSON(home+'servers/id/'+server+'/section/web/subsection/bp/action/settings', function(arr)
	{
		$.each(arr, function(i, val)
		{
			if(i == 'e')
				bootbox.dialog('<h3 class="red">Ошибка</h3>'+val,
					[{
							"label" : "Продолжить",
					}]
				);

			if(i == 's')
			{
				$('#data_line_1').css('display', 'table-row');
				$('#data_line_2').css('display', 'table-row');
				$('#data_line_3').css('display', 'table-row');
				$('#data_line_4').css('display', 'table-row');
			}

			if(i == 'bp_login')
				$('#bp_login').val(val);

			if(i == 'bp_passwd')
				$('#bp_passwd').val(val);

			if(i == 'bp_mail')
				$('#bp_mail').val(val);

			if(i == 'bp_vk')
				$('#bp_vk').val(val);

			if(i == 'bp_skype')
				$('#bp_skype').val(val);

			if(i == 'bp_webmoney')
				$('#bp_webmoney').html(val);

			if(i == 'bp_wmr')
				$('#bp_wmr').val(val);

			if(i == 'bp_sign_key')
				$('#bp_sign_key').val(val);
			
			if(i == 'bp_freekassa_m')
				$('#bp_freekassa_m').val(val);
			
			if(i == 'bp_freekassa_word')
				$('#bp_freekassa_word').val(val);
			
			if(i == 'bp_freekassa_word2')
				$('#bp_freekassa_word2').val(val);
			
			if(i == 'bp_freekassa')
				$('#bp_freekassa').html(val);

		});

		loading(0)
	});
}