function gebi(id){
	return document.getElementById(id);
}
function confirmAction(message){
    return confirm(message);
}

function hideFilter()
{
	gebi('FilterContent').style.display = 'none';
	gebi('FilterBar').style.display = 'block';
	return false;
}

function showFilter()
{
	gebi('FilterContent').style.display = 'block';
	gebi('FilterBar').style.display = 'none';
	return false;
}

function openWin(url, name){
	var _win = window.open(url,name,'scrollbars=yes,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no,modal=yes');
	_win.focus();
}

function openWinUnmodal(url, name){
	var _win = window.open(url,name,'scrollbars=yes,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
	_win.focus();
}

function openWinDefaultName(url){
	openWin(url, 'defaultName');
}

function doChangeDisplay(treeId,id){
	var div = document.getElementById(treeId+'_node_div_'+id);
	if(div==null){
		return false;
	}
	var img = document.getElementById(treeId+'_node_img_'+id);
	
	if(div.style.display == 'block'){
		div.style.display = 'none';
		img.src = './img/treeComp/plus.png';
	}else{
		div.style.display = 'block';
		img.src = './img/treeComp/minus.png';
	}
	return false;
}

function doChangeNode(treeId,id){
	var checkBox = document.getElementById('cb_'+treeId+'_'+id);
	var div = document.getElementById(treeId+'_content_node_'+id);
	if(checkBox.checked){
		div.style.display = "block";
		focusNode(treeId+'_'+id);
	}else{
		clearNode(treeId+'_'+id);
		div.style.display = "none";
	}
}

function allowNumbersOnly(event){
	var numcheck = /\d/;
	var keynum;
	if(window.event){
		keynum = event.keyCode;
	}
	else if(event.which) {
		keynum = event.charCode;
	}else{
		return true;
	}
	var keychar = String.fromCharCode(keynum);
	if(keynum<32){
		return true;
	}
	return numcheck.test(keychar);
}

function doClickNode(treeId,id){
	var checkbox = document.getElementById('cb_'+treeId+'_'+id);
	var isChecked = checkbox.checked;
	if(checkbox.attributes.parentId){
		var parentId = checkbox.attributes.parentId.value;
		handleParents(treeId,parentId);
	}
	handleChildrens(treeId,id,isChecked);
}
	
function handleParents(treeId,id){
	var checkbox = document.getElementById('cb_'+treeId+'_'+id);
	var div = document.getElementById(treeId+'_node_div_'+id);
	var innerCheckboxes = div.getElementsByTagName("input");
	for(var i=0; i<innerCheckboxes.length; i++){
		var box = innerCheckboxes[i];
		if(box.attributes.parentId){
			if(box.attributes.parentId.value==id && (box.checked || box.disabled)){
				checkbox.disabled = true;
				if(checkbox.attributes.parentId){
					handleParents(treeId,checkbox.attributes.parentId.value);
				}
				return;
			}
		} 
	}
	if(!checkbox.attributes.disabledPermanent || checkbox.attributes.disabledPermanent.value != 1){
		checkbox.disabled = false;
	}

	if(checkbox.attributes.parentId){
		handleParents(treeId,checkbox.attributes.parentId.value);
	}
}
	
function handleChildrens(treeId,id, isChecked){
	var div = document.getElementById(treeId+'_node_div_'+id);
	if(!div){
		return;
	}
	var innerCheckboxes = div.getElementsByTagName("input");
	for(var i=0; i<innerCheckboxes.length; i++){
		var box = innerCheckboxes[i];
		if(box.attributes.parentId){
			if(box.attributes.parentId.value==id){
				box.disabled = isChecked;
				handleChildrens(treeId,getNodeId(treeId, box), isChecked);	
			}
		} 
	}
}
	
function getNodeId(treeId, checkbox){
	var treeIdLength = (treeId == null) ? 4 : treeId.length;
	var id = checkbox.id;
	var nodeId = id.substring(treeIdLength + 4);
	return nodeId;
}