function SearchToggle(gid, qt, id, pid) {
	s_clear(qt);
	
	if(pid !=0) {
		document.getElementById(pid).className = "cellReport_sel"; // gid, qt
		ajax_showTooltip('/ajax/get_tooltip_content/' + id + '/' + qt + '/' + 1, document.getElementById(pid));
	} else {
		document.getElementById(gid).className = "cellReport_sel";
		ajax_showTooltip('/ajax/get_tooltip_content/' + id + '/' + qt + '/' + 1, document.getElementById(gid));
	}
	document.getElementById('ajax_tooltipObj').style.left = "400px";
}

function Toggle(gid, qt, id, pid, qt2l, qt1l) {
	//colapseAll(qt, gid);
	//clearAll(gid, qt, 1);
	clear(qt);
	
	if(pid !=0) {
		document.getElementById(pid).className = "tree_item_sel"; // gid, qt
		ajax_showTooltip('/ajax/get_tooltip_content/' + id + '/' + qt + '/' + 0, document.getElementById(pid));
	} else {
		document.getElementById(gid).className = "tree_item_sel";
		ajax_showTooltip('/ajax/get_tooltip_content/' + id + '/' + qt + '/' + 0, document.getElementById(gid));
	}
	document.getElementById('ajax_tooltipObj').style.left = "400px";
}

function s_clear(qt) {
	//alert(qt);
	for(var i = 0; i < qt; i++) {
		sb = "s_sub" + i;
		var ar = document.getElementById(sb).getElementsByTagName("div");
		for(var j=0; j<ar.length; j++) {
			if(ar[j].id.match(/u_t_[0-9]+/)) {
				ar[j].className = "cellReport";
			}
			else if(ar[j].id.match(/^xs_t_[0-9]+/)) {
				ar[j].className = "cellReport";
			}
		}
	}
}

function clear(qt) {
	//alert(qt);
	for(var i = 0; i < qt; i++) {
		sb = "sub" + i;
		var ar = document.getElementById(sb).getElementsByTagName("div");
		for(var j=0; j<ar.length; j++) {
			if(ar[j].id.match(/u_t_[0-9]+/)) {
				ar[j].className = "tree_item";
			}
			else if(ar[j].id.match(/^xs_t_[0-9]+/)) {
				ar[j].className = "tree_item";
			}
		}
	}
}

function clearAll(gid, qt, isOpening) {
	for(var i = 0; i < qt; i++) {
		sb = "sub" + i;
		var ar = document.getElementById(sb).getElementsByTagName("div");
		for(var j=0; j<ar.length; j++) {
			if(ar[j].id == gid && ar[j].id.match(/u_t_[0-9]+/) && isOpening == 0) {
				ar[j].className = "tree_item";
			}
			else if(ar[j].id != gid && !ar[j].id.match(/^img[0-9]+/) && !ar[j].id.match(/^x_t_s_[0-9]+/)) {
				ar[j].className = "tree_item";
			}
		}
	}
}

function s_clearAll(gid, qt, isOpening) {
	for(var i = 0; i < qt; i++) {
		sb = "s_sub" + i;
		var ar = document.getElementById(sb).getElementsByTagName("div");
		for(var j=0; j<ar.length; j++) {
			if(ar[j].id == gid && ar[j].id.match(/u_t_[0-9]+/) && isOpening == 0) {
				ar[j].className = "cellReport";
			}
			else if(ar[j].id != gid && !ar[j].id.match(/^img[0-9]+/) && !ar[j].id.match(/^x_t_s_[0-9]+/)) {
				ar[j].className = "cellReport";
			}
		}
	}
}

function colapseAll(qt, gid) {
	for(var i = 0; i < qt; i++) {
		sb = "sub" + i;
		var ar = document.getElementById(sb).getElementsByTagName("div");
		for(var j=0; j<ar.length; j++) {
			if(ar[j].style.display == "block" && gid.match(/u_t_[0-9]+/)) {
				ar[j].style.display = "none";
			}
			if(ar[j].id.match(/^x_t_s_[0-9]+/) && ar[j].id != gid && gid.match(/^x_t_s_[0-9]+/)) {
				ar[j].style.display="none";
			}
		}
	}
}

function ExpandBranch(gn, sf, item, qt, qt2l, qt1l) {
	ajax_hideTooltip();

	var self = document.getElementById(sf);
	obj=document.getElementById(item);
	visible=(obj.style.display!="none")

	if (visible) {
		obj.style.display="none";
		self.className = "tree_item";
	} else {
		obj.style.display="block";
		self.className = "tree_item_sel";
	}
	
	//colapseAll(qt, item);
	//clearAll(sf, qt, 1);
	clear(qt);
}

function ExpandCategory(gn, sf, item, qt, qt2l, qt1l) {
	ajax_hideTooltip();

	var self = document.getElementById(sf);
	obj=document.getElementById(item);
	visible=(obj.style.display!="none")

	if (visible) {
		obj.style.display="none";
		self.className = "cellItem";
	} else {
		obj.style.display="block";
		self.className = "cellItem_opened";
	}
	
	//colapseAll(qt, item);
	//clearAll(sf, qt, 1);
	s_clear(qt);
}
