function getMoonAge(year, month, day)
{	
        if (year < 2000) {
           r = year % 19
        }
        else {
           r = year % 2000
        }

	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-9
	}

	while(r>29)
	{	
		r = r-30
	}

	while(r<0)
	{	
		r = r+30
	}

	return r
}
		
function getMoonPhase(moonAge)
{	
	if (moonAge<2) return "nueva"
	if (moonAge<5) return "cuarto_creciente"
	if (moonAge<11) return "cuarto_creciente"
	if (moonAge<13) return "cuarto_creciente"
	if (moonAge<16) return "llena"
	if (moonAge<20) return "cuarto_menguante"
	if (moonAge<24) return "cuarto_menguante"
	if (moonAge<29) return "cuarto_menguante"
	if (moonAge<30) return "nueva"
}

function getMoonPhaseImg(moonAge)
{	
	if (moonAge<2) return "nueva"
	if (moonAge<5) return "cuarto_creciente"
	if (moonAge<11) return "cuarto_creciente"
	if (moonAge<13) return "cuarto_creciente"
	if (moonAge<16) return "llena"
	if (moonAge<20) return "cuarto_menguante"
	if (moonAge<24) return "cuarto_menguante"
	if (moonAge<29) return "cuarto_menguante"
	if (moonAge<30) return "nueva"
}


monthNames = new Array(13)
monthNames[1]  = "enero"
monthNames[2]  = "febrero"
monthNames[3]  = "marzo"
monthNames[4]  = "abril"
monthNames[5]  = "mayo"
monthNames[6]  = "junio"
monthNames[7]  = "julio"
monthNames[8]  = "agosto"
monthNames[9]  = "septiembre"
monthNames[10] = "octubre"
monthNames[11] = "noviembre"
monthNames[12] = "diciembre"
		 
dayNames = new Array(8)
dayNames[1]  = "domingo"
dayNames[2]  = "lunes"
dayNames[3]  = "martes"
dayNames[4]  = "mi&eacute;rcoles"
dayNames[5]  = "jueves"
dayNames[6]  = "viernes"
dayNames[7]  = "s&aacute;bado"
		 
function getLongDate(dateObj)
{	
	theDay = dayNames[dateObj.getDay()+1]
	theMonth = monthNames[dateObj.getMonth()+1]
	theDate = dateObj.getDate()
        if (dateObj.getYear() < 2000) {
           theYear = 1900+dateObj.getYear() }
        else {
           theYear = dateObj.getYear()
        }
	return ""+theDate+" de "+theMonth+" de "+theYear
}
		
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
}

