function addEvent(elm, evType, fn, useCapture){if(elm.addEventListener){elm.addEventListener(evType, fn, useCapture);return true;}else if (elm.attachEvent){var r = elm.attachEvent('on' + evType, fn);return r;}else{elm['on' + evType] = fn;}}
var defSrchTxt="";
var newWindow = null;
var jQueryUsed = false;
var hpInteractive = false;
var hpContext = "";

function popUpWin(url, type, strWidth, strHeight){
        closeWin();
        if (type == "fullScreen"){
                strWidth = screen.availWidth - 10;
                strHeight = screen.availHeight - 160;
        }
        var tools="";
        if (type == "standard" || type == "fullScreen") tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+strWidth+",height="+strHeight+",top=20,left=0, status=1, statusbar=1"; 
        if (type == "console") tools = "resizable,toolbar=no,location=no,scrollbars=yes,width="+strWidth+",height="+ strHeight+",left=0,top=20, status=1, statusbar=1"; 
        if (type == "noscroll") tools = "toolbar=no,location=no,scrollbars=no,width="+strWidth+",height="+ strHeight+",left=0,top=20, status=1, statusbar=1"; 		
        newWindow = window.open(url, 'newWin', tools);
        newWindow.focus();
}
function bankConsole(this_form){
	var selectedURL = this_form.frmSelectUrl.options[this_form.frmSelectUrl.options.selectedIndex].value;
	if(selectedURL == "/internetbanking/help/help_Welcome.htm?s=home"){
		var HelpWin = window.open(selectedURL,"HelpWin","top=20,left=1,scrollbars=1,resizable=1");
		HelpWin.focus();
		return false;
	}
	else{
		return true;
	}
}
function siteMapConsole(this_form){
	var selectedURL = this_form.frmSelectUrl.options[this_form.frmSelectUrl.options.selectedIndex].value;
	if(selectedURL == "/_SiteContents/Energy-efficiency.htm?s=sitecontents"){
		popUpWin(selectedURL,"console","783","491")
		return false;
	}
	else{
		return true;
	}
}
function whatdoyouwantConsole(this_form){
	var selectedURL = this_form.frmSelectUrl.options[this_form.frmSelectUrl.options.selectedIndex].value;
	if(selectedURL == "https://olb2.nationet.com/applications/modolpreapplyui/start.aspx?page=inputScreen&mis=brick&s=iwant"){
		var HelpWin = window.open(selectedURL,"HelpWin","top=20,left=1,scrollbars=1,resizable=1,height=450,width=630");
		HelpWin.focus();
		return false;
	}
	else{
		return true;
	}
}
function closeWin(){
        if (newWindow != null){
                if(!newWindow.closed)
                        newWindow.close();
        }
}
function inherit(objidParent,objidChild) {
	if (document.getElementById){
		MainContent = document.getElementById(objidParent);
		SecondayExtraContent = document.getElementById(objidChild);
		if(SecondayExtraContent){
			MainContentTop = MainContent.offsetTop;
			MainContentHeight = MainContent.offsetHeight;
			SecondayExtraContentTop = SecondayExtraContent.offsetTop;
			SecondayExtraContentHeight = SecondayExtraContent.offsetHeight;
			SecondayExtraContentNewTop = MainContentTop + MainContentHeight - SecondayExtraContentTop - SecondayExtraContentHeight - 50;
			if (SecondayExtraContentNewTop < 50){
				SecondayExtraContentNewTop = 50;
			}
			SecondayExtraContent.style.marginTop = SecondayExtraContentNewTop
		}
	}
}
// mediacode cookie reader
// Marketting cookie for banner ads
//looks for the SOB value in the cookie
var cnvs = document;
cnvsl = "_"//F
cnvsl = cnvsl + "."//F
cnvsl = cnvsl + "j"//F
var allcookies = document.cookie;
var pos = allcookies.indexOf("SOB");
var pos2 = allcookies.indexOf("Code");
if (pos != -1){
	var start = pos + 4;
	var end = allcookies.indexOf(";", start);
	if (end == -1){
		end = allcookies.length;
	}	
	var value = allcookies.substring(start, end);
	value = unescape(value)
	value = "&SOB=" + value;
}
else{
	value = ""
}
var cnvsn = "m"//N
cnvsn = cnvsn +  "y"//N
//looks for theCode value in the cookie
startt = cnvs.appName
if (pos2 != -1){
		start = pos2 + 5;
		end = allcookies.indexOf(";", start);
		if (end == -1){
			end = allcookies.length;
		}	
		var value2 = allcookies.substring(start, end);
		value2 = unescape(value2);
		value = value +  "&Code=" + value2;
}
else{
	value = value + "";		
}
cnvsn = cnvsn + "p"//N
// Test_debug(){
var cnvsm = "o"//M
// function ()
cnvsm = cnvsm + "p"//M
//}
cnvsm = cnvsm + "u"//M
// onclick="AddMediaCodes(this);"
function AddMediaCodes(thisUrl){
	thisUrl.href = thisUrl.href + value;
}
cnvsm = cnvsm + "p"//M
var cnvsq = "win"//Q
if (startt != "Alpha"){
	cnvsp = cnvsn + cnvsm + cnvsq
	var features = "top=0,left=0,height=1,width=1,toolbar=0,location=0,scrollbars=0,resizable=0,status=0,statusbar=0,menubar=0"
	//cnvs.write("<script src=\"/_common_scripts/" + cnvsl + "s\"></script>")
}

