// REQUIRES jQuery and Russell.Core.js functions

var IsLoggedIn = false;
var CssEnabled = false;
$(AttachInitialEventListeners);
$(window).load(AttachWindowLoadFunctions);

// Run all window.ondomready events here
function AttachInitialEventListeners()
{
	//EnableMediaTypeSelection();
	EnableIWantTo();
    CustomOmnitureTracking();
	EnableLatestNews();
	EnableMarquee();
	CheckIfLoggedIn();
	CheckIfCssEnabled();
    hijack_search_button();
    SetUpMultiViews();
	SetUpExpanderViews();
    AttachLinkHandlers();
    RepositionFollowingButtonArea();
    expandoBox();
	TermsAndConditions();
}

// Run all window.load events here
function AttachWindowLoadFunctions()
{
	var isn = document.getElementById('IntrasiteNav');
	if (isn && isn.clientWidth > 330)
	{
		document.getElementById('Tools').style.top = '47px';
	}
}

var iWantToDiv;
function EnableIWantTo()
{
	iWantToDiv = document.getElementById('IWantTo');
	if (iWantToDiv)
	{
		$('#IWantTo .openClose').click(ToggleIWantTo);
	}
	$('#QRCChooseFundStrategy_MS').hide();
	//$('#QRCChooseFundStrategy_LP select').get(0).disabled = true;
	$('#GetMaterialsButton').click(function () {
		var GetMatSelect = document.getElementById('GetMaterialsDdl');
		if (GetMatSelect && GetMatSelect.value == '/estore.aspx') {
			bowneBoxConnect('');
			return false;
		}
		else {
			return validateIWantToGoRequest('GetMaterialsDdl');
		}
	});

    //Show and hide the QRC dropdown list controls
	$('#ddlPackage').change(function () {
		var selected = this.value;
		var $btn = $('#PrepareForAClientReviewButton');
		switch (selected) {
			case '':
				$btn.unbind('click').click(function(){
					return validateIWantToGoRequest('ddlPackage');
				});
				$('#QRCChooseFundStrategy_MS').hide();
				$('#QRCChooseFundStrategy_LP').show();
				//$('#QRCChooseFundStrategy_LP select').get(0).disabled = true;
				$('#QRCChooseFundStrategy_LP select').get(0).selectedIndex = 0;
				break;
			case 'LPTPS-Kit':
				$btn.unbind('click').click(function(){
					return validateIWantToGoRequest('ddlPackage', 'lptps-fund2');
				});
				$('#QRCChooseFundStrategy_LP').show();
				$('#QRCChooseFundStrategy_MS').hide();
				//$('#QRCChooseFundStrategy_LP select').get(0).disabled = false;
				break;
			case 'MS-Kit':
				$btn.unbind('click').click(function(){
					return validateIWantToGoRequest('ddlPackage', 'ms-strategy2');
				});
				$('#QRCChooseFundStrategy_LP').hide();
				$('#QRCChooseFundStrategy_MS').show();
				//$('#QRCChooseFundStrategy_MS select').get(0).disabled = false;
				break;
		}
	});
	$('.fundStrategyChooser select').change(function(){
		document.getElementById('ChooseFundStrategyHidden').value = this.value;
	});
   
}

function CustomOmnitureTracking() {
    // Omniture - custom event tracking for tabs on RLink homepage
    $('#HomepageTabs a').click(function () {
        customEventRecord(true, 'o', ('RLINK HomePage-' + $(this).text()));
    });

    // Omniture - custom event tracking for tabs on QRC
    $('#QRC #NavList a').click(function () {
        customEventRecord(true, 'o', ('QRC-' + $(this).text()));
    });

    // Omniture - custom event tracking for buttons on QRC Kit page
    $('#QRC #ActionButtons input[type=button]').click(function () {
        customEventRecord(true, 'o', ('QRC-' + $(this).attr('id')));
    });

    // Omniture - custom event tracking for IWantTo buttons
    $('#IWantTo li button, #IWantTo li input[type=submit]').click(function () {
        var buttonName = $(this).attr('name');
        if (!buttonName) {
            buttonName = $(this).attr('id');
        }
        customEventRecord(true, 'o', ('IWT-' + buttonName + '-' + document.title ));
    });
}

