// Funções gerais


function toggleMe(a){
	var e=document.getElementById(a);
	if(!e) {
		 return true;
	}
	if((e.style.display=="none")||(e.style.display=="")){
		e.style.display="block"
	}
	else{
		e.style.display="none"
	}
	return true;
}

function toggleMeLoginEsqueci(a){
	if(a == 1){
		document.getElementById("divEsqueci").style.display="block"
		document.getElementById("divLogin").style.display="none"
	}
	else if(a == 2){
		document.getElementById("divEsqueci").style.display="none"
		document.getElementById("divLogin").style.display="block"
	}
	return true;
}

function ValidacaoEmail(value) {
 return (value == "" || value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) != -1);
}


function TiraValue(valor,campo){
	if(campo.value == valor){
		campo.value="";
	}
}

function ColocaValue(valor,campo){
	if(campo.value == ""){
		campo.value=valor;
	}
}

function validaNewsletter(formulario){
	if(formulario.desNome.value=="" || formulario.desNome.value=='seu nome'){
		alert("Por favor, preencha o campo 'Nome'.");
		formulario.desNome.focus();
		return false;
	}
	if(formulario.emlEmail.value==""){
		alert("Por favor, preencha o campo 'E-mail'.");
		formulario.emlEmail.focus();
		return false;
	}
	if(ValidacaoEmail(formulario.emlEmail.value)==""){
		alert("Por favor, preencha o campo: 'E-mail' corretamente.");
		formulario.emlEmail.focus();
		return false;
	}
	ajaxHTML("msg_newsletter", "ajaxEnviaNewsletter.php?desNome="+formulario.desNome.value+"&emlEmail="+formulario.emlEmail.value+"&codpraca="+formulario.codpraca.value);
	return false;
}


function validaComentario(formulario){
	if(formulario.desNome.value==""){
		alert("Por favor, preencha o campo 'Nome'.");
		formulario.desNome.focus();
		return false;
	}
	if(formulario.desIdade.value==""){
		alert("Por favor, preencha o campo 'Idade'.");
		formulario.desIdade.focus();
		return false;
	}
	if(formulario.emlEmail.value==""){
		alert("Por favor, preencha o campo 'E-mail'.");
		formulario.emlEmail.focus();
		return false;
	}
	if(ValidacaoEmail(formulario.emlEmail.value)==""){
		alert("Por favor, preencha o campo: 'E-mail' corretamente.");
		formulario.emlEmail.focus();
		return false;
	}
	if(formulario.desProfissao.value==""){
		alert("Por favor, preencha o campo 'Profissão'.");
		formulario.desProfissao.focus();
		return false;
	}
	if(formulario.texComentario.value==""){
		alert("Por favor, preencha o campo 'Comentário'.");
		formulario.texComentario.focus();
		return false;
	}
}

function validacadastroBdpraVC(formulario){
	if(formulario.desTitulo.value == ""){
		document.getElementById("desTitulo").className="campovazio";
		document.getElementById("desTitulo").focus();
		return false;
	}
	if(formulario.desCidade.value == ""){
		document.getElementById("desCidade").className="campovazio";
		document.getElementById("desCidade").focus();
		return false;
	}
	checado = false;
	for (i=0;i<formulario.arquivo.length;i++){ 
       if (formulario.arquivo[i].checked) {
		  checado = true;
          break; 
	   }
    }
	if(!checado){
		document.getElementById("comentarioArquivo").innerHTML = "selecione uma opção.";
		return false;
	}
	else{
		document.getElementById("comentarioArquivo").innerHTML = "";
		if(formulario.arquivo[i].value == "imagem"){
			if(formulario.uplImagem.value == ""){
				formulario.uplImagem.className="campovazio";
				formulario.uplImagem.focus();
				return false;
			}
		}
		else if(formulario.arquivo[i].value == "video"){
			if(formulario.uplVideo.value == ""){
				formulario.uplVideo.className="campovazio";
				formulario.uplVideo.focus();
				return false;
			}
		}
		else if(formulario.arquivo[i].value == "url"){
			if(formulario.urlYoutube.value == ""){
				formulario.urlYoutube.className="campovazio";
				formulario.urlYoutube.focus();
				return false;
			}
		}
	}
	if(formulario.texComentario.value == ""){
		document.getElementById("texComentario").className="campovazio";
		document.getElementById("texComentario").focus();
		return false;
	}
}

