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 postComentario(id_post)
{
	var nome = getId('nome');
	var email = getId('email');
	var cidade = getId('cidade');
	var texto = getId('txtComentario');
	var blank = getId('blank');
	
	if(nome.value=='')
	{
		alert('Informe seu nome!');
		nome.focus();
		return false;
	}	
	if(!checkMail(email.value))
	{
		alert('Preencha seu email corretamente!');
		email.focus();
		return false;
	}
	if(cidade.value=='')
	{
		alert('Informe sua cidade!');
		cidade.focus();
		return false;
	}
	if(texto.value=='')
	{
		alert('Todos os campos devem ser preenchidos!');
		texto.focus();
		return false;
	}
	mostraId('enviando');
	xajax_postComentario(id_post, nome.value, email.value, cidade.value, texto.value, blank.value);
}

function mostraComentarios(id_post)
{
	mostraId('carregando');
	xajax_mostraComentarios(id_post);
}

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

function postMural()
{
	var nome = getId('nome');
	var email = getId('email');
	var cidade = getId('cidade');
	var texto = getId('txtComentario');
	var blank = getId('blank');
	
	if(nome.value=='')
	{
		alert('Informe seu nome!');
		nome.focus();
		return false;
	}	
	if(!checkMail(email.value))
	{
		alert('Preencha seu email corretamente!');
		email.focus();
		return false;
	}
	if(cidade.value=='')
	{
		alert('Informe sua cidade!');
		cidade.focus();
		return false;
	}
	if(texto.value=='')
	{
		alert('Todos os campos devem ser preenchidos!');
		texto.focus();
		return false;
	}
	mostraId('enviando');
	xajax_postMural(nome.value, email.value, cidade.value, texto.value, blank.value);
}

function mostraRecados(pagina)
{
	if(!pagina)
		pagina = 0;
	mostraId('carregando');
	xajax_mostraRecados(pagina);
}