/*
	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]);
  }
 }


 
 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);
    
        
}




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 for highlighting tabs that do not navigate to new page
window.addEvent('domready', function() {
	$$('#domicileMenu ul li a').each(function(item) {
		//if (item.href.substring(0, 1) == '#') {
			item.addEvent('click', function() {
				$$('#domicileMenu ul li').each(function(list) { list.removeClass('current'); if (list.getPrevious()) { list.addClass('pipe'); } });
				item.getParent().addClass('current');
				if (item.getPrevious()) { item.removeClass('pipe'); } 
			});
		//}
	});
});
 
