﻿function ExibirIndique(){
    var arrayPageSize = getPageSize();
    var arrayPageScroll = getPageScroll();
    var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 4);
    document.getElementById('div_indique').style.top = lightboxTop+"px";
    document.getElementById('div_indique').style.zIndex = 999999;
    document.getElementById('div_indique').style.display = '';
}

function ExibirProposta()
{
    var arrayPageSize = getPageSize();
    var arrayPageScroll = getPageScroll();
    var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 4);
    document.getElementById('div_proposta').style.top = lightboxTop+"px";
    document.getElementById('div_proposta').style.zIndex = 999999;
    document.getElementById('div_proposta').style.display = '';
}

function Fechar(quem)
{
    document.getElementById(quem).style.display = 'none';
    
    if(quem == 'div_indique')
    {
        LimparDadosIndique();
    }
    else{
        LimparDadosProposta();
    }
    
}

function LimparDadosIndique()
{
    //Fazendo que estes itens fiquem sempre vísiveis - Indique.
    document.getElementById('div_conteudo_indique').style.display='';
    document.getElementById('enviar_indique').style.display = '';
    document.getElementById('sucesso_indique').style.display = 'none';  
    document.getElementById('erro_indique').style.display = 'none';  
    
    document.getElementById('anuncio_nome').value = '';
    document.getElementById('anuncio_email').value = '';
    document.getElementById('email_amigo').value = '';
    document.getElementById('nome_amigo').value = '';
    
    document.getElementById('anuncio_nome').className = 'txtfield';
    document.getElementById('erroanuncio_nome').style.display = 'none';
    
    document.getElementById('anuncio_email').className = 'txtfield';
    document.getElementById('erroanuncio_email').style.display = 'none';
    
    document.getElementById('nome_amigo').className = 'txtfield';
    document.getElementById('erronome_amigo').style.display = 'none';
    
    document.getElementById('email_amigo').className = 'txtfield';
    document.getElementById('erroemail_amigo').style.display = 'none';
}

function LimparDadosProposta()
{
    //Fazendo que estes itens fiquem sempre vísiveis - Indique.
    document.getElementById('div_conteudo_proposta').style.display='';
    document.getElementById('enviar_proposta').style.display = '';
    document.getElementById('sucesso_proposta').style.display = 'none';  
    document.getElementById('erro_proposta').style.display = 'none';  
    
    document.getElementById('proposta_nome').value = '';
    document.getElementById('proposta_email').value = '';
    document.getElementById('proposta_telefone').value = '';
    document.getElementById('proposta_descricao').value = '';
    document.getElementById('proposta_descricao').value = '';
    document.getElementById('proposta_financiamento').checked = false;
    document.getElementById('proposta_troca_veiculo').checked = false;
    
    document.getElementById('proposta_nome').className = 'txtfield';
    document.getElementById('erroproposta_nome').style.display = 'none';
    
    document.getElementById('proposta_email').className = 'txtfield';
    document.getElementById('erroproposta_email').style.display = 'none';
    
    document.getElementById('proposta_telefone').className = 'txtfield';
    document.getElementById('erroproposta_telefone').style.display = 'none';
    
    document.getElementById('proposta_descricao').className = 'txtfield';
    document.getElementById('erroproposta_descricao').style.display = 'none';
    
}

