
// tabs/content flipping

var divListArr = new Array();

function buildTabs() {
	var sourceDiv = document.getElementById("pageTabs");
	divListArr = sourceDiv.getElementsByTagName("li");
	return;
	}


function showContent(aNode) {
	
	// Hide all the content divs
	for (var i=0; i < divListArr.length; i++) {
		hideDiv(divListArr[i]);
		}
	
	// Set all tabs back to "normal", and set the clicked tab as Current
	selectTab(aNode);
	
	// Show the content div for the clicked tab
	showDiv(aNode);
	
	return;
	}


function hideDiv(node) {
	var nodeID = node.id;
	nodeID = nodeID.replace("_t","");
	var div = document.getElementById(nodeID);
	if (div != null) { div.style.display='none'; }
	return;
	}


function showDiv(node) {
	var nodeID = node.id;
	nodeID = nodeID.replace("_t","");
	var div = document.getElementById(nodeID);
	div.style.display='block';
	return;
	}


function selectTab( node ) {
	var nodeID = node.id;
	var newnode = nodeID.replace("_t","");
	var aNode = document.getElementById(nodeID);
	
	// Grab all the LI elements
	var liNodeList = aNode.parentNode.getElementsByTagName("li");
	
	// Loop through each element to reveal the inner links
	for ( var i = 0; i< liNodeList.length; i++) {
	//for ( var i = 0; i< 2; i++) {
		
		// Grab the inner links by anchor tag
		var aNodeList = liNodeList[i].getElementsByTagName("A");
		
		// loop through links to change background/styles
		for ( var a = 0; a< aNodeList.length; a++) {
		
			// If the current looped list element is the clicked tab
			// set the names and classNames to current
			if (liNodeList[i].id == nodeID) {
				//alert(nodeID+"/"+newnode+"/"+liNodeList[i].id);
				
				if (aNodeList[a].className.match("Link")) {
					aNodeList[a].name = "current";
					aNodeList[a].className = "currentLink";
					}
				else if (aNodeList[a].className.match("Close")) {
					aNodeList[a].name = "current";
					aNodeList[a].className = "currentClose";
					}
				
				}
			else {
				
				// Change the names and classNames of the links either
				// to current, or bacl to "normal"
				if (aNodeList[a].className.match("Link")) {
					aNodeList[a].name = "normal";
					aNodeList[a].className = "Link";
					}
				else if (aNodeList[a].className.match("Close")) {
					aNodeList[a].name = "normal";
					aNodeList[a].className = "Close";
					}
				
				}
			
			}
		}
	
	return true;
	}


function deleteTab ( node ) {
	// Node is currently the "X" link. This function will grab its parent, 
	//	delete the tab, and delete the corresponding content div
	
	// Grab Node's name.
	var Name = node.name;
	
	// Grab Node's parent
	var listElement = node.parentNode;
	
	// Grab the links within Node's parent
	var aNodeList = listElement.getElementsByTagName("A");
	
	// This will hold the text within the tab's link and will be used in the confirmtation box.
	var tabTaxt = "";
	
	// loop through links so you can find the one with the class currentLink or Link
	for ( var a = 0; a< aNodeList.length; a++) {
	
		if (aNodeList[a].className.match("Link")) {
		
			// Grab the text of the link
			tabTaxt = aNodeList[a].text;
			
			// Break the loop
			a = (aNodeList.length+1);
			
			}
		
		}
		
	// Grab this tabs parent
	var ulElements = listElement.parentNode;
	
	// Grab all the tabs
	var liNodeList = ulElements.getElementsByTagName("LI");
	
	// If there is only one tab left, do not allow it to be deleted
	if (liNodeList.length == 1) {
		alert("You can not delete all the tabs.");
		}
	else {
	
		//Check to make sure they actually want to delete the tab
		if (confirm("Are you sure you want to remove the '"+tabTaxt+"' tab?")) {
				
				// Grab the tab's ID
				var tabID = listElement.id;
				
				// Remove the _t so we know the name of the content div to remove
				contentID = tabID.replace("_t","");
				
				// Remove the tab
				ulElements.removeChild(listElement);
				
				// Find the content tab
				var contentDiv = document.getElementById(contentID);
				
				// Grab the parent of the content tab
				var contentDivParent = contentDiv.parentNode;
				
				// Remove the content tab
				var removedDiv = contentDivParent.removeChild(contentDiv);
				
				// If this tab was the "Current" tab, make sure to switch they
				// tab and content focus to the first tab/content area
				if (Name == "current") {
					var liNodeList = ulElements.getElementsByTagName("LI");
					selectTab(liNodeList[0]);
					showContent(liNodeList[0]);
					}
				else {
					//alert("normal");
					}
				
			return true;
			}
		else {
			return true;
			}
		}
	}






function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=300,height=150,left=200,top=200');");
}



//** Tab Content script- � Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
//** Last updated: Nov 8th, 06

var enabletabpersistence=0 //enable tab persistence via session only cookies, so selected tab is remembered?

////NO NEED TO EDIT BELOW////////////////////////
var tabbedContentWrapperIDs=new Object()

