<%@ include file = "ErReporterTracker.jsp" %>
<%@ page import = "com.eg.EgDateInfo" %>
<%@ page import = "com.eg.EgServicesInfo" %>
<%@ page import = "com.eg.EgTablesInfo" %>
<%@ page import = "com.eg.EgTesterInfo" %>
<%@ page import = "com.eg.EgDbInfo" %>
<%@ page import = "com.eg.EgMappingInfo"%>
<%@ page import = "com.eg.EgTestInfo"%>
<%@ page import = "com.eg.EgSpecsInfo"%>
<%@ page import = "com.eg.EgURLDecoder" %>
<%@ page import = "com.eg.EgConfigInfo"%>
<%@ page import = "com.egurkha.util.DateTimeTokenizer" %>
<%@ page import = "com.egurkha.util.DateUtil" %>
<%@ page import = "egurkha.reporter.ErInfo" %>
<%@ page import = "com.egurkha.util.StringUtils" %>
<%@ page import = "com.eg.EgReportInfo" %>
<%@ page import = "java.text.SimpleDateFormat" %>
<%@ page import = "com.eg.MappingNameSorter"%>
<%@ page import = "com.eg.EgName" %>
<%@ page import = "net.sf.json.*" %>
<%@ taglib prefix="egui" uri="../WEB-INF/eg-taglib.tld" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

<%!
	private int[] getDefinedPercentile(String testName, String measureName) {
		EgTesterInfo testerInfo=new EgTesterInfo("manager");
		EgServicesInfo servicesInfo = new EgServicesInfo("manager");
		String customPercentileName = testerInfo.getCustomPercentileName(testName + ":" + measureName);
		int[] percentile = null;
		if(customPercentileName == null) {
			percentile = servicesInfo.getDefaultPercentileForCapacity();
		} else {
			percentile = servicesInfo.getPercentileForCapacity(customPercentileName);
			if(percentile == null) {
				percentile = servicesInfo.getDefaultPercentileForCapacity();
			}
		}
		return percentile;
	}

	private static final String BLANK_SPACE = " ";
	private static final String COMA = ",";
	private static final String COLON = ":";
	private static final String UTF_8 = "UTF-8";
%>
<%

	String titleToDisplay=request.getParameter("er_RmDispName");

	//Back Button - Start
	String bggroundStr = (String)request.getAttribute("bggroundStr");
	String status = (String)request.getAttribute("status");
	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 queryString="";

	String backButtonEnable = request.getParameter("back");
	if(backButtonEnable != null && backButtonEnable.equalsIgnoreCase("True"))
	{
		status = (String)request.getParameter("status");
		bggroundStr = (String)request.getParameter("bggroundStr");
		request.setAttribute("SYSTEM_CAPACITY_REPORT", null);
	}