function validacadastroContato(formulario){
	if(formulario.desNome.value == ""){
		document.getElementById("desNome").className="campovazio";
		formulario.desNome.focus();
		return false;
	}
	if(formulario.emlEmail.value == ""){
		document.getElementById("emlEmail").className="campovazio";
		formulario.emlEmail.focus();
		return false;
	}
	if(ValidacaoEmail(formulario.emlEmail.value)==""){
		document.getElementById("emlEmail").className="campovazio";
		formulario.emlEmail.focus();
		return false;
	}
	if(formulario.texMensagem.value == ""){
		document.getElementById("texMensagem").className="campovazio";
		formulario.texMensagem.focus();
		return false;
	}
	return true;
}

function validaCadastroUsuario(formulario){
	if(formulario.desNome.value == ""){
		document.getElementById("desNome").className="campovazio";
		document.getElementById("desNome").focus();
		return false;
	}
	if(formulario.emlEmail.value == ""){
		document.getElementById("emlEmail").className="campovazio";
		document.getElementById("emlEmail").focus();
		return false;
	}
	if(ValidacaoEmail(formulario.emlEmail.value)==""){
		document.getElementById("emlEmail").className="campovazio";
		document.getElementById("emlEmail").focus();
		return false;
	}
	if(formulario.desSenha.value == ""){
		document.getElementById("desSenha").className="campovazio";
		document.getElementById("desSenha").focus();
		return false;
	}
	if(formulario.desConfirmaSenha.value == ""){
		document.getElementById("desConfirmaSenha").className="campovazio";
		document.getElementById("desConfirmaSenha").focus();
		return false;
	}
	if(formulario.desSenha.value != formulario.desConfirmaSenha.value){
		document.getElementById("desSenha").className="campovazio";
		document.getElementById("desSenha").focus();
		return false;
	}
	if(formulario.datDataNascimento.value == ""){
		document.getElementById("datDataNascimento").className="campovazio";
		document.getElementById("datDataNascimento").focus();
		return false;
	}
	if(formulario.desCEP.value == ""){
		document.getElementById("desCEP").className="campovazio";
		document.getElementById("desCEP").focus();
		return false;
	}
}

/*Função Pai das Mascaras*/
function Mascara(o,f){
	v_obj=o
	v_fun=f
	setTimeout("execmascara()",1)
}

/*Função que Executa os objetos*/
function execmascara(){
	v_obj.value=v_fun(v_obj.value)
}    

/*Função que permite apenas numeros*/
function Integer(v){
	return v.replace(/\D/g,"")
}

/*Função que permite apenas numeros*/
function Letter(v){
	return v.replace(/[0-9]/,"")
}

/*Função que padroniza CEP*/
function Cep(v){
	v=v.replace(/\D/g,"")
	v=v.replace(/^(\d{5})(\d)/,"$1-$2") 
	return v
}

/*Função que padroniza DATA*/
function Data(v){
	v=v.replace(/\D/g,"") 
	v=v.replace(/(\d{2})(\d)/,"$1/$2") 
	v=v.replace(/(\d{2})(\d)/,"$1/$2") 
	return v
}