function FazerProposta()
{
    var sucesso = true;
    
    document.getElementById('proposta_nome').className = 'txtfield';
    document.getElementById('erroproposta_nome').style.display = 'none';
    
    document.getElementById('proposta_email').className = 'txtfield';
    document.getElementById('erroproposta_email').style.display = 'none';
    
    document.getElementById('proposta_telefone').className = 'txtfield';
    document.getElementById('erroproposta_telefone').style.display = 'none';
    
    document.getElementById('proposta_descricao').className = 'txtfield';
    document.getElementById('erroproposta_descricao').style.display = 'none';
    
    if(EmptyField(document.getElementById('proposta_nome')))
    {
        sucesso = false;
        document.getElementById('proposta_nome').className = 'error';
        document.getElementById('erroproposta_nome').style.display = '';
        document.getElementById('erroproposta_nome').innerHTML = 'Por favor informe seu nome.';  
    }
    
    if(EmptyField(document.getElementById('proposta_email')))
    {
        sucesso = false;
        document.getElementById('proposta_email').className = 'error';
        document.getElementById('erroproposta_email').style.display = '';
        document.getElementById('erroproposta_email').innerHTML = 'Por favor informe seu e-mail.';  
    }
    else
    {
      if(!valida_email(document.getElementById('proposta_email')))
      {
        sucesso = false;
        document.getElementById('proposta_email').className = 'error';
        document.getElementById('erroproposta_email').style.display = '';
        document.getElementById('erroproposta_email').innerHTML = 'E-mail inválido.';  
      }
    }
    
    if(EmptyField(document.getElementById('proposta_telefone')))
    {
        sucesso = false;
        document.getElementById('proposta_telefone').className = 'error';
        document.getElementById('erroproposta_telefone').style.display = '';
        document.getElementById('erroproposta_telefone').innerHTML = 'Por favor informe seu e-mail.';  
    }
    else
    {
      if(!valida_telefone(document.getElementById('proposta_telefone')))
      {
        sucesso = false;
        document.getElementById('proposta_telefone').className = 'error';
        document.getElementById('erroproposta_telefone').style.display = '';
        document.getElementById('erroproposta_telefone').innerHTML = 'Telefone inválido.';  
      }
    }
    if(EmptyField(document.getElementById('proposta_descricao')))
    {
        sucesso = false;
        document.getElementById('proposta_descricao').className = 'error';
        document.getElementById('erroproposta_descricao').style.display = '';
        document.getElementById('erroproposta_descricao').innerHTML = 'Por favor faça a sua proposta.';  
    }
    
    if(!sucesso)
    {
        alert('Alguns campos não foram preenchidos da forma devida. Por favor verifique os campos em destaque.'); 
        return false;
    }
    
    var proposta_nome = document.getElementById('proposta_nome').value;
    var proposta_email = document.getElementById('proposta_email').value;
    var proposta_telefone = document.getElementById('proposta_telefone').value;
    var proposta_descricao = document.getElementById('proposta_descricao').value;
    var proposta_financiamento = document.getElementById('proposta_financiamento').checked;
    var proposta_troca_veiculo = document.getElementById('proposta_troca_veiculo').checked;
    
    var email_dono_veiculo = document.getElementById('hd_email').value;
    var nome_dono_veiculo = document.getElementById('hd_nomeProprietario').value;
    
    var veiculo = document.getElementById('hd_veiculo').value;
    
    var retornoAjax = detalhe_veiculo.FazerProposta(parseInt(veiculo),email_dono_veiculo,nome_dono_veiculo,proposta_nome,proposta_email,proposta_telefone,proposta_descricao,proposta_financiamento,proposta_troca_veiculo).value;
    
    if(retornoAjax)
    {
        document.getElementById('div_conteudo_proposta').style.display='none';
        document.getElementById('enviar_proposta').style.display = 'none';
        document.getElementById('sucesso_proposta').style.display = 'block';            
    }
    else
    {
        document.getElementById('div_conteudo_proposta').style.display='none';
        document.getElementById('enviar_proposta').style.display = 'none';
        document.getElementById('sucesso_proposta').style.display = 'block';
    }
}


function FazerProposta2()
{
    var sucesso = true;
    
    document.getElementById('proposta_nome2').className = 'txtfield';
    document.getElementById('erroproposta_nome2').style.display = 'none';

    document.getElementById('proposta_email2').className = 'txtfield';
    document.getElementById('erroproposta_email2').style.display = 'none';

    document.getElementById('proposta_telefone2').className = 'txtfield';
    document.getElementById('erroproposta_telefone2').style.display = 'none';

    document.getElementById('proposta_descricao2').className = 'txtfield';
    document.getElementById('erroproposta_descricao2').style.display = 'none';

    if(EmptyField(document.getElementById('proposta_nome2')))
    {
        sucesso = false;
        document.getElementById('proposta_nome2').className = 'error';
        document.getElementById('erroproposta_nome2').style.display = '';
        document.getElementById('erroproposta_nome2').innerHTML = 'Por favor informe seu nome.';  
    }
    if(EmptyField(document.getElementById('proposta_email2')))
    {
        sucesso = false;
        document.getElementById('proposta_email2').className = 'error';
        document.getElementById('erroproposta_email2').style.display = '';
        document.getElementById('erroproposta_email2').innerHTML = 'Por favor informe seu e-mail.';  
    }
    else
    {
      if(!valida_email(document.getElementById('proposta_email2')))
      {
        sucesso = false;
        document.getElementById('proposta_email2').className = 'error';
        document.getElementById('erroproposta_email2').style.display = '';
        document.getElementById('erroproposta_email2').innerHTML = 'E-mail inválido.';  
      }
    }
    if(EmptyField(document.getElementById('proposta_telefone2')))
    {
        sucesso = false;
        document.getElementById('proposta_telefone2').className = 'error';
        document.getElementById('erroproposta_telefone2').style.display = '';
        document.getElementById('erroproposta_telefone2').innerHTML = 'Por favor informe seu e-mail.';  
    }
    else
    {
      if(!valida_telefone(document.getElementById('proposta_telefone2')))
      {
        sucesso = false;
        document.getElementById('proposta_telefone2').className = 'error';
        document.getElementById('erroproposta_telefone2').style.display = '';
        document.getElementById('erroproposta_telefone2').innerHTML = 'Telefone inválido.';  
      }
    }
    if(EmptyField(document.getElementById('proposta_descricao2')))
    {
        sucesso = false;
        document.getElementById('proposta_descricao2').className = 'error';
        document.getElementById('erroproposta_descricao2').style.display = '';
        document.getElementById('erroproposta_descricao2').innerHTML = 'Por favor faça a sua proposta.';  
    }
   
    
    if(!sucesso)
    {
        alert('Alguns campos não foram preenchidos da forma devida. Por favor verifique os campos em destaque.'); 
        return false;
    }
    
    var proposta_nome = document.getElementById('proposta_nome2').value;
    var proposta_email = document.getElementById('proposta_email2').value;
    var proposta_telefone = document.getElementById('proposta_telefone2').value;
    var proposta_descricao = document.getElementById('proposta_descricao2').value;
    
    //var proposta_financiamento = document.getElementById('proposta_financiamento2').checked;
    //var proposta_troca_veiculo = document.getElementById('proposta_troca_veiculo2').checked;
    
    var proposta_financiamento = false;
    var proposta_troca_veiculo = false;
    
    var email_dono_veiculo = document.getElementById('hd_email').value;
    var nome_dono_veiculo = document.getElementById('hd_nomeProprietario').value;
    
    var veiculo = document.getElementById('hd_veiculo').value;
    
    var retornoAjax = detalhe_veiculo.FazerProposta(parseInt(veiculo),email_dono_veiculo,nome_dono_veiculo,proposta_nome,proposta_email,proposta_telefone,proposta_descricao,proposta_financiamento,proposta_troca_veiculo).value;

    if(retornoAjax)
    {
   		document.getElementById('div_conteudo_proposta2').style.display='none';
        //document.getElementById('enviar_proposta2').style.display = 'none';
        document.getElementById('sucesso_proposta2').style.display = 'block';
    }
    else
    {
        document.getElementById('div_conteudo_proposta2').style.display='none';
        //document.getElementById('enviar_proposta2').style.display = 'none';
        document.getElementById('erro_proposta2').style.display = 'block';
    }
    return false;   
    
}




