<!doctype html>
<html>
<head>
<title>Close Relatives - RJM Programming - March, 2017 ... thanks to Science Puzzles for Young Einsteins by Helene Hovanec page 54</title>
<script type='text/javascript'>

var vsnw=[0,0,0,0];
var which=-1, score=0, goes=0, extras='', extradelim='', afirstcall=true;

function Close_Relative(name, darray) {
this.name = name;
this.clues = [darray[0].split('|')[0], darray[1].split('|')[0], darray[2].split('|')[0], darray[3].split('|')[0]];
this.answers = [darray[0].split('|')[1], darray[1].split('|')[1], darray[2].split('|')[1], darray[3].split('|')[1]];
this.numwords = [darray[0].split('|')[0].split(' ').length, darray[1].split('|')[0].split(' ').length, darray[2].split('|')[0].split(' ').length, darray[3].split('|')[0].split(' ').length];
}

var thedefaults = [
new Close_Relative('Face Parts',['saw|jaw','south|mouth','creek|cheek','sips|lips']),
new Close_Relative('Flowers',['dairy|daisy','nose|rose','sweep tea|sweet pea','lilt on thy galley|lily of the valley']),
new Close_Relative('Trees',['seeping pillow|weeping willow','late balm|date palm','sherry|cherry','mine|pine']),
new Close_Relative('Fruits',['drape|grape','slum|plum','teach|peach','ample|apple']),
new Close_Relative('Deer',['dawn|fawn','slag|stag','goose|moose','ilk|elk']),
new Close_Relative('Horses',['posy|pony','scallion|stallion','bolt|colt','mark|mare']),
new Close_Relative('Leg Parts',['angle|ankle','knew|knee','fort|foot','thin|shin']),
new Close_Relative('Arm Parts',['whist|wrist','hank|hand','linger|finger','bunny zone|funny bone']),
new Close_Relative('Meats',['park|pork','steam|steak','deal|veal','lame|lamb']),
new Close_Relative('Vegetables',['seas|peas','lama jeans|lima beans','strong deans|spring beans','squish|squash']),
new Close_Relative('Seasons',['simmer|summer','tinter|winter','full|fall','string|spring']),
new Close_Relative('Body Organs',['river|liver','rungs|lungs','heard|heart','drain|brain'])
];

var defsel='<select id=? onchange="changed(this);"><option value="a">a</option><option value="b">b</option><option value="c">c</option><option value="d">d</option><option value="e">e</option><option value="f">f</option><option value="g">g</option><option value="h">h</option><option value="i">i</option><option value="j">j</option><option value="k">k</option><option value="l">l</option><option value="m">m</option><option value="n">n</option><option value="o">o</option><option value="p">p</option><option value="q">q</option><option value="r">r</option><option value="s">s</option><option value="t">t</option><option value="u">u</option><option value="v">v</option><option value="w">w</option><option value="x">x</option><option value="y">y</option><option value="z">z</option></select>';

var mores = (location.search.split('categories=')[1] ? decodeURIComponent(location.search.split('categories=')[1].split('&')[0]) : '');

function cr_setCookie(thisg) { // thanks to JavaScript and Ajax by Tom Negrino and Dori Smith
var expireDate = new Date();
expireDate.setMonth(expireDate.getMonth()+6);
//alert(thisg);
document.cookie = "categories=" + encodeURIComponent(thisg) + "; expires=" + expireDate.toGMTString();
}

function cr_deleteCookie() { // thanks to JavaScript and Ajax by Tom Negrino and Dori Smith
var expireDate = new Date();
expireDate.setMonth(expireDate.getMonth()-6);
document.cookie = "categories=; expires=" + expireDate.toGMTString();
}

function cr_cookieVal(firstcall) {
if (firstcall && mores != '') {
if (document.cookie == '') {
extras=mores;
cr_setCookie(mores);
}
} else {
if (document.cookie != '') {
//alert(9);
var tCookie=document.cookie.split("; ");
for (var j=0; j<tCookie.length; j++) {
if ("categories" == tCookie[j].split("=")[0]) {
if (firstcall && decodeURIComponent(tCookie[j].split("=")[1]) != "") {
addthis(decodeURIComponent(tCookie[j].split("=")[1]));
}
return decodeURIComponent(tCookie[j].split("=")[1]);
}
}
}
}
return '';
}

function changed(what) {
var whichrow=eval(-1 + eval(what.id.split('_')[1]));
var whichcol=eval(-1 + eval(what.id.split('_')[2]));
if (vsnw[whichrow] <= 0) {
what.value=thedefaults[which].answers[whichrow].substring(whichcol, eval(1 + whichcol));
} else {
goes++;
if (what.options[what.selectedIndex].title) {
//alert('*' + what.options[what.selectedIndex].title + '*');
if (what.options[what.selectedIndex].title == " ") {
score+=5;
vsnw[whichrow]--;
//alert('vsnw[' + whichrow + ']=' + vsnw[whichrow]);
} else {
what.value=thedefaults[which].clues[whichrow].substring(whichcol, eval(1 + whichcol));
score--;
}
} else {
//alert('what.id=' + what.id + ' which=' + which + ' whichrow=' + whichrow + ' whichcol=' + whichcol);
what.value=thedefaults[which].clues[whichrow].substring(whichcol, eval(1 + whichcol));
//alert('!' + what.options[what.selectedIndex].title + '!');
score--;
}
document.getElementById('score').innerHTML='Score: ' + score + '/' + goes;
}
if (0 == (vsnw[0] + vsnw[1] + vsnw[2] + vsnw[3])) {
which=-1;
pickobject();
}
}

