
var min_year = 1950; // defines lowest year in year menu
var max_year = thn; // defines highest year in the year menu

// make this false to prevent the weekday element from being displayed
var weekday_showing = true;

// make this true to make month return a number (0-11)
var month_returned_as_number = true;

if (min_year <= 400)
 alert("Minimum year must be higher than 400 for this algorithm to work.");

function changeDays(numb,date_form) {
 mth = date_form.month.selectedIndex;
 sel = date_form.year.selectedIndex;
 yr = date_form.year.options[sel].text;
 if (numb != 1) {
  numDays = numDaysIn(mth-1,yr);
  date_form.date.options.length = numDays+1;
  for (i=27;i<=numDays;i++) {
    date_form.date.options[i].text = i;
  }
 }
 day = date_form.date.selectedIndex+1;
}

function numDaysIn(mth,yr) {
 if (mth==3 || mth==5 || mth==8 || mth==10) return 30;
 else if ((mth==1) && leapYear(yr)) return 29;
 else if (mth==1) return 28;
 else return 31;
}

function leapYear(yr) {
 if (((yr % 4 == 0) && yr % 100 != 0) || yr % 400 == 0)
  return true;
 else
  return false;
}

function arr() {
 this.length=arr.arguments.length;
 for (n=0;n<arr.arguments.length;n++) {
  this[n] = arr.arguments[n];
 }
}
 
months = new arr("Jan.","Feb.","Mar.","Apr.","May",
 "June","July","Aug.","Sep.","Oct.","Nov.","Dec.");

//months = new arr("Jan'","Feb'","Mar'","Apr'","May'",
// "June'","July'","Aug'","Sep'","Oct'","Nov'","Dec'");

// *** comment out the one you don't want to use ***
//months = new arr("Januari","Februari","Maret","April","Mei",
// "Juni","Juli","Agustus","September","Oktober","November","Desember");
 
var cur = new Date();
 
function getWeekDay(mth,day,yr) {
 first_day = firstDayOfYear(yr);
 for (num=0;num<mth;num++) {
  first_day += numDaysIn(num,yr);
 }
 first_day += day-1;
 return first_day%7;
}

function firstDayOfYear(yr) {
 diff = yr - 401;
 return parseInt((1 + diff + (diff / 4) - (diff / 100) + (diff / 400)) % 7);
}

// fixes a Netscape 2 and 3 bug
function getFullYear(d) { // d is a date object
 yr = d.getYear();
 if (yr < 1000)
  yr+=1900;
 return yr;
}