﻿
function CheckAllDataGridCheckBoxes(aspCheckBoxID, checkVal) {
    re = new RegExp(':' + aspCheckBoxID + '$')  //generated control name starts with a colon
    for(i = 0; i < document.forms[0].elements.length; i++) {
       elm = document.forms[0].elements[i]
        if (elm.type == 'checkbox') {
            if (re.test(elm.name)) {
                elm.checked = checkVal
            }
        }
    }
}

function CheckCompanyContacts(aspCheckBoxID, companyName, checkVal) {
    re = new RegExp(aspCheckBoxID + '$');  
    for(i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i];
        if (elm.type == 'checkbox') {
            if (re.test(elm.name)) {
                td = elm.parentNode;
                row = td.parentNode;
                tdCompany = row.children[3];
                if (tdCompany.innerHTML == companyName) {
                    elm.checked = checkVal;
                }
            }
        }
    }
}

function CheckParentContact(aspCheckBoxID, companyName, checkVal) {
    var allTheSame = true;
    re = new RegExp(aspCheckBoxID + '$');  
    var parentCheckbox;
    for(i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i];
        if (elm.type == 'checkbox') {
            if (re.test(elm.name)) {
                td = elm.parentNode;
                row = td.parentNode;
                tdIsCompany = row.children[2];
                tdCompany = row.children[3];
                if (tdCompany.innerHTML == companyName) {
                    if (tdIsCompany.innerHTML == 'True') {
                        parentCheckbox = elm;
                    } else {
                        if (elm.checked != checkVal) allTheSame = false;
                    }                    
                }
            }
        }
    }
    if (parentCheckbox != null) {
        if (allTheSame == true) {
            parentCheckbox.checked = checkVal;
        } else {
            parentCheckbox.checked = false;
        }
    }
}

/* this function is for the Inspections.ascx page */
function TogglePORequiredFlag(checkVal) {
    var setting;
    if (checkVal) {
        setting = 'visible';
    } else {
        setting = 'hidden';
    }
    var elm = document.getElementById('spanPORequired');
    elm.style.visibility = setting;
}
