<%@  page pageEncoding="utf-8" contentType="text/html;charset=utf-8" import="com.novell.webaccess.common.JSPConduit, com.novell.emframe.dev.eMFrameUtils" %>
<%   JSPConduit c = JSPConduit.getJSPConduit(request);
   c.stringTable("DevResources");
   c.stringTable("FwResources"); %>
<HTML>
<HEAD>
<TITLE><%= c.toHTML(c.string("RBSManagement.CreateRoleTitle")) %></TITLE>
<LINK href="<%= c.getModulesUrl() + "/dev/css/hf_style.css" %>" rel="styleSheet" type="text/css">
<jsp:include page='<%= c.getPath("dev/eMFrameScripts_inc.jsp") %>' flush="true" />
<jsp:include page='<%= c.getPath("dev/OSScripts_inc.jsp") %>' flush="true" />
<style>
.gray
{
background-color: #bfbfbf;
}
</style>
<SCRIPT language="JavaScript">


   //==================================
   // onPageLoad()
   //==================================
   function onPageLoad()
   {
   	// Set this for the ObjectSelector
      returnFromOS();
      setSelfProvisioningCheckBoxValue();
      setFocusToFormElement();
   }

   //==================================
   // setWaitCursor()
   //==================================
   function setWaitCursor()
   {
	   document.body.style.cursor="wait";
   }

   //===========================================================================================
   // setSelfProvisioningCheckBoxValue()
	//
	// This value will only be true if it was checked previously and the user is coming back from
	// the task page in the wizard.
   //===========================================================================================
   function setSelfProvisioningCheckBoxValue()
   {
   	if (document.CreateEguideRoleForm.SelfProvisioningRole.value == "true")
      {
      	document.CreateEguideRoleForm.SelfProvisioningCheckbox.checked = true;
      }
   }

   //===========================================================================================
   // checkCreateRoleNullInput()
	//
	// Called when the page is being submitted. Save off the new role name and the
	// the value of the SelfProvisioning checkbox.
   //===========================================================================================
   function checkCreateRoleNullInput()
   {
      var strContainerInput 	= document.CreateEguideRoleForm.CreateRoleContext.value;
      var strRoleNameInput 	= document.CreateEguideRoleForm.CreateRoleName.value;

      if ((null == strRoleNameInput) || (0 == strRoleNameInput.length))
      {
         alert("<%= c.toScript(c.string("CreateRole.InvalidRoleName")) %>");
         return false;
      }

      if ((null == strContainerInput) || (0 == strContainerInput.length))
      {
         alert("<%= c.toScript(c.string("CreateRole.InvalidRoleContext")) %>");
         return false;
      }

      // Make sure they haven't entered more than 1024 characters.
      var sizeOk = checkFinalTextAreaSize();
      if (sizeOk == false)
      {
      	 document.CreateEguideRoleForm.CreateRoleDescription.focus();
         return false;
      }

      // Everything is ok. Get the new role name.
      getSelectedRoleName();
	  setSelfProvisioningRole();
      setWaitCursor();

      return true;
   }

	//==================================
   // setFocusToFormElement()
   //==================================
   function setFocusToFormElement()
   {
      document.CreateEguideRoleForm.CreateRoleName.focus();
   }

   //==================================
   // onPagegetSelectedRoleNameLoad()
   //==================================
   function getSelectedRoleName()
   {
      var strCreateRoleName 		= document.CreateEguideRoleForm.elements["CreateRoleName"].value;
      var strCreateRoleContext 	= document.CreateEguideRoleForm.elements["CreateRoleContext"].value;
      var strCreateRoleFullName 	= strCreateRoleName + "." + strCreateRoleContext;

      document.CreateEguideRoleForm.elements["CreateRoleFullName"].value=strCreateRoleFullName;
      document.CreateEguideRoleForm.elements["CreateRoleDisplayName"].value=strCreateRoleName;
   }

   //==================================
   // setSelfProvisioningRole()
   //==================================
   function setSelfProvisioningRole()
   {
      var selfProvisioningRole = "false";

      // If the checkbox element is not on the page becuase the [This] flag is set to false in the
		// eMFrame.cfg file this check will return null. If the checkbox is there the value will be read
		// and used as the SelfProvisioningRole value.
      if (null != document.CreateEguideRoleForm.SelfProvisioningCheckbox)
		{
			selfProvisioningRole	= document.CreateEguideRoleForm.SelfProvisioningCheckbox.checked;
		}

		document.CreateEguideRoleForm.elements["SelfProvisioningRole"].value=selfProvisioningRole;
   }

	// Check to make sure the description attribute max size is not exceeded.
   function checkFinalTextAreaSize()
   {
      var maxlimit = 1024;

      if (document.CreateEguideRoleForm.CreateRoleDescription.value.length > maxlimit) // if too long...trim it!
		{
         var limitMessage = "<%= c.toScript(c.string("ModifyRBSObjectDescription.ExceededLimit")) %>";
         alert(limitMessage);
         document.CreateEguideRoleForm.CreateRoleDescription.value = document.CreateEguideRoleForm.CreateRoleDescription.value.substring(0, maxlimit);
         return false;
      }
      else
      {
      	return true;
      }
   }

