// strip html tags from the title
document.title = document.title.replace(/<.*?>/g, '');

// Validation functions for forms
function isEmailValid(string) {
	if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) {
		return true;
	} else {
		return false;
	}
}


function trim(str) {
    str = str.replace(/^\s+/, '');
    for (var i = str.length - 1; i >= 0; i--) {
        if (/\S/.test(str.charAt(i))) {
            str = str.substring(0, i + 1);
            break;
        }
    }
    return str;
}


$.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }
});

$(document).ready(function(){
	
	var pathinfo = window.location.pathname.split('/');
	
	if(pathinfo[1]=='') {
		$('#top-nav ul#top-nav-list li#home').addClass('top-nav-on-hard');
	} else {
		$('#top-nav ul#top-nav-list li#' + pathinfo[1]).addClass('top-nav-on-hard');
		
		if(pathinfo[3]!=undefined) {
			$('#left-channel ul#sub-nav li#' + pathinfo[3] + ' a').addClass('on-state');
			$('#left-channel ul#sub-nav li#' + pathinfo[3] + ' a').append(' &#187;');
		} else if(pathinfo[2]!=undefined) {
			$('#left-channel ul#sub-nav li#' + pathinfo[2] + ' a').addClass('on-state');
			$('#left-channel ul#sub-nav li#' + pathinfo[2] + ' a').append(' &#187;');
		}

	}

	$("#top-nav ul#top-nav-list li a").mouseover(function(){
		$(this).parent("li").addClass("top-nav-on");
		$("#top-nav ul li #mega-menu-about").addClass("on");
	});
	
	$("#top-nav ul#top-nav-list li a").mouseout(function(){
    		$(this).parent("li").removeClass("top-nav-on");	
  	});	

	$("ul#side-nav li a.base-item").mouseover(function(){
		$(this).parent("li").addClass("side-nav-on");
	});
	
	$("ul#side-nav li a.base-item").mouseout(function(){
    		$(this).parent("li").removeClass("side-nav-on");	
  	});	  	
	
	$("ul#side-nav li a.kill-link").click(function(e){
			e.preventDefault();
  	});	  	

	$('#top-nav li').hover(
	function () {
	    //show its submenu
	    $('ul', this).slideDown(100);
	},
	function () {
	    //hide its submenu
	    $('ul', this).slideUp(100);    
	    $(this).parent("li").removeClass("top-nav-on");	
	}
	);

	$('ul.sf-menu').superfish();
	

	// These two functions are "plugins" to make the numeric sort work on 
	// various pages that use the jQuery dataTables plugin
	jQuery.fn.dataTableExt.oSort['numeric-comma-asc']  = function(a,b) {
		var x = (a == "-") ? 0 : a.replace( /,/, "." );
		var y = (b == "-") ? 0 : b.replace( /,/, "." );
		x = parseFloat( x );
		y = parseFloat( y );
		return ((x < y) ? -1 : ((x > y) ?  1 : 0));
	};

	jQuery.fn.dataTableExt.oSort['numeric-comma-desc'] = function(a,b) {
		var x = (a == "-") ? 0 : a.replace( /,/, "." );
		var y = (b == "-") ? 0 : b.replace( /,/, "." );
		x = parseFloat( x );
		y = parseFloat( y );
		return ((x < y) ?  1 : ((x > y) ? -1 : 0));
	};


jQuery.fn.dataTableExt.oSort['date-euro-asc'] = function(a, b) {
    if (trim(a) != '') {
        var frDatea = trim(a).split(' ');
        var frTimea = frDatea[1].split(':');
        var frDatea2 = frDatea[0].split('/');
        var x = (frDatea2[2] + frDatea2[1] + frDatea2[0] + frTimea[0] + frTimea[1] + frTimea[2]) * 1;
    } else {
        var x = 10000000000000; // = l'an 1000 ...
    }
 
    if (trim(b) != '') {
        var frDateb = trim(b).split(' ');
        var frTimeb = frDateb[1].split(':');
        frDateb = frDateb[0].split('/');
        var y = (frDateb[2] + frDateb[1] + frDateb[0] + frTimeb[0] + frTimeb[1] + frTimeb[2]) * 1;                      
    } else {
        var y = 10000000000000;                     
    }
    var z = ((x < y) ? -1 : ((x > y) ? 1 : 0));
    return z;
};
 
jQuery.fn.dataTableExt.oSort['date-euro-desc'] = function(a, b) {
    if (trim(a) != '') {
        var frDatea = trim(a).split(' ');
        var frTimea = frDatea[1].split(':');
        var frDatea2 = frDatea[0].split('/');
        var x = (frDatea2[2] + frDatea2[1] + frDatea2[0] + frTimea[0] + frTimea[1] + frTimea[2]) * 1;                       
    } else {
        var x = 10000000000000;                     
    }
 
    if (trim(b) != '') {
        var frDateb = trim(b).split(' ');
        var frTimeb = frDateb[1].split(':');
        frDateb = frDateb[0].split('/');
        var y = (frDateb[2] + frDateb[1] + frDateb[0] + frTimeb[0] + frTimeb[1] + frTimeb[2]) * 1;                      
    } else {
        var y = 10000000000000;                     
    }                   
    var z = ((x < y) ? 1 : ((x > y) ? -1 : 0));                   
    return z;
};




	$("#emailthispage").colorbox({
			width:455, 
			inline:true, 
			href:".email-this-page-form",
			onOpen:function(){ 
				$(".email-this-page-form #emailinvalid").hide();
				$(".email-this-page-form #youremailinvalid").hide();
			}
	});
	
		$('#emailForm').submit(function(){
		
			// If validation fails, this variable value is set to false
			// and validation messaging is displayed. Otherwise the form
			// values are sent to the application layer for processing.
			var isvalidflag = true;


			// Turns off any existing error messages each time form is
			// submitted or re-submitted
			$('#emailForm input').removeClass("required");
			$('#emailForm textarea').removeClass("required");
			$(".email-this-page-form #emailinvalid").hide();
			$(".email-this-page-form #youremailinvalid").hide();


			// Grabs each form item value and assign to a variable
			var emailaddress = $("input#emailaddress").val();
			var subject = $("input#subject").val();
			var message = $("textarea#messagecomments").val();
			var yourfirstname = $("input#yourfirstname").val();
			var yourlastname = $("input#yourlastname").val();
			var youremail = $("input#youremail").val();

			// Validates each variable, displays error messaging  and 
			// switches isvalidflag.
			if (emailaddress == "") {
				
				$("input#emailaddress").addClass("required");
				isvalidflag = false;
				
			} else if(!isEmailValid(emailaddress)) {
				$(".email-this-page-form #emailinvalid").show();				
				$(".email-this-page-form #emailinvalid").addClass("smallerrormessaging");
				$("input#emailaddress").addClass("required");
				isvalidflag = false;
			};

			if (subject == "") {
				
				$("input#subject").addClass("required");
				isvalidflag = false;
			};

			if (message == "") {
				
				$("textarea#messagecomments").addClass("required");
				isvalidflag = false;
			};
			
			if (yourfirstname == "") {
				
				$("input#yourfirstname").addClass("required");
				isvalidflag = false;
			};
			
			if (yourlastname == "") {
				
				$("input#yourlastname").addClass("required");
				isvalidflag = false;
			};
			
			if (youremail == "") {
				
				$("input#youremail").addClass("required");
			    isvalidflag = false;
				
			} else if(!isEmailValid(youremail)) {
				
				$(".email-this-page-form #youremailinvalid").show();
				$(".email-this-page-form #youremailinvalid").addClass("smallerrormessaging");
				$("input#youremail").addClass("required");
				isvalidflag = false;
			};
			
			if (isvalidflag==false) {
				return false;				
			} else {
				
				$('#emailForm').hide();
				$("#email-this-thank-you").show();
				
				$.post('/email_this_page', $("#emailForm").serialize());

				
				return false;
			}
			
		});
	
	
		$('#changePasswordForm').submit(function(){
			
			// If validation fails, this variable value is set to false
			// and validation messaging is displayed. Otherwise the form
			// values are sent to the application layer for processing.
			var isvalidflag = true;
			
			// Turns off any existing error messages each time form is
			// submitted or re-submitted
			$('#changePasswordForm input').removeClass("required");
				
			if($("#password1").val() == '')
			{
				$("#password1").addClass("required");
				isvalidflag = false;
			}
			if($("#password2").val() == '')
			{
				$("#password2").addClass("required");
				isvalidflag = false;
			}
			if($("#password1").val() != $("#password2").val())
			{
				$("#password1").addClass("required");
				$("#password2").addClass("required");
				alert('The passwords you typed do not match; please try again.');
				isvalidflag = false;
			}

			if (isvalidflag==false) {
				
				
				return false;				
			}

		});
	
	
		$('#sign-in-form').submit(function(){
	
			// If validation fails, this variable value is set to false
			// and validation messaging is displayed. Otherwise the form
			// values are sent to the application layer for processing.
			var isvalidflag = true;
			
			// Turns off any existing error messages each time form is
			// submitted or re-submitted
			$('#sign-in-form input').removeClass("required");
			$("#sign-in #emailinvalid").hide();

			// Grabs each form item value and assign to a variable
			var signinemail = $("input#signinemail").val();
			var signinpassword = $("input#signinpassword").val();
			
			
			// Validates each variable, displays error messaging  and 
			// switches isvalidflag.
			if (signinemail == "") {
				
				$("#sign-in input#signin-email").addClass("required");
				isvalidflag = false;
				
			}
			
			if(!isEmailValid(signinemail)) {
				$("#sign-in #emailinvalid").show();				
				$("#sign-in input#signinemail").addClass("required");
				isvalidflag = false;
			};			
			
			if (signinpassword == "") {
				
				$("input#signinpassword").addClass("required");
				isvalidflag = false;
			};
			
			if (isvalidflag==false) {
				
				
				return false;				
			}
			
		});	
	
	
	$('#register-form').submit(function(){
		
		// Turns off any existing error messages each time form is
		// submitted or re-submitted		
		$("#error-messaging #investor-category").hide();

		if (undefined == $("input.register[name='investorCategory']:checked").val()) {
			$("#error-messaging #investor-category").show();
			return false;
		} else {return true;}

	});

	$('#contact-us-form').submit(function() {
		
		// If validation fails, this variable value is set to false
		// and validation messaging is displayed. Otherwise the form
		// values are sent to the application layer for processing.
		var isvalidflag = true;
		$("#contact-us-form #message-error").hide();
		
		// Turns off any existing error messages each time form is
		// submitted or re-submitted
		$('#contact-us-form input, #contact-us-form textarea').removeClass("required");
		
		// Grabs each form item value and assign to a variable
		var message = $("textarea#message").val();
		//var firstname = $("input#firstname").val();
		//var lastname = $("input#lastname").val();
		//var emailaddress = $("input#emailaddress").val();
		//var phonenumber = $("input#phonenumber").val();

		// Validates each variable, displays error messaging  and 
		// switches isvalidflag.
		if (message == "") {
			
			$("#contact-us-form textarea#message").addClass("required");
			$("#contact-us-form #message-error").show();
			isvalidflag = false;
		} 
		
		//if(firstname == "") {
		//	$("#contact-us-form input#firstname").addClass("required");
		//	isvalidflag = false;
		//} 
		
		//if(lastname == "") {
		//	$("#contact-us-form input#lastname").addClass("required");
		//	isvalidflag = false;
		//} 
		
		//if(!isEmailValid(emailaddress)) {
		//	$("#contact-us-form input#emailaddress").addClass("required");
		//	isvalidflag = false;			
		//} 
		
		//if(emailaddress == "") {
		//	$("#contact-us-form input#emailaddress").addClass("required");
		//	isvalidflag = false;		
		//} 
		
		//if(phonenumber == "") {
		//	$("#contact-us-form input#phonenumber").addClass("required");
		//	isvalidflag = false;
		//};

		if (isvalidflag==false) {


			return false;				
		} else {
			
			
			$("#contact-us-form").hide();
			$("#contact-thank-you").show();
			
			$.post('/contact_form', $("#contact-us-form").serialize());
			
			
			return false;
			//$('#contact-us-form').submit();
		}
	});
	
	
	$('#clearingPlatformId').change(function() {
		var value = $("select#clearingPlatformId :selected").val();
		if(value == "-1") {
			$("tr#clearing-platform").val('');
			$("tr#clearing-platform").show();
		} else {
			$("tr#clearing-platform").val(value);
			$("tr#clearing-platform").hide();
		}
	});
	
	$('#stateId').change(function() {
		var value = $("select#stateId :selected").val();
		if(value == "-1") {
			$("tr#state-alt").val('');
			$("tr#state-alt").show();
		} else {
			$("tr#state-alt").val(value);
			$("tr#state-alt").hide();
		}
	});	
	
	
	$('#account-info-form').submit(function(){ 

		// If validation fails, this variable value is set to false
		// and validation messaging is displayed. Otherwise the form
		// values are sent to the application layer for processing.
		var isvalidflag = true;
		
		// Turns off any existing error messages each time form is
		// submitted or re-submitted
		$('#account-info-form input').removeClass("required");
		$('#account-info-form select').removeClass("required");
		$("span#signin-email").hide();
		$("span#signin-password").hide();
		
		// Grabs each form item value and assign to a variable
		var firstName = $("input#firstName").val();
		var lastName = $("input#lastName").val();
		if (investorCategory!='INDIV') {
			var firmName = $("input#firmName").val();
			//var titleId = $("select#titleId").val();
		}
		
		var clearingPlatform = $("input#clearingPlatform").val();
		var stateAlt = $("input#stateAlt").val();
		var addressLine1 = $("input#addressLine1").val();
		var city = $("input#city").val();
		//var stateId = $("select#stateId").val();
		var postalCode = $("input#postalCode").val();
		//var countryId = $("input#countryId").val();
		var phoneNumber = $("input#phoneNumber").val();
		var emailAddress = $("input#emailAddress").val();
		var password = $("input#password").val();
		var passwordConfirm = $("input#passwordConfirm").val();
		var company = $("input#company").val();
		
		if(firstName == "") {
			$("input#firstName").addClass("required");
			isvalidflag = false;
		} 
		
		if(lastName == "") {
			$("input#lastName").addClass("required");
			isvalidflag = false;
		} 		
		
		
		
 		if($("#titleId :selected").val() == "" && investorCategory!='INDIV'){
 			$("select#titleId").addClass("required");
 			isvalidflag = false;
		}			
		
 		if($("select#clearingPlatformId :selected").val() == "" && investorCategory=='RIA'){
 			$("select#clearingPlatformId").addClass("required");
 			isvalidflag = false;
		}	
		
 		if($("select#clearingPlatformId :selected").val() == "-1" && investorCategory=='RIA' && clearingPlatform == ""){
 			$("input#clearingPlatform").addClass("required");
 			isvalidflag = false;
		}		
		
		if(addressLine1 == "") {
			$("input#addressLine1").addClass("required");
			isvalidflag = false;
		} 
		
		if(city == "") {
			$("input#city").addClass("required");
			isvalidflag = false;
		} 
		
 		if($("select#stateId :selected").val() == ""){
 			$("select#stateId").addClass("required");
 			isvalidflag = false;
		}		
		
		
		
 		if($("select#stateId :selected").val() == "-1" && stateAlt == ""){
 			$("input#stateAlt").addClass("required");
 			isvalidflag = false;
		}	
		
		
 		if(firmName == "") {
 			$("input#firmName").addClass("required");
 			isvalidflag = false;
		}
		
		if(postalCode == "") {
			$("input#postalCode").addClass("required");
			isvalidflag = false;
		} 
		
 		if($("select#countryId :selected").val() == ""){
 			$("select#countryId").addClass("required");
 			isvalidflag = false;
		}	

		if(company == "") {
			$("input#company").addClass("required");
			isvalidflag = false;
		} 	
		
		if(phoneNumber == "") {
			$("input#phoneNumber").addClass("required");
			isvalidflag = false;
		} 			
		
		if(emailAddress == "") {
			$("input#emailAddress").addClass("required");
			isvalidflag = false;
		} 	

		if(!isEmailValid(emailAddress)) {
			$("input#emailAddress").addClass("required");
			$("span#signin-email").show();
			isvalidflag = false;			
		} 		

		if(password == "") {
			$("input#password").addClass("required");
			isvalidflag = false;
		} 	

		if(passwordConfirm == "") {
			$("input#passwordConfirm").addClass("required");
			isvalidflag = false;
		} 
		
		if (passwordConfirm != password) {
			$("input#password").addClass("required");
			$("input#passwordConfirm").addClass("required");
			$("span#signin-password").show();
			isvalidflag = false;
		}

		if (isvalidflag==false) {

			return false;				
		} else {
			
			
			return true;
		}

	});	
	
	
	
	
	
	$("#page-to-email").attr("value", window.location)
	
	
	$("#help-improve").colorbox({width:700, inline:true, href:".satisfaction-form"});



	
	  $("a.investor-bubble-link").bind('mouseover', function() {  
		if ($("#investor-bubble").hasClass("not-visible")) {
			$("#investor-bubble").removeClass("not-visible").addClass("is-visible");
		}

	  });
	  
	  $("a.investor-bubble-link").bind('mouseout', function() {  
		if ($("#investor-bubble").hasClass("is-visible")) {
			$("#investor-bubble").removeClass("is-visible").addClass("not-visible");
		}

	  });	  
	  
	  $("#investor-bubble").bind('mouseover', function() {  
		if ($("#investor-bubble").hasClass("not-visible")) {
			$("#investor-bubble").removeClass("not-visible").addClass("is-visible");
		}	  
	  });


	  $("#investor-bubble").bind('mouseout', function() {  
		if ($("#investor-bubble").hasClass("is-visible")) {
			$("#investor-bubble").removeClass("is-visible").addClass("not-visible");
		}
	  });  	
	  	  
	  
	  
	  
	  
	
	  
	


$('#prospectuses-content table').dataTable({
			"bFilter": false,
			"bLengthChange": false,
			"iDisplayLength": 1000,
				"aoColumns": [
				null,
				null,
				null,
				null
				]			
	});
	
$('#fact-sheets-content table').dataTable({
			"bFilter": false,
			"bLengthChange": false,
			"iDisplayLength": 1000,
				"aoColumns": [
				null,
				null,
				null,
				null				
				]			
	});	
	
	
$('#product-essentials-content table').dataTable({
			"bFilter": false,
			"bLengthChange": false,
			"iDisplayLength": 1000,
				"aoColumns": [
				null,
				null,
				null,
				null				
				]			
	});		
	


	$('#prospectuses-content table tr:even').removeClass("odd");
	$('#prospectuses-content table tr:even').removeClass("even");
	$('#prospectuses-content table tr:odd').addClass("odd");
	$('#prospectuses-content table tr:even').addClass("even");

	$('#prospectuses-content table tr:visible:even td').removeClass("sorting_1");
	$('#prospectuses-content table tr:visible:odd td').removeClass("sorting_1");

	$('#fact-sheets-content table tr:visible:even td').removeClass("sorting_1");
	$('#fact-sheets-content table tr:visible:odd td').removeClass("sorting_1");

	$('#fact-sheets-content table th').click(function() {
		$('#fact-sheets-content table tr:visible').removeClass("alt");
		$('#fact-sheets-content table tr:even').addClass("alt");
				
		$('#fact-sheets-content table th img').attr('src', '/images/product-info/sort-right.gif').attr('width', '4').attr('height', '7');
		$('#'+this.id+".sorting_asc img").attr('src', '/images/product-info/sort-down.gif').attr('width', '7').attr('height', '4');
		$('#'+this.id+".sorting_desc img").attr('src', '/images/product-info/sort-up.gif').attr('width', '7').attr('height', '4');				
				
	});
	
		$("#fact-sheets-content #table-title.sorting_asc img").attr('src', '/images/product-info/sort-down.gif').attr('width', '7').attr('height', '4');
	
	

	$('#prospectuses-content table th').click(function() {
		$('#prospectuses-content table tr:visible').removeClass("alt");
		$('#prospectuses-content table tr:even').addClass("alt");
				
		$('#prospectuses-content table th img').attr('src', '/images/product-info/sort-right.gif').attr('width', '4').attr('height', '7');
		$('#'+this.id+".sorting_asc img").attr('src', '/images/product-info/sort-down.gif').attr('width', '7').attr('height', '4');
		$('#'+this.id+".sorting_desc img").attr('src', '/images/product-info/sort-up.gif').attr('width', '7').attr('height', '4');				
				
	});
	
		$("#prospectuses-content #table-title.sorting_asc img").attr('src', '/images/product-info/sort-down.gif').attr('width', '7').attr('height', '4');

	
	
	$('#product-essentials-content table th').click(function() {
		$('#product-essentials-content table tr:visible').removeClass("alt");
		$('#product-essentials-content table tr:even').addClass("alt");
				
		$('#product-essentials-content table th img').attr('src', '/images/product-info/sort-right.gif').attr('width', '4').attr('height', '7');
		$('#'+this.id+".sorting_asc img").attr('src', '/images/product-info/sort-down.gif').attr('width', '7').attr('height', '4');
		$('#'+this.id+".sorting_desc img").attr('src', '/images/product-info/sort-up.gif').attr('width', '7').attr('height', '4');				
				
	});	
	
		$("#product-essentials-content #table-title.sorting_asc img").attr('src', '/images/product-info/sort-down.gif').attr('width', '7').attr('height', '4');

	/*
	$('#product-info-section-profile table.stripeMe tr').mouseover(function() {
		$(this).addClass("over");
	});

	$('#product-info-section-profile table.stripeMe tr').mouseout(function() {
		$(this).removeClass("over");
	}); */
	
	
	
	
	



	
	$("#content-print a, #content-print-double a").first().mouseup(function() {
		window.print();
		return false;
	});

	
	$(".close-window").click(function() {
		
		$('#cboxClose').click();
		return false;
	});


	
		


	$("li.trigger").click(function(){
		$(this).toggleClass("active").next();
		$('.infosheets').toggle();  
	});

	//================================================================
	// SUBNAV JS
	//================================================================
	$(".category_banner").hover(function(){showCategory("none");})
	
	// what should this be called?
	var gwagb0f9 = ['broad','narrow','finetune','multi','single','leveraged',
		'strategy','dig_domestic','dig_international','intl','volatility',
		'steep','flat','point','none'];
	
	$(".category_button").hover(
		function(){
			var $this = $(this);
			
			if($this.hasClass("selected"))
				return;
			
			for(var idx in gwagb0f9)
			{
				if($this.hasClass(gwagb0f9[idx]))
					showCategory(gwagb0f9[idx]);
			}
		}
	);

	$(".category").hover(
		function () {},
		function () {
			showCategory("none");
		}
	);
	
	$("#content-stage-wide").hover(
		function () {},
		function () {
			showCategory("none");
		}
	);
	//================================================================


	//================================================================
	// SUBNAV SHOW CATEGORY FUNCTION
	//================================================================
	function showCategory(category){

		// Hide all categories (a catch-all to hide the currently-selected category.)
		$(".category").hide();
		// Remove the "selected" state from all nav buttons (a catch-all to hide the currently-selected button.)
		$(".category_button").removeClass("selected");


		// Now show the chosen category and set the associated nav button to "selected" state
		if(category != "none")
		{
			//open this category menu
			$(".category." + category).animate({opacity:"show",height:"show"},"fast");
			//set this category button to "selected"
			$(".category_button." + category).addClass("selected");
		}
	}
	//================================================================

	$("ul.infosheets").hide();
	$("li.trigger").click(function() {
		$(this).toggleClass("active").next();
		$('ul.infosheets').toggle();  
	});
	$('#legal').hide();
	$('#privacy').click(function () {

		var text = $(this).children('div#legal');

		if (text.is(':hidden')) {
			text.slideDown('200');
			$(this).children('span').html('-');		
		} else {
			text.slideUp('200');
			$(this).children('span').html('+');		
		}
		
	});
	
	

	if (pathinfo[1]=="product_information") {
		var prodinfofilter = $.getUrlVar('filter');
//		$('#product-info-category').val(prodinfofilter);
//		setProductInfoPage();
	}
	
	if (pathinfo[1]=="pass_thru") {
		var passthruwebsite = $.getUrlVar('site');
		
		$('#content-stage h3 a#pass-thru-site').attr("href", "http://" + passthruwebsite).text(passthruwebsite);
		
		setTimeout(function() {
		  window.location.replace("http://" + passthruwebsite);
		}, 3000);		
	}	
	
	
	
	$("a").click(function() {
		
		var file_extension = $(this).attr('href').split('.').pop().toLowerCase();
		if($.inArray(file_extension, ['pdf']) == 0) {
			window.open(this.href);
			return false;
		}
	});
	
	$("ul#sub-nav #understanding_ipath_etns a").html("Understanding<br />iPath ETNs");
	if (pathinfo[3]=="understanding_ipath_etns") {
		$("ul#sub-nav #understanding_ipath_etns a").append(" &#187;");
	}
	
	
	$('#search-form').submit(function(){ 
		var isvalidflag = true;
		var searchbox = $("input#searchbox").val();
		
		// If the user chooses a ticker symbol in the search box,
		// go straight to that page, skipping over the
		// search results page
		var tickers = new Array ("bal","blng","bcm","bwv","cafe","choc","cow","ctnn","cupm","dcng","dfvl","dfvs","dirt","djp","dlbs","dldl","dtul","dtus","dtyl","dtys","emlb","emsa","ero","flat","foil","gaz","gbb","grn","grwn","gsp","hevy","ici","inp","ivo","jja","jjc","jje","jjg","jjm","jjn","jjp","jjs","jjt","jju","jo","jyn","ld","ledd","lstk","mfla","mfsa","nib","nini","oil","olem","ong","pgm","rolo","rosa","rtla","rtsa","sbv","sfla","sfsa","sgar","sgg","stpp","vxx","vxz","vzz","vzzb","vzzb","weet","xvz","xxv","rola","dlbl", "ivop", "ayt", "jem", "pgd");

		if (searchbox == "") {

				// $("input#searchbox").addClass("required");
				isvalidflag = false;
		}
		
		if (isvalidflag==false) {

			return false;				
		} else {
			
			for (i=0; i<tickers.length; i++) {
				if (searchbox.toLowerCase() == tickers[i]) {
					location.href = "/product/" + searchbox.toLowerCase();
					return false;
				}
		}
	}		
		
		
		
	});	
});