function IndicarAnuncio()
{
    var sucesso = true;
    
    document.getElementById('anuncio_nome').className = 'txtfield';
    document.getElementById('erroanuncio_nome').style.display = 'none';
    
    document.getElementById('anuncio_email').className = 'txtfield';
    document.getElementById('erroanuncio_email').style.display = 'none';
    
    document.getElementById('nome_amigo').className = 'txtfield';
    document.getElementById('erronome_amigo').style.display = 'none';
    
    document.getElementById('email_amigo').className = 'txtfield';
    document.getElementById('erroemail_amigo').style.display = 'none';
    
    if(EmptyField(document.getElementById('anuncio_nome')))
    {
        sucesso = false;
        document.getElementById('anuncio_nome').className = 'error';
        document.getElementById('erroanuncio_nome').style.display = '';
        document.getElementById('erroanuncio_nome').innerHTML = 'Por favor informe seu nome.';  
    }
    if(EmptyField(document.getElementById('anuncio_email')))
    {
        sucesso = false;
        document.getElementById('anuncio_email').className = 'error';
        document.getElementById('erroanuncio_email').style.display = '';
        document.getElementById('erroanuncio_email').innerHTML = 'Por favor informe seu e-mail.';  
    }
    else
    {
      if(!valida_email(document.getElementById('anuncio_email')))
      {
        sucesso = false;
        document.getElementById('anuncio_email').className = 'error';
        document.getElementById('erroanuncio_email').style.display = '';
        document.getElementById('erroanuncio_email').innerHTML = 'E-mail inválido.';  
      }
    }
    
    if(EmptyField(document.getElementById('nome_amigo')))
    {
        sucesso = false;
        document.getElementById('nome_amigo').className = 'error';
        document.getElementById('erronome_amigo').style.display = '';
        document.getElementById('erronome_amigo').innerHTML = 'Por favor informe o nome do seu amigo.';  
    }
    
    if(EmptyField(document.getElementById('email_amigo')))
    {
        sucesso = false;
        document.getElementById('email_amigo').className = 'error';
        document.getElementById('erroemail_amigo').style.display = '';
        document.getElementById('erroemail_amigo').innerHTML = 'Por favor informe o e-mail do seu amigo.';  
    }
    else
    {
      if(!valida_email(document.getElementById('email_amigo')))
      {
        sucesso = false;
        document.getElementById('email_amigo').className = 'error';
        document.getElementById('erroemail_amigo').style.display = '';
        document.getElementById('erroemail_amigo').innerHTML = 'E-mail inválido.';  
      }
    }
    
    if(!sucesso)
    {
        alert('Alguns campos não foram preenchidos da forma devida. Por favor verifique os campos em destaque.'); 
        return false;
    }
    var seu_nome = document.getElementById('anuncio_nome').value;
    var seu_email = document.getElementById('anuncio_email').value;
    var nome_amigo = document.getElementById('nome_amigo').value;
    var email_amigo = document.getElementById('email_amigo').value;

    var veiculo = document.getElementById('hd_veiculo').value;
    
    var retornoAjax = detalhe_veiculo.IndicarAnuncio(parseInt(veiculo),seu_nome,seu_email,nome_amigo,email_amigo).value;
    
    
    if(retornoAjax)
    {
        document.getElementById('div_conteudo_indique').style.display='none';
        document.getElementById('enviar_indique').style.display = 'none';
        document.getElementById('sucesso_indique').style.display = '';            
    }
    else
    {
        document.getElementById('div_conteudo_indique').style.display='none';
        document.getElementById('enviar_indique').style.display = 'none';
        document.getElementById('erro_indique').style.display = '';
    }
}

