jsnoticias = {
	idNoticia : 0,
	nome : '',
	email : '',
	site : '',
	comentario : '',
	
	enviar : function(pagina){
		this.limpaValidacao();
		msg = this.valida();
		if (msg == ''){
			noticias.enviarComentario(this.idNoticia, this.nome, this.email, this.site, this.comentario).value;
			document.getElementById('txtNomeComentario').value = '';
			document.getElementById('txtEmailComentario').value = '';
			document.getElementById('txtSiteComentario').value = '';
			document.getElementById('txtComentario').value = '';
			document.getElementById('divFormComentarios').style.display = 'none';
			document.getElementById('divComentarioSucesso').style.display = '';
		}
	},
	
	valida : function (){
		var msg = '';
		this.idNoticia = FuncoesGerais.BuscaParametro('n');
		this.nome = document.getElementById('txtNomeComentario').value;
		this.email = document.getElementById('txtEmailComentario').value;
		this.site = document.getElementById('txtSiteComentario').value;
		this.comentario = document.getElementById('txtComentario').value;

		if(this.nome == ''){
			msg = "Preencha o campo <b>Nome do Remetente</b>."
			document.getElementById('txtNomeComentario').className = "input error";
		}
		if(FuncoesGerais.ValidaEmail(this.email)==0){
			msg = "Preencha o campo <b>Email do Remetente</b> corretamente."
			document.getElementById('txtEmailComentario').className = "input error";
		}
		/*if(this.site == ''){
			msg = "Preencha o campo <b>Site</b>."
			document.getElementById('txtSiteComentario').className = "input error";
		}*/
		if(this.comentario == ''){
			msg = "Preencha o campo <b>Comentário</b> corretamente."
			document.getElementById('txtComentario').className = "error";
		}
		
		return msg;
	},
	
	limpaValidacao : function(){
		document.getElementById('txtNomeComentario').className = "input";
		document.getElementById('txtEmailComentario').className = "input";
		document.getElementById('txtSiteComentario').className = "input";
		document.getElementById('txtComentario').className = "";
	},
	
	abreForm : function(){
		document.getElementById('divComentarioSucesso').style.display = 'none';
		document.getElementById('divFormComentarios').style.display = '';
	},
	
	abreComentarios : function(){
		this.idNoticia = FuncoesGerais.BuscaParametro('n');
		
		document.getElementById('divConteudoComentarios').innerHTML = noticias.carregaComentarios(this.idNoticia, 1).value;
		if (document.getElementById('divConteudoComentarios').innerHTML == ''){
			document.getElementById('divConteudoComentarios').innerHTML = 'Não existem comentários';
		}else{
			document.getElementById('divTotalComentarios').innerHTML = document.getElementById('divTotComentarios').value;
			document.getElementById('divPgComentarios').innerHTML = noticias.carregaPaginacaoComentarios(document.getElementById('divTotPgComentarios').value, 1).value;

			document.getElementById('divPgComents').style.display = '';
		}
		document.getElementById('divComentarios').style.display = '';
	},
	
	pgComentarios : function(pagina){
		this.idNoticia = FuncoesGerais.BuscaParametro('n');
		
		document.getElementById('divConteudoComentarios').innerHTML = noticias.carregaComentarios(this.idNoticia, pagina).value;
		document.getElementById('divPgComentarios').innerHTML = noticias.carregaPaginacaoComentarios(document.getElementById('divTotPgComentarios').value, pagina).value;
	}
}
