<?php use_helper( 'UrlFunctions' ); ?>
<?php use_helper( 'UtilFunctions' ); ?>
<?php use_helper( 'IncludePartial' ); ?>

<div class="container">
    <button type="button" class="btn btn-primary btn-lg btn-block" onclick="guardarFeriados();">GUARDAR FERIADOS</button>
    <div class="calendar" id="content_calendar"></div>
    <button type="button" class="btn btn-primary btn-lg btn-block" onclick="guardarFeriados();">GUARDAR FERIADOS</button>
</div>

<script>
$( '#content_calendar' ).calendar();
</script>

<script type="text/javascript">
showAlertBootStrap = function( elm_id_content, class_default, message_alert )
{
    var html_alert = '<div class="alert ' + class_default + ' alert-dismissible fade show" role="alert"> ' +
            '' + message_alert +
            '<button type="button" class="close" data-dismiss="alert" aria-label="Close">' +
                '<span aria-hidden="true">&times;</span>' +
            '</button>' +
        '</div>';
    $( "#" + elm_id_content ).append( html_alert );
}

guardarFeriados = function()
{
    var a_Elms = $( '#content_calendar' ).find( ".jqyc-range-choosen-between" );
    var a_Params = new Array();
    $.each
    ( 
        a_Elms, 
        function( i_Key, o_Elm ) 
        {
            var s_Anio = $( o_Elm ).data( "year" );
            var s_Mes  = $( o_Elm ).data( "month" );
            var s_Dia  = $( o_Elm ).data( "day-of-month" );

            //a_Params.push( { Anio: s_Anio, Mes: s_Mes, Dia: s_Dia } );
            a_Params.push( "feriados[]="+ s_Anio + "-" + s_Mes + "-" + s_Dia );

            pr( s_Anio + "-" + s_Mes + "-" + s_Dia );
        }
    );

    var strFormSerialize = a_Params.join( "&" ) + "&tipo_proc=guardar_feriados";
    
    executeAjaxJson
    ( 
        "<?php echo buildUrl( 'feriados/request', "" ) ?>", 
        strFormSerialize,
        function( o_json )
        {
            //console.log( o_json );
            //ocultarCargaImg();
            if( o_json.error )
            {
                showAlertBootStrap( 'content_alert', 'alert-danger', o_json.mensaje_error );
                //mostrarMensajeError( o_json.mensaje_error );
                return false;
            }
            
        } 
    );

    return false;
}
</script>

<script type="text/javascript">
//ahora se busca la relacion de valores que son feriados
var a_Data = <?=$a_Data?>;

//pr( a_Data );

$.each
( 
    a_Data, 
    function( i_Key, o_Values ) 
    {
        var elm = $( '#content_calendar' ).find( '.jqyc-not-empty-td[data-day-of-month="' + o_Values.dia + '"].jqyc-not-empty-td[data-month="' + o_Values.mes + '"].jqyc-not-empty-td[data-year="' + o_Values.anio + '"]')
                                          .addClass( "jqyc-range-choosen-between" );
    }
);
</script>