<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Broadcasting and Listening - RJM Programming - October, 2015</title>
<link href='//www.rjmprogramming.com.au/PHP/emboss_h1.css' rel='stylesheet' type='text/css'>
<script type='text/javascript'>

var words=new Array();

var fromtext="Please select a broadcast below ...";
var totext="Please select a broadcast below ...";

var inboxurl="";
var outboxurl="";

var identity="";
var datetimebit="";
var subject="";

var cf = "14px Courier New";

var stcmd=new Array();
var numcmd=0;
var thiscmd=0;

var listenurl="";
var score=2000;
var goes=0;

var delim='';

var elem, which=0, ie, elemLeft=0, elemTop=0, context=null;

function doslowly() {
if (eval(thiscmd) < eval(numcmd)) {
eval(stcmd[thiscmd]);
thiscmd++;
setTimeout(doslowly, 103);
}
}

function drawsomewords(somewords) {
var thewords=somewords.replace(/<br>\\n/g, "\\n");
var thelines, jj, tx, ty, stuffs, stuff="", nextx=10, nexty=-20, kk, onex=0;
context.clearRect(0, 0, elem.width, elem.height);
if (1 == 2) {
context.strokeStyle = "blue";
context.font = cf;
thelines=thewords.split("\\n");
if (thelines.length == 1) thelines=thewords.split("\n");
for (jj=0; jj<thelines.length; jj++) {
stuffs=thelines[jj].split(",");
if (stuffs.length >= 3) {
stuff=thelines[jj].replace("" + stuffs[0] + "," + stuffs[1] + ",", "");
context.strokeText(stuff,stuffs[0],stuffs[1]);
nextx=eval(stuffs[0]);
nexty=eval(20 + eval(stuffs[1]));
} else {
stuff=thelines[jj];
context.strokeText(stuff,nextx,Math.abs(eval(nexty)));
nexty=eval(20 + Math.abs(eval(nexty)));
}
}
} else {
onex=nextx;
thiscmd=0;
numcmd=0;
context.strokeStyle = "blue";
context.font = cf;
thelines=thewords.split("\\n");
if (thelines.length == 1) thelines=thewords.split("\n");
for (jj=0; jj<thelines.length; jj++) {
stuffs=thelines[jj].split(",");
if (stuffs.length >= 3) {
stuff=thelines[jj].replace("" + stuffs[0] + "," + stuffs[1] + ",", "");
if (eval(nexty) < 0) {
nextx=eval(stuffs[0]);
onex=nextx;
nexty=eval(stuffs[1]);
}
} else {
stuff=thelines[jj];
if (eval(nexty) < 0) {
onex=nextx;
nexty=eval(Math.abs(eval(nexty)));
}
}
for (kk=0; kk<stuff.length; kk++) {
if (eval(1 + numcmd) > eval(stcmd.length)) {
stcmd.push('context.strokeText("' + stuff.substring(kk, eval(1 + kk)) + '",' + nextx + ',' + nexty + ')');
} else {
stcmd[numcmd]='context.strokeText("' + stuff.substring(kk, eval(1 + kk)) + '",' + nextx + ',' + nexty + ')';
}
numcmd++;
if (numcmd == 1) {
setTimeout(doslowly, 103);
}
//context.strokeText(stuff.substring(kk, eval(1 + kk)),nextx,nexty);
//alert(nextx + "," + nexty + "," + stuff.substring(kk, eval(1 + kk)));
nextx+=8;
}
nextx=eval(onex);
nexty=eval(20 + nexty);
}
}
}

function fixdatetimebit() {
var d = new Date();
document.getElementById('datetimebit').value = ' @ ' + d.toLocaleString();
}

function validatetheform() {
if (document.getElementById('words').value == "") {
document.getElementById('words').style.border='2px solid red';
return false;
}
return true;
}

