<!--//
//Copyright© 2005 Fresh Ideas Scotland Ltd. All Rights Reserved.
//**Start Encode**
function verifyCorrectBrowser(){
  if(navigator.appName == "Microsoft Internet Explorer")
    if (navigator.appVersion.indexOf ("5.") >= 0)
      return(true);
    else
      return(false);
}
function getAppropriatePage(){
  var str1 = "Had this been an actual Web site, a page compatible with ";
  var str2 = "browsers other than ";
  var str3 = "Microsoft Internet Explorer 5.0 ";
  var str4 = "would have been loaded.";
  if (verifyCorrectBrowser())
    document.write(str1 + str3 + str4);
  else
    document.write(str1 + str2 + str3 + str4);
}
//-->



// Globals
var W3CDOM = (document.getElementsByTagName && document.createElement);
var curZoom = 100;
var validForm = true;
var firstError;
var isOpera = navigator.userAgent.indexOf("Opera") > -1; 
var isIE = navigator.userAgent.indexOf("MSIE") > 1 && !isOpera; 
var isMoz = navigator.userAgent.indexOf("Mozilla/5.") == 0 && !isOpera;

var currentTicker, firstTicker, tickerFilter, tickerMsgs, tickerCount = 0, tickerTimeout, clockInt;

// ticker
function pauseTicker() { clearInterval(tickerTimeout); }
function resumeTicker() { tickerTimeout = setInterval(changeTicker, 6000); }

// event handlers
onload = function() { init(); }

function init()
{
	// set current zoom from cookie if present
	if (GetCookie("currentZoom") != null) {
		curZoom = parseInt(GetCookie("currentZoom"));
		do_Zoom();
	}

	initSiteStat();
	
	// don't run ticker code for browsers that don't support the W3C DOM
	if (!document.createElement) return false;
 
	if (isIE) initIE();
	if (isOpera) initOpera();

	document.forms[0].onsubmit = function (){
		return validate()
	}
	
	if (document.getElementById)
	{
		initTickers();
		initOpeners();
		initHoverLinks();
		showSearchHighlight();	
	}
}