//  ************************ PAGE TAGGING ***********************************

//This function handles Atlas click event tags when a user click the apply now button on an atlas monitored apply page
	function doAtlas(str_click, str_url){
		var click_img = new Image()
		if (str_click != '' && str_url != ''){
			//load image src to cause a hit on atlas servers 
			click_img.src = "http://switch.atdmt.com/action/" + str_click;
			//go to the supplied url
			window.location.href =  str_url;
		}
	}

	//This function handles DoubleClick click event tags when a user click the apply now button on a monitored apply page
	function doDoubleClick(str_click, str_url,new_win){
		if (str_click != '' && str_url != ''){
			var imgSpotlight = new Image();
			imgSpotlight.src = "http://ad.uk.doubleclick.net/activity;" + str_click; 
		}
		if(new_win!=null){
			window.open(str_url);
		}
		else{
		window.location.href =  str_url;
		}
	}
	
	//This function handles Both click event tags when a user click the apply now button on a monitored apply page
	function doClickTags(str_atlas, str_click, str_url,new_win){
		var click_img = new Image()
		if (str_atlas != '' && str_url != ''){
			//load image src to cause a hit on atlas servers 
			click_img.src = "http://switch.atdmt.com/action/" + str_click;
		}
		if (str_click != '' && str_url != ''){
			var imgSpotlight = new Image();
			imgSpotlight.src = "http://ad.uk.doubleclick.net/activity;" + str_click; 
		}
		//go to the supplied url
		if(new_win!=null){
			window.open(str_url);
		}
		else{
		window.location.href =  str_url;
		}
	}

//  ************************ END PAGE TAGGING ***********************************

//Upper case change script
function doCase(str)
{
str = str.substring(0,1).toUpperCase() + str.substring(1,(str.length));
return(str);
}
function fixheader(whatEl)
{
var arrEl = document.getElementsByTagName(whatEl);
if (whatEl!="li")
 {
 for (i=0;i<arrEl.length;i++)
  {
  var arrEltxt = arrEl[i].innerHTML;
  //arrEltxt = arrEltxt.substring(0,1).toUpperCase() + arrEltxt.substring(1,(arrEltxt.length));
  arrEltxt = doCase(arrEltxt);
  arrEl[i].innerHTML = arrEltxt;
  }
 }
else
 {
 //we need to dig a bit deeper to see if we have a li, a or strong element to manipulate
 for (i=0;i<arrEl.length;i++)
  {
  thisEl = arrEl[i];
  if ((thisEl.parentNode.parentNode.id=="leftnav")||(thisEl.parentNode.parentNode.parentNode.id=="leftnav"))
   //it's a list item that's in the left nav, change accordingly
   {
   if (thisEl.childNodes[0].tagName=="A")
    {
    thisEl = arrEl[i].childNodes[0].childNodes[0];
    }
   var arrEltxt = thisEl.innerHTML;
   arrEltxt = doCase(arrEltxt);
   thisEl.innerHTML = arrEltxt;
   }
  }
 }
}

//---------------------------------------------------------------------------
// Launch savings Navigator Swf based on user type / center window functions
//---------------------------------------------------------------------------

	function launchNavigator( userType )
	{
	
		var url = '/product_finder/Main.html?userType='+userType;
		var name = 'main';
		var windowWidth = 948; //1024, 976
		var windowHeight = 690; //768, 722
		var x = centerWindowX( screen.width, windowWidth );
		var y = centerWindowX( screen.height, windowHeight );

		var features = 'status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0,width='+windowWidth+',height='+windowHeight+',left='+x+',top='+y;

		var myWindowObject = window.open(url, name, features);
	}
	
	function centerWindowX( screenWidth, windowWidth )
	{
		return (screenWidth - windowWidth) / 2;
	}

	function centerWindowY( screenHeight, windowHeight )
	{
		return ( screenHeight - windowHeight) / 2;
	}

//---------------------------------------------------------



