/*** Graceful degrade for non-javascript users & some event capture for livesearch ***/




/*** START Primary nav hover function for IE ***/

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

/*** START Countries selector ***/

// Preload the AJAX loading gif
ajaxgif=new Image();
ajaxgif.src="/assets/image/ajaxload.gif";

function countriesreveal() { // Show, hide or add to territory selector box
	document.getElementById('countriesbox').style.visibility = 'visible';
	
  // Set the static lists (no longer ajax)
	document.getElementById('countriesboxhead').innerHTML = "";
	var countriesheader="<div id='countriestitle'>Commonly visited PwC sites</div><br clear='all' />";

	document.getElementById('countriescontents').innerHTML = "";
  var countriesoutput="<table id='countriestable' border='0'><tbody><tr><td><ul class='countrylist'><li><a href='http://www.pwc.com/gx/en/index.jhtml?ld=no'>Global</a></li><li><a href='http://www.pwc.com/au/en'>Australia</a></li> <li><a href='http://www.pwc.com/br/pt'>Brazil</a></li> <li><a href='http://www.pwc.com/ca/en'>Canada</a></li> <li><a href='http://www.pwccn.com'>China</a>&nbsp;/&nbsp;<a href='http://www.pwchk.com'>Hong Kong</a></li> <li><a href='http://www.pwc.fr'>France</a></li> <li><a href='http://www.pwc.de'>Germany</a></li> <li><a href='http://www.pwc.com/in/en'>India</a></li></ul></td><td><ul class='countrylist'><li><a href='http://www.pwc.com/it/it'>Italy</a></li> <li><a href='http://www.pwcjp.com/e/index.html'>Japan</a></li> <li><a href='http://www.pwc.com/mx/es'>Mexico</a></li><li><a href='http://www.pwc.com/m1/en'>Middle East</a></li> <li><a href='http://www.pwc.com/nl/nl'>Netherlands</a></li> <li><a href='http://www.pwc.com/ru/ru'>Russia</a></li> <li><a href='http://www.pwc.com/sg/en'>Singapore</a></li> <li><a href='http://www.pwc.com/za/en'>South Africa</a></li></ul></td><td valign='top'><ul class='countrylist'><li><a href='http://www.pwc.com/kr/ko'>South Korea</a></li> <li><a href='http://www.pwc.com/es/es'>Spain</a></li> <li><a href='http://www.pwc.com/se/sv'>Sweden</a></li> <li><a href='http://www.pwc.ch'>Switzerland</a></li> <li><a href='http://www.pwc.co.uk'>United Kingdom</a></li> <li><a href='http://www.pwc.com/us/en'>United States</a></li> </ul> </td></tr></tbody></table><br clear='all'> <p style='text-align: right; font-weight: bold;'><a href='http://www.pwc.com/gx/en/site-index.jhtml'>Complete list of PwC territory sites</a></p><br clear='all' />";
	
	// Finally write the output; close button, header & contents.
	document.getElementById('countriesboxclose').innerHTML = "<a href='#' onClick='countrieshide(); return false;'><img src='/assets/image/icon_close.gif' alt='Close' border='0' id='countriesclosebutton' /></a>"
	document.getElementById('countriesboxhead').innerHTML = countriesheader;
	document.getElementById('countriescontents').innerHTML = countriesoutput;
}


function countrieshide() { 	// Clear the contents of the box and hide the div
	document.getElementById('countriescontents').innerHTML = "";  
	document.getElementById('countriesbox').style.visibility = 'hidden';  
}

/*** START Live search ***/



