﻿/*  START jQuery functions*/
function doSecurityJQueryFunctions(){
	if (jQueryUsed){
		(function($){
			if(!document.defaultView || !document.defaultView.getComputedStyle){
				var oldCurCSS = jQuery.curCSS;
				jQuery.curCSS = function(elem, name, force){
					if(name !== 'backgroundPosition' || !elem.currentStyle || elem.currentStyle[ name ]){
						return oldCurCSS.apply(this, arguments);
					}
					var style = elem.style;
					if ( !force && style && style[ name ] ){return style[ name ];}
					return oldCurCSS(elem, 'backgroundPositionX', force) +' '+ oldCurCSS(elem, 'backgroundPositionY', force);
				};
			}
		})(jQuery);
		//Stop IE flicker
		if ($.browser.msie == true) {document.execCommand('BackgroundImageCache', false, true);}
		function HomepageNavigationMouseOver(){
			$("#tsColumnOne a").mouseover(function(){
				var y = ($(this).find("b").css("backgroundPosition").split(" ")[1]);
				$(this).find("b").css("backgroundPosition","-180px " + y);
			}).mouseout(function(){
				var y = ($(this).find("b").css("backgroundPosition").split(" ")[1]);
				$(this).find("b").css("backgroundPosition","0px " + y);
			}).blur(function(){$(this).mouseout();}).focus(function(){$(this).mouseover();
			});
		}
		HomepageNavigationMouseOver();
		var checklist = new Array(5);
		for (var i=0; i < checklist.length; i++){
			checklist[i]= new Array;
		}
		var imageTick = "<img src=\"/security/_images/tick.jpg\" alt=\"tick\" /> ";
		var imageCross = "<img src=\"/security/_images/cross.jpg\" alt=\"cross\" /> ";
		checklist[0][0] = "I have anti-virus software installed and I run a scan at least weekly and regulary update it.";
		checklist[0][1] = "I don't know if an anti-virus is installed or up to date.";
		checklist[0][2] = "Good. It is important to scan files and e-mails for viruses.";
		checklist[0][3] = "It is very important to have up to date anti-virus software installed.";
		checklist[1][0] = "I have a firewall and it's up to date.";
		checklist[1][1] = "I don't know if a firewall is installed or up to date.";
		checklist[1][2] = "Good. This protects you from unsolicited connections to your computer.";
		checklist[1][3] = "You should some sort of firewall installed. At a minimum, have your operating firewall enabled.";
		checklist[2][0] = "My PC or Mac automatically receives operating system and browser updates when they are released.";
		checklist[2][1] = "I don't know if my PC or Mac receives any or all available updates.";
		checklist[2][2] = "Good. An up to date system will help protect you from security vulnerabilities.";
		checklist[2][3] = "You should check to see if there are updates available for your operating system and your browsers.";
		checklist[3][0] = "I scan my PC for spyware or adware on a regular basis.";
		checklist[3][1] = "I don't know if any anti-spyware software is installed.";
		checklist[3][2] = "Good. An regular spyware scan will ensure safe browsing.";
		checklist[3][3] = "It is important to scan for spyware regularly.";
		var marginTopSolutionRegistering = "50px";
		function populateCheckList(){
			$("#TroubleshootingSolutionRegistering li").each(function(){
				var IndexLi = $("#TroubleshootingSolutionRegistering li").index(this);
				// populate the solution with radio buttons
				$(this).contents("p").prepend("<input type=\"radio\" name=\"radioGroup" + IndexLi + "\" id=\"radioGroup" + IndexLi + "b\" /><label for=\"radioGroup" + IndexLi + "b\">" + checklist[IndexLi][1] + "</label><br />");
				$(this).contents("p").prepend("<input type=\"radio\" name=\"radioGroup" + IndexLi + "\" id=\"radioGroup" + IndexLi + "a\" /><label for=\"radioGroup" + IndexLi + "a\">" + checklist[IndexLi][0] + "</label><br />");
			});
			// run this on the first click
			$("#TroubleshootingSolutionRegistering a:last").one('click',function(){
				// work through the radios to check advice to be given
				$("#TroubleshootingSolutionRegistering li p").each(function(){
					var IndexLi = $("#TroubleshootingSolutionRegistering li p").index(this);
					if($(this).find("input:first").is(":checked")){
						$(this).prepend(imageTick + checklist[IndexLi][2]);
					}
					else{
						$(this).prepend(imageCross + checklist[IndexLi][3]);
					}
				});
				// remove the radio buttons and labels
				$("#TroubleshootingSolutionRegistering p :not(a,img)").remove();
				// hide the first link
				$("#TroubleshootingSolutionRegistering li a:even").hide();
				// wrap a span inside
				$("#TroubleshootingSolutionRegistering li a:odd").wrap("<span>");
				// show the second link
				$("#TroubleshootingSolutionRegistering li a:odd").show();
				// set the text on the link
				$(this).html("<strong>Let's see if you need any more help</strong>");
				marginTopSolutionRegistering = $("#TroubleshootingSolutionRegistering").height() - 105;
				$("#footer").animate({marginTop: marginTopSolutionRegistering}, "slow" );
				return false;
			});
		}
		function initiateTroubleshootingCheckList(){
			// hide the answers and hide the second link to the rough guide

			// save the alt text
			var TroubleshootingCheckListRegisteringAltText = $("#TroubleshootingCheckListRegistering a").text()
			var TroubleshootingCheckListTroubleAltText = $("#TroubleshootingCheckListTrouble a").text()
			var TroubleshootingCheckListOtherAltText = $("#TroubleshootingCheckListOther a").text()

			// get rid of the text, it flickers sometimes
			$("#TroubleshootingCheckListRegistering a,#TroubleshootingCheckListTrouble a,#TroubleshootingCheckListOther a").empty();

			//  add images to links
			$("#TroubleshootingCheckListRegistering a").append("<img src=\"/troubleshooting/_images/registering-for-internet-banking.gif\" /><img src=\"/troubleshooting/_images/registering-for-internet-banking_hover.gif\" /><img src=\"/troubleshooting/_images/registering-for-internet-banking_click.gif\" />");
			$("#TroubleshootingCheckListTrouble a").append("<img src=\"/troubleshooting/_images/having-trouble-signing-on-or-off.gif\" /><img src=\"/troubleshooting/_images/having-trouble-signing-on-or-off_hover.gif\" /><img src=\"/troubleshooting/_images/having-trouble-signing-on-or-off_click.gif\" />");
			$("#TroubleshootingCheckListOther a").append("<img src=\"/troubleshooting/_images/other-common-questions.gif\" /><img src=\"/troubleshooting/_images/other-common-questions_hover.gif\" /><img src=\"/troubleshooting/_images/other-common-questions_click.gif\" />");
			
			$("#TroubleshootingCheckListRegistering img").attr("alt",TroubleshootingCheckListRegisteringAltText);
			$("#TroubleshootingCheckListTrouble img").attr("alt",TroubleshootingCheckListTroubleAltText);
			$("#TroubleshootingCheckListOther img").attr("alt",TroubleshootingCheckListOtherAltText);
			
			// hide the mouseover images
			$("#TroubleshootingSolutionRegistering,#TroubleshootingSolutionTrouble,#TroubleshootingSolutionOther,#TroubleshootingSolutionRegistering li a:odd,#TroubleshootingCheckListRegistering img:nth-child(3),#TroubleshootingCheckListTrouble img:nth-child(3),#TroubleshootingCheckListOther img:nth-child(3)").hide();

			//hide the second one slowly, to highlight link
			$("#TroubleshootingCheckListRegistering img:nth-child(2)").animate({opacity: 1.0}, 3000).fadeOut("slow")
			$("#TroubleshootingCheckListTrouble img:nth-child(2)").animate({opacity: 1.0}, 3000).fadeOut("slow")
			$("#TroubleshootingCheckListOther img:nth-child(2)").animate({opacity: 1.0}, 3000).fadeOut("slow")

			var blnRegisteringHidden = true;
			var blnTroubleHidden = true;
			var blnOtherHidden = true;
			$("#TroubleshootingCheckListRegistering").toggle(function(){			
				$("#TroubleshootingSolutionRegistering").slideDown("slow");
				blnRegisteringHidden = false;
				$("#footer").animate({marginTop: marginTopSolutionRegistering}, "slow" );
				//hide the images and the campaigns	
				$("#TroubleshootingCheckListRegistering img:nth-child(1),#TroubleshootingCheckListRegistering img:nth-child(2)").hide();
				$("#TroubleshootingCheckListRegistering img:nth-child(3)").show();
				if ($("#TroubleshootingSolutionTrouble").is(":visible")) {
					$("#TroubleshootingCheckListTrouble").click().trigger('mouseout');
					$("#TroubleshootingCheckListTrouble img:nth-child(2)").mouseout();
				}
				if ($("#TroubleshootingSolutionOther").is(":visible")) {
					$("#TroubleshootingCheckListOther").click().trigger('mouseout');
					$("#TroubleshootingCheckListOther img:nth-child(2)").mouseout();
				}
			},function(){
				$("#TroubleshootingSolutionRegistering").slideUp("slow");
				if(blnTroubleHidden && blnOtherHidden){
					$("#footer").animate({marginTop: "0px"}, "slow" );
					//$("#campaignSlot1,#campaignSlot2").fadeIn("slow");
				}
				blnRegisteringHidden = true;
				$("#TroubleshootingCheckListRegistering img:nth-child(1),#TroubleshootingCheckListRegistering img:nth-child(3)").hide();
				$("#TroubleshootingCheckListRegistering img:nth-child(2)").show();
			});
			$("#TroubleshootingCheckListTrouble").toggle(function(){
				$("#TroubleshootingSolutionTrouble").slideDown("slow");
				blnTroubleHidden = false;
				$("#footer").animate({marginTop: "200px"}, "slow" );
				$("#TroubleshootingCheckListTrouble img:nth-child(1),#TroubleshootingCheckListTrouble img:nth-child(2)").hide();
				$("#TroubleshootingCheckListTrouble img:nth-child(3)").show();
				//$("#campaignSlot1,#campaignSlot2").hide();
				if ($("#TroubleshootingSolutionRegistering").is(":visible")){
					$("#TroubleshootingCheckListRegistering").click();
					$("#TroubleshootingCheckListRegistering img:nth-child(2)").mouseout();
				}
				if ($("#TroubleshootingSolutionOther").is(":visible")) {
					$("#TroubleshootingCheckListOther").click().trigger('mouseout');
					$("#TroubleshootingCheckListOther img:nth-child(2)").mouseout();
				}
			},function(){
				$("#TroubleshootingSolutionTrouble").slideUp("slow");
				if(blnRegisteringHidden && blnOtherHidden){
					$("#footer").animate({marginTop: "0px"}, "slow" );
					//$("#campaignSlot1,#campaignSlot2").fadeIn("slow");
				}
				blnTroubleHidden = true;
				$("#TroubleshootingCheckListTrouble img:nth-child(1),#TroubleshootingCheckListTrouble img:nth-child(3)").hide();
				$("#TroubleshootingCheckListTrouble img:nth-child(2)").show();
			});
			$("#TroubleshootingCheckListOther").toggle(function(){
				$("#TroubleshootingSolutionOther").slideDown("slow");
				$("#troubleshootingChecklistWrapper").css("padding-bottom", "10px");
				blnOtherHidden = false;
				$("#TroubleshootingCheckListOther img:nth-child(1),#TroubleshootingCheckListOther img:nth-child(2)").hide();
				$("#TroubleshootingCheckListOther img:nth-child(3)").show();
				$("#footer").animate({marginTop: "0px"}, "slow" );
				//$("#campaignSlot1,#campaignSlot2").hide();
				if ($("#TroubleshootingSolutionRegistering").is(":visible")){
					$("#TroubleshootingCheckListRegistering").click();
					$("#TroubleshootingCheckListRegistering img:nth-child(2)").mouseout();
				}
				if ($("#TroubleshootingSolutionTrouble").is(":visible")) {
					$("#TroubleshootingCheckListTrouble").click().trigger('mouseout');
					$("#TroubleshootingCheckListTrouble img:nth-child(2)").mouseout();
				}
			},function(){
				$("#TroubleshootingSolutionOther").slideUp("slow");
				if(blnRegisteringHidden && blnTroubleHidden){
					$("#footer").animate({marginTop: "0px"}, "slow" );
					//$("#campaignSlot1,#campaignSlot2").fadeIn("slow");
				}
				$("#troubleshootingChecklistWrapper").css("padding-bottom", "0");				
				blnOtherHidden = true;
				$("#TroubleshootingCheckListOther img:nth-child(1),#TroubleshootingCheckListOther img:nth-child(3)").hide();
				$("#TroubleshootingCheckListOther img:nth-child(2)").show();
			});
			$("#TroubleshootingCheckListRegistering img:first").mouseover(function(){
				$("#TroubleshootingCheckListRegistering img:nth-child(2)").fadeIn(1000);
			});
			$("#TroubleshootingCheckListRegistering img:nth-child(2)").mouseout(function(){
				$("#TroubleshootingCheckListRegistering img:nth-child(2)").fadeOut(1000);
				$("#TroubleshootingCheckListRegistering img:nth-child(1)").show();
			});
			$("#TroubleshootingCheckListRegistering img:nth-child(3)").mouseover(function(){
				$("#TroubleshootingCheckListRegistering img:nth-child(1),#TroubleshootingCheckListRegistering img:nth-child(2)").hide();
			});
			$("#TroubleshootingCheckListRegistering a").focus(function(){
				$("#TroubleshootingCheckListRegistering img:first").trigger("mouseover");
			});
			$("#TroubleshootingCheckListRegistering a").blur(function(){
				$("#TroubleshootingCheckListRegistering img:nth-child(2)").trigger("mouseout");
			});
			$("#TroubleshootingCheckListTrouble img:first").mouseover(function(){
				$("#TroubleshootingCheckListTrouble img:nth-child(2)").fadeIn(1000);
			});
			$("#TroubleshootingCheckListTrouble img:nth-child(2)").mouseout(function(){
				$("#TroubleshootingCheckListTrouble img:nth-child(2)").fadeOut(1000);
				$("#TroubleshootingCheckListTrouble img:nth-child(1)").show();
			});
			$("#TroubleshootingCheckListTrouble img:nth-child(3)").mouseover(function(){
				$("#TroubleshootingCheckListTrouble img:nth-child(1),#TroubleshootingCheckListTrouble img:nth-child(2)").hide();
			});
			$("#TroubleshootingCheckListTrouble a").focus(function(){
				$("#TroubleshootingCheckListTrouble img:first").trigger("mouseover");
			});
			$("#TroubleshootingCheckListTrouble a").blur(function(){
				$("#TroubleshootingCheckListTrouble img:nth-child(2)").trigger("mouseout");
			});
			$("#TroubleshootingCheckListOther img:first").mouseover(function(){
				$("#TroubleshootingCheckListOther img:nth-child(2)").fadeIn(1000);
			});
			$("#TroubleshootingCheckListOther img:nth-child(2)").mouseout(function(){
				$("#TroubleshootingCheckListOther img:nth-child(2)").fadeOut(1000);
				$("#TroubleshootingCheckListOther img:nth-child(1)").show();
			});
			$("#TroubleshootingCheckListOther img:nth-child(3)").mouseover(function(){
				$("#TroubleshootingCheckListOther img:nth-child(1),#TroubleshootingCheckListOther img:nth-child(2)").hide();
			});
			$("#TroubleshootingCheckListOther a").focus(function(){
				$("#TroubleshootingCheckListOther img:first").trigger("mouseover");
			});
			$("#TroubleshootingCheckListOther a").blur(function(){
				$("#TroubleshootingCheckListOther img:nth-child(2)").trigger("mouseout");
			});
			populateCheckList();
		}
		initiateTroubleshootingCheckList();
		function tidyPopupHelp(){
			var filename = window.location.href.split("/");
			var img = filename[filename.length-1].split(".")[0]
			
			$("body:has(div.helpContent) div.helpContent").append("<img src=\"/security/_images/pop-up-help-" + img + ".gif\" />");
			$("body:has(div.helpContent) img:first").attr("alt","")
			$("body:has(div.helpContent) input,body:has(div.helpContent) hr").remove();
			
		}
		if(window.location.href.indexOf("NRMODE") == -1){
			tidyPopupHelp();		
		}
		function addPopups(){
			$("a[rel=Help]").click(function(){
				popUpWin($(this).attr("href"), "standard", "740", "600");
				return false;
			});
		}
		addPopups();		
		function tidyBackgroundImageOnQuickLinks(){
			$("#quickLinksList a:eq(3)").css("backgroundPosition","right -420px")
		}
		tidyBackgroundImageOnQuickLinks();
		function fixMeaninglessMoreInfoLinksSecurity()
		{			
			// For security site
			$("#tsColumnTwo .slot a.buttonExit").each(function(){
				/*$(this).each(function(){
					alert(this.tagName);
				});*/
				$(this).wrapInner(" <span class='srhelp'>(" + $(this).prev().attr("alt") + ")</span>");
			})			
			$("span.srhelp")
			.css("display","block")
			.css("position","absolute")
			.css("text-indent","-30000px")
			.css("overflow","hidden")
			;
		}
		fixMeaninglessMoreInfoLinksSecurity();		
	}
}

addEvent(window, 'load', doSecurityJQueryFunctions, false);
