<!--
////////////////////////////////////////////////////////
// Copyright 2003, Timothy James Forsythe, all rights reserved.
// Permission granted to use, copy, modify, and distribute so long as
// the above copyright and this permission statement are retained in all
// copies.  THERE IS NO WARRANTY - USE AT YOUR OWN RISK.
//
// based on the algorithms of Karl Palmen
// http://www.hermetic.ch/cal_stud/palmen/yerm1.htm
////////////////////////////////////////////////////////

var Y_FIRST_JDN = 1948379;

function YDate()
{
  this.day   = "";
  this.month = "";
  this.yerm  = "";
  this.cycle = "";
}

function JDNToYerm(jdn)
{
  var date = new YDate();

  if (jdn >= Y_FIRST_JDN)
  {
  	date.day = jdn - Y_FIRST_JDN;

  	date.cycle = 1 + Math.floor(date.day / 25101);
  	date.day = date.day % 25101;
  	
  	date.yerm = 1 + (3 * Math.floor(date.day / 1447));
  	date.day = date.day % 1447;
  	
  	date.yerm = date.yerm + (Math.floor(date.day / 502));
  	date.day = date.day % 502;
  	
  	date.month = (1 + (2 * Math.floor(date.day / 59)));
  	date.day = date.day % 59;
  	
  	date.month = date.month + Math.floor(date.day / 30);
  	date.day = date.day % 30;
  	
  	date.day = date.day + 1;
  }

  return date;
}

function YermToJDN(cycle,yerm,month,day)
{
  var jdn;

  cycle--;
  jdn = Y_FIRST_JDN + (cycle * 25101);
  yerm--;
  jdn += ((Math.floor(yerm/3)*1447) + (yerm%3) * 502);
  month--;
  jdn += ((Math.floor(month/2)*59) + (month%2) * 30);
  jdn += (day - 1);
  
  return jdn;
}

-->