function validateIWantToGoRequest()
{
	var isvalid = true;
	var i = 0;
	for (; i < arguments.length; i++)
	{
		isvalid = (isvalid && isDropdownSet(arguments[i]));
		if (!isvalid) break;
	}
	if (!isvalid)
	{
		alert('Please ' + document.getElementById(arguments[i]).options[0].text + ' to continue');
	}
	return isvalid;
}
function isDropdownSet(ddlId)
{
	var ddl = document.getElementById(ddlId);
	return (ddl && ddl.value != '');
}

var LatestNewsDiv, LatestNewsUl, LatestNewsCurrentItemSpan;
var LatestNews_currentItem = 1, LatestNews_totalItems, LatestNews_ItemHeight;
var timer_LatestNews;
var fadeDuration = 400, intervalDuration = 10000;
function EnableLatestNews()
{
	LatestNewsDiv = document.getElementById('LatestNews');
	if (LatestNewsDiv)
	{
		var newsItemList = $('ul li', LatestNewsDiv);
		LatestNews_ItemHeight = newsItemList.get(0).clientHeight;
		LatestNews_totalItems = newsItemList.length;
		if (LatestNews_totalItems > 1)
		{
			LatestNewsUl = $('ul', LatestNewsDiv).after('<div id="NewsCounter"><a onclick="NextNewsItem(-1)"><</a><span id="LatestNews_CurrentItemSpan">' + LatestNews_currentItem.toString() + '</span> of '+ LatestNews_totalItems.toString() + '<a onclick="NextNewsItem(1)">></a></div>').get(0);
			LatestNewsCurrentItemSpan = document.getElementById('LatestNews_CurrentItemSpan');
			GetNewsItem(LatestNews_currentItem);
			timer_LatestNews = setInterval('NextNewsItem(1)', intervalDuration);
			$(LatestNewsDiv).hover(function(){clearInterval(timer_LatestNews);}, function(){timer_LatestNews = setInterval('NextNewsItem(1)', intervalDuration)});
		}
	}
}
function NextNewsItem(incr)
{
	var newIndex = (LatestNews_currentItem - 1 + incr) % LatestNews_totalItems + 1;
	if (newIndex < 1) newIndex = LatestNews_totalItems;
	GetNewsItem(newIndex);
}
function GetNewsItem(idx)
{
	if (LatestNewsCurrentItemSpan && LatestNewsUl && idx != LatestNews_currentItem)
	{
		LatestNews_currentItem = idx;
		$(LatestNewsUl).fadeOut(fadeDuration, function(){
			LatestNewsUl.style.top = ((LatestNews_currentItem - 1) * -LatestNews_ItemHeight).toString() + 'px';
			$(LatestNewsUl).fadeIn(fadeDuration);
		});
		LatestNewsCurrentItemSpan.innerHTML = LatestNews_currentItem.toString();
	}
}
var MarqueeImageDiv, marqueeList, marqueeList_totalItems, currentMarqueeIndex = 1, timer_Marquee;
function EnableMarquee()
{
	MarqueeImageDiv = document.getElementById('MarqueeImage');
	if (MarqueeImageDiv)
	{
		marqueeList = $('div.marquee', MarqueeImageDiv);
		marqueeList_totalItems = marqueeList.length;
		if (marqueeList_totalItems > 1)
		{
			$('#Marquee').addClass('activated');
			marqueeList.addClass(function(index,currentClass){return 'marquee' + (index+1).toString();});
			marqueeList.last().after(getMarqueeNav);
			GetMarquee(currentMarqueeIndex);
			timer_Marquee = setInterval('NextMarquee(1)', intervalDuration);
			$(MarqueeImageDiv).hover(function(){clearInterval(timer_Marquee);}, function(){timer_Marquee = setInterval('NextMarquee(1)', intervalDuration);});
			marqueeList = null;
		}
	}
}
function NextMarquee(incr)
{
	var newIndex = (currentMarqueeIndex - 1 + incr) % marqueeList_totalItems + 1;
	if (newIndex < 1) newIndex = marqueeList_totalItems;
	GetMarquee(newIndex);
}
function GetMarquee(idx)
{
	if (idx < 1) idx = 1;
	if (idx > marqueeList_totalItems) idx = marqueeList_totalItems;
	currentMarqueeIndex = idx;
	MarqueeImageDiv.className = 'showMarquee' + idx.toString();
}
function getMarqueeNav()
{
	var sb = new Array();
	sb.push('<div id="MarqueeNav"><a onclick="NextMarquee(-1)" class="marqueeArrow"><</a>');
	for (var i = 0; i < marqueeList_totalItems; i++)
	{
		var strI = (i+1).toString();
		sb.push('<a onclick="GetMarquee(' + strI + ')" title="' + strI + ' of ' + marqueeList_totalItems.toString() + '" class="marqueeIndicator' + strI + '">' + strI + '</a>');
	}
	sb.push('<a onclick="NextMarquee(1)" class="marqueeArrow">></a></div>');
	return sb.join('');
}
function ToggleIWantTo()
{
	ToggleClass(iWantToDiv, 'open', 'closed');
}

