function collapse(id, obj){
	if(obj){
		(obj.className == 'comments_collapse') ? obj.className = 'comments_show' : obj.className = 'comments_collapse';
	}		
	(document.getElementById(id).style.display == 'block') ? document.getElementById(id).style.display = 'none' : document.getElementById(id).style.display = 'block';
}

function checkIsBanned(){
	if(is_banned==1){
		alert('Вы не можете использовать данную функцию так как на данный момент ЗАБАНЕНЫ!');
		return false;
	}			
	return true;
}

function checkUser(){
//alert(user_pid);
	if(user_pid==1){
		return false;
	}			
	return true;
}

function refreshPage(_on_complete){
	//ajax('Comments&refresh_user=1', 'comments_refresh_user_ajax_div', _on_complete);
	document.location = document.location;
}

function showForm(_form_type, _answer_pid, _question_id, _page, _user_pid, _first_level_answer_pid){
	//if(!checkIsBanned()){
	//	return;
	//}	
	if(document.getElementById(_form_type+'_'+_answer_pid)){
		showHideForm(_form_type+'_'+_answer_pid);
		return;
	}
	ajax4('Comments&show_form=1&answer_pid='+_answer_pid+'&form_type='+_form_type+'&question_id='+_question_id+'&page='+_page+'&user_pid='+_user_pid+'&first_level_answer_pid='+_first_level_answer_pid, 'comments_form_div_for_answer_'+_answer_pid);
}

function showHideForm(_name){
	var obj = document.getElementById(_name);
	(obj.style.display == '') ? obj.style.display = 'none' : obj.style.display = '';
}

function plus(){
	if(!checkUser()){
		ajax4('ShortRegistration&show_form=reg_and_login&on_complete=showForm()', 'short_registration_ajax_div');
	}
	if(!checkIsBanned()){
		return;
	}
}

function minus(){
	if(!checkUser()){
		ajax4('ShortRegistration&show_form=reg_and_login&on_complete=showForm()', 'short_registration_ajax_div');
	}
	if(!checkIsBanned()){
		return;
	}
}

function submitComment(_id, _question_id, _page, _first_level_answer_pid){
	var sFormName = 'new_comment_form_' + _id;
	if(document.forms[sFormName].comment.value == ''){
		alert('Необходимо ввести тело ответа!');
		return false;
	}else{
		document.getElementById(_id).style.display="none";
		var onclick = '';
		onclick = disableButtonOnclick('new_comment_submit_button_'+_id);	
		ajax4('Comments&add_comment=1&parent_pid='+_id+'&comment='+urlencode(document.forms[sFormName].comment.value) + '&question_id='+_question_id+'&page='+_page+'&first_level_answer_pid='+_first_level_answer_pid, 'comments_ajax_div', 'enableButtonOnclick(\'new_comment_submit_button_'+_id+'\')');
	}
}

function submitDelete(_id, _question_id, _page, _user_pid){
	if (confirm("Вы уверены, что хотите удалить этот ответ?")) {
		ajax4('Comments&delete=1&answer_pid='+_id+'&user_pid='+_user_pid+'&page='+_page+'&question_id='+_question_id, 'comments_ajax_div');
	}
}

function submitComplain(_id, _question_id, _page){
	var sFormName = 'complain_form_' + _id;
	if(document.forms[sFormName].complain.value == ''){
		alert('Необходимо ввести тело ответа!');
		return false;
	}else{
		ajax4('Comments&complain=1&answer_pid='+_id+'&complain='+document.forms[sFormName].complain.value + '&question_id='+_question_id+'&page='+_page);
		showHideForm('complain_'+_id);
		alert('Ваше замечание добавлено!');
	}
}

function submitBlock(_id, _question_id, _page){
	var sFormName = 'block_form_' + _id;
	if(document.forms[sFormName].ban_reason.value == ''){
		alert('Необходимо ввести причину бана!');
		return false;
	}else{
		ajax4('Comments&block=1&answer_pid='+_id+'&ban_reason='+document.forms[sFormName].ban_reason.value + '&question_id='+_question_id+'&page='+_page+'&ban_time=' + document.forms[sFormName].ban_time.value + '&user_pid=' + document.forms[sFormName].user_pid.value);
		showHideForm('block_'+_id);
		alert('Пользователь заблокирован!');
	}
}

