﻿/* Nuevo de eblanco */

function RegistraDatePicker(nombreControl, fnAccion) {
    nombreControl = "#" + nombreControl;
    $.datepicker.setDefaults($.datepicker.regional['es']);
    $(nombreControl).datepicker(
    {
        onSelect: function (dateText, inst) {
            if (fnAccion != null) fnAccion(dateText, inst);        
        },
        minDate: -30
    });

}

function CreaCaptcha() {
    Recaptcha.create("6Lc61AoAAAAAAHl4fHS_5J2vVTQk3mg47hlErOBa",
            "recaptcha_div", {
                theme: "clean"
            });
}


$(document).ready(function () {
    /*
    $(".agregarSimple").click(function() {
    callAddToCalendar($(this), 1);
    });

    $(".agregarSimpleInteres").click(function() {
    callAddToCalendar(aCalendar, 2);
    });

    $(".agregarSimpleInteresNoAsistir").click(function() {
    callAddToCalendar(aCalendar, 3);
    });
    */
    $(".opcionesCalendarioModal").dialog({
        autoOpen: false,
        height: 200,
        width: 300,
        modal: true,
        resizable: false,
        title: 'Opciones de calendario'
    });
});

function showCalendarOptions(elem, tieneCal, urlCalendar) {

    if (!tieneCal) {
        elem.dialog("open");
    }
    else {
        window.location.href = urlCalendar;
    }


}

function addToCalendar(calendarElement, urlTarget, idUsuario, idEvento, alreadyCalText, urlCalendar, textElement, option) {


    $.post(urlTarget, { idUsuario: idUsuario, idLocalizacionEvento: idEvento, tipoAsistencia: option },
                        function (data) { alert("El evento se ha añadido al calendario"); }
                        );

    // Probar esto
    calendarElement.onclick = null;   
    textElement.html(alreadyCalText);
    calendarElement.dialog("close");

    return true;
}
