<%
/**
 *	Name		: ErEsxGuestReport.jsp
 *
 *	purpose		: This page is used to display the individual Virtual Machine information
 *
 *	Created by	: Soban Babu.M.S
 */
%>
<%@ page import = "egurkha.reporter.*" %>
<%@ page import = "java.util.*" %>
<%@ page import = "java.text.SimpleDateFormat" %>
<%@ page import ="com.eg.ErDbServer"%>
<%@ page import="com.egurkha.pdfmaker.*"%>

<%@ page import = "egurkha.*" %>
<%@ page import = "com.eg.EgDbInfo" %>
<%@ page import ="com.eg.EgInstallInfo"%>
<%@ page import ="com.eg.IniFile"%>
<%@ page import="com.egurkha.ini.*" %>
<%@ page import="com.eg.EgDateInfo" %>
<%@ page import = "com.eg.MappingNameSorter"%>
<%@ page import = "com.eg.EgName"%>
<%@ page import="com.eg.EgGroupInfo" %>
<%@ page import="com.eg.EgReportInfo" %>
<%@ page import="com.eg.EgServicesInfo" %>
<%@ page import="com.eg.EgThresholdInfo" %>
<%@ include file = "ErReporterTracker.jsp" %>
<%@ page import = "com.egurkha.*" %>
<%@ page import = "com.eg.EgMappingInfo" %>
<%@ page import="com.eg.EgURLEncoder" %>
<%@ page import = "java.net.*" %>
<%@ page import="com.eg.EgTablesInfo" %>
<%@ page import="com.eg.EgSpecsInfo" %>
<%@ page import="com.eg.EgDiscInfo" %>
<%@ page import="com.eg.EgDbInfo" %>
<%@ page import="egurkha.reporter.ErEsxVMutils" %>
<%@ page import="com.eg.EgLastMeasureThread" %>

<%@ page import = "java.net.URLEncoder" %>
<%@ page import = "java.net.URLDecoder" %>
<%@ page import = "com.egurkha.util.DateTimeTokenizer" %>
<%@ page import = "com.egurkha.util.DateUtil" %>
<%@ page import = "com.egurkha.util.StringUtils" %>
<%@ page import = "java.text.*" %>
<%@ page import = "com.eg.EgConfigInfo"%>
<%@ taglib prefix="egui" uri="../WEB-INF/eg-taglib.tld" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import = "net.sf.json.*" %>
<%@ page import="com.egurkha.util.StringUtils"%>


<%
	String bggroundStr = (String)request.getAttribute("bggroundStr");
	String status = (String)request.getAttribute("status");
	String titleToDisplay=request.getParameter("er_RmDispName");					

	//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("htableMinMaxAvgPer",null);
		request.setAttribute("htableTargetHost",null);
		request.setAttribute("Form_Data",null);
		bggroundStr = (String)request.getParameter("bggroundStr");
	}
	//Back Button - End
	String strScreenWidth = request.getParameter("screenWidth");
	int screenWidth = 990;
	try{
		screenWidth = Integer.parseInt(strScreenWidth);
	}catch(Exception e){screenWidth = 990;}
