////DIAGNOSTIC - this code demonstrates that the 'Sweet Titles' tooltips can 
////only be applied to a single element without child elements.  The element
////being hovered over is what the toolTipLib object then assumes we have a
////tooltip for; this is not the case, because the tooltipref attribute is only
////on the containing element, not its children.
//toolTipLib.tipOver=function(e){
//    toolTipLib.obj = getEventSrc(e);
//    tID = setTimeout("showtooltiphover()",1);
//}
//function showtooltiphover(){
//    var disphtml="";
//    disphtml+="toolTipLib.obj tagname: " +  toolTipLib.obj.tagName;
//    disphtml+="<br />";
//    var ttref = toolTipLib.obj.getAttribute("tooltipref");
//    disphtml+="toolTipLib.obj tooltipref: " + (ttref ? ttref : "None.");
//    
//    document.getElementById("ShowHoverForTooltip").innerHTML=disphtml;
//}

//SetTheseChecks:  This sets the 'checked' value of all checkboxes with strPrefix in their name to bVal (bVal must be true or false).
//Adapted from DrugSurveys' repsys.js
function SetTheseChecks(strName, bVal) {
	var aryBase = document.getElementsByName(strName);
	for (var i=0, j=aryBase.length; i < j; i++) {
		aryBase[i].checked = bVal ? 'checked' : '';
	}
}

//Toggle-display function, initially for report descriptions.
function PopulateURS(URSText){
    var el = document.getElementById("URSDesc");
    el.innerText = (el.innerText=="") ? URSText : "";
}

//Function copied from MHD_PI, error reporting modified
//Modifies state of: divErrors
function isValidForm(){
    var strErrorMessage = "There were form errors.  See the above notes.";
    var retval = true;

    var funcaryValids;
    if(arguments.length > 0){
        funcaryValids = arguments;
    } else {
        //Exhaustively validate the whole form, according to externally-defined gfuncaryValids
        funcaryValids = gfuncaryValids;
    }
    
    //Use an array to temporarily store the validation functions' results, because && is a short-circuit operator.
    var aryRetvals = new Array();
    for(var i=0; i<funcaryValids.length; i++){
        aryRetvals[i] = funcaryValids[i]();
        retval = retval && aryRetvals[i];
    }
    
    //Error reporting
    var errs = document.getElementById('divErrors');
    if(retval){
        errs.innerHTML = "";
        errs.style.display = 'none';
    } else {
        //Request from AMH - don't display the message.  We'll instead display the message only if there are multiple things that could go wrong.
        if(funcaryValids.length > 1){
            errs.innerHTML = strErrorMessage;
            errs.style.display = 'block';
        }
    }
    return retval;
}

//GLOBAL variable
gfuncaryValids = new Array();