function initSiteStat() {
	thisHost = location.hostname.toLowerCase();
	thisPath = location.pathname.toLowerCase();
	
	if (thisPath == '/') thisPath = '/home';
	thisPath = thisPath.substr(1).replace(/\//gi,".");
	if (thisPath.charAt(thisPath.length-1)==".") thisPath = thisPath.substr(0,thisPath.length-1);
	
	thisPath="http://uk.sitestat.com/scottishexecutive/scottishexecutive/s?" + thisPath + ".p&amp;ns__t="+(new Date()).getTime();
	
	ns_0=document.referrer;
	
	ns_0=(ns_0.lastIndexOf("/")==ns_0.length-1)?ns_0.substring(ns_0.lastIndexOf("/"),0):ns_0;
	if(ns_0.length>0)thisPath+="&amp;ns_referrer="+escape(ns_0);
	if (thisHost.indexOf(".") > -1) { 
	// || thisHost == 'sh81inta'
		if(document.images){
			window.status = thisPath;
			ns_1=new Image();
			ns_1.src=thisPath;
		}else {
			document.write("<img src=\""+thisPath+"\" width=\"1\" height=\"1\" />");
			window.status = "write - " & thisPath;
		}
	}
}

function initOpeners() {
	var anchorLinks = document.getElementsByTagName("a");
	for (var i=0;i<anchorLinks.length;i++)
		if (anchorLinks[i].className == 'newWin')
			anchorLinks[i].target = '_blank';
}

function initHoverLinks() {
	var anchorLinks = document.getElementsByTagName("a");
	for (var i=0;i<anchorLinks.length;i++)
		if (anchorLinks[i].className.indexOf('hover') > -1 ) {
			anchorLinks[i].onmouseover = HoverDiv;
			anchorLinks[i].onmouseout = UnHoverDiv;
		}
}

function HoverDiv(e) {
	var targ = getEventTarget(e);
	targ.parentNode.parentNode.className += ' hover';
}

function UnHoverDiv(e) {
	var targ = getEventTarget(e);
	targ.parentNode.parentNode.className = targ.parentNode.parentNode.className.replace(/ hover/gi,'');
}

function initTickers() {
	// test if ticker exists in this document
	if (!window.tickerList) tickerList = document.getElementById("tickerList");

	if (tickerList && !currentTicker && !window.opera)
	{
		// get collection of list items
		tickerMsgs = tickerList.getElementsByTagName("li");
		// current item initialises to first in list
		currentTicker = tickerMsgs[0];

		// if more than one item in list set up changing code
		if (tickerMsgs.length > 1)
		{
			// control events to pause display when mouse is over "ticker" box
			tickerList.onmouseover = pauseTicker;
			tickerList.onmouseout = setTickerTimeout = resumeTicker;
			
			// fancy effects in IE use filter effect on div containing ul
			var filterObj = currentTicker.parentNode.parentNode;
			// verify that filters are defined on div
			tickerFilter = (filterObj.filters && filterObj.filters.length > 0) ? filterObj.filters[0] : null;
			
			setTickerTimeout();

			// get all the anchors contained in the list items
			var tickerLinks = tickerList.getElementsByTagName("a");
			// cycle through collection
			for (var i=0; i<tickerLinks.length; i++)
			{
				// attach control functions to anchors focus and blur events
				tickerLinks[i].onfocus = pauseTicker;
				tickerLinks[i].onblur = resumeTicker;
				// hide all but first item
				if (i>0) tickerMsgs[i].style.display = "none";
			}
			
		}
		else
		{
			// Only one news item, no need to change ticker
			tickerMsgs[0].style.display = "block";
		}
		if (document.readyState && document.readyState=="complete") loaded = true;
	}
}
function changeTicker() {
	if (currentTicker == tickerMsgs[tickerCount]) {
		if (tickerFilter)
			tickerFilter.apply();
		currentTicker.style.display = "none";
		if (tickerFilter) {
			tickerFilter.play();
			setTimeout(changeTicker2, 1150);
		} else {
			changeTicker2();
		}
	}
}

function changeTicker2() {
	if (tickerFilter)
		tickerFilter.apply();
	tickerCount = (++tickerCount == tickerMsgs.length) ? 0 : tickerCount;
	currentTicker = tickerMsgs[tickerCount];
	currentTicker.style.display = "block";
	if (tickerFilter)
		tickerFilter.play();
}

/* http://www.kryogenix.org/code/browser/searchhi/ */
/* Modified 20021006 to fix query string parsing and add case insensitivity */

function highlightWord(node,word) {
	// Iterate into this nodes childNodes
	if (node.hasChildNodes) {
		var hi_cn;
		for (hi_cn=0;hi_cn<node.childNodes.length;hi_cn++) {
			highlightWord(node.childNodes[hi_cn],word);
		}
	}
	
	// And do this node itself
	if (node.nodeType == 3) { 
	// text node
		tempNodeVal = node.nodeValue.toLowerCase();
		tempWordVal = word.toLowerCase();
		if (tempNodeVal.indexOf(tempWordVal) != -1) {
			pn = node.parentNode;
			if (pn.className != "searchword") {
				// word has not already been highlighted!
				nv = node.nodeValue;
				ni = tempNodeVal.indexOf(tempWordVal);
				// Create a load of replacement nodes
				before = document.createTextNode(nv.substr(0,ni));
				docWordVal = nv.substr(ni,word.length);
				after = document.createTextNode(nv.substr(ni+word.length));
				hiwordtext = document.createTextNode(docWordVal);
				hiword = document.createElement("span");
				hiword.className = "searchword";
				hiword.appendChild(hiwordtext);
				pn.insertBefore(before,node);
				pn.insertBefore(hiword,node);
				pn.insertBefore(after,node);
				pn.removeChild(node);
			}
		}
	}
}

function showSearchHighlight() {
	if (!document.createElement) return;
	ref = document.referrer;
	if (ref.indexOf('?') == -1) return;
	qs = ref.substr(ref.indexOf('?')+1);
	qsa = qs.split('&');
	for (i=0;i<qsa.length;i++) {
		qsip = qsa[i].split('=');
	    if (qsip.length == 1) continue;
        if (qsip[0] == 'q' || qsip[0] == 'p' || qsip[0] == 'sClue') {
        // q= for Google; p= for Yahoo; sClue = Convera
			words = unescape(qsip[1].replace(/\+/g,' ')).split(/\s+/);
	        for (w=0;w<words.length;w++) {
				if (words[w].length > 2) {
					highlightWord(document.getElementsByTagName("body")[0],words[w]);
				}
            }
		}
	}
}

function initIE() {
	if (navigator.appVersion.indexOf('MSIE 4') > 0) return;
	var oldBodyText, newBodyText, reg;
	
	if (document.all.mainBody) {
		oldBodyText = document.all.mainBody.innerHTML;
		if (oldBodyText.indexOf("<IFRAME") > 0) return;
		reg = /<ABBR([^>]*)>([^<]*)<\/ABBR>/g;
		newBodyText = oldBodyText.replace(reg, '<ABBR $1><SPAN class=\"help\" $1>$2</SPAN></ABBR>');
		document.all.mainBody.innerHTML = newBodyText;
		

		/* attach resize event and do initial resize */
		/*IE_Resize();
		window.onresize = IE_Resize; */
	}
}

/*
function IE_Resize() {
	if (document.all.pageForm.action == '/Home') return;
	
	var cWidth = document.all.mainBody.clientWidth;
	var mClass = document.all.mainColumn.className;
	if (mClass == "noright" || mClass == "noleft") {
		if (navigator.appVersion.indexOf('MSIE 5') > 0) {
			//document.all.mainColumn.style.width = cWidth - 179;
			//document.all.mainColumn.style.overflow = "auto";
		} else {
			document.all.mainColumn.style.width = cWidth - 195;
			document.all.mainColumn.style.overflowX = "auto";
		}
	}
	if (mClass == "threecol") {
		if (navigator.appVersion.indexOf('MSIE 5') > 0) {
			//document.all.mainColumn.style.width = cWidth - 374;
			//document.all.mainColumn.style.overflow = "auto";
		} else {
			document.all.mainColumn.style.width = cWidth - 390;
			document.all.mainColumn.style.overflowX = "auto";
		}
	}		
}
*/

function initOpera() {
	if (document.all.newsTicker)
		document.all.newsTicker.style.overflow = "auto";
}

/*** Text zooming ***/
function ZoomOut() {
	if (curZoom > 70) curZoom -= 10;
	do_Zoom();
	return false;
}

function ZoomIn() {
	if (curZoom < 250) curZoom += 10;
	do_Zoom();
	return false;
}

function ZoomDefault() {
	curZoom = 100;
	do_Zoom();
	return false;
}

function ZoomTo(z) {
	curZoom = z;
	do_Zoom();
	return false;
}

function do_Zoom() {
	document.getElementsByTagName("body")[0].style.fontSize = curZoom + '%';
	document.getElementById("z1").firstChild.className = "";
	document.getElementById("z2").firstChild.className = "";
	document.getElementById("z3").firstChild.className = "";
	document.getElementById("z4").firstChild.className = "";
	
	if (curZoom == 80) document.getElementById("z1").firstChild.className = "on";
	if (curZoom == 100) document.getElementById("z2").firstChild.className = "on";
	if (curZoom == 125) document.getElementById("z3").firstChild.className = "on";
	if (curZoom == 145) document.getElementById("z4").firstChild.className = "on";
	
	SetCookie("currentZoom",curZoom,false);
}

function GetCookie(sName) {
	var aCookie = document.cookie.split("; ");
	for (var i=0; i < aCookie.length; i++) {
		var aCrumb = aCookie[i].split("=");
		if (sName == aCrumb[0]) 
			return unescape(aCrumb[1]);
	}
	return null;
}

function SetCookie(sName, sValue, isSession) {
	if (!isSession) {
		date = new Date(2010,12,31);
		document.cookie = sName + "=" + escape(sValue) + "; path=/; expires=" + date.toGMTString();
	} else {
		document.cookie = sName + "=" + escape(sValue) + "; path=/;";
	}
}

function getEventTarget(e) {
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	// defeat Safari bug
	if (targ.nodeType == 3) 
		targ = targ.parentNode;
	return targ;
}


/******* FORMS ********/
// modified from Quirksmode example
// may need to hide code from IE Mac
function validate() {
	validForm = true;
	errorstring = '';
	firstError = null;
	
	var x = document.forms[0].elements;
	for (var i=0;i<x.length;i++)
	{
		if (x[i].className.indexOf("required") > -1)
		{
			// Ordinary text box
			if (!x[i].value && x[i].type=='text')
				writeError(x[i]);
				
			// Multiline text box
			if (x[i].tagName.toLowerCase() == 'textarea' && !x[i].value)
				writeError(x[i]);
			
			//alert(x[i].tagName);
			// Dropdown list
			if (x[i].tagName.toLowerCase() == 'select') {
				if (x[i].selectedIndex < 1)
					writeError(x[i]);
				if (x[i].selectedIndex > 0)
					if (x[i].options[x[i].selectedIndex].value == '')
						writeError(x[i]);
			}
		}
		
		// Validate email fields
		if ((x[i].className.indexOf("Email") > -1)  && (!x[i].value.match(/^(([a-z0-9_\-]+)\.)*[a-z0-9_\-]+@(([a-z0-9_\-]+)\.)+[a-z0-9_\-]+$/i)))
		{
			if (x[i].value)
				writeInvalid(x[i],"not a valid email address format");
		}
		
		// Validate number fields
		if ((x[i].className.indexOf("Number") > -1) && (x[i].value))
		{
			if (x[i].value) {
				var num = parseFloat(x[i].value);
				//alert(isNaN(num));
				if (isNaN(num))
					writeInvalid(x[i], "not a valid number")
				else {
					// check for range limit
					if (document.getElementById(x[i].parentNode.id + "_Min")) {
						var minValue = parseFloat(document.getElementById(x[i].parentNode.id + "_Min").value);
						var maxValue = parseFloat(document.getElementById(x[i].parentNode.id + "_Max").value);
						if (num < minValue || maxValue < num) {
							writeInvalid(x[i], "Value must be between " + minValue + " and " + maxValue);
						}
					}
				}
			}
		}
		
		// Validate Date fields
		if (x[i].className.indexOf("Date") > -1)
		{
			if (x[i].value) {
				var dt = Date.parse(x[i].value);
				if (isNaN(dt))
					writeInvalid(x[i],"invalid date format")
				else {
					// check for range limit
					if (document.getElementById(x[i].parentNode.id + "_Min")) {
						var minValue = new Date(document.getElementById(x[i].parentNode.id + "_Min").value);
						var maxValue = new Date(document.getElementById(x[i].parentNode.id + "_Max").value);
						dt = new Date(x[i].value);
						//alert(minValue);
						//alert(dt);
						//alert(dt < minValue);
						//alert(maxValue < dt);
						if (dt < minValue || maxValue < dt) {
							writeInvalid(x[i], "Value must be between " + minValue.toGMTString().substring(5,16) + " and " + maxValue.toGMTString().substring(5,16));
						}
					}
				}
			}

		}
	}
	
	// required Checkboxlist or Radiobuttonlist
	x = document.getElementsByTagName("fieldset");
	for (var i=0;i<x.length;i++) {
		if (x[i].className.indexOf("required") > -1)
		{
			var selectedIndex = -1;
			
			// step through all child input controls
			var fx = x[i].getElementsByTagName("input");
			for (var j=0;j<fx.length;j++) {
				if (fx[j].checked)
					selectedIndex = j;
			}
			
			// check if we failed to find a selected item
			if (selectedIndex == -1) {
				writeError(x[i]);
			}	
		}
	}
	
	if (!W3CDOM)
		alert(errorstring);
	
	if (firstError)
		firstError.focus();
	
	return validForm;
}

function writeInvalid(obj, msg)
{
	if (validForm)
		firstError = obj;
	validForm = false;

	if (obj.hasError)
		return;
	
	if (W3CDOM)
	{
		obj.className += ' error';
		obj.onchange = removeError;
		var sp = document.createElement('span');
		sp.className = 'error';
		sp.appendChild(document.createTextNode(msg));
		obj.parentNode.appendChild(sp);
		obj.hasError = sp;
	}
	else
	{
		errorstring += obj.name + ': ' + message + '\n';
		obj.hasError = true;
	}
}

function writeError(obj)
{
	//if (obj.tagName == 'fieldset') return;

	if (validForm)
		firstError = obj;
	validForm = false;

	if (obj.hasError)
		return;
	
	if (W3CDOM)
	{
		message="required";
		if (document.getElementById(obj.parentNode.id + "_errMsg"))
			message =document.getElementById(obj.parentNode.id + "_errMsg").value;
		obj.className += ' error';
		obj.onchange = removeError;
		var sp = document.createElement('span');
		sp.className = 'error';
		sp.appendChild(document.createTextNode(message));
		obj.parentNode.appendChild(sp);
		obj.hasError = sp;
	}
	else
	{
		errorstring += obj.name + ': ' + message + '\n';
		obj.hasError = true;
	}
}

function removeError()
{
	this.className = this.className.substring(0,this.className.lastIndexOf(' '));
	this.parentNode.removeChild(this.hasError);
	this.hasError = null;
	this.onchange = null;
}

// JavaScript Document
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->

<!--
	var lastWidth = window.innerWidth;
	var lastHeight = window.innerHeight;


	function PW_ReDrawNetscape() 
	{ 
		if (document.layers) //  are we in dhtml ns4?
		{	
			if( (lastWidth != window.innerWidth) || (lastHeight != window.innerHeight))
			{
		   	 window.location=window.location;	// this'll toggle.
				 lastWidth = window.innerWidth;
				 lastHeight = window.innerHeight;
			}
		}
	}
//-->

<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);


