// JavaScript Document

//script para abrir popup
function OpenWindow(FileNameToOpen,janela,largura,altura)
{
newWindow = window.open(FileNameToOpen,janela, 'width='+largura+', height='+altura+', toolbar=no, scrollbars=yes, location=no, left=100, top=100')
if (newWindow.open)
{
newWindow.focus()
}
}

// Início do código de Aumentar/ Diminuir a letra
 
// Para usar coloque o comando: "javascript:mudaTamanho('tag_ou_id_alvo', -1);" para diminuir
// e o comando "javascript:mudaTamanho('tag_ou_id_alvo', +1);" para aumentar
 
var tagAlvo = new Array('p'); //pega todas as tags p//
 
// Especificando os possíveis tamanhos de fontes, poderia ser: x-small, small...
var tamanhos = new Array( '9px','10px','11px','12px','13px','14px','15px' );
var tamanhoInicial = 2;
 
function mudaTamanho( idAlvo,acao ){
  if (!document.getElementById) return
  var selecionados = null,tamanho = tamanhoInicial,i,j,tagsAlvo;
  tamanho += acao;
  if ( tamanho < 0 ) tamanho = 0;
  if ( tamanho > 6 ) tamanho = 6;
  tamanhoInicial = tamanho;
  if ( !( selecionados = document.getElementById( idAlvo ) ) ) selecionados = document.getElementsByTagName( idAlvo )[ 0 ];
  
  selecionados.style.fontSize = tamanhos[ tamanho ];
  
  for ( i = 0; i < tagAlvo.length; i++ ){
    tagsAlvo = selecionados.getElementsByTagName( tagAlvo[ i ] );
    for ( j = 0; j < tagsAlvo.length; j++ ) tagsAlvo[ j ].style.fontSize = tamanhos[ tamanho ];
  }
}

//script que rediciona as caixas de artigos
// Funcao que redireciona 
function navegaBoxGeral(url){
        if(url != ""){
        window.location.assign(url);
        } else {
        return false;
        }
}

function navegaBoxGeralBlank(url) {
	if(url != ""){
	window.open(url); 
    } else {
        return false;
    }	
}

// funcao de redirecionamento
function redirect(URLStr) { 

	var location = URLStr; 
	
	document.location.href=location;

}

// FORMULARIO PARA CADASTRO
function Formatar_Telefone(objeto,tammax,teclapres){

    var tecla = teclapres.keyCode;
    vr = objeto.value;
    vr = vr.replace( "(", "" );
    vr = vr.replace( ")", "" );
    vr = vr.replace( " ", "" );
    vr = vr.replace( "-", "" );
    tam = vr.length;

    if (tam < tammax && tecla != 8) {
            tam = vr.length + 1 ;
    }

    if (tecla == 8 ) {
            tam = tam - 1 ;
    }

    if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) {
            if ( tam <= 4 ) {
                     objeto.value = vr ;
            }
             if ( (tam > 4) && (tam <= 8) ) {
                     objeto.value = vr.substr(0,tam-4) + '-' + vr.substr( tam - 4, tam ) ;
            }
             if ( (tam >= 9) && (tam <= 10) ) {
                    objeto.value = '(' + vr.substr(0,2) + ') ' + vr.substr(2,tam-6) + '-' + vr.substr(tam-4,tam) ;
            }
    }
}

function Validar_Email(email){

    if(email.length < 6) {
            return false;
    }

    var x = 0;
    for (var c=0;c<email.length;c++) {
            if (email.substring(c,c+1) == '@') {
                    x = c;
            }
    }
    var y = 0;
    if (x > 0) {
            for (c=x;c<email.length;c++) {
                    if (email.substring(c,c+1)=='.') {
                            y = c;
                            var valida = 1;
                    }
            }
            if (y > 0) {
                    var dominio = '';
                    for (c=x;c<y;c++) {
                            dominio = dominio + email.substring(1,c);
                    }
            }
    }
    else {
            return false;
    }
    if (y <= x+2){
            return false;
    }
    if (valida == 1){
            return true;
    }
}


