// Original script by Charlie Petitt. Completed July 6, 2002.

// Set initial values

mo_name='Jan'; date_addend='01'; century_name='20'; year_name='00';


function GetDay() {

// Set month_addend and mo_length for most months, and mo_no for all

if (mo_name=='Jan') {mo_no='01';}
if (mo_name=='Feb') {mo_no='02';}
if (mo_name=='March') {month_addend=4; mo_length=31; mo_no='03';}
if (mo_name=='April') {month_addend=0; mo_length=30; mo_no='04';}
if (mo_name=='May') {month_addend=2; mo_length=31; mo_no='05';}
if (mo_name=='June') {month_addend=5; mo_length=30; mo_no='06';}
if (mo_name=='July') {month_addend=0; mo_length=31; mo_no='07';}
if (mo_name=='Aug') {month_addend=3; mo_length=31; mo_no='08';}
if (mo_name=='Sep') {month_addend=6; mo_length=30; mo_no='09';}
if (mo_name=='Oct') {month_addend=1; mo_length=31; mo_no='10';}
if (mo_name=='Nov') {month_addend=4; mo_length=30; mo_no='11';}
if (mo_name=='Dec') {month_addend=6; mo_length=31; mo_no='12';}


// Set sequential date for determining Old Style and New Style

sequential_date=century_name+year_name+mo_no+date_addend;


// Set century_addend and century_leap values

if (century_name=='0') {century_addend=4; century_leap='yes';}
else if (century_name=='1') {century_addend=3; century_leap='yes';}
else if (century_name=='2') {century_addend=2; century_leap='yes';}
else if (century_name=='3') {century_addend=1; century_leap='yes';}
else if (century_name=='4') {century_addend=0; century_leap='yes';}
else if (century_name=='5') {century_addend=6; century_leap='yes';}
else if (century_name=='6') {century_addend=5; century_leap='yes';}
else if (century_name=='7') {century_addend=4; century_leap='yes';}
else if (century_name=='8') {century_addend=3; century_leap='yes';}
else if (century_name=='9') {century_addend=2; century_leap='yes';}
else if (century_name=='10') {century_addend=1; century_leap='yes';}
else if (century_name=='11') {century_addend=0; century_leap='yes';}
else if (century_name=='12') {century_addend=6; century_leap='yes';}
else if (century_name=='13') {century_addend=5; century_leap='yes';}
else if (century_name=='14') {century_addend=4; century_leap='yes';}
else if (century_name=='15') {century_addend=3; century_leap='yes';}
else if (century_name=='16') {century_addend=2; century_leap='yes';}
else if (eval(sequential_date)<17520903) {
    century_addend=1; century_leap='yes';}
else if (century_name=='17') {century_addend=4; century_leap='no';}
else if (century_name=='18') {century_addend=2; century_leap='no';}
else if (century_name=='19') {century_addend=0; century_leap='no';}
else if (century_name=='20') {century_addend=6; century_leap='yes';}
else if (century_name=='21') {century_addend=4; century_leap='no';}
else if (century_name=='22') {century_addend=2; century_leap='no';}
else if (century_name=='23') {century_addend=0; century_leap='no';}
else if (century_name=='24') {century_addend=6; century_leap='yes';}
else if (century_name=='25') {century_addend=4; century_leap='no';}
else if (century_name=='26') {century_addend=2; century_leap='no';}
else if (century_name=='27') {century_addend=0; century_leap='no';}
else if (century_name=='28') {century_addend=6; century_leap='yes';}
else if (century_name=='29') {century_addend=4; century_leap='no';}


// Set year_addend and leap_number

year_no=eval(year_name);
leap_group=Math.floor(year_no/4); total_years=leap_group*4;
year_addend=year_no+leap_group;
leap_number=year_no-total_years;


// Set month_addend and mo_length for first two months, accounting for leap years

if (century_leap=='yes' && year_no==0) {leap='yes'}
else if (year_no==0) {leap='no'}
else if (leap_number==0) {leap='yes'}
else {leap='no'}

if (leap=='yes') {
if (mo_name=='Jan') {month_addend=0; mo_length=31;}
if (mo_name=='Feb') {month_addend=3; mo_length=29;}
}

if (leap=='no') {
if (mo_name=='Jan') {month_addend=1; mo_length=31;}
if (mo_name=='Feb') {month_addend=4; mo_length=28;}
}

// Figure the day of the week

day = eval(month_addend) + eval(date_addend) + eval(century_addend) + eval(year_addend);
wks=Math.floor(day/7); totaldays=wks*7;
day=day-totaldays;



// Display results

if (century_name=='0' && year_name=='00') {zero='\nThis year was actually 1 B.C.'}
else {zero=''}

if (eval(date_addend)>eval(mo_length)) {
dow='This month has only ' + mo_length + ' days.';}

else if (day==1) {dow='Sunday'}
else if (day==2) {dow='Monday'}
else if (day==3) {dow='Tuesday'}
else if (day==4) {dow='Wednesday'}
else if (day==5) {dow='Thursday'}
else if (day==6) {dow='Friday'}
else if (day==0) {dow='Saturday'}



// This next bunch of nonsense is to provide separate results for
// Old Style and New Style, for the 170 years of transition

if (eval(sequential_date)>15821014 && eval(sequential_date)<17520903) {

if (eval(date_addend)>eval(mo_length)) {
ndow='This month has only ' + mo_length + ' days.';}

else if (eval(sequential_date)<17000229) {

if (day==1) {ndow='Thursday'}
else if (day==2) {ndow='Friday'}
else if (day==3) {ndow='Saturday'}
else if (day==4) {ndow='Sunday'}
else if (day==5) {ndow='Monday'}
else if (day==6) {ndow='Tuesday'}
else if (day==0) {ndow='Wednesday'}

}

else if (eval(sequential_date)==17000229) {
ndow='This month has only 28 days.'}

else {

if (day==1) {ndow='Wednesday'}
else if (day==2) {ndow='Thursday'}
else if (day==3) {ndow='Friday'}
else if (day==4) {ndow='Saturday'}
else if (day==5) {ndow='Sunday'}
else if (day==6) {ndow='Monday'}
else if (day==0) {ndow='Tuesday'}

}

alert(date_addend + ' ' + mo_name + ' ' + century_name+year_name +
'\n' + 'Old Style: ' + dow + '\n' + 'New Style: ' + ndow);

}



// Back to normal reckoning

else {

alert(date_addend + ' ' + mo_name + ' ' + century_name+year_name +
'\n' + dow + zero);

}

}