function validaLogin(formulario){
	formulario = document.getElementById(formulario);

	if(formulario.emlEmailLogin.value == "" || formulario.emlEmailLogin.value == "e-mail"){
		document.getElementById("emlEmailLogin").className="campovazio";
		document.getElementById("emlEmailLogin").focus();
		return false;
	}
	if(ValidacaoEmail(formulario.emlEmailLogin.value)==""){
		document.getElementById("emlEmailLogin").className="campovazio";
		document.getElementById("emlEmailLogin").focus();
		return false;
	}
	if(formulario.desSenhaLogin.value == "" || formulario.desSenhaLogin.value == "senha"){
		document.getElementById("desSenhaLogin").className="campovazio";
		document.getElementById("desSenhaLogin").focus();
		return false;
	}

	formulario.submit();
}

function validaLogin2(formulario){
	if(formulario.emlEmailLogin.value == "" || formulario.emlEmailLogin.value == "e-mail"){
		formulario.emlEmailLogin.className="campovazio";
		formulario.emlEmailLogin.focus();
		return false;
	}
	if(ValidacaoEmail(formulario.emlEmailLogin.value)==""){
		formulario.emlEmailLogin.className="campovazio";
		formulario.emlEmailLogin.focus();
		return false;
	}
	if(formulario.desSenhaLogin.value == "" || formulario.desSenhaLogin.value == "senha"){
		formulario.desSenhaLogin.className="campovazio";
		formulario.desSenhaLogin.focus();
		return false;
	}

	formulario.submit();
}

function validaEsqueciSenha(formulario){
	formulario = document.getElementById(formulario);

	if(formulario.emlEmailSenha.value == "" || formulario.emlEmailSenha.value == "e-mail"){
		document.getElementById("emlEmailSenha").className="campovazio";
		document.getElementById("emlEmailSenha").focus();
		return false;
	}
	if(ValidacaoEmail(formulario.emlEmailSenha.value)==""){
		document.getElementById("emlEmailSenha").className="campovazio";
		document.getElementById("emlEmailSenha").focus();
		return false;
	}

	formulario.submit();
}

function toggleEsqueciSenha(){
	document.getElementById('login').style.display = "none";
	document.getElementById('esqueciSenha').style.display = "block";
}

function clearInput(input) {
	var elementInput = document.getElementById(input);

	if(elementInput.value == elementInput.defaultValue) {
		elementInput.value = "";
	}
}

function setInput(input) {
	var elementInput = document.getElementById(input);

	if(elementInput.value == elementInput.defaultValue || elementInput.value == "") {
		elementInput.value = elementInput.defaultValue;
	}
}

function submitForm(formulario) {
	document.getElementById(formulario).submit();
}

function tiraCampoVazio(id){
	document.getElementById(id).className="";
}

function campoArquivo(valorRadio){
	document.getElementById("comentarioArquivo").innerHTML = "";
	if(valorRadio == "imagem"){
		document.getElementById("boxImagem").style.display="block";
		document.getElementById("boxVideo").style.display="none";
		document.getElementById("boxUrl").style.display="none";
	}
	else if(valorRadio == "video"){
		document.getElementById("boxImagem").style.display="none";
		document.getElementById("boxVideo").style.display="block";
		document.getElementById("boxUrl").style.display="none";
	}
	else if(valorRadio == "url"){
		document.getElementById("boxImagem").style.display="none";
		document.getElementById("boxVideo").style.display="none";
		document.getElementById("boxUrl").style.display="block";
	}
}
	

function doisDigitosRelogio(value) {
	return (value > 9) ? "" + value : "0" + value;
}

function atualizaRelogio(){ 
    momentoAtual = new Date();
	
    hora = momentoAtual.getHours();
    minuto = momentoAtual.getMinutes(); 

    relogio = doisDigitosRelogio(hora) + ":" + doisDigitosRelogio(minuto);
	
	if(document.getElementById('relogio')) {
	    document.getElementById('relogio').innerHTML = relogio;
	}

	setTimeout("atualizaRelogio()",1000) 
}

/*
Funções para chamar AJAX
*****************************************************************************/

function ajaxEnviaNews(idobj, endereco){
	ajaxHTML(idobj, endereco);
}


