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 abuse (id, obj, type) { 
	$('#abuseText').attr ('value', '');
	$('#abuseId').attr ('value', id);
	$('#abuseType').attr ('value', type);
	if (type == 'rc' || type == 'bc' || type == 'mc') {
		$('.abuseHeader').html ('Пожаловаться на комментарий');
	}
	else if (type == 'bl' || type == 'mi') {
		$('.abuseHeader').html ('Пожаловаться на заметку');
	}
	else if (type == 'al') {
		$('.abuseHeader').html ('Пожаловаться на фотоотчет');
	}
	else if (type == 'alb') {
		$('.abuseHeader').html ('Пожаловаться на фотоальбом');
	}
		
	lastObj = obj;
	$.colorbox({href:"#abuseContainer", 
				inline:true
	});
} 

function closeAbuse () {
    $.colorbox.close();
}

function sendAbuse () {
	var type = $('#abuseType').attr ('value');
	if (type == 'alb') type = 'al';
	var id = $('#abuseId').attr ('value');
	var url = '/ajax/abuse/';
	switch (type) {
		case 'rc':
			url += 'rcomment/'+id+'/';
    		break;
		case 'bc':
			url += 'bcomment/'+id+'/';
    		break;
		case 'al':
			url += 'photo/'+id+'/';
        	break;
		case 'bl':
			url += 'blog/'+id+'/';
    		break;
		case 'mi':
			url += 'micro/'+id+'/';
    		break;
		case 'mc':
			url += 'mcomment/'+id+'/';
    		break; 
	}
	$.post (url, {'data': $('#abuseText').attr ('value')}, function(data, status) {
		if (status == 'success') {
			$.colorbox.close ();
			$(lastObj).after ('<span>Жалоба отправлена</span>').remove ();
		}
	},
	"html");
}