// JavaScript Document

window.onload = initialise;

function initialise(){
	initSearchBox();
	currentPageLink();
	resetDropdowns();
	if(document.location.href == 'http://www.surrey.ac.uk/gateway/test/slideshow.htm'){
	  openSlideshow('campus.xml');
	  }
	var pageURL = document.location.href;
	//Check to see whether we're in the stationery ordering process and if so, call the init() function
	if(pageURL.indexOf('http://www.surrey.ac.uk/brand/stationery') > -1){
	  init();
	  }
    // Call the function to style abbreviation tags in IE
	// Actually, leave it out for now as it's causing problems in Portal Edit mode
	//styleAbbr();
	}


// This function clears the search box of the default text
var defaultSearch = 'Search...';

function initSearchBox(){
	if(document.forms.searchform.q.value == ''){
		document.forms.searchform.q.value = defaultSearch;
	}
}

function clearSearch(searchBox){
	if(searchBox.value == defaultSearch){
		searchBox.value = '';
 		}
	}
	
function currentPageLink(){
	for(var i=0; i<document.links.length; i++){
		if(document.location.href.toUpperCase() == document.links[i].href.toUpperCase()){
			document.links[i].className = 'currentPageLink';
			}
		}
	}

function dropdownRedirect(url){
	if(url != ''){return true;}
	else{return false;}
	}
	
function resetDropdowns(){
	document.forms.information_for.url.selectedIndex = 0;
	document.forms.information_about.url.selectedIndex = 0;
	}
	
	
function translation(url) {
  newWindow = window.open(url, 'Translation', 'width=432, height=100, scrollbars=yes');
  }	
  
  Rollimage = new Array()

  Rollimage[0]= new Image()
  Rollimage[0].src = "http://www.surrey.ac.uk/assets/images/nursing.jpg"

  Rollimage[1] = new Image()
  Rollimage[1].src = "http://www.surrey.ac.uk/assets/images/nursingroll.jpg"

  function SwapOut(){
    document.nursing.src = Rollimage[1].src;
    return true;
  }

  function SwapBack(){
    document.nursing.src = Rollimage[0].src; 
    return true;
  }


  // This script, taken from http://www.sovavsiti.cz/css/abbr.html, is used to enable abbr tags to display their titles in IE
  // Inserted by Matt Farrow, 29 January 2008

  var isIE = (document.all) ? true:false;

  function styleAbbr() {
    var oldBodyText, newBodyText, reg
    if (isIE) {
      oldBodyText = document.body.innerHTML;
      reg = /<ABBR([^>]*)>([^<]*)<\/ABBR>/g;
      newBodyText = oldBodyText.replace(reg, '<ABBR $1><SPAN class=\"abbr\" $1>$2</SPAN></ABBR>');
      document.body.innerHTML = newBodyText;
      }
    }