add debug
[kps.git] / kps_web / scripts.js
blob380bc9e18a8efc11bffc125d4620261920a26d18
1 var temp, temp2, cookieArray, cookieArray2, cookieCount;
3 function initiate(){
5 cookieCount=0;
7 if(document.cookie){
9 cookieArray=document.cookie.split(";");
10 cookieArray2=new Array();
12 for(i in cookieArray){
13 cookieArray2[cookieArray[i].split("=")[0].replace(/ /g,"")]=cookieArray[i].split("=")[1].replace(/ /g,"");
18 cookieArray=(document.cookie.indexOf("state=")>=0)?cookieArray2["state"].split(","):new Array();
20 temp=document.getElementById("containerul");
22 for(var o=0;o<temp.getElementsByTagName("li").length;o++){
24 if(temp.getElementsByTagName("li")[o].getElementsByTagName("ul").length>0){
26 temp2 = document.createElement("span");
27 temp2.className = "symbols";
28 temp2.style.backgroundImage = (cookieArray.length>0)?((cookieArray[cookieCount]=="true")?"url(minus.png)":"url(plus.png)"):"url(plus.png)";
29 temp2.onclick=function(){
30 showhide(this.parentNode);
31 writeCookie();
34 temp.getElementsByTagName("li")[o].insertBefore(temp2,temp.getElementsByTagName("li")[o].firstChild)
36 temp.getElementsByTagName("li")[o].getElementsByTagName("ul")[0].style.display = "none";
38 if(cookieArray[cookieCount]=="true"){
39 showhide(temp.getElementsByTagName("li")[o]);
42 cookieCount++;
45 else{
47 temp2 = document.createElement("span");
48 temp2.className = "symbols";
49 temp2.style.backgroundImage = "url(page.png)";
51 temp.getElementsByTagName("li")[o].insertBefore(temp2,temp.getElementsByTagName("li")[o].firstChild);
61 function showhide(el){
63 el.getElementsByTagName("ul")[0].style.display=(el.getElementsByTagName("ul")[0].style.display=="block")?"none":"block";
65 el.getElementsByTagName("span")[0].style.backgroundImage=(el.getElementsByTagName("ul")[0].style.display=="block")?"url(minus.png)":"url(plus.png)";
71 function writeCookie(){ // Runs through the menu and puts the "states" of each nested list into an array, the array is then joined together and assigned to a cookie.
73 cookieArray=new Array()
75 for(var q=0;q<temp.getElementsByTagName("li").length;q++){
77 if(temp.getElementsByTagName("li")[q].childNodes.length>0){
78 if(temp.getElementsByTagName("li")[q].childNodes[0].nodeName=="SPAN" && temp.getElementsByTagName("li")[q].getElementsByTagName("ul").length>0){
80 cookieArray[cookieArray.length]=(temp.getElementsByTagName("li")[q].getElementsByTagName("ul")[0].style.display=="block");
87 document.cookie="state="+cookieArray.join(",")+";expires="+new Date(new Date().getTime() + 365*24*60*60*1000).toGMTString();