// JavaScript Document

// ----- START Text Resizer -----
// set the font size according to the user's preference, called by setFontSize() or user click
function chgFontSz(i) {
	var bodyID = document.getElementsByTagName("body")[0];
	setCookie(i);
	switch(i) {
		case "1":
			bodyID.style.fontSize="100%";
			break;
		case "2":
			bodyID.style.fontSize="115%";
			break;
		case "3":
			bodyID.style.fontSize="130%";
			break;
	}
	return false
}

// saves the font size preference to a cookie, expires in one year
function setCookie(i) {
	var nextyear = new Date();
	nextyear.setFullYear(nextyear.getFullYear() + 1);
	document.cookie = "diageofontsize=" + i + "; expires=" + nextyear.toGMTString() + "; path=/";
}

// sets the font size according to the cookie value, called by onload
function setFontSize() {
	var allCookies = document.cookie;
	var pos = allCookies.indexOf("diageofontsize=");
	if (pos != -1) {
		var start = pos + 9;
		var end = allCookies.indexOf(";", start);
		if (end == -1) end = allCookies.length;
		var value = allCookies.substring(start, end);
		chgFontSz(value);
	}
}
// ----- END Text Resizer -----


// ----- START Search box focus/blur clear + refill -----
function clearBox(objID) {
	if (objID.value == 'Search') {
		objID.value = '';
	}
}

function fillBox(objID) {
	if (objID.value == '') {
		objID.value = 'Search';
	}
}
// ----- END Search box focus/blur clear + refill -----


// ----- START MM Jump Select Menu function -----
function jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
// ----- END MM Jump Select Menu function -----

// ----- START Toggle Show Hide function -----
function showhide(hideableObj,textObj) {
	
	if (document.getElementById(hideableObj).style.display == 'none') {
		document.getElementById(hideableObj).style.display = 'block';
		document.getElementById(textObj).innerHTML = 'Hide individual notes';

	} else {
		document.getElementById(hideableObj).style.display = 'none';
		document.getElementById(textObj).innerHTML = 'Select individual notes';
	}
}
// ----- END Toggle Show Hide function -----

// ----- START Roll Over function -----
var NS,IE,N06
NS   = (document.layers) ? true:false;                 // NETSCAPE 4 ******************
IE   = (document.all) ? true:false;                    // IE 4Up  *********************
N06 = ((document.getElementById)&&(!IE))?true:false;   // NETSCAPE 6 etc. *************
// END BROWSER VARIABLES **************************************************************
// mouseover scripts including fix for NS complete path *******************************

function preload(imgObj,imgSrc) {
	if (document.images) {
		eval(imgObj+' = new Image()');
		eval(imgObj+'.src = "'+imgSrc+'"');
	}
}

function swapOver(i,imgName) {
	if (NS && i!=null){
		eval('document.'+i+'.document.images["'+imgName+'"].src = '+imgName+'over.src');
	} else {
		document.images[imgName].src = eval(imgName+"over.src");
	}
}
function swapOut(i,imgName) {
	if (NS && i!=null){
		eval('document.'+i+'.document.images["'+imgName+'"].src = '+imgName+'off.src');
	} else {
		document.images[imgName].src = eval(imgName+"off.src");
	}
}
function imgChange(i,imgObj,imgName) {
	if (NS && i!=null){
		eval('document.'+i+'.document.images["'+imgName+'"].src = '+imgObj+'.src');
	} else {
		document.images[imgName].src = eval(imgObj+".src");
	}
}
// ----- END Roll Over function -----



// ############## Init function calls on page loaded #################

window.onload = function () {

}

//Barry's JS functions 10 Dec 2008:
function popup(url) {
    newwindow = window.open(url, 'name', 'height=500,width=700,resizable=yes,scrollbars=yes,toolbar=no,status=no,menubar=no');
    if (window.focus) { newwindow.focus() }
    return false;
}

function addPageToBasket() {

    var PageTitle = document.title;
    var PageUrl = document.URL;

    if (PageTitle.indexOf('|') != -1) {
        var arrPageTitle = PageTitle.split('|');
        PageTitle = arrPageTitle[0];
    }

    //alert(PageTitle + ' : ' + PageUrl);

    return popup('/PrintBasket.aspx?Mode=Add&PageTitle=' + PageTitle + '&PageUrl=' + PageUrl);
}

function viewBasket() {
    return popup('/PrintBasket.aspx');
}



/* Client-side access to querystring name=value pairs
	Version 1.3
	28 May 2008
	
	License (Simplified BSD):
	http://adamv.com/dev/javascript/qslicense.txt
*/
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = {};
	
	if (qs == null) qs = location.search.substring(1, location.search.length);
	if (qs.length == 0) return;

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i = 0; i < args.length; i++) {
		var pair = args[i].split('=');
		var name = decodeURIComponent(pair[0]);
		
		var value = (pair.length==2)
			? decodeURIComponent(pair[1])
			: name;
		
		this.params[name] = value;
	}
}

Querystring.prototype.get = function(key, default_) {
	var value = this.params[key];
	return (value != null) ? value : default_;
}

Querystring.prototype.contains = function(key) {
	var value = this.params[key];
	return (value != null);
}

//Check if PDF Basket Mode
;

function checkMode() {
    var qs = new Querystring();
    if (qs.contains("pdfMode")) {
        //enable the print stylesheet
        var pdfStyleSheet = document.getElementById("ctl00_pdfStyleSheet");
        pdfStyleSheet.media = 'screen';
        //alert(qs.get("pdfMode"));
    }
}

function mailFriend() {
    var mailSubject = 'Page from Compass Corporate Responsibility Report 2008 Site';
    var mailBody = 'Hello %0D%0A%0D%0AI thought you might be interested in the following page from the Compass Group PLC Corporate Responsibility website: %0D%0A%0D%0A' + escape(location.href);
    document.location = 'mailto:?SUBJECT=' + mailSubject + '&BODY=' + mailBody
}




