$(document).ready(function(){
	
	$('body style').remove();
	
	$('#txt-busca').click(function (){
		$(this).val('');
	});
	
	$('.externo').attr('target', '_blanck');
	

	$('#carregandoCon').hide();
	$('#recomendar-formulario').hide();;
	
	$('#recomendar-site').click(function() {
		$('#recomendar-formulario').fadeIn(900);
		return false;
	});
	
	
	function validaEmail(mail) {
	    var er = RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
	    if (er.test(mail) == false) {
	        return false;
	    }
	    return true;
	}
	
	
		/////////////////////////////////////////////////////////////////////////////////////
    	// Formulario Contato
    	
		$('#envia-recomenda').submit(function(event) {
        
		var email = $('#seu-email').val();
        var nome = $('#seu-nome').val();
		var amigo_email = $('#email-amigo').val();
        var amigo_nome = $('#nome-amigo').val();
        var link_indicado = $('#link_indicado').val();
        error = false;
        errorList = [];
        
        if (nome == '') {
            errorList.push('<strong>Nome invalido</strong>, por favor corrija o nome informado');
            var error = true;
        }
        
        if (email == '' && !validaEmail(email)) {
            errorList.push('<strong>E-mail invalido</strong>, por favor corrija o e-mail informado');
            var error = true;
        }
		
		if (amigo_nome == '') {
            errorList.push('<strong>Nome Amigo invalido</strong>, por favor corrija o nome informado');
            var error = true;
        }
        
        if (amigo_email == '' && !validaEmail(amigo_email)) {
            errorList.push('<strong>E-mail Amigo invalido</strong>, por favor corrija o e-mail informado');
            var error = true;
        }
        
        $('#listErrors').slideUp().end();
        
        if (error == false) {
			$.ajax({
                type: 'post',
                //url: 'http://localhost/wordpress/wp-content/themes/depoimentosamor/ajax.php',
				url: 'http://www.fotosdecasamentos.com.br/wp-content/themes/fotosdecasamento/ajax.php',
                data: {
                    'acao': 'contato',
                    'nome': nome,
                    'email': email,
					'nome_amigo': amigo_nome,
                    'email_amigo': amigo_email,
					'link_indicado': link_indicado
                },
				
                dataType: 'json',
				beforeSend: function(){$('#carregandoCon').show();},
                success: function(valor){

                    // cadastro corretamente
                    if (valor.error == true) {
						$('#carregandoCon').fadeOut().remove();
						$('.engloba-form').hide('slow');
                        $('#listErrors').html('<ul></ul>');
                        $('#listErrors ul').html('<li>' + valor.msg + '</li>');
                        $('#listErrors').slideDown();
                    }
					
                    else {
                        $('#listErrors').html('<ul></ul>');
                        $('#listErrors ul').html('<li>' + valor.msg + '</li>');
                        $('#listErrors').slideDown();
                        $('#carregandoCon').fadeOut().remove();
                    }
					
                }
            });
        }
		
		
        else {
            errors = '';
            for (i = 0; i < errorList.length; i++) {
                errors += '<li>' + errorList[i] + '</li>';
            }
            
            $('#listErrors').html('<ul></ul>');
            $('#listErrors ul').html(errors);
            
            errors = '';
            errorList.length = 0;
            
            $('#listErrors').slideDown();
            
        }
        
        event.preventDefault(event);
        return false;
    });
});