/*** START Send & share global defaults ***/

  if (sharetitle === undefined) { var sharetitle = "Share"; }

	function writesharelink() {
		document.write("<li id='ptshare'><a href='#' target='_self' class='shareicon' onclick='shareboxreveal(); return false;'>" + sharetitle + "</a></li>");
	}

	// Icon, Pre-URL, Post-URL, Description/alt tag, Onlick. Only declare them if they don't already exist from local.js

	if (arr_ss [0] === undefined) {
		// Twitter
		arr_ss [0] = new Array()
		arr_ss [0][0] = "/assets/image/share_twitter.gif";
		arr_ss [0][1] = "http://twitter.com/home?status=" + escape(window.location);
		arr_ss [0][2] = "";  // E.G. arr_ss [0][2] = "&param=something";
		arr_ss [0][3] = "Twitter";
		arr_ss [0][4] = "";
	}

	if (arr_ss [1] === undefined) {
		// Facebook
		arr_ss [1] = new Array()
		arr_ss [1][0] = "/assets/image/share_facebook.gif";
		arr_ss [1][1] = "http://www.facebook.com/share.php?u=" + escape(window.location);
		arr_ss [1][2] = "";
		arr_ss [1][3] = "Facebook";
		arr_ss [1][4] = "";
	}
	
	if (arr_ss [2] === undefined) {
		// Linkedin
		arr_ss [2] = new Array()
		arr_ss [2][0] = "/assets/image/share_linked.gif";
		arr_ss [2][1] = "http://www.linkedin.com/shareArticle?mini=true&url=" + escape(window.location);
		arr_ss [2][2] = "";
		arr_ss [2][3] = "Linkedin";
		arr_ss [2][4] = "";
	}
	
	if (arr_ss [3] === undefined) {
		// Mixx
		arr_ss [3] = new Array()
		arr_ss [3][0] = "/assets/image/share_mixx.gif";
		arr_ss [3][1] = "http://www.mixx.com/submit?page_url=" + escape(window.location);
		arr_ss [3][2] = "";
		arr_ss [3][3] = "Mixx";
		arr_ss [3][4] = "";
	}

	if (arr_ss [4] === undefined) {
		// Digg
		arr_ss [4] = new Array()
		arr_ss [4][0] = "/assets/image/share_digg.gif";
		arr_ss [4][1] = "http://digg.com/submit?phase=2&url=" + escape(window.location);
		arr_ss [4][2] = "";
		arr_ss [4][3] = "Digg";
		arr_ss [4][4] = "";
	}

	if (arr_ss [5] === undefined) {
		// Google buzz
		arr_ss [5] = new Array()
		arr_ss [5][0] = "/assets/image/share_googlebuzz.gif";
		arr_ss [5][1] = "http://www.google.com/reader/link?url=" + escape(window.location);
		arr_ss [5][2] = "";
		arr_ss [5][3] = "Google buzz";
		arr_ss [5][4] = "";
	}

	function shareboxreveal() { // Show, hide or add to territory selector box
		document.getElementById('sharebox').style.display = 'block';
	}

	function shareboxhide() { 	// Clear the contents of the box and hide the div
		document.getElementById('sharebox').style.display = 'none';  
	}

function writesharebox() { // Taken from HTML for 3rd party templates
	var sendshare = "<div id='sharebox'><ul id='shareicons'><div id='shareboxclose'><a href='#' onClick='shareboxhide(); return false;'><img src='/assets/image/icon_close.gif' alt='Close' border='0' /></a></div>"	
	if (window.sendsharetitle === undefined) { window.sendsharetitle = escape("Page title here"); }
	for (i=0;i<arr_ss.length; i++) {
	    sendshare = sendshare + "<li id='share" + i + "'><a href='" + arr_ss[i][1] + "&title=" + sendsharetitle + arr_ss[i][2] + "' onclick='" + arr_ss[i][4] + "' target='_blank' class='shareicon'><img src='" + arr_ss[i][0] + "' border='0' alt='" + arr_ss[i][3] + "' />&nbsp;" + arr_ss[i][3] + "</a></li>";	
	}
	sendshare = sendshare + "</ul></div>";
	document.write(sendshare);
}

  // Default R2 forms validation message (translatable))
  if (formvalidationmsg === undefined) { var formvalidationmsg = "Please complete the highlighted fields"; }
  
/*** START Lightweight browser detection ***/

//alert(BrowserDetect.browser + ' ' + BrowserDetect.version + ' on ' + BrowserDetect.OS);

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

