function validateEmail(elementValue){
    var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
    return emailPattern.test(elementValue); 
}


$(document).ready(function(){
$('#email').focus(function(){
this.tempValue1 = this.value;
this.value = '';
$('#email').addClass('focused');
});
$('#email').blur(function(){
if (this.value == '') {
this.value = this.tempValue1;
}
$('#email').removeClass('focused');
});
$('#name').focus(function(){
this.tempValue1 = this.value;
this.value = '';
$('#name').addClass('focused');
});
$('#name').blur(function(){
if (this.value == '') {
this.value = this.tempValue1;
}
$('#name').removeClass('focused');
});
});

var recaptcha = {
    register: function() {
        $('.recaptchaForm').submit(recaptcha.validate);
    },

    validate: function() {
        var email = $('#contactEmail').val();
        if(validateEmail(email)){
            var challenge = $('#recaptcha_challenge_field').val();
            var response  = $('#recaptcha_response_field').val();
            var infoName  = new Array();
            $('.recaptchaInfo').each(function(x){
                infoName[x] = $('#'+this.id).attr('rel');
            });
            var infoValue  = new Array();
            $('.recaptchaInfo').each(function(y){
                infoValue[y] = $('#'+this.id).val();
            });
            var strNames  = infoName.join('+++');
            var strValues = infoValue.join('+++');
            $.post('default/contact/validate-recaptcha',
                { challenge_field: challenge, response_field: response },
                function(valid) {
                    if(valid) {
                        $.post('default/contact/send', { names: strNames, values: strValues },
                            function(send) {
                                if(send) {
                                    $(document).attr('location','default/contact/success');
                                }
                            }, 'json'
                        );
                    } else {
                        $.jGrowl("The validation data were incorrect.", { header: 'Alerta', life: 10000 });
                        Recaptcha.reload ();
                    }
                }, 'json'
            );
        } else {
            $.jGrowl("The email address is invalid.", { header: 'Alerta', life: 10000 });
        }
        return false;
    }
}