</script>
</head>
<body style='background-color:orange;'>
<h1 align='center'>Broadcasting <a target=_blank style='text-decoration:none;' href='./broadcast_listen.html' title='Broadcast and Listen'>and</a> Listening</h1>
<h2 align='center'>RJM Programming - October, 2015</h2>
<h4 align='center'>Be a broadcaster or listen to broadcast present or past</h4>
<div align='center' id='mydiv'>
<table cellspacing=5 cellpadding=5>
<tbody>
<tr><th style='background-color:lightblue;'>Broadcast or Listen Status</th><th id='titlebit'>Feedback (at yellow canvas below)</th></tr>
<tr><td style='background-color:lightblue;'>I am a: <select id='iam' name='iam' onchange='whatami(this.value);'><option value=''>Please choose role below ...</option><option value='broadcast'>Broadcaster</option><option value='listen'>Listener</option></select><br><br><div style='display:none;' id='broadcastdiv'><form target='writer' action='./broadcast_listen.php' method='POST' onsubmit="return validatetheform()">Subject: <input style='width:55%;' type='text' value='' name='subject' id='subject'></input><br><br>Words *: <br><textarea onkeyup="document.getElementById('titlebit').innerHTML='This is what a listener sees (at yellow canvas below)'; drawsomewords(this.value);" id='words' name='words' rows=12 cols=28></textarea><br><br>My Name/Email: <input style='width:55%;' type='text' value='' name='emailname' id='emailname'></input><input type='hidden' name='datetimebit' id='datetimebit' value=''></input><br><br><input style='background-color:pink;' onclick='fixdatetimebit();' type='submit' value='Broadcast Words for Listeners'></input></form><br><br><p id='bstatus'></p></div><div id='dmail' align='center' style='word-wrap: break-word;background-color:#fffff0;width:100%;'></div><table style="width:100%;"><tr><th style='width:50%;'><a href="#" onclick=" window.open('test_broadcast_listen.php','_blank','top=100,left=100,width=300,height=300'); " title="Mailbox self tester">Mail</a> In</th><th style='width:50%;'><a href="#" onclick=" window.open('test_broadcast_listen.php','_blank','top=100,left=100,width=300,height=300'); " title="Mailbox self tester">Mail</a> Out</th></tr><tr><td id='mailin' style='width:50%;word-wrap: break-word;'></td><td id='mailout' style='width:50%;word-wrap: break-word;'></td></tr></table></div></td><td><canvas id='mycanvas' width=500 height=440 style='background-color:yellow;position:absolute;top:265px;left:52%;width:500px;height:440px;'></canvas></td></tr>
</tbody>
</table>
</div>
<script type='text/javascript'>

function whatami(urole) {
if (urole == 'broadcast') {
document.getElementById('broadcastdiv').style.display='block';
} else {
var d = new Date();
var rnum=Math.floor(Math.random() * 19000) + 1;
document.getElementById('broadcastdiv').innerHTML='<iframe src="broadcast_list.html?rnum=' + rnum + d.toLocaleString() + '" onload="listenerplace(this);" id="listeneriframe"></iframe>';
}
}

function read_mail(instuff) {
var outstuff=instuff;
if (instuff != "") {
var d, redofd="", ofd="", prefixb="";
var spare=document.getElementById('mailin').innerHTML;
var inlines=instuff.split("\n");
d = new Date();
redofd="<font size=1 color=red>" + d.toLocaleString() + "</font><br>";
for (var i=eval(-1 + inlines.length); i>=0; i--) {
if (inlines[i].replace("<br>","") != "") {
spare=prefixb + ofd + inlines[i] + "<br>" + spare;
prefixb="";
ofd="";
} else if (1 == 2) {
d = new Date();
ofd="<font size=1 color=green>" + d.toLocaleString() + "</font><br>";
}
}
document.getElementById('mailin').innerHTML="<br>" + redofd + spare;
}
return outstuff;
}

function send_mail(outstuff) {
var instuff=outstuff;
if (outstuff != "") {
var d, redofd="", ofd="", prefixb="";
var spare=document.getElementById('mailout').innerHTML;
var inlines=instuff.split("\n");
d = new Date();
redofd="<font size=1 color=red>" + d.toLocaleString() + "</font><br>";
for (var i=eval(-1 + inlines.length); i>=0; i--) {
if (inlines[i].replace("<br>","") != "") {
spare=prefixb + ofd + inlines[i] + "<br>" + spare;
ofd="";
prefixb="";
} else if (1 == 2) {
d = new Date();
ofd="<font size=1 color=green>" + d.toLocaleString() + "</font><br>";
}
}
document.getElementById('mailout').innerHTML="<br>" + redofd + spare;
}
return instuff;
}

function inboxcheck() {
if (inboxurl != "") {
if (1 == 2 && document.getElementById('inbox').src.indexOf("broadcast_listen.php") != -1) {
document.getElementById('mailinout').innerHTML='<iframe onload=check_mail_in(this) style=display:none id=inbox src=' + inboxurl + ' title=inbox></iframe><iframe onload=check_mail_out(this) style=display:none id=outbox src=' + inboxurl.replace('mb_in', 'mb_out') + ' title=outbox></iframe>';
} else {
document.getElementById('inbox').src=inboxurl;
}
inboxurl="";
}
}

function outboxcheck() {
if (outboxurl != "") {
if (1 == 2 && document.getElementById('outbox').src.indexOf("broadcast_listen.php") != -1) {
document.getElementById('mailinout').innerHTML='<iframe onload=check_mail_in(this) style=display:none id=inbox src=' + outboxurl.replace('mb_out', 'mb_in') + ' title=inbox></iframe><iframe onload=check_mail_out(this) style=display:none id=outbox src=' + outboxurl + ' title=outbox></iframe>';
} else {
document.getElementById('outbox').src=outboxurl;
}
outboxurl="";
}
}

