function subMenu(Opcion) {
	if (Opcion != "SubQuienesSomos") document.getElementById("SubQuienesSomos").style.display = "none";
	if (Opcion != "SubNoticias") document.getElementById("SubNoticias").style.display = "none";
	// if (Opcion != "SubEnlaces") document.getElementById("SubEnlaces").style.display = "none";
	if (Opcion != "SubDocumentos") document.getElementById("SubDocumentos").style.display = "none";
	
	document.getElementById(Opcion).style.display = (document.getElementById(Opcion).style.display == "") ? "none" : "";
}


function cambiaOpcion(frm) {
	switch(frm.Opcion.value) {
		case "resultados.php":
			document.getElementById("ColTitulo").style.display 				= "";
			document.getElementById("ColFecha").style.display 				= "";
			document.getElementById("ColNombreApellido").style.display 	= "";
			document.getElementById("ColOrganizaciones").style.display 	= "";
			document.getElementById("ColPais").style.display 					= "";
			document.getElementById("ColUbicacion").style.display 			= "";
			break;
		case "proyectos_listado.php":
			document.getElementById("ColTitulo").style.display 				= "";
			document.getElementById("ColFecha").style.display 				= "";
			document.getElementById("ColNombreApellido").style.display 	= "none";
			document.getElementById("ColOrganizaciones").style.display 	= "none";
			document.getElementById("ColPais").style.display 					= "";
			document.getElementById("ColUbicacion").style.display 			= "none";
			break;
		case "noticias_listado.php?Categoria=1":
		case "noticias_listado.php?Categoria=2":
		case "noticias_listado.php?Categoria=3":
			document.getElementById("ColTitulo").style.display 				= "";
			document.getElementById("ColFecha").style.display 				= "";
			document.getElementById("ColNombreApellido").style.display 	= "none";
			document.getElementById("ColOrganizaciones").style.display 	= "none";
			document.getElementById("ColPais").style.display 					= "none";
			document.getElementById("ColUbicacion").style.display 			= "none";
			break;
		case "eventos_listado.php":
			document.getElementById("ColTitulo").style.display 				= "";
			document.getElementById("ColFecha").style.display 				= "";
			document.getElementById("ColNombreApellido").style.display 	= "none";
			document.getElementById("ColOrganizaciones").style.display 	= "none";
			document.getElementById("ColPais").style.display 					= "";
			document.getElementById("ColUbicacion").style.display 			= "";
			break;
		case "expertos_listado.php":
			document.getElementById("ColTitulo").style.display 				= "none";
			document.getElementById("ColFecha").style.display 				= "none";
			document.getElementById("ColNombreApellido").style.display 	= "";
			document.getElementById("ColOrganizaciones").style.display 	= "none";
			document.getElementById("ColPais").style.display 					= "none";
			document.getElementById("ColUbicacion").style.display 			= "none";
			break;
		case "organizaciones_listado.php":
			document.getElementById("ColTitulo").style.display 				= "none";
			document.getElementById("ColFecha").style.display 				= "none";
			document.getElementById("ColNombreApellido").style.display 	= "none";
			document.getElementById("ColOrganizaciones").style.display 	= "";
			document.getElementById("ColPais").style.display 					= "";
			document.getElementById("ColUbicacion").style.display 			= "";
			break;
		case "acuerdos_listado.php":
		case "publicaciones_listado.php":
		case "instrumentos_listado.php":
			document.getElementById("ColTitulo").style.display 				= "";
			document.getElementById("ColFecha").style.display 				= "";
			document.getElementById("ColNombreApellido").style.display 	= "none";
			document.getElementById("ColOrganizaciones").style.display 	= "none";
			document.getElementById("ColPais").style.display 					= "none";
			document.getElementById("ColUbicacion").style.display 			= "none";
			break;
		case "estadisticas_listado.php":
			document.getElementById("ColTitulo").style.display 				= "";
			document.getElementById("ColFecha").style.display 				= "";
			document.getElementById("ColNombreApellido").style.display 	= "none";
			document.getElementById("ColOrganizaciones").style.display 	= "none";
			document.getElementById("ColPais").style.display 					= "";
			document.getElementById("ColUbicacion").style.display 			= "none";
			break;
	}
	
	frm.action=frm.Opcion.value;
}


// This function gets called when the end-user clicks on some date.
function selected(cal, date) {
  cal.sel.value = date; // just update the date in the input field.
  if (cal.dateClicked)
    // if we add this call we close the calendar on single-click.
    // just to exemplify both cases, we are using this only for the 1st
    // and the 3rd field, while 2nd and 4th will still require double-click.
    cal.callCloseHandler();
}

// And this gets called when the end-user clicks on the _selected_ date,
// or clicks on the "Close" button.  It just hides the calendar without
// destroying it.
function closeHandler(cal) {
  cal.hide();                        // hide the calendar
//  cal.destroy();
  _dynarch_popupCalendar = null;
}


