﻿

function validarSeccion1() {

    var lang = document.getElementById('lang');

    if (lang != null) {

        if (lang.value == 'EN')
            return validation_en();
        else
            return validation_es();
    }
}



function validation_es() {

    var errores = 'Hacen falta campos por llenar:\n';
    var numErrores = 0;
    if (document.briefingForm.nombre.value == '') {
        errores = errores + '- Nombre es obligatorio\n';
        numErrores = 1;
    }
    if (document.briefingForm.apellido.value == '') {
        errores = errores + '- Apellido es obligatorio\n';
        numErrores = 1;
    }

    if (document.briefingForm.tel.value == '') {
        errores = errores + '- Teléfono es obligatorio\n';
        numErrores = 1;
    }

    if (document.briefingForm.email.value == '') {
        errores = errores + '- Email es obligatorio\n';
        numErrores = 1;
    }


    if (!valEmail(document.briefingForm.email.value)) {
        errores = errores + '- Email debe ser un Email valido\n';
        numErrores = 1;
    }

    if (numErrores == 1) {
        alert(errores);
        return (false);
    } else {
        return (true);
    }

}


function validation_en() {

    var errores = 'Some required fields are blank:\n';
    var numErrores = 0;
    if (document.briefingForm.nombre.value == '') {
        errores = errores + '- Please provide a first name\n';
        numErrores = 1;
    }
    if (document.briefingForm.apellido.value == '') {
        errores = errores + '- Please provide surname(s)\n';
        numErrores = 1;
    }

    if (document.briefingForm.tel.value == '') {
        errores = errores + '- Please provide telephone number\n';
        numErrores = 1;
    }

    if (document.briefingForm.email.value == '') {
        errores = errores + '- Please provide an e-mail address\n';
        numErrores = 1;
    }


    if (!valEmail(document.briefingForm.email.value)) {
        errores = errores + '- E-mail must be a valid e-mail address\n';
        numErrores = 1;
    }

    if (numErrores == 1) {
        alert(errores);
        return (false);
    } else {
        return (true);
    }
}


function valEmail(valor) {

    re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
    if (!re.exec(valor)) {
        return false;
    } else {
        return true;
    }
}

