/*

The idea here is that we do not need to force people to do some CSS-related things in Contribute that we can just take care of with a script like this. This function will cycle through the links in the main content area and assign icon clases to the links that need them. The function is added to the window.onload event handler.

Theoretically, this is useful for any CSS-related task we wish to accomplish that cannot be done through Contribute. Those users only have limited abilities to apply certain styles and use certain HTML entities, and Contribute seems to balk at the suggestion of using special classes that we put together. Note that this should only be used on Contribute pages, because it is neither proper nor convenient to rely on Javascript to accomplish this stuff on pages where we may simply apply these styles ourselves.

*/

function assignLinkClasses() {
	if (document.getElementById && document.getElementsByTagName) {
		var itContribute;
		if (itContribute = document.getElementById('itContribute')) {
			var links = itContribute.getElementsByTagName('a');
			for (l=0; l < links.length; l++) {
				link = links[l];
				if (!link.className) {
					// Search for specific things about the link.
					href = link.getAttribute('href');
					if (href.indexOf('mailto:') == 0) {
						link.className = 'icon-email';
					} else if (href.indexOf('.pdf') == href.length-4) {
						link.className = 'icon-pdf';
					} else if (href.indexOf('.doc') == href.length-4) {
						link.className = 'icon-doc';
					}
				}
			}
		}
	}
}

var oldOnload = window.onload;
window.onload = function() {
	if (oldOnload) oldOnload;
	assignLinkClasses();
}