﻿jQuery.noConflict();
(function($) { $(function() {
	
	if($("a[rel=external]")){
		$("a[rel=external]").click(function() {
	        window.open(this.href);  
	        return false;
		});
	}

   /********************Advisor Only Descriptor for internal menu**************************/
   
  /* $(".g-navlist > li").mouseover(function() {
		if($(this).find("a").text()=="My Goals" || $(this).find("a").text()=="My Focus" || $(this).find("a").text()=="My Practice Tracker" || $(this).find("a").text()=="My Profile" || $(this).find("a").text()=="Payment Information")
	   $(this).find("a").text();
	});*/
   
   
   
   
   /*************************************************************************************/


$("#general-nav > li:last-child, #secondary-nav td:last-child").addClass("last-child");

//*****************************************************************************************************
//Carousel
//*****************************************************************************************************
if ($('#carousel').length) {
	$('#carousel').bxSlider({
		pager: true,
		auto: true,
		autoHover: true,
		pause: 8000
	});
}

//*****************************************************************************************************
// Password Reveal
//*****************************************************************************************************
var reveal = $(".reveal");
if (reveal.length) {
	var passFields = $("input[type=password]"),
		unmaskedPassFields = $(".unmasked-pass");
	reveal.change(function() {
		if (reveal.is(":checked")) {
			unmaskedPassFields.show();
			passFields.hide();
		} else {
			passFields.show();
			unmaskedPassFields.hide();
		}
	});
	passFields.keyup(function() {
		copyPassValue($(this), $(this).parent().children(".unmasked-pass"));
	}).keyup();
	unmaskedPassFields.keyup(function() {
		copyPassValue($(this), $(this).parent().children("input[type=password]"));
	});
}
function copyPassValue(source, destination) {
	destination.val(source.val());
}

//*****************************************************************************************************
// Adding File Input Field
//*****************************************************************************************************
$(".add-file").click(function() {
	$(".file-input:first").clone().insertBefore($(this).parent()).find("input").val("");
	return false;
});

//*****************************************************************************************************
//Adding Income Type Input Field
//*****************************************************************************************************
$("#add_income_type").click(function() {
	$(".hidden_income_type:first").removeClass('hidden_income_type');
	return false;
});

//*****************************************************************************************************
//Adding Child Input Field
//*****************************************************************************************************
$("#add_child").click(function() {
	$(".hidden_child:first").removeClass('hidden_child');
	return false;
});

//*****************************************************************************************************
//Adding Staff Member Input Field
//*****************************************************************************************************
$("#add_staff").click(function() {
	$(".hidden_staff:first").removeClass('hidden_staff');
	return false;
});

//*****************************************************************************************************
// Show / Hide function
//*****************************************************************************************************

$("#AgreementInitiationPaymentTypePayByCreditCard").click(function() {
	$(this).addClass('show_hide_checked');
	$("#AgreementInitiationPaymentTypePayByCheck").removeClass('show_hide_checked');
	
	$("#check_info").hide('fast');
	$("#credit_card_info").show('fast');
});

$("#AgreementInitiationPaymentTypePayByCheck").click(function() {
	$(this).addClass('show_hide_checked');
	$("#AgreementInitiationPaymentTypePayByCreditCard").removeClass('show_hide_checked');
	
	$("#check_info").show('fast');
	
	if($("#AgreementMonthlyPaymentTypePayByCreditCard").hasClass('show_hide_checked') == false){
		$("#credit_card_info").hide('fast');
	}
});

$("#AgreementMonthlyPaymentTypePayByCreditCard").click(function() {
	$(this).addClass('show_hide_checked');
	$("#AgreementMonthlyPaymentTypePayByBankDraft").removeClass('show_hide_checked');
	
	$("#bank_draft_info").hide('fast');
	$("#credit_card_info").show('fast');
	
});

$("#AgreementMonthlyPaymentTypePayByBankDraft").click(function() {
	$(this).addClass('show_hide_checked');
	$("#AgreementMonthlyPaymentTypePayByCreditCard").removeClass('show_hide_checked');
	
	$("#bank_draft_info").show('fast');
	if($("#AgreementInitiationPaymentTypePayByCreditCard").hasClass('show_hide_checked') == false){
		$("#credit_card_info").hide('fast');
	}
});


//*****************************************************************************************************
// Datepicker
//*****************************************************************************************************
var datePick = $('.date-pick');
if (datePick.length) {
var activeDatePanel = $(".select-date");
//initialise the "Select date" link
datePick
	.datePicker(
		// associate the link with a date picker
		{
			createButton: false,
			startDate: '01/01/2000',
			endDate: '31/12/2020'
		}
	).bind(
		// when the link is clicked display the date picker
		'click', function() {
			activeDatePanel = $(this).parent();
			updateSelects($(this).dpGetSelected()[0]);
			$(this).dpDisplay();
			return false;
		}
	).bind(
		// when a date is selected update the SELECTs
		'dateSelected', function(e, selectedDate, $td, state) {
			updateSelects(selectedDate);
		}
	).bind('dpClosed', function(e, selected) {
		updateSelects(selected[0]);
	});

var updateSelects = function (selectedDate)
{
	var selectedDate = new Date(selectedDate);
	activeDatePanel.find('.select-day option[value=' + selectedDate.getDate() + ']').attr('selected', 'selected');
	activeDatePanel.find('.select-month option[value=' + (selectedDate.getMonth()+1) + ']').attr('selected', 'selected');
	activeDatePanel.find('.select-year option[value=' + (selectedDate.getFullYear()) + ']').attr('selected', 'selected');
}
// listen for when the selects are changed and update the picker
$('.select-day, .select-month, .select-year').bind('change', function() {
	activeDatePanel = $(this).parents(".select-date");
	var d = new Date(
		activeDatePanel.find('.select-year').val(),
		activeDatePanel.find('.select-month').val()-1,
		activeDatePanel.find('.select-day').val()
	);
	activeDatePanel.find('.date-pick').dpSetSelected(d.asString());
});
// default the position of the selects to today

var d = new Date(
		activeDatePanel.find('.select-year').val(),
		activeDatePanel.find('.select-month').val()-1,
		activeDatePanel.find('.select-day').val()
	);

// var default_date = new Date('01/01/2000');

var today = new Date();
// alert(d.getDate()+'/'+(d.getMonth()+1)+'/'+d.getFullYear());
// alert(today.getTime());
//if(d.getTime() == 946706400000 || d.getTime() == 946677600000 || d.getTime() == 0){
 if(d.getDate()+'/'+(d.getMonth()+1)+'/'+d.getFullYear() == '1/1/2000'  || d.getTime() == 0){
	updateSelects(today.getTime());
	// and update the datePicker to reflect it...
	$('.select-day').trigger('change');
}

}

//*****************************************************************************************************
// Tables Stripped Decoration
//*****************************************************************************************************
$(".zebrine").each(function() {
	$("tbody tr:even", this).addClass("even");
});

//*****************************************************************************************************
//Default Input Texts
//*****************************************************************************************************
function defaultInputValues(node, defaultValue) {
	node.val(defaultValue);
	node.focus(function() {
		if ($(this).val() == defaultValue) {
			$(this).val("");
		}
	}).blur(function() {
		if ($(this).val() == "") {
			$(this).val(defaultValue);
		}
	});
}
if($("#auth-form #UserUsername").val() == ''){
	defaultInputValues($("#auth-form #UserUsername"), "Username");
	defaultInputValues($("#auth-form #UserPassword"), "Password");
}

defaultInputValues($("#RegistrationNewAdvisorForm #UserUsername"), "Username");
defaultInputValues($("#RegistrationNewAdvisorForm #UserPassword"), "Password");

defaultInputValues($("#RegistrationApplicationForm #UserExistUsername"), "Username");
defaultInputValues($("#RegistrationApplicationForm #UserPassword"), "Password");

/*
$('#auth-form').submit(function() {
		$('#auth-form #UserUsername').val(Base64.encode($('#auth-form #UserUsername').val()));
		$('#auth-form #UserPassword').val(Base64.encode($('#auth-form #UserPassword').val()));
		
//		alert($('#auth-form #UserUsername').val());
//		alert($('#auth-form #UserPassword').val());
    });
*/


//*****************************************************************************************************
// Drop Down Navigation
//*****************************************************************************************************
var ejectedList, limiter, ejectedList_position, activeLink;
$(".sublist-owner").hover(function() {
	ejectedList = $(this).children(".c-ejected-list"),
	limiter = $(this).parent(),
	ejectedList_position = $(this).offset().left - limiter.offset().left + ejectedList.innerWidth(),
	activeLink = $(this).children("a");
//	if (ejectedList_position >= limiter.innerWidth()) {
//		ejectedList.addClass("shown-from-right");
//	} else {
		ejectedList.addClass("shown");
//	}
	activeLink.addClass("active");
}, function() {
	ejectedList.removeClass("shown shown-from-right");
	activeLink.removeClass("active");
});

//*****************************************************************************************************
// Drop Down Navigation for Table
//*****************************************************************************************************

$(".sublist-owner_t").hover(function() {
	ejectedList = $(this).children(".c-ejected-list_t"),
	limiter = $(this).parents("#secondary-nav__parent"),
	this_left = Math.round($(this).offset().left) - limiter.offset().left,
	ejectedList_position = this_left + ejectedList.innerWidth(),
	activeLink = $(this);
	if (ejectedList_position >= limiter.innerWidth()) {
		ejectedList.css({
			left: "auto",
			right: limiter.width() - this_left - $(this).width() + "px"
		});
	} else {
		ejectedList.css({
			left: this_left + "px",
			right: "auto"
		});
	}
//	activeLink.addClass("active");
}, function() {
	ejectedList.css({
		left: "-9999em",
		right: "auto"
	});
//	activeLink.removeClass("active");
});
/*
var subEjectedList, subActiveLink;
$(".third-level-owner_t").hover(function() {
	subEjectedList = $(this).children(".c-ejected-list_t");
	subActiveLink = $(this).children("a");
	if	((ejectedList_position + subEjectedList.innerWidth() >= limiter.innerWidth()) || (ejectedList_position >= limiter.innerWidth())) {
			subEjectedList.css({
				left: "auto",
				right: "100%"
			});
	} else {
			subEjectedList.css("left", "100%");
	}
	
	subActiveLink.addClass("active");
}, function() {
	subEjectedList.css({
		left: "-9999em",
		right: "auto"
	});
	subActiveLink.removeClass("active");
});
var subSubEjectedList, subSubActiveLink;
$(".fourth-level-owner_t").hover(function() {
	subSubEjectedList = $(this).children(".c-ejected-list_t");
	subSubActiveLink = $(this).children("a");
	if	((ejectedList_position + subEjectedList.innerWidth() + subEjectedList.innerWidth() >= limiter.innerWidth()) || (ejectedList_position >= limiter.innerWidth())) {
			subSubEjectedList.css({
				left: "auto",
				right: "100%"
			});
	} else {
			subSubEjectedList.css("left", "100%");
	}
	
	subSubActiveLink.addClass("active");
}, function() {
	subSubEjectedList.css({
		left: "-9999em",
		right: "auto"
	});
	subSubActiveLink.removeClass("active");
});
*/
//*****************************************************************************************************
//Collapse Down Vertical Navigation
//*****************************************************************************************************
$(".expanded-list").hide();
/*$(".sublist-parent > a").click(function() {
	$(this).parent().siblings(".sublist-parent").
		add($(this).parent().find(".sublist-parent")).
		find("a.active").removeClass("active").
		end().find(".expanded-list:visible").slideUp("fast");
	$(this).toggleClass("active").blur().next().slideToggle("fast");
	return false;
});*/

//*****************************************************************************************************
//Slide Down Item
//*****************************************************************************************************
$(".item-list .slide-down, .collapsible-v-nav .slide-down").click(function() {
	$(this).toggleClass("active").parent().children("ul").slideToggle("fast");
});
$(".row .slide-down").click(function() {
	$(this).toggleClass("active").parents("table").next(".g-hidden").slideToggle("fast");
});

$(".possibilities_slide").click(function() {
	
//	$(this).next(".g-hidden").slideToggle("fast").siblings(".g-hidden").slideUp("fast");
	$(this).next(".g-hidden").slideToggle("fast");
    
	$(this).children(".slide-down").toggleClass("active");
//	$(this).siblings("div").children(".slide-down").removeClass("active");
});

$("#possibilities_tabs li").click(function() {
	
	var block = $(this).attr('id');
	
	$(".possibilities_tabs_block").hide("fast");
	
	$("#"+block+"_block").show("fast");
    
	$(this).toggleClass("active");
	$(this).siblings("li").removeClass("active");

});

//*****************************************************************************************************
//Registration form validation errors
//*****************************************************************************************************

$('input.form-error').focus(function(){
	$(this).next('div.error-message').hide("fast");
	$(this).val('');
	$(this).removeClass('form-error');
	$(this).parents("div.error").removeClass('error');
});

//*****************************************************************************************************
// TinyMCE Text Editor
//*****************************************************************************************************
/*if ($("script[src*=tiny_mce]").length) {
tinyMCE.init({
	// General options
	mode : "exact",
	elements : "text-editor",
	theme : "advanced",
	plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave",

	// Theme options
	theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
	theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
	theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
	theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft",
	theme_advanced_toolbar_location : "top", 
	
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_statusbar_location : "bottom",
	theme_advanced_resizing : false,
	
	// Drop lists for link/image/media/template dialogs
	template_external_list_url : "/js/tiny_mce/lists/template_list.js",
	external_link_list_url : "/js/tiny_mce/lists/link_list.js",
	external_image_list_url : "/js/tiny_mce/lists/image_list.js",
	media_external_list_url : "/js/tiny_mce/lists/media_list.js",
	
	// Replace values for the template plugin
	template_replace_values : {
		username : "Some User",
		staffid : "991234"
	}
});
}*/

//*****************************************************************************************************
//Event Adding choose event Type
//*****************************************************************************************************
	if($("#UpcomingEventEventType").val() != ''){
		switch ($("#UpcomingEventEventType").val()){
			case '':
				$(".conference_call, .hosted_conference_call, .excell_meeting, .barrier_breaker_workshop, .training_summit, .true_wealth_institute").hide('fast');
				break;
			case 'Conference Calls/Webinars':
				$(".hosted_conference_call, .excell_meeting, .barrier_breaker_workshop, .training_summit, .true_wealth_institute").hide('fast');
				$(".conference_call").show('fast'); 
				break;
			case 'Hosted Conference Calls/Webinars':
				$(".conference_call, .excell_meeting, .barrier_breaker_workshop, .training_summit, .true_wealth_institute").hide('fast');
				$(".hosted_conference_call").show('fast');
			case 'Excell Meetings':
				$(".conference_call, .hosted_conference_call, .barrier_breaker_workshop, .training_summit, .true_wealth_institute").hide('fast');
				$(".excell_meeting").show('fast');
				break;
			case 'Barrier Breaker Workshops':
				$(".conference_call, .hosted_conference_call,  .excell_meeting, .training_summit, .true_wealth_institute").hide('fast');
				$(".barrier_breaker_workshop").show('fast');
				break;
			case 'Team’N Training Summits':
				$(".conference_call, .hosted_conference_call,  .excell_meeting, .barrier_breaker_workshop, .true_wealth_institute").hide('fast');
				$(".training_summit").show('fast');
				break;
			case 'True Wealth Institute':
				$(".conference_call, .hosted_conference_call,  .excell_meeting, .barrier_breaker_workshop .training_summit").hide('fast');
				$(".true_wealth_institute").show('fast');
				break;
				
		}
	}
	
	$("#UpcomingEventEventType").change(function() {
//		alert(this.value);
		switch (this.value){
			case '':
				$(".conference_call, .hosted_conference_call, .excell_meeting, .barrier_breaker_workshop, .training_summit, .true_wealth_institute").hide('fast');
				$('#UpcomingEventAddForm input, textarea').each(function(n,element){
					if($(element).attr('type')!='hidden' && $(element).attr('type')!='submit'){
						$(element).val('');
					}
				});
				break;
			case 'Conference Calls/Webinars':
				$(".hosted_conference_call, .excell_meeting,  .barrier_breaker_workshop, .training_summit, .true_wealth_institute").hide('fast');
				$('#UpcomingEventAddForm input, textarea').each(function(n,element){
					if($(element).attr('type')!='hidden' && $(element).attr('type')!='submit'){
						$(element).val('');
					}
				});
				$(".conference_call").show('fast'); 
				break;
			case 'Hosted Conference Calls/Webinars':
				$(".conference_call, .excell_meeting, .barrier_breaker_workshop, .training_summit, .true_wealth_institute").hide('fast');
				$('#UpcomingEventAddForm input, textarea').each(function(n,element){
					if($(element).attr('type')!='hidden' && $(element).attr('type')!='submit'){
						$(element).val('');
					}
				});
				$(".hosted_conference_call").show('fast'); 
				break;
			case 'Excell Meetings':
				$(".conference_call, .hosted_conference_call, .barrier_breaker_workshop, .training_summit, .true_wealth_institute").hide('fast');
				$('#UpcomingEventAddForm input, textarea').each(function(n,element){
					if($(element).attr('type')!='hidden' && $(element).attr('type')!='submit'){
						$(element).val('');
					}
				});
				$(".excell_meeting").show('fast');
				break;
			case 'Barrier Breaker Workshops':
				$(".conference_call, .hosted_conference_call, .excell_meeting, .training_summit, .true_wealth_institute").hide('fast');
				$('#UpcomingEventAddForm input, textarea').each(function(n,element){
					if($(element).attr('type')!='hidden' && $(element).attr('type')!='submit'){
						$(element).val('');
					}
				});
				$(".barrier_breaker_workshop").show('fast');
				break;
			case 'Team’N Training Summits':
				$(".conference_call, .hosted_conference_call, .excell_meeting, .barrier_breaker_workshop, .true_wealth_institute").hide('fast');
				$('#UpcomingEventAddForm input, textarea').each(function(n,element){
					if($(element).attr('type')!='hidden' && $(element).attr('type')!='submit'){
						$(element).val('');
					}
				});
				$(".training_summit").show('fast');
				break;
			case 'True Wealth Institute':
				$(".conference_call, .hosted_conference_call, .excell_meeting, .barrier_breaker_workshop, .training_summit").hide('fast');
				$('#UpcomingEventAddForm input, textarea').each(function(n,element){
					if($(element).attr('type')!='hidden' && $(element).attr('type')!='submit'){
						$(element).val('');
					}
				});
				$(".true_wealth_institute").show('fast');
				break;
		}
		
	});

//*****************************************************************************************************
//Accordion Checkbox click
//*****************************************************************************************************
$(".item-list input:checkbox").click(function() {
//	
	if($(this).attr('checked')){
		inputs = $(this).parent('div').parent('li').find("ul").find("input[type='checkbox']");
		inputs.each(function(){
			$(this).attr('checked', 'checked');
		});

	} else {
		inputs = $(this).parent('div').parent('li').find("ul").find("input[type='checkbox']");
		inputs.each(function(){
			$(this).removeAttr('checked');
		});
	}
	
});

//*****************************************************************************************************
//Super Admin Checkbox click
//*****************************************************************************************************
$("#UserSuperManageAccounts:checkbox").click(function() {
//	
	if($(this).attr('checked')){
		inputs = $(this).parents('div.rc-box-content__aligner').find("input[type='checkbox']");
		inputs.each(function(){
			$(this).attr('checked', 'checked');
		});

	}
	
});

//*****************************************************************************************************
//Credit Card Typpe Digits
//*****************************************************************************************************

$("#CardCardType").change(function() {
//	alert(this.value);
	switch (this.value){
		case 'American Express':
			$('#CardCardNumber').attr('maxlength', '15');
			$('#CardCardNumber').attr('minlength', '15');
			$('#required_digits').text('(15 digits)');
			
			$('#CardCvcNumber').attr('maxlength', '4');
			$('#CardCvcNumber').attr('minlength', '4');
			$('#required_cvc_digits').text('(4-digit code on front of card)');
			break;
		
		default:
			$('#CardCardNumber').attr('maxlength', '16');
			$('#CardCardNumber').attr('minlength', '16');
			$('#required_digits').text('(16 digits)');
			
			$('#CardCvcNumber').attr('maxlength', '3');
			$('#CardCvcNumber').attr('minlength', '3');
			$('#required_cvc_digits').text('(3-digit code on back of card)');
			break;
	}
	
});


//*****************************************************************************************************
//Redirect Anchors send
//*****************************************************************************************************

if($('#UserAnchorValue')){
	anchor = location.href.split('#');
	if(anchor){
		$('#UserAnchorValue').val(anchor[1]);
	}
}

if ($('a.fancy_open').length){
	$('a.fancy_open').fancybox();
}	



//*****************************************************************************************************
//Stuff Members checkbox
//*****************************************************************************************************

$('#StaffMemberAddForm #AgreementAdministrativeStaffMember').click(function() {
//	
	
	if($(this).attr('checked')){
		inputs = $('#StaffMemberAddForm .required');
		inputs.each(function(){
			$(this).addClass('required_blank').removeClass('required');
		});
	} else {
		inputs = $('#StaffMemberAddForm .required_blank');
		inputs.each(function(){
			$(this).addClass('required').removeClass('required_blank');
		});
	}
});

//*****************************************************************************************************
//My Goals Details
//*****************************************************************************************************
/*
$("a.goal_details_show").click(function(){
	
	$(this).next("div.goal_details").slideToggle("slow").siblings("div.goal_details:visible").slideUp("slow");

});
*/

//*****************************************************************************************************
//IE Anchors Fix
//*****************************************************************************************************


$('a[href*=#]').click(function() {
	if($(this).parent().attr('class')=='scrollable_navigation' || $(this).attr('href').indexOf('javascript')>-1) return;
	var duration=50;
	var easing='swing';
	var newHash=this.hash;
	var oldLocation=window.location.href.replace(window.location.hash, '');
	var newLocation=this;
	if(oldLocation+newHash==newLocation)
	{
		var target=$(this.hash+', a[name='+this.hash.slice(1)+']').offset().top;
		if(target > $(document).height()-$(window).height()) target=$(document).height()-$(window).height();			
		if($.browser.safari) var animationSelector='body:not(:animated)';
		else var animationSelector='html:not(:animated)';
		$(animationSelector).animate({ scrollTop: target }, duration, easing, function() {
			window.location.href=newLocation;
		});
		return false;
	}
});


$("#topcontrol").css("position", "absolute");

$('#topcontrol').click(function() {
	window.location.href='#';
	the_scroll = $(window).height() - 65;
	$("#topcontrol").css("top", the_scroll + "px");
});

$(window).scroll(function() {
	the_scroll = $(window).height() - 65 + $(window).scrollTop();
    $("#topcontrol").css("top", the_scroll + "px");
});

}); })(jQuery);