try
{
	String s_iniFile_dir = EgInstallInfo.getInstallDir()+ "/manager/config/";
	String uiFile = "eg_ui.ini";
	JSONObject json = new JSONObject();
	ErUserData erdata = new ErUserData(UBean.getUserId(),false);
	ErUtils erUtils = new ErUtils();
	com.eg.IniFile egUI = new com.eg.IniFile(s_iniFile_dir + uiFile);
	com.egurkha.ini.IniUI ui = (com.egurkha.ini.IniUI)com.egurkha.ini.IniUI.getInstance();
    String thisLanguage = ui.getDefaultLanguage();
	UserRegistry mregistry = UserRegistry.getInstance();
	User muser = mregistry.getUser(session.getId());
	if (muser!=null)
	{
		String userLang = muser.getLanguage();
		if (userLang!=null && !userLang.equalsIgnoreCase("NULL"))
		{
			thisLanguage=userLang;
		}
	}
    MappingNameSorter sorter = new MappingNameSorter(thisLanguage);
	EgDateInfo egDt = new EgDateInfo();
	EgReportInfo reportInfo = new EgReportInfo("manager");
	EgSpecsInfo specsInfo = new EgSpecsInfo("manager");
	EgTablesInfo tablesInfo = new EgTablesInfo ("manager");
	EgCrawler crawlerBean = new EgCrawler(new IniFile(s_iniFile_dir + "eg_topology.ini"));
	EgMappingInfo intlmap = new EgMappingInfo(thisuser.getLanguage());
	EgDbInfo dbInfo = new EgDbInfo("manager");
	ErInfo erInfo = new ErInfo();
	EgTestInfo tokInfo = new EgTestInfo("manager");
	String mngrIProc = new IniFile(new EgConfigInfo("manager").getDbFile()).getValue("DB_PROPERTIES","ManagerUrl");
	int pageWidthProces = 1024;

	User this_user = UserRegistry.getInstance().getUser(session.getId());
	ErComponentsUtils compUtil = new ErComponentsUtils(thisuser.getLoginID());
	ErReportHelper erh = new ErReportHelper();
	EgUserRole userRole = this_user.getUserRole();
	boolean hasAdminTab = userRole.hasAnyAdminRole(EgUserPermission.ADMIN);
	boolean isCompletedUserRole = userRole.hasAllComponentAccess();

	com.eg.IniFile servicesInfo = new com.eg.IniFile(s_iniFile_dir + "eg_services.ini");
	String isCapacityTrendEnabled=servicesInfo.getValue("MISC_ARGS","CapacityTrendEnabled");
	
	  json.put("hasAdminTab",hasAdminTab);
	  json.put("isCompletedUserRole",isCompletedUserRole);
	  json.put("isCapacityTrendEnabled",isCapacityTrendEnabled);

	queryString="";
	//String[] options = {"Any","1 day", "2 days", "3 days", "4 days","5 days", "6 days","1 week","2 weeks","3 weeks","1 month"};
	String[] options = {"Any","1 day", "2 days", "3 days", "4 days","5 days", "6 days","1 week","2 weeks","3 weeks","1 month","3 months","6 months","9 months","12 months"};
	String dispDate = null;
	String comFormat = null;
	String disable="";

	String currentDateFormat = strUserDateFormat;

	String s_site = "";
	String isSubmit = request.getParameter("isSubmit");
	String er_type = request.getParameter("er_type");
	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 er_timeline = request.getParameter("er_timeline");
	String s_inidate = request.getParameter("inidate");
	String strmin = request.getParameter("startmin");
	String enmin = request.getParameter("endmin");
	String reqFromSchedule = request.getParameter("fromSchedule");
	String s_comptype = request.getParameter("er_comptype");
	status = (String)request.getAttribute("status");
	String[] selectedCompArray = request.getParameterValues("er_component");
	String schedule_id = request.getParameter("schedule_id");
	String fromScheduleModify = request.getParameter("fromScheduleModify");
	String fromFavoriteModify = request.getParameter("fromFavoriteModify");
	String favorite_id = request.getParameter("id");
	String er_favorite = request.getParameter("er_favorite");

	String selectedComponents = "";
	String userid = UBean.getUserId();
	boolean isBackgroundProcess = false;
	
	Vector v_site = new Vector();
	Vector v_component = new Vector();
	Vector v_componentName = new Vector();
	Vector v_comptype = new Vector();
	Vector temp_component = new Vector();
	Vector unique_component = new Vector();
	Vector v_comp_popup = new Vector();
	Vector v_comp_popup_disp = new Vector();
	String selectedGroup = request.getParameter("select_group");
	com.eg.EgTopoInfo topoInfo = new com.eg.EgTopoInfo("manager");
	String treeParam = request.getParameter("treeParam");
	List measureList = new ArrayList();
	String measureOrder = reportInfo.getValue("SYSTEM_CAPACITY", "MeasureOrder");
	StringTokenizer measureOrderToken = new StringTokenizer(measureOrder, ",");
	while(measureOrderToken.hasMoreTokens())
	{
		String measure = measureOrderToken.nextToken();
		measureList.add(measure);
	}
	if(selectedGroup!=null && selectedGroup.equalsIgnoreCase("Zone"))
	{
		session.setAttribute("Source","Zone"); // for eg help
		List v_siteList = compUtil.getUserZones();
		if(v_siteList!=null && v_siteList.size()>0)
		{
			v_site.addAll(v_siteList);
		}
		if(!v_site.contains("--Default--"))
			v_site.insertElementAt("--Default--",0);
		s_site = request.getParameter("er_site");
		if(treeParam!=null && treeParam.length() >0)
		{
			s_site = treeParam;
		}
		if(s_site != null) 
		{
			temp_component =  new Vector(compUtil.getTypeModifyComponents(compUtil.getZoneComponents(s_site,true),2));
			for(int i=0;i<temp_component.size();i++)
			{
				String temp = (String)temp_component.get(i);
				String tempStr = temp.substring(0,temp.lastIndexOf(COLON));
				String compName = temp.substring(temp.indexOf(COLON)+1,temp.lastIndexOf(COLON));
				if(compName.indexOf(COLON)>-1)
				{
					tempStr = tempStr.substring(0,tempStr.lastIndexOf(COLON));
					if(!unique_component.contains(tempStr))
					{
						unique_component.add(tempStr);
						v_component.add(temp);
					}
				}
				else
				{
					if(!unique_component.contains(tempStr))
					{
						unique_component.add(tempStr);
						v_component.add(temp);
					}
				}
			}
		}
	}
	else if(selectedGroup!=null && selectedGroup.equalsIgnoreCase("Service"))
	{
		session.setAttribute("Source","Service"); // for eg help
		v_site = compUtil.getUserServices(true);
		s_site = request.getParameter("er_site");
		if(treeParam!=null && treeParam.length() >0)
		{
			s_site = treeParam;
		}
		if(s_site != null) 
		{
			temp_component = compUtil.getTypeModifyComponents(compUtil.getServiceComponents(s_site),2);
			for(int i=0;i<temp_component.size();i++)
			{
				String temp = (String)temp_component.get(i);
				String tempStr = temp.substring(0,temp.lastIndexOf(COLON));
				String compName = temp.substring(temp.indexOf(COLON)+1,temp.lastIndexOf(COLON));
				if(compName.indexOf(COLON)>-1)
				{
					tempStr = tempStr.substring(0,tempStr.lastIndexOf(COLON));
					if(!unique_component.contains(tempStr))
					{
						unique_component.add(tempStr);
						v_component.add(temp);
					}
				}
				else
				{
					if(!unique_component.contains(tempStr))
					{
						unique_component.add(tempStr);
						v_component.add(temp);
					}
				}
			}
		}
	}
	else if(selectedGroup!=null && selectedGroup.equals("Segment"))
	{
		session.setAttribute("Source","Segment"); // for eg help
		v_site = compUtil.getUserSegments();
		s_site = request.getParameter("er_site");
		if(treeParam!=null && treeParam.length() >0)
		{
			s_site = treeParam;
		}
		if(s_site != null) {
			temp_component = compUtil.getTypeModifyComponents(compUtil.getSegmentComponents(s_site),2);
			for(int i=0;i<temp_component.size();i++)
			{
				String temp = (String)temp_component.get(i);
				String tempStr = temp.substring(0,temp.lastIndexOf(COLON));
				String compName = temp.substring(temp.indexOf(COLON)+1,temp.lastIndexOf(COLON));
				if(compName.indexOf(COLON)>-1)
				{
					tempStr = tempStr.substring(0,tempStr.lastIndexOf(COLON));
					if(!unique_component.contains(tempStr))
					{
						unique_component.add(tempStr);
						v_component.add(temp);
					}
				}
				else
				{
					if(!unique_component.contains(tempStr))
					{
						unique_component.add(tempStr);
						v_component.add(temp);
					}
				}
			}
		}
	}
	else if(selectedGroup!=null && selectedGroup.equals("Component"))
	{
		boolean relevant = false;
		String str_token="";
		String s_tmp = "";
		String server_type = "";
		session.setAttribute("Source","Component"); // for eg help
		temp_component = compUtil.getAllUserComponents1();
		List compTypes = compUtil.getAllComponentType();
		Vector v_compt = new Vector();
		List aSpecificTest = new ArrayList();
		List AggMeasureList = new ArrayList();
		for(int i=0;i<measureList.size();i++)
		{
			String iniKey=(String)measureList.get(i);
			String testData = reportInfo.getValue("SYSTEM_CAPACITY",iniKey);
			StringTokenizer strtok = new StringTokenizer(testData, ",");
			while(strtok.hasMoreTokens())
			{
				String test = strtok.nextToken();
				aSpecificTest.add(test);
			}
		}

		String aggMeasureOrder = reportInfo.getValue("SYSTEM_CAPACITY", "AggMeasureOrder");
		StringTokenizer aggMeasureOrderToken = new StringTokenizer(aggMeasureOrder, ",");
		while(aggMeasureOrderToken.hasMoreTokens())
		{
			String measure = aggMeasureOrderToken.nextToken();
			AggMeasureList.add(measure);
		}
		for(int i=0;i<AggMeasureList.size();i++)
		{
			String iniKey=(String)AggMeasureList.get(i);
			String testData = reportInfo.getValue("SYSTEM_CAPACITY",iniKey);
			StringTokenizer strtok = new StringTokenizer(testData, ",");
			while(strtok.hasMoreTokens())
			{
				String test = strtok.nextToken();
				aSpecificTest.add(test);
			}
		}

		String SeparateTest = "";
		for(int j=0; j< compTypes.size(); j++)
		{
			server_type = (String)compTypes.get(j);
			relevant = false;
			if(aSpecificTest != null && aSpecificTest.size() > 0)
			{
				for(int k =0;k<aSpecificTest.size();k++)
				{
					SeparateTest=(String)aSpecificTest.get(k);
					if(SeparateTest == null || SeparateTest.indexOf(":")==-1)
						continue;
					SeparateTest = SeparateTest.substring(0,SeparateTest.indexOf(":"));
					if(specsInfo.isTestRelevantForServer(server_type,SeparateTest,false))
					{
						relevant = true;
						break;
					}
				}
			}
			if(relevant)
			{
				v_compt.add(server_type);
			}
		}
		compTypes= new ArrayList();
		if(v_compt!=null && v_compt.size() > 0)
		{
			compTypes.addAll(v_compt);
		}
		else
		{
			compTypes = compUtil.getAllComponentType();
		}
		if(compTypes.size() > 0)
		{
			v_comptype.addAll(compTypes);
			/*List rList = new ArrayList();
			for(int j=0; j< v_comptype.size(); j++)
			{
				String tempStr = (String)v_comptype.get(j);
				if(tempStr.startsWith("Agg_"))
					rList.add(tempStr);
			}
			v_comptype.removeAll(rList);*/
			v_comptype.remove("Host_system");
			if(s_comptype == null)
				s_comptype = (String)v_comptype.get(0);
			if(s_comptype != null && !s_comptype.equals("-1") && !s_comptype.equals("NotApplicable") && v_comptype.contains(s_comptype)) 
			{
				List removeList = new ArrayList();
				for(int i=0; i<temp_component.size(); i++) 
				{
					String v_comp = (String)temp_component.get(i);
					String temp = v_comp.substring(v_comp.lastIndexOf(":")+1);
					//if(!(temp.equals(s_comptype)) || temp.startsWith("Agg_")) 
					if(!(temp.equals(s_comptype)))
					{
						removeList.add(v_comp);
					}
				}
				temp_component.removeAll(removeList);
				for(int i=0;i<temp_component.size();i++)
				{
					String tempComp = (String) temp_component.get(i);
					String componentName = tempComp.substring(0,tempComp.indexOf(":"));
					if(!v_componentName.contains(componentName))
					{
						v_componentName.add(componentName);
						v_component.add(tempComp);
					}
				}
			}
			else
			{
				v_component = new Vector();
			}
		}
	}
	String dispCsvStartDate = s_st_time+" "+s_st_hr+COLON+strmin;
	String dispCsvEndDate = s_en_time+" "+s_en_hr+COLON+enmin;

	String confirmation = reportInfo.getValue("BACKGROUND_PROCESS","NeedConfirmation");
	String strbgrepportName = reportInfo.getValue("BACKGROUND_PROCESS","EnableBackgroundReport");
	String limitforbg = reportInfo.getValue("BACKGROUND_PROCESS","MinDurationForReport");
	status = (String)request.getAttribute("status");
	
	String startDateTime = "";
	String endDateTime = "";
	long msecsPerHour = (long) 1000 * 60 * 60;

	if(er_timeline == null)
	{
		er_timeline="1 week";
	}

	List selectedCompList = new ArrayList();
	if(selectedCompArray != null) 
	{
		for (int i = 0; i < selectedCompArray.length; i++) 
		{
			try 
			{
				selectedCompList.add(EgURLDecoder.decode(selectedCompArray[i], UTF_8));
			}
			catch (Exception e1) {}
		}
	}
	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();
			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"))
			{//weeks
				value *= (7 * 24 * 3600);
			}
			else if (unit.startsWith("mo"))
			{//months
				java.util.Date dt_temp = egDt.egetRealDate();
				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"))
			{
				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);
			}
		}
		if ((startDateTime != null) && (endDateTime != null))
		{
			s_inidate="MM/dd/yyyy";
			try
			{
				int shr=Integer.parseInt(startDateTime.substring(startDateTime.indexOf(DateTimeTokenizer.BLANK_SPACE)+1, startDateTime.indexOf(COLON)));
				strmin=startDateTime.substring(startDateTime.indexOf(COLON)+1);
				int en_hr=Integer.parseInt(endDateTime.substring(endDateTime.indexOf(DateTimeTokenizer.BLANK_SPACE)+1, endDateTime.indexOf(COLON)));
				enmin=endDateTime.substring(endDateTime.indexOf(COLON)+1);
				s_en_time=endDateTime.substring(0, endDateTime.indexOf(DateTimeTokenizer.BLANK_SPACE));
				s_st_time=startDateTime.substring(0, startDateTime.indexOf(DateTimeTokenizer.BLANK_SPACE));
				s_st_hr = String.valueOf(shr);
				s_en_hr = String.valueOf(en_hr);
			}
			catch(Exception e)
			{
				System.out.println("Eception caught :"+e);
				e.printStackTrace();
			}
		}
	}
	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;
			s_inidate="MM/dd/yyyy";
		}
		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;
		}
	}
	if(er_type == null) {
		er_type="Yes";
	}
	boolean isServiceChange = false;
	
	if(request.getParameter("isServiceChange") != null && request.getParameter("isServiceChange").equalsIgnoreCase("true")) {
		isServiceChange = true;
	}
	boolean noDataFound = true;
	Map resultMap = (Map) session.getAttribute("SYSTEM_CAPACITY_REPORT");
	/** For Save CSV Data Format */
	List list = new LinkedList();		//Add List of Data
	Vector v_measure_csv = new Vector();	//User ColumnName
	List list_data = new LinkedList();	//ColumnData
	Hashtable h_tabrc = new Hashtable();	//SubTable Data
	Hashtable h_tab = new Hashtable();	//SunTitle with SubTable Data
	String s_title = "";

	if(resultMap != null && isSubmit != null && isSubmit.equalsIgnoreCase("true"))
	{
		Boolean noData = ((Boolean) resultMap.get("NO_DATA_FOUND"));
		if(noData != null)
			noDataFound = noData.booleanValue();
	}
	/*boolean isDescriptorAvailable = false;
	if(resultMap != null && isSubmit != null && isSubmit.equalsIgnoreCase("true"))
	{
		Boolean descData = ((Boolean) resultMap.get("DESCRIPTOR_AVAILABLE"));
		if(descData != null)
			isDescriptorAvailable = descData.booleanValue();
	}*/
	String excludeweekend = request.getParameter("er_excwe");
	if (excludeweekend == null || excludeweekend.equals("")) {
		excludeweekend = "Yes";
	}
	String Days = (erh.getExcludeWeekends("EXCLUDE_WEEKEND","Days") == null) ?
			"Saturday,Sunday" : erh.getExcludeWeekends("EXCLUDE_WEEKEND","Days");
	
	Vector v_time = new Vector();
	v_time.add("00");
	v_time.add("01");
	v_time.add("02");
	v_time.add("03");
	v_time.add("04");
	v_time.add("05");
	v_time.add("06");
	v_time.add("07");
	v_time.add("08");
	v_time.add("09");
	v_time.add("10");
	v_time.add("11");
	v_time.add("12");
	v_time.add("13");
	v_time.add("14");
	v_time.add("15");
	v_time.add("16");
	v_time.add("17");
	v_time.add("18");
	v_time.add("19");
	v_time.add("20");
	v_time.add("21");
	v_time.add("22");
	v_time.add("23");

	Vector v_min = new Vector();
	v_min.add("00");
	v_min.add("05");
	v_min.add("10");
	v_min.add("15");
	v_min.add("20");
	v_min.add("25");
	v_min.add("30");
	v_min.add("35");
	v_min.add("40");
	v_min.add("45");
	v_min.add("50");
	v_min.add("55");
	v_min.add("59");

	String timefrom="";
	String minfrom="";
	String timeto="";
	String minto="";
	String timefrom1=(erh.getTimeFrame("TIMEFRAME","From")==null) ? "00:00" :erh.getTimeFrame("TIMEFRAME","From");
	String timeto1=(erh.getTimeFrame("TIMEFRAME","To")==null) ? "23:59" :erh.getTimeFrame("TIMEFRAME","To");
	timefrom1 = reportInfo.getValue("SYSTEM_CAPACITY","startTime");
	timeto1 = reportInfo.getValue("SYSTEM_CAPACITY","endTime");
	StringTokenizer st;
	if(timefrom1 != null)
	{
		st = new StringTokenizer(timefrom1,":");
		if(st.hasMoreTokens())
		{
			timefrom=st.nextToken();
			minfrom=st.nextToken();
		}
	}
	if(timeto1 != null)
	{
		st=new StringTokenizer(timeto1,":");
		if(st.hasMoreTokens())
		{
			timeto=st.nextToken();
			minto=st.nextToken();
		}
	}
	String timefrom2 = request.getParameter("timefrom");
	String minfrom2 = request.getParameter("minfrom");
	String timeto2 = request.getParameter("timeto");
	String minto2 = request.getParameter("minto");
	String stmin = "00";

	if (timefrom2!=null)
		timefrom = timefrom2;
	if (minfrom2!=null)
		minfrom = minfrom2;
	if (timeto2!=null)
		timeto = timeto2;
	if (minto2!=null)
		minto = minto2;

	session.setAttribute("PDF_URL", mngrIProc+"/final/reporter/ErSystemCapacityReportPrint.jsp");

	//json = new JSONObject();
	JSONObject pageParams = new JSONObject();
	JSONObject hiddenParams = new JSONObject();
	JSONObject screenLabels = new JSONObject();

	hiddenParams.put("er_trenddata","Yes");
	hiddenParams.put("getMaxDaysInMonth",String.valueOf(ErUtils.getMaxDaysInMonth()));
	hiddenParams.put("fromSchedule",reqFromSchedule);
	hiddenParams.put("bgenabled",strbgrepportName);
