Rev Author Line No. Line
185 miho 1 /***********************************************
2 * Switch Content script- © Dynamic Drive (www.dynamicdrive.com)
3 * This notice must stay intact for legal use. Last updated April 2nd, 2005.
4 * Visit http://www.dynamicdrive.com/ for full source code
5 ***********************************************/
6  
7 var enablepersist="on" // Enable saving state of content structure using session cookies? (on/off)
8 var collapseprevious="yes" // Collapse previously open content when opening present? (yes/no)
9  
10 var contractsymbol='<div class="minusbox">-</div>' // HTML for contract symbol. For image, use: <img src="${prefix}whatever.gif">
11 var expandsymbol='<div class="plusbox">+</div>' // HTML for expand symbol.
12 var expandonload=false
13  
14 if (document.getElementById)
15 {
16 document.write('<style type="text/css">')
17 document.write('.switchcontent{display:none;}')
18 document.write('</style>')
19 }
20  
21 function getElementbyClass(rootobj, classname)
22 {
23 var temparray=new Array()
24 var inc=0
25 for (i=0; i<rootobj.length; i++)
26 {
27 if (rootobj[i].className==classname)
28 temparray[inc++]=rootobj[i]
29 }
30 return temparray
31 }
32  
33 function sweeptoggle(ec)
34 {
35 var thestate=(ec=="expand")? "block" : "none"
36 var inc=0
37 while (ccollect[inc])
38 {
39 ccollect[inc].style.display=thestate
40 inc++
41 }
42 revivestatus()
43 collapseprevious = (ec=="expand")? "no" : "yes"
44 }
45  
46  
47 function contractcontent(omit)
48 {
49 var inc=0
50 while (ccollect[inc])
51 {
52 if (ccollect[inc].id!=omit)
53 ccollect[inc].style.display="none"
54 inc++
55 }
56 }
57  
58 function expandcontent(curobj, cid)
59 {
60 var spantags=curobj.getElementsByTagName("SPAN")
61 var showstateobj=getElementbyClass(spantags, "showstate")
62 if (ccollect.length>0)
63 {
64 if (collapseprevious=="yes")
65 contractcontent(cid)
66 document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
67 if (showstateobj.length>0) //if "showstate" span exists in header
68 {
69 if (collapseprevious=="no")
70 showstateobj[0].innerHTML=(document.getElementById(cid).style.display=="block")? contractsymbol : expandsymbol
71 else
72 revivestatus()
73 }
74 }
75 }
76  
77 function revivecontent()
78 {
79 contractcontent("omitnothing")
80 selectedItem=getselectedItem()
81 selectedComponents=selectedItem.split("|")
82 collapseprevious=selectedComponents[0]
83 for (i=1; i<selectedComponents.length-1; i++)
84 document.getElementById(selectedComponents[i]).style.display="block"
85 }
86  
87 function revivestatus()
88 {
89 var inc=0
90 while (statecollect[inc])
91 {
92 if (ccollect[inc].style.display=="block")
93 statecollect[inc].innerHTML=contractsymbol
94 else
95 statecollect[inc].innerHTML=expandsymbol
96 inc++
97 }
98 }
99  
100 function get_cookie(Name)
101 {
102 var search = Name + "="
103 var returnvalue = "";
104 if (document.cookie.length > 0)
105 {
106 offset = document.cookie.indexOf(search)
107 if (offset != -1)
108 {
109 offset += search.length
110 end = document.cookie.indexOf(";", offset);
111 if (end == -1) end = document.cookie.length;
112 returnvalue=unescape(document.cookie.substring(offset, end))
113 }
114 }
115 return returnvalue;
116 }
117  
118 function getselectedItem()
119 {
120 if (get_cookie(window.location.pathname) != "")
121 {
122 selectedItem=get_cookie(window.location.pathname)
123 return selectedItem
124 }
125 else
126 return ""
127 }
128  
129 function saveswitchstate()
130 {
131 var inc=0, selectedItem=collapseprevious+"|"
132 while (ccollect[inc])
133 {
134 if (ccollect[inc].style.display=="block")
135 selectedItem+=ccollect[inc].id+"|"
136 inc++
137 }
138 document.cookie=window.location.pathname+"="+selectedItem
139 }
140  
141 function do_onload()
142 {
143 uniqueidn=window.location.pathname+"firsttimeload"
144 var alltags=document.all? document.all : document.getElementsByTagName("*")
145 ccollect=getElementbyClass(alltags, "switchcontent")
146 statecollect=getElementbyClass(alltags, "showstate")
147 if (enablepersist=="on" && ccollect.length>0)
148 {
149 document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0"
150 firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load
151 if (!firsttimeload)
152 revivecontent()
153 }
154 if (ccollect.length>0 && statecollect.length>0)
155 revivestatus()
156  
157 if (expandonload)
158 sweeptoggle('expand')
159 }
160  
161 if (window.addEventListener)
162 window.addEventListener("load", do_onload, false)
163 else if (window.attachEvent)
164 window.attachEvent("onload", do_onload)
165 else if (document.getElementById)
166 window.onload=do_onload
167  
168 if (enablepersist=="on" && document.getElementById)
169 window.onunload=saveswitchstate