function Julian(yr, mt, dy)
{    
  if (mt < 3) {            // January & February to be considered as  
    mt = mt + 12;           // 13th & 14th month
    yr = yr - 1;            // of previous year
   } 
   
  var years = Math.floor((4712 + yr) * 365.25);              // days of full years since -4712  
  var leaps = Math.floor(yr / 100) - Math.floor(yr / 400);   // calculate invalid leap days
  var mnths = Math.floor(((mt - 1) * 30.6) + 0.2);           // days of full months
  return years - leaps + mnths + dy;                        
}
YMD = new Array(2)                             // 3 elements: 0, 1 and 2
function JulToYMD(jul)
{
  jul = jul + 68569
  var temp = Math.floor((4 * jul) / 146097)
  jul = jul - Math.floor((146097 * temp + 3) / 4)
  var tmpYear = Math.floor((4000 * (jul + 1)) / 1461001)
  jul = jul - Math.floor((1461 * tmpYear) / 4) + 31
  var tmpMonth = Math.floor((80 * jul) / 2447)  
  YMD[0] = 100 * (temp - 49) + tmpYear + Math.floor(tmpMonth / 11)  // year = element 0
  YMD[1] = tmpMonth + 2 - (12 * Math.floor(tmpMonth / 11))          // month = element 1
  YMD[2] = jul - Math.floor((2447 * tmpMonth) / 80)                 // day = element 2
}
function MonthName(month)
{
  var mthname=new Array(13);  // 0 thru 12 (record 0 = empty)
    mthname[1]="January";
    mthname[2]="February";
    mthname[3]="March";
    mthname[4]="April";
    mthname[5]="May";
    mthname[6]="June";
    mthname[7]="July";
    mthname[8]="August";
    mthname[9]="September";
    mthname[10]="October";
    mthname[11]="November";
    mthname[12]="December";
  return mthname[month];
}  
function LongDate(yr, mt, dy)
{  
  if (Julian(yr, mt, dy) < 1) {
    alert("Dates before 11/25/4714 b.C. not allowed")
    yr = -4713                              // display lbound date instead
    mt = 11
    dy = 25
   } 
  
  if (yr > 9999) {
    alert("Dates after 12/31/9999 not allowed")
    yr = 9999                               // display ubound date instead
    mt = 12
    dy = 31
   }
 
  if (yr < 1) {
    var annm = yr - 1                       // make computational year a true BC-year
    var year = Math.abs(annm) + " b.C."     // skip minus-sign and add "b.C."
   }
  else {
    var year = yr    
   }  
  
  return MonthName(mt) + " " + dy + ", " + year;  
}
function Easter(yr)
{
  var temp1 = Math.floor((8 * Math.floor(yr / 100) + 13) / 25);
  var temp2 = Math.floor(yr / 100) - Math.floor(yr / 400) + 4;
  var days  = (19 * (yr % 19) + (11 + temp2 - temp1) % 30) % 30;
  var refdays = days;
  if (refdays == 29) {
    days = 28;
    }
  if (refdays == 28 && (yr % 19) > 10) {
    days = 27;
    }
  var factor = ( 2 * (yr % 4) + 4 * (yr % 7) + 6 * days + temp2 % 7 ) % 7; 
  days = days + factor + 21;
  
  return(Julian(yr, 3, 1) + days);   // March One + number of found days
}
function FullYear(theDate)
{
	x = theDate.getYear();
	var y = x % 100;
	y += (y < 38) ? 2000 : 1900;
	return y;
}


