function GroupForm(obj, group_var, selall_var, change, level)
{
	this.obj = obj;
	this.group_obj = new Array();
   
	if(typeof(group_var) == 'object')
	{
		if(group_var.length)
		{
			for(i=0; i<group_var.length; i++) 
         	{
            	this.group_obj[this.group_obj.length] = this.obj[group_var[i]];
         	}
		}
	}
	else
	{
   		this.group_obj[this.group_obj.length] = this.obj[group_var];
	}
   
	this.selall_obj = this.obj[selall_var];
	this.enable_change = change;
	this.level = arguments.length < 5 ? 3 : level;
   
	this.onSelectAllClick = GroupForm_onSelectAllClick;
	this.onSelectAllCheck = GroupForm_onSelectAllCheck;
	this.onClick = GroupForm_onClick;
	this.onChange = GroupForm_onChange;
}

function GroupForm_onSelectAllCheck(action)
{
	if(arguments.length && this.selall_obj)
	{
		if(this.selall_obj.length)
		{
			for(i=0; i<this.selall_obj.length; i++) 
         	{
            	this.selall_obj[i].checked = action;
         	}
		}
		else 
      	{
         	this.selall_obj.checked = action;
      	}
	}
}

function GroupForm_onSelectAllClick(action)
{
	if(arguments.length && this.group_obj.length) 
	{
		for(j=0; j<this.group_obj.length; j++) 
		{
			if(this.group_obj[j].length) 
			{
				for(i=0; i<this.group_obj[j].length; i++) 
				{
					this.group_obj[j][i].checked = action;
					if(this.enable_change)
					{
						this.onChange(this.group_obj[j][i]);
					}
				}
			}
			else 
			{
				this.group_obj[j].checked = action;
				if(this.enable_change)
				{
					this.onChange(this.group_obj[j]);
				}
			}
		}
      
		this.onSelectAllCheck(action);
	}
}

function GroupForm_onClick()
{
	var AllChecked = true;
   
	if(this.group_obj) 
	{
		for(j=0; j<this.group_obj.length; j++) 
		{
			if(this.group_obj[j].length) 
			{
				for(i=0; i<this.group_obj[j].length; i++) 
				{
					if(!this.group_obj[j][i].checked) 
					{
						AllChecked = false;
						break;
					}
				}
			}
			else 
			{
				AllChecked = this.group_obj[j].checked;
			}
		}

      this.onSelectAllCheck(AllChecked);
   }
}
   
function GroupForm_onChange(obj, checked)
{
	var changeObj = obj;
	
	var checked = arguments.length < 3 ? obj.checked : false;

	for(l=1; l<this.level; l++)
	{
		changeObj = changeObj.parentNode;
	}

	if(checked)
	{
		changeObj.style.backgroundColor = '#d4d4c5';
	}
	else
	{
		changeObj.style.backgroundColor = '';
	}
}

function Hide(evt, element)
{
   evt = (evt) ? evt : ((window.event) ? event : null);
   
   if(evt)
   {
     	var relatedTarget = (evt.relatedTarget) ? evt.relatedTarget : ((evt.toElement) ? evt.toElement : null);
		if(relatedTarget.tagName.toLowerCase() == 'div')
		{
			ShowHide(element, false);
		}
   }
}