// email.js
// Email functionality for H1 onclick event specifics for Google Chart work
// RJM Programming
// Robert Metcalfe
// January 2015
var wua = navigator.userAgent;
var wisiPad = /iPad/i.test(wua) || /iPhone OS 3_1_2/i.test(wua) || /Android/i.test(wua) || /iPhone OS 3_2_2/i.test(wua);
var wisTouch = /touch/i.test(wua) || /Touch/i.test(wua);
var gcadvice = ' ... To email a snapshot of this Google Chart click me.';
var wisMobile = false;
var wisWebView = false;
function depends(ins) {
if (ins == "") return wisWebView;
return ins;
}
function getH1s(evt) {
if (wisWebView || navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
wisWebView = wisWebView;
} else {
wisMobile = false;
wisWebView = false;
}
if (wisWebView) {
if (document.body.innerHTML.indexOf("jkl" + "email") == -1) {
document.body.innerHTML = document.body.innerHTML + "<iframe name='jklemail' id='jklemail' style='display:none;height:1px;width=1px;' src='http://www.rjmprogramming.com.au/PHP/webviewemail.php?get=' height=1 width=1></iframe><a id='email' target='jklemail' title='To email a snapshot of this Google Chart click me.' style='display:inline;' href='http://www.rjmprogramming.com.au/PHP/webviewemail.php?get=&subject=Google%20Chart%20Snapshot&body=" + encodeURIComponent(depends(document.URL).replace('?','&')) + "'>Email snapshot to: </a> <input id='aaltemail' name='aaltemail' type='text' value='' onblur=" + '"' + " document.getElementById('email').href=document.getElementById('email').href.replace('mt=','mt=' + this.value + '&junk=').replace('get=','mt=' + this.value + '&junk='); " + '"' + "></input>";
}
} else {
if (document.body.innerHTML.indexOf("mail" + "to:") == -1 && document.body.innerHTML.indexOf(">E" + "mail") == -1) {
document.body.innerHTML = document.body.innerHTML + "<a id='email' style='display:none;' href='mail" + "to:fillin.email@address?subject=Google%20Chart%20Snapshot&body=" + encodeURIComponent(document.URL) + "'>Email snapshot ...</a>";
document.getElementById('email').click();
}
}
}
function gcinit() {
if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
wisWebView = wisWebView;
} else {
wisMobile = false;
wisWebView = false;
}
if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) { // is mobile
wisMobile = true;
wisWebView = true;
if (depends("") && (document.URL.indexOf("=WebView") != -1 || document.URL.indexOf("WebView=") != -1 || document.URL.indexOf("=UIWebView") != -1)) { // called this way by iOS or Android WebView
wisWebView = true;
wisWebView = depends("");
if (wisWebView) {
if (navigator.userAgent.toLowerCase().indexOf("ie") != (0 - 1)) {
aallPs = document.getElementsByTagName('a');
} else {
aallPs= document.getElementsByTagName('a');
}
for (var jj=0; jj < aallPs.length; jj++) {
if (("*" + aallPs[jj].innerHTML).indexOf("*Another ") != -1) {
if ((aallPs[jj].href + "*").indexOf(".php*") != -1) {
if (document.URL.indexOf("&") != -1) {
var huha=document.URL.split("&");
aallPs[jj].href = huha[0];
} else {
aallPs[jj].href = document.URL;
}
}
}
}
}
} else {
wisWebView = false;
}
}
if (1 == 1) {
if (navigator.userAgent.toLowerCase().indexOf("ie") != (0 - 1)) {
allPs = document.getElementsByTagName('h1');
} else {
allPs= document.getElementsByTagName('h1');
}
for (var j=0; j < allPs.length; j++) {
if (depends("") && wisWebView) {
if (document.body.innerHTML.indexOf("ijk" + "email") == -1) {
document.body.innerHTML = document.body.innerHTML + " <iframe name='ijkemail' id='ijkemail' style='display:none;height:1px;width=1px;' src='http://www.rjmprogramming.com.au/PHP/webviewemail.php?get=' height=1 width=1></iframe><a id='remail' target='ijkemail' title='To email a snapshot of this Google Chart click me.' style='display:inline;' href='http://www.rjmprogramming.com.au/PHP/webviewemail.php?get=&subject=Google%20Chart%20Snapshot&body=" + encodeURIComponent(depends(document.URL).replace('?','&')) + "'>Email snapshot of Google Chart to: </a> <input id='altemail' name='altemail' type='text' value='' onblur=" + '"' + " document.getElementById('remail').href=document.getElementById('remail').href.replace('mt=','mt=' + this.value + '&junk=').replace('get=','mt=' + this.value + '&junk='); " + '"' + "></input>";
}
} else {
if (document.body.innerHTML.indexOf("MAIL" + "TO:") == -1 && document.body.innerHTML.indexOf(">E" + "mail") == -1) {
document.body.innerHTML = document.body.innerHTML + " <a id='remail' title='To email a snapshot of this Google Chart click me.' style='display:inline;' href='MAIL" + "TO:fillin.email@address?subject=Google%20Chart%20Snapshot&body=" + encodeURIComponent(depends(document.URL)) + "'>Email snapshot of Google Chart ...</a>";
}
}
if ((wisiPad || wisTouch)) {
allPs[j].onclick = getH1s;
if (allPs[j].title.indexOf(gcadvice) == -1) allPs[j].title += gcadvice;
} else {
allPs[j].onclick = getH1s;
if (allPs[j].title.indexOf(gcadvice) == -1) allPs[j].title += gcadvice;
}
}
}
}
setTimeout(gcinit, 2000);