Ext.namespace('Sourceflow.form');

Sourceflow.form.RadioSelect = function (params)
{	   

	this.rightSpacing=40;
	this.rightToggleSpacing=0;
	if (Ext.isChrome || Ext.isSafari) this.rightToggleSpacing=5;
	this.type="Sourceflow.form.RadioSelect";
	this.id = Ext.id();
	this.transform = params.transform;
	this.selectId = this.transform.id;
	this.selectName = this.transform.name;
	this.useCheckboxes=params.useCheckboxes || false;
	var s = Ext.getDom(this.transform);
	this.maxSelected=params.maxSelected || 3;
	this.zIndexBase=params.zIndexBase || 1000;
	this.allowMultiple = params.allowMultiple || true;
	this.closeOnSelect = params.closeOnSelect || true;
	if (params.containerCell) this.containerCell = params.containerCell;
	this.onOptionsChanged = params.onOptionsChanged || function(){};
	this.parentObj = params.parentObj || null;
	this.panelWidth = params.panelWidth || 300;
	this.showAllOptionsText = params.showAllOptionsText || "View Options";
	
	this.cellWidth = params.cellWidth || 130;
	
    this.loadStore();
    this.setupValuePanel();
    this.containerCell = Utilities.findNearestParentWithTag(s,"td");// s.parentNode.parentNode.parentNode; //table cell

    s.parentNode.removeChild(s);

    this.selectionQueue = [];
    
    this.setupRadioPanel();
    if (!document.radioSelectRegistry) document.radioSelectRegistry=[];
    document.radioSelectRegistry.push(this);
    
    var inp = Ext.query("button",this.radioToggle.getEl().dom);
    inp[0].sfType='toggle';
    
    var self = this;
    document.body.onclick=function(x){
	    var target = x ? x.target : event.srcElement; 
	    var rp = Utilities.findNearestParentWithTagAndClass(target,"div","radioGroup");
	    if (!rp && (!target.sfType || target.sfType!='toggle')) self.hideAll();
    };

	this.originalValues = this.getSelectedValues();
	this.isVisible=true;
    this.isSetup = true;
   // alert(this.getSelectedValues());
}

Sourceflow.form.RadioSelect.prototype.loadStore = function()
{
	var s = Ext.getDom(this.transform);
	this.el = s;
	this.listParent = document.createElement('div');
	this.listParent.className = 'listParent-RadioSelect';
	this.listParent.style.position='relative';
	this.listParent.sfType='RadioSelect';
	
	s.parentNode.appendChild(this.listParent); 
	this.mode = 'local';
    this.data = [];
    var opts = s.options;

    this.selectedValues = [];
    for(var i = 0, len = opts.length;i < len; i++){
        var o = opts[i];
        var value = (o.hasAttribute ? o.hasAttribute('value') : o.getAttribute('value') !== null) ? o.value : o.text;
        if(o.selected && !Ext.isEmpty(this.value, true) || i==0) {
        	if (value=='') value = o.text;
            this.value = value;
            this.text = o.text;
            this.selectedValues.push(value);
        }
        this.data.push([value, o.text]);

        
    }

    this.store = new Ext.data.ArrayStore({
        'id': 0,
        fields: ['value', 'text'],
        data : this.data,
        autoDestroy: true
    });
    this.valueField = 'value';
    this.displayField = 'text';
    
}
Sourceflow.form.RadioSelect.prototype.resetToValue = function(displayValue)
{
	var key = this.getKeyFromTextValue(displayValue);
	this.writeValueToValuePanel(displayValue);
	var options = this.radioOptions;
	for (var i=0;i<options.length;i++)
	{
		var option = options[i];
		option.setValue(option.value==key);
	}
}