function questionShowForm(_form_type, _question_id, _user_pid){
	//if(!checkIsBanned()){
	//	return;
	//}	
	if(document.getElementById(_form_type+'_0')){
		showHideForm(_form_type+'_0');
		return;
	}
	ajax4('UserQuestionPage&show_form=1&form_type='+_form_type+'&question_id='+_question_id+'&user_pid='+_user_pid, 'comments_form_div_for_answer_0');
}

function questionSubmitComment(_question_id){
	var sFormName = 'new_comment_form_0';
	if(document.forms[sFormName].comment.value == ''){
		alert('Необходимо ввести тело ответа!');
		return false;
	}else{
		//var onclick = '';
		//onclick = disableButtonOnclick('new_comment_submit_button_0');
		ajax4('UserQuestionPage&add_comment=1&comment='+document.forms[sFormName].comment.value + '&question_id='+_question_id, 'comments_ajax_div', 'enableButtonOnclick(\'new_comment_submit_button_0\')');
	}
}

function questionSubmitDelete(_question_id, _user_pid){
	if (confirm("Вы уверены, что хотите удалить вопрос?")) {
		ajax4('UserQuestionPage&delete=1&user_pid='+_user_pid+'&question_id='+_question_id, 'comments_ajax_div');
	}
}

function questionSubmitComplain(_question_id){
	var sFormName = 'complain_form_0';
	if(document.forms[sFormName].complain.value == ''){
		alert('Необходимо ввести тело ответа!');
		return false;
	}else{
		//onclick = disableButtonOnclick('complain_submit_button_0');
		ajax4('UserQuestionPage&complain=1&complain='+document.forms[sFormName].complain.value + '&question_id='+_question_id);
		showHideForm('complain_0');
		alert('Ваше замечание добавлено!');
	}
}

function questionSubmitBlock(_id, _question_id){
	var sFormName = 'block_form_0';
	if(document.forms[sFormName].ban_reason.value == ''){
		alert('Необходимо ввести причину бана!');
		return false;
	}else{
		//onclick = disableButtonOnclick('block_submit_button_0');
		ajax4('UserQuestionPage&block=1&answer_pid='+_id+'&ban_reason='+document.forms[sFormName].ban_reason.value + '&question_id='+_question_id+'&ban_time=' + document.forms[sFormName].ban_time.value + '&user_pid=' + document.forms[sFormName].user_pid.value);
		showHideForm('block_0');
		alert('Пользователь заблокирован!');
	}
}

function disableButtonOnclick(_id){
	//var onclick = document.getElementById(_id).onclick; 
	//document.getElementById(_id).onclick="";
	document.getElementById(_id).style.display="none";
	//return onclick;
}

function enableButtonOnclick(_id){
	document.getElementById(_id).style.display="";
	//document.getElementById(_id).onclick=_onclick;
}

/* Экспертная зоня */

function expertZoneShowForm(_form_type, _question_id){
	if(document.getElementById(_form_type+'_0')){
		showHideForm(_form_type+'_0');
		return;
	}
	ajax4('QuestionPage&show_form=1&form_type='+_form_type+'&question_id='+_question_id, 'questionpage_form_div_for_answer_0');
}

function expertZoneSubmitComplain(_question_id){
	var sFormName = 'complain_form_0';
	if(document.forms[sFormName].complain.value == ''){
		alert('Необходимо ввести тело ответа!');
		return false;
	}else{
		//onclick = disableButtonOnclick('complain_submit_button_0');
		ajax4('QuestionPage&complain=1&&complain='+document.forms[sFormName].complain.value + '&question_id='+_question_id);
		showHideForm('complain_0');
		alert('Ваше замечание добавлено!');
	}	
}

function refreshComments(_question_id){
	sajax('Comments&question_id='+_question_id, 'comments_ajax_div');
}

function refreshUserQuestionPage(_question_id){
	sajax('UserQuestionPage&question_id='+_question_id, 'user_question_page_ajax_div');
}

function refreshQuestionPage(_question_id){
	sajax('QuestionPage&question_id='+_question_id, 'question_page_ajax_div');
}
