if(typeof Protoplasm=="undefined"){throw ("protoplasm.js not loaded, could not intitialize treeselect")}if(window.Control==undefined){Control={}}Control.TreeSelect=function(b,d){var w=null;function s(y){y=y.replace(/^\s+/,"");for(var x=y.length-1;x>=0;x--){if(/\S/.test(y.charAt(x))){y=y.substring(0,x+1);break}}return y}function n(C,x){var z=[];var B=(x||document).getElementsByTagName("*");var A=new RegExp("\\b"+C+"\\b");for(var y=0;y<B.length;++y){if(B[y].className.match(A)){z[z.length]=B[y]}}return z}function l(y,z){cl=y.className?y.className.split(/ /):[];for(var x=0;x<cl.length;++x){if(cl[x]==z){return}}cl[cl.length]=z;y.className=cl.join(" ")}function m(y,A){if(!y.className){return}cl=y.className.split(/ /);var z=[];for(var x=0;x<cl.length;++x){if(cl[x]!=A){z[z.length]=cl[x]}}y.className=z.join(" ")}function u(x){var i=window.event||x;if(i.stopPropagation){i.stopPropagation()}else{i.cancelBubble=true}}function o(y,i,x){if(y.addEventListener){y.addEventListener(i,x,false)}else{y.attachEvent("on"+i,x)}}function r(y,i,x){if(y.removeEventListener){y.removeEventListener(i,x,false)}else{y.detachEvent("on"+i,x)}}function g(i){return function(x){if(w){clearTimeout(w);w=null}k.value=i.id;if(j.nodeName.toUpperCase()=="INPUT"){j.value=s(i.childNodes[0].nodeValue)}else{j.innerHTML=s(i.childNodes[0].nodeValue)}u(x);q(x);return false}}function a(i){return function(x){if(w){clearTimeout(w);w=null}w=setTimeout(function(){var y=[];if(i.getElementsByTagName("ul").length){y[0]=i.getElementsByTagName("ul")[0]}var E=i.parentNode;while(E&&E!=b){if(E.nodeName.toUpperCase()=="UL"){y[y.length]=E}E=E.parentNode}var B=[];var C=b.getElementsByTagName("ul");for(var A=0;A<C.length;++A){var D=false;for(var z=0;z<y.length;++z){if(y[z]==C[A]){D=true;break}}if(!D){B[B.length]=C[A]}}for(var A=0;A<y.length;++A){y[A].style.display="block";y[A].style.zIndex=99;l(y[A].parentNode,"active")}for(var A=0;A<B.length;++A){B[A].style.display="none";B[A].style.zIndex=0;m(B[A].parentNode,"active")}w=null},200);u(x);return false}}function v(i){if(!i.id&&i.getElementsByTagName("ul").length){o(i,"click",a(i))}else{o(i,"click",g(i))}o(i,"mouseover",a(i));var x=i.getElementsByTagName("ul");if(x.length){l(i,"submenu")}}var k=n("itemvalue",b)[0];var j=n("itemname",b)[0];var c=b.getElementsByTagName("ul")[0];function e(i){if(c.style.display=="block"){c.style.display="none"}else{return h(i)}}function h(i){c.style.display="block";o(document,"click",q);u(i);return false}function q(z){var y=c.getElementsByTagName("ul");for(var x=0;x<y.length;++x){y[x].style.display="none";y[x].style.zIndex=0;m(y[x].parentNode,"active")}c.style.display="none";r(document,"click",q)}var t=document.createElement("img");t.src="/images/dropdown.png";t.style.verticalAlign="middle";if(j.nextSibling){j.parentNode.insertBefore(t,j.nextSibling)}else{j.parentNode.appendChild(t)}o(t,"click",e);o(j,"click",h);j.readOnly=true;var f=b.getElementsByTagName("li");for(var p=0;p<f.length;++p){v(f[p])}return{element:b}};Protoplasm.register("treeselect",Control.TreeSelect);