﻿

function CargarTab()
{
    tabstrips = "EditRecordTab"
    tabheads = "ctl00_ContentPlaceHolder1_TabStrip_1"
    LoadTabstrip(true);
    if ("<%=EsModoAlta%>" == "True")
    {
        LoadTabstrip(true);
    }
    else
    {
        LoadTabstrip(true);
        SeleccionarTabInicial();
    }
}
function ValidarDatos()
{

    //usuario
    if (document.getElementById("ctl00_ContentPlaceHolder1_TextEditUsuario") != null)
    {
        var usuario = document.getElementById("ctl00_ContentPlaceHolder1_TextEditUsuario").value;
        if (usuario.length == 0)
        {
            alert("Campo usuario obligatorio.");
            document.getElementById("ctl00_ContentPlaceHolder1_TextEditUsuario").focus();
            return false;
        }

        if (usuario != null && usuario.length < 6)
        {
            alert("Campo usuario ha de tener al menos 6 caracteres.");
            document.getElementById("ctl00_ContentPlaceHolder1_TextEditPassword").focus();
            return false;
        }
    }


    //password
    var texteditpassword = document.getElementById("ctl00_ContentPlaceHolder1_TextEditPassword");
    var texteditpasswordconfirm = document.getElementById("ctl00_ContentPlaceHolder1_TextEditPasswordConfirm");

    if (texteditpassword != null && texteditpassword.value.length == 0)
    {
        alert("Campo contraseña obligatorio.");
        document.getElementById("ctl00_ContentPlaceHolder1_TextEditPassword").focus();
        return false;
    }

    if (texteditpassword != null && texteditpassword.value.length < 6)
    {
        alert("Campo contraseña ha de tener al menos 6 carácteres.");
        document.getElementById("ctl00_ContentPlaceHolder1_TextEditPassword").focus();
        return false;
    }

    if (texteditpasswordconfirm != null && texteditpasswordconfirm.value.length == 0)
    {
        alert("Campo confirmacion contraseña obligatorio.");
        document.getElementById("ctl00_ContentPlaceHolder1_TextEditPasswordConfirm").focus();
        return false;
    }

    if (texteditpasswordconfirm != null && texteditpassword != null && texteditpassword.value != texteditpasswordconfirm.value)
    {
        alert("El campo contraseña y confirmacion contraseña son distintos.");
        return false;
    }


    if (!ValidarObligatorio(document.getElementById("ctl00_ContentPlaceHolder1_TextEditEmail"), "correo electrónico")) return false;
    if (!ValidarObligatorio(document.getElementById("ctl00_ContentPlaceHolder1_TextEditConfEmail"), "confirma correo electrónico")) return false;

    var correo = document.getElementById("ctl00_ContentPlaceHolder1_TextEditEmail");
    var correoconfirm = document.getElementById("ctl00_ContentPlaceHolder1_TextEditConfEmail");
    
    if (correo != null && correoconfirm != null && correo.value != correoconfirm.value)
    {
        alert("El campo correo electrónico y confirmacion correo electrónico son distintos.");
        return false;
    }
    
    //fecha
    var dia = document.getElementById("ctl00_ContentPlaceHolder1_ComboEditDia").value;
    var mes = document.getElementById("ctl00_ContentPlaceHolder1_ComboEditMes").value;
    var anyo = document.getElementById("ctl00_ContentPlaceHolder1_ComboEditAnyo").value;

    if (dia == "" || mes == "" || anyo == "")
    {
        alert("Fecha nacimiento obligatoria.");
        return false;
    }

    if (isDate(mes, dia, anyo) == false)
    {
        alert("Fecha nacimiento invalida.");
        return false;
    }
    if (!ValidarObligatorio(document.getElementById("ctl00_ContentPlaceHolder1_ComboEditSexo"), "sexo")) return false;
    if (!ValidarObligatorio(document.getElementById("ctl00_ContentPlaceHolder1_TextEditCodigoPostal"), "código postal")) return false;
    if (isUnsignedInteger(document.getElementById("ctl00_ContentPlaceHolder1_TextEditCodigoPostal").value) == false)
    {
        alert("El formato del campo código postal es incorrecto.");
        document.getElementById("ctl00_ContentPlaceHolder1_TextEditCodigoPostal").focus();
        return false;
    }
    if (!ValidarObligatorio(document.getElementById("ctl00_ContentPlaceHolder1_ComboEditPais"), "país")) return false;
    if (!ValidarObligatorio(document.getElementById("ctl00_ContentPlaceHolder1_ComboEditProvincia"), "provincia")) return false;
    if (!ValidarObligatorio(document.getElementById("ctl00_ContentPlaceHolder1_ComboEditMunicipio"), "municipio")) return false;

   
    if (!ValidarObligatorio(document.getElementById("ctl00_ContentPlaceHolder1_TextBoxValorCaptcha"), "imagen validación")) return false;



    if (Page_IsValid != null && Page_IsValid == false)
    {
        alert("Algunos campos son incorrectos.");
        return false;
    }

    return true;
}

function GuardarDatos()
{
    if (ValidarDatos() == true)
    {
        document.getElementById("accion").value = "Guardar";
        document.forms[0].submit();
    }
}

function ClickTab(numtab, tab)
{
    document.getElementById("ctl00_ContentPlaceHolder1_wrapcuestionariomiperfil").style.display = "inline";
    InitializeTabstrip('EditRecordTab', numtab, tab);
}


function CodigoPostalSeleccionado(identificadorcodigopostal)
{
    document.getElementById("accion").value = "ObtenerCodigoPostal";
    document.getElementById("codigopostal").value = identificadorcodigopostal;
    document.forms[0].submit();
}

function AbrirMantenimientoCambioPassword()
{
    window.location = "MantenimientoCambioPassword.aspx";
}

function AbrirMantenimientoBajaUsuario()
{
    window.location = "MantenimientoBajaUsuario.aspx";
}