<!DOCTYPE html>

<%@ include file="EgTrackerA.jsp" %>
<%@ include file="listSearchJson.jsp" %>
<%@ taglib prefix="egui" uri="../WEB-INF/eg-taglib.tld"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

<%
	response.setHeader("Cache-Control","no-store");
	response.setHeader("Pragma","no-cache");
	response.setDateHeader("Expires", -1);

	boolean isDouble = com.eg.EgDbInfo.doubleByteEnabled;
	com.eg.EgServicesInfo servicesInfo = new com.eg.EgServicesInfo("manager");
	boolean isAllowHostName = servicesInfo.isAllowHostNames();
	String currentAction = request.getParameter("server");
	if (currentAction != null && currentAction.equalsIgnoreCase("new"))
		currentAction = "add";
	String modifyserver = "no";
	if(request.getParameter("modifyserver") != null && request.getParameter("modifyserver").trim().length()>0 && !request.getParameter("modifyserver").equalsIgnoreCase("null"))
	{
		currentAction = request.getParameter("modifyserver");
		if (currentAction != null && currentAction.equalsIgnoreCase("true"))
		{
			modifyserver = "true";
			currentAction = "modify";
		}
	}
	String serverCategory = request.getParameter("serverGategory");
	String serverType = request.getParameter("serverType");
	String from = request.getParameter("from");
	String reqfrom = request.getParameter("reqfrom");
	String comptype = request.getParameter("comptype");
	String activeCompTypes = request.getParameter("activeCompTypes");
	
	String homepage_comptype = "";
	String homepage_nickport = "";
	String homepage_server = "";
	if(reqfrom != null && (reqfrom.equals("comp_mng_umng") || reqfrom.equals("discovery_mng_umng") || reqfrom.equals("comp_add_modify") || reqfrom.equals("comp_add_mod_new")))
	{
		homepage_comptype = request.getParameter("servers");
		if(homepage_comptype != null && homepage_comptype.indexOf(":")>0)
		{
			homepage_nickport = homepage_comptype.substring(homepage_comptype.indexOf(":")+1);
			homepage_server = homepage_comptype.substring(0,homepage_comptype.indexOf(":"));
		}
	}
	String queryString = "";
	if(from != null && from.equals("inventory")) // From Home>discovery pop-up
	{
		currentAction = "manage";
		queryString = request.getQueryString();
	}

	boolean firstTime = currentAction != null && currentAction.equals("modify")? true:false;
	String s_elementType = request.getParameter("elementType");
	String s_elementName = request.getParameter("elementName");
	String s_category = request.getParameter("category");
	String s_serverType = request.getParameter("serverType");
	String s_operation = request.getParameter("operation");
	String s_anchorComponent = request.getParameter("anchorComponent");
	String s_autoAssociatedToZone = request.getParameter("autoAssociatedToZone");
	String s_nickPort = request.getParameter("server");
	if(s_nickPort != null && (s_nickPort=s_nickPort.trim()).length()>0 && !s_nickPort.equalsIgnoreCase("null"))
	{
		s_nickPort = com.eg.EgURLDecoder.decode(s_nickPort,"UTF-8");
	}
	if(s_operation == null || (s_operation=s_operation.trim()).length()==0 || s_operation.equalsIgnoreCase("null"))
	{
		s_operation = "";
	}
	String displayPage = "aggNewServer.jsp";
	if(currentAction != null && currentAction.equals("modify"))
	{
		displayPage = "aggNewServer_modify.jsp";
	}

	// for limited components
	String fromWizard = request.getParameter("fromWizard");
	if(com.egurkha.util.StringUtils.isNull(fromWizard))
	{
		fromWizard = "";
	}

	String fromAction = request.getParameter("fromAction");
	if (com.egurkha.util.StringUtils.isNull(fromAction))
	{
		fromAction = "";
	}
	String classify = request.getParameter("classify");
	if (com.egurkha.util.StringUtils.isNull(classify))
	{
		classify = "";
	}

	String compGlanceCompType = request.getParameter("compGlanceCompType");
	if (com.egurkha.util.StringUtils.isNull(compGlanceCompType))
	{
		compGlanceCompType = "";
	}
	
	if(session.getAttribute("redirectPageURL") != null)
	{
		backHref = (String)session.getAttribute("redirectPageURL");
	}
	