function Validar_Cadastro(){
    
	if (document.formCad.nome.value=="") {
            document.formCad.nome.focus();
            alert("Digite seu nome!");
            return false;
    }	
	
    if (document.formCad.email.value=="") {
            document.formCad.email.focus();
            alert("Informe o seu e-mail!");
            return false;
    } else {
            if (!Validar_Email(document.formCad.email.value)) {
                    document.formCad.email.focus();
                    alert("Digite um e-mail válido!");
                    return false;
            }
    }	        
	
	if (document.formCad.endereco.value=="") {
            document.formCad.endereco.focus();
            alert("Digite o nome da sua rua!");
            return false;
    }	
	
	if (document.formCad.n.value=="") {
            document.formCad.n.focus();
            alert("Digite o número da sua casa!");
            return false;
    }	
	          
	if (document.formCad.bairro.value=="") {
            document.formCad.bairro.focus();
            alert("Digite o nome do seu bairro!");
            return false;
    }	
			
	if (document.formCad.cidade.value=="") {
            document.formCad.cidade.focus();
            alert("Digite o nome da sua cidade!");
            return false;
    }	        		  
    
	if (document.formCad.senha01.value=="") {
            document.formCad.senha01.focus();
            alert("Digite a sua senha!");
            return false;
    }        
        
    
	if (document.formCad.senha02.value=="") {
            document.formCad.senha02.focus();
            alert("Confirme a sua senha!");
            return false;
    }  

	if (document.formCad.senha01.value!="" && document.formCad.senha02.value!="") {
        
		var senha01 = document.formCad.senha01.value;    
		var senha02 = document.formCad.senha02.value;
		
		if(senha01 != senha02) {
			document.formCad.senha01.focus();
            alert("As senhas não são iguais!");
            return false;
		}
    }                 
            
}


function Validar_EditCadastro(){
    
	if (document.formCad.nome.value=="") {
            document.formCad.nome.focus();
            alert("Digite seu nome!");
            return false;
    }	
	
    if (document.formCad.email.value=="") {
            document.formCad.email.focus();
            alert("Informe o seu e-mail!");
            return false;
    } else {
            if (!Validar_Email(document.formCad.email.value)) {
                    document.formCad.email.focus();
                    alert("Digite um e-mail válido!");
                    return false;
            }
    }	        
	
	if (document.formCad.endereco.value=="") {
            document.formCad.endereco.focus();
            alert("Digite o nome da sua rua!");
            return false;
    }	
	
	if (document.formCad.n.value=="") {
            document.formCad.n.focus();
            alert("Digite o número da sua casa!");
            return false;
    }	
            
	if (document.formCad.bairro.value=="") {
            document.formCad.bairro.focus();
            alert("Digite o nome do seu bairro!");
            return false;
    }	
			
	if (document.formCad.cidade.value=="") {
            document.formCad.cidade.focus();
            alert("Digite o nome da sua cidade!");
            return false;
    }	        		          
        
    if (document.formCad.senha01.value!="" || document.formCad.senha02.value!="") {
        
		var senha01 = document.formCad.senha01.value;    
		var senha02 = document.formCad.senha02.value;
		
		if(senha01 != senha02) {
			document.formCad.senha01.focus();
            alert("As senhas não são iguais!");
            return false;
		}
    }                 
            
}	

function Validar_Testemunho(){
    
	if (document.formCad.nome.value=="") {
            document.formCad.nome.focus();
            alert("Digite seu nome!");
            return false;
    }	
	
    if (document.formCad.email.value=="") {
            document.formCad.email.focus();
            alert("Informe o seu e-mail!");
            return false;
    } else {
            if (!Validar_Email(document.formCad.email.value)) {
                    document.formCad.email.focus();
                    alert("Digite um e-mail válido!");
                    return false;
            }
    }
	
	if (document.formCad.testemunho.value=="") {
            document.formCad.testemunho.focus();
            alert("Digite seu testemunho!");
            return false;
    }		
	
}

function Validar_Pergunta(){
    
	if (document.formCad.nome.value=="") {
            document.formCad.nome.focus();
            alert("Digite seu nome!");
            return false;
    }	
	
    if (document.formCad.email.value=="") {
            document.formCad.email.focus();
            alert("Informe o seu e-mail!");
            return false;
    } else {
            if (!Validar_Email(document.formCad.email.value)) {
                    document.formCad.email.focus();
                    alert("Digite um e-mail válido!");
                    return false;
            }
    }
	
	if (document.formCad.pergunta.value=="") {
            document.formCad.pergunta.focus();
            alert("Digite sua pergunta!");
            return false;
    }		
	
}
	