// frm is the form object
// elm is the checkbox which initiated the click
// val is the unique group name
function ween_toggleEditor(id, eleToggleLink, imageid) {
  var elmlink = document.getElementById(eleToggleLink);
  var elmimg = document.getElementById(imageid);
  if (elmlink.title == 'Hide TinyMCE')
  {
    tinyMCE.execCommand('mceRemoveControl', false, id);
    elmlink.title = 'Show TinyMCE'; 
	elmimg.src = 'styles/advanced/images/enabletiny.gif'; 

  }
  else
  {
    tinyMCE.execCommand('mceAddControl', false, id);
    elmlink.title = 'Hide TinyMCE';
	elmimg.src = 'styles/advanced/images/disabletiny.gif'; 
  }
}

function select_deselectAll (formname, elm, group)
{
	var frm = document.forms[formname];
	
    // Loop through all elements
    for (i=0; i<frm.length; i++)
    {
        // Look for our Header Template's Checkbox
        if (elm.attributes['checkall'] != null && elm.attributes['checkall'].value == group)
        {
            if (frm.elements[i].attributes['checkme'] != null && frm.elements[i].attributes['checkme'].value == group)
              frm.elements[i].checked = elm.checked;
        }
        // Work here with the Item Template's multiple checkboxes
        else if (frm.elements[i].attributes['checkme'] != null && frm.elements[i].attributes['checkme'].value == group)
        {
            // Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
            if(frm.elements[i].checked == false)
            {
                frm.elements[1].checked = false; //Uncheck main select all checkbox
            }
        }
    }
}

function initCheckboxGroup(formname, group)
{
	var frm = document.forms[formname];
	var checkAllIndex = -1;
	var unchecked = false;
	
  // Loop through all elements
    for (i=0; i<frm.length; i++)
    {
        // Look for our Header Template's Checkbox
        if (frm.elements[i].attributes['checkall'] != null && frm.elements[i].attributes['checkall'].value == group)
        {
            checkAllIndex = i
        }
        // Work here with the Item Template's multiple checkboxes
        else if (frm.elements[i].attributes['checkme'] != null && frm.elements[i].attributes['checkme'].value == group)
        {
            // Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
            if(frm.elements[i].checked == false)
            {
            	unchecked = true;
                break;
            }
        }
    }	
    
    // If all the boxes in this group are checked, check the checkall 
    if(checkAllIndex != -1 && unchecked == false)
      frm.elements[checkAllIndex].checked = true;
}


