var siteUrl = '/AssetManager/';
var OP   = (navigator.userAgent.indexOf("Opera") != -1);
var IE   = (navigator.userAgent.indexOf("MSIE") != -1) && !OP;
if (IE)
{
    sfHover = function()
    {   var sfEls = document.getElementById("navContainer").getElementsByTagName("LI");
    	for (var i=0; i<sfEls.length; i++)
    	{   sfEls[i].onmouseover=function()
    	    {   this.className+=" hover";
    		}
    		sfEls[i].onmouseout=function()
    		{   this.className=this.className.replace(new RegExp(" hover\\b"), "");
    		}
    	}
    }
    if (window.attachEvent) window.attachEvent("onload", sfHover);
}

if (location.href.indexOf('') == -1){ 
	location.href = ''; 
}
else{
		$(document).ready(function() {
                

		if (urlParameter('redirectTo') != '' && urlParameter('redirectName') != '') {
			if (typeof setLinkName == 'function') {
				s.linkTrackVars='prop8,prop9';
				s.linkTrackEvents='None';
				s.prop8 = urlParameter('redirectName');
				s.prop9 = urlParameter('redirectTo');
				s.tl(true,'d', urlParameter('redirectName'));
			}
			location.href = decodeURIComponent(urlParameter('redirectTo'));
			return false;
		}
	    
		// Check for cookies and redirect to Disclaimer
		// --------------------------------------------- 
		
		$('#accept').click(function(){
		    $.cookie('seenDisclaimer', siteUrl,{ expires: 90, path: '/' });
	        var redirectTo = location.href.indexOf('ReturnTo=') != -1 ? location.href.split('ReturnTo=')[1] : '/';
	        location.href = redirectTo;
	    });
		
	    if ((!$.cookie('seenDisclaimer') || $.cookie('seenDisclaimer') != siteUrl) && location.href.toLowerCase().indexOf('disclaimer') == -1 && location.href.toLowerCase().indexOf('/footer') == -1 && siteUrl.toLowerCase() != '/investor/' && siteUrl.toLowerCase() != '/sandbox/'){	       			    	    	 location.href = siteUrl + '/Disclaimer.aspx?ReturnTo=' + location.href; 
	    }
	    else{
	    	 $('div.pageDisplay').show();
	    }
	
	    // Change search box contents on focus/blur
		// --------------------------------------------- 
		$('#_searchTerms')
			.focus(function(){
				if ($(this).val() == 'Search'){ $(this).val(''); }
			})
			.blur(function(){
				if ($(this).val() == ''){ $(this).val('Search'); }
			});
		
		
		// Add search terms in the search action
		$('#_searchForm').submit(function(){
			$(this).attr('action',$(this).attr('action') + '?terms=' + $('#_searchTerms').val());
		});
		
		
		// FIX -- talking point links
		$('#latestTalkingPoints a').each(function(){
			if (location.href.indexOf($(this).attr('href')) != -1){
				$(this).parent().remove();
			}	
		});
		if ($('#latestTalkingPoints a').length > 5){
			$('#latestTalkingPoints a:last').remove();
		}
		
		// FIX -- repeated breadcrumb arrows 
		$('.breadcrumb a:empty').remove();
		$('.breadcrumb a').after(' » ');
		
		// FIX -- webconferences empty Learn more link
		$('.webConferences a').each(function(){
			if (location.href.indexOf($(this).attr('href')) != -1){
				$(this).parent().remove();
			}	
		});
		
		// Global navigation drop menus
		// --------------------------------------------- 
		
		$('#navContainer ul li').each(function(){
			if ($(this).find('ul').length > 0){
				$(this).addClass('hasMenu');
			}
		});
		
		// Last sitemap node
	    $('.sitemap ul ul').each(function(){ $(this).children('li:last').addClass('last'); });
	    
		// Redirect interactive factsheet - DC site
	    if (urlParameter('FundID') && urlParameter('ShareClassID') && urlParameter('FundType')){
	    	if (urlParameter('FundType') == 'Life'){
				$('#factsheet, #factsheetDP').attr('src','http://213.229.167.101/JP/JP.mvc/Overview?fundId=' + urlParameter('FundID') + '&ShareClassId=' + urlParameter('ShareClassID') + '&country=GB&lang=EN');
			}
			else{
				$('#factsheet, #factsheetDP').attr('src','http://213.229.167.101/JP/JP.mvc/Overview?fundId=' + urlParameter('FundID') + '&ShareClassId=' + urlParameter('ShareClassID') + '&country=GB&lang=EN&paramMIFID=' + mifid);
			}
		}
        // Redirect Investment Trust interactive factsheet
	    if (urlParameter('TrustCode')){
	    	//$('#InvTrustFactsheet').attr('src','http://213.229.167.101/ITRUST/TestUC.aspx?trustCode=' + urlParameter('TrustCode') + '&css=2&PARAMMIFID=' + mifid + '&AspxAutoDetectCookieSupport=1');

$('#InvTrustFactsheet').attr('src','http://213.229.167.101/JP/JP.mvc/ITOverview?FundId=' + urlParameter('TrustCode') + '&PARAMMIFID=' + mifid);

	    }	});
}

// FIX -- get top most Section
function getTopSection(){
	if (siteUrl != ''){
		return location.pathname.split('/')[2];
	}
	else{
		return location.pathname.split('/')[1];
	}
}

// Get URL parameters
// --------------------------------------------- 
function urlParameter(name){
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
	var regexS = "[\\?&]"+name+"=([^&#]*)"; 
	var regex = new RegExp(regexS); 
	var results = regex.exec(window.location.href);  
	if (results == null){
		return ""; 
	}
	else{
		return results[1];
	}
}


/*Added by Shrikant  for CAS-08538 on 07/02/2010*/
		
function toggleDivDisplay(objId)
{

	var divObj;
	divObj = document.getElementById(objId);

	if(divObj == undefined) {return;}

	
	divObj.style.display = (divObj.style.display == 'none') ? 'block' : 'none';


}

// Change site name to friendly display name in site switcher - KA
$(function() {
	var $siteName = $('#siteName');
	if ('Asset and Wealth Manager' == 'Private investor') {
		$siteName.html('For investors');
	}
	if ('Asset and Wealth Manager' == 'Adviser') {
		$siteName.html('For advisers');
	}
	if ('Asset and Wealth Manager' == 'Asset and Wealth Manager') {
		$siteName.html('For asset and wealth managers');
	}
	if ('Asset and Wealth Manager' == 'Institutional investor') {
		$siteName.html('For institutional investors');
	}
	if ('Asset and Wealth Manager' == 'Investment Trusts') {
		$siteName.html('For investment trusts');
	}
	if ('Asset and Wealth Manager' == 'Defined Contribution') {
		$siteName.html('Defined Contribution Pension Schemes');
	}
});
