<!-- Starts updates_toc.js

/////////////////////////////////////////
// Author: Ariel Yoguel
// Last version: jun-2007
// Description: prints news TOC
/////////////////////////////////////////

if (Updates == undefined) {}
else {
	// Defines news.html location
	var news_href = "";
	for (var i = 0; i < Files.length; i++) {
		if (Files[i][2] == "Novedades") {
			news_href = Files[i][1];
			break;
		}
	}
	
	// Defines how many lines will be printed
	var n_short_format = 10;
	var n_long_format = 18;
	
	// Verbose output when in news.html, otherwise brief format
	var long_format = (in_news_section) ? true : false;
	
	// In long format
	if (long_format) {
		// Prints header
		document.writeln("<h2>Novedades</h2>");
		
		// Opens list
		document.writeln("<ul id='updates_long'>");
	}
	// In TOC
	else {
		// Prints header
		document.writeln("<h3>Novedades</h3>");
	
		// Opens list
		document.writeln("<ul id='updates_toc'>");
	}
	
	// Defines number of lines
	var number_of_lines = long_format ? n_long_format : n_short_format;
	
	// 'count' counts number of lines
	var count = 0;
	for (var i = 0; count < number_of_lines; i++) {
		
		var news_date = Updates[i][0];
		var news_month = Updates[i][1];
		var news_year = Updates[i][2];
		var short_desc = Updates[i][3];
		var long_desc = Updates[i][4];
		var show = Updates[i][5];
		
		// Shows news by default
		if (show == undefined) show = true;
		
		// Prints nothing
		if (short_desc == "" || !show || short_desc == undefined || news_date == undefined || news_month == undefined || news_year == undefined) {}
			// Prints line
			else {
			// Date string construction
		
			// Date in short format
			// Date
			var short_date_string = news_date < 10 ? "0" + news_date : news_date;
			
			// Month
			short_date_string += "-" + Cal[ news_month - 1 ];
			
			// Date (deleted)
			// short_date_string += "-" + (news_year < 10 ? "0" + news_year : news_year);
			
			// Date in long format
			var news_date_object = new Date(2000 + news_year, news_month - 1, news_date);
			var day_of_the_week_number = news_date_object.getDay();
			var day_of_the_week_desc = Days_of_the_week[day_of_the_week_number];
			var long_date_string = day_of_the_week_desc + " " + news_date + " de " + Calendar[news_month - 1];
		
			// First line
			if (count == 0) {
				//  Today's date (millisecs)
				var today_stamp = new Date();
				var today_millisecs = Date.parse(today_stamp);
				
				// Last update's date (millisecs)
				var last_updated_millisecs = Date.parse(news_date_object);
				
				// Difference between update's date and today's date
				var millisecs_difference = today_millisecs - last_updated_millisecs;
				
				// Highlights last update within 3 days (86400000 millisecs/day)
				var highlight_last_update = (millisecs_difference < 259200000) ? true : false;
			} // End if count
			
			// Opens line
			document.write("<li>");
			
			// Opens highlighting if necessary
			if (highlight_last_update && count == 0) {
				// In long format
				if (long_format) {
					// Opens highlighting in long format with id
					// document.write("<div id='updates_highlighting_inLong'>");
				}
				// In TOC
				else {
					// Opens highlighting in TOC format with id
					document.write("<div id='updates_highlighting_inTOC'>");	
				}							
			} // End if highlight_last_update && count == 0
			
			if (long_format) {
				// Prints date in long format with anchor
				document.write("<a name='anchor_" + count + "'>" + long_date_string + "</a>");
				// There is no separator needed
			}
			else {
				// Prints date in short format
				document.write(short_date_string);
				// Prints separator
				document.write(":&nbsp;");
			}
			
			// Prints no link
			if (long_format || long_desc == "" || long_desc == undefined) {
				
				// Prints short description
				
				// In long format
				if (long_format) {
					// Prints short description in long format with id and highlighted
					if (highlight_last_update && count == 0) {
						document.write("<div class='short_desc_element_inLong'>");
						document.write("<div id='updates_highlighting_inLong'>" + short_desc + "</div>");
						document.write("</div>");					
					} // End if 
					// Prints short description in long format with id but not highlighted
					else {
						document.write("<div class='short_desc_element_inLong'>" + short_desc + "</div>");
					} // End else
				}
				// In TOC
				else {
					// Prints short description in TOC with id
					document.write("<div class='short_desc_element_inTOC'>" + short_desc + "</div>");
					
				}
				
				// Prints long description if necessary
				if (long_format && long_desc != "" && long_desc != undefined) {
					document.write("<div class='long_desc_element'>" + long_desc + "</div>");
				}	
			}
			// Prints link
			else {
				var long_desc_length = long_desc.length; // With HTML
				var link_title = long_desc.substring(0,long_desc_length);
	
				// Deletes all HTML
				var myRe = /<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gi;
				link_title = link_title.replace(myRe, "");
			
				// Rewrite simple quotation marks (there is no doubles)
				link_title = link_title.replace(/'/g, "\"");
				
				// Rewrite &quot; as "
				link_title = link_title.replace(/\&quot;/g, "\"");
				
				var link_title_length = link_title.length; // Without HTML
	
				// Max length permitted
				var max_title_length = 100;
				
				// Longer
				if (link_title_length > max_title_length) {
					// Shortening
					link_title = link_title.substring(0,max_title_length);
					link_title += "...";
				}
				// Shorter
				else {}
	
				// Defines link URL
				var link_href = news_href;
				// Adds anchor number (if link is off anchor number counts anyway)
				link_href += "#anchor_" + count;
	
				// Opens short description id
				document.write("<div class='short_desc_element_inTOC'>");
	
				// Opens link
				document.write("<a href='" + link_href + "' title='" + link_title + "'>");
	
				// Prints short description (no wrapping)
				document.write("<span class='nowrap'>" + short_desc + "</span>");
				
				// Closes link
				document.write("</a>");
				
				// Closes short description id
				document.write("</div>");
			} // End if long_format
			
			// Closes highlighting if necessary
			if (highlight_last_update && count == 0 && !long_format) {
				document.write("</div>");			
			}
			
			// Closes line
			document.writeln("</li>");
			count++;
		} // End if short_desc
	} // End for i
	
	// Closes list
	document.writeln("</ul>");
} // Else ends

// Ends updates_toc.js -->
