/*
	This script is enclosed in a MooTools test, to ensure
	that only MooTools-capable browsers (top-tier) execute it.
*/

if(window.onDomReady)
{
	///////////////////////////////////////////////////////////////////////////
	// Add a CSS flag that indicates JS+DOM is working 
	
	window.onDomReady(function()
	{
		$$("body")[0].addClass("javascript");
	});



	///////////////////////////////////////////////////////////////////////////
	// Add a onFocus handler for search boxes
	
	window.onDomReady(function()
	{
		$$(".search_query").each(function(searchQuery)
		{		
			var defaultValue = searchQuery.value;
			
			searchQuery.onfocus = function()
			{
				searchQuery.value = (searchQuery.value == defaultValue) ?
					"" : searchQuery.value;
			};
			
			searchQuery.onblur = function() 
			{ 
				searchQuery.value = (searchQuery.value == "") ? defaultValue :
					searchQuery.value;
			};
		});
	});
	
	
	
	///////////////////////////////////////////////////////////////////////////
	// Print page link 
	
	window.onDomReady(function()
	{
		var placeholder = $("print_page_placeholder");
		if(placeholder)
		{
			placeholder.innerHTML = "<a href=\"javascript:window.print();\">Print</a> ";
		}
	});
	
	
	
	///////////////////////////////////////////////////////////////////////////
	// Adjust Font Size link
	
	window.onDomReady(function()
	{
		var cookieOptions = { duration: false, path: "/" };
		var cssPrefix = "size";
		var fontSize = 0;
		var maxFontSize = 3;

		/* adjust font size, and save cookie */
		var setFontSize = function()
		{
			var pattern = /\s*size\d+\s*/;
			document.body.className = 
				(" " + document.body.className + " ").replace(pattern, " ").clean();
			document.body.className = (document.body.className + " " + 
				(cssPrefix + fontSize)).clean();		
			Cookie.set("FONT_SIZE", fontSize, cookieOptions);
		};
		
		/* 	load cookie, and set font size */
		var getFontSize = function()
		{
			fontSize = Cookie.get("FONT_SIZE");
			fontSize = fontSize ? fontSize : 0;
			fontSize = Math.min(maxFontSize, 
				Math.max(0, fontSize.toInt()));
			setFontSize();
		};	
		
		var placeholder = $("font_resize_placeholder");
		if(placeholder)
		{
			var virtual_dir = base_path ? base_path : "/";
			
			placeholder.innerHTML = '&nbsp;|&nbsp; Adjust Font Size' +
				'<a href="javascript:void(0);" class="increase"><img src="' + virtual_dir + 'images/arrows/gray_up.gif" /></a>' +
				'<a href="javascript:void(0);" class="decrease"><img src="' + virtual_dir + 'images/arrows/gray_down.gif" /></a>';
				
			$$("#font_resize_placeholder .increase")[0].onclick = function()
			{
				fontSize = Math.min(maxFontSize, fontSize + 1);
				setFontSize();
			};
			
			$$("#font_resize_placeholder .decrease")[0].onclick = function()
			{
				fontSize = Math.max(0, fontSize - 1);
				setFontSize();
			};
		}
		
		getFontSize();
		
	});		
}

//this function checks the 1st part of the variable to evaluate whether the link should open in a new window
//2nd part determines the link it should go to
 function openFunds(url) {
 var urls = url.split("|");
 if (url.indexOf("True") > -1) {
  location.href = urls[0];
  }
  else {
    window.open(urls[0]);
  }
 }


//// var vehicles = new Array("(Variable Investments)", "(Mutual Funds)", "(Separately Managed Accounts)", "(Closed-End Funds)");
// //var directories = new Array("variable-investment", "mutual-funds", "sma", "closed-end");
// 
// //declaring a multi-dimentional array, the 1st dimension is the vehicle name and the 2nd dimension is the corresponding directory
// var vehDirObject = new Array();
// vehDirObject = [["Variable Investments","variable-investment"], ["Mutual Funds","mutual-funds"], ["Separately Managed Accounts","sma"],["Closed-End Funds","closed-end"]];
// function openFund(label, value,ht) {
// var roycefunds = ht.split("||");
//  for (var i = 0; i < vehDirObject.length; i++) {

