// JavaScript Document

function checkMail(mail){
	var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
	if(typeof(mail) == "string"){
			if(er.test(mail)){ return true; }
	}else if(typeof(mail) == "object"){
			if(er.test(mail.value)){
									return true;
							}
	}else{
			return false;
			}
}

function somenteNumero(e){
	var tecla=(window.event)?event.keyCode:e.which;
	if((tecla > 47 && tecla < 58) || tecla == 0) return true;
	else{
	if (tecla != 8) return false;
	else return true;
	}
}


function getId(id) {
	return document.getElementById(id);
}

function mostraId(id)
{
	$("#"+id).show("fast");
}

function escondeId(id)
{
	$("#"+id).hide("fast");
}

function mostraEscondeId(id)
{
	if(getId(id).style.display=='none')
	{
		$("#"+id).show("fast");
	}
	else
	{
		$("#"+id).hide("fast");
	}
}


//==============================================================

function loginAluno()
{
	var login = document.getElementById('txtlogin');
	var senha = document.getElementById('txtsenha');
	if(login.value=='' || senha.value=='')
	{
		alert('Preencha login e senha!')
		{
			login.focus();
			return false;
		}
	}
	document.getElementById('verificando').style.display = 'block';
	xajax_loginAluno(login.value, senha.value);
}

function logoutAluno()
{
	xajax_logoutAluno();
}

//============================================================

function postComentario(id_licao)
{
	var bt = getId('bt_enviar');
	var comentario = getId('txt_comentario');
	if(comentario.value=='')
	{
		alert('Preencha o campo de texto!');
		comentario.focus();
		return false;
	}
	bt.disabled = true;
	bt.value = 'Aguarde. Enviando...';
	xajax_postComentario(id_licao, comentario.value);
}

function comentariosLicao(id_licao)
{
	getId('comentariosLicao').innerHTML = 'Carregando comentarios...';
	xajax_comentariosLicao(id_licao);
}

//============================================================

function postRecado()
{
	var para = getId('para');
	var texto = getId('txtRecado');
	if(para.value==''||para.value=='Para')
	{
		alert('Preencha para quem vai o recado.');
		para.focus();
		return false;
	}
	if(texto.value=='') 
	{
		alert('Preencha o campo da mensagem!');
		texto.focus();
		return false;
	}
	mostraId('enviando');
	xajax_postRecado(para.value, texto.value);
}