﻿function checkChildParents(nodo) {       
        var mainDiv         = nodo.parentNode.parentNode.parentNode.parentNode.parentNode;
        var inputMainDiv    = mainDiv.getElementsByTagName("input");
		var auxCheckBox     = false;
		var checkBoxYes		= false; 
		var auxCheckBoxYes	= false; 
		
        for (var i = 0; i<inputMainDiv.length; i++){    
			if (inputMainDiv[i].id.indexOf("_YesAnswerCheckBox") > 0 ){        
				if (nodo.checked){
					//If the checkbox is checked, the YesAnswerCheckBox must be checked
					checkBoxYes = document.getElementById(inputMainDiv[i].id);
					checkBoxYes.checked = true;
					checkBoxYes.disabled = true;      
				}
				else {	                   
					//If there is at least one checkbox checked, then YesAnswerCheckBox must be checked
					var checkNodes = nodo.parentNode.parentNode.childNodes;
					for (j=0; j<checkNodes.length; j++){
						if (checkNodes[j].tagName == "LI"){
							var x = checkNodes[j].childNodes;
							for(k=0; k < x.length; k++){
								if (x[k].type == 'checkbox'){
									if (x[k].checked)
										auxCheckBoxYes = true;
									else
										auxCheckBoxYes = false;
								}  
								if (auxCheckBoxYes)
									break;                                  
							}
						}
						if (auxCheckBoxYes)
							break;
					}  
					//If auxCheckBoxYes, means there is at least one checkbox checked                                 
					if (auxCheckBoxYes){
						inputMainDiv[i].checked = true;
                        inputMainDiv[i].disabled = true;						
					}  
					else{
						inputMainDiv[i].checked = false;
                        inputMainDiv[i].disabled = false;
					} 
				}
			}
			
			//This part is for the checkboxes
            if (inputMainDiv[i].id.indexOf("_IpedsFederalCheckBox") > 0){                
				if(inputMainDiv[i].type == 'checkbox'){
					if (nodo.checked){			
					    //If the current child CheckBox is checked, then the parent checkbox must be checked		    
						inputMainDiv[i].checked = nodo.checked;
						inputMainDiv[i].disabled = nodo.checked;	
						auxCheckBox = true;				  
                    }
                    else{
					    //If the current child CheckBox is not checked and at least other child checkbox in this 
					    //group is checked then the parent checkBox must be checked
                        var checkNodes = nodo.parentNode.parentNode.childNodes;
                        for (j=0; j<checkNodes.length; j++){
                            if (checkNodes[j].tagName == "LI"){
                                var x = checkNodes[j].childNodes;
                                for(k=0; k < x.length; k++){
                                    if (x[k].type == 'checkbox'){
                                        if (x[k].checked)
                                        	auxCheckBox = true;
                                        else
                                            auxCheckBox = false;
                                    }  
                                    if (auxCheckBox)
                                        break;                                  
                                }
                            }
                            if (auxCheckBox)
                                break;
						}                                   
						if (auxCheckBox){
                            inputMainDiv[i].checked = true;
                            inputMainDiv[i].disabled = true;
                        }  
                        else{
                            inputMainDiv[i].checked  = false;
                            inputMainDiv[i].disabled = false;                         
                        }
                    }                                       
                }
			}             
        }       
	} 
	
	