function DBRadioGroup(parent){//构造函数    
	var pdiv,obj=document.createElement('div');//创建一个控制节点
	if(parent){pdiv=parent;}else pdiv=document.body;//获取父块
    pdiv.appendChild(obj);
	obj.Button=new Array(); //单选按钮radio
	obj.Span=new Array(); //标签
	obj.ID;
	obj.Items=new Strings(); 
	obj.Values=new Strings();
	obj.DataField=null;//主表字段    
	obj.DataSet;  
	obj.SubDiv=new Array();//容纳radio的子块
	obj.OnClick=DBRG_onclick; //radion的onclick事件
	obj.RecordMove=DBRG_recordmove; //当记录发生滚动时，radio的改变
	obj.CreateRadio=DBRG_createradio;//创建radio	
	obj.removeradios=DBRG_removeradios;
	obj.Show=DBRG_show;
	obj.HandleMessage=DBRG_handlemessage;
  if(isIE)
	obj.onpropertychange=DC_onpropertychange
  else
	addEventTimerListener(obj,DC_onpropertychange);
	obj.style.position='absolute';
    obj.oncontextmenu=div_oncontextmenu;
	return obj;
}
function DBRG_onpropertychange()//属性变化处理
{
  var n=event.propertyName;
  switch(n){
	case 'DataSet':
	  if(this.OldDataSet)this.OldDataSet.RemoveLink(this);//从原来的DATASET中移除
      if(this.DataSet)this.DataSet.LinkObj(this);
	  this.OldDataSet=this.DataSet;
	  break;
  }
}
function DBRG_show(){
  this.CreateRadio();
}
function DBRG_createradio(){ //创建子块和radio，标签
  if(this.FrameDiv)this.removeradios();
  var item=this.Items.Strings;
  var values=this.Values.Strings;
  this.FrameDiv=document.createElement('div');
  this.appendChild(this.FrameDiv);//把子块添加到大块中		
  for(var i=0;i<item.length;i++){
	this.Button[i]=document.createElement('input');
	this.SubDiv[i]=document.createElement('div');
	this.Span[i]=document.createElement('span');
	this.FrameDiv.appendChild(this.SubDiv[i]);	//把子块添加到大块中		
	this.Button[i].type="radio"; 	
	this.Button[i].value=values[i]; 
	this.Span[i].innerText=item[i];//显示标签				
	this.Button[i].setAttribute('parent',this);				
	this.Button[i].onclick=this.OnClick;//添加onclick事件
	this.SubDiv[i].appendChild(this.Button[i]);//向子块中添加radio
	this.SubDiv[i].appendChild(this.Span[i]);//添加标签			
  }		
}
function DBRG_removeradios()
{
   this.removeChild(this.FrameDiv);
   this.FrameDiv.removeNode(true);
}
function DBRG_onclick(){
	for(var i=0;i<this.parent.Items.Strings.length;i++){ 
		this.parent.Button[i].checked=false; //置所有的radio为没选中
		this.checked=true; //把当前发生onclick事件的radio设为选中
		}
	var p=this.parent;	
	var parm=this.value;
	if(p.DataSet.Fields.State!=szNew){
     if (p.DataSet.RecordCount==0){p.DataSet.Append();}
     else p.DataSet.Edit();
	}
    var f=p.DataSet.Fields.Field[p.DataField];
	if(!f)jcl_err(p.Name+'.DataField:'+p.DataField+Err_NoField);
	f.Value = parm;
	if(f.Err)this.focus();		
}

function DBRG_handlemessage(sender,msg,recno){
	switch(msg){
		case 0:this.Show();this.RecordMove();break; 
		case 1: this.RecordMove();break;
		case 2:	this.RecordMove();break;
		case 3:	this.RecordMove();break;  //记录发生滚动时
		case 4:	this.RecordMove();break;
		case 5:	this.RecordMove();break;
		case 6:	this.RecordMove();break;
		case 7:	this.RecordMove();break;
		case 8:	this.RecordMove();break;
		//case 9:	this.RecordMove();break;
	}
}
function DBRG_recordmove(){  //根据主表当前记录的值来确定那个radio可选
    var f=this.DataSet.Fields.Field[this.DataField];
	if(!f)jcl_err(this.Name+'.DataField:'+this.DataField+Err_NoField);
	var currentvalue=f.Value;	
	var d=this.DataSet;
	d.AutoControl=false;	
	var radios=this.Button;
	for(var i=0;i<radios.length;i++){
		this.Button[i].checked=false;
		if(radios[i].value==currentvalue){
			this.Button[i].checked=true;
		}
	}	
	d.AutoControl=true;
}
