//Fecha de creación: 25-01-2010
//Valida el formulario de avales para empresas

function comprobar_formulario()
{
    var errores;
    var f = document.getElementById("form_avales");
    errores = comprobar_valores_nulos();
    if (!validar_email(f.email.value))
        {
            errores += "Introduzca un email valido.\n";
        }
    if (errores != "")
    {
        alert(errores);
        return false;
    }
    else
    {
        f.submit();
        return true;
    }
    
}

function comprobar_valores_nulos()
{
    var debe_rellenar = "Debe rellenar el campo ";
    var f = document.getElementById("form_avales");
    var errores = "";
    if (f.nombre.value == "")
    {
        errores += debe_rellenar + "nombre.\n";
    }
    if(f.cif.value == "")
    {
        errores += debe_rellenar +  "cif.\n";
    }
    if (f.domicilio.value == "")
    {
        errores += debe_rellenar + "domicilio.\n";
    }
    if (f.poblacion.value == "")
    {
        errores += debe_rellenar + "poblacion.\n";
    }
    if(f.provincia.value == "")
    {
        errores += debe_rellenar + "provincia.\n";
    }
    if(f.telefono.value == "")
    {
        errores += debe_rellenar +"telefono.\n";
    }
    if (f.email.value == "")
    {
        errores += debe_rellenar + "email.\n";
    }
    if (f.importe_linea.value == "")
    {
        errores += debe_rellenar + "Importe de linea.\n";
    }
    errores += comprobar_checks_tipo_fianza();
    return errores;
}


//Comprueba que al menos un checkboxes esta activo.
function comprobar_checks_tipo_fianza()
{
    var errores = "";
    var f = document.getElementById("form_avales");
    var chequeado = false;

    //Por limpieza, creamos variables con el valor de los checks
    var publica = f.f_publica.checked;
    var licitacion = f.f_licitacion.checked;
    var ejecucion = f.f_ejecucion.checked;
    var mantenimiento = f.f_mantenimiento.checked;
    var anticipio = f.f_anticipo.checked;
    var ett = f.f_ett.checked;
    var otros = f.f_otros.checked;
    //Si al menos uno este checado.
    if (publica || licitacion || ejecucion || mantenimiento || anticipio || ett || otros)
        {
            chequeado = true;
        }
    if (!chequeado)
        {
            errores = "Debe rellenar al menos un tipo de fianza\n";
        }

    return errores;
}