/*****************************************
** Used with 1 div. This activates it.	**
** Currently used by: N/A				**
*****************************************/
function toggle_on_div(div_name)
{
	document.getElementById(div_name).style.display = "block";
}

/*********************************************
** Used with 1 div. This deactivates it.	**
** Currently used by: N/A					**
*********************************************/
function toggle_off_div(div_name)
{
	document.getElementById(div_name).style.display = "none";
}

/*************************************************************************
** Used with 2 divs. This deactivates one when the other is activated.	**
** Currently used by: Ajax dynamic drop-down							**
*************************************************************************/
function toggle_on_div_toggle_off_other(div_name,other_div)
{
   document.getElementById(div_name).style.display = "block";
   
   if (document.getElementById(other_div).style.display == "block")
   {
	   document.getElementById(other_div).style.display = "none";
   }
}

/*************************************************************************
** Used with 1 div. Toggles div											**
*************************************************************************/
function toggle_div(div_name,other_div)
{
	if(document.getElementById(div_name).style.display == "block")
	{
   		document.getElementById(div_name).style.display = "none";
	}
   
   if (document.getElementById(div_name).style.display == "none")
   {
	   document.getElementById(div_name).style.display = "block";
   }
}
/*********************************************************************************
** Used with > 2 divs. This deactivates all other divs when one is activated.	**
** Currently used by: Form Elements												**
*********************************************************************************/
function toggle_on_div_toggle_off_others(div_count,type_num,div_id)
{
   for (i = 0; i < div_count; i++)
   {
	   var increment = i + 1;
	   
	   if (increment == type_num)
	   {
		   document.getElementById(div_id+'_div_'+increment).style.display = "block";
	   }
	   else
	   {
		   document.getElementById(div_id+'_div_'+increment).style.display = "none";
	   }
   }
   
}
/*********************************************************************************
** Add or Remove classes.														**
** Currently used by: Tabbed Login												**
*********************************************************************************/
// Make sure the "FM" namespace object exists
if (typeof FM != 'object') {
    FM = new Object();
}

/**
 * Checks a given class attribute for the presence of a given class
 *
 * @author  Dan Delaney     http://fluidmind.org/
 * @param   element         DOM Element object (or element ID) to remove the class from
 * @param   nameOfClass     The name of the CSS class to check for
 */
FM.checkForClass = function(element, nameOfClass) {
    if (typeof element == 'string') { element = document.getElementById(element); }

    if (element.className == '') {
        return false;
    } else {
        return new RegExp('\\b' + nameOfClass + '\\b').test(element.className);
    }
}


/**
 * Adds a class to an element's class attribute
 *
 * @author  Dan Delaney     http://fluidmind.org/
 * @param   element         DOM Element object (or element ID) to add the class to
 * @param   nameOfClass     Class name to add
 * @see     checkForClass
 */
FM.addClass = function(element, nameOfClass) {
    if (typeof element == 'string') { element = document.getElementById(element); }

    if (!FM.checkForClass(element, nameOfClass)) {
        element.className += (element.className ? ' ' : '') + nameOfClass;
        return true;
    } else {
        return false;
    }
}


/**
 * Removes a class from an element's class attribute
 *
 * @author  Dan Delaney     http://fluidmind.org/
 * @param   element         DOM Element object (or element ID) to remove the class from
 * @param   nameOfClass     Class name to remove
 * @see     checkForClass
 */
FM.removeClass = function(element, nameOfClass) {
    if (typeof element == 'string') { element = document.getElementById(element); }

    if (FM.checkForClass(element, nameOfClass)) {
        element.className = element.className.replace(
            (element.className.indexOf(' ' + nameOfClass) >= 0 ? ' ' + nameOfClass : nameOfClass),
            '');
        return true;
    } else {
        return false;
    }
}

