
/*
    Function to detect browser and platform, and returns a string:

    pcnetscape6  = netscape 6.x on pc
    pcnetscape4  = netscape 4.x on pc

    macie        = ie on macinstosh
    macnetscape4 = netscape 4.x on macintosh
    macnetscape6 = netscape 6.x on macintosh

    linux        = linux platform (browser not specified)
*/

function sniffer()
{
  result = ' ';
  var testos = navigator.platform.toLowerCase();
  if(navigator.appVersion.indexOf("Win") !=-1)
  {
    if(navigator.appName=="Netscape" && document.layers)
    {
      result = 'pcnetscape4';
      return result;
    }
    else if(navigator.appName=="Netscape" && document.getElementById)
    {
      result = 'pcnetscape6';
      return result;
    }
    else if(navigator.appName!="Netscape")
    {
      result = 'pcie';
      return result;
    }
  }
  else if (testos.indexOf("mac")==0)
  {
    var macnav = navigator.appName.toLowerCase();

    if (macnav.indexOf("netscape")==0 && document.layers)
    {
      result = 'macnetscape4';
      return result;
    }
    else if(macnav.indexOf("netscape")==0 && document.getElementById)
    {
      result = 'macnetscape6';
      return result;
    }
    else if(macnav.indexOf("netscape")!=0 && document.all)
    {
      result = 'macie';
      return result;
    }
  }

  else if(testos.indexOf("linux") == 0)
  {
    result = 'linux';
    return result;
  }
}

/*
   Function to sniff out platform and insert appropriate style sheet
*/

function insertcss()
{
  if( sniffer() == 'pcnetscape4')
    document.write ('<link rel=stylesheet href="nn_styles.css">');

  if( sniffer() == 'pcnetscape6')
    document.write ('<link rel=stylesheet href="ie_styles.css">');

  if( (sniffer()) == 'pcie')
    document.write('<link rel=stylesheet href="ie_styles.css">');

  if( (sniffer() == 'macnetscape4') || (sniffer() == 'macnetscape6') || (sniffer() == 'macie') )
    document.write ('<link rel=stylesheet href="mac_styles.css">');
}


/*
    Function to perform mouseovers on buttons, but will optionally change an extra image
    too. The extra image may have more than one rollover image, which can be specified.
*/

function imageswap(imagename,swaptype,imagename2,image2index) // swaptype 0 = onmouseover, 1 = onmouseout, 2 = onclick
{
  if(document.images)
  {
    if(swaptype==0) // onmouseover
    { document.images[imagename].src = eval(imagename + "b.src"); }
    if(swaptype==1) // onmouseout
    { document.images[imagename].src = eval(imagename + "a.src"); }
    if(swaptype==2) // onclick
    { document.images[imagename].src = eval(imagename + "c.src"); }

    if(imagename2!="") // test to see if an optional extra image to swap is specified
    {
      if(image2index==0) // onmouseover
      { document.images[imagename2].src = eval(imagename2 + "b.src"); }
      if(image2index==1) // onmouseout restore this page's default 'section' image
      { document.images[imagename2].src = eval(imagename2 + "a.src"); }
    }
  }
}

/*
	 =============================================================
	 Image swap function
	 =============================================================
*/

var preloadpix = new Array (

// navigation
  ["home",		"images/button_home_off.gif",			"images/button_home_over.gif"],
  ["calendar",	"images/button_calendar_off.gif",		"images/button_calendar_over.gif"],
  ["metrics",	"images/button_metrics_off.gif",		"images/button_metrics_over.gif"],
  ["exchange",	"images/button_exchange_off.gif",	    "images/button_exchange_over.gif"],
  ["contacts",	"images/button_contacts_off.gif",		"images/button_contacts_over.gif"],
  ["admin",		"images/button_admin_off.gif",		    "images/button_admin_over.gif"],
  ["logout",	"images/button_logout_off.gif",			"images/button_logout_over.gif"]
);



/*
	 =====================================================================================
	 Cycle through the preloadpix array, creating
	 image objects using the details specified in the
	 'imagesarray' array.
	 =====================================================================================
*/
function preloader(obj)
{
	for(var i=0;i<obj.length;i++)
	{
		eval(obj[i][0] + "a = new Image()");
		eval(obj[i][0] + "a.src = '" + obj[i][1] + "'");

		eval(obj[i][0] + "b = new Image()");
		eval(obj[i][0] + "b.src = '" + obj[i][2] + "'");
	}
}

preloader(preloadpix);

