<%
/*******************************************************************************
*	File name			:	ErCapacityCumulationReport.jsp
*	Purpose				:	Comparing Different combinations like component-layer-test-measure-info
							with other component-layer-test-measure combinations
*	Version				:	1.0
*	Author				:	Saravanan.M & Solomon.S
*	Creation Date		:	13/05/2003 - (dd/mm/yyyy)
*******************************************************************************/
%>

<%@ include file = "ErReporterTracker.jsp" %>
<%@ page import = "java.util.*"%>
<%@ page import = "java.sql.*"%>
<%@ page import = "com.eg.EgDbInfo"%>
<%@ page import = "com.eg.IniFile"%>
<%@ page import = "com.eg.EgDateInfo"%>
<%@ page import = "com.eg.EgURLEncoder"%>
<%@ page import = "com.egurkha.ini.IniUI" %>
<%@ page import = "com.eg.EgInstallInfo,com.eg.EgSpecsInfo" %>
<%@ page import = "com.eg.EgConfigInfo" %>
<%@ page import = "egurkha.EgCrawler" %>
<%@ page import = "com.eg.EgGroupInfo" %>
<%@ page import = "com.eg.EgViewInfo" %>
<%@ page import = "com.eg.EgTopoInfo" %>
<%@ page import = "com.eg.EgAggregateInfo" %>
<%@ page import= "com.eg.EgTesterInfo" %>
<%@ page import = "com.eg.EgServicesInfo" %>
<%@ page import = "com.eg.EgMappingInfo" %>
<%@ page import = "java.net.URLEncoder" %>
<%@ page import = "java.net.URLDecoder" %>
<%@ page import = "com.eg.MappingNameSorter"%>
<%@ page import = "com.eg.EgName"%>
<%@ page import = "com.egurkha.util.DateTimeTokenizer" %>
<%@ page import = "com.egurkha.util.DateUtil" %>
<%@ page import = "com.egurkha.util.StringUtils" %>
<%@ page import= "com.egurkha.util.ListUtils" %>
<%@ page import = "java.text.*" %>
<%@ page import = "net.sf.json.*" %>
<%@ taglib prefix="egui" uri="../WEB-INF/eg-taglib.tld" %>
<%@ page language="java" contentType="application/json; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="egui" uri="../WEB-INF/eg-taglib.tld" %>

<%
	JSONObject rootJson = new JSONObject();
	JSONObject selectedObj = new JSONObject();
	JSONObject hiddens = new JSONObject();
	JSONObject selectionDetails = new JSONObject();
	JSONObject screenLabels = new JSONObject();
	JSONObject backgroundResultObj = new JSONObject();
	JSONObject resultsObj = new JSONObject();

	EgDateInfo egDt = new EgDateInfo();
	IniFile iniObj;
	iniObj=new IniFile(EgInstallInfo.getInstallDir() + "/manager/config/eg_report.ini");
	String mgrIp = new IniFile(new EgConfigInfo("manager").getDbFile()).getValue("DB_PROPERTIES","ManagerUrl");
	Vector v_template=new Vector();
	EgViewInfo egviewinfo=new EgViewInfo("manager");
	IniUI ui = IniUI.getInstance();
	UserRegistry tregistry = UserRegistry.getInstance();
	User tuser = tregistry.getUser(session.getId());
	String thisLanguage = ui.getDefaultLanguage();
	EgTesterInfo testerInfo = new EgTesterInfo ("manager");
	if (tuser!=null)
	{
		String userLang = tuser.getLanguage();
		if (userLang!=null && !userLang.equalsIgnoreCase("NULL"))
		{
			thisLanguage=userLang;
		}
	}
	String decimal_point=request.getParameter("decimal_point");
		if(decimal_point==null)
			decimal_point="2";

