// JScript File
function EnviarFormContato()
{
    var sucesso = true;
    
    // Define os estilos padrões
    document.getElementById('nome').className = 'txtfield';
    document.getElementById('erronome').style.display = 'none';

    document.getElementById('email').className = 'txtfield';
    document.getElementById('erroemail').style.display = 'none';
    
    document.getElementById('cidade').className = 'txtfield';
    document.getElementById('errocidade').style.display = 'none';
    
    
    //Verificando se os campos estão corretamente preenchidos.
    if(EmptyField(document.getElementById('nome')))
    {
        sucesso = false;
        document.getElementById('nome').className = 'error';
        document.getElementById('erronome').style.display = '';
        document.getElementById('erronome').innerHTML = 'Por favor, informe o nome para contato.';  
    } 
        
    if(EmptyField(document.getElementById('email')))
    {
        sucesso = false;
        document.getElementById('email').className = 'error';
        document.getElementById('erroemail').style.display = '';
        document.getElementById('erroemail').innerHTML = 'Por favor, informe o e-mail para contato.';  
    }
    else
    {
        if(!valida_email(document.getElementById('email')))
        {
            sucesso = false;
            document.getElementById('email').className = 'error';
            document.getElementById('erroemail').style.display = '';
            document.getElementById('erroemail').innerHTML = 'E-mail Inválido.';  
        }
    }
    
    if(EmptyField(document.getElementById('cidade')))
    {
        sucesso = false;
        document.getElementById('cidade').className = 'error';
        document.getElementById('errocidade').style.display = '';
        document.getElementById('errocidade').innerHTML = 'Por favor, informe sua cidade.';  
    } 
    
    if (!sucesso) {
        alert('Alguns campos não foram preenchidos da forma devida. Por favor, verifique os campos marcados em vermelho.'); 
        return false;
    }
    
    //Caso tenha chegado até aqui, envia-se o formulário de contato.
    var nome_ = document.getElementById('nome').value;   
    var email_ = document.getElementById('email').value;
    var fone_residencial = document.getElementById('fone').value;
    var cidade = document.getElementById('cidade').value;
    var horario_contatar = ""
    
    for(var i=0; i < document.Form.horario_contato.length; i++)
    {
        if(document.Form.horario_contato[i].checked)
        {
            if(i == (document.Form.horario_contato.length-1))
                horario_contatar +=document.Form.horario_contato[i].value;
            else
                horario_contatar +=document.Form.horario_contato[i].value + ", ";
        }
    }
    
    var forma_contatar = "";
    for(var i=0; i < document.Form.forma_contato.length; i++)
    {
        if(document.Form.forma_contato[i].checked)
        {
            if(i == (document.Form.forma_contato.length-1))
                forma_contatar +=document.Form.forma_contato[i].value;
            else
                forma_contatar +=document.Form.forma_contato[i].value + ", ";
            
        }
    }
    
    if(document.getElementById('minha_copia').checked)
    {
        minha_lista.EnviarListaImoveis(nome_, email_);
    }
    
    if(!minha_lista.EnviarFormularioContato(nome_,email_, fone_residencial,forma_contatar,horario_contatar,cidade).value)
    {
        document.getElementById('erro_contato').style.display = "";
        document.getElementById('form_contato').style.display  = "none";
    }
    else
    {
        document.getElementById('sucesso_contato').style.display = "";
        document.getElementById('form_contato').style.display  = "none";
    }
}
