﻿//This function will swap out a specific css class (src) from an HTML element for another class (dest).
//This function takes into account that there may me multiple classes per element.
//If the source class is not found, then the destination class will be appended.
function SwapCssClass(obj, src, dest)
{
	var replaced = false;
	
	//If the source class is blank then the caller intends to append the class.
	if (src != '')
	{	
		//Get all the css classes currently contained by this element, and then recreate the 
		//class list, replacing the source class with the destination class.
		var classes = new Array();
		classes = obj.className.split(' ');
		obj.className = '';
		for(i = 0; i < classes.length; i++)
		{
			if (classes[i] == src)
			{
				obj.className = obj.className + dest + ' ';
				replaced = true;
			}
			else
			{
				obj.className = obj.className + classes[i] + ' ';
			}
		}
	}

	//If the destination class was never written, then the source class wasn't found 
	//so append the destination class.	
	if (!replaced)
	{
		obj.className = obj.className + dest + ' ';
	}
	
	//Remove the trailing space.
	obj.className = obj.className.substring(0, obj.className.length - 1);
}
