/*******************************************************************************/
/* This file contains custom functions used by all pages on the site:
/* 
/*	Master page functions
/*  Popup handler
/*  Name Active X Control suppression
/*  
/*******************************************************************************/

/*************************BEGIN MASTER PAGE FUNCTIONS***************************/

$(document).ready(function() 
{
	//Do Not Call on HomePage
	var ua = navigator.userAgent.toLowerCase();
	if($('#leftpromo').length==0) {
		fnCheckEmptyContents(ua);
	}
      
      //For All Pages
	fnCheckContent(ua);

	preloadImages("/NMFNIMAGES/FinancialGuidanceOrange33.gif",
	  			"/NMFNIMAGES/ProductsServicesOrange33.gif",
	  			"/NMFNIMAGES/CareerOrange33.gif",
	  			"/NMFNIMAGES/AboutOrange33.gif");

	//the following command fixes flickering background images in IE6
	try {
	     document.execCommand('BackgroundImageCache',false,true);
	} catch (err) {
	     //do nothing
	}
	
	//load IE6 print stylesheet if browser is IE6
	if ($.browser.msie && $.browser.version == 6){
		$("link[media=print]").replaceWith('<link href="/Style Library/IE6print.css" rel="stylesheet" type="text/css" media="print" />');
	}
	
	/*
	* In Safari and IE8 the original shadow set in the CSS was getting clipped off.  That shadow was
	* set on the div with the ID "zz2_UtilityNavn2Items".  Solution is to move the shadow to the table
	* which is a direct child of the div, and then reposition the div and make it transparent.
	*/
	//fix Learning Center shadow on Safari
	if ($.browser.safari) {
	     $("#zz2_UtilityNavn2Items > table").addClass("webkitLearningCenterShadow");//apply the shadow to the table
	     $lrnCtrDiv =  $("#zz2_UtilityNavn2Items");
	     $lrnCtrDiv.css("background-color", "transparent");
	     $lrnCtrDiv.removeClass("utility_over");//remove existing CSS class used for positioning and IE/Firefox shadows
          $lrnCtrDiv.addClass("webkitLearningCenterLocation");//add modified CSS class to reposition element based on the shadow being on the inner table
	}

	//fix learning center shadow in IE8
	if ($.browser.msie && $.browser.version == 8){
	     $("#zz2_UtilityNavn2Items > table").addClass("IE8LearningCenterShadow");//apply the shadow to the table
	     $lrnCtrDiv =  $("#zz2_UtilityNavn2Items");
	     $lrnCtrDiv.css("background-color", "transparent");
	     $lrnCtrDiv.removeClass("utility_over");//remove existing CSS class used for positioning and IE/Firefox shadows
          $lrnCtrDiv.addClass("IE8LearningCenterLocation");//add modified CSS class to reposition element based on the shadow being on the inner table
	}
	
	bindContentEvents();
	
	/*   Add a javascript callback function to execute after all asynchronous events.
	*	http://www.asp.net/Ajax/Documentation/Live/ClientReference/Sys.WebForms/PageRequestManagerClass/PageRequestManagerEndRequestEvent.aspx
	*/
	Sys.WebForms.PageRequestManager.getInstance().add_endRequest(bindContentEvents);
	
});

function bindContentEvents(sender, args) {
	/*
	*    This function binds events to DOM objects.
	*    It is called initially on page load, and again after each asynchronous request (AJAX) to re-bind the potentially new content.
	*	args contains useful information like error message in async response, see http://www.asp.net/Ajax/Documentation/Live/ClientReference/Sys.WebForms/EndRequestEventArgsClass/
	*/
	
	//bind anchors that open popups
	handle_popups();
	
	//show the edit panel if page is in edit mode
	var $editPanel = $('.EditPanel');
	if (/\S/.test($editPanel.html()) == true) {//EditPanel has non-whitespace content, page is currently being edited
		$editPanel.show();
	} else { //page is not currently being edited
		/*
		* simulate :hover pseudoclass on <span> in IE6
		* This fix cannot be applied while editing the page, as the Sharepoint Rich Text Editor
		* will persist the "text-decoration: none" that is applied to elements that are hovered
		* while authoring.
		*/
		if ($.browser.msie && $.browser.version == 6){
			$(".ms-rteCustom-BodyLinks, .ms-rteCustom-BodyLinksWithArrow, .ms-rteCustom-BodyHeaderLink, .ms-rteCustom-ExpandedPromoRollOverLink, .genericHoverUnderline").hover(
			function(){//over
				$(this).css("text-decoration","underline");
			},function(){//out
				$(this).css("text-decoration","none");
			});
		}
	}
	
}