/*

	======================================================================================
	popup function
	======================================================================================

*/


function popup_form()
{
  var os = navigator.platform.toLowerCase();
  if(os.indexOf("mac")==0)
  {
    window.open('form.html','form','width=482,height=415,scrollbars=yes');
  }
  else 
  {
    window.open('form.html','form','width=450,height=430,scrollbars=yes');
  }
}

function popup_biography(myint)
{
  var os = navigator.platform.toLowerCase();
  if(os.indexOf("mac")==0)
  {
    window.open("biography.asp?id=" + myint,'biog','width=450,height=400,scrollbars=yes');
  }
  else 
  {
    window.open("biography.asp?id=" + myint,'biog','width=450,height=400,scrollbars=yes');
  }
}

function popup_tips()
{
  var os = navigator.platform.toLowerCase();
  if(os.indexOf("mac")==0)
  {
    window.open("search_tips.html",'tips','width=300,height=400,scrollbars=yes');
  }
  else 
  {
    window.open("search_tips.html",'tips','width=300,height=400,scrollbars=yes');
  }
}

function popup_upload(ThePath)
{
  var os = navigator.platform.toLowerCase();
  if(os.indexOf("mac")==0)
  {
    window.open('upload_file.asp?ThePath=' + ThePath,'myupload','width=400,height=172,scrollbars=no');
  }
  else
  {
    window.open('upload_file.asp?ThePath=' + ThePath,'myupload','width=400,height=172,scrollbars=no');
  }
}

function popup_createfolder(ThePath)
{
  var os = navigator.platform.toLowerCase();
  if(os.indexOf("mac")==0)
  {
   var  dippy = window.open('create_folder.asp?ThePath=' + ThePath,'myfolder','width=380,height=172,scrollbars=no');
  }
  else
  {
   var  dippy = window.open('create_folder.asp?ThePath=' + ThePath,'myfolder','width=380,height=172,scrollbars=no');
  }

}
function popupitem(path)
{
   var itempopup=window.open(path,'itempopup','width=270,height=200,left=0,top=0');
}
function _pop(url){
	var w = 760;
	var h = 520;	
	var l = (screen.width-w)/2;
	var t = (screen.height-h)/2;	
	var win = window.open(url,'v','left='+l+',top='+t+',width='+w+',height='+h+',status');
	win.focus();

}
// Popup window functions for Short Courses activities
function _popVideoActivities(url){
	var w = 772;
	var h = 562;	
	var l = (screen.width-w)/2;
	var t = (screen.height-h)/2;	
	var win = window.open(url,'vid','left='+l+',top='+t+',width='+w+',height='+h+',status');
	win.focus();
}
function _popInteractiveActivities(url){
	var w = 772;
	var h = 562;	
	var l = (screen.width-w)/2;
	var t = (screen.height-h)/2;	
	var win = window.open(url,'int','left='+l+',top='+t+',width='+w+',height='+h+',status');
	win.focus();
}
function _popMobileActivities(url){
	var w = 772;
	var h = 582;	
	var l = (screen.width-w)/2;
	var t = (screen.height-h)/2;	
	var win = window.open(url,'mob','left='+l+',top='+t+',width='+w+',height='+h+',status');
	win.focus();
}
// Popup window function for Conference Booking
function _popConferenceBook(url){
	var w = 668;
	var h = 562;	
	var l = (screen.width-w)/2;
	var t = (screen.height-h)/2;	
	var win = window.open(url,'vid','left='+l+',top='+t+',width='+w+',height='+h+',scrollbars=yes,location=no,status');
	win.focus();
}
//////
var itempopup=false;
function popup(path,scrollbars,width,height)
{
if(typeof(scrollbars)==undefined)scrollbars='no';
if(typeof(width)==undefined)width=780;
if(typeof(height)==undefined)height=480;
   itempopup=window.open(path,'itempopup','width='+width+',height='+height+',left=0,top=0,scrollbars='+scrollbars);
   itempopup.moveTo(0,0);
}
var itempopup='';
function popup2(path)
{
	if(!itempopup.closed && itempopup.location){itempopup.location.href=path;itempopup.window.resizeTo(200,200);}
   itempopup=window.open(path,'itempopup','width=200,height=150,scrollbars=yes,left=0,top=0');
   itempopup.moveTo(0,0);
   if(window.focus)itempopup.focus();
}


/*linktext*/
var tabtext=Array('','Description','More','Buy this item');

