function clean_catholicResult()
{document.catholic_form.catholic_result.value=0;document.catholic_form.catholic_palm.value=0;document.catholic_form.catholic_maundy.value=0;document.catholic_form.catholic_good.value=0;document.catholic_form.catholic_ascension.value=0;document.catholic_form.catholic_whitsunday.value=0;}
function clean_orthodoxResult()
{document.orthodox_form.orthodox_result.value=0;document.orthodox_form.orthodox_palm.value=0;document.orthodox_form.orthodox_maundy.value=0;document.orthodox_form.orthodox_good.value=0;document.orthodox_form.orthodox_ascension.value=0;document.orthodox_form.orthodox_whitsunday.value=0;}
function trim(s)
{return rtrim(ltrim(s));}
function ltrim(s)
{return s.replace(/^\s+/,'');}
function rtrim(s)
{return s.replace(/\s+$/,'');}
function calculate_catholic_holidays(_year,_month,_day)
{var intYear=parseInt(_year);var intMonth=parseInt(_month)-1;var intDay=parseInt(_day);var step_forward=86400000;var step_backward=-86400000;var easter_date=new Date(intYear,intMonth,intDay,1,1,1);var monthName="";var dayName="";var monthArray=new Array("January","February","March","April","May","June","July","August","September","October","November","December");var dayArray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");current_date=new Date(easter_date);for(var i=0;i<7;i++)
{current_date.setTime(current_date.getTime()+step_backward);}
monthName=monthArray[current_date.getMonth()];dayName=dayArray[current_date.getDay()];document.catholic_form.catholic_palm.value=dayName+", "+monthName+" "+current_date.getDate()+", "+current_date.getFullYear();current_date=new Date(easter_date);for(var i=0;i<3;i++)
{current_date.setTime(current_date.getTime()+step_backward);}
monthName=monthArray[current_date.getMonth()];dayName=dayArray[current_date.getDay()];document.catholic_form.catholic_maundy.value=dayName+", "+monthName+" "+current_date.getDate()+", "+current_date.getFullYear();current_date=new Date(easter_date);for(var i=0;i<2;i++)
{current_date.setTime(current_date.getTime()+step_backward);}
monthName=monthArray[current_date.getMonth()];dayName=dayArray[current_date.getDay()];document.catholic_form.catholic_good.value=dayName+", "+monthName+" "+current_date.getDate()+", "+current_date.getFullYear();current_date=new Date(easter_date);for(var i=1;i<40;i++)
{current_date.setTime(current_date.getTime()+step_forward);}
monthName=monthArray[current_date.getMonth()];dayName=dayArray[current_date.getDay()];document.catholic_form.catholic_ascension.value=dayName+", "+monthName+" "+current_date.getDate()+", "+current_date.getFullYear();current_date=new Date(easter_date);for(var i=1;i<50;i++)
{current_date.setTime(current_date.getTime()+step_forward);}
monthName=monthArray[current_date.getMonth()];dayName=dayArray[current_date.getDay()];document.catholic_form.catholic_whitsunday.value=dayName+", "+monthName+" "+current_date.getDate()+", "+current_date.getFullYear();}
function calculate_orthodox_holidays(_year,_month,_day)
{var intYear=parseInt(_year);var intMonth=parseInt(_month);var intDay=parseInt(_day);var step_forward=86400000;var step_backward=-86400000;var easter_date=new Date(intYear,intMonth,intDay,1,1,1);var monthName="";var dayName="";var monthArray=new Array("January","February","March","April","May","June","July","August","September","October","November","December");var dayArray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");current_date=new Date(easter_date);for(var i=0;i<7;i++)
{current_date.setTime(current_date.getTime()+step_backward);}
monthName=monthArray[current_date.getMonth()];dayName=dayArray[current_date.getDay()];document.orthodox_form.orthodox_palm.value=dayName+", "+monthName+" "+current_date.getDate()+", "+current_date.getFullYear();current_date=new Date(easter_date);for(var i=0;i<3;i++)
{current_date.setTime(current_date.getTime()+step_backward);}
monthName=monthArray[current_date.getMonth()];dayName=dayArray[current_date.getDay()];document.orthodox_form.orthodox_maundy.value=dayName+", "+monthName+" "+current_date.getDate()+", "+current_date.getFullYear();current_date=new Date(easter_date);for(var i=0;i<2;i++)
{current_date.setTime(current_date.getTime()+step_backward);}
monthName=monthArray[current_date.getMonth()];dayName=dayArray[current_date.getDay()];document.orthodox_form.orthodox_good.value=dayName+", "+monthName+" "+current_date.getDate()+", "+current_date.getFullYear();current_date=new Date(easter_date);for(var i=1;i<40;i++)
{current_date.setTime(current_date.getTime()+step_forward);}
monthName=monthArray[current_date.getMonth()];dayName=dayArray[current_date.getDay()];document.orthodox_form.orthodox_ascension.value=dayName+", "+monthName+" "+current_date.getDate()+", "+current_date.getFullYear();current_date=new Date(easter_date);for(var i=1;i<50;i++)
{current_date.setTime(current_date.getTime()+step_forward);}
monthName=monthArray[current_date.getMonth()];dayName=dayArray[current_date.getDay()];document.orthodox_form.orthodox_whitsunday.value=dayName+", "+monthName+" "+current_date.getDate()+", "+current_date.getFullYear();}
function catholicEaster(_year)
{clean_catholicResult();Easter_month=0;Easter_day=0;_year=trim(_year);if(_year=="")
{alert("Year must be an integer.");document.catholic_form.catholic_year.focus();document.catholic_form.catholic_year.select();return false;}
else
{intYear=parseInt(_year);if(!(intYear>=0))
{alert("Year must be a positive integer.");document.catholic_form.catholic_year.focus();document.catholic_form.catholic_year.select();return false;}
A=intYear%19+1;tmp=Math.floor(intYear/100);B=tmp+1;tmp=Math.floor((3*B)/4);C=tmp-12;tmp=Math.floor((8*B+5)/25);D=tmp-5;tmp=Math.floor((intYear*5)/4);E=tmp-10-C;F=((11*A+20+D-C)%30+30)%30;if(F==24||(F==25&&A>11))
F=F+1;G=44-F;if(G<21)
G=G+30;N=G+7-((E+G)%7);if(N>31)
{Easter_month=4;Easter_day=N-31;}
else
{Easter_month=3;Easter_day=N;}
intDay=parseInt(Easter_day);intMonth=parseInt(Easter_month);nameMonth="";switch(intMonth)
{case 1:nameMonth="January";break;case 2:nameMonth="February";break;case 3:nameMonth="March";break;case 4:nameMonth="April";break;case 5:nameMonth="May";break;case 6:nameMonth="June";break;case 7:nameMonth="July";break;case 8:nameMonth="August";break;case 9:nameMonth="September";break;case 10:nameMonth="October";break;case 11:nameMonth="November";break;case 12:nameMonth="December";break;}
document.catholic_form.catholic_result.value=nameMonth+" "+intDay+", "+intYear;calculate_catholic_holidays(intYear,intMonth,intDay);}}
function orthodoxEaster(_year)
{clean_orthodoxResult();Easter_month=0;Easter_day=0;_year=trim(_year);if(_year=="")
{alert("Year must be an integer.");document.orthodox_form.orthodox_year.focus();document.orthodox_form.orthodox_year.select();return false;}
else
{intYear=parseInt(_year);if(!(intYear>=0))
{alert("Year must be a positive integer.");document.orthodox_form.orthodox_year.focus();document.orthodox_form.orthodox_year.select();return false;}
reminder=intYear%19;switch(reminder)
{case 0:Easter_month=4;Easter_day=19;break;case 1:Easter_month=4;Easter_day=8;break;case 2:Easter_month=4;Easter_day=27;break;case 3:Easter_month=4;Easter_day=16;break;case 4:Easter_month=4;Easter_day=5;break;case 5:Easter_month=4;Easter_day=24;break;case 6:Easter_month=4;Easter_day=13;break;case 7:Easter_month=5;Easter_day=2;break;case 8:Easter_month=4;Easter_day=21;break;case 9:Easter_month=4;Easter_day=10;break;case 10:Easter_month=4;Easter_day=29;break;case 11:Easter_month=4;Easter_day=18;break;case 12:Easter_month=4;Easter_day=7;break;case 13:Easter_month=4;Easter_day=26;break;case 14:Easter_month=4;Easter_day=15;break;case 15:Easter_month=4;Easter_day=4;break;case 16:Easter_month=4;Easter_day=23;break;case 17:Easter_month=4;Easter_day=12;break;case 18:Easter_month=5;Easter_day=1;break;}
tmp_dow=1;tmp_day_number=Easter_day;tmp_month=Easter_month-1;while(true)
{tmp_easter_date=new Date(intYear,tmp_month,tmp_day_number);tmp_dow=tmp_easter_date.getDay();if(tmp_dow==0)
{break;}
else
{if(tmp_month==2)
if(tmp_day_number==31)
{tmp_day_number=1;tmp_month=3;}
else
{tmp_day_number=tmp_day_number+1;}
else
if(tmp_month==3)
if(tmp_day_number==30)
{tmp_day_number=1;tmp_month=4;}
else
{tmp_day_number=tmp_day_number+1;}
else
if(tmp_month==4)
if(tmp_day_number==31)
{tmp_day_number=1;tmp_month=5;}
else
{tmp_day_number=tmp_day_number+1;}}}
Easter_day=tmp_day_number;Easter_month=tmp_month;intDay=parseInt(Easter_day);intMonth=parseInt(Easter_month);nameMonth="";switch(intMonth)
{case 0:nameMonth="January";break;case 1:nameMonth="February";break;case 2:nameMonth="March";break;case 3:nameMonth="April";break;case 4:nameMonth="May";break;case 5:nameMonth="June";break;case 6:nameMonth="July";break;case 7:nameMonth="August";break;case 8:nameMonth="September";break;case 9:nameMonth="October";break;case 10:nameMonth="November";break;case 11:nameMonth="December";break;}
document.orthodox_form.orthodox_result.value=nameMonth+" "+intDay+", "+intYear;calculate_orthodox_holidays(intYear,intMonth,intDay);}}