//Function to preload images.  Takes n number of image arguments
var nmImages = new Array();
function preloadImages(){
	for (x=0; x< preloadImages.arguments.length; x++){
	nmImages[x] = new Image();
	nmImages[x].src = preloadImages.arguments[x];
	}
}

//Function To check Empty Content in Summary Links and Page Content Fields

function fnCheckEmptyContents(ua)
{
		$('.body_content')[0].style.backgroundColor = '#ffffff';       

		//Remove Promo Box if no content is present
        if(document.getElementById('AppNow')!=undefined)
        {
            var promoContent;
        	//For IE
 	       	if(ua.indexOf('msie')!=-1)
 	       	{	
            	 promoContent= document.getElementById('AppNow').innerText;
                 	
            }            
            else
            {	
            	promoContent = document.getElementById('AppNow').textContent.trim();
            }
	            
	        if((promoContent =='') || (promoContent==' ') || (promoContent =='&nbsp;')||(promoContent =='<DIV id=ctl00_PlaceHolderMain_ctl01__ControlWrapper_RichHtmlField style="DISPLAY: inline"></DIV>'))
	        {
	            document.getElementById('AppNow').style.display='none';
	        }
          
        }
        
        //Remove Optional Promo Box if no content is present
        if(document.getElementById('OptionalPromoBox')!=undefined)
        {
        	if(ua.indexOf('msie')!=-1)
 	       	{
            	var OPpromoContent= document.getElementById('OptionalPromoBox').innerText;
            }
            
            else
            {
            	var OPpromoContent= document.getElementById('OptionalPromoBox').textContent.trim();
            }
	            
	        if((OPpromoContent=='') || (OPpromoContent==' ') || (OPpromoContent=='&nbsp;'))
	        {
	            document.getElementById('OptionalPromoBox').style.display='none';
	        }
        }
        
               
	 //Removes Page Content Div if no content is present	 
	 if($('.CTPDesc').length!=0)
	 {
		 //Removes Page Content Div if no content is present
		 if(ua.indexOf('msie')!=-1)
		 {
		 	
		 	var pageContent = $('.CTPDesc')[0].innerText;
		 }
		 else
		 {
		 	var pageContent = $('.CTPDesc')[0].textContent;
		 }
		 
		if(pageContent!=undefined)
	        {
				pageContent =pageContent.trim();
	            if((pageContent =='') || (pageContent ==' ') ||(pageContent =='<span></span>&nbsp;'))
	            {
	                $('.CTPDesc').hide();
	            }
			 }
	}
	
	//Apply Border to Content which is more in height
	if($('.COLeftCont').length!=0)
	{
		//If Left Content is more
		if($('.COLeftCont')[0].clientHeight >= $('.COContRight')[0].clientHeight)
		{
			$('.COLeftCont')[0].style.borderRight = '1px gray dotted';
		}
		
		else
		{
			$('.COLeftCont')[0].style.borderRight = 'none';
			$('.COBotCont1')[0].style.marginRight = '0px';
			$('.COBotCont1')[0].style.paddingRight = '0px';
			$('.COContRight')[0].style.paddingLeft = '20px';
			$('.COGroup_Header2')[0].style.marginLeft = '10px';
			$('.COContRight')[0].style.borderLeft = '1px gray dotted';

		}
			
	}




	
}
//Function to check if Page Disclosure is empty and remove unwanted space taken by site actions in IE
function fnCheckContent(ua)
{
	//Change Learning Center Color to Black, url none and hover decoration to none
	 $('.zz2_UtilityNav_1')[3].style.color = 'black';
	 $('.zz2_UtilityNav_1')[3].href = '#';
	 $('.zz2_UtilityNav_1, .utility_text, .zz2_UtilityNav_6, .zz2_UtilityNav_14, utility_links_hover')[4].style.textDecoration = 'none';
 	 $('.zz2_UtilityNav_1, .utility_text, .zz2_UtilityNav_6, .zz2_UtilityNav_14, utility_links_hover')[4].style.cursor = 'default';

    //Removes the Page Disclosure Div if no Page Disclosure is added
	 if(document.getElementById('NMPageDisclosure')!=undefined)
        {
        	if(ua.indexOf('msie')!=-1)
			{
	            var PDis = document.getElementById('NMPageDisclosure').innerText;
	            PDis =PDis.trim();
            }
            
            else
            {
            	var PDis = document.getElementById('NMPageDisclosure').textContent;
	            PDis =PDis.trim();
            }
            
            if(PDis != '')
            {
                document.getElementById('NMPageDisclosure').style.display='block';
            }
            
        }
        
		//Remove unwanted space for site actions for anonymous users
		var $siteac = $('.siteactioncont');
		//siteactioncont contains non-whitespace text
		if(/\S/.test($siteac.html()) == true) 
		{
			$siteac.show();
			
			/*
			*	re-position the learnmore link on the homepage
			*    do not reposition if page is being edited
			*/
			var $editPanel = $('.EditPanel');
			if (/\S/.test($editPanel.html()) == false) {//EditPanel is empty, page is not currently being edited
				var $learnMoreDiv = $("#LearnMore");
				if ($learnMoreDiv.length > 0) {//div with id=LearnMore exists on page
				     var curTop = parseInt($learnMoreDiv.css("top"));
				     var siteActionHeight = $siteac.height();
				     var pageEditToolbarHeight = 0;
				     $pageEditToolbar = $("#ctl00_ctl07_toggleContainerColorBar");
				     if ($pageEditToolbar.length > 0) {//length is the number of DOM elements affected by this jQuery object
				          pageEditToolbarHeight = $pageEditToolbar.height();
				     }
					var newTop = curTop - siteActionHeight - pageEditToolbarHeight;
				     $learnMoreDiv.css("top", newTop);
				}
			}
		}  
}

