
function CST_Init()
{
	// Eliminate some forum interface elements to make articles look more like articles
	var AddressBarURL = new String( window.location );
	if( -1 != AddressBarURL.search("atei.ro/Pagini/") )
	{
		// Hide the first table after the 2nd table with class="bordercolor"
		var CompleteTableList = document.getElementsByTagName("table");
		var ProcessedElements = 0;
		for( idx = 0; idx < CompleteTableList.length; idx++ )
		{
			if( "bordercolor" == CompleteTableList[idx].className )
			{
				ProcessedElements++;
				
				if( 2 == ProcessedElements )
				{
					CompleteTableList[idx+1].style.display = "none";
					break;
				}
			}
		}
		
		// Hide the 3rd TD in the second table with style="table-layout: fixed;"
		ProcessedElements = 0;
		for( idx = 0; idx < CompleteTableList.length; idx++ )
		{
			if( -1 != CompleteTableList[idx].style.cssText.search("table-layout: fixed;") )
			{
				ProcessedElements++;
				
				if( 2 == ProcessedElements )
				{
					CompleteTableList[idx].getElementsByTagName("td")[2].style.display = "none";
					break;
				}
			}
		}
		
		// Hide all tables with class="tborder" and the one after the 3rd
		ProcessedElements = 0;
		for( idx = 0; idx < CompleteTableList.length; idx++ )
		{
			if( "tborder" == CompleteTableList[idx].className )
			{
				CompleteTableList[idx].style.display = "none";
				ProcessedElements++;
				
				if( 3 == ProcessedElements )
				{
					CompleteTableList[idx+2].style.display = "none";
					break;
				}
			}
		}
		
		// Hide the TD with width=16%
		var CompleteTDList = document.getElementsByTagName("td");
		for( idx = 0; idx < CompleteTDList.length; idx++ )
		{
			if( "16%" == CompleteTDList[idx].width )
			{
				CompleteTDList[idx].style.display = "none";
			}
		}
		
		ProcessedElements = 0;
		for( idx = 0; idx < CompleteTDList.length; idx++ )
		{
			if( "85%" == CompleteTDList[idx].width )
			{
				ProcessedElements++;
				
				if( 2 == ProcessedElements )
				{
					CompleteTDList[idx].getElementsByTagName("table")[0].style.display = "none";
					CompleteTDList[idx].getElementsByTagName("hr")[0].style.display = "none";
					break;
				}
			}
		}
	}
	
	// Insert the RestrictionSearch call if we're viewing "Ilustri necredinciosi"
	if( -1 != AddressBarURL.search("/ilustri-necredinciosi") )
	{
		document.getElementsByName("search")[0].setAttribute("onKeyUp", "CST_RestrictionSearch();");
    }
}

function CST_RestrictionSearch()
{
	// The expression to search for will be the currently entered text with the case-insensitive modifier
	var TextInput = document.getElementsByName("search")[0];
	var CurrentSearchExpression = new RegExp( TextInput.value, "i" );

	// Find the <DIV class="post"...>
	var CompleteDivList = document.getElementsByTagName("div");
	var TheAtheistList;
	var idx;
	for( idx = 0; idx < CompleteDivList.length; idx++ )
	{
		if( "post" == CompleteDivList[idx].className )
		{
			TheAtheistList = CompleteDivList[idx].getElementsByTagName("div");
			break;
		}
	}

	// Process each <DIV style="text-align:left...> inside the AtheistList
	for( idx = 1; idx < TheAtheistList.length; idx++ )
	{
		if( -1 != TheAtheistList[idx].style.cssText.search("text-align: left;") )
		{
			// Trim the searchable string down to its actual text-contents
			var SearchableString = new String( TheAtheistList[idx].innerHTML );
			SearchableString = SearchableString.replace( /<\/?[^>]+>/ig, "" );
			
			// Search for the pattern the user just entered
			if( -1 == SearchableString.search(CurrentSearchExpression) )
			{
				TheAtheistList[idx].style.display = "none";
			}
			else
			{
				TheAtheistList[idx].style.display = "block";
			}
		}
	}
}

document.observe( "dom:loaded", CST_Init );
document.addEventListener( "DOMContentLoaded", CST_Init, false );

