﻿/*
	ChangeTab
	
	Functions change the style display value of a set of containers.
	
	An array named "setArray" is necessary in order for this function to
	work properly.
	
	Author: Matthew Elliott matt_elliott(at)sonic.com
	
	Copyright 2005 Sonic Solutions.  All rights reserved.
	
	# Revised 2006-07-17 to add support for changing a tab without an ID
*/

/* function changeTab
	@param id - Element id
	@return nothing
	
	Calls the appropriate functions for toggling the visibility of the tabs
	defined in the setArray based on the id requesting the display change.
*/
function changeTab(id, this_id) {
	var currentId = id;
	
	for (i = 0; i < setArray.length; i++) {
		if (setArray[i] != id) {
			turnOff(setArray[i]);
		}
	}
	
	if (arguments.length >= 2) {
		toggleHighlightByElement(arguments[2].parentNode);
	}
	else {
		toggleHighlight(this_id);
	}
	
	toggleVisibility(id, currentId);
	
	return;
}

/* function toggleVisibility
	@param id currentId - Element id is the element to toggle the visibility. 
		currentId is the currently active element id.
	@return Nothing
	
	Calls the turnOn or turnOff functions depending on the current visibility
	of the element requesting the toggle. If the element requesting the toggle
	is the currently visible element, then its request will be ignored.
*/
function toggleVisibility(id, currentId){
	try {
		var me = document.getElementById(id);
	
		if	(me.style.display=="none"){
			turnOn(id);
		}
		else if (id != currentId) {
			turnOff(id);
		}
	}
	catch (e) {}
	
	return;
}

/* function turnOff
	@param id - Element id
	@return Nothing
	
	Accepts an Element id and sets the style display to none
*/
function turnOff(id) {
	try {
		var me = document.getElementById(id);
		me.style.display = "none";
	}
	catch (e) {}
}

/* function turnOn
	@param id - Element id
	@return Nothing
	
	Accepts an Element id and sets the style display to block
*/
function turnOn(id) {
	try {
		var me = document.getElementById(id);
		me.style.display = "block";
	}
	catch (e) {}
}

function toggleHighlight(id) {
	try {
		toggleHighlightByElement(document.getElementById(id));
	}
	catch (e) { }
}

function toggleHighlightByElement(me) {
	try {
		var FORMAT_ON_1 = "_on";
		var FORMAT_ON_2 = " on";
		
		var formatFlag = false;
		
		if (me.className.indexOf(FORMAT_ON_1) > 0) {
			// do nothing
			formatFlag = true;
		}
		else if (me.className.indexOf(FORMAT_ON_2) > 0) {
			//do nothing
		}
		else {
			if (formatFlag == true) {
				turnOnHighlightByElement(me, FORMAT_ON_1);
			}
			else {
				turnOnHighlightByElement(me, FORMAT_ON_2);
			}
		}
		
		var children = me.parentNode.childNodes;
		
		for (i = 0; i < children.length; i++) {
			if ((children[i] != me) && (children[i].nodeType != 3)) {
				if (formatFlag == true) {
					turnOffHightlightByElement(children[i], FORMAT_ON_1);
				}
				else {
					turnOffHightlightByElement(children[i], FORMAT_ON_2);
				}
			}
		}
	}
	catch (e) { }
}

function turnOnHightlight(id, format) {
	try {
		turnOnHighlightByElement(document.getElementById(id), format);	
	}
	catch (e) { }
}

function turnOnHighlightByElement(me, format) {
	try {
		me.className = me.className + format;
	}
	catch (e) { }
}

function turnOffHightlight(id, format) {
	try {
		turnOffHightlightByElement(document.getElementById(id), format);
	}
	catch (e) { }
}

function turnOffHightlightByElement(me, format) {
	try {
		me.className = me.className.replace(format, "");
	}
	catch (e) { }
}
