function userLogin() {
	new Request({
		url: '/users/login',  data: $('userLoginForm').toQueryString(),
		onComplete: function(r) {
			if( r == 'true' ) userPanel();
			else ajaxLogAdd('email или пароль не верен');
		}
	}).send();
}

function userRestorePass() {
	new Request({
		url:'/users/restore', data: '&data[User][user_email]='+$('restoreEmail').value,
		onComplete: function(result) {
			result = JSON.decode(result);
			if( result.result ) {
				$('restoreBox').addClass('none');
			}			
			ajaxLogAdd(result.mes);
		}
	}).send();
}

function userLogOut() {
	new Request({
		url:'/users/logout', 
		onComplete: function() {
			userPanel();
		}
	}).send();
}

function userPanel() {
	new Request({
		url:'/users/panel', 
		onComplete: function(r) {
			$('userPanel').empty().set('html', r);
		}
	}).send();
}

function getCartInfo() {
	new Request({
		url:'/cart/info', 
		onComplete: function(r) {
			$('cartInfoBlock').empty().set('html', r);
		}
	}).send();
}

function getCartBody() {
	new Request({
		url:'/cart/body', onComplete: function(r) {
			$('cartBody').empty().set('html', r);
		}
	}).send();
}

function addPrice( price_id ) {
	new Request({
		url:'/cart/add/'+price_id, 
		onComplete: function(r) {
			ajaxLogAdd(r); getCartInfo(); 
		}
	}).send();
}

function removePrice( price_id ) {
	if( confirm('Вы уверены ???') ) {
		new Request({
			url:'/cart/remove/'+price_id, 
			onComplete: function() { 
				getCartBody(); 
				getCartInfo();
			}
		}).send();
	}
}

function ajaxLogRemove( divID )  {
	$(divID).destroy();
	if( $('ajaxLogs').getChildren().length == 0 ) { 
		$('ajaxLogs').addClass('none');
	}
}

function ajaxLogAdd( mes ) {
	var divID = 'log-'+$time();
	$('ajaxLogs').removeClass('none').adopt(
		new Element('div', {
			html: mes, id:divID
		})
	);
	setTimeout("ajaxLogRemove('"+ divID +"');", 5000 );
}
