function auth()
{
	//$('#auth_error').hide();		
	var user = $('#user_email_ajax').val()
	var pass = $('#user_password_ajax').val()
	var data = 'user_email='+user + '&user_password='+pass + '&oper=login';
	$.ajax({
		type: "POST",
		url: "/ajax/auth/",
		data: data,
		cache: false,
		success: reAuth
	});
}
function reAuth(html)
{	
	var myObject = Json.evaluate(html);
	if(myObject['isAuth']){
		$('#login_form').slideToggle('slow', function (){			
			$("#my_profile_information").slideToggle('slow');			
			setTimeout(hideNotify, 15000);
		});				
		$('#login_btn').hide();
		$('#profile_btn').show();
	
	} else {
		$('#aaauth_title').hide();
		$('#auth_error').show();
	}
}

function hideNotify()
{
	$("#my_profile_information").slideToggle('slow');
	$('#login_form_div').hide(10);
}

function authLogout()
{
	var data = 'oper=logout';
	$.ajax({
		type: "POST",
		url: "/ajax/auth/",
		data: data,
		cache: false,
		success: reAuthLogout
	});
}

function reAuthLogout(html)
{
	var myObject = Json.evaluate(html);
	if (myObject['isLogout']){
		$('#login_form_div').hide()
		$('#user_email_ajax').val('e-mail')
		$('#user_password_ajax').val('')
		$('#profile_btn').hide();
		$('#login_btn').show();
		window.location.reload()
	}
}

function authRestore()
{
	var email = $('#auth_restore').val();
	$('#recover_password_error').hide();
	var reg = new RegExp("[0-9a-z_]+@[0-9a-z_^.]+\\.[a-z]{2,3}", 'i')
	if (reg.test(email)) {
		var data = 'oper=restore' + '&email='+email;
		$.ajax({
			type: "POST",
			url: "/ajax/auth/",
			data: data,
			cache: false,
			success: function(html){
				$('#recover_password').slideToggle('slow', function (){
					$('#recover_password_close').slideToggle('slow');
					$('#auth_restore').val('E-mail');
				});				
			}
		});				
	} else {
		$('#recover_password_error').show();
		$('#auth_restore').focus();
		if($('#auth_restore').val()=='E-mail'){
			$('#auth_restore').val('');
		}		
	}
}


function submitenter(myfield,e)
{
	var keycode;
	if (window.event)
	keycode = window.event.keyCode;
	else if (e)
	keycode = e.which;
	else
	return true;

	if (keycode == 13) {
		auth();
		return false;
	}

}

function showLoginForm()
{		
	$('#aaauth_title').show();	
	$('#user_email_ajax').val('e-mail')
	$('#user_password_ajax').val('')
	$('#recover_password_close').hide();
	$('#recover_password').hide();	
	$('#login_form_div').show(10);	
	$('#auth_error').hide();
	$('#login_form').slideToggle('slow', function (){
		if ($(this).css("display") == "none") {
			$('#login_form_div').hide(10);	
			$('#auth_error').hide();
		}
	});
}

function showProfileForm()
{	
	$("#my_profile_information").hide();
	$('#login_form_div').show(10);	
	$('#my_profile').slideToggle('slow', function (){
		if ($(this).css("display") == "none") {
			$('#login_form_div').hide(10);	
		}
	});
}

function showRestoreForm()
{		
	$('#recover_password_error').hide();
	$('#login_form').slideToggle('slow', function (){
		$("#recover_password").slideToggle("slow");
	});
}
