﻿// Checks to see if the client is Internet Explorer
// Return a boolean (true = IE) (False = Other)
function isIE()
{
    return document.all ? true : false;
}

// Function to work around the inherited problem of related asp:radiobuttons having
// unique groupnames due to their parent nodes implementing the INamingContainer interface
function SetUniqueRadioButton(current)
{ 
   var rootControl = /^\w+/.exec(current.name);
   var groupName = /\w+$/.exec(current.name);
   var regExp = new RegExp(rootControl + '.*' + groupName); 
   
   for(i = 0; i < document.forms[0].elements.length; i++) 
   { 
      e = document.forms[0].elements[i];
      if (e.type == 'radio') 
      { 
         if (regExp.test(e.name)) 
         { 
            e.checked = false; 
         } 
      } 
   } 
   
   current.checked = true; 
}

// Function to retrieve all elements of a specified type from a container element
// For example, get all child nodes in a table which are of type checkbox
function getChildNodesByType(element, type)
{
    var output = new Array();
    
    if (element.hasChildNodes())
        for (var i=0; i<element.childNodes.length; i++)
        {
            if (element.childNodes[i].nodeName == type || element.childNodes[i].type == type)
                output.push(element.childNodes[i]);
            
            if (element.childNodes[i].hasChildNodes())
                output = output.concat(getChildNodesByType(element.childNodes[i], type));
        }

    return output;
}

// Raises an alert to confirm raised click event of a delete button
function confirmDelete(e, title)
{
    var message = "DELETE " + title.toUpperCase() + '\n' +
                  "Are you sure? This " + title.toLowerCase() + " and any related data \n" +
                  "will be irrevocably removed.\n\n" + 
                  "" +
                  "OK - Yes, delete this " + title.toLowerCase() + "\n" +
                  "CANCEL - No, keep this "  + title.toLowerCase();
                  
    if (!confirm(message))
        if (isIE())
            e.returnValue = false;
        else
            e.preventDefault(true);

}