function Chinese(animal,animalI,branch,branchI,stem,stemI) {
  this.animal = animal; this.animalImage = animalI; this.branch = branch; this.branchImage = branchI; this.stem = stem; this.stemImage = stemI;}
function setChinese(animal,animalI,branch,branchI,stem,stemI) {myChinese[chineseIndex++] = new Chinese(animal,animalI,branch,branchI,stem,stemI);}
var chineseIndex = 0; var myChinese = new Array();
setChinese('Pig','images/pig.gif','hai','images/hai4.gif','gui','images/gui3.gif');
setChinese('Rat','images/rat.gif','zi','images/zi3.gif','jia','images/jia3.gif');
setChinese('Ox','images/ox.gif','chou','images/chou3.gif','yi','images/yi3.gif');
setChinese('Tiger','images/tiger.gif','yin','images/yin2.gif','bing','images/bing3.gif');
setChinese('Rabbit','images/rabbit.gif','mao','mao3.gif','ding','images/ding1.gif');
setChinese('Dragon','images/dragon.gif','chen','images/chen2.gif','wu','images/wu4.gif');
setChinese('Snake','images/snake.gif','si','images/si4.gif','ji','images/ji3.gif');
setChinese('Horse','images/horse.gif','wu','images/wu3.gif','geng','images/geng1.gif');
setChinese('Goat','images/goat.gif','wei','images/wei4.gif','xin','images/xin1.gif');
setChinese('Monkey','images/monkey.gif','shen','images/shen1.gif','ren','images/ren2.gif');
setChinese('Rooster','images/rooster.gif','you','images/you3.gif');
setChinese('Dog','images/dog.gif','xu','images/xu1.gif');
var branchImage1 = 'images/di4.gif'; var branchImage2 = 'images/zhi1.gif'; var stemImage1 = 'images/tian1.gif'; var stemImage2 = 'images/gan1.gif';
var cnys = new Array(
  1.31, 2.19, 2.08, 1.29, 2.16, 2.04, 1.25, 2.13, 2.02, 1.22,
  2.10, 1.30, 2.18, 2.06, 1.26, 2.14, 2.03, 1.23, 2.11, 2.01,
  2.20, 2.08, 1.28, 2.16, 2.05, 1.25, 2.13, 2.02, 1.23, 2.10,
  1.30, 2.17, 2.06, 1.26, 2.14, 2.04, 1.24, 2.11, 1.31, 2.19,
  2.08, 1.27, 2.15, 2.05, 1.25, 2.13, 2.02, 1.22, 2.10, 1.29,
  2.17, 2.06, 1.27, 2.14, 2.03, 1.24, 2.12, 1.31, 2.18, 2.08,
  1.28, 2.15, 2.05, 1.25, 2.13, 2.02, 1.21, 2.09, 1.30, 2.17,
  2.06, 1.27, 2.15, 2.03, 1.23, 2.11, 1.31, 2.18, 2.07, 1.28,
  2.16, 2.05, 1.25, 2.13, 2.02, 2.20, 2.09, 1.29, 2.17, 2.06,
  1.27, 2.15, 2.04, 1.23, 2.10, 1.31, 2.19, 2.07, 1.28, 2.16,
  2.05, 1.24, 2.12, 2.01, 1.22, 2.09, 1.29, 2.18, 2.07, 1.26, 
  2.14, 2.03, 1.23, 2.10, 1.31, 2.19, 2.09, 1.28, 2.16, 2.05, 
  1.25, 2.12, 2.01, 1.22, 2.10, 1.29, 2.17, 2.06, 1.26, 2.13,
  2.03, 1.23, 2.11, 1.31, 2.19, 2.08, 1.28, 2.15, 2.04, 1.24,
  2.12, 2.01, 1.22, 2.10, 1.30, 2.17, 2.06, 1.26, 2.14, 2.02,
  1.23, 2.11
);
function chNYCalc(y) {
    this.start = ''; this.end = ''; m = 3; d = 28;
    var newYear = cnys[y - 1900]; var newMonth = Math.floor(newYear); var newDay = Math.round((newYear*100)-(newMonth*100));
    var c;     // animal number
    a = new Array ("Rat",  "Ox", "Tiger", "Rabbit(Hare)","Dragon", "Snake", "Horse", "Sheep(Goat)","Monkey", "Rooster", "Dog", "Boar(Pig)")
    var animal,animalPrev;
    if ((m > newMonth) || ((m == newMonth) && (d >= newDay))) {
      // this year
      this.branch = (y-3) % 12; this.stem = (y-3) % 10;
      var nextYear = cnys[y - 1900 + 1]; var nextMonth = Math.floor(nextYear);  var nextDay = Math.round((nextYear*100)-(nextMonth*100));
      var lastDay = nextDay - 1;
      if (lastDay == 0) {lastMonth = nextMonth - 1;lastDay = 31;} else lastMonth = nextMonth;
      c = (y-4) % 12; cPrev= (y-5) % 12; animal = a[c]; animalPrev = a[cPrev]; mm = newMonth; dd = newDay;
      this.start = formatFullDate(newDay,newMonth,y); this.end   = formatFullDate(lastDay,lastMonth,y+1);
    }
    else {
      // last year
      this.branch = (y-4) % 12; this.stem = (y-4) % 10;
      var oldYear = cnys[y - 1900 - 1]; var oldMonth = Math.floor(oldYear); var oldDay = Math.round((oldYear*100)-(oldMonth*100));
      var lastDay = newDay - 1;
      if (lastDay == 0) {lastMonth = newMonth - 1; lastDay = 31;} else lastMonth = newMonth;
      c = (y-4) % 12; cPrev= (y-5) % 12; animal = a[c]; animalPrev = a[cPrev]; mm = oldMonth; dd = oldDay;
      this.start = formatFullDate(oldDay,oldMonth,y-1); this.end   = formatFullDate(lastDay,lastMonth,y);
    }
    return {month: mm, day: dd, animal: animal, animalPrev: animalPrev}; // object containing the results
}
function clrTxt(form){ form.day.value = ""; form.month.value = ""; form.animal.value = ""; form.animalPrev.value = "";}
// Validate the year, calculate, and set results in form.
function chny(form) {
    begVal="beg"; now = new Date; then = new Date; var year = form.year.value;
    if (year >= 1901 && year <= 2050) {
      result = chNYCalc(year);
      if (result.month == 1) form.month.value = "January";
      else form.month.value = "February";
      form.day.value = result.day; form.animal.value = result.animal; form.animalPrev.value = result.animalPrev;
      then.setDate(result.day); then.setMonth(result.month - 1); then.setYear(year)
    } else {form.year.value = ""; form.month.value = ""; form.day.value = ""; form.animal.value = ""; form.animalPrev.value = "";}
  }