try
{
	boolean isEnglishLanguage=false;
	if(trackerLanguage!=null && trackerLanguage.equals("en_US"))
	{
		isEnglishLanguage=true;
	}
	List lst = new LinkedList();
	EgDateInfo egDt = new EgDateInfo();
	EgTablesInfo tablesInfo = new EgTablesInfo("manager");
	EgReportInfo reportinfo = new EgReportInfo("manager");
	String confrimation = reportinfo.getValue("BACKGROUND_PROCESS","NeedConfirmation");
	String strbgrepportName = reportinfo.getValue("BACKGROUND_PROCESS","EnableBackgroundReport");
	String limitforbg = reportinfo.getValue("BACKGROUND_PROCESS","MinDurationForReport");
	ErVMGuestServerReportBean ervmGuest = new ErVMGuestServerReportBean();
	String thisLanguage="";
	if (thisuser!=null)
	{
		String userLang = thisuser.getLanguage();
		if (userLang!=null && !userLang.equalsIgnoreCase("NULL"))
		{
			thisLanguage=userLang;
		}
	}
	ErComponentsUtils compUtils = new ErComponentsUtils(thisuser.getLoginID());
	EgMappingInfo mappingInfo = new EgMappingInfo(thisLanguage);
	MappingNameSorter sorter = new MappingNameSorter(thisLanguage);
	HashMap GuestResourceTypeMap = (HashMap)request.getAttribute("guestResourceMap");
	HashMap guestTypeMap=(HashMap)request.getAttribute("guestMap");
	HashMap powerOnPerCentMap=(HashMap)request.getAttribute("powerOnPerCentMap");
	HashMap hashAvgMap = (HashMap)request.getAttribute("hashAvgMap");
	HashMap mapListTime = (HashMap)request.getAttribute("mapListTime");
	IniUI ui = IniUI.getInstance();
	ErUtils erUtils = new ErUtils();
	EgDbInfo dbInfo=new EgDbInfo("manager");
	String mngrIProc = new IniFile(new EgConfigInfo("manager").getDbFile()).getValue("DB_PROPERTIES","ManagerUrl");
	String search = request.getParameter("search");
	Vector vmInformationList = (Vector)request.getAttribute("listAllDuration");
	List listUserTypes = compUtils.getAllComponentType();
	//getting parameters for this page
	String er_comptype = request.getParameter("er_comptype");
	String er_virtualcenter = request.getParameter("er_virtualcenter");
 	//String backQenable = request.getParameter("backQenable");
 	String er_type = request.getParameter("er_type");
	String ervm_type = request.getParameter("ervm_type");
	String s_st_time = request.getParameter("er_stdate");
	String s_en_time = request.getParameter("er_enddate");
	String s_st_hr = request.getParameter("starthr");
	String s_en_hr = request.getParameter("endhr");
	String strmin = request.getParameter("startmin");
	String enmin  = request.getParameter("endmin");
	String er_trenddata  = request.getParameter("er_trenddata");
	String selectBy = request.getParameter("selectBy");
	String ervm_disp = request.getParameter("ervm_disp");
	String sortduration =  request.getParameter("sortduration");
	String reqFromSchedule = request.getParameter("fromSchedule");
	String schedule_id = request.getParameter("schedule_id");
	String uiFile = "eg_ui.ini";
	String s_iniFile_dir = EgInstallInfo.getInstallDir()+ "/manager/config/";
	IniFile egUI = new IniFile(s_iniFile_dir + uiFile);
	String currentDateFormat=null;
	Vector v_comp = compUtils.getAllUserComponents1();
	boolean hasVMs = false;
	if (strUserDateFormat==null)
	{
		currentDateFormat = ui.getValue("CURRENT_DATE_FORMAT","selectedDateFormat");
	}
	else
	{
		currentDateFormat=strUserDateFormat;
	}
	String comFormat=currentDateFormat;
	currentDateFormat = strUserDateFormat;
	long msecsPerHour = (long) 1000 * 60 * 60;
	String er_mode = request.getParameter("er_mode");
	String[] er_component = request.getParameterValues("er_component");
	String sub="";
	String divStatus = request.getParameter("divStatus");
	String srcForImg="";
	String s_component_dd = "";
	String isOnlyVMAssigned=null;
	if(divStatus==null)
	{
		divStatus="none";
	}
	if(divStatus.equals("none"))
	{
		srcForImg="/final/images/moreoption.png";
	}
	else if(divStatus.equals("block"))
	{
		srcForImg="/final/images/lessoption.png";
	}
	if (ervm_disp !=null && ervm_disp.equals("Yes"))
	{
		sub = "MEASURE_GROUP";
	}
	else
	{
		sub = "VIRTUAL_MEASURE_GROUP";
	}
	String strreportName ="";
	if(ervm_disp != null && ervm_disp.equals("Yes"))
	{
		strreportName = "Virtualization_VM_Physical_Resource";
	}
	else
	{
		strreportName = "Virtualization_VM_Virtual_Resource";
	}
	if(er_trenddata == null)
	{
		er_trenddata = "No";
	}
	String detailed = "";
	String trend = "";
	String er_timeline = request.getParameter("er_timeline");
	String starttimeformat = "";
	String endtimeformat = "";
	String startDateTime = "";
	String endDateTime = "";
	String dispDate = null;
	String startDateforBean = "";
	String endDateforBean = "";
	String Hourfrom = "";
	String Minfrom = "";
	String Hourto = "";
	String Minto = "";
	String fromTime,toTime;
	String timefrom = "";
	String timeto = "";
	//String str_selectedVM = "";
	StringTokenizer st = null;
	ErEsxVMutils eresx = new ErEsxVMutils();
	ArrayList virtualCenters = new ArrayList();
	String subject = "VIRTUAL_GUEST";
	Vector v_comp_popup = new Vector();
	Vector v_comp_popup_disp = new Vector();
	Vector v_time = new Vector();
	Vector v_min = new Vector();
	HashMap mappedtimeline = new HashMap();
	mappedtimeline = eresx.getTimeline();
	v_time = (Vector)mappedtimeline.get("timehour");
	v_min = (Vector)mappedtimeline.get("timemin");
	String timefrom2 = request.getParameter("timefrom");
	String minfrom2 = request.getParameter("minfrom");
	String timeto2 = request.getParameter("timeto");
	String minto2 = request.getParameter("minto");
	fromTime = reportinfo.getTimeFrame(subject,"FROM");
	toTime = reportinfo.getTimeFrame(subject,"TO");
	String strGuestVM = request.getParameter("select_vm");
	
    String fromScheduleModify = request.getParameter("fromScheduleModify");
	String fromFavoriteModify = request.getParameter("fromFavoriteModify");
	String favorite_id = request.getParameter("id");
	String er_favorite = request.getParameter("er_favorite");
	
	JSONObject json = new JSONObject();
	JSONObject screenLabels = new JSONObject();
	JSONObject pageParams = new JSONObject();
	JSONObject hiddenParams = new JSONObject();
	// for vm report starts here 
	String isUserVmReport = request.getParameter("isUserVmReport");
	List a_userVMs = thisuser.getAlluserDesktopVms();
	if(a_userVMs!=null && a_userVMs.size()>0)
	{
		hasVMs = true;
	}
	if(er_comptype!=null && er_comptype.equalsIgnoreCase("Virtual_Machine"))
	{
		if(!a_userVMs.contains(strGuestVM))
		{
			strGuestVM = (String)a_userVMs.get(0);
		}
		ArrayList serverList = (ArrayList)thisuser.getVMHostHistory(strGuestVM);
		if(serverList!=null && serverList.size()>0)
		{
			String sampple_server = (String)serverList.get(0);
			er_comptype = sampple_server.substring(sampple_server.lastIndexOf(":")+1);
		}
	}
	ArrayList er_components = new ArrayList();
	if (!StringUtils.isNull(isUserVmReport ) && isUserVmReport.equalsIgnoreCase("yes"))
	{
		Hashtable ht_vmMappedWithServer		= new Hashtable();
		ht_vmMappedWithServer = EgLastMeasureThread.vmMapDbForHistory;
		ervm_disp = "No";
		JSONArray selectedComponents = new JSONArray();
		ArrayList vmsList = new ArrayList();

		//vmsList.addAll(thisuser.getOnlyVMs());
		vmsList.addAll(a_userVMs);
		if(vmsList.size()>0)
			isOnlyVMAssigned="true";
		if(strGuestVM == null && vmsList !=null && vmsList.size() >0)
		{
			strGuestVM = (String)vmsList.get(0);
		}
		//if(vmsList !=null && vmsList.size() >0 && ht_vmMappedWithServer.size()>0 )
		if(vmsList !=null && vmsList.size() >0)
		{
			//ArrayList serverList = (ArrayList)ht_vmMappedWithServer.get(strGuestVM);
			ArrayList serverList = (ArrayList)thisuser.getVMHostHistory(strGuestVM);
			if(serverList!=null)
			{
				for(int ii=0;serverList.size()>ii;ii++)
				{
					String serverfullname =(String)serverList.get(ii);
					er_comptype= serverfullname.substring(serverfullname.lastIndexOf(":")+1);
					String tmpcomp=serverfullname.substring(0,serverfullname.lastIndexOf(":"));
					if(!er_components.contains(tmpcomp))
						er_components.add(tmpcomp);
				}
			}
		}
		if(er_components != null && er_components.size()>0)
		{
			//s_component_dd = (String)er_components.get(0);
			//for(int i=0;er_components.size()>i;i++)
			//{
				selectedComponents.add((String)er_components.get(0));
			//}
		}
		json.put("selectedComponents",selectedComponents);
		JSONArray vmOptsJson = new JSONArray();
		if(vmsList != null && vmsList.size() > 0)
		{
			Collections.sort(vmsList,String.CASE_INSENSITIVE_ORDER);
		
			Iterator itrVMList = vmsList.iterator();
			while(itrVMList.hasNext())
			{
				String vmName = (String) itrVMList.next();
				JSONObject jObj = new JSONObject();
				jObj.put("displayField",vmName);
				jObj.put("valueField",vmName);
				vmOptsJson.add(jObj);
			}
			if(!StringUtils.isNull(strGuestVM) && !strGuestVM.equals("Not Applicable"))
			{
				pageParams.put("selectedVM",strGuestVM);
			}
			else
			{
				String defaultVM = (String)vmsList.get(0);
				pageParams.put("selectedVM",defaultVM);
			}
		}
		else
		{
			JSONObject jObj = new JSONObject();
			jObj.put("displayField",mappingInfo.getTextDescription("reporter.common.Not Applicable"));
			jObj.put("valueField","Not Applicable");
			vmOptsJson.add(jObj);
			pageParams.put("selectedVM","Not Applicable");
		}
		json.put("vmOptsJson",vmOptsJson);
		json.put("selectedComptype",er_comptype);
	}
	// for vm report ends here
	if(strGuestVM!=null)
	{
		if(strGuestVM.indexOf("|plus|")>-1){
			strGuestVM=StringUtils.replace(strGuestVM,"|plus|","+");
		}
		if(strGuestVM.indexOf("|amp|")>-1)
		{
			strGuestVM=StringUtils.replace(strGuestVM,"|amp|","&");
		}
		if (strGuestVM.indexOf("|pct|")>-1)
		{
			strGuestVM=StringUtils.replace(strGuestVM,"|pct|","%");
		}
		if (strGuestVM.indexOf("|hash|")>-1)
		{
			strGuestVM=StringUtils.replace(strGuestVM,"|hash|","#");
		}
	}
	if (!StringUtils.isNull(isUserVmReport ) && isUserVmReport.equalsIgnoreCase("yes")){
		pageParams.put("selectedVM",strGuestVM);
	}


	st = new StringTokenizer(fromTime,":");
	if(st.hasMoreTokens())
	{
		Hourfrom = st.nextToken();
		Minfrom = st.nextToken();
	}
	st = new StringTokenizer(toTime,":");
	if(st.hasMoreTokens())
	{
		Hourto = st.nextToken();
		Minto = st.nextToken();
	}
	if (timefrom2 !=  null)
	{
		Hourfrom = timefrom2;
	}
	if (minfrom2 != null)
	{
		Minfrom = minfrom2;
	}
	if (timeto2 != null)
	{
		Hourto = timeto2;
	}
	if (minto2 != null)
	{
		Minto = minto2;
	}
	EgDiscInfo discIni = new EgDiscInfo("manager");
	if(s_st_time != null && s_en_time != null)
	{
		if(DateUtil.isDate(s_st_time.trim(),"MM/dd/yyyy"))
		{
			starttimeformat=DateUtil.changeDateFormat(s_st_time.trim(),"MM/dd/yyyy",currentDateFormat);
		}
		else
		{
			starttimeformat=s_st_time.trim();
		}
		if(DateUtil.isDate(s_en_time,"MM/dd/yyyy"))
		{
			endtimeformat = DateUtil.changeDateFormat(s_en_time.trim(),"MM/dd/yyyy",currentDateFormat);
		}
		else
		{
			endtimeformat = s_en_time.trim();
		}
	}
	String opt = request.getParameter("er_trenddata");
	if(opt == null)
	{
		opt="No";
	}
	if(er_timeline == null  || er_timeline.equals(" "))
	{
		er_timeline="1 day";
	}
	String[] options=null;
	if(opt!=null && opt.equals("No"))
	{
		 options = new String[]{"Any","1 hour", "3 hours", "6 hours", "9 hours", "12 hours", "15 hours", "18 hours", "21 hours","1 day", "2 days", "3 days", "4 days", "5 days", "6 days","1 week","2 weeks","3 weeks","4 weeks","1 month"};
	}
	else
	{
		if(er_timeline!=null && !er_timeline.equals("Any"))
		{
			String tmp=er_timeline.substring(er_timeline.indexOf(" ")+1,er_timeline.length());
			if(tmp.startsWith("h"))
			{
				er_timeline="1 day";
			}
		}
		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"};
	}
	String disable="";
	if(er_timeline!=null&&!er_timeline.equals("Any"))
	{
		disable ="disabled";
	}
	//
	String startDate = "";
	String endDate = "";
	String stsec = "";
	String ensec = "";
	if(er_timeline != null && !er_timeline.equals("Any"))
	{
		s_st_time = "";
		s_en_time = "";
		ErEsxVMutils ervm = new ErEsxVMutils();
		ervm.setCurrentDateFormat(currentDateFormat);
		if(er_timeline.endsWith("last"))
			ervm.setUser(thisuser);
		HashMap mapTimeLine = ervm.getDateTime(er_timeline,er_trenddata);
 		startDate = (String)mapTimeLine.get("dbstartdate");
		endDate = (String)mapTimeLine.get("dbenddate");
		s_st_time = (String)mapTimeLine.get("calStartDate");
		s_en_time = (String)mapTimeLine.get("calEndDate");
		s_st_hr = (String)mapTimeLine.get("startHour");
		s_en_hr = (String)mapTimeLine.get("endHour");
		strmin = (String)mapTimeLine.get("startMin");
		enmin = (String)mapTimeLine.get("endMin");
		stsec = (String)mapTimeLine.get("startSec");
		ensec = (String)mapTimeLine.get("endSec");

	
		String temp_st_Date =null;
		if(DateUtil.isDate(s_st_time,"MM/dd/yyyy"))
		{
			
			comFormat = "MM/dd/yyyy";
			temp_st_Date = DateUtil.changeDateFormat(s_st_time,comFormat,currentDateFormat);
			s_st_time = temp_st_Date;
		}
		String temp_en_Date =null;
		if(DateUtil.isDate(s_en_time,"MM/dd/yyyy"))
		{
			
			comFormat = "MM/dd/yyyy";
			temp_en_Date = DateUtil.changeDateFormat(s_en_time,comFormat,currentDateFormat);
			s_en_time = temp_en_Date;
		}
		
	
	}
	else
	{
		startDate = DateUtil.changeDateFormat(s_st_time.trim(),currentDateFormat,"dd-MM-yyyy");
		endDate = DateUtil.changeDateFormat(s_en_time.trim(),currentDateFormat,"dd-MM-yyyy");
	}
	//
	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;
		}
	}
	String detailval = reportinfo.getValue("MISC","DetailedTime");
	String strCombinedGraphValue = reportinfo.getValue("MISC","CombinedGraph");
	boolean isCombinedGraph = true;
	if(strCombinedGraphValue!=null && (strCombinedGraphValue.equalsIgnoreCase("False") || strCombinedGraphValue.equalsIgnoreCase("No")))
		isCombinedGraph = false;
	ArrayList vmhostlist  = new ArrayList();
	session.setAttribute("PDF_URL", mngrIProc+"/final/reporter/ErVMDetailsPrint.jsp");

	//hiddenParams.put("startmin",strmin);
	hiddenParams.put("isOnlyVMAssigned",isOnlyVMAssigned);
	//hiddenParams.put("endmin",enmin);
	hiddenParams.put("getMaxDaysInMonth",String.valueOf(ErUtils.getMaxDaysInMonth()));
	hiddenParams.put("userID",thisuser.getLoginID());
	hiddenParams.put("detailtime",detailval);
	hiddenParams.put("inidate",currentDateFormat);
	hiddenParams.put("er_rtype","Virtualization");
	hiddenParams.put("er_trgttype","Virtual_Machine_Details");
	hiddenParams.put("er_check","Virtualization");
	hiddenParams.put("reqfrom","vmGuest");
	hiddenParams.put("currentformat",currentDateFormat);
	hiddenParams.put("er_excweekend",request.getParameter("er_excwe"));
	hiddenParams.put("currentDateFormatForJS",currentDateFormatForJS);
	hiddenParams.put("isVmReport",request.getParameter("isVmReport"));
	hiddenParams.put("isUserVmReport",request.getParameter("isUserVmReport"));
	hiddenParams.put("fromSchedule",reqFromSchedule);
	hiddenParams.put("schedule_id",schedule_id);
	hiddenParams.put("er_ViewName","ErEsxGuestReport.jsp");
