1 //** Tab Content script- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
\r 
   2 //** Last updated: June 29th, 06
\r 
   4 var enabletabpersistence=1 //enable tab persistence via session only cookies, so selected tab is remembered?
\r 
   6 ////NO NEED TO EDIT BELOW////////////////////////
\r 
   7 var tabcontentIDs=new Object()
\r 
   9 function expandcontent(linkobj){
\r 
  10 var ulid=linkobj.parentNode.parentNode.id //id of UL element
\r 
  11 var ullist=document.getElementById(ulid).getElementsByTagName("li") //get list of LIs corresponding to the tab contents
\r 
  12 for (var i=0; i<ullist.length; i++){
\r 
  13 ullist[i].className=""  //deselect all tabs
\r 
  14 if (typeof tabcontentIDs[ulid][i]!="undefined") //if tab content within this array index exists (exception: More tabs than there are tab contents)
\r 
  15 document.getElementById(tabcontentIDs[ulid][i]).style.display="none" //hide all tab contents
\r 
  17 linkobj.parentNode.className="selected"  //highlight currently clicked on tab
\r 
  18 document.getElementById(linkobj.getAttribute("rel")).style.display="block" //expand corresponding tab content
\r 
  19 saveselectedtabcontentid(ulid, linkobj.getAttribute("rel"))
\r 
  22 function savetabcontentids(ulid, relattribute){// save ids of tab content divs
\r 
  23 if (typeof tabcontentIDs[ulid]=="undefined") //if this array doesn't exist yet
\r 
  24 tabcontentIDs[ulid]=new Array()
\r 
  25 tabcontentIDs[ulid][tabcontentIDs[ulid].length]=relattribute
\r 
  28 function saveselectedtabcontentid(ulid, selectedtabid){ //set id of clicked on tab as selected tab id & enter into cookie
\r 
  29 if (enabletabpersistence==1) //if persistence feature turned on
\r 
  30 setCookie(ulid, selectedtabid)
\r 
  33 function getullistlinkbyId(ulid, tabcontentid){ //returns a tab link based on the ID of the associated tab content
\r 
  34 var ullist=document.getElementById(ulid).getElementsByTagName("li")
\r 
  35 for (var i=0; i<ullist.length; i++){
\r 
  36 if (ullist[i].getElementsByTagName("a")[0].getAttribute("rel")==tabcontentid){
\r 
  37 return ullist[i].getElementsByTagName("a")[0]
\r 
  43 function initializetabcontent(){
\r 
  44 for (var i=0; i<arguments.length; i++){ //loop through passed UL ids
\r 
  45 if (enabletabpersistence==0 && getCookie(arguments[i])!="") //clean up cookie if persist=off
\r 
  46 setCookie(arguments[i], "")
\r 
  47 var clickedontab=getCookie(arguments[i]) //retrieve ID of last clicked on tab from cookie, if any
\r 
  48 var ulobj=document.getElementById(arguments[i])
\r 
  49 var ulist=ulobj.getElementsByTagName("li") //array containing the LI elements within UL
\r 
  50 for (var x=0; x<ulist.length; x++){ //loop through each LI element
\r 
  51 var ulistlink=ulist[x].getElementsByTagName("a")[0]
\r 
  52 if (ulistlink.getAttribute("rel")){
\r 
  53 savetabcontentids(arguments[i], ulistlink.getAttribute("rel")) //save id of each tab content as loop runs
\r 
  54 ulistlink.onclick=function(){
\r 
  58 if (ulist[x].className=="selected" && clickedontab=="") //if a tab is set to be selected by default
\r 
  59 expandcontent(ulistlink) //auto load currenly selected tab content
\r 
  61 } //end inner for loop
\r 
  62 if (clickedontab!=""){ //if a tab has been previously clicked on per the cookie value
\r 
  63 var culistlink=getullistlinkbyId(arguments[i], clickedontab)
\r 
  64 if (typeof culistlink!="undefined") //if match found between tabcontent id and rel attribute value
\r 
  65 expandcontent(culistlink) //auto load currenly selected tab content
\r 
  66 else //else if no match found between tabcontent id and rel attribute value (cookie mis-association)
\r 
  67 expandcontent(ulist[0].getElementsByTagName("a")[0]) //just auto load first tab instead
\r 
  69 } //end outer for loop
\r 
  73 function getCookie(Name){ 
\r 
  74 var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
\r 
  75 if (document.cookie.match(re)) //if cookie found
\r 
  76 return document.cookie.match(re)[0].split("=")[1] //return its value
\r 
  80 function setCookie(name, value){
\r 
  81 document.cookie = name+"="+value //cookie value is domain wide (path=/)
\r