<!doctype html>
<head>
<meta charset="utf-8">

<title>Thesaurus Search via Yql - RJM Programming - 2014</title>
<link href='//www.rjmprogramming.com.au/PHP/emboss_h1.css' rel='stylesheet' type='text/css'>
<script type='text/javascript'>
window.onload = initAll;
var myxhr = false;
var url = "";
var dprefix = "http://www.thefreedictionary.com/";

function onblurdo() {
//url='./yql_thesaurus.php?language=' + document.getElementById('language').value + '&selname=' + this.value;
url = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20thesaurus%20where%20key%3D%225r3uguAhHMoAQJIlShGL%22%20and%20word%3D%22" + document.getElementById('selname').value.replace(/ /g,'%20') + "%22%20and%20language%3D%22" + document.getElementById('language').value + "%22&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=";
if (document.getElementById('language').value == "fr_FR") dprefix = "http://www.systranet.com/dictionary/fr-en/";
if (document.getElementById('language').value == "de_DE") dprefix = "http://www.dict.cc/?s=";
if (document.getElementById('language').value == "es_ES") dprefix = "http://www.wordreference.com/es/en/translation.asp?spen=";
if (document.getElementById('language').value == "it_IT") dprefix = "http://www.wordreference.com/iten/";
//var omif=document.getElementById('mif');
//omif.src = url;
//omif.style.display='block';
if (myxhr) {
//console.log("prehere");

myxhr.onreadystatechange = setThesaurusWords;
myxhr.open("GET", url, true);
myxhr.send(null);
} else {
alert("Not able to create XMLHttpRequest ... sadly.");
}
}

function initAll() {
document.getElementById("selname").onblur = onblurdo;


if (window.XMLHttpRequest) {
myxhr = new window.XMLHttpRequest;
}
else {
try {
myxhr = new ActiveXObject("Msxml2.XMLHTTP");
} catch (othermicrosoft) {
try {
myxhr = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
myxhr = false;
}
}
}
checkget();
}

function setThesaurusWords() {
var i, ii, myline, mywords, preword, mylist, endbit="", secgotest;
if (myxhr.readyState == 4) {
if (myxhr.status == 200) {
//console.log("here");
if (myxhr.responseText) {


mylist = myxhr.responseText.split('"synonyms":"');

secgotest = document.body.innerHTML.split("<br><div ");
if (secgotest.length > 1) {
document.body.innerHTML = secgotest[0];
}

endbit = endbit + "<br><div align='center' id='mydiv'><table style='border:8px blue solid;' border=5 cellspacing=8 cellpadding=8><thead><tr><th>Similar Meaning</th><th>Opposite Meaning</th></tr><tbody>";
for (i=1; i<mylist.length; i++) {
myline = mylist[i].split('"');
mywords = myline[0].split("|");
for (ii=0; ii<mywords.length; ii++) {
preword = mywords[ii].split(" (");
if (mywords[ii].indexOf(" (antonym)") !== -1) {
endbit = endbit + "<tr><td style='background-color:white;'></td><td style='background-color:white;'><a style='text-decoration:none;' target=_blank title='" + mywords[ii].replace(" (antonym)", "") + "' href='" + dprefix + preword[0].replace(" (antonym)", "") + "'>" + mywords[ii].replace(" (antonym)", "") + "</a></td></tr>";
} else {
endbit = endbit + "<tr><td style='background-color:white;'><a style='text-decoration:none;' target=_blank title='" + mywords[ii].replace(" (antonym)", "") + "' href='" + dprefix + preword[0].replace(" (antonym)", "") + "'>" + mywords[ii].replace(" (antonym)", "") + "</a></td><td style='background-color:white;'></td></tr>";
}
}
}
endbit = endbit + "</tbody></table></div>";
document.body.innerHTML = document.body.innerHTML + endbit;


}
} else {
//console.log("Problem: " + myxhr.status);
alert("Problem: " + myxhr.status);
}
}
}

function checkget() {
var startwith = location.search.split('startwith=')[1] ? location.search.split('startwith=')[1].split('&')[0] : "";
if (startwith != "") {
var workedstr=decodeURIComponent(startwith);
var wstr=workedstr.toLowerCase().replace("+", " ").replace("+", " ").replace("+", " ").replace("+", " ").replace("+", " ").replace("+", " ").replace("+", " ").replace("+", " ").replace("+", " ").replace("+", " ");
document.getElementById('selname').value=wstr;
//document.getElementById('myform').submit();
//document.body.click();
onblurdo();
}
}

</script>
</head>
<body align='center' style=" background-color: cyan;" onclick=" var sis=document.getElementById('selname').value; var lng=document.getElementById('language').value; if (sis != '') { window.open('./yql_thesaurus.php?language=' + lng + '&selname=' + sis, 'mif'); } ">
<br><h1 align='center'>&nbsp;Thesaurus Search</h1>
<div align='center'>
<form id="myform" method="POST" style=" background-color: lightgray;" action="#">
<br>&nbsp;&nbsp;&nbsp;&nbsp;<select onclick="var i=1;" id="language" name="language"><option value="en_US">English</option><option value="es_ES">Spanish</option><option value="de_DE">German</option><option value="fr_FR">French</option><option value="it_IT">Italian</option></select>&nbsp;<i>Thesaurus</i> Search:&nbsp;<input style=" background-color: yellow;" type="text" onclick=" this.value=''; " name="selname" id="selname" onblur=" onblurdo(); " /><br><br>
&nbsp;<p name="info" id="info">... Results go below ...</p><br><iframe id="mif" src="javascript:false;" style="display:none; width:100%; height:900px; background-color: lightgreen;"></iframe>
</form>
</div>
<script>
var ua = navigator.userAgent;
var isiPad = /iPad/i.test(ua) || /iPhone OS 3_1_2/i.test(ua) || /iPhone OS 3_2_2/i.test(ua);
if (isiPad) {
document.getElementById('myform').innerHTML = document.getElementById('myform').innerHTML.replace("best to tab or click/touch out", "best to finish with keyboard button, not Go button");
}
</script>
</body>

</html>