<!-- Begin

//boolean to set to true on CG pages that include report_matrix.jsp, since there is
//dependent code in report_matrix for CG pages only.
//depends on bug 4612. if we decide to do this later via another method, this could probably 
//be deleted safely - Daniel T 6/4/04
var isCustomGroups = false;

var clckcnt = 0;

// developed by willmaster.com
// modified by dkt
/*
NOTE: this function works all well and good when using it 
on an input type="image" or input type="submit" via a regular <form> post 
[usage:<form.... onsubmit="return clckcntr()">]
HOWEVER, doesn't seem to work well if used in any of the 
custom document.form.submit() functions which are called via links 
(e.g. <a href="javascript:submitForm()">Force Page Submit</a>)
SOLUTION: change any place where you need to use the clckcntr function to fire on the 
onclick event instead (e.g. <a href="#" onclick="submitForm();return false;")Force Page Submit</a>)
where submitForm() looks like:
function submitForm(){if(clckcntr()){document.form.submit()}}
-daniel 11/26/03
*/
function clckcntr() {
   if(clckcnt >= 1) {
      alert('Please wait, we\'re currently working on your request.');
      return false;
   }
   clckcnt++;
   return true;
}

// Check or uncheck all checkboxes for given form and given checkbox name
// if val is true, all checkboxes will be checked;
// if val is false, all checkboxes will be unchecked
// Usage: <input type="checkbox" name="checkAll" onClick="SetChecked('formName', true|false, 'checkboxName')" /> 
function SetChecked(form, val, chkName) {
   dml=document.forms[form];
   len = dml.elements.length;
   var i=0;
   for( i=0 ; i<len ; i++) {
      if ((dml.elements[i].name==chkName || dml.elements[i].id==chkName) && dml.elements[i].disabled != true) {
         dml.elements[i].checked=val;
      }
   }
}

function validateSelection(form, chkName, alertMessage){
    if (CountChecked(form, chkName) <= 0){
        alert(alertMessage);
        return false;
    }
    return true;
}


function CountChecked(form, chkName) {
   dml=document.forms[form];
   len = dml.elements.length;
   var i=0;
   var count=0;
   for( i=0 ; i<len ; i++) {
      if (dml.elements[i].name==chkName && dml.elements[i].checked) {
         count++;
      }
   }
   return count;
}

/**
 * If the checkbox named relatedBoxName is checked, then all checkboxes
 * named chkName will be checked; if the checkbox named relatedBoxName
 * is unchecked, all checkboxes named chkName will be unchecked.
 * Assumes there is only one checkbox named relatedBoxName.
 */
function propagateCheckToNestedCheckboxes(formName, relatedBoxName, chkName)
{
    docForm = document.forms[formName];
    var i;
    var relatedIndex = 0;
    var numTotal = 0;
    var numChecked = 0;
    for(i = 0; i < docForm.elements.length; i++) {
        if(docForm.elements[relatedIndex].name != relatedBoxName)
            relatedIndex++;
    }
    for(i = 0; i < docForm.elements.length; i++) {
        if(docForm.elements[i].name == chkName) {
            docForm.elements[i].checked = docForm.elements[relatedIndex].checked;
        }
    }
}

/**
 * If *type* checkboxes named chkName are checked, then the checkbox
 * named relatedBoxName will be checked; otherwise, the checkbox named
 * named relatedBoxName will be unchecked. Assumes there is only one
 * checkbox named relatedBoxName.
 * ...where *type* is 'any' or 'all'; i.e. if param type is string 'any',
 * then if any checkboxes named chkName are checked, etc...; and if param
 * type is string 'all', then if all checkboxes named chkName are checked, etc.
 * note: that's 'any' or 'all' without the quotation marks
 */
function propagateCheckToRelatedCheckbox(formName, relatedBoxName, chkName, type)
{
    docForm = document.forms[formName];
    var i;
    var relatedIndex = 0;
    var numTotal = 0;
    var numChecked = 0;
    for(i = 0; i < docForm.elements.length; i++) {
        if(docForm.elements[i].name == chkName) {
            numTotal++;
            if(docForm.elements[i].checked)
                numChecked++;
        }
        if(docForm.elements[relatedIndex].name != relatedBoxName)
            relatedIndex++;
    }
    if(type == "all")
        docForm.elements[relatedIndex].checked = (numChecked == numTotal);
    else if(type == "any")
        docForm.elements[relatedIndex].checked = (numChecked > 0);
}

// strips a parameter name and value from a URL and returns the new string.
function StripParam(URL, paramName) {
   var stripped = URL;                    // the final string to return
   var index = stripped.indexOf(paramName + "=");
   if (index != -1) {
      stripped = stripped.substring(0, index);
      var removed = URL.substring(index); // the entire string starting with the
                                          // segment to strip out
      var index2 = removed.indexOf("&");  // check for remaining parameters
      if (index2 != -1 && index2 != removed.length - 1) {
         stripped += removed.substring(index2 + 1); // keep the remaining params
      } else {
         // now that we've stripped out parameter, make sure remaining URL does
         // not end in '&' or '?'.  if so, take it out.
         var lastChar = stripped.charAt(stripped.length - 1);
         if (lastChar == '?' || lastChar == '&') {
            stripped = stripped.substring(0, stripped.length - 1);
         }
      }
   }
   return stripped;
}

