<!doctype html>
<html>
<head>
<title>Send email/SMS of Morse Code</title>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=0.25, maximum-scale=8, user-scalable=yes" />
<link href='//www.rjmprogramming.com.au/PHP/emboss_h1.css' rel='stylesheet' type='text/css'>
<script type='text/javascript'>

var documentURL='';

var surl;
var aem='aemail';

var cnt = 1;

var startagain='';

var wasemailee = ''; //'fill.in@email';

var mtable = [
'.-','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', //--..
'.----','1', //.----
'..---','2', //..---
'...--','3', //...--
'....-','4', //....-
'.....','5', //.....
'-....','6', //-....
'--...','7', //--...
'---..','8', //---..
'----.','9', //----.
'-----','0', //-----
' ', ' '
];

function prealetter() {
aletter("","");
}

function sendsms() {
if (document.getElementById("to").value.trim() != '' && document.getElementById("to").value.trim().replace(/0/g,'').replace(/1/g,'').replace(/2/g,'').replace(/3/g,'').replace(/4/g,'').replace(/5/g,'').replace(/6/g,'').replace(/7/g,'').replace(/8/g,'').replace(/9/g,'') == '') {
document.getElementById("asms").href="sm" + "s:" + document.getElementById("to").value.trim() + "&body=" + encodeURIComponent(document.URL.split('#')[0].split('?')[0] + '?to=' + document.getElementById("to").value.trim() + '&mc=' + encodeURIComponent(document.getElementById("mymc").innerHTML));
document.getElementById("asms").click();
}
}

function aletter(myv,myc) {
var i, j, k, lmc, words, letters, amsg='', thisvalue;
if (startagain != '') {
cnt = cnt + 1;
startagain='';
document.getElementById("myh1").innerHTML = "My Morse Code Message " + cnt;
if (document.getElementById("to").value.indexOf('@') != -1) {
document.getElementById("aemail").href="mai" + "lto:" + document.getElementById("to").value + "?subject=My%20Morse%20Code%20Message&body=" + encodeURIComponent(document.URL.split('#')[0].split('?')[0] + '?to=' + document.getElementById("to").value + '&mc=');
document.getElementById("mymsg").innerHTML = '';
document.getElementById("mymc").innerHTML = '';
} else if (document.getElementById("to").value.trim() != '' && document.getElementById("to").value.trim().replace(/0/g,'').replace(/1/g,'').replace(/2/g,'').replace(/3/g,'').replace(/4/g,'').replace(/5/g,'').replace(/6/g,'').replace(/7/g,'').replace(/8/g,'').replace(/9/g,'') == '') {
document.getElementById("asms").href="sm" + "s:" + document.getElementById("to").value.trim() + "&body=" + encodeURIComponent(document.URL.split('#')[0].split('?')[0] + '?to=' + document.getElementById("to").value.trim() + '&mc=');
document.getElementById("mymsg").innerHTML = '';
document.getElementById("mymc").innerHTML = '';
}
if (1 == 2) {
thisvalue=document.getElementById("to").value;
wasemailee = 'fill.in@email';
document.getElementById("aemail").href=document.getElementById("aemail").href.replace(wasemailee,thisvalue).replace(encodeURIComponent(wasemailee),encodeURIComponent(thisvalue));
wasemailee=thisvalue;
}
}
if (myv == '') {

if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
var shuh=document.getElementById("mymsel").innerHTML;
document.getElementById("mymsel").style.display='none';
document.body.innerHTML=document.body.innerHTML + "<div align='center'>" + shuh.replace(/\/option/g, "/input").replace(/option /g, "input type='button' ") + "</div>";
} else {
document.body.innerHTML=document.body.innerHTML.replace(">--.</option>", ">--.</option></select><select multiple size=8 style='width:100px;font-size:36px;'>");
document.body.innerHTML=document.body.innerHTML.replace(">---</option>", ">---</option></select><select multiple size=8 style='width:100px;font-size:36px;'>");
document.body.innerHTML=document.body.innerHTML.replace(">.--</option>", ">.--</option></select><select multiple size=8 style='width:100px;font-size:36px;'>");
document.body.innerHTML=document.body.innerHTML.replace(">....-</option>", ">....-</option></select><select multiple size=8 style='width:100px;font-size:36px;'>");
document.getElementById("mymsel").size=8;
}


document.getElementById("reset").href = document.URL;
surl=document.URL.split("?");
document.getElementById("aemail").href = ('mai' + 'lto:' + wasemailee + '?subject=My%20Morse%20Code%20Message&body=' + encodeURIComponent(document.URL.split('#')[0].split('?')[0] + '?to=' + wasemailee + '&mc='));
var preymc=location.search.substring(1).split("&");
var thisvalue=''; //'fill.in@email';
var thatvalue=document.getElementById("altemail").value;
if (preymc.length <= 1 && thatvalue.indexOf("@") != -1) {
thisvalue=thatvalue;
document.getElementById("aemail").href=document.getElementById("aemail").href.replace(wasemailee,thisvalue).replace(encodeURIComponent(wasemailee),encodeURIComponent(thisvalue));
wasemailee=thisvalue;
document.getElementById("to").value = thisvalue;
} else if (preymc.length > 1) {
document.getElementById("myh1").innerHTML += ' (back?)';
var aymc=preymc[0].substring(0).split("=");
thisvalue=decodeURIComponent(aymc[aymc.length - 1]);
if (thatvalue.indexOf("@") != -1) thisvalue=thatvalue;
document.getElementById("aemail").href=document.getElementById("aemail").href.replace(wasemailee,thisvalue).replace(encodeURIComponent(wasemailee),encodeURIComponent(thisvalue));
wasemailee=thisvalue;
document.getElementById("to").value = thisvalue;
var ymc=preymc[1].substring(1).split("=");
document.getElementById("ym").innerHTML = "Your Morse Code Message";
lmc = decodeURIComponent(ymc[1].replace(/\%20/g,'_').replace(/\+/g,'_'));
words=lmc.split('__');
for (i=0; i<words.length; i++) {
letters=words[i].split('_');
for (j=0; j<letters.length; j++) {
for (k=0; k<mtable.length; k++) {
if (letters[j] == mtable[k]) {
amsg = amsg + mtable[k + 1];
}
}
}
amsg = amsg + '_';
}

document.getElementById("yh").innerHTML = amsg.replace(/_/g,' ');
}
if (document.URL.indexOf("?isMobile=y") != -1) {
document.getElementById("myh1").innerHTML = "My Morse Code Message";
}
} else {
document.getElementById("mymsg").innerHTML = document.getElementById("mymsg").innerHTML + myv;
document.title = document.getElementById("mymsg").innerHTML;
document.getElementById("mymc").innerHTML = (document.getElementById("mymc").innerHTML + myc + ' ').replace(/_/g,' ');
document.getElementById("aemail").href = document.getElementById("aemail").href + myc + '_';
}
}