function OpenInNewWindow(url, name)
{
	name = window.open(url, name, "height=540,width=785,status=yes,toolbar=yes,menubar=yes,location=yes,scrollbars=yes,resizable=yes");
}

function fnNMCheckRelatedLinks()
{//called via inline javascript
	if($('.FSPTopContent').length!=0)
	 {
		 //Removes Page Content Div if no content is present
		 if($.browser.msie)
		 {
		 	
		 	var pageContent = $('.FSPTopContent')[0].innerText;
		 }
		 else
		 {
		 	var pageContent = $('.FSPTopContent')[0].textContent;
		 }
		 
		if(pageContent!=undefined)
	        {
				pageContent =pageContent.trim();
	            if((pageContent !='') && (pageContent !=' ') &&(pageContent !='<span></span>&nbsp;'))
	            {
	                $('.FSPTopContent').show();
	            }
			 }
	}
	
	if(document.getElementById('TabZone1') != null) {
		fnCheckTabs();
	}
    fncheckBannerImage();

	if($('.CTGroup_Header')[0])
	{
		if(navigator.userAgent.toLowerCase().indexOf('msie') != -1)
		{
	        var bHeader = $('.CTGroup_Header')[0].innerText.trim();	    
	    }            
	    else
	    {
	        var bHeader = $('.CTGroup_Header')[0].textContent.trim();
		}
		if((bHeader !='') && (bHeader !='&nbsp;'))
        {
            $('.CTGroup_Header')[0].style.display='block';
        }
    }
    
     //Remove Promo Box if no content is present
    if(document.getElementById('AppNow')!=undefined)
    {
        var promoContent;
    	//For IE
       	if(navigator.userAgent.toLowerCase().indexOf('msie') != -1) 	       	
       	{	
        	 promoContent= document.getElementById('AppNow').innerText;
             	
        }            
        else
        {	
        	promoContent = document.getElementById('AppNow').textContent.trim();
        }
            
        if((promoContent !='') && (promoContent!=' ') && (promoContent !='&nbsp;')&&(promoContent !='<DIV id=ctl00_PlaceHolderMain_ctl01__ControlWrapper_RichHtmlField style="DISPLAY: inline"></DIV>'))
        {
            document.getElementById('AppNow').style.display='block';
        }
      
    }
    
     if((document.getElementById('divSummaryLinks')!=undefined) 
    || (document.getElementById('SummCont')!=undefined))
    {
    	document.getElementById('NMPageDisclosure').style.width = '675px';		
    }

    
	if(document.getElementById('divSummaryLinks')!=undefined)
    {	
    	if(navigator.userAgent.toLowerCase().indexOf('msie'))
		{
            var Summ = document.getElementById('SummCont').innerText;
        }            
        else
        {
            var Summ = document.getElementById('SummCont').textContent.trim();
		}
        if((Summ !='') && (Summ !=' ') && (Summ !='&nbsp;')&&(Summ !='<DIV id=ctl00_PlaceHolderMain_ctl01__ControlWrapper_RichHtmlField style="DISPLAY: inline"></DIV>'))
        {
            document.getElementById('divSummaryLinks').style.display='block';
        }
    } 

    
	//Properly places the image for the Summary Links in case of image on left
	for ( var count = 0; count < $('.image-area-left').length; ++count)
    {
    	var imageDv  = $('.image-area-left')[count];
    	 if ( imageDv.nextSibling != undefined )
    	 {
		 	 if (imageDv.nextSibling.firstChild != undefined )
    	 		if (imageDv.nextSibling.firstChild.offsetHeight != undefined )
    	 		{ 
    				var height =imageDv.nextSibling.firstChild.offsetHeight + 5;
    				imageDv.style.height = height  + "px";  
    			}
         }       	
    }
    if(document.getElementById('Summ')!=undefined)
    {
        var Summ = document.getElementById('Summ').innerHTML;
        Summ=Summ.trim();
        if( (Summ =='') || (Summ =='&nbsp;') )
        {
            document.getElementById('Summ').style.display='none';
            if(document.getElementById('SummLink2')!=undefined)
            document.getElementById('SummLink2').style.display='none';
        }        
    }   
    if(document.getElementById('Summ1')!=undefined)
    {
        var Summ = document.getElementById('Summ1').innerHTML;
        Summ=Summ.trim();
        if((Summ =='') || (Summ =='&nbsp;') )
        {
            document.getElementById('Summ1').style.display='none';
            if(document.getElementById('SummLink1')!=undefined)
            document.getElementById('SummLink1').style.display='none';
        }        
    }
    var ua = navigator.userAgent.toLowerCase();
    if(document.getElementById('SummCont')!=undefined)
    {	
    	if(ua.indexOf('msie')!=-1)
		{
            var Summ = document.getElementById('SummCont').innerText;
            Summ=Summ.trim();
        }            
        else
        {
            var Summ = document.getElementById('SummCont').textContent;
			Summ=Summ.trim();
			if ( Summ != '')
			{
				var elm = document.getElementById('SummCont');			
			    if ( elm.getElementsByClassName("slm-layout-main").length <= 1 )
					Summ = '';

			}
        }
        if(Summ =='' || Summ== ' ')
        {
            document.getElementById('SummCont').style.display='none';
            if(document.getElementById('Summ')!=undefined)
            {
               document.getElementById('Summ').style.display='none';
            }  
        }
    }        
    if(document.getElementById('SummCont1')!=undefined)
    {
    	if(ua.indexOf('msie')!=-1)
		{
            var Summ = document.getElementById('SummCont1').innerText;
            Summ=Summ.trim();
        }
        else
        {
        	var Summ = document.getElementById('SummCont1').textContent;
        	Summ=Summ.trim();
			if ( Summ != '')
			{
				var elm = document.getElementById('SummCont1');			
				if ( elm.getElementsByClassName("slm-layout-main").length <= 1 )
					Summ = '';
			}


        }
        if(Summ =='' || Summ==' ')
        {
            document.getElementById('SummCont1' ).style.display='none';
            if(document.getElementById('Summ1')!=undefined)
            {
               document.getElementById('Summ1').style.display='none';
            }
        }
    }    
}