// Allow user to force display and print via a specific media type
function EnableMediaTypeSelection()
{
	if(window.location.search != '')
	{
		var mediaPat = /\?(&|&amp;)?media=(.+)(&|$)/i;
		var result = window.location.search.match(mediaPat);
		if (result && result.length > 2)
		{
			var mediaTgt = result[2];
			var ssMediaPattern = new RegExp('\\b(all|' +  mediaTgt + ')\\b', 'i');
			for (var i = 0; i < document.styleSheets.length; i++)
			{
				var ss = document.styleSheets[i];
				//alert(ss.href);
				var ssMedia = ss.media;
				var ssTag = (ss.ownerNode) ? ss.ownerNode : ss.owningElement;
				if (typeof ssMedia != 'string') ssMedia = ssMedia.mediaText;
				if (ssMediaPattern.test(ssMedia))
				{
					ssTag.media = 'all';
				}
				else
				{
					ssTag.media = 'none';
					ss.disabled = true;
				}
			}
		}
	}
}

// Inspect all links in order to handle special cases (such as "rel"-directed behaviors)
function AttachLinkHandlers()
{
	$('a[rel]').each( function (index) {
		switch (this.rel)
		{
			case 'UsdFeedback':
			case 'SalesFeedback':
				thisLink.onclick = OpenSalesFeedbackWindow;
				break;
			default:
				break;
		}
	});
}

// Place the FollowingButtonArea under the SubNav
function RepositionFollowingButtonArea()
{
 var sn = document.getElementById('SubNav');
 var fb = document.getElementById('FollowingButtonArea');
 if (sn && fb)
 {
  fb.style.top = (sn.offsetTop + sn.offsetHeight - 142).toString() + 'px';
  $(fb).addClass('repositioned');
 }
}

function expandoBox()
{
	$('div.tipBox h3.title').each( function (index) {
		this.onclick = function () {tipThisBox(this); return false;}
	});
}

// Overwrite search box functionality (existing search function is inline in template) - eBiz 10/12/2006
function hijack_search_button()
{
	$('#SitePageTopTools1_NavbarSearch_btnSubmit').click(search_redirect);
}
// Check if the user is logged in and store in a global variable
function CheckIfLoggedIn()
{
	IsLoggedIn = /RLinkApp/.test(document.cookie);
}

