// CodeThatTable PRO
// Version: 3.2.1 (06.29.06.1)
// IT IS ILLEGAL TO USE UNREGISTERED VERSION OF THE SCRIPT. WE PERFORM
// MONITORING OF THE SITES THAT USE SCRIPT USING GOOGLE AND SPECIAL WORDS
// INCLUDED INTO THE SCRIPT. WE WILL INITIATE LEGAL ACTIONS AGAINST THE
// PARTIES THAT VIOLATE LICENSE AGREEMENT. PLEASE REGISTER THE SCRIPT.
// Copyright (c) 2003-2006 by CodeThat.Com
// http://www.codethat.com/

function CCodeThatTable(name)
{
  	  var t=this;
	  t.name=name;
	  t.def={datatype:0,data:[]};
	  t.rows=[];
	  t.cols=[];
	  t.cells=[];
	  t.keyCol=0;
	  t.sortCol=-1;
	  t.sortType=1;
	  t.rowIndex=[];
	  t.page=1;
	  t.amountPerPage=-1;
	  t.rowStyle={};
	  t.tableStyle={};
	  t.rowHandler=null;
	  t.rowStart=-1;
	  t.rowHover=-1;
	  t.imgSortAsc="<";
	  t.imgSortDesc=">";
	  t.imgSortAscActive="<";
	  t.imgSortDescActive=">";
	  t.imgMultiSortAscActive="<";
	  t.imgMultiSortDescActive=">";
	  t.imgFirstPage="<<";
	  t.imgLastPage=">>";
	  t.imgPrevPage="<";
	  t.imgNextPage=">";
	  t.resetSortControl="Reset sort";
	  t.resetMarkControl="Reset select";
	  t.resetSearchControl="Reset search";
	  t.amountControl="Per Page: ";
	  t.searchControl="Search: ";
	  t.searchValue="";
	  t.useMultiSort=0;
	  t.useSort=1;
	  t.useAmountPanel=1;
	  t.useSearchPanel=0;
	  t.usePagePanel=1;
	  t.useResetPanel=0;
	  t.multiSortCol=[];
	  t.multiSortType=[];
	  t.vr=[];
	  t.pageCount=1;
	  t.useEdit=0;
	  t.editIndicator="*";
	  t.editTitle='edit';
	  t.editClass='';
	  t.Phase=1;
 	  t.CheckedCol = 1;
	  t.LotsCol = 2;
	  t.StrategyCol = 3;
	  t.VendorCol = 4;
	  t.MarketsCol = 5;
	  t.FrequencyCol = 6;
	  t.CostCol = 7;
	  t.SCapitalCol = 8;
	  t.TotalPnLCol = 9;
	  t.AnnualPnLCol = 10;
	  t.DrawdownCol = 11;
	  t.StartDateCol = 12;
	  t.displayseries = true;
	  t.maxPortfolio = 20;
	  t.showcharts = true;
	  t.newPopWin='';
	  t.selectedRow = -1;
	  t.firstRow = -1;
	  t.tableHTML = "";
	  t.PaintCount = 1;
	  t.chartHTML="";
	  t.statisticsHTML="";
	  t.strategy_titleHTML="";
	  t.stringLst = null;
	  t.stringStrategyLst = null;
	  t.numberLst = null;
	  t.FilterValue = "All";
	  t.FilterCol = 1;
	  t.onlyTop = false;
	  t.serieslength = 0;
	  t.numberStrategyLst = null;	
	  t.ToTalPnLStrategyLst = null;
	  t.tableLeftWidth = 457;
	  t.tableRightWidth = 403;
	  t.tableBottomWidth = 870;
	  t.checkedCount=0;
	  
	  t.Starting_Capital_USD = 0;
	  t.endCapital = 0;
	  t.Total_PnL_USD = 0;
	  t.Total_PnL_Percent = 0;
	  t.Start_Date = 0;
	  t.Max_Draw_Down_USD = 0;
	  t.Max_Draw_Down_Percent = 0;
	  t.Portfolio_Cost_USD = 0;

	  t.Strategy_Starting_Capital_USD = 0;
	  t.Strategy_endCapital = 0;
	  t.Strategy_Total_PnL_USD = 0;
	  t.Strategy_Total_PnL_Percent = 0;
	  t.Strategy_Start_Date = 0;
	  t.Strategy_Max_Draw_Down_USD = 0;
	  t.Strategy_Max_Draw_Down_Percent = 0;
	  t.Strategy_Portfolio_Cost_USD = 0;
	  
	  ua.oldB=(ua.oldOpera||ua.nn4);
	  ua.br=(ua.oldOpera)?1:((ua.nn4)?2:0);
	  };
  {
  var CGp=CCodeThatTable.prototype;
	  CGp.makeStyle=function(obj,param,cssName)
    {
    var css;
	  if(Def(css=makeCssClass(obj[param])))
      	{
      	cssName=makeNameUnique(cssName);
	  	obj[param]=cssName;
	  	css="\n."+cssName+"{"+css+"}";
	  	};
	  return css;
	};
	
	
	CGp.init=function(datatype,data)
    {
    var t=this,rowCount=0,colCount=0,r=t.rows.length;
	  switch(parseInt(datatype))
      {
      	case 0:break;
	  	case 1:data=t.fromCSV(data);break;
	  	case 2:data=t.fromCSVFile(data);break;
	  	case 3:data=t.fromXMLFile(data);break;
	  	case 4:data=t.fromXML(data);break;
	  	default:data=[];
	  };
	  t.rows=[];
	  t.rowIndex=[];
	  rowCount=data.length;
	  t.cols=[];
	  colCount=(rowCount)?data[0].length:0;
	  t.cells=[];
	  for(i=0;i<rowCount;i++)
      {
      	t.rows[i]=new CCodeThatRow(t,i);
	  	t.rowIndex[i]=i;
	  	if(data[i].constructor!=Array)
      	  data[i]=data[i].data;
	    if(data[i].constructor!=Array)
     	     data[i]=new Array(data[i]);
	  };
	  if(!colCount&&Def(t.def.colDef))
      	colCount=t.def.colDef.length;
	  for(i=0;i<colCount;i++)
      	t.cols[i]=new CCodeThatColumn(t,i,t.def.colDef[i]);
	  for(i=0;i<rowCount;i++)
      {
      	t.cells[i]=[];
	  	for(j=0;j<colCount;j++)
       	 t.cells[i][j]=new CCodeThatCell(t.rows[i],t.cols[j],data[i][j]);
	  };
	  if(t.amountPerPage<=0)
      	t.amountPerPage=rowCount;
	  t.initFirstPageTop();	
	  
	  if (t.onlyTop) 
	  	t.tableBottomWidth = t.tableStyle.width;
	//  if(!ua.oldOpera)t.paint();
	  };
	  
	  
	CGp.loadData=function(tableDef)
    {
      var t=this,style="",imgs=[],data=[],datatype=0,d;
	  if(Def(tableDef))
      	t.def=tableDef;
	  if(Def(t.def.datatype))
      	datatype=t.def.datatype;
	  if(Def(t.def.data))
	  	data=t.def.data;
	  if(datatype==0)
	  	{
			if(data&&data.constructor!=Array)data=new Array(data);
			if(t.def.colDef&&t.def.colDef.constructor!=Array)t.def.colDef=new Array(t.def.colDef);
	  	};
	  if(ua.oldB)
	  	if(datatype>1)
	  		{
			alert("Can't load data from file for old browser!");
			datatype=0;
			data=[];
	  		};
	  for(i in t)
	  	{
			if((i.indexOf("Style")>-1)&&t[i].constructor==Object)
				{
					if(Def(t.def[i]))
						t[i]=t.def[i];
					for(j in t[i])
						{
							if(j.indexOf("Class")>-1) style+=t.makeStyle(t[i],j,'');
	  					};
	  			};
			if(Def(t.def[i]))
				{
					if(i.indexOf("use")==0)
						eval('t[i] = '+t.def[i]);
					if(i.indexOf("Control")>-1)t[i]=makeControl(t.def[i]);
					if(i.indexOf("img")>-1){t[i]=makeImgTag(t.def[i],i,t[i]);
					imgs[imgs.length]=t[i].src;
	  			}
			if(i.indexOf("edit")==0)t[i]=t.def[i];
	  	};
	  };
	  for(i=0;Def(t.def.colDef)&&i<t.def.colDef.count;i++)
	  	{
			style+=t.makeStyle(t.def.colDef[i].titleClass,"titleClass","title"+i+"_");
			style+=t.makeStyle(t.def.colDef[i].titleClass,"cellClass","cell"+i+"_");
	  	};
	  if(Def(style))dw("<style>"+style+"</style>");
	  t.amountPerPage=t.def.amountPerPage;
	  if(Def(t.def.keyCol))t.keyCol=t.def.keyCol;
	  t.rowHandler=t.def.rowHandler;
	  t.init(datatype,data);
	  };

CGp.pageTitletoHTML=function()
  {
	var t=this, h="<td><div nowrap align='left'; margin-bottom:12px;margin-top:19px;><font color=\"#000000\" size=\"2\" face=\"Verdana\"><b>";
	switch (t.Phase) {
		case 1: t.pageTitle="Select Strategies"; break;
		case 2: t.pageTitle="Portfolio Statistics"; break;
		case 3: t.pageTitle="Register for Free Trial"; break;
	}
	h+=t.pageTitle+"</b></font></div></td>";
	h+="<td>"+t.SetEnlargeCode()+"</td>";
	return h;
  };

CGp.styledTable=function(twidth)
{
 var h="<table width=\"" + twidth + "\" style=\"border-top: 1px; border-top-color: #CCCCCC; border-top-style: solid; border-left: 1px; border-left-color: #CCCCCC; border-left-style: solid; border-bottom: 1px; border-bottom-color: #CCCCCC; border-bottom-style: solid; border-right: 1px;border-right-color: #CCCCCC; border-right-style: solid;\" cellpadding=\"0\" cellspacing=\"0\">";
    
 return h;
}

CGp.styledTableTable=function(twidth)
{
 var h="<table width=\"" + twidth + "\" style=\"border-top: 1px; border-top-color: #CCCCCC; border-top-style: solid; border-left: 1px; border-left-color: #CCCCCC; border-left-style: solid; border-bottom: 1px; border-bottom-color: #CCCCCC; border-bottom-style: solid; border-right: 1px;border-right-color: #CCCCCC; border-right-style: solid;\" cellpadding=\"3\" cellspacing=\"1\">";
    
 return h;
}


CGp.emptystyledTable=function()
{
 var h="<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">";
    
 return h;
}

CGp.emptystyledTablewithPadding=function(tpadding)
{
 var h="<table cellpadding=\""+tpadding+"\" cellspacing=\"0\" border=\"0\">";
    
 return h;
}

CGp.styledTitlewithID=function(ttitle)
{
	var h=" <FONT color=\"#2C4D90\" style=\"font-size:13px\" face=\"Verdana\" ><b>"+ttitle+"</b></FONT>";
    return h;
}

CGp.styledResultsTitle=function(ttitleleft,checkboxtitle,ttitleright,divname)
{
    var h="<td height=\"25\"  width=\"160\" align=\"left\" valign=\"middle\" bgcolor=\"#D6E1EB\">"; 
    h+=" <div id=" + divname +" style=\"margin-left:5px\"> ";
	h+=t.styledTitlewithID(ttitleleft);
	h+=" </div>";
	h+=" </td> "; 
	h+=" <td height=\"25\" width=\"280\" align=\"left\" valign=\"middle\" bgcolor=\"#D6E1EB\">"; 
    h+=" <div style=\"margin-left:5px;\"> ";
	h+=" <FONT color=\"#000000\" style=\"font-size:11px\" face=\"Verdana\" ><b>&nbsp;Compare to: "+checkboxtitle+"</b></FONT>";
    h+=" </div>";
	h+="</td> "; 
	h+=" <td height=\"25\" align=\"right\" valign=\"middle\" bgcolor=\"#D6E1EB\">"; 
    h+=" <div style=\"margin-right:1px\"> ";
	h+=" <FONT color=\"#2C4D90\" style=\"font-size:13px\" face=\"Verdana\" ><b>"+ttitleright+"</b></FONT>";
    h+=" </div>";
	h+="</td> "; 
	return h;
}

CGp.styledTitle=function(ttitleleft,ttitleright,divname)
{
    var h="<td height=\"25\"  align=\"left\" valign=\"middle\" bgcolor=\"#D6E1EB\">"; 
    h+=" <div id=" + divname +" style=\"margin-left:5px\"> ";
	h+=t.styledTitlewithID(ttitleleft);
	h+=" </div>";
	h+=" </td> "; 
	h+=" <td height=\"25\" align=\"right\" valign=\"middle\" bgcolor=\"#D6E1EB\">"; 
    h+=" <div style=\"margin-right:1px\"> ";
	h+=" <FONT color=\"#2C4D90\" style=\"font-size:13px\" face=\"Verdana\" ><b>"+ttitleright+"</b></FONT>";
    h+=" </div>";
	h+="</td> "; 
	return h;
}

CGp.styledRegisteredTitle=function(ttitleleft,ttitleright,divname)
{
    var h="<td height=\"25\" align=\"left\" colspan=\"3\" valign=\"middle\" bgcolor=\"#D6E1EB\">"; 
    h+=" <div id=" + divname +" style=\"margin-left:5px\"> ";
	h+=t.styledTitlewithID(ttitleleft);
	h+=" </div>";
	h+=" </td> "; 
	return h;
}

CGp.styledTableTitle=function(ttitleleft,twidth)
{
    var h="<td height=\"25\"";
	if (twidth>0)
		h+=" width=\""+twidth+"\" ";
	h+=" align=\"left\" valign=\"middle\" bgcolor=\"#D6E1EB\">"; 
    h+=" <div style=\"margin-left:0px\"> ";
	h+=" <FONT color=\"#2C4D90\" style=\"font-size:11px\" face=\"Verdana\" ><b>"+ttitleleft+"</b></FONT>";
    h+=" </div>";
	h+="</td> "; 
    
 return h;
}


CGp.SetImage=function(div_id_name, img_type)
{
	var h="http://www.strategyxchange.com/Matrix/images/BtnBuildPort.gif";
	if (div_id_name=="BP_button") 
		{
		if (img_type == "out")
			h="http://www.strategyxchange.com/Matrix/images/BtnBuildPort.gif";
		if (img_type == "over")
			h="http://www.strategyxchange.com/Matrix/images/BtnBuildPort1.gif";
		document.BP_button.src=h;
		}
	if (div_id_name=="FT_button") 
		{
		if (img_type == "out")
			h="http://www.strategyxchange.com/Matrix/images/BtnFreeTrial.gif";
		if (img_type == "over")
			h="http://www.strategyxchange.com/Matrix/images/BtnFreeTrial1.gif";
		document.FT_button.src=h;
		}
	if (div_id_name=="SC_button") 
		{
		if (img_type == "out")
			h="http://www.strategyxchange.com/Matrix/images/BtnSelectStrategies.gif";
		if (img_type == "over")
			h="http://www.strategyxchange.com/Matrix/images/BtnSelectStrategies1.gif";
		document.SC_button.src=h;
		}
	if (div_id_name=="UPR_button") 
		{
		if (img_type == "out")
			h="http://www.strategyxchange.com/Matrix/images/BtnUpdPortRes.gif";
		if (img_type == "over")
			h="http://www.strategyxchange.com/Matrix/images/BtnUpdPortRes1.gif";
		document.UPR_button.src=h;
		}
	if (div_id_name=="PP_button") 
		{
		if (img_type == "out")
			h="http://www.strategyxchange.com/Matrix/images/BtnBuyPortfolio.gif";
		if (img_type == "over")
			h="http://www.strategyxchange.com/Matrix/images/BtnBuyPortfolio1.gif";
		document.PP_button.src=h;
		}
	if (div_id_name=="ST_button") 
		{
		if (img_type == "out")
			h="http://www.strategyxchange.com/Matrix/images/BtnSubmit.gif";
		if (img_type == "over")
			h="http://www.strategyxchange.com/Matrix/images/BtnSubmit1.gif";
		document.ST_button.src=h;
		}
	
} 

// --------------------------------------------------------------------------------
//
// SetEnlargeCode
//
// --------------------------------------------------------------------------------
CGp.SetEnlargeCode=function()
	{
		var t=this, strPageName	= "Empty_chart_code", style_value="Empty_chart_code";
		
		t.firstRow=t.setFirstRow();	
		if (t.firstRow != -1 && t.Phase==1)
		{
			var productId=t.getProductId(t.firstRow);
			var params = "http://www.strategyxchange.com/Charts/"+productId+"/chart_large.xml";	
			strPageName = t.DrawChartObject(params,"strategy_popup_charts",820,410);	
		//	style_value = t.DrawLargeChartStyle(params,820,410);
		}
		var h="";
		h+="<div id=draw_chart_code>";
		h+="<input type='hidden' id=xx_chart_code name='xx_chart_code' value='"+strPageName+"'></input>";
		h+="</div></td><td>";
		h+="<div id=draw_chart_style>";
		h+="<input type='hidden' id=xx_chart_style name='x1_chart_style' value='Empty_chart_style'></input>";
		h+="</div>";
		return h;
	};
	


// --------------------------------------------------------------------------------
//
// topFirstPagetoHTML		
//
// --------------------------------------------------------------------------------
CGp.topFirstPagetoHTML=function()
  {
	var t=this,s="",s1="",s2="",a="",f="",i,j,k,idx,useEdit=t.useEdit,colspan=t.cols.length;
	
	var imgTooltip = "<img src=\"http://www.strategyxchange.com/Matrix/images/info_help.gif\"></img>";
	var tooltip_text_inner="Select your strategies criteria, check mark one or more strategies, click Build Portfolio"; 
	tooltip_text_inner = "<SPAN title=\"" +tooltip_text_inner+"\" class=\"popup\" >"+imgTooltip+"</SPAN>"; 
	
	var h=t.emptystyledTablewithPadding(5);
	//open table 1
	h+="<tr>";
	h+=t.pageTitletoHTML();
	h+="</tr>";
	h+="</table>";
	//closed table 1
				
	h+=t.emptystyledTablewithPadding(5); 
  	//open table 2
	h+="<tr><td align=\"left\" valign=\"top\">";
	h+=t.styledTable(t.tableLeftWidth);
	//open table 2.1
	
	h+="<tr>";
	h+=t.styledTitle("Select Criteria",tooltip_text_inner,"filters_titles_div");

	h+="</tr>";
    h+="<tr><td colspan=2>";
				
	h+=t.emptystyledTablewithPadding(5);
	//open table 2.1.1
	
	h+="<tr>"+((useEdit)?"<td class=\""+t.tableStyle.thClass+"\">&nbsp;</td>":"");
		
	var isTitle = true;		
	var sortFilters = new Array(9);
	for(i=0;i<t.cols.length;i++)
		{
				switch(t.cols[i].title) 
					{
					case "Vendor":	sortFilters[0] = i; break;
					case "S. Capital":	sortFilters[1] = i; break;
					case "Markets":	sortFilters[2] = i; break;
					case "Total P&L":	sortFilters[3] = i; break;
					case "Frequency":	sortFilters[4] = i; break;
					case "Drawdown":	sortFilters[5] = i; break;
					case "Cost*":	sortFilters[6] = i; break;
					case "Age":	sortFilters[7] = i; break;
					case "Default":	sortFilters[8] = -1; break;
					}
		}
	isTitle = true;
	var filters_text="";
	for(j=0;j<8;j++)
		{
		a="";
		var i=sortFilters[j];
		if (t.cols[i].useAutoFilter && t.cols[i].isVisible) 
			{
				if (isTitle)
					{
					filters_text+="<tr>";
					filters_text+="<th bgcolor='#FFFFFF' height='23' aligh='left'"+a+" "+t.cols[i].width+">";
					filters_text+="<div nowrap align='left'; margin-bottom:7px;>"+t.cols[i].title+":</div></th>";
					filters_text+="<th vailgn='top' vailgn='left' aligh='left'><div nowrap align='left'; margin-bottom:5px;>"+t.cols[i].filterToHTML()+"</div></th>";
					isTitle = false;
					}
				else 
					{
					filters_text+="<th bgcolor='#FFFFFF' height='23' aligh='left'"+a+" "+t.cols[i].width+">";
					filters_text+="<div nowrap align='left'; margin-bottom:7px;>"+t.cols[i].title+":</div></th>";
					filters_text+="<th vailgn='top' vailgn='left' aligh='right'><div nowrap align='left'; margin-bottom:7px;>"+t.cols[i].filterToHTML()+"</div></th>";
					filters_text+="</tr>";
					isTitle = true;
					}
			}
				
		}
	if (!isTitle)
			filters_text+="</tr>";
	h+=filters_text;
	h+="<tr></tr>";
			
		
	h+="</tr>";
	h+="</table>";
	//close table 2.1.1
	
	h+="</td></tr>";
	h+="</table>";
	//close table 2.1
	
	h+=t.ButtonDrawPortfolio();
	h+="</td><td>";
	
	var selectedRow = 1;
	t.firstRow=t.setFirstRow();	
	
	if (t.selectedRow != -1)
		selectedRow=t.selectedRow;
	else if (t.firstRow != -1)
		selectedRow=t.firstRow;
		
	var strPageName = "http://www.strategyxchange.com/Matrix/portfolio/chart.xml";
	var strategyname="AngleD:Dow Daily";
	
	var Strategydata=new String(t.cells[selectedRow][t.StrategyCol].getDataForFilter());
	var Vendordata=new String(t.cells[selectedRow][t.VendorCol].getDataForFilter());
	strategyname=Strategydata.substring(Strategydata.indexOf(":")+1,Strategydata.length);
	if ((strategyname.length + Vendordata.length) < 40)
			strategyname=Vendordata+" : "+strategyname;
	var productId=t.getProductId(selectedRow);
	strPageName = "http://www.strategyxchange.com/Charts/"+productId+"/chart.xml";	
	
	h+=t.styledTable(t.tableRightWidth);
    //open table 2.2
	h+="<tr>";
	var strOpenPageName = "http://www.strategyxchange.com/Matrix/showcharts.html";
			
	var imgControl = "<a href=\""+strOpenPageName+"\" onclick=\"window.open(this.href);return false;\" target=\"new\"><img border=\"0\" src=\"http://www.strategyxchange.com/Matrix/images/enlarge.gif\"></img></a>";
	
	h+=t.styledTitle(strategyname,imgControl,"draw_strategy_title");
	h+="</tr>";
	h+="<tr>";
	h+="<td colspan=2 width=\"100%\" height=\"200\">";
		 
	h+="<div id=draw_strategy_chart>";
	t.chartHTML=t.DrawChartObject(strPageName,"strategy_charts",t.tableRightWidth,200);
	h+=t.chartHTML;
	h+="</div>";

	h+="</td></tr>";
	h+="</table>";
	//close table 2.2
	
	h+="</td></tr>";
	h+="</table>";
	//close table 2
	
	return h;
};

CGp.CountVisibleRows=function()
  {
	  var rowCount=0;
	  for (i=0;i<t.rows.length;i++)
	  	if (t.rows[i].isVisible)
			rowCount+=1;
	return rowCount;
  }

CGp.ButtonDrawSubmit=function()
  {
	var t=this;
	var font_style = "<FONT style=\"font-size:9px\" face=\"Verdana\" style=\"font-weight:normal\">";
	 
 	h="<table cellpadding=\"5\" cellspacing=\"0\" width=\""+t.tableBottomWidth+"\" border=\"0\">";
	// open table 3
	
	h+="<tr><td align=\"left\" width=\"155\"><div nowrap align='left'; margin-bottom:2px; margin-left:2px;>";
	h+="<a onMouseOver=\"t.SetImage('SC_button','over');return true;\" onMouseOut=\"t.SetImage('SC_button','out');return true;\">";
	h+="<img name=SC_button src=\"http://www.strategyxchange.com/Matrix/images/BtnSelectStrategies.gif\" border=\"0\" onclick=\"t.SelectStrategies()\"></img>";
	h+="</a></div></td>";
	
 	h+="<td aligh='left'><div nowrap align='left'; margin-bottom:2px; margin-left:2px;>";
	h+="<a onMouseOver=\"t.SetImage('ST_button','over');return true;\" onMouseOut=\"t.SetImage('ST_button','out');return true;\">";
	h+="<img name=ST_button src=\"http://www.strategyxchange.com/Matrix/images/BtnSubmit.gif\" border=\"0\" onclick=\"t.SubmitFreeTrial();\"></img>";
	h+="</a></div></td>";
	
	h+="</tr>";
	h+="</table>";
	return h;
  };

CGp.ButtonDrawPortfolio=function()
  {
	var t=this;
	var font_style = "<FONT style=\"font-size:9px\" face=\"Verdana\" style=\"font-weight:normal\">";
	
    var h="<table cellpadding=\"0\" align=\"left\" width=\""+t.tableLeftWidth+"\" valign=\"bottom\" cellspacing=\"0\" border=\"0\">";
 
 	h+="<tr><td colspan=\"3\" height='10' aligh='left'><div nowrap align='left'; valign='bottom' margin-top:5px; margin-bottom:0px; margin-left:5px;>";
	h+="</div></td>";
	h+="</tr>";
	h+="<tr><td height='15' width=\"150\" aligh='left'><div id=total_systems_fit_text align='left'; valign='bottom' margin-top:5px; margin-bottom:0px; margin-left:10px;>";
	h+=font_style+t.CountVisibleRows()+ " systems fit the criteria</FONT>";
	h+="</div></td>";
	h+="<td></td><td align='right'><div align='right' valign='bottom' margin-top:5px; margin-bottom:0px; margin-right:10px;>"+font_style+t.utilsToHTML()+"</FONT></div></td>";
	h+="</tr>";
	h+="<tr><td height='15' width=\"150\" aligh='left'><div id=total_systems_selected_text align='left'; valign='bottom' margin-top:5px; margin-bottom:0px; margin-left:10px;>";
	h+=font_style+t.checkedCount+ " systems are selected</FONT>";
	h+="</div></td><td></td><td></td>";
	h+="</tr>";
	
	h+="<tr>";
	h+="<td height='33' width=\"150\" aligh='left'><div nowrap align='left'; valign='bottom' margin-top:10px; margin-bottom:0px; margin-left:0px;>";
	h+="<a onMouseOver=\"t.SetImage('BP_button','over');return true;\" onMouseOut=\"t.SetImage('BP_button','out');return true;\">";
	h+="<img name=BP_button src=\"http://www.strategyxchange.com/Matrix/images/BtnBuildPort.gif\" border=\"0\" onclick=\"t.BuildPortfolio()\"></img>";
	h+="</a>";
	h+="</div></td>";
	
	h+="<td height='33' aligh='left'><div nowrap align='left'; valign='bottom' margin-top:10px; margin-bottom:0px; margin-left:0px;>";
	h+="<a onMouseOver=\"t.SetImage('FT_button','over');return true;\" onMouseOut=\"t.SetImage('FT_button','out');return true;\">";
	h+="<img name=FT_button src=\"http://www.strategyxchange.com/Matrix/images/BtnFreeTrial.gif\" border=\"0\" onclick=\"t.FreeTrial()\"></img>";
	h+="</a>";
	h+="</div></td>";
	h+="<td align='right'><div align='right' valign='bottom' margin-top:5px; margin-bottom:0px; margin-right:10px;>"+font_style+t.pageTurnToHTML()+"</FONT></div></td>";
	
	h+="</tr>";
	h+="</table>";
	return h;
  };


CGp.topSecondPagetoHTML=function()
  {
	var t=this,s="",s1="",s2="",a="",f="",i,j,k,idx,useEdit=t.useEdit,colspan=t.cols.length;
	
	var h=t.emptystyledTablewithPadding(5);
	h+="<tr>";
	h+=t.pageTitletoHTML();
	h+="</tr>";
	h+="</table>";
	
	h+=t.emptystyledTablewithPadding(5);
	// open table 2
	h+="<tr><td valign=\"top\">";
	
	h+="<div id=draw_strategy_statistics>";
	t.statisticsHTML = t.SetPortfolioStatistics(-1);
	h+=	t.statisticsHTML;
	h+=	"</div>";

	h+="</td><td>";

	// open table 2.1
	h+=t.styledTable(t.tableRightWidth);
    h+="<tr>";
	
	var strOpenPageName = "http://www.strategyxchange.com/Matrix/showcharts.html";
	var imgControl = "<a href=\""+strOpenPageName+"\" onclick=\"window.open(this.href);return false;\" target=\"new\"><img border=\"0\"  src=\"http://www.strategyxchange.com/Matrix/images/enlarge.gif\"></img></a>";
		
	h+=t.styledTitle("Portfolio Equity Curve ($)",imgControl,"draw_strategy_title"); 
    h+="</tr>";
	h+="<tr>";
	h+="<td colspan=2 width=\"100%\" height=\"200\">";
	 
	var strPageName = "http://www.strategyxchange.com/Matrix/portfolio/chart.xml";
	
	h+="<div id=draw_strategy_chart>";
	t.chartHTML=t.DrawChartObject(strPageName,"strategy_charts",t.tableRightWidth,200);
	h+=t.chartHTML;
	h+="</div>";
	
	h+="</td></tr>";
	// close table 2.1
	h+="</table>";
	h+="</td></tr>";
	// closetable 2
	h+="</table>";
				
	h+="<table cellpadding=\"5\" cellspacing=\"0\" width=\""+t.tableBottomWidth+"\" border=\"0\">";
	// open table 3
	
	h+="<tr><td align=\"left\" width=\"155\">";
	h+="<div nowrap margin-bottom:2px; margin-left:2px;>";
	h+="<a onMouseOver=\"t.SetImage('SC_button','over');return true;\" onMouseOut=\"t.SetImage('SC_button','out');return true;\">";
	h+="<img name=SC_button src=\"http://www.strategyxchange.com/Matrix/images/BtnSelectStrategies.gif\" border=\"0\" onclick=\"t.SelectStrategies()\"></img>";
	h+="</a></div></td>";
	
	h+="<td align=\"left\">";
	h+="<div nowrap margin-bottom:2px; margin-left:2px;>";
	h+="<a onMouseOver=\"t.SetImage('UPR_button','over');return true;\" onMouseOut=\"t.SetImage('UPR_button','out');return true;\">";
	h+="<img name=UPR_button src=\"http://www.strategyxchange.com/Matrix/images/BtnUpdPortRes.gif\" border=\"0\" onclick=\"t.UpdatePortfolioResults()\"></img>";
	h+="</a></div></td>";
	
	h+="<td align=\"right\" width=\"155\">";
	h+="<div nowrap align=\"right\" margin-bottom:2px;margin-left:2px;>";
	h+="<a onMouseOver=\"t.SetImage('FT_button','over');return true;\" onMouseOut=\"t.SetImage('FT_button','out');return true;\">";
	h+="<img name=FT_button src=\"http://www.strategyxchange.com/Matrix/images/BtnFreeTrial.gif\" border=\"0\" onclick=\"t.FreeTrial()\"></img>";
	h+="</a></div></td>";
	
	h+="<td align=\"right\" width=\"155\">";
	h+="<div nowrap align=\"right\" margin-bottom:2px;margin-left:2px;>";
	h+="<a onMouseOver=\"t.SetImage('PP_button','over');return true;\" onMouseOut=\"t.SetImage('PP_button','out');return true;\">";
	h+="<img name=PP_button src=\"http://www.strategyxchange.com/Matrix/images/BtnBuyPortfolio.gif\" border=\"0\" onClick=\"javascpipt:ft.submit()\"></img>";
	h+="</a>";
	h+="</div></td>";

	h+="</tr>";
	h+="</table>";
	// close table 3
	return h;
};


CGp.topThirdPagetoHTML=function()
  {
	var t=this;
	var imgTooltip = "<img src=\"http://www.strategyxchange.com/Matrix/images/info_help.gif\"></img>";
	var tooltip_text_inner="Fill in Strategy Runner platform information"; 
	
	var h = "<form name=\"f"+t.name+"\" method=\"POST\" action=\"http://www.strategyrunner.com/Registration/SendMail.php\">"; 
	h+=t.emptystyledTablewithPadding(5);
	//open table 1
	h+="<tr>";
	h+=t.pageTitletoHTML();
	h+="</tr>";
	h+="</table>";
	//close table 1
	
	h+=t.emptystyledTablewithPadding(5);
	//open table 2
	h+="<tr><td>";
	h+=t.styledTable(t.tableBottomWidth);
	//open table 2.1
	h+="<tr><td>";
	h+=t.emptystyledTablewithPadding(5);
	h+="<tr><td>";
	//open table 2.1.1
	h+="&nbsp;You have selected the following "+t.checkedCount+" strategies:<br>";
	h+="<input name=\"Number_of_strategies\" value=\""+t.checkedCount+"\" type=\"hidden\" />";

	var cParam=0;
	for(i=0;i<t.rows.length;i++)
		if (t.isCheckedRow(i))
			{
			var prodID = t.getProductId(i);
			h+="<input name=\"Strategy_"+cParam+"\" value=\""+prodID+"\" type=\"hidden\" />";
			cParam++;
			}
			  
	h+=t.tableHTML; 
	h+="</td><td valign=\"top\">";
	h+=t.emptystyledTablewithPadding(5);
	h+="<tr><td>";
	
	h+="<br>";
	h+="These systems will be auto-executed on your simulated/demo SR account. ";
	h+="In order to view systems performance you need to have an active SR simulated account and have the SR Demo Platform installed on your computer.<br><br>";
	h+="Fill in the form and click Submit. <br>";
	h+="Fields marked with * are required <br>";
	h+="</td></tr>";
	h+="</table>";
	//close table 2.1.1
	h+="</td></tr>";
	h+="</table>";
	h+="</td></tr>";
	h+="</table>";
	//close table 2.1
	h+="</td></tr>";
	h+="</table>";
	//Close table 2
	
	
//	h+=	"</td></tr><tr><td>&nbsp;";
	h+=	"</td></tr><tr><td valign=\"top\">";
	
	h+=t.emptystyledTable(5);
	// close table 2.3
	h+="<tr><td valign=\"top\">";
	// close table 2.3.1
	
	
	h+=t.emptystyledTablewithPadding(5);
	// Open table 1
	h+="<tr><td valign=\"top\">";
	
	h+=t.styledTable(t.tableLeftWidth-20);
    // open table 2
	h+="<tr>";
	tooltip_text_inner="Fill in Personal information"; 
	tooltip_text_inner = "<SPAN title=\"" +tooltip_text_inner+"\" class=\"popup\" >"+imgTooltip+"</SPAN>"; 
	
	h+=t.styledRegisteredTitle("Personal Information",tooltip_text_inner,"Personal_Info_div"); 
  	h+="</tr>";
	h+=t.SetRegistrationLine("","*User Name","<input name=\"username\" type=\"text\" value=\"\" />");
	h+=t.SetRegistrationLine("","*Password","<input name=\"password\" type=\"text\" value=\"\" />");
	h+=t.SetRegistrationLine("","*Repeat Password","<input name=\"repeat_password\" type=\"text\" value=\"\" />");
	h+=t.SetRegistrationLine("","*First Name","<input name=\"first_name\" type=\"text\" value=\"\" />");
	h+=t.SetRegistrationLine("","*Last Name","<input name=\"last_name\" type=\"text\" value=\"\" />");
	h+=t.SetRegistrationLine("","City","<input name=\"city\" type=\"text\" value=\"\" />");
	h+=t.SetRegistrationLine("","State","<input name=\"state\" type=\"text\" value=\"\" />");
	h+=t.SetRegistrationLine("","Country",t.CountryCombo());
	h+=t.SetRegistrationLine("","*Daytime Phone Number","<input name=\"phone_number\" type=\"text\" value=\"\" />");
	h+=t.SetRegistrationLine("","*E-mail Address","<input name=\"email\" type=\"text\" value=\"\" />");
	 
	h+="</table>";
	// close table 2
	
	h+="</td></tr>";
	h+="</table>";
	// close table 1
	
	h+="</td><td valign=\"top\">";
	
	h+=t.emptystyledTablewithPadding(5);
	h+="<tr><td valign=\"top\">";
	// open table 1
	
	h+="<div id=draw_sr_info>";
	h+=t.styledTable(t.tableRightWidth+20);
	// open table 2
	h+="<tr>";
	tooltip_text_inner="Fill in Strategy Runner platform information"; 
	tooltip_text_inner = "<SPAN title=\"" +tooltip_text_inner+"\" class=\"popup\" >"+imgTooltip+"</SPAN>"; 
	
	h+=t.styledRegisteredTitle("Strategy Runner Information",tooltip_text_inner,"SR_Info_div"); 
    h+="</tr>";
	h+=t.SetRegistrationLine("<input name=\"SR_user\" type=\"radio\" value=\"I'm a new client\" checked/>","I'm a new client","");
	h+=t.SetRegistrationLine("<input name=\"SR_user\" type=\"radio\" value=\"I have a SR Demo or SR Educator\" />","I have a SR Demo or SR Educator","");
	h+=t.SetRegistrationLine("<input name=\"SR_user\" type=\"radio\" value=\"I'm already using SR Console to trade my live account\" />","I'm already using SR Console to trade my live account","");
	h+=t.SetRegistrationLine("","User Name","<input name=\"active_user_name\" type=\"text\" value=\"\" />");
	h+=t.SetRegistrationLine("","Server Name","<input name=\"active_server_name\" type=\"text\" value=\"\" />");
	h+="</table>";
	// close table 2
	h+=	"</div>";
	
	h+=	"</td></tr><tr><td valign=\"top\">";
	h+=t.styledTable(t.tableRightWidth+20);
    h+="<tr>";
	tooltip_text_inner="Fill in Account and Broker information"; 
	tooltip_text_inner = "<SPAN title=\"" +tooltip_text_inner+"\" class=\"popup\" >"+imgTooltip+"</SPAN>"; 
	
	h+=t.styledRegisteredTitle("Account and Broker Information (optional)",tooltip_text_inner,"Broker_Info_div"); 
  	h+="</tr>";
	//h+=t.SetRegistrationLine("<input name=\"Broker_user\" type=\"radio\" value=\"1\" checked/>","I don't have an account","");
	h+=t.SetRegistrationLine("<input name=\"Broker_user\" type=\"checkbox\" value=\"2\" />","I have or plan to open an account with following broker","");
	h+=t.SetRegistrationLine("","Broker Name","<input name=\"broker_name\" type=\"text\" value=\"\" />");
	h+=t.SetRegistrationLine("","Broker Website","<input name=\"broker_website\" type=\"text\" value=\"\" />");

	 
	h+="</table>";
	// close table 2.3.2
	h+="</td></tr>";
	h+="</table>";
	
	h+="</td></tr>";
	
	h+="<tr><td colspan='2'>";
	h+="<input name=\"IAgree\" type=\"checkbox\" value=\"\" /><b>I understand</b> that in order to receive a free trial, my personal information will be send to vendors of the chosen strategies.";
	h+="</td></tr>";
	
	h+="</table>";
	
	h+=t.ButtonDrawSubmit();
	
	h+=t.emptystyledTablewithPadding(5);
	h+="<tr><td>";
	h+=t.styledTable(t.tableBottomWidth);
	// open table 2.2
	h+="<tr>";
	tooltip_text_inner="SR Demo Platform description"; 
	tooltip_text_inner = "<SPAN title=\"" +tooltip_text_inner+"\" class=\"popup\" >"+imgTooltip+"</SPAN>"; 
	
	h+=t.styledRegisteredTitle("SR Demo Platform description",tooltip_text_inner,"SR_Info_div"); 
    h+="</tr>";
	h+="<tr><td width=\"237\" height=\"140\" align=\"center\">";
	h+=t.emptystyledTablewithPadding(5);
	h+="<tr><td>";
	h+="<a href=\"http://www.strategyrunner.com/Registration/AddStrategiesForex/AddStrategies.swf\" target=\"new\">";
	h+="<img border=\"0\" src=\"http://www.strategyrunner.com/Content/images/Strategies/SRProScreen.gif\" align=\"absmiddle\" width=\"275\" height=\"238\" >";
	h+="</img></a>";
	h+="</td></tr>";
	h+="</table>";
	h+="</td><td valign=\"top\">";
	h+=t.emptystyledTablewithPadding(5);
	h+="<tr><td valign=\"top\">";
	h+="Your strategies will be auto-executed on your simulated account via SR servers.<br><br>";
	h+="You will be able to monitor strategies performance on your SR Demo platform from your office, home or any other computer. <br><br>";
	h+="You can trade along with the strategies.<br><br>"; 
	h+="You can manage strategies online through SR Demo platform. Add, stop (take profit or trade out), and liquidate strategies at any time. <br><br>";
	h+="</td></tr>";
	h+="</table>";
	h+="</td></tr>";
	h+="</table>";
	h+="</td></tr>";
	h+="</table>";
	h+="</form>";
	// close table 2.2
	

	// close table 2
	return h;
};

CGp.DisclaimertoHTML=function()
  {
	var t=this;
		
	var h=t.emptystyledTable();
	h+="<tr><td>";
	h+=t.styledTable(t.tableBottomWidth);
	h+="<tr><td>";
	var h=t.emptystyledTablewithPadding(5);
	h+="<tr><td>";
	
	h+= "<br><br>*Please note that the use of forex automated strategies will include an additional 1 pip in commissions per trade.<br><br>";
	h+= "<b><i>Hypothetical Performance Disclaimer:</b> "; 
	h+= "Results do not take into effect monthly subscription fees and transactions costs. ";
	h+= "Hypothetical or simulated performance results have certain inherent limitations. Unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not actually been executed, the results may have under- or over-compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profits or losses similar to those shown.</i>";
	
	h+="</td></tr>";
	h+="</table>";
	h+="</td></tr>";
	h+="</table>";
	h+="</td></tr>";
	h+="</table>";
				
	return h;
};



CGp.tabletoHTML=function()
  {
	var t=this,s="",s1="",s2="",a="",f="",i,j,k,useBrowsingFilter=0,useAutoFilter=0,idx,useEdit=t.useEdit,colspan=t.cols.length;
	if (t.onlyTop) 
	  	t.tableBottomWidth = t.tableStyle.width;
	var h = "";
	if (t.Phase < 3) 
    	h="<form name=\"f"+t.name+"\" method=\"POST\" action=\"http://www.strategyxchange.com/SearchResults.asp\">";
	h+=t.emptystyledTable();
	// open table 1		
	if (t.onlyTop) 
	h+=t.emptystyledTable();
	else
	h+=t.emptystyledTablewithPadding(5);
	// open table 1.1		
	h+="<tr><td>";
	if (t.Phase < 3) h+=t.styledTableTable(t.tableBottomWidth);
    else h+=t.styledTableTable(t.tableLeftWidth-30);
	                    
    // open table 1.1.1		
	
	if(useEdit)
		{
		colspan++;
		if(!t.editClass) t.editClass=t.tableStyle.thClass;
		};
		
	h+="<tr>"+((useEdit)?"<td class=\""+t.tableStyle.thClass+"\">&nbsp;</td>":"");
	for(i=0;i<t.cols.length;i++)
		{
		a=((Def(t.cols[i].titleClass))?" class=\""+t.cols[i].titleClass+"\"":" class=\""+t.tableStyle.thClass+"\"");
		if(t.cols[i].isVisible)
			{
			if (i==t.CheckedCol)
				h+=t.styledTableTitle("<input name=\"titleall\" id=\"combo_title\" type=\"checkbox\" align=\"center\" value=\"\" onclick=\"t.checkall(this.checked)\" />",0); //
			else
				h+=t.styledTableTitle(t.cols[i].titleToHTML(t.cols[i].sortType),t.cols[i].width); 
			}
		if(t.cols[i].useAutoIndex&&!t.cols[i].index.length) t.setIndex(i);
		if(t.cols[i].useAutoFilter&&!t.cols[i].filter.length) t.cols[i].setFilter();
			useAutoFilter=useAutoFilter||t.cols[i].useAutoFilter;
		}
	h+="</tr>";
	if(useEdit)
		{
		h+="<tr class=\""+t.editClass+"\"><td>"+t.editTitle+"</td>";
		for(i=0;i<t.cols.length;i++)
			{
			if(t.cols[i].isVisible)h+="<td class=\""+t.editClass+"\" id='"+t.getID('edit'+i)+"' "+t.cols[i].alignment+">&nbsp;</td>";
			};
		h+="</tr>";
		};
	if(!t.vr.length)
		{
		for(i=0;i<t.rowIndex.length;i++)
			if(t.rows[t.rowIndex[i]].isVisible)
				t.vr[t.vr.length]=t.rowIndex[i];
	  	}
	a=t.amountPerPage;
	k=0;
	t.pageCount=((t.vr.length%a==0)?(t.vr.length/a):(Math.floor(t.vr.length/a)+1));
	s=(t.page-1)*a;
	f=(t.page*a<t.vr.length)?t.page*a:t.vr.length;
	for(i=s;i<f;i++)
		{
		idx=t.vr[i];
		if(s1==t.rowStyle.darkClass)
			s1=t.rowStyle.lightClass;
		else 
			s1=t.rowStyle.darkClass;
		t.rows[idx].css=s1;
		if(t.rows[idx].isMark)
			s2=t.rowStyle.markClass;
		else s2=s1;a=" class=\""+s2+"\" onClick=\""+t.name+".rows["+idx+"].setMark();\""+" onMouseOver=\""+t.name+".rows["+idx+"].setHover();\"";
		if(k==0)
			h+="<tr id=\""+t.name+"_row_"+idx+"\""+a+">";else h+="</tr><tr id=\""+t.name+"_row_"+idx+"\""+a+">";if(useEdit)h+="<td>"+((t.rows[idx].isChange)?t.editIndicator:"")+"</td>";
		for(j=0;j<t.cols.length;j++)
			{
			if(t.cols[j].isVisible&&Def(t.cells[idx][j]))
				h+="<td "+t.cols[j].alignment+" class='"+((Def(t.cols[j].cellClass))?t.cols[j].cellClass:((ua.nn4)?s2:""))+"'>"+t.cells[idx][j].getData()+"</td>";
	  		}
		k++;
	 	};
	h+="</tr>";
	
	h+="</table>";
	// close table 1.1.1	
	h+="</td></tr></table>";
	// close table 1.1	
	h+="</table>";
	// close table 1	
	if (t.Phase < 3) h+="</form>";
//	alert("close form f" + t.name);
	t.firstRow=t.setFirstRow();	
	
	return h;
};
	  
CGp.getProductId=function(row)
	{
	var t=this;
	var lots_data = new String(t.cells[row][t.LotsCol].getDataForFilter());
	var Pos = lots_data.search(":");
	var value = lots_data.substring(0,Pos);
	return value;
	};

CGp.CalculatecheckedCount=function()
{
	var h="",t=this, count=0;
		
	for(i=0;i<t.rows.length;i++)
		{
		var checked_data = new String(t.cells[i][t.CheckedCol].getDataForFilter());
		var Pos = checked_data.search(":");
		if (Pos != -1)
			{
			if (checked_data.substring(Pos+1,checked_data.length) == "true") 
				count+=1;
			}
		}
	return count;
};

CGp.checkboxtest=function(product_id,checked)
{
	var h="",t=this;
	var changed=false;
	//var id_name=CodeThat.findElement("cb_itemId_"+product_id);
	//var ifchecked = "false";
	//if (Def(id_name) && id_name!=null && id_name.checked)
	//	ifchecked = "true";
		
	for(i=0;i<t.rows.length;i++)
		{
		if (t.rows[i].isVisible)
			{
				var checked_data = new String(t.cells[i][t.CheckedCol].getDataForFilter());
				var Pos = checked_data.search(":");
				var value = checked_data;
				var row_checked = "false";
				if (Pos == -1)
					{ if (checked) changed = true; row_checked = "true"; }
				else
					{
					value = checked_data.substring(0,Pos);
					row_checked = checked_data.substring(Pos+1,checked_data.length);
					if (checked && row_checked == "false") { changed = true; row_checked = "true";  }
					if (!checked && row_checked == "true") { changed = true; row_checked = "false";  }
					}
				if (product_id == value)
					{
					t.cells[i][t.CheckedCol].setData(product_id+":"+row_checked);
					if (changed && checked) t.checkedCount+=1;  
					if (changed && !checked) t.checkedCount-=1; 
					break;
					}
			}
		}
	if (t.Phase == 1)
		t.setTotalSystemsText();
	return h;
};

CGp.isCheckedRow=function(row)
	{
	var t=this;
		
	var checked_data = new String(t.cells[row][t.CheckedCol].getDataForFilter());
	var Pos = checked_data.search(":");
	if (Pos == -1)
		return false;
	var value = checked_data.substring(Pos+1,checked_data.length);
	if ( value == "true" ) 
		return true;
	else 
		return false;
	};
	
CGp.checkall=function(ifchecked)
{		
	var t=this;
	for(i=0;i<t.rows.length;i++)
		{
		var changed=false;
		var checked_data = new String(t.cells[i][t.CheckedCol].getDataForFilter());
		var Pos = checked_data.search(":");
		var row_checked = "false";
		var product_id = checked_data;
		if (Pos == -1)
			{ if (ifchecked) changed = true; row_checked = "true"; } 
		else
			{
			row_checked = checked_data.substring(Pos+1,checked_data.length);
			if (ifchecked && row_checked == "false") { changed = true; row_checked = "true";  }
			if (!ifchecked && row_checked == "true") { changed = true; row_checked = "false";  }
			product_id = checked_data.substring(0,Pos);
			}
		
		if (changed)
			{
				var id_name=CodeThat.findElement("cb_itemId_"+product_id);
				if (Def(id_name) && id_name!=null) 
					{
					id_name.checked = ifchecked;
					if (ifchecked) t.checkedCount+=1; 
					if (!ifchecked) t.checkedCount-=1; 
					t.cells[i][t.CheckedCol].setData(product_id+":"+row_checked);
				//	alert("set checkbox=" + product_id+":"+row_checked); 
					}
				else if (!ifchecked)
					{
					t.cells[i][t.CheckedCol].setData(product_id+":"+row_checked);
					}
			}
		}
	if (!ifchecked) t.checkedCount=0;
	if (t.Phase == 1)
		t.setTotalSystemsText();
					
	return true;
	
};

CGp.checkSubmit=function()
{		
	var t=this;
	for(i=0;i<t.rows.length;i++)
		{
		var value = t.getProductId(i);
		var id_name=CodeThat.findElement("cb_itemId_"+value);
		if (Def(id_name) && id_name!=null) 
			{
			alert("checkbox " + value+";"+id_name.checked+";"+id_name.name);
			}
		var id_name_text=CodeThat.findElement("textB_"+value);
		if (Def(id_name_text) && id_name_text!=null) 
			{
			alert("lots " + value+";"+id_name_text.value+";"+id_name_text.name);
			}
		}
		
	return true;
};

CGp.lotsOnEdit=function(lvalue,lname)
{
	var h="", t=this;
	var Pos = lname.indexOf(".");
	var product_id=lname.substring(Pos+1,lname.length);
	for (i=0; i<t.rows.length; i++)
		if (t.rows[i].isVisible)
			{ 
			var checked_data = new String(t.cells[i][t.CheckedCol].getDataForFilter());
			var Pos1 = checked_data.search(":");
			var value = checked_data;
			if (Pos1 != -1)
				value = checked_data.substring(0,Pos1);
			if (product_id == value)	
				{
					t.cells[i][t.LotsCol].setData(product_id+":"+lvalue);
					return h;
				}
			}
	return h;
};
	  
CGp.fromCSV=function(s,spt)
  {
		var t=this,d=[],i;
		if(Undef(spt))spt=";";
		if(ua.oldB)d=s.split("\n");else d=s.split(/\r?\n/);
		for(i=0;i<d.length;i++)d[i]=d[i].split(spt);
	  	return d;
  };
	  
CGp.fromCSVFile=function(s,spt)
	{
		var t=this,d=[],doc=null,r,i,c;
		
		if(ua.oldB||Undef(s))
			return d;
		if(window.ActiveXObject)
			{
				doc=new ActiveXObject("Microsoft.XMLDOM");
				doc.async=0;
				doc.load(s);
				doc=doc.documentElement.text;
	  		};
		if(window.XMLHttpRequest)
			{
				r=new XMLHttpRequest;
				r.open("GET",s,0);
				if(Def(r.overrideMimeType))r.overrideMimeType("text/xml");
				r.send(null);
				if(!r.responseXML)
					return d;
				doc=r.responseXML.documentElement.firstChild.nodeValue;
			};
		if(ua.opera7&&Def(w)&&Def(w.document)&&w.document.readyState=='complete')
			{
				doc=w.document.getElementsByTagName("data")[0].firstChild.nodeValue;
	  		};
		if(Def(doc))
			{
				d=this.fromCSV(doc,spt);
				if(Def(w)&&!w.closed)
					{
					w.close();w=null;curId=0;
			  		}
				return d;
	  		};
	  	if(Undef(w))
	  		{
			w=window.open(s);
			window.focus();
	  		};
	  	if(curId<10)
	  		window.setTimeout(t.name+".init(2, '"+s+"')",1000);
	  	else
	  		{
			if(confirm(curId+" tries to access to file "+s+". \nDo you wish try again?"))
				{
					curId=0;window.setTimeout(t.name+".init(2, '"+s+"')",1000);
	  			}
			else
				{
					alert("Can't load data from file "+s+"!");
					if(Def(w)&&!w.closed)
						{
							w.close();
							w=null;
							curId=0;
	  					};
	  			};
	  		};
	  curId++;
	  return d;
	  };
	  
 CGp.fromXML=function(x)
 	{
		var t=this,d=[];
		if(Undef(x)||x.indexOf("<?")==-1)
			return d;
		var xml=new CXMLTree(x),i,j,f;
		xml=xml.toObject();
		xml=xml.data;
		if(Def(xml.row))
			{
				xml=xml.row;
				if(Undef(xml))
					return d;
				if(xml.constructor!=Array)
					xml=[xml];
				for(i=0;i<xml.length;i++)
					{
						d[i]=[];
						f=xml[i].field;
						if(Undef(f))continue;
						if(f.constructor!=Array)f=[f];
						for(j=0;j<f.length;j++)
							{
								d[i][j]=(Undef(f[j].__value))?"":f[j].__value;
	  						};
	  				};
	  		}
		else
			{
				for(i in xml)
					if(i.indexOf("value")>-1&&Def(xml[i]))
						x=xml[i];
				d=t.fromCSV(x);
	  		};
	  return d;
	  };
	  
	  
  CGp.fromXMLField=function(f)
  	{
		var e="";
		if(ua.ie)
			e=(Def(f.text))?f.text:"";
		else 
			e=(Def(f.firstChild))?f.firstChild.nodeValue:"";
	  return e;
	  };
	  
	  CGp.fromXMLFile=function(x)
	  	{
			var t=this,d=[],doc=null,row,r,i,j;
			if(ua.oldB||Undef(x))
				return d;
			if(window.ActiveXObject)
				{
					doc=new ActiveXObject("Microsoft.XMLDOM");
					doc.async=0;
					doc.load(x);
	  			};
			if(window.XMLHttpRequest)
				{
					r=new XMLHttpRequest;
					r.open("GET",x,0);
					if(Def(r.overrideMimeType))
						r.overrideMimeType("text/xml");
					r.send(null);
					if(!r.responseXML)
						return d;
					doc=r.responseXML.documentElement;
	  			};
			if(ua.opera7&&Def(w)&&Def(w.document)&&w.document.readyState=='complete')
				{
					doc=w.document;
	  			};
			if(Def(doc))
				{
					for(i=0;i<doc.getElementsByTagName("row").length;i++)
						{
							d[d.length]=[];
							row=doc.getElementsByTagName("row")[i];
							for(j=0;j<row.getElementsByTagName("field").length;j++)
								d[i][j]=t.fromXMLField((ua.moz)?row.getElementsByTagName("field")[j]:row.getElementsByTagName("field").item(j));
						};
					if(Def(w)&&!w.closed){w.close();w=null;curId=0;
	  			}
			return d;
	  };
	if(Undef(w))
	  	{
			w=window.open(x);window.focus();
	  	};
	if(curId<10)
		window.setTimeout(t.name+".init(3, '"+x+"')",1000);
	else
		{
				if(confirm(curId+" tries to access to file "+x+". \nDo you wish try again?"))
					{
						curId=0;window.setTimeout(t.name+".init(3, '"+x+"')",1000);
			  	    }
				else{alert("Can't load data from file "+x+"!");
				if(Def(w)&&!w.closed)
					{
						w.close();w=null;curId=0;
	  				};
	  	};
	 };
	 curId++;
	 return d;
	 };
	 
	 CGp.loadXMLFile=function(x)
	  	{
			var t=this,d=[],xmlDoc=null,row,r,i,j;
			if(ua.oldB||Undef(x))
				return d;
			if(window.ActiveXObject)
				{
					xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
					xmlDoc.async=0;
					xmlDoc.load(x);
	  			};
			if(window.XMLHttpRequest)
				{
					r=new XMLHttpRequest;
					r.open("GET",x,0);
					if(Def(r.overrideMimeType))
						r.overrideMimeType("text/xml");
					r.send(null);
					if(!r.responseXML)
						return d;
					xmlDoc=r.responseXML.documentElement;
	  			};
			
			
			if(ua.opera7&&Def(w)&&Def(w.document)&&w.document.readyState=='complete')
				{
					xmlDoc=w.document;
	  			};
			
			if(Def(xmlDoc))
				{
					var xmlObj = xmlDoc; //.documentElement;
					t.stringStrategyLst = xmlObj.getElementsByTagName("string");
					t.numberStrategyLst = xmlObj.getElementsByTagName("number");
					xmlDoc=null;
					xmlObj=null;
					if(Def(w)&&!w.closed)
						{
							w.close();
							w=null;
							curId=0;
						}
					return d;
	  			};
			if(Undef(w))
	  			{
				w=window.open(x);window.focus();
			  	};
			if(curId<10)
				window.setTimeout(t.name+".init(3, '"+x+"')",1000);
			else
				{
				if(confirm(curId+" tries to access to file "+x+". \nDo you wish try again?"))
					{
						curId=0;window.setTimeout(t.name+".init(3, '"+x+"')",1000);
			  	    }
				else{alert("Can't load data from file "+x+"!");
				if(Def(w)&&!w.closed)
					{
						w.close();w=null;curId=0;
	  				};
			  	};
	 		};
	 curId++;
	 return d;	 
	 };
	 
// --------------------------------------------------------------------------------
//
// Filter functions
//
// --------------------------------------------------------------------------------
  CGp.getKeyArray=function(keyCol)
  	{
		var name=keyCol,t=this,keyArray=[];
		if(keyCol.constructor==String&&isNaN(parseInt(keyCol)))
			{
				keyCol=t.getColByTitle(keyCol);
	  		};
		if(keyCol<0||keyCol>=t.cols.length)
			{
				keyCol=-1;
	  		};
		for(i=0;i<t.rows.length;i++)
			{
				if(t.rows[i].isMark)
				if(keyCol==-1)
					keyArray[keyArray.length]=i;
				else 
					keyArray[keyArray.length]=t.cells[i][keyCol].getDataForFilter();
	  		};
	  return keyArray;
	  };
	  
// --------------------------------------------------------------------------------
//
// Filter functions
//
// --------------------------------------------------------------------------------
	  
CGp.setKeyArray=function(keyCol,keyArray)
	{
		var name=keyCol,t=this;
		if(keyCol.constructor==String&&isNaN(parseInt(keyCol)))
			{
				keyCol=t.getColByTitle(keyCol);
	  		};
		if(keyCol<0||keyCol>=t.cols.length)
			{
				alert("No such column "+name+" in table!");
	  			return;
	  		};
		if(keyArray.constructor!=Array||keyArray.length==0)
			{
				keyArray=[];
	  		};
		t.search(1);
		for(i=0;i<t.rows.length;i++)
			{
				if(keyArray.length>0&&keyArray.indexOf(t.cells[i][keyCol].getDataForFilter())==-1)
					{
						t.rows[i].isVisible=0;
	  				};
	  		};
		t.setPage(1);
	  };
	  
	  
	CGp.getColByTitle=function(title)
		{
			var colIdx=-1,t=this;
			for(i=0;i<t.cols.length;i++)
				{
					if(t.cols[i].title==title)
						{
							colIdx=i;
							break;
	  					};
	  			};
	  return colIdx;
	  };
	  

// --------------------------------------------------------------------------------
//
// Check close
//
// --------------------------------------------------------------------------------
  CGp.checkClose=function(trans_value,param)
	{
		var Pos;
		var value=trans_value;
		
		while (value.length > 0) {
			pos = value.search("<"+param);
			if (pos == -1) 
					{	
						alert(param + " opened = "+value);
						break;
					}
			value = value.substring(pos+param.length+1,value.length);
			if (value.length <= 0) 
					{	
						alert(param + " is cool = "+value);
						break;
					}
			
			var value_reverse = value;
			var pos_reverse = 0;
			while (value_reverse.length > 0) 
				{
				pos = value_reverse.search("</"+param+">");
				if (pos == -1) 
						break;
				pos_reverse += pos+param.length+3;
				value_reverse = value_reverse.substring(pos+param.length+3,value_reverse.length);
				}
			if (value_reverse == value) 
					{	
						alert(param + " is not closed = "+value);
						break;
					}
			pos_reverse -= (param.length+3);
			value = value_reverse.substring(0,pos_reverse);
				
		}
		alert(param + " is cool = "+value);
	}
			
// --------------------------------------------------------------------------------
//
// To HTML functions
//
// --------------------------------------------------------------------------------
	  
	  CGp.toHTML=function()
	  	{
		var t=this,h="";
		//alert("paint " +t.Phase);
		// if (t.Phase == 2 && t.PaintCount == 1) { t.PaintCount+=1; return h; }
		t.tableHTML = t.tabletoHTML();	
		if (t.onlyTop)
			{
			h+=t.tableHTML; return h;
			}
		//	if (t.PaintCount != 2)
		switch(t.Phase) { 
			case 1: h+=t.topFirstPagetoHTML(); h+=t.tableHTML; h+=t.DisclaimertoHTML(); break;
			case 2: h+=t.topSecondPagetoHTML(); h+=t.tableHTML; h+=t.DisclaimertoHTML(); break;
			case 3: h+=t.topThirdPagetoHTML(); break;
			}
		
	//	t.checkClose(h,"form");	
	  	t.PaintCount+=1;
		return h;
		};
	  
// --------------------------------------------------------------------------------
//
// initFirstPageTop functions
//
// --------------------------------------------------------------------------------
	  CGp.initFirstPageTop=function()
	  	{
				
			var t=this,h="";

			for(i=0;i<t.cols.length;i++)
				{
					if(t.cols[i].useAutoFilter) 
						{
						if(t.cols[i].useAutoIndex&&!t.cols[i].index.length) t.setIndex(i);
						switch (t.cols[i].title)
							{
							case "Cost*": t.cols[i].setCostFilter(); break;
							case "S. Capital": t.cols[i].setCapitalFilter(); break;
							case "Total P&L": t.cols[i].setTotalPnLFilter(); break;
							case "Drawdown": t.cols[i].setDrawdownFilter(); break;
							case "Age": t.cols[i].setAgeFilter(); break;
							default: if(t.cols[i].useAutoFilter&&!t.cols[i].filter.length) t.cols[i].setFilter(); break;
							}
						}
					else
						{
						if(t.cols[i].useAutoIndex&&!t.cols[i].index.length) t.setIndex(i);
						}
				}
									
	  		return h;
	  };

	  
// --------------------------------------------------------------------------------
//
// DrawChartURL
//
// --------------------------------------------------------------------------------

	  CGp.DrawChartURL=function(params,pwidth,pheight)
		{		
			var h = "", t=this;
			pwidth-=2;
			document.strategy_charts.SetVariable ( "update_url", params );
			return h;
		};
		
// --------------------------------------------------------------------------------
//
// DrawLargeChartStyle
//
// --------------------------------------------------------------------------------

	  CGp.DrawLargeChartStyle=function(params,pwidth,pheight)
		{		
			var h = "", t=this, i=0;
			var numbers_value="", datas_value="";
			
	 		t.loadXMLFile(params);
			var ser_length = t.stringStrategyLst.length;
			
			for (i=0; i<ser_length-1; i++)
			 	numbers_value += "<number>" + t.numberStrategyLst[i].childNodes[0].nodeValue + "</number>";
				
			for (i=0; i<ser_length-2; i++)
				datas_value += "<string>"+ t.stringStrategyLst[i].childNodes[0].nodeValue + "</string>";

			h="<chart>";
 			h+=t.SetStyleChartTop();
			h+="<chart_data><row><null/>"; 
			h+=datas_value;
			h+="</row><row><string />";
			h+=numbers_value; 
			h+="</row></chart_data>";
			h+=t.SetStyleChartBottom(pwidth,pheight);
			h+="</chart>";
 


		return h;
		
		};
	
// --------------------------------------------------------------------------------
//
// DrawChartObject
//
// --------------------------------------------------------------------------------

	  CGp.DrawChartObject=function(params,divname,pwidth,pheight)
		{		
			var h = "";
			
		    var h ="<OBJECT id="+divname+" style=\"z-index:2\"; classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"";
			h+="codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\"";
			h+="WIDTH=\"" + pwidth + "\" ";
			h+="HEIGHT=\"" + pheight + "\" ";
			h+="ALIGN=\"\">";
			
			h+="<PARAM NAME=movie VALUE=\"http://www.strategyxchange.com/Matrix/portfolio/chart.swf?library_path=http://www.strategyxchange.com/Matrix/charts_library&xml_source="+params+"\">";

			h+="<PARAM NAME=quality VALUE=high>";
			h+="<PARAM NAME=bgcolor VALUE=#EEEEEE>";
			h+="<EMBED src=\"chart.swf\" ";
			h+="       quality=high ";
			h+="       bgcolor=#EEEEEE  ";
			h+="       WIDTH=\""+pwidth-100+"\" "; //300
			h+="       HEIGHT=\""+pheight-100+"\" "; //150
			h+="       ALIGN=\"left\" ";
			h+="       swLiveConnect=\"true\" ";
			
			h+="       TYPE=\"application/x-shockwave-flash?library_path=http://www.strategyxchange.com/Matrix/charts_library&xml_source=http://www.strategyxchange.com/Matrix/portfolio/sample.xml\"";
			
			h+="       PLUGINSPAGE=\"http://www.macromedia.com/go/getflashplayer\">";
			h+="</EMBED>";
			h+="</OBJECT>";
			
			return h;
		}
// --------------------------------------------------------------------------------
//
// DrawChartStyle
//
// --------------------------------------------------------------------------------

	CGp.DrawChartStyle=function(params,pwidth,pheight)
		{		
		pwidth-=2;
		
		var h="", t=this, chart_value="<chart>";
		chart_value+=t.SetStyleChartTop();
		chart_value+=t.SetStyleChartBottom(pwidth,pheight);
		chart_value+="</chart>";
 
		if (Def(document.strategy_charts) && document.strategy_charts!=null)
			{
			document.strategy_charts.SetVariable ( "update_xml", chart_value );
			}
		return h;
		}

// --------------------------------------------------------------------------------
//
// SeriesPnLValues
//
// --------------------------------------------------------------------------------
	 CGp.SeriesPnLValues=function(row)
 		{
			var row_numbers_value="", t=this;
			if (row!=-1)
				{
				var strategy_numbers = new Array(1);
				var i=row;
				var productId = t.getProductId(i);	
				var lots_data = new String(t.cells[i][t.LotsCol].getDataForFilter());
				var Pos = lots_data.search(":");
				var Lotsdata = parseFloat(lots_data.substring(Pos+1,lots_data.length));
				var SCapitaldata=parseFloat(t.cells[i][t.SCapitalCol].getDataForFilter());
				var TotalPnLdata=parseFloat(t.cells[i][t.TotalPnLCol].getDataForFilter());
					
				var strPageName = "http://www.strategyxchange.com/Charts/"+productId+"/chart.xml";
				t.loadXMLFile(strPageName);
				var iP=0, iS=0;
					
				for (iP=0;iP<t.serieslength;iP++)
			 		{
					strategy_numbers.length = iP+1;
					strategy_numbers[iP] = 0;
					while (iS<t.stringStrategyLst.length-1 
						   && t.stringStrategyLst[iS].childNodes[0].nodeValue < t.stringLst[iP])
						iS+=1;
					if (iS>=t.stringStrategyLst.length-1)
			 			break;
					var strategy_PnL = parseFloat(t.numberStrategyLst[iS].childNodes[0].nodeValue);
					if (strategy_PnL != 0 && t.stringStrategyLst[iS].childNodes[0].nodeValue == t.stringLst[iP])
						{
						strategy_numbers[iP] = strategy_numbers[iP]+strategy_PnL*Lotsdata*SCapitaldata*0.01;	 
						}
					else 
						{
						if (iP>0)
							strategy_numbers[iP]=strategy_numbers[iP-1];
						}
					}
				for (iX=iP;iX<t.serieslength;iX++)
			 		if (iX>0)
						strategy_numbers[iX]=strategy_numbers[iX-1];
	 			for (iP=0;iP<t.serieslength;iP++)
			 		{
					strategy_numbers[iP]+=t.numberLst[0];
					row_numbers_value+="<number>"+strategy_numbers[iP]+"</number>";
					}
				}
			return row_numbers_value;
		}

// --------------------------------------------------------------------------------
//
// SetStyleChartTop
//
// --------------------------------------------------------------------------------

	  CGp.SetStyleChartTop=function()
	  	{
			var h="<license>K1X98PQWIECL.NS5T4Q79KLYCK07EK</license><axis_ticks value_ticks=\"true\" category_ticks=\"true\" major_thickness=\"1\" minor_thickness=\"0\" minor_count=\"1\" major_color=\"000000\" minor_color=\"000000\" position=\"outside\" /><axis_category size=\"9\" color=\"000000\" alpha=\"100\" font=\"arial\" bold=\"true\" skip=\"15\" orientation=\"diagonal_up\" /><axis_value n=\"0\" font=\"arial\" bold=\"true\" size=\"9\" color=\"000000\" alpha=\"100\" steps=\"3\" prefix=\"\" suffix=\"\" decimals=\"0\" separator=\"\" show_min=\"true\" /><chart_border color=\"000000\" top_thickness=\"1\" bottom_thickness=\"1\" left_thickness=\"1\" right_thickness=\"1\" />"; 
			return h;
		}
		

// --------------------------------------------------------------------------------
//
// SetStyleChartTop
//
// --------------------------------------------------------------------------------

	  CGp.SetStyleChartBottom=function(pwidth,pheight)
	  	{
			var h="<chart_grid_h alpha=\"0\" color=\"ffffff\" thickness=\"1\" type=\"solid\" /><chart_grid_v alpha=\"0\" color=\"ffffff\" thickness=\"1\" type=\"solid\" /><chart_pref line_thickness=\"1\" point_shape=\"none\" fill_shape=\"false\" /><chart_rect x=\"65\" y=\"25\" width=\""+(pwidth-100)+"\" height=\""+(pheight-80)+"\" positive_color=\"eeeeee\" positive_alpha=\"100\" negative_color=\"cccccc\" negative_alpha=\"100\" /><chart_type>Line</chart_type><chart_value position=\"cursor\" size=\"12\" color=\"000000\" alpha=\"100\" /><draw><text color=\"000000\" alpha=\"0\" font=\"arial\" rotation=\"-90\" bold=\"true\" size=\"11\" x=\"5\" y=\"280\" width=\""+(pwidth-70)+"\" height=\""+(pheight-50)+"\" h_align=\"center\" v_align=\"top\">Profit &amp; Loss</text><text color=\"000000\" alpha=\"0\" font=\"arial\" rotation=\"0\" bold=\"true\" size=\"11\" x=\"200\" y=\"220\" width=\"60\" height=\"30\" h_align=\"left\" v_align=\"bottom\">Date</text></draw><legend_rect x=\"-100\" y=\"-100\" width=\"10\" height=\"10\" margin=\"10\" /><series_color><color>0033cc</color><color>00FF00</color></series_color>";
			return h;
			
		}
// --------------------------------------------------------------------------------
//
// DrawPortfolioChart
//
// --------------------------------------------------------------------------------

	  CGp.DrawPortfolioChart=function(params,pwidth,pheight)
		{		
			var i=0, t=this;
			pwidth-=2;
			var h="", chart_value_large="<chart>", chart_value="<chart>", row_numbers_value="", numbers_value="", datas_value="";
			
			for (i=0;i<t.serieslength;i++)
			 	numbers_value+="<number>"+t.numberLst[i]+"</number>";
			for (i=0;i<t.serieslength-1;i++)
				datas_value+="<string>"+t.stringLst[i]+"</string>";

			row_numbers_value=t.SeriesPnLValues(params);	
				
			chart_value="<chart>";
 			chart_value+=t.SetStyleChartTop();
			chart_value+="<chart_data><row><null/>"; 
			chart_value+=datas_value;
			chart_value+="</row><row><string />";
			chart_value+=numbers_value; 
			if (row_numbers_value!=""){
				chart_value+="</row><row><string />";
				chart_value+=row_numbers_value; 
			}
			chart_value+="</row></chart_data>";
			chart_value+=t.SetStyleChartBottom(pwidth,pheight);
			chart_value+="</chart>";
 
			document.strategy_charts.SetVariable ( "update_xml", chart_value );

			chart_value_large="<chart>";
 			chart_value_large+=t.SetStyleChartTop();
			chart_value_large+="<chart_data><row><null/>"; 
			chart_value_large+=datas_value;
			chart_value_large+="</row><row><string />";
			chart_value_large+=numbers_value; 
			if (row_numbers_value!=""){
				chart_value+="</row><row><string />";
				chart_value+=row_numbers_value; 
			}
			chart_value_large+="</row></chart_data>";
			chart_value_large+=t.SetStyleChartBottom(820,410);
			chart_value_large+="</chart>";
 
			var code_value = "<input type='hidden' id=xx_chart_code name='xx_chart_code' value='" + t.DrawChartObject(params,"strategy_popup_charts",820,410) +"'></input>";
			draw_chart_code.innerHTML = code_value;
			var code_style = "<input type='hidden' id=xx_chart_style name='x1_chart_style' value='" + chart_value_large +"'></input>";
			draw_chart_style.innerHTML = code_style;

		return h;
		}
	
// --------------------------------------------------------------------------------
//
// Select Strategies - on click of Select Strategies - moving to first page
//
// --------------------------------------------------------------------------------

	  CGp.SelectStrategies=function()
	  {
		var t=this,h;
		t.Phase=1;
		for(i=0;i<t.rows.length;i++)
			t.rows[i].isVisible=1;
		t.selectedRow=-1;
		t.PaintCount=1;
		t.search();
		//t.setPage(1);
		//t.checkall(false);
		t.checkedCount=t.CalculatecheckedCount();
		t.setTotalSystemsText();
		return true;		
		
		}

// --------------------------------------------------------------------------------
//
// UpdatePortfolioResults - on click of UpdatePortfolioResults - stay to second page
//
// --------------------------------------------------------------------------------

	  CGp.UpdatePortfolioResults=function()
	  {
		var t=this,h="";
		var cParams = 0;

		for(i=0;i<t.rows.length;i++)
				if (t.isCheckedRow(i))
					cParams += 1;
		if (!t.isValidNumberOfStrategies(cParams))
			return true;
		t.firstRow=t.setFirstRow();	
		t.showportfoliochart(t.firstRow);

		return true;			
	   }



  CGp.SubmitFreeTrial=function()
	  {
		var a = ft.email.value;
		if(!ft.IAgree.checked) { alert("Please check mark I understand"); return true; }
		if(ft.first_name.value=="") { alert("Please fill in your first name"); return true; }
		if(ft.last_name.value=="") { alert("Please fill in your last name"); return true; }
		if(ft.username.value=="") { alert("Please select a user name"); return true; }
		if(ft.password.value=="") { alert("Please select a Password"); return true; }
		if(ft.repeat_password.value=="") { alert("Please retype your Password"); return true; }
		if(ft.password.value != ft.repeat_password.value) { alert("You typed two diferent passwords"); return true; }
		if(ft.phone_number.value=="" ) { alert( "Please fill in your phone number" ); return true; }
		if(a.indexOf("@")<3) { alert("Please enter a valid Email address"); return true; }
		if(a.indexOf(".")<6) { alert("Please enter a valid Email address"); return true; }
		ft.submit();
		return true;
	  }
	  
	 CGp.CountryCombo=function()
	  {  
	   var h = "<select name=\"country\" COLS=\"32\" style=\"font-family: verdana, helv, helvetica; font-size: 11px; line-height: 13px\">";
            				  h += "<option style=\"COLOR: black\" selected>Choose a country</option>";
         					  h += "<option value=\"Afghanistan\">Afghanistan</option>";
      					      h += "<option value=\"Albania\">Albania</option>";
     					      h += "<option value=\"Algeria\">Algeria</option>";
                              h += "<option value=\"Andorra\">Andorra</option>";
                              h += "<option value=\"Angola\">Angola</option>";
                              h += "<option value=\"Anguilla\">Anguilla</option>";
                              h += "<option value=\"Antarctica\">Antarctica</option>";
                              h += "<option value=\"Antigua &amp; Barbudo\">Antigua &amp; Barbudo</option>";
                              h += "<option value=\"Argentina\">Argentina</option>";
                              h += "<option value=\"Armenia\">Armenia</option>";
                              h += "<option value=\"Aruba\">Aruba</option>";
                              h += "<option value=\"Australia\">Australia</option>";
                              h += "<option value=\"Austria\">Austria</option>";
                              h += "<option value=\"Azerbaijan\">Azerbaijan</option>";
                              h += "<option value=\"Bahamas\">Bahamas</option>";
                              h += "<option value=\"Bahrain\">Bahrain</option>";
                              h += "<option value=\"Bangladesh\">Bangladesh</option>";
                              h += "<option value=\"Barbados\">Barbados</option>";
                              h += "<option value=\"Belarus\">Belarus</option>";
                              h += "<option value=\"Belize\">Belize</option>";
                              h += "<option value=\"Belgium\">Belgium</option>";
                              h += "<option value=\"Benin\">Benin</option>";
                              h += "<option value=\"Bermuda\">Bermuda</option>";
                              h += "<option value=\"Bhutan\">Bhutan</option>";
                              h += "<option value=\"Bolivia\">Bolivia</option>";
                              h += "<option value=\"Bosnia &amp; Herzegovina\">Bosnia &amp; Herzegovina</option>";
                              h += "<option value=\"Botswana\">Botswana</option>";
                              h += "<option value=\"Bouvet Island\">Bouvet Island </option>";
                              h += "<option value=\"Brazil\">Brazil</option>";
                              h += "<option value=\"British Indian Ocean Territories\">British Indian Ocean Territories</option>";
                              h += "<option value=\"Brunei Darussalam\">Brunei Darussalam</option>";
                              h += "<option value=\"Bulgaria\">Bulgaria</option>";
                              h += "<option value=\"Burkina Faso\">Burkina Faso</option>";
                              h += "<option value=\"Burundi\">Burundi</option>";
                              h += "<option value=\"Cambodia\">Cambodia</option>";
                              h += "<option value=\"Cameroon\">Cameroon</option>";
                              h += "<option value=\"Canada\">Canada</option>";
                              h += "<option value=\"Cape Verde\">Cape Verde</option>";
                              h += "<option value=\"Cayman Islands\">Cayman Islands</option>";
                              h += "<option value=\"Central African Republic\">Central African Republic</option>";
                              h += "<option value=\"Chad\">Chad</option>";
                              h += "<option value=\"Chile\">Chile</option>";
                              h += "<option value=\"China\">China</option>";
                              h += "<option value=\"Christmas Island\">Christmas Island</option>";
                              h += "<option value=\"Cocos (Keeling) Islands\">Cocos (Keeling) Islands</option>";
                              h += "<option value=\"Colombia\">Colombia</option>";
                              h += "<option value=\"Comoros\">Comoros</option>";
                              h += "<option value=\"Congo\">Congo</option>";
                              h += "<option value=\"Cook Islands\">Cook Islands</option>";
                              h += "<option value=\"Costa Rica\">Costa Rica</option>";
                              h += "<option value=\"Cote D'ivoire\">Cote D'ivoire</option>";
                              h += "<option value=\"Croatia\">Croatia</option>";
                              h += "<option value=\"Cuba\">Cuba</option>";
                              h += "<option value=\"Cyprus\">Cyprus</option>";
                              h += "<option value=\"Czech Republic\">Czech Republic</option>";
                              h += "<option value=\"Denmark\">Denmark</option>";
                              h += "<option value=\"Djibouti\">Djibouti</option>";
                              h += "<option value=\"Dominica\">Dominica</option>";
                              h += "<option value=\"Dominican Republic\">Dominican Republic</option>";
                              h += "<option value=\"East Timor\">East Timor</option>";
                              h += "<option value=\"Ecuador\">Ecuador</option>";
                              h += "<option value=\"Egypt\">Egypt</option>";
                              h += "<option value=\"El Salvador\">El Salvador</option>";
                              h += "<option value=\"Equatorial Guinea\">Equatorial Guinea</option>";
                              h += "<option value=\"Eritrea\">Eritrea</option>";
                              h += "<option value=\"Estonia\">Estonia</option>";
                              h += "<option value=\"Ethiopia\">Ethiopia</option>";
                              h += "<option value=\"Falkland Islands (Malvinas)\">Falkland Islands (Malvinas)</option>";
                              h += "<option value=\"Faroe Islands\">Faroe Islands</option>";
                              h += "<option value=\"Fiji\">Fiji</option>";
                              h += "<option value=\"Finland\">Finland</option>";
                              h += "<option value=\"France\">France</option>";
                              h += "<option value=\"France, Metropolitan\">France, Metropolitan</option>";
                              h += "<option value=\"French Guiana\">French Guiana</option>";
                              h += "<option value=\"French Polynesia\">French Polynesia</option>";
                              h += "<option value=\"French Southern Territories\">French Southern Territories</option>";
                              h += "<option value=\"Gabon\">Gabon</option>";
                              h += "<option value=\"Gambia\">Gambia</option>";
                              h += "<option value=\"Georgia\">Georgia</option>";
                              h += "<option value=\"Germany\">Germany</option>";
                              h += "<option value=\"Ghana\">Ghana</option>";
                              h += "<option value=\"Gibraltar\">Gibraltar</option>";
                              h += "<option value=\"Greece\">Greece</option>";
                              h += "<option value=\"Greenland\">Greenland</option>";
                              h += "<option value=\"Grenada\">Grenada</option>";
                              h += "<option value=\"Guadeloupe\">Guadeloupe</option>";
                              h += "<option value=\"Guam\">Guam</option>";
                              h += "<option value=\"Guatemala\">Guatemala</option>";
                              h += "<option value=\"Guinea\">Guinea</option>";
                              h += "<option value=\"Guinea-Bissau\">Guinea-Bissau</option>";
                              h += "<option value=\"Guyana\">Guyana</option>";
                              h += "<option value=\"Haiti\">Haiti</option>";
                              h += "<option value=\"Heard and Mcdonald Islands\">Heard and Mcdonald Islands</option>";
                              h += "<option value=\"Honduras\">Honduras</option>";
                              h += "<option value=\"Hong Kong\">Hong Kong</option>";
                              h += "<option value=\"Hungary\">Hungary</option>";
                              h += "<option value=\"Iceland\">Iceland</option>";
                              h += "<option value=\"India\">India</option>";
                              h += "<option value=\"Indonesia\">Indonesia</option>";
                              h += "<option value=\"Iran\">Iran</option>";
                              h += "<option value=\"Iraq\">Iraq</option>";
                              h += "<option value=\"Ireland\">Ireland</option>";
                              h += "<option value=\"Israel\">Israel</option>";
                              h += "<option value=\"Italy\">Italy</option>";
                              h += "<option value=\"Jamaica\">Jamaica</option>";
                              h += "<option value=\"Japan\">Japan</option>";
                              h += "<option value=\"Jordan\">Jordan</option>";
                              h += "<option value=\"Kazakhstan\">Kazakhstan</option>";
                              h += "<option value=\"Kenya\">Kenya</option>";
                              h += "<option value=\"Kiribati\">Kiribati</option>";
                              h += "<option value=\"Korea, Democratic People's Republic\">Korea, Democratic People's Republic</option>";
                              h += "<option value=\"Korea, Republic of\">Korea, Republic of</option>";
                              h += "<option value=\"Kuwait\">Kuwait</option>";
                              h += "<option value=\"Kyrgyzstan\">Kyrgyzstan</option>";
                              h += "<option value=\"Laos, People's Democratic Republic of\">Laos, People's Democratic Republic of</option>";
                              h += "<option value=\"Latvia\">Latvia</option>";
                              h += "<option value=\"Lebanon\">Lebanon</option>";
                              h += "<option value=\"Lesotho\">Lesotho</option>";
                              h += "<option value=\"Liberia\">Liberia</option>";
                              h += "<option value=\"Libyan Arab Jamahiriya\">Libyan Arab Jamahiriya</option>";
                              h += "<option value=\"Liechtenstein\">Liechtenstein</option>";
                              h += "<option value=\"Lithuania\">Lithuania</option>";
                              h += "<option value=\"Luxembourg\">Luxembourg</option>";
                              h += "<option value=\"Macau\">Macau</option>";
                              h += "<option value=\"Madagascar\">Madagascar</option>";
                              h += "<option value=\"Malawi\">Malawi</option>";
                              h += "<option value=\"Malaysia\">Malaysia</option>";
                              h += "<option value=\"Maldives\">Maldives</option>";
                              h += "<option value=\"Mali\">Mali</option>";
                              h += "<option value=\"Malta\">Malta</option>";
                              h += "<option value=\"Marshall Islands\">Marshall Islands</option>";
                              h += "<option value=\"Martinique\">Martinique</option>";
                              h += "<option value=\"Mauritania\">Mauritania</option>";
                              h += "<option value=\"Mauritius\">Mauritius</option>";
                              h += "<option value=\"Mayotte\">Mayotte</option>";
                              h += "<option value=\"Mexico\">Mexico</option>";
                              h += "<option value=\"Micronesia\">Micronesia</option>";
                              h += "<option value=\"Moldova\">Moldova</option>";
                              h += "<option value=\"Monaco\">Monaco</option>";
                              h += "<option value=\"Mongolia\">Mongolia</option>";
                              h += "<option value=\"Montserrat\">Montserrat</option>";
                              h += "<option value=\"Morocco\">Morocco</option>";
                              h += "<option value=\"Mozambique\">Mozambique</option>";
                              h += "<option value=\"Myanmar\">Myanmar</option>";
                              h += "<option value=\"Namibia\">Namibia</option>";
                              h += "<option value=\"Nauru\">Nauru</option>";
                              h += "<option value=\"Nepal\">Nepal</option>";
                              h += "<option value=\"Netherlands\">Netherlands</option>";
                              h += "<option value=\"Netherlands Antilles\">Netherlands Antilles</option>";
                              h += "<option value=\"New Caledonia\">New Caledonia</option>";
                              h += "<option value=\"New Zealand\">New Zealand</option>";
                              h += "<option value=\"Nicaragua\">Nicaragua</option>";
                              h += "<option value=\"Niger\">Niger</option>";
                              h += "<option value=\"Nigeria\">Nigeria</option>";
                              h += "<option value=\"Niue\">Niue</option>";
                              h += "<option value=\"Norfolk Island\">Norfolk Island</option>";
                              h += "<option value=\"Northern Mariana Islands\">Northern Mariana Islands</option>";
                              h += "<option value=\"Norway\">Norway</option>";
                              h += "<option value=\"Oman\">Oman</option>";
                              h += "<option value=\"Pakistan\">Pakistan</option>";
                              h += "<option value=\"Palau\">Palau</option>";
                              h += "<option value=\"Panama\">Panama</option>";
                              h += "<option value=\"Papua New Guinea\">Papua New Guinea</option>";
                              h += "<option value=\"Paraguay\">Paraguay</option>";
                              h += "<option value=\"Peru\">Peru</option>";
                              h += "<option value=\"Philippines\">Philippines</option>";
                              h += "<option value=\"Pitcairn\">Pitcairn</option>";
                              h += "<option value=\"Poland\">Poland</option>";
                              h += "<option value=\"Portugal\">Portugal</option>";
                              h += "<option value=\"Puerto Rico\">Puerto Rico</option>";
                              h += "<option value=\"Qatar\">Qatar</option>";
                              h += "<option value=\"Reunion\">Reunion</option>";
                              h += "<option value=\"Romania\">Romania</option>";
                              h += "<option value=\"Russian Federation\">Russian Federation</option>";
                              h += "<option value=\"Rwanda\">Rwanda</option>";
                              h += "<option value=\"Saint Helena\">Saint Helena</option>";
                              h += "<option value=\"Saint Kitts &amp; Nevis\">Saint Kitts &amp; Nevis</option>";
                              h += "<option value=\"Saint Lucia\">Saint Lucia</option>";
                              h += "<option value=\"Saint Pierre &amp; Miquelon\">Saint Pierre &amp; Miquelon</option>";
                              h += "<option value=\"Saint Vincent &amp; the Grenadines\">Saint Vincent &amp; the Grenadines</option>";
                              h += "<option value=\"Samoa, African\">Samoa, African</option>";
                              h += "<option value=\"Samoa, American\">Samoa, American</option>";
                              h += "<option value=\"San Marino\">San Marino</option>";
                              h += "<option value=\"Sao Tome &amp; Principe\">Sao Tome &amp; Principe</option>";
                              h += "<option value=\"Saudi Arabia\">Saudi Arabia</option>";
                              h += "<option value=\"Senegal\">Senegal</option>";
                              h += "<option value=\"Seychelles\">Seychelles</option>";
                              h += "<option value=\"Sierra Leone\">Sierra Leone</option>";
                              h += "<option value=\"Singapore\">Singapore</option>";
                              h += "<option value=\"Slovakia\">Slovakia</option>";
                              h += "<option value=\"Slovenia\">Slovenia</option>";
                              h += "<option value=\"Solomon Islands\">Solomon Islands</option>";
                              h += "<option value=\"Somalia\">Somalia</option>";
                              h += "<option value=\"South Africa\">South Africa</option>";
                              h += "<option value=\"South Georgia &amp; Sandwich Islands\">South Georgia &amp; Sandwich Islands</option>";
                              h += "<option value=\"Spain\">Spain</option>";
                              h += "<option value=\"Sri Lanka\">Sri Lanka</option>";
                              h += "<option value=\"Sudan\">Sudan</option>";
                              h += "<option value=\"Suriname\">Suriname</option>";
                              h += "<option value=\"Svalbard &amp; Jan Mayen\">Svalbard &amp; Jan Mayen</option>";
                              h += "<option value=\"Swaziland\">Swaziland</option>";
                              h += "<option value=\"Sweden\">Sweden</option>";
                              h += "<option value=\"Switzerland\">Switzerland</option>";
                              h += "<option value=\"Syrian Arab Republic\">Syrian Arab Republic</option>";
                              h += "<option value=\"Taiwan\">Taiwan</option>";
                              h += "<option value=\"Tajikistan\">Tajikistan</option>";
                              h += "<option value=\"Tanzania\">Tanzania</option>";
                              h += "<option value=\"Thailand\">Thailand</option>";
                              h += "<option value=\"Togo\">Togo</option>";
                              h += "<option value=\"Tokelau\">Tokelau</option>";
                              h += "<option value=\"Tonga\">Tonga</option>";
                              h += "<option value=\"Trinidad &amp; Tobago\">Trinidad &amp; Tobago</option>";
                              h += "<option value=\"Tunisia\">Tunisia</option>";
                              h += "<option value=\"Turkey\">Turkey</option>";
                              h += "<option value=\"Turkmenistan\">Turkmenistan</option>";
                              h += "<option value=\"Turks and Caicos Islands\">Turks and Caicos Islands</option>";
                              h += "<option value=\"Tuvalu\">Tuvalu</option>";
                              h += "<option value=\"Uganda\">Uganda</option>";
                              h += "<option value=\"Ukraine\">Ukraine</option>";
                              h += "<option value=\"United Arab Emirates\">United Arab Emirates</option>";
                              h += "<option value=\"United Kingdom\">United Kingdom</option>";
                              h += "<option value=\"United States\">United States</option>";
                              h += "<option value=\"United States Minor Outlying Islands\">United States Minor Outlying Islands</option>";
                              h += "<option value=\"Uruguay\">Uruguay</option>";
                              h += "<option value=\"Uzbekistan\">Uzbekistan</option>";
                              h += "<option value=\"Vanuatu\">Vanuatu</option>";
                              h += "<option value=\"Vatican City State\">Vatican City State</option>";
                              h += "<option value=\"Venezuela\">Venezuela</option>";
                              h += "<option value=\"Vietnam\">Vietnam</option>";
                              h += "<option value=\"Virgin Islands (British)\">Virgin Islands (British)</option>";
                              h += "<option value=\"Virgin Islands (U.S.)\">Virgin Islands (U.S.)</option>";
                              h += "<option value=\"Wallis &amp; Futuna Islands\">Wallis &amp; Futuna Islands</option>";
                              h += "<option value=\"Western Sahara\">Western Sahara</option>";
                              h += "<option value=\"Yemen\">Yemen</option>";
                              h += "<option value=\"Yugoslavia\">Yugoslavia</option>";
                              h += "<option value=\"Zaire\">Zaire</option>";
                              h += "<option value=\"Zambia\">Zambia</option>";
                              h += "<option value=\"Zimbabwe\">Zimbabwe</option>";
                              h += "</select>";
		return h;
	  };
// --------------------------------------------------------------------------------
//
// Free Trail - on click of Free Trail - moving to second page
//
// --------------------------------------------------------------------------------

	  CGp.FreeTrial=function()
	  {
		var t=this;
		var cParams = 0;
		for(i=0;i<t.rows.length;i++)
			if (t.isCheckedRow(i))
			    cParams += 1;
		if (!t.isValidNumberOfStrategies(cParams))
			return true;
		for(i=0;i<t.rows.length;i++)
			if (t.isCheckedRow(i))
				t.rows[i].isVisible=1;
			else
				t.rows[i].isVisible=0;
			
		//document.body.style.cursor = "wait";
		t.Phase=3;
		t.PaintCount=1;
		t.search();
	//	t.setPage(1);
		t.checkall(true);
		//document.body.style.cursor = "default";
		return true;
	}
// --------------------------------------------------------------------------------
//
// Build Portfolio - on click of Build Portfolio - moving to second page
//
// --------------------------------------------------------------------------------

	  CGp.BuildPortfolio=function()
	  {
		var t=this;
		var cParams = 0;
		for(i=0;i<t.rows.length;i++)
			if (t.isCheckedRow(i))
			    cParams += 1;
		if (!t.isValidNumberOfStrategies(cParams))
			return true;
		for(i=0;i<t.rows.length;i++)
			if (t.isCheckedRow(i))
				t.rows[i].isVisible=1;
			else
				t.rows[i].isVisible=0;
			
		//document.body.style.cursor = "wait";
		t.Phase=2;
		t.PaintCount=1;
		t.search();
//		t.setPage(1);
		
		t.checkall(true);
		t.firstRow=t.setFirstRow();	
		t.showportfoliochart(-1);		
		t.checkedCount=t.CalculatecheckedCount();
		
		//document.body.style.cursor = "default";
		return true;
	}
	  

// --------------------------------------------------------------------------------
//
// pageTurnToHTML functions
//
// --------------------------------------------------------------------------------
  
	  
	  CGp.pageTurnToHTML=function()
	  	{
			var t=this,c=t.pageCount,h="",i;
			if(c>1)
				{
					h=" <a href=\""+this.setAction("setPage",1)+"\">"+t.imgFirstPage+"</a> &nbsp;";
					if(t.page>1)
						h+=" <a href=\""+t.setAction("setPage",(t.page-1))+"\">"+t.imgPrevPage+"</a> &nbsp;";
						if(!ua.oldB)
							{
								h+=" <select name=\""+t.getID("pt")+"\" onChange=\""+t.name+".setPage(this.value);\">";
								for(i=1;i<=c;i++)
									{
										h+="<option value=\""+i+"\"";
										if(t.page==i)
											h+=" selected ";
										//h+=">"+((i-1)*t.amountPerPage+1)+"-"+((i*t.amountPerPage<t.vr.length)?(i*t.amountPerPage):t.vr.length)+"</option>";
								    	h+=">"+i+"</option>";
								    }
								h+="</select>";
	  						};
						if(t.page<c)	
							h+=" &nbsp; <a href=\""+this.setAction("setPage",(t.page*1+1))+"\">"+t.imgNextPage+"</a>";
					h+=" &nbsp; <a href=\""+this.setAction("setPage",c)+"\">"+t.imgLastPage+"</a>";
	  				}
				else
					{
						if(!t.vr.length)
							h+="";
						else 
							//h+=((t.page-1)*t.amountPerPage+1)+"-"+((t.page*t.amountPerPage<t.vr.length)?(t.page*t.amountPerPage):t.vr.length);
	  						h+="Page: 1";
	  				};
	  return h;
	  };
	  
// --------------------------------------------------------------------------------
//
// utilsToHTML functions
//
// --------------------------------------------------------------------------------
	  
	CGp.utilsToHTML=function()
		{
			var t=this,h="",a;
			if(t.useResetPanel)
				{
					alert("utilsToHTML");
					h+=" &nbsp; <a href=\""+t.setAction("resetSort","")+"\">"+t.resetSortControl+"</a>"+" &nbsp;  <a href=\""+t.setAction("setSearch","")+"\">"+t.resetSearchControl+"</a>";
					if(!ua.nn4&&!ua.oldOpera)h+=" &nbsp; <a href=\""+t.setAction("resetMark","")+"\">"+t.resetMarkControl+"</a>";
					h+="<br><br>";
	  			};
			if(t.useSearchPanel)
				{
					h+=t.searchControl+"<input type=\"text\" maxlength=\"256\" value=\""+t.searchValue+"\" name=\"search\" ";
					if(!ua.nn4)
						h+="style=\"width:200px; \" onKeyPress=\"keyPress(this.form.b1); \"";
						h+="> ";
						a=t.setAction("setSearch","document.forms[f"+t.name+"].search.value");
						if(a.indexOf("javascript")==-1)
							a="window.location.href='"+a+"'";
						else 
							a=t.name+".setSearch(document.forms[&quot;f"+t.name+"&quot;].search.value)";
						if(ua.nn4)
							{
								h+=" <a href=\"javascript:"+t.name+".setSearch(window.document.layers['"+t.name+"'].document.forms['f"+t.name+"'].search.value); \">OK</a>";
	  						}
						else
							{
								h+=" <input type=\"button\" name=\"b1\" value=\"OK\" onClick=\""+a+"\">";
	 						};
				};
				if(t.useAmountPanel)
					{
						h=" &nbsp; "+t.amountControl+" &nbsp; ";
						if(!ua.nn4)
							{
							a=t.setAction("setAmountPerPage","document.forms[f"+t.name+"].amountPerPage.value");//t._id+",this.value");
							if(a.indexOf("javascript")==-1)
								a="window.location.href='"+a+"'";
							else 
								a=t.name+".setAmountPerPage(this.options[this.selectedIndex].value)";
							a="onChange=\""+a+"\"";
							}
	  					if(ua.nn4)
							{
							h+=" <a href=\"javascript:"+t.name+".setAmountPerPage(window.document.layers['"+t.name+"'].document.forms['f"+t.name+"'].amountPerPage.value);  \">OK</a>";
	  						}
						h+="<select id=\"amountPerPage\" name=\"amountPerPage\"" +a+">";
						if (t.amountPerPage == 10)
							h+="<option value='10' selected>10</option>";
    					else
							h+="<option value='10'>10</option>";
						if (t.amountPerPage == 25)
							h+="<option value='25' selected>25</option>";
    					else
							h+="<option value='25'>25</option>";
						if (t.amountPerPage == 50)
							h+="<option value='50' selected>50</option>";
    					else
							h+="<option value='50'>50</option>";
						if (t.amountPerPage == 75)
							h+="<option value='75' selected>75</option>";
    					else
							h+="<option value='75'>75</option>";
						if (t.amountPerPage == 100)
							h+="<option value='100' selected>100</option>";
    					else
							h+="<option value='100'>100</option>";
    					//h+="<option value='10' "+(10==this.amountPerPage)?"selected":""+">10</option>";
    					//h+="<option value='25' "+(25==this.amountPerPage)?"selected":""+">25</option>";
    					//h+="<option value='50' "+(50==this.amountPerPage)?"selected":""+">50</option>";
    					//h+="<option value='75' "+(75==this.amountPerPage)?"selected":""+">75</option>";
    					//h+="<option value='All' "+(75<this.amountPerPage)?"selected":""+">All</option>";
  						h+="</select>";
						//alert(h);
	 			 };
	  return h;
	  };
	  
	
   CGp.setFirstRow=function()
  	{
		var t=this;
		if (t.amountPerPage == -1)
			return -1;
		var count=(t.page-1)*t.amountPerPage;
		var icount=0;
		for(i=0;i<t.rowIndex.length;i++)
			if(t.rows[t.rowIndex[i]].isVisible)
				{
				if (icount == count)
					return t.rowIndex[i]; 
				icount++;
	  			}
		return -1;
	};
	
  CGp.setPage=function(page)
  	{
		var t=this;
		t.page=page;
		t.firstRow=t.setFirstRow();	
		if(!ua.oldOpera)
			t.paint();
		if(t.useEdit)
			t.getEditValues();
	};
	  
	  
	CGp.repaint=function()
		{
  		var t=this;
	//	t.DrawChartStyle("",t.tableRightWidth,200);
		}
		
   CGp.setAmountPerPage=function(amount)
   	{
		if (amount=="All")
			amount=this.rows.length;
		//alert(amount);
		if(isNaN(parseInt(amount))||Undef(amount)||parseInt(amount)<=0)
			{
				alert("Can't use value "+amount+" as count of records per page!");
				if(Def(document.forms['f'+this.name].elements["amountPerPage"]))
					document.forms['f'+this.name].elements["amountPerPage"].value=this.amountPerPage;
	  			return;
	  }
	  this.amountPerPage=amount;
	  this.setPage(1);
	  };
	  
// --------------------------------------------------------------------------------
//
// setSort functions
//
// --------------------------------------------------------------------------------
	  
CGp.setSort=function(sortCol,sortType)
	{
		var t=this,i;
		t.sortCol=sortCol;
		t.sortType=sortType;
		t.multiSortCol.length=0;
		t.multiSortType.length=0;
		if(!t.cols[t.sortCol].index.length)
			t.setIndex(t.sortCol);
		t.rowIndex.setValue(t.cols[t.sortCol].index);
		if(t.sortType==-1)
			t.rowIndex.reverse();
		t.firstRow=t.setFirstRow();	
		
		t.vr.length=0;
		t.setPage(1);
		t.firstRow=t.setFirstRow();	
		
		if (t.Phase==2) t.showportfoliochart(t.firstRow);
	  };
	  
	  
CGp.resetSort=function(sortCol)
	{
		var t=this;
		if(t.sortCol==-1)
			return;
		if(Undef(sortCol)||t.sortCol==sortCol)
			{
				t.sortCol=-1;
				t.sortType=1;
				t.multiSortCol.length=0;
				t.multiSortType.length=0;
				for(i=0;i<t.rows.length;i++)
					t.rowIndex[i]=i;
	  		}
		else
			{
				idx=t.multiSortCol.indexOf(sortCol);
				if(idx>0)
					{
						t.multiSortCol.length=t.multiSortType.length=idx;
						for(z=0;z<t.multiSortCol.length;z++)
							{
								t.setMultiSort(t.multiSortCol[z],t.multiSortType[z]);
	  						};
	 				 };
			  };
		t.vr.length=0;
		t.setPage(1);
	  };
	  
	  
	  
CGp.resetMark=function()
	{
		var t=this;
		for(i=0;i<t.rows.length;i++)
			if(t.rows[i].isMark)
				{
					t.rows[i].setMark();
	 			 }
	};
	
CGp.setMultiSort=function(sortCol,sortType)
	{
		var t=this,mc=t.multiSortCol,mt=t.multiSortType,i,j,k,left,right,rows,r1,r2;
		if(!t.useMultiSort)
			return;
		if(mc.length==0)
			{
				if(t.sortCol==-1)
					{
						t.sortCol=sortCol;
						t.sortType=sortType;
				  	}
				 else
				 	{
						mc[mc.length]=t.sortCol;
						mt[mt.length]=t.sortType;
	  				}
				mc[mc.length]=sortCol;
				mt[mt.length]=sortType;
	  		}
		else
			{
				i=mc.indexOf(sortCol);
				if(i>-1)
					{
						mt[i]=sortType;
	 				 }
				else
					{
						mc[mc.length]=sortCol;
						mt[mt.length]=sortType;
					};
	  		};
		if(t.cols[t.sortCol].index.length==0)
			t.setIndex(t.sortCol);
		t.rowIndex.setValue(t.cols[t.sortCol].index);
		if(t.sortType==-1)
			t.rowIndex.reverse();
		for(i=1;i<mc.length;i++)
			{
				for(j=1;j<t.rows.length;j++)
					{
						left=right=-1;
						r1=t.rowIndex[j-1];
						r2=t.rowIndex[j];
						while(t.cells[r1][mc[i-1]].compareTo(t.cells[r2][mc[i-1]])==0)
							{
								if(left==-1)
									left=j-1;
								right=j;
								j++;
								if(j<t.rows.length)
									{
										r1=t.rowIndex[j-1];
										r2=t.rowIndex[j];
	 								 }
								else break;
							 };
						if(left>-1&&right>-1)
							{
								rows=t.setIndex2(mc[i],left,right);
								if(mt[i]==-1)
									rows.reverse();
								for(k=0;k<rows.length;k++)
									t.rowIndex[left+k]=rows[k]._id;
	  						};
	  				};
	  		};
		t.vr.length=0;
		t.setPage(1);
	  };
	  
	  
CGp.search=function(dontPaint)
	{
		  var isVisible,data,re=new RegExp(this.searchValue,"gi"),t=this,i;
		  t.cols[t.CheckedCol].isVisible=1; 
		  t.cols[t.LotsCol].isVisible=1; 
  		  t.cols[t.MarketsCol].isVisible=1; 
		  t.cols[t.FrequencyCol].isVisible=1; 
		  t.cols[t.CostCol].isVisible=1; 
		  t.cols[t.SCapitalCol].isVisible=1; 
		  t.cols[t.TotalPnLCol].isVisible=1; 
		  t.cols[t.DrawdownCol].isVisible=1; 
		  t.cols[t.StartDateCol].isVisible=1; 

		  switch (t.Phase) {
				case 1: t.cols[t.LotsCol].isVisible=0; break;
				case 2: break;
				case 3: t.cols[t.CheckedCol].isVisible=0; t.cols[t.MarketsCol].isVisible=0; t.cols[t.FrequencyCol].isVisible=0; t.cols[t.CostCol].isVisible=0; t.cols[t.SCapitalCol].isVisible=0; t.cols[t.TotalPnLCol].isVisible=0; t.cols[t.DrawdownCol].isVisible=0; t.cols[t.StartDateCol].isVisible=0; break;
				}
				
	      for(i=0;i<t.rows.length;i++)
				{
				if (t.Phase==1) t.rows[i].isVisible=1;
			//	if (!t.isCheckedRow(i) && t.Phase>1)
			//		t.rows[i].isVisible=0;
 				};
			
			for(i=0;i<t.rows.length;i++)
				{
					isVisible=0;
					for(j=0;j<t.cols.length;j++)
						{
							data=new String(t.cells[i][j].getDataForFilter());
								
							if(t.cols[j].useAutoFilter) 
								{
								if (t.cols[j].title == "Cost*" || t.cols[j].title == "S. Capital" || t.cols[j].title == "Drawdown" || t.cols[j].title == "Total P&L" || t.cols[j].title == "Age")
									{
									var minValue=0, maxValue=0;
									if (t.cols[j].title == "Cost*")
										{
											var v1="0 - 100", v2="100 - 200", v3="200 - 500", v4="500 - 1,000", v5="> 1,000";
											switch (this.cols[j].filterValue.valueOf())
												{
												case v1: minValue = 0; maxValue=99; break;
												case v2: minValue = 100; maxValue=200; break;
												case v3: minValue = 200; maxValue=500; break;
												case v4: minValue = 500; maxValue=1000; break;
												case v5: minValue = 1000; maxValue=100000; break;
												default: minValue = 0; maxValue=100000; break;
												}
										}
									if (t.cols[j].title == "S. Capital")
										{
											var v1="< 3,000", v2="< 4,000", v3="< 5,000", v4="< 7,500", v5="< 10,000", v6="< 15,000", v7="< 20,000", v8="< 30,000", v9="> 30,000";
											switch (this.cols[j].filterValue.valueOf())
												{
												case v1: minValue = 0; maxValue=3000; break;
												case v2: minValue = 0; maxValue=4000; break;
												case v3: minValue = 0; maxValue=5000; break;
												case v4: minValue = 0; maxValue=7500; break;
												case v5: minValue = 0; maxValue=10000; break;
												case v6: minValue = 0; maxValue=15000; break;
												case v7: minValue = 0; maxValue=20000; break;
												case v8: minValue = 0; maxValue=30000; break;
												case v9: minValue = 30000; maxValue=10000000; break;
												default: minValue = 0; maxValue=10000000; break;
												}
										}
									if (t.cols[j].title == "Total P&L")
										{
											var t=this, v1="0% - 50%", v2="50% - 100%", v3="> 100%";
											switch (this.cols[j].filterValue.valueOf())
												{
												case v1: minValue = 0; maxValue=50; break;
												case v2: minValue = 50; maxValue=100; break;
												case v3: minValue = 100; maxValue=100000; break;
												default: minValue = -100000; maxValue=100000; break;
												}
										}
									if (t.cols[j].title == "Drawdown")
										{
											var t=this, v1="< 10%", v2="< 20%", v3="< 50%";
											switch (this.cols[j].filterValue.valueOf())
												{
												case v1: minValue = -10; maxValue=0; break;
												case v2: minValue = -20; maxValue=0; break;
												case v3: minValue = -50; maxValue=0; break;
												default: minValue = -100000; maxValue=100000; break;
												}
										}
									if (t.cols[j].title == "Age")
										{
											var t=this, v1="< 1 mth", v2="1 mth - 2 mths", v3="> 2 mths";
											switch (this.cols[j].filterValue.valueOf())
												{
												case v1: minValue = 0; maxValue=1/12; break;
												case v2: minValue = 1/12; maxValue=1/4; break;
												case v3: minValue = 1/4; maxValue=100000; break;
												default: minValue = -100000; maxValue=100000; break;
												}
										}
									t.rows[i].isVisible=t.rows[i].isVisible&&((data.valueOf()>=minValue && data.valueOf()<=maxValue)||t.cols[j].filterValue=="");		
									}
								else
									{
										t.rows[i].isVisible=t.rows[i].isVisible&&(data.valueOf()==this.cols[j].filterValue.valueOf()||t.cols[j].filterValue=="");
									}
								}
							if(Def(t.searchValue)&&t.cols[j].type!="Image")
									isVisible=isVisible||(data.search(re)>-1);
	  					};
					if(Def(t.searchValue))
						t.rows[i].isVisible=t.rows[i].isVisible&&isVisible;
	 			 };
			
			t.vr.length=0;
			var cParams = 0;
			for(i=0;i<t.rows.length;i++)
			{
				if (t.rows[i].isVisible)
					cParams++;
			};
			if (cParams == 0)
				{
				alert("No strategies match your search criteria");
				t.FilterCol = -1;
				return true;
				}
			t.firstRow=t.setFirstRow();	
			t.selectedRow = -1;
			if(Undef(dontPaint))
				t.setPage(1);
	  };
	  
	  CGp.setTotalSystemsText=function()
	  	{
			var font_style = "<FONT style=\"font-size:9px\" face=\"Verdana\" style=\"font-weight:normal\">";
   			var t=this;
			if(Def(total_systems_fit_text) && total_systems_fit_text!=null)
		   		total_systems_fit_text.innerHTML=font_style+t.CountVisibleRows()+ " systems fit the criteria</FONT>";
			if(Def(total_systems_selected_text) && total_systems_selected_text!=null)
		   		total_systems_selected_text.innerHTML=font_style+t.checkedCount+ " systems are selected</FONT>";
	  	};
	  
	  CGp.setFilter=function(filterCol,filterValue)
	  	{
		    this.checkall(false);
		    var visiblerows = new Array(t.rows.length);
		    for(i=0;i<t.rows.length;i++)
			  visiblerows[i] = t.rows[i].isVisible;
			 
			this.selectedRow = -1;
			t.FilterValue = this.cols[filterCol].filterValue;
	 		t.FilterCol = filterCol;
			this.cols[filterCol].filterValue=filterValue;
			this.search();
			if (t.FilterCol == -1) {
				for(i=0;i<t.rows.length;i++)
					t.rows[i].isVisible=visiblerows[i];
				this.cols[filterCol].filterValue=t.FilterValue;
			}
			if (t.Phase==1)
				this.setTotalSystemsText();
	  	};
	  
	  CGp.setMultipleFilter=function(filterCol,filterValue1,filterValue2,filterValue3,filterValue4)
	  	{
			var isVisible,data,re=new RegExp(this.searchValue,"gi"),t=this,i;
			for(i=0;i<t.rows.length;i++)
				t.rows[i].isVisible=1;
			for(i=0;i<t.rows.length;i++)
				{
				isVisible=0;
				data=new String(t.cells[i][filterCol].getDataForFilter());
				t.rows[i].isVisible=(data.valueOf()==filterValue1)||(data.valueOf()==filterValue2)||(data.valueOf()==filterValue3)||(data.valueOf()==filterValue4);
				};
			t.vr.length=0;
			t.setPage(1);

	  	};
	  
	  CGp.setSearch=function(searchValue)
	  	{
			this.selectedRow = -1;
			if(Undef(searchValue))searchValue="";
			if(this.searchValue==""&&searchValue=="")
				return;
			this.searchValue=searchValue;
			this.search();
	  };
	  
	  
	  CGp.compare=function(row1,row2)
	  	{
			var g=row1.grid,c=g.sortCol,r1;
	 		 return g.cells[row1._id][c].compareTo(g.cells[row2._id][c]);
	  };
	  
	  
	  CGp.setIndex=function(sortCol)
	  	{
			var t=this,i,sc=t.sortCol,rows=[];
			t.sortCol=sortCol;
			rows.setValue(t.rows);
			rows=rows.sort(t.compare);
			for(i=0;i<t.rows.length;i++)
				{
					t.cols[t.sortCol].index[i]=rows[i]._id;
	  			};
			t.sortCol=sc;
	  };
	  
	  
	  CGp.setIndex2=function(sortCol,left,right)
	  	{
			var t=this,sc=t.sortCol,rows=[],i,j;
			t.sortCol=sortCol;
			for(i=left;i<right+1;i++)
				{
					j=t.rows.indexOf(t.rowIndex[i]);
					rows[rows.length]=t.rows[j];
	  			};
			rows=rows.sort(t.compare);
			t.sortCol=sc;
	  return rows;
	  };
	  
	  
	  CGp.paint=function()
	  	{
			var t=this,HTML=t.toHTML();
			//alert("paint");
			//if (t.Phase == 2 && t.PaintCount == 1) { t.PaintCount++; return true; }
			switch(ua.br)
				{
					case 1: dw(HTML); break;
					case 2: var lr=CodeThat.findElement(t.name); if(Undef(lr))CT_createLayer(t.name,CodeThat.getWinWidth(),CodeThat.getWinHeight(),'','',1,1,'','#ffffff','','','visible','','',1,100,'',HTML);else CT_HTML(t.name,HTML);break;
					default: var lr=CodeThat.findElement(t.name); if(Undef(lr))dw("<div id=\""+t.name+"\"></div>");
					CT_HTML(t.name,HTML);
	  			};
			//t.repaint();
	  };
	  
// --------------------------------------------------------------------------------
//
// setAction functions
//
// --------------------------------------------------------------------------------
  
	  CGp.setAction=function(funcName,funcParam)
	  	{
			var l,z;
			if(ua.oldOpera)
				{
					l=window.location.href;
					var stack=[],idx=[],isExist=0,p1=[],p2=[];
					if(l.indexOf("?")>-1)
						{
							l=l.slice(l.indexOf("?")+1);
							while(l.indexOf("&")>-1)
								{
									stack[stack.length]=l.slice(0,l.indexOf("&"));
									l=l.slice(l.indexOf("&")+1);
	  							}
							stack[stack.length]=l;
							for(z=0;z<stack.length;z++)
								{
									if(stack[z].indexOf(funcName)>-1)
										{
											idx[idx.length]=z;isExist=1;
	 									 };
	 							 };
							alert("set sort");
							switch(funcName)
								{
									case "setPage":
									case "setAmountPerPage":
									case "setSort":if(isExist)stack[idx[0]]="";break;
									case "setSearch":if(isExist)stack[idx[0]]="";for(z=0;z<stack.length;z++)if(stack[z].indexOf("setMultiSort")>-1)stack[z]="";break;
									case "setFilter":
									case "setMultiSort":if(isExist){p1=eval("["+funcParam+"]");for(z=0;z<idx.length;z++){p2=stack[idx[z]].slice(stack[idx[z]].indexOf("(")+1,stack[idx[z]].indexOf(")"));p2=eval("[\""+p2.replace(new RegExp(","),"\",\"")+"\"]");if(p2[0]==p1[0])stack[idx[z]]="";
	  							};
	  						};break;
	  				};
					l=window.location.href.slice(0,window.location.href.indexOf("?")+1);
					for(z=0;z<stack.length;z++)
						{
						if(Def(stack[z]))l+=stack[z]+"&";
	  					};
					l+=funcName+"("+funcParam+")";
	  			}
					else
						{
							l=window.location.href+"?"+funcName+"("+funcParam+")";
	  					};
					l=l.replace(new RegExp("this.value"),"'+ this.value + '");
					l=l.replace(new RegExp("document.forms\\[f"+this.name+"\\].amountPerPage.value","gi"),"'+ document.forms['f"+this.name+"'].amountPerPage.value + '");
					l=l.replace(new RegExp("document.forms\\[f"+this.name+"\\].search.value","gi"),"'+ document.forms['f"+this.name+"'].search.value + '");
	  			}
					else
						{
							l="javascript:"+this.name+"."+funcName+"("+funcParam+"); ";
	  					};
	  return l;
	  };
	  
	  
	  CGp.doAction=function(datatype,data)
	  	{
			if(Def(datatype)&&Def(data))
				this.init(datatype,data);
			if(ua.oldOpera&&window.location.href.indexOf("?")>1)
				{
					var func=window.location.href.slice(window.location.href.indexOf("?")+1);
					var stack=[];
					var toDo="";
					while(func.indexOf("&")>-1)
						{
							stack[stack.length]=func.slice(0,func.indexOf("&"));
							func=func.slice(func.indexOf("&")+1);
	  					};
					stack[stack.length]=func;
					if(Def(stack))
						{
							for(i=0;i<stack.length;i++)
								{
									stack[i]=stack[i].replace(new RegExp("\\("),"(\"").replace(new RegExp(","),"\",\"").replace(new RegExp("\\)"),"\")");
									toDo+=this.name+"."+stack[i]+";\n";
	  							};
							eval(toDo);
	  					}
					this.paint();
	 			 }
				 else
				 	{
						this.paint();
	  				};
	  };
	  
	  
	  
	  CGp.callRowHandler=function()
	  	{
			if(this.useEdit)
				{
					this.getEditValues();
	 			 };
			if(Def(this.rowHandler))
				{
					this.rowHandler(this.getKeyArray(this.keyCol));
	  			}
		};
		
		
	CGp.getID=function(prx){
		return this.name+prx;
	  };
	  
	CGp.showportfoliocharthower=function(rowid)	
	  	{
			var t=this;
			if (rowid == -1)
				t.showportfoliochart(rowid);
			else 
			{	
				if (t.displayseries)
				{
				t.statisticsHTML = t.SetStrategyStatistics(rowid);
				if (t.statisticsHTML == "")
					return true;
				draw_strategy_statistics.innerHTML=t.statisticsHTML; 
				if (t.showcharts)
					t.chartHTML=t.DrawPortfolioChart(rowid,t.tableRightWidth,200);
				}
			}
	    }
	
	CGp.showportfoliochart=function(rowid)	
	  	{
			var t=this;
			//t.selectedRow = rowid;
			if (t.showcharts)
				{
				t.statisticsHTML = t.SetPortfolioStatistics(rowid);
				if (t.statisticsHTML == "")
					return true;
				draw_strategy_statistics.innerHTML=t.statisticsHTML; 
				t.chartHTML=t.DrawPortfolioChart(rowid,t.tableRightWidth,200);
				}
		};
		
	CGp.SetResultsLine=function(title,value1,value2)	
	  	{
		var h="<tr><td width=\"160\">";
		var tdstyle = "<div align=\"left\" style=\"margin-top:6px; margin-bottom:6px; margin-left:5px;\">";
	   	h+=tdstyle+"<b>"+title+"</b></div></td><td>";
		if (value2 == "")
			h+=tdstyle+"&nbsp;&nbsp;&nbsp;&nbsp; "+value1+"</div></td>";
		else
			{
				h+=tdstyle+"&nbsp;&nbsp;&nbsp; "+value1+"</div></td><td>";
				h+=tdstyle+"&nbsp;&nbsp;&nbsp;&nbsp; "+value2+"</div></td>";
			}
		h+="</tr>";
		return h;
		}
	
	CGp.SetRegistrationLine=function(title,value1,value2)	
	  	{
		var h="<tr><td width=\"10\">";
		var tdstyle = "<div align=\"left\" style=\"margin-top:3px; margin-bottom:3px; margin-left:5px;\">";
		h+=tdstyle+"<b>"+title+"</b></div></td>";
		if (title!="") {
	   		h+="<td align=\"left\" colspan=\"2\">";
			h+=tdstyle+value1+"</div></td></tr>";
		}
		else
			{
			h+="<td align=\"left\" width=\"160\">";
			h+=tdstyle+value1+"</div></td><td align=\"left\">";
			h+=tdstyle+value2+"</div></td></tr>";
			}
		return h;
		}
		
	CGp.isValidNumberOfStrategies=function(count)	
	  	{
		if (count == 0)
			{
			alert("There are no strategies in your portfolio, please check mark at least one strategy.");
			return false;
			}
		if (count > t.maxPortfolio)
			{
			alert("There are over " + t.maxPortfolio + " strategies in your portfolio, please uncheck some of the strategies.");
			return false;
			}
		return true;
		}
	
	CGp.SetDisplayStrategyStatistics=function(rowid)	
	  	{
			var t=this;
			t.showportfoliocharthower(rowid);
		}
		
	CGp.DrawPortfolioStatistics=function(rowid)	
	{
		var h="", t=this;
		
		var t=this,h="";
		var imgTooltip = "<img src=\"http://www.strategyxchange.com/Matrix/images/info_help.gif\"></img>";
		var tooltip_text_inner="Adjust lot sizes to meet your Risk and Return criterions, click Update Portfolio Results";
		var strategyname = "";
		
		var comboboxstrategy="<select id=\"selectedstrategy\" name=\"selectedstrategy\" onChange=\"t.SetDisplayStrategyStatistics(this.value)\" >";
		if (rowid == -1)
			comboboxstrategy+="<option value=\"-1\" selected>...</option>";
		else
			comboboxstrategy+="<option value=\"-1\">...</option>";
		for(i=0;i<t.rows.length;i++)
			if (t.rows[i].isVisible)
				{
					var Strategydata=new String(t.cells[i][t.StrategyCol].getDataForFilter());
					strategyname=Strategydata.substring(Strategydata.indexOf(":")+1,Strategydata.length);
					if (strategyname.length > 25)
					strategyname=strategyname.substring(0,25);
					if (rowid == i)
						comboboxstrategy+="<option value=\""+i+"\" selected>"+strategyname+"</option>";
					else
						comboboxstrategy+="<option value=\""+i+"\" >"+strategyname+"</option>";
				}
		comboboxstrategy+="</select>";
		
		//alert(checkboxstrategy);
		tooltip_text_inner = "<SPAN title=\"" +tooltip_text_inner+"\" class=\"popup\" >"+imgTooltip+"</SPAN>"; 
		
		h=t.styledTable(t.tableLeftWidth);
    	h+="<tr>";
		h+=t.styledResultsTitle("Portfolio Statistics",comboboxstrategy,tooltip_text_inner,"Portfolio_statistics_div"); 
    	h+="</tr>";
		h+="<tr><td colspan=3>";
				
		h+=t.emptystyledTable();
		
		if (rowid == -1) 
			{
			h+=t.SetResultsLine("Starting Capital ($)","$"+t.addCommas(t.Starting_Capital_USD.toFixed(2)),"");
			h+=t.SetResultsLine("End Capital ($)","$"+t.addCommas(t.endCapital.toFixed(2)),"");
			h+=t.SetResultsLine("Total P&amp;L ($)","$"+t.addCommas(t.Total_PnL_USD.toFixed(2)),"");
			h+=t.SetResultsLine("Total P&amp;L (\%)",t.Total_PnL_Percent.toFixed(2)+"%","");
			h+=t.SetResultsLine("Start Date",t.Start_Date+" years","");
			h+=t.SetResultsLine("Max Draw Down ($)","$"+t.addCommas(t.Max_Draw_Down_USD.toFixed(2)),"");
			h+=t.SetResultsLine("Max Draw Down (%)",t.Max_Draw_Down_Percent.toFixed(2)+"%","");
			h+=t.SetResultsLine("Portfolio Cost ($)","$"+t.addCommas(t.Portfolio_Cost_USD)+" per month","");
			}
		else
			{
			h+=t.SetResultsLine("Starting Capital ($)","$"+t.addCommas(t.Starting_Capital_USD.toFixed(2)),"$"+t.addCommas(t.Strategy_Starting_Capital_USD.toFixed(2)));
			h+=t.SetResultsLine("End Capital ($)","$"+t.addCommas(t.endCapital.toFixed(2)),"$"+t.addCommas(t.Strategy_endCapital.toFixed(2)));
			h+=t.SetResultsLine("Total P&amp;L ($)","$"+t.addCommas(t.Total_PnL_USD.toFixed(2)),"$"+t.addCommas(t.Strategy_Total_PnL_USD.toFixed(2)));
			h+=t.SetResultsLine("Total P&amp;L (\%)",t.Total_PnL_Percent.toFixed(2)+"%",t.Strategy_Total_PnL_Percent.toFixed(2)+"%");
			h+=t.SetResultsLine("Start Date",t.Start_Date+" years",t.Strategy_Start_Date+" years");
			h+=t.SetResultsLine("Max Draw Down ($)","$"+t.addCommas(t.Max_Draw_Down_USD.toFixed(2)),"$"+t.addCommas(t.Strategy_Max_Draw_Down_USD.toFixed(2)));
			h+=t.SetResultsLine("Max Draw Down (%)",t.Max_Draw_Down_Percent.toFixed(2)+"%",t.Strategy_Max_Draw_Down_Percent.toFixed(2)+"%");
			h+=t.SetResultsLine("Portfolio Cost ($)","$"+t.addCommas(t.Portfolio_Cost_USD)+" per month","$"+t.addCommas(t.Strategy_Portfolio_Cost_USD)+" per month");
			}
		h+="</td></tr>";
		h+="</table>";
		h+="</table>";
				
		return h;
	}
	
	CGp.SetPortfolioStatistics=function(rowid)	
	  	{
		var t=this,h="";
		var strategyname = "";
		
		t.Starting_Capital_USD = 0;
		t.endCapital = 0;
		t.Total_PnL_USD = 0;
		t.Total_PnL_Percent = 0;
		t.Start_Date = 0;
		t.Max_Draw_Down_USD = 0;
		t.Max_Draw_Down_Percent = 0;
		t.Portfolio_Cost_USD = 0;
			
		var cParams=0;
		for(i=0;i<t.rows.length;i++)
			{
				var value = t.getProductId(i);	
				if (t.isCheckedRow(i))
					{
					cParams += 1;
					var lots_data = new String(t.cells[i][t.LotsCol].getDataForFilter());
					var Pos = lots_data.search(":");
					var Lotsdata = parseFloat(lots_data.substring(Pos+1,lots_data.length));
					
					var SCapitaldata=parseFloat(t.cells[i][t.SCapitalCol].getDataForFilter());
					var TotalPnLdata=parseFloat(t.cells[i][t.TotalPnLCol].getDataForFilter());
					var Costdata=parseFloat(t.cells[i][t.CostCol].getDataForFilter());
					var StartDatedata=parseFloat(t.cells[i][t.StartDateCol].getDataForFilter());
					var productId=value;
					t.Starting_Capital_USD+=SCapitaldata*Lotsdata;
					t.Total_PnL_USD+=TotalPnLdata*SCapitaldata*Lotsdata*0.01;
					t.Portfolio_Cost_USD+=Costdata*Lotsdata;
					if (t.Start_Date < StartDatedata) t.Start_Date=StartDatedata;
					}
			}
		if (t.Starting_Capital_USD == 0)
			t.Total_PnL_Percent = 0;
		else 
			t.Total_PnL_Percent = t.Total_PnL_USD/t.Starting_Capital_USD*100;
		t.initPortfolioStatistics();	
		t.Max_Draw_Down_USD = t.MaxDrawDown(-1);
		var Sharpe_Ratio_Percent = t.SharpeRatio(-1);
		if (t.Starting_Capital_USD == 0)
			t.Max_Draw_Down_Percent = 0;
		else 
			t.Max_Draw_Down_Percent = t.Max_Draw_Down_USD/t.Starting_Capital_USD*100;
		t.endCapital = t.Total_PnL_USD+t.Starting_Capital_USD;
			
		if (!t.isValidNumberOfStrategies(cParams))
			return h;
	  	
		if (rowid == -1) 
			h=t.DrawPortfolioStatistics(rowid);
		if (rowid != -1 && t.displayseries)
			h=t.SetStrategyStatistics(rowid);
		return h;
		}
		

CGp.SetStrategyStatistics=function(rowid)	
	  	{
		var t=this,h="";
		var i=rowid;
		
		t.Strategy_Starting_Capital_USD = 0;
		t.Strategy_Total_PnL_USD = 0;
		t.Strategy_endCapital = 0;
		t.Strategy_Total_PnL_Percent = 0;
		t.Strategy_Start_Date = 0;
		t.Strategy_Portfolio_Cost_USD = 0;
		t.Strategy_Max_Draw_Down_USD = 0;
		t.Strategy_Max_Draw_Down_Percent = 0;
		
		var lots_data = new String(t.cells[i][t.LotsCol].getDataForFilter());
		var Pos = lots_data.search(":");
		var Lotsdata = parseFloat(lots_data.substring(Pos+1,lots_data.length));
		var SCapitaldata=parseFloat(t.cells[i][t.SCapitalCol].getDataForFilter());
		var TotalPnLdata=parseFloat(t.cells[i][t.TotalPnLCol].getDataForFilter());
		var Costdata=parseFloat(t.cells[i][t.CostCol].getDataForFilter());
		var StartDatedata=parseFloat(t.cells[i][t.StartDateCol].getDataForFilter());
		t.Strategy_Starting_Capital_USD = SCapitaldata*Lotsdata; 
		t.Strategy_Total_PnL_USD = TotalPnLdata*SCapitaldata*Lotsdata*0.01;
		t.Strategy_endCapital = t.Strategy_Starting_Capital_USD+t.Strategy_Total_PnL_USD;
		if (t.Strategy_Starting_Capital_USD == 0)
			t.Strategy_Total_PnL_Percent = 0;
		else 
			t.Strategy_Total_PnL_Percent = t.Strategy_Total_PnL_USD/t.Strategy_Starting_Capital_USD*100;
		t.Strategy_Start_Date=StartDatedata;
		t.Strategy_Portfolio_Cost_USD=Costdata;
					
		t.initStrategyStatistics(rowid);	
		t.Strategy_Max_Draw_Down_USD=t.MaxDrawDown(rowid);
		if (t.Strategy_Starting_Capital_USD == 0)
			t.Strategy_Max_Draw_Down_Percent = 0;
		else 
			t.Strategy_Max_Draw_Down_Percent = t.Strategy_Max_Draw_Down_USD/t.Strategy_Starting_Capital_USD*100;
		
		h = t.DrawPortfolioStatistics(rowid);
		return h;
		}

	CGp.addCommas=function(nStr)
	{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
	}

CGp.initPortfolioStatistics=function()	
		{
		var t=this,h="";
		var Starting_Capital_USD=0
		var Max_Draw_Down_USD = 0;
		
		var cParams=0;
		
		var todayDate=new Date(); 
		var startDate=new Date();
		var currentDate=new Date(); 
		
		startDate.setMonth(0);
		startDate.setDate(1);
		currentDate.setMonth(0);
		currentDate.setDate(1);
		
		t.serieslength = 0;	
		t.stringLst = new Array(1);
		t.numberLst = new Array(1);
			
		while (currentDate <= todayDate)
			{
			var month = currentDate.getMonth()+1;
			var day = currentDate.getDate();
			var date = "2007-"+((month<10)?"0"+month:month)+"-"+((day<10)?"0"+day:day);
			t.stringLst.length = t.serieslength+1;
			t.numberLst.length = t.serieslength+1;
			
			t.stringLst[t.serieslength] = date;
			t.numberLst[t.serieslength] = 0;	
			
			currentDate.setDate(currentDate.getDate()+1);
			t.serieslength+=1;
			}	
		
		for(i=0;i<t.rows.length;i++)
			{
				var value = t.getProductId(i);	
				if (t.isCheckedRow(i))
					{
					cParams += 1;
					var lots_data = new String(t.cells[i][t.LotsCol].getDataForFilter());
					var Pos = lots_data.search(":");
					var Lotsdata = parseFloat(lots_data.substring(Pos+1,lots_data.length));
					
					
					var SCapitaldata=parseFloat(t.cells[i][t.SCapitalCol].getDataForFilter());
					var productId=value;
					var TotalPnLdata=parseFloat(t.cells[i][t.TotalPnLCol].getDataForFilter());
					Starting_Capital_USD+=SCapitaldata*Lotsdata;
					
					var strPageName = "http://www.strategyxchange.com/Charts/"+productId+"/chart.xml";
					t.loadXMLFile(strPageName);
					var iP=0;
	 				var iS=0;
					
					for (iP=0;iP<t.serieslength;iP++)
			 			{
						while (iS<t.stringStrategyLst.length-1 
							   && t.stringStrategyLst[iS].childNodes[0].nodeValue < t.stringLst[iP])
							iS+=1;
						if (iS>=t.stringStrategyLst.length-1)
			 				break;
						var strategy_PnL = parseFloat(t.numberStrategyLst[iS].childNodes[0].nodeValue);
						if (strategy_PnL != 0 && t.stringStrategyLst[iS].childNodes[0].nodeValue == t.stringLst[iP])
							{
							t.numberLst[iP] = t.numberLst[iP]+strategy_PnL*Lotsdata*SCapitaldata*0.01;	 
							}
						else 
							{
							if (iP>0)
								t.numberLst[iP]=t.numberLst[iP-1];
							}
						}
					for (iX=iP;iX<t.serieslength;iX++)
			 			if (iX>0)
							t.numberLst[iX]=t.numberLst[iX-1];
	 				}
			}
			
		for (i=0;i<t.serieslength;i++)
			t.numberLst[i] += Starting_Capital_USD;
		};
		
		
		CGp.initStrategyStatistics=function(rowid)	
		{
		var t=this,h="";
		var Starting_Capital_USD=0
			
		var i=rowid;
		var value = t.getProductId(i);	
		var lots_data = new String(t.cells[i][t.LotsCol].getDataForFilter());
		var Pos = lots_data.search(":");
		var Lotsdata = parseFloat(lots_data.substring(Pos+1,lots_data.length));
			
		var SCapitaldata=parseFloat(t.cells[i][t.SCapitalCol].getDataForFilter());
		var productId=value;
		var TotalPnLdata=parseFloat(t.cells[i][t.TotalPnLCol].getDataForFilter());
		Starting_Capital_USD+=SCapitaldata*Lotsdata;
					
		var strPageName = "http://www.strategyxchange.com/Charts/"+productId+"/chart.xml";
		t.loadXMLFile(strPageName);
		t.ToTalPnLStrategyLst = new Array(1);
		for (iP=0;iP<t.numberStrategyLst.length;iP++)
			{
			t.ToTalPnLStrategyLst.length = iP+1;
			t.ToTalPnLStrategyLst[iP] = 0;
			var strategy_PnL = parseFloat(t.numberStrategyLst[iP].childNodes[0].nodeValue);
			if (strategy_PnL != 0)
				t.ToTalPnLStrategyLst[iP] = strategy_PnL*Lotsdata*SCapitaldata*0.01;	 
			else 
				{
				if (iP>0)
					t.ToTalPnLStrategyLst[iP]=t.ToTalPnLStrategyLst[iP-1];
				}
			}
			
		for (i=0;i<t.numberStrategyLst.length;i++)
			t.ToTalPnLStrategyLst[i] += Starting_Capital_USD;
		};
		
	CGp.MaxDrawDown=function(rowid)	
		{
		var Max_Draw_Down_USD = 0;
							
		var MaxDD = 0, LocalDD = 0, Max = 0, TotalPnL = 0;
        var serieslength;
		if (rowid == -1)
		    serieslength = t.serieslength;
		else
		    serieslength = t.ToTalPnLStrategyLst.length-1;
		
		for (i=0;i<serieslength;i++)
			{
			if (rowid == -1)
				TotalPnL = t.numberLst[i];
			else
				TotalPnL = t.ToTalPnLStrategyLst[i];
			
			if (TotalPnL > Max) 
				{
				Max = TotalPnL;
				if (MaxDD < LocalDD) 
					MaxDD = LocalDD;
				LocalDD = 0;
				}
			else
				{
				if (TotalPnL < Max && LocalDD < Max - TotalPnL)
						LocalDD = Max - TotalPnL;
				}
			}
            
        if (MaxDD < LocalDD) 
            MaxDD = LocalDD;
							    
		Max_Draw_Down_USD = (-1)*MaxDD;	
		return Max_Draw_Down_USD;
		};
	
	CGp.SharpeRatio=function()	
	  	{
		var SharpeRatio_Percent = 0;
		var avgMonthlyReturn = 0, StartBalance = 0, EndBalance = 0, NumberOfMonth = 0;
        var MonthlyReturn = 0; 
		var MonthlyRiskFreeRate = 0.02/12.0;
        var stdMonthlyReturn = 0;
        var StartDate, EndDate, CurrDate;
        var fFirstMonth = true;
		var sqrt12 = Math.sqrt(12.0);

		StartDate = "2000-01-01";
		for (i=0;i<t.serieslength;i++)
			{
			CurrDate = t.stringLst[i];
			if (CurrDate.substring(5,8) != StartDate.substring(5,8))
				{
					// new month
					if (fFirstMonth) 
						{
						StartBalance = t.numberLst[i];
						fFirstMonth = false;
						}
					else
						{
						EndBalance = t.numberLst[i];
						if (StartBalance != 0)
							MonthlyReturn = ((EndBalance - StartBalance)/StartBalance);
						avgMonthlyReturn += MonthlyReturn;
						StartBalance = EndBalance;
						NumberOfMonth++;
						}
				}			
			}
		if (NumberOfMonth != 0)
			avgMonthlyReturn = avgMonthlyReturn / NumberOfMonth;					    
		StartDate = "2000-01-01";
		fFirstMonth = true;
		for (i=0;i<t.serieslength;i++)
			{
			CurrDate = t.stringLst[i];
			if (CurrDate.substring(5,8) != StartDate.substring(5,8))
				{
					if (fFirstMonth) 
						{
						StartBalance = t.numberLst[i];
						fFirstMonth = false;
						}
					else
						{
						EndBalance = t.numberLst[i];
						if (StartBalance != 0)
							MonthlyReturn = ((EndBalance - StartBalance)/StartBalance);
						stdMonthlyReturn += (MonthlyReturn-avgMonthlyReturn)*(MonthlyReturn-avgMonthlyReturn);
						StartBalance = EndBalance;
						}
				}			
			}
		if (NumberOfMonth != 0)
			stdMonthlyReturn = stdMonthlyReturn / NumberOfMonth;					    
		if (stdMonthlyReturn != 0)
			{
				stdMonthlyReturn = Math.sqrt(stdMonthlyReturn); 
				SharpeRatio_Percent = sqrt12*(avgMonthlyReturn - MonthlyRiskFreeRate)/stdMonthlyReturn;	
			}
		return SharpeRatio_Percent;
		}
	
	CGp.showstrategychart=function(rowid)	
	  	{
			var t=this;
			t.selectedRow = rowid;
			if (t.showcharts)
				{
				var Strategydata=new String(t.cells[rowid][t.StrategyCol].getDataForFilter());
				var Vendordata=new String(t.cells[rowid][t.VendorCol].getDataForFilter());
				var product_id = t.getProductId(rowid);					
	   		    var strPageName = "http://www.strategyxchange.com/Charts/"+product_id+"/chart.xml";
				var strLargePageName = "http://www.strategyxchange.com/Charts/"+product_id+"/chart_large.xml";
				
				t.chartHTML=t.DrawChartURL(strPageName,t.tableRightWidth,200);
				var code_value = t.DrawChartObject(strLargePageName,"strategy_popup_charts",820,410);
				code_value = "<input type='hidden' id=xx_chart_code name='xx_chart_code' value='" + code_value +"'></input>";
				draw_chart_code.innerHTML = code_value;
				
				var strategyname=Strategydata.substring(Strategydata.indexOf(":")+1,Strategydata.length);
				if ((strategyname.length + Vendordata.length) < 40)
					strategyname=Vendordata+" : "+strategyname;
				
				t.strategy_titleHTML = t.styledTitlewithID(strategyname);
				draw_strategy_title.innerHTML=t.strategy_titleHTML;
				}
		};
	  
};




