<%@  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");
%>
<%@ taglib uri="/WEB-INF/iman.tld" prefix="iman" %>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>

<iman:stringtable bundle="FwResources"/>
<iman:stringtable bundle="DevResources"/>

<HTML>
<HEAD>
	<LINK href="<%= c.getModulesUrl()%>/dev/css/hf_style.css" rel="styleSheet" type="text/css">
	<TITLE>Octet String Editor</TITLE>
   <STYLE type="text/css">
      .verticalAI { font-size: 10px; text-align: right }
      .horizontalAI { width: 6px; font-size: 10px }
      textarea { font-size: 12px }
   </STYLE>

   <SCRIPT language="JavaScript" src="<%= c.getModulesUrl() %>/dev/javascripts/OctetStringTextBox.js"></SCRIPT>

   <SCRIPT language="JavaScript">

	function checkOpener()
	{
		if(opener == null || opener.closed)
		{
			self.close();
		}
		else
		{
			setTimeout(checkOpener, 500);
		}
	}
	
	function changeValue(newValue)
	{
		document.forms[0].HexTextBox.value = newValue;
        updateFormTextBoxes();
        document.forms[0].HexTextBox.focus();
	}
    function checkInput()
    {
		var charCode;
		var c=0;

        document.forms[0].HexTextBox.value = document.forms[0].HexTextBox.value.toUpperCase();
        while(c<document.forms[0].HexTextBox.value.length){
            charCode=document.forms[0].HexTextBox.value.charCodeAt(c);
            if((charCode > 47 && charCode < 58) || (charCode > 64 && charCode < 71)){}
            else if(charCode == 32){}
            else{
            	alert("<%= c.string("ExtendObject.HexEditor.Error") %>");
            	document.forms[0].HexTextBox.value=document.forms[0].prevvalue.value;
            	break;
            }
            c++;
        }
        document.forms[0].prevvalue.value=document.forms[0].HexTextBox.value
    }
    
    function IsHexValid()
    {
    	var hexValue = document.forms[0].HexValue.value;

         if(hexValue.length%2==1)//check if there is a stray nibble at the end.
         {
         	alert('<iman:string key="HexEditor.InvalidHex" />');
         	return false;
         }
         return true;
    
    }


      function getHexValue()
      {
         var hexValue = document.forms[0].HexValue.value;

         /***  //Don't pad with a '0', just throw an alert box.
         if(hexValue.length%2==1) //pad a 0 at the front if there's a stray nibble at the end. Why?
         {
         	if(hexValue.charAt(0)=="0")
            {
               hexValue = hexValue.substring(1);
            }
            else
            {
               hexValue="0" + hexValue;
            }
            
         }
         */

         return hexValue;
      }


   <%
      String mvedName = request.getParameter("mvedName");
      if(mvedName!=null && mvedName.length()>0){
   %>

      // return value to mved
      function addAndClose()
      {
      	 if (!IsHexValid())
      	 	return;
         var text = getHexValue();
         var mvse = opener.mv<%= mvedName%>;
         
		 if (text!=null && text.length>0)
         {
         <% if (c.var("edit").equals("true")) { %>
            opener.mvselSetValue(mvse, text);
         }
         mvse.m_isEditing = false;
         <% }else{ %>
            opener.mvselAdd(mvse, text);
         }
         <% } %>
         opener.mvselOnChange(mvse);
         window.close();
      }

    <%}else{%>

      function addAndClose()
      {
      	 if (!IsHexValid())
      	 	return;
         var hexValue = getHexValue();

         var l = top.opener.<%= c.var("controlString") %>;
         <% if (c.var("osaction").equals("edit")) { %>
            MVOSEdit(l,hexValue);
         <% } else { %>
            <% if (c.var("osaction").equals("add")) { %>
               var val = hexValue;
               l[l.length] = new Option(val, val);
               //top.opener.mvselAdd(l,);
            <% } else { %>
               l.value = hexValue;
            <% } %>
         <% } %>
         window.close();
      }

   <% } %>


      function onInit()
      {
         <% if(mvedName==null || mvedName.length()==0){ %>
            <% if (c.var("osaction").equals("edit")) { %>
               var index = top.opener.<%= c.var("controlString") %>.selectedIndex;
               document.forms[0].HexTextBox.value = window.opener.<%= c.var("controlString") %>[index].value;
            <% } else {
               if (c.var("osaction").equals("add")) { %>
                  document.forms[0].reset();
               <% } else { %>

               document.forms[0].HexTextBox.value = window.opener.<%= c.var("controlString") %>.value;   //asciiToHex
               <% } %>
            <% } %>

            updateFormTextBoxes();

         <% }else{ %>
            <% if (c.var("edit").equals("true")) { %>
               document.forms[0].HexTextBox.value = opener.document.form.<%= mvedName %>[opener.document.form.<%= mvedName %>.selectedIndex].value;
               updateFormTextBoxes();
            <% } %>
         <% } %>

         document.forms[0].HexTextBox.focus();
         checkOpener();
      }
	</SCRIPT>