// open a pop-up, specifying full path/filename
function openWindow(filename,width,height) {
    smallWindow = window.open(filename, "detailsWindow","toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width="+width+",height="+height);
}
// open a pop-up, specifying full path/filename
function makeSmallWindow(filename) {
    smallWindow = window.open(filename, "detailsWindow","toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=500,height=480");
}

// open a pop-up, specifying full path/filename
function makeSmallWindowWithScrollbar(filename) {
    smallWindow = window.open(filename, "detailsWindow","toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=500,height=480");
}

// open a pop-up for help, specifying full path/filename
function makeHelpWindow(filename) {
    smallWindow = window.open(filename, "helpWindow","toolbar=yes,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=760,height=500");
}

// open a pop-up window for DI user research
function openUserResearchWindow(filename, windowname) {
    smallWindow = window.open(filename, windowname,"toolbar=yes,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=760,height=500");
}

// open a pop-up window for product tour
function openProductTourWindow() {
    productTourWindow = window.open("http://www.riverpub.com/products/edusoft/tour/application.html", "detailsWindow","toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=770,height=530");
}

// trim a string of all leading and trailing whitespace, "trimming" null to ""
function trim(toTrim) {
    if (toTrim == null) {
        toTrim = "";
    }
    var leadingSpace = /^\s*/; 
    var trailingSpace = /\s*$/; 
    return toTrim.replace(leadingSpace, "").replace(trailingSpace, "");
}

function getHelp(url){
    myWindow = window.open(url, "newwin", "height=300,width=500,scrollbars=yes");
    myWindow.focus();
}

//pass in object to check to see if it is undefined
function isUndefined(obj){
    if ((typeof obj)=="undefined"){
        return true;
    }
    else {
        return false;
    }
}

function makeScreenshotWindow(imagepath, width, height) {
    var strBuf = '';
 
    // we should add a check of arguments length; if none, default width 
    // & height to some preset values
        
    strBuf += '<html><body style="margin: 10px;"><div align="center"><img src="' + imagepath + '" border="0"><br><div style="font-family: Arial, Helvetica; font-size: 10pt;"><a href="javascript:window.close()">close window</a></div></div></body></html>';
    screenshotWindow = window.open("", "screenshotWindow","toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=" + width + ",height=" + height + "");
    screenshotWindow.document.write(strBuf);
}

///////////// Functions to show/hide a single element  ////////////

function showElement(elementID) {
    setElementVisibility(elementID, "visible");
}

function hideElement(elementID) {
    setElementVisibility(elementID, "hidden");
}

function setElementVisibility(elementID, visibility) {
    document.getElementById(elementID).style.visibility = visibility;
}

///////////// Functions to show/hide multiple elements  ////////////

function showDropdowns(elementsToHideForTooltipString) {
    showElements(arguments); // Shortcut to allow passing variable # of args
}

function hideDropdowns(elementsToHideForTooltipString) {
    hideElements(arguments); // Shortcut to allow passing variable # of args
}

function showElements(elementIDs) {
    setElementVisibilities(elementIDs, "visible");
}

function hideElements(elementIDs) {
    setElementVisibilities(elementIDs, "hidden");
}

function setElementVisibilities(elementIDs, visibility) {
    for (i = 0; i < elementIDs.length; i++) {
        document.getElementById(elementIDs[i]).style.visibility = visibility;
    }
}

/** 
 * returns true if any checkboxes (or radio buttons) are selected,
 * accounting for cases when checkboxes are not an array but a single
 * checkbox.
 */
function global_anyChecked(checkboxes) {
    if(isUndefined(checkboxes.length)) {
        if(checkboxes.checked) {
            return true;
        }
    } else {
        for(i = 0; i < checkboxes.length; i++) {
            if(checkboxes[i].value != "" && checkboxes[i].checked) {
                return true;
            }
        }
    }
    return false;
}

/**
 *  Note: this must be called from within a the div that is dimmable.  Also, said div must
 *  have position = "relative".  Ex: 
 *      <div id="notAlways" style="position:relative"> 
 *      <script language="javascript"> prepareDimmable("notAlways", "#F9F9F9");</script>
 *      ... 
 *      </div id="notAlways" style="position:relative"> 
 */
function prepareDimmable(id, bgColor) {
    if(is_mac && (is_ie || !is_safari_1_3_up)) {
            document.write("<div id='" + id + "_dimmer' style=\"position:absolute;top:0"
                            + ";left:0;width:0;height:0"
                            + ";display:none; background-image:url(/img/misc/dialog_shader_bg.gif);"
                            + " background-repeat:repeat;\"></div>");
    } else {
            document.write("<div id='" + id + "_dimmer' style=\"position:absolute;top:0"
                            + ";left:0" + ";width:0" + ";height:0"
                            + ";display:none; background-color: " + bgColor 
                            + ";opacity:0.6;filter:alpha(opacity=60);\"></div>");
    }
}

function dimDiv(id, undim) {
   var dimmable = document.getElementById(id);
   var elem = document.getElementById(id + "_dimmer");
   if(elem != null && dimmable != null) { 
        var height = dimmable.offsetHeight;
        var width = dimmable.offsetWidth;
        //width = is_fx ? width-2 : width; 
        //height = is_fx ? height-2 : height;
       elem.style.height = height;
       elem.style.width = width;
       elem.style.display = (undim ? "none" : "block");
   }
}


// End -->
