var AnthemRotatingTable = function(id, params) {
		//Ext.QuickTips.init();
		this.dailyTag="/day";
		this.monthlyTag="/mo.";
		this.tableId = id;
		this.htmltable =Ext.get(id);
		this.effectiveTableEdgePadding=0;
		this.sfType="AnthemRotatingTable";
		this.parentDiv = this.htmltable.parent("div");
		this.parentDiv.dom.style.width="850px";
		this.parentDiv.dom.style.position="relative";
		this.tableDom = this.htmltable.dom;
		
		var cells = this.getTableCells(this.getTableRows()[0]);
		if (cells.length==1) {
			this.tableDom.style.display='none'; //this means there are no columns
			Ext.get("divReset").dom.style.display='none';
			Ext.query("div.planContent")[0].style.display='none';
		}
		else {
		
			var  p = Ext.get("pTableInstructions");
			if (p) {
				p.dom.style.display="none";
			}
		
			this.titlePosition ="left";
			this.checkboxImage='images/cb_uc.jpg';
			this.recalcImage='images/btn_recalc.jpg';
			
			this.moreDescriptionText="Full description";
			if (params.moreDescriptionText) this.moreDescriptionText=params.moreDescriptionText;

			this.premiumTitleClassName="premiumTitle";
			this.customerTitleClassName="customerRowTitle";
			
			this.premiumViewRatesLinkText="Select plan options for each family member";
			if (params.premiumViewRatesLinkText) this.premiumViewRatesLinkText=params.premiumViewRatesLinkText;
			this.individualMemberRatesTitle="Individual Member Rates";
			if (params.individualMemberRatesTitle) this.individualMemberRatesTitle=params.individualMemberRatesTitle;
			
			this.individualMemberRatesText="Choose a plan for each family member by clicking the check boxes and then click \"recalculate\"";
			if (params.individualMemberRatesText) this.individualMemberRatesText=params.individualMemberRatesText;

			this.showAllOptionsText="View Options";
			if (params.showAllOptionsText) this.showAllOptionsText=params.showAllOptionsText;
			
			this.applyNowText='Apply Now';
			if (params.applyNowText) this.applyNowText=params.applyNowText;
			
			this.closeIndividualImage='images/btn_closeIndiv.jpg';
			this.grandTotalText="Select plans for the names above and click 'recalculate' for the total.";
			if (params.grandTotalText) this.grandTotalText=params.grandTotalText;

			this.grandTotalDisplayText="<i>(Total monthly premiums and grand total may reflect discounted rates.)</i>";
			if (params.grandTotalDisplayText) this.grandTotalDisplayText=params.grandTotalDisplayText;

			this.planTermMismatchMessage = "Not applicable.";
			if (params.planTermMismatchMessage) this.planTermMismatchMessage=params.planTermMismatchMessage;

			this.customerPriceMask ="---";
			this.recalculateText="Recalculate";
			if (params.recalculateText) this.recalculateText=params.recalculateText;

			this.columnHasBeenExpanded=0;
			this.closelinkMargin=20;
			this.tableMovementOffsetLeftCorrection=-100;
			this.customerBackgroundColor="#ECF6F7";
			this.popupDivs = [];
			this.changesArePending=false;
			this.customerCellsAreVisible = false;
			this.newCellWidth=216//this is the width of generated cells without padding w/4 = 156, w/3 = 216
			this.totalCellWidth=237 //this is the actual width of cells with padding w/4 = 177, w/3 = 236
			this.negativePlansPanelLeftMargin=0;
			this.noCustomerRateText="Not Available";
			if (params.noCustomerRateText) this.noCustomerRateText=params.noCustomerRateText;

			this.noRateText="No rate available";
			if (params.noRateText) this.noRateText=params.noRateText;
			
			this.individualRatesHeader='Individual';
			if (params.individualRatesHeader) this.individualRatesHeader=params.individualRatesHeader;
			
			this.minimumColumnNumber = 3;
			this.useAJAX = true;

			if (params.useAJAX!=undefined) {
				this.useAJAX = params.useAJAX;
			}
			
			var btns = Utilities.replaceButtons("table#rotatingtable tr#applyNowRow a",{text:this.applyNowText});
			if (Ext.isIE6) {
				var self = this;
				for (var x=0;x<btns.length;x++) {
					btns[x].on('mouseover',function(){self.refreshAllRadioSelects()});
					btns[x].on('mouseout',function(){self.refreshAllRadioSelects()});
				}
			}
			//if (Ext.isIE6) self.refreshAllRadioSelects();
			this.rateRequestIsVirtual = params.rateRequestIsVirtual || false;
			
			if (this.rateRequestIsVirtual===true) Ext.query('.divReset')[0].style.display='none';
			
			this.fixedCellWidth = 140;
			
			this.AJAXHandler = new AJAXHandler({});
			this.AJAXHandler.parentObj = this;
			
			this.checkboxSelectedImage='images/cb_uc_c.jpg';
			this._feedback = new Ext.Panel({
		        id:'feedback',
		        title:'Feedback:',
				width:200,
				height:1000,
				top:0,
				style:'position:absolute; top:0; left:0; width:200px; height:1000px; border:2px solid black;overflow:scroll;display:none'//display:none
		    });
		    
		    this.viewport={};
		    this.viewport.left = params.viewport.left || 0;
		    this.viewport.right = params.viewport.right || 5;
		    this.viewport.width = this.viewport.right - this.viewport.left;
			if (params.viewport) {
				this.leftmostVisibleIndex=params.viewport.left;
				this.rightmostVisibleIndex=params.viewport.right;
				this.viewportWidth = this.rightmostVisibleIndex - this.leftmostVisibleIndex;
			}
			if (params.titles) {
				this.titlePosition = params.titles.position;
				this.titleValues = params.titles.values;
			}
			else {
				this.titleCells=[];
				this.titleValues=[];
				var rows = this.getTableRows();
				
				
				
				for (var j=0;j<rows.length;j++) {
					var row = rows[j];
					var cells = row.getElementsByTagName('td');
					if (j===0) {
						for (var i=0;i<cells.length;i++) {
							this.overwriteHeaderCells(cells[i]);
						}
					}
					this.titleCells.push(cells[0]);
					this.titleValues.push(cells[0].innerHTML);
					row.deleteCell(0);
					
					
				}
				this.createTitleTable(this.titleCells);
			}
			
			if (params.checkboxImage) {
				this.checkboxImage=params.checkboxImage;
			}
			if (params.checkboxSelectedImage) {
				this.checkboxSelectedImage=params.checkboxSelectedImage;
			}
			if (params.moreDescriptionText) {
				this.moreDescriptionText=params.moreDescriptionText;
			}
			if (params.premiumTitleClassName) {
				this.premiumTitleClassName=params.premiumTitleClassName;
			}
			if (params.premiumViewRatesLinkText) {
				this.premiumViewRatesLinkText=params.premiumViewRatesLinkText;
			}
	
			if (params.buttons)	{	
				this.leftButtons=params.buttons.moveLeft;
				this.rightButtons=params.buttons.moveRight;
			}
			
			this.measuringRow=0;
			if (params.measuringRow) this.measuringRow = params.measuringRow;
			if (params.recalcImage) this.recalcImage = params.recalcImage;
			
			this.totalMoves=0;
			this.characterLimit = 100000;//60
			
			if (params.characterLimit) this.characterLimit = params.characterLimit;
			
			this.descriptionRows = [];
			if (params.descriptionRows) this.descriptionRows = params.descriptionRows;
			this.optionRows = [];
			if (params.optionRows) this.optionRows = params.optionRows;
			this.customerRows = [];
			if (params.customerRows) this.customerRows = params.customerRows;
			this.premiumRows = [];
			if (params.premiumRows) this.premiumRows = params.premiumRows;
			this.ignoreTheseRows=[];
			if (params.ignoreTheseRows) this.ignoreTheseRows = params.ignoreTheseRows;
			this.overbarRows=[];
			if (params.overbarRows) this.overbarRows = params.overbarRows;
			this.applyNowRows = [];
			if (params.applyNowRows) this.applyNowRows = params.applyNowRows;
			
			this.customerTriggerLinks=[];
			this.recalculateButtons=[];
			
			this.grandTotalRows = [];
			if (params.grandTotalRows) this.grandTotalRows = params.grandTotalRows;
			
			this.plans = [];
			if (params.plans) {
				this.plans = params.plans;
			}
			
			var tds = this.getTableCells(this.getTableRows()[0]);
			
			var minParentNodeWidthRequired = (tds.length*(this.totalCellWidth)+200);
			if (Utilities.trimPx(this.parentDiv.dom.style.width) < minParentNodeWidthRequired) {
				this.parentDiv.dom.style.width = minParentNodeWidthRequired+"px";
			}
	
			this.truncateDescriptionRows();
	
			
			
			if (Ext.isIE6) {
				Ext.get("wrapper").dom.style.overflow="visible";
			}
			
			this.registerOptionRows();
			this.registerPremiumCells();
			this.getTableSizing();	
			if (!Ext.isIE6) {this.setButtonEnabledStatus(true);}
			this.setupPlanInformation();
	
			
			
			if (this.parentDiv) {
				this.tableSizing.parentDivOriginalWidth = this.parentDiv.dom.style.width;
				this.parentDiv.dom.style.position="relative";
				this.parentDiv.dom.style.overflow="hidden";
	
				
				
				this.leftPadding = this.parentDiv.dom.style.paddingLeft;
				
				if (this.leftPadding.indexOf("px"!=-1))
				{
					this.leftPadding=this.leftPadding.substr(0,this.leftPadding.length-2);
				}
				this.leftPadding = parseInt(this.leftPadding);
				
				//var rightPanelLeft = (this.tableSizing.rightHiddenStartPosition+this.leftPadding);
				this.rightPanelLeftPosition = this.totalCellWidth*this.viewport.width+this.leftPadding-this.negativePlansPanelLeftMargin;
			//	if (this.rateRequestIsVirtual) this.rightPanelLeftPosition = this.fixedCellWidth*this.viewport.width+this.leftPadding-this.negativePlansPanelLeftMargin;
				
				
				//alert(this.tableSizing.cellWidth+" "+this.viewport.width+" "+this.leftPadding+" "+this.negativePlansPanelLeftMargin);
				var leftM = parseInt((this.parentDiv.dom.parentNode.offsetWidth-(this.rightPanelLeftPosition+this.leftPadding))/2);
				if (leftM>0) this.parentDiv.dom.style.marginLeft=leftM+"px";
				
	
				
				this.leftPanel=document.createElement('div');
				this.leftPanel.id="leftPanel";
				this.leftPanel.style.position="absolute";
				this.leftPanel.style.left="0px";
				this.leftPanel.style.top="0px";
				this.leftPanel.style.zIndex=this.htmltable.dom.style.zIndex+10;
				this.leftPanel.style.width=(this.tableSizing.leftHiddenWidth+this.leftPadding)+"px";
				this.leftPanel.style.height=this.tableSizing.totalHeight+"px";
				this.leftPanel.style.backgroundColor="#FFFFFF";
				this.parentDiv.dom.appendChild(this.leftPanel);
	
				this.parentDiv.dom.parentNode.style.width=(this.rightPanelLeftPosition+90)+"px";
	
				this.rightPanelExt = new Ext.Panel({id:'rightPanel',border:false,style:"position:absolute;top:-1px;left:"+(this.rightPanelLeftPosition)+"px;z-index:"+(this.htmltable.dom.style.zIndex+15)+";width:"+this.tableSizing.rightHiddenWidth+"px;height:"+(this.tableSizing.totalHeight+4)+"px;background-color:#FFFFFF; border:none"});
	//border-left:1px solid red;
				//alert(this.parentDiv.dom.parentNode);
				this.rightPanelExt.render(Ext.get(this.parentDiv.dom.parentNode));
				this.rightPanel = this.rightPanelExt.getEl();//.appendChild(this.rightPanel);
				
				var body = Ext.getBody().dom;
				
				var lbWidth = 19;
				for (var k=0;k<this.leftButtons.length;k++) {
					
					var lb = Ext.get(this.leftButtons[k]).dom;
					var lbMargin=(Utilities.trimPx(this.leftPanel.style.width)
						- lbWidth)+"px";
					lb.style.width=lbWidth+"px";
					lb.style.marginLeft=lbMargin;

					lb.parentNode.removeChild(lb);
					//this.parentDiv.dom.parentNode.appendChild(lb);
					this.leftPanel.appendChild(lb);
					lb.style.right="0px";
					lb.style.zIndex=100;
				}
				for (var k=0;k<this.rightButtons.length;k++) {
					
					var rb = Ext.get(this.rightButtons[k]).dom;
					rb.parentNode.removeChild(rb);
					this.parentDiv.dom.parentNode.appendChild(rb);
					rb.style.left=(this.rightPanelLeftPosition)+"px";
					rb.style.zIndex=100;
				}
				this.popupPanel=document.createElement('div');
				this.popupPanel.style.position="absolute";
				this.popupPanel.style.left="0px";
				this.popupPanel.style.top="0px";
				this.popupPanel.style.zIndex=50;
				for (var k=0;k<this.popupDivs.length;k++) {
					//this.popupPanel.appendChild(this.popupDivs[k]);
					Ext.getBody().dom.appendChild(this.popupDivs[k]);
				}
				this.parentDiv.dom.parentNode.appendChild(this.popupPanel);
			//	alert(this.rightPanel);
			
				if (this.titlePosition && this.titlePosition=='left')
				{
					this.createTitleTable();
				}

				this.hideCustomerRows();

				this.leftPanel.appendChild(this.titleTable);
				
				if (!Ext.isIE6) {this.setButtonEnabledStatus();}
			}
			
			//add extra columns if too small
			this.finishTable();
			this._feedback.render('wrapper');
		}
	}
	AnthemRotatingTable.prototype.finishTable = function()
	{
		var trs = this.getTableRows();
		var tds = this.getTableCells(trs[this.measuringRow]);
		var columnsNeeded = this.minimumColumnNumber-tds.length;
		this.effectiveTableEdgePadding = 0;
		if (columnsNeeded>0) {

			for (c=0;c<columnsNeeded;c++) {
				for (var j=0;j<trs.length;j++) {
					var tr = trs[j];
					var tds = this.getTableCells(tr);
					//var lastTd = tds[tds.length-1];
					var newTd = tr.insertCell(tds.length);
					if (j==0) {
						this.effectiveTableEdgePadding +=this.getTableCellSize(newTd).width;
						
					}
					//newTd.width=this.getTableCellSize(lastTd).width;
					newTd.innerHTML="&nbsp;";
					newTd.isFillerCell = true;
					//
					//for (var i=0;i<tds.length;i++) {
						
					//}
				}
			}
		}
		
		var titleRows = this.titleTable.rows;
		
		var totalPadding=0;
		for (c=0;c<titleRows.length;c++) {
			var tds = this.getTableCells(trs[c]);
			var ttds = this.getTableCells(titleRows[c]);
			var th = Ext.get(ttds[0]).getHeight();
			var exttd = Ext.get(tds[0]);
			var h = exttd.getHeight();
			if (h<th && c<titleRows.length-1) {
				if (Ext.isIE6) th++;
				else if (!Ext.isIE && !Ext.isGecko) {
					var padd = Utilities.getCurrentStylePadding(tds[0]);
					th-=Utilities.getIntegerPixelValue(padd.top)+Utilities.getIntegerPixelValue(padd.bottom)+1;
				}
				if (Ext.isGecko || Ext.isSafari || Ext.isChrome) {
					tds[0].style.display.height=th+"px";
					tds[0].height=th;
				}
				else {
					exttd.setHeight(th);
				}
			}
			totalPadding+=th-h;
		}
		//var bs = Utilities.replaceButtons("table#defaultPlanTable a.appNow",{text:this.applytNowText,saveOldButton:true});
		//alert(this.effectiveTableEdgePadding);
		if (Ext.isIE6 && totalPadding>0) {
			for (var j=0;j<this.rightButtons.length;j++) {
				var rb = Ext.get(this.rightButtons[j]).dom;
				var h = Utilities.getIntegerPixelValue(rb.style.height);
				h+=totalPadding;
				rb.style.height=h+"px";
			}
		}
		
		var loadmask = Ext.get("plantableloading");
		if (loadmask) loadmask.dom.parentNode.removeChild(loadmask.dom);
		if (Ext.isIE6) {
			this.tableDom.style.position = 'static';
			this.tableDom.style.left='0';
			this.tableDom.style.top='0';
			var overlap = this.tableOverlapsPanels();
			
			//this.setButtonEnabledStatus(true);
			for (var c=0;c<this.leftButtons.length;c++) {
				var b = Ext.get(this.leftButtons[c]).dom;
				b.style.display = overlap.left==false ? "none":"";
			}
			
			for (var c=0;c<this.rightButtons.length;c++) {
				var b = Ext.get(this.rightButtons[c]).dom;
				b.style.display = overlap.right==false ? "none":"";
			}
		}
		
		loadmask = Ext.get("ie6spacer");
		if (loadmask) loadmask.dom.parentNode.removeChild(loadmask.dom);
	}
	AnthemRotatingTable.prototype.reset = function()
	{

		var parent = this.tableDom.parentNode;
		parent.removeChild(this.tableDom);
		this.htmltable = null;
		alert('reset');
	}
	AnthemRotatingTable.prototype.setGrandTotal = function()
	{
	
		if (this.customersSelected && this.customersSelected.length>0)
		{
			var trs = this.getTableRows();
			var total =0;
			var dailyRatesExist = false;
			var monthlyRatesExist = false;
			for (var j=0;j<this.premiumRows.length;j++) {
				var tr = trs[this.premiumRows[j]];
				var tds = this.getTableCells(tr);
				for (var k=0;k<tds.length;k++) {
					var td = tds[k];
					var rate = td.innerHTML;
					var ind = rate.indexOf("$");
					if (ind!=-1) {
						rate = rate.substring(ind+1);
						var x = this.getPriceAndInterval(rate);
						if (x.interval==this.dailyTag) dailyRatesExist=true;
						else if (x.interval==this.monthlyTag) monthlyRatesExist=true;
						
						total+=parseFloat(x.rate);
						//alert(rate+" "+ind);
					}
				}
			}
			//this.customersSelected = null;
			
			var priceString = isNaN(total) ? total : "$"+total.toFixed(2)+" "+(dailyRatesExist ? this.dailyTag:this.monthlyTag);
			if (dailyRatesExist===true && monthlyRatesExist===true) priceString=this.planTermMismatchMessage;
			this.grandTotalContainer.innerHTML = 
			"<span style='font-weight:bold; font-size:16px; padding: 0 0; background-repeat:no-repeat; margin-right:25px;'>"
			+ priceString+"</span><span style='font-size:12px;'>"+this.grandTotalDisplayText+"</span>"; //background-image:url(images/leftArrow.jpg); 
		}
		
	}
	AnthemRotatingTable.prototype.clearGrandTotal = function()
	{
		if (this.grandTotalBox) {
		
		//	var size = Ext.util.TextMetrics.measure(this.grandTotalBox,this.grandTotalText);
			this.grandTotalContainer.innerHTML = this.grandTotalText;
			var height = Utilities.findSize(this.grandTotalContainer).height;
			this.grandTotalContainer.style.marginTop="-7px";
		}
	}
	AnthemRotatingTable.prototype.createGrandTotalBox = function()
	{
		if (this.rightPanel && this.leftPanel)
		{
			var leftPanelWidth = Utilities.findSize(this.leftPanel).width;
			var panelWidth = Utilities.findRelativePos(this.rightPanel.dom,this.leftPanel)[0]-leftPanelWidth;
			var trs = this.getTableRows();
			var tds = this.getTableCells(trs[this.grandTotalRows[0]]);
			var panelPos = Utilities.findRelativePos(tds[0],this.tableDom);

			var panelHeight =Utilities.findSize(tds[0]).height;

			this.grandTotalBox = document.createElement("div");
			var borderWidth = 2;
			this.grandTotalBox.id="divGrandTotal";
			this.grandTotalBox.style.width=(panelWidth-borderWidth)+"px";
			this.grandTotalBox.style.height=(panelHeight-borderWidth)+"px";
			this.grandTotalBox.style.position="absolute";
			this.grandTotalBox.style.left=(leftPanelWidth+borderWidth)+"px";
			this.grandTotalBox.style.top=(panelPos[1]+borderWidth-2)+"px";
			this.grandTotalBox.style.textAlign="left";
			this.grandTotalBox.style.marginLeft="25px";
			this.grandTotalBox.style.fontSize="14px";
			this.grandTotalBox.style.verticalAlign="middle";
			this.grandTotalBox.style.backgroundColor="#FFFFFF";
			
			var layerDiv = document.createElement("div");
			layerDiv.style.height = this.grandTotalBox.style.height;
			layerDiv.style.position="relative";
			this.grandTotalBox.appendChild(layerDiv);
			
			this.grandTotalContainer = document.createElement("div");
			this.grandTotalContainer.style.position="absolute";
			this.grandTotalContainer.style.width=(panelWidth-borderWidth)+"px";
			
			this.grandTotalContainer.style.top="50%";
			this.grandTotalContainer.style.left="0";
			layerDiv.appendChild(this.grandTotalContainer);
			
			this.clearGrandTotal();
			this.parentDiv.dom.appendChild(this.grandTotalBox);
		}
	}
	
	AnthemRotatingTable.prototype.overwriteHeaderCells = function(td)
	{
		if (!this.closeButtons) this.closeButtons={};
		if (!this.linksToClose) this.linksToClose={};
		
		var idNum=0;
		var key = "_btn_close_"+idNum
		while (this.closeButtons[key]) {
			idNum++;
			key = "_btn_close_"+idNum;
			
		}
		
		var fudgeFactor = Ext.isIE ? 2*(this.tableDom.border > 0 ? 1:0) : 0;

		var width = (this.getTableCellSize(td).width-fudgeFactor);
		var titlediv = document.createElement('div');
		var titlespan = document.createElement('span');
		var closelink = document.createElement('a');
		var closeimg = document.createElement('img');
		titlediv.style.position="relative";
		titlediv.style.width="100%";
		var images= [];
		images.push("images/btn_close_cols.jpg");
		var ip = new ImagePreloader(images,function(){closeimg.src = "images/btn_close_cols.jpg";});
		
		closeimg.alt = "Close";
		closeimg.style.display="none";
		var self = this;
		closelink.appendChild(closeimg);
		closelink.onclick=function(){return self.closeColumns(closelink);};
		closelink.href="#";
		closelink.style.position="absolute";

		closelink.style.left=(150)+"px";//(width+this.closelinkMargin)+"px";

		closelink.style.bottom="-5px";
		closelink.id="_btn_close_"+idNum;
		this.closeButtons[closelink.id]={};
		this.closeButtons[closelink.id].idNum=idNum;
		this.closeButtons[closelink.id].button=closelink;
		this.closeButtons[closelink.id].headerCell = td;
		if (td.innerHTML) titlespan.innerHTML = td.innerHTML;
		td.innerHTML="";

		titlediv.appendChild(titlespan);
		titlediv.appendChild(closelink);
		
		td.appendChild(titlediv);
		if (!td.id) td.id = Ext.id();
			
	}
	
	AnthemRotatingTable.prototype.createTitleTable = function(cells) {
			this.titleCreated=1;
			
			this.titleTable = document.createElement('table');
			this.titleTable.id='titleTable';
			if (this.tableSizing)
			{
				this.titleTable.cellPadding =this.tableSizing.cellPadding;
				this.titleTable.cellSpacing =this.tableSizing.cellSpacing;
				this.titleTable.border =this.tableSizing.border;
			}
			this.titleTable.style.cssFloat='right';
			this.titleTable.style.styleFloat='right';

			this.titleTable.style.zIndex=2;
			var trs2 = this.getTableRows();
			var classes=[];
			var ids=[];
			var fontsizes=[];
			var bgcs=[];
			for (var j=0;j<this.titleValues.length;j++)
			{
				var tr= this.titleTable.insertRow(j);
				if (cells) {
						var td = cells[j];
						ids.push(td.id);
						classes.push(td.className);
						if (td.id) var id = td.id; else id=null;
						if (td.style.fontSize) var fontSize = td.style.fontSize; else id=null;
						tr.appendChild(td);
						//this.addFeedback(j+" "+this.titleValues.length+" "+fontSize);
						if (id) {tr.childNodes[0].id = id;tr.childNodes[0].style.fontSize=fontSize;}
				} else {
			
					var tds2 = trs2[j].getElementsByTagName('td');

					if (this.tableSizing.rows[j])
					{
	
						var td = tr.insertCell(0);
						
						td.innerHTML=this.titleValues[j];
						var fudgeFactor = Ext.isIE ? 2*(this.tableDom.border > 0 ? 1:0)+1 : 0;
						
						var td2 = tds2[0];
						
						//alert(borders.top);
						if (td2.currentStyle) {
							var styleObj = td2.currentStyle; 
							//this.addFeedback(styleObj);
							fontsizes.push(styleObj['fontSize']);
							bgcs.push(styleObj['backgroundColor']);
							for (var i in td2.currentStyle) {
							//	td.style[i]=td2.currentStyle[i];
								//this.addFeedback(i+' '+styleObj[i]);
							}
						} else if (Ext.isGecko) {
							var styleObj = document.defaultView.getComputedStyle(td2, null); 
							//this.addFeedback(styleObj['backgroundColor']);
							fontsizes.push(styleObj['fontSize']);
							bgcs.push(styleObj['backgroundColor']);

							for (var i in styleObj) {
							//	td.style[i]=td2.currentStyle[i];
								//this.addFeedback(i+' '+styleObj[i]);
							}
						} else { //if (Ext.isSafari) 
							var styleObj = document.defaultView.getComputedStyle(td2, null); 
							fontsizes.push(styleObj['font-size']);
							bgcs.push(styleObj['background-color']);
							for (var i in styleObj) {
							//	td.style[i]=td2.currentStyle[i];
								//this.addFeedback(i+' '+styleObj[i]);
							}
							
							if ((styleObj['border-bottom-width'] &&  styleObj['border-bottom-width']!='0px')
								 || (styleObj['border-top-width'] &&  styleObj['border-top-width']!='0px')){
								fudgeFactor = (Utilities.trimPx(styleObj['border-bottom-width']) +Utilities.trimPx(styleObj['border-top-width']));
								//this.titleTable.style.marginTop='2px';
								//this.addFeedback(td.currentStyle);
								//td.currentStyle=td2.currentStyle;
							}
							
						} 
						/*	
						if (Utilities.arrayContains(this.premiumRows,j)==true) {
							td.className = this.premiumTitleClassName;
							td.innerHTML+="<br/>";
							var a = document.createElement('a');
							a.className = "lnkShowCustomers";
							a.tableObject=this;
							a.innerHTML=this.premiumViewRatesLinkText;
							a.onclick=function(){this.tableObject.showCustomerRows();return false;};
							a.href="#";
							a.style.display = this.customerRows.length>1 ? '':'none';
							var self = this;
							//var button = document.createElement('input');
							//button.type='image';
						//	button.tableObject=this;
							//button.src=this.recalcImage;
							//button.onclick=function(){self.recalculateButtonClicked(this);return false;};
							//button.style.display='none';
							
							
							var div = document.createElement('div');
							div.style.height="40%";
							td.appendChild(div);
							div.appendChild(a);
							//div.appendChild(button);
							this.customerTriggerLinks.push(a);
							
							
							 var btn = new Ext.Button({
					        	text:'Recalculate',
								//tooltip:'Recalculate',
					            scale:'custom',
					            cls:'btnRecalc',
					            tableObject:self,
					            renderTo:div,
					            handler:function(){self.recalculateButtonClicked(this);return false;}});
					        btn.getEl().dom.style.display='none';
					        this.recalculateButtons.push(btn);
						}
						else */
						if (Utilities.arrayContains(this.customerRows,j)==true) {
							td.className = this.customerTitleClassName;
						}
						var borders = Utilities.getCurrentStyleBorders(td2);
						var ff2=0;
						if (Ext.isIE) ff2 = borders.top.width+borders.bottom.width-2;
						ff2=ff2>0 ? ff2+1:ff2;
						//this.addFeedback("td diagnostic: "+this.tableSizing.rows[j][0].height+" "+fudgeFactor+" "+ff2);
						if (j==this.titleValues.length-1) ff2-=1;
						td.height=(this.tableSizing.rows[j][0].height-fudgeFactor-ff2);
						//td.style.padding='0';
						td.style.borderTop=borders.top.value;
						td.style.borderBottom=borders.bottom.value;
					
					}
				}
			}
			
			var trs = this.titleTable.getElementsByTagName('tr');
			for (var j=0;j<trs.length;j++)
			{
				
				var tr = trs[j];
				var thisid = ids[j];
				var thisclass = classes[j];
				var tds = tr.getElementsByTagName('td');
				if (fontsizes[j]) {
					//this.addFeedback(j+' '+fontsizes[j]);
					tds[0].style.fontSize=fontsizes[j];
				}
				tds[0].style.paddingRight="10px";
				
				if (bgcs[j]&& +this.ignoreTheseRows&&(Utilities.arrayContains(this.ignoreTheseRows,j)==false) && j>0) {
					 tds[0].style.backgroundColor=bgcs[j];
				}
				
				if (j==0) {
					//var planRecs = Ext.get('h2PlanRecs');
					//if (planRecs) {
					//	tds[0].innerHTML = planRecs.dom.innerHTML;
					//	planRecs.dom.style.display='none';
					//}
				}
				else if (j==1) tds[0].style.borderTop="1px solid white";
				else if (j==trs.length-1) {
					tr.className = "lastRow";
					tds[0].style.borderBottom="1px solid #E9ECFB";
				}
			}
			
			
	}
	AnthemRotatingTable.prototype.recalculateButtonClicked = function(button){
		var self = button.tableObject;
		
		if (self.useAJAX===true && (!self.rateRequestIsVirtual || self.rateRequestIsVirtual===false)) {
		
			self.setAllChanges(self,this.customerCellsAreVisible);
			
			var ajaxParams = {'optionChanges':self.optionChanges,'onFinish':self.setRateValues,'AJAXHandler':self.AJAXHandler}; 
			
			if (self.customerInfo) {
				ajaxParams.customerChanges = self.customerInfo;
			}
			self.AJAXHandler.handleRecalculateButtonClicked(self,ajaxParams);
			//TODO: get results for new rate requests
	
			self.hideRecalculateButton(self);
			
			//clear the queue
			self.optionChanges=[];
		}
	}
	AnthemRotatingTable.prototype.setAllChanges = function(obj,includeCustomerCells){
	
		var optionChanges=[];
		var trs = obj.getTableRows();
		var hRow = trs[0];
		var hCells = obj.getTableCells(hRow);
		var leftTableRows = this.titleTable.childNodes[0].childNodes;
		
		var oRows = [];
		var oRowIndices = [];

		var oCells = {};


		for (var j=0;j<obj.optionRows.length;j++)
		{
			if (Utilities.arrayContains(oRowIndices,obj.optionRows[j])==false) {
				oRowIndices.push(obj.optionRows[j]);
				var or = trs[obj.optionRows[j]];
				oRows.push(or);
				
				oCells[obj.optionRows[j]]=obj.getTableCells(or);
			}
		}
		
		
		if (this.customersSelected && this.customersSelected.length>0)
		{
			var columnsSelected = {};
			for (var j=0;j<obj.customersSelected.length;j++)
			{	
				var selection = obj.customersSelected[j];
				var cell = Ext.getDom(selection.id);
				if (cell)
				{
					if (!columnsSelected[cell.cellIndex]) columnsSelected[cell.cellIndex]=[];
					
					columnsSelected[cell.cellIndex].push(selection);
				}
			}
			
			for (var j=0;j<obj.premiumRows.length;j++)
			{
				var pRow = trs[obj.premiumRows[j]];
				
				var pCells = obj.getTableCells(pRow);
				for (var k in columnsSelected)
				{
					//k is the column index of a selected customer
					var pc = pCells[k];
					if (!pc.id) pc.id = Ext.id();
					var columnId = pc.id;
					var hIndex = obj.getEquivalentHeaderIndex(hRow,pc.cellIndex);
					var hc = hCells[hIndex];
					
					var change = obj.getChangeForPremiumCell(obj,hc,pc,oCells,oRowIndices,columnsSelected,true);
					change.restrictToCustomersListed = true;
					if (change) optionChanges.push(change);
			 	}
			}
		}
		else {

			var mRow = trs[obj.measuringRow];
			var pRows = [];
			
			
			
			if (includeCustomerCells)
			{
				var allCustomerCells = [];
				for (var j=0;j<obj.customerRows.length;j++) {
					var cCells = obj.getTableCells(trs[obj.customerRows[j]]);
					for (var k=0;k<cCells.length;k++)
					{
						var cc = cCells[k];
						if (j==0) var columnArr = [];
						else var columnArr = allCustomerCells[k];
	
						if (!cc.customerName) {
							var customerRowIndex = obj.customerRows[j];
							var customerNameRow = leftTableRows[customerRowIndex]; 
							var leftCells = this.getTableCells(customerNameRow);
							var customerName = leftCells[0].innerHTML;
							cc.customerName = customerName;
						}
						
						var cellObj = {'id':cc.id,'customerName':cc.customerName};
						columnArr.push(cellObj);
						allCustomerCells.push(columnArr);
					}
				}
			}
	
			for (var j=0;j<obj.premiumRows.length;j++)
			{
				var pRow = trs[obj.premiumRows[j]];
				
				var pCells = obj.getTableCells(pRow);
				for (var k=0;k<pCells.length;k++)
				{
					var pc = pCells[k];
					var hIndex = obj.getEquivalentHeaderIndex(hRow,pc.cellIndex);
					var hc = hCells[hIndex];
		
					var change = obj.getChangeForPremiumCell(obj,hc,pc,oCells,oRowIndices,allCustomerCells,includeCustomerCells);
					if (change) optionChanges.push(change);
				}
			}
			
		}
		//alert(Ext.util.JSON.encode(optionChanges));
		obj.optionChanges = optionChanges;
			//alert(optionChanges);
			//change contains: plan db id, plan external id, premium cell id, option key, option value 
			//var change = this.getChangeObject(radioSelect.plan.planId,
				//externalId,premiumCell.id,key,radioSelect.selectedValues[0]);
	}
	AnthemRotatingTable.prototype.getChangeForPremiumCell = function(obj,hc,pc,oCells,oRowIndices,allCustomerCells,includeCustomerCells){
							
		if (!pc.id) pc.id = Ext.id();
		var columnId = pc.id;
		var k=pc.cellIndex;
		
		if (hc.plan)
		{
			var planId = hc.plan.planId;
			var externalId = hc.plan.externalId;
			var options=[];
			
			for (var l=0;l<oRowIndices.length;l++)
			{
				if (oCells[oRowIndices[l]] && oCells[oRowIndices[l]][k])
				{
					var oc = oCells[oRowIndices[l]][k];
					var optionSet = false;
					if (oc.combobox && oc.combobox.isVisible===true) {
						var el = oc.combobox.listParent;
						var xkey = obj.getExternalIdAndOptionKeyFromSelect(oc.combobox.transform);
						
						if (!el.style || el.style.display=='') {

							option={};
							option.key=xkey.optionKey;
							option.value = oc.combobox.getKeyFromTextValue();
							options.push(option);
							optionSet = true;
						}
						
					}
					
					if (optionSet===false && oc.optionKey&& oc.optionValue) {
						option={};
						option.key= oc.optionKey;
						option.value =  oc.optionValue;
						options.push(option);
						optionSet = true;
					}

				}
			}
			
			var columnCustomerCells = includeCustomerCells && includeCustomerCells==true ? allCustomerCells[k] : null;	
			var change = this.getChangeObject(planId,externalId,columnId,options,columnCustomerCells,includeCustomerCells);
			return change;
		}
		
		return null;
	}
	
	AnthemRotatingTable.prototype.setPrices = function(obj){

		var referenceCell = null;
		var columnsToRates = {};
		var cashValues = {};
		var columnsToErrors = {};
		for (var j=0;j<obj.rates.length;j++)
		{
			rateObj = obj.rates[j];
			if (j==0) referenceCell = Ext.get(rateObj.column).dom;
			var newRate = rateObj.rate;

			if (newRate && !isNaN(newRate)) {
				//cell.cashValue = newRate;
				//cell.innerHTML="$"+newRate.toFixed(2);
				columnsToRates[rateObj.column] = "$"+newRate.toFixed(2);
				cashValues[rateObj.column] = newRate;
			}
			else if (rateObj.errors) {
				var err="<div style='position:relative'><div style='font-size:11px; position:absolute;top:0; left:50%; width:100px; margin-left:-50px;'>Rate no longer available.</div></div>&nbsp;";

				//for (var k=0;k<rateObj.errors.length;k++) {
				//	err+="<li>"+rateObj.errors[k]+"</li>";
				//}
				//err+="</ul>";
				columnsToErrors[rateObj.column] = err;
			}

		}
		
		if (referenceCell)
		{
			var row = referenceCell.parentNode;
			var premiumCells = row.childNodes;
			for (var j=0;j<premiumCells.length;j++)
			{
				var pId = premiumCells[j].id;
				if (!premiumCells[j].style) premiumCells[j].style=[];
				
				if (!pId || pId=='' || !columnsToRates[pId])
				{
					
					if (columnsToErrors[pId])
					{
						var value = columnsToErrors[pId];
						premiumCells[j].style.paddingBottom = "38px";
					} else {
						var value = "$"+Utilities.getMoneyUnformatted(premiumCells[j].cashValue);
						premiumCells[j].style.paddingBottom="";
					}
				} else  {
				//this one works
					premiumCells[j].style.paddingBottom="";
					var value = Utilities.getMoneyUnformatted(columnsToRates[pId]);
					premiumCells[j].cashValue = cashValues[pId];
				}
				premiumCells[j].innerHTML = value;
			}

		}

	}
	AnthemRotatingTable.prototype.addFeedback = function(info){
		this._feedback.setTitle(this._feedback.title + "<br/>"+info);
	}
	AnthemRotatingTable.prototype.hideCustomerRows = function()
	{
		this.customerCellsAreVisible=false;
		this.hideHybridRows(this.customerRows);
		this.hideHybridRows(this.overbarRows);
		this.hideHybridRows(this.grandTotalRows);
		if (this.grandTotalBox) this.grandTotalBox.style.display='none';
		if (Ext.isIE6)
		{
			if (this.rightButtons)
			{
				for (var j=0;j<this.rightButtons.length;j++)
				{
	
						var buttonDom = Ext.get(this.rightButtons[j]).dom;

						buttonDom.style.height=this.getTableCellSize(this.tableDom).height;	

				}
				
			}
			if (this.leftButtons)
			{
				for (var j=0;j<this.leftButtons.length;j++)
				{
	
						var buttonDom = Ext.get(this.leftButtons[j]).dom;
						buttonDom.style.height=this.getTableCellSize(this.tableDom).height;	
						
				}
				
			}

		}
	}
	AnthemRotatingTable.prototype.hideHybridRows = function(hiddenArray)
	{
		var tableRows = this.getTableRows();
		var titleRows = this.titleTable.rows;
		for (var j=0;j<hiddenArray.length;j++)
		{
			var index = hiddenArray[j];
			var tr = tableRows[index];
			var titleTR = titleRows[index];

			tr.style.display="none";
			titleTR.style.display="none";

		}
	}
	AnthemRotatingTable.prototype.truncateDescriptionRows = function()
	{
		var tableRows = this.getTableRows();
		
		for (var j=0;j<this.descriptionRows.length;j++)
		{
			var index = this.descriptionRows[j];
			var tr = tableRows[index];
			var tds = this.getTableCells(tr);
			
			var lastRow = tableRows[tableRows.length-1];
			var lastRowTds = this.getTableCells(lastRow);
			
			var htrs = tableRows[0];
			var headerRowTds = this.getTableCells(htrs);
			
			var tablepos = Utilities.findPos(this.tableDom);
			var self = this;
			for (var i=0;i<tds.length;i++)
			{
				var td = tds[i];
				var lastRowTd = lastRowTds[i];
				var htd = headerRowTds[i];
				var title = Ext.query("div span",htd)[0].innerHTML;
				if (td.innerHTML.length > this.characterLimit ) {//&& this.rateRequestIsVirtual===false
					var fullDescriptionText = td.innerHTML;
					var descriptionText = td.innerHTML.substring(0,this.characterLimit);
					
					while (descriptionText!='' && descriptionText.substring(descriptionText.length-1,descriptionText.length)!=" ") {
						descriptionText = descriptionText.substring(0,descriptionText.length-1);	
					}
					td.innerHTML = descriptionText+" ... ";
					var span = document.createElement('span');
					span.className = "spanDescriptionHover";
					span.style.position="relative";
					span.style.display="block";

					if (i==0) {
						var tdExt = Ext.get(td);
						var tdh = tdExt.getHeight();
						tdh=parseInt(tdh/2);
					}
					var h = tdh - Ext.util.TextMetrics.measure(td,td.innerHTML,this.newCellWidth).height;

					span.style.height="10px";
					var pT = (h-(Ext.isIE ? 140 : 70));
					if (pT<0) pT=0;
					span.style.paddingTop=pT+"px";
					var id = "_mouseover_description_div_"+i;
					
					var a = document.createElement('a');
					a.innerHTML=this.moreDescriptionText;
					a.href="#"+id;
					a.onclick=function(){return false;};
					td.appendChild(span);
					span.appendChild(a);
					a.id = "_descriptionDiv_"+Ext.id();
					a.className = "aDescriptionHover";
				/*	Ext.QuickTips.register({
					    target: a.id,
					    title:title,
					    cls:'descriptionPopup',
					    text: fullDescriptionText,
					    width: 255,
					    shadowOffset: 8,
					    dismissDelay: 0
					});*/

					var pos = Utilities.findPos(a);

					var div = document.createElement('div');
					div.id=id;
					
					var ff=Ext.isGecko ? 45:0;
					
					div.style.position="absolute";					
					div.style.top=(pos[1]-tablepos[1]-35+ff)+"px";
					div.style.left=(pos[0]-tablepos[0]+290)+"px";
					div.style.display="none";
					div.style.zIndex="50";
					div.className="outerPopup";
					lastRowTd.appendChild(div);
					this.popupDivs.push(div);
					
					var topDiv = document.createElement('div');
					topDiv.style.position="relative";			
					topDiv.className="topDiv";
					topDiv.width="100%";
					
					var titlediv = document.createElement('div');
					var descriptionDiv = document.createElement('div');
					descriptionDiv.innerHTML=fullDescriptionText;
					var bottomDiv = document.createElement('div');
					titlediv.style.margin="15px";
					titlediv.style.marginRight="20px";
					titlediv.innerHTML=title;
					titlediv.className="title";
					
					descriptionDiv.style.margin="15px";
					descriptionDiv.style.marginRight="20px";
					descriptionDiv.style.marginTop="0";
					descriptionDiv.className="description";
					
					div.appendChild(topDiv);
					div.appendChild(titlediv);
					div.appendChild(descriptionDiv);
					div.appendChild(bottomDiv);
					
					
					bottomDiv.marginTop="20px";
					bottomDiv.style.position="relative";			
					bottomDiv.className="bottomDiv";
					bottomDiv.width="100%";
					
					var shadowDiv = document.createElement('div');
					bottomDiv.appendChild(shadowDiv);
					
					shadowDiv.style.position="absolute";		
					shadowDiv.className="shadow";
					
					var topBGDiv = document.createElement('div');
					topDiv.appendChild(topBGDiv);
					
					topBGDiv.style.position="absolute";		
					topBGDiv.className="topBG";
					
					var ffmo = Ext.isChrome ? 40:0;
					
					a.onmouseover=function(){self.showHideDescriptionDivIfExists(this,true,null,this.tableMovementOffsetLeftCorrection-40,ffmo);};
					a.onmouseout=function(){self.showHideDescriptionDivIfExists(this);};
					
					htd.descriptionMouseoverDiv = div;
				}
				else if (td.innerHTML.length==0) td.innerHTML="&nbsp;";
			}
		}
	}
	AnthemRotatingTable.prototype.registerPremiumCells = function()
	{
		var tableRows = this.getTableRows();
		for (var j=0;j<this.premiumRows.length;j++)
		{
			var index = this.premiumRows[j];
			var tr = tableRows[index];
			var tds = this.getTableCells(tr);
			for (var i=0;i<tds.length;i++)
			{
				tds[i].isPremiumRow = true;
			}
		}
	}
	
	
	AnthemRotatingTable.prototype.registerOptionRows = function()
	{
		var tableRows = this.getTableRows();
		for (var j=0;j<this.optionRows.length;j++)
		{
			var index = this.optionRows[j];
			var tr = tableRows[index];
			var tds = this.getTableCells(tr);
			if (!this.radioSelects) this.radioSelects = {};
			var len = tds.length;
			for (var q=0;q<len;q++)
			{
				var td = tds[q];

				var selectLists = Ext.query("select",td);
				
				if (selectLists && selectLists[0])
				{
					this.showInstructionParagraph();
					var selectList = selectLists[0];
					td.optionKey = this.getExternalIdAndOptionKeyFromSelect(selectList.id).optionKey;
					var selectItems = selectList.options;//getElementsByTagName("option");
					var tmp = "";
					for (var x in selectList) tmp+=x+" ";
					
					td.extensions=[];
					for (var k=0;k<selectItems.length;k++)
					{		
						td.extensions.push({text:selectItems[k].text,value:selectItems[k].value});
					}
					
					var xtds = Ext.query("td",tr);
					this.addOptionButton(td,selectLists[0]);
					if (!selectList.id) selectList.id = Ext.id();
					this.radioSelects[selectList.id]=this.selectToCombo(selectList, td,8);
					var res = "";
					td.combobox.plan=this.plans[q];
					
				}

			}
		}
		//alert(Utilities.findKeys(this.radioSelects));
		
	}
	AnthemRotatingTable.prototype.showInstructionParagraph = function() {
		if (!this.paragraphShown) {
			this.paragraphShow=true;
			var  p = Ext.get("pTableInstructions");
			if (p) {
				p.dom.style.display="none";
			}
		}
	}
	
	AnthemRotatingTable.prototype.selectToCombo = function(selectList, container, zindex)
	{
			if (Ext.isChrome) selectList = Ext.getDom(selectList);
			var val;
			if (typeof selectList=="string" && !Ext.isChrome)
			{
				selectedId = selectList;
				var s = Ext.get(selectedId);
				var selectedIndex=-1;
				for (var j=0;j<s.dom.options.length;j++) {
					var opt = s.dom.options[j];

					if (s.dom.options[j].selected) selectedIndex=j;
				}
				if (Ext.isIE6 && selectedIndex!=0) {
					s.dom.options[selectedIndex].selected=false;
					selectedIndex++;	
					s.dom.options[selectedIndex].selected=true;

				}
				container.selectedIndex = selectedIndex;
				val = s.dom.options[selectedIndex].text;
			}
			else {
				selectedId = selectList.id;
				container.selectList = selectList;

				if (selectList.options.length==0) selectList = Ext.getDom(selectList.id);

				var selectedIndex=-1;
				for (var j=0;j<selectList.options.length;j++) {
					var opt = selectList.options[j];
					if (selectList.options[j].selected) selectedIndex=j;
				}
				container.selectedIndex = selectedIndex;
				
			}
			var parentObj = this;
			var converted = new Sourceflow.form.RadioSelect({
					transform:selectedId,
					zIndexBase:zindex,
					containerCell:container,
					panelWidth:300,
					cellWidth: 130,
					maxSelected:3,
					parentObj: this,
					useCheckboxes:true//,
					//onOptionsChanged: parentObj.optionChanged
				});
			//alert(Utilities.findKeys(val));
			if ((Ext.isSafari || Ext.isChrome) && (typeof selectList=="string")) {
					//converted.setValue(val);
			}
			container.combobox = converted;
			return converted;
		
	}
	AnthemRotatingTable.prototype.optionChanged = function(parentObj)
	{
		if (!parentObj) parentObj = this.parentObj;
		//parentObj.addPlanChange(parentObj, this);
		parentObj.hidePrices("Recalculate");
		parentObj.hideCustomerPrices();
		
		
		//option 1: add change, show recalc button

		//parentObj.showRecalculateButton();
		
		//option 2: do recalc
		if (!parentObj.rateRequestIsVirtual || parentObj.rateRequestIsVirtual===false) {
			parentObj.setAllChanges(parentObj,parentObj.customerCellsAreVisible);
			
			var ajaxParams = {'optionChanges':parentObj.optionChanges,
				'onFinish':parentObj.setRateValues,
				'AJAXHandler':parentObj.AJAXHandler}; 
			
			if (parentObj.customerInfo) {
				ajaxParams.customerChanges = parentObj.customerInfo;
			}
			
			parentObj.AJAXHandler.handleRecalculateButtonClicked(
				parentObj, ajaxParams
				);
		}
	}
	AnthemRotatingTable.prototype.addPlanChange = function(parentObj, radioSelect)
	{
		if (!parentObj.optionChanges) parentObj.optionChanges=[];

		//external id is recorded in select list id
		var transformId = radioSelect.transform;
		var bracketInd =transformId.indexOf("[");
		var externalId = transformId.substring(0,bracketInd);
		
		//string key is as well
		var key = transformId.substring(bracketInd+1,transformId.indexOf("]"));

		//column id is the id of the column's premium cell
		var columnIndex = radioSelect.containerCell.cellIndex;
		var trs = parentObj.getTableRows();
		var premiumRow = trs[trs.length-1];
		var premiumCell = parentObj.getTableCells(premiumRow)[columnIndex];
		
		if (!premiumCell.id) premiumCell.id = Ext.id();

		var options = [];
		var option = {};
		option.key=key;
		option.value=radioSelect.selectedValues[0];
		options.push(option);
		//change contains: plan db id, plan external id, premium cell id, option key, option value 
		var change = this.getChangeObject(radioSelect.plan.planId,
			externalId,premiumCell.id,options);
		parentObj.optionChanges.push(change);
		
	}
	AnthemRotatingTable.prototype.getExternalIdAndOptionKeyFromSelect = function(transformId)
	{
		var bracketInd =transformId.indexOf("[");
		var externalId = transformId.substring(0,bracketInd);
		
		//string key is as well
		var key = transformId.substring(bracketInd+1,transformId.indexOf("]"));
		return {"externalId":externalId,"optionKey":key};
	}
	AnthemRotatingTable.prototype.getChangeObject = function(planId,
		externalId,columnId,options,customers,getIndividualRates)
	{
		var change = {};
		change.planId = planId;
		change.externalId = externalId;
		change.url=location.href;
		change.columnId = columnId;

		if (options && options.length>0) change.options=options;
		if (customers && customers.length>0) change.customers=customers;
		
		change.getIndividualRates = getIndividualRates && getIndividualRates==true;
		
		return change;
	}
	AnthemRotatingTable.prototype.setupPlanInformation = function()
	{
		var self = this;
		var tableRows = this.getTableRows();
		var titleTds = this.getTableCells(tableRows[0]);
		
		for (var j=0;j<titleTds.length;j++)
		{
			titleTds[j].plan = this.plans[j];
		}
		var leftTableRows = this.titleTable.childNodes[0].childNodes;
		for (var j=0;j<this.customerRows.length;j++)
		{
			var customerRowIndex = this.customerRows[j];
			var customerRow = tableRows[customerRowIndex];
			var customerCells = this.getTableCells(customerRow);
			var customerNameRow = leftTableRows[customerRowIndex]; 
			var leftCells = this.getTableCells(customerNameRow);
			var customerName = leftCells[0].innerHTML;
			for (var i=0;i<customerCells.length;i++)
			{
				
				if (this.plans[i].customerPremiums)
				{
					var val = this.plans[i].customerPremiums[customerRowIndex];
					
				}
				else val=customerCells[i].innerHTML;

				customerCells[i].innerHTML="&nbsp;";
				var cbDiv = document.createElement('div');
				cbDiv.style.position='relative';
				cbDiv.style.width="120px";
				
				var cbImg = document.createElement('img');
				
				cbImg.src = this.checkboxImage;
				cbImg.style.position='absolute';
				cbImg.style.left='10px';		
				cbImg.style.top='-15px';	
				
				if (Ext.isIE6) cbImg.style.display='none';
				
				var valSpan = document.createElement('span');
				valSpan.style.display="block";
				valSpan.style.padding="0";
				valSpan.style.width="80px";
				valSpan.style.height="0";
				valSpan.style.textAlign="right";
				valSpan.style.position='absolute';
				valSpan.style.left='30%';	
				valSpan.style.top='-15px';	
				valSpan.className = 'valspan-customercell';
				var premium = parseFloat(val);
				
				valSpan.innerHTML = this.makePrice(val);
				cbDiv.appendChild(cbImg);
				cbDiv.appendChild(valSpan);
				
				if (!customerCells[i].id) customerCells[i].id=Ext.id();
				customerCells[i].valSpan=valSpan;
				customerCells[i].appendChild(cbDiv);
				customerCells[i].style.verticalAlign='top';
				customerCells[i].customerName=customerName;
				customerCells[i].planId = this.plans[i].planId;
				customerCells[i].premium = premium
				customerCells[i].onclick = function(){self.customerCellClicked(this)};
			}
		}
	}
	AnthemRotatingTable.prototype.makePrice = function(val) {
		var x = this.getPriceAndInterval(val);
		var suffix = x.interval;
		val = x.rate;
		if (isNaN(val) && isNaN(val.toString().replace(",",""))) return val;
		val = val.toString();
		if (val.indexOf('.')==val.length-2) val+='0';
		else if (val.indexOf('.')==-1) val+='.00';
		if (val.indexOf('$')==-1) val = '$'+val;
		return val+suffix;
	}
	
	AnthemRotatingTable.prototype.getPriceAndInterval = function(val) {
		val=val+'';
		if (!val || !val.indexOf) return  {'rate':val,'interval':''};
		var suffix = "";
		var dyInd = val.indexOf(this.dailyTag);
		var mnInd = val.indexOf(this.monthlyTag)
		if (dyInd>0) {
			suffix = this.dailyTag;
			val = val.substring(0,dyInd).trim();
		}
		else if (mnInd>0) {
			suffix = this.monthlyTag;
			val = val.substring(0,mnInd).trim();
		}
		return {'rate':val,'interval':suffix};
	}
	
	AnthemRotatingTable.prototype.customerCellClicked = function(cell)
	{
		if (!cell.errors && cell.valSpan.innerHTML!=this.customerPriceMask
			&& cell.valSpan.innerHTML!=this.noCustomerRateText)
		{
			this.hidePrices(this.recalculateText);
			this.clearGrandTotal();
			this.showRecalculateButton();
			if (!this.customersSelected) this.customersSelected=[];
			if (!this.customerPlansSelected) this.customerPlansSelected=[];
			
			var row = cell.parentNode;
			var tds = this.getTableCells(row);
			
			var selectedImages=this.findToggleImages(cell,this.checkboxSelectedImage);
			if (selectedImages.length>0) {
				var currentlySelected= Utilities.endsWith(selectedImages[0].src,this.checkboxSelectedImage);
			}
			for (var j=0;j<tds.length;j++)
			{
				tds[j].style.backgroundColor=this.customerBackgroundColor;			
				this.setCellImage(tds[j],this.checkboxImage,this.checkboxSelectedImage);
				tds[j].selected=false;
				
				for (var k=0;k<this.customersSelected.length;k++) {
					if (this.customersSelected[k].id==tds[j].id) this.customersSelected.splice(k,1);
				}
			}
			
			
			if (selectedImages.length>0) {
				if (currentlySelected==false) {
					this.setCellImage(cell,this.checkboxSelectedImage,this.checkboxImage);
					cell.style.backgroundColor="#FFF7D3";
					cell.selected=true;
					var cellObj = {'id':cell.id,'customerName':cell.customerName};
					this.customersSelected.push(cellObj);
				} else {
					this.setCellImage(cell,this.checkboxImage,this.checkboxImage);
				}
				
			} 
		}

	}
	AnthemRotatingTable.prototype.findRelevantNode = function(cell)
	{
		var nodes = cell.childNodes;
		if (nodes.length>1)
		{
			for (var c=0;c<nodes.length;c++) {
				
				if (nodes[c].childNodes && nodes[c].childNodes.length>1) return c;
			}
		}
		return 0;
	}
	AnthemRotatingTable.prototype.setCellImage = function(cell,img,imgToReplace)
	{
		var imgs=this.findToggleImages(cell,imgToReplace);
		for (var k=0;k<imgs.length;k++) {
			if (imgs[k].src.indexOf(imgToReplace)>0) imgs[k].src = img;

		}
	}
	AnthemRotatingTable.prototype.findToggleImages = function(node,imgToReplace)
	{
		var xx= Ext.query("img",node);
		var result=[];
		for (var k=0;k<xx.length;k++) {
			result.push(xx[k]);

		}
		return result;
	}
	AnthemRotatingTable.prototype.getHeaderCell = function(cell)
	{
		var trs = this.getTableRows();
		var cellHeaderIndex = this.getEquivalentHeaderIndex(trs[0], cell.cellIndex);

		var headerCell = trs[0].getElementsByTagName('td')[cellHeaderIndex];
		return headerCell;
	}
	AnthemRotatingTable.prototype.openColumnButtonClicked = function(self,a,titlediv)
	{
		var cell = Utilities.findNearestParentWithTag(titlediv,"td");
		var radioSelect = cell.combobox;
		cell.extensions =radioSelect.getSelectedValues();
		if (cell.extensions.length>1) self.openingButton=this;
		var trs = self.getTableRows();
		for (var i=0;i<self.customerRows.length;i++)
		{
			var tr = trs[self.customerRows[i]];
			var tds = self.getTableCells(tr);
			for (var j=0;j<tds.length;j++)
			{
				tds[j].style.backgroundColor=self.customerBackgroundColor;		
				self.setCellImage(tds[j],self.checkboxImage,self.checkboxSelectedImage);
				tds[j].selected=false;

			}
		}
		self.customersSelected=[];
		self.hideCustomerPrices();
		self.showHideDescriptionDivIfExists(a); 
		self.clearGrandTotal();
		
		if (cell.extensions.length>0) {
			if (titlediv.parentNode.extensions.length==1)
			{
				var valuePanel = radioSelect.valuePanel;
				valuePanel.getEl().dom.childNodes[0].childNodes[0].innerHTML=cell.extensions[0].text;
				self.optionChanged(self);
			}
			else {
				self.addColumn(titlediv);

				radioSelect.resetToValue(cell.temporarySpan.innerHTML);
			}
		}
		return false;
	}
	AnthemRotatingTable.prototype.addOptionButton = function(td,selectList)
	{
		var self = this;
		var titlediv = document.createElement('div');
		var titlespan = document.createElement('span');
		var openlink = document.createElement('a');
		var openimg = document.createElement('img');
		var self = this;
		
		var tr=td.parentNode;
		
		titlediv.id="titlediv-"+Ext.id();
		
		titlediv.style.position="relative";
		
		openimg.src = "images/btn_open_cols.jpg";
		openimg.alt = "Open";
		
		var id="_show_options_"+td.cellIndex+"_"+tr.rowIndex;
		openlink.rel=selectList.id;
		openlink.appendChild(openimg);
		openlink.onclick=function(){
			AnthemRotatingTable.prototype.openColumnButtonClicked(self,this,titlediv);
			return false;
			};
		openlink.href="#"+id;
		openlink.style.position="absolute";
		
		var size = this.getTableCellSize(td);
		
		openlink.style.left="110px";//(.7*size.width)+"px";
		openlink.style.top="25px";

		titlespan.innerHTML = td.innerHTML;
		td.innerHTML="";
		
		titlediv.appendChild(titlespan);
		titlediv.appendChild(openlink);
		
		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.zIndex="450";
		mouseoverdiv.style.left="180px";
		mouseoverdiv.style.top="-25px";
		openlink.onmouseover=function(){self.showHideDescriptionDivIfExists(this,true,null,98,-40);};
			//new Effect.Pulsate(this.rel,{pulses:3,duration:1.0,from:0.3,afterFinish:function(q){Utilities.setOpacity(q.element,10);}});
			
		openlink.onmouseout=function(){self.showHideDescriptionDivIfExists(this);};
		
		//titlediv.appendChild(mouseoverdiv);
		//openlink.style.display="none";
		td.appendChild(titlediv);
		var alltrs = this.getTableRows();
		var lastTr = alltrs[alltrs.length-1];
		var alltds = this.getTableCells(lastTr);
		var lastTd = alltds[td.cellIndex];
		this.popupDivs.push(mouseoverdiv);
		//lastTd.appendChild(mouseoverdiv);
		
		td.openlink = openlink;
		td.mouseoverdiv= mouseoverdiv;
	}
						
	
	
	AnthemRotatingTable.prototype.getTableRows = function()
	{
		this.tableDom.tempid='theparent'+Ext.id();
		var allTRs = this.tableDom.tBodies[0].getElementsByTagName('tr');
		var result=[];
		for (var c=0;c<allTRs.length;c++)
		{
			if (allTRs[c].parentNode.parentNode.tempid==this.tableDom.tempid) result.push(allTRs[c]);
		}
		
		this.tableDom.tempid=null;
		return result;
	}
	AnthemRotatingTable.prototype.getTableCells = function(tr)
	{
		tr.tempid='theparent'+Ext.id();
		var allSubTDs = tr.getElementsByTagName('td');
		var result=[];
		for (var c=0;c<allSubTDs.length;c++)
		{
			if (allSubTDs[c].parentNode.tempid==tr.tempid) result.push(allSubTDs[c]);
		}
		
		tr.tempid=null;
		return result;
	}
	AnthemRotatingTable.prototype.getTableSizing = function()
	{
		this.tableSizing={};
		this.tableSizing.totalWidth=this.htmltable.getWidth();
		this.tableSizing.totalHeight=this.htmltable.getHeight();
		
		
		this.tableSizing.rows=[];
		this.tableSizing.leftHiddenWidth=0;
		this.tableSizing.rightHiddenWidth=0;
		this.tableSizing.rightHiddenStartPosition=0;
		this.tableSizing.leftMoveIncrement=0;
		this.tableSizing.rightMoveIncrement=0;
		
		
		this.tableSizing.cellPadding = this.tableDom.cellPadding;
		this.tableSizing.cellSpacing = this.tableDom.cellSpacing;
		this.tableSizing.border = this.tableDom.border;
		
		var trs = this.getTableRows();
		for (var j=0;j<trs.length;j++)
		{
			var tr = trs[j];
			var tds = tr.getElementsByTagName('td');
			this.tableSizing.rows[j]=[];
			for (var i=0;i<tds.length;i++)
			{
				
				this.tableSizing.smallTable = tds.length < this.portWidth;
				var td = tds[i];
				//if (this.rateRequestIsVirtual===true) {
				//	td.width=this.fixedCellWidth;
				//}
				if (!td.id) td.id = Ext.id();
				var temp = this.getTableCellSize(td);
				this.tableSizing.rows[j][i]=temp;
				
				if (j==this.measuringRow) 
				{ 
					this.tableSizing.cellWidth = temp.width;
					this.tableSizing.effectiveViewportWidth=Math.min(tds.length,this.viewportWidth);
					this.addFeedback("before "+j+" "+this.leftmostVisibleIndex+" "+this.rightmostVisibleIndex+" "+this.viewportWidth+" "+tds.length+" "+this.tableSizing.smallTable+" "+Math.min(tds.length,this.viewportWidth));
					if (this.leftmostVisibleIndex<0) 
					{
						this.leftmostVisibleIndex=0;
						this.rightmostVisibleIndex=this.leftmostVisibleIndex+this.tableSizing.effectiveViewportWidth;
					}
					this.addFeedback("middle "+j+" "+this.leftmostVisibleIndex+" "+this.rightmostVisibleIndex+" "+this.viewportWidth+" "+tds.length+" "+this.tableSizing.smallTable+" "+Math.min(tds.length,this.viewportWidth));
					if (this.rightmostVisibleIndex>tds.length-1) 
					{
						this.rightmostVisibleIndex=tds.length-1;
						if (this.tableSizing.smallTable==true) this.leftmostVisibleIndex=0;
						else this.leftmostVisibleIndex=this.rightmostVisibleIndex-this.tableSizing.effectiveViewportWidth;
					}
				this.addFeedback("after "+j+" "+this.leftmostVisibleIndex+" "+this.rightmostVisibleIndex+" "+this.viewportWidth+" "+tds.length+" "+this.tableSizing.smallTable+" "+Math.min(tds.length,this.viewportWidth));
					
					if (i==this.leftmostVisibleIndex-1 && this.leftmostVisibleIndex>0)
					{
						
						this.tableSizing.leftMoveIncrement=temp.width;
					}
					else if (i==this.rightmostVisibleIndex && this.rightmostVisibleIndex<tds.length-1)
					{
						this.tableSizing.rightMoveIncrement=temp.width;
						
					}
					
					if (i<this.leftmostVisibleIndex)
					{
						this.tableSizing.leftHiddenWidth+=temp.width;
					}
					if (i<this.rightmostVisibleIndex+1)
					{
						this.tableSizing.rightHiddenStartPosition+=temp.width;//this.totalCellWidth;//temp.width;
					}
					if (i>=this.rightmostVisibleIndex-1)
					{
						this.tableSizing.rightHiddenWidth+=temp.width;
					}
				}
			}
			
		}
	//	if (this.rateRequestIsVirtual===true) {
	//		this.tableSizing.cellWidth=this.fixedCellWidth;
	//		this.tableSizing.rightMoveIncrement=this.fixedCellWidth;
	//		this.tableSizing.leftMoveIncrement=this.fixedCellWidth;
	//	}
		this.tableSizing.leftHiddenWidth+=parseInt(this.tableDom.border);		
		this.tableSizing.rightHiddenStartPosition+=parseInt(this.tableDom.border);
		this.tableSizing.rightHiddenWidth = 1000;// this.parentDiv.getWidth()-this.tableSizing.rightHiddenStartPosition-parseInt(this.tableDom.border);
		this.tableSizing.tableSize = this.getTableCellSize(this.tableDom);
		this.tableSizing.viewPortCells=this.rightmostVisibleIndex-this.leftmostVisibleIndex+1;
		//assumed: constant width columns
		this.tableSizing.viewPortWidth=this.tableSizing.viewPortCells*this.tableSizing.rows[this.measuringRow][0].width;
	}
	AnthemRotatingTable.prototype.getTableCellSize = function(td)
	{

		var temp = {};
		if (td.getHeight && td.getWidth)
		{
			temp.height=td.getHeight();
			temp.width=td.getWidth();
		}
		else 
		{	
			//this is IE - offset heights too large initially
			temp.height = td.offsetHeight;
			temp.width = td.offsetWidth;
		}
		//this.addFeedback(td.cellIndex+' '+temp.height);
		return temp;
	}
	AnthemRotatingTable.prototype.getRightBorderCorrection = function()
	{
		var rightPanelPos = this.rightPanelExt.getPosition()[0];
		var rightTableEdgePos = this.htmltable.getRight();
		
		var leftPanelExt = Ext.get(this.leftPanel);
		var leftTableEdgePos = this.htmltable.getLeft();

		var leftPanelPos = leftPanelExt.getLeft()+leftPanelExt.getWidth();

		if (leftTableEdgePos<leftPanelPos)
		{
			var self = this;
			new Effect.Move(this.tableDom,{x:(leftPanelPos-leftTableEdgePos),y:0,mode:'relative', afterFinish: function(){self.setButtonEnabledStatus()}});
		}
	}
	AnthemRotatingTable.prototype.reportSizing = function(tag)
	{
		//var trs = this.getTableRows();
		//var tds = trs[0].getElementsByTagName('td');

		//this.addFeedback(tag+this.getTableCellSize(tds[0]).width);
	}
	
	
	AnthemRotatingTable.prototype.hideOtherToggles= function(index)
	{
		var tableRows = this.getTableRows();
		for (var j=0;j<this.optionRows.length;j++)
		{
			var currentindex = this.optionRows[j];
			//if (currentindex!=index)
			//{
				
				var tr = tableRows[currentindex];
				var tds = this.getTableCells(tr);
				for (var i=0;i<tds.length;i++)
				{
					var td = tds[i];
					
					var a = td.childNodes[0].childNodes[1];
					if (a) new Effect.Fade(a);
					else {
						//just need to get rid of these, they don't work anyway
						
						var inner = td.childNodes[0].innerHTML;
						if (inner) {
							var apos = 	inner.toLowerCase().indexOf("<a");
							var cpos = inner.toLowerCase().indexOf("</a>");
							if (apos>0 && cpos>apos) {
								td.childNodes[0].innerHTML = inner.substring(0,apos)+inner.substring(cpos+4);
	
							}
						}
					}
				}
			//}
		}
		

	}
	AnthemRotatingTable.prototype.showAllToggles= function()
	{
		var tableRows = this.getTableRows();
		for (var j=0;j<this.optionRows.length;j++)
		{
			var currentindex = globalObjectRegistration.optionRows[j];

			var tr = tableRows[currentindex];
			var tds = globalObjectRegistration.getTableCells(tr);
			for (var i=0;i<tds.length;i++)
			{
				var td = tds[i];
				var a = td.childNodes[0].childNodes[1];
				if (a) new Effect.Appear(a);
			}
			
		}
		

	}
	AnthemRotatingTable.prototype.disableMoveEvents = function()
	{
		for (var j=0;j<this.leftButtons.length;j++) {
			var lb = Ext.get(this.leftButtons[j]).dom;
			lb.oldonclick = lb.onclick;
			lb.onclick=null;
			lb.disabled = true;
		}
		for (var j=0;j<this.rightButtons.length;j++) {
			var rb = Ext.get(this.rightButtons[j]).dom;
			rb.oldonclick = rb.onclick;
			rb.onclick=null;
			rb.disabled = true;
		}
	}
	AnthemRotatingTable.prototype.restoreMoveEvents = function(params)
	{
		for (var j=0;j<this.leftButtons.length;j++) {
			var lb = Ext.get(this.leftButtons[j]).dom;
			lb.onclick=lb.oldonclick;
			lb.disabled = false;
		}
		for (var j=0;j<this.rightButtons.length;j++) {
			var rb = Ext.get(this.rightButtons[j]).dom;
			rb.onclick=rb.oldonclick;
			rb.disabled = false;
		}
	}
	AnthemRotatingTable.prototype.moveTableColumns = function(params)
	{
		var button = params.button;
		if (this.moving!==true)
		{
			if (params.increment) var increment=-params.increment;
			if (params.viewport) {
				var leftmostVisibleIndex=params.viewport.left;
				var rightmostVisibleIndex=params.viewport.right;
			}
			var quantum = 0;
			
			if (increment<0)
			{
				quantum = increment*this.tableSizing.cellWidth;//this.tableSizing.rightMoveIncrement;		
			}
			else
			{			
				quantum = increment*this.tableSizing.cellWidth;//this.tableSizing.leftMoveIncrement;
			}
				
			var tableDerailed =	this.tableEdgesAreInsidePanels(quantum);

			var self = this;
			if (increment!=0 && tableDerailed.left===false && tableDerailed.right===false) {
				new Effect.Move(this.tableId, { x: quantum, y: 0, mode: 'relative',
								queue: { position: 'end', scope: 'tableslider'  },
								beforeStart: function(effect) {
									//if (self.checkTableEndpoints()==true) effect.cancel();
									//self.disableMoveEvents();
									if (button) {
										button.temp = button.onclick;
										
										button.onclick = null;
									}
									self.moving = true;
									//alert('start '+self.leftButtons[0].onclick);
								},
								afterFinish: function() {
									self.moving=null;
									//self.restoreMoveEvents();
									if (button) {
										button.onclick = button.temp;
									}
									self.refreshTable();
									if (Ext.isIE6) self.refreshAllRadioSelects();
									//alert('finish '+self.leftButtons[0].onclick);
								}});
				this.leftmostVisibleIndex-=increment;
				this.rightmostVisibleIndex-=increment;
	
				
			}
			else {
				this.setButtonEnabledStatus();
			}
		}
		//self.moving=null;
		//self.restoreMoveEvents();
	}
	AnthemRotatingTable.prototype.refreshAllRadioSelects = function()
	{	
		for (id in this.radioSelects) {
			if (this.radioSelects[id].isVisible === true) {
				this.radioSelects[id].setVisible(false);
				this.radioSelects[id].setVisible(true);
			}
		}
	}
	AnthemRotatingTable.prototype.checkTableEndpoints = function()
	{
		var queue = Effect.Queues.get('tableslider');
		return queue.size()>0;

	}
	AnthemRotatingTable.prototype.setButtonsEnabledDisabled = function(enabled)
	{
		if (!enabled) enabled=false;
		if (this.leftButtons)
		{
			for (var j=0;j<this.leftButtons.length;j++)
			{
				this.leftButtons[j].enabled=enabled;
			}
		}
		if (this.rightButtons)
		{
			for (var j=0;j<this.rightButtons.length;j++)
			{
				this.rightButtons[j].enabled=enabled;
			}
		}
	}
	AnthemRotatingTable.prototype.tableEdgesAreInsidePanels = function(move)
	{
		if (!move) move=0;
		var fuzzy = 7;
		var rightPanelLocation = this.rightPanelExt ? this.rightPanelExt.getEl().dom.offsetLeft : 800;
		var leftPanelLocation = this.leftPanel ? this.leftPanel.offsetLeft + Ext.get(this.leftPanel).getWidth() : 0;
		
		var tableRightEdge = this.tableDom.offsetLeft+this.htmltable.getWidth()+move - this.effectiveTableEdgePadding;
		var tableLeftEdge = this.tableDom.offsetLeft + move;
		
		var leftEdgeIsInside = tableLeftEdge>leftPanelLocation+fuzzy;// || this.tableDom.offsetLeft-fuzzy<leftPanelLocation;
		var rightEdgeIsInside = tableRightEdge+fuzzy < rightPanelLocation;// || tableRightEdge+fuzzy > rightPanelLocation;
		return {'left':leftEdgeIsInside, 'right':rightEdgeIsInside};
	}
	
	AnthemRotatingTable.prototype.tableOverlapsPanels = function(move)
	{
		if (!move) move=0;
		var fuzzy = 7;
		var rightPanelLocation = this.rightPanelExt ? this.rightPanelExt.getEl().dom.offsetLeft : 800;
		rightPanelLocation+=this.effectiveTableEdgePadding;
		var leftPanelLocation = this.leftPanel ? this.leftPanel.offsetLeft + Ext.get(this.leftPanel).getWidth() : 0;
		
		var tableRightEdge = this.tableDom.offsetLeft+this.htmltable.getWidth()+move;
		var tableLeftEdge = this.tableDom.offsetLeft + move;
		
		var leftOverlaps = tableLeftEdge+fuzzy<leftPanelLocation;// || this.tableDom.offsetLeft-fuzzy<leftPanelLocation;
		var rightOverlaps = tableRightEdge-fuzzy > rightPanelLocation;// || tableRightEdge+fuzzy > rightPanelLocation;
		return {'left':leftOverlaps, 'right':rightOverlaps};
	}
	
	AnthemRotatingTable.prototype.setButtonEnabledStatus = function(useSimpleToggle)
	{

		var disableRightButton = this.rightmostVisibleIndex==this.tableSizing.rows[this.measuringRow].length-1;
		var disableLeftButton = this.leftmostVisibleIndex==0;
		
		if (this.rightPanelExt && this.leftPanel) {
		
			
			var overlap = this.tableOverlapsPanels();
			disableRightButton = overlap.right==false;
			disableLeftButton = overlap.left==false;

			if (this.leftButtons)
			{
				
				for (var j=0;j<this.leftButtons.length;j++)
				{

					if (useSimpleToggle && useSimpleToggle==true) Ext.get(this.leftButtons[j]).dom.style.display=disableLeftButton && disableLeftButton===true ? "none" : "block";
					else this.fadeAppear(this.leftButtons[j],disableLeftButton);
					if (Ext.isIE6)
					{
							var buttonDom = Ext.get(this.leftButtons[j]).dom;
							buttonDom.style.height=this.getTableCellSize(this.tableDom).height;		
					}
				}
			}
			if (this.rightButtons)
			{
				for (var j=0;j<this.rightButtons.length;j++)
				{
					if (useSimpleToggle && useSimpleToggle==true) {
						var buttonDom = Ext.get(this.rightButtons[j]).dom;
						buttonDom.style.display=disableRightButton && disableRightButton===true ? "none" : "block";
					
					}
					else this.fadeAppear(this.rightButtons[j],disableRightButton);
					if (Ext.isIE6)
					{
						var buttonDom = Ext.get(this.rightButtons[j]).dom;
						buttonDom.style.height=this.getTableCellSize(this.tableDom).height;	
					}
				}
			}
		}
	}
	AnthemRotatingTable.prototype.fadeAppear = function(control,hideControl)
	{
		if (hideControl && hideControl==true) new Effect.Fade(control);
		else new Effect.Appear(control);
	}
	AnthemRotatingTable.prototype.getEquivalentHeaderIndex = function(tr, currentIndex)
	{

		var tds = this.getTableCells(tr);
		var counter=0;
		
		for (var j=0;j<tds.length;j++)
		{
			var currentSpan = tds[j].colSpan;
			counter+=currentSpan;
			if (counter>currentIndex) return j;
		}

		return currentIndex;
	}
	AnthemRotatingTable.prototype.addColumn = function(button, cellsToMake)
	{
		
		var cell = Utilities.findNearestParentWithTag(button,"td");//button.parentNode;

		var extensionIndex=cell.extensions.length-cellsToMake;
		var currentIndex = cell.cellIndex;
		var currentRowIndex = cell.parentNode.rowIndex;
		var row = cell.parentNode;
		var trs = this.getTableRows();
		var cellHeaderIndex = this.getEquivalentHeaderIndex(trs[0], cell.cellIndex);

		var headerCell = trs[0].getElementsByTagName('td')[cellHeaderIndex];
		var newTDs = [];
		globalObjectRegistration=this;
		if (!headerCell.temporarySpans) headerCell.temporarySpans=[];
		if (!headerCell.hiddenOptions) headerCell.hiddenOptions=[];
		if (!headerCell.hiddenOptionsExt) headerCell.hiddenOptionsExt=[];
		if (!headerCell.optionValueSpans) {
			headerCell.optionValueSpans=[];
			
		}
		if (!cellsToMake) {
			//this is the first column opened
			cellsToMake =cell.extensions.length-1;
			var selectList = cell.getElementsByTagName('select');
			if (selectList && selectList.length>0) {
				selectList[0].style.display='none';
				var optionValueSpan = document.createElement('span');
				optionValueSpan.id="temporarySpan_"+row.rowIndex;
				optionValueSpan.innerHTML=cell.extensions[0].text;
				cell.appendChild(optionValueSpan);
				headerCell.temporarySpans.push(optionValueSpan);
				
				headerCell.hiddenOptions.push(selectList[0]);
			}
			
			if (cell.combobox) {
				
				var csze = this.getTableCellSize(cell);
				
				var ch = csze.height;

				if (Ext.isIE || Ext.isSafari|| Ext.isChrome) ch-=21;
				cell.height=ch;

				cell.combobox.setVisible(false);
				var optionValueSpan = document.createElement('span');
				optionValueSpan.id="temporarySpan_"+row.rowIndex;
				optionValueSpan.innerHTML=cell.extensions[0].text;
				optionValueSpan.style.position="absolute";
				optionValueSpan.style.display="block";
				optionValueSpan.style.width=(.75*this.newCellWidth)+"px";
				
				cell.optionValue = cell.extensions[0].value;
				
				var locCell = Utilities.findPos(cell);
				var locTable = Utilities.findPos(this.tableDom);

				optionValueSpan.style.top=(locCell[1]-locTable[1]+12)+"px";
				
				//optionValueSpan.style.border="1px solid black";
				cell.appendChild(optionValueSpan);
				headerCell.temporarySpans.push(optionValueSpan);
				headerCell.hiddenOptionsExt.push(cell.combobox);
				cell.temporarySpan = optionValueSpan;
			}
			
		}

		var fudgeFactor = Ext.isIE ? 2*(this.titleTable.border > 0 ? 1:0) : 0;
		for (var j=0;j<trs.length;j++)
		{

			var tr = trs[j];
			var tds = this.getTableCells(tr);
			if (j==0) {
				var currentHeaderIndex = this.getEquivalentHeaderIndex(tr, currentIndex);
				if (Ext.isIE) {
					var td = tr.childNodes[currentHeaderIndex];
				}
				else {
					
					var td = tr.childNodes[(2*currentHeaderIndex+2)];
					var effectiveIndex=0;
					for (var k=0;k<tr.childNodes.length;k++) {
						//this.addFeedback(k+" "+Ext.util.Format.htmlEncode(tr.childNodes[k])+tr.childNodes[k].tagName);
						if (tr.childNodes[k].tagName && tr.childNodes[k].tagName=="TD") {
							if (effectiveIndex == currentHeaderIndex) var td = tr.childNodes[k];
							effectiveIndex++;
						}
					}
					
				}


				if (!td.colSpan) td.colSpan=1;
				var currentSpan = td.colSpan;
				td.colSpan++;

				if (currentSpan>1)
				{var alreadyExpanded=1;}
				
				var closelink = td.childNodes[0].childNodes[1];

				var closeimg =  closelink.childNodes[0];
				idNum = parseInt(closelink.id.substring(11));

			}
			if (j>0) {
				var td = this.duplicateCell(tds,trs,currentIndex,j,cell,headerCell,cellsToMake,fudgeFactor);
				
				newTDs.push(td);
				
			}
		}
		if (this.linksToClose[idNum])
		{
			for (var j=0;j<this.linksToClose[idNum].length;j++)
			{
				newTDs.push(this.linksToClose[idNum][j]);
			}
			
		}
		this.linksToClose[idNum]=newTDs;

		//use new cell width instead
		this.slideColumnOut(newTDs,this.newCellWidth,closeimg,globalObjectRegistration,alreadyExpanded,closelink,currentRowIndex, button, cellsToMake);
		
		
		
		return false;
	}
	AnthemRotatingTable.prototype.duplicateCell = function(tds,trs,currentIndex,currentColumnIndex,cellToExpand,headerCell,cellsToMake,fudgeFactor) {
				
				var isCustomerRow = Utilities.arrayContains(this.customerRows,currentColumnIndex);
				var isPremiumRow = Utilities.arrayContains(this.premiumRows,currentColumnIndex);
				var oldtd = tds[currentIndex];
				var row = cellToExpand.parentNode;
				
                         // alert(Utilities.findKeys(headerCell.plan));
				//create new cell
				var td = trs[currentColumnIndex].insertCell(currentIndex+1);
				//if (oldtd.cashValue) td.cashValue = oldtd.cashValue;

				if (isPremiumRow) {
					td.isPremiumRow = true;
					td.cashValue =0;
				}
				//get padding values
				var padding = Utilities.getCurrentStylePadding(td);
				var oldpadding = Utilities.getCurrentStylePadding(oldtd);
				
				var optionValueSpan = document.createElement('div');
				
				
				var iebordercrutch = document.createElement('span');
				iebordercrutch.innerHTML="&nbsp;";
				iebordercrutch.style.fontSize="3px";

				optionValueSpan.style.margin='0';
				optionValueSpan.id = "_"+currentColumnIndex+"_"+cellsToMake;
				var converted = null;
				//always track the key
				td.optionKey = oldtd.optionKey;
				td.optionValue = cellToExpand.extensions[cellsToMake].value;
				if (currentColumnIndex==row.rowIndex) {
					//this is the row that was clicked
					optionValueSpan.innerHTML=cellToExpand.extensions[cellsToMake].text;	
					
					//td.optionValue = cellToExpand.extensions[cellsToMake].value;	
				}
				else {
					if (oldtd.innerHTML!=' ' 
						&& oldtd.innerHTML!="&nbsp;" 
						&& Utilities.arrayContains(this.ignoreTheseRows,currentColumnIndex)==false) {
						
						//node is complete copy of old td
						var node = oldtd.cloneNode(true);
						
						
						var isOptionRow = Utilities.arrayContains(this.optionRows,td.parentNode.rowIndex);

						if (isOptionRow===true) {
							 var comboIsHidden = oldtd.combobox && oldtd.combobox.isVisible===false;
							 
							 //two possibilities, one is that an option pulldown still exists
							 var combos = Ext.query(".listParent-RadioSelect",oldtd);

							 if (combos && combos.length>0 && !comboIsHidden) {

								converted = true;
								td.innerHTML='';
								
								var exts = oldtd.combobox.getAllValues();
								var oldSelect = oldtd.selectList;
								var newSelect = document.createElement("select");
								optionValueSpan.appendChild(newSelect);

								td.comboToDuplicate = oldtd.combobox;
								
								td.selectList = oldtd.selectList;
								newSelect.id = oldSelect.id+"_"+cellsToMake;
								for (var m=0;m<exts.length;m++)
								{
									var opt = document.createElement("option");
									opt.text = exts[m].text;
									opt.value = exts[m].value;
									newSelect.options.add(opt);
								}
							} else { 
								//no combo, means it was expanded already and is just a value
								//OR never had multiple values

								td.optionValue = oldtd.optionValue;
								//optionValueSpan = node;
								var cns = node.childNodes;

								for (var c=0;c<cns.length;c++)
								{
									if (!cns[c].id || cns[c].id.indexOf("titlediv")!=0) optionValueSpan.appendChild(cns[c].cloneNode(true));
								}
							}
						} else {
							//child nodes of old td
							var cns = node.childNodes;

							for (var c=0;c<cns.length;c++)
							{
								var cn = cns[c];
	
								if (cn.innerHTML) {	
									optionValueSpan.appendChild(cn);
								}
								else if (cn.nodeValue)
								{
									//this is a text node
									var internal = document.createElement('span');
									internal.innerHTML = cn.nodeValue;
									optionValueSpan.appendChild(internal);
								}
								else
								{
									//this needs a fudge for IE
									var internal = document.createElement('span');
									internal.appendChild(cn);
									optionValueSpan.appendChild(internal);
								}
								
								
							}

							//take care of customer rows
							if (isCustomerRow==true) {
								td.onclick = function(){globalObjectRegistration.customerCellClicked(this)};
								td.customerName = oldtd.customerName;
								td.isCustomerCell = true;
							}
							
							//description rows
							var isDescriptionRow = Utilities.arrayContains(this.descriptionRows,currentColumnIndex);
							if (isDescriptionRow==true && optionValueSpan.childNodes && optionValueSpan.childNodes.length>1) {
								var dcns = optionValueSpan.childNodes[1].childNodes;
								var self = this;
								var ffmo = Ext.isIE || Ext.isSafari ? -40:0;
								for (var d=0;d<dcns.length;d++)
								{
									var dcn = dcns[d];
	
									if (dcn.tagName=="A") {
										dcn.href+="_"+cellsToMake;
	
										dcn.onmouseover=function(){self.showHideDescriptionDivIfExists(this,true,null,this.tableMovementOffsetLeftCorrection-40,ffmo);};
										dcn.onmouseout=function(){self.showHideDescriptionDivIfExists(this);};
	
									}
								}
							}
							
							if (currentColumnIndex==trs.length-1) {
								
								if (headerCell.descriptionMouseoverDiv && !Ext.get(headerCell.descriptionMouseoverDiv.id+"_"+cellsToMake))
								{
									var newMouseOverDiv = headerCell.descriptionMouseoverDiv.cloneNode(true);
									newMouseOverDiv.id+="_"+cellsToMake;
									//this.popupPanel.appendChild(newMouseOverDiv);
									Ext.getBody().appendChild(newMouseOverDiv);
								}
							}
							
							var isApplyNowRow = Utilities.arrayContains(this.applyNowRows,currentColumnIndex);
							
							
						}		
					}
				}
				if (padding.top=="0px") optionValueSpan.style.marginTop=oldpadding.top;
				if (padding.left=="0px") optionValueSpan.style.marginLeft=oldpadding.left;
				
				var width = (this.getTableCellSize(td).width-fudgeFactor);

				width-=Utilities.getIntegerPixelValue(oldpadding.left)+Utilities.getIntegerPixelValue(oldpadding.right);
				
				optionValueSpan.style.display='none';
				td.appendChild(optionValueSpan);
				if (converted) {
                    newSelect.plan = headerCell.plan;
					td.converted=newSelect.id;
					td.awaitingConversion=true;

				} else {
					//td.optionValue = oldtd.optionValue;
				}

				td.appendChild(iebordercrutch);
				td.plan = headerCell.plan;
				
				if (isCustomerRow==true) {
					this.setCellImage(td,this.checkboxImage,this.checkboxSelectedImage);
				}
				td.style.width="0px";
				
				if (isApplyNowRow===true && oldtd.oldButton) {
					var nb = oldtd.newButton;
					td.innerHTML='';

					var btn = new Ext.Button({
			        	text:nb.text,
						tooltip:nb.tooltip,
			            scale:'custom',
			            iconCls:'btnIcon-rightArrow',
			            cls:'customExtButton',
			            //renderTo:td,
			            href:nb.href,
			            handler:nb.handler});
			        td.newButton = btn;
				}

				if (oldtd.className) td.className = oldtd.className;
				Utilities.setDisplayValue(td,oldtd.style.display);
				headerCell.optionValueSpans.push(optionValueSpan);
				
			/*	if (oldtd.height) {
					alert(oldtd.height);
					var h = oldtd.height;
					if (Ext.isChrome || Ext.isSafari) {
						var pd = Utilities.getCurrentStylePadding(td);
						var bd = Utilities.getCurrentStyleBorders(td);
						alert(bd.top+' '+bd.bottom+' '+pd.top+' '+pd.bottom+' '+pd.all);
						h = (Utilities.trimPx(h)-Utilities.trimPx(pd.top)-Utilities.trimPx(pd.bottom)-Utilities.trimPx(bd.top)-Utilities.trimPx(bd.bottom))+'px';
						alert(h);
					}
					//if (!Ext.isChrome && !Ext.isSafari) 
					//td.height= h;
				}*/
				
				return td;
	}
	AnthemRotatingTable.prototype.slideColumnOut = function(newTDs,width,closeimg,self,alreadyExpanded,closelink,currentRowIndex, button, cellsToMake)
	{
		var cell = button.parentNode;
		var headerCell = closeimg.parentNode.parentNode.parentNode;

		for (var j=0;j<newTDs.length;j++)
		{
			if (j<newTDs.length-1)
			{
				
				newTDs[j].val=j;

				new Effect.Morph(newTDs[j], {
				  style: {
					width: (width)+'px'
				  },
				  beforeStart: function(q)
				  {
					  	self.columnHasBeenExpanded=1;
					  	var j=q.element.val;
					  	if (j==0)
						{
							self.parentDiv.dom.style.width=(self.parentDiv.getWidth()+2*width)+'px';
							self.hideOtherToggles(currentRowIndex);
							q.element.childNodes[0].style.width="100%";
							
						}
						
						if (q.element.awaitingConversion) {
						  	var comboToDuplicate = q.element.comboToDuplicate;
						  	//alert((typeof q.element.converted)+' '+q.element.converted.tagName+' '+q.element.converted);
						  	var combo = self.selectToCombo(q.element.converted, q.element,8);
							combo.setSelectedValues(comboToDuplicate.getSelectedValues());
							combo.writeValueToValuePanel(comboToDuplicate.getValueFromValuePanel());
							combo.valuePanel.setHeight(comboToDuplicate.valuePanel.getHeight());
							//combo.setTriggerVisible(false);
							q.element.combobox.plan=q.element.plan;
							q.element.awaitingConversion = null;

							for (var j in self.radioSelects)
							{
								if (comboToDuplicate && comboToDuplicate.plan.planId!=self.radioSelects[j].plan.planId)  self.radioSelects[j].setTriggerVisible(false);
                                //alert(comboToDuplicate.plan+' '+globalObjectRegistration.radioSelects[j].plan)
							}
						}
						
						
					  
				  },
				  afterFinish: function(q)
				  {
					if (q.element.isCustomerCell && q.element.isCustomerCell===true) {
					//	if (q.element.childNodes[0].childNodes[1]) q.element.valSpan = q.element.childNodes[0].childNodes[1].childNodes[1];
					//	else q.element.valSpan = q.element.childNodes[0].childNodes[0].childNodes[1].childNodes[1];
						if (!q.element.id) q.element.id = Ext.id();
						var valspans = Ext.query(".valspan-customercell",q.element);

						//if (valspans.length==0) alert("missing: "+q.element.id+" "+q.element.cellIndex+" "+q.element.parentNode.rowIndex+" "+q.element.innerHTML);
						//else 
						q.element.valSpan = valspans[0];
						
						q.element.isCustomerCell=null;
					}
					
					if (q.element.newButton) {
						q.element.newButton.render(q.element);
					}
					  
				  }
				});
			} else {
				new Effect.Morph(newTDs[j], {
				  style: {
					width: width+'px'
				  },
				  afterFinish: function(q) {

					  if (alreadyExpanded)
					  {
							new Effect.Move(closelink,{x:width,y:0,mode:'relative'});
					  } else if (closeimg) new Effect.Appear(closeimg, {afterFinish: function(){closeimg.parentNode.style.opacity="1";}});
					  self.refreshTable();
					 cellsToMake--;
					 
					 if (self.closingButton) {
						cellsToMake=0;
						self.expandInterrupted = true;
						self.closeColumns(self.closingButton);
						

					} else if (cellsToMake>0) self.addColumn(button, cellsToMake);
					//  globalObjectRegistration.addFeedback(td.childNodes[0].innerHTML);
					
					
					
					if (cellsToMake==0 && headerCell.optionValueSpans)
					{
						for (var c=0;c<headerCell.optionValueSpans.length;c++) {
						
							if (headerCell.optionValueSpans[c].parentNode && headerCell.optionValueSpans[c].parentNode.childNodes[0].innerHTML.length>0) {
								headerCell.optionValueSpans[c].parentNode.childNodes[1].style.display='none';
							}
							Utilities.setDisplayValue(headerCell.optionValueSpans[c],'');
							//new Effect.Appear(headerCell.optionValueSpans[c],{afterFinish:function(q){Utilities.setOpacity(q.element,100);}});
							
						}
						if (self.useAJAX===true &&
						(!self.rateRequestIsVirtual || self.rateRequestIsVirtual===false)) {
							self.hidePrices(this.recalculateText);
							
							//option 1: show recalculate button
							//globalObjectRegistration.showRecalculateButton();
							
							//option 2:instead of showing recalculate, create and send request
							self.setAllChanges(self,self.customerCellsAreVisible);
							
							var ajaxParams = {'optionChanges':self.optionChanges,
								'onFinish':self.setRateValues,
								'AJAXHandler':self.AJAXHandler};
			
							if (self.customerInfo) {
								ajaxParams.customerChanges = self.customerInfo;
							}
							
							self.AJAXHandler.handleRecalculateButtonClicked(
								self,ajaxParams
								);
						}	
							self.openingButton=null;
						
					}
					self.checkCellVisible(q.element);
				   }//closeimg.style.display="inline";
				});
			}
		}
	}
	
	AnthemRotatingTable.prototype.checkCellVisible = function(el)
	{
		var rightPanelPos = this.rightPanelExt.getPosition()[0];
		var rightTableEdgePos = Utilities.findPos(el)[0];
		this.reportSizing("corrected width: ");
		
		var widthToMove = Utilities.findSize(el).width;
		rightTableEdgePos = rightTableEdgePos+widthToMove;	
		if (rightTableEdgePos-rightPanelPos>.5*widthToMove)
		{
			var self=this;
			this.moveTableColumns({increment:1});
			
			
		}
	}
	AnthemRotatingTable.prototype.slideColumnIn = function(newTDs,closelink,self, cell)
	{
		var closeimg = closelink.childNodes[0];
		var headerCell = closelink.parentNode.parentNode;
		var headerDiv = closelink.parentNode;
		var headerCell = headerDiv.parentNode;
		var trs = [];
		var cellIndex = self.getEquivalentHeaderIndex(self.getTableRows()[0], newTDs[0].cellIndex)+1;
		var indexToDelete = false;
		var childDivs=[];
		for (var j=0;j<newTDs.length;j++)
		{
			var td = newTDs[j];
			if (td.childNodes.length>0 && td.childNodes[0].innerHTML && td.childNodes[0].tagName!="TABLE") td.childNodes[0].innerHTML="";
			else td.innerHTML="";
		}

		for (var j=0;j<newTDs.length;j++)
		{
			var td = newTDs[j];
			
			childDivs.push(td.childNodes[0]);
			var tr = td.parentNode;
			trs.push(tr);
            var firstRow = j==0;
            var lastRow = j==newTDs.length-1;

			if (firstRow===true) {
				new Effect.Morph(td, {
				  style: {
					width: '0px'
				  },
				  beforeStart: function() {
					  new Effect.Fade(closeimg);
					 	td.innerHTML="";
					  }
					 
				});
			} 
			else if (lastRow===true)
			{
				new Effect.Morph(td, {
				  style: {
					width: '0px'
				  },
				  afterFinish:function(q) {		
				  	//alert(q.element);  
				  	var td = q.element
				  	if (indexToDelete===false) {
                          //THIS ONLY WORKS IF ALL OTHER PLANS ARE CLOSED
				  		indexToDelete = headerCell.cellIndex+1;// td.cellIndex-headerCell.colSpan+2;
				  	}

					  headerCell.colSpan=1;
					  for (var i=0;i<trs.length;i++)
					  {
						  if (Ext.isIE) {
							 var theseTds = self.getTableCells(trs[i]);
							 if (theseTds[indexToDelete].combobox) {
							 	var radioPanel = theseTds[indexToDelete].combobox.radioPanel;
							 }
							 theseTds[indexToDelete].parentNode.removeChild(theseTds[indexToDelete]);
						  }
						  else
						  {
							  try {
							  trs[i].deleteCell(indexToDelete);} catch (e) {alert(e.message);}
						  }
					  }

					  self.refreshTable();
					  self.getRightBorderCorrection();
					  self.showAllToggles();
					  var width = self.tableSizing.rows[0][0].width;
					  closelink.style.left=(width)+"px";
					  
					  if (headerCell.temporarySpans) {
						for (var k=0;k<headerCell.temporarySpans.length;k++) {
							headerCell.temporarySpans[k].parentNode.removeChild(headerCell.temporarySpans[k]);
						}
						headerCell.temporarySpans=null;
					  }
					  if (headerCell.hiddenOptions) {
						for (var k=0;k<headerCell.hiddenOptions.length;k++) {
							new Effect.Appear(headerCell.hiddenOptions[k]);
						}
						headerCell.hiddenOptions=null;
					  }
					  if (headerCell.hiddenOptionsExt) {
						for (var k=0;k<headerCell.hiddenOptionsExt.length;k++) {
							headerCell.hiddenOptionsExt[k].setVisible(true);
						}
						headerCell.hiddenOptions=null;
					  }
					  if (headerCell.optionValueSpans) {
					  	headerCell.optionValueSpans=null;
					  }
					  self.closingButton = null;
					  for (var j in self.radioSelects)
					  {
						self.radioSelects[j].setTriggerVisible(true);
					  }

                      if (self.customerCellsAreVisible) {
                          self.recalculateButtonClicked(self.recalculateButtons[0]);
                      
                      }
					}
				});
			} 
			else 
			{
				new Effect.Morph(td, {
				  style: {
					width: '0px'
				  }
				  
				});
			} 
		}
	}
	AnthemRotatingTable.prototype.getIntervalText = function(interval)
	{
		var ret = this.monthlyTag;
		if (interval=="Daily") ret = this.dailyTag;
		return " "+ret;
		
	}
	AnthemRotatingTable.prototype.setRateValues = function(val)
	{
		var hideAll = false;
		var exemptions = null;
		if (this.parentObj&&this.parentObj.sfType=='AJAXHandler')
		{
			var tableObj = this.parentObj.parentObj;
			var allRates = val.rates;
			for (var j=0;j<allRates.length;j++)
			{
				var cId = allRates[j].column;
				var rate = allRates[j].rate;
				var interval = allRates[j].interval;
				var errors = allRates[j].errors;
				var cObj = Ext.get(cId);
				if (cObj) var  cell = cObj.dom;
				if (rate && cell)
				{
					cell.errors=null;
					if (cell.valSpan) {
						cell.valSpan.innerHTML = tableObj.makePrice(rate)+tableObj.getIntervalText(interval);		
						hideAll=true;	
					}
					else if (cell.cashValue || cell.isPremiumRow) {
						var value = Utilities.getMoneyUnformatted(rate);
						cell.cashValue = rate;
						cell.innerHTML = isNaN(rate) ? rate : "$"+rate.toFixed(2)+tableObj.getIntervalText(interval);
					}
				} else if (errors) {
					cell.errors=errors;
					if (cell.valSpan) {
						hideAll=true;	
						cell.valSpan.innerHTML='';
						//cell.valSpan.innerHTML = tableObj.getErrorLink(errors,tableObj.noCustomerRateText);
						cell.valSpan.appendChild(tableObj.getErrorLink(errors,tableObj.noCustomerRateText));
					}
					else if (cell.cashValue || cell.isPremiumRow) {		
							
							var lnk = tableObj.getErrorLink(errors,tableObj.noRateText);
							cell.innerHTML='';
							if (!exemptions) exemptions=[];
							if (!cell.id) cell.id=Ext.id();
							exemptions.push(cell.id);
						//cell.innerHTML = lnk;
						cell.appendChild(lnk);
					}
				} else {
					//alert('rate got lost: rate: '+rate+' cell: '+cell+' obj:'+Ext.util.JSON.encode(allRates));
				}
			}

			tableObj.setGrandTotal();
			//alert(hideAll);
			tableObj.hideEmptyPrices("&nbsp;",hideAll,exemptions);
		}
		
		
	}
	AnthemRotatingTable.prototype.getErrorLink = function(errors,errorOverText) {

		var errorText="";
		var sep ="";
		for (var j=0;j<errors.length;j++) {		
			errorText+=sep+errors[j];
			sep ="||";
		}

	
		var retval = document.createElement("a");
		retval.href="#";
		retval.innerHTML = errorOverText;
		retval.title=errorText;
		retval.alt=errorText;
		retval.style.color='black';
		retval.style.cursor='text';
		retval.style.textDecoration='none';
		retval.onclick = function() {alert(errorText); return false;};
		return retval;
	}
	
	AnthemRotatingTable.prototype.hideCustomerPrices = function()
	{
		var tableRows = this.getTableRows();
		for (var j=0;j<this.customerRows.length;j++) {
			var row = tableRows[this.customerRows[j]];
			var cells = this.getTableCells(row);
			for (var k =0;k<cells.length;k++) {
				var cell = cells[k];
				
				if (cell.valSpan) {
					cell.valSpan.innerHTML=this.customerPriceMask;
				}
			}
		}
	}
	AnthemRotatingTable.prototype.showCustomerRows = function()
	{
		this.customerCellsAreVisible=true;
		this.hideCustomerPrices();
		this.clearGrandTotal();
		if (this.grandTotalBox) this.grandTotalBox.style.display='';
		this.setAllChanges(this,true);
		
		var ajaxParams = {'optionChanges':this.optionChanges,'onFinish':this.setRateValues,'AJAXHandler':this.AJAXHandler}; 
		
		if (this.customerInfo) {
			ajaxParams.customerChanges = this.customerInfo;
		}
		
		if (this.useAJAX) this.AJAXHandler.showCustomersClicked(this,ajaxParams);
		var hiddenRows = this.overbarRows;
		for (var j=0;j<this.customerRows.length;j++)
		{
			hiddenRows.push(this.customerRows[j]);
		}
		for (var j=0;j<this.grandTotalRows.length;j++)
		{
			hiddenRows.push(this.grandTotalRows[j]);
		}

		
		var tableRows = this.getTableRows();
		var titleRows = this.titleTable.rows;
		for (var j=0;j<hiddenRows.length;j++)
		{
			var index = hiddenRows[j];
			
			var tr = tableRows[index];
			var titleTR = titleRows[index];

			Utilities.setDisplayValue(tr,'');
			Utilities.setDisplayValue(titleTR,'');

			var tds = this.getTableCells(tr);
			var ttds = this.getTableCells(titleTR);
			
			if (Ext.isIE6) {
				for (var i=0;i<tds.length;i++)
				{
					var cbImg = Ext.query("img",tds[i]);
					if (cbImg && cbImg[0]) cbImg[0].style.display='';
				}
			}
			
			var effects=[];
			var self = this;
			var ttd = ttds[0];
			Utilities.setDisplayValue(ttd,'');
		}

		//this.showRecalculateButton();
		for (var j=0;j<this.customerTriggerLinks.length;j++)
		{
				this.customerTriggerLinks[j].style.display='none';
		}
		for (var j=0;j<this.recalculateButtons.length;j++)
		{
				var btn = this.recalculateButtons[j];
				if (!btn.style) btn = btn.getEl().dom;
				btn.style.display='none';
		}
		this.hidePrices("&nbsp;");
		var div = document.createElement('div');
		
		var titleDiv = document.createElement('div');
		titleDiv.innerHTML=this.individualMemberRatesTitle;
		titleDiv.style.cssFloat="left";
		titleDiv.style.styleFloat="left";
		titleDiv.style.width="165px";
		div.appendChild(titleDiv);
		titleDiv.className="titleSpan";
		
		//var img = document.createElement('img');
		//img.src = 'images/leftArrow.jpg';
		//titleDiv.appendChild(img);
		//img.className="arrow";
		
		var textDiv = document.createElement('div');
		textDiv.innerHTML=this.individualMemberRatesText;
		div.appendChild(textDiv);
		textDiv.style.cssFloat="left";
		textDiv.style.styleFloat="left";
		//textDiv.style.border="1px solid black";
		//textDiv.style.height="100%";
		textDiv.style.verticalAlign="middle";

		textDiv.style.padding="0";
		var nCells = Math.min(this.tableSizing.rows[this.measuringRow].length,this.viewportWidth);

		var xw = Utilities.findRelativePos(this.rightPanel.dom,this.leftPanel)[0];

		var sizeLeft = xw-365; //345 is the combined size of the other two elements
		if (Ext.isIE6) {
			sizeLeft-=40;
		}
		if (sizeLeft > 450) textDiv.style.marginTop="8px";
		textDiv.style.width=sizeLeft+"px";
		textDiv.className="textSpan";
		
		var closeButton = document.createElement('input');
		closeButton.type='image';
		closeButton.style.cssFloat="right";
		closeButton.style.styleFloat="right";
		closeButton.style.marginRight="15px";
		closeButton.src=this.closeIndividualImage;
		closeButton.tableObj = this;
		div.appendChild(closeButton);
		closeButton.className="closeButton";
		closeButton.onclick=function(){this.tableObj.closeIndividualRates(this);return false;};
		
		this.parentDiv.dom.appendChild(div);
		
		div.style.verticalAlign="middle";
		div.style.position='absolute';
		div.className="overBarDiv";
		div.style.zIndex=15;
		textDiv.style.height=div.style.height;
		this.setOverBarLayout(div,tableRows,titleRows);

		if (this.columnHasBeenExpanded==1)
		{
			var trrep = tableRows[7];
			var tdsrep = this.getTableCells(trrep);
			var pt = Utilities.findPos(trrep.parentNode.parentNode);
			var currentLeft = 1;
			var refreshRow=0;
			for (var i=0;i<tds.length;i++)
			{
				var td = tdsrep[i];
				var p = Utilities.findPos(td);
				if (td.offsetLeft!=currentLeft) {
					//this.addFeedback(i+": "+td.offsetLeft+"   s:"+currentLeft);
					refreshRow=1;
				}
				
				var size = this.getTableCellSize(td);
				currentLeft+=size.width;
				
				
			}
			
		
			if (refreshRow==1)
			{
				//this.addFeedback('moving 0');
				//new Effect.Move(this.tableDom,{x:0,y:0});
			}
		}
		
		if (!this.grandTotalBox) this.createGrandTotalBox();
		this.refreshTable();
		
	}
	AnthemRotatingTable.prototype.showRecalculateButton = function()
	{
		var self = this;
		var useEffect=null;
		for (var j=0;j<this.customerTriggerLinks.length;j++)
		{
			if (useEffect) {
				new Effect.Fade(this.customerTriggerLinks[j],
							  {
								  afterFinish: function() {
									  for (var j=0;j<self.recalculateButtons.length;j++)
										new Effect.Appear(self.recalculateButtons[j]);
								  }
							  });
			} else {
				var btn = self.recalculateButtons[j];
				if (!btn.style) btn = btn.getEl().dom;
				if (btn.style.display==='none')
				new Effect.Appear(btn, {beforeStart: function(){if (self.customerCellsAreVisible==true) self.customerTriggerLinks[j].style.display='none';}});
			}
		}
	}
	AnthemRotatingTable.prototype.hideRecalculateButton = function(tableObj)
	{
		for (var j=0;j<tableObj.recalculateButtons.length;j++)
		{
				var btn = tableObj.recalculateButtons[j];
				if (!btn.style) btn = btn.getEl().dom;
				new Effect.Fade(btn,
				  {
					  afterFinish: function() {
					  
						  if (tableObj.customerCellsAreVisible==false && tableObj.customerRows.length>1)
						  {
							  for (var j=0;j<tableObj.customerTriggerLinks.length;j++)
									//new Effect.Appear(button.tableObj.customerTriggerLinks[j]);
									tableObj.customerTriggerLinks[j].style.display='';
							  }
						  }
				  });

		}
	}
	AnthemRotatingTable.prototype.hideEmptyPrices = function(overtext,hideAll,exemptions)
	{
		if (!hideAll) hideAll = false;
		if (!overtext) overtext="Recalculate";
		var tableRows = this.getTableRows();
		for (var j=0;j<this.premiumRows.length;j++)
		{
			var index = this.premiumRows[j];
			var tr = tableRows[index];
	 		var tds = this.getTableCells(tr);
			for (var i=0;i<tds.length;i++)
			{
			
				tds[i].isPremiumRow=true;
				var cashValue=tds[i].innerHTML.replace(",","").replace("$","").replace(this.dailyTag,"").replace(this.monthlyTag,"");
				
				//alert(isNaN(cashValue)+ " "+ (!tds[i].errors));
				
				if (isNaN(cashValue) && (!tds[i].errors || hideAll==true)
					&& (!exemptions || !Utilities.arrayContains(exemptions,tds[i].id))) // tds[i].innerHTML.substring(this.noRateText)!=-1)
				{
					
					//alert(i+" "+tds[i].innerHTML);
					tds[i].innerHTML=overtext;
				}
				
				
				//new Effect.CashRegister(node,0,{duration:.6}); 
				
			}
		}
	}
	
	AnthemRotatingTable.prototype.hidePrices = function(overtext, hideAll)
	{
		if (!hideAll) hideAll = false;
		if (!overtext) overtext="Recalculate";
		var tableRows = this.getTableRows();
		for (var j=0;j<this.premiumRows.length;j++)
		{
			var index = this.premiumRows[j];
			var tr = tableRows[index];
	 		var tds = this.getTableCells(tr);
			for (var i=0;i<tds.length;i++)
			{
				var cashValue=tds[i].innerHTML.replace(",","");
				if (!isNaN(cashValue.substring(cashValue.indexOf('$')+1)))
				{
					
					cashValue=tds[i].innerHTML;
					tds[i].cashValue=cashValue.substring(cashValue.indexOf('$')+1);
				}
				
				
				//new Effect.CashRegister(node,0,{duration:.6}); 
				if (tds[i].isFillerCell!==true) tds[i].innerHTML=overtext;
			}
		}
	}
	AnthemRotatingTable.prototype.closeIndividualRates = function(button)
	{

		button.tableObj.hideCustomerRows();
		button.parentNode.style.display='none';
		//button.tableObj.hideRecalculateButton(button.tableObj);
		
		//button.tableObj.showRecalculateButton(button.tableObj);
		this.hidePrices(button.tableObj.recalculateText);
		for (var j=0;j<button.tableObj.customerTriggerLinks.length;j++) {
			button.tableObj.customerTriggerLinks[j].style.display='';
		}
		
		button.tableObj.deselectAllCustomers(button.tableObj);
		
		/*var tableRows = this.getTableRows();
		
		
		for (var j=0;j<this.premiumRows.length;j++)
		{
			var index = this.premiumRows[j];

			var tr = tableRows[index];
	 		var tds = this.getTableCells(tr);
			for (var i=0;i<tds.length;i++)
			{
				tds[i].innerHTML = tds[i].cashValue;

			}
		}*/
		//button.tableObj.recalculateButtons[0].fireEvent('click');
		button.tableObj.recalculateButtonClicked(button.tableObj.recalculateButtons[0]);
		
	}
	AnthemRotatingTable.prototype.deselectAllCustomers = function(tableObj) {
		tableObj.customersSelected = null;

		var trs = tableObj.getTableRows();
		for (var i=0;i<tableObj.customerRows.length;i++) {
			var tr = trs[tableObj.customerRows[i]];
			var tds = tableObj.getTableCells(tr);
			for (var j=0;j<tds.length;j++)
			{
				tds[j].style.backgroundColor=this.customerBackgroundColor;			
				this.setCellImage(tds[j],this.checkboxImage,this.checkboxSelectedImage);
				tds[j].selected=false;
			}
		}
	}
	
	AnthemRotatingTable.prototype.setOverBarLayout = function(div,tableRows,titleRows)
	{
		
		var index = this.overbarRows[0];
		var tr = tableRows[index];
		var ttr = titleRows[index];
		var ttd = this.getTableCells(ttr)[0];
		
		var titlePos = Utilities.findPos(ttd);
		var parentPos = Utilities.findPos(div.parentNode);

		var ff = Ext.isSafari ? 9:0;
		
		div.style.left=(titlePos[0]-parentPos[0])+"px";
		div.style.top=(titlePos[1]-parentPos[1]-ff)+"px";
		
		var size = this.getTableCellSize(ttd);

		div.style.height=size.height+"px";
	//	this.addFeedback(this.tableSizing.viewPortWidth);
		if (this.rightPanelLeftPosition) div.style.width=(this.rightPanelLeftPosition+this.negativePlansPanelLeftMargin)+"px";

	}
	AnthemRotatingTable.prototype.refreshTable = function()
	{
		
		//this.getTableSizing();
		this.setButtonEnabledStatus();
	}
	AnthemRotatingTable.prototype.closeColumns = function(button)
	{
		if (this.expandInterrupted)
		{
			this.openingButton = null;
			this.expandInterrupted = null;
		}
		this.closingButton=button;
		var buttonObj = this.closeButtons[button.id];

		if (buttonObj && !this.openingButton)
		{
			var idNum = buttonObj.idNum;
			//this.addFeedback(idNum);
			var tds = this.linksToClose[idNum];		
			this.slideColumnIn(tds,button,this,button.parentNode);
			this.linksToClose[idNum]=[];
			//this.closeButtons[button.id]={};
		}
		//for (var id in this.closeButtons) 
		return false;
	}
	
	AnthemRotatingTable.prototype.showHideDescriptionDivIfExists=function(a,showDiv, relativeTo, xMargin,yMargin) {

		if (a.href.indexOf("#")!=-1) {
			var s = a.href.substring(a.href.indexOf("#")+1); 
			var x = Ext.get(s); 
			if (x) {
				this.showHideDiv(showDiv,x,a,relativeTo);
			}
		}
	}
	AnthemRotatingTable.prototype.showHideDiv = function(showDiv,x,a,relativeTo, xMargin,yMargin)
	{
	
	
		var x = Ext.get(x); 
		if (showDiv&& showDiv==true) var dv = 'block';
		else var dv = 'none';
		var dw = document.body.scrollWidth;

		if (showDiv&& showDiv==true) {
			if (!relativeTo) relativeTo = Ext.getBody().dom;//this.parentDiv.dom;
			if (!xMargin) xMargin=0;
			if (!yMargin) yMargin=0;
			var relPos = Utilities.findRelativePos(a,relativeTo);
			var linkSize = Utilities.findSize(a);
			if (x.dom.currentStyle) {
				var styleObj = x.dom.currentStyle; 
			}
			x.dom.style.zIndex=50;
			var xy = [relPos[0]+linkSize.width+xMargin+this.tableMovementOffsetLeftCorrection,relPos[1]+linkSize.height+yMargin];
			
		//	xy = Ext.get(a).getXY();
			//alert(xy+' '+x.adjustForConstraints(xy));
			//x.setXY(x.adjustForConstraints(xy));
		//	alert(x.getXY()+' '+x.adjustForConstraints(xy));
			var w = Utilities.findSize(x.dom).width;
			if (dw<xy[0]+w) {
				xy[0] -= (xy[0]+w)-dw + 20;
				if (Ext.isChrome || Ext.isSafari) xy[0]-=50;
			}
			
			if (Ext.isChrome) xy[1]-=40;
			
			x.dom.style.top=(xy[1])+"px";
			x.dom.style.left=(xy[0])+"px";

		}
		x.dom.style.display=dv; 
	}

	
	function ImagePreloader(images, callback)
	{
	   // store the call-back
	   this.callback = callback;

	   // initialize internal state.
	   this.nLoaded = 0;
	   this.nProcessed = 0;
	   this.aImages = new Array;
	   // record the number of images.
	
	   this.nImages = images.length;
	   // for each image, call preload()
	
	   for ( var i = 0; i < images.length; i++ ) 
		  this.preload(images[i]);
	}


	
	ImagePreloader.prototype.preload = function(image)
	{
	   // create new Image object and add to array
	   var oImage = new Image;
	   this.aImages.push(oImage);
	
	   // set up event handlers for the Image object	
	   oImage.onload = ImagePreloader.prototype.onload;
	   oImage.onerror = ImagePreloader.prototype.onerror;
	   oImage.onabort = ImagePreloader.prototype.onabort;
	

	   // assign pointer back to this.
	   oImage.oImagePreloader = this;
	   oImage.bLoaded = false;
	

	   // assign the .src property of the Image object
	   oImage.src = image;	
	}
	ImagePreloader.prototype.onComplete = function()
	{
	   this.nProcessed++;
	   if ( this.nProcessed == this.nImages )
	   {
		  this.callback(this.aImages, this.nLoaded);
	   }
	}

	ImagePreloader.prototype.onload = function()
	{
	   this.bLoaded = true;
	   this.oImagePreloader.nLoaded++;
	   this.oImagePreloader.onComplete();
	}

	ImagePreloader.prototype.onerror = function()
	{
	   this.bError = true;
	   this.oImagePreloader.onComplete();
	}
	
	ImagePreloader.prototype.onabort = function()
	{
	   this.bAbort = true;
	   this.oImagePreloader.onComplete();
	}


