var getObject = function(id){
	return document.getElementById(id);
}
var kill = function(id){
	var toKill = getObject(id);
	var parentNode = toKill.parentNode;
	parentNode.removeChild(toKill);
}
var delete_user = function(user){
if (confirm("Are you sure you want to delete this user?")){ 
		$.ajax({
			type: "POST",
			url: "ajax.php",
			data: "action=delete_user&user=" + user,
			success: function(msg){
				if (msg == 'ok') {
					kill(user);
				}
				else {
					$("div#errors").html("<li>Error: system cann't delete this user!</li>");
				}
			}
		});
}
}
var block_user = function(user){
if (confirm("Are you sure you want to block this user?")){ 
		$.ajax({
			type: "POST",
			url: "ajax.php",
			data: "action=block_user&user=" + user,
			success: function(msg){
				if (msg == 'ok') {
					kill('block_'+user);
				}
				else {
					$("div#errors").html("<li>Error: system cann't block this user!</li>");
				}
			}
		});
}
}
var slideUpDown = function(id,speed){
              if ($('#'+id).is(":hidden")) {
                  $('#'+id).slideDown(speed);
              }else{
                  $('#'+id).slideUp(speed);
              }
}
var delete_page = function(id){
if (confirm("Are you sure you want to delete this page?")){ 
		$.ajax({
			type: "POST",
			url: "ajax.php",
			data: "action=delete_page&page=" + id,
			success: function(msg){
				if (msg == 'ok') {
					kill(id);
				}
				else {
					$("div#err").html("<li>Error: system cann't delete this page!</li>");
				}
			}
		});
}
}
var selectComplete = function(symbol){
	$('input.symbolAutoComplete').attr('value',symbol);
	$("div#autocomplete").slideUp();
}
var slideUpAutoComplete = function(){
	
}
$(document).ready(function(){
	$('input.symbolAutoComplete').keyup(function(){
		var str = $(this).attr('value');
		if (str.length > 0) {
			$(this).addClass('indicator');
			$("div#autocomplete").slideUp();
			$.ajax({
				type: "GET",
				url: "autocomplete.php",
				data: "str=" + str,
				success: function(msg){
					$("div#autocomplete > ul").html(msg);
					$("div#autocomplete").slideDown();
					$('input.symbolAutoComplete').removeClass('indicator');
				}
			});
		}
	});
	$('input.symbolAutoComplete').blur(function(){
		setTimeout('$("div#autocomplete").slideUp()',500);
		$(this).removeClass('indicator');
	});
});
