// (c) Andrii Vasyliev
// HPS watch functions

function showFavourite (t) {
	if (t) {
		var txt = t=="yes" ? "Remove from favourites" : "Add to favourites";
		document.getElementById('favourite').innerHTML = txt;
	};
};

function showComment (r) {
	if (r=='ok\n') {
		document.getElementById('commentPosted').innerHTML = 'Thank you. Your comment has been posted.';
		document.getElementById('noCommentsYet').innerHTML = '';
		document.getElementById('hiddenComment').style.display = 'block';
	} else alert(r);
};

function postComment (f) {
	object_id = f.obj_id.value;
	old_comment = f.message.value;
	if (!old_comment) {
		f.message.focus();
		alert('Please, enter the message to post!');
		return false;
	};
	new_comment = sol.dif.checkText(old_comment);
	if (old_comment!=new_comment) {
		f.message.value = new_comment;
		f.message.focus();
		alert('Please, use only english letters for the message!');
		return false;
	};
	new_comment = sol.dif.checkBlacklist(old_comment);
	if (old_comment!=new_comment) {
		f.message.value = new_comment;
		f.message.focus();
		alert("Please, don't use words like:"+sol.dif.badwords+"!");
		return false;
	};
	document.getElementById('hiddenMessage').innerHTML = sol.dif.html_prepare(new_comment);
	sol.ajax.get('/post/comment',showComment,{'object_id':object_id,'message':f.message.value});
	return false;
};

function showAbuse (t) {
	if (t) {
		document.getElementById('abuse').innerHTML = '<b>The video has been reported abusive!</b>';
	};
};

var already_rated = false;

function postRating (object_id,rating) {
	if (already_rated) return false;
	already_rated = true;
	sol.rating.stop(rating);
	sol.ajax.get('/post/rating',showRating,{'object_id':object_id,'rating':rating});
};

function showRating (r) {
	if (r.substr(0,3)!='ok,') {
		alert(r);
		return false;
	};
	var ar = r.split(',');
	document.getElementById('rated').innerHTML		= "Your vote was counted";
	document.getElementById('new_rating').innerHTML		= ar[1];
	document.getElementById('new_total_ratings').innerHTML	= ar[2];
};