//   if (label.indexOf(vehDirObject[i][0]) > -1) {
//    directory = vehDirObject[i][1];

//   }
//  }
//  
//  if (label.indexOf("Royce") > -1) {
//  var url;var urls;
//    for (var j = 0; j < roycefunds.length; j++)
//     {
//        urls=roycefunds[j].split("|");
//        
//           if (value.indexOf(urls[0]) > -1) 
//           {
//                url=urls[1];
//                j=roycefunds.length-1;
//          
//           }
//      }  

//   window.open(url);
//  }
//  else {
//   location.href = base_path + "products/" + directory + "/overview/" + value + ".aspx";
//  }
// }



//this function determines how non-royce and royce funds should behave when the funds have been selected in the drop down
 var vehDirObject = new Array();
 vehDirObject = [["Variable Investments","variable-investment"], ["Mutual Funds","mutual-funds"], ["Separately Managed Accounts","sma"],["Closed-End Funds","closed-end"]];
 function openNewWindow(label, value,ht) {
 var roycefunds = ht.split("||");
 var values = value.split("|");
  for (var i = 0; i < vehDirObject.length; i++) {

   if (label.indexOf(vehDirObject[i][0]) > -1) {
    directory = vehDirObject[i][1];

   }
  }
  
  if (values[1].indexOf("False") > -1 ) {
  var url;var urls;
    for (var j = 0; j < roycefunds.length; j++)
     {
        urls=roycefunds[j].split("|");
        
           if (values[0].indexOf(urls[0]) > -1) 
           {
                url=urls[1];
                j=roycefunds.length-1;
          
           }
      }  

   window.open(url);
  }
  else {
   location.href = base_path + "products/" + directory + "/overview/" + values[0] + ".aspx";
  }
 }
 
 function print_all(thisID, showall){
	    
    thisID = thisID.replace(/printall/,"showall");
    thisID = thisID.replace(/_/g,"$");
	    
    if (showall == 0){
        __doPostBack(thisID,'');
    }
        
    setTimeout('window.print()', 3000);
    
    //setTimeout('after_print_all("'+thisID+'", "'+showall+'")', 9000);
    
        
}


var show;

function ShowAll(val)
{

    show = val;
}

function PrintAll(thisID, showall,PrintAllID,ShowAllID){
	    
    thisID = thisID.replace(PrintAllID,ShowAllID);
    thisID = thisID.replace(/_/g,"$");
	
	if(show == 1)
	{    
       show = 0;
       __doPostBack(thisID,''); 
       
        setTimeout('window.print()', 1500);
    }else{
        window.print()
    }
        
   
    
    //setTimeout('after_print_all("'+thisID+'", "'+showall+'")', 9000);
}


//function after_print_all(thisID, showall){
//    thisID = thisID.replace(/printall/,"showall");
//    thisID = thisID.replace(/_/g,"$");
//    
//    if (showall == 0){
//        __doPostBack(thisID,'');
//    }
//}



function writeFlashObject(longdesc, htmlAttributes, heightWidth, flashCodeBase, srcString, extraParamTags)
{
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' + longdesc + htmlAttributes + heightWidth + ' codebase="' + flashCodeBase + '"><param name="MOVIE" value="' + srcString + '" />' + extraParamTags + '</object>');
}

var flashObject = 1;

function fixflash(containerID)
{
    var flashContainer = document.getElementById(containerID);
    
    if(flashContainer != null)
    {
        var flashMovie = document.createElement("div");
        flashMovie.innerHTML = flashContainer.innerHTML.replace(/</g, "<").replace(/>/g, ">");
        flashContainer.parentNode.insertBefore(flashMovie, flashContainer);
        flashContainer.parentNode.removeChild(flashContainer);
        flashMovie.setAttribute("id",containerID);
    }
}


function togglediv(divid) {

	if (document.getElementById(divid).style.display == 'none') {
		document.getElementById(divid).style.display = '';
		document.getElementById(divid).style.visibility = '';
	} else {
		document.getElementById(divid).style.display = 'none';
		document.getElementById(divid).style.visibility = 'hidden';
	}
}
 