$('#form-contato').submit(function(e){	
    e.stopPropagation();
    
    /*$('.content-result').hide();
    $('.content-result').html('');*/
    
    loadButton($('#form-contato button.btn-success'));
	
	$.ajax({
		url: base_url+"comdono/ajax/contato_ajax/index",
		dataType: 'json',
		type: 'POST',
		data: getForm(),
		success: function(retorno)
		{		
			if (retorno.valid === true)
			{	
			    loadButton(null,false);
			    //$("#form-contato")[0].reset();
			    $('#form-contato input[name=telefone]').val("");
			    $("textarea#mensagem").val("Olá! Gostaria de conversar melhor sobre os termos de uso.");
			    $('.content-form #content-error').html('');
			    $('.content-form').hide();
			    $('.modal-title').html("Pronto!");
    	        $('.content-result').show();
    	        $('.content-result').html(retorno.msg);
			}
			else
			{ 
			    loadButton(null,false);
			    ico = '<img src="'+base_url+'/assets/img/comdono/icons/error.png">';
    	        $('.content-form #content-error').html('<label class="error-login"><span>'+ico+'</span>'+retorno.msg+'</label>');
			}
		},
		error: function(error)
		{ 
		    loadButton(null,false);
			ico = '<img src="'+base_url+'/assets/img/comdono/icons/error.png">';
	        $('.content-form #content-error').html('<label class="error-login"><span>'+ico+'</span>Não foi possível enviar o e-mail. Tente novamente mais tarde.</label>');
		}
	});
	return false;
})

function getForm(){
    
    data = [];
    $('#form-contato').find('input:not([type=radio]):input:not([type=checkbox]):input:not([type=file])').each(function(key,value){
        if(this.name != "")
            data.push({"name": this.name, "value": this.value});
    });
    $('#form-contato').find('textarea').each(function(key,value)    {
        if(this.name != "")
            //data.push({"name": this.name, "value": CKEDITOR.instances[this.name].getData()});
            data.push({"name": this.name, "value": this.value});
    });
    $('#form-contato').find('input[type=radio]:checked').each(function(key,value)    {
        if(this.name != "")
            data.push({"name": this.name, "value": this.value});
    });
    $('#form-contato').find('select option:selected').each(function(key,value)    {
        if(this.parentElement.localName == 'select')
            data.push({"name": this.parentElement.name, "value": this.value});
            
        if(this.parentElement.parentElement.localName == 'select')
            data.push({"name": this.parentElement.parentElement.name, "value": this.value});
    });
    
    $('#form-contato').find('input[type=checkbox]:checked').each(function(key,value)    {
        if(this.name != "")
            data.push({"name": this.name, "value": this.value});
    });
    
    $('#form-contato').find('input[type=checkbox]:not(:checked)').each(function(key,value)    {
        if(this.name != "")
            data.push({"name": this.name, "value": ""});
    });
    
    return data;
}