function trim(string)
{
	return string.replace(/(^\s+)|(\s+$)/g, "");
}


$().ready(function() {

	$('.index').attr('title', 'Изменение, по сравнению со вчерашним днём');
	$('table.rating tr:odd').addClass('odd');
	$('table.rating tr:even').addClass('even');

  $("input[id='add_account_button']").click(function(){
		if (trim($("input[id='add_account_name']").val())!='')
		{
			$("input[id='add_account_button']").attr("disabled", "true");
			$("input[id='add_account_button']").val('Получение данных об аккаунте...');
			$.post("/add/", { name: $("input[id='add_account_name']").val(), category_id: $("select[id='add_account_category_id']").val()},	
				  function(data)
				  {
				  	if (data.result == 'error_notexists')
				  	{
				  		$("#add_account_message_box").html('Такого аккаунта не существует!');
				  		$("input[id='add_account_button']").removeAttr('disabled');
				  		$("input[id='add_account_button']").val('Добавить аккаунт');

				  	}
				  	else if (data.result == 'error_category')
				  	{
				  		$("#add_account_message_box").html('Пожалуйста, выберите категорию!');
				  		$("input[id='add_account_button']").removeAttr('disabled');
				  		$("input[id='add_account_button']").val('Добавить аккаунт');

				  	}
				  	else
						window.location = '/'+data.name+'/';
				  },"json");
		}
	});

  $("input[id='search_account_button']").click(function(){
		if (trim($("input[id='search_account_name']").val())!='')
		{
			$("input[id='search_account_button']").attr("disabled", "true");
			$("input[id='search_account_button']").val('Поиск...');
			$.post("/search/", { name: $("input[id='search_account_name']").val()},	
				  function(data)
				  {
				  	if (data.result == 'error_notexists')
				  	{
				  		$("#search_account_message_box").html('Аккаунт не был добавлен в рейтинг!');
				  		$("input[id='search_account_button']").removeAttr('disabled');
				  		$("input[id='search_account_button']").val('Найти аккаунт');

				  	}
				  	else
						window.location = '/'+data.name+'/';
				  },"json");
		}
	});

});