// ------------------------------------------------------------------
// JavaScripts for bioneural.net
// Edited 19 Dec 2004
// ------------------------------------------------------------------

// ------------------------------------------------------------------
// 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
// ------------------------------------------------------------------

	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")
	imgCt = myPix.length 

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

// ------------------------------------------------------------------
// E-mail me the page URL
// 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;
   }
}
u = window.location;
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: Cameron Gregory http://www.bloke.com/javascript/Clock/
// ------------------------------------------------------------------

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

function doDate(x)
{
  for (i=0;i<num;i++) {
    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);