/* Copyright © 2008 Deep Web Technologies, Inc.  All rights reserved. */

function CollectionTreeManager(A){this.categories=[];this.formName=A;this.initialSelections=[];this.imageCache=[];}CollectionTreeManager.prototype.setInitialCollections=function(A){if(A.length==1&&A[0]===""){A=[];}this.initialSelections=A;};CollectionTreeManager.prototype.setCategories=function(A){if(A.length==1&&A[0]===""){A=[];}this.categories=A;};CollectionTreeManager.prototype.getCheckBoxesFromCollectionCode=function(E){var B=[];var A=document.getElementsByTagName("input");for(var C=0;C<A.length;C++){if(A[C].type=="checkbox"){var D=A[C].value;if(E==D||E==this.extractId(D)){B.push(A[C]);}}}return B;};CollectionTreeManager.prototype.toggle=function(A){var B=document.getElementById(A);if(B.style.display!="none"){this.collapseNode(A);}else{this.expandNode(A);}document.getElementById("all").checked=this.areAllChecked();if(this.areAllNodesExpanded()){this.setImage("allCategoryImage","minus");}if(this.areAllNodesCollapsed()){this.setImage("allCategoryImage","plus");}return false;};CollectionTreeManager.prototype.collapseNode=function(A){var B=document.getElementById(A);B.style.display="none";this.setImage("ximg"+A,"plus");};CollectionTreeManager.prototype.expandNode=function(A){var B=document.getElementById(A);B.style.display="block";this.setImage("ximg"+A,"minus");};CollectionTreeManager.prototype.areAllNodesExpanded=function(){return this.checkCategoryStyle("none");};CollectionTreeManager.prototype.areAllNodesCollapsed=function(){return this.checkCategoryStyle("block");};CollectionTreeManager.prototype.checkCategoryStyle=function(A){var B;for(B=0;B<this.categories;++B){if(document.getElementById(this.categories[B]).style.display==A){return false;}}return true;};CollectionTreeManager.prototype.toggleAll=function(){var A=document.getElementById("allCategoryImage");if(String(A.src).indexOf("plus.gif")>0){this.expandAll();this.setImage("allCategoryImage","minus");}else{this.collapseAll();this.setImage("allCategoryImage","plus");}return false;};CollectionTreeManager.prototype.expandAll=function(){var A;for(A=0;A<this.categories.length;A++){this.expandNode(this.categories[A]);}};CollectionTreeManager.prototype.collapseAll=function(){var A;for(A=0;A<this.categories.length;A++){this.collapseNode(this.categories[A]);}};CollectionTreeManager.prototype.checkAllSources=function(){if(typeof (document.getElementById("all"))!="undefined"){document.getElementById("all").checked=this.areAllChecked();}};CollectionTreeManager.prototype.check_group=function(D){var C=document.getElementById("z"+D);var B=document.getElementById(D).getElementsByTagName("input");for(var A=0;A<B.length;A++){B[A].checked=C.checked;}this.checkAllSources();};CollectionTreeManager.prototype.check_status=function(E){var D=document.getElementById("z"+E);var C=document.getElementById(E).getElementsByTagName("input");if(C.length===0){return ;}var B=0;for(var A=0;A<C.length;A++){if(C[A].type=="checkbox"&&C[A].checked){B++;}}if(B>0&&B==C.length){D.checked=true;}else{D.checked=false;if(B!==0){this.expandNode(E);}}this.checkAllSources();};CollectionTreeManager.prototype.setAllCheckBoxes=function(D){var A=document.getElementById("categoryBlock");var B=A.getElementsByTagName("input");if(B){for(var C=0;C<B.length;C++){if(B[C].type=="checkbox"){B[C].checked=D;}}}};CollectionTreeManager.prototype.uncheckAll=function(){this.setAllCheckBoxes(false);};CollectionTreeManager.prototype.checkAll=function(){this.setAllCheckBoxes(true);};CollectionTreeManager.prototype.areAllChecked=function(){var A=document.getElementById("categoryBlock");var B=A.getElementsByTagName("input");if(!B){return false;}for(var C=0;C<B.length;C++){if(B[C].type=="checkbox"&&B[C].id!="all"){if(!B[C].checked){return false;}}}return true;};CollectionTreeManager.prototype.extractId=function(C){var A=C.indexOf("_");var B="";if(A>0){B=C.substr(A+1,C.length-1);}return B;};CollectionTreeManager.prototype.addToImageCache=function(A,C,B){this.imageCache[A]=new Image(11,11);this.imageCache[A].src=C;this.imageCache[A].alt=B;};CollectionTreeManager.prototype.setImage=function(A,B){document.images[A].src=this.imageCache[B].src;document.images[A].alt=this.imageCache[B].alt;document.images[A].title=this.imageCache[B].title;};CollectionTreeManager.prototype.toggleSelect=function(){var A=document.getElementById("all");if(A.checked){this.checkAll();}else{this.uncheckAll();}};CollectionTreeManager.prototype.getInitialCheckBoxIds=function(){var D=[];var C;var B;var A;for(C=0;C<this.initialSelections.length;++C){A=this.getCheckBoxesFromCollectionCode(this.initialSelections[C]);for(B=0;B<A.length;++B){D.push(A[B].value);}}return D;};CollectionTreeManager.prototype.setupCategoryTree=function(){var C;var F;if(this.initialSelections.length===0||this.initialSelections[0]=="NONE"){this.uncheckAll();}else{if(this.initialSelections[0]=="ALL"){this.checkAll();}else{F=this.getInitialCheckBoxIds();var A=document.forms[this.formName].selectedCollections;if(typeof (A)=="undefined"){A=document.forms[this.formName].collections;}if(typeof (A)=="undefined"){window.alert("Error:  Why are there no collections?");return ;}for(C=0;C<A.length;C++){var E=A[C];E.checked=false;for(var B=0;B<F.length;B++){if(E.value==F[B]||this.extractId(E.value)==F[B]){E.checked=true;}}}for(C=0;C<this.categories.length;C++){var D="cat"+(C+1);if(document.getElementById("z"+D)){this.check_status(D);}}}}this.checkAllSources();if(this.categories.length===1){this.expandAll(this.categories);}};