var wedNightBibleStudy = new Array();
var wedNightEffFlag;
var dateObj;
var currYear;
var currMonth;
var currDOM;

initialize_current_date();
initialize_wed_night_bible_study();




function write_curr_wed_night_bible_study()
{
    document.write("Along with the Bible, we are using ");
    if (wedNightEffFlag)
    {   
        write_bible_study_title(wedNightBibleStudy, ",");
        document.write(" a book written by ");
        write_bible_study_author(wedNightBibleStudy, "");
        document.write(" about ");
        write_bible_study_subject(wedNightBibleStudy, ".");
    }
    else
    {
        write_bible_study_title_eff(wedNightBibleStudy, ",");
        document.write(" a book written by ");
        write_bible_study_author_eff(wedNightBibleStudy, "");
        document.write(" about ");
        write_bible_study_subject_eff(wedNightBibleStudy, ".");
    }
}

function write_future_wed_night_bible_study()
{
    if (wedNightEffFlag)
    {
         document.write("<BR/><BR/>");
         document.write("Starting ");
         write_bible_study_date_eff(wedNightBibleStudy, ",");
         document.write(" we will be studying ");
         write_bible_study_title_eff(wedNightBibleStudy, ",");
         document.write(" a book written by ");
         write_bible_study_author_eff(wedNightBibleStudy, "");
         document.write(" about ");
         write_bible_study_subject_eff(wedNightBibleStudy, "."); 
    }
}


function write_bible_study_author(bible_study, punc)
{
    document.write(bible_study[AUTHOR]);
    document.write(punc);
}

function write_bible_study_author_eff(bible_study, punc)
{
    document.write(bible_study[AUTHOR_EFF]);
    document.write(punc);
}

function write_bible_study_date_eff(bible_study, punc)
{
    document.write(get_month_name(bible_study[MONTH_EFF]));
    document.write(" ");
    document.write(bible_study[DOM_EFF]);
    document.write(", ");
    document.write(bible_study[YEAR_EFF]);
    document.write(punc);
}

function get_month_name(month_num)
{
    month_name = "";
    if (month_num == 1)
    {
        month_name = "January";
    }  
    if (month_num == 2)
    {
        month_name = "February";
    }
    if (month_num == 3)
    {
        month_name = "March";
    }
    if (month_num == 4)
    {
        month_name = "April";
    } 
    if (month_num == 5)
    {
        month_name = "May";
    }
    if (month_num == 6)
    {
        month_name = "June";
    }
    if (month_num == 7)
    {
        month_name = "July";
    }
    if (month_num == 8)
    {
        month_name = "August";
    }
    if (month_num == 9)
    {
        month_name = "September";
    }
    if (month_num == 10)
    {
        month_name = "October";
    }
    if (month_num == 11)
    {
        month_name = "November";
    }
    if (month_num == 12)
    {
        month_name = "December";
    }
    return month_name;
}

function write_bible_study_title(bible_study, punc)
{
    document.write("<I>");
    document.write(bible_study[TITLE]);
    document.write("</I>");
    document.write(punc);
}

function write_bible_study_title_eff(bible_study,punc)
{
    document.write("<I>");
    document.write(bible_study[TITLE_EFF]);
    document.write("</I>");
    document.write(punc);
}

function write_bible_study_subject(bible_study, punc)
{
    document.write(bible_study[SUBJECT]);
    document.write(punc);
}

function write_bible_study_subject_eff(bible_study, punc)
{
    document.write(bible_study[SUBJECT_EFF]);
    document.write(punc);
}

function initialize_wed_night_bible_study()
{

    for (count=0; count<numServices; count++)
    {
        curr_flag = servicesData[count][FLAG];
        if (curr_flag == WEDNESDAY)
        {
            curr_name = servicesData[count][NAME];
            if (curr_name.indexOf("Adult") >= 0)
            {
                for (pcount=0; pcount<NUM_PARAMS; pcount++)
                {
                    wedNightBibleStudy[pcount] = servicesData[count][pcount];
                }
                wedNightEffFlag = GetEffectiveFlag(wedNightBibleStudy);
            }   
        }
    }
}

function initialize_current_date()
{
    dateObj = new Date();
    currYear = dateObj.getYear();
    if (currYear < 1900)
    {
        currYear = currYear + 1900;
    }
    currMonth = dateObj.getMonth() + 1;
    currDOM = dateObj.getDate();
}

function GetEffectiveFlag(bible_study)
{
    eff_month = bible_study[MONTH_EFF];
    eff_dom = bible_study[DOM_EFF];
    eff_year = bible_study[YEAR_EFF];

    if (currYear < eff_year)
    {
        return 1;
    }
    if (currYear == eff_year)
    {
        if (currMonth < eff_month)
        {
             return 1;
        }
        if (currMonth == eff_month)
        {
            if (currDOM < eff_dom)
            {
                return 1;
            }
        }
    }
    return 0;
}