function ajaxNota(nota, cod, tabela){
	ajaxHTML("votoComentario"+cod, "ajaxRatingStar.php?cod="+cod+"&nota="+nota+"&tabela="+tabela);
}


/*
Funções da ENQUETE
*****************************************************************************/

function toggleMeEnquete(a,b){
	var e=document.getElementById(a);
	var f=document.getElementById(b);
	if((!e)||(!f)) {
		 return true;
	}
	if(e.style.display=="none"){
		e.style.display="block"
		f.style.display="none"
	}
	else{
		e.style.display="none"
		f.style.display="block"
	}
	return true;
	document.geElementById("verificaVoto").innerHTML="";
}

function envia_enquete(codenquete){
	form 			= document.forms[1];
	totRespostas 	= document.enquete.radiobutton.length;
	valorChecado	= false;
	for(i=0; i<totRespostas; i++){
		if(document.enquete.elements["radiobutton"][i].checked){
			valorChecado = true;
			break;
		}
	}//for
	if(!valorChecado){
		alert("Por favor, selecione uma das opções de resposta.");
	}
	else{
		cod = acharadio();
	    ajaxHTML('verificaVoto', 'ajaxGravaEnquete.php?codresposta=' + cod + '&codenquete=' + codenquete + '&' + Math.ceil(Math.random()*1000));
		ajaxHTML('resEnquete', 'ajaxResultadoEnquete.php?codenquete=' + codenquete + '&' + Math.ceil(Math.random()*1000));
		for(i=0; i<totRespostas; i++){
			document.enquete.elements["radiobutton"][i].checked = false;
		}//for
	}
}

function acharadio(){
  for(i=0;i<5;i++){
    if(document.enquete.radiobutton[i].checked){
	  return document.enquete.radiobutton[i].value;
	}
  }
}

/*
Funções Compartilhar
*****************************************************************************/

function ToggleCompartilhar(id) { 
	if (document.getElementById(id)){
		if (document.getElementById(id).style.display=='block') {
			document.getElementById(id).style.display='none'
		}
		else {
			document.getElementById(id).style.display='block'
		}
	}
}


function validaEnviaNews(){
	if(document.formEnviaNews.seunome.value==""){
		alert("Por favor, preencha o campo: 'Seu Nome'.");
		document.formEnviaNews.seunome.focus();
		return false;
	}
	if(document.formEnviaNews.seuemail.value==""){
		alert("Por favor, preencha o campo: 'Seu e-mail'.");
		document.formEnviaNews.seuemail.focus();
		return false;
	}
	if(ValidacaoEmail(document.formEnviaNews.seuemail.value)==""){
		alert("Por favor, preencha o campo: 'Seu e-mail' corretamente.");
		document.formEnviaNews.seuemail.focus();
		return false;
	}
	if(document.formEnviaNews.destinatario.value==""){
		alert("Por favor, preencha o campo: 'Destinatário'.");
		document.formEnviaNews.destinatario.focus();
		return false;
	}
	if(document.formEnviaNews.emaildestinatario.value==""){
		alert("Por favor, preencha o campo: 'E-mail'.");
		document.formEnviaNews.emaildestinatario.focus();
		return false;
	}
	if(ValidacaoEmail(document.formEnviaNews.emaildestinatario.value)==""){
		alert("Por favor, preencha o campo: 'E-mail' corretamente.");
		document.formEnviaNews.emaildestinatario.focus();
		return false;
	}
	var url = 'ajaxEnviaNews.php?seunome='+document.formEnviaNews.seunome.value+
								'&seuemail='+document.formEnviaNews.seuemail.value+
								'&destinatario='+document.formEnviaNews.destinatario.value+
								'&emaildestinatario='+document.formEnviaNews.emaildestinatario.value+
								'&endereco_pag='+document.formEnviaNews.endereco_pag.value;

	ajaxHTML('div_compartilhar', url);
	return false;
}