//** 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?
var imgDir = '/images/';

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

function expandcontent(linkobj)
{
//	var ulid=linkobj.parentNode.parentNode.parentNode.id //id of UL element
	var ulid=linkobj.parentNode.parentNode.parentNode.parentNode.id; //id of TABLE element

	var ulidObj=linkobj.parentNode.parentNode; //id of UL element
	var ullist=ulidObj.getElementsByTagName("td") //get list of TD's corresponding to the tab contents
	for (var i=0; i<ullist.length; i++)
	{

		if (ullist[i].className == 'leftEdge_selected')
		{
			ullist[i].className = 'leftEdge';
		}
		else if (ullist[i].className == 'rightEdge_selected')
		{
			ullist[i].className = 'rightEdge';
		}
		else if (ullist[i].className == 'Link_selected')
		{
			ullist[i].className = 'Link';
		}
		//else if ( ullist[i].className != 'margin' )
		//{
		//	ullist[i].className="";  //deselect all tabs
		//}
		
    	if ( ullist[i].children && ullist[i].children[0] && ullist[i].children[0].src )
		{
    		ullist[i].children[0].src = ullist[i].children[0].src.replace("selected_",""); 
		}
		if (typeof tabcontentIDs[ulid][i]!="undefined") //if tab content within this array index exists (exception: More tabs than there are tab contents)
		{
			document.getElementById(tabcontentIDs[ulid][i]).style.display="none" //hide all tab contents
		}
	}

	linkobj.parentNode.className="Link_selected"  //highlight currently clicked on tab
	//linkobj.parentNode.previousSibling.firstChild.src = linkobj.parentNode.previousSibling.firstChild.src.replace("tab_","selected_tab_");  
	linkobj.parentNode.previousSibling.className = 'leftEdge_selected';
	//linkobj.parentNode.nextSibling.firstChild.src = linkobj.parentNode.nextSibling.firstChild.src.replace("tab_","selected_tab_");
	linkobj.parentNode.nextSibling.className = 'rightEdge_selected';
	document.getElementById(linkobj.getAttribute("tabName")).style.display="block" //expand corresponding tab content
	saveselectedtabcontentid(ulid, linkobj.getAttribute("tabName"))
}

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

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

function saveselectedtabcontentid(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, tabcontentid)
{ //returns a tab link based on the ID of the associated tab content
	var ullist=document.getElementById(ulid).getElementsByTagName("td")
	for (var i=0; i<ullist.length; i++)
	{
		if (ullist[i].getElementsByTagName("a")[0].getAttribute("tabName")==tabcontentid)
		{
			return ullist[i].getElementsByTagName("a")[0]
			break
		}
	}
}

function initializetabcontent()
{
	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("td") //array containing the TD 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 && ulistlink.getAttribute("tabName")){
				savetabcontentids(arguments[i], ulistlink.getAttribute("tabName")) //save id of each tab content as loop runs
				ulistlink.onclick=function(){
					expandcontent(this)
					return false
				}
				if (ulist[x].className=="Link_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 tabcontent id and tabName attribute value
				expandcontent(culistlink) //auto load currenly selected tab content
			else //else if no match found between tabcontent id and tabName 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 getParameter( Parameter, URL )
{
  var Value = '';
	if ( !URL ) URL = document.location.search.substring(1);
  
  var Parameters = URL.split( '&' );

	for ( var i = 0; i < Parameters.length; i++ )
  {
		if ( Parameters[i].toLowerCase().indexOf( Parameter.toLowerCase() + '=' ) > -1 )
    {
			Value = Parameters[i].substring( Parameters[i].indexOf( '=' ) + 1 );
      if ( Value == 'undefined' ) Value = '';
		}
	}
	return Value;
}

function drawTabs()
{
  var Str = '<table border="0" cellspacing="0" cellpadding="0" class="shadetabs" id="maintab">';
  Str += '<tr><td class="margin"><img width=10 src="'+imgDir+'s.gif"></td>';

  var thisTab = getParameter( 'Tab' );
  if ( !thisTab || thisTab == '' ) thisTab = 0;

  for ( var i=0; i < arguments.length; i++ )
  {
    if ( i == thisTab ) 
      Str += '    <td class="leftEdge_selected"><img width=3 src="'+imgDir+'s.gif"></td>' +
             '<td class="Link_selected"><A href="#" tabName="tcontent'+eval(i+1)+'">'+arguments[i]+'</A></td>' +
             '<td class="rightEdge_selected"><img width=3 src="'+imgDir+'s.gif"></td>';
    else
      Str += '    <td class="leftEdge"><img width=3 src="'+imgDir+'s.gif"></td>' +
             '<td class="Link"><A href="#" tabName="tcontent'+eval(i+1)+'">'+arguments[i]+'</A></td>' +
             '<td class="rightEdge"><img width=3 src="'+imgDir+'s.gif"></td>';
  }
  Str += '    <td class="margin last"><img width=3 src="'+imgDir+'s.gif"></td>';
  //Str += '	  <td  id="rightMargin" /></td></tr>';
  Str += '	  </tr>';
  Str += '</table>';
  document.write( Str );
}


