function birthday(dy,mn)
{
//Get today's date and time at the user's computer

var now = new Date();

var mm = now.getMonth();
var dd = now.getDate();  //User's day of the month
var day = parseInt(dy);
var mon = parseInt(mn) - 1;

if((mm == mon)&&(dd == day))
{
//Birthday detected
var divopen = "<div style=\"position:absolute; left:19px; top:750px; width:124px; height:162px;\">";
var imgtag = "<img src=\"images/bxvism.bmp\" width=\"124\" height=\"161\" border=\"0\" id=\"pic_bxvi\" name=\"pic_bxvi\" title=\"\" alt=\"Papa\">";
var divclose = "</div>";
document.write(divopen + imgtag + divclose);
divopen = "<div class=\"regcent\" style=\"position:absolute; left:19px; top:920px; width:124px; height:30px;\"><span class=\"ar13\">";
divclose = "</span></div>";
document.write(divopen + "Pope Benedict\'s Birthday" + divclose);
}

}

function getDayDiff(dd,mm,yy,hh,mn,dd0,mm0,yy0,hh0,mn0)
{
//Returns the difference in days between two dates (dd/mm/yy hh:mn and dd0/mm0/yy0 hh0:mn0)

var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
var d,d0,dDiff,dow,dte,dms,dms0,one_day;
dd=parseInt(dd); mm = parseInt(mm); yy = parseInt(yy); hh = parseInt(hh); mn = parseInt(hh); 
dd0=parseInt(dd0); mm0 = parseInt(mm0); yy0 = parseInt(yy0); hh0 = parseInt(hh0); mn0 = parseInt(hh0);

//Set 1 day in milliseconds
one_day=1000*60*60*24;  //number of millisecondsin 1 day

dte = new Date(yy,mm,dd,hh,mn,0,0);
dms = dte.getTime();  // msec since 1st Jan 1970

dte =new Date(yy0,mm0,dd0,hh0,mn0,0,0);
dms0 = dte.getTime();  // msec since 1st Jan 1970
 
//Convert to days 
d = dms/one_day;
d0 = dms0/one_day;
// alert('User Date: ' + d + '  Start Date: ' + d0);
			
dDiff = d - d0; //difference in days between the User date and the Start date
      
//convert to an integer					
if(dDiff < 0){dow = Math.floor(dDiff)} else {dow = Math.floor(dDiff)};
//alert('Days since start of the week = ' + dDiff + ' Day of week = ' + dow);

return dow;
}