Sourceflow.form.RadioSelect.prototype.reset = function(originalValues,displayValue)
{
	var options = this.radioOptions;
	if (!originalValues) originalValues = this.originalValues;

	if (originalValues) {
		for (var i=0;i<options.length;i++)
		{
			var option = options[i];
			var valueSet = false;
			for (var c=0;c<originalValues.length;c++) {
				var j = originalValues[c].index;
				if (j==i) {
					
					if (valueSet===false) {
						displayValue = displayValue || option.text;
						this.writeValueToValuePanel(displayValue);
					}
					valueSet=true;
				}
			}

			option.setValue(valueSet);
		}
	}
}
Sourceflow.form.RadioSelect.prototype.setSelectedClass = function(inp,value) {
	if (value===false && inp.getEl()) Utilities.replaceClass(inp.getEl().dom.parentNode,"x-combo-selected","");
	else if (value == true && inp.getEl()) inp.getEl().dom.parentNode.className+=" x-combo-selected";
}
Sourceflow.form.RadioSelect.prototype.setValue = function(input)
{
	if (input) {
		var radioSelect = input.radioSelect;
		//input.tempid="radio-current-item"+Ext.id();
		var options = radioSelect.radioOptions;
		var valuePanel = radioSelect.valuePanel;
		radioSelect.selectedValues=[];
		var checked = input.getValue();
		//alert(input+" "+radioSelect);
		if (radioSelect.useCheckboxes==true)
		{
			
			var max = radioSelect.maxSelected;		
			var len = radioSelect.selectionQueue.length;
			var currentIndex = radioSelect.checkboxItemsCounted % max;
			radioSelect.checkboxItemsCounted++;
	
			radioSelect.selectionQueue=radioSelect.getModifiedSelectionQueue(input);
			//alert(radioSelect.selectionQueue);
	    	for (var i=0;i<options.length;i++)
	    	{
	    		var inp = options[i];
				//alert(input+" "+inp.checked+" "+Utilities.arrayContains(radioSelect.selectionQueue,inp.value));
				inp.suspendEvents();
				var isSelected = Utilities.arrayContains(radioSelect.selectionQueue,inp.value);
				inp.setValue(isSelected);
				radioSelect.setSelectedClass(inp,isSelected);
				//alert(inp.getEl().dom.className);//
				
	    	}
	    	input.setValue(checked);
		}
	
		for (var i=0;i<options.length;i++)
		{
			var inp = options[i];
			if (inp.checked) {
				var oldHeight = valuePanel.getHeight();
				
				if (radioSelect.useCheckboxes===false) radioSelect.writeValueToValuePanel(inp.boxLabel);
				
				//preserve height - height was at max needed
				if (valuePanel.getHeight()<oldHeight) valuePanel.setHeight(oldHeight)
				radioSelect.selectedValues.push(inp.value);
			}
			//alert(inp.getEl().dom.parentNode.className);
			if (inp.getValue()===false && inp.getEl()) Utilities.replaceClass(inp.getEl().dom.parentNode,"x-combo-selected","");
			else if (inp.value == input.value && inp.getEl()) input.getEl().dom.parentNode.className+=" x-combo-selected";
			inp.resumeEvents();
		}
		if (input.checked && inp.getEl()) {
			input.getEl().dom.parentNode.className+=" x-combo-selected";
			
		}
		//alert("selected "+radioSelect.selectedValues+" "+input.value+" "+radioSelect.closeOnSelect+" "+radioSelect.useCheckboxes);
		if ((radioSelect.isSetup==true) && Utilities.arrayContains(radioSelect.selectedValues,input.value)
				&& (radioSelect.lastRadioId != input.id)) {
			if (radioSelect.useCheckboxes==false) radioSelect.lastRadioId = input.id;
			//alert(input.id);
			radioSelect.onOptionsChanged();
		}
		if (radioSelect.closeOnSelect===true && radioSelect.useCheckboxes===false) {
			radioSelect.hideRadioGroup(radioSelect.radioToggle);
		}
	}
	//input.tempid=null;
}
Sourceflow.form.RadioSelect.prototype.writeValueToValuePanel = function(value) {
 	this.valuePanel.getEl().dom.childNodes[0].childNodes[0].innerHTML=value;//;
}
Sourceflow.form.RadioSelect.prototype.getValueFromValuePanel = function() {
 	return this.valuePanel.getEl().dom.childNodes[0].childNodes[0].innerHTML.replace("&amp;","&");//;
}
Sourceflow.form.RadioSelect.prototype.getKeyFromTextValue = function(value) {
	if (!value) value = this.getValueFromValuePanel();
	for (var j=0;j<this.radioOptions.length;j++) {
		if (this.radioOptions[j].text==value) return this.radioOptions[j].value;
	}
 	return null;
}
Sourceflow.form.RadioSelect.prototype.getModifiedSelectionQueue = function(input) {
	var max = this.maxSelected;	
	var oldQueue = this.selectionQueue;
	var len = oldQueue.length;
	if (len==0) {
		//check that queue is up to date

		var options = this.radioOptions;
		for (var i=0;i<options.length;i++) {
			var inp = options[i];
			if (inp.getValue()===true) {
				oldQueue.push(inp.value);
			}
		}
		len = oldQueue.length;
		//alert(oldQueue.length);
		
	}

	var newQueue = [];
	var checked = input.getValue();
	
	//if checked, adding a value to the list
	if (checked==true)
	{

		var start = (len<max ? 0:1); 
		for (var i=start;i<len;i++) {
			newQueue.push(oldQueue[i]);
		}

		newQueue.push(input.value);
	}
	//if unchecked, removing one
	else {
		for (var i=0;i<len;i++) {
			if (oldQueue[i]!=input.value) newQueue.push(oldQueue[i]);
		}
	}
	
	return newQueue;
}
Sourceflow.form.RadioSelect.prototype.getSelectedValuesFromRadioSelect = function()
{
	var options = this.radioOptions;
	this.selectedValues=[];
	for (var i=0;i<options.length;i++)
	{
		var inp = options[i];
		if (inp.checked) {
			this.selectedValues.push(inp.value);
		}
	}
}
getKeys = function(obj)
{
	var keys = "";
	for (var c in obj) keys+=" "+c;
	return keys;
}
Sourceflow.form.RadioSelect.prototype.hideAll = function()
{
	for (var i=0;i<document.radioSelectRegistry.length;i++) {
		document.radioSelectRegistry[i].radioPanel.hide();
		//document.radioSelectRegistry[i].radioToggle.setTooltip("Show Options");
		document.radioSelectRegistry[i].radioToggle.setIconClass('trigger-icon-class');
	}
}
Sourceflow.form.RadioSelect.prototype.showHideRadioGroup = function(btn)
{
	var rg = btn.radioPanel;
	var rgHidden = rg.hidden;
	
	btn.parentObject.hideAll();

	if (rgHidden) {
		btn.parentObject.showRadioGroup(btn);
	}
	else {
		btn.parentObject.hideRadioGroup(btn);
	}
}
Sourceflow.form.RadioSelect.prototype.hideRadioGroup = function(btn)
{
	var rg = btn.parentObject.radioPanel;
	//btn.parentObject.radioToggle.setTooltip("Show Options");
	rg.hide();
	btn.parentObject.radioToggle.setIconClass('trigger-icon-class');
}
Sourceflow.form.RadioSelect.prototype.showRadioGroup = function(btn)
{
		var rg = btn.parentObject.radioPanel;
		var dw = document.body.scrollWidth;
		var dh = !Ext.isIE ? window.innerHeight :
			(document.documentElement.clientHeight || document.body.clientHeight);
		
		//btn.setTooltip("Hide Options");
		var xy = btn.getPosition(false);
		xy[1]+=22;
		xy[0]-=150;
		
		var w = rg.getWidth();
		if (dw<xy[0]+w) {
			xy[0] -= (xy[0]+w)-dw + 20;
		}

		var h = rg.getHeight();
		
		var yp = Utilities.findPos(btn.getEl().dom)[1];
		var offset = Ext.isIE ? document.documentElement.scrollTop : window.pageYOffset
	//	alert(offset+' '+yp+' '+dh+' '+h);
		
		
		if (dh<yp+h-offset) {
			xy[1] = yp - (h);
		}

		if (!Ext.isIE6 ) {
			rg.setPagePosition(xy);
			this.setPosition=true;
		}
		else {
			rg.setPosition(xy);
			this.setPosition=true;
		}

		rg.show();
		
		/*
		var cbs = Ext.query(".x-form-cb-label",rg.getEl().dom);
		cbs[0].parentNode.style.border='1px solid blue';
		cbs[0].parentNode.style.width="200px";
		cbs[0].parentNode.childNodes[0].style.border='1px solid red';
		cbs[0].style.border='1px solid red';
		cbs[0].childNodes[0].style.border='1px solid black';
		cbs[0].childNodes[0].style.styleFloat='left';

		alert(cbs[0].innerHTML);
		
		*/
		btn.setIconClass('trigger-icon-selected-class');
}
Sourceflow.form.RadioSelect.prototype.toggleCheckboxRadios = function(input)
{
	
	var radioSelect = input.radioSelect;
	radioSelect.radioPanel.destroy();
	radioSelect.useCheckboxes=!radioSelect.useCheckboxes;
	radioSelect.setupRadioPanel();
	radioSelect.radioPanel.show();
	
	input.parentObject.showRadioGroup(input.parentObject.radioToggle);
}
Sourceflow.form.RadioSelect.prototype.getEl = function()
{
	return this.containerPanel.getEl();
}
Sourceflow.form.RadioSelect.prototype.getSelectedValues = function()
{
	var result=[];
	if (this.useCheckboxes==true)
	{
		var options = this.radioOptions;

    	for (var i=0;i<options.length;i++)
    	{
    		var inp = options[i];

			if (inp.getValue()===true) {
				var tmp = {};
				tmp.text = inp.text;
				tmp.value = inp.value;
				tmp.index = i;
				result.push(tmp);
			}
		}
	}
	return result;
}
Sourceflow.form.RadioSelect.prototype.setSelectedValues = function(values)
{
	var result=[];
	if (this.useCheckboxes==true)
	{
		var options = this.radioOptions;
		for (var i=0;i<options.length;i++)
    	{
    		options[i].setValue(false);
    		this.setSelectedClass(options[i],false); 
    	}
    	for (var i=0;i<values.length;i++)
    	{
    		var tmp =values[i];
    		var inp = options[tmp.index];

			if (inp) {
				inp.suspendEvents();
				inp.setValue(true);
				inp.resumeEvents();
				this.setSelectedClass(inp,true); 
			}
		}
	}

}
Sourceflow.form.RadioSelect.prototype.getAllValues = function()
{
	var result=[];
	if (this.useCheckboxes==true)
	{
		var options = this.radioOptions;

    	for (var i=0;i<options.length;i++)
    	{
    		var inp = options[i];

			//if (inp.getValue()===true) {
				var tmp = {};
				tmp.text = inp.text;
				tmp.value = inp.value;
				tmp.index = i;
				result.push(tmp);
			//}
		}
	}
	return result;
}
Sourceflow.form.RadioSelect.prototype.setupValuePanel = function()
{
	var panelId = 'valuePanel-'+this.id;
	var radioId = 'radioId-'+this.id;
	var containerPanelId = 'containerPanel-'+this.id;
	var toggleId = 'radioToggle-'+this.id;
	var groupId = 'radioGroup-'+this.id;

	this.radioToggle = new Ext.Button({
		id:toggleId,
		icon:'/common/ext-3.0.0/resources/images/default/form/trigger.gif',
		//tooltip:'Show Options',
		width:17,
		toggle:true,
		parentObject:this,
		iconCls:'trigger-icon-class',
		style:'position:absolute;right:'+this.rightToggleSpacing+'px;z-index:'+(this.zIndexBase+1),
		handler:this.showHideRadioGroup
		});
	
	this.valuePanel = new Ext.Panel({
		id: panelId,
		border:false,
		cls:'sf-value-panel',
		html:this.text});
	this.containerPanel = new Ext.Panel({
		id: containerPanelId,
		border:false,
		items:[this.radioToggle,this.valuePanel]});

	this.containerPanel.render(this.listParent);
	//this.radioToggle.on('toggle',function(){alert('x');});
	//alert(this.radioToggle.getEl().dom.tagName);
	
	

}
Sourceflow.form.RadioSelect.prototype.setVisible = function(arg)
{
	this.isVisible = arg;
	if (arg==true) {
		if (this.listParent.show) this.listParent.show();
		else this.listParent.style.display='';
	}
	else {
		if (this.listParent.hide)  this.listParent.hide();
		this.listParent.style.display='none';
	}
}
Sourceflow.form.RadioSelect.prototype.setTriggerVisible = function(arg)
{
	this.radioToggle.setVisible(arg);
}
Sourceflow.form.RadioSelect.prototype.createOpenLink = function()
{
		var self = this;
		var openlink = document.createElement('a');
		var openimg = document.createElement('img');
		
		openimg.src = "images/btn_open_cols.jpg";
		openimg.alt = "Open";
		
		var id="_show_options_"+this.containerCell.cellIndex+"_"+this.containerCell.parentNode.rowIndex;

		var titlediv = this.containerCell.childNodes[0];
		titlediv.childNodes[0].id = "titlediv-"+Ext.id();
		if (!this.containerCell.combobox) {
			this.containerCell.combobox = this;
			this.containerCell.extensions = this.getAllValues();
			this.containerCell.openlink = openlink;
		}
		openlink.appendChild(openimg);
		openlink.onclick=function(){
			AnthemRotatingTable.prototype.openColumnButtonClicked(self.parentObj,this,titlediv);
			return false;
			};
		openlink.href="#"+id;
		openlink.style.position="absolute";

		openlink.style.left="110px";//(.7*size.width)+"px";
		openlink.style.top="25px";
	
		var mouseoverdiv = document.createElement('div');
		mouseoverdiv.id=id;	
		mouseoverdiv.style.display="none";
		mouseoverdiv.innerHTML=this.showAllOptionsText;//"Show all options";
		mouseoverdiv.className="optionShowMouseover";
		mouseoverdiv.style.position="absolute";
		mouseoverdiv.style.textAlign="center";
		mouseoverdiv.style.zIndex="450";
		mouseoverdiv.style.left="180px";
		mouseoverdiv.style.top="-25px";
		//this.radioToggle
		openlink.onmouseover=function(){self.parentObj.showHideDescriptionDivIfExists(this,true,null,90,-30);};
	
		openlink.onmouseout=function(){self.parentObj.showHideDescriptionDivIfExists(this);};
		Ext.getBody().dom.appendChild(mouseoverdiv);

		return openlink;
}
Sourceflow.form.RadioSelect.prototype.setupRadioPanel = function()
{
	var panelId = 'valuePanel-'+this.id;
	var radioId = 'radioId-'+this.id;
	var containerPanelId = 'containerPanel-'+this.id;
	var toggleId = 'radioToggle-'+this.id;
	var groupId = 'radioGroup-'+this.id;
	var closeId = 'closeGroup-'+this.id;
	//inner panel
	this.radioGroup = new Ext.Panel({
			id:groupId,
			name:groupId,
			border:false,
			cls:'x-combo-list-inner radioGroup',
			width:this.panelWidth,
			style:'margin-top:10px;margin-bottom:10px;'
			});
	
			
		var innerValuePanel = Ext.query("div.x-panel-body",this.valuePanel.getEl().dom);

			
/*	this.radioCloseButton = new Ext.Button({
		id:closeId,
		icon:'/common/ext-3.0.0/resources/images/default/form/clear-trigger.gif',
		tooltip:'Close',
		width:17,
		parentObject:this,
		iconCls:'close-icon-class',
		style:'margin-left:250px;',
		parentObject:this,
		handler:this.hideRadioGroup
		});
	this.radioGroup.add(this.radioCloseButton);*/
	
	if (this.useCheckboxes==false)
	{
		
		this.radioOptions = [];
		var lastChecked = null;
		var maxSize = 0;
		for(var i = 0;i < this.data.length; i++){
	        var o = this.data[i];
	       // var isChecked = Utilities.arrayContains(this.selectedValues,o[0]);
	      // alert(this.selectedValues);
	         var isChecked = this.selectedValues.length>0 && this.selectedValues[this.selectedValues.length-1]==o[0];
	        var text = o[1];
	        
	        
			var width = Utilities.getIntegerPixelValue(Utilities.getCurrentStyle(this.listParent.parentNode).width);
			if (isNaN(width)) width=this.panelWidth;
			var sze = Ext.util.TextMetrics.measure(this.listParent.parentNode,text,width-this.rightSpacing);

			if (this.containerCell) {
	
				//var containerWidth = Utilities.getIntegerPixelValue(Utilities.getCurrentStyle(this.containerCell).width);
				//alert(containerWidth+" "+this.rightSpacing);
				
				var szeincontainer = Ext.util.TextMetrics.measure(this.containerCell,text,this.cellWidth-this.rightSpacing);
				if (szeincontainer.height>maxSize) maxSize=szeincontainer.height;
			}
			//alert(this.id+" "+text+" "+sze.height+" "+maxSize);
			if (sze.height>maxSize) maxSize = sze.height;
	        var radio = new Ext.form.Radio({
	        	value:o[0],
	        	boxLabel: text,
	        	name:groupId,
	        	checked: false,
	        	radioSelect:this,
	        	style:'margin:0 10px;',
	        	labelStyle:'margin-right:40px',
	        	height:sze.height+12,
	        	width:this.panelWidth-this.rightSpacing,
	        	cls:'x-combo-list-item',
	        	valuePanel:this.valuePanel
	        	}
	        );
	       if (isChecked) lastChecked=radio;
	       radio.on("check",this.setValue)
	       this.radioOptions.push(radio);
	        this.radioGroup.add(radio);
	    }
	    if (lastChecked) lastChecked.checked = true;
		else if (!this.isSetup) {
			this.radioOptions[0].checked=true;
		}
		innerValuePanel.style=[];
		maxSize*=.8;
		innerValuePanel.style.height=maxSize+'px';
		
		if (maxSize<45) maxSize=45;
		this.containerPanel.setHeight(maxSize);
	}
	else
	{
		var maxSize = 0;
		this.checkboxItemsCounted=0;
		this.radioOptions = [];
		var lastval = null;
		for(var i = 0;i < this.data.length; i++){
	       var o = this.data[i];
	       // var isChecked = Utilities.arrayContains(this.selectedValues,o[0]);
	      // alert(this.selectedValues);
	         var isChecked = this.selectedValues.length>0 && this.selectedValues[this.selectedValues.length-1]==o[0];
	        var text = o[1];
	        
	        
			var width = Utilities.getIntegerPixelValue(Utilities.getCurrentStyle(this.listParent.parentNode).width);
			if (isNaN(width)) width=this.panelWidth;
				
			if (this.containerCell && (Ext.isSafari || Ext.isChrome)) {
	
				var containerWidth = Utilities.getIntegerPixelValue(Utilities.getCurrentStyle(this.containerCell).width);	
				var sze = Ext.util.TextMetrics.measure(this.containerCell,text,this.cellWidth-this.rightSpacing);
			//	if (szeincontainer.height>maxSize) maxSize=szeincontainer.height;
			}
			else {
				var sze = Ext.util.TextMetrics.measure(this.listParent.parentNode,text,width-this.rightSpacing);
		
			}
			//alert(this.id+" "+text+" "+sze.height+" "+maxSize);
			//alert("Val: "+text+" sic "+szeincontainer.height +" s.h "+ sze.height);
			var adjSize = (Ext.isSafari || Ext.isChrome) ? .6*sze.height : sze.height;
			var browserTopMargin = -3;
			//if (Ext.isGecko) 	browserTopMargin = -18;		
			if (sze.height>maxSize) maxSize = adjSize;
			
			var lbl = Ext.isIE7 ? 
				'<span style="display:block;width:245px; padding-left:15px; margin-top:'+browserTopMargin+'px;">'+text+'</span><span style="clear:both;font-size:1px;height:0;display:block;"></span>' :
				'<span style="display:block;width:245px;float:right; margin-left:5px; margin-top:'+browserTopMargin+'px;">'+text+'</span><span style="clear:both;font-size:1px;height:0;display:block;"></span>';
	        var radio = new Ext.form.Checkbox({
	        	value:o[0],
	        	text:text,
	        	sfType:'Ext.form.Checkbox',
	        	boxLabel: lbl,
	        	name:groupId,
	        	checked: isChecked,
	        	//style:'margin:0 10px; padding-right:10px; position:relative',
	        	autoHeight:true,
	        	//height:adjSize+20,
	        	cls:'x-combo-list-item',
	        	radioSelect:this,
	        	parentObject:this,
	        	valuePanel:this.valuePanel
	        	}
	         
	        );
	        if (isChecked) lastChecked=radio;
	       radio.on("check",this.setValue);
	       this.radioOptions.push(radio);
	        this.radioGroup.add(radio);
	    }
	    this.selectedValues=[lastval];
	    innerValuePanel.style=[];
	    //alert("Row: "+maxSize);
	    //
	    maxSize+=30;
	    //alert("Row after: "+maxSize);
		innerValuePanel.style.height=maxSize+'px';
		
		if (maxSize<45) maxSize=45;
		this.containerPanel.setHeight(maxSize);
	}
	
	var instructionDiv = document.createElement('div');
	instructionDiv.className = "nobordersinside radioselectinstructions";
	instructionDiv.innerHTML="<span>Select up to "+this.maxSelected+" options that you'd like to compare and click the button.</span>";
	instructionDiv.id = Ext.id();
	instructionDiv.style.padding="5px";
	instructionDiv.style.border="0";
	var openlink = this.containerCell.openlink;

	if (!openlink) openlink = this.createOpenLink();
	else if (openlink.parentNode) openlink.parentNode.removeChild(openlink);
	if (!openlink.id) openlink.id = Ext.id();
	var buttonDiv = document.createElement('div');
	buttonDiv.style.position='relative';
	buttonDiv.className = "nobordersinside";
	buttonDiv.style.height="30px";
	buttonDiv.id = Ext.id();
	buttonDiv.appendChild(openlink);
	openlink.style.top="0";
	openlink.style.left="180px";
	
	//alert(openlink.onmouseover);
	var self = this;
	this.radioToggle.href = '#'+openlink.id;
	this.radioToggle.parentObj = this.parentObj;
	var s = openlink.href.substring(openlink.href.indexOf("#")+1); 
	//var sp = Ext.get(s);
	this.radioToggle.getButton = function(){
		var a = Ext.query('.trigger-icon-class',this.getEl().dom)[0];
		return a;
	}
	//showHideDiv(showDiv,x,a,relativeTo, xMargin,yMargin)
	//
//self.showHideDescriptionDivIfExists(this,true,null,98,-40);
	this.radioToggle.on('mouseover',function() {
		self.parentObj.showHideDiv(true,s,this.getButton(),null, 98,-40);
	});
	this.radioToggle.on('mouseout',function() {
		self.parentObj.showHideDiv(false,s);
	});
	
	openlink.onmouseover=null;
	openlink.onmouseout=null;
	
	var showCheckboxText = this.useCheckboxes ? 'Switch to radios':'Switch to checkboxes';
	this.checkboxToggle = new Ext.Button({
		id:toggleId,
		text:showCheckboxText,
		style:'margin:10px;',
		handler:this.toggleCheckboxRadios,
		radioSelect:this,
		parentObject:this,
		hidden:this.allowMultiple
		});

	this.radioPanel = new Ext.Panel({
		id: radioId,
		cls:'radioPanel',
		hidden:true,
		shadow:!Ext.isIE6,
		shadowOffset:10,
		floating:!Ext.isIE6,
		style:'z-index:'+(this.zIndexBase+10)+';width:'+ this.panelWidth+'px;',
		items:[instructionDiv,this.radioGroup,this.checkboxToggle,buttonDiv]});

	this.radioToggle.radioPanel=this.radioPanel;

	this.radioPanel.render(Ext.getBody());
	
	if (this.valuePanel.getHeight()<maxSize) this.valuePanel.setHeight(maxSize);
	
	if (Ext.isIE6) {
		var rpd = this.radioPanel.getEl().dom;//setPagePosition(this.radioToggle.getPosition());
		rpd.style.position='absolute';
	}
	
	if (lastChecked) {
		lastChecked.getEl().dom.parentNode.className+=" x-combo-selected";//"x-combo-selected","");
	}
	if (!this.isSetup) {
		this.setValue(this.radioOptions[0]);

	}
	
	var inp = Ext.query("input",this.radioGroup.getEl().dom);
    inp.each(function(x){x.sfType='toggle';});

}