function swapItemContent(id,tab)
{
if(document.getElementById('d2_'+id).style.display=='block' || tab==2)restoreThumb(id);
allTabsDown(id);
document.getElementById('d'+tab+'_'+id).style.display='block';
changeTabUp(id,tab);
}

function allTabsDown(id)
{
	var t;
	for(i=1;i<4;i++){//go through all 3 tabs
	t=document.getElementById('t'+i+'_'+id);//get the element
	document.getElementById('d'+i+'_'+id).style.display='none';//hide the content
	if(t.getElementsByTagName("span")[0]){//only change if required, to avoid some flickering
		t.className='itemtab'+i;//change the class
		t.innerHTML='<a class="tab" href="javascript:swapItemContent('+id+','+i+');">'+tabtext[i]+'</a>';
		}
	}
}
function changeTabUp(id,tab){
	var thetab=document.getElementById('t'+tab+'_'+id); //get the tab
	thetab.className='itemtab'+tab+'_up'; //change the class
	thetab.innerHTML='<span class="taboff">'+tabtext[tab]+'</span>'; //remove the link
}

/* function to change the thumbnail and its associated link*/
function changeThumb(id, dir, thumb, alias, fullsize,ilink,first)
{
	
	//var type=ilink.getElementsByTagName("img")[0].alt;
	//if(type=="flash" && first!="1")popup(fullsize);
	restoreText(id);
	var theLink=document.getElementById('img_'+id); //link
	var theImg=theLink.getElementsByTagName("img")[0];//image within
	theImg.src=thumb;
	theImg.alt=alias;
	theLink.href=fullsize;
	theLink.title=alias;
theLink.onclick=function(){popup2(fullsize);return false;};theImg.className="item_image";
theLink.style.visibility="visible";
	//if(type=="image"){}
	//if(type=="flash"){theLink.onclick=function(){popup(fullsize);return false;};theImg.className="item_media";}
	//if(type!="flash" && type!="image"){theLink.onclick="";theImg.className="item_media";}
	/* indicate link */
		ilink.style.textDecoration='none';
		ilink.style.color='#ccc';
}

/*return thumbnail to first link, taking arguments from onclick*/
function restoreThumb(id)
{
	restoreText(id); //first set all text to normal
	var div=document.getElementById('d2_'+id); //containing div
	var links=div.getElementsByTagName('a'); //links within
	var dets;
	for (var i=0;i<links.length;i++){
		if(links[i].onclick && links[i].onclick.toString().indexOf('changeThumb')!=-1){
			dets=links[i].onclick.toString(); //convert from object to string
			dets=dets.split("\n")[2] // take out the function itself 
			if(dets.split('\'')[1])dets=dets.split('\''); // IE uses ' to seperate the arguments
			else dets=dets.split('\"'); //mozilla uses "
//alert(dets[1]+", "+dets[3]+", "+dets[5]+", "+dets[7]);
			//changeThumb(id,"","","",dets[7],"",1); //change the thumbnail
	var theLink=document.getElementById('img_'+id); //link
	var theImg=theLink.getElementsByTagName("img")[0];//image within
	theImg.src="images/nocolour_spacer.gif";theImg.alt="";
theLink.href="";theLink.title="";theImg.className="item_image";theLink.onclick=null;
theLink.style.visibility="hidden";
			break; //don't do it on any other images !
		}
	}
}

/* change all more text links to normal*/
function restoreText(id)
{
	var div=document.getElementById('d2_'+id);//containing div
	var links=div.getElementsByTagName('a');//links within

	for (var i=0;i<links.length;i++){
		if(links[i].onclick){ //if it has a onclick
			links[i].style.textDecoration='underline'; //set to normal
			links[i].style.color='#000'; 
	}
}

	
}

function ecommerce(buy)
{
var option=window.confirm("An e-mail will now be sent to each of the sellers informing them that you wish to purchase these items. \nThe seller will get in touch with you as soon as possible with details on how you can pay for these items.", "");
var add='ecomm.php';
if (option) buy.submit();
}


function rollover(alink)
{
	var but=alink.getElementsByTagName("img")[0];
	var rollover='_omo'; // holds the suffix given to the rollover state
	var suffix = but.src.substring(but.src.lastIndexOf('.')); //holds the file extension
	//take the last 4 characters off to check if it already rolled over
	var omo= but.src.substring((but.src.lastIndexOf('.')-(rollover.length)),but.src.lastIndexOf('.')); 
	var newsrc; // variable to hold the new src url
	//if it is already rolled over, take off the suffix
	if (omo==rollover) {
		newsrc=but.src.substring(0,(but.src.lastIndexOf('.')-(rollover.length)));
		newsrc=newsrc+suffix;
	}
	//otherwise add the rollover suffix
	else{
		newsrc=but.src.substring(0,but.src.lastIndexOf('.'));
		newsrc=newsrc+ rollover + suffix;
	}
	//change the button src
	but.src=newsrc;
}