var iPath = {};
	
iPath.UserType = function(spec, my)
{
	var that = {};
	
	var COOKIE_NAME = 'userType';
	
	var userType = '';
	
	// returns 'pro' or 'indiv'
	that.get = function()
	{
		return userType;
	}
	
	that.set = function(value, refresh)
	{
		switch(value)
		{
			case 'PROFESSIONAL':
			case 'INDIVIDUAL':
				$.cookie(COOKIE_NAME, value, {expires: 365 * 10, path: '/'});
				userType = value;
				
				// it is suggested you allow the function to refresh the page immediately
				// to allow server-side code relying on the cookie the ability to
				// refresh itself
				if(refresh !== false)
					window.location.href = window.location.href;
				
				break;
			default:
				throw new Error('bad userType ' + value + ' specified');
		}
	}
	
	that.switchType = function(refresh)
	{
		switch($.cookie(COOKIE_NAME))
		{
			case 'PROFESSIONAL':
				that.set('INDIVIDUAL', refresh);
				break;
			case 'INDIVIDUAL':
				that.set('PROFESSIONAL', refresh);
				break;
		}

	}
	
	var init = function()
	{
		if($.cookie(COOKIE_NAME) != 'PROFESSIONAL' && $.cookie(COOKIE_NAME) != 'INDIVIDUAL')
			that.set('PROFESSIONAL', false);
		
		userType = $.cookie(COOKIE_NAME);
		
		//console.debug('userType = ' + userType);
	}
	
	$(function() {init();});
	return that;
}();
