
// This code orders all callout header colors automatically
// Version 1.0.1

// Place this code after the last callout on the page
// Call the JavaScript file: 
// "//www.ibm.com/systems/js/sortcalloutcolors.js"
// Next, call this JavaScript function on your page (under script tags):
// sortCalloutColors(); 

// To customize the number of blue-headers and lightgray-headers, 
// use the number of blue and lightgray headers under the parenthesis
// For example: sortCalloutColors(2,3); 
// You would have 2 blue headers and 3 light gray headers, and the rest would be white

// Authors:
// Ronaldo Messias de Aguiar/Brazil/Contr/IBM@IBMBR
// Fabio Adriano Ferreira de Almeida/Brazil/Contr/IBM@IBMBR
// Rodrigo da Silva Melo/Brazil/Contr/IBM@IBMBR

// ibm.com - Global Web Production Services

function sortCalloutColors(blueheaders,lgrayheaders){

	var dom = (document.getElementsByTagName)?true:false; // verify if browser is DOM enabled

	if(dom){ // runs only if browser is DOM enabled

		var allTr, el, reg, i, c, b; // declares variables

		if (typeof(blueheaders) == 'undefined') blueheaders = 1; // default number of blue headers
		if (typeof(lgrayheaders) == 'undefined') lgrayheaders = 2;  // default number of lightgray headers
		reg = /^(v14-header-)(\d)(-small)$/; // regular expression for all hearder classes
		c = 1; // this counter numbers all the callouts

		allTr = document.getElementsByTagName('tr'); // gets all <tr> 
		
		for (i = 0; i < allTr.length; i++){ // scans all <tr>

			for (b=0; (el = allTr[i].childNodes[b]) && el.nodeType!=1; b++); // gets only the first valid tag inside <tr>. it can be a <td> or <th>

			if (reg.test(el.className)){ // verify if this is a callout header

				if (c <= blueheaders ) el.className='v14-header-1-small'; // sets as blue-headered
				else if (c <= (blueheaders + lgrayheaders) ) el.className='v14-header-4-small'; // sets as lightgray-headered
				else el.className='v14-header-3-small'; // sets other callouts as white-headered

				c++; // go to next callout

			}
		}
	}
}