function pickobject() {
var tdbit='',j,k,xextras,ixextras;
if (mores != "") {
cr_setCookie(mores);
xextras=mores.split('!');
mores="";
for (ixextras=0; ixextras<xextras.length; ixextras++) {
addthis(xextras[ixextras]);
}
} else if (afirstcall && document.URL.indexOf('categories=') == -1) {
cr_cookieVal(afirstcall);
afirstcall=false;
}
afirstcall=false;
if (which < 0) which=Math.floor(Math.random() * thedefaults.length);
document.getElementById('nameof').innerHTML=thedefaults[which].name;
vsnw=thedefaults[which].numwords;
for (j=0; j<4; j++) {
tdbit='';
document.getElementById('clue' + eval(1 + j)).innerHTML=thedefaults[which].clues[j];
for (k=0; k<thedefaults[which].clues[j].length; k++) {
if (thedefaults[which].clues[j].substring(k, eval(1 + k)) == " ") {
tdbit+="<select style='background-color:yellow;'><option value=' '> </option></select>";
} else {
tdbit+=defsel.replace('?', 'ans_' + eval(1 + j) + '_' + eval(1 + k)).replace(">" + thedefaults[which].clues[j].substring(k, eval(1 + k)) + "<"," selected>" + thedefaults[which].clues[j].substring(k, eval(1 + k)) + "<").replace(">" + thedefaults[which].answers[j].substring(k, eval(1 + k)) + "<"," title=' '>" + thedefaults[which].answers[j].substring(k, eval(1 + k)) + "<");
}
}
document.getElementById('answer' + eval(1 + j)).innerHTML=tdbit;
}
}