function titleit() {
var opts=document.getElementsByTagName('option');
for (var iopts=0; iopts<opts.length; iopts++) {
if (('' + opts[iopts].title).trim() == '') {
opts[iopts].title=opts[iopts].value.replace(' ', 'Space');
}
}
}

</script>
</head>
<body title='Click away to form your morse code' onload=' documentURL=document.URL; setTimeout(prealetter, 1000);' style='background-color:yellow;'>
<div align='center' style='background-color:pink;'>
<h1 id='ym'></h1>
<h2 id='yh'></h2>
</div>
<h1 id='myh1' align='center'>My <a target=_blank title='Morse Code information ... thanks' href='http://stackoverflow.com/questions/1352587/convert-a-string-into-morse-code'>Morse Code</a> Message</h1>
<div align='center'>
<p id='mymsg'></p>
<p id='mymc' style='font-size:18px;'></p>
<span id='myspan'>To: <input placeholder='Enter email address or SMS number' title='Enter email address or SMS number' id='to' size=30 type='text' value='' onblur=" aem='asms'; if (this.value.indexOf('@') == -1) { sendsms(); } else if (this.value.indexOf('@') != -1) { aem='aemail'; document.getElementById('iemail').src='morsecode.php?set=' + this.value; document.getElementById(aem).href=document.getElementById(aem).href.replace('o:' + wasemailee,'o:' + this.value).replace(encodeURIComponent('o:' + wasemailee),encodeURIComponent('o:' + this.value)); } wasemailee=this.value; "></input><input type='button' onclick=" aem='asms'; if (document.getElementById('to').value.indexOf('@') == -1) { sendsms(); } else if (document.getElementById('to').value.indexOf('@') != -1) { aem='aemail'; if (documentURL.indexOf('?isMobile=y') != -1) { startagain='y'; document.getElementById('iemail').src='./morsecode.php?mt=' + encodeURIComponent(document.getElementById(aem).href); document.getElementById('myspan').innerHTML=document.getElementById('myspan').innerHTML.replace('Email' + ' Sent To: ','To: ').replace('SMS' + ' Sent To: ','To: ').replace('To:','Email' + ' Sent To:').replace('o:' + wasemailee, 'o:' + document.getElementById('to').value).replace(encodeURIComponent(':' + wasemailee), encodeURIComponent(':' + document.getElementById('to').value).replace('to=&', 'to=' + encodeURIComponent(document.getElementById('to').value) + '&')); document.getElementById('myh1').innerHTML = document.getElementById('myh1').innerHTML + ' sent'; } else { document.getElementById(aem).href='mailto:' + document.getElementById('to').value + '?subject=' + document.getElementById(aem).href.replace('to%3D%26', 'to%3D' + encodeURIComponent(document.getElementById('to').value) + '%26').split('?subject=')[1]; document.getElementById(aem).click(); } }" value='Send email/SMS of Morse Code below'></input> <a id='reset' href='./morsecode.html' title='reset'>Reset</a> <a style='text-decoration:underline;cursor:pointer;' id='hints' data-href='./morsecode.html' onclick='titleit();' title='hint'>Hint</a></span><br>
<select id='mymsel' multiple size=40 style='width:100px;font-size:36px;'>
<option onclick="aletter(this.value,'_');" value=' '> </option>
<option onclick="aletter(this.value,'.-');" value=a>.-</option>
<option onclick="aletter(this.value,'-...');" value=b>-...</option>
<option onclick="aletter(this.value,'-.-.');" value=c>-.-.</option>
<option onclick="aletter(this.value,'-..');" value=d>-..</option>
<option onclick="aletter(this.value,'.');" value=e>.</option>
<option onclick="aletter(this.value,'..-.');" value=f>..-.</option>
<option onclick="aletter(this.value,'--.');" value=g>--.</option>
<option onclick="aletter(this.value,'....');" value=h>....</option>
<option onclick="aletter(this.value,'..');" value=i>..</option>
<option onclick="aletter(this.value,'.---');" value=j>.---</option>
<option onclick="aletter(this.value,'-.-');" value=k>-.-</option>
<option onclick="aletter(this.value,'.-..');" value=l>.-..</option>
<option onclick="aletter(this.value,'--');" value=m>--</option>
<option onclick="aletter(this.value,'-.');" value=n>-.</option>
<option onclick="aletter(this.value,'---');" value=o>---</option>
<option onclick="aletter(this.value,'.--.');" value=p>.--.</option>
<option onclick="aletter(this.value,'--.-');" value=q>--.-</option>
<option onclick="aletter(this.value,'.-.');" value=r>.-.</option>
<option onclick="aletter(this.value,'...');" value=s>...</option>
<option onclick="aletter(this.value,'-');" value=t>-</option>
<option onclick="aletter(this.value,'..-');" value=u>..-</option>
<option onclick="aletter(this.value,'...-');" value=v>...-</option>
<option onclick="aletter(this.value,'.--');" value=w>.--</option>
<option onclick="aletter(this.value,'-..-');" value=x>-..-</option>
<option onclick="aletter(this.value,'-.--');" value=y>-.--</option>
<option onclick="aletter(this.value,'--..');" value=z>--..</option>
<option onclick="aletter(this.value,'_');" value=' '> </option>
<option onclick="aletter(this.value,'.----');" value=1>.----</option>
<option onclick="aletter(this.value,'..---');" value=2>..---</option>
<option onclick="aletter(this.value,'...--');" value=3>...--</option>
<option onclick="aletter(this.value,'....-');" value=4>....-</option>
<option onclick="aletter(this.value,'.....');" value=5>.....</option>
<option onclick="aletter(this.value,'-....');" value=6>-....</option>
<option onclick="aletter(this.value,'--...');" value=7>--...</option>
<option onclick="aletter(this.value,'---..');" value=8>---..</option>
<option onclick="aletter(this.value,'----.');" value=9>----.</option>
<option onclick="aletter(this.value,'-----');" value=0>-----</option>
</select>
</div>
<a style='display:none;' id='aemail' href='mailto:fill.in@email?subject=My%20Morse%20Code%20Message&body='>email</a>
<a style='display:none;' id='asms' href='sms:&body='>sms</a>
<iframe id='iemail' style='display:none;height:1px;width=1px;' src='morsecode.php?get=' height=1 width=1></iframe>
<input type='hidden' id='altemail' value=''></input>
</body>
</html>