//ctad_included("rollover.js");
//ctad_require("functions.js");

/**
Rollover is a static class providing a function to automatically install rollover capabilities on 
arbitrary images in the page. The function is automatically run onload. It scans the page for images 
with a src which ends in _ro. it then installs the necessary mouseovers/mousouts to do
rollovers on the image. if you have an image with name ending _ro, you must have a corresponding image 
with name _omo. for example nice_ro.gif needs nice_omo.gif.

@usage: just include rollover.js in the header. functions.js is also required . if you had to make a fake functions.js
in an emergency to suit this you would at least need the event_install and ctad_error functions.
you would also need the settings.js file setting functions_debug. this script also requires
getElementsByTagName which the normal functions.js 'repairs' for older IE browsers

@author: jo frudd
@author: jon halle

	$Id: rollover.js,v 1.3 2005/03/16 16:18:43 jonh Exp $
*/
function Rollover(){

}

/**
setting for time to wait before checking if preload worked (in ms)
*/
Rollover.wait_for_preload=2000;
	
/**
installs rollovers on images which fit the naming scheme
*/
Rollover.install= function(){

	
	var imgs = document.getElementsByTagName('img');
	for (var i=0;i<imgs.length;i++){
		if (imgs[i].src.match(/_ro\..*$/i)){
			var img=imgs[i];
			img.i_src=img.src;
			img.r_src=img.i_src.replace(/_ro\./i,"_over.");
			event_install(img,"onmouseover",function(){this.src=this.r_src;});
			event_install(img,"onmouseout",function(){this.src=this.i_src;});
			Rollover.preload(img.i_src);
			Rollover.preload(img.r_src);
		}
	}

}
	
	
	


/**
preload an arbitrary src
*/
Rollover.preload=function(src){
	var img = new Image();
	
	//test for success
	//img.onerror would be easiest but mozilla does not support it for local files
	img.onload=function(){this.loaded=true;};
	window.setTimeout(function(){Rollover.check_loaded(img)},Rollover.wait_for_preload)	;
	
	img.src=src;
	
}

/**
show developer error for any image which doesnt preload
*/
Rollover.check_loaded=function(img){
	/*if (!img.loaded){
		alert("Image "+img.src.split("/").pop()+" does not exist but rollover wants to preload it. Full path is:\n"+img.src);
	}*/

}

//install this onload
event_install(window,"onload",Rollover.install);
function event_install(obj,event_name,f){
	if (obj.addEventListener){	//W3C
		obj.addEventListener(event_name.substr(2), f,false);
	}else if (obj.attachEvent){	 //IE 
		obj.attachEvent(event_name, function(){obj._f=f;obj._f();obj_f=null});
	}
}
function disablefields(elem)
{
	/*var inputs=document.getElementsByTagName("input");
	var textareas=document.getElementsByTagName("textarea");
	var selects=document.getElementsByTagName("select");
	var found=0;
	if(elem.checked){
	for (var i=0;i<inputs.length;i++){
		if(found==1 && inputs[i].type!="checkbox" && inputs[i].type!="submit"){inputs[i].readOnly=true;inputs[i].style.visibility='hidden';}
		if(inputs[i]==elem)found=1;
	}
	for (var i=0;i<textareas.length;i++){
		textareas[i].readOnly=true;textareas[i].style.visibility='hidden';
	}
		for (var i=0;i<selects.length;i++){
		if(selects[i].name!='location'){selects[i].readOnly=true;selects[i].style.visibility='hidden';}
	}

	}
	else{
	for (var i=0;i<inputs.length;i++){
		if(found==1 && inputs[i].type!="checkbox" && inputs[i].type!="submit"){inputs[i].readOnly=false;inputs[i].style.visibility='visible';}
		if(inputs[i]==elem)found=1;
	}
	for (var i=0;i<textareas.length;i++){
		textareas[i].readOnly=false;textareas[i].style.visibility='visible';
	}
		for (var i=0;i<selects.length;i++){
		selects[i].readOnly=false;selects[i].style.visibility='visible';
	}
	}
	*/
}
