﻿// ------------------------------------------------------------------
// JavaScripts for bioneural.net
// Edited 28 Oct 2005
// ------------------------------------------------------------------

// ------------------------------------------------------------------
// Make a pop-up window
// ------------------------------------------------------------------

function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=420,height=450,left = 430,top = 287');");
}

// ------------------------------------------------------------------
// Display a random image at the top of the sidebar
// From: JavaScript for the World Wide Web 5th ed, Peachpit Press
// ------------------------------------------------------------------


	var myPix = new Array("http://homepage.mac.com/bruce.mckenzie/images/random/random_pic_1.jpg","http://homepage.mac.com/bruce.mckenzie/images/random/random_pic_2.jpg","http://homepage.mac.com/bruce.mckenzie/images/random/random_pic_3.jpg","http://homepage.mac.com/bruce.mckenzie/images/random/random_pic_4.jpg","http://homepage.mac.com/bruce.mckenzie/images/random/random_pic_5.jpg","http://homepage.mac.com/bruce.mckenzie/images/random/random_pic_6.jpg","http://homepage.mac.com/bruce.mckenzie/images/random/random_pic_7.jpg");

	var imgCt = myPix.length;

	function choosePic() {
		if (document.images) {
			var randomNum;
			randomNum = Math.floor((Math.random() * imgCt))
			document.myPicture.src = myPix[randomNum]
		}
	}

// ------------------------------------------------------------------
// E-mail me the page URL
// From: Modified from http://www.codelifter.com
// ------------------------------------------------------------------

var good;
function checkEmailAddress(field) {
// the following expression must be all on one line...
var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
if (goodEmail) {
good = true;
}
else {
alert('Please enter a valid e-mail address.');
field.focus();
field.select();
good = false;
   }
}
var u = window.location;
var m = "Page link to bioneural.blog";
function mailThisUrl() {
good = false
checkEmailAddress(document.eMailer.address);
if (good) {
// the following expression must be all on one line...
window.location = "mailto:"+document.eMailer.address.value+"?subject="+m+"&body="+document.title+" "+u;
   }
}

// ------------------------------------------------------------------
// Clock
// From: Modified from Cameron Gregory http://www.bloke.com/javascript/Clock/
// ------------------------------------------------------------------

var speed=1000;
//len=28;
var len=25;
var tid = 0;
var num=0;
var clockA = new Array();
var offsetA = new Array();
var dd = new Date();

function doDate(x)
{
  for (i=0;i<num;i++) {
    var dt = new Date();
  
    if (offsetA[i] != 0) {
      gt = dt.getTime();
      gt = gt + offsetA[i];
      dt.setTime(gt);
      }
  
    clockA[i].date.value = dt.toGMTString();
    }

  tid=window.setTimeout("doDate()",speed);
}

function start() {
  clockA[num] = document.forms["form"+num];
  //offsetA[num] = 0;
//window.alert( (new Date()).getTimezoneOffset());
d = new Date();
  if (navigator.appVersion.substring(0,3) == "2.0")
    offsetA[num] = (d.getTimezoneOffset()*60*1000);
  else
    offsetA[num] = -(d.getTimezoneOffset()*60*1000);
  if (num == 0)  
    tid=window.setTimeout("doDate()",speed);
  num++;
}

function startLong(diff) {
//window.alert("hay" + (new Date()).toGMTString());
  clockA[num] = document.forms["form"+num];
  //offsetA[num] = (diff - dd.getTimezoneOffset())*60*1000;
  offsetA[num] = (diff)*60*1000;
  //offsetA[num] = (-diff)* 60*1000;
  if (num == 0)  
    tid=window.setTimeout("doDate()",speed);
  num++;
}

function cleartid() {
  window.clearTimeout(tid);
}
 
// for some reason on some pages this crashes netscape
function Clock()
{
  document.write('<form name=form'+num+'><input name=date size=')
  document.write(len)
  document.write(' value="Clock: Requires Javascript"></form>')
  start();
}
 
// for some reason on some pages this crashes netscape
function ServerClock(diff)
{
  document.write('<form name=form'+num+'><input name=date size=')
  // we chop the end, because it would be the wrong timezone
  document.write(25);
  //document.write(19)
  document.write(' value="Clock: Javascript"></form>')
  startLong(diff);
}

// ------------------------------------------------------------------
// StyleSwitcher
// From: http://idontsmoke.co.uk/2002/ss/
// ------------------------------------------------------------------

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

// ------------------------------------------------------------------
// Advanced JavaScript Popup Windows for Images
// From: Modified from http://www.pcurtis.com/popup_advanced.htm
// ------------------------------------------------------------------

var newwindow;
var wheight = 0, wwidth = 0;

function popitup5(url, title, iwidth, iheight, colour) {
var pwidth, pheight;

if ( !newwindow || newwindow.closed ) {
pwidth=iwidth+30;
pheight=iheight+30;
newwindow=window.open('','htmlname','width=' + pwidth +',height=' +pheight + ',resizable=1,top=50,left=10');
wheight=iheight;
wwidth=iwidth;
}

if (wheight!=iheight || wwidth!=iwidth ) {
pwidth=iwidth+30;
pheight=iheight+60;
newwindow.resizeTo(pwidth, pheight);
wheight=iheight;
wwidth=iwidth;
}

newwindow.document.clear();
newwindow.focus();
newwindow.document.writeln('<html> <head> <title>' + title + '<\/title> <\/head> <body bgcolor=\"' + colour + '\"> <center>');
newwindow.document.writeln('<img src=\"' + url + '\">');
newwindow.document.writeln('<\/center> <\/body> <\/html>');
newwindow.document.close();
newwindow.focus();
}

// ------------------------------------------------------------------
// Load CSS by screen resolution
// From: Modified from http://www.devx.com/tips/Tip/14369
// ------------------------------------------------------------------

if (window.screen.width < 800) {
document.write("<link rel='stylesheet' type='text/css' media='screen' href='http://homepage.mac.com/bruce.mckenzie/css/2005a/single.css'>");
}

// ------------------------------------------------------------------
// Expandable list
// From: http://www.flooble.com/scripts/expand.php
// ------------------------------------------------------------------

var ie4 = false;
if(document.all) {
	ie4 = true;
}
function getObject(id) {
	if (ie4) {
		return document.all[id];
	} else {
		return document.getElementById(id);
	}
}

function toggle(link, ulId) {
	var lText = link.innerHTML;
	var d = getObject(ulId);
	if (lText == '+') {
		link.innerHTML = '&#8722;';
		d.style.display = 'block';
	} else {
		link.innerHTML = '+';
		d.style.display = 'none';
	}
}