﻿function efeito(id, img){
    id.style.background = "url(imagens/"+img+"_h.jpg) center no-repeat";
}

function exEfeito(id, img){
    id.style.background = "url(imagens/"+img+".jpg) center no-repeat";
}

function selecione(id){
    id = document.getElementById(id);
    
    if(id.style.display == "none")
        id.style.display = "block";
    else
        id.style.display = "none";
}

function alterar(elemento){
    id = document.getElementById("categoria1");
    id.value = elemento;
    
    selecione("opcoes");
    document.getElementById("opcoes").style.display = "none";
}

function alterarOrd(elemento, opcoes, ordenacao){
    id = document.getElementById(ordenacao);
    id.value = elemento;
    
    selecione(opcoes);
}

// ao clicar no documento chama a função evento
document.onclick=evento;

// função evento, o e representa o evento que chamou ela, ou seja, o click
function evento(e){

    // definindo target
    // (e && e.target) para FF
    // (event && event.srcElement) para IE
    var target = (e && e.target) || (event && event.srcElement);

    //categorias busca principal
    var obj = document.getElementById('opcoes');

    var obj2 = document.getElementById('selecione');
    var obj3 = document.getElementById('categoria1');

    checkParent(target)?obj.style.display='none':null;

    target==obj2?obj.style.display='block':null;    
    target==obj3?obj.style.display='block':null;  
    
    //primeira ordenacao
    var obj = document.getElementById('opcoes-ordenacao');

    var obj2 = document.getElementById('selecione2');
    var obj3 = document.getElementById('ordenacao');

    checkParent(target)?obj.style.display='none':null;

    target==obj2?obj.style.display='block':null;    
    target==obj3?obj.style.display='block':null;    
    
    //segunda ordenacao
    var obj = document.getElementById('opcoes-ordenacao2');

    var obj2 = document.getElementById('selecione3');
    var obj3 = document.getElementById('ordenacao2');

    checkParent(target)?obj.style.display='none':null;

    target==obj2?obj.style.display='block':null;    
    target==obj3?obj.style.display='block':null;    
}

function checkParent(t){
    while(t.parentNode){
        if(t==document.getElementById('opcoes-ordenacao')){
        return false
    }
    t=t.parentNode
}
    return true
}

function alteraImg(elemento){
    document.getElementById("img-principal").src = "produtos/2_" + elemento;
    document.getElementById("img-principal").alt = "produtos/3_" + elemento;
}

function limpa(elemento, valor){
    if(elemento.value == valor)
        elemento.value = "";
    else{
        if(elemento.value == "")
            elemento.value = valor;
    }
}


function divVermelha(elemento){  
    document.getElementById("img"+elemento).src = "imagens/seta_menu_h.png";

}

function divBranca(elemento){  
    document.getElementById("img"+elemento).src = "imagens/seta_menu.png";
}

function validaFale(){

	d = document.contato;
	if (d.nome.value == "")
	{
		alert("Preencha o campo Nome!");
		d.nome.focus();
		return false;	
	}
    
	if (d.tel.value == "")
	{
		alert("Preencha o campo Telefone!");
		d.tel.focus();
		return false;	
	}
    
    	if (d.estado.value == "")
	{
		alert("Preencha o campo Estado!");
		d.estado.focus();
		return false;	
	}
	
	
		var str = d.emailamigo.value;
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		
		if (str.indexOf(at)==-1){
		   alert("Email Inválido!")
       	   d.email.focus();
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Email Inválido!")
       	   d.email.focus();
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   alert("Email Inválido!")
       	   d.email.focus();
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   alert("Email Inválido!")
       	   d.email.focus();
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   alert("Email Inválido!")
       	   d.email.focus();
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   alert("Email Inválido!")
       	   d.email.focus();
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		   alert("Email Inválido!")
       	   d.email.focus();
		    return false
		 }
		 
		 
    if (d.cidade.value == "")
	{
		alert("Preencha o campo Cidade!");
		d.cidade.focus();
		return false;	
	}
	

	if (d.assunto.value == "")
	{
		alert("Preencha o campo Assunto!");
		d.assunto.focus();
		return false;	
	}

	if (d.comentarios.value == "")
	{
		alert("Preencha o campo Mensagem!");
		d.comentarios.focus();
		return false;	
	}

	else
		return true;
	
}

