
var tickers = [ ];
$(document).ready(function()
{
	$.ajax(
	{ 
		type: 'GET', 
		url: '/funds/products.xml',
		dataType: 'xml',
		success: function(xmlDOM)
		{
			$(xmlDOM).find('Ticker').each(function()
			{
				tickers.push($(this).text().toUpperCase());
			});
			
			$('#site-search form').submit(function(event)
			{
				var text = $('#site-search input[type=text]').val();
				for(var i=0;i<tickers.length;i++)
				{
					if(tickers[i] == text.toUpperCase())
					{
						window.location = '/funds/' + text.toLowerCase() + '.html';
						event.preventDefault();
					}
				}
			});
			
			$('.hp-form-search').submit(function(event)
			{
				var text = $('.hp-form-search input[type=text]').val();
				for(var i=0;i<tickers.length;i++)
				{
					if(tickers[i] == text.toUpperCase())
					{
						window.location = '/funds/' + text.toLowerCase() + '.html';
						event.preventDefault();
					}
				}
			});
			
			$('.hp-nav-search').submit(function(event)
			{
				var text = $('.hp-nav-search input[type=text]').val();
				for(var i=0;i<tickers.length;i++)
				{
					if(tickers[i] == text.toUpperCase())
					{
						window.location = '/funds/' + text.toLowerCase() + '.html';
						event.preventDefault();
					}
				}
			});
			
			$(':input[title]').each(function() {
				var $this = $(this);
				if($this.val() === '') {
					$this.val($this.attr('title'));
				}
				$this.focus(function() {
					if($this.val() === $this.attr('title')) {
						$this.val('');
					}
				});
				$this.blur(function() {
					if($this.val() === '') {
						$this.val($this.attr('title'));
					}
				});
			});
			
		}
	});
});