function fncheckBannerImage()
{
	//Removes the div if no Banner Image is added and adds some gap below body header
	if(document.getElementById('ctl00_PlaceHolderMain_ctl01__ControlWrapper_RichImageField')!=undefined)
    {
    	 if($.browser.msie && $.browser.version == 7)
    	 {
    		if($('.NMCTPImg').length!=0)
    		{
    			$('.NMCTPImg')[0].style.paddingBottom='15px';
    		}
    	 }
    	 var BImage = document.getElementById('ctl00_PlaceHolderMain_ctl01__ControlWrapper_RichImageField').innerHTML;
		BImage =BImage.trim().toLowerCase();
        if( (BImage !='') && (BImage !='<span></span>&nbsp;')&& (BImage!='<span dir=""></span>&nbsp;') )
        {        	        	
            document.getElementById('BannerImage').style.display='block';
            if ( $('.STPBImage').length > 0)
                $('.STPBImage')[0].style.marginBottom='0px';
        }
    }
    if(document.getElementById('ctl00_PlaceHolderMain_RichImageField1__ControlWrapper_RichImageField')!=undefined)
    {
    	 if($.browser.msie && $.browser.version == 7)
    	 {
    		if($('.NMCTPImg').length!=0)
    		{
    			$('.NMCTPImg')[0].style.paddingBottom='15px';
    		}
    	 }
    	 var BImage = document.getElementById('ctl00_PlaceHolderMain_RichImageField1__ControlWrapper_RichImageField').innerHTML;
		BImage =BImage.trim().toLowerCase();
        if( (BImage !='') && (BImage !='<span></span>&nbsp;')&& (BImage!='<span dir=""></span>&nbsp;') )
        {
        	if($('.NMCTPImg')[0])
        	{
    			$('.NMCTPImg')[0].style.display = 'block';
    		}
    		else
    		{
        		document.getElementById('BannerImage').style.display='block';
			}
            if ( $('.STPBImage').length > 0)
                $('.STPBImage')[0].style.marginBottom='0px';
        }
    }
}

