// initBrain.js $Revision: 4.85a$ Sun Feb 21 2010 22:07 
var counter;
function getStarted()
{
var a, content, menu, side, wants, writing;
if (top != self) top.location.replace(self.location.href.toLowerCase());
window.defaultStatus = "Mitch Miller's Web"; 
counter = 0;
if (!document.getElementsByTagName) return false;
if ((content = document.getElementById("content")) == null) return false;
if ((wants = getMyCookie("topics")) == null) wants = "block";
if (wants != "block")
{
content.style.marginRight = "0px";
wants = "none";
}
side = document.getElementById("sidebarright");
menu = getMyElement("li", "page-item-246");
writing = getMyElement("li", "page-item-250");
if (menu == null || side == null || writing == null) return false;
side.style.display = wants;
menu.onclick = doTopics;
writing.onclick = noTopics;
if (!isWriting())
document.cookie = "topics=" + side.style.display + "; path=/; max-age=1728000;";
a = document.getElementsByTagName("a");
for (var i = 0; i < a.length; i++)
{
if (a[i].getAttribute("href") && a[i].getAttribute("rel") == "external")
    a[i].target = "_blank";
}
document.search.s.onfocus = prepSearch;
try { document.topics.show.onclick = doTopics; } catch (e) {};
return loadTextDiv('/php/one_tweet.php', 'twitter', null);
} // end getStarted

function getMyCookie(ok)
{
if (document.cookie == null) return null;
var info = decodeURIComponent(document.cookie);
var j = info.indexOf(ok);
if (j == -1) return null;
j+= 1 + ok.length;      
var what = "";
do
{
what += info.charAt(j++);
} while (j < info.length && info.charAt(j) != ';');

return what;
} // end getMyCookie

function getMyElement(eType, klass)
{
var i, lists, q, retval = null, x = false;
lists = document.getElementsByTagName(eType);
for (i = 0; i < lists.length && x == false; i++)
{
retval = lists[i];
if ( ( q = lists[i].className.indexOf(klass) ) != -1 )
{
x = true;
} // end if
} // end for

return x ? retval : null;
} // end getMyElement

function doTopics()
{
var content = document.getElementById("content");
var side = document.getElementById("sidebarright");
if (content == null || side == null) return true;

if (side.style.display == "none")
{
content.style.marginRight = "195px";
side.style.display = "block";
loadTextDiv('/php/topics011010.php', 'sidebarright', null);
}
else
{
side.style.display = "none";
content.style.marginRight = "0px";
}
document.cookie = "topics=" + side.style.display + "; path=/; max-age=1728000;";
return false;
} // end doTopics

function noTopics()
{
var content = document.getElementById("content");
var side = document.getElementById("sidebarright");
if (content != null && side != null)
{
side.style.display = "none";
content.style.marginRight = "0px";
document.cookie = "topics=none; path=/; max-age=1728000;";
return true;
}
return false;
} // end noTopics

function isWriting()
{
var stuff = new Array("post-217","post-250","post-251","post-274","post-275","post-276","post-277","post-280","post-283");
var done = null;
for (var i = 0; (i < stuff.length) && (done == null); i++)
{ done = document.getElementById(stuff[i]); }
if (done != null) return noTopics(); else return false;
} // end isWriting

function byeBye() { window.defaultStatus = ""; }

function prepSearch()
{
if (counter++ == 0) document.search.s.value = "";
return true;
}

function getRequest()
{
var xmlreq = false;
if (window.XMLHttpRequest)
{
xmlreq = new XMLHttpRequest();
return xmlreq;
}

if (window.ActiveXObject)
{
try { xmlreq = new ActiveXObject("Msxml2.XMLHTTP"); }
catch (err) { xmlreq = false; }
if (xmlreq == false)
{
try { xmlreq = new ActiveXObject("Microsoft.XMLHTTP"); }
catch (err) { xmlreq = false; }
}
}
 
return xmlreq;
} // end getRequest

function loadTextDiv(cgi, div, query)
{
var answer = "ERROR 1";
var command, elem, program, req, ok = false;
if (cgi == null || div == null) return false;
if ((elem = document.getElementById(div)) == null ) return false;
program = (cgi.charAt(0) == '/') ? cgi : '/cgi-bin/' + cgi + '.cgi';
command = (query == null) ? program : program + '?' + escape(query);
if ((req = getRequest()) == false) return false;
req.open("GET", command, false);
req.send(null);
if (req.status != 204)
{
if (req.status == 200) ok = true;
answer = req.responseText; 
}
elem.innerHTML = answer;
return ok;
} // end loadTextDiv

if (window.addEventListener)
{
window.addEventListener('load', getStarted, false);
window.addEventListener('unload', byeBye, false);
}
else
{
window.attachEvent('onload', getStarted);
window.attachEvent('onunload', byeBye);
} // end if 