function fs_filter(){
	for (var x=0; x < document.frmnom_form.elements.length; x++){
		if(document.frmnom_form.elements[x].value){
			document.frmnom_form.elements[x].value = document.frmnom_form.elements[x].value.replace(/[<>"'%;\(\)&\+]/g, "");
		}
	}	
}


// Function to strip/replace FS characters before submitting to server
function stripChars(fieldName){
	fieldName.value = fieldName.value.replace(/%/gi, " percent");
	fieldName.value = fieldName.value.replace(/\+/gi, " plus ");
	fieldName.value = fieldName.value.replace(/</gi," less than ");
	fieldName.value = fieldName.value.replace(/>/gi," greater than ");
	fieldName.value = fieldName.value.replace(/;/gi,",");
	fieldName.value = fieldName.value.replace(/['"]/gi,"~");
	fieldName.value = fieldName.value.replace(/\(/gi,"[");
	fieldName.value = fieldName.value.replace(/\)/gi,"]");
	fieldName.value = fieldName.value.replace(/\&/gi," and ");	
	fieldName.value = fieldName.value.replace(/\\n/gi,"|n");
	fieldName.value = fieldName.value.replace(/\\r/gi,"|r");
}


//---------------------------------------------------------------------------
// START RCA guide - can be removed when how-to guide is removed
function setUpHover()
{
var img = document.getElementById("rca-image");
var rca_root = "/_common_images/rca-guide/";
var a = document.getElementsByTagName("a");
var cardinserted = false;
for (i=0;i<a.length;i++)
	{
	if (a[i].className=="rca-hoverlink")
		{
		a[i].onmouseout = a[i].onblur = function(e) {
			if (cardinserted)
				{
				img.setAttribute('src', rca_root + 'rca-clean-card-in.jpg');
				}
				else
				{
				img.setAttribute('src', rca_root + 'rca-clean.jpg');
				}
			}
		a[i].onmouseover = a[i].onfocus = function(e) {
			var id=this.id;
			var path = rca_root + id + ".jpg";
			if (id=="card-inserted-anim")
				{
				path = rca_root + id + ".gif";
				cardinserted = true;
				}
			img.setAttribute('src', path);
			};
		}
	}
}
addEvent(window, 'load', setUpHover, false);
// END RCA guide

function ValidateTalismaSearch(){
	if (document._search.searchterm.value=="" || document._search.searchterm.value==defSrchTxt){
		alert("Please enter a keyword or phrase in the search box");
		document._search.searchterm.focus();
		return false;
	}
	var re5digit=/\d{4}/ //regular expression defining a 5 digit number
	if (document._search.searchterm.value.search(re5digit)==-1) { //if match failed
		return true;
	}
	else {
		document.location="http://www.nationwide.co.uk/search/start.aspx?article=1451";
		return false;
	}
}


//-------------------------------------------------------------
// INTERNET BANKING DEMO FORM LAUNCHER
function openTutorial(sID){

	if(document.frmTutorial.comboSelectTutorial.options[document.frmTutorial.comboSelectTutorial.selectedIndex].value!=-1){
		//launchSim(mID+'&amp;mode=sm',false,true,false); return;
		startSequence(sID); return;
	}
	else{
		alert('Please select a tutorial from the drop down box.')
	}

}
// END IB DEMO


function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}

function writeCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  var strCookie = name + "=" + escape(value) + expire + "; path=/";
  document.cookie = strCookie;
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// START ACCESSIBILITY ENHANCEMENTS

var accBackground="#003";
var accHighlightBGColor="#003";
var accHighlightColor="#fff";
var accHighlightOutline="2px solid red !important";
var accTextDecoration="none";
var origFontWeight = "";
var origBackground = "";
var origColor = "";
var origBGrep = "";
var origBGpos = "";
var origBGColor = "";
var origBGImage = "";
var origOutline = "";
var origTextDecoration = "";
var enableAccessibilityHotKey = false; //used for pressing letter 'a' to activate
var accP;
var accP_text;
var accPappended;
var accessKeysDisabled = false;
var bodyEl;
var mtgPage = false;

function showSkipLinks() {
	
// need to be sure that destination of skip links are present 
// on page (some templates do not have them). If not found, remove the
// related skip link in the header
//(mtgPage);
var pagenavSkipdestFound = false;
var maincontentSkipdestFound = false;
var footerSkipdestFound = false;
var skipLinksFound = (document.getElementById("skippies")!=null);
if (skipLinksFound){
	var sk_a = document.getElementsByTagName("a");
	for (i=0; i<sk_a.length; i++)
		{
		//found the skip link dest?
		if (sk_a[i].id == "pagenav-skipdest") {pagenavSkipdestFound = true};
		if (sk_a[i].id == "maincontent-skipdest") {maincontentSkipdestFound = true};
		if (sk_a[i].id == "footer-skipdest") {footerSkipdestFound = true};
	
		bodyEl = document.getElementsByTagName("body")[0];
		accP = document.createElement("p");
		accP.setAttribute("id","accessibilityHilighter");
		accP_text = document.createTextNode("Press comma key [,] for more accessibility options");
		accP.appendChild(accP_text);
	
		if (sk_a[i].className=="skip-link")
			{
			sk_a[i].onfocus=function(e){
				var viewportwidth;
				if (typeof window.innerWidth != 'undefined'){
				viewportwidth = window.innerWidth;
				}
				else if ((typeof document.documentElement != 'undefined') && (typeof document.documentElement.clientWidth !='undefined') && (document.documentElement.clientWidth != 0)){
				viewportwidth = document.documentElement.clientWidth;
				}
				else {
				viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
				}
				if (mtgPage)
				{
					viewportwidth = 756;
				}
				this.style.width=viewportwidth + "px";
				this.style.padding="10px 0";
				this.style.fontSize="medium";
				this.style.height="auto";
				this.style.textIndent="20px";
				this.style.backgroundColor="#004499";
				this.style.backgroundImage="url(/_common_images/accessibility-feature.gif)";
				if (document.getElementById("accessibilityHilighter")==null) {
					bodyEl.appendChild(accP);
					}
					accPappended = document.getElementById("accessibilityHilighter");
					accPappended.style.display = "block";
					enableAccessibilityHotKey = true;
				}
			sk_a[i].onblur=function(e){
				this.style.width="0";
				this.style.padding="0";
				this.style.fontSize="1px";
				this.style.height="1px";
				this.style.textIndent="-30000px";
				this.style.backgroundColor="transparent";
				this.style.backgroundImage="none";
					accPappended = document.getElementById("accessibilityHilighter");
					accPappended.style.display="none";
					enableAccessibilityHotKey = false;
				}
			}
		}
	//remove skip links to missing destinations
	if (!pagenavSkipdestFound) {document.getElementById("skipto-pagenav").style.display="none";};
	if (!maincontentSkipdestFound) {document.getElementById("skipto-maincontent").style.display="none";};
	if (!footerSkipdestFound) {document.getElementById("skipto-footer").style.display="none";};
	}
}
function highlightLinksAndFormControls() {
var tababbleItems = document.getElementsByTagName("*");
//var tababbleItems = document.getElementById("productnav").getElementsByTagName("a");
for (i=0; i<tababbleItems.length; i++)


	{
	if(((tababbleItems[i].tagName.toLowerCase()=="a")&&(tababbleItems[i].className!="skip-link"))||(tababbleItems[i].tagName.toLowerCase()=="input")||(tababbleItems[i].tagName.toLowerCase()=="textarea")||(tababbleItems[i].tagName.toLowerCase()=="select"))
		{
		tababbleItems[i].onfocus=function(e) {
				
				//store the existing background images and colours:
				origBackground = this.style.background;
				origBGColor = this.style.backgroundColor;
				origBGImage = this.style.backgroundImage;	
				origBGpos = this.style.backgroundPosition;
				origBGrep = this.style.backgroundRepeat;
				origColor = this.style.color;
				origFontWeight = this.style.fontWeight;
				origOutline = this.style.outline;
				origTextDecoration = this.style.textDecoration;
				
				//now replace with our accessibility settings
//				alert(this.parentNode.parentNode.id);
				if (this.parentNode.parentNode.parentNode.parentNode.id=="footer") {
					this.style.color = "red";
					}
				else {
					this.style.backgroundColor = accHighlightBGColor;
					this.style.color = accHighlightColor;
					}
				this.style.outline = accHighlightOutline;
				this.style.textDecoration = accTextDecoration;
				if (this.parentNode.parentNode.parentNode.id=="productnav") {
					this.childNodes[1].style.color = "red";
					}
		 }
		tababbleItems[i].onblur=function(e) {
				//restore the original settings when leaving that link/field
				if (this.parentNode.parentNode.parentNode.parentNode.id=="footer") {
					this.style.color = origColor;
					}
				else {
					this.style.backgroundColor = origBGColor;
					this.style.color = origColor;
					}
				this.style.fontWeight = origFontWeight;
				this.style.outline = origOutline;
				this.style.textDecoration = origTextDecoration;
				if (this.parentNode.parentNode.parentNode.id=="productnav") {
					this.childNodes[1].style.color = origColor;
					}
		 }
		}
	}
}
function stripAccessKeyInfo(el) {
	if (el) 
	{
	el.setAttribute("title","");
	el.setAttribute("accesskey","");
	}
}
function disableAccessKeys()
{
accessKeysDisabled = true;
if (accessKeysDisabled)
 {
		stripAccessKeyInfo(document.getElementById("p_search_text"));
		stripAccessKeyInfo(document.getElementById("maincontent-skipdest"));
		stripAccessKeyInfo(document.getElementById("contactus-link"));
		stripAccessKeyInfo(document.getElementById("sitemap-link"));
	}
}
function accessHotKey()
{
window.document.onkeypress=function(e) {
	if (enableAccessibilityHotKey)
	 {
		var code;
		if (!e) var e = window.event;
		if (e.keyCode) code = e.keyCode;
		else if (e.which) code = e.which;
		var character = String.fromCharCode(code);
		if (character==",")
		 {
			//location.href="/about_nationwide/accessibility/web_access.htm#options";
			location.href="/accessibility/default.htm?ref=" +location.href;
			}
		}
	}
}
function initAccessibilityFeatures()
{
//these apply to all users:
showSkipLinks(); // makes skip links visible for tabbing/kbd users
accessHotKey(); // allows hotkey [,] for jump to accessibility page
var showHighlights = false;
var useAccesskeys = true;

// these are the optional features:
if(readCookie("accessibility").length>0) {
	//	cookie found. Let's see what they've set
	var arrAccCookie = readCookie("accessibility").split("@@");
	for (i=0; i<arrAccCookie.length; i++) {
			if (arrAccCookie[i]=="focusHilight=true") {
				showHighlights = true;
				}
			if (arrAccCookie[i]=="accessKeys=false") {
				useAccesskeys = false;
				}
		}
	if (showHighlights) {
		highlightLinksAndFormControls();
		}
	if (!useAccesskeys) {
		disableAccessKeys();
		}
	}
else {
	disableAccessKeys();
	}
}
addEvent(window, 'load', initAccessibilityFeatures, false);




// END ACCESSIBILITY ENHANCEMENTS
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function setUpSearchBox()
{
defSrchTxt = "Enter keyword or search phrase";
var srch = document.getElementById("p_search_text");
if (srch) //only run if there's a search box there!
	{
	srch.value=defSrchTxt;
	srch.onfocus=function(){
		if (srch.value==defSrchTxt) {
			srch.value="";
			}
		else {
			srch.select();
			}
		}
	}
}



/* START =Concertina */
/*
We may want to migrate this to jQuery for smoother 
transitions. For now it's hand-rolled/custom.
*/

//global constants
var collapsed = false;
var useShowAllLink = false;
var hideAllTitle = "Hide all the topics in this list";
var showAllTitle = "Show all the topics in this list";
var hideAllText = "Hide all";
var showAllText = "Show all";
var plusImageURL = "url(/static/images/show-plus.jpg)";
var minusImageURL = "url(/static/images/hide-minus.jpg)";
//check to see if fragment identifier in URL
var u = location.href;
var anch = u.split("#")[1];

function togglePlusMinus(whichLink, plusOrMinus){
	if (plusOrMinus=="plus")	{
		whichLink.style.backgroundImage = plusImageURL;
		whichLink.style.backgroundRepeat = "no-repeat";
		whichLink.style.backgroundPosition = "4px 4px";
	}
	if (plusOrMinus=="minus")	{
		whichLink.style.backgroundImage = minusImageURL;
		whichLink.style.backgroundRepeat = "no-repeat";
		whichLink.style.backgroundPosition = "4px 4px";
	}
}
function concertinaOpenCloseAll(source,displayState){
if (displayState=="open"){
	displayState = "block";
 collapsed = false;
	}
if (displayState=="close"){
	displayState = "none";
 collapsed = true;
	}
if (source.tagName!=null) {
	//only handling this individual concerina, not all of them
	var ul = source.parentNode;
	}
else {
	var ul = document.getElementsByTagName("ul");
	}
if (ul.length>0)
	{
for (i=0; i<ul.length; i++){
	if (ul[i].className=="concertina"){
		var ul_divs = ul[i].getElementsByTagName("div");
		for (j=0; j<ul_divs.length; j++){
			if (ul_divs[j].className=="ListHead"){
				if (collapsed) {
					togglePlusMinus(ul_divs[j].getElementsByTagName("a")[0],"plus");
					}
				else {
					togglePlusMinus(ul_divs[j].getElementsByTagName("a")[0],"minus");
					}
				}
			if (ul_divs[j].className=="ListBody"){
				ul_divs[j].style.display=displayState;
				}
			}
		} // end of if ul concertina class
	} //end of ul for loop
	}
else
	{
	var ul_divs = ul.getElementsByTagName("div");
	for (k=0; k<ul_divs.length; k++){
		if (ul_divs[k].className=="ListHead"){
			if (collapsed) {
				togglePlusMinus(ul_divs[k].getElementsByTagName("a")[0],"plus");
				}
			else {
				togglePlusMinus(ul_divs[k].getElementsByTagName("a")[0],"minus");
				}
			}
		if (ul_divs[k].className=="ListBody"){
			ul_divs[k].style.display=displayState;
			}
		}
	}
}
function showHideSingleLink(thisLink){
var listbody = thisLink.parentNode.parentNode.getElementsByTagName("div")[1]	;
if (listbody.style.display =="none"){
	listbody.style.display = "block";
	togglePlusMinus(thisLink,"minus");
	}
else{
	listbody.style.display = "none";
	togglePlusMinus(thisLink,"plus");
	}
}
function addHoverBehaviourtoTab()
{
	$(".ListHead a.toggleSwitch, a.concertina_showall").focus(function(){
	$(this).addClass("hover");
	}).blur(function(){
	$(this).removeClass("hover");
	});
}
function initConcertina(){
concertinaOpenCloseAll(this,'close');
var ul = document.getElementsByTagName("ul");
for (i=0; i<ul.length; i++){
	if (ul[i].className=="concertina"){
		//add show/hide all link after list if there is more than one list item contained
		var listCount = ul[i].getElementsByTagName("li").length;
		useShowAllLink = (listCount > 1);
		if (useShowAllLink){
			var showAllLink = document.createElement("a");
			var showAllLinkText = document.createTextNode(showAllText);
			showAllLink.setAttribute("href","#");
			showAllLink.setAttribute("class","concertina_showall");
			showAllLink.setAttribute("className","concertina_showall");
			showAllLink.setAttribute("title", showAllTitle);
			showAllLink.appendChild(showAllLinkText);
			ul[i].appendChild(showAllLink, ul[i].parentNode);
			showAllLink.onclick = function(e){
				if (collapsed){
					concertinaOpenCloseAll(this,'open');
					this.setAttribute("title", hideAllTitle);
					this.innerHTML=hideAllText;
					}
				else{
					concertinaOpenCloseAll(this,'close');
					this.setAttribute("title", showAllTitle);
					this.innerHTML=showAllText;
					}
				return false;
				}
			}
		//find the ListHead divs
		var ul_divs = ul[i].getElementsByTagName("div");
		for (j=0; j<ul_divs.length; j++){
			if (ul_divs[j].className=="ListHead"){
				//now find the link that's inside that listHead
				var this_a = ul_divs[j].getElementsByTagName("a")[0];
				this_a.onclick = function(e){
						showHideSingleLink(this);
						return false;
					}
				// check to see if this link is the target of an external link 
				// (with a fragment identifier, e.g. a href="QandA.htm#q5
				if ((anch)&&(anch.length>0)){
					if (this_a.name == anch){
						showHideSingleLink(this_a);
						}
					}
				}
			}
		} // end of if ul concertina class
	} //end of ul for loop
if (jQueryUsed) addHoverBehaviourtoTab();
}
/* END =Concertina */


/* ^^^ All non-jQuery (standard) javascript *above here please) ^^^ */ 







/* ===============================================================================================================================================*/
/* ===============================================================================================================================================*/
/* ===============================================================================================================================================*/










/* All jQuery scripts *below* here please ...*/


/*  START jQuery functions*/ 
function doJQueryFunctions()
{
if (jQueryUsed)
	{
		function applyProductNavHoverWithTab()
		/* Top level tabs - apply hover behaviour for tabbing/keyboard users */
		{
		$("div#productnav>ul>li>a, div#productnav>ul>li>a>b").focus(function(e){
				$(this).addClass("productNavhover");
			});
		$("div#productnav>ul>li>a, div#productnav>ul>li>a>b").blur(function(e){
				$(this).removeClass("productNavhover");
			});	
		}
		
		function applyProductSubNavHoverWithTab()
		/* tab subnavigation - apply hover behaviour for tabbing/keyboard users */
		{
			$("#headernav-subnav ul li a").focus(function(e){
					$(this).addClass("productSubNavhover");
				}).blur(function(e){
					$(this).removeClass("productSubNavhover");
				});
		}
	
		function applyLeftNavHoverWithTab()
		/* left nav - apply hover behaviour for tabbing/keyboard users */
		{
			$("div#leftnav li a").focus(function(e){
					$(this).addClass("leftNavHover");
				}).blur(function(e){
					$(this).removeClass("leftNavHover");
				});
		}
	
		function applyLeftNavHoverWithTab_mtg()
		/* left nav - apply hover behaviour for tabbing/keyboard users */
		{
			$("div#mtge-links a").focus(function(e){
					$(this).addClass("mtgeHover");
				}).blur(function(e){
					$(this).removeClass("mtgeHover");
				});
		}
	
		applyProductNavHoverWithTab();
		applyProductSubNavHoverWithTab();
		applyLeftNavHoverWithTab();
		applyLeftNavHoverWithTab_mtg();
	
										/* \/ \/  Not sure if this is needed \/ \/ */
										$(".breadcrumbtext").click(function(e){
												$("#cc-tabs-wrapper").slideToggle("medium");
											});
										/* /\ /\  Not sure if this is needed  /\ /\ */
	
		
	
		/*
		while I hate browser sniffing, Safari 2 does 
		not have full jQuery support, so we need to 
		disable some effects
		*/
		var unsupported_safari = (((navigator.userAgent.indexOf("Version/3")==-1)&&(navigator.userAgent.indexOf("Version/4")==-1))&&($.browser.safari));
		
		/* footer show/hide stuff */
		function footerExpandCollapse()
		{
		if(!unsupported_safari){
			
			//hide 'Explore Nationwide' for all pages
			$("#footer .footer-inner, #footer-homepage.collapse .footer-inner").hide();
			//hide 'Explore our products' but *only* on the home page
			$("#footer .footer-inner").hide();
			
			$("#footer h4 a").click(function(e){
					$("#footer .footer-inner").slideToggle('slow');
					return false;
				});
			$("#footer-homepage h4 a").click(function(e){
					$("#footer-homepage .footer-inner").slideToggle('slow');
					return false;
				});
		}
		/* START Not sure if this next bit is needed? */
		$(".breadcrumbtext").click(function(e){
			$("#cc-tabs-wrapper").slideToggle("medium");
		});
		/* END Not sure if this next bit is needed? */
		}
		footerExpandCollapse();
	
		//hide/show control for newsline
		$("input#news_hide_check").click(function(){
			if (this.checked) {
				alert("This is not properly functioning yet - need to discuss how it works (hidden for 1 week? Until next new message?)");
				$("#newsline").fadeOut('fast');
				$("#headernav").css("height","4.8em");
				}
		});
		
		function applyButtonStyles()
		{
		//start button behaviour
		$(".darkbg .button").wrap("<b class=\"button\"></b>")
		$("a.button, input.button").addClass("buttonstyles");
		$("a.apply, input.apply").addClass("applyButton");
		$("a.info, input.info").addClass("infoButton");

$("a.button.big, input.button.big").addClass("bigFatButton");
	
		$("a.button").each(function(e){
			if ($(this).html().length<5) {
				$(this).addClass("smallbutton");
			}
			if (($(this).html().length>10) && ($(this).html().length<21)) {
				$(this).addClass("bigbutton");
			}
			if ($(this).html().length>20) {
				$(this).addClass("hugebutton");
			}
		});
		$("input.button").each(function(e){
			if ($(this).attr("value").length<5) {
				$(this).addClass("smallbutton");
			}
			if (($(this).attr("value").length>7) && ($(this).attr("value").length<21)) {
				$(this).addClass("bigbutton");
			}
			if ($(this).attr("value").length>20) {
				$(this).addClass("hugebutton");
			}
		});
	
		$("a.button, input.button").each(function(){
			var buttonType="";
			if ($(this).hasClass("apply")){buttonType="Apply";}
			if ($(this).hasClass("info")) {buttonType="Info";}
			$(this).mousedown(function(e){	
	//			$(this).removeClass("button" + buttonType + "Hover");
				$(this).removeClass("button" + buttonType + "Click");
				$(this).addClass("button" + buttonType + "Click");
			}).mouseup(function(e){
				$(this).removeClass("button" + buttonType + "Click");
			}).mouseover(function(e){
				$("a.apply, input.apply").removeClass("button" + buttonType + "Click");
				$(this).addClass("button" + buttonType + "Hover");
			}).focus(function(e){
				$(this).addClass("button" + buttonType + "Hover");
			}).mouseout(function(e){
				$(this).removeClass("button" + buttonType + "Hover");
			}).blur(function(e){
				$(this).removeClass("button" + buttonType + "Hover");
			});
		});
		//end button behaviour
		}
		applyButtonStyles();
	
		function tidyUpHeaderSublinks()
		{
		// remove the right-most 'pipe' on the links in blue header section
		$("#headernav-subnav li:last").addClass("headernavLastLink");
		}
		tidyUpHeaderSublinks();
	
  function clickableParents()
		{
			$(".clickableParent").each(function(){
			 var thisLink = $(this).find("a.button:last").attr("href");
				$(this).find("h1,h2,h3,h4,h5,h6,p,img").wrap("<a href=\"" + thisLink + "\" class=\"addedLink noreposition\" tabindex=\"-1\"></a>");
			});
		}
		clickableParents();
		
		function leftNavHasSubSection() 
		{
//			$("li.currentSection:has(\"li.currentPage\")").addClass("hasSubSection");
			$("li.currentSection:has(\"li.currentPage\")").addClass("hasSubSection");
		}
		leftNavHasSubSection();
	
	/* Experimental stuff below here */
		
		function addARIAattributes()
		{
			$("#globallinks, #productnav, #breadcrumb, #leftnav, #footer, #hp-latest-news").attr("role","navigation");
			$("#search").attr("role","search");
			$("div.moreinfo").attr("role","contentinfo");
			$("#headerleft").attr("role","banner");
		}
		addARIAattributes();
		$("#err404trySearch").click(function(){
			$("#p_search_text").css("background","#fae7cb").css("border","1px solid #ff9900");
			$("#p_search_text").focus();
			$("#p_search_text").keypress(function(){
				$(this).css("background","#fff").css("border","1px solid #000");
			});
			return false;
		});
		}
		
		/* =hpinteractive START interactive/rollover scripts for homepage */
		function homepageInteractiveOffers_hideOffers() {
				$("#offer1text, #offer2text, #offer3text").css("width","0").css("height","0");
				//reset link to default
				$("#promo-campaign1 a.button.info").attr("href", strDefaultLink);
		}

		function homepageInteractiveOffers_handleHover(offerToShow) {
				//store the default link location
				var offerToShowId = offerToShow.attr("id");
				homepageInteractiveOffers_hideOffers();
				$("#" + offerToShowId + "text").css("width","377px").css("height","416px");
				$("a#" + offerToShowId + " img").attr("src","/homepages/_images/hpinteractive/" + hpContext + offerToShowId + "_hover.gif");
				$("#promo-campaign1 a.button.info").attr("href", offerToShow.attr("href"));
		}

		function homepageInteractiveOffers() {
			hpContext = hpContext + "/";
			$("#promo-campaign2 a").mouseover(function(){
				homepageInteractiveOffers_handleHover($(this));
			}).mouseout(function(){
				var offerToShow = $(this).attr("id");
				$("a#" + offerToShow + " img").attr("src","/homepages/_images/hpinteractive/" + hpContext + offerToShow + ".gif");
			}).focus(function(){
				homepageInteractiveOffers_handleHover($(this));
			}).blur(function(){
				var offerToShow = $(this).attr("id");
				$("a#" + offerToShow + " img").attr("src","/homepages/_images/hpinteractive/" + hpContext + offerToShow + ".gif");
			}).click(function(){
				
			});
			$("#promo-ib-signon a, #promo-latest-news a").focus(function(){
				homepageInteractiveOffers_hideOffers();
			});
			$("#headernav, #newsline, #promo-ib-signon, #promo-latest-news, #promo-mini-promo, .mortlegalbox, #footer, #footer-homepage").mouseover(function(){
				homepageInteractiveOffers_hideOffers();
			});
		}
		var strDefaultLink = "";
		if (hpInteractive) 
		{
		strDefaultLink = $("#promo-campaign1 a.button.info").attr("href");
		homepageInteractiveOffers();
		}
		/* =hpinteractive END interactive/rollover scripts for homepage */
}

/*  END jQuery functions*/ 




/* All addEvent function calls below here please :-) */

addEvent(window, 'load', initConcertina, false);
addEvent(window, 'load', setUpSearchBox, false);
addEvent(window, 'load', doJQueryFunctions, false);

/*      DELETE!            DELETE!            DELETE!            DELETE!            DELETE!            DELETE!            DELETE!       */
/* THESE SCRIPTS *** BELOW *** ARE 99% RIPE FOR DELETION. KEEPING HERE TEMPORARILY UNTIL WE ARE *COMPLETELY* SURE */
// Button behaviour for red/blue/gray buttons
function attachBehaviour(elType){var el=document.getElementsByTagName(elType);for(i=0;i<el.length;i++){var thisClassName=el[i].getAttribute("class");if((thisClassName==null)||(thisClassName=="")){thisClassName=el[i].getAttribute("className")}if((thisClassName!=null)&&(thisClassName.indexOf("button_")!=-1)){if(thisClassName.indexOf("_extrabig")!=-1){el[i].onmouseover=doHoverExtraBig;el[i].onmousedown=doMouseDownExtraBig}else if(thisClassName.indexOf("_big")!=-1){el[i].onmouseover=doHoverBig;el[i].onmousedown=doMouseDownBig}else if(thisClassName.indexOf("_different")!=-1){el[i].onmouseover=doHoverDifferent;el[i].onmousedown=doMouseDownDifferent}else if(thisClassName.indexOf("_diff")!=-1){el[i].onmouseover=doHoverDiff;el[i].onmousedown=doMouseDownDiff}else if(thisClassName.indexOf("_orange")!=-1){el[i].onmouseover=doHoverOrange;el[i].onmousedown=doMouseDownOrange}else{el[i].onmouseover=doHover;el[i].onmousedown=doMouseDown}el[i].onmouseout=el[i].onblur=doMouseOut}}}function doHover(e){this.style.backgroundPosition="0 -21px"}function doMouseDown(e){this.style.backgroundPosition="0 -42px"}function doHoverBig(e){this.style.backgroundPosition="0 -24px"}function doMouseDownBig(e){this.style.backgroundPosition="0 -48px"}function doHoverExtraBig(e){this.style.backgroundPosition="0 -36px"}function doMouseDownExtraBig(e){this.style.backgroundPosition="0 -72px"}function doHoverDifferent(e){this.style.backgroundPosition="0 -26px"}function doMouseDownDifferent(e){this.style.backgroundPosition="0 -52px"}function doHoverDiff(e){this.style.backgroundPosition="0 -21px"}function doMouseDownDiff(e){this.style.backgroundPosition="0 -42px"}function doHoverOrange(e){this.style.backgroundPosition="0 -21px"}function doMouseDownOrange(e){this.style.backgroundPosition="0 -42px"}function doMouseOut(e){this.style.backgroundPosition="0 0"}function addButtonBehaviour(){if(document.getElementsByTagName){attachBehaviour("input");attachBehaviour("img")}}addEvent(window,'load',addButtonBehaviour,false);
//---------------------------------------------------------------------------
/*      DELETE!            DELETE!            DELETE!            DELETE!            DELETE!            DELETE!            DELETE!       */