</SCRIPT>
</HEAD>

<BODY TEXT="#000000" LINK="#000000" VLINK="#000000" ALINK="#000000" bgcolor="#FFFFFF" onLoad="onPageLoad();">
<FORM name="CreateEguideRoleForm" method=post action="webacc" onSubmit="return(checkCreateRoleNullInput())">
   <input type=hidden name="taskId" value="<%= c.var("taskId") %>">
   <input type=hidden name="merge" value="fw.ChooseTasks">
   <input type=hidden name="error" value="dev.GenErr">
   <input type=hidden name="User.context" value="<%= c.var("User.context") %>">
   <input type=hidden name="nextState" value="getTasksForRole">
   <input type=hidden name="CreateRolePreviousPage" value="CreateEguideRole">
   <input type=hidden name="CreateRoleFullName" value="<%= c.toHTML(c.var("CreateRoleFullName")) %>">
   <input type=hidden name="CreateRoleDisplayName" value="<%= c.toHTML(c.var("CreateRoleDisplayName")) %>">
   <input type=hidden name="CreateEguideRole" value="true">
   <input type=hidden name="SelfProvisioningRole" value="<%= c.toHTML(c.var("SelfProvisioningRole")) %>">
   <input type=hidden name="RBSAdmin_RoleType" value="eGuide">
   <!-- End of hidden tags -->

