/*************************
@Javascript - Extra Functions
@Page: extra_functions.js
**************************/

/***********************************************
@Function: find_DOM()
@Description: Will find an object' DOM and assign a style
attribute if the user wants one assigned.

@Arguments :: object_id, incl_style
	@object_id = id name of the object
	@incl_style = set to 1 to add style, any other # to not
***********************************************/
function find_DOM(object_id,incl_style)
{ 
    if (document.getElementById) { 
        found_object = document.getElementById(object_id); 
    } 
    else if (document.all) { 
        found_object = document.all[object_id]; 
    } 
    else { 
        browser_version = parseInt(navigator.appVersion); 
        if ((navigator.appName.indexOf('Netscape') != 1 && browser_version == 4)) { 
            found_object = document.layers[object_id]; 
            var nav4 = true; 
        }      
    } 

    if (incl_style == 1 && !nav4) { 
        return found_object.style; 
    } else { 
        return found_object; 
    }          
} 


/***********************************************
@Function: change_tab()
@Description: This function will change the tab and content
for the user.

@Arguments :: obj
	@obj = The object which should be shown as selected
***********************************************/
function change_tab(obj)
{
	var sel = "tabBGSel";
	var nor = "tabBG";
	var selSpecial = "tabBGSpecialSel";
	var norSpecial = "tabBGSpecial";
	var c_class = obj.className;
	var c_id = obj.id;
	var td = document.getElementsByTagName("td");
	var td_id = new String();
	var dom_style = new String();
	var pos = new String();
	var positions = new Array("_upper","_lower","_mid");
	
	if (c_class.indexOf("Special") != -1) {
		var special = true;
	} else {
		var special = false;
	}

	//If the table class is set to not selected run the code
	//We check this because we don't want the user to hide
	//everything they are looking at. If they were to click on
	//the tab they are currently on, and this precaution is not
	//set it would hide everything.
	if (c_class == nor || c_class == norSpecial) {
		if (special) {
			obj.className = selSpecial;
		} else {
			obj.className = sel;
		}

		//Figure out if the tab positions are in upper, lower, or mid
		//region of the page, and set the pos variable
		for (var x = 0; x < positions.length; x++) {
			if (c_id.indexOf(positions[x]) != -1) {
				pos = positions[x];
			}
		}

		//Cycle thru all the table columns and find the id param
		//If the id is not equal to the current id and the word tab_
		//and variable pos are found in the id, we change the class
		//to look like it has been indexed back one level
		for(var i = 0; i < td.length; i++) {
			td_id = td[i].id;
			if (td_id != c_id && td_id.indexOf("tab_") != -1 && td_id.indexOf(pos) != -1) {
				dom_style = find_DOM(td_id,0);
				if (dom_style.className.indexOf("Special") != -1) {
					dom_style.className = norSpecial;
				} else {
					dom_style.className = nor;
				}
			}
		}

		//Call the tab_content function
		tab_content(obj,pos);
	}
}

/***********************************************
@Function: tab_content()
@Description: This function will change the content that
is supposed to show with the correct content tab.

@Arguments :: obj, pos
	@obj = The object which should be shown as selected
	@pos = the position of the tab from the function called
	above.
***********************************************/
function tab_content(obj,pos)
{
	var sel = "tabContentSel";
	var nor = "tabContent";
	var c_id = obj.id + "_content";
	var c_style = find_DOM(c_id,0);
	var span = document.getElementsByTagName("span");
	var span_id = new String();

	//Set the content for the selected tab to show
	c_style.className = sel;
	
	//Cycle thru all other spans on the page, if the span
	//is not equal to the one we just displayed and the
	//word _tab and the pos variable are found in the id,
	//we will hide the content.
	for(var i = 0; i < span.length; i++) {
		span_id = span[i].id;
		if (span_id != c_id && span_id.indexOf("tab_") != -1 && span_id.indexOf(pos) != -1) {
			dom_style = find_DOM(span_id,0);
			dom_style.className = nor;
		}
	}
}