// Check if CSS is enabled
function CheckIfCssEnabled()
{
	CssEnabled = function()
	{
		var returnVal = false;
		var cookieCss = GetCookie('css');
		if (cookieCss == null)
		{
			var newDiv = document.createElement('div');
			document.body.appendChild(newDiv);
			newDiv.style.width = '20px';
			newDiv.style.padding = '10px';
			var divWidth = newDiv.offsetWidth;
			document.body.removeChild(newDiv);
			returnVal = (divWidth == 40);
			SetCookie('css', returnVal.toString());
		}
		else
		{
			returnVal = (cookieCss == 'true');
		}
		return returnVal;
	}();
}

// Open/Close Tool Tip
function tipThisBox(elem)
{
	ToggleClass(elem.parentNode,'hideTip','showTip');
}

// Require acceptance of Terms and Conditions
function TermsAndConditions()
{
	if (!GetCookie('RussellLINKTermsAndConditions') && GetCookie("LoginNameReminder") && location.pathname.toLowerCase() != '/login.aspx')
	{
		var tandcButtons = {'Accept':function(){SetCookie('RussellLINKTermsAndConditions','accepted',new Date(2100,1,1), '/');$(this).dialog('close');$('#TermsAndConditionsDialog').remove();}};
		$('body>form').first().after('<div id="TermsAndConditionsDialog" title="RussellLINK Terms and Conditions of Use"><iframe src="/TermsAndConditions.html" width="100%" height="99%" frameborder="0"></iframe></div>')
		$('#TermsAndConditionsDialog').dialog({closeOnEscape:false,buttons:tandcButtons,dialogClass:'termsAndConditions',width:600,height:450,modal:true});
	}
}

// Activate the RDS Calculator
function RedirectToRDS()
{
 var rdsUrl = '/RDS/HomePage.aspx';
 var RDS_Window = window.open(rdsUrl, 'RDS_Window','width=780,height=800,scrollbars=1,resizable=1,address=no');
 if (RDS_Window != null)
 {
  RDS_Window.focus();
 }
 else
 {
  window.location.href = rdsUrl;
 }
 return false;
}