function isvalid(theone) {
var isok=true;
var firsttheone=theone.split(',')[0] + ',';
var yourone=('new Close_Relative("' + firsttheone + theone.replace(firsttheone,'').toLowerCase().replace(/\'/g,'').replace(/\"/g,'') + '"])').replace(',','"~["').replace(/,/g,'"~"').replace(/~/g,",");
var huhs=(firsttheone + theone.replace(firsttheone,'').toLowerCase()).split('|');
var jwords,jdiff=0,iwords,awords,cwords, ananswer="", aclue=huhs[0].split(',')[eval(-1 + huhs[0].split(',').length)];
for (var iclue=1; iclue<aclue.length; iclue++) {
ananswer=huhs[iclue].split(',')[0];
cwords=aclue.split(' ');
awords=ananswer.split(' ');
for (iwords=0; iwords<cwords.length; iwords++) {
if (awords[iwords].length != cwords[iwords].length) {
isok=false;
alert('Sorry, but "' + theone + '" does not suit the game rules because (at least) one clue word length is different to its corresponding answer word length.');
return false;
}
jdiff=0;
for (jwords=0; jwords<cwords[iwords].length; jwords++) {
if (awords[iwords].substring(jwords, eval(1 + jwords)) != cwords[iwords].substring(jwords, eval(1 + jwords))) jdiff++;
}
if (jdiff != 1) {
isok=false;
alert('Sorry, but "' + theone + '" does not suit the game rules because the number of clue word letter differences to its corresponding answer word letters is not one in (at l;east) one clue and answer word pair.');
return false;
}
}
if (cwords.length != awords.length) isok=false;
if (huhs[iclue].indexOf(',') != -1) {
aclue=huhs[iclue].split(',')[eval(-1 + huhs[iclue].split(',').length)];
}
}
if (!isok) alert('Sorry, but "' + theone + '" does not suit the game rules.');
return isok;
}

function addthis(inadd) {
var theone=null, yourone="", pretheone,ipre,lpre=1,theones, realask=false, firsttheone='';
which=-1;
while (theone == null) {
if (inadd != "") {
theone=yourone;
pretheone=inadd;
document.getElementById('showlast').style.display='inline';
document.getElementById('nocookies').style.display='inline';
} else {
realask=true;
pretheone=prompt(inadd + "Enter your five comma separated entry (one letter change per word from clue to answer) that goes ... Category, clue1|answer1, clue2|answer2, clue3|answer3, clue4|answer4 ... and to do more than one at a time, separate by ! ... and to clear the cookie data regarding this enter a blank string (or one or more space characters only to avoid being prompted again)", "Vehicle Types,bar|car,sour wheep drove|four wheel drive,track|truck,can|van");
if (pretheone != null) {
theone=yourone;
if (pretheone.trim() == "") {
cr_deleteCookie();
extras="";
extradelim="";
if (pretheone == "") {
pretheone=prompt("Enter your five comma separated entry (one letter change per word from clue to answer) that goes ... Category, clue1|answer1, clue2|answer2, clue3|answer3, clue4|answer4 ... and to do more than one at a time, separate by !", "Vehicle Types,bar|car,sour wheep drove|four wheel drive,track|truck,can|van");
if (pretheone != null) {
if (pretheone.trim() = "") return;
}
} else {
theone=null;
realask=false;
}
}
}
}
if (pretheone != null) {
theones=pretheone.split('!');
lpre=theones.length;
if (theone != null) theone=theones[0];
} else {
realask=false;
}
for (ipre=0; ipre<lpre; ipre++) {
if (theone == null) {
which=-1;
realask=false;
theone=yourone;
} else if (theone.split(',').length == 5 && theone.split('|').length == 5) {
if (isvalid(theone)) {
if (("!" + extras + "!").indexOf(("!" + theone + "!")) == -1) {
extras+=extradelim + theone;
extradelim="!";
}
firsttheone=theone.split(',')[0] + ',';
yourone=('new Close_Relative("' + firsttheone + theone.replace(firsttheone,'').toLowerCase().replace(/\'/g,'').replace(/\"/g,'') + '"])').replace(',','"~["').replace(/,/g,'"~"').replace(/~/g,",");
thedefaults.push(eval(yourone));
if (eval(1 + ipre) == lpre) {
if (inadd == "" || document.URL.indexOf('categories=') != -1) {
realask=true;
which=eval(-1 + eval(thedefaults.length));
}
} else {
theone=theones[eval(1 + ipre)];
}
}
} else if (theone.split(',').length == 5) {
alert('Sorry, but "' + theone + '" does not suit the game rules because the answer fields have not been provided.');
realask=false;
theone=null;
} else if (theone.split('|').length == 5) {
alert('Sorry, but "' + theone + '" does not suit the game rules because the number of data fields is wrong, perhaps because you have forgotten the Category field.');
realask=false;
theone=null;
} else {
alert('Sorry, but "' + theone + '" does not suit the game rules because the number of data fields is wrong.');
realask=false;
theone=null;
}
}
}
if (which >= 0 && realask) {
document.getElementById('showlast').style.display='inline';
pickobject();
}
}

function shareviaemail() {
var prefix=document.getElementById('aemail').href.split('body=');
if (extras == "") {
document.getElementById('aemail').href=prefix[0] + 'body=' + encodeURIComponent(document.URL.split('#')[0].split('?')[0]);
} else {
cr_setCookie(extras);
document.getElementById('aemail').href=prefix[0] + 'body=' + encodeURIComponent(document.URL.split('#')[0].split('?')[0] + '?categories=' + encodeURIComponent(extras));
}
document.getElementById('aemail').click();
}


</script>
</head>
<body onload=' pickobject(); ' style='background-color:yellow;'>
<div style='width:100%; text-align:center;'>
<h1>Close Relatives <a href='#' style='text-decoration:none;cursor:pointer;' onclick=" document.getElementById('a_add').click(); " title='Add your own set of data, and we will let you know if it is valid or not.'>➕</a><a id='eemail' onclick='shareviaemail();' title='Share via Email a link to this game called Close Relatives'>📧</a><a id='showlast' style='display:none;text-decoration:none;cursor:pointer;' title='Pick last user supplied question and add it to cookie data for game revisits' href='#' onclick="cr_setCookie(extras); document.getElementById('nocookies').style.display='inline'; which=eval(-1 + eval(thedefaults.length)); pickobject();">🍪</a><a id='nocookies' style='display:none;text-decoration:none;cursor:pointer;' title='Clear cookies' href='#' onclick="cr_deleteCookie(); extras=''; extradelim=''; document.getElementById('showlast').style.display='none'; this.style.display='none';"><strike style='color:red;font-size:30px;'>🍪</strike></a></h1>
</h1>
<h3>RJM Programming - March, 2017</h3>
<h4> ... thanks to Science Puzzles for Young Einsteins by Helene Hovanec</h4>

<h2>Change a letter in each of the dropdown words to be words suiting the category shown, or <a id='a_add' title='Add your own set of data, and we will let you know if it is valid or not.' href='#' onclick="addthis('');">add</a> your own into the mix.</h2>
<h3 id='score'>Score: 0/0</h3>

<table border=50 style='width:100%; text-align:center;background-color:lightgreen;'>
<tbody>
<tr><th colspan=2 id='nameof'></th></tr>
<tr><td id='clue1'></td><td id='answer1'></td></tr>
<tr><td id='clue2'></td><td id='answer2'></td></tr>
<tr><td id='clue3'></td><td id='answer3'></td></tr>
<tr><td id='clue4'></td><td id='answer4'></td></tr>
</tbody>
</table>

</div>
<a target='_top' style='display:none;' href='mailto:fillin@email.to?subject=Close%20Relatives%20Game&body=' id='aemail'>Share via Email</a>
</body>
</html>