<html>

<head>
<title>Morsen</title>
</head>

<body>
<script language="JavaScript" type="text/javascript">
function mors(){
javascript:text2cw(form);

}


function mors1(){
javascript:text2cw(this.form);
}




function text2cw(form) {

text= new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
                 "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z",
                 " ",".",",","?",":","-","!","=","+","","","","","","",
                 "0","1","2","3","4","5","6","7","8","9","@","ch","#","/","_");

cw=new Array(".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..",
             "--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--..",
             ".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..",
             "--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--..",
             " ",".-.-.-","--..--","..--..","---...","-....-","!","-...-","--.--",".-.-","..--","---.",".-.-",".-..----","---.",
             "-----",".----","..---","...--","....-",".....","-....","--...","---..","----.",".--.-.","----","-----.-.","-..-.","..--....");

   m = "";


   t1 = form.text.value;
   t = t1.toUpperCase();


   for(var i = 0; i < t.length; i++) {
      ch = t.substring(i, i+1);
      for(var j = 0; j < text.length; j++) {
         if(ch == text[j]) {
            m = m + cw[j] + " ";
            break;
         }
      }
   }
   form.cw.value = m;
}

function cw2text(form) {

text= new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
                 "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z",
                 " ",".",",","?",":","-","!","=","+","","","","","","",
                 "0","1","2","3","4","5","6","7","8","9","@","ch","#","/","_");

cw=new Array(".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..",
             "--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--..",
             ".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..",
             "--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--..",
              " ",".-.-.-","--..--","..--..","---...","-....-","!","-...-","--.--",".-.-","..--","---.",".-.-",".-..---","---.",
             "-----",".----","..---","...--","....-",".....","-....","--...","---..","----.",".--.-.","----","-----.-.","-..-.","..--....");


   t = ""; s = 0; idx = 0;


   m = form.cw.value;
   m = m + " ";
   len = m.length - 1;
   while((idx != -1) && (idx < len)) {


      idx = m.indexOf(" ", s);
      if(idx != -1) {
         m1 = m.substring(s, idx);


         for(var j = 0; j < cw.length; j++) {
            if(m1 == cw[j]) {
               t = t + text[j];
               break;
            }
         }
      }


      if(m.substring(idx+1, idx+2) == " ") {
         t = t + " ";
         idx++;
      }


      if((j == cw.length) && (m.substring(s,idx+1) != " ") && (idx < len))
      {idx = idx - m1.length;}
      idx++;
      s = idx;
   }

   form.text.value = t;
}
function ClearWindow(form) {
  form.cw.value = "";
  form.text.value = "";
  }

//-->
</script>
<div align="center"><center>

<table height="312" cellSpacing="0" cellPadding="0" width="100%" border="0">
<TBODY>
  <tr>
    <td width="100%" height="80"><h1>Das Morse-Alphabet</h1>
    </td>
  </tr>
  <tr>
    <td vAlign="center" width="100%" height="118"><form name="form">
      <p>Text in diesem Fenster eingeben <br>
      <textarea onkeyup="javascript:text2cw(this.form)"
      style="font-weight: bold; font-size: 12pt; color: rgb(0,0,0)" name="text" rows="4"
      wrap="virtual" cols="61"></textarea>&nbsp; </p>
      <p><br>
      <textarea style="font-weight: bold; font-size: 15pt; color: rgb(0,0,0)" name="cw" rows="4"
      wrap="virtual" cols="51"></textarea> <font color="#FFFF00"
      face="Verdana, Arial, Helvetica, sans-serif" size="4"><b><br>
      <input style="width: 100px; height: 20px" class="button" onclick="javascript:mors1();"
      type="button" value="mors2" width="50" name="mors2"><input
      style="width: 100px; height: 20px" class="button" onclick="javascript:cw2text(this.form);"
      type="button" value="mors1" width="60" name="text1"></b></font></p>
    </form>
    </td>
  </tr>
</TBODY>
</table>
</center></div>

<p>onkeyup=&quot;javascript:cw2text(this.form)&quot; </p>
</body>
</html>
