function check_registration()
{	
	var tmp = true;
	
	if(!field_check_text('username', 3))
	{
		tmp = false;
	}
	
	if(!field_check_text('password', 3))
	{
		tmp = false;
	}
	
	if(!field_check_text('password2', 3))
	{
		tmp = false;
	}
	
	if(document.getElementById('password').value != document.getElementById('password2').value)
	{
		var error = "#d56900";
		document.getElementById('lpassword').style.color = error;
		document.getElementById('lpassword2').style.color = error;
		if(document.getElementById(i+'-error'))
			showdiv(i+'-error');
		
		tmp = false;
	}
	
	if(!check_email('email'))
	{
		tmp = false;
	}
	
	return tmp;
}

function key_change_status(e)
{
	var KeyID = (window.event) ? event.keyCode : e.keyCode;
	
	if(KeyID == 13)
	{
		save_user_status();
		document.getElementById('status_save').focus();
	}
}

function save_user_status(interact)
{
	var interact = (interact) ? true : false;
	var user_status = document.getElementById('user_status').value;
	$("#current_user_status").fadeOut("fast");

	$.ajax({
		url: "index.php",
		type: "POST",
		data: ({action : 'user_status', action_type : 'ajax', user_status : user_status}),
		dataType: "html",
		success: function(msg)
		{
			$("#current_user_status").stop();
			msg = ajax_retrieve_messages(msg);
			document.getElementById('user_status_holder').innerHTML = msg[0];
			if(document.getElementById('actions'))
			{
				if(!interact)
					document.getElementById('actions').innerHTML = msg[1] + document.getElementById('actions').innerHTML;
			}
			if(document.getElementById('wassup_holder'))
				document.getElementById('wassup_holder').innerHTML = msg[1] + document.getElementById('wassup_holder').innerHTML;

			$("#last-status-"+msg[2]).show(500);
			$('#status_edit').tooltip({track: true, delay: 200, showURL: false, showBody: " - ", fade: 350, extraClass: 'none' });
			$('#status_save').tooltip({track: true, delay: 200, showURL: false, showBody: " - ", fade: 350, extraClass: 'none' });
			$('#current_user_status').tooltip({track: true, delay: 200, showURL: false, showBody: " - ", fade: 350, extraClass: 'none' });
		}
	});
}

var status_status = 0;
function user_swap_status_change(id)
{
	if(id == 1)
	{
		$("#current_user_status").hide();
		$("#user_status_info").show();
		$("#user_status").focus();
		$("#status_edit").hide();
		$("#status_save").show();
		
		status_status = 1;
		
		$(document).bind("click",function(e)
		{
			if(status_status == 3)
			{
				var pos = $("#status_save").position();
				//alert(pos.left + ", " + pos.top + " " + e.pageX + ", " + e.pageY + " " + status_status);
				if((pos.left - 10 >= e.pageX) && (pos.left + 18 + 1 <= e.pageX) && (pos.top - 3 >= e.pageY) && (pos.top + 18 <= e.pageY))
				{
					$(document).unbind("click");
					save_user_status();
					status_status = 0;
				}
				else
				{
					$("#user_status_info").fadeOut(300);
					$("#current_user_status").show(); 
					$("#status_edit").show(); 
					$("#status_save").hide();
					$(document).unbind("click");
				}
				status_status = 0;
			}
			status_status++;
		});	
		
		status_status = 2;		
	}
	else if(id == 2)
	{
		$("#user_status_info").fadeOut(500, function() {$("#current_user_status").show(); $("#status_edit").show(); $("#status_save").hide();});
		$(document).unbind("click");			
	}
}
