<%@  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("BaseResources"); %>
<HTML>
<HEAD>
<TITLE><%= c.toDisplay(c.string("CreateAttr.Title")) %></TITLE>
<LINK rel="stylesheet" href="<%= c.getModulesUrl() + "/dev/css/hf_style.css" %>" type="text/css">
<jsp:include page='<%= c.getPath("dev/eMFrameScripts_inc.jsp") %>' flush="true" />
<jsp:include page='<%= c.getPath("dev/ValidateIntegerScripts_inc.jsp") %>' flush="true" />
</HEAD>

<!-------------------------JAVA SCRIPT BEGINS HERE------------------------------------------->
<SCRIPT language="JavaScript">

function nextSelected()
{
   // to validate the ASN1ID since Netscape had problems with onblur
   if (!validateASN1IDString(document.EnterAttrNameForm.NewAttrID, "<%= c.string("UIHandler.OnlyDigits") %> "))
   {
      return false;
   }

   // Check if a name has been entered.
   if(document.EnterAttrNameForm.NewAttrName.value=="")
   {
      alert("<%= c.toScript(c.string("CreateAttr.MustEnterName")) %>")
      document.EnterAttrNameForm.NewAttrName.focus();
   }
   else
   {
      if(doesNameExist())
      {
         alert ("<%= c.toScript(c.string("CreateClass.NameAlreadyExists")) %>");
         document.EnterAttrNameForm.NewAttrName.focus();
      }
      else
      {
         document.EnterAttrNameForm.elements["EnteredAttrName"].value= document.EnterAttrNameForm.NewAttrName.value;
         document.EnterAttrNameForm.elements["EnteredAttrID"].value = document.EnterAttrNameForm.NewAttrID.value;
         document.EnterAttrNameForm.elements["merge"].value="base.CreateAttrSyntax";
         document.EnterAttrNameForm.elements["nextState"].value="getNewAttrName";
         document.EnterAttrNameForm.elements["Task.SelectedButton"].value="nextSelected";
         document.EnterAttrNameForm.submit();
      }
   }
}//end of function

function doesNameExist()
{
   //The following example demonstrates the use of the global and ignore case flags with match.
   //str = "abcDdcba";
   //newArray = str.match(/d/gi);
   //document.write(newArray);
   var attrName= document.EnterAttrNameForm.elements["AttrNames"].value;
   var newAttrName = document.EnterAttrNameForm.NewAttrName.value;
   attrNameArray = new Array(document.EnterAttrNameForm.elements["AttrCount"].value);
   attrNameArray = attrName.split("\,");
   newAttrName = newAttrName.toUpperCase(newAttrName);
   for (i=0; i < attrNameArray.length; i++)
   {
      tmpString = attrNameArray[i].toUpperCase(attrNameArray[i])
      if(newAttrName == tmpString)
      {
         return true;
      }
   }
   return false;
}// end of function

function setFormFocus()
{
   document.EnterAttrNameForm.NewAttrName.focus();
   return true;
}

function putAttrName()
{
   var attrname;
   attrname = document.EnterAttrNameForm.elements["EnteredAttrName"].value;
   document.EnterAttrNameForm.NewAttrName.value=attrname;
   return true;
}


//This works for NS 4+ and IE 5+ but not NS6
// Check to make sure that user only inputs numbers and periods
var focused=false;
if (document.captureEvents)
{
   document.captureEvents(Event.KEYPRESS);
}
document.onkeypress=function(e){
   if (!focused)
   {
     return true;
   }
   if (!e && event)
   {
      e={which:event.keyCode};
   }
   if (e.which != 46 && (e.which < 48 || e.which >57))
   {
      return false;
   }
}

/*
// This works for NS6 and IE5
function checknumber()
{
var x=document.EnterAttrNameForm.NewAttrID.value
var anum=/(^\d+$)|(^\d+\.\d)/
if (anum.test(x))
testresult=true
else
{
alert("Please input a valid number!");
document.EnterAttrNameForm.NewAttrID.focus();
testresult=false
}
return (testresult)
}


function checkban()
{
if (document.layers||document.all||document.getElementById)
return checknumber()
else
return true
}*/

