var months = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

function init(){
	if(document.getElementById("browseMonthSelect"))
		remDupBrowseOptions();
	if(document.getElementById("articleListingTable"))
		organizeArticles();
	if(location.hash) location.hash = location.hash;
}

function organizeArticles(){
	var articles = document.getElementById("articleListingTable").getElementsByTagName("TR");
	var numNewRows = 0;
	for(var i=0; (i+numNewRows)<articles.length; i++){
		if( (i==0) || ( ((articles[i+numNewRows].id.substring(0,4)) != (articles[i+numNewRows-1].id.substring(0,4))) || ((articles[i+numNewRows].id.substring(5,7)) != (articles[i+numNewRows-1].id.substring(5,7))) ) ){
			var newHeadRow = document.createElement("TR");
			var newHeadCell = document.createElement("TD");
			var month;
			if(articles[i+numNewRows].id.charAt(5)=='0'){
				month = parseInt(articles[i+numNewRows].id.charAt(6))-1;
			}else{
				month = parseInt(articles[i+numNewRows].id.substring(5,7))-1;
			}
			newHeadCell.colSpan = '3';
			newHeadCell.className = 'listingHeader';
			newHeadCell.innerHTML = '<a name=' + articles[i+numNewRows].id.substring(0,7) + '></a><span>' + months[month] + '&nbsp;' + articles[i+numNewRows].id.substring(0,4) + '</span>';
			newHeadRow.appendChild(newHeadCell);
			articles[i+numNewRows].parentNode.insertBefore(newHeadRow,articles[i+numNewRows]);
			numNewRows++;
		}
	}
}

function remDupBrowseOptions(){
	var articles = document.getElementById("browseMonthSelect").getElementsByTagName("OPTION");
	if(articles.length<2) return;
	for(var i=2; i<articles.length; i++){
		if( ((articles[i].id.substring(0,4)) == (articles[i-1].id.substring(0,4))) && ((articles[i].id.substring(5,7)) == (articles[i-1].id.substring(5,7))) ){
			articles[i].parentNode.remove(i);
			i--;
		}
	}

}