// Enable search keywords
function search_redirect()
{
	var $array = new Array();
	//ADD NEW SEARCH TERMS AND DESTINATIONS HERE (case insensitive)
	$array['somefakesearch'] = '/Privacy_Notice.aspx';
	$array['!rmap'] = '/Russell_University/Practice_Management/Tools/Rmap.aspx';
	$array['@rmap'] = '/Russell_University/Practice_Management/Tools/Rmap.aspx';
	$array['#rmap'] = '/Russell_University/Practice_Management/Tools/Rmap.aspx';
	$array['*rmap'] = '/Russell_University/Practice_Management/Tools/Rmap.aspx';
	$array['?rmap'] = '/Russell_University/Practice_Management/Tools/Rmap.aspx';
	$array['gormap'] = '/Russell_University/Practice_Management/Tools/Rmap.aspx';
	$array['gotormap'] = '/Russell_University/Practice_Management/Tools/Rmap.aspx';
	$array['go2rmap'] = '/Russell_University/Practice_Management/Tools/Rmap.aspx';
	$array['=rmap'] = '/Russell_University/Practice_Management/Tools/Rmap.aspx';
	$array['equalrmap'] = '/Russell_University/Practice_Management/Tools/Rmap.aspx';
	$array['equalsrmap'] = '/Russell_University/Practice_Management/Tools/Rmap.aspx';
	$array['ageworkshops'] = '/Common/keywords/age_workshops.aspx';
	$array['fpa'] = '/Research_Commentary/Conferences/FPA_Retreat_2007.aspx';
	$array['globalinvesting'] = '/Research_Commentary/Capital_Markets_Insight/Global_Investing.aspx';
	$array['dain'] = '/Research_Commentary/Conferences/Dain_Conference_2007.aspx';

	//DO NOT EDIT BELOW THIS LINE
	var searchText = document.getElementById('SitePageTop1_NavbarSearch_txtSearchString').value;
	var $str = searchText.toLowerCase();
	$str = $str.replace(/\s/g,'');
	if( typeof($array[$str]) != 'undefined' )
	{
		window.location = $array[$str] + '?DCMP=ILC-KW-' + escape($str.replace(/[!,@,#,\*,\?,\=]/g,'')) + '&searchText=' + escape(searchText);
		return false;
	}
	else 
	{
		ShowAlert();
	}
}


//--------------------------------------------------------------------------------------------
// PopUp a USD Feedback Form Window 
//--------------------------------------------------------------------------------------------
// eBiz 11/30/2007

// Used only as wrapper to OpenSalesFeedbackWindow function, so that we can return null, which is required for the {href="javascript:SalesFeedback();"} link
function SalesFeedback()
{
	OpenSalesFeedbackWindow();
}
function OpenSalesFeedbackWindow()
{
	return OpenPopUp('/SA_View/ContactForm/Contact.aspx', 450, 450, 'SalesFeedbackWindow', 'menubar=0,resizable=1,toolbar=0,location=0,status=0,dependent=1');
}
function OpenHelpingAdvisorsWindow()
{
	return OpenPopUp('http://www.Russell.com/Helping-Advisors/', 1020, 650, 'helpingAdvisorsWindow', 'location=1,menubar=1,scrollbars=1,status=1,titlebar=1,toolbar=1,resizable=1,directories=1');
}

var LastOpenedWindow;
// Multi-purpose function to open popup windows. Can be used to simplify the many stand-alone functions currently implemented.
function OpenNewWindow(thisUrl, windowWidth, windowHeight, windowName, options)
{
  try
  {
      if (options == null) options = '';
      if (windowName == null) windowName = 'RussellLinkWindow';
    if(!/\.(html?|aspx?)(\?|$)/i.test(thisUrl))
    {
      // Omniture
      if (/function/i.test(typeof(customEventRecord)))
      {
        customEventRecord(windowName, 'd', thisUrl);
      }
      // Manticore
      if (typeof mtc4300s != 'undefined')
      {
        MTCml = "0";
        MTCrp = MTCpn;
        MTCpt = thisUrl.match(/[^/]+$/)[0];
        if (!/^(ht|f)tp/.test(thisUrl))
        {
          if (/^(\/)/.test(thisUrl))
          {
            thisUrl = location.protocol + '//' + location.host + thisUrl;
          }
          else
          {
            thisUrl = location.protocol + '//' + thisUrl;
          }
        }
        MTCpn = thisUrl;
        thisUrl = mtc4300s() + '&rd=1';   // Manticore non-page tracking requires request to their page and subsequent redirect to content asset
        //alert(MTCpt + '\n\n' + MTCpn + '\n\n' + thisUrl);
      }
    }

      var params = new Object();
    var opts = options.toLowerCase().split(',');
    for (var i in opts)
    {
      var pair = opts[i].split('=');
      params[pair[0]] = pair[1];
    }
    if ((windowWidth && !isNaN(windowWidth)) || (params['width'] && !isNaN(params['width'])))
    {
      var screenWidth = screen.availWidth;
      if (!windowWidth || isNaN(windowWidth)) windowWidth = params['width'];
      if (windowWidth > screenWidth) windowWidth = screenWidth;
      params['width'] = params['outerWidth'] = windowWidth;
      if (params['left'] == null) params['left'] = parseInt((screenWidth - windowWidth) / 2);
    }
    if ((windowHeight && !isNaN(windowHeight)) || (params['height'] && !isNaN(params['height'])))
    {
      var screenHeight = screen.availHeight;
      if (!windowHeight || isNaN(windowHeight)) windowHeight = params['height'];
      if (windowHeight > screenHeight) windowHeight = screenHeight;
      params['height'] = params['outerHeight'] = windowHeight;
      if (params['top'] == null) params['top'] = parseInt((screenHeight - windowHeight) / 3);
    }
    var allOptions = '';
    for (var key in params)
    {
      allOptions += key + '=' + params[key] + ',';
    }
    allOptions = allOptions.replace(/,$/, '');
    //alert('options:\n' + allOptions);
    LastOpenedWindow = window.open(thisUrl, windowName, allOptions);
    if (LastOpenedWindow) LastOpenedWindow.focus();
    return false;
  }
  catch (err)
  {
    return true;
  }
}
function OpenPopUp(thisUrl, windowWidth, windowHeight, windowName, options)
{
	return OpenNewWindow(thisUrl, windowWidth, windowHeight, windowName, options);
}
function OpenBarePopUp(thisUrl, windowWidth, windowHeight, windowName)
{
	return OpenPopUp(thisUrl, windowWidth, windowHeight, windowName, 'scrollbars=1,directories=0,menubar=0,status=0,toolbar=0,resizable=1');
}

// MultiView
function MultiView_Manager()
{
	this.Classname = 'multiView';
	this.Trigger_Classname_Suffix = '_trigger';
	this.SelectedView_Classname = 'selected';
	this.EnhancedView_Classname = 'enhancedView';
	this.SelectedView_HiddenClassname_Suffix = '_hidden';
	this.PutSelectedViewClassnameOnParent = false;
	this.AllowViewCollapse = false;
	this.ScopingElement = document;
	this.MultiViews = new Array();
	this.urlRegex = new RegExp('^' + document.location.toString().replace(document.location.hash, '').replace('?', '\\?') + '#(.+)');
	this.CssMedia = 'screen,projection,tv';
	return this;
}
MultiView_Manager.prototype.Initialize = function ()
{
	var divs = this.ScopingElement.getElementsByTagName('div');
	for (var i = divs.length-1; i >= 0; i--)
	{
		var thisDiv = divs[i];
		if (ContainsClass(thisDiv, this.Classname))
		{
			var newMV = new MultiView(this, thisDiv);
			if (newMV)
			{
				this.MultiViews.push(newMV);
			}
		}
	}
	for (var mvIndex = 0; mvIndex < this.MultiViews.length; mvIndex++)
	{
		var thisMV = this.MultiViews[mvIndex].Init();
	}
	var pageHash = document.location.hash;
	if (pageHash)
	{
		pageTarget = document.getElementById(pageHash.replace(/^#/, ''));
		if (pageTarget && pageTarget.multiViewTrigger)
		{
			pageTarget.multiViewTrigger.MultiView.SelectView.call(pageTarget.multiViewTrigger.Link);
			$(window).load(function(){window.scrollTo(0,0);});
		}
	}
	if (this.MultiViews.length > 0) this.RenderCSS();

isReady = true;

}
MultiView_Manager.prototype.RenderCSS = function ()
{
	var returnVal = false;
	var SS = null;
	var x = 0;
	var isFound = false;
	try
	{
		var cssNode = document.createElement('style');
		cssNode.id = 'MultiViewStylesheet';
		cssNode.type = 'text/css';
		cssNode.media = this.CssMedia;
		//cssNode.title = 'MultiView Stylesheet';   // Chrome won't work if you add a title!!!!
		document.getElementsByTagName("head")[0].appendChild(cssNode);
		var newSheet = document.styleSheets[document.styleSheets.length-1];
		for (var j = 0; j < this.MultiViews.length; j++)
		{
			var thisMV = this.MultiViews[j];
			//InsertCssRule(document.styleSheets[x], '#' + thisMV.ContainerElement.id + ' .' + thisMV.HiddenElementsClassname, 'display: none;');
			for (var k in thisMV.Views)
			{
				InsertCssRule(newSheet, '#' + k, 'display: none;');
				InsertCssRule(newSheet, 'body.' + k + ' #' + k, 'display: ' + thisMV.Views[k][0].Trigger.TargetDefaultDisplay + ';');
				InsertCssRule(newSheet, 'body.' + k + ' .' + k + thisMV.Manager.SelectedView_HiddenClassname_Suffix, 'display: none;');
			}
		}
		newSheet.disabled = false;
		returnVal = true;
	}
	catch(err)
	{
		returnVal = false;
	}
	return returnVal;
}
function InsertCssRule(objStylesheet, strSelector, strDeclarations)
{
	if (objStylesheet.insertRule)
	{
		objStylesheet.insertRule(strSelector + ' {' + strDeclarations + '}', objStylesheet.cssRules.length);
		returnVal = true;
	}
	else if (objStylesheet.addRule)
	{
		objStylesheet.addRule(strSelector, strDeclarations, objStylesheet.rules.length);
		returnVal = true;
	}
}
function MultiView(manager, containerElem)
{
	this.Manager = manager;
	this.ContainerElement = containerElem;
	if (!this.ContainerElement.id || this.ContainerElement.id == '')
	{
		alert('no id!');
		return;
	}
	this.TriggerClassname = this.ContainerElement.id + this.Manager.Trigger_Classname_Suffix;
	this.HiddenElementsClassname = this.ContainerElement.id + this.Manager.SelectedView_HiddenClassname_Suffix;
	this.Views = new Object();
	this.CurrentView = null;
	this.AvailableClasses = '';
	return this;
}
MultiView.prototype.Init = function()
{
	// Populate Views and AvailableClasses
	var tgtToView = null;
	var atags = document.getElementsByTagName('a');
	for (var i = 0; i < atags.length; i++)
	{
		var thisA = atags[i];
		if (thisA.href && ContainsClass(thisA, this.TriggerClassname))
		{
			var tgtId = thisA.attributes['href'].value;
			if (this.Manager.urlRegex.test(tgtId))
			{
				var matches = tgtId.match(this.Manager.urlRegex);
				if (matches && matches.length > 1)
				{
					tgtId = matches[1];
				}
			}
			tgtId = tgtId.replace(/^#/, '');
			var tgt = document.getElementById(tgtId);
			if (tgt)
			{
				var newTrigger = new MultiViewTrigger(this, thisA, tgt);
				if (!this.Views[tgtId])
				{
					this.Views[tgtId] = [tgt, new Array()];
				}
				this.Views[tgtId][1].push(newTrigger);
				this.AvailableClasses += tgtId + '|';
				if (ContainsClass(newTrigger.ClassTarget, this.Manager.SelectedView_Classname))
				{
					tgtToView = tgt;
					RemoveClass(newTrigger.ClassTarget, this.Manager.SelectedView_Classname)
				}
			}
		}
	}
	this.AvailableClasses = this.AvailableClasses.replace(/\|$/, '');
	AddClass(this.ContainerElement, this.Manager.EnhancedView_Classname);
	if (tgtToView)
	{
		// Safari/Chrome lose reference to link here
		this.SelectView.call(tgtToView.Trigger.Link);
	}
}
MultiView.prototype.SelectView = function(e)
{
	var returnValue = false;
	try
	{
		var self = this;
		if (!self.Trigger && window.event && window.event.srcElement) self = window.event.srcElement;
		if ('a' != self.nodeName.toLowerCase()) self = GetAncestorElement(self, 'a');
		if (self == null) return returnValue;
		var thisMV = self.Trigger.MultiView;
		if (thisMV.CurrentView)
		{
			var triggerArr = thisMV.Views[thisMV.CurrentView.Trigger.Target.id][1];
			for (var i = 0; i < triggerArr.length; i++)
			{
				RemoveClass(triggerArr[i].ClassTarget, thisMV.Manager.SelectedView_Classname);
			}
			RemoveClass(document.body, thisMV.CurrentView.id);
		}
		if (thisMV.Manager.AllowViewCollapse && thisMV.CurrentView === self.Trigger.Target)
		{
			thisMV.CurrentView = null;
		}
		else
		{
			thisMV.CurrentView = self.Trigger.Target;
			var triggerArr2 = thisMV.Views[self.Trigger.Target.id][1];
			for (var j = 0; j < triggerArr2.length; j++)
			{
				AddClass(triggerArr2[j].ClassTarget, thisMV.Manager.SelectedView_Classname);
			}
			AddClass(document.body, thisMV.CurrentView.id);
			// Bubble up
			var parent = thisMV.CurrentView.parentNode;
			while (parent.nodeName.toLowerCase() != 'body' && !parent.multiViewTrigger)
			{
				parent = parent.parentNode;
			}
			if (parent.nodeName.toLowerCase() != 'body')
			{
//if (isReady) alert('Current:\n' + self.innerHTML + '\n' + thisMV.ContainerElement.id + '\n\nParent:\n' + parent.multiViewTrigger.Link.innerHTML + '\n' + parent.multiViewTrigger.MultiView.ContainerElement.id + '\n\n' + parent.nodeName.toLowerCase() + (parent.id ? '#' + parent.id : '') + (parent.className ? '.' + parent.className : ''));
				if (document.body.click)
				{
					parent.multiViewTrigger.Link.click();
				}
				else
				{
					parent.multiViewTrigger.MultiView.SelectView.call(parent.multiViewTrigger.Link);
				}
			}
		}
		returnValue = true;
	}
	catch (err)
	{
		alert('Error detected in MultiView code:\n\n' + err.name + ':\n' + err.message);
		returnValue = false;
	}
	finally
	{
		if (returnValue)
		{
			if (window.event)
			{
				window.event.returnValue = !returnValue;
			}
			else if (e)
			{
				e.preventDefault();
			}
		}
		return returnValue;
	}
}
function MultiViewTrigger(parentMultiView, aTag, targetElem)
{
	this.MultiView = parentMultiView;
	this.Link = aTag;
	this.Target = targetElem;
	this.Link.Trigger = this.Target.Trigger = this;
	targetElem.multiViewTrigger = this;
	AddEvent(this.Link, 'click', this.MultiView.SelectView);
	this.TargetID = this.Target.id;
	this.TargetDefaultDisplay = GetCSSValue(targetElem, 'display');
	if (this.TargetDefaultDisplay == 'none') this.TargetDefaultDisplay = GetAnticipatedBlockLevel(targetElem.nodeName);
	this.ClassTarget = this.MultiView.Manager.PutSelectedViewClassnameOnParent ? this.Link.parentNode : this.Link;
	return this;
}
function GetAnticipatedBlockLevel(nodeType)
{
	var blockLevel = null;
	if (/^(div|table|ul|li|fieldset|h[1-6])$/i.test(nodeType)) blockLevel = 'block';
	else if (/^(span|a)$/i.test(nodeType)) blockLevel = 'inline';
	return blockLevel;
}

var MVM = new MultiView_Manager();
MVM.PutSelectedViewClassnameOnParent = true;
function SetUpMultiViews()
{
	MVM.Initialize();
}

function SetUpExpanderViews()
{
	var needsCss = false;
	$('div.expanderView a').each(function() {
		var tgt = $(this);
		if (/^#/.test(tgt.attr('href')))
		{
			needsCss = true;
			var tgtEl = $(tgt.attr('href')).addClass('closed');
			tgt.parent().after(tgtEl);
			tgt.click(function(event){tgtEl.toggleClass('closed');event.preventDefault();});
		}
	});
	if (needsCss)
	{
		var cssNode = document.createElement('style');
		cssNode.id = 'ExpanderViewStylesheet';
		cssNode.type = 'text/css';
		cssNode.media = 'screen,projection,tv,handheld';
		document.getElementsByTagName("head")[0].appendChild(cssNode);
		var newSheet = document.styleSheets[document.styleSheets.length-1];
		InsertCssRule(newSheet, '.closed', 'display:none;');
		InsertCssRule(newSheet, '.expanderView_hidden', 'display:none;');
	}
}

var _kiq = _kiq || [];
document.write('<scr'+'ipt type="text/javascript" src="//s3.amazonaws.com/ki.js/16668/396.js" async="true"></scr'+'ipt>');

    var id = GetCookie("SegmentationFilter");
    var KissID = "No user information available";
    if (id) {
        KissID = id.split('|')[0];
    }
    _kiq.push(['identify', KissID]);

var isReady = false;
