﻿$(document).ready(function() {
    // wire up cluetip
    $('#cluetip1').cluetip({
        local: true,
        // sticky: true,
        mouseOutClose: true,
        cluetipClass: 'rounded',
        dropShadow: false,
        positionBy: 'mouse',
        waitImage: false,
        showTitle: true,
        width: 300,
        fx: { open: 'fadeIn' }
    });

    // wireup cover popups (overlays)
    $("img[rel]").overlay({
        speed: 'fast',
        fadeInSpeed: 0,
        backgroundElement: '#BodyPane',
        top: 0,

        finish: {
            top: 0,
            left: 'center',
            absolute: true
        },
        onLoad: function() {
            // select the radio button -- the id is buried in a hidden input item
            // sneaky but effective.
            var id = this.getContent().find('.hid').val();
            $('#' + id).attr('checked', 'checked');
        }
    });


});  // end doc ready

function log(msg) {
    if (typeof (console) != 'undefined') {
        console.log(msg);
    }
}


function SetBirthDays(birthMonth, birthDay) {
    var thirtyOne = [1, 3, 5, 7, 8, 10, 12];
    var numDays = 0;
    var month = parseInt(birthMonth.val());
    if ($.inArray(month, thirtyOne) >= 0) {
        numDays = 31;
    }
    else {
        if (month == 2) {
            numDays = 29;
        } else if (month == 0) {
            numDays = 0;
        } else {
            numDays = 30;
        }
    }
    if (numDays == 0) {
        birthDay.attr('disabled', 'disabled');
    }
    else {
        // recreate days drop down
        birthDay.removeAttr('disabled'); // ensure we can select it
        var sel = parseInt($('#' + birthDay[0].id + ' option:selected').val()); // get currently selected value
        birthDay.children().remove().end(); // clear options
        for (j = 1; j <= numDays; j++)  // add options
        {
            birthDay.append($('<option></option>').val(j).html(j));
        }
        if (!isNaN(sel)) {
            sel--; // zero base
            $("#"+birthDay[0].id+" option:eq(" + sel + ")").attr('selected', 'selected');
        }
    }
}

function SetMiddleName(midName) {
    var midNameSpan = $('#middlename');
    var sel = $('#'+midName[0].id+' option:selected').val().toLowerCase();
    var lastNameSpan = $('#lastNameSpan');

    if (sel === "no") {
        midNameSpan.css('display', 'none');
        lastNameSpan.html("Child's Last Name:");
    } else if (sel === "yes") {
        lastNameSpan.html("Child's Last Name:");
        midNameSpan.css('display', 'inline');
    } else if (sel === "last") {
        midNameSpan.css('display', 'none');
        lastNameSpan.html("Child's Middle Name:");
    }
}

function SetDedication(dedication, dedicationText) {
    var str = $('#' + dedication[0].id + ' option:selected').text();
    if ((str.toLowerCase() === 'none') || (str.toLowerCase() === 'create your own')) {
        str = '';
    }
    dedicationText.val( str );
}
        