// This function shows the calendar under the element having the given id.
// It takes care of catching "mousedown" signals on document and hiding the
// calendar if the click was outside.
function showCalendar(id, format, showsTime, showsOtherMonths) {
	var el = document.getElementById(id);
	if (_dynarch_popupCalendar != null) {
	// we already have some calendar created
	_dynarch_popupCalendar.hide();                 // so we hide it first.
	} else {
	// first-time call, create the calendar.
	var cal = new Calendar(1, null, selected, closeHandler);
	// uncomment the following line to hide the week numbers
	// cal.weekNumbers = false;
	if (typeof showsTime == "string") {
	cal.showsTime = true;
	cal.time24 = (showsTime == "24");
	}
	if (showsOtherMonths) {
	cal.showsOtherMonths = true;
	}
	_dynarch_popupCalendar = cal;                  // remember it in the global var
	cal.setRange(1900, 2070);        // min/max year allowed.
	cal.create();
	}
	_dynarch_popupCalendar.setDateFormat(format);    // set the specified date format
	_dynarch_popupCalendar.parseDate(el.value);      // try to parse the text in field
	_dynarch_popupCalendar.sel = el;                 // inform it what input field we use

	// the reference element that we pass to showAtElement is the button that
	// triggers the calendar.  In this example we align the calendar bottom-right
	// to the button.
	_dynarch_popupCalendar.showAtElement(document.getElementById(id+'Img'), "Br");        // show the calendar

	return false;
}


function dateIsSpecial(year, month, day) {
	try {var m = SPECIAL_DAYS[year][month];} catch(e){}
	if (!m) return false;
	for (var i in m) if (m[i] == day) return true;
	return false;
};
function ourDateStatusFunc(date, y, m, d) {
	return (dateIsSpecial(y, m, d)) ? "evento" : false;
};



function dateChanged(calendar) {
	// Beware that this function is called even if the end-user only
	// changed the month/year.  In order to determine if a date was
	// clicked you can use the dateClicked property of the calendar:
	if (calendar.dateClicked) {
		// OK, a date was clicked, redirect to /yyyy/mm/dd/index.php
		var y = calendar.date.getFullYear();
		var m = Right("00"+(calendar.date.getMonth()+1), 2);     // integer, 01..12
		var d = Right("00"+calendar.date.getDate(), 2);      // integer, 01..31
		
		// Direccion.
		var Location = "eventos_listado.php?FechaDesde="+d+"%2F"+m+"%2F"+y+"&FechaHasta="+d+"%2F"+m+"%2F"+y;
		if (dateIsSpecial(y, (m-1), d)) window.location = Location
	}
}


function showFlatCalendar(Calendario) {
  var parent = document.getElementById(Calendario);

  // construct a calendar giving only the "selected" handler.
  var cal = new Calendar(0, null, dateChanged);

  // hide week numbers
  cal.weekNumbers = false;
  

  cal.setDisabledHandler(ourDateStatusFunc);
  cal.setDateFormat("%A, %B %e");

  // this call must be the last as it might use data initialized above; if
  // we specify a parent, as opposite to the "showCalendar" function above,
  // then we create a flat calendar -- not popup.  Hidden, though, but...
  cal.create(parent);

  // ... we can show it here.
  cal.show();
}


function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}


var pagina = 1;
function cambiaNoticiasHome(accion) {
	(accion=='ant') ? pagina-- : pagina++;
	EnviaGet('noticias_home.php', 'pag='+pagina, cambiaNoticiasHomeVuelta);
}
function cambiaNoticiasHomeVuelta() {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			var xmlDoc 	= http_request.responseXML.documentElement;
			pagina 			= xmlDoc.getElementsByTagName("pagina");
			pagina 			= parseInt(pagina[0].childNodes[0].nodeValue);
			noticia 			= xmlDoc.getElementsByTagName("noticia");
			noticia 			= noticia[0].childNodes[0].nodeValue;
			
			document.getElementById("noticiaHome").innerHTML = noticia;
		} else {
			alert('There was a problem with the request.');
		}
	}
}


var paginaP = 1;
function cambiaProyectosHome(accion) {
	(accion=='ant') ? paginaP-- : paginaP++;
	EnviaGet('proyectos_home.php', 'pag='+paginaP, cambiaProyectosHomeVuelta);
}
function cambiaProyectosHomeVuelta() {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			var xmlDoc 	= http_request.responseXML.documentElement;
			paginaP 			= xmlDoc.getElementsByTagName("pagina");
			paginaP 			= parseInt(paginaP[0].childNodes[0].nodeValue);
			proyecto 		= xmlDoc.getElementsByTagName("proyecto");
			proyecto 		= proyecto[0].childNodes[0].nodeValue;
			
			document.getElementById("proyectoHome").innerHTML = proyecto;
		} else {
			alert('There was a problem with the request.');
		}
	}
}