</SCRIPT>
</HEAD>
<BODY text="#000000" link="#000000" vlink="#000000" alink="#000000" bgcolor="#FFFFFF" onload="putAttrName();setFormFocus();" >
<FORM name="EnterAttrNameForm" method=post action="webacc">

<!------------------------  WEBACCESS VARIABLES ---------------------------->

<INPUT type="hidden" name="error" value="dev.GenErr">
<INPUT type="hidden" name="merge" value="">
<INPUT type="hidden" name="User.context" value="<%= c.var("User.context") %>">
<INPUT type="hidden" name="nextState" value="">
<INPUT type="hidden" name="taskId" value="<%= c.var("taskId") %>">
<INPUT type="hidden" name="Task.SelectedButton" value="">
<INPUT type="hidden" name="AttrNames" value="<%= c.var("AttrNames") %>">
<INPUT type="hidden" name="AttrCount" value="<%= c.var("AttrCount") %>">
<INPUT type="hidden" name="EnteredAttrName" value="<%= c.var("EnteredAttrName") %>">
<INPUT type="hidden" name="EnteredAttrID" value="<%= c.var("EnteredAttrID") %>">

<% c.set("WizardHeader.title", c.toDisplay(c.string("CreateAttr.Title")));
   c.set("WizardHeader.subtitle", c.toDisplay(c.string("Schema.Step1")));
   c.set("WizardHeader.instruction", c.toDisplay(c.string("CreateAttr.Instr1")));
   c.set("WizardHeader.helpFile", "base/schemacreate_attr_wizard_name.html"); %>
<jsp:include page='<%= c.getPath("dev/WizardHeader_inc.jsp") %>' flush="true" />

<!----------------------------------------- CONTENT TABLE ------------------------------------>

<TABLE border="0" cellspacing="0" cellpadding="2">
   <TR valign="baseline">
      <TD class="mediumtext">
      <%= c.toDisplay(c.string("ShowAttr.Name")) %>
      </TD>
   </TR>
   <TR valign="baseline">
      <TD class="mediumtext">
         <INPUT type="text" name="NewAttrName" Size="25" Maxlength="32">
      </TD>
   </TR>
   <TR valign="baseline">
      <TD class="mediumtext">
      <%= c.toDisplay(c.string("SchemaID")) %>
      </TD>
   </TR>
   <TR valign="baseline">
      <TD class="smalltext2d">
         <INPUT type="text" name="NewAttrID" Size="25" onChange='validateASN1IDString(this, "<%= c.string("UIHandler.OnlyDigits") %> ");'>&nbsp; <%= c.toDisplay(c.string("CreateAttr.Optional")) %>
      </TD>
   </TR>
</TABLE>

<!------------------------- BUTTON TABLE ----------------------------------->
<TABLE width="100%" border="0" cellspacing="0" cellpadding="0" >
   <TR>
      <TD>&nbsp;</TD>
   </TR>
   <TR>
      <TD><jsp:include page='<%= c.getPath("dev/Bar_inc.jsp") %>' flush="true" /></TD>
   </TR>
   <TR>
      <TD>
         <A HREF="#"><IMG src="<%= c.getModulesUrl() + "/dev/images/" + c.string("Button.BackDisabled.image") %>" alt="<%= c.toDisplay(c.string("Button.BackDisabled.alt")) %>" title="<%= c.toDisplay(c.string("Button.BackDisabled.alt")) %>" border=0></A>
         <A HREF="#"onClick="javascript:nextSelected();return false"> <IMG src="<%= c.getModulesUrl() + "/dev/images/" + c.string("Button.Next.image") %>" alt="<%= c.toDisplay(c.string("Button.Next.alt")) %>" title="<%= c.toDisplay(c.string("Button.Next.alt")) %>" border=0></A>
         <jsp:include page='<%= c.getPath("dev/Cancel_inc.jsp") %>' flush="true" />
      </TD>
   </TR>
</TABLE>
</FORM>
</BODY></HTML>

