﻿var numCurStory = 1;
var numMinStory = 1;
var numMaxStory = 3;

var numTextAreaLimit = 500;

$(document).ready(function() {
    // rollover for the top nav
    $("img.TopNavBtn").hover(
        function() {
            $(this).attr("src", $(this).attr("src").replace("-Off", "-On"));
        },
        function() {
            $(this).attr("src", $(this).attr("src").replace("-On", "-Off"));
        }
    );

    // change gallery thumbs opacity on hover
    $("img.KidsPhotoGallery").hover(
        function() {
            $(this).animate({ "opacity": 0.4 }, 500);
        },
        function() {
            $(this).animate({ "opacity": 1 }, 500);
        }
    );

    // Change the image in the display
    $("img.KidsPhotoGallery").click(function() {
        $("#KidsPhotosGalleryCurrent").attr("src", $(this).attr("src").replace("sm", "big"));
    });

    // Go back 1 story
    $("#SuccessStoryBtnBack").click(function() {
        $("#SuccessStory" + numCurStory).css("display", "none");

        numCurStory -= 1;   // decrease by 1

        $("#SuccessStory" + numCurStory).css("display", "block");

        if (numCurStory == numMinStory) {   // hide the next button
            $("#SuccessStoryBack").css("display", "none");
        } // if

        $("#SuccessStoryNext").css("display", "block");
    });

    // Go Forward 1 story
    $("#SuccessStoryBtnNext").click(function() {
        $("#SuccessStory" + numCurStory).css("display", "none");

        numCurStory += 1;   // increment by 1

        $("#SuccessStory" + numCurStory).css("display", "block");

        if (numCurStory == numMaxStory) {   // hide the next button
            $("#SuccessStoryNext").css("display", "none");
        } // if

        $("#SuccessStoryBack").css("display", "block");
    });

    // add validation controls.
    $("form#frmECard").validate
    ({
        onfocusout: false,
        errorLabelContainer: "#ECardErrorBox",
        wrapper: "fieldset",
        rules:
        {
            YourName:
            {
                required: true,
                maxlength: 50
            },
            YourEmail:
            {
                required: true,
                email: true,
                maxlength: 100
            },
            RecipientName:
            {
                required: true,
                maxlength: 50
            },
            RecipientEmail:
            {
                required: true,
                email: true,
                maxlength: 100
            },
            Message:
            {
                required: true,
                maxlength: numTextAreaLimit
            }
        },
        messages:
        {
            YourName: "Please enter your name.",
            YourEmail: "Please enter your Email.",
            RecipientName: "Please enter the recipient's name",
            RecipientEmail: "Please enter the recpient's Email",
            Message: "Please enter a message"
        }
    });

    // Limit the textarea to 500
    $("#Message").keyup(function() {
        // remove the last character
        if ($("#Message").val().length > numTextAreaLimit) {
            $("#Message").val($("#Message").val().substr(0, $("#Message").val().length - 1));
        } // if
    });

    // Send the ECard Email
    $("#ECardSend").click(function() {
        if ($("form#frmECard").validate().form()) {

            $.post("Kids-ECardHandler.asp",
                        {
                            YourName: $("#YourName").val(),
                            YourEmail: $("#YourEmail").val(),
                            RecipientName: $("#RecipientName").val(),
                            RecipientEmail: $("#RecipientEmail").val(),
                            Message: $("#Message").val(),
                            Type: $("input[@name='ECardRadio']:checked").val()
                        },
                        function(data) {
                            var strMessage = (data == "1") ? "Your E-Card has been sent successfully." : "There was an error sending your E-Card.<!--" + data + "-->";

                            $("#ECardErrorBox").html("<p class=\"ECardThankYou\">" + strMessage + "</p>");
                            $("#ECardErrorBox").show();
                        }
            );
        } // if
    });

    // Preview the ECard
    $("#ECardPreview").click(function() {
        if ($("form#frmECard").validate().form()) {
            var m_strParams = "from=" + $("#YourName").val() + "&to=" + $("#RecipientName").val() + "&message=" + $("#Message").val() + "&type=" + $("input[@name='ECardRadio']:checked").val();
            OpenWin('Kids-ECardPreview.asp?' + m_strParams, '874', '600');
        } // if
    });

});
