function validateCommentForm(_is_logged, _guest_email)
{
	bolRes = true;

	resetCommentErrors(_is_logged, _guest_email)
	
	bolRes = checkComment() && bolRes;
	if(!_is_logged)
	{
		bolRes = checkCaptcha() && bolRes;
		if(_guest_email)
		{
			bolRes = checkEmail() && bolRes;
		}
	}

	return bolRes;
}

function checkCaptcha()
{
	var objCaptcha = document.getElementById("Captcha");
	var objError = document.getElementById("CaptchaError");

	if(objCaptcha.value == "")
	{
		objError.innerHTML = "Обязательное";
		return false;
	}
	
	return true;
}

function resetCommentErrors(_is_logged, _guest_email)
{
	document.getElementById("CommentError").innerHTML = "";
	if(!_is_logged)
	{
		document.getElementById("CaptchaError").innerHTML = "";
		if(_guest_email)
		{
			document.getElementById("EmailError").innerHTML = "";
		}
	}
}

function checkComment()
{
	var objComment = objWysiwyg.getContent();
	var objError = document.getElementById("CommentError");
	
	if(objComment == "")
	{
		objError.innerHTML = "Обязательное";
		return false;
	}
	
	return true;
}

function checkEmail()
{
	var objEmail = document.getElementById("UserEmail");
	var objError = document.getElementById("EmailError");
	
	if(objEmail.value == "")
	{
		objError.innerHTML = "Обязательное";
		return false;
	}
	
	if(!doCheckMail(objEmail.value))
	{
		objError.innerHTML = "Введите правильный Email";
		return false;
	}
	
	return true;
}

function getAjaxComment(_userId, _idTypeObj, _idObj, _isPublic, _is_logged, _send_email, $_guest_email)
{
	doShowLoader('addCommentLoader');
	document.getElementById("CommentFormError").innerHTML = "";
	if(document.getElementById("submitPost") != null) document.getElementById("submitPost").disabled = true;
	if(document.getElementById("submitEmail") != null) document.getElementById("submitEmail").disabled = true;
	
	var CaptchaId = 0;
	var Captcha = "";
	var UserEmail = "";

	if(!_is_logged)
	{
		CaptchaId = document.getElementById("captchaId").value;
		Captcha = document.getElementById("Captcha").value;
		if($_guest_email)
		{
			UserEmail = document.getElementById("UserEmail").value;
		}
	}

	var UserComment = objWysiwyg.getContent();
	
	var objAjaxPage = new AjaxPageManage();
	objAjaxPage.doLoading = function() {}
	objAjaxPage.setResponseData = function() {doAddComment(objAjaxPage.responseText, _is_logged, $_guest_email); doHideLoader("addCommentLoader");}
	
	objAjaxPage.getAjaxPage('get_comment', ['action', 'idTypeObj', 'idObj', 'userId', 'captchaId', 'Captcha', 'UserComment', 'isPublic', 'sendEmail', 'UserEmail'], ["ADD", _idTypeObj, _idObj, _userId, CaptchaId, Captcha, UserComment, _isPublic, _send_email, UserEmail]);
}

function doAddComment(_responseText, _is_logged, $_guest_email)
{
	if(_responseText.length > 1)
	{
		var objContainer = document.getElementById("commentContainer");
		objContainer.innerHTML += _responseText;
		
		objWysiwyg.setContent("");
	}
	else
	{
		objError = document.getElementById("CommentFormError");

		if(_responseText == 1)
		{
			objError.innerHTML = "Произошла ошибка, попробуйте еще раз позже";
		}
		else if(_responseText == 2)
		{
			objError.innerHTML = "Сообщение успешно отправлено";
			objWysiwyg.setContent("");
		}
		else if(_responseText == 3)
		{
			objError.innerHTML = "Неправильно заполнена проверка";
		}
	}

	if(!_is_logged)
	{
		document.getElementById("Captcha").value = "";
		if($_guest_email)
		{
			document.getElementById("UserEmail").value = "";
		}
	}
	
	if(document.getElementById("submitPost") != null) document.getElementById("submitPost").disabled = false;
	if(document.getElementById("submitEmail") != null) document.getElementById("submitEmail").disabled = false;
}

function removeAjaxComment(_objLink, _custId, _commentId)
{
	var objAjaxPage = new AjaxPageManage();
	objAjaxPage.setResponseData = function() {doRemoveComment(_objLink);}
	objAjaxPage.getAjaxPage('get_comment', ['action', 'userId', 'commentId'], ["DELETE", _custId, _commentId]);
}

function doRemoveComment(_objLink)
{
	var objTable = _objLink.parentNode.parentNode.parentNode;
	objTable.parentNode.removeChild(objTable);
}
