//Calendario Maya 

hoy = new Date;
//fechaactual = new Date(hoy.getFullYear(),hoy.getMonth(), hoy.getDate(), 0,0,0);
fechaactual = new Date(hoy.getFullYear(),hoy.getMonth(),hoy.getDate())
//fecha = new Date (2004,08,17)
fecha = new Date (1900,09,13)
r = 86400 * 1000
//para probar fecha futura///////////////////////////////////////////////////////
//hoy=new Date (1973,05,29)
//fechaactual = new Date(hoy.getFullYear(),hoy.getMonth(),hoy.getDate())
//fin para probar////////////////////////////////////////////////////////////////
dias = (fechaactual-fecha)/r;

//Listas de selos y tonos
function ListaSellos(){
this.length = 20
this[0] = "Imix"
this[1] = "Ik"
this[2] = "Akbal"
this[3] = "Kan"
this[4] = "Chicchan"
this[5] = "Cimi"
this[6] = "Manik"
this[7] = "Lamat"
this[8] = "Muluc"
this[9] = "Oc"
this[10] = "Chuen"
this[11] = "Eb"
this[12] = "Ben"
this[13] = "Ix"
this[14] = "Men"
this[15] = "Cib"
this[16] = "Caban"
this[17] = "Etznab"
this[18] = "Cauac"
this[19] = "Ahau"
}
var Sellos = new ListaSellos()

//lista de imágenes de sellos

function ListaSellosimg(){
this.length = 20
this[0] = "Dragon.gif"
this[1] = "Viento.gif"
this[2] = "Noche.gif"
this[3] = "Semilla.gif"
this[4] = "Serpiente.gif"
this[5] = "Enlazador.gif"
this[6] = "Mano.gif"
this[7] = "Estrella.gif"
this[8] = "Luna.gif"
this[9] = "Perro.gif"
this[10] = "Mono.gif"
this[11] = "Humano.gif"
this[12] = "Caminante.gif"
this[13] = "Mago.gif"
this[14] = "Aguila.gif"
this[15] = "Guerrero.gif"
this[16] = "Tierra.gif"
this[17] = "Espejo.gif"
this[18] = "Tormenta.gif"
this[19] = "Sol.gif"
}
var Sellosimg = new ListaSellosimg()

//Lista de nombre de Uinales

function ListaUinales(){
this.length = 19
this[0] = "Pop"
this[1] = "Uo"
this[2] = "Zip"
this[3] = "Zotz"
this[4] = "Zec"
this[5] = "Xul"
this[6] = "Yaxkin"
this[7] = "Mol"
this[8] = "Chen"
this[9] = "Yax"
this[10] = "Zac"
this[11] = "Ceh"
this[12] = "Mac"
this[13] = "Kankin"
this[14] = "Muan"
this[15] = "Pax"
this[16] = "Kayab"
this[17] = "Cumku"
this[18] = "Uayeb"
}
var Uinales = new ListaUinales()

//Lista de imágenes de Uinales

function ListaUinalesimg(){
this.length = 19
this[0] = "pop.gif"
this[1] = "uo.gif"
this[2] = "zip.gif"
this[3] = "zotz.gif"
this[4] = "zec.gif"
this[5] = "xul.gif"
this[6] = "yaxkin.gif"
this[7] = "mol.gif"
this[8] = "chen.gif"
this[9] = "yax.gif"
this[10] = "zac.gif"
this[11] = "ceh.gif"
this[12] = "mac.gif"
this[13] = "kankin.gif"
this[14] = "muan.gif"
this[15] = "pax.gif"
this[16] = "kayab.gif"
this[17] = "cumku.gif"
this[18] = "uayeb.gif"
}
var Uinalesimg = new ListaUinalesimg()

//Lista de meses en español

function Mesesp(){
this.length =11
this[0] = "Enero" 
this[1] = "Febrero" 
this[2] = "Marzo" 
this[3] = "Abril" 
this[4] = "Mayo" 
this[5] = "Junio" 
this[6] = "Julio" 
this[7] = "Agosto" 
this[8] = "Septiembre" 
this[9] = "Octubre" 
this[10] = "Noviembre" 
this[11] = "Diciembre" 
}
var Mes = new Mesesp()

//Lista de dias semana en español

function Diaesp(){
this.length =6
this[0] = "Domingo" 
this[1] = "Lunes" 
this[2] = "Martes" 
this[3] = "Miercoles" 
this[4] = "Jueves" 
this[5] = "Viernes" 
this[6] = "Sábado"  
}
var Diasemana = new Diaesp()

//Fija choltun en 2 de Mayo de 1900

kin=17
uinal=12
tun=5
katun=14
baktun=12


//calculo sello solar////////////////////////////////////////////////
sellofinal =(dias%20) //utilizo el operador módulo
//sellofinal=dias+1
//set sellofinal [expr ($sellofinal-1)]
//set sello [lindex $sellos [expr $sellofinal]]
sello=Sellos[sellofinal]
//set sellofoto [lindex $selloimg [expr $sellofinal]]
sellofoto =Sellosimg[sellofinal]