function expandcontent(linkobj){
	var ulid=linkobj.parentNode.parentNode.id //id of UL element
	var ullist=document.getElementById(ulid).getElementsByTagName("li") //get list of LIs corresponding to the tab contents
	for (var i=0; i<ullist.length; i++){
		ullist[i].className=""  //deselect all tabs
		if (typeof tabbedContentWrapperIDs[ulid][i]!="undefined") //if tab content within this array index exists (exception: More tabs than there are tab contents)
			document.getElementById(tabbedContentWrapperIDs[ulid][i]).style.display="none" //hide all tab contents
		}
	linkobj.parentNode.className="selected"  //highlight currently clicked on tab
	document.getElementById(linkobj.getAttribute("rel")).style.display="block" //expand corresponding tab content
	saveselectedtabbedContentWrapperid(ulid, linkobj.getAttribute("rel"))
	}

function expandtab(tabbedContentWrapperid, tabnumber){ //interface for selecting a tab (plus expand corresponding content)
	var thetab=document.getElementById(tabbedContentWrapperid).getElementsByTagName("a")[tabnumber]
	if (thetab.getAttribute("rel"))
		expandcontent(thetab)
	}

function savetabbedContentWrapperids(ulid, relattribute){// save ids of tab content divs
	if (typeof tabbedContentWrapperIDs[ulid]=="undefined") //if this array doesn't exist yet
		tabbedContentWrapperIDs[ulid]=new Array()
	tabbedContentWrapperIDs[ulid][tabbedContentWrapperIDs[ulid].length]=relattribute
	}

function saveselectedtabbedContentWrapperid(ulid, selectedtabid){ //set id of clicked on tab as selected tab id & enter into cookie
	if (enabletabpersistence==1) //if persistence feature turned on
		setCookie(ulid, selectedtabid)
	}

function getullistlinkbyId(ulid, tabbedContentWrapperid){ //returns a tab link based on the ID of the associated tab content
	var ullist=document.getElementById(ulid).getElementsByTagName("li")
	for (var i=0; i<ullist.length; i++){
		if (ullist[i].getElementsByTagName("a")[0].getAttribute("rel")==tabbedContentWrapperid){
			return ullist[i].getElementsByTagName("a")[0]
			break
			}
		}
	}

function initializetabbedContentWrapper(){
	for (var i=0; i<arguments.length; i++){ //loop through passed UL ids
		if (enabletabpersistence==0 && getCookie(arguments[i])!="") //clean up cookie if persist=off
			setCookie(arguments[i], "")
		var clickedontab=getCookie(arguments[i]) //retrieve ID of last clicked on tab from cookie, if any
		var ulobj=document.getElementById(arguments[i])
		var ulist=ulobj.getElementsByTagName("li") //array containing the LI elements within UL
		for (var x=0; x<ulist.length; x++){ //loop through each LI element
			var ulistlink=ulist[x].getElementsByTagName("a")[0]
			if (ulistlink.getAttribute("rel")){
				savetabbedContentWrapperids(arguments[i], ulistlink.getAttribute("rel")) //save id of each tab content as loop runs
				ulistlink.onclick=function(){
				expandcontent(this)
				return false
				}
			if (ulist[x].className=="selected" && clickedontab=="") //if a tab is set to be selected by default
				expandcontent(ulistlink) //auto load currenly selected tab content
				}
			} //end inner for loop
		if (clickedontab!=""){ //if a tab has been previously clicked on per the cookie value
			var culistlink=getullistlinkbyId(arguments[i], clickedontab)
			if (typeof culistlink!="undefined") //if match found between tabbedContentWrapper id and rel attribute value
				expandcontent(culistlink) //auto load currenly selected tab content
			else //else if no match found between tabbedContentWrapper id and rel attribute value (cookie mis-association)
				expandcontent(ulist[0].getElementsByTagName("a")[0]) //just auto load first tab instead
			}
		} //end outer for loop
	}

function getCookie(Name){ 
	var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
	if (document.cookie.match(re)) //if cookie found
	return document.cookie.match(re)[0].split("=")[1] //return its value
	return ""
	}

function setCookie(name, value){
	document.cookie = name+"="+value //cookie value is domain wide (path=/)
	}


function toggle(id) {
	if (document.getElementById) {
		with (document.getElementById(id).style) {
			if (display == "none") {
				display = "block";
			}else if(display == "block") {
				display = "none";
			}else if (display == "") {
				display = "block";
			}
		}
	}
}

function changeTabs(Link, IDs) {
	var tabSpanNode = Link.parentNode;					//alert(tabDivNode.id);
	var tabDivNode = tabSpanNode.parentNode;					//alert(tabDivNode.id);
	var allSpans = tabDivNode.getElementsByTagName("SPAN");	//alert(allLinks);
	var allLinks = tabDivNode.getElementsByTagName("A");	//alert(allLinks);
	for (i = 0; i <= allSpans.length-1; i++) {
		//alert(allLinks[i]);
		allLinks[i].className = "None";
		allSpans[i].className = "None";
		}
	Link.className = "Current";
	tabSpanNode.className = "Current";

	
	}

function hideTheseIDs(IDs) {
	//alert(IDs);
	for (i = 0; i <= IDs.length-1; i++) {
		eval('document.getElementById("' + IDs[i] + '").style.display="none"');
		}
	}

