// Javascript for BSUC email and web faq. Mark Annand. Rev. Nov 2001.
// NB There's more of this code on oe_email_via_web.html as for some reason
// the javascript wouldn't work when called from here ...

   // The following invoke pop up windows, 
   // but different sizes and places ...
   // Values or graphics are passed for the function to display or a text string ...
 
function openWin(graphic,title)  
                   {
   // open new window with name 'picture'.
 
   picture= open("", "diagram", "scrollbars=no,width=175,height=185,screenX=540,screenY=330,left=540,top=330");
   // open document and write to it
   picture.document.open();
  
   picture.document.write("<HTML><HEAD><TITLE>");
   picture.document.write(title);
   picture.document.write("</TITLE></HEAD><BODY onBlur='self.close()'>");
   picture.document.write("<CENTER>");
   picture.document.write('<IMG SRC="');
   picture.document.write(graphic);
   picture.document.write('">');
   picture.document.write("</CENTER>");
   picture.document.write("</BODY></HTML>");
   // close the document - (not the window! I've asked that to shut itself ...)
   picture.document.close();  
                    }
function openWin1(graphic,title)  
                   {
 
   illustration= open("", "diagram", "scrollbars=no,width=393,height=276,screenX=175,screenY=100,left=175,top=100");
   // open document and write to it
   illustration.document.open();
 
   illustration.document.write("<HTML><HEAD><TITLE>");
   illustration.document.write(title);
   illustration.document.write("</TITLE></HEAD><BODY onBlur='self.close()'>");
   illustration.document.write("<CENTER>");
   illustration.document.write('<IMG SRC="');
   illustration.document.write(graphic);
   illustration.document.write('">');
   illustration.document.write("</CENTER>");
   illustration.document.write("</BODY></HTML>");
   // close the document - (not the window! I've asked that to shut itself ...)
   illustration.document.close();  
                    }

/* Used to open a spoof pop up ad ... */
					
function openWingrr(graphic,title)  
                   {
 
   illustration= open("", "diagram", "scrollbars=no,width=352,height=124,screenX=200,screenY=300,left=300,top=350");
   // open document and write to it
   illustration.document.open();
 
   illustration.document.write("<HTML><HEAD><TITLE>");
   illustration.document.write(title);
   illustration.document.write("</TITLE></HEAD><BODY onBlur='self.close()'>");
   illustration.document.write("<CENTER>");

   illustration.document.write('<IMG SRC="');
   illustration.document.write(graphic);
   illustration.document.write('">');

   illustration.document.write("</CENTER>");
   illustration.document.write("</BODY></HTML>");
   // close the document - (not the window! I've asked that to shut itself ...)
   illustration.document.close();  
                    }
					
function openWin2(htmlstring,title)  
                   {
 
   webpage= open("", "htmlstring", "scrollbars=yes,width=280,height=320,screenX=175,screenY=100,left=175,top=100");
   // open document and write to it
   webpage.document.open();
 
   webpage.document.write("<HTML><HEAD><TITLE>This window closes itself</TITLE>");
   webpage.document.write("</HEAD>");
   webpage.document.write("<BODY BGCOLOR=#FFFFAA onBlur='self.close()'>");
   webpage.document.write("<FONT FACE=verdana COLOR=#339933>");
   webpage.document.write(htmlstring)
   webpage.document.write("</FONT>");
   webpage.document.write("</BODY></HTML>");
   // close the document - (not the window! I've asked that to shut itself ...)
   webpage.document.close();  
                    }
					
function openWin3(graphic,title)  
                   {
   // open new window with name 'picture'.
 
   picture= open("", "diagram", "scrollbars=no,width=293,height=245,screenX=175,screenY=120,left=175,top=120");
   // open document and write to it
   picture.document.open();
  
   picture.document.write("<HTML><HEAD><TITLE>");
   picture.document.write(title);
   picture.document.write("</TITLE></HEAD><BODY onBlur='self.close()'>");
   picture.document.write("<CENTER>");
   picture.document.write('<IMG SRC="');
   picture.document.write(graphic);
   picture.document.write('">');
   picture.document.write("</CENTER>");
   picture.document.write("</BODY></HTML>");
   // close the document - (not the window! I've asked that to shut itself ...)
   picture.document.close();  
                    }
					
function openWin4(graphic,title)  
                   {
   // open new window with name 'picture'.
 
   picture= open("", "diagram", "scrollbars=no,width=440,height=468,screenX=175,screenY=75,left=175,top=75");
   // open document and write to it
   picture.document.open();
  
   picture.document.write("<HTML><HEAD><TITLE>");
   picture.document.write(title);
   picture.document.write("</TITLE></HEAD><BODY onBlur='self.close()'>");
   picture.document.write("<CENTER>");
   picture.document.write('<IMG SRC="');
   picture.document.write(graphic);
   picture.document.write('">');
   picture.document.write("</CENTER>");
   picture.document.write("</BODY></HTML>");
   // close the document - (not the window! I've asked that to shut itself ...)
   picture.document.close();  
                    }	

// The following handles requests from user to install a Markhelp sidebar tab.				
					
function insert_sidebar_markhelp()

{ if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function"))
{ window.sidebar.addPanel ("Mark's Help","http://users.bathspa.ac.uk/markhelp/index_sidebar.html",""); } }
					
/*
					
*/

// The following modified from http://www.eposic.com/samples/generators/part1.html -
// with thanks - it's used in the ECDL test chooser page.

function makeArray(len)
{
for (var i=0; i<len; i++)
this[i] = null;
this.length = len;
}
function random(n)
{
seed = (0x015a4e35 * seed) % 0x7fffffff;
return (seed >> 16) % n;
}
var now;
var seed;
var things;
var numThings;

function initvars()
{
now = new Date();
seed = now.getTime() % 0xffffffff;
numThings = 0;
things = new makeArray(0);
things[numThings++] = " Test 1 ";
things[numThings++] = " Test 2 ";
things[numThings++] = " Test 3 ";
things[numThings++] = " Test 4 ";
}

function genthing()
{
var whichThing = random(numThings);
var thingText = things[whichThing];
document.theform.Thing.value = thingText;
return;
}



/* *  *  *  *  *  *  *  *  *  *  *  *  *

   Javascript styleswitcher from 'alistapart'
   http://www.alistapart.com/stories/alternate/

  *  *  *  *  *  *  *  *  *  *  *  *  * */

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);

/* the following from: http://www.phon.ucl.ac.uk/home/mark/audio/play.htm

These are the JavaScript functions.
     The PlaySound() function requires a <bgsound id="sound"> tag somewhere
	 in the file.
	 The EvalSound() functions requires a <embed src=...> tag with a name
	 attribute matching the name of the object called.
	 The DHTMLSound() function requires a <span id=dummyspan></span> tag
	 somewhere in the file.

	 10-May-2006 the javascript functions have been moved to an included file to circumvent Microsoft's IE disaster
*/

function EvalSound(soundobj) {
  var thissound=document.getElementById(soundobj);
  thissound.Play();
}

//
// The End!