//	hiddenParams.put("forwardto","ErSystemCapacityReport");
	hiddenParams.put("isServiceChange","false");
	hiddenParams.put("er_type",er_type);
	hiddenParams.put("er_rtype","Capacity Planning");
	hiddenParams.put("er_trgttype","System");
//	hiddenParams.put("isFavorite","false");
	hiddenParams.put("inidate",currentDateFormat);
	hiddenParams.put("select_group",selectedGroup);
	//hiddenParams.put("isSchedule","false");
	hiddenParams.put("schedule_id",schedule_id);
	hiddenParams.put("limitforbg",limitforbg);
	hiddenParams.put("savereport","save");
	hiddenParams.put("savereport","save");
	hiddenParams.put("er_bgreportfrom","CapacityPlanning_System");
	hiddenParams.put("eruserid",userid);
	hiddenParams.put("er_ViewName","ErSystemCapacityReport.jsp");
	if(fromScheduleModify!=null)
		hiddenParams.put("fromScheduleModify",fromScheduleModify);
	else
		hiddenParams.put("fromScheduleModify","null");
	if(fromFavoriteModify!=null)
		hiddenParams.put("fromFavoriteModify",fromFavoriteModify);
	else
		hiddenParams.put("fromFavoriteModify","null");
	hiddenParams.put("favorite_id", favorite_id);
	hiddenParams.put("er_favorite", er_favorite);
	
	if(measureList.size()>3)
	{
		pageWidthProces = (measureList.size()*300)+50;
	}
	hiddenParams.put("pageWidthProces", pageWidthProces+"");
	
%>
	<%@  include file ="ErTimeFormatJSON.jsp"%> 
