function reformedCals(in1,in2,in3) 
{
	return WorldCal(in1,in2,in3) + '<br />' + FixedCal(in1,in2,in3)
}

function jdAndUTC(theDate)
{
	//this is code to generate a mod date for the doc in jd and iso
	modDt = new Date(document.lastModified)
	dateSecs = modDt.getTime()	datejd = Math.round(dateSecs/864)/100000 + 2440587.5	dayjd = Math.floor((nowSecs/864/100000) + 2440587.5)	timejd = dayjd + "." + Math.round((datejd - dayjd) *100000)
	modDate = (modDt.getUTCFullYear() + "-" + padString(modDt.getUTCMonth()+1,2) + "-" + padString(modDt.getUTCDate(),2) + " " + padString(modDt.getUTCHours(),2) + ":" + padString(modDt.getUTCMinutes(),2) +" UTC")

}

function padString(thenum,thefactor)
{//pads a number or string with leading zeros
	pad0s = new String(Math.pow(10,thefactor))
	thepad = pad0s + String(thenum)
	thestring= thepad.substr((-1*thefactor),thefactor)
	return thestring
}

function jdCal()
{
	//a julian date object
	this.jdParts = jdParts

	//new Date() returns current jd
	//new Date(2004, 6, 29, 12, 1) returns local date
	//Date.UTC(2004, 6, 29, 12) returns utc date

	function jdParts(ms, zone) {
		//input should be milliseconds, zone is in +/- longitude
        zone = Number(zone);
		//if (zone ==''){zone = 180}
		localOffset =  (Math.floor((zone - 180)/0.360))/1000;

		try{
			ms.setHours(ms.getHours()-localOffset)		//produces 'local' time
		}	catch(err){}					//don't care what the error is

		this.jdDT = Math.round(ms/864)/100000 + 2440587.5 + localOffset
		this.jdDay = Math.floor((ms/864/100000) + 2440587.5 + localOffset)
		this.jdDTString = this.jdDay + "." + Math.round((this.jdDT - this.jdDay) *100000)
	}
}

function utcString(theDate)
{
	//a function to convert a date into a string in the format 'YYYY-MM-DD HH:MM UTC'
	theDate = new Date(theDate)
	utcString = theDate.getUTCFullYear() + "-" + padString(theDate.getUTCMonth()+1,2) + "-" + padString(theDate.getUTCDate(),2) + " " + padString(theDate.getUTCHours(),2) + ":" + padString(theDate.getUTCMinutes(),2) +" UTC"
	return utcString

}

function GregCal(inputYear,inputMonth,inputDate)
{		
	monthNames = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
	weekdayNames = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday","Saturday")
	gregDate = new Date(inputYear,inputMonth-1,inputDate)
	return gregDate.getFullYear() + " " + monthNames[gregDate.getMonth()] + " " + gregDate.getDate() + " (" + weekdayNames[gregDate.getDay()] + ")"
}

function FixedCal(inputYear,inputMonth,inputDate)
{
	//convert input data
	formatDate = getDayCount(inputYear,inputMonth,inputDate)
	var fixedDayCount = formatDate[0]
	var theYear = formatDate[1]

	//now figure out international fixed date
	var fixedDate = ""
	leapDayOffset = hasLeapDay(theYear)*-1
	if ((fixedDayCount == 168) && (leapDayOffset != 0)) {
		fixedDate = "LeapDay"
		}
	else if (fixedDayCount + leapDayOffset == 364) {
		fixedDate = "YearEndDay"
		}
	else if ((fixedDayCount > 168) && (leapDayOffset != 0)) {
		 fixedDayCount = fixedDayCount + leapDayOffset
		}

	monthNames = new Array("January", "February", "March", "April", "May", "June", "Sol", "July", "August", "September", "October", "November", "December")
	weekdayNames = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday","Saturday")

	var newDay = fixedDayCount % 28 + 1
	var newMonth = Math.floor(fixedDayCount/28) 
	var newMonthTemp = "0" + (newMonth+1)
	var newMonthText = newMonthTemp.substr(newMonthTemp.length-2)
	var newMonthName = monthNames[newMonth]
	var weekdayName = weekdayNames[fixedDayCount%7]

	if (fixedDate == "") {
		fixedDate = theYear + " " + newMonthName+" "+newDay + " (" + weekdayName + ")"
		}
	return fixedDate
}

function WorldCal(inputYear,inputMonth,inputDate)
{
	//convert input data
	formatDate = getDayCount(inputYear,inputMonth,inputDate)
	var worldDayCount = formatDate[0]
	var theYear = formatDate[1]

	//now figure out international fixed date
	var worldDate = ""
	leapDayOffset = hasLeapDay(theYear)*-1
	if ((worldDayCount == 182) && (leapDayOffset != 0)) {
		worldDate = "LeapDay"
		}
	else if (worldDayCount + leapDayOffset == 364) {
		worldDate = "YearEndDay"
		}
	else if ((worldDayCount > 182) && (leapDayOffset != 0)) {
		 worldDayCount = worldDayCount + leapDayOffset
		}

	monthNames = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
	weekdayNames = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday","Saturday")
	
	var dayNumber = ""
	var monthNumber = ""
	 quarter = Math.floor(worldDayCount/91)
	 dayOfQuarter = worldDayCount % 91
	if (dayOfQuarter < 31) { 
		//first month of quarter has 31 days
		 monthNumber = ("0" + ((quarter) * 3 + 1))
		 dayNumber = (dayOfQuarter + 1)
		 }
	else {
		// second two months of the quarter have 30 days each
		 tempDOQ = dayOfQuarter - 31
		 monthNumber =  ("0" + ((quarter) * 3 + 1 + (Math.floor(tempDOQ / 30) + 1)))
		 dayNumber =  (tempDOQ % 30 + 1)
		 }
	var weekdayName = weekdayNames[worldDayCount%7]
	var monthName = monthNames[monthNumber-1]
	//monthNumber.substr(monthNumber.length - 2)
	if (worldDate == "") {
		worldDate = theYear + " " + monthName +" "+ dayNumber + " (" + weekdayName + ")"
		}
	return worldDate
}

function getDayCount(inputYear,inputMonth,inputDate)
{
	//set month to zero indexed number
	inputMonth = inputMonth -1

	//turn input string into a date object
	var newDate = new Date(inputYear,inputMonth,inputDate)
	var theYear = newDate.getFullYear()

	//get year beginning date
	var beginDate = new Date(newDate)
	beginDate.setMonth(0)
	beginDate.setDate(1)

	//calucate day of year, zero indexed
	var dayOfYear = Math.round((newDate-beginDate)/86400000)
	return Array(dayOfYear,theYear)
}

function hasLeapDay(theYear)
{
	if ((theYear % 4 == 0) && (theYear % 100 != 0) || (theYear % 400 == 0)) {
		return 1
		}
	else {
		return  0
		}
}
//reformedCals('2000','9','2')