function fnCheckTabs()
{
	if(document.getElementById('divCTPPBOT') == null) 
	{
		var i;
	
		for(i=1;i<=6;i++) 
		{
			var contents = $('#Tab'+i+'Text').html();
            contents = contents.replace("&nbsp;", " ");

            if (/[\S]+/.test(contents) == true)
			{
				document.getElementById('Tab'+i+'Sel').style.backgroundColor='#F0F0F0';
				document.getElementById('Tab'+i+'LeftCorner').style.backgroundColor='#F0F0F0';
				document.getElementById('Tab'+i).style.backgroundColor='#F0F0F0';
				document.getElementById('Tab'+i+'RightCorner').style.backgroundColor='#F0F0F0';
				document.getElementById('Tab'+i+'Text').style.color='#336699';
			} 
			else 
			{
				document.getElementById('TabZone' + i ).style.display='none';
			}
		}
		
		var LocId;
		var tabParam_pattern = /tab=([^&#]+)/;
		var queryString = document.location.search;
		var tabHash_pattern = /#([^&#?]+)/;
		var hashString = document.location.hash;
		var tab_parts = [];
		if (tabHash_pattern.test(hashString) == true) {//look for #whatever in hash
			tab_parts = tabHash_pattern.exec(hashString);
			LocId = tab_parts[1].replace(/-/g,' ');//convert hyphens to spaces
			LocId = LocId.replace(/\%20/g,' ');//convert %20 to spaces
		} else if (tabParam_pattern.test(queryString) == true) {//look for tab=whatever in query string
			tab_parts = tabParam_pattern.exec(queryString);
			LocId = tab_parts[1].replace(/-/g,' ');//convert hyphens to spaces
			LocId = LocId.replace(/\%20/g,' ');//convert %20 to spaces
		}
		

		if(LocId!=null)
		{ 

		    var i=1;
		    for(i=1;i<7;i++)
		    {
		        var Id=document.getElementById('Tab'+i+'Text').innerHTML.split('&nbsp;')[0];
		        var mId;
		        if(Id.split('\n')[1]!=undefined)
		        {
		            mId=Id.split('\n')[1].split('&nbsp;')[0].substring(8);
		            mId=mId.replace(/(^\s*|\s*$)/,"");
		        }
		        
		        if(Id==LocId||mId==LocId)
		        {//selected tab
		          if (typeof(runSiteCatalystTabLoad) == 'function') {//detect proper load of external SiteCatalyst files
					runSiteCatalystTabLoad(i);
				}
				
				document.getElementById('Tab'+i+'ContentZone').style.display='block';

				document.getElementById('Tab'+i+'RightCorner').removeAttribute('class');
				document.getElementById('Tab'+i+'RightCorner').setAttribute('className','right_corner');
				document.getElementById('Tab'+i+'RightCorner').setAttribute('class','right_corner');

				document.getElementById('Tab'+i+'Text').style.color='#FFFFFF';
				document.getElementById('Tab'+i+'Text').removeAttribute('class');
				document.getElementById('Tab'+i+'Text').setAttribute('className','tabtext_style');
				document.getElementById('Tab'+i+'Text').setAttribute('class','tabtext_style');

				document.getElementById('Tab'+i).removeAttribute('class');
				document.getElementById('Tab'+i).setAttribute('className','tab_text');
				document.getElementById('Tab'+i).setAttribute('class','tab_text');

				document.getElementById('Tab'+i+'LeftCorner').removeAttribute('class');
				document.getElementById('Tab'+i+'LeftCorner').setAttribute('className','left_corner');
				document.getElementById('Tab'+i+'LeftCorner').setAttribute('class','left_corner');

				document.getElementById('Tab'+i+'Sel').removeAttribute('class');
				document.getElementById('Tab'+i+'Sel').setAttribute('className','tabs_control');
				document.getElementById('Tab'+i+'Sel').setAttribute('class','tabs_control');
	            }
	            else
	            {//non-selected tab
	            		document.getElementById('Tab'+i+'ContentZone').style.display='none';
			            
			            document.getElementById('Tab'+i+'RightCorner').removeAttribute('class');
			            document.getElementById('Tab'+i+'RightCorner').setAttribute('className','noright_corner');
			            document.getElementById('Tab'+i+'RightCorner').setAttribute('class','noright_corner');
			            
			            document.getElementById('Tab'+i+'Text').removeAttribute('class');
			            document.getElementById('Tab'+i+'Text').setAttribute('className','non_selectedtab_text');
			            document.getElementById('Tab'+i+'Text').setAttribute('class','non_selectedtab_text');
			            
			            document.getElementById('Tab'+i).removeAttribute('class');
			            document.getElementById('Tab'+i).setAttribute('className','non_selectedtab');
			            document.getElementById('Tab'+i).setAttribute('class','non_selectedtab');
			            
			            document.getElementById('Tab'+i+'LeftCorner').removeAttribute('class');
			            document.getElementById('Tab'+i+'LeftCorner').setAttribute('className','noleft_corner');
			            document.getElementById('Tab'+i+'LeftCorner').setAttribute('class','noleft_corner');
			            
			            document.getElementById('Tab'+i+'Sel').removeAttribute('class');
			            document.getElementById('Tab'+i+'Sel').setAttribute('className','non_selected');
			            document.getElementById('Tab'+i+'Sel').setAttribute('class','non_selected');
	            }
	        
	        }
	        
		}
		else
		{//tab param missing, select first tab by default
			if (typeof(runSiteCatalystTabLoad) == 'function') {//detect proper load of external SiteCatalyst files
				runSiteCatalystTabLoad(1);
			}
			document.getElementById('Tab2ContentZone').style.display='none';
			document.getElementById('Tab3ContentZone').style.display='none';
			document.getElementById('Tab4ContentZone').style.display='none';
			document.getElementById('Tab5ContentZone').style.display='none';
			document.getElementById('Tab6ContentZone').style.display='none'; 
	        if(document.getElementById('Tab1Text').innerHTML!="&nbsp;"||document.getElementById('Tab1Text').innerHTML!="\n								&nbsp;")
	        {
	            document.getElementById('Tab1ContentZone').style.display='block';
    	        
	            document.getElementById('Tab1RightCorner').removeAttribute('class');
	            document.getElementById('Tab1RightCorner').setAttribute('className','right_corner');
	            document.getElementById('Tab1RightCorner').setAttribute('class','right_corner');
	            
	            document.getElementById('Tab1Text').style.color = '#FFFFFF';
	            document.getElementById('Tab1Text').removeAttribute('class');
	            document.getElementById('Tab1Text').setAttribute('className','tabtext_style');
	            document.getElementById('Tab1Text').setAttribute('class','tabtext_style');
	            
	            document.getElementById('Tab1').removeAttribute('class');
	            document.getElementById('Tab1').setAttribute('className','tab_text');
	            document.getElementById('Tab1').setAttribute('class','tab_text');
	            
	            document.getElementById('Tab1LeftCorner').removeAttribute('class');
	            document.getElementById('Tab1LeftCorner').setAttribute('className','left_corner');
	            document.getElementById('Tab1LeftCorner').setAttribute('class','left_corner');
	            
	            document.getElementById('Tab1Sel').removeAttribute('class');
	            document.getElementById('Tab1Sel').setAttribute('className','tabs_control');
	            document.getElementById('Tab1Sel').setAttribute('class','tabs_control');
    		    
	          
	        }
		}
		
		//vertically center tab text in IE browsers.  Other browers respect the display: table-cell, which allows for vertical-align in CSS

		if ($.browser.msie) {
			$('.tabtext_style, .non_selectedtab_text').each(function(){
				var textHeight = $(this).height();
				var containerHeight = $(this).parent().height();
				var topMargin = (containerHeight - textHeight) / 2;
				$(this).css("margin-top", topMargin + "px");
			});
  		}

		
	}
}


function fnServiceTopicChangeDropDownSelect(ddlAccountTypeId, ddlHowToId)
{
	var ddlAccountType = document.getElementById(ddlAccountTypeId);
    var ddlHowTo = document.getElementById(ddlHowToId);
    ddlAccountType.value = "Life Insurance";
	ddlHowTo.selectedIndex = 0;
}

/************************* END MASTER PAGE FUNCTIONS ***************************/

/*************************BEGIN POPUP FUNCTIONS*********************************/
/*	Open links in new window based on parameters in the href.
*	This keeps the links clean from javascript, as this script overrides the onClick event if one of following parameters is found.
*    The window will be opened with a clean URL that has been stripped of these parameters
*
*    Parameters
*    win_type       optional: string representing a group of settings
*    win_width      optional: number representing window width in pixels
*    win_height     optional: number representing window height in pixels
*    win_top        optional: number representing window top position in pixels
*    win_left       optional: number representing window left position in pixels
*/

function handle_popups() {
	$("a[target='_blank']").each(function(){
		var screenWidth = screen.width;
		var screenHeight = screen.height;
		var top = 0;
		var left = 0;
		var width = 0;
		var height = 0;
		var locat = 1;
		var menubar = 1;
		var resizable = 1;
		var scrollbars = 1;
		var status = 1;
		var titlebar = 1;
		var toolbar = 1;
		
		var $a = $(this);
		var href = $a.attr("href");
		var cleaned_href = href;//will contain href minus the extra parameters required by this script
		var overrideDefaultAction = false;
		
		//check if URL explicitly sets type via win_type
		var win_type_pattern = /win_type=([a-zA-Z0-9_-]+)/;
		var type_parts = win_type_pattern.exec(href);
		if (type_parts != null && typeof type_parts[1] != "undefined") {
			overrideDefaultAction = true;
			var popup_type = type_parts[1];
			switch(popup_type.toLowerCase()) {
				case "formcalc":
					locat = 0;
					toolbar = 0;
					width = 600;
					height = 425;
					left = screenWidth - 615;
					break;
				case "formcalclarge":
					locat = 0;
					toolbar = 0;
					width = 720;
					height = 640;
					left = screenWidth - 735;
					break;
				case "formcalcxlarge":
					locat = 0;
					toolbar = 0;
					width = 820;
					height = 640;
					left = screenWidth - 840;
					break;
				case "dailyunitvalues":
					width = 600;
					height = 450;
					left = 150;
					break;
				case "recruiting":
					locat = 0;
					menubar = 0;
					width = 620;
					height = 550;
					left = screenWidth - 635;
					break;
				case "pdfform":
					locat = 0;
					toolbar = 0;
					width = 600;
					height = 425;
					left = 100;
					top = 100;
					break;
				default:
					//a commonly used width and height
					width = 775;
					height = 600;
			}
			cleaned_href = remove_param(cleaned_href, "win_type="+popup_type);
		}

		//check if HREF explicitly sets width via win_width
		var win_width_pattern = /win_width=([0-9]+)/;
		var width_parts = win_width_pattern.exec(href);
		if (width_parts != null && typeof width_parts[1] != "undefined") {
			overrideDefaultAction = true;
			width = width_parts[1];
			cleaned_href = remove_param(cleaned_href, "win_width="+width);
		}

		//check if HREF explicitly sets height via win_height
		var win_height_pattern = /win_height=([0-9]+)/;
		var height_parts = win_height_pattern.exec(href);
		if (height_parts != null && typeof height_parts[1] != "undefined") {
			overrideDefaultAction = true;
			height = height_parts[1];
			cleaned_href = remove_param(cleaned_href, "win_height="+height);
		}

		//check if HREF explicitly sets top via win_top
		var win_top_pattern = /win_top=([0-9]+)/;
		var top_parts = win_top_pattern.exec(href);
		if (top_parts != null && typeof top_parts[1] != "undefined") {
			overrideDefaultAction = true;
			top = top_parts[1];
			cleaned_href = remove_param(cleaned_href, "win_top="+top);
		}

		//check if HREF explicitly sets left via win_left
		var win_left_pattern = /win_left=([0-9]+)/;
		var left_parts = win_left_pattern.exec(href);
		if (left_parts != null && typeof left_parts[1] != "undefined") {
			overrideDefaultAction = true;
			left = left_parts[1];
			cleaned_href = remove_param(cleaned_href, "win_left="+left);
		}

		if (overrideDefaultAction) {
			$a.click(function(){
				var specs = "'" +
					"location=" + locat +
					",menubar=" + menubar +
					",resizable=" + resizable +
					",scrollbars=" + scrollbars +
					",status=" + status +
					",titlebar=" + titlebar +
					",toolbar=" + toolbar +
					",top=" + top +
					",left=" + left +
					",width=" + width +
					",height=" + height +
					"'";
				window.open(cleaned_href, "_blank", specs);
				return false; //stop default action
			});
		}
		
	});
}

function remove_param(url, param) {
	var i1 = url.indexOf(param) - 1; //minus 1 to get the preceeding ? or & char
	var i2 = i1 + param.length + 1; //plus 1 to include final char
	var cleaned_url = url.substring(0,i1) + url.substring(i2, url.length);
	return cleaned_url;
}

/************************* END POPUP FUNCTIONS *********************************/


/************************* BEGIN FUNCTION TO FIX ACTIVEX INSTALL ISSUE  *********************************/



//
// THIS OVERRIDES THE OOTB SHAREPOINT FUNCTION WHICH CAUSES ACTIVEX INSTALL ISSUES
//
// Essentially it overrides the ootb sharepoint function which calls the activex object
// See http://support.microsoft.com/default.aspx/kb/931509 for info on the issue

	function ProcessDefaultOnLoad(onLoadFunctionNames)
	{
		
		ProcessPNGImages();
		UpdateAccessibilityUI();
		
		//** We comment out the offending ootb function
		//** and leave the rest of the functions as they were
		//ProcessImn();
		for (var i=0; i < onLoadFunctionNames.length; i++)
		{
			var expr="if(typeof("+onLoadFunctionNames[i]+")=='function'){"+onLoadFunctionNames[i]+"();}";
			eval(expr);
		}
		if (typeof(_spUseDefaultFocus)!="undefined")
			DefaultFocus();
	}	

/************************* END FUNCTION TO FIX ACTIVEX INSTALL ISSUE  *********************************/


