function validateMessageSending () {
	var isError = false;
	if ($('#recipients').val () == '') {
		$('#recipientsError').fadeIn ();
		isError = true;
	}
	else {
		$('#recipientsError').hide ();
	}
	
	var message = $.trim ($('#message').val ());
	
	if (message == '') {
		$('#messageError').fadeIn ();
		isError = true;
	}
	else {
		$('#messageError').hide ();
	}
	
	if (isError) return false;
}

function show_frm_input()
{
  var f=document.getElementById("frm_input")
  if(f.style.display=="none")
  {
  	f.style.display="block"

  }
  else
  {
  	f.style.display="none"	  
  }
  return false;
}

function check_for_user()
{
	var f=document.getElementById("frm_input")
	if(f.chb1.checked)
	{f.remember_pw.value=1}
	f.submit()
}


function check_for_input()
{

	if(event.keyCode==13)
	{
		var f=document.getElementById("frm_input")			
		f.submit()
	}

}

function addFavorite (data_id, type, obj) {
	$(obj).after ('<a href="javascript://" onClick="deleteFavorite ('+data_id+', '+type+', this);" class="in_favorite" title="удалить из избранного"></a>').remove ();
	$.get ('/ajax/favorite/add/', {'data_id': data_id, 'type' : type}, function (data, status) {
		if (!(status == 'success' && data.error == 0)) {
			$(obj).after ('<a href="javascript://" onClick="addFavorite ('+data_id+', '+type+', this);" class="favorite" title="в избранное"></a>').remove ();
		}
	},
	'json');
}

function deleteFavorite (data_id, type, obj) {
	$(obj).after ('<a href="javascript://" onClick="addFavorite ('+data_id+', '+type+', this);" class="favorite" title="в избранное"></a>').remove ();
	$.get ('/ajax/favorite/delete/', {'data_id': data_id, 'type' : type}, function (data, status) {
		if (!(status == 'success' && data.error == 0)) {
			$(obj).after ('<a href="javascript://" onClick="deleteFavorite ('+data_id+', '+type+', this);" class="in_favorite" title="удалить из избранного"></a>').remove ();
		}
	},
	'json');
}

function blog_subscribe (subscribe, obj) {
	var url = '/blog/' + (subscribe == 1 ? '' : 'un')+'subscribe/';
	
	$(obj).attr ('title', $(obj).attr ('class') == 'subscribe' ? 'отписаться от блога' : 'подписаться на блог');
	$(obj).attr ('onClick', $(obj).attr ('class') == 'subscribe' ? 'blog_subscribe (0, this);' : 'blog_subscribe (1, this);');
	$(obj).attr ('class', $(obj).attr ('class') == 'subscribe' ? 'unsubscribe' : 'subscribe');
	
	
	$.get (url, {}, function(data, status) {
		if (status != 'success') {
			$(obj).attr ('title', $(obj).attr ('class') == 'subscribe' ? 'отписаться от блога' : 'подписаться на блог');
			$(obj).attr ('onClick', $(obj).attr ('class') == 'subscribe' ? 'blog_subscribe (0, this);' : 'blog_subscribe (1, this);');
			$(obj).attr ('class', $(obj).attr ('class') == 'subscribe' ? 'unsubscribe' : 'subscribe');
		}
	},
	'html');
}

function openLink(link) {
	var newWindow = window.open(link, '_blank');
	newWindow.focus();
	return false;
}

function sendPM(userid){
	$.colorbox({href:'http://rybalka/office/messages/write/'+userid+'/', iframe: true, width: "80%", height: "80%"});
}

function blacklist(userid, action) {
	var message = 'Вы действительно хотите '+
				  (action == 1 ? 'добавить пользователя в черный список' : 'удалить пользователя из черного списка')+'?';
	if (confirm (message)) {
		var url = '/ajax/blacklist/'+(action == 1 ? 'add' : 'delete')+'/'+userid;
		if (action == 1) {
			$('.blacklistAdd', $('#userbox'+userid)).hide ();
			$('.blacklistRemove', $('#userbox'+userid)).show ();
			$('.addToFriends', $('#userbox'+userid)).hide ();
			$('.sendMessageButton', $('#userbox'+userid)).hide ();
			$('.yourFriend', $('#userbox'+userid)).hide ();
		}
		else {
			$('.blacklistAdd', $('#userbox'+userid)).show ();
			$('.addToFriends', $('#userbox'+userid)).show ();
			$('.sendMessageButton', $('#userbox'+userid)).show ();
			$('.blacklistRemove', $('#userbox'+userid)).hide ();
		}
			
		$.get(url, {}, function (data, status) {}, 'json');
	}
}

function cancelBubbling(e) {
	alert('ok');
	if( typeof( e ) == "undefined" && typeof( window.event ) != "undefined" ) e = window.event; // do things.... 
	if (typeof( window.event ) != "undefined" ) { e.cancelBubble=true; } else { e.stopPropagation(); }
}