// JavaScript Document

	//_# FUNÇÃO TRIM #_
	function Trim(str){return str.replace(/^\s+|\s+$/g,"");}
	//_#
	
	//_# FUNÇÕES DE FOCUS #_
	function eskemaFocos(obj){
		trimed = Trim(obj.value);
		if (trimed == Trim(obj.defaultValue)){
			obj.value = "";
		}
	}
	
	function eskemaBlur(obj){
		trimed = Trim(obj.value);
		if (trimed == ''){
			obj.value = obj.defaultValue;
		}
	}
	//_#
	
	//_# CHECA E-MAIL VÁLIDO (TRUE | FALSE) #_
	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;
			}
	}
	
	$(document).ready(function(){
							   
 		$(".foco").focus(function(){
			eskemaFocos(this);			  
		});
		$(".foco").blur(function(){
			eskemaBlur(this);			  
		});
		
		$("#enviarNews").click(function(){
			if ( !checkMail($("#email").val()) ){
				alert('Favor preencher o campo E-Mail corretamente!');
				$("#email").focus();
			}else {
				document.newsletterForm.submit();
			}
		});
		
		carrega();				
	});
	
	//_# FUNÇÃO QUE CARREGA MAIS COMENTÁRIOS QUANDO CLICA NO BOTÃO, DEPOIS DO AJAX ELE CHAMA A PRÓPRIA FUNÇÃO PRA ATUALIZAR O EVENT HANDLER (ONCLICK) PRO NOVO BOTAO Q VEIO DO AJAX
	function carrega(){
		$("#more").click(function(){
			count++;
			$(".mais5").remove();
			
			$.post("ajax/ajax.php?funcao=coments", { limit : count }, function(retorno){
				$("#comentUL").append(retorno);
				carrega();
			});
		});
	}
	//_#
	
	var count = 0; //_# VARIAVEL UTILIZADA PARA SOMAR QUANTAS VEZES CLICOU EM ABIR MAIS 5 COMENTARIOS

	function validaComentarios() {
		if ( $("#nomeComent").val() == '' || $("#nomeComent").val() == 'Nome...' ){
			alert('Favor preencher o campo Nome!');
			$("#nomeComent").focus();
			return false;
		}else if ( !checkMail($("#emailComent").val()) ){
			alert('Favor preencher o campo E-Mail corretamente!');
			$("#emailComent").focus();
			return false;
		}else if ( $("#comentarioComent").val() == '' || $("#comentarioComent").val() == 'Comentário...' ){
			alert('Favor preencher o campo Comentário!');
			$("#comentarioComent").focus();
			return false;
		}
		return true;
	}

	function validaContato() {
		if ( $("#nome").val() == '' || $("#nome").val() == 'Nome...' ){
			alert('Favor preencher o campo Nome!');
			$("#nome").focus();
			return false;
		}else if ( !checkMail($("#emailcontato").val()) ){
			alert('Favor preencher o campo E-Mail corretamente!');
			$("#emailcontato").focus();
			return false;
		}else if ( $("#comentario").val() == '' || $("#comentario").val() == 'Comentário...' ){
			alert('Favor preencher o campo Comentário!');
			$("#comentario").focus();
			return false;
		}
		return true;
	}