function getMassVenue(tst,dyTst,mnTst,yrTst,hrTst,minTst)
{

var nxt,sumMass,ch,tm,thm,thr,tmn,tmnow,dsvc,svc,cmt,cmtS,ldr,hs,gf,fwdlook,ist;
var nxthr, nxtmn, tod, svcDay, srvceDay, srvceHr, srvceMn, srvceTime, srvceChurch;
var dd,mm,yy,hh,mn,dowUser,doy,isleap;
var ddBegin,mmBegin,yyBegin,hhBegin,mnBegin;
var wkdys = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");
var edays = new Array(102,94,114,99,90,110,95,87,106,91,111,103);

var len = chtim.length;
var nxtt,nxtd,nxtch,nxtsvc;
var gotService = 0;

//Check whether we take today's date (or one entered by the user)

tst = parseInt(tst);
if(tst == 0)
{
//Get today's date and time at the user's computer
var now = new Date();

mm = now.getMonth();  //User's month  Jan = 0
dd = now.getDate();  //User's day of the month
yy = now.getFullYear(); //User's year
hh = now.getHours();
mn = now.getMinutes();
if(yy%4 == 0){isleap = 1} else {isleap =0}
doy = DayofYear(mm,dd,isleap);
}
else
{
//Retrieve date and time from the arguments of the calling routine
dd = parseInt(dyTst);
mm = parseInt(mnTst) - 1; //Month number (mnTst) has Jan=1, convert to a Jan=0 convention
yy = parseInt(yrTst);
hh = parseInt(hrTst);
mn = parseInt(minTst);

//Calculate the day of the year
if(yy%4 == 0){isleap = 1} else {isleap =0}
doy = DayofYear(mm,dd,isleap);
}


var mmd = mm+1;
//alert("Day of Year= " + doy + " Day of Week=" + dowUser + " Date= " + dd + "/" + mmd + "/" + yy)

// weekBegin is an array set in the script getMassXX.js
ddBegin = weekBegin[0];
mmBegin = weekBegin[1] - 1;
yyBegin = weekBegin[2];
hhBegin = weekBegin[3];
mnBegin = weekBegin[4];

var mmBegind = mmBegin + 1.0;

var tt = hh + mn/60;
var ttBegin = hhBegin + mnBegin/60

var dowUser = getDayDiff(dd,mm,yy,hh,mn,ddBegin,mmBegin,yyBegin,hhBegin,mnBegin);

//dowUser is the day of the week when the User loads the website

//alert('Day of Week ' + dowUser);


mmd = mm + 1;
//alert('Date and Time = ' + dd +'/' + mmd + '/' + yy + '  Time = ' + hh + ':' + mn + ' Day of Week = ' + dowUser + 'Day of Year = ' + doy + ' Start parameter ist = ' + ist); 
	
gf = edays[yy-2009] - 2;
hs = edays[yy-2009] - 1;



tim = hh + mn/60;

for(var i=0; i<len; i++)
{
//Loop through the array 
  dsvc = chtim[i][0];   //Service day 0=Sunday
  ch = chtim[i][1];  //Church name
  svc = chtim[i][2]; //Service
  thm = chtim[i][3];  //Service time in hours and minutes separated by a colon :
  cmt = chtim[i][4]; //Comment for the day
 
  //Calculate time of service if any
  var ss = thm.split(':');
  thr = parseInt(ss[0]);
  if(ss.length > 1){tmn = parseInt(ss[1])} else {tmn = 0}
  tm = thr + tmn/60;
  //alert("ServiceDay= " + dsvc + " Service= " + svc + " Church= " + ch + " User Day= " + dowUser +  " User Time= " + tim + " Service Time= " + tm);
	
// alert(tm + ' ' + thr + ':' + tmn + ' ServiceDay ' + dsvc + ' Day of Week ' + dowUser);
  
  
  //Find the first service with dowUser > = dsvc and ch != "" and tm != 0

 if((dowUser <= dsvc) && (ch != ""))
 {
   
	 if(((dowUser == dsvc)&&(tim < tm)) || (dowUser < dsvc))
	 {
	 // We have identified the next service
	 nxtch = ch;
	 nxtd = dsvc;
	 nxtt = tm;
	 nxtsvc = svc;
	 //alert('Next Service is ' + nxtd + ' Church is ' + ch + ' Service Type = ' + svc + ' User DOW is ' + dowUser);
	 gotService = 1;
	 }
 }
 
 if(gotService == 1){break}

} //end for loop


if(gotService == 1)
{

if(nxtch == "J"){srvceChurch = "St Joseph\'s"}
else if(nxtch == "A"){srvceChurch = "St Augustine\'s"}
else if(nxtch == "C"){srvceChurch = "the Convent of Mercy"}
else if(nxtch == "O"){srvceChurch = cmt}
else if(nxtch == "P"){srvceChurch = "Plymouth Cathedral"}
else if(nxtch == "T"){srvceChurch = "St Paul\'s, Westham"}
else{srvceChurch = "St Augustine\'s School"}

//Check whether the service (if it is a Mass), is a Saturday Vigil Mass or Sunday Morning Mass
//any Mass at a time later than 4pm is counted as a vigil mass
//If there is no comment, a comment will be assigned according to thisSun or nextSun variable 


if(nxtt >= 16)
{
  //alert(' Service day = ' + dsvc + ' Mass time = ' + nxtt);
  //Evening Mass
  if(dsvc == -1)
  {
  //This saturday vigil Mass
  if(cmt == ""){cmt = 'Vigil Mass: ' + thisSun}
  }
  else if(dsvc == 6)
  {
  //Next saturday vigil Mass
  if(cmt == ""){cmt = 'Vigil Mass: ' + nextSun}
  }
}
else
{
  //Standard morning Mass or am or pm Nuptial Mass
  if(dsvc == 0)
  {
  //This Sunday morning
  if(cmt == ""){cmt = thisSun}
  }
  else if(dsvc == 7)
  {
  //Next Sunday morning
  if(cmt == ""){cmt = nextSun}
  }
	
	//alert(' Service day = ' + dsvc + ' Mass time = ' + nxtt + ' Comment = ' + cmt);
}

//Compute the time of day (tod: am, pm, noon, midnight according to the time)
if(nxtt == 12){nxthr = 12; tod = " noon"} else if(nxtt == 24){nxthr = 12; tod = " midnight"} else if (nxtt < 12){nxthr = nxtt; tod = " am"} else if(nxtt >= 13){nxthr = nxtt-12; tod = " pm"} else {nxthr = nxtt; tod = " pm"}

//add the fraction of the hour changed into minutes
srvceHr = Math.floor(nxthr);
if(tmn < 10){srvceMn = "0" + tmn} else {srvceMn = tmn};


if(nxthr > srvceHr)
{srvceTime = srvceHr + ":" + srvceMn + tod}
else {srvceTime = srvceHr + tod};

//Check whether the next service is the same day, or 1 or more days hence. 
//If the service is tomorrow, we give details, otherwise a simple note

var tmrrw = 0;
if(nxtd > dowUser)
{
	fwdlook = nxtd - dowUser;  //the number of days hence
	if((nxtd-dowUser) == 1)
	{
	tmrrw = doy +1;
	if(tmrrw > (365 + isleap)){tmrrw = 1}
	if(nxtd < 0 ){nxtd = nxtd + 7} 
	srvceDay = " tomorrow (" + wkdys[nxtd] + ")";
	}
	else
	{
	if(nxtd < 0 ){nxtd = nxtd + 7} 
	srvceDay = " on this coming " + wkdys[nxtd]
	}
}	
else
{fwdlook = 0; srvceDay = " today"}

/*
var nxtwdy = nxtd;
if(nxtd < 0){nxtwdy = nxtd + 7}
alert("Next day = " + nxtd + " Dayof Week = " + dowUser + " Day = " + wkdys[nxtwdy]);
alert('Tomorrow = ' + tmrrw + ' Day of week = ' + dowUser);
*/

if(tmrrw != 0)
{
//day of week tomorrow
dowUser = dowUser + 1;
if(dowUser > 6){dowUser = dowUser - 7}
var saints = getSaintDay(tmrrw,isleap,dowUser);
var majorFeast = principalFeasts(yy,tmrrw,isleap);
var sName = trim(saints[0]);
var isfeast = majorFeast[0];
//alert('Tomorrow = ' + tmrrw + ' Saints day = ' + saints);
if(isfeast == 1)
{
var feast = majorFeast[1];
document.write("Tomorrow is " + feast);
}
else
{
if(sName != ""){document.write("Tomorrow is the feast of " + sName)}
}
}

if(nxtsvc != "Mass")
{
if(nxtsvc != "Service"){ldr = "<br>"} else {ldr = "<br>Our "}
} 
else {ldr = "<br>Our next "}
 
document.write(ldr + nxtsvc + " will be at " + srvceChurch +  srvceDay + " at " + srvceTime);

if(ch == "S")
{
 if(dowUser == 6)
 {cmtS = "(for the Children of the Parish and their Parents only)"}
 else
 {cmtS = "(for the schoolchildren, their parents and relatives and school staff only)"}
 if(cmt != ""){cmt = cmtS + '<br/>' + cmt} else {cmt = cmtS}
};

//Display comments on a future service only if we are less than 2 days away
if((cmt != "")&&(fwdlook < 2))
{
if(nxtch == "O"){cmt = "See Newsletter for details"}  // Note that "O" is the letter, standing for 'Other' not a zero
document.write("<br>" + cmt);
}

if(msgSeason != "")
{document.write('<br><br> <span class=\"ta14g\">' + msgSeason + '<\/span><br><span class=\"ta14g\">' + msgSeasonMasses + '<\/span>')}

} // end if (gotService == 1)


}

