/*****************************
The tree menu in this page is based on the code of CNL Tree Menu by CNLei,Fengyan (www.cnlei.net, cnlei.iecn.net)
We have added dynamic children expansion funtion using Ajax tech.
-- Zuoshuang Xiang
Update : Mar 3, 2006
*****************************/
function Ob(o){
 var o=document.getElementById(o)?document.getElementById(o):o;
 return o;
}

function Hd(o) {
 Ob(o).style.display="none";
}

function Sw(o) {
 Ob(o).style.display="";
}

function ExCls(o,a,b,n,e,k,s){
 var o=Ob(o);
 for(i=0;i<n;i++) {o=o.parentNode;}
 var innerHtml = o.innerHTML.replace(/\n/,'').replace(/\r/,'');
 if (o.className=='Closed') {
	 if (!(innerHtml.match('<ul>') || o.innerHTML.match('<UL>'))) {
 		o.className = 'LoadTree';
		getNode(o,e,k,s);
	 }
	 else {
 		o.className=o.className==a?b:a;
	}
 }
 else {
 	o.className=o.className==a?b:a;
 }
}


//require dojo 0.9.0
function getNode(o,e,k,s) {
  var o=Ob(o);
  dojo.xhrGet( {
	// The following URL must match that used to test the server.
	url: "tree_ajax.php?edge=" + e + "&keywords=" + k + "&c_species=" + s ,
	handleAs: "text",

	timeout: 5000, // Time in milliseconds

	// The LOAD function will be called on a successful response.
	load: function(response, ioArgs) {
		o.className = 'Opened';
		if (response.replace(/\r/,'').replace(/\n/,'').match('<li ')) {
			o.innerHTML += response;
		}
	  return response; 
	},

	// The ERROR function will be called in an error case.
	error: function(response, ioArgs) {
	  console.error("HTTP status code: ", ioArgs.xhr.status);
	  return response;
	  }
	});	
}