%>
<html>
<head>
	<meta charset="utf-8">
	<title>New Aggregate Component</title>

	<egui:skin ui="admin"/>

	<script type="text/javascript" src="../extjs/ext-all.js"></script>

	<!-- Fancy Scroll-->
	<script src="/final/jquery/jquery.js"></script>
	<script src="/final/styles/jscrollpane/jquery.jscrollpane.js" ></script>
	<script src="/final/styles/jscrollpane/jquery.mousewheel.js" ></script>
	<script src="/final/styles/jscrollpane/mwheelIntent.js" ></script>
	<link rel="stylesheet" href="/final/styles/jscrollpane/jquery.jscrollpane.css"/>

	<script language="JavaScript1.2" src="eg_scripts/validate.js"></script>
	<script language="JavaScript1.2" src="../scripts/<%=script_src%>"></script>
	<!-- Application folder -->
	<script type="text/javascript" src="AggregateNewComponent/app/app.js"></script>
	<script language="JavaScript1.2">
	// for IE support startsWith and endsWith function overrides
	if (!String.prototype.startsWith) 
	{
		String.prototype.startsWith = function (searchString, position) {
			position = position || 0;
			 return this.substr(position, searchString.length) === searchString;
		};
	}

	if (!String.prototype.endsWith)
	{
		String.prototype.endsWith = function(search, this_len) {
			if (this_len === undefined || this_len > this.length) {
				this_len = this.length;
			}
			return this.substring(this_len - search.length, this_len) === search;
		};
	}

	var reqfrom = '<%=reqfrom%>';
	var comptype = '<%=comptype%>';
	var activeCompTypes = '<%=activeCompTypes%>'; 
	var homepage_nickport = '<%=homepage_nickport%>';
	var homepage_server = '<%=homepage_server%>';
	var csrfToken = '<%=strCsrfToken%>';
	var pageDesc2 = '<egui:intnl description="EgHostCheck.jsp"/>';
	var pageDesc3 = '<egui:intnl description="<%=displayPage%>"/>';
	var pageTitle = '<egui:intnl text="admin.server.Aggregate Component"/>';
	var addButtonText = '<egui:intnl text="admin.server.Add New Aggregate Component"/>';
	var noCompsAlert = '<egui:intnl text="admin.server.No aggregate components found"/>';
	var jsonDataHolder = '';
	var publicJSON = '';
	var publicJSON = '';
	var validate_publicJSON = '';
	var ctrler = '';
	var qryStr = '<%=queryString%>';
	var server='<%=request.getParameter("server")%>';
	var currentAction = '<%=currentAction%>';
	var isDoubleByteMgr='<%=isDouble%>';
	var isAllowHostName='<%=isAllowHostName%>';
	var serverCategory = '<%=serverCategory%>';
	var serverType = '<%=serverType%>';
	var addCompURL = '<%=request.getQueryString()%>';
	var fromAction = '<%=fromAction%>';
	var classify = '<%=classify%>';
	var alertMsg1 = '<egui:intnl text="admin.server.Nick name is not allowed in DBL(Chinese,Korean,Japanese),since manager is SingleByte"/>';
	/*var alertMsg2 = '<egui:intnl text="admin.server.The Operating System must be selected"/>.';
	var alertMsg3 = '<egui:intnl text="admin.server.A mode must be selected for agentless monitoring"/>.';
	var alertMsg4 = '<egui:intnl text="admin.server.Perfmon is available only for Windows operating systems"/>.';
	var alertMsg5 = '<egui:intnl text="admin.server.is not available for Windows operating systems"/>.';
	var alertMsg6 = '<egui:intnl text="admin.server.Mode should be SNMP for this server type"/>';
	var alertMsg7 = '<egui:intnl text="admin.server.Atleast one external agent must be selected"/>.';
	var alertMsg8 = '<egui:intnl text="admin.server.Please enter the port number"/>.';
	var alertMsg9 = '<egui:intnl text="admin.server.Port should be a valid number"/>';
	var alertMsg10 = '<egui:intnl text="admin.server.Port numbers cannot have decimals"/>';
	var alertMsg11 = '<egui:intnl text="admin.server.Only valid integers are allowed"/>.';
	var alertMsg12 = '<egui:intnl text="admin.common.Invalid port number"/>.';
	var alertMsg13 = '<egui:intnl text="admin.server.Spaces not allowed for port numbers"/>';
	var alertMsg14 = '<egui:intnl text="admin.server.User field cannot have a null value"/>';
	var alertMsg15 = '<egui:intnl text="admin.server.Password field cannot have a null value"/>';
	var alertMsg16 = "<egui:intnl text='admin.test.Password data should not contain pipe and double quotes'/>";
	var alertMsg17 = '<egui:intnl text="admin.server.Please do not leave blank space in the user field"/>';
	var alertMsg18 = '<egui:intnl text="admin.server.Please enter the IP address of the host"/>.';
	var alertMsg19 = '<egui:intnl text="admin.server.Please enter the IP address/host name"/>.';*/
	var alertMsg20 = '<egui:intnl text="admin.server.Your host/nick name cannot be the same as one of the internal representation types used by eG Enterprise"/>';
	var alertMsg21 = '<egui:intnl text="admin.server.Please choose another host/nick name"/>.';
	var alertMsg22 = '<egui:intnl text="admin.server.Please enter the nick name"/>';
	/*var alertMsg23 = '<egui:intnl text="admin.server.Atleast one Esx Server Host must be selected"/>.';
	var alertMsg24 = '<egui:intnl text="admin.server.Atleast one cloud Server must be selected"/>.';*/
	var alertMsg25 = '<egui:intnl text="admin.server.Please enter the same ip address if you are entering ip address for the hostname field"/>';
	var alertMsg26 = '<egui:intnl text="admin.server.Your hostname cannot be same as the component type"/>';
	/*var alertMsg27 = '<egui:intnl text="admin.server.Please enter the port number"/>.';
	var alertMsg28 = '<egui:intnl text="admin.server.Port number should be numerical or NULL"/>.';
	var alertMsg29 = '<egui:intnl text="admin.server.Please enter the SID"/>.';
	var alertMsg30 = '<egui:intnl text="admin.server.Please enter unique SID names"/>.';*/
	var alertMsg31 = '<egui:intnl text="admin.server.Hostname should not start or end with a dot"/> '+" \'.\' ";
	var alertMsg32 = '<egui:intnl text="admin.server.Please select a type of aggregate component"/>';
	var alertMsg33 = '<egui:intnl text="admin.server.Aggregate component has not been added"/>';
	var alertMsg34 = '<egui:intnl text="admin.server.Aggregate component has been added successfully"/>';
	var alertMsg35 = '<egui:intnl text="admin.server.Aggregate component has been modified successfully"/>';
	var alertMsg36 = '<egui:intnl text ="admin.server.You are modifying an existing aggregate component"/>'+". "+'<egui:intnl text ="admin.server.Please note that data already collected for this aggregate component will no longer be available after the modification"/>';
	//var alertMsg37 = '<egui:intnl text="admin.server.Removal of SID is not allowed"/>.';
	var alertMsg38 = '<egui:intnl text="admin.server.Sorry! You cannot modify a host/nick name that has been assigned to an external agent"/>';
	var alertMsg39 = '<egui:intnl text="admin.server.Sorry! You cannot modify a host/nick name that has been assigned to a remote agent"/>';
	var alertMsg40 = '<egui:intnl text="admin.server.Special Characters not allowed"/>.';
	var alertMsg41 = '<egui:intnl text="admin.server.Space not allowed"/>.';

	var label_Category = '<egui:intnl text="admin.server.Category"/>';
	var label_CompTyep = '<egui:intnl text="admin.server.Aggregate component type"/>';
	var label_HostIP = '<egui:intnl text="admin.server.Host IP/Name"/>';
	var label_Monitoring = '<egui:intnl text="admin.server.Monitoring"/>';
	var label_Component = '<egui:intnl text="admin.server.Nick name"/>';
	var label_aggregate_component = '<egui:intnl text="admin.server.Aggregate component"/>';
	var label_HostCheck1 = '<egui:intnl text="admin.server.Do you wish to rename all the components that have the old host name"/>?';
	var label_HostCheck2 = '<egui:intnl text="admin.server.Do you wish to add the new host name for this component and apply for all components"/>?';
	var label_Add = '<egui:intnl text="admin.common.Add"/>';
	var label_Update = '<egui:intnl text="admin.common.Update"/>';
	var label_Back = '<egui:intnl text="admin.common.Back"/>';
	/*var label_port = '<egui:intnl text="admin.server.Port number"/>';
	var label_sid = '<egui:intnl text="admin.server.SID"/>';
	var label_isPass = '<egui:intnl text="admin.server.Is passive"/>';
	var label_mts =  '<egui:intnl text="admin.server.MTS enabled"/>';
	var label_ExtAgents = '<egui:intnl text="admin.server.External agents"/>';
	var label_Agentless = '<egui:intnl text="admin.server.Agentless"/>';
	var label_IntAgentAssign = '<egui:intnl text="admin.server.Internal agent assignment"/>';
	var label_OS = '<egui:intnl text="admin.server.OS"/>';
	var label_Mode = '<egui:intnl text="admin.server.Mode"/>';
	var label_RemPort = '<egui:intnl text="admin.server.Remote port"/>';
	var label_RemUser = '<egui:intnl text="admin.server.User"/>';
	var label_RemPwd = '<egui:intnl text="admin.server.Password"/>';*/
	var label_ExtAgents = '<egui:intnl text="admin.server.External agents"/>';
	var label_RemAgent = '<egui:intnl text="admin.server.Remote agent"/>';
	/*var label_IntAgent = '<egui:intnl text="admin.server.Internal agent"/>';
	var label_VirEnv = '<egui:intnl text="admin.server.Virtual environment"/>';
	var label_VirServs = '<egui:intnl text="admin.server.Virtual servers"/>';
	var label_CloudEnv = '<egui:intnl text="admin.server.Cloud environment"/>';
	var label_CloudServ = '<egui:intnl text="admin.server.Cloud servers"/>';*/
	var label_Cancel = '<egui:intnl text="admin.common.Cancel"/>';
	var label_compInfo = '<egui:intnl text="admin.server.Component Information"/>';
	/*var label_monAppro = '<egui:intnl text="admin.server.Monitoring approach"/>';
	var label_extInfo = '<egui:intnl text="admin.server.Additional information"/>';*/
	var updating = '<egui:intnl text="admin.common.Updating"/>';
	var plsWait = '<egui:intnl text="admin.common.Please wait"/>';
	var backHref = '<%=backHref%>';
	
	var probsErrorMessage = '<egui:intnl text="admin.error.Problem encountered while loading the user interface"/>';
	var requestTimeOut = '<egui:intnl text="admin.error.Response timed out"/>';

	var associated_comps_alert = '<egui:intnl text="admin.server.Please associate components to aggregate component"/>';
	//var queryString = '<%=queryString%>';
	var s_elementType = '<%=s_elementType%>';
	var s_elementName = '<%=s_elementName%>';
	//var s_category = '<%=s_category%>';
	//var s_serverType = '<%=s_serverType%>';
	var s_operation = '<%=s_operation%>';
	//var s_anchorComponent = '<%=s_anchorComponent%>';
	//var s_autoAssociatedToZone = '<%=s_autoAssociatedToZone%>';
	//var s_compName = '<%=s_nickPort%>';
	//var s_modifyserver = '<%=modifyserver%>';

	/*var d_queryString = '<%=queryString%>';
	var d_elementType = '<%=s_elementType%>';
	var d_elementName = '<%=s_elementName%>';
	var d_category = '<%=s_category%>';
	var d_serverType = '<%=s_serverType%>';
	var d_operation = '<%=s_operation%>';
	var d_anchorComponent = '<%=s_anchorComponent%>';
	var d_autoAssociatedToZone = '<%=s_autoAssociatedToZone%>';
	var d_compName = '<%=s_nickPort%>';
	*/
	var confirmation1 = '<egui:intnl text="admin.user.You will lose already associated components once you modify this"/>'+". "+'<egui:intnl text="admin.server.Are you sure you want to continue?"/>';

	var firstTime = <%=firstTime%>;
	var filter_by = '<egui:intnl text="admin.server.Filter by"/>';
	var associated_components = '<egui:intnl text="admin.server.Associated components"/>';
	var available_components = '<egui:intnl text="admin.server.Available components"/>';
	var list_of_zones = '<egui:intnl text="admin.server.List of zones"/>';
	var list_of_services = '<egui:intnl text="admin.server.List of services"/>';
	var list_of_segments = '<egui:intnl text="admin.server.List of segments"/>';
	var list_of_groups = '<egui:intnl text="admin.server.List of groups"/>';
	var filter_by = '<egui:intnl text="admin.server.Filter by"/>';
	var select_comp_type = '<egui:intnl text="admin.server.Please select a aggregate component type"/>';
	var component_created_from = '<egui:intnl text="admin.server.Component created from "/>&nbsp;<%=s_elementType%>';
	var auto_associate_to_this_zone = '<egui:intnl text="admin.server.Auto associate this component to this zone"/>&nbsp;<b><%=s_elementName%></b>' ;
	var nick_exist_alert = '<egui:intnl text="admin.server.Nick name already exists"/>'+". "+'<egui:intnl text="admin.server.Please provide a new nick name"/>';
	var errorTitle = '<egui:intnl text="admin.user.Error"/>';
	var compnonetLabel = '<egui:intnl text="admin.server.Components"/>';
	var yesLabel = '<egui:intnl text="admin.common.Yes"/>';
	var noLabel = '<egui:intnl text="admin.common.No"/>';

	// wizard design starts...
	var fromWizard = '<%=fromWizard%>';
	var compGlanceCompType = '<%=compGlanceCompType%>';
	var homeTitle = '<div>'+pageTitle+' <img src="/final/images/spacer.gif" id="homeTitle" class="iconInfoCircle" style="vertical-align:text-top;position:relative;top:2px"/></div>';
	//var createZoneTitle = '<div>'+pageTitle+' <img src="/final/images/spacer.gif" id="createZoneTitle" class="iconInfoCircle" style="vertical-align:text-top;position:relative;top:2px"/></div>';
	//var childPageTitle = '<div>'+subPageTitle+' <img src="/final/images/spacer.gif" id="childPageTitle" class="iconInfoCircle" style="vertical-align:text-top;position:relative;top:2px"/></div>';

	// wizard design ends..

	Ext.onReady(function(){
		Ext.Ajax.extraParams = {"com.eg.CSRF_NONCE" : csrfToken};
		Ext.data.Connection.prototype.extraParams = {"com.eg.CSRF_NONCE" : csrfToken};
		Ext.data.ScriptTagProxy.prototype.extraParams = {"com.eg.CSRF_NONCE" : csrfToken};

		Ext.Ajax.on('requestexception', function (conn, response, options) {
			var errorStr = response.responseText;
			if (errorStr != undefined && errorStr != 'undefined' && errorStr.indexOf("customerror") != -1)
			{
				if (errorStr.indexOf("user-session-invalid") != -1)
				{
					callWindow(1);
				}
				else if (errorStr.indexOf("user-deleted") != -1)
				{
					callWindow(2);
				}
				else if (errorStr.indexOf("user-timedout") != -1)
				{
					callWindow(3);
				}
			}
			else
			{
				if (response.status == 302 || (response.timedout != undefined && response.timedout == true))
				{
					Ext.Msg.show({
						title : errorTitle,
						msg : requestTimeOut,
						buttons : Ext.Msg.OK,
						icon : 'iconError'
					});
				}
				else
				{
					console.log(response.responseText);
					Ext.Msg.show({
						title : errorTitle,
						msg : probsErrorMessage,
						buttons : Ext.Msg.OK,
						icon : 'iconError'
					});
				}
			}
		});
	});
	</script>
</head>
<BODY>
	<div id="loadmask" class="x-mask-msg x-layer x-mask-msg-default" style="z-index: 19001;left:45%;top:35%;"><div class="x-mask-loading" style="position:relative">Loading...</div></div>
</BODY>
</html>
<%

	if (com.egurkha.util.StringUtils.isNull(fromWizard))
	{
		session.setAttribute("adminLastAccessedURL","/final/admin/EgAggregateTree.jsp");
	}
%>