function CCodeThatRow(grid,id)
	{
		var t=this;
		t.grid=grid;
		t._id=id;
		t.isMark=0;
		t.isVisible=1;
		t.css=t.grid.rowStyle.lightClass;
	  };
	  
	  
{
	var CRp=CCodeThatRow.prototype;
	
	CRp.setMark=function()
		{
			var z,idx1,idx2,idx3;
			this.isMark=(!this.isMark);
			this.setCSS();
		//	t.checkboxOnClick(this._id);
			if(isCtrl)
				{
					this.grid.rowStart=this._id;
					this.grid.callRowHandler();
	  			return;
	  			}
			for(z=0;z<this.grid.rows.length;z++)
				{
					if(z!=this._id&&this.grid.rows[z].isMark)
						{
							this.grid.rows[z].isMark=0;
							this.grid.rows[z].setCSS();
	  					};
	  			};
	  
	  if(isShift)
	  	{
			if(this.grid.rowStart==-1)
				this.grid.rowStart=this._id;
				var idx1=this.grid.rowIndex.indexOf(this.grid.rowStart),idx2=this.grid.rowIndex.indexOf(this._id),idx3=0;
				if(idx1>idx2)
					{
						idx3=idx1;
						idx1=idx2;
						idx2=idx3;
	  			};
				for(z=idx1;z<=idx2;z++)
					{
						if(this.grid.rowIndex[z]==this._id)continue;
						else{this.grid.rows[this.grid.rowIndex[z]].isMark=1;
						this.grid.rows[this.grid.rowIndex[z]].setCSS();
	  };
	  };
	  }else{this.grid.rowStart=this._id;
	  };
	  this.grid.callRowHandler();
	  };
	  
	  
	  
	  CRp.setCSS=function(css)
	  	{
			var t=this,htmlObjName=t.grid.name+"_row_"+t._id;
			if(ua.oldB)
				return;
			if(Def(window.document.getElementById(htmlObjName)))
				{
					if(Undef(css))
						{
							if(t.isMark)CT_css(htmlObjName,t.grid.rowStyle.markClass);
							else CT_css(htmlObjName,t.css);
	 				 }
				else{CT_css(htmlObjName,css);
	  };
	  };
	  };
	  
	  
	  CRp.setHover=function()
	  	{
			if(ua.oldB)
				return;
			this.setCSS(this.grid.rowStyle.hoverClass);
			if(this._id!=this.grid.rowHover&&this.grid.rowHover>-1)
				this.grid.rows[this.grid.rowHover].setCSS();
			this.grid.rowHover=this._id;
			this.grid.selectedRow = this.grid.rowHover;
			
			switch (t.Phase)
				{
					case 1: t.showstrategychart(this.grid.rowHover); break;
					case 2: t.selectedRow = this.grid.rowHover; break; //t.showportfoliocharthower(this.grid.rowHover); break;
				}
	  };
	  
	  	
	  
	  
	  CRp.valueOf=function(){
			return this._id;
	  };
	  
	  };
	  
	  
	  function CCodeThatColumn(grid,id,colDef)
	  	{
			var t=this,i,w=0;
			t.grid=grid;
			t._id=id;
			t.useSort=1;
			t.index=[];
			t.filter=[];
			t.filterValue="";
			for(i in DEFAULT_COLDEF)
				t[i]=DEFAULT_COLDEF[i];
			if(Def(colDef))
				{
					for(i in colDef)
						{
							if(Def(colDef[i]))
								if(i.indexOf("is")>-1||i.indexOf("use")>-1||i.indexOf("Function")>-1)
									eval("t[i] = "+colDef[i]);
								else 
									t[i]=colDef[i];
	  					};
					w=parseInt(colDef.width);t.width=(isNaN(w)||w>0)?" width=\""+colDef.width+"\"":"";t.alignment=(Def(colDef.alignment))?" align=\""+colDef.alignment+"\"":"";
	  			};
			if(Undef(t.title))
				t.title='Column #'+id;
			if(Undef(t.titleClass))
				t.titleClass=t.defaultClass;
			if(Undef(t.titleClass))
				t.titleClass=t.grid.tableStyle.thClass;
			if(Undef(t.tooltip))
				t.tooltip='';
	  };
	  
	  {
		  var CCp=CCodeThatColumn.prototype;
		  CCp.titleToHTML=function(colSortType)
		  	{
				var t=this,g=t.grid,h="",l=[g.imgSortAsc,t.title,g.imgSortDesc],i;
				var activeAsc=false, activeDesc=false;
				if(!g.useSort||!t.useSort)
					return t.title;
				if(g.sortCol==t._id)
					{
						if(g.sortType==1)
							{
							l=[g.imgSortAscActive,t.title,g.imgSortDesc];
							activeAsc=true;
							activeDesc=false;
							}
						else 
							{
							l=[g.imgSortAsc,t.title,g.imgSortDescActive];
							activeAsc=false;
							activeDesc=true;
							}
	  				}
				if(l.length==3)
					{
						h =l[1];
						if ((colSortType == "asc" && !activeAsc)||activeDesc)
							h+=" <a class="+t.titleClass+" href=\""+g.setAction("setSort",t._id+",1")+"\">"+l[2]+"</a>";
						if ((colSortType == "desc" && !activeDesc)||activeAsc)
							h+=" <a class="+t.titleClass+" href=\""+g.setAction("setSort",t._id+",-1")+"\">"+l[0]+"</a>";
	  				}
					
				return h;
	  };
	  	
		
		
	CCp.getID=function(prx)
		{
			var t=this;
	  	    return t.grid.getID(prx)+t._id;
	     };
	
	CCp.setFilter=function()
		{
			var t=this,g=t.grid,i,v;
			if(!t.useAutoFilter)
				return;
			t.filter.length=0;
			for(i=0;i<g.rows.length;i++)
				{
					v=g.cells[i][t._id].getDataForFilter();
					if(Def(v)&&typeof(v)!='unknown'&&t.filter.indexOf(v)==-1)
						t.filter[t.filter.length]=v;
	  			};
			if(!ua.oldB)
				eval("try{t.filter = t.filter.sort(compare)}catch(e){}");
			else 
				t.filter=t.filter.sort(compare);
	  };
	  
	  CCp.setCostFilter=function()
		{
			var t=this, v1="0 - 100", v2="100 - 200", v3="200 - 500", v4="500 - 1,000", v5="> 1,000";
			
			t.filter.length=0;
			t.filter[t.filter.length]=v1;
			t.filter[t.filter.length]=v2;
			t.filter[t.filter.length]=v3;
			t.filter[t.filter.length]=v4;
			t.filter[t.filter.length]=v5;
	  };
	  
	  CCp.setTotalPnLFilter=function()
		{
			var t=this, v1="0% - 50%", v2="50% - 100%", v3="> 100%";
			
			t.filter.length=0;
			t.filter[t.filter.length]=v1;
			t.filter[t.filter.length]=v2;
			t.filter[t.filter.length]=v3;
	  };
	  
	   CCp.setDrawdownFilter=function()
		{
			var t=this, v1="< 10%", v2="< 20%", v3="< 50%";
			
			t.filter.length=0;
			t.filter[t.filter.length]=v1;
			t.filter[t.filter.length]=v2;
			t.filter[t.filter.length]=v3;
	  };
	  	  
	   CCp.setAgeFilter=function()
		{
			var t=this, v1="< 1 mth", v2="1 mth - 3 mths", v3="> 3 mths";
			
			t.filter.length=0;
			t.filter[t.filter.length]=v1;
			t.filter[t.filter.length]=v2;
			t.filter[t.filter.length]=v3;
	  };
	  
	  CCp.setCapitalFilter=function()
		{
			var t=this, v1="< 3,000", v2="< 4,000", v3="< 5,000", v4="< 7,500", v5="< 10,000", v6="< 15,000", v7="< 20,000", v8="< 30,000", v9="> 30,000";
			
			t.filter.length=0;
			t.filter[t.filter.length]=v1;
			t.filter[t.filter.length]=v2;
			t.filter[t.filter.length]=v3;
			t.filter[t.filter.length]=v4;
			t.filter[t.filter.length]=v5;
			t.filter[t.filter.length]=v6;
			t.filter[t.filter.length]=v7;
			t.filter[t.filter.length]=v8;
			t.filter[t.filter.length]=v9;
			
	  };
	  
	  CCp.filterToHTML=function()
	  	{
			var t=this,i,h="&nbsp;",a="";
			if(!t.useAutoFilter)
				return h;
			if(!ua.nn4)
				{
					a=t.grid.setAction("setFilter",t._id+",this.value");
					if(a.indexOf("javascript")==-1)
						a="window.location.href='"+a+"'";
					else 
						a=t.grid.name+".setFilter("+t._id+", this.options[this.selectedIndex].value)";a="onChange=\""+a+"\"";
	  			};
			h="<select id='"+t.getID("filter")+"' name='"+t.getID("filter")+"' "+a+"><option value=''>"+EMPTY_ROW+"</option>";
			for(i=0;i<t.filter.length;i++)
				h+="<option value=\""+t.filter[i]+"\""+((t.filterValue!=""&&t.filter[i].toString()==t.filterValue)?" selected":"")+">"+t.filter[i]+"</option>";
			h+="</select>";
			if(ua.nn4)
				h+="&nbsp; <a href=\""+t.grid.setAction("setFilter",t._id+", window.document.layers['"+t.grid.name+"'].document.forms['f"+t.grid.name+"']."+t.getID("filter")+".options[window.document.layers['"+t.grid.name+"'].document.forms['f"+t.grid.name+"']."+t.getID("filter")+".selectedIndex].value")+"\">OK</a>";
			return h;
	  	};
	  
	  };
	  
	  function CCodeThatCell(row,col,data)
	  	{
			var t=this;
			t.row=row;
			t.col=col;
			switch(this.col.type)
				{
					case "Date":data=parseDate(data,DATE_FORMAT);break;
					case "Image":break;
					default:if(ua.oldB)eval("data = parse"+this.col.type+"(data)");else eval("try{eval(\"data = parse\" + this.col.type + \"(data)\");}catch(e){};");break;
	  			};
		  t.data=data;
	  };
	  
	  {
		  
		  var CCp=CCodeThatCell.prototype;
		  CCp.compareTo=function(cell)
		  	{
			return this.col.compareFunction(this.data,cell.data);
	  		};
			
		CCp.getData=function()
			{
				var t=this,data="";
				switch(t.col.type)
					{
						case "Image":if((Def(t.data)&&t.data.constructor!=Object)||ua.oldOpera)t.data=parseImage(t.data);data=formatImage(t.data);break;
						case "String":
						case "Number":
						case "HTML":
						case "Email":if(ua.oldB)eval("data = format"+this.col.type+"(t.data)");else eval("try{eval(\"data = format\" + this.col.type + \"(t.data)\");}catch(e){};");break;
						case "URL":
						case "Date":
						case "Currency":
						default:if(ua.oldB)eval("data = format"+t.col.type+"(t.data, "+t.col.type.toUpperCase()+"_FORMAT)");else eval("try{eval('data = format' + t.col.type + '(t.data, ' + t.col.type.toUpperCase() + '_FORMAT)');}catch(e){data = t.data}; ");break;
	  				};
	  			return data;
	  		};
			
		CCp.getDataForFilter=function()
			{
				var t=this;
				switch(t.col.type)
					{
						case "Date":if(ua.oldB)eval("data = format"+t.col.type+"(t.data, "+t.col.type.toUpperCase()+"_FORMAT)");else eval("try{eval('data = format' + t.col.type + '(t.data, ' + t.col.type.toUpperCase() + '_FORMAT)');}catch(e){data = t.data};");break;
						case "Image":if(this.data.src.indexOf("undefined")<0){start=((this.data.src.lastIndexOf("/")<0)?this.data.src.lastIndexOf("\\"):this.data.src.lastIndexOf("/"))+1;data=this.data.src.slice(start);}else data="No image";break;
						default:data=this.data;break;
					  };
	 			 return data;
	 		 };
	  };
	  
	  
	  CodeThat.regEventHandler('keydown',isEnterPressed);
	  CodeThat.regEventHandler('click',isKeyHold);
	  CodeThat.regEventHandler('mousemove',isKeyHold);
	  CodeThat.regEventHandler('selectstart',cancelSelection);
	  var isEnter=0,isShift=0,isCtrl=0,isAlt=0,curId=0,w=null;
	  function cancelSelection(e)
	  	{
			if(e._e.shiftKey||e._e.ctrlKey)
				{
					if(ua.moz&&e._e.cancelable)e._e.preventDefault();
					else e._e.returnValue=false;
	  				return false;
	  			};
	  };
	  
	  
	  function isEnterPressed(e)
	  	{
			if(e._e.keyCode==13)
				isEnter=1;
			else 
				isEnter=0;
			isKeyHold(e);
	  };
	  
	  
	  function isKeyHold(e)
	  	{
			isShift=e.shift;
			isCtrl=e.ctrl;
			isAlt=e.alt;
	  };
	  
	  
	  function keyPress(buttonObj)
	  	{
			if(Def(window.event))
				{
					isEnter=(window.event.keyCode==13);
	  			};
			if(isEnter)
				buttonObj.click();
	  };
	  
	  var CTp=CCodeThatTable.prototype;
	  CTp.getEditValues=function()
	  	{
			var t=this,i,j,idx,test=[],result=[];
			idx=t.getKeyArray(-1);
			for(j=0;j<t.cols.length;j++)
				{
					for(i=0;i<idx.length;i++)
						{
							test[i]=t.cells[idx[i]][j].data;
	  					};
					result[j]=test.isSame();
	  			};
			t.printEditValues(result);
	  };
	  
	  CTp.printEditValues=function(res)
	  	{
			var t=this,i,k=t.getKeyArray(-1);
			if(!res||!res.length||!k.length)
				return;
			for(i=0;i<t.cols.length;i++)
				{
					t.printEditValue(i,res[i]);
	  			};
	  };
	  
	  
	  CTp.printEditValue=function(i,res)
	  	{
			var t=this;
			if(t.cols[i].input)
				{
					switch(t.cols[i].input)
						{
							case "select":res=t.cols[i].value.toCombo('combo'+i,res,t.name+'.setEditValue('+i+', this.value)',0,t.cols[i].nullValue,t.cols[i].hint);break;
							case "radio":res=t.cols[i].value.toRadio('radio'+i,res,t.name+'.setEditValue('+i+', this.value)');break;
							case "checkbox":res=t.cols[i].value.toCheckbox('checkbox'+i,res,t.name+'.setEditValue('+i+', this.value)');break;
							case "text":res=toText('text'+i,res,t.name+'.setEditValue('+i+', this.value)');break;
							case "button":res=t.cols[i].value.toButton('button'+i);break;
	  					};
	  	  CT_HTML(t.getID('edit'+i),res);
	  };
	  };
	  
	  
	  CTp.setEditValue=function(col,value)
	  	{
			var t=this,i,idx;
			if(!value||value=='')
				{
					if(!confirm('Do you really wish to set empty value?'))
						return;
			  	};
			idx=t.getKeyArray(-1);
			for(i=0;i<idx.length;i++)
				{
					t.def.data[idx[i]][col]=value;
					t.cells[idx[i]][col].setData(value);
					t.rows[idx[i]].isChange=1;
	  			};
			t.setPage(t.page);
	  };
	  
	  
	  CTp.exportEditValues=function()
	  	{
			var t=this,i,j,k=0,value=[];
			for(i=0;i<t.rows.length;i++)
				{
					if(t.rows[i].isChange)
						{
							value[k]=[];
							for(j=0;j<t.cols.length;j++)
								{
									value[k][j]=t.cells[i][j].getDataForFilter();
	  							};
							k++;
	  					};
	  			};
	  return value.toStr();
	  };
	  
	  var CCp=CCodeThatCell.prototype;
	  CCp.setData=function(data)
	  	{
			var t=this,f,err="",i;
			switch(t.col.type)
				{
					case "Date":if(Def(data)&&parseDate(data,DATE_FORMAT)==null){err=data;data=t.data;}else data=parseDate(data,DATE_FORMAT);break;
					case "Image":break;
					case "Number":
					case "Currency":
					default:if(ua.oldB)eval("data = parse"+t.col.type+"(data)");else eval("try{eval(\"data = parse\" + t.col.type + \"(data)\");}catch(e){};");
	  			};
			t.data=data;
	  };
	  
	  var a=Array.prototype;
	  a.toCombo=function(name,value,onChange,multi,nullValue,hint)
	  	{
			var h='',i;
			if(nullValue)h+="\n<option value=''>"+nullValue+"</option>";if(!hint)hint=this;for(i=0;i<this.length;i++){h+="\n<option value='"+this[i]+"'"+((this[i].toString()==value.toString())?" selected":"")+">"+hint[i]+"</option>";
	  	};
	  return "<select name='"+name+"'"+((onChange)?" onChange=\""+onChange+"\"":"")+((multi)?" multiple":"")+">"+h+"</select>";
	  };
	  
	  a.toRadio=function(name,value,onClick,hint)
	  	{
			var h='',i;
			if(!hint)hint=this;
			for(i=0;i<this.length;i++)
				{
					h+="<input type='radio' name='"+name+"' value='"+this[i]+"' id='"+name+"_"+i+"'"+((onClick)?" onClick=\""+onClick+"\"":"")+((this[i].toString()==value.toString())?" checked":"")+">";h+=" "+hint[i];
	  			};
	  		return h;
	  };
	  
	  function toText(name,value,onEnter)
	  	{
			var h="<input type='text' name='"+name+"' value='"+value+"' "+((onEnter)?" onKeyPress=\"if (isEnter) "+onEnter+";\" onBlur=\""+onEnter+"\"":"")+">";
			return h;
	  };
	  
	  a.toCheckbox=function(name,value,onClick)
	  	{
			var h="<input type='checkbox' name='"+name+"' value='"+this[0]+"'"+((this[0]==value)?" checked":"")+((onClick)?" onClick=\"if (this.checked) this.value='"+this[0]+"';else this.value='"+this[1]+"';"+onClick+"\"":"")+">";
	  return h;
	  };
	  
	  a.toButton=function(name)
	  	{
			var h="<input type='button' name='"+name+"' value='"+this[0]+"' onClick=\""+this[1]+"\">";
	  		return h;
	  	};
		
	  a.isSame=function()
	  	{
			if(!this.length)
				return '';
			var i,res=this[0].toString();
			for(i=1;i<this.length;i++)
				{
					if(this[i].toString()!=res)
						{
							res='';break;
	  					};
	  			};
	  return res;
	  };
	  
	  
	  a.toStr=function()
	  	{
			var s='';
			if(!this.length)
				return '';
			if(this[0].constructor==Array)
				{
					for(var i=0;i<this.length;i++)
						s+=((i)?",\n":"")+this[i].toStr();
	  				return '['+s+']';
	  			}
			else
				{
				return '["'+this.join('","')+'"]';
	  			};
	  };
	  
	  
	  var CT_Table=null;
	  function CT_getParent(src)
	  	{
			while(Def(src)&&Def(src.tagName)&&src.tagName.toLowerCase()!="tr"&&src.tagName.toLowerCase()!="body")
				{
					src=((ua.ie)?src.parentElement:src.parentNode);
	  			};
	  return src;
	  };
	  
	  CodeThat.regEventHandler('mouseover',CT_setHover);
	  function CT_setHover(e)
	  	{
			if(ua.oldB)
				return true;
			var o=CT_getParent(e.target),id_table=null;
			if(o.id)
				{
					var id_table=o.id.substring(0,o.id.indexOf('_'));
					if(id_table)
						CT_Table=eval(id_table);
	  			}
			else
				{
					if(CT_Table&&CT_Table.rows&&CT_Table.rows[CT_Table.rowHover])
						{
							CT_Table.rows[CT_Table.rowHover].setCSS();
							CT_Table.rowHover=-1;
						};
	  			};
		};
		
	
			