</HEAD>

<BODY onLoad="onInit()">
<CENTER>
 <FORM onSubmit="addAndClose();">
  <TABLE border="0" cellpadding="0" cellspacing="0">
    <TR>
      <TD></TD>
      <TD></TD>
      <TD colspan="2">&nbsp;</TD>
      <TD></TD>
      <TD></TD>
      <TD></TD>
      <TD></TD>
    </TR>
    <TR>
      <TD class="mediumtext">&nbsp;</TD>
      <TD class="mediumtext">&nbsp;</TD>
      <TD class="mediumtext" colspan="2"><iman:string key="OctetStringEditor.HexValues"/>:</TD>
      <TD class="mediumtext"></TD>
      <TD class="mediumtext"></TD>
      <TD class="mediumtext"></TD>
      <TD class="mediumtext"><iman:string key="OctetStringEditor.UnicodeValues"/>:</TD>
    </TR>
    <TR>
      <TD class="mediumtext"></TD>
      <TD class="mediumtext"></TD>
      <TD class="mediumtext" colspan="2"><input type="hidden" name="prevvalue" value=""></TD>
      <TD class="mediumtext"></TD>
      <TD class="mediumtext"></TD>
      <TD class="mediumtext"></TD>
      <TD class="mediumtext"></TD>
    </TR>
    <TR>
      <TD></TD>
      <TD></TD>
      <TD colspan="2">
        <table border="0" cellpadding="0" cellspacing="0" width="100%">
          <TR>
            <TD width="1"></TD>
            <TD class="horizontalAI">0</TD>
            <TD class="horizontalAI">1</TD>
            <TD class="horizontalAI">2</TD>
            <TD class="horizontalAI">3</TD>
            <TD class="horizontalAI">4</TD>
            <TD class="horizontalAI">5</TD>
            <TD class="horizontalAI">6</TD>
            <TD class="horizontalAI">7</TD>
            <TD class="horizontalAI">8</TD>
            <TD class="horizontalAI">9</TD>
            <TD class="horizontalAI">A</TD>
            <TD class="horizontalAI">B</TD>
            <TD class="horizontalAI">C</TD>
            <TD class="horizontalAI">D</TD>
            <TD class="horizontalAI">E</TD>
            <TD class="horizontalAI">F</TD>
            <TD width="5"></TD>
          </TR>
        </table>
      </TD>
      <TD>&nbsp;&nbsp;</TD>
      <TD></TD>
      <TD>&nbsp;</TD>
      <TD>
        <table border="0" cellpadding="0" cellspacing="0" width="100%">
          <TR>
            <TD width="1"></TD>
            <TD class="horizontalAI">0</TD>
            <TD class="horizontalAI">4</TD>
            <TD class="horizontalAI">8</TD>
            <TD class="horizontalAI">12</TD>
            <TD width="5"></TD>
          </TR>
        </table>
      </TD>
    </TR>
    <TR>
      <TD valign="top" class="verticalAI">
        <table border="0" cellpadding="0" cellspacing="0">
          <TR>
            <TD height="5"></TD>
          </TR>
          <TR>
            <TD class="verticalAI">00</TD>
          </TR>
          <TR>
            <TD class="verticalAI">10</TD>
          </TR>
          <TR>
            <TD class="verticalAI">20</TD>
          </TR>
          <TR>
            <TD class="verticalAI">30</TD>
          </TR>
          <TR>
            <TD class="verticalAI">40</TD>
          </TR>
          <TR>
            <TD class="verticalAI">50</TD>
          </TR>
          <TR>
            <TD class="verticalAI">60</TD>
          </TR>
          <TR>
            <TD class="verticalAI">70</TD>
          </TR>
          <TR>
            <TD class="verticalAI">80</TD>
          </TR>
          <TR>
            <TD class="verticalAI">90</TD>
          </TR>
          <TR>
            <TD class="verticalAI">A0</TD>
          </TR>
          <TR>
            <TD class="verticalAI">B0</TD>
          </TR>
          <TR>
            <TD class="verticalAI">C0</TD>
          </TR>
          <TR>
            <TD class="verticalAI">D0</TD>
          </TR>
          <TR>
            <TD class="verticalAI">E0</TD>
          </TR>
          <TR>
            <TD class="verticalAI">F0</TD>
          </TR>
        </table>
      </TD>
      <TD valign="top" class="verticalAI"></TD>
      <TD valign="top" colspan="2"><textarea rows="16" name="HexTextBox" cols="48" onkeyup="checkInput(); updateAsciiTextBox();"></textarea></TD>
      <TD valign="top"></TD>
      <TD valign="top">
        <table border="0" cellpadding="0" cellspacing="0">
          <TR>
            <TD height="5"></TD>
          </TR>
          <TR>
            <TD class="verticalAI">00</TD>
          </TR>
          <TR>
            <TD class="verticalAI">16</TD>
          </TR>
          <TR>
            <TD class="verticalAI">32</TD>
          </TR>
          <TR>
            <TD class="verticalAI">48</TD>
          </TR>
          <TR>
            <TD class="verticalAI">64</TD>
          </TR>
          <TR>
            <TD class="verticalAI">80</TD>
          </TR>
          <TR>
            <TD class="verticalAI">96</TD>
          </TR>
          <TR>
            <TD class="verticalAI">112</TD>
          </TR>
          <TR>
            <TD class="verticalAI">128</TD>
          </TR>
          <TR>
            <TD class="verticalAI">144</TD>
          </TR>
          <TR>
            <TD class="verticalAI">160</TD>
          </TR>
          <TR>
            <TD class="verticalAI">176</TD>
          </TR>
          <TR>
            <TD class="verticalAI">192</TD>
          </TR>
          <TR>
            <TD class="verticalAI">208</TD>
          </TR>
          <TR>
            <TD class="verticalAI">224</TD>
          </TR>
          <TR>
            <TD class="verticalAI">240</TD>
          </TR>
        </table>
      </TD>
      <TD valign="top"></TD>
      <TD valign="top"><textarea rows="16" name="AsciiTextBox" onkeyup="checkAsciiInput(); updateHexTextBox();" cols="16"></textarea></TD>
    </TR>
    <TR>
      <TD></TD>
      <TD></TD>
      <TD colspan="2">&nbsp;</TD>
      <TD></TD>
      <TD></TD>
      <TD></TD>
      <TD></TD>
    </TR>
    <TR>
      <TD></TD>
      <TD></TD>
      <TD class="mediumtext"><iman:string key="OctetStringEditor.HexDataSize"/>: <span id="HexDataSize">0</span>&nbsp;</TD>
      <TD class="mediumtext"><iman:string key="OctetStringEditor.DecDataSize"/>: <span id="DecDataSize">0</span></TD>
      <TD></TD>
      <TD></TD>
      <TD></TD>
      <TD class="mediumtext"><input type="checkbox" name="AutoSpacing" value="ON" onclick="updateFormTextBoxes();" id="fp1" checked>
        <label name="radiolabel" for="fp1"><iman:string key="OctetStringEditor.AutoFormat"/></label></TD>
    </TR>
    <TR>
      <TD></TD>
      <TD></TD>
      <TD class="mediumtext">&nbsp;</TD>
      <TD class="mediumtext"></TD>
      <TD></TD>
      <TD></TD>
      <TD></TD>
      <TD class="mediumtext"></TD>
    </TR>
    <TR>
      <TD></TD>
      <TD></TD>
      <TD class="mediumtext">
        <% if (c.var("osaction").equals("add")) { %>
        <a href="javascript:addAndClose();"><IMG name="Add" alt="<%= c.string("Button.Add.alt") %>" src="<%= c.getModulesUrl() + "/dev/images/" + c.string("Button.Add.image") %>" border="0"></a>
        <% } else { %>
        <a href="javascript:addAndClose();"><IMG name="Modify" alt="<%= c.string("Button.Modify.alt") %>" src="<%= c.getModulesUrl() + "/dev/images/" + c.string("Button.Modify.image") %>" border="0"></a>
        <% } %>
        <a href="javascript:onInit();"><IMG name="Reset" alt="<%= c.string("Button.Reset.alt") %>" src="<%= c.getModulesUrl() + "/dev/images/" + c.string("Button.Reset.image") %>" border="0"></a>
      </TD>
      <TD class="mediumtext"></TD>
      <TD></TD>
      <TD></TD>
      <TD></TD>
      <TD class="mediumtext"></TD>
    </TR>
  </TABLE>
  <input type="hidden" name="HexValue">
 </FORM>
</CENTER>
<IFRAME src="webacc?taskId=dev.Empty&merge=fw.OctetStringUpload_inc" name="uploadFrame" id="uploadFrame" width="500" height="100" marginwidth="0" marginheight="0" style="border: 0px"></IFRAME>
</BODY>
</HTML>

