$('#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",
						callback : function(){
							if(data['input'] == 'table-row')
								$('#contact').css('display', data['input']);
							else
								$('#contact').hide();
						}
					}]
				);

			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');
				$('#data_line_5').css('display', 'table-row');
				$('#data_line_6').css('display', 'table-row');
				$('#data_line_7').css('display', 'table-row');
			}

			if(i == 'bp_name')
				$('#bp_name').val(val);
			
			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_unitpay')
				$('#bp_unitpay').html(val);

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

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

			if(i == 'bp_freekassa')
				$('#bp_freekassa').html(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);
		});

		loading(0)
	});
}