function adicionaComentario() {
	
	var xmlhttp;
	if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } // code for IE7+, Firefox, Chrome, Opera, Safari
	else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } // code for IE6, IE5
	
	xmlhttp.onreadystatechange=function ac() {
		if(xmlhttp.readyState==4) {			
			if (xmlhttp.responseText == "Sucesso!") {
  				document.getElementById('texto_retorno').innerHTML="Sucesso!";
				listaComentarios();
				document.getElementById('botao_enviar').disabled='true';
			} else {
				document.getElementById('texto_retorno').innerHTML="Insucesso!";
			}
  		}
	}
	
	
	var url="../scriptsphp/accoesComentarios.php?tipo=workshops&accao=adicionar&comentario="+document.getElementById('comentario').value+"&nome="+document.getElementById('nome').value+"&email="+document.getElementById('email').value
	
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}


function toggleComentarios() {
	var obj=document.getElementById('todos_os_comentarios')
	
	if (obj.style.display == 'none') obj.style.display='table';
	else obj.style.display='none';
}


function listaComentarios() {
	
	var xmlhttp;
	if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } // code for IE7+, Firefox, Chrome, Opera, Safari
	else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } // code for IE6, IE5
	
	xmlhttp.onreadystatechange=function lc() {
		if(xmlhttp.readyState==4) { document.getElementById('lista_de_comentarios').innerHTML=xmlhttp.responseText; }
	}
	
	var url="../scriptsphp/accoesComentarios.php?tipo=workshops&accao=listar"
	
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	
}

function testaLimiteTextarea(obj, limite) {
	if (obj.value.length > limite) obj.value = obj.value.substring(0, limite);
	return true;
}

function validaAdicionaComentarioWorkshop() {
	var objAviso = document.getElementById('texto_retorno');
	if (document.forms[0].nome.value == "") { objAviso.innerHTML='Erro: Nome vazio'; return false; }
	if (document.forms[0].comentario.value == "") { objAviso.innerHTML='Erro: Comentário vazio'; return false; }
	//objAviso.innerHTML='';
	
	//adiciona comentario
	adicionaComentario();
	objAviso.innerHTML='A enviar...';
}