/**
 *
 * Copyright (c) 2002-2004 Bluetetra Software.  All rights reserved.
 *
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL BLUETETRA SOFTWARE BE LIABLE FOR 
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *  
 * http://www.bluetetra.com
 *
 */

var target = "content";
var fiFileName = "fileTreeIndex.htm";
var nsFilterFileName = "nsFilter.htm";

function FN (href, path, fname) {
	this.href = href;
	this.path = path;
	this.fname = fname;

	this.children = null;
	this.hasChild = (this.children != null) && (this.children.length>0);	
}

function F (fileTree) {
	this.fileTree = fileTree;
}


function filetree_showAllFiles() {
	parent._nsFilter = null;
	parent.componentIndex.location.href=fiFileName;
}

function filetree_filterFiles () {
	parent._href = fiFileName;
	window.open(nsFilterFileName, "_blank", 
		"height=200,width=400,location=no,menubar=no,scrollbars=yes,status=yes,resizable=yes,toolbar=no");

}

function filetree_setFilterToAll() {
	var nsList = new Array();
	var i = 0;

	for (var ns in filetreeDB) {
		nsList[i] = ns; 		
		i++;
	}

	parent._nsFilter = nsList;
}


function filetree_displayFilesNoNS (nsList, fileList) {

	var files = new Array ();
	var n = 0;

	for (var i=0; i<fileList.length; i++) {
		var list = fileList [i];
		var namespace = nsList[i];

		if (list == null) {
			continue;
		}
	
		for (var j=0; j<list.length; j++) {
			files[n] = list[j];
			n++;	
		}	
	}
	
	files = files.sort();

	filetree_outputList (null, files);	
}


function filetree_displayFilesNS (nsList, fileList) {

	for (var i=0; i<fileList.length; i++) {
		var list = fileList [i];
		var namespace = nsList[i];

		if (list == null) {
			continue;
		}
	
		filetree_outputList (namespace, list);	
	}
}


function filetree_displayFiles (nsList, fileList) {
	if (parent._groupByNSFlag) {
		filetree_displayFilesNS (nsList, fileList)
	} else {
		filetree_displayFilesNoNS (nsList, fileList)
	}
}

function filetree_showFiles() {
	if (parent._nsFilter == null) {
		filetree_setFilterToAll();		
	}
	
	var nsList = parent._nsFilter;
	var files = new Array();
	var nss = new Array();

	for (var i=0; i<nsList.length; i++) {
		files [i] = filetreeDB [nsList[i]].fileTree;	
		nss[i] = nsList[i];
	}		

	filetree_displayFiles (nss, files);
}

function filetree_groupByNS(flag) {
	parent._groupByNSFlag = flag;
	parent.componentIndex.location.href=fiFileName;	
}

function filetree_outputList (ns, list) {	
	
	if (list == null || list.length<=0) {
		return;
	}

	if (parent._groupByNSFlag) {
		var fpath = filetreeNSMap[ns];

		var str = '<div class="nsBox"><div class="itemNS">'+
				'<nobr><img style="cursor: pointer" src="img/minus.gif" hspace="2" align="middle" onclick="IClick(this)">'+
				'<a class="chref" href="'+fpath+
				'" title="'+encodeURI(ns)+
				'" target="'+target+'">'+encodeURI(ns)+'</a></nobr></div>'+
				'<div style="margin-left: 0.5em">';

		document.write (str);
	}

	var list = filetree_transformList (list);

	for (var i=0; i<list.length; i++) {
		filetree_outputTree (list[i]);
	}
	
	if (parent._groupByNSFlag) {
		document.write ('</div></div>');
	}
}

function filetree_transformList (list) {
	var newList = new Array();
	
	var dirNode = null;
	var cI = 0;
	var dI = 0;
	var i = 0;

	while (i<list.length) {
		if (dirNode == null) {
			dirNode = new FN (null, list[i].path, null);
			dirNode.children = new Array();
			dirNode.hasChild = true;
			cI = 0;
			dirNode.children[cI] = list[i]; 
			cI++; 
			newList[dI] = dirNode; 
			dI++;
			i++;
		} else {
			if (list[i].path == dirNode.path) {
				dirNode.children[cI] = list[i]; 
				cI++; 
				i++;
			} else {
				dirNode = null;
			}
		}
	}

	return newList;
}

