function cleanForm() {	
$('#form').resetForm();	
$("#perguntaCategoria").selected = 0;;
$("#perguntaCategoria_error").html("");	
$("#descricao_error").html("");	
$('#confirmacaoEnvioAjax').html('');
}
function validatePergunta() {
var validate = true;
if ($("#perguntaCategoria").val() == '' || $("#perguntaCategoria").val() == undefined ) {
$("#perguntaCategoria_error").html("<font color='red'><b>Obrigatorio</b></font>");
validate = false;
} else
$("#perguntaCategoria_error").html("");
if ($("#descricao").val() == '' || $("#descricao").val() == undefined || $("#descricao").val() == '... e o conteudo da pergunta.') {
$("#descricao_error").html("<font color='red'><b>Obrigatorio</b></font>");
validate = false;
} else
$("#descricao_error").html("");
if (validate)
enviarPergunta();
}
function showQuestionForm(){
$('#confirmacaoEnvioAjax').html('');	
$("#perguntaHide").fadeIn();
}
function hideQuestionForm(){
$("#perguntaHide").fadeOut();
}		
/********************************************|PERGUNTA|*****************************************/
function enviarPergunta() {
$.ajax( {
contentType : 'application/x-www-form-urlencoded; charset=ISO-8859-1',
type : "POST",
url : "?do=public/pergunta&action=insert",
data : $('#form').formSerialize(),
datatype : 'text',
onload : $("#confirmacaoEnvioAjax").html("<img src='pages/public/layout/images/loading.gif'>"),
success : function(msg) {
hideQuestionForm();
$("#confirmacaoEnvioAjax").html("<span><font color='green'>Pergunta enviada com sucesso.</font></span>");
$('#form').resetForm();
listarPerguntaAbertaAjax();
},
error : function(msg, ms2, ms3) {
//alert("ERROR function enviarPergunta");
}
});
}
function listarPerguntaAbertaAjax() {
$.ajax( {
type : "GET",
url : "?do=public/pergunta&action=listarPerguntaAbertaAjax",
data : '',
datatype : 'text',
success : function(msg) {
$("#listaPerguntaAbertaAjax").html(msg);
},
error : function(msg, ms2, ms3) {
//alert("ERROR function listarPerguntaAbertaAjax");
}
});
}
function listarPerguntaFechadaAjax() {
$.ajax( {
type : "GET",
url : "?do=public/pergunta&action=listarPerguntaFechadaAjax",
data : '',
datatype : 'text',
success : function(msg) {
$("#listaPerguntaFechadaAjax").html(msg);
},
error : function(msg, ms2, ms3) {
//alert("ERROR function listarPerguntaFechadaAjax");
}
});
}
function updatePerguntaAjax() {
var idPergunta = $("#idPergunta").val();
var param = "idPergunta=" + idPergunta;
$.ajax( {
contentType : 'application/x-www-form-urlencoded;charset=ISO-8859-1',
type : "POST",
url : "?do=public/pergunta&action=getPerguntaAjax",
data : param,
dataType : "text",
success : function(msg) {
$("#pergunta").val(msg);
},
error : function(msg, ms2, ms3) {
//alert("ERROR function updatePerguntaAjax");
}
});
}
/**********************************************||**************************************************/
/*************************************|PERGUNTA DESCRICAO|*****************************************/
function listarPerguntaDescricaoAjax() {
var idPergunta = $("#idPergunta").val();
var param = "idPergunta=" + idPergunta;
$.ajax( {
type : "POST",
url : "?do=public/pergunta&action=listarPerguntaDescricaoAjax",
data : param,
dataType : "text",
success : function(msg) {
$("#listaPerguntaDescricaoAjax").html(msg);
},
error : function(msg, ms2, ms3) {
//alert("ERROR function listarPerguntaDescricaoAjax");
}
});
}
function validatePerguntaDescricao() {
var validate = true;
if ($("#descricao").val() == '' || $("#descricao").val() == undefined) {
$("#descricao_error").html("<font color='red'><b>Obrigatorio</b></font>");
validate = false;
} else
$("#descricao_error").html("");
if (validate)
insertPerguntaDescricaoAjax();
}
function insertPerguntaDescricaoAjax() {
var idPergunta = $("#idPergunta").val();
var descricao = $("#descricao").val();
var param = "idPergunta=" + idPergunta + "&descricao=" + descricao;
$.ajax( {
type : "POST",
url : "?do=public/pergunta&action=insertPerguntaDescricaoAjax",
data : param,
dataType : "text",
onload: utilShowHide(),
success : function(msg) {
if (msg == 'aberta') {
$("#descricao").val("");
listarPerguntaDescricaoAjax();
} else
alert("Esta pergunta já está fechada!");

$("#msg_enviado").css('display','none');
$("#button_enviado").css('display','block');

},
error : function(msg, ms2, ms3) {
//alert("ERROR function salvarPerguntaDescricaoAjax");
}
});
}

function utilShowHide(){
	$("#button_enviado").css('display','none');
	$("#msg_enviado").css('display','block');	
}

function closePergunta(idPergunta) {
if (confirm("Deseja realmente encerrar esta pergunta?"))
window.location = '?do=public/pergunta&action=closePergunta&idPergunta='+idPergunta;
else
$("#descricao").focus();
}
function insertBreakLine(perguntaDescricao){
	perguntaDescricao.value += '<br>';
}
/**********************************************||**************************************************/