<%
	hiddenParams.put("er_usertimeline",strUsrTimeline);
	String action = request.getParameter("action");
	if(action!=null && action.equals("changeComponent"))
	{
		//er_component
		JSONArray componentList = new JSONArray();
		if(v_component.size() == 0)
		{
			v_comp_popup.add("-1");
			v_comp_popup_disp.add("Not Applicable");
			JSONObject jObj = new JSONObject();
			jObj.put("displayField",intlmap.getTextDescription("reporter.common.Not Applicable"));
			jObj.put("valueField","-1");
			componentList.add(jObj);
			pageParams.put("selectedComps","-1");
		}
		else
		{
			Collections.sort(v_component,String.CASE_INSENSITIVE_ORDER);
			String tempComponent = (String) v_component.get(0);
			StringBuffer sbSelectedValues= new StringBuffer();
			for( int i=0; i<v_component.size(); i++)
			{
				String s=(String)v_component.get(i);
				String strcompname = "";
				strcompname = s.substring(0,s.indexOf(COLON));
				if(selectedCompList.size() == 0 || selectedCompList.contains("-1") || selectedCompList.contains(v_component.get(i)))
				{
					sbSelectedValues.append(","+s);
				}
				v_comp_popup.add(s);
				v_comp_popup_disp.add(strcompname);
				JSONObject jObj = new JSONObject();
				jObj.put("displayField",strcompname);
				jObj.put("valueField",s);
				componentList.add(jObj);
			}
			if(sbSelectedValues!=null)
			{
				String selectedComps = sbSelectedValues.toString();
				if(selectedComps!=null && (selectedComps.length()>0 && selectedComps.indexOf(",")==0))
					selectedComps = selectedComps.substring(1);

				pageParams.put("selectedComps",selectedComps);
			}
		}
		json.put("pageParams",pageParams);
		json.put("hiddenParams",hiddenParams);
		json.put("componentList",componentList);
		response.setContentType("application/json;charset=UTF-8");
		response.getWriter().write(json.toString());
	}
	else
	{
		String strWidth = "90%";
		if(backreqMap == null || backreqMap != null && backreqMap.size() == 0)
			strWidth="100%";

		String timePeriodLbl = intlmap.getTextDescription("reporter.common.Time Period");
		String timeLineLbl = intlmap.getTextDescription("reporter.common.Timeline");
		String fromLbl = intlmap.getTextDescription("reporter.common.From");
		String toLbl = intlmap.getTextDescription("reporter.common.To");
		String compLbl = intlmap.getTextDescription("reporter.capacity.Component");
		String systemLbl = intlmap.getTextDescription("reporter.capacity.System");

		screenLabels.put("reporter.common.SYSTEM CAPACITY REPORT",intlmap.getTextDescription("reporter.common.SYSTEM CAPACITY REPORT"));
		screenLabels.put("reporter.common.Back",intlmap.getTextDescription("reporter.common.Back"));
		screenLabels.put("reporter.common.SAVE",intlmap.getTextDescription("reporter.common.SAVE"));
		screenLabels.put("reporter.common.PRINT",intlmap.getTextDescription("reporter.common.PRINT"));
		screenLabels.put("reporter.common.MAIL",intlmap.getTextDescription("reporter.common.MAIL"));
		screenLabels.put("reporter.capacity.Component Type",intlmap.getTextDescription("reporter.capacity.Component Type"));
		screenLabels.put("reporter.common.Not Applicable",intlmap.getTextDescription("reporter.common.Not Applicable"));
		screenLabels.put("reporter.capacity.Component",compLbl);
		screenLabels.put("reporter.common.Time period",timePeriodLbl);
		screenLabels.put("reporter.common.From",fromLbl);
		screenLabels.put("reporter.common.To",toLbl);
		screenLabels.put("reporter.common.Hrs",intlmap.getTextDescription("reporter.common.Hrs"));
		screenLabels.put("reporter.common.Mins",intlmap.getTextDescription("reporter.common.Mins"));
		screenLabels.put("reporter.common.Timeline",timeLineLbl);
		screenLabels.put("reporter.common.Report Generation",intlmap.getTextDescription("reporter.common.Report Generation"));
		screenLabels.put("reporter.common.Exclude weekends",intlmap.getTextDescription("reporter.common.Exclude weekends"));
		screenLabels.put("reporter.common.Report Name",intlmap.getTextDescription("reporter.common.Report Name"));
		screenLabels.put("reporter.common.Report Type",intlmap.getTextDescription("reporter.common.Report Type"));
		screenLabels.put("reporter.common.Excludes",intlmap.getTextDescription("reporter.common.Excludes")+" "+intlmap.getTextDescription("reporter.common."+Days));

		String fromFavSch = request.getParameter("fromFavSch");
		if(backreqMap != null && backreqMap.size() > 0 &&  enableBack && request.getParameter("enableBack")!=null && request.getParameter("enableBack").equalsIgnoreCase("true") || (fromFavSch!=null && fromFavSch.equalsIgnoreCase("true")))
		{
			json.put("ID","backQnumber="+erhelputils.getBackID()+"&"+erhelputils.getQueryString());
		}
		queryString = request.getQueryString();
		String selected = "";
		if(selectedGroup!=null && (selectedGroup.equalsIgnoreCase("Service") || selectedGroup.equalsIgnoreCase("Segment")|| selectedGroup.equalsIgnoreCase("Zone")))
		{
			pageParams.put("selectedGroup",selectedGroup);
			screenLabels.put("selectedGroup",intlmap.getTextDescription("reporter.common."+selectedGroup));
			JSONArray selectedGrpList = new JSONArray();
			if(v_site.size() == 0)
			{
				JSONObject jObj = new JSONObject();
				jObj.put("displayField",intlmap.getTextDescription("reporter.common.Not Applicable"));
				jObj.put("valueField","-1");
				selectedGrpList.add(jObj);
				pageParams.put("selectedGroupValue","-1");
			}
			else
			{
				Collections.sort(v_site,String.CASE_INSENSITIVE_ORDER);
				String tempService = (String) v_site.get(0);

				JSONObject jObj = new JSONObject();
				jObj.put("displayField",intlmap.getTextDescription("reporter.capacity.Please select a "+selectedGroup));
				jObj.put("valueField","-1");
				selectedGrpList.add(jObj);
				if(v_site==null || v_site.size()==0)
				{
					pageParams.put("selectedGroupValue","-1");
				}
				for( int i=0; i<v_site.size(); i++)
				{
					String grpValue = (String)v_site.get(i);
					jObj = new JSONObject();
					jObj.put("displayField",grpValue);
					jObj.put("valueField",grpValue);
					selectedGrpList.add(jObj);
					if(s_site != null)
					{
						if(s_site.equalsIgnoreCase(grpValue))
							pageParams.put("selectedGroupValue",grpValue);
					}
					else
					{
						if(tempService.equalsIgnoreCase(grpValue))
							pageParams.put("selectedGroupValue",grpValue);
					}
				}
			}
			json.put("selectedGrpList",selectedGrpList);
		}
		else if(selectedGroup!=null && selectedGroup.equalsIgnoreCase("Component"))
		{
			pageParams.put("selectedGroup",selectedGroup);
			screenLabels.put("selectedGroup",intlmap.getTextDescription("reporter.common."+selectedGroup));
			//er_comptype
			JSONArray componentTypeList = new JSONArray();
			selected = "";
			if(v_comptype.size() == 0)
			{
				JSONObject jObj = new JSONObject();
				jObj.put("displayField",intlmap.getTextDescription("reporter.common.Not Applicable"));
				jObj.put("valueField","-1");
				componentTypeList.add(jObj);
				pageParams.put("selectedCompType","-1");
			}
			else
			{
				Collections.sort(v_comptype,String.CASE_INSENSITIVE_ORDER);
				String defaultOption = "";
				if(s_comptype == null)
				{
					pageParams.put("selectedCompType","-1");
				}
				JSONObject jObj = new JSONObject();
				jObj.put("displayField",intlmap.getTextDescription("reporter.common.Please choose a Component Type"));
				jObj.put("valueField","-1");
				componentTypeList.add(jObj);

				//v_comptype=compUtil.getIntnlSupportCompType(v_comptype,"#");
			
				ArrayList sortedNameList1 = new ArrayList();
				sortedNameList1 = sorter.getSortedCompTypeList(v_comptype);
				for(int n=0;n<sortedNameList1.size();n++)
				{
					EgName nameObj =(EgName) sortedNameList1.get(n);
					String dispValue = nameObj.getLocalName();
					String sCompType = nameObj.getActualName();
					//String s=(String)v_comptype.get(n);
					//ArrayList aListData = tokInfo.egTokenizer(s,"#");
			        //String CompTypeDisp=(String)aListData.get(0);
					//String CompTypeValue=(String)aListData.get(1);

					jObj = new JSONObject();
					jObj.put("displayField",dispValue);
					jObj.put("valueField",sCompType);
					componentTypeList.add(jObj);

					if(s_comptype != null)
					{
						if(s_comptype.equalsIgnoreCase(sCompType))
							pageParams.put("selectedCompType",sCompType);
					}
				}
			}
			json.put("componentTypeList",componentTypeList);
			//er_component
			JSONArray componentList = new JSONArray();
			selected = "";
			if(v_component.size() == 0)
			{
				v_comp_popup.add("-1");
				v_comp_popup_disp.add("Not Applicable");
				JSONObject jObj = new JSONObject();
				jObj.put("displayField",intlmap.getTextDescription("reporter.common.Not Applicable"));
				jObj.put("valueField","-1");
				componentList.add(jObj);
				pageParams.put("selectedComps","-1");
			}
			else
			{
				Collections.sort(v_component,String.CASE_INSENSITIVE_ORDER);
				String tempComponent = (String) v_component.get(0);
				StringBuffer sbSelectedValues= new StringBuffer();
				for( int i=0; i<v_component.size(); i++)
				{
					String s=(String)v_component.get(i);
					String strcompname = "";
					strcompname = s.substring(0,s.indexOf(COLON));
					if(selectedCompList.size() == 0 || selectedCompList.contains("-1") || selectedCompList.contains(v_component.get(i)))
					{
						sbSelectedValues.append(","+s);
					}
					v_comp_popup.add(s);
					v_comp_popup_disp.add(strcompname);
					JSONObject jObj = new JSONObject();
					jObj.put("displayField",strcompname);
					jObj.put("valueField",s);
					componentList.add(jObj);
				}
				if(sbSelectedValues!=null)
				{
					String selectedComps = sbSelectedValues.toString();
					if(selectedComps!=null && (selectedComps.length()>0 && selectedComps.indexOf(",")==0))
						selectedComps = selectedComps.substring(1);

					pageParams.put("selectedComps",selectedComps);
				}
			}
			json.put("componentList",componentList);
		}
		JSONArray yesNoOpts = new JSONArray();
		JSONObject yesOpt = new JSONObject();
		yesOpt.put("displayField",intlmap.getTextDescription("reporter.common.Yes")+" ("+Days+") ");
		yesOpt.put("valueField","Yes");
		yesNoOpts.add(yesOpt);
		JSONObject noOpt = new JSONObject();
		noOpt.put("displayField",intlmap.getTextDescription("reporter.common.No"));
		noOpt.put("valueField","No");
		yesNoOpts.add(noOpt);

		json.put("yesNoOpts",yesNoOpts);

		if (!StringUtils.isNull(titleToDisplay)){ 
			list.add(titleToDisplay);
		}
		else
		{
			list.add(intlmap.getTextDescription("reporter.common.SYSTEM CAPACITY REPORT"));
		}
		if(excludeweekend.equalsIgnoreCase("Yes") )
		{
			list.add('"'+timePeriodLbl+":"+fromLbl+" "+request.getParameter("timefrom")+":"+request.getParameter("minfrom")+intlmap.getTextDescription("reporter.common.Hrs")+" "+toLbl+" "+request.getParameter("timeto")+":"+request.getParameter("minto")+intlmap.getTextDescription("reporter.common.Hrs")+'"'+","+'"'+intlmap.getTextDescription("reporter.common.Exclude weekends")+":"+Days+'"');
		}
		else
		{
			list.add(timePeriodLbl+":"+fromLbl+" "+request.getParameter("timefrom")+":"+request.getParameter("minfrom")+intlmap.getTextDescription("reporter.common.Hrs")+" "+toLbl+" "+request.getParameter("timeto")+":"+request.getParameter("minto")+intlmap.getTextDescription("reporter.common.Hrs"));
		}
		json.put("timelineComboArray",timelineComboArray);
		pageParams.put("startDateJSON",startDateJSON);
		pageParams.put("endDateJSON",endDateJSON);
		pageParams.put("startHourJSON",startHourJSON);
		pageParams.put("endHourJSON",endHourJSON);

		pageParams.put("startDateForDisplay",startDateForDisplay);
		pageParams.put("startHourForDisplay",startHourForDisplay);
		pageParams.put("startMinForDisplay",startMinForDisplay);
		pageParams.put("endDateForDisplay",endDateForDisplay);
		pageParams.put("endHourForDisplay",endHourForDisplay);
		pageParams.put("endMinForDisplay",endMinForDisplay);

		pageParams.put("startmin",startMin);
		pageParams.put("endmin",endMin);
		pageParams.put("timefrom",timefrom);
		pageParams.put("minfrom",minfrom);
		pageParams.put("timeto",timeto);
		pageParams.put("minto",minto);

		pageParams.put("selectedTimeline",er_timeline);
		String er_reportgenration = request.getParameter("er_reportgenration");
		if (er_reportgenration != null && er_reportgenration.equals("background"))
		{
			pageParams.put("er_reportgenration","background");
		}
		else if (er_reportgenration != null && er_reportgenration.equals("background-csv"))
		{
			pageParams.put("er_reportgenration","background-csv");
		}
		else
		{
			pageParams.put("er_reportgenration","foreground");
		}
		String bg_reportname = request.getParameter("bg_reportname");
		if(bg_reportname == null)
		{
			bg_reportname = "";
		}
		JSONArray repGenOpts= new JSONArray();
		JSONObject bgOpt = new JSONObject();
		bgOpt.put("displayField",strbackground);
		bgOpt.put("valueField","background");
		repGenOpts.add(bgOpt);
		if(!er_type.equalsIgnoreCase("Yes"))
		{
			bgOpt = new JSONObject();
			//bgOpt.put("displayField","Background Save - CSV");
			bgOpt.put("displayField",intlmap.getTextDescription("reporter.common.Background Save")+" - "+  intlmap.getTextDescription("reporter.common.CSV"));
			bgOpt.put("valueField","background-csv");
			repGenOpts.add(bgOpt);
		}		
		bgOpt = new JSONObject();
		bgOpt.put("displayField",strforeground);
		bgOpt.put("valueField","foreground");
		repGenOpts.add(bgOpt);
		json.put("repGenOpts",repGenOpts);

		pageParams.put("bg_reportname",bg_reportname);

		if(reqFromSchedule!=null && reqFromSchedule.equalsIgnoreCase("Yes"))
		{
			screenLabels.put("selectSubmitBtnLbl",intlmap.getTextDescription("reporter.common.SAVE"));
		}
		else
		{
			screenLabels.put("selectSubmitBtnLbl",intlmap.getTextDescription("reporter.common.SUBMIT"));
		}
		String heading1="",title="";
		if(s_site!=null)
		{
			heading1 = intlmap.getTextDescription("reporter.common.Service ")+ " - " + s_site;
		    title="Service";
		}
		if(selectedGroup!=null && selectedGroup.equalsIgnoreCase("Component")) {
			if(s_comptype!=null)
			{
				heading1 = intlmap.getTextDescription("reporter.common.Component Type ")+" - " + intlmap.getComponentTypeDescription(s_comptype);
				 title=" Component Type";
			}
		}
		else if(selectedGroup!=null && selectedGroup.equalsIgnoreCase("Segment")) {
			if(s_site!=null)
			{
				heading1 = intlmap.getTextDescription("reporter.common.Segment") +" - " + s_site;
				 title="Segment";
			}
		}
		else if(selectedGroup!=null && selectedGroup.equalsIgnoreCase("Zone")) {
			if(s_site!=null)
			{
				heading1 = intlmap.getTextDescription("reporter.common.Zone")+" - " + s_site;
				 title="Zone";
			}
		}
		String sDateForDisplay=startDateForDisplay+" "+startHourForDisplay+":"+startMinForDisplay;
		String eDateForDisplay=endDateForDisplay+" "+endHourForDisplay+":"+endMinForDisplay;

		screenLabels.put("selectionDetailsTitle",title);
		JSONObject selDetailsJson = new JSONObject();
		String s_reportType="";		
		if(er_type!=null && er_type.equals("Yes")) {
			s_reportType=intlmap.getTextDescription("reporter.common.Graph");
		} else {
			s_reportType=intlmap.getTextDescription("reporter.common.Data");
		}
		selDetailsJson.put(intlmap.getTextDescription("reporter.common.Report Type"), s_reportType);
		selDetailsJson.put(intlmap.getTextDescription("reporter.cpacity.Analyze by"),heading1);
		selDetailsJson.put(intlmap.getTextDescription("reporter.cpacity.Exclude weekends"),intlmap.getTextDescription("reporter.common."+excludeweekend));
		selDetailsJson.put(timePeriodLbl,excludeweekend);
		selDetailsJson.put(timePeriodLbl,"<span class='font_bold'> </span> "+timefrom+":"+minfrom+"   "+"<span class='font_bold'>"+ intlmap.getTextDescription("reporter.common.to") +"</span> "+timeto+":"+minto);
		selDetailsJson.put(timeLineLbl,"<span class='font_bold'> </span> "+sDateForDisplay+" " + intlmap.getTextDescription("reporter.common.hrs")+"  "+"<span class='font_bold'>"+ intlmap.getTextDescription("reporter.common.to") +"</span>  "+eDateForDisplay + " " + intlmap.getTextDescription("reporter.common.hrs"));		
		json.put("selDetailsJson",selDetailsJson);
		JSONArray gTypeArr = new JSONArray();
		JSONObject gTypeObj = new JSONObject();
		gTypeObj.put("displayField", intlmap.getTextDescription("reporter.common.Graph"));
		gTypeObj.put("valueField", "Yes");
		gTypeArr.add(gTypeObj);
		
		gTypeObj = new JSONObject();
		gTypeObj.put("displayField", intlmap.getTextDescription("reporter.common.Data"));
		gTypeObj.put("valueField", "No");

		gTypeArr.add(gTypeObj);

		json.put("gTypeArr", gTypeArr);
		if (er_reportgenration != null && (er_reportgenration.equals("background") || er_reportgenration.equals("background-csv")))
		{
			if(bggroundStr != null && !bggroundStr.equals(""))
			{
				isBackgroundProcess = true;
				String strReportName="CapacityPlanning_System";
				if(status != null && (status.equalsIgnoreCase("duplicate") || status.equalsIgnoreCase("exceedLimit")))
				{
					strReportName="All Report Types";
				}
				pageParams.put("bggroundStr",bggroundStr);
				pageParams.put("status",status);
				if(status != null && !status.equalsIgnoreCase("exceedLimit"))
				{
					pageParams.put("bgRrtMsg",erbgreport.getlangsupportedString(bggroundStr,bgString,urs));
				}
				else
				{
					pageParams.put("bgRrtMsg",bggroundStr);
				}
				if(strReportName!=null && strReportName.indexOf(" ") > -1)
				{
					strReportName = com.eg.EgURLEncoder.encode(strReportName, "UTF-8");
				}
				pageParams.put("bgRrtUrl","/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");
				pageParams.put("bgRptLinkMsg",intlmap.getTextDescription("reporter.common.Click here to see a list of generated and processing reports"));
				json.put("dataAvailable","true");
			}
			else
			{
				json.put("dataAvailable","false");
			}
		}
		else 
		{
			if(isSubmit != null && isSubmit.equalsIgnoreCase("true"))
			{
				String heading = "";
				if(s_site!=null)
					heading = intlmap.getTextDescription("reporter.common.Service")+" - " + s_site;
				if(selectedGroup.equalsIgnoreCase("Component")) {
					if(s_comptype!=null)
						heading = intlmap.getTextDescription("reporter.common.Component Type")+" - " + intlmap.getComponentTypeDescription(s_comptype);
				} else if(selectedGroup.equalsIgnoreCase("Segment")) {
					if(s_site!=null)
						heading = " Segment - " + s_site;
				} else if(selectedGroup.equalsIgnoreCase("Zone")) {
					if(s_site!=null)
						heading = intlmap.getTextDescription("reporter.common.Zone")+" - " + s_site;
				}

				// Added for csv
				Vector v_date = new Vector();
				v_date.add("\""+intlmap.getTextDescription("reporter.common.Start Date")+" : "+sDateForDisplay+"\"");
				v_date.add("\""+intlmap.getTextDescription("reporter.common.End Date")+" : "+eDateForDisplay+"\"");
				
				s_title = "";
				list.add(v_date);
				list.add(intlmap.getTextDescription("reporter.common.System Capacity Report") + " - "+heading);
				// added for csv ends
				
				String cpuUtilization = null;
				String freeMemoryAvailable = null;
				String diskspaceUsage = null;
				String diskBusy = null;
				String networkAvailability = null;
				Vector v_test = new Vector();
				Map measureNameMap = new HashMap();
				Map measureCheckMap = new HashMap();
				Map testMeasureKeyMap = new HashMap();

				// added for csv starts
				list_data = new LinkedList();
				v_measure_csv = new Vector();
				h_tabrc = new Hashtable();
				h_tab = new Hashtable();
				v_measure_csv.add(intlmap.getTextDescription("reporter.capacity.Component"));
				String systemTest = "SystemTest";
				boolean isSummaryOnly = false;
				String summaryOnly = reportInfo.getValue("SYSTEM_CAPACITY","SummaryOnly");
				if(summaryOnly != null && summaryOnly.equalsIgnoreCase("yes"))
					isSummaryOnly = true;
						

				for(int i=0;i<measureList.size();i++)
				{
					String iniKey=(String)measureList.get(i);
					String testData = reportInfo.getValue("SYSTEM_CAPACITY",iniKey);
					StringTokenizer strtok = new StringTokenizer(testData, ",");
					while(strtok.hasMoreTokens())
					{
						String testAndMeasure = strtok.nextToken();
						String test = testAndMeasure.substring(0, testAndMeasure.indexOf(COLON));
						String testMeasure = testAndMeasure.substring(testAndMeasure.indexOf(COLON)+1);
						String measureUnit  = tablesInfo.getUnitForMeasure(test,testMeasure);
						boolean isSelectedTest = false;
						
						boolean descriptorAvail = false;
						String service = null;
						Vector infos = null;
						for(int j=0; j<v_component.size(); j++)
							{
								String componentType = "";
								String tempCompType = (String)v_component.get(j);
								String selectedComp = tempCompType.substring(0, tempCompType.indexOf(COLON));
								if(!selectedGroup.equalsIgnoreCase("Component"))
								{
									componentType = tempCompType.substring(tempCompType.indexOf(COLON)+1);
									componentType = componentType + COLON + tempCompType.substring(0,tempCompType.indexOf(COLON));
								}
								else
								{
									componentType = tempCompType;
								}
							
								infos = erInfo.getInfosForTest(service,test,componentType);
							
								if(infos.size()>0 && !infos.contains("+"))
								{
									descriptorAvail = true;
									break;
								}
							}
						if(selectedGroup.equalsIgnoreCase("Component"))
						{
							isSelectedTest = specsInfo.isTestRelevantForServer(s_comptype, test, false);
							if(isSelectedTest)
							{
								if(!v_test.contains(testAndMeasure))
								{
									v_test.add(testAndMeasure);
									String measureName = reportInfo.getValue("SYSTEM_CAPACITY", iniKey+"_Title");
									String measure_Check = reportInfo.getValue("SYSTEM_CAPACITY",iniKey+"_Check");
									measureNameMap.put(testAndMeasure, measureName);
									screenLabels.put(iniKey+"_Title",measureName+" ("+measureUnit+")");
									measureCheckMap.put(testAndMeasure,measure_Check);
									testMeasureKeyMap.put(testAndMeasure,iniKey);
									if((isSummaryOnly && systemTest.equalsIgnoreCase(test)) || !descriptorAvail)
									{
										v_measure_csv.add(measureName + " - "+ measureUnit);
										v_measure_csv.add("");
										v_measure_csv.add("");
									}
									else
									{
										v_measure_csv.add(measureName + " - "+ measureUnit);
										v_measure_csv.add("");
										v_measure_csv.add("");
										v_measure_csv.add("");
									}
								}
							}
						}
						else
						{
							for(int j=0; j<v_component.size(); j++)
							{
								String component = (String)v_component.get(j);
								String compType = component.substring(0, component.indexOf(COLON));
								isSelectedTest = specsInfo.isTestRelevantForServer(compType, test, false);
								if(isSelectedTest)
								{
									if(!v_test.contains(testAndMeasure))
									{
										v_test.add(testAndMeasure);
										String measureName = reportInfo.getValue("SYSTEM_CAPACITY", iniKey+"_Title");
										String measure_Check = reportInfo.getValue("SYSTEM_CAPACITY",iniKey+"_Check");
										measureNameMap.put(testAndMeasure, measureName);
										screenLabels.put(iniKey+"_Title",measureName+" ("+measureUnit+")");
										measureCheckMap.put(testAndMeasure,measure_Check);
										testMeasureKeyMap.put(testAndMeasure,iniKey);
										if((isSummaryOnly && systemTest.equalsIgnoreCase(test)) || !descriptorAvail)
										{
											v_measure_csv.add(measureName + " - "+ measureUnit);
											v_measure_csv.add("");
											v_measure_csv.add("");
											
										}
										else
										{
											v_measure_csv.add(measureName + " - "+ measureUnit);
											v_measure_csv.add("");
											v_measure_csv.add("");
											v_measure_csv.add("");
											
										}
										
									}
								}
							}
						}
					}

				}
				if(s_comptype!=null && s_comptype.startsWith("Agg_") && selectedGroup.equalsIgnoreCase("Component"))
				{
					if(selectedGroup.equalsIgnoreCase("Component"))
						v_test = new Vector();
					String aggMeasureOrder = reportInfo.getValue("SYSTEM_CAPACITY", "AggMeasureOrder");
					measureOrderToken = new StringTokenizer(aggMeasureOrder, ",");
					measureList = new ArrayList();
					while(measureOrderToken.hasMoreTokens())
					{
						String measure = measureOrderToken.nextToken();
						measureList.add(measure);
					}
					for(int j=0;j<measureList.size();j++)
					{
						String iniKey=(String)measureList.get(j);
						String testData = reportInfo.getValue("SYSTEM_CAPACITY",iniKey);
						StringTokenizer strtok = new StringTokenizer(testData, ",");
						while(strtok.hasMoreTokens())
						{
							String testAndMeasure = strtok.nextToken();
							String test = testAndMeasure.substring(0, testAndMeasure.indexOf(COLON));
							String testMeasure = testAndMeasure.substring(testAndMeasure.indexOf(COLON)+1);
							String measureUnit  = tablesInfo.getUnitForMeasure(test,testMeasure);
							boolean isSelectedTest = false;
							
							boolean descriptorAvail = false;
							String service = null;
							Vector infos = null;
							for(int jj=0; jj<v_component.size(); jj++)
							{
								String componentType = "";
								String tempCompType = (String)v_component.get(jj);
								String selectedComp = tempCompType.substring(0, tempCompType.indexOf(COLON));
								if(!selectedGroup.equalsIgnoreCase("Component"))
								{
									componentType = tempCompType.substring(tempCompType.indexOf(COLON)+1);
									componentType = componentType + COLON + tempCompType.substring(0,tempCompType.indexOf(COLON));
								}
								else
								{
									componentType = tempCompType;
								}
							
								infos = erInfo.getInfosForTest(service,test,componentType);
							
								if(infos.size()>0 && !infos.contains("+"))
								{
									descriptorAvail = true;
									break;
								}
							}

							if(selectedGroup.equalsIgnoreCase("Component"))
							{
								isSelectedTest = specsInfo.isTestRelevantForServer(s_comptype, test, false);
								if(isSelectedTest)
								{
									String measureTiteleKey = iniKey.substring(3);
									String measureName = reportInfo.getValue("SYSTEM_CAPACITY", measureTiteleKey+"_Title");
									String measure_Check = reportInfo.getValue("SYSTEM_CAPACITY",measureTiteleKey+"_Check");
									String replaceTestName = reportInfo.getValue("SYSTEM_CAPACITY", measureTiteleKey);
									measureNameMap.put(testAndMeasure, measureName);
									screenLabels.put(measureTiteleKey+"_Title",measureName+" ("+measureUnit+")");
									v_test.add(replaceTestName);
									measureCheckMap.put(testAndMeasure,measure_Check);
									testMeasureKeyMap.put(testAndMeasure,measureTiteleKey);
									if((isSummaryOnly && systemTest.equalsIgnoreCase(test)) || !descriptorAvail)
									{
										v_measure_csv.add(measureName + " - "+ measureUnit);
										v_measure_csv.add("");
										v_measure_csv.add("");
									}
									else
									{
										v_measure_csv.add(measureName + " - "+ measureUnit);
										v_measure_csv.add("");
										v_measure_csv.add("");
										v_measure_csv.add("");
									}
								
								}
							}
						}

					}
				}
				int[] percentiles;
				String rhs = "";
				String strPercentile = "";
				//String systemTest = "SystemTest";
				String greaterThan = ">";
				
				Collections.sort(v_component);

				if(!noDataFound)
				{
					json.put("dataAvailable","true");
					String repType = (String)resultMap.get("opt");
					//System.out.println("repType-->"+repType);
					if(repType !=null && repType.equalsIgnoreCase("data"))
					{
						//boolean isSummaryOnly = false;
						list_data.add("");
						boolean descriptorAvail = false;
						Hashtable infoTable  = new Hashtable();

						JSONArray gridData = new JSONArray();
						JSONArray columnDetails = new JSONArray();

						JSONObject cObj = new JSONObject();
						cObj.put("colName","System");
						cObj.put("Measurement","NONE");
						cObj.put("SUB_COLUMNS","0");
						columnDetails.add(cObj);

						int gridColumnCnt = 1;
						List columName = new ArrayList();
						if(v_test.size()>4)
						{
							pageWidthProces = (v_test.size()*300)+50;
						}
						hiddenParams.put("pageWidthProces", pageWidthProces+"");
						for(int i =0; i<v_test.size();i++)
						{
							descriptorAvail = false;
							String temStrTest = (String)v_test.get(i);
							String test = temStrTest.substring(0,temStrTest.indexOf(COLON));
							if(test.indexOf("_")>-1)
							{
								continue;
							}
							String measure = temStrTest.substring(temStrTest.indexOf(COLON)+1);
							String measureUnit = tablesInfo.getUnitForMeasure(test,measure);
							if(measureUnit==null || measureUnit.length()==0)
								measureUnit = "%";
							percentiles = getDefinedPercentile(test,measure);
							rhs = reportInfo.getValue("CAPACITY_PLANNING",test+ COLON +measure);
							if(rhs == null || rhs.length() == 0){
								rhs = "MAX";
							}
							if("MP".equalsIgnoreCase(rhs)){
								rhs = "MIN";
							}else{
								rhs = "MAX";
							}
							String percentile = (rhs.equals("MAX") ? String.valueOf(percentiles[1]) : String.valueOf(percentiles[0]));
							
							String service =null;
							Vector infos = null;
							for(int j=0; j<v_component.size(); j++)
							{
								String componentType = "";
								String tempCompType = (String)v_component.get(j);
								String selectedComp = tempCompType.substring(0, tempCompType.indexOf(COLON));																								
								if(!selectedGroup.equalsIgnoreCase("Component"))
								{
									componentType = tempCompType.substring(tempCompType.indexOf(COLON)+1);
									componentType = componentType + COLON + tempCompType.substring(0,tempCompType.indexOf(COLON));
								}
								else
								{
									componentType = tempCompType;
								}
								//componentType = componentType.substring(componentType.indexOf("#")+1);
								infos = erInfo.getInfosForTest(service,test,componentType);
								
								if(infos.size()>0 && !infos.contains("+"))
								{
									descriptorAvail = true;
									break;
								}
							}
							infoTable.put(test,new Boolean(descriptorAvail));
							JSONObject jObj = new JSONObject();

							//String measureDispName = reportInfo.getValue("SYSTEM_CAPACITY","Measure"+(i+1)+"_Title");
							String measureDispName = (String)measureNameMap.get(temStrTest);
							if(!columName.contains(measureDispName))
							{
								columName.add(measureDispName);
								jObj.put("colName",measureDispName);
								jObj.put("Measurement",measureUnit);
								
								if((isSummaryOnly && systemTest.equalsIgnoreCase(test)) || !descriptorAvail)
								{
									gridColumnCnt = gridColumnCnt+2;
									jObj.put("SUB_COLUMNS","3");
									JSONArray subHeadingsForMeasure =  new JSONArray();
									subHeadingsForMeasure.add(percentile+intlmap.getTextDescription("reporter.capcity.th")+"\n"+intlmap.getTextDescription("reporter.common.%tile"));
									subHeadingsForMeasure.add(intlmap.getTextDescription("reporter.cpacity.Avg"));
									subHeadingsForMeasure.add(intlmap.getTextDescription("reporter.cpacity.Current"));
									jObj.put("subHeadingsForMeasure",subHeadingsForMeasure);
									//list_data.add(intlmap.getTextDescription("reporter.cpacity.Descriptor"));
									list_data.add(percentile+intlmap.getTextDescription("reporter.cpacity.th Percentile"));
									list_data.add(intlmap.getTextDescription("reporter.cpacity.Avg"));
									list_data.add(intlmap.getTextDescription("reporter.cpacity.Current"));
								}
								else
								{
									gridColumnCnt = gridColumnCnt+3;
									jObj.put("SUB_COLUMNS","4");
									JSONArray subHeadingsForMeasure =  new JSONArray();
									subHeadingsForMeasure.add(intlmap.getTextDescription("reporter.capcity.Descriptor"));
									subHeadingsForMeasure.add(percentile+intlmap.getTextDescription("reporter.capcity.th")+"\n"+intlmap.getTextDescription("reporter.common.%tile"));
									subHeadingsForMeasure.add(intlmap.getTextDescription("reporter.cpacity.Avg"));
									subHeadingsForMeasure.add(intlmap.getTextDescription("reporter.cpacity.Current"));
									jObj.put("subHeadingsForMeasure",subHeadingsForMeasure);
									list_data.add(intlmap.getTextDescription("reporter.cpacity.Descriptor"));	list_data.add(percentile+intlmap.getTextDescription("reporter.cpacity.th Percentile"));
									list_data.add(intlmap.getTextDescription("reporter.cpacity.Avg"));
									list_data.add(intlmap.getTextDescription("reporter.cpacity.Current"));
								}
								columnDetails.add(jObj);
							}
						}
						if(selectedGroup.equals("Component"))
						{
							String[] selectedComps = request.getParameterValues("er_component");
							List componentList = Arrays.asList(selectedComps);
							v_component.clear();
							v_component.addAll(componentList);
						}
						String tdClass = "";
						Collections.sort(v_component,String.CASE_INSENSITIVE_ORDER);
						for(int i = 0; i < v_component.size(); i++)
						{
							String compStr = (String)v_component.get(i);
							String component = "";
							String compType = "";
							
							 if(selectedGroup.equals("Component")) {
								 compType = compStr.substring(compStr.lastIndexOf(COLON)+1);
								 component = compStr.substring(0,compStr.indexOf(COLON));
							} else {
								 component = compStr.substring(compStr.indexOf(COLON)+1,compStr.lastIndexOf(COLON));
								 if(component.indexOf(COLON) != -1)
									 component = component.substring(0,component.indexOf(COLON));
								 compType = compStr.substring(0,compStr.indexOf(COLON));
							}
							
							compType = intlmap.getComponentTypeDescription(compType);
							boolean isInfosAvail = true;
							boolean initialFalg = true;
							boolean isSameComponent = true;
							
							int count = 0;
							String previousComp = "";
							int infoCount = 0;
							String strTemp = (String)resultMap.get(component+COLON+"rowSpan");

							Boolean valuesAvailable = (Boolean)resultMap.get(component);
							boolean isValuesAvailable = false;
							if(valuesAvailable != null)
								isValuesAvailable = valuesAvailable.booleanValue();
							if(!isValuesAvailable)
								continue;
							if(i == 0 && !tdClass.equalsIgnoreCase("tdborder")){
								tdClass = "tdborder";
							}else if( i % 2 ==  0 && !tdClass.equalsIgnoreCase("tdborder")){
								tdClass = "tdborder";
							}else if(!tdClass.equalsIgnoreCase("tdborder2")){
								tdClass = "tdborder2";
							} else {
								tdClass = "tdborder";
							}
							if(strTemp != null) {
								infoCount = Integer.parseInt(strTemp);
							}
							//for( int k=0; k<infoCount; k++)
							while(isInfosAvail)
							{
								isInfosAvail = false;
								if(count == 0)
								{
									list_data.add(component);
								}
								else
								{
									list_data.add("");
								}
								//added for csv ends

								int gridRowColCount = 1;

								JSONObject gridRow =  new JSONObject();
								gridRow.put("COLUMN_0",systemLbl+ " : " +component);
								String majorColor=reportInfo.getValue("SYSTEM_CAPACITY","Major");
								String criticalColor=reportInfo.getValue("SYSTEM_CAPACITY","Critical");
								for( int j=0; j<v_test.size(); j++)
								{
									String tempStr = (String)v_test.get(j);
									String tempTest = tempStr.substring(0,tempStr.indexOf(COLON));
									if(tempTest.indexOf("_")>-1)
									{
										continue;
									}
									String tempMeasure = tempStr.substring(tempStr.indexOf(COLON)+1);
									String tempStrMax = "";
									String tempStrAvg = "";
									String tempStrCurrent = "";
									String temprhs = reportInfo.getValue("CAPACITY_PLANNING",tempTest+ COLON +tempMeasure);
									if(temprhs == null || temprhs.length() == 0){
										temprhs = "MAX";
									}
									if("MP".equalsIgnoreCase(temprhs)){
										temprhs = "MIN";
									}else{
										temprhs = "MAX";
									}
									
									tempMeasure = dbInfo.getColumnForMeasure(tempTest, tempMeasure);
									List infoList = null;
									infoList = (ArrayList)resultMap.get(component+COLON+tempTest);
									if(infoList == null) {
										infoList = new ArrayList();
									}
									String desc = "";
									if(infoList.size() > 0)
									{
										if(infoList.size() > count)
											desc = (String) infoList.get(count);
										else
											desc = "-";
									}
									else
									{
										infoList = null;
										desc = "-";
									}
									if(desc != null)
									{
										tempStrMax = (String)resultMap.get(component+COLON+tempTest+COLON+tempMeasure+"_"+temprhs+COLON+desc+COLON+"minmax");
										tempStrAvg = (String)resultMap.get(component+COLON+tempTest+COLON+tempMeasure+"_"+temprhs+COLON+desc+COLON+"avg");
										tempStrCurrent=(String)resultMap.get(component+COLON+tempTest+COLON+tempMeasure+"_"+temprhs+COLON+desc+COLON+"current");
										
									}
									
									if(desc == null)
										desc ="-";
									if(tempStrMax == null || tempStrMax.equals(""))
										tempStrMax= "-";

									if(tempStrAvg == null)
										tempStrAvg = "-";
									  if(tempStrCurrent==null)
										  tempStrCurrent="-";
									String color = "";
									double tempValue = 0;
									
									String testMeasureKey = (String)testMeasureKeyMap.get(tempStr);
									String measure_Check = (String)measureCheckMap.get(tempStr);
									
									if(!tempStrMax.equals("-"))
									{
										tempValue = Double.valueOf(tempStrMax).doubleValue();
									}
									
									if(!tempStrMax.equals("-"))
									{
										double dataValMin = Double.valueOf(reportInfo.getValue("SYSTEM_CAPACITY",testMeasureKey+"_Major")).doubleValue();
										double dataValMax = Double.valueOf(reportInfo.getValue("SYSTEM_CAPACITY",testMeasureKey+"_Critical")).doubleValue();
										if(measure_Check.equalsIgnoreCase(greaterThan))
										{
											if( tempValue > dataValMax )
												color = criticalColor;//"HighBgCls";//reportInfo.getValue("SYSTEM_CAPACITY","Critical");
											else if( tempValue > dataValMin )
												color = majorColor;//"MediumBgCls";//reportInfo.getValue("SYSTEM_CAPACITY","Major");
										}
										else
										{
											if( tempValue < dataValMin )
												color = criticalColor;//"HighBgCls";//reportInfo.getValue("SYSTEM_CAPACITY","Critical");
											else if( tempValue < dataValMax )
												color = majorColor;//"MediumBgCls";//reportInfo.getValue("SYSTEM_CAPACITY","Major");
										}
									}

									if(desc.length() > 0)
										desc = desc.substring(desc.indexOf("+")+1);
									if(desc.equals(""))
										desc = "-";
									String tempDesc = reportInfo.getValue("SYSTEM_CAPACITY","RemoveDescriptor");
									String removeTest = tempDesc.substring(0,tempDesc.indexOf(COLON));
									String removeMeasure = tempDesc.substring(tempDesc.indexOf(COLON)+1 , tempDesc.lastIndexOf(COLON));
									String removeDesc = tempDesc.substring(tempDesc.lastIndexOf(COLON)+1);
									if(tempTest.equalsIgnoreCase(removeTest)&& tempMeasure.equalsIgnoreCase(removeMeasure)&& desc.equalsIgnoreCase(removeDesc))
									{
										int colIdx1 = gridRowColCount++;
										gridRow.put("COLUMN_"+colIdx1,"-");

										int colIdx2 = gridRowColCount++;
										gridRow.put("COLUMN_"+colIdx2,"-");

										int colIdx3 = gridRowColCount++;
										gridRow.put("COLUMN_"+colIdx3,"-");
										
										//added for csv starts
										list_data.add(dbInfo.formatValue("-"));
										list_data.add(dbInfo.formatValue("-"));
										list_data.add(dbInfo.formatValue("-"));
										//added for csv ends
										continue;
									}
									Boolean tempVal = (Boolean)infoTable.get(tempTest);
									descriptorAvail = tempVal.booleanValue();
									if((isSummaryOnly && tempTest.equalsIgnoreCase(systemTest)) || !descriptorAvail)
									{
										if(StringUtils.isNull(color))
											color ="-";

										int colIdx1 = gridRowColCount++;
										gridRow.put("COLUMN_"+colIdx1,dbInfo.formatValue(tempStrMax));
										gridRow.put("COLUMN_Color"+colIdx1,color);

										int colIdx2 = gridRowColCount++;
										gridRow.put("COLUMN_"+colIdx2,dbInfo.formatValue(tempStrAvg));

										int colIdx3 = gridRowColCount++;
										gridRow.put("COLUMN_"+colIdx3,tempStrCurrent);

										//added for csv starts
										//list_data.add("-");
										list_data.add(dbInfo.formatValue(tempStrMax));
										list_data.add(dbInfo.formatValue(tempStrAvg));
										list_data.add(tempStrCurrent);//For Current Value
										//added for csv ends
									}
									else
									{
										if(StringUtils.isNull(color))
											color ="-";

										int colIdx = gridRowColCount++;
										gridRow.put("COLUMN_"+colIdx,desc);

										int colIdx1 = gridRowColCount++;
										gridRow.put("COLUMN_"+colIdx1,dbInfo.formatValue(tempStrMax));
										gridRow.put("COLUMN_Color"+colIdx1,color);

										int colIdx2 = gridRowColCount++;
										gridRow.put("COLUMN_"+colIdx2,dbInfo.formatValue(tempStrAvg));
										int colIdx3 = gridRowColCount++;
										gridRow.put("COLUMN_"+colIdx3,tempStrCurrent);
										
										//added for csv starts
										list_data.add(desc);
										list_data.add(dbInfo.formatValue(tempStrMax));
										list_data.add(dbInfo.formatValue(tempStrAvg));
										   if(tempStrCurrent==null)tempStrCurrent="-";
										list_data.add(tempStrCurrent); //For Current Value
										//added for csv ends
									}
									if(infoList == null && !isInfosAvail)
									{
										isInfosAvail = false;
									}
									else if(count == infoCount-1)
									{
										isInfosAvail = false;
									}
									else
									{
										isInfosAvail = true;
									}
								}// test loop
								count ++;
								//isSameComponent = false;
								gridData.add(gridRow);
							}// isinfo loop
						}// component loop

						// added for csv 
						h_tabrc.put(v_measure_csv,list_data);
						h_tab.put(s_title,h_tabrc);
						list.add(h_tab);
						list_data.add("\n");
						v_measure_csv = new Vector();
						list_data = new LinkedList();
						h_tabrc = new Hashtable();
						h_tab = new Hashtable();

						//json.put("gridSubHeaders",gridSubHeaders);

						JSONObject gridObj = new JSONObject();
						gridObj.put("gridData",gridData);
						gridObj.put("COLUMNS",columnDetails);
						gridObj.put("gridColumnCnt",String.valueOf((gridColumnCnt-1)));
						gridObj.put("GRID_TITLE",intlmap.getTextDescription("reporter.common.System Capacity Report")+" "+heading);

						json.put("gridObj",gridObj);
						
						//added for csv Ends
						String majorColor = reportInfo.getValue("SYSTEM_CAPACITY","Major");
						String criticalColor = reportInfo.getValue("SYSTEM_CAPACITY","Critical");
						String legendTextMajor = reportInfo.getValue("SYSTEM_CAPACITY","LegendTextMajor");
						String legendTextCritical = reportInfo.getValue("SYSTEM_CAPACITY","LegendTextCritical");
						// added fro csv
						v_measure_csv.add("Measurements");
						v_measure_csv.add("Major / "+legendTextMajor);
						v_measure_csv.add("Critical / "+legendTextCritical);

						screenLabels.put("reporter.common.Measurements",intlmap.getTextDescription("reporter.common.Measurements"));
						screenLabels.put("reporter.capacity.Major",intlmap.getTextDescription("reporter.capacity.Major /")+" "+legendTextMajor);
						screenLabels.put("reporter.capacity.Critical",intlmap.getTextDescription("reporter.capacity.Critical")+" "+legendTextCritical);

						JSONArray measThreshDataArr =  new JSONArray();
						for(int i =0; i<v_test.size();i++)
						{
							JSONObject measThreshData =  new JSONObject();
							String temStrTest = (String)v_test.get(i);
							String test = temStrTest.substring(0,temStrTest.indexOf(COLON));
							String tempMeasure = temStrTest.substring(temStrTest.indexOf(COLON)+1);
							String measureDispName = (String)measureNameMap.get(temStrTest);
							String measure_Check = (String)measureCheckMap.get(temStrTest);
							String measure_key = (String)testMeasureKeyMap.get(temStrTest);
							String measureUnit  = tablesInfo.getUnitForMeasure(test,tempMeasure);
							measThreshData.put("measure",measureDispName);
							measThreshData.put("major",measure_Check+" "+reportInfo.getValue("SYSTEM_CAPACITY",measure_key+"_Major")+" "+measureUnit);
							measThreshData.put("critical",measure_Check+" "+reportInfo.getValue("SYSTEM_CAPACITY",measure_key+"_Critical")+""+measureUnit);

							list_data.add(measureDispName);
							list_data.add(measure_Check+" "+reportInfo.getValue("SYSTEM_CAPACITY",measure_key+"_Major")+" "+measureUnit);
							list_data.add(measure_Check+" "+reportInfo.getValue("SYSTEM_CAPACITY",measure_key+"_Critical")+" "+measureUnit);

							measThreshDataArr.add(measThreshData);
						}
						json.put("measThreshDataArr",measThreshDataArr);
					}
					else if(repType !=null && repType.equalsIgnoreCase("chart"))
					{
						Map chartData = (Map) resultMap.get("chartData");	
						List comList = new ArrayList(chartData.keySet());						
						JSONObject chartJsonObj = null;
						JSONArray chartArray = new JSONArray();
						for(int i=comList.size()-1;i>=0;i--)
						{
							String comp = (String)comList.get(i);
							chartJsonObj = (JSONObject)chartData.get(comp); 
							chartJsonObj.put("title", comp);
							chartArray.add(chartJsonObj);
						}												
						json.put("chartDataArr",chartArray);
					}									
				}// no data found false
				else
				{
					json.put("dataAvailable","false");
					screenLabels.put("errorMsg",intlmap.getTextDescription("reporter.common.No measures available for the current selection"));
				}
			}// submit block
			// added for csv starts
			h_tabrc.put(v_measure_csv,list_data);
			h_tab.put(s_title,h_tabrc);
			list.add(h_tab);
			list_data.add("\n");
			v_measure_csv = new Vector();
			list_data = new LinkedList();
			h_tabrc = new Hashtable();
			h_tab = new Hashtable();
			String repType = (String)request.getParameter("opt");
			if(repType != null && "chart".equalsIgnoreCase(repType))
			{
				HashMap reportData=(HashMap)session.getAttribute("SYSTEM_CAPACITY_REPORT");
				ErSystemCapacityReportBean appBean = new ErSystemCapacityReportBean();
				List lst = appBean.createDataForCSV(reportData,request);
				session.setAttribute("list",lst);
			}
			else
			{
				if(list!= null && !list.isEmpty())
				{
					session.setAttribute("list",list);
				}
			}
			//added for csv ends
		}// for foreground report
		//for mail starts
		
		json.put("hiddenParams",hiddenParams);
		json.put("screenLabels",screenLabels);
		json.put("pageParams",pageParams);
		response.setContentType("application/json;charset=UTF-8");
		String strEncodeer_timeline = er_timeline;
		if(er_timeline != null)
			strEncodeer_timeline = com.eg.EgURLEncoder.encode(er_timeline,UTF_8);
		s_st_time  = request.getParameter("startdate");
		s_en_time  = request.getParameter("enddate");
		if(s_st_time != null && s_en_time != null && s_inidate != null)
		{
			s_st_time = com.eg.EgURLEncoder.encode(s_st_time,UTF_8);
			s_en_time = com.eg.EgURLEncoder.encode(s_en_time,UTF_8);
			s_inidate = com.eg.EgURLEncoder.encode(s_inidate,UTF_8);
		}
		String dataProcess = mngrIProc+"/final/reporter/ErSystemCapacityReportPrint.jsp;jsessionid="+ session.getId()+"?select_group="+selectedGroup+"&er_comptype="+s_comptype+"&er_site="+s_site+"&startdate="+s_st_time+"&enddate="+s_en_time+"&timefrom="+timefrom2+"&minfrom="+minfrom2+"&timeto="+timeto2+"&minto="+minto2+"&starthr="+s_st_hr+"&endhr="+s_en_hr+"&er_timeline="+strEncodeer_timeline+"&startmin="+startMin+"&endmin="+endMin+"&inidate="+s_inidate+"&pageWidthProces="+pageWidthProces;
		if(selectedCompArray != null)
		{
			//for(int j=0; j<selectedCompArray.length; j++)
			{
				//dataProcess += "&er_component=" + com.eg.EgURLEncoder.encode(selectedCompArray[j],UTF_8);
			}
		}
		session.setAttribute("MAIL_URL",dataProcess);
		String servletName="/final/servlet/com.eg.ErSystemCapacityReportC?";
		String params = "select_group="+selectedGroup+"&er_comptype="+s_comptype+"&er_site="+s_site+"&startdate="+s_st_time+"&enddate="+s_en_time+"&timefrom="+timefrom2+"&minfrom="+minfrom2+"&timeto="+timeto2+"&minto="+minto2+"&starthr="+s_st_hr+"&endhr="+s_en_hr+"&er_timeline="+strEncodeer_timeline+"&startmin="+startMin+"&endmin="+endMin+"&inidate="+s_inidate+"&er_RmDispName="+request.getParameter("er_RmDispName");
		json.put("DATA_URL","../.."+servletName+params+"&option=data");
		json.put("CSV_URL", "../.."+servletName+params+"&option=csv");
		response.getWriter().write(json.toString());
	}
	//for mail ends
	// for redirecting same page in reporter Starts
	queryString=(String)ErUtils.prepareQueryString(request.getParameterMap());
	String qString="";
	String qStringBackUrl = "";
	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) {
				if(reqparam.equals("er_site"))
				{
					value=com.eg.EgURLEncoder.encode(value, UTF_8);
				} else if(reqparam.equals("startdate"))
				{
					value=com.eg.EgURLEncoder.encode(value, UTF_8);
				} else if(reqparam.equals("enddate"))
				{
					value=com.eg.EgURLEncoder.encode(value, UTF_8);
				} else if(reqparam.equals("inidate"))
				{
					value=com.eg.EgURLEncoder.encode(value, UTF_8);
				}
				qString += reqparam+"="+value+"&";
			}
		}
		if(request.getParameter("isSubmit")!=null)
		{
			session.setAttribute("reportLastAccessedURL","/final/reporter/ErSystemCapacityReport.jsp?isSubmit=true&"+ qString);
		}
		else 
		{
			session.setAttribute("reportLastAccessedURL","/final/reporter/ErSystemCapacityReport.jsp?" + qString);
		}
	}// redirecting reporter same page ends
}
catch(Throwable t)
{
	t.printStackTrace();
}
	//Back Button - Start
	ArrayList listbackvar = new  ArrayList();
	if(request.getParameter("isSubmit")!=null)
	{
		listbackvar.add("ErSystemCapacityReport.jsp?");
		listbackvar.add("status="+status+"&bggroundStr="+bggroundStr+"&"+queryString);
		session.setAttribute("favSchBackDisplay","Yes");
	}
	else 
	{
		listbackvar.add("ErSystemCapacityReport.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
%>