function rating( _id, direction, _fun ) {
	if( direction == 'up' ) {
		url = '/ajax/ratingup/';
	}
	else {
		url = '/ajax/ratingdown/';
	}
	
	$.post( url, { id: _id, fun: _fun }, function( result ) {
		if( result == 'up' || result == 'down' ) {
			var rating = parseInt( $("#r" + _id).html() );
			if ( result == 'up' ) {
				rating++
			}
			else {
				rating--;
			}
			if( rating == 0 ) {
				$( "#r" + _id ).html( "0" );
			}
			else {
				$( "#r" + _id ).html( rating );
			}
		}
		else {
			switch( result ) {
				default:
				case '0':
					alert( 'Ошибка' );
					break;
				case '1':
					alert( 'Нельзя голосовать больше 10 раз в день' );
					break;
				case '2':
					alert( 'Вы уже голосовали сегодня' );
					break;
				case '3':
					alert( 'Можно голосовать только один раз в день' );
					break;
			}
		}
	} );
	return;
}

function checkEmail( fieldObject ) {
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)([a-z.0-9]{2,15})+$/;
	if ( !filter.test( fieldObject.value ) ) {
		fieldObject.focus();
		fieldObject.select();
		alert( 'Неправильный адрес электронной почты' );
		return false;
	}
	else return true;
}

var OldColors = new Array(6);
function lightRow( cell ) {
	for( i = 0; i < ( cell.parentNode.cells.length );i++ ) {
		OldColors[i] = cell.parentNode.cells[i].style.backgroundColor;
		cell.parentNode.cells[i].style.backgroundColor = '#424242';
	}
}

function darkRow( cell ) {
	for( i = 0; i < ( cell.parentNode.cells.length );i++ ) {
		cell.parentNode.cells[i].style.backgroundColor = OldColors[i];
	}
}

function ch_lth() {
	s = 140 - $('#postsender').val().length;
	if( s < 0 ) {
		s_val = $('#postsender').val().substring(0, 140);
		$('#postsender').val(s_val);
		s = 0;
	}
	$('#postcounter').html(s);
	return;
}

jQuery( document ).ready( function($) {
	$('a[rel*=map]').facebox();
	$('a[rel*=userbars]').facebox();
})