// <![CDATA[

function swap(targetId,buttonId){
  
  if (document.getElementById)
        {
        target = document.getElementById(targetId);
  	    buttonName = document.getElementById(buttonId);
          
            if (target.style.display == "none")
                {
                target.style.display = "block";
                } 
            else 
                {
                target.style.display = "none";
                }

			if (target.style.display == "none")
                {
                buttonName.src = "assets/closed.gif";
                }
            else 
                {
                buttonName.src = "assets/open.gif";
                }
                
        }
}
// ]]>

function compareEmails(catalogue) {
        if (catalogue.email.value != catalogue.email2.value) {
                alert("Your email addresses don't match. Please double check");
                return false;
        } else {
                return true;
        }
}

<!--
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
//-->


<!--

var flashinstalled = 0;
var flashversion = 0;
MSDetect = "false";
if (navigator.plugins && navigator.plugins.length)
{
	x = navigator.plugins["Shockwave Flash"];
	if (x)
	{
		flashinstalled = 2;
		if (x.description)
		{
			y = x.description;
			flashversion = y.charAt(y.indexOf('.')-1);
		}
	}
	else
		flashinstalled = 1;
	if (navigator.plugins["Shockwave Flash 2.0"])
	{
		flashinstalled = 2;
		flashversion = 2;
	}
}
else if (navigator.mimeTypes && navigator.mimeTypes.length)
{
	x = navigator.mimeTypes['application/x-shockwave-flash'];
	if (x && x.enabledPlugin)
		flashinstalled = 2;
	else
		flashinstalled = 1;
}
else
	MSDetect = "true";

// -->

<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->



function toggleCS() 
{ 
cs=true; 
if(document.styleSheets.length>0) 
{ 
cs=!document.styleSheets[0].disabled; 
for(i=0;i<document.styleSheets.length;i++) 
{document.styleSheets[i].disabled=cs;} 
} 
} 


<!--
var doAlerts=true;
function changeSheets(whichSheet){
  whichSheet=whichSheet-1;
  if(document.styleSheets){
    var c = document.styleSheets.length;
    if (doAlerts) alert('Change to Style '+(whichSheet+1));
    for(var i=0;i<c;i++){
      if(i!=whichSheet){
        document.styleSheets[i].disabled=true;
      }else{
        document.styleSheets[i].disabled=false;
      }
    }
  }
}
//-->

var s=document.cookie.split(":");
var v=s[0],f=(s[1])?s[1]:'default.css';
document.write('<link rel="stylesheet" type="text/css" href="'+f+'">\n');//.css">\n');
function switchStyle (n,s){
  var x=new Date();x.setTime(x.getTime()+(60*60*24*365));
    document.cookie=s+':'+n+':'+';expires='+x.toGMTString()+';path=/';
      history.go(0);
}



<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->

<!--
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-->