/* 
Script for future Talisma search use. May be used - in conjunction with jQuery - 
to correct problems on the page without requiring a bank release
*/

	var isNbsBrowser = ((navigator.userAgent.toUpperCase().indexOf("HO32600")!=-1)||(navigator.userAgent.toUpperCase().indexOf("HO32501")!=-1));
	//alert("isNbsBrowser = " + isNbsBrowser);
	if (!isNbsBrowser) {
		$("#PrimaryItem2").after("<li id=\"PrimaryItem2a\"><a href=\"/isas/default.htm\"><span>ISAs</span></a></li>");
	}
	
	function fixStraplineAlt() {
		$("img[alt='proud to be a building society']").attr("alt","On your side");
	}
	fixStraplineAlt();

	function setUpConcertina(){
		$("a.toggle")
		.click(function(event){
			event.preventDefault();
			var $object = $(this).parent().next();
			$object.toggle();
		})
		.toggle(function(){
			$(this).prev().text("-");
		},
		function(){
			$(this).prev().text("+");
		})
		.parent().next().hide();
		var l = location.href;
		if (l.indexOf("#")!=-1) {
			var trigger = l.split("#")[1];
			$("a#" + trigger).click();
		}
	}
	setUpConcertina();

	// popups and link styling
	function managePopUpLinks()
	{
	$("a[href$='.doc']").addClass("worddoc");
	$("a[href$='.ppt']").addClass("powerpointdoc");
	$("a[href$='.xls']").addClass("exceldoc");
	$("a[href$='.pdf']").addClass("pdfdoc");
	$("a[href$='.txt']").addClass("txtdoc");
	$("a[href$='.zip']").addClass("zipdoc");
	
	$("a.worddoc, a.powerpointdoc, a.exceldoc, a.pdfdoc, a.txtdoc").addClass("popup")
	
	$("a.popup").each(function(){
	 	var title="This link opens in a new window";
		var width="780";
		var height="550";
		var left="0";
		var top="20";
		var status=",status=1, statusbar=1";

		$(this)
		.attr("title",title)
		.click(function(){
			var tools="";
			var url = ($(this).attr("href"));
			var newWindow;
				var popWidth=width;
				var popHeight=height;
				tools = "width = " + popWidth + " ,height =" + popHeight + ",resizable,toolbar=no,location=no,scrollbars=yes,left=" + left + ",top=" + top + status;
			newWindow = window.open(url, 'newWin', tools);
			return false;
		})
	});

	$("a.simgpopup").each(function(){
		var title="This link displays an image in a new window";
		var width="200";
		var height="100";
		var left="300";
		var top="300";
		var status="";
			
		$(this)
		.attr("title",title)
		.click(function(){
			var tools="";
			var url = ($(this).attr("href"));
			var newWindow;
				var popWidth=width;
				var popHeight=height;
				tools = "width = " + popWidth + " ,height =" + popHeight + ",resizable,toolbar=no,location=no,scrollbars=yes,left=" + left + ",top=" + top + status;
			newWindow = window.open(url, 'newWin', tools);
			return false;
		})
	});

	$("a.limgpopup").each(function(){
		var title="This link displays an image in a new window";
		var width="1023";
		var height="260";
		var left="1";
		var top="10";
		var status="";
		$(this)
		.attr("title",title)
		.click(function(){
			var tools="";
			var url = ($(this).attr("href"));
			var newWindow;
			var popWidth=width;
			var popHeight=height;
			tools = "width = " + popWidth + " ,height =" + popHeight + ",resizable,toolbar=no,location=no,scrollbars=yes,left=" + left + ",top=" + top + status;
			newWindow = window.open(url, 'newWin', tools);
			return false;
		})
	});

	$("a.pdfdoc").css({
		"background-image": "url(/_/images/sprites/mini-icons.gif)",
		"background-position": "0 -249px",
		"background-repeat": "no-repeat",
		"border": "medium none",
		"padding-left": "20px"
	});

	$("a[href$='.doc']").attr("title","This Word document will open in a new window or tab");
	$("a[href$='.ppt']").attr("title","This PowerPoint document will open in a new window or tab");
	$("a[href$='.xls']").attr("title","This Excel document will open in a new window or tab");
	$("a[href$='.pdf']").attr("title","This PDF link will open in a new window or tab");
	$("a[href$='.txt']").attr("title","This text document will open in a new window or tab");
	}
	managePopUpLinks();
	
var helpFilterText = "&larr; <strong>Tip</strong>: Changing this to 'All words' may improve search results";

function anyOrAllSelection()
{
	$("#ddlSearchUsing").after("<span id=\"searchTip\">jjj</span>");
	$("#searchTip").css("font-size","12px").css("padding-left","5px");
	
	function flashTip()
	{
	$("#searchTip").html(helpFilterText);
	$("#searchTip")
	.fadeTo('medium',0.6).fadeTo('fast',1)
	.fadeTo('medium',0.6).fadeTo('fast',1)
	.fadeTo('medium',0.6).fadeTo('fast',1)
	.fadeTo('medium',0.6).fadeTo('fast',1)
	}

	if ($("#ddlSearchUsing").val()=="any")
		{
		flashTip();
		}
	else
		{
		$("#searchTip").empty();
		}

$("#ddlSearchUsing").change(function(){
	if ($("#ddlSearchUsing").val()=="any")
		{
			flashTip();
		}
	else
		{
		$("#searchTip").empty();
		}
	})
	
	
}
//anyOrAllSelection();

function concertinaClickByName(){
	var hash = document.location.href.substr(document.location.href.lastIndexOf("#"));
	if(hash.length>1){
		hash=hash.substr(1);
		$("a.toggle[name='"+hash+"']").click();
	}
}
concertinaClickByName();