//	hiddenParams.put("forwardto","ErEsxGuestReport");
	hiddenParams.put("er_bgreportfrom",strreportName);
	hiddenParams.put("bgenabled",strbgrepportName);
	hiddenParams.put("limitforbg",limitforbg);
	hiddenParams.put("savereport","save");
	hiddenParams.put("servletName","com.eg.ErEsxVMServerReportC");
	hiddenParams.put("divStatus",divStatus);
	hiddenParams.put("sortduration",sortduration);
	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);

	ArrayList listMeasure = new ArrayList();
	String strReqMeasure = request.getParameter("er_measure");
	listMeasure = eresx.getGroupNames(sub);
	if(strReqMeasure == null && listMeasure != null && listMeasure.size()>0)
	{
		strReqMeasure = (String)listMeasure.get(0);
	}
	if (listMeasure.size() > 0)
	{
		if (listMeasure.contains("Vmotion_duration"))
		{
			listMeasure.remove(listMeasure.indexOf("Vmotion_duration"));
		}
	}
//	HashMap guestTypeMap=(HashMap)request.getAttribute("guestMap");
//	HashMap powerOnPerCentMap=(HashMap)request.getAttribute("powerOnPerCentMap");
	String backQenable=request.getParameter("backQenable");
	ArrayList  compTypeList = new ArrayList();
	ArrayList collectCompTypes = new ArrayList();
	if(er_type != null && er_type.equals("Yes"))
	{
		collectCompTypes = reportinfo.getComponent(sub,false);
	}
	else
	{
		collectCompTypes = reportinfo.getComponent(sub,false);
	}
	List allUserCompTypes = compUtils.getAllComponentType();
	if (allUserCompTypes != null && allUserCompTypes.size() >0)
	{
		for (int j = 0; j < collectCompTypes.size();j++)
		{
			String strCompType = (String)collectCompTypes.get(j);
			if(allUserCompTypes.contains(strCompType))
			{
				compTypeList.add(strCompType);
			}
		}
	}
	try
	{
	String strwidth = "90%";
	if(backreqMap == null || backreqMap != null && backreqMap.size() == 0)
		strwidth="100%";

	String pageTitle = "";
	if (ervm_disp != null && ervm_disp.equals("Yes"))
	{
		pageTitle = mappingInfo.getTextDescription("reporter.vmdetail.VIRTUAL MACHINES ")+" "+mappingInfo.getTextDescription("reporter.vmdetail.VM DETAILS");//PHYSICAL RESOURCES USAGE
		if (!StringUtils.isNull(titleToDisplay)){ 
			lst.add(titleToDisplay);
		}
		else
		{
			lst.add(pageTitle);
		}
	}
	else
	{
		pageTitle = mappingInfo.getTextDescription("reporter.vmdetail.VIRTUAL MACHINES ")+" "+mappingInfo.getTextDescription("reporter.vmdetail.VM DETAILS");//VIRTUAL RESOURCES USAGE
		lst.add(pageTitle);

		if (!StringUtils.isNull(titleToDisplay)){ 
			lst.add(titleToDisplay);
                }
           	else
	     	{
			lst.add(pageTitle);
		 }
	}
	screenLabels.put("pageTitle",pageTitle);
	screenLabels.put("reporter.common.Back",mappingInfo.getTextDescription("reporter.common.Back"));
	screenLabels.put("reporter.common.SAVE",mappingInfo.getTextDescription("reporter.common.SAVE"));
	screenLabels.put("reporter.common.PRINT",mappingInfo.getTextDescription("reporter.common.PRINT"));
	screenLabels.put("reporter.common.MAIL",mappingInfo.getTextDescription("reporter.common.MAIL"));
	screenLabels.put("reporter.common.CSV",mappingInfo.getTextDescription("reporter.common.CSV"));
	screenLabels.put("reporter.common.ADD TO FAVORITES",mappingInfo.getTextDescription("reporter.common.ADD TO FAVORITES"));
	screenLabels.put("reporter.common.ADD TO SCHEDULES",mappingInfo.getTextDescription("reporter.common.ADD TO SCHEDULES"));
	screenLabels.put("reporter.common.Selection",mappingInfo.getTextDescription("reporter.common.Selection"));
	screenLabels.put("reporter.thin.Component Type",mappingInfo.getTextDescription("reporter.thin.Component Type"));
	screenLabels.put("reporter.common.Report Type",mappingInfo.getTextDescription("reporter.common.Report Type"));
	screenLabels.put("reporter.esx.Virtual Machine",mappingInfo.getTextDescription("reporter.esx.Virtual Machine"));
	screenLabels.put("reporter.consolidated.Filter by VMs",mappingInfo.getTextDescription("reporter.consolidated.Filter by VMs"));
	screenLabels.put("reporter.vmdetails.Virtual Machine",mappingInfo.getTextDescription("reporter.vmdetails.Virtual Machine"));
	screenLabels.put("reporter.thin.Virtual Center",mappingInfo.getTextDescription("reporter.thin.Virtual Center"));
	screenLabels.put("reporter.vmdetails.Measure group",mappingInfo.getTextDescription("reporter.vmdetails.Measure Group"));
	screenLabels.put("reporter.common.Graph",mappingInfo.getTextDescription("reporter.common.Graph"));
	

	
	String menuForVM=request.getParameter("menuForVM");
	if(backreqMap != null && backreqMap.size() > 0 && request.getParameter("enableBack")!=null && request.getParameter("enableBack").equalsIgnoreCase("true"))
	{
		//pageParams.put("ID","backQnumber="+erhelputils.getBackID()+"&"+erhelputils.getQueryString());
		if(menuForVM!=null)
		json.put("ID","menuForVM="+menuForVM+"&backQnumber="+erhelputils.getBackID()+"&"+erhelputils.getQueryString());
		else
		json.put("ID","backQnumber="+erhelputils.getBackID()+"&"+erhelputils.getQueryString());

	}
	//if(ervm_disp != null && ervm_disp.equals("Yes")  && ( guestTypeMap == null || guestTypeMap != null && guestTypeMap.size() ==  0) || ervm_disp != null && ervm_disp.equals("No")  && ( guestTypeMap == null ||  guestTypeMap != null && guestTypeMap.size() ==  0))
	if( guestTypeMap == null || guestTypeMap.size() ==  0)
	{
		if(ervm_disp != null && ervm_disp.equals("Yes"))
		{
			pageParams.put("showUtilities","Yes");
		}
		else
		{
		pageParams.put("showUtilities","No");
		}
	}
	else if (er_type !=null && !er_type.equals("Yes"))
	{
		pageParams.put("showUtilities","Yes");
	}
	else
	{
		pageParams.put("showUtilities","Yes");
	}
	String strphysicalChecked = "";
	String strvirtualChecked = "";
	if(ervm_disp !=null && ervm_disp.equals("Yes"))
	{
		strphysicalChecked = "selected";
		strvirtualChecked = "";
	}
	else 
	{
		strphysicalChecked = "";
		strvirtualChecked = "selected";
	}

	JSONArray selectionOptsJson = new JSONArray();
	JSONObject phyResrcUsageOpt = new JSONObject();
	phyResrcUsageOpt.put("displayField",mappingInfo.getTextDescription("reporter.vmdetails.Physical Resources Usage"));
	phyResrcUsageOpt.put("valueField","Yes");
	selectionOptsJson.add(phyResrcUsageOpt);

	JSONObject virtualResrcUsageOpt = new JSONObject();
	virtualResrcUsageOpt.put("displayField",mappingInfo.getTextDescription("reporter.vmdetails.Virtual Resources Usage"));
	virtualResrcUsageOpt.put("valueField","No");
	selectionOptsJson.add(virtualResrcUsageOpt);
//ervm_disp
	json.put("selectionOptsJson",selectionOptsJson);

	pageParams.put("ervm_disp",ervm_disp);
	pageParams.put("er_type",er_type);
	pageParams.put("ervm_type",ervm_type);

	String strgraghChecked = "";
	String strdataChecked = "";
	if(er_type!=null && er_type.equals("Yes"))
	{
		strgraghChecked="checked";
	}
	else
	{
		strdataChecked="checked";
	}
	JSONArray repTypeOptsJson = new JSONArray();
	JSONObject graphOpt = new JSONObject();
	graphOpt.put("displayField",mappingInfo.getTextDescription("reporter.common.Graph"));
	graphOpt.put("valueField","Yes");
	repTypeOptsJson.add(graphOpt);

	JSONObject dataOpt = new JSONObject();
	dataOpt.put("displayField",mappingInfo.getTextDescription("reporter.common.Data"));
	dataOpt.put("valueField","No");
	repTypeOptsJson.add(dataOpt);
//er_type
	json.put("repTypeOptsJson",repTypeOptsJson);

	ArrayList vmList = new ArrayList();
	ArrayList listservers = new ArrayList();
	ArrayList selectedList = new ArrayList();
	int vmLimitCount = 0;
	if (compTypeList != null  && er_comptype ==null && compTypeList.size() >0 || (er_comptype != null && er_comptype.equals("null")))
	{
		if(compTypeList!=null && compTypeList.size()>0)
		{
	 		er_comptype = (String)compTypeList.get(0);
			er_comptype = er_comptype.trim();
		}
 	}
	
	String virtual_center = "";
	if (er_comptype != null)
	{
		virtual_center = eresx.getVirtualCenter(er_comptype);
	}
	ArrayList aTemp = new ArrayList();
  	if (virtual_center != null && !virtual_center.equals(""))
	{
		aTemp.add(virtual_center);
		virtualCenters = new ArrayList(compUtils.getTypeModifyComponents(compUtils.getUserComponents(aTemp),2));
	}
	aTemp = new ArrayList();
	aTemp.add(er_comptype);
	List userservers = compUtils.getTypeModifyComponents(compUtils.getUserComponents(aTemp),2);
	if (userservers != null && userservers.size() > 0)
	{
		for (int j = 0;j < userservers.size(); j++)
		{
			String strServer = (String)userservers.get(j);
			String nickName = strServer.substring(strServer.indexOf(":")+1);
			listservers.add(nickName);
		}
	}
	if (compTypeList != null && compTypeList.size() > 0)
	{
		if (er_comptype != null && !er_comptype.equals("null"))
		{
			vmList = ervmGuest.getAllGuest("",er_comptype,urs);
 		}
		else
		{
			if(compTypeList.size() > 0)
			{
 				vmList = ervmGuest.getAllGuest("",(String)compTypeList.get(0),urs);
			}
 		}
	}
	if(isUserVmReport==null || !isUserVmReport.equalsIgnoreCase("yes")) // VM and normal comp assingned
	{
		if((vmList ==null || vmList.size()==0)&&a_userVMs!=null && a_userVMs.size()>0)
		{
			vmList = new ArrayList();
			vmList.addAll(a_userVMs);
			userservers = (ArrayList)thisuser.getVMHostHistory(strGuestVM);
			if (userservers != null && userservers.size() > 0)
			{
				listservers = new ArrayList();
				for (int j = 0;j < userservers.size(); j++)
				{
					String strServer = (String)userservers.get(j);
					String nickName = strServer.substring(0,strServer.lastIndexOf(":"));
					listservers.add(nickName);
				}
				er_component = (String[])listservers.toArray(new String[listservers.size()]);
			}
		}
	}
 	if(strGuestVM != null)
	{
		strGuestVM = strGuestVM.trim();
	}
	if(strGuestVM == null && vmList !=null && vmList.size() >0)
	{
		strGuestVM = (String)vmList.get(0);
	}
	if (strGuestVM != null)
	{
		strGuestVM = strGuestVM.trim();
		ArrayList vmrealatedcomponent = new ArrayList();
		try
		{
			vmrealatedcomponent = eresx.getEsxHostForVM(strGuestVM,er_comptype);
		}
		catch(Exception er)
		{
			er.printStackTrace();
		}
 		//ArrayList vmrealatedcomponent = eresx.getEsxHostForVM(strGuestVM,er_comptype);
 		for (int e = 0 ; e < vmrealatedcomponent.size();e++)
		{
			String strAllServer = (String)vmrealatedcomponent.get(e);
			if (listservers.contains(strAllServer))
			{
				vmhostlist.add(strAllServer);
			}
		}
	}
	ArrayList listfilterEsx = new ArrayList();
 	if (!StringUtils.isNull(er_virtualcenter) && !er_virtualcenter.trim().equals("All"))
	{
		String strComp= er_virtualcenter.substring(er_virtualcenter.indexOf(":")+1);
		if (strComp.indexOf(":NULL") > -1)
		{
			strComp = strComp.substring(0,strComp.indexOf(":"));
		}
		String port_no = er_virtualcenter.substring(er_virtualcenter.lastIndexOf(":")+1);
		HashMap  mappedEsx = eresx.getEsxHostForVC(virtual_center,urs,strComp,port_no,"VIRTUAL_CENTER");
		
		ArrayList listEsxServers = new ArrayList();
		
		if (er_comptype != null)
		{
			listEsxServers =(ArrayList)mappedEsx.get(er_comptype);
		}

 		if (vmhostlist != null && vmhostlist.size() > 0)
		{
			for (int j = 0; j < listEsxServers.size(); j++)
			{
				String strHostName = (String)listEsxServers.get(j);
				strHostName = strHostName.substring(strHostName.indexOf(":")+1);
				if (vmhostlist.contains(strHostName.trim()))
				{
					listfilterEsx.add(strHostName);
				}
			}
		}
		vmhostlist = listfilterEsx;
	}
	if(er_component == null && vmhostlist != null)
	{
		er_component = (String[])vmhostlist.toArray(new String[0]);
	}
	if(er_component != null)
	{
		selectedList.addAll(Arrays.asList(er_component));
	}
	session.setAttribute("componame",selectedList);
	String moreUsers = reportinfo.getValue(sub,"moreVMS");
	if (!moreUsers.equals(""))
	{
		vmLimitCount = Integer.parseInt(moreUsers.trim());
	}
	
	String strVMs = "";
	/*for (int v = 0 ;v < vmList.size(); v++)
	{
		strVMs+=(String)vmList.get(v)+",";
	}
	if(strVMs != null && strVMs.length() > 1)
	{
		strVMs = strVMs.substring(0,strVMs.length()-1);
	}
	*/
	hiddenParams.put("vmStrData","");
	if(hasVMs)
	{
		compTypeList.add("Virtual_Machine");
	}
	if(vmList != null && vmList.size() < vmLimitCount)
	{
		//er_comptype		
		JSONArray compTypeJson = new JSONArray();
		if (compTypeList != null && compTypeList.size() == 1)
		{
			JSONObject jObj = new JSONObject();
			jObj.put("displayField",mappingInfo.getComponentTypeDescription(er_comptype));
			jObj.put("valueField",er_comptype);
			compTypeJson.add(jObj);
			pageParams.put("selectedCompType",er_comptype);
		}
		else if (compTypeList != null && compTypeList.size() > 1)
		{
			if (compTypeList != null && compTypeList.size() >0)
			{
				compTypeList=sorter.getSortedCompTypeList(compTypeList);
				for (int g = 0;g < compTypeList.size();g++)
				{
					EgName nameObj =(EgName) compTypeList.get(g);
					String strCompType = nameObj.getActualName();
					JSONObject jObj = new JSONObject();
					jObj.put("displayField",nameObj.getLocalName());
					jObj.put("valueField",strCompType);
					compTypeJson.add(jObj);	
				}
				if(!StringUtils.isNull(er_comptype))
				{
					pageParams.put("selectedCompType",er_comptype);
				}
			}
		}
		else
		{
			JSONObject jObj = new JSONObject();
			jObj.put("displayField",mappingInfo.getTextDescription("reporter.common.Not Applicable"));
			jObj.put("valueField","Not Applicable");
			compTypeJson.add(jObj);
			pageParams.put("selectedCompType","Not Applicable");
		}
		json.put("compTypeJson",compTypeJson);
		//select_vm
		/*if(vmList==null || (vmList != null && vmList.isEmpty()))
		{
			vmList = ervmGuest.getAllGuest("",er_comptype,urs);
		}*/
		if (isUserVmReport == null || !isUserVmReport.equalsIgnoreCase("yes")){
		JSONArray vmOptsJson = new JSONArray();
		if(vmList != null && vmList.size() > 0)
		{
			vmList.remove("");
			Collections.sort(vmList,String.CASE_INSENSITIVE_ORDER);
			Iterator itrVMList = vmList.iterator();
			while(itrVMList.hasNext())
			{
				String vmName = (String) itrVMList.next();
				JSONObject jObj = new JSONObject();
				jObj.put("displayField",vmName);
				jObj.put("valueField",vmName);
				vmOptsJson.add(jObj);
			}
			if(!StringUtils.isNull(strGuestVM) && !strGuestVM.equals("Not Applicable"))
			{
				if(strGuestVM.indexOf("_on_")>-1)
				{
					strGuestVM = strGuestVM.substring(strGuestVM.indexOf("_on_")+4);
				}
				pageParams.put("selectedVM",strGuestVM);
			}
			else
			{
				String defaultVM = (String)vmList.get(0);
				pageParams.put("selectedVM",defaultVM);
			}
		}
		else
		{
			JSONObject jObj = new JSONObject();
			jObj.put("displayField",mappingInfo.getTextDescription("reporter.common.Not Applicable"));
			jObj.put("valueField","Not Applicable");
			vmOptsJson.add(jObj);
			pageParams.put("selectedVM","Not Applicable");
		}
		json.put("vmOptsJson",vmOptsJson);
		}
	}
	else
	{
		String skinColor = "";
		skinColor = thisuser.getReporterSkin();
		JSONArray compTypeJson =  new JSONArray();
		//er_comptype
		if (compTypeList != null && compTypeList.size() == 1)
		{
			JSONObject jObj = new JSONObject();
			jObj.put("displayField",mappingInfo.getComponentTypeDescription(er_comptype));
			jObj.put("valueField",er_comptype);
			compTypeJson.add(jObj);
			pageParams.put("selectedCompType",er_comptype);
		}
		else if (compTypeList != null && compTypeList.size() > 1)
		{
			for (int g = 0;g < compTypeList.size();g++)
			{
				String strCompValue = (String)compTypeList.get(g);
				JSONObject jObj = new JSONObject();
				jObj.put("displayField",mappingInfo.getComponentTypeDescription(strCompValue));
				jObj.put("valueField",strCompValue);
				compTypeJson.add(jObj);
			}
			if(!StringUtils.isNull(er_comptype))
			{
				pageParams.put("selectedCompType",er_comptype);
			}
		}
		else
		{
			JSONObject jObj = new JSONObject();
			jObj.put("displayField",mappingInfo.getTextDescription("reporter.common.Not Applicable"));
			jObj.put("valueField","Not Applicable");
			compTypeJson.add(jObj);
			pageParams.put("selectedCompType","Not Applicable");
		}

		json.put("compTypeJson",compTypeJson);

		String dispsearch="";
		if(search == null)
		{
			dispsearch = "";
		}
		else
		{
			dispsearch = search;
		}
		
		//search
		ArrayList searchvmList = (ArrayList)request.getAttribute("allguestNames");
   		if (searchvmList !=null && searchvmList.size() > 0)
		{
			vmList=searchvmList;
		}
		else
		{
			if(search != null && search.equals(""))
			{
				vmList = ervmGuest.getAllGuest("",er_comptype,urs);
			}
		}
		//select_vm
		if (isUserVmReport == null || !isUserVmReport.equalsIgnoreCase("yes")){
		JSONArray vmOptsJson = new JSONArray();
 		if(vmList == null || vmList.size() == 0 )
		{
			JSONObject noDataOpt = new JSONObject();
			noDataOpt.put("displayField",mappingInfo.getTextDescription("reporter.esx.Not Applicable"));
			noDataOpt.put("valueField","Not Applicable");
			vmOptsJson.add(noDataOpt);
			pageParams.put("selectedVM","Not Applicable");
		}
		else
		{
			Collections.sort(vmList,String.CASE_INSENSITIVE_ORDER);
			JSONObject defaultDataOpt = new JSONObject();
			defaultDataOpt.put("displayField",mappingInfo.getTextDescription("reporter.esx.Please choose a Virtual Machine"));
			defaultDataOpt.put("valueField","-1");
			vmOptsJson.add(defaultDataOpt);

			Iterator itrGuestVms = vmList.iterator();
			while(itrGuestVms.hasNext())
			{
				String vmName = (String) itrGuestVms.next();
				JSONObject vmOpt = new JSONObject();
				vmOpt.put("displayField",vmName);
				vmOpt.put("valueField",vmName);
				vmOptsJson.add(vmOpt);
			}

			if(StringUtils.isNull(strGuestVM))
			{
				pageParams.put("selectedVM","-1");
			}
			else
			{
				if(strGuestVM.indexOf("_on_")>-1)
				{
					strGuestVM = strGuestVM.substring(strGuestVM.indexOf("_on_")+4);
				}
				pageParams.put("selectedVM",strGuestVM);
			}
		}
		json.put("vmOptsJson",vmOptsJson);
		}
	}
	//er_virtualcenter
	
	//virtualCenters List to Set convertion for eliminating Duplicates
	Set<String> virtualCenters_set_temp = new HashSet<String>();
	if (virtualCenters != null && virtualCenters.size() > 0)
	{
		virtualCenters_set_temp = new HashSet<String>(virtualCenters);
	}

	if (virtualCenters_set_temp != null && virtualCenters_set_temp.size() > 0)
	{
		virtualCenters = new ArrayList<String>(virtualCenters_set_temp);
	}
	

	JSONArray vcOptsJson = new JSONArray();
	if (virtualCenters != null && virtualCenters.size() > 0)
	{
		pageParams.put("showVcCombo","true");
		JSONObject defaultOpt =  new JSONObject();
		defaultOpt.put("displayField",mappingInfo.getTextDescription("reporter.common.All"));
		defaultOpt.put("valueField","All");
		vcOptsJson.add(defaultOpt);

		for (int g = 0;g < virtualCenters.size();g++)
		{
			String strCompValue = (String)virtualCenters.get(g);
			String strCompType= strCompValue.substring(0,strCompValue.indexOf(":"));
			String strComp= strCompValue.substring(strCompValue.indexOf(":")+1);
			if (strComp.indexOf(":NULL") > -1)
			{
				strComp = strComp.substring(0,strComp.indexOf(":"));
			}
			JSONObject vcOpt =  new JSONObject();
			vcOpt.put("displayField",mappingInfo.getComponentTypeDescription(strCompType)+":"+strComp);
			vcOpt.put("valueField",strCompValue);
			vcOptsJson.add(vcOpt);
		}
		json.put("vcOptsJson",vcOptsJson);
		if(StringUtils.isNull(er_virtualcenter))
		{
			pageParams.put("selectedVc","All");
		}
		else
		{
			pageParams.put("selectedVc",er_virtualcenter);
		}
	}
	else
	{
		pageParams.put("showVcCombo","false");
	}
	EgServicesInfo si = new EgServicesInfo("manager");
	boolean computsum = si.getAvgSumTrends();
	String trenddata=request.getParameter("er_trenddata");
	if(trenddata!=null &&  trenddata.equalsIgnoreCase("Yes"))
	{
		pageParams.put("selectedShowDataOption",trenddata);
	}
	else
	{
		pageParams.put("selectedShowDataOption","No");
	}
	screenLabels.put("reporter.common.Hypervisors",mappingInfo.getTextDescription("reporter.common.Hypervisors"));
	if(er_type != null && er_type.equals("Yes"))
	{
		//er_measure
		JSONArray measureGroupOptsJson = new JSONArray();
		if (listMeasure != null && listMeasure.size() > 0)
		{
			Collections.sort(listMeasure,String.CASE_INSENSITIVE_ORDER);
			if(listMeasure.size() > 1)
			{
				listMeasure.add("All");
			}
			JSONObject defaultOpt = new JSONObject();
			defaultOpt.put("displayField",mappingInfo.getTextDescription("reporter.vmdetails.Please choose a Measure Group"));
			defaultOpt.put("valueField","-1");
			measureGroupOptsJson.add(defaultOpt);
			for (int t = 0; t < listMeasure.size(); t++)
			{
				String strMeasure = (String)listMeasure.get(t);
				if (strMeasure != null && strMeasure.equals("Timein_usage")&& ervm_disp != null && ervm_disp.equals("Yes"))
					continue;
				String dispstrmeas="";
				if(strMeasure != null && strMeasure.equals("Timein_usage"))
				{
					dispstrmeas = "Uptime Status";
				}
				else if(strMeasure != null && strMeasure.equals("TcpIp_usage"))
				{
					dispstrmeas = "Tcp_Connection";
				}
				else
				{
					dispstrmeas = strMeasure;
				}
				String strdispstrmeas =mappingInfo.getTextDescription("reporter.vmdetails."+dispstrmeas);
				JSONObject measGrpOpt = new JSONObject();
				measGrpOpt.put("displayField",strdispstrmeas);
				measGrpOpt.put("valueField",strMeasure);
				measureGroupOptsJson.add(measGrpOpt);
			}
			if(StringUtils.isNull(strReqMeasure))
			{
				pageParams.put("selectedMeasureGrp","-1");
			}
			else
			{
				pageParams.put("selectedMeasureGrp",strReqMeasure);
			}
 		}
		else
		{
			JSONObject defaultOpt = new JSONObject();
			defaultOpt.put("displayField",mappingInfo.getTextDescription("reporter.common.Not Applicable"));
			defaultOpt.put("valueField","Not Appicable");
			measureGroupOptsJson.add(defaultOpt);
			pageParams.put("selectedMeasureGrp","Not Appicable");
 		}
		json.put("measureGroupOptsJson",measureGroupOptsJson);
		//er_component
		screenLabels.put("reporter.common.Show Data",mappingInfo.getTextDescription("reporter.common.Show Data"));
		JSONArray physicalServersOptsJson = new JSONArray();
		StringBuffer selectedPhyServersSb = new StringBuffer();
		if (vmhostlist == null || vmhostlist != null && vmhostlist.size() == 0)
		{
			if (!StringUtils.isNull(isUserVmReport ) && isUserVmReport.equalsIgnoreCase("yes")){
				if(er_components != null && er_components.size()>0)
				s_component_dd = (String)er_components.get(0);
			} else {
				s_component_dd = "Not Applicable";
			}
			v_comp_popup.add("Not Applicable");
			v_comp_popup_disp.add("Not Applicable !");
			JSONObject defaultOpt = new JSONObject();
			defaultOpt.put("displayField",mappingInfo.getTextDescription("reporter.common.Not Applicable"));
			defaultOpt.put("valueField","Not Appicable");
			physicalServersOptsJson.add(defaultOpt);
			pageParams.put("selectedPhyServers","Not Appicable");
		}
		else
		{
			Collections.sort(vmhostlist,String.CASE_INSENSITIVE_ORDER);
			s_component_dd = (String)vmhostlist.get(0);
			for (int t = 0; t < vmhostlist.size(); t++)
			{ 
				String strHostName = (String)vmhostlist.get(t);
				String strDispHostName = "";
				if (strHostName.indexOf(":NULL") > -1)
				{
					strDispHostName = strHostName.substring(0,strHostName.indexOf(":"));
				}
				else
				{
					strDispHostName = strHostName;
				}
				v_comp_popup.add(strHostName);
				v_comp_popup_disp.add(strDispHostName);
				JSONObject phyServerOpt = new JSONObject();
				phyServerOpt.put("displayField",strDispHostName);
				phyServerOpt.put("valueField",strHostName);
				physicalServersOptsJson.add(phyServerOpt);				
				if(strHostName != null && selectedList.contains(strHostName))
				{
					selectedPhyServersSb.append(","+strHostName);
				}
			}
		}
		if(selectedPhyServersSb!=null)
		{
			String selectedPhyServers = selectedPhyServersSb.toString();
			if(selectedPhyServers!=null && selectedPhyServers.indexOf(",")==0)
			{
				selectedPhyServers = selectedPhyServers.substring(1);
			}
			pageParams.put("selectedPhyServers",selectedPhyServers);
		}
		json.put("physicalServersOptsJson",physicalServersOptsJson);
	}
	else
	{
		JSONArray physicalServersOptsJson = new JSONArray();
		StringBuffer selectedPhyServersSb = new StringBuffer();
		if (vmhostlist == null || vmhostlist != null && vmhostlist.size() == 0)
		{
			s_component_dd = "Not Applicable";
			v_comp_popup.add("Not Applicable");
			v_comp_popup_disp.add("Not Applicable !");
			JSONObject defaultOpt = new JSONObject();
			defaultOpt.put("displayField",mappingInfo.getTextDescription("reporter.common.Not Applicable"));
			defaultOpt.put("valueField","Not Appicable");
			physicalServersOptsJson.add(defaultOpt);
			pageParams.put("selectedPhyServers","Not Appicable");
		}
		else
		{
			Collections.sort(vmhostlist,String.CASE_INSENSITIVE_ORDER);
			s_component_dd = (String)vmhostlist.get(0);
			for (int t = 0; t < vmhostlist.size(); t++)
			{ 
				String strHostName = (String)vmhostlist.get(t);
				String strDispHostName = "";
				if (strHostName.indexOf(":NULL") > -1)
				{
					strDispHostName = strHostName.substring(0,strHostName.indexOf(":"));
				}
				else
				{
					strDispHostName = strHostName;
				}
				JSONObject phyServerOpt = new JSONObject();
				phyServerOpt.put("displayField",strDispHostName);
				phyServerOpt.put("valueField",strHostName);
				physicalServersOptsJson.add(phyServerOpt);				
				if(strHostName != null && selectedList.contains(strHostName))
				{
					selectedPhyServersSb.append(","+strHostName);
				}
			}
			if(selectedPhyServersSb!=null)
			{
				String selectedPhyServers = selectedPhyServersSb.toString();
				if(selectedPhyServers!=null && selectedPhyServers.indexOf(",")==0)
				{
					selectedPhyServers = selectedPhyServers.substring(1);
				}
				pageParams.put("selectedPhyServers",selectedPhyServers);
			}
			json.put("physicalServersOptsJson",physicalServersOptsJson);
		}
	}
	String er_excwewee = request.getParameter("er_excwe");
	if(computsum)
	{
		pageParams.put("showDataCombo","true");

		JSONArray dataOpts = new JSONArray();
		JSONObject detailedOpt = new JSONObject();
		detailedOpt.put("displayField",mappingInfo.getTextDescription("reporter.common.Detailed"));
		detailedOpt.put("valueField","No");
		dataOpts.add(detailedOpt);

		JSONObject trendOpt = new JSONObject();
		trendOpt.put("displayField",mappingInfo.getTextDescription("reporter.common.Trend"));
		trendOpt.put("valueField","Yes");
		dataOpts.add(trendOpt);

		json.put("dataOpts",dataOpts);

	}
	else
	{
		pageParams.put("showDataCombo","false");
	}

	JSONArray yesNoOpts = new JSONArray();
	JSONObject yesOpt = new JSONObject();
	yesOpt.put("displayField",mappingInfo.getTextDescription("reporter.common.Yes")+" ("+reportinfo.getExcludeWeekend(sub)+") ");
	yesOpt.put("valueField","Yes");
	yesNoOpts.add(yesOpt);

	JSONObject noOpt = new JSONObject();
	noOpt.put("displayField",mappingInfo.getTextDescription("reporter.common.No"));
	noOpt.put("valueField","No");
	yesNoOpts.add(noOpt);

	json.put("yesNoOpts",yesNoOpts);

	if(!StringUtils.isNull(er_excwewee))
	{
		pageParams.put("execludeWeekEnd",er_excwewee);
	}
	else
	{
		pageParams.put("execludeWeekEnd","No");
	}
	String weekend=request.getParameter("er_excwe");
	String csv_wk="";
	if(weekend!=null && weekend.equalsIgnoreCase("Yes"))
			 csv_wk=mappingInfo.getTextDescription("reporter.common.Exclude weekends")+" : "+reportinfo.getExcludeWeekend(sub);
	lst.add(mappingInfo.getTextDescription("reporter.common.Time period")+":"+mappingInfo.getTextDescription("reporter.common.From")+" "+request.getParameter("timefrom")+":"+request.getParameter("minfrom")+mappingInfo.getTextDescription("reporter.common.Hrs")+" "+mappingInfo.getTextDescription("reporter.common.To")+" "+request.getParameter("timeto")+":"+request.getParameter("minto")+mappingInfo.getTextDescription("reporter.common.Hrs")+","+'"'+csv_wk+'"');
	String sdate = request.getParameter("startdate");	
	String edate = request.getParameter("enddate");	
	String shr = request.getParameter("starthr");	
	String ehr = request.getParameter("endhr");	
	String smin = request.getParameter("startmin");
	String emin = request.getParameter("endmin");
	String starttimeformat1 = sdate+ " " +shr+":"+smin+" "+"Hrs ";
	String endtimeformat1   = edate+ " " +ehr+":"+emin+" Hrs ";

		EgTimeZoneConverter converterStart=null;
		EgTimeZoneConverter converterEnd=null;
		String st_dateTime="";
		String en_dateTime="";
		if(sdate!=null)
		{
			if(DateUtil.isDate(sdate,"MM/dd/yyyy"))
			{
				comFormat = "MM/dd/yyyy";
			}
			else
			{
				comFormat = currentDateFormat;
			}
			dispDate = 	DateUtil.changeDateFormat(sdate,comFormat,currentDateFormat);
			converterStart = new EgTimeZoneConverter(dispDate+" "+shr+":"+smin,thisuser);
			st_dateTime=converterStart.getDateTime()+" "+"Hrs ";
		}
		if(edate!=null)
		{
			if(DateUtil.isDate(edate,"MM/dd/yyyy"))
			{
				comFormat = "MM/dd/yyyy";
			}
			else
			{
			comFormat = currentDateFormat;
			}
			dispDate = 	DateUtil.changeDateFormat(edate,comFormat,currentDateFormat);
			converterEnd = new EgTimeZoneConverter(dispDate+" "+ehr+":"+emin,thisuser);
			en_dateTime=converterEnd.getDateTime()+" "+"Hrs ";
		}
	Vector dvec = new Vector();
	String stimefmt = "Start Date : "+st_dateTime;
	String etimefmt = "End Date : "+en_dateTime;
	dvec.add('"'+stimefmt+'"');
	dvec.add('"'+etimefmt+'"');
	lst.add(dvec);

	screenLabels.put("reporter.common.Exclude weekends",mappingInfo.getTextDescription("reporter.common.Exclude weekends"));
	screenLabels.put("reporter.common.Excludes",mappingInfo.getTextDescription("reporter.common.Excludes")+" "+reportinfo.getExcludeWeekend(sub));

	screenLabels.put("reporter.common.Time period",mappingInfo.getTextDescription("reporter.common.Time period"));
	screenLabels.put("reporter.common.Timeline",mappingInfo.getTextDescription("reporter.common.Timeline"));
	screenLabels.put("reporter.common.From",mappingInfo.getTextDescription("reporter.common.From"));
	screenLabels.put("reporter.common.Hrs",mappingInfo.getTextDescription("reporter.common.Hrs"));
	screenLabels.put("reporter.common.Mins",mappingInfo.getTextDescription("reporter.common.Mins"));
	screenLabels.put("reporter.common.To",mappingInfo.getTextDescription("reporter.common.To"));
	screenLabels.put("reporter.common.Report Generation",mappingInfo.getTextDescription("reporter.common.Report Generation"));
	screenLabels.put("reporter.common.Report Name",mappingInfo.getTextDescription("reporter.common.Report Name"));

	pageParams.put("Hourto",Hourto);
	pageParams.put("Minto",Minto);
	pageParams.put("Hourfrom",Hourfrom);
	pageParams.put("Minfrom",Minfrom);
%>
	<%@  include file ="ErTimeFormatJSON.jsp"%>

<%
	hiddenParams.put("er_usertimeline",strUsrTimeline);
	json.put("timelineComboArray",timelineComboArray);
	pageParams.put("startDateJSON",startDateJSON);
	pageParams.put("endDateJSON",endDateJSON);
	pageParams.put("startHourJSON",startHourJSON);
	pageParams.put("endHourJSON",endHourJSON);
	pageParams.put("selectedTimeline",er_timeline);
	pageParams.put("startmin",startMin);
	pageParams.put("endmin",endMin);
	
	//User TimeZone changes
	pageParams.put("startDateForDisplay",startDateForDisplay);
	pageParams.put("startHourForDisplay",startHourForDisplay);
	pageParams.put("endDateForDisplay",endDateForDisplay);
	pageParams.put("endHourForDisplay",endHourForDisplay);
	pageParams.put("startMinForDisplay",startMinForDisplay);
	pageParams.put("endMinForDisplay",endMinForDisplay);
	chartTypeForUI=ErHighchartUtils.getChartType(startDateForHighchart,endDateForHighchart,currentDateFormat+" HH:mm");
	json.put("chartType",chartTypeForUI);

	String  pdfStartDate = startDateForDisplay+" "+startHourForDisplay+":"+startMinForDisplay;
	String pdfEndDate = endDateForDisplay+" "+endHourForDisplay+":"+endMinForDisplay;

	JSONArray repGenOpts = new JSONArray();
	JSONObject foreGdOpt = new JSONObject();
	foreGdOpt.put("displayField",strforeground);
	foreGdOpt.put("valueField","foreground");
	repGenOpts.add(foreGdOpt);
	
	JSONObject bgOpt = new JSONObject();
	if (er_type != null && er_type.equals("No"))
	{
		bgOpt.put("displayField","Background Save - CSV");
		bgOpt.put("valueField","background-csv");
		repGenOpts.add(bgOpt);
	}
	bgOpt = new JSONObject();
	bgOpt.put("displayField",strbackground);
	bgOpt.put("valueField","background");
	repGenOpts.add(bgOpt);

	json.put("repGenOpts",repGenOpts);

	String er_reportgenration = request.getParameter("er_reportgenration");
	if(StringUtils.isNull(er_reportgenration))
		er_reportgenration = "foreground";

	pageParams.put("er_reportgenration",er_reportgenration);
	String bg_reportname = request.getParameter("bg_reportname");
	String submitBtnLbl = "";
	if(reqFromSchedule!=null && reqFromSchedule.equalsIgnoreCase("Yes"))
	{
		submitBtnLbl = mappingInfo.getTextDescription("reporter.common.SAVE");
	}
	else
	{
		submitBtnLbl = mappingInfo.getTextDescription("reporter.common.SUBMIT");
	}
	screenLabels.put("submitBtnLbl",submitBtnLbl);
	if(bggroundStr != null && !bggroundStr.equals(""))
	{
		if(status != null && (status.equalsIgnoreCase("duplicate") || status.equalsIgnoreCase("exceedLimit")))
		{
			strreportName ="All Report Types";
		}
		if(strreportName!=null && strreportName.indexOf(" ") > -1)
		{
			strreportName = com.eg.EgURLEncoder.encode(strreportName, "UTF-8");
		}
		String bgLangSupportStr=bggroundStr;
		if(status != null && !status.equalsIgnoreCase("exceedLimit"))
		{
			bgLangSupportStr=erbgreport.getlangsupportedString(bggroundStr,bgString,urs);
		}
		String bgLinkUrl = "/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&er_bgreportfrom="+strreportName;
		String bgLinkMsg = mappingInfo.getTextDescription("reporter.common.Click here to see a list of generated and processing reports");
		pageParams.put("bgLangSupportStr",bgLangSupportStr);
		pageParams.put("bgLinkUrl",bgLinkUrl);
		pageParams.put("bgLinkMsg",bgLinkMsg);
		pageParams.put("bggroundStr",bggroundStr);
		pageParams.put("status",status);
	}
	hiddenParams.put("trendenable",String.valueOf(computsum));
try
{
 	if(bggroundStr == null ||bggroundStr != null && bggroundStr.equals(""))
	{
%>
	<%@ include file="ErEsxVMDataincludeJson.jsp" %>
<%
	}
	session.setAttribute("list",lst);
}
catch(Exception e)
{
	e.printStackTrace();
}
	session.setAttribute("guestTypeMap",guestTypeMap);
	session.setAttribute("poweredOn",powerOnPerCentMap);
	session.setAttribute("GuestResourceTypeMap",GuestResourceTypeMap);

	json.put("hiddenParams",hiddenParams);
	json.put("screenLabels",screenLabels);
	json.put("pageParams",pageParams);
	response.setContentType("application/json;charset=UTF-8");
	response.getWriter().write(json.toString());

	String strQueryforfraph = "/final/servlet/com.eg.ErEsxVMServerReportC?vmGraph=yes&startmin="+strmin+"&endmin="+enmin+"&er_rtype=server&timefrom="+timefrom2+"&timeto="+timeto2+"&minfrom="+minfrom2+"&minto="+minto2+"&er_excwe="+request.getParameter("er_excwe")+"&er_timeline="+URLEncoder.encode(er_timeline)+"&userID="+urs+"&er_trenddata=No&starthr="+s_st_hr+"&endhr="+s_en_hr+"&st_date="+startDate+"&en_date="+endDate+"&inidate="+URLEncoder.encode(currentDateFormat)+"&option=operation&search=&forResoures=Yes&er_mode="+er_mode+"&er_type="+er_type+"&isSubmit=true&er_comptype="+er_comptype;
	if (strGuestVM != null )
	{
 		strQueryforfraph += "&select_vm="+EgURLEncoder.encode(strGuestVM,"UTF-8");
	}
	if (selectedList != null && selectedList.size() > 0)
	{
		for (int d = 0; d < selectedList.size(); d++)
		{
			String strselectcomp = (String)selectedList.get(d);
			strQueryforfraph+="&er_component="+strselectcomp;
		}
	}
	Map param = request.getParameterMap();
	Set s_param = param.keySet();
	String queryString = "";
	Iterator i_param = s_param.iterator();
	while(i_param.hasNext())
	{
		String st_key = (String)i_param.next();
		String value = "";
		try
		{
			value = (String)param.get(st_key);
			if(value != null && st_key != null && st_key.equals("select_vm"))
			{
				queryString+="&"+st_key+ "=" +EgURLEncoder.encode(value,"UTF-8");
			}
			if(value != null && value.indexOf(" ")>-1)
			{
				queryString+="&"+st_key+ "=" +EgURLEncoder.encode(value,"UTF-8");
			}
			else
			{
				queryString+="&"+st_key+ "=" +value;
			}
		}
		catch(ClassCastException e)
		{
			value=((String[])param.get(st_key))[0];
			if(st_key != null && st_key.equals("select_vm")&& value != null)
			{
				queryString += "&"+st_key+ "=" +EgURLEncoder.encode(value, "UTF-8");
			}
			else
			{
				if(value != null && value.indexOf(" ") > -1)
				{
					queryString += "&"+st_key+ "=" +EgURLEncoder.encode(value,"UTF-8");
				}
				else
				{
					queryString += "&"+st_key+ "=" +value;
				}
			}
 		}
	}
	HashMap queryMap = new HashMap(erUtils.parseQueryString(queryString));
	queryString = "/final/servlet/com.eg.ErEsxVMServerReportC?"+queryString.substring(1,queryString.length());

	session.setAttribute("querygraph",strQueryforfraph);
	String strScheme = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort();
	if (er_type != null && er_type.equals("Yes"))
	{
		queryMap.put("strScheme",strScheme);
		session.setAttribute("querygraph",strQueryforfraph+"&er_height=250&er_width=380");
	}
	else
	{
		HashMap typemap = new HashMap();
		typemap.put("guestTypeMap",guestTypeMap);
		typemap.put("vmInformationList",vmInformationList);
		typemap.put("hashAvgMap",hashAvgMap);
		session.setAttribute("pdfMap",typemap);
	}
 		session.setAttribute("reqMap",queryMap);

	String encodecurrentDateFormat="";
	if(currentDateFormat != null)
	{
		encodecurrentDateFormat = EgURLEncoder.encode(currentDateFormat,"UTF-8");
	}
	String encodeer_timeline="";
	if(er_timeline != null)
	{
		encodeer_timeline = EgURLEncoder.encode(er_timeline,"UTF-8");
	}
	String encodeselect_vm="";
	if(request.getParameter("select_vm") != null)
	{
		encodeselect_vm = EgURLEncoder.encode(request.getParameter("select_vm"),"UTF-8");
	}

		startDate = DateUtil.changeDateFormat(s_st_time.trim(),"dd-MM-yyyy",currentDateFormat);
		endDate = DateUtil.changeDateFormat(s_en_time.trim(),"dd-MM-yyyy",currentDateFormat);
	String dataProcess = mngrIProc+"/final/reporter/ErVMDetailsPrint.jsp;jsessionid="+ session.getId()+"?"+"ervm_disp="+request.getParameter("ervm_disp")+"&stdate="+EgURLEncoder.encode(startDate,"UTF-8")+"&endate="+EgURLEncoder.encode(endDate,"UTF-8")+"&Hourfrom="+Hourfrom+"&Minfrom="+Minfrom+"&Hourto="+Hourto+"&Minto="+Minto+"&starthr="+s_st_hr+"&endhr="+s_en_hr+"&stmin="+startMin+"&enmin="+endMin+"&select_vm="+encodeselect_vm+"&ervm_disp="+ervm_disp+"&selectedCompType="+er_comptype+"&er_timeline="+encodeer_timeline+"&er_type="+er_type+"&er_measure="+request.getParameter("er_measure")+"&sortduration="+sortduration+"&inidate="+encodecurrentDateFormat;
	session.setAttribute("MAIL_URL",dataProcess);
}
	catch(Exception e)
	{
		e.printStackTrace();
	}
	
	String QueryString =(String)ErUtils.prepareQueryString(request.getParameterMap());
	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.equals("userID"))
			{
				value=com.eg.EgURLEncoder.encode(value, "UTF-8");
			}
			if(reqparam!=null&&reqparam.equals("eruserid"))
			{
				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("st_date"))
			{
				value=com.eg.EgURLEncoder.encode(value, "UTF-8");
			}
			if(reqparam!=null&&reqparam.equals("en_date"))
			{
				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("select_vm"))
			{
				value=com.eg.EgURLEncoder.encode(value, "UTF-8");
			}
			if(reqparam!=null&&reqparam.equals("currentformat"))
			{
				value=com.eg.EgURLEncoder.encode(value, "UTF-8");
			}
			Qstring=Qstring+reqparam+"="+value+"&";
		}
	}
//Back button - Start
ArrayList listbackvar = new  ArrayList();

if(request.getParameter("isSubmit") != null)
{
	session.setAttribute("reportLastAccessedURL","/final/reporter/ErEsxGuestReport.jsp?"+"enableBack=false&"+Qstring);

	listbackvar.add("ErEsxGuestReport.jsp?");
	listbackvar.add("status="+status+"&bggroundStr="+bggroundStr+"&"+QueryString);
	session.setAttribute("favSchBackDisplay","Yes");
}
else
{
	session.setAttribute("reportLastAccessedURL","/final/reporter/ErEsxGuestReport.jsp?"+Qstring);
	listbackvar.add("ErEsxGuestReport.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
}
catch(Exception e)
{
	e.printStackTrace();
}
	//For Setting the PDf File Name
	String report_Type = request.getParameter("er_type");
	HashMap paramVal =new HashMap();
	if(report_Type!=null && report_Type.equalsIgnoreCase("Yes"))
		paramVal.put("fileName","VirtualMachineDetailsReport_Graph");
	else if(report_Type!=null && report_Type.equalsIgnoreCase("No"))
		paramVal.put("fileName","VirtualMachineDetailsReport_Data");
	session.setAttribute("parameters", paramVal);
%>