function CNY(d,m,y) {
  this.start = ''; this.end = '';
  var whichcncycle = new Array(1864,76,1924,77,1984,78,2044,79,2104,80); var whichcnyear = new Array(2000,4698);
  this.cnyear = ''; this.cncyle = ''; this.cnyrno = '';
  if ((y > 1900) && (y < 2051)) {
    var newYear = cnys[y - 1900]; var newMonth = Math.floor(newYear); var newDay = Math.round((newYear*100)-(newMonth*100));
    if ((m > newMonth) || ((m == newMonth) && (d >= newDay))) {
      // this year
      this.branch = (y-3) % 12; this.stem = (y-3) % 10;
      this.cnyear=(y-whichcnyear[0])+whichcnyear[1];
      for (var icn=0; icn<=whichcncycle.length-4; icn+=2){
       if ((y >= whichcncycle[icn]) && (y < whichcncycle[icn+2])) {this.cncycle=whichcncycle[icn+1]; this.cnyrno=y-whichcncycle[icn]+1;}}
      var nextYear = cnys[y - 1900 + 1]; var nextMonth = Math.floor(nextYear); var nextDay = Math.round((nextYear*100)-(nextMonth*100)); var lastDay = nextDay - 1;
      if (lastDay == 0) { lastMonth = nextMonth - 1; lastDay = 31; } else lastMonth = nextMonth;
      this.start = formatFullDate(newDay,newMonth,y); this.end   = formatFullDate(lastDay,lastMonth,y+1);
    }
    else {
      // last year
      this.branch = (y-4) % 12; this.stem = (y-4) % 10;
      this.cnyear=(y-whichcnyear[0])+whichcnyear[1];
      for (var icn=0; icn<=whichcncycle.length-4; icn+=2){if ((y >= whichcncycle[icn]) && (y < whichcncycle[icn+2])) {this.cncycle=whichcncycle[icn+1]; this.cnyrno=y-whichcncycle[icn]+1;}}
      var oldYear = cnys[y - 1900 - 1]; var oldMonth = Math.floor(oldYear); var oldDay = Math.round((oldYear*100)-(oldMonth*100)); var lastDay = newDay - 1;
      if (lastDay == 0) { lastMonth = newMonth - 1; lastDay = 31; } else lastMonth = newMonth;
      this.start = formatFullDate(oldDay,oldMonth,y-1);
      this.end   = formatFullDate(lastDay,lastMonth,y);
    }
  }
  else {this.branch = (y-3) % 12; this.stem = (y-3) % 10;}
}