<script>
function getNodeFromNodes(objNodes)
{
var objID=objNodes.getAttribute("ID");
objID=objID.substring(0,objID.indexOf("Nodes"))+"CheckBox";
var objNode=document.getElementById(objID);
return objNode;
}
function getNodesFromNode(objNode)
{
var objID=objNode.getAttribute("ID");
objID=objID.substring(0,objID.indexOf("CheckBox"))+"Nodes";
var objNodes=document.getElementById(objID);
return objNodes;
}
function getParentByTagName(element, tagName)
{
var parent = element.parentNode;
var upperTagName = tagName.toUpperCase();
while (parent && (parent.tagName.toUpperCase() != upperTagName))
{
parent = parent.parentNode ? parent.parentNode : parent.parentElement;
}
return parent;
}
function getChildCheckState(parentNode,type)
{
var parentNodes
if(type==0)
{
parentNodes=getNodesFromNode(parentNode)
}
else
{
parentNodes=parentNode
}
if(parentNodes==null || parentNodes == "undefined")
return true;
for(var i=0; i<parentNodes.children.length; i++)
{
var childNode = parentNodes.children[i];
if(childNode.tagName=="INPUT" && childNode.type=="checkbox")
{
if(childNode.checked==false)
return false;
}
else
{
var returnState=getChildCheckState(childNode,1);
if(returnState==false)
return false;
}
}
return true;
}
function checkParent(parentNode)
{
if(getChildCheckState(parentNode,0)==true)
parentNode.checked=true
else
return;
var objParentNodes = getParentByTagName(parentNode,"div");
if(objParentNodes==null || objParentNodes == "undefined")
return;
var objParentNode=getNodeFromNodes(objParentNodes);
if(objParentNode==null || objParentNode == "undefined")
return;
if(objParentNode.tagName!="INPUT" && objParentNode.type == "checkbox")
return;
checkParent(objParentNode);
}
function setParentNodeState(childNode,checkState)
{
var objParentNodes = getParentByTagName(childNode,"div");
if(objParentNodes==null || objParentNodes == "undefined")
return;
var objParentNode = getNodeFromNodes(objParentNodes);
if(objParentNode==null || objParentNode == "undefined")
return;
if(objParentNode.tagName!="INPUT" && objParentNode.type == "checkbox")
return;
if(checkState==true)
{
checkParent(objParentNode)
}
else
{
objParentNode.checked = false;
setParentNodeState(objParentNode,false);
}
}
function setChildNodeState(parentNodes,checkState)
{
for(var i=0; i<parentNodes.children.length; i++)
{
var childNode = parentNodes.children[i];
if(childNode.tagName=="INPUT" && childNode.type=="checkbox")
childNode.checked = checkState;
setChildNodeState(childNode, checkState);
}
}
function TransferCheck()
{
var objNode = event.srcElement;
if(objNode==null || objNode=="undefined")
return;
if(objNode.tagName!="INPUT" || objNode.type!="checkbox")
return;
var objNodes = getNodesFromNode(objNode);
if(objNodes==null || objNodes == "undefined")
{
setParentNodeState(objNode,objNode.checked);
}
else
{
setChildNodeState(objNodes,objNode.checked);
setParentNodeState(objNode,objNode.checked);
}
}
</script>