/**************************/

/* Add Close Button */

var fldClose = document.getElementById('fldPopupCloseButton');
if (fldClose) {
	var divClose = document.createElement('div');
	divClose.className = 'popupButtonContainer';
	var btnClose = document.createElement('input');
	btnClose.type = 'image';
	btnClose.className = 'button close';
	btnClose.setAttribute("src","/Images/Home/tsp/buttons/btnCloseWindow.gif");
	btnClose.setAttribute("alt","close window");
	btnClose.setAttribute("title","close window");
	btnClose.setAttribute("name","btnClose");
	btnClose.setAttribute("id","btnClose");
	btnClose.setAttribute("value","close window");
	btnClose.onclick = function() {window.close();return false;};
	divClose.appendChild(btnClose);
	fldClose.appendChild(divClose);
}

/* Amended for WF76 - Review May 05*/


/* Add Close and Print Buttons */

var fldActButtons = document.getElementById('fldActionButtons');
if (fldActButtons) {
	var div = document.createElement('div');
	div.className = 'popupButtonContainer stackedButtonContainer';

	/* Add Close Button  */
	var divClose = document.createElement('div');
	var btnClose = document.createElement('input');
	btnClose.type = 'image';
	btnClose.className = 'button close';
	btnClose.setAttribute("src","/Images/Home/tsp/buttons/btnCloseWindow.gif");
	btnClose.setAttribute("alt","close window");
	btnClose.setAttribute("title","close window");
	btnClose.setAttribute("name","btnClose");
	btnClose.setAttribute("id","btnClose");
	btnClose.setAttribute("value","close window");
	btnClose.onclick = function() {window.close();return false;};
	divClose.appendChild(btnClose);

	/* Add Print Button  */
	var divPrint = document.createElement('div');
	var btnPrint = document.createElement('img');
	btnPrint.setAttribute("src","/Images/Home/tsp/buttons/btnPrintThisPage.gif");
	btnPrint.setAttribute("alt","print this page");
	btnPrint.setAttribute("title","print this page");
	btnPrint.setAttribute("name","btnPrint");
	btnPrint.setAttribute("id","btnPrint");
	btnPrint.style.cursor = (navigator.userAgent.indexOf("MSIE") > -1) ? 'hand':'pointer';
	btnPrint.onclick = function() {window.print(); return false;};
	divPrint.appendChild(btnPrint);

	/* Add button containers to container */
	div.appendChild(divPrint);
	div.appendChild(divClose);
	
	/* Add container to fieldset */
	fldActButtons.appendChild(div);
}

/***********************/
/* start of Cookies.js */

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;
}

/* end of Cookies.js */
/*********************/

/******************************/
/* start of HighVisibility.js */

var strCookie = "style";

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")) {
            var enabled = !a.disabled; a.disabled = true;
            if(!enabled && a.getAttribute("title") == title) {
                a.disabled = false;
            }
        }
    }
}


function setHighVisStyleSheet() 
{
    // set stylesheet regardless of widget's occurrence on this page
    var cookie = readCookie(strCookie);

    setActiveStyleSheet(cookie ? cookie : "");
    if (navigator.userAgent.indexOf("MSIE") > -1) {
        // MSIE needs a gentle reminder
        setActiveStyleSheet(cookie ? cookie : "");
    }
}

/* end of HighVisibility.js */
/****************************/

//setup encapsulated event handlers by known browser limitations
var kde = (navigator.vendor == 'KDE');
var op7 = /opera[\/ ]7/i.test(navigator.userAgent);

//konqueror supports addEventListener but in < 3.2 it doesn't work
//otherwise this is the standard condition
if(!kde && typeof window.addEventListener != "undefined")
{
    window.addEventListener('load',onloadFunction,false);
}
//opera supports addEventListener but the load event comes from document
else if(op7)
{
    document.addEventListener('load',onloadFunction,false);
}
//win/ie has a proprietary method
else if(typeof window.attachEvent != "undefined")
{
    window.attachEvent('onload',onloadFunction);
}
//for everyone else
else
{
    //if there's an existing onload function
    if(typeof window.onload == "function")
    {
        //copy it and then call it before our function
        var currentOnload = onload;
        window.onload = function()
        {
            currentOnload();
            onloadFunction();
        };
    }
    else
    {
        //otherwise just call our function
        window.onload = onloadFunction;
    }
    //this method will end up being mac/ie5, konqueror, 
    //and anything else that gets this far
    //this script should come *after* any other scripting on the page
    //to avoid overwriting other onload functions
}


//initialise constructor
function onloadFunction()
{
   	setHighVisStyleSheet();
}