//calculo el tono o dia////////////////////////////////////////////////
//set tonotemp [expr fmod($dias,13)]
tono=(dias%13)+1
//set tono [expr int($tonotemp+1)]
//set tonoi [expr ($tono-1)]
//set tonofoto [lindex $tonoimg [expr $tonoi]]


//Calculo Habb//////////////////////////////////////////////////////////

//fecha referencia
//fecharefer=new Date (2004,03,06);
fecharefer=new Date (1900,04,02);
diashaab = (fechaactual-fecharefer)/r;
haabs = (fechaactual-fecharefer)/r;
diast = (fechaactual-fecharefer)/r;
dias = (fechaactual-fecharefer)/r;
anofechaactual = hoy.getFullYear();


while (diast > 365) {

//compensación de los dias visiestos
if ((anofechaactual%4)==0 ) { 
anofechaactual= anofechaactual-1;
haabs= haabs-365;//370
diast =diast-365;//370

} else  { 
haabs=haabs-365; 
anofechaactual=anofechaactual-1;
diast=diast-365;
}
}

dia =(haabs%20)
//

//calculo UINAL//////////////////////////////////////////////////////////
//rota año
resu=dias
if ( dias <=365 ) {
resu =dias
}

while ( resu > 365 ) {

resu = resu-365
}

//Buscando los 19 uinales
if ( resu <= 19 ) {
	deltay=0
}

if ( resu >= 20 && resu <=39 ) {
      deltay=1
}

if ( resu >= 40 && resu <=59 ) {
	deltay=2
}

if ( resu >= 60 && resu <=79 ) {
	deltay=3
}
if ( resu >= 80 && resu <=99 ) {
	deltay=4
}
if ( resu >= 100 && resu <=119 ) {
	deltay=5
}
if ( resu >= 120 && resu <=139 ) {
	deltay=6
}
if ( resu >= 140 && resu <=159 ) {
	deltay=7
}
if ( resu >= 160 && resu <=179 ) {
	deltay= 8
}
if ( resu >= 180 && resu <=199 ) {
	deltay=9
}
if ( resu >= 200 && resu <=219 ) {
	deltay=10
}
if ( resu >= 220 && resu <=239 ) {
	deltay=11
}
if ( resu >= 240 && resu <=259 ) {
	deltay=12
}

if ( resu >= 260 && resu <=279 ) {
	deltay=13
}
if ( resu >= 280 && resu <=299 ) {
	deltay=14
}
if ( resu >= 300 && resu <=319 ) {
	deltay=15
}
if ( resu >= 320 && resu <=339 ) {
	deltay=16
}
if ( resu >= 340 && resu <=359 ) {
	deltay=17
}

if ( resu >= 360 && resu <=365 ) {
	deltay=18
}


//preparando indice de imagen uinal
uinalfoto =Uinalesimg[deltay]
//preparando texto para mostrar
uinaltext=Uinales[deltay]
//uinaldia [lindex $uinaldiaimg [expr $dia]]



//Calculo cuenta larga /////////////////////////////////////////////////////////////

//esto era antes del boton fecha
//set diaactual [clock seconds]
//set diaactual [expr $diaactual/86400]


diaactual= dias


while ( diaactual > 0 ) {
	
	if ( kin < 19 ) {
		kin=kin+1
		diaactual=diaactual-1
	} else  {
		kin= 0
		if (uinal < 17 ) {
		uinal=uinal+1
		diaactual=diaactual-1
	} else  {
		uinal=0
		if ( tun < 19 ) {
		tun= tun+1
		diaactual=diaactual-1
	} else  {
		tun=0
		if ( katun < 19 ) {
		katun=katun+1
		diaactual=diaactual-1
	} else  {
		baktun=0
		if ( baktun < 19 ) {
		baktun=baktun+1
		diaactual=diaactual-1
}
}
}
}
}
}

//fin fecha larga

//Presentacion de resultados

//document.write("<HTML><HEAD><TITLE></TITLE></HEAD><BODY>")
document.write("<BR><FONT SIZE=4 color=#000000><B>Fecha Maya del Día " + Diasemana[hoy.getDay()] + " " + hoy.getDate()+" de "+ Mes[hoy.getMonth()]+" de "+ hoy.getFullYear() +"</B></FONT><BR><BR><P><FONT SIZE=+1><B>")

document.write("<FONT color=#9999FF>CHOLTUN <FONT color=#000000>" +baktun +" " + katun +" " + tun + " " + uinal + " " + kin + "<BR>")
document.write("<FONT color=#9999FF>TZOLKIN <FONT color=#000000> "+ tono + " " + sello + " ")
document.write("<IMG SRC="+"./images/" + sellofoto + ">" + "<BR>")
document.write("<FONT color=#9999FF>HAAB <FONT color=#000000>" + dia + " "+ uinaltext+ " " )
document.write("<IMG SRC="+"./images/" + uinalfoto + ">" + "<BR><BR>")

//document.write("Uinal:" + sellofinal + "<BR>")
//document.write("Dias " + dias + "<BR>")
document.write("</B><FONT SIZE=3 color=#660000><BR>")
//document.write("</BODY></HTML>")