function check_mail_in(iois) {
if (iois != null) {
var aconto = (iois.contentWindow || iois.contentDocument);
if (aconto != null) {
if (aconto.document) { aconto = aconto.document; }
if (aconto.body != null && inboxurl == "") {
var d = new Date();
var rnum=Math.floor(Math.random() * 19000) + 1;
var preqs=iois.src.split('?');
inboxurl=preqs[0] + '?rnum=' + rnum + d.toLocaleString();
setTimeout(inboxcheck, 1964);
if (aconto.body.innerHTML != "") {
document.title="mail in is " + read_mail(aconto.body.innerHTML);
iois.src='./broadcast_listen.php?rnum=-1' + rnum + d.toLocaleString();
}
}
}
}
}


function check_mail_out(iois) {
if (iois != null) {
var aconto = (iois.contentWindow || iois.contentDocument);
if (aconto != null) {
if (aconto.document) { aconto = aconto.document; }
if (aconto.body != null && outboxurl == "") {
var d = new Date();
var rnum=Math.floor(Math.random() * 19000) + 1;
var preqs=iois.src.split('?');
outboxurl=preqs[0] + '?rnum=' + rnum + d.toLocaleString();
setTimeout(outboxcheck, 1969);
if (aconto.body.innerHTML != "") {
document.title="mail out is " + send_mail(aconto.body.innerHTML);
iois.src='./broadcast_listen.php?rnum=-2' + rnum + d.toLocaleString();
}
}
}
}
}


function listenerplace(iois) {
if (iois != null) {
var aconto = (iois.contentWindow || iois.contentDocument);
if (aconto != null) {
if (aconto.document) { aconto = aconto.document; }
if (aconto.body != null) {
//alert(aconto.body.innerHTML);
document.getElementById('broadcastdiv').innerHTML=aconto.body.innerHTML.replace(fromtext,totext.substring(0,fromtext.length)).replace(/\n/g, "<br>");
if (totext != fromtext) drawsomewords(totext);
totext="Please select a broadcast below ...";
document.getElementById('broadcastdiv').style.display='block';
}
}
}
}

window.onload = (function(){

var frombit="", whenbit="", subjectbit="", emailbit="";

listenurl=location.search.split('listenurl=')[1] ? location.search.split('listenurl=')[1].split('&')[0] : "";
identity=location.search.split('identity=')[1] ? location.search.split('identity=')[1].split('&')[0] : "";
datetimebit=location.search.split('dtb=')[1] ? location.search.split('dtb=')[1].split('&')[0] : "";
subject=location.search.split('subject=')[1] ? location.search.split('subject=')[1].split('&')[0] : "";

if (listenurl != "") {
document.getElementById('iam').value='listen';
totext=decodeURIComponent(listenurl).replace(/<br>\\n/g, "\\n");
if (subject == "") {
subjectbit="";
} else {
subjectbit="<br>" + decodeURIComponent(subject);
emailbit+=encodeURIComponent(decodeURIComponent(subject));
}
if (datetimebit == "") {
whenbit="";
} else {
whenbit="<br> ... at " + decodeURIComponent(datetimebit);
emailbit+=encodeURIComponent(" ... at " + decodeURIComponent(datetimebit));
}
if (identity == "") {
frombit="";
} else {
if (decodeURIComponent(identity).indexOf("@") != -1) {
frombit="<br> ... via <a href='mailto:" + decodeURIComponent(identity) + "?subject=" + encodeURIComponent("Re: ") + emailbit + "&body=" + encodeURIComponent("Regarding \n\n" + '"' + "\n") + encodeURIComponent(totext.replace(/\\n/g, "\n").replace(/\n/g, "\n")) + encodeURIComponent("\n" + '"' + "\n\n ... can I just say ...\n\n\n") + "' title='Optional email (reply)'>" + decodeURIComponent(identity) + "</a>";
} else {
frombit="<br> ... via " + decodeURIComponent(identity);
}
}
document.getElementById('titlebit').innerHTML='Feedback (at yellow canvas below)' + subjectbit + frombit + whenbit;
whatami('listen');
//setTimeout(andthen, 2000);
}

score=location.search.split('score=')[1] ? location.search.split('score=')[1].split('&')[0] : score;
goes=location.search.split('goes=')[1] ? location.search.split('goes=')[1].split('&')[0] : goes;

ie = (function(){ // thanks to http://stackoverflow.com/questions/5574842/best-way-to-check-for-ie-less-than-9-in-javascript-without-library

var undef,
v = 3,
div = document.createElement('div'),
all = div.getElementsByTagName('i');

while (
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
all[0]
);

return v > 4 ? v : undef;

}());

if (ie < 9) {
elem=document.getElementById('mydiv');
} else {
//alert(981);
elem=document.getElementById('mycanvas');
//alert(982 + elem.id);
context = elem.getContext("2d");
//context.drawImage(img,0,0);
//alert(983);
elemLeft = elem.offsetLeft;
//alert(984);
elemTop = elem.offsetTop;
//alert(985 + " " + elemTop);
}


}());

</script>
<iframe style='display:none;' title='Broadcast Writer' id='writer' name='writer' src='./broadcast_listen.php'></iframe>
<div id='mailinout'>
</div>
</body>
</html>