﻿$(document).ready(function () {
    $(".event-reminder").boxy({title: "Create Event Reminder",closeable: true, draggable: true,
                                modal: false, cache: false, modal: true, closeText: "x", afterShow:
                                
        function() {
            $(".reminder-date").focus(function() {
                $(this).animate({color: "#c21b04"},300);
            });
            $(".reminder-date").blur(function() {
                $(this).animate({color: "#424242"},300);
            });
            
            $(".reminder-time").focus(function() {
                $(this).animate({color: "#c21b04"},300);
            });
            $(".reminder-time").blur(function() {
                $(this).animate({color: "#424242"},300);
            });
            
            $(".red-button").mouseover(function () {
                $(this).animate({backgroundColor: "#ce371a"},200);
            });
            
            $(".red-button").mouseout(function () {
                $(this).animate({backgroundColor: "#c21b04"},200);
            });
            
            
            $("#lnkAddReminder").click(function() {
                var eId = $("input[id*='hidEventId']").val();
                var date = $(".reminder-date").val();
                var time = $(".reminder-time").val();
                
                rxDate=/^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
                rxTime=/^[0-9]{2}\:[0-9]{2}$/;
                
                if((rxDate.test(date))&&(rxTime.test(time))) {
                    $.ajax ({       // ... send ajax call ...
                        type: "POST",
                        cache: false,
                        url: "Resource/ajax/submitEventReminder.aspx",
                        data: "event="+eId+"&date="+date+"&time="+time,
                        dataType: "xml",
                        success: handleEventReminderPass,
                        error: handleEventReminderError
                    });
                }
            });
        }
    });
});


function handleEventReminderPass(xml, textStatus) {
    if($(xml).find("error").length<1) {
        $("#jAddReminderContent").slideUp(600, function() {
            $("#jAddReminderContent").html("<p><strong>Thanks</strong>,<br />Your reminder has been set, you will recieve an email on the date/time you specified.</p>");
            $("#jAddReminderContent").slideDown(600);
            
            $(".reminder-date").focus(function() {
                $(this).animate({color: "#c21b04"},300);
            });
            $(".reminder-date").blur(function() {
                $(this).animate({color: "#424242"},300);
            });
            
            $(".reminder-time").focus(function() {
                $(this).animate({color: "#c21b04"},300);
            });
            $(".reminder-time").blur(function() {
                $(this).animate({color: "#424242"},300);
            });
            
            $(".red-button").mouseover(function () {
                $(this).animate({backgroundColor: "#ce371a"},200);
            });
            
            $(".red-button").mouseout(function () {
                $(this).animate({backgroundColor: "#c21b04"},200);
            });
            
            
            $("#lnkAddReminder").click(function() {
                var eId = $("input[id*='hidEventId']").val();
                var date = $(".reminder-date").val();
                var time = $(".reminder-time").val();
                
                rxDate=/^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
                rxTime=/^[0-9]{2}\:[0-9]{2}$/;
                
                if((rxDate.test(date))&&(rxTime.test(time))) {
                    $.ajax ({       // ... send ajax call ...
                        type: "POST",
                        cache: false,
                        url: "Resource/ajax/submitEventReminder.aspx",
                        data: "event="+eId+"&date="+date+"&time="+time,
                        dataType: "xml",
                        success: handleEventReminderPass,
                        error: handleEventReminderError
                    });
                }
            });
        });
    } else {
        handleEventReminderError(null,null,null);
    }
}

function handleEventReminderError(XMLHttpRequest, textStatus, errorThrown) {
    $("#jAddReminderContent").slideUp(600, function() {
        var html=$("#jAddReminderContent").html();
        $("#jAddReminderContent").html("<p><strong>Error</strong>,<br />A server error occured. Please try again.</p>"+html);
        $("#jAddReminderContent").slideDown(600);
        
        $(".reminder-date").focus(function() {
                $(this).animate({color: "#c21b04"},300);
            });
            $(".reminder-date").blur(function() {
                $(this).animate({color: "#424242"},300);
            });
            
            $(".reminder-time").focus(function() {
                $(this).animate({color: "#c21b04"},300);
            });
            $(".reminder-time").blur(function() {
                $(this).animate({color: "#424242"},300);
            });
            
            $(".red-button").mouseover(function () {
                $(this).animate({backgroundColor: "#ce371a"},200);
            });
            
            $(".red-button").mouseout(function () {
                $(this).animate({backgroundColor: "#c21b04"},200);
            });
            
            
            $("#lnkAddReminder").click(function() {
                var eId = $("input[id*='hidEventId']").val();
                var date = $(".reminder-date").val();
                var time = $(".reminder-time").val();
                
                rxDate=/^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
                rxTime=/^[0-9]{2}\:[0-9]{2}$/;
                
                if((rxDate.test(date))&&(rxTime.test(time))) {
                    $.ajax ({       // ... send ajax call ...
                        type: "POST",
                        cache: false,
                        url: "Resource/ajax/submitEventReminder.aspx",
                        data: "event="+eId+"&date="+date+"&time="+time,
                        dataType: "xml",
                        success: handleEventReminderPass,
                        error: handleEventReminderError
                    });
                }
            });
    });
}
