// This function add an img "update" tag to each rows from a column (index with class "updateFlag" or first column) from a table (with class "main") 
 // based on row values data-updateYear="2022" data-updateMonth="Feb"
 // only for current month and month+1
 
  
(function() {


	var table = document.getElementsByClassName("main");
	if (table.length===0){ return -1;}	
		
	var index,indexes = document.getElementsByClassName("updateFlag");
	if (indexes.length===0){ index=0;}
	else {index = indexes[0].cellIndex;}
		
		
	for (var i = 0, row; row = table[0].rows[i]; i++) {
		console.dir(table[0].rows[i]);
		if (row.hasAttribute("data-updateYear")) {		
					
			var year = row.getAttribute("data-updateYear") ? parseInt(row.getAttribute("data-updateYear")): 2023; // default 2022
			var month = row.getAttribute("data-updateMonth") ? new Date(Date.parse(row.getAttribute("data-updateMonth") +" 1, 2023")).getMonth() + 1: 0; // default jan
			var now = new Date();				
			if(year === now.getFullYear() && ( month === now.getMonth() || month-1 === now.getMonth() ) )  { // show img for this month + next one (published one month later )
				row.cells[index].insertAdjacentHTML("afterbegin",'<img src="../images/update1.gif" width="22" height="10" alt=""><br>');
			}	
			
		}
	}
})();