function WFlags76(Prefix)
{
	this.Prefix = Prefix;
	this.name = '';
	this.edtValue = $(Prefix + 'edtValue');
	this.edtItems = $(Prefix + 'edtItems');
	this.CheckBoxList = new Array();
	this.tblMain = $(Prefix + 'tblMain');
	this.columnsCount = 0;
	this.uniqueId = '';

    // private	
    var items = '';
	
	this.ckeckBox_OnClick  = function(checkBoxID, value)
    {
    1;
        cb = document.getElementById(checkBoxID);
        if (cb)
           this.edtValue.value = parseInt(this.edtValue.value) +  (cb.checked ? value : -value );
    }

    this.getValue = function()
    {
    1;
        return this.edtValue.value;
    }
    
    this.setValue = function(value)
    {
        if (this.CheckBoxList.length > 0)
        {
            for (var i=0; i < this.CheckBoxList.length; i++)
            {
                cb = document.getElementById(Prefix + this.CheckBoxList[i].ID);
                if (cb)
                   cb.checked = this.CheckBoxList[i].Value & value;
            }
            this.edtValue.value = value;
        }
    }
    
    this.getIsUserVisible = function()
    {
        return this.tblMain.style.display != 'none';
    }
    
    this.setIsUserVisible = function(value)
    {
        this.tblMain.style.display = value == 'True' ? 'block' : 'none';
    }
    
    this.getItemsStr = function()
    {
       // return items;
    }
    
    this.setItemsStr = function(val)
    {
        items = val;
        
        if (this.edtItems) this.edtItems.value = this.encode(val);
        
        var itemsDom = this.newXMLDOM();
        itemsDom.loadXML(val);
        
        while (this.tblMain.rows.length) this.tblMain.deleteRow(0);
        this.CheckBoxList = new Array();
        
        var fiNode = itemsDom.documentElement.firstChild;
        var columnIndex = 0;
        var tr = null;
        while(fiNode)
        {
            if (!columnIndex || columnIndex >= this.columnsCount)
            {
                tr = this.tblMain.insertRow(-1);
                columnIndex = 0;
            }
            
            var fiValue = fiNode.selectSingleNode('Value').text;
            var td = tr.insertCell(-1);
            var chb_id = this.Prefix + 'cb_' +  fiValue;
            var td_html = '<input type="checkbox" ';
            td_html += 'id="' + chb_id + '" ';
            td_html += 'name="' + this.uniqueId + 'cb_' +  fiValue + '" ';
            td_html += 'onclick="' + this.name + '.ckeckBox_OnClick(\'' + chb_id + '\', ' + fiValue + ')"';
            td_html += '>';
            td_html += '<label for="' + chb_id + '">' + fiNode.selectSingleNode('Name').text + '</label>';
            td.innerHTML = td_html;
            
            this.CheckBoxList[this.CheckBoxList.length] = {ID: 'cb_' + fiValue, Value: fiValue};
            
            columnIndex++;
            fiNode = fiNode.nextSibling;
        }
        
        this.setValue(this.edtValue.value);
    }
    
    this.newXMLDOM = function()
	{
		return xml.DOMDocument.create();
	}
	
	this.decode = function(s)
    {
        return s.ReplaceAll("&lt;", "<").ReplaceAll("&gt;", ">");
    }
    
    this.encode = function(s)
    {
        return s.ReplaceAll("<", "&lt;").ReplaceAll(">", "&gt;");
    }
}

function Controls76_WFlags76_Builder(name, obj_id)
{
    this.name = name;
    try { this.obj = eval(obj_id); }
    catch (ex) { this.obj = null; }
    
    this.properties = new Array('IsUserVisible', 'ItemsStr', 'Value');
    
    this.get_prop = function(prop_name)
    {
        if (this.obj != null)
            switch(prop_name) 
            {
                default: return eval('if (this.obj.get' + prop_name + ') this.obj.get' + prop_name + '()');
            }
            
        return "";
    }
    
    this.set_prop = function(prop_name, prop_value)
    {
        if (this.obj != null)
            switch(prop_name)
            {
                default: eval('if (this.obj.set' + prop_name + ') this.obj.set' + prop_name + '(prop_value)');
            }
    }
}