function filetree_outputTree (node) {
	if (node.hasChild == false) {
		filetree_outputLeaf (node);
	} else {
		filetree_outputNonLeaf (node);
	}
}

function filetree_getFileName(node) {
	return node.fname;
}

function filetree_getDirName(node) {
	return node.path;
}

function filetree_outputLeaf (node) {
	var str = '<span class="leaf">'+
			  '<nobr>'+
			  '<img src="img/leaf.gif" hspace="2" align="middle">'+
			  '<a class="chref" href="'+node.href+
			  '" title="'+filetree_getFileName(node)+
			  '" target="'+target+'">'+filetree_getFileName(node)+'</a></nobr>'+
			  '</span><br />'
	
	document.write (str);
}

function filetree_outputNonLeaf (node) {
	var str = '<div><div class="nonleaf">'+
			'<nobr><img style="cursor: pointer" src="img/minus.gif" hspace="2" align="middle" onclick="IClick(this)">'+
			'<span class="dir">'+filetree_getDirName(node)+'</span></nobr></div>'+
			'<div style="margin-left: 0.8em">';

	document.write (str);

	var childs = node.children;
	for (var i=0; i<childs.length; i++) {
		filetree_outputLeaf (childs[i]);
	}					

	document.write ('</div></div>');
}

var filetreeDB = new Array();
var filetreeNSMap = new Array();

filetreeDB ["http://schemas.xmlsoap.org/soap/encoding/"] =  new F (new Array(new FN("http___schemas_xmlsoap_org_soap_encoding_SchemaOverview.htm","http://schemas.xmlsoap.org/soap/encoding/","xsd")));
filetreeNSMap ["http://schemas.xmlsoap.org/soap/encoding/"] = "http___schemas_xmlsoap_org_soap_encoding_/index.htm";
filetreeDB ["http://schemas.xmlsoap.org/soap/envelope/"] =  new F (new Array(new FN("http___schemas_xmlsoap_org_soap_envelope_SchemaOverview.htm","http://schemas.xmlsoap.org/soap/envelope/","xsd")));
filetreeNSMap ["http://schemas.xmlsoap.org/soap/envelope/"] = "http___schemas_xmlsoap_org_soap_envelope_/index.htm";
filetreeDB ["http://schemas.xmlsoap.org/wsdl/"] =  new F (new Array(new FN("http___schemas_xmlsoap_org_wsdl_SchemaOverview.htm","http://schemas.xmlsoap.org/wsdl/","xsd")));
filetreeNSMap ["http://schemas.xmlsoap.org/wsdl/"] = "http___schemas_xmlsoap_org_wsdl_/index.htm";
filetreeDB ["http://schemas.xmlsoap.org/wsdl/http/"] =  new F (new Array(new FN("http___schemas_xmlsoap_org_wsdl_http_SchemaOverview.htm","http://schemas.xmlsoap.org/wsdl/http/","xsd")));
filetreeNSMap ["http://schemas.xmlsoap.org/wsdl/http/"] = "http___schemas_xmlsoap_org_wsdl_http_/index.htm";
filetreeDB ["http://schemas.xmlsoap.org/wsdl/mime/"] =  new F (new Array(new FN("http___schemas_xmlsoap_org_wsdl_mime_SchemaOverview.htm","http://schemas.xmlsoap.org/wsdl/mime/","xsd")));
filetreeNSMap ["http://schemas.xmlsoap.org/wsdl/mime/"] = "http___schemas_xmlsoap_org_wsdl_mime_/index.htm";
filetreeDB ["http://schemas.xmlsoap.org/wsdl/soap/"] =  new F (new Array(new FN("http___schemas_xmlsoap_org_wsdl_soap_SchemaOverview.htm","http://schemas.xmlsoap.org/wsdl/soap/","xsd")));
filetreeNSMap ["http://schemas.xmlsoap.org/wsdl/soap/"] = "http___schemas_xmlsoap_org_wsdl_soap_/index.htm";

