/* Error de minimización. Devolviendo el contenido no minimizado.
(1,10): run-time error CSS1031: Expected selector, found 'valPhone('
(1,10): run-time error CSS1025: Expected comma or open brace, found 'valPhone('
(66,10): run-time error CSS1031: Expected selector, found 'showModalLoader('
(66,10): run-time error CSS1025: Expected comma or open brace, found 'showModalLoader('
(87,10): run-time error CSS1031: Expected selector, found 'hideModalLoader('
(87,10): run-time error CSS1025: Expected comma or open brace, found 'hideModalLoader('
 */
function valPhone(element, caption, maxLength=20, required=true){
    var valor = '' + $(element).val();
    var showmodal = $(element).prop("showmodal");

    var span = $('span[data-valmsg-for="' + element.id + '"]');

    if (required) {
        if (valor.trim() == '' || isNaN(valor)) {            
            span.text('El campo ' + caption + ' no es un número de teléfono válido.');

            if (showmodal == 'true') {
             
                var titulo = $(element).prop("titulo");
                var mensaje = $(element).prop("mensaje");
               
                bootbox.dialog({
                    title: titulo,
                    message: mensaje,
                    size: 'small',
                    buttons: {
                        ok: {
                            label: "Cerrar",
                            className: 'btn-info',
                            callback: function () {
                                return;
                            }
                        }
                        }
                });

                /*
                var modal = $('#modalAlert');
                modal.find('.modal-title').text(titulo);
                modal.find('.modal-body').text(mensaje);
                $('#modalAlert').modal();
                */
            }

            return;
        }
    }

    if (valor.length > maxLength) {                
        span.text('El campo ' + caption + ' debe tener longitud máxima de ' + maxLength + ' caracteres.');

        if (showmodal == 'true') {
            var titulo = $(element).prop("titulo");
            var mensaje = $(element).prop("mensaje");
            var modal = $('#modalAlert');
            modal.find('.modal-title').text(titulo);
            modal.find('.modal-body').text(mensaje);
            $('#modalAlert').modal();
        }

        return;
    }

    span.text('');

    return;        
}
/**
 * Muestra la ventana de espera
 * @param callBackFunction 
 */
function showModalLoader(callBackFunction) {
    jQuery('#mainPage').attr('aria-hidden', 'true'); // mark the main page as hidden
    jQuery('#modalOverlay').css('display', 'block'); // insert an overlay to prevent clicking and make a visual change to indicate the main apge is not available
    jQuery('#modalLoader').css('display', 'block');                   // make the modal window visible
    jQuery('#modalLoader').attr('aria-hidden', 'false');   // mark the modal window as visible

    jQuery('#modalLoader').attr("role", "alert");
    jQuery('#modalLoader').attr("aria-live", "assertive");
    jQuery('#modalLoader').attr("aria-atomic", "true");

    $("#modalLoader").removeClass("modal");
    $("#modalLoader").addClass("load");

    // llamada la funcion callback que realiza la accion
    callBackFunction();

}

/**
 * Oculta la ventan de espera
 */
function hideModalLoader() {
    jQuery('#mainPage').attr('aria-hidden', 'false'); // mark the main page as hidden
    jQuery('#modalOverlay').css('display', 'none'); // insert an overlay to prevent clicking and make a visual change to indicate the main apge is not available
    jQuery('#modalLoader').css('display', 'none');                   // make the modal window visible
    jQuery('#modalLoader').attr('aria-hidden', 'true');   // mark the modal window as visible

    jQuery('#modalLoader').removeAttr("role");
    jQuery('#modalLoader').removeAttr("aria-live");
    jQuery('#modalLoader').removeAttr("aria-atomic");
}