try
{
	String mngrIProc = new IniFile(new EgConfigInfo("manager").getDbFile()).getValue("DB_PROPERTIES","ManagerUrl");
	EgMappingInfo intlmap=new EgMappingInfo(thisuser.getLanguage());
	String skinColor="";
	skinColor = tuser.getReporterSkin();
	ErComponentsUtils compUtils = new ErComponentsUtils(thisuser.getLoginID());
	EgMappingInfo mappingInfo = new EgMappingInfo(thisLanguage);
	String nameLang="";
	String typeLang="";
	String testLang="";
	String measureLang="";
	String descLang="";
	nameLang=mappingInfo.getTextDescription("reporter.CapacityPlan.Name");
	typeLang=mappingInfo.getTextDescription("reporter.CapacityPlan.Type");
	testLang=mappingInfo.getTextDescription("reporter.CapacityPlan.Test");
	measureLang=mappingInfo.getTextDescription("reporter.CapacityPlan.Measure");
	descLang=mappingInfo.getTextDescription("reporter.CapacityPlan.Descriptor");
	ArrayList serverList = new ArrayList();
	MappingNameSorter sorter = new MappingNameSorter(thisLanguage);
	String str = request.getRequestURI();
	java.util.Date dt = new java.util.Date();
	SimpleDateFormat dft= new SimpleDateFormat("MM/dd/yyyy");
	String time = dft.format(dt);
	EgServicesInfo si = new EgServicesInfo("manager");
	String trendQuery="";
	if(request.getParameter("er_trenddata")!=null && request.getParameter("er_trenddata") != " ")
	{
		trendQuery=request.getParameter("er_trenddata");
	}
	else
	{
		trendQuery="No";
	}
	ErReportHelper er_helper = new ErReportHelper();
	ErUtils erUtils =  new ErUtils();
	ErReqData erd = new ErReqData(request);
	EgDbInfo dbInfo=new EgDbInfo("manager");
	EgSpecsInfo specsInfo = new EgSpecsInfo("manager");
	String s_site = request.getParameter("er_site");
	String s_test = request.getParameter("er_test");
	String s_meas = request.getParameter("er_measure");
	String arr_comp[] = request.getParameterValues("er_component");
	String arr_component[] = request.getParameterValues("er_component");
	String arr_info[] = request.getParameterValues("er_info_list");
	if(arr_info!=null && arr_info.length>0)
	{
		for(int i=0;i<arr_info.length;i++)
		{
			String arr_infos = arr_info[i];
			if(arr_infos!=null && arr_infos.length()>0)
			{
				arr_infos = erUtils.specialCharDecode(arr_infos);
			}
			arr_info[i]=arr_infos;
		}
	}
	String s_combination = request.getParameter("er_combination");
	String arr_selection[] = request.getParameterValues("er_selection");
	String strselection=request.getParameter("er_flag");
	String s_comp=request.getParameter("er_component");
	String st_dataFrom=request.getParameter("er_dataFrom");
	String fav_view=request.getParameter("cmd");
	Vector v_service=null;
	String s_service="";
	s_service=request.getParameter("er_service");
	String s_template=request.getParameter("er_templateEnable");
	if (s_template==null)
		s_template=iniObj.getValue("REPORT_TEMPLATES","UseTemplates");
	String detailval= iniObj.getValue("MISC","DetailedTime");
	String s_farmserver = request.getParameter("er_service");
	String timefrom=request.getParameter("timefrom");
	String s_printQS="";
	String strQry_st_time = request.getParameter("startdate");
	String strQry_en_time = request.getParameter("enddate");
	ArrayList singleColors = (ArrayList)request.getAttribute("singleColors");
	ArrayList singleSelection = (ArrayList)request.getAttribute("singleSelection");
	EgReportInfo reportinfo = new EgReportInfo("manager");
	String selected="";// added by edward
	List dataOptionList = new ArrayList();
	ArrayList dontTrendTests = testerInfo.getDisabledTrendTests();
	String st_datafrom1=request.getParameter("er_dataFrom");
	String reqFromSchedule = request.getParameter("fromSchedule");
	String fromScheduleModify = request.getParameter("fromScheduleModify");
	String schedule_id = request.getParameter("schedule_id");
	String fromFavoriteModify = request.getParameter("fromFavoriteModify");
	String favorite_id = request.getParameter("id");
	String er_favorite = request.getParameter("er_favorite");
	String myCombination = "";
	String s_treeParam = request.getParameter("er_comptype");
	if(arr_selection != null)
	{
		s_combination ="";
		for(int i=0; i<arr_selection.length; i++)
		{
			arr_selection[i] = erUtils.specialCharDecode(arr_selection[i]);
			s_combination += arr_selection[i]+"0eghash0eghash0";
		}
		myCombination = s_combination;
	}
	
	dataOptionList.add("Measure");
	
	if(s_test != null && !dontTrendTests.contains(s_test)) 
	{	
		dataOptionList.add("Avg Trend");
		dataOptionList.add("Max Trend");
	}
	String er_dataoption = request.getParameter("er_dataoption");
	if(er_dataoption == null) {
		er_dataoption = (String) dataOptionList.get(0);
	}
	String selTempl="";
	selTempl=request.getParameter("er_template");
	if(request.getParameter("er_combination")!=null && request.getParameter("er_combination").trim().length()>0)
	{
		if(s_combination!=null && s_combination.indexOf("$$")>-1)
		{
			s_combination=StringUtils.replace(s_combination,"$$","0eghash0eghash0");
		}
	}
	boolean templateEnable=false;
	ErInfo erInfo = new ErInfo();
	Vector v_comp_popup = new Vector();
	Vector v_comp_popup_disp = new Vector();
	Vector v_test=new Vector();
	if (s_site!=null && !s_site.equals("-1"))
	{
		v_test=er_helper.getMetaTestsForSite(s_site);
		v_template=er_helper.getMetaTemplateForSite(s_site);
	}else
	{
		v_test=er_helper.getAllMetaTests();
		v_template=er_helper.getMetaTemplateForSite(null);
		//v_template=er_helper.getMetaTemplate();
	}
	User usr = UserRegistry.getInstance().getUser(session.getId());
	Vector userTests = (Vector)v_test;
	Map usrTest = usr.getTests();
	v_test = new Vector();
	HashSet hv_test = new HashSet();
	if(userTests!=null && !userTests.isEmpty())
	{
		for(int u =0; u < userTests.size(); u++)
		{
			if(usrTest!=null)
			{
				if(usrTest.containsKey((String)userTests.get(u)))
				{
					String strUserTest=(String)userTests.get(u);
					if (!com.eg.EgInstallInfo.isConfigTest(strUserTest))
					{
						if(s_treeParam!=null && s_treeParam.length() > 0)
						{
							boolean flag = Server.isTestRelevantForServer(s_treeParam,strUserTest);
							if(flag)
							{
								hv_test.add(strUserTest);
							}
						}
						else
						{
							v_test.add(strUserTest);
						}
					}
				}
			}
		}
	}
	
	if(hv_test!=null && !hv_test.isEmpty())
	{
		v_test.addAll(hv_test);
	} 
	Vector v_meas=erInfo.getMeasuresForTest(1,s_test);
	Vector mappingMeasure=new Vector();
	// added for measure list in an order
	ArrayList aListMeasure = new ArrayList();
	ArrayList aListMappingMeas = null;
	if(v_meas!=null && v_meas.size()>0)
	{
		aListMeasure.addAll(v_meas);
		aListMappingMeas = sorter.getSortedMeasureList(s_test,aListMeasure);
		for(int  v=0;v<v_meas.size();v++)
		{
			String measure=(String)v_meas.get(v);
			String mappStr=intlmap.getMeasureDescription(s_test,measure);
			mappingMeasure.add(mappStr);
		}
	}
	String sumType=request.getParameter("er_summaryType");
	if (sumType == null ||	sumType.equals(""))
		sumType="DS";
	if(st_dataFrom == null || st_dataFrom.equals(""))
	{
		st_dataFrom="Component";
	}

	Vector v_comp = new Vector();
	Vector v_availComps = compUtils.getAllUserComponents1();
	v_comp = compUtils.getAllUserComponents1();
	
	Vector userTemplates=(Vector)v_template;
	v_template=new Vector();
	if(userTemplates!=null && !userTemplates.isEmpty())
	{
		for(int i=0;i<userTemplates.size();i++)
		{
			String templateName=(String)userTemplates.get(i);
			String tempVal=iniObj.getValue("REPORT_TEMPLATES",templateName);
			if (tempVal!=null && tempVal.indexOf(":")<0)
				continue;
			StringTokenizer st_testName=new StringTokenizer(tempVal,":");
			String iniTestName=st_testName.nextToken();
			if(v_test!=null)
			{
				for(int kk=0; kk<v_test.size(); kk++)
				{
					if(iniTestName.equalsIgnoreCase(v_test.get(kk).toString().trim()))
						v_template.add(templateName);
				}
			}
		}
	}
	Vector v_infos=new Vector();
	ErInfo erinfo=new ErInfo();
	Collections.sort(v_comp);
	Collections.sort(v_availComps);
	if(s_test != null && !s_test.equalsIgnoreCase("-1"))
	{
		for(int i=v_comp.size()-1;i>=0;i--)
		{
			String s_com = v_comp.get(i).toString();
			if(st_dataFrom!=null && st_dataFrom.equalsIgnoreCase("Component"))
			{
				if(!specsInfo.isTestRelevantForServer(s_com.substring(s_com.lastIndexOf(":")+1),s_test))
					v_comp.removeElementAt(i);
			}
			else
			{
				if(!specsInfo.isTestRelevantForServer(s_com.substring(0,s_com.indexOf(":")),s_test))
					v_comp.removeElementAt(i);
			}
		}
		arr_comp = erd.getComponents();
	}//else v_comp.removeAllElements();
	if(v_comp != null)
		Collections.sort(v_comp);
	Vector v_componetdisp=new Vector();
	for(int i=0;i<v_comp.size();i++)
	{
		String dispcomp=(String)v_comp.get(i);
		if(dispcomp.indexOf(":NULL")>-1)
		{
			v_componetdisp.add(dispcomp.substring(0,dispcomp.indexOf(":NULL"))+":"+dispcomp.substring(dispcomp.indexOf("NULL:")+5));
		}
		else
		{
			v_componetdisp.add(dispcomp);
		}
	}

	arr_comp = new String[v_comp.size()];
	//if(s_comp!=null && !s_comp.equals(""))
	if(arr_component != null){
		for(int i=0; i<arr_component.length; i++)
		{
			if(s_site == null || s_site.equals("-1") || s_site.equals("null"))
				s_site=null;
			Vector tempInfo = erInfo.getInfosForTest(s_site,s_test,arr_component[i]);
			for(int j=0; j<tempInfo.size(); j++)
			{
				String tempStr = (String) tempInfo.get(j);
				v_infos.add(tempStr);
			}
		}
		v_infos = ErUtils.formatString(v_infos,"$0+$1","$1");
		v_infos = ListUtils.removeDuplicates(v_infos,true);
	}


	Vector v_qry_string = (Vector) request.getAttribute("chartData");
	Vector v_pdf_qry = (Vector)request.getAttribute("pdfData");
	int chartCount = -1;
	if (v_qry_string != null && !v_qry_string.contains("No Component Found"))
		chartCount =v_qry_string.size() / 2;

	Vector v_newPdf_qry=new Vector();
	if(v_pdf_qry!=null && chartCount>0)
	{
		for(int v=0;v<v_pdf_qry.size();v=v+2)
		{
			v_newPdf_qry.add((String)v_pdf_qry.get(v));
			if(v_pdf_qry.size()>0)
			{
				String  s_qry=(String)v_pdf_qry.get(v+1);
				String SQstring="";
				if(s_qry!=null)
				{
					StringTokenizer strtok = new StringTokenizer(s_qry,"&");
					String surl=s_qry.substring(0,s_qry.indexOf("&"));
					surl = mgrIp + surl;
					while(strtok.hasMoreTokens())
					{
						String  param = strtok.nextToken();
						if(param.indexOf("=")>-1)
						{
							String reqparam =param.substring(0,param.indexOf("="));
							String value =""; value=param.substring(param.indexOf("=")+1,param.length());
							if(reqparam.equals("er_component") ||  reqparam.equals("er_info_list") || reqparam.equals("er_selection") ||reqparam.equals("er_site") )
							{
								value=URLDecoder.decode(value);
								if(value.indexOf("+")>-1){
									value=StringUtils.replace(value,"+","|plus|");
								}else if(value.indexOf("&")>-1){
									value=StringUtils.replace(value,"&","|amp|");
								}else if(value.indexOf("%")>-1){
									value=StringUtils.replace(value,"%","|pct|");
								}
								if(value!=null && value.equals("-1"))
									value="";
								if(value!=null  && !value.equals(""))
									value=EgURLEncoder.encode(value,"UTF-8");
							}
							SQstring=SQstring+reqparam+"="+value+"&";
						}
					}
					if(SQstring.endsWith("&"))
						SQstring=SQstring.substring(0,SQstring.lastIndexOf("&"));
					v_newPdf_qry.add(surl+SQstring);
				}
			}
		}
	}

	Vector v_sites = new Vector(compUtils.getUserSites());
	boolean showSite = v_sites.size()>0;
	int compareLimit = er_helper.getCompareLimit();
	String includezone=request.getParameter("er_dataZone");
	String opt=request.getParameter("er_trenddata");
	if(opt==null)
		opt="No";
	String  s_st_time = request.getParameter("startdate");
	String 	s_en_time = request.getParameter("enddate");
	String 	s_st_hr = request.getParameter("starthr");
	String s_en_hr = request.getParameter("endhr");
	String strsmin=request.getParameter("startmin");
	String etrsmin=request.getParameter("endmin");
	String  er_timeline=request.getParameter("er_timeline");


	if(er_timeline==null  || er_timeline.equals(" "))
	{
			er_timeline="1 week";
	}
	//Date calculation according to time select
	String[] options = new String[]{"Any","1 day", "2 days", "3 days", "4 days", "5 days", "6 days","1 week","2 weeks","3 weeks","4 weeks","1 month"};
	
	long msecsPerHour = (long) 1000 * 60 * 60;
	String startDateTime="";
	String endDateTime="";
	String uiFile = "eg_ui.ini";
	String s_iniFile_dir = EgInstallInfo.getInstallDir()+ "/manager/config/";
	IniFile egUI = new IniFile(s_iniFile_dir + uiFile);
	String currentDateFormat =strUserDateFormat;
	String dispDate = null;
	String comFormat = null;
	if(er_timeline!=null&&!er_timeline.equals("Any"))
	{
		int blankSpaceIndex = er_timeline.indexOf(DateTimeTokenizer.BLANK_SPACE);
		if (blankSpaceIndex > 0)
		{
			SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm");
			java.util.Date today = egDt.egetRealDate();
			if(opt!=null && opt.equals("No"))
			{
				endDateTime = sdf.format(today);
			}
			else
			{
				endDateTime = sdf.format(today);
			}
			long value = Integer.parseInt(er_timeline.substring(0, blankSpaceIndex));
			String unit = er_timeline.substring(blankSpaceIndex+1).toLowerCase();
			if (unit.startsWith("h"))
			{//hours
				value *= 3600;
			}
			else if (unit.startsWith("d"))
			{//days
				value *= (24 * 3600);
			}
			else if (unit.startsWith("w"))
			{
				if(unit.endsWith("last")){
					//last week
					int weekCount = (int) value;
					SimpleDateFormat simpledf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
					java.util.Date currDateTime = egDt.egetRealDate();
					String currentDateTime = simpledf.format(currDateTime);
					String currentDate = currentDateTime.substring(0, currentDateTime.indexOf(DateTimeTokenizer.BLANK_SPACE));
					String currentHr = currentDateTime.substring(currentDateTime.indexOf(DateTimeTokenizer.BLANK_SPACE)+1, currentDateTime.indexOf(":"));
					String currentMin = currentDateTime.substring(currentDateTime.indexOf(":")+1, currentDateTime.lastIndexOf(":"));
					String userFormat = thisuser.getUserDateFormat();
					String curFormatDate = DateUtil.changeDateFormat(currentDate,"MM/dd/yyyy", userFormat); 
					EgTimeZoneConverter realDateTime = new EgTimeZoneConverter(curFormatDate+" "+currentHr+":"+currentMin,thisuser);
					java.util.Date realDate=new SimpleDateFormat(userFormat).parse((String) realDateTime.getDate(false));
					Calendar c = Calendar.getInstance();
					c.setTime(realDate);
					int i = c.get(Calendar.DAY_OF_WEEK) - c.getFirstDayOfWeek() * weekCount;
					int startDayCount = 7 * weekCount + (1 * (weekCount - 1));
					int lastDayCount = 6 * weekCount + (1 * (weekCount - 1));
					c.add(Calendar.DATE, - i - startDayCount);
					c.set(Calendar.HOUR, 00);
					c.set(Calendar.MINUTE, 00);
					java.util.Date start = c.getTime();
					startDateTime = new SimpleDateFormat(userFormat).format(start);
					c.add(Calendar.DATE, lastDayCount);	
					c.set(Calendar.HOUR, 23);
					c.set(Calendar.MINUTE, 00);
					java.util.Date end = c.getTime();
					endDateTime = new SimpleDateFormat(userFormat).format(end);
					System.out.println("ErCapacityCumulationReportJSON Last Week Start Date-->"+startDateTime+ "    End Time-->"+endDateTime);
				}else{
					//weeks
					value *= (7 * 24 * 3600);
				}
			}
			else if (unit.startsWith("mo"))
			{
				if(unit.endsWith("last"))
				{//last month
					int monthCount = (int) value;
					SimpleDateFormat simpledf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
					java.util.Date currDateTime = egDt.egetRealDate();
					String currentDateTime = simpledf.format(currDateTime);
					String currentDate = currentDateTime.substring(0, currentDateTime.indexOf(DateTimeTokenizer.BLANK_SPACE));
					String currentHr = currentDateTime.substring(currentDateTime.indexOf(DateTimeTokenizer.BLANK_SPACE)+1, currentDateTime.indexOf(":"));
					String currentMin = currentDateTime.substring(currentDateTime.indexOf(":")+1, currentDateTime.lastIndexOf(":"));
					String userFormat = thisuser.getUserDateFormat();
					String curFormatDate = DateUtil.changeDateFormat(currentDate,"MM/dd/yyyy", userFormat); 
					EgTimeZoneConverter realDateTime = new EgTimeZoneConverter(curFormatDate+" "+currentHr+":"+currentMin,thisuser);
					java.util.Date realDate=new SimpleDateFormat(userFormat).parse((String) realDateTime.getDate(false));
					Calendar c = Calendar.getInstance();
					c.setTime(realDate);
					c.add(Calendar.MONTH, -monthCount);
					c.set(Calendar.DATE, 1);
					c.set(Calendar.HOUR, 00);
					c.set(Calendar.MINUTE, 00);
					java.util.Date start = c.getTime();
					startDateTime = new SimpleDateFormat(userFormat).format(start);
					Calendar c1 = Calendar.getInstance();
					c1.setTime(realDate);
					c1.add(Calendar.MONTH, -1);
					c1.set(Calendar.DAY_OF_MONTH, c1.getActualMaximum(Calendar.DAY_OF_MONTH));
					c1.set(Calendar.HOUR, 23);
					c1.set(Calendar.MINUTE, 59);
					java.util.Date end = c1.getTime();
					endDateTime = new SimpleDateFormat(userFormat).format(end);
					System.out.println("ErCapacityCumulationReportJSON Last Month Start Date-->"+startDateTime+ "    End Time-->"+endDateTime);
				}else{
					//months
					if(opt!=null && opt.equals("No"))
					{
						java.util.Date dt_temp = new java.util.Date(egDt.egetUTCDate());
						Calendar cal_temp = new GregorianCalendar();
						cal_temp.setTime(dt_temp);
						//cal_temp.add(Calendar.DATE,-1);
						cal_temp.add(Calendar.HOUR_OF_DAY,0);
						java.util.Date dt_temp1 = cal_temp.getTime();
						long l_temp = dt_temp1.getTime();
						int  totalDays=24*(ErUtils.getMaxDaysInMonth());
						startDateTime = egDt.egetDate(l_temp -(long)( (value*totalDays * msecsPerHour)));
						startDateTime = DateUtil.changeDateFormat(startDateTime,
						"dd/MM/yyyy HH:mm","MM/dd/yyyy HH:mm");
					}
					else
					{
						java.util.Date dt_temp = new java.util.Date(endDateTime);
						Calendar cal_temp = new GregorianCalendar();
						cal_temp.setTime(dt_temp);
						cal_temp.add(Calendar.HOUR_OF_DAY,0);
						java.util.Date dt_temp1 = cal_temp.getTime();
						long l_temp = dt_temp1.getTime();
						int  totalDays=24*(ErUtils.getMaxDaysInMonth());
						startDateTime = egDt.egetDate(l_temp -(long)( (value*totalDays * msecsPerHour)));
						startDateTime = DateUtil.changeDateFormat(startDateTime,
						"dd/MM/yyyy HH:mm","MM/dd/yyyy HH:mm");
					}
				}
			}
			if (unit!=null&&!unit.startsWith("mo")&& !unit.endsWith("last"))
			{
				java.util.Date start = new java.util.Date();
				java.util.Date startTmp=new java.util.Date(endDateTime);
				start.setTime(startTmp.getTime() - (value * 1000));
				startDateTime = sdf.format(start);
			}else if (unit.endsWith("last")){
				String usrStartDateTime = startDateTime +" 00:00";
				String usrEndDateTime = endDateTime +" 23:59";
				System.out.println("ErCapacityCumulationReportJSON User Start Date-->"+usrStartDateTime+ "    End Time-->"+usrEndDateTime);
				EgTimeZoneConverter timeZoneConverterStart = new EgTimeZoneConverter(usrStartDateTime, thisuser, true);
				startDateTime = DateUtil.changeDateFormat((String) timeZoneConverterStart.getDate(false), thisuser.getUserDateFormat(), "MM/dd/yyyy");
				startDateTime = startDateTime+" "+(String) timeZoneConverterStart.getHour()+":"+(String) timeZoneConverterStart.getMinute();
				EgTimeZoneConverter timeZoneConverterEnd = new EgTimeZoneConverter(usrEndDateTime, thisuser, true);
				endDateTime = DateUtil.changeDateFormat((String) timeZoneConverterEnd.getDate(false), thisuser.getUserDateFormat(), "MM/dd/yyyy");
				endDateTime = endDateTime +" "+(String) timeZoneConverterEnd.getHour()+":"+(String) timeZoneConverterEnd.getMinute();
				System.out.println("ErCapacityCumulationReportJSON Manager Start Date-->"+startDateTime+ "    End Time-->"+endDateTime);
			}
		}
		if ((startDateTime != null) && (endDateTime != null))
		{
			int shr = Integer.parseInt(startDateTime.substring(startDateTime.indexOf(DateTimeTokenizer.BLANK_SPACE)+1, startDateTime.indexOf(":")));
			int en_hr = Integer.parseInt(endDateTime.substring(endDateTime.indexOf(DateTimeTokenizer.BLANK_SPACE)+1, endDateTime.indexOf(":")));
			strsmin=startDateTime.substring(startDateTime.indexOf(DateTimeTokenizer.BLANK_SPACE)+1);
			strsmin=strsmin.substring(strsmin.indexOf(":")+1);
			endDateTime=endDateTime.trim();
			etrsmin=endDateTime.substring(endDateTime.indexOf(DateTimeTokenizer.BLANK_SPACE)+1);
			etrsmin=etrsmin.substring(etrsmin.indexOf(":")+1);
			s_en_time=endDateTime.substring(0, endDateTime.indexOf(DateTimeTokenizer.BLANK_SPACE));
			s_st_time=startDateTime.substring(0, startDateTime.indexOf(DateTimeTokenizer.BLANK_SPACE));

			//if(er_timeline.trim().indexOf("hour")> -1){}else{strsmin="00";etrsmin="00";}
			if(opt!=null && opt.equals("No"))
			{
				s_st_hr = String.valueOf(shr);
				s_en_hr = String.valueOf(en_hr);
			}
		}
	}
	String disable="";
	if(er_timeline!=null&&!er_timeline.equals("Any"))
	{
		disable ="disabled";
	}
	if(er_timeline!=null&&er_timeline.equals("Any"))
	{
		String StrDate="";
		try
		{
			java.text.SimpleDateFormat df=new java.text.SimpleDateFormat("MM/dd/yyyy k 'at' hh:mm");
			StrDate =df.format(new java.util.Date());
		}
		catch(Exception ee)
		{
			System.out.println("Exception is"+ee);
		}
		String SDate =StrDate.substring(0,StrDate.indexOf(" "));
		String shour =StrDate.substring(StrDate.indexOf(" "),StrDate.lastIndexOf(""));
		shour = shour.substring(0,3);
		if(s_st_time==null)
		{
			s_st_time=SDate;
		}
		if(s_en_time==null)
		{
			s_en_time=SDate;
		}
		if(s_st_hr==null)
		{
			shour =shour.trim();
			int starthr = Integer.parseInt(shour);
			starthr = starthr-1;
			s_st_hr=String.valueOf(starthr);
		}
		if(s_en_hr==null)
		{
			shour =shour.trim();
			s_en_hr =shour;
		}
	}

	StringBuffer printQS= new StringBuffer();
	printQS.append("er_gtype=CapacityPlanning");
	String tbound =request.getParameter("er_timeline");
	printQS.append("&er_tbound=" + tbound);
	printQS.append("&er_timeline=" + request.getParameter("er_timeline"));
	printQS.append("&startdate=" + request.getParameter("startdate"));
	printQS.append("&enddate=" + request.getParameter("enddate"));
	printQS.append("&starthr=" +request.getParameter("starthr"));
	printQS.append("&endhr=" + request.getParameter("endhr"));
	printQS.append("&startmin="+request.getParameter("startmin"));
	printQS.append("&endmin="+request.getParameter("endmin"));
	printQS.append("&er_mode=" + request.getParameter("er_mode"));
	printQS.append("&er_summaryType=" + request.getParameter("er_summaryType"));
	printQS.append("&userID="+urs);
	if(st_dataFrom!=null)
		printQS.append("&er_dataFrom="+st_dataFrom);
	if(s_service!=null)
	{
		String sess_service=EgURLEncoder.encode(s_service,"UTF-8");
		printQS.append("&er_service="+s_service);
		printQS.append("&er_test="+s_test);
		printQS.append("&er_measure="+s_meas);
		printQS.append("&sess_service="+sess_service);
	}
	String pqs=printQS.toString();
	String ergraphtype=request.getParameter("er_graphtype");
	printQS.append("&er_graphtype="+request.getParameter("er_graphtype"));
	printQS.append("&er_trenddata="+request.getParameter("er_trenddata"));
	printQS.append("&er_trgttype="+request.getParameter("er_trgttype"));
	printQS.append("&er_dataoption="+request.getParameter("er_dataoption"));
	printQS.append("&decimal_point="+decimal_point);

	if(arr_selection!=null)
	{
		for(int k =0;k<arr_selection.length;k++)
			printQS.append("&er_selection=" + com.eg.EgURLEncoder.encode(arr_selection[k],"UTF-8"));
	}
	//priya
	printQS.append("&option=Graph&printGraph=yes&er_width=670&er_height=400&enlarged=true");
	HashMap tmpmap1=ErUtils.parseQueryString(printQS.toString() );
	tmpmap1.put("fromPrint", "true");
	session.setAttribute("CapacityPlanprintgraphparams",tmpmap1);
	String s_modify=request.getParameter("modify");
	if(s_site!=null && !s_site.equals("") && !s_site.equals("-1") )
		st_datafrom1="Service";
	boolean isModify = true;
	if(s_modify!=null && s_modify.equalsIgnoreCase("false"))
		isModify=false;

		String site1="";
		String comp1="";
		String test1="";
		String measure1 = "";
		String desc1 = "-";
		String toScript ="";
		String toScriptText="";
		String compTypem = "";
		String layerm = "";
		String testm = "";
		String measurem = "";
		String descm = "";
	// added for backgrond report generation
	String er_trenddata="";
	String confrimation = reportinfo.getValue("BACKGROUND_PROCESS","NeedConfirmation");
	String strbgrepportName = reportinfo.getValue("BACKGROUND_PROCESS","EnableBackgroundReport");
	String limitforbg = reportinfo.getValue("BACKGROUND_PROCESS","MinDurationForReport");
	String bggroundStr = (String)request.getAttribute("bggroundStr");
	String status = (String)request.getAttribute("status");
	boolean isBackgroundProcess = false;
	//background report  generation ends here

	//Back Button - Start
	HashMap backreqMap = (HashMap)session.getAttribute("backQuery");
	String backQnumber = request.getParameter("backQnumber");
	String servlet2 = request.getParameter("backServletName");
	
	ErHelperUtils erhelputils = null;

	if( servlet2!=null && !servlet2.equals(""))
		erhelputils = new ErHelperUtils(backreqMap,backQnumber,servlet2);
	else
		erhelputils = new ErHelperUtils(backreqMap,backQnumber);

	boolean enableBack=erhelputils.isBackButtonEnable();

	String backButtonEnable = request.getParameter("back");
	if(backButtonEnable != null && backButtonEnable.equalsIgnoreCase("True"))
	{
		status = (String)request.getParameter("status");
		request.setAttribute("chartData",null);
		request.setAttribute("pdfData",null);
		bggroundStr = (String)request.getParameter("bggroundStr");
	}
	//Back Button - End

	if((s_combination!=null)&&(s_combination.trim().length()>0) && !s_combination.equalsIgnoreCase("-10eghash0eghash0"))
	{
		String c_items[] = null;
		String[] tempToken1 = StringUtils.getTokens(s_combination,"||");
		if(st_datafrom1.equalsIgnoreCase("Service") && tempToken1.length == 1 && s_combination.indexOf("| |")==-1)
		{
			c_items = new String[1];
			c_items[0] = s_combination;
		}
		else
		{
			c_items=StringUtils.getTokens(s_combination,"0eghash0eghash0") ;
			int p=c_items.length;

		}

		if(c_items!=null && c_items.length > 0)
		{
			for(int i =0; i < c_items.length; i++)
			{
				String oneDetail = c_items[i];

				if(oneDetail.indexOf("|plus|")>-1)
				{
					oneDetail=StringUtils.replace(oneDetail,"|plus|","+");
				}else if(oneDetail.indexOf("|amp|")>-1)
				{
					oneDetail=StringUtils.replace(oneDetail,"|amp|","&");
				}else if (oneDetail.indexOf("|pct|")>-1)
				{
					oneDetail=StringUtils.replace(oneDetail,"|pct|","%");
				}

				String[] tempToken = StringUtils.getTokens(oneDetail,"0eghash0eghash0");
				StringTokenizer st_dd = new StringTokenizer(oneDetail,"|");
				//Upgrade from 3.4.2 to 4.2.0
				String[] st_tempToken = StringUtils.getTokens(oneDetail,"||");
				if(st_tempToken.length==2)
				{
					if(st_dd.hasMoreTokens())
					{
						s_service = st_dd.nextToken();
						if(s_service!=null)
						{
							v_comp = compUtils.getTypeModifyComponents(compUtils.getServiceComponents(s_service),2);
							v_componetdisp = new Vector();
							if(v_comp!=null && v_comp.size()>0)
							{
								for(int compCount=0;compCount<v_comp.size();compCount++)
								{
									String s_tmp=(String)v_comp.elementAt(compCount);
									String str_comptype=s_tmp.substring(0,s_tmp.indexOf(":"));
									String str_compname=s_tmp.substring(s_tmp.indexOf(":")+1);
									String s_component = str_compname +":"+str_comptype;
									v_comp.setElementAt(s_component,compCount);
								}
								for(int compCount=0;compCount<v_comp.size();compCount++)
								{
									String dispcomp=(String)v_comp.get(compCount);
									if(dispcomp.indexOf(":NULL")>-1)
									{
										v_componetdisp.add(dispcomp.substring(0,dispcomp.indexOf(":NULL"))+":"+dispcomp.substring(dispcomp.indexOf("NULL:")+5));
									}
									else
									{
										v_componetdisp.add(dispcomp);
									}
								}
							}
						}
					}
				}
					site1="";
					desc1="-";
					measure1="";

				if(st_dd.hasMoreTokens())
				{

					comp1 = st_dd.nextToken();

					if(st_dd.hasMoreTokens())
					{
						String s=st_dd.nextToken();
					}
					if(st_dd.hasMoreTokens())
					{
						test1 = st_dd.nextToken();

					}
					if(st_dd.hasMoreTokens())
					{
						measure1 = st_dd.nextToken();

					}
					if(st_dd.hasMoreTokens())
					{
						desc1 = st_dd.nextToken();

					}

					String compName;
					String compType;
					if(comp1.equalsIgnoreCase("All"))
					{
						compName = comp1;
						compType = comp1;
					}
					else
					{
						compName = comp1.substring(0,comp1.lastIndexOf(":"));
						compType = comp1.substring(comp1.lastIndexOf(":")+1);
					}
					String formed = compType + ":" + compName;
						compTypem=mappingInfo.getComponentTypeDescription(compType);
						testm=mappingInfo.getTestDescription(test1.trim());
					String s_templateEnable=request.getParameter("er_templateEnable");
					if(s_templateEnable!=null && s_templateEnable.equalsIgnoreCase("Yes"))
					{
						for(int $i=0;$i<userTemplates.size();$i++)
						{
							String templateName=(String)userTemplates.get($i);
							String tempVal=iniObj.getValue("REPORT_TEMPLATES",templateName);
							if(tempVal.equals(test1+":"+measure1))
								measurem=templateName;
						}
					}
					else
						measurem=mappingInfo.getMeasureDescription(test1,measure1);
						if(s_template.equals("yes"))
						{
							test1="_";
							testm="_";
						}
						toScript += compName+','+compType+','+test1+','+measure1+','+desc1+"0eghash0";
						toScriptText += compName+','+compTypem+','+testm+','+measurem+','+desc1+"0eghash0";
				}
			}
			if(toScript.endsWith("0eghash0"))
			toScript = toScript.substring(0,toScript.lastIndexOf("0eghash0"));
			if(toScriptText.endsWith("0eghash0"))
			toScriptText = toScriptText.substring(0,toScriptText.lastIndexOf("0eghash0"));
			/*toScript=com.egurkha.util.StringUtils.replace(((toScript==null)?"":toScript), "\\", "\\\\");
			toScriptText=com.egurkha.util.StringUtils.replace(((toScriptText==null)?"":toScriptText), "\\", "\\\\");*/
			toScript=((toScript==null)?"":toScript);
			toScriptText=((toScriptText==null)?"":toScriptText);
			
		}
	}
	String selectCount=request.getParameter("selectCount");
	String strPrintParam = (String)ErUtils.prepareQueryString(request.getParameterMap());
	Vector v_summarytype=new Vector();
	v_summarytype.add("Hourly Summary");
	v_summarytype.add("Daily Summary");
	v_summarytype.add("Monthly Summary");
	
	session.setAttribute("Report_Query_String",strPrintParam);
	hiddens.put("loadCombination",erUtils.specialCharEncode(myCombination));
	hiddens.put("currTime", time);
	hiddens.put("modify", s_modify);
	hiddens.put("er_rtype", "Capacity Planning");
	hiddens.put("er_gtype", "CapacityPlanning");
	hiddens.put("er_trgttype", "Cumulation");
	hiddens.put("detailtime", detailval);
	hiddens.put("er_dataFrom", st_dataFrom);
	hiddens.put("includesubzone", request.getParameter("includesubzone"));
	hiddens.put("er_flag", "true");
	hiddens.put("er_ViewName", "ErCapacityCumulationReport.jsp");
	hiddens.put("getMaxDaysInMonth", String.valueOf(ErUtils.getMaxDaysInMonth()));
	hiddens.put("inidate", currentDateFormat);
	hiddens.put("reporttype", "Capacity");
	//hiddens.put("startdate", request.getParameter("startdate"));
	//hiddens.put("enddate", request.getParameter("enddate"));
	//hiddens.put("starthr", s_st_hr);
	//hiddens.put("endhr", s_en_hr);
	hiddens.put("us_id", urs);
	hiddens.put("userID", urs);
//	hiddens.put("startmin", strsmin);
//	hiddens.put("endmin", etrsmin);
	hiddens.put("template", String.valueOf(templateEnable));
	hiddens.put("map_test", "");
	hiddens.put("map_measure", "");
	hiddens.put("er_type", "Yes");
	//hiddens.put("singleselection", singleSelection);
	hiddens.put("singlecolors", singleColors);
	hiddens.put("forwardto", "ErCapacityCumulationReport");
	hiddens.put("er_bgreportfrom", "CapacityPlanning_Cumulation");
	hiddens.put("bgenabled", strbgrepportName);
	hiddens.put("limitforbg", limitforbg);
	hiddens.put("savereport", "save");
	hiddens.put("fromSchedule", reqFromSchedule);
	if(fromScheduleModify!=null)
		hiddens.put("fromScheduleModify",fromScheduleModify);
	else
		hiddens.put("fromScheduleModify","null");
	if(fromFavoriteModify!=null)
		hiddens.put("fromFavoriteModify",fromFavoriteModify);
	else
		hiddens.put("fromFavoriteModify","null");
	hiddens.put("favorite_id", favorite_id);
	hiddens.put("er_favorite", er_favorite);
	hiddens.put("schedule_id", schedule_id);
	//prakash commented this because whenever reload happens id gets appended in hiddens and when loading grid it duplicates gets appended. that s why commented it. If needed and have to uncomment this, check favorite, schedule and reload.
	//hiddens.put("ID", "backQnumber="+erhelputils.getBackID()+"&"+erhelputils.getQueryString());
	hiddens.put("er_optionselect", "Component");
	hiddens.put("er_templateEnable", "false");
	hiddens.put("measureWithUnit", "");
	
	screenLabels.put("TITLE", intlmap.getTextDescription("reporter.CapacityPlan.CAPACITY CUMULATION REPORT"));
	String fromFavSch = request.getParameter("fromFavSch");
	//for enable back
	if(request.getParameter("enableBack")!=null && request.getParameter("enableBack").equalsIgnoreCase("true"))
	{
		enableBack = true;
	}
	if(backreqMap != null && backreqMap.size() > 0 &&  enableBack && request.getParameter("enableBack")!=null && request.getParameter("enableBack").equalsIgnoreCase("true") && (fromFavSch!=null && fromFavSch.equalsIgnoreCase("true")))
	{
		hiddens.put("ID", "backQnumber="+erhelputils.getBackID()+"&"+erhelputils.getQueryString());
	}
	s_printQS="option=Graph&printGraph=yes&er_gtype=CapacityPlanning";
	s_printQS = "&er_tbound="+request.getParameter("er_tbound")+"&er_graphtype=Single"+"&er_timeline="+request.getParameter("er_timeline")+"&er_gtype="+request.getParameter("er_gtype")+"&currTime="+request.getParameter("currTime")+"&startdate="+strQry_st_time+"&starthr="+s_st_hr+"&enddate="+strQry_en_time+"&endhr="+s_en_hr+"&startmin="+strsmin+"&endmin="+etrsmin+"&userID="+urs+"&er_dataoption="+request.getParameter("er_dataoption");
	s_printQS=s_printQS.substring(1,s_printQS.length());

	rootJson.put("PRINT_URL", "../servlet/com.eg.ErRepoLiteC?"+s_printQS+"&er_trenddata="+trendQuery+"&option=Graph&printGraph=yes&er_type=CapacityPlan&pdfPrint=yes");

	rootJson.put("PDF_URL", "../reporter/ErHtmlToSavePdf.jsp?"+s_printQS+"&option=Graph&printGraph=yes&er_type=CapacityPlan");

	if (chartCount == 1 && ((arr_selection!=null) || (st_dataFrom!=null && st_dataFrom.equalsIgnoreCase("Service"))))
	{
		//priya
		String dataQS="";
		String q_str = (String)v_qry_string.get(1);
		if (q_str.indexOf("er_selection")>-1)
			q_str = q_str.substring(0,q_str.indexOf("er_selection")-1);
		StringTokenizer strtok = new StringTokenizer(q_str,"&");
		while(strtok.hasMoreTokens())
		{
			String param = strtok.nextToken();
			if(param!=null && param.indexOf("=")>-1)
			{
				String reqparam =param.substring(0,param.indexOf("="));
				String value = param.substring(param.indexOf("=")+1,param.length());
				String val1=value;
				if(value==null)
					value="";
				if(reqparam.equals("er_component") ||  reqparam.equals("er_info_list"))
				{
					if(value.indexOf("+")>-1){
						value=StringUtils.replace(value,"+","|plus|");
					}else if(value.indexOf("&")>-1){
						value=StringUtils.replace(value,"&","|amp|");
					}else if(value.indexOf("%")>-1){
						value=StringUtils.replace(value,"%","|pct|");
					}
					if(value!=null && value.equals("-1"))
							value="";
					if(value!=null  && !value.equals(""))
							value=EgURLEncoder.encode(URLDecoder.decode(value),"UTF-8");
				}
				dataQS=dataQS+reqparam+"="+value+"&";
			}
			if(param!=null && param.startsWith("/final"))
				dataQS+=param;
		}
}
							//For Templates Code
							//showSite=true;
							int colanWidth=2;
							int siteSize=210;
							if(iniObj.getVariables("REPORT_TEMPLATES",true)!=null)
							{
								v_template=(Vector)v_template.clone();
								Collections.sort(v_template,String.CASE_INSENSITIVE_ORDER);
								String qryString="";
								String useTemplate="",useTest="";
								templateEnable=false;
								if(erd.s_template!=null)
									s_template=erd.s_template;
								if(s_template!=null && s_template.equalsIgnoreCase("yes"))
								{
									useTemplate="checked";
									useTest=" ";
									out.println("templateEnable true");
									templateEnable=true;
								}
								else
								{
									useTemplate=" ";
									useTest="checked";
								}
								if(v_qry_string!=null && !v_qry_string.isEmpty() && !v_qry_string.contains("No Component Found"))
								{
									String stemp=(String)v_qry_string.get(1);
									qryString="er_gtype="+erd.s_gtype+"&er_timeline="+erd.s_timeline+"&er_tbound="+erd.s_tbound+"&er_graphtype="+erd.s_gtype;
								}
								else
									qryString=request.getQueryString();

								colanWidth=3;
								siteSize=210;
								if(st_dataFrom == null || !st_dataFrom.equalsIgnoreCase("Component"))
								{
									User this_user = UserRegistry.getInstance().getUser(session.getId());
									Vector v_zones    = new Vector();
									Vector v_segment  = new Vector();
									Vector v_viewzone = new Vector();
									if(compUtils.getUserZones() != null)
										v_zones.addAll(compUtils.getUserZones());
									if(v_zones != null && v_zones.contains("--Default--"))
										v_zones.remove("--Default--");
									v_segment.addAll(Arrays.asList(compUtils.getUserSegments()));
									for(int j=0;j<v_zones.size();j++)
									{
										Vector viewplus=egviewinfo.getviewsforzone((String)v_zones.get(j));
										v_viewzone.add((String)v_zones.get(j));
										for(int k=0;k<viewplus.size();k++)
										{
										  v_viewzone.add((String)v_zones.get(j)+"-view:"+(String)viewplus.get(k));
										}
									}
									String userid = UBean.getUserId();
									ErUserData user=new ErUserData(userid,false);
								}
							}
	screenLabels.put("reporter.common.Test", intlmap.getTextDescription("reporter.common.Test"));
	if(!templateEnable)
	{
		serverList = sorter.getSortedTestList(v_test);
		if(s_test!=null)
		{
			
			for(int j=0; j< serverList.size(); j++)
			{
				//String tempStr = (String) serverList.get(j);
				EgName nameObj = (EgName)serverList.get(j);
				String tmpVal = nameObj.getActualName();
		     		EgAggregateInfo aggregateInfo = new EgAggregateInfo("manager");
				 if(aggregateInfo.isAggregateTest(tmpVal))
				{
				   serverList.remove(j);
				}
			}
			JSONArray testArr = new JSONArray();
			for(int n=0;n<serverList.size();n++)
			{
				EgName nameObj = (EgName)serverList.get(n);
				String tmpVal = nameObj.getActualName();
				String tmpDis = nameObj.getLocalName();
				JSONObject testObj = new JSONObject();
				testObj.put("valueField", tmpVal);
				testObj.put("displayField", tmpDis);
				testArr.add(testObj);
				if(s_test!=null && s_test.equalsIgnoreCase(tmpVal))
				{
					selectedObj.put("testSelected", tmpVal);
				}
			}
			rootJson.put("testCombo", testArr);
		}
		screenLabels.put("reporter.CapacityPlan.Measure", intlmap.getTextDescription("reporter.CapacityPlan.Measure"));

		if(aListMappingMeas!=null)
		{
				JSONArray measureArr = new JSONArray();
				JSONObject measureObj = new JSONObject();
				measureObj.put("displayField", intlmap.getTextDescription("reporter.common.Please choose a Measure"));
				measureObj.put("valueField", "-1");
				measureArr.add(measureObj);
				for(int c=0;c<aListMappingMeas.size();c++)
				{
					EgName nameObj = (EgName)aListMappingMeas.get(c);
					String tmpVal = nameObj.getActualName();
					String tmpDis = nameObj.getLocalName();
					measureObj = new JSONObject();
					measureObj.put("displayField", tmpDis);
					measureObj.put("valueField", tmpVal);
					measureArr.add(measureObj);
					if(s_meas!=null && s_meas.equalsIgnoreCase(tmpVal))
					{
						selectedObj.put("measureSelected", tmpVal);
					}
				}
				rootJson.put("measureCombo", measureArr);
		}
	}
	screenLabels.put("reporter.common.Component", intlmap.getTextDescription("reporter.common.Component"));
	JSONArray compArr = new JSONArray();
	if(s_test!=null && !v_comp.isEmpty())
	{
		
		Collections.sort(v_comp, String.CASE_INSENSITIVE_ORDER);
		Collections.sort(v_componetdisp, String.CASE_INSENSITIVE_ORDER);
		for(int n=0;n<v_comp.size();n++)
		{
			String s=(String)v_componetdisp.get(n);
			String strcompname=s.substring(0,s.lastIndexOf(":")+1);
			String strcomptype=s.substring(s.lastIndexOf(":")+1);
			JSONObject compObj = new JSONObject();
			String compNameAndType = strcompname+intlmap.getComponentTypeDescription(strcomptype);
			compObj.put("valueField", v_comp.get(n));
			compObj.put("displayField", compNameAndType);
			compArr.add( compObj );
			//zone component
			if(st_dataFrom!=null && st_dataFrom.equalsIgnoreCase("Zone")
				 && s_farmserver !=null && !s_farmserver.equalsIgnoreCase("--Default--"))
			{
				if(s_comp!=null && s_comp.equalsIgnoreCase((String)v_comp.get(n)))
				{
					v_comp_popup.add((String)v_comp.get(n));
					v_comp_popup_disp.add(strcompname+""+strcomptype);
					selectedObj.put("compSelected", v_comp.get(n));
				}
				else
				{
					if(includezone !=null && !includezone.equalsIgnoreCase("no"))
					{
						v_comp_popup.add((String)v_comp.get(n));
						v_comp_popup_disp.add(strcompname+""+strcomptype);
					}
				}
			}
		}


		//other than zone component
		if(st_dataFrom!=null && !st_dataFrom.equalsIgnoreCase("Zone"))
		{
			for(int n=0;n<v_comp.size();n++)
			{
				String s=(String)v_componetdisp.get(n);
				String strcompname=s.substring(0,s.lastIndexOf(":")+1);
				String strcomptype=s.substring(s.lastIndexOf(":")+1);
				boolean isSelected = false;

				JSONObject compObj = new JSONObject();
				String compNameAndType = strcompname+intlmap.getComponentTypeDescription(strcomptype);
				compObj.put("valueField", v_comp.get(n));
				compObj.put("displayField", compNameAndType);
				compArr.add( compObj );
				
				if(arr_component!=null )
				{
					for( int i=0; i<arr_component.length; i++)
					{
						String temp=arr_component[i];
						if( temp.equalsIgnoreCase((String)v_comp.get(n)))
						{
							selectedObj.put("compSelected", v_comp.get(n));
							isSelected = true;
							break;
						}
					}
				}

				if(isSelected)
				{
					v_comp_popup.add((String)v_comp.get(n));
					v_comp_popup_disp.add(strcompname+""+strcomptype);
				}
				else
				{
					v_comp_popup.add((String)v_comp.get(n));
					v_comp_popup_disp.add(strcompname+""+strcomptype);
				}
			}
		}
	}
	else if(s_comp!=null && !v_availComps.isEmpty()) 
	{
		//default zone component
		if(st_dataFrom!=null && st_dataFrom.equalsIgnoreCase("Zone") && s_farmserver !=null && s_farmserver.equalsIgnoreCase("--Default--"))
		{
			for(int k=0;k<v_availComps.size();k++)
			{

				String defaultComp=(String)v_componetdisp.get(k);
				String strDefcompname=defaultComp.substring(0,defaultComp.lastIndexOf(":")+1);
				String strDefcomptype=defaultComp.substring(defaultComp.lastIndexOf(":")+1);

				JSONObject compObj = new JSONObject();
				String compNameAndType = strDefcompname+intlmap.getComponentTypeDescription(strDefcomptype);
				compObj.put("valueField", v_availComps.get(k));
				compObj.put("displayField", compNameAndType);
				compArr.add( compObj );

				if(s_comp!=null && s_comp.equalsIgnoreCase((String)v_availComps.get(k)))
				{
					v_comp_popup.add((String)v_availComps.get(k));
					v_comp_popup_disp.add(strDefcompname+""+strDefcomptype);
					selectedObj.put("compSelected", v_availComps.get(k));
				}
				else
				{
					if(includezone !=null && !includezone.equalsIgnoreCase("no"))
					{
						v_comp_popup.add((String)v_availComps.get(k));
						v_comp_popup_disp.add(strDefcompname+""+strDefcomptype);
					}
				}

			}
		}
	}
	else
	{
		v_comp_popup.add("-1");
		v_comp_popup_disp.add("Not Applicable");
	}
	rootJson.put("compCombo", compArr);
	for(int n=0;n<v_comp_popup.size();n++)
	{
		String s=(String)v_comp_popup.get(n);
		String ss=(String)v_comp_popup_disp.get(n);
	}
	screenLabels.put("reporter.CapacityPlan.Descriptor", intlmap.getTextDescription("reporter.CapacityPlan.Descriptor"));

		//priya
		String aa = null;
		Vector mhost = new Vector();
		if(arr_component!=null && s_test!=null && !s_test.equals("-1") && !s_test.equals("null"))
		{
			Vector v_info = new Vector();
			for(int n=0; n<arr_component.length; n++)
			{
				mhost = erInfo.getMsmtHostForTest(s_site,s_test,arr_component[n]);
				if(mhost.size()>1)
				{
					if((v_infos.size())>0)
					{
						for(int j=0;j<v_infos.size();j++)
						{
							for(int i=0;i<mhost.size();i++)
							{
								aa = v_infos.get(j) + "(" + mhost.get(i) + ")";
								v_info.add(aa);
							}
						}
					}
					else
					{
						for(int i=0;i<mhost.size();i++)
						{
							aa = "(" + mhost.get(i) + ")";
							v_info.add(aa);
						}
					}
				}
				else
				{
					if((v_infos.size())>0)
					{
						for(int j=0;j<v_infos.size();j++)
						{
							aa =(String) v_infos.get(j);
							v_info.add(aa);
						}
					}
				}
			}
			v_infos =(Vector)v_info.clone();
			v_infos = ListUtils.removeDuplicates(v_infos,true);
		}
		Collections.sort(v_infos,String.CASE_INSENSITIVE_ORDER);
		ListIterator liItr = v_infos.listIterator();
		JSONArray infoArr = new JSONArray();
		JSONObject infoObj = new JSONObject();
		if ( v_infos.size() > 0 )
		{
			infoObj.put("valueField", "-1");
			infoObj.put("displayField", "All Descriptors");
			infoArr.add(infoObj);
		}
		while( liItr.hasNext() )
		{
			String getVal = (String) liItr.next();
			infoObj = new JSONObject();
			infoObj.put("valueField", getVal);
			infoObj.put("displayField", getVal);
			infoArr.add(infoObj);
		}
		if ( arr_info != null && arr_info.length > 0 )
		{
			List getSelList = Arrays.asList(arr_info);
			JSONArray tmpArr = new JSONArray();
			tmpArr.addAll(getSelList);
			selectedObj.put("infoSelected", getSelList.get(0));
		}
		rootJson.put("infoCombo", infoArr);

		String align="";
		String width="";
		String width1="";
		if(erd.s_compare_graphtype==null || erd.s_compare_graphtype.equalsIgnoreCase("Single"))
		{
			align="left";
			width="54%";
			width1="14%";
		}
		else
		{
			if(chartCount!=1 || chartCount==-1)
			{
				width="54%";
				width1="16%";
				align="left";
			}
			else
			{
				align="left";
				width="54%";
				width1="14%";
			}
		}
		if((s_combination!=null)&&(s_combination.trim().length()>0)&&!s_combination.equalsIgnoreCase("-10eghash0eghash0"))
		{
			StringTokenizer s=new StringTokenizer(s_combination,"0eghash0eghash0");
			Vector v_combination = new Vector();
			//while(s.hasMoreTokens())
				//v_combination.add(s.nextToken());
			/*String c_items[]=StringUtils.getTokens(s_combination,"0eghash0eghash0") ;
			if (c_items != null)
			{
				for (int j=0;j < c_items.length; j++)
				{
					v_combination.add(c_items[j]) ;
				}
			}*/
			v_combination.addAll(Arrays.asList(arr_selection));
			String  selTest="";
			String mapTest="";
			String  selMeasure="";
			String selDesc="";
			String  outStr="";
			Vector mapStr=new Vector();
			if(v_combination!=null  && v_combination.size()>0)
			{
				for(int k=0;k<v_combination.size();k++)
				{
					String sel=(String)v_combination.get(k);
					String comp=sel.substring(0,sel.indexOf("| |"));
					String  tok=sel.substring(sel.indexOf("| |")+2,sel.length());
					String  co;
					if(comp.equalsIgnoreCase("All"))
					{
						co = comp;
					}
					else
					{
						co=comp.substring(0,comp.lastIndexOf(":"));
					}
					String  type=comp.substring(comp.lastIndexOf(":")+1,comp.length());
					String  mapco=co+":"+intlmap.getComponentTypeDescription(type);
					StringTokenizer stm=new StringTokenizer(tok,"|");
					int tokcnt=stm.countTokens();
					selTest=(String)stm.nextToken();
					mapTest=intlmap.getTestDescription(selTest);
					selMeasure=intlmap.getMeasureDescription(selTest,(String)stm.nextToken());
					outStr=mapco+"| |"+mapTest+"|"+selMeasure;
					if(tokcnt==3)
					{
						selDesc=(String)stm.nextToken();
						outStr=outStr+"|"+selDesc;
					}
					mapStr.add(outStr);
				}
			}
//												out.println(erUtils.fillSelectBox(v_combination,mapStr,"",arr_selection));
		}
		screenLabels.put("reporter.common.Add", intlmap.getTextDescription("reporter.common.Add"));
		screenLabels.put("reporter.common.Remove", intlmap.getTextDescription("reporter.common.Remove"));
		hiddens.put("toScrpt", erUtils.specialCharEncode(toScript));
		hiddens.put("toScrpText", erUtils.specialCharEncode(toScriptText));
		String space="";
		String space1="";
		String showDataWidth="";
		String timelineWidth="";
		String s_single_sel="",s_multiple_sel="",g_multiple="";
		boolean computsum=si.getAvgSumTrends();
		hiddens.put("er_graphtype", "Single");
		hiddens.put("er_trenddata", trendQuery);
		hiddens.put("trendenable", String.valueOf(computsum));
	
%>
<%@include file="ErTimeFormatJSON.jsp"%>
<%
		hiddens.put("er_usertimeline", strUsrTimeline);
		
		rootJson.put("startDateForDisplay",startDateForDisplay);
		rootJson.put("startHourForDisplay",startHourForDisplay);
		rootJson.put("startMinForDisplay",startMinForDisplay);
		rootJson.put("endDateForDisplay",endDateForDisplay);
		rootJson.put("endHourForDisplay",endHourForDisplay);
		rootJson.put("endMinForDisplay",endMinForDisplay);
		chartTypeForUI=ErHighchartUtils.getChartType(startDateForHighchart,endDateForHighchart,currentDateFormat+" HH:mm");
		rootJson.put("chartType",chartTypeForUI);
		screenLabels.put("reporter.common.Timeline", intlmap.getTextDescription("reporter.common.Timeline"));
		screenLabels.put("reporter.common.From", intlmap.getTextDescription("reporter.common.From"));
		screenLabels.put("reporter.common.To", intlmap.getTextDescription("reporter.common.To"));
		screenLabels.put("reporter.common.Hr", intlmap.getTextDescription("reporter.common.Hr"));
		screenLabels.put("reporter.common.Graph", intlmap.getTextDescription("reporter.common.Graph"));

		rootJson.put("timelineCombo",timelineComboArray);
		rootJson.put("timelineHourCombo",timelineHourComboArray);
		rootJson.put("selectedTimeline",er_timeline);
		rootJson.put("startDate",startDateJSON);
		rootJson.put("endDate",endDateJSON);
		rootJson.put("startHour",startHourJSON);
		rootJson.put("endHour",endHourJSON);
		rootJson.put("startmin", startMin);
		rootJson.put("endmin", endMin);
		rootJson.put("selectedGraphMode",selectedGraphMode);
		screenLabels.put("reporter.common.CumulateUsing", intlmap.getTextDescription("reporter.common.Cumulate Using"));
		screenLabels.put("reporter.common.ReportType", intlmap.getTextDescription("reporter.common.Report Type"));
		session.setAttribute("data_option",er_dataoption);
		JSONArray gridTitleArr = new JSONArray();
		gridTitleArr.add(nameLang);
		gridTitleArr.add(typeLang);
		gridTitleArr.add(testLang);
		gridTitleArr.add(measureLang);
		gridTitleArr.add(descLang);
		rootJson.put("COLUMN_HEADERS", gridTitleArr);
		JSONArray cummulateArr = new JSONArray();
		for(int i=0; i<dataOptionList.size(); i++) 
		{
			String dataOption = (String)dataOptionList.get(i);
			JSONObject cummulateObj = new JSONObject();
			cummulateObj.put("displayField", dataOption);
			cummulateObj.put("valueField", dataOption);
			cummulateArr.add(cummulateObj);
			selected = "";
			if ( dataOption.equals(er_dataoption) ) 
			{
				selectedObj.put("cumulateSelected", dataOption);
				selected = "selected";
			}
		}
		rootJson.put("cumulateCombo", cummulateArr);
		JSONArray summaryArr = new JSONArray();
		for(int n=0;n<v_summarytype.size();n++)
		{
			String s=(String)v_summarytype.get(n);
			String value = "DS";
			if(s.equalsIgnoreCase("Monthly Summary"))
				value = "MS";
			if(s.equalsIgnoreCase("Hourly Summary"))
				value = "HS";
			JSONObject summaryObj = new JSONObject();
			summaryObj.put("displayField", intlmap.getTextDescription("reporter.common."+s));
			summaryObj.put("valueField", value);
			summaryArr.add(summaryObj);
			if(sumType!=null && sumType.equalsIgnoreCase(value))
			{
				selectedObj.put("summarySelected", value);
			}
		}
		rootJson.put("summaryCombo", summaryArr);
		screenLabels.put("reporter.consolidated.Report Generation", intlmap.getTextDescription("reporter.consolidated.Report Generation"));
		screenLabels.put("reporter.consolidated.Report Name", intlmap.getTextDescription("reporter.consolidated.Report Name"));
		JSONArray reportArr = new JSONArray();
		JSONObject reportObj = new JSONObject();
		reportObj.put("displayField", strbackground);
		reportObj.put("valueField", "background");
		reportArr.add(reportObj);

		reportObj = new JSONObject();
		reportObj.put("displayField", strforeground);
		reportObj.put("valueField", "foreground");
		reportArr.add(reportObj);
		rootJson.put("reportGenCombo", reportArr);

		String er_reportgenration = request.getParameter("er_reportgenration");
		String er_background ="";
		String er_foreground ="";
		if (er_reportgenration != null && er_reportgenration.equals("background"))
		{
			selectedObj.put("reportGenSelected", "background");
			er_background = "selected";
			er_foreground = "";
		}
		else
		{
			selectedObj.put("reportGenSelected", "foreground");
			er_background = "";
			er_foreground = "selected";
		}
		String bg_reportname = request.getParameter("bg_reportname");
		if(bg_reportname == null)
		{
			bg_reportname = "";
		}
		if(strbgrepportName != null && strbgrepportName.equalsIgnoreCase("Yes"))
		{
			if (er_reportgenration != null && er_reportgenration.equals("background"))
			{
				selectedObj.put("reportName", bg_reportname);
			}
		}
		if(reqFromSchedule!=null && reqFromSchedule.equalsIgnoreCase("Yes"))
		{
			screenLabels.put("reporter.common.SUBMIT", intlmap.getTextDescription("reporter.common.SAVE"));
		}
		else
		{
			screenLabels.put("reporter.common.SUBMIT", intlmap.getTextDescription("reporter.common.SUBMIT"));
		}
		if(bggroundStr != null && !bggroundStr.equals(""))
		{
			isBackgroundProcess = true;
			String strReportName="CapacityPlanning_Cumulation";
			if(status != null && (status.equalsIgnoreCase("duplicate") || status.equalsIgnoreCase("exceedLimit")))
			{
				strReportName="All Report Types";
			}
			backgroundResultObj.put("status", status);
			if(status != null && !status.equalsIgnoreCase("exceedLimit"))
			{
				backgroundResultObj.put("backgroundResponseText", erbgreport.getlangsupportedString(bggroundStr,bgString,urs));
			}
			else
			{
				backgroundResultObj.put("backgroundResponseText", bggroundStr);
			}
			if(strReportName!=null && strReportName.indexOf(" ") > -1)
			{
				strReportName = com.eg.EgURLEncoder.encode(strReportName, "UTF-8");
			}
			backgroundResultObj.put("backgroundLink", "/final/servlet/com.eg.ErStartBackGroundReportC?back=true&er_bgreportfrom="+strReportName+"&userID="+com.eg.EgURLEncoder.encode(urs, "UTF-8")+"&savereport=search&er_filterby=Report_Name&forwardto=ErBackGoundProcess");
			backgroundResultObj.put("backgroundText", intlmap.getTextDescription("reporter.common.Click here to see a list of generated and processing reports"));
	}
	if(chartCount > 0)
	{

		selectionDetails.put(intlmap.getTextDescription("reporter.common.Cumulate Using"), intlmap.getTextDescription("reporter.common."+er_dataoption));

		String tmpTimeline = "<span class='font_bold'> </span> "
		+startDateForDisplay+" "+startHourForDisplay+":"+startMinForDisplay+" hrs"+
		" <span class='font_bold'>  "+intlmap.getTextDescription("reporter.common.to")+" </span>"
		+endDateForDisplay+" "+endHourForDisplay+":"+endMinForDisplay+" hrs";

		selectionDetails.put(intlmap.getTextDescription("reporter.common.Timeline"), tmpTimeline);
		if(chartCount == 1)
		{
			String title="";
			if(request.getParameter("er_selection")!=null)
			{
				title=request.getParameter("er_selection");
				title=title.replace('|','/');
			}
			else
			{
				title="/ /"+erd.s_test+"/"+s_meas;
			}
			String s_qrystring=(String)v_qry_string.get(1);
			String showLegends = (String)request.getParameter("showLegend");
			if(showLegends == null)
				showLegends = "true";

			HashMap tmpmap=ErUtils.parseQueryString(s_qrystring.substring(s_qrystring.indexOf("?")+1)+"&er_width=900&er_height=400&option=graph&enlarged=true&er_trenddata="+trendQuery+"er_templateEnable="+s_template+"er_dataoption="+er_dataoption+"&decimal_point="+decimal_point+"&showLegend="+showLegends);
			
			session.setAttribute("graphparams",tmpmap);
			String tmpqs="";
			if (s_qrystring.indexOf("er_selection") >-1 )
			{
				tmpqs=s_qrystring.substring(0,s_qrystring.indexOf("er_selection") -1);
			}else
			{
				tmpqs=s_qrystring;
				
			}
			if(v_qry_string.get(0).toString().indexOf(":")>-1)
			{
				String isthecomp=v_qry_string.get(0).toString();
				String compname="";
				if(isthecomp.indexOf(":NULL")>-1)
				{
					compname=isthecomp.substring(0,isthecomp.indexOf(":NULL"));
					compname=compname+isthecomp.substring(isthecomp.lastIndexOf(":NULL")+5);
				}
				else
				{
					compname=isthecomp;
				}
				resultsObj.put("TITLE", compname.substring(0,compname.lastIndexOf(":")+1)+intlmap.getComponentTypeDescription(compname.substring(compname.lastIndexOf(":")+1)));
			}
			else
			{
				resultsObj.put("TITLE", v_qry_string.get(0));
			}
			String tmpQS="";
			if(tmpqs!=null)
			{
				StringTokenizer strtok = new StringTokenizer(tmpqs,"&");
				while(strtok.hasMoreTokens())
				{
					String param = strtok.nextToken();
					if(param!=null && param.indexOf("=")>-1)
					{
							String reqparam =param.substring(0,param.indexOf("="));
							String value = param.substring(param.indexOf("=")+1,param.length());
							String val1=value;
							if(value==null)
								value="";
							if(reqparam.equals("er_component") ||  reqparam.equals("er_info_list"))
							{
								if(value.indexOf("+")>-1){
									value=StringUtils.replace(value,"+","|plus|");
								}else if(value.indexOf("&")>-1){
									value=StringUtils.replace(value,"&","|amp|");
								}else if(value.indexOf("%")>-1){
									value=StringUtils.replace(value,"%","|pct|");
								}
								if(value!=null && value.equals("-1"))
									value="";
								if(value!=null  && !value.equals(""))
									value=EgURLEncoder.encode(URLDecoder.decode(value),"UTF-8");
							}
							tmpQS=tmpQS+reqparam+"="+value+"&";

					}
					else
					{
						if(param!=null && param.startsWith("/final"))
							tmpQS+=param;
					}
				}
			}
			String showLegend = (String)request.getParameter("showLegend");
			if(showLegend == null)
				showLegend = "true";
			tmpQS+="&showLegend="+showLegend;
			if(s_multiple_sel.equals("checked"))
			{
				resultsObj.put("IMAGE_URL", tmpQS+"&option=graph&decimal_point="+decimal_point);
				resultsObj.put("IMAGE_HEIGHT", "200");
				resultsObj.put("IMAGE_WIDTH", "380");
				resultsObj.put("IMAGE_TITLE", v_qry_string.get(0));
			}
			else
			{
				resultsObj.put("IMAGE_URL", tmpQS+"&option=graph&decimal_point="+decimal_point);
				resultsObj.put("IMAGE_HEIGHT", "200");
				resultsObj.put("IMAGE_WIDTH", "380");
				resultsObj.put("IMAGE_TITLE", v_qry_string.get(0));
				String strselectioncount = reportinfo.getValue("MISC","RightDisplaySelectioncount");
						
				int selectioncount=10;
				if(strselectioncount !=null && !strselectioncount.equals(""))
				{
					try
					{
						selectioncount = Integer.parseInt(strselectioncount);
					}
					catch (Exception e)
					{
						selectioncount = 10;
					}
				}
				selectioncount = 2;
				if (singleSelection != null && singleSelection.size() >selectioncount)
				{
					//out.println("singleSelection null");
						int count1=0;
						JSONArray legendArr = new JSONArray();
						for (int k=0; k <singleSelection.size();k++)
						{
							String st_key = (String)singleColors.get(k);
							String value = (String)singleSelection.get(k);
							st_key = st_key.substring(1,st_key.length());
							JSONObject legendObj = new JSONObject();
						if(k%2 ==0)
						{
							String dispValue="";
							int n=0;
							int h=0;
							int charval=value.length();
							for (int y=0;y <charval ;y++ )
							{
								if(n==60)
								{
								  dispValue += value.substring(h,y)+"<br>";
								  h=y;
								  n=0;
								}
								n++;
							}
							if(n < 60)
							{
								dispValue += value.substring(h,charval)+"<br>";
							}
							if(value.indexOf(" ")>-1)
							{
								dispValue = value;
							}
							legendObj.put("COLOR", st_key);
							legendObj.put("INFOS", dispValue);
						}
						else if(k%2 !=0)
						{
							String dispValue="";
							int n=0;
							int h=0;
							int charval=value.length();
							for (int y=0;y <charval ;y++ )
							{
								if(n==60)
								{
								  dispValue += value.substring(h,y)+"<br>";
								  h=y;
								  n=0;
								}
								n++;
							}
							if(n < 60)
							{
								dispValue += value.substring(h,charval)+"<br>";
							}
							if(value.indexOf(" ")>-1)
							{
								dispValue = value;
							}
							legendObj.put("COLOR", st_key);
							legendObj.put("INFOS", dispValue);
						}
						else
						{
							legendObj.put("COLOR", st_key);
							legendObj.put("INFOS", value);
						}
						legendArr.add(legendObj);
						}
						resultsObj.put("LEGENDS", legendArr);
				}
				session.setAttribute("singleColors",singleColors);
				session.setAttribute("singleSelection",singleSelection);
			}
		}
		else
		{
			//boolean leftQuad = true;
			for(int i=0;i<chartCount;i++)
			{
				String s_title =(String)v_qry_string.get(i*2);
				//String s_comp=s_title.substring(
				boolean leftQuad = (i%2==0);
				if(leftQuad) out.println("<tr>");
				String Qstring="";
				String pQstring="";
				String s_infolist="";
				String  s_qrystring=(String)v_qry_string.get(i*2+1);
				JSONObject legendObj = new JSONObject();
				if(s_qrystring!=null)
				{
					StringTokenizer strtok = new StringTokenizer(s_qrystring,"&");
					while(strtok.hasMoreTokens())
					{
						String param = strtok.nextToken();
						if(param!=null && param.indexOf("=")>-1)
						{
							String reqparam =param.substring(0,param.indexOf("="));
							String value = param.substring(param.indexOf("=")+1,param.length());
							if(value==null)
								value="";
							if(reqparam.equals("er_info_list"))
							{
								if(!value.equals("") && value.length()>0 )
								{
									if(value.startsWith("(") && value.endsWith(")"))
										s_infolist=" "+value;
									else
										s_infolist=" ("+value+")";
								}
								else
									s_infolist=value;
							}
							if(reqparam.equals("er_component") ||  reqparam.equals("er_info_list"))
							{
								if(value.indexOf("+")>-1){
									value=StringUtils.replace(value,"+","|plus|");
								}else if(value.indexOf("&")>-1){
									value=StringUtils.replace(value,"&","|amp|");
								}else if(value.indexOf("%")>-1){
									value=StringUtils.replace(value,"%","|pct|");
								}
								if(value!=null && value.equals("-1"))
									value="";
								if(value!=null  && !value.equals(""))
									value=EgURLEncoder.encode(URLDecoder.decode(value),"UTF-8");
							}
							pQstring=pQstring+reqparam+"="+value+"&";
						}
						else
						{
							if(param!=null && param.startsWith("/final"))
								pQstring+=param;
						}
					}
				}
	String strselectioncount = reportinfo.getValue("MISC","RightDisplaySelectioncount");
			
	int selectioncount=10;
	if(strselectioncount !=null && !strselectioncount.equals(""))
	{
		try
		{
			selectioncount = Integer.parseInt(strselectioncount);
		}
		catch (Exception e)
		{
			selectioncount = 10;
		}
	}
	if (singleSelection != null && singleSelection.size() >selectioncount)
	{
			int count1=0;
			JSONArray legendArr = new JSONArray();
			for (int k=0; k <singleSelection.size();k++)
			{
				String st_key = (String)singleColors.get(k);
				String value = (String)singleSelection.get(k);
				st_key = st_key.substring(1,st_key.length());
 			if(k%2 ==0)
			{
				String dispValue="";
				int n=0;
				int h=0;
				int charval=value.length();
				for (int y=0;y <charval ;y++ )
				{
					if(n==60)
					{
					  dispValue += value.substring(h,y)+"<br>";
					  h=y;
					  n=0;
					}
					n++;
				}
				if(n < 60)
				{
					dispValue += value.substring(h,charval)+"<br>";
				}
				if(value.indexOf(" ")>-1)
				{
					dispValue = value;
				}
				legendObj.put("COLOR", st_key);
				legendObj.put("INFOS", dispValue);
			}
			else if(k%2 !=0)
			{
				String dispValue="";
				int n=0;
				int h=0;
				int charval=value.length();
				for (int y=0;y <charval ;y++ )
				{
					if(n==60)
					{
					  dispValue += value.substring(h,y)+"<br>";
					  h=y;
					  n=0;
					}
					n++;
				}
				if(n < 60)
				{
					dispValue += value.substring(h,charval)+"<br>";
				}
				if(value.indexOf(" ")>-1)
				{
					dispValue = value;
				}
				legendObj.put("COLOR", st_key);
				legendObj.put("INFOS", dispValue);
			}
			else
			{
				legendObj.put("COLOR", st_key);
				legendObj.put("INFOS", value);
			}
 			legendArr.add(legendObj);
			}
			resultsObj.put("LEGENDS", legendArr);
	}
				if(s_title.indexOf(":")>-1)
				{
					String isthecomp=s_title;
					String compname="";
					if(isthecomp.indexOf(":NULL")>-1)
					{
						compname=isthecomp.substring(0,isthecomp.indexOf(":NULL"));
						compname=compname+isthecomp.substring(isthecomp.lastIndexOf(":NULL")+5);
					}
					else
					{
						compname=isthecomp;
					}
				}
				if(!leftQuad) out.println("</tr>");
			}
		}
		HashMap param = new HashMap();
		param.put("REPORT_PARAM",ErUtils.parseQueryString(ErUtils.prepareQueryString(request.getParameterMap())));
		param.put("REPORT_DATA",v_newPdf_qry);
		session.setAttribute("parameters", param);
	}

	HashMap parameters= new HashMap(request.getParameterMap());
	if(parameters!=null && parameters.get("er_selection")!=null)
	{
		Object obj =parameters.get("er_selection");
		if(obj instanceof String[])
		{
			String[] str1 = (String[])obj;
			for(int cnt=0;cnt<str1.length;cnt++)
			{
				str1[cnt] = com.eg.EgURLEncoder.encode(str1[cnt],"UTF-8");
			}
			parameters.put("er_selection",str1);
		}
		else if(obj instanceof String)
		{
			String str1 = (String)obj;
			str1 = com.eg.EgURLEncoder.encode(str1,"UTF-8");
			parameters.put("er_selection",str1);
		}
	}
	
	//String queryString =(String)ErUtils.prepareQueryString(request.getParameterMap());
	String queryString =(String)ErUtils.prepareQueryString(parameters);
	String Qstring="";
	if(queryString!=null)
	{
		StringTokenizer strtok = new StringTokenizer(queryString,"&");
		while(strtok.hasMoreTokens())
		{
			String parameter = strtok.nextToken();
			int ind = parameter.indexOf("=");
			if (ind < 0)
				continue;
			String reqparam =parameter.substring(0,ind);
			String value = parameter.substring(ind+1);
			if ( reqparam != null && reqparam.equalsIgnoreCase("call") )
			{
				continue;
			}
			if(reqparam!=null&&reqparam.equals("er_info_list"))
			{
				value=com.eg.EgURLEncoder.encode(value, "UTF-8");
			}
			if(reqparam!=null&&reqparam.equals("er_component"))
			{
				value=com.eg.EgURLEncoder.encode(value, "UTF-8");
			}
			if(reqparam!=null&&reqparam.equals("er_combination"))
			{
				value=com.eg.EgURLEncoder.encode(value, "UTF-8");
			}
			if(reqparam!=null&&reqparam.equals("er_selection"))
			{
				value=com.eg.EgURLEncoder.encode(value, "UTF-8");
			}
			if(reqparam!=null&&reqparam.equals("loadCombination")) //..
			{
				value=com.eg.EgURLEncoder.encode(value, "UTF-8");
			}
			if(reqparam!=null&&reqparam.equals("startdate"))
			{
				value=com.eg.EgURLEncoder.encode(value, "UTF-8");
			}
			if(reqparam!=null&&reqparam.equals("enddate"))
			{
				value=com.eg.EgURLEncoder.encode(value, "UTF-8");
			}
			if(reqparam!=null&&reqparam.equals("inidate"))
			{
				value=com.eg.EgURLEncoder.encode(value, "UTF-8");
			}
			if(reqparam!=null&&reqparam.equals("currTime"))
			{
				value=com.eg.EgURLEncoder.encode(value, "UTF-8");
			}
			if(reqparam!=null&&reqparam.equals("toScrpText"))
			{
				value=com.eg.EgURLEncoder.encode(value, "UTF-8");
			}
			if(reqparam!=null&&reqparam.equals("singleselection"))
			{
				value=com.eg.EgURLEncoder.encode(value, "UTF-8");
			}
			if(reqparam!=null&&reqparam.equals("limitforbg"))
			{
				value=com.eg.EgURLEncoder.encode(value, "UTF-8");
			}
			if(reqparam!=null&&reqparam.equals("er_timeline"))
			{
				value=com.eg.EgURLEncoder.encode(value, "UTF-8");
			}
			if(reqparam!=null&&reqparam.equals("er_rtype"))
			{
				value=com.eg.EgURLEncoder.encode(value, "UTF-8");
			}
			if(reqparam!=null&&reqparam.equals("ID")) //..
			{
				continue;
			}
			Qstring=Qstring+reqparam+"="+value+"&";
		}
	}


	//Back Button - Start
	ArrayList listbackvar = new  ArrayList();
	if(request.getParameter("isSubmit")!=null)
	{
		session.setAttribute("reportLastAccessedURL","/final/servlet/com.eg.ErRepoLiteC?"+Qstring);
		listbackvar.add("/servlet/com.eg.ErRepoLiteC?");
		listbackvar.add("status="+status+"&bggroundStr="+bggroundStr+"&bg_reportname="+bg_reportname+"&"+queryString);
		session.setAttribute("favSchBackDisplay","Yes");
	}
	else
	{
		session.setAttribute("reportLastAccessedURL","/final/reporter/ErCapacityCumulationReport.jsp?"+Qstring);
		listbackvar.add("ErCapacityCumulationReport.jsp");
		listbackvar.add(queryString);
		session.setAttribute("favSchBackDisplay","No");
	}
	String backadded = erhelputils.getBackID();
	backreqMap = erhelputils.setBackQueryMap(backreqMap,backadded,listbackvar);
	session.setAttribute("backQuery",backreqMap);

	//Back Button - End

	// added for mail
	String qrString="";
	if(s_printQS!=null)
	{
		StringTokenizer sttok = new StringTokenizer(s_printQS,"&");
		while(sttok.hasMoreTokens())
		{
			String param = sttok.nextToken();
			int in = param.indexOf("=");
			if (in < 0)
				continue;
			String rparam =param.substring(0,in);
			String val = param.substring(in+1);
			if(rparam!=null&&rparam.equals("er_tbound"))
			{
				val=com.eg.EgURLEncoder.encode(val, "UTF-8");
			}
			if(rparam!=null&&rparam.equals("er_graphtype"))
			{
				val=com.eg.EgURLEncoder.encode(val, "UTF-8");
			}
			if(rparam!=null&&rparam.equals("er_timeline"))
			{
				val=com.eg.EgURLEncoder.encode(val, "UTF-8");
			}
			if(rparam!=null&&rparam.equals("er_gtype"))
			{
				val=com.eg.EgURLEncoder.encode(val, "UTF-8");
			}
			if(rparam!=null&&rparam.equals("currTime"))
			{
				val=com.eg.EgURLEncoder.encode(val, "UTF-8");
			}
			if(rparam!=null&&rparam.equals("startdate"))
			{
				val=com.eg.EgURLEncoder.encode(val, "UTF-8");
			}
			if(rparam!=null&&rparam.equals("starthr"))
			{
				val=com.eg.EgURLEncoder.encode(val, "UTF-8");
			}
			if(rparam!=null&&rparam.equals("enddate"))
			{
				val=com.eg.EgURLEncoder.encode(val, "UTF-8");
			}
			if(rparam!=null&&rparam.equals("endhr"))
			{
				val=com.eg.EgURLEncoder.encode(val, "UTF-8");
			}
			if(rparam!=null&&rparam.equals("startmin"))
			{
				val=com.eg.EgURLEncoder.encode(val, "UTF-8");
			}
			if(rparam!=null&&rparam.equals("endmin"))
			{
				val=com.eg.EgURLEncoder.encode(val, "UTF-8");
			}
			if(rparam!=null&&rparam.equals("userID"))
			{
				val=com.eg.EgURLEncoder.encode(val, "UTF-8");
			}
			if(rparam!=null&&rparam.equals("er_dataoption"))
			{
				val=com.eg.EgURLEncoder.encode(val, "UTF-8");
			}
			if(rparam!=null&&rparam.equals("er_trenddata"))
			{
				val=com.eg.EgURLEncoder.encode(val, "UTF-8");
			}
			qrString=qrString+rparam+"="+val+"&";
		}
	}
	session.setAttribute("PDF_URL", mngrIProc+"/final/servlet/com.eg.ErRepoLiteC");

	qrString=mngrIProc+"/final/servlet/com.eg.ErRepoLiteC;jsessionid="+ session.getId()+"?"+qrString+"&er_trenddata="+trendQuery+"&option=Graph&printGraph=yes&er_type=CapacityPlan&pdfPrint=no";
	session.setAttribute("MAIL_URL",qrString);

	if(decimal_point!=null)
		selectedObj.put("selected_decimal_point", decimal_point);



	rootJson.put("selectedValues", selectedObj);
	rootJson.put("selectionDetails", selectionDetails);
	rootJson.put("screenLabels", screenLabels);
	rootJson.put("hiddens", hiddens);
	if ( !backgroundResultObj.isEmpty() )
	{
		rootJson.put("backgroundResults", backgroundResultObj);
	}
	if ( !resultsObj.isEmpty() )
	{
		rootJson.put("RESULTS", resultsObj);
	}
	out.println(rootJson.toString());
}
catch(Exception e)
{
	e.printStackTrace();
}
%>