function abreDiv(elemento){
    
    if 
        (document.getElementById(elemento).style.display == "none")
            document.getElementById(elemento).style.display = "block";
    else
        document.getElementById(elemento).style.display = "none";
        
}

function limpaEmail(elemento){
	if(elemento.value == "Digite seu e-mail...")
		elemento.value = "";
}

function retornaEmail(elemento){
	if(elemento.value == "")
		elemento.value = "Digite seu e-mail...";
}

//Formato os campos com moeda

function formataMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;    
    // 13=enter, 8=backspace as demais retornam 0(zero)
    // whichCode==0 faz com que seja possivel usar todas as teclas como delete, setas, etc    
    if ((whichCode == 13) || (whichCode == 0) || (whichCode == 8))
    	return true;
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
 
 
    if (strCheck.indexOf(key) == -1) 
    	return false; // Chave inválida
    len = objTextBox.value.length;
    for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != 

SeparadorDecimal)) 
        	break;
    aux = '';
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) 
        	aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) 
    	objTextBox.value = '';
    if (len == 1) 
    	objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 2) 
    	objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += SeparadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        	objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
    }
    return false;
}
//Fim Formato os campos com moeda



function validaArquitetos(){

	d = document.cadArquitetos;
	if (d.nome.value == "")
	{
		alert("Preencha o campo Nome!");
		d.nome.focus();
		return false;	
	}
    
	if (d.endereco.value == "")
	{
		alert("Preencha o campo Endereço!");
		d.endereco.focus();
		return false;	
	}
    
    	if (d.estado.value == "")
	{
		alert("Preencha o campo Estado!");
		d.estado.focus();
		return false;	
	}
	
	
		var str = d.email.value;
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		
		if (str.indexOf(at)==-1){
		   alert("Email Inválido!")
       	   d.email.focus();
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Email Inválido!")
       	   d.email.focus();
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   alert("Email Inválido!")
       	   d.email.focus();
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   alert("Email Inválido!")
       	   d.email.focus();
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   alert("Email Inválido!")
       	   d.email.focus();
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   alert("Email Inválido!")
       	   d.email.focus();
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		   alert("Email Inválido!")
       	   d.email.focus();
		    return false
		 }
		 
		 
    if (d.cidade.value == "")
	{
		alert("Preencha o campo Cidade!");
		d.cidade.focus();
		return false;	
	}
	

	if (d.bairro.value == "")
	{
		alert("Preencha o campo Bairro!");
		d.bairro.focus();
		return false;	
	}

	if (d.cep.value == "")
	{
		alert("Preencha o campo CEP!");
		d.cep.focus();
		return false;	
	}
	
	if (d.tel.value == "")
	{
		alert("Preencha o campo Telefone!");
		d.tel.focus();
		return false;	
    }
	else
		return true;
	
}



function validaIndique(d){

	d = document.indique;
	if (d.nome.value == "")
	{
		alert("Preencha o campo Seu Nome!");
		d.nome.focus();
		return false;	
	}
    
		
		var str = d.email.value;
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		
		if (str.indexOf(at)==-1){
		   alert("Email Inválido!")
       	   d.email.focus();
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Email Inválido!")
       	   d.email.focus();
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   alert("Email Inválido!")
       	   d.email.focus();
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   alert("Email Inválido!")
       	   d.email.focus();
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   alert("Email Inválido!")
       	   d.email.focus();
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   alert("Email Inválido!")
       	   d.email.focus();
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		   alert("Email Inválido!")
       	   d.email.focus();
		    return false
		 }
		 
		 
    if (d.nomeamigo.value == "")
	{
		alert("Preencha o campo Nome do Amigo!");
		d.nomeamigo.focus();
		return false;	
	}
	

	var str = d.emailamigo.value;
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		
		if (str.indexOf(at)==-1){
		   alert("Email Inválido!")
       	   d.emailamigo.focus();
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Email Inválido!")
       	   d.emailamigo.focus();
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   alert("Email Inválido!")
       	   d.emailamigo.focus();
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   alert("Email Inválido!")
       	   d.emailamigo.focus();
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   alert("Email Inválido!")
       	   d.emailamigo.focus();
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   alert("Email Inválido!")
       	   d.emailamigo.focus();
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		   alert("Email Inválido!")
       	   d.emailamigo.focus();
		    return false
		 }
		 
	else
		return true;
	
}