function getMoonAge(year, month, day)
{	
	d = Math.floor(year/20)
	r = year-(d*20) //r is the remainder of (year/20)

	while (r>9)
	{	
		r = r-19
	}

	r = r*11

	while (r>29)
	{	
		r = r-30
	}

	if (month<3)
	{	
		month = month+2
	}

	r = r+month+day

	if (year<100)
	{	
		r = r-4
	}
	else
	{
		r = r-8.3
	}

	while(r>29)
	{	
		r = r-30
	}

	while(r<0)
	{	
		r = r+30
	}

	return r
}
		
function getMoonPhase(moonAge)
{	

	if (moonAge<1) return "Luna noua"
	if (moonAge<6) return "Luna in crestere"
	if (moonAge<9) return "Luna in crestere"
	if (moonAge<13) return "Luna in crestere"
	if (moonAge<16) return "Luna plina"
	if (moonAge<20) return "Luna in scadere"
	if (moonAge<23) return "Luna in scadere(ultimul patrar)"
	if (moonAge<25) return "Luna in scadere"
	if (moonAge<29) return "Luna in scadere"
	if (moonAge<1) return "Luna noua"
}

function getMoonPhaseImg(moonAge)
{	
	if (moonAge<1) return "New"
	if (moonAge<5) return "Waxing_Cresent"
	if (moonAge<9) return "First_Quarter"
	if (moonAge<13) return "Waxing_Gibbous"
	if (moonAge<16) return "Full"
	if (moonAge<20) return "Waning_Gibbous"
	if (moonAge<22) return "Last_Quarter"
	if (moonAge<25) return "Waning_Cresent"
	if (moonAge<29) return "Waning_Cresent"
	if (moonAge<30) return "New"
}


monthNames = new Array(13)
monthNames[1]  = "Ianuarie"
monthNames[2]  = "Februarie"
monthNames[3]  = "Martie"
monthNames[4]  = "Aprilie"
monthNames[5]  = "Mai"
monthNames[6]  = "Iunie"
monthNames[7]  = "Iulie"
monthNames[8]  = "August"
monthNames[9]  = "Septembrie"
monthNames[10] = "Octombrie"
monthNames[11] = "Noiembrie"
monthNames[12] = "Decembrie"
		 
dayNames = new Array(8)
dayNames[1]  = "Duminica"
dayNames[2]  = "Luni"
dayNames[3]  = "Marti"
dayNames[4]  = "Miercuri"
dayNames[5]  = "Joi"
dayNames[6]  = "Vineri"
dayNames[7]  = "Sambata"
		 
function getLongDate(dateObj)
{	
	theDay = dayNames[dateObj.getDay()+1]
	theMonth = monthNames[dateObj.getMonth()+1]
	theDate = dateObj.getDate()
	
	return ""+theDay+", "+theMonth+"  "+theDate
}
		
function getNextFull(moonAge)
{	
	currMilSecs = (new Date()).getTime()
	daysToGo = 15 - moonAge
	while(daysToGo<2)
	{	
		daysToGo = daysToGo+29
	}
	milSecsToGo = daysToGo*24*60*60*1000
	nextMoonTime = currMilSecs+milSecsToGo
	nextMoonDate = new Date(nextMoonTime)
	return nextMoonDate
}
		
function getNextNew(moonAge)
{	
	currMilSecs = (new Date()).getTime()
	daysToGo = 29 - moonAge
	while(daysToGo<2)
	{	
		daysToGo = daysToGo+29
	}
	milSecsToGo = daysToGo*24*60*60*1000
	nextMoonTime = currMilSecs+milSecsToGo
	nextMoonDate = new Date(nextMoonTime)
	return nextMoonDate
}