<% if (session.getAttribute("DeviceType").equals("browser")) { %>
	<DIV id="Layer2" style="position:absolute; left:5px; top:4px; width:650px; height:400px; z-index:2">
<% }
      c.set("WizardHeader.title", c.toHTML(c.string("CreateEguideRole.WizardTitle")));
      c.set("WizardHeader.subtitle", c.toHTML(c.string("CreateEguideRole.Subtitle")));
      c.set("WizardHeader.helpFile", "base/createeguiderole.html");
      c.set("WizardHeader.HelpWindowWidth", "500");
      c.set("WizardHeader.HelpWindowHeight", "500"); %>
   <jsp:include page='<%= c.getPath("dev/WizardHeader_inc.jsp") %>' flush="true" />
   <TABLE width="100%" border="0" cellspacing="0" cellpadding="3">
   	<TR>
      	<TD class="mediumtext" width="48%" valign="bottom"><%= c.toHTML(c.string("CreateRole.RoleName")) %><BR>
         <input type=text name="CreateRoleName" value="<%= c.toHTML(c.var("CreateRoleDisplayName")) %>" size=35 maxlength=64></TD>
         <TD width="2%" bgcolor="#FFFFFF">&nbsp;</TD>
         <TD width="50%" bgcolor="#FFFFFF" class="instructions"><%= c.toHTML(c.string("CreateRole.Example")) %></TD>
      </TR>
      <TR>
      	<TD class="mediumtext" width="48%" valign="bottom"><%= c.toHTML(c.string("CreateRole.Collection")) %><BR>
            <% if (c.var("RBSAdmin_TaskDelegate").equals("taskDelegate") == true) { %>
               <input class="gray" type="text" name="CreateRoleContext" value="<%= c.toHTML(c.var("CreateRoleContext")) %>" size="35" readonly>
            <% } else { %>
               <input type=text name="CreateRoleContext" value="<%= c.toHTML(c.var("CreateRoleContext")) %>" size=35>
		   	      <% c.set("OS.TypeFilter", "rbsCollection2");
		   	         c.set("OS.Control", "CreateRoleContext");
                     c.set("OS.Mode", "search");
                     c.set("OS.History", "true"); %>
		   	   <jsp:include page='<%= c.getPath("dev/OS_inc.jsp") %>' flush="true" />
            <% } %>
         </TD>
         <TD width="2%" bgcolor="#FFFFFF">&nbsp;</TD>
      	<TD width="50%" bgcolor="#FFFFFF" class="instructions"><%= c.toHTML(c.string("CreateRole.EnterPath")) %></TD>
      </TR>
      <TR>
      	<TD class="mediumtext" width="48%" valign="bottom"><%= c.toHTML(c.string("CreateRole.Description")) %><BR>
         <TEXTAREA name="CreateRoleDescription" value="<%= c.var("CreateRoleDescription") %>" rows="3" cols=30 wrap="VIRTUAL" maxlength="64"><%= c.var("CreateRoleDescription") %></TEXTAREA>
         </TD>
         <TD width="2%">&nbsp;</TD>
      	<TD width="50%">&nbsp;</TD>
      </TR>
      <% if (c.var("Provider.eMFrame.This.enable").equals("true")) { %>
      <TR>
      	<TR>
      	<TD width="48%" class="mediumtext">
            <input type=checkbox	name="SelfProvisioningCheckbox"><%= c.toHTML(c.string("CreateEguideRole.AllowSelfManagement")) %>
         </TD>
         <TD width="2%" bgcolor="#FFFFFF">&nbsp;</TD>
         <TD width="50%" class="instructions"><%= c.toHTML(c.string("CreateEguideRole.Note")) %></TD>
      </TR>
      <% } %>
   </TABLE>
<% if (session.getAttribute("DeviceType").equals("browser")) { %>
	</DIV>
   <DIV id="Layer1" style="position:absolute; left:6px; top:480px; width:650px; height:80px; z-index:3">
<% } %>
   <TABLE width="100%" border="0" cellspacing="0" cellpadding="0">
      <TR>
      	<TD class="ruleabove">
         	<a href="#"><IMG src="<%= c.getModulesUrl() + "/dev/images/" + c.string("Button.BackDisabled.image") %>" alt="<%= c.toHTML(c.string("Button.BackDisabled.alt")) %>" title="<%= c.toHTML(c.string("Button.BackDisabled.alt")) %>" border=0></a>
            <INPUT type=image name="Next" alt="<%= c.toHTML(c.string("Button.Next.alt")) %>" src="<%= c.getModulesUrl() + "/dev/images/" + c.string("Button.Next.image") %>" border=0>
            <jsp:include page='<%= c.getPath("dev/Cancel_inc.jsp") %>' flush="true" />
         </TD>
      </TR>
   </TABLE>
<% if (session.getAttribute("DeviceType").equals("browser")) { %>
	</DIV>
<% } %>
</FORM>
<jsp:include page='<%= c.getPath("dev/OSFooter_inc.jsp") %>' flush="true" />
</BODY></HTML>
