jQuery(document).ready(function($) {
	
	// JGEF MODAL
	
	$("#jamAlert").jqm({
		trigger: $('a[href*="jubakfund.com"]'),
		ajax: '/jgef-modal-alert',
		onLoad:jamURL
	});
	
	
	// if ($('.section-home .video a')) {
	// 	$("#video-window").jqm({
	// 		trigger: $('.section-home .video a'),
	// 		ajax: '@href'
	// 	});
	// }
	
	var myOpen=function(hash){ 
		var url = $(hash.t).attr('href') + ' #post-content';
		$('#video-window').load(url);
	}; 
	
	
	$(".snapshot .tab a").click(function() {
		$('.chart').hide();
		$('.snapshot .active').removeClass('active');
		$(this).addClass('active');
		$($(this).attr('href')).show();
		return false;
	});
	
	
	$(".sidebar #s").val($("label[for=s]").text());
	$(".sidebar #s").focus(function() {
		if ($(this).val() == $("label[for=s]").text()) {
			$(this).val("");
		}
	}).blur(function() {
		if ($(this).val() == "") {
			$(this).val($("label[for=s]").text());
		}
	});
	
	
	
	
	// BROKERAGE NOTIFICATION FORM
	// 
	// $("#broker-request").submit(function() {
	// 	
	// 	// run validation here
	// 	var error = false;
	// 	var errorMsg = "";
	// 	var errorEls = new Array();
	// 	$(".formErrors").remove();
	// 	
	// 	if ($("#broker").attr('checked') == false) {
	// 		error = true;
	// 	}
	// 	
	// 
	// 	if (($("#broker").attr("checked") == true) && (undefined === $("input[name='broker-value']:checked").val())) {
	// 		error = true;
	// 		errorMsg += '<span class="error">Please enter a broker, or select one from the list.</span>';
	// 		errorEls.push("#broker-options");
	// 	}
	// 	
	// 	if (($("#broker-value-other").attr("checked") == true) && ($("#broker-value-other-string").val() == "")) {
	// 		error = true;
	// 		errorMsg += '<span class="error">Please enter a broker, or select one from the list.</span>';
	// 		errorEls.push('#broker-value-other-string');
	// 	}
	// 	
	// 	if (($("#emailme").attr("checked") == true) && (!validEmail($("#email-address")))) {
	// 		error = true;
	// 		errorMsg += '<span class="error">Please enter a valid email address.</span>';
	// 		errorEls.push("#email-address");
	// 	}
	// 	
	// 	console.log(error);
	// 	if (error) {
	// 		// form had errors.. display them
	// 		
	// 		$("#broker-request").prepend('<div class="formErrors">'+errorMsg+'</div>');
	// 		
	// 	} else {
	// 		// form is cool.. submit the form!
	// 
	// 		$(".formErrors").remove();
	// 
	// 		// ajax submission
	// 		$u = $(this).attr('action');
	// 		$.post($u, $(this).serialize(), function(data) {
	// 
	// 			$("#broker-request").closest('.post').append(data);
	// 			$("#broker-request").fadeOut(function() {
	// 				$(".response").fadeIn();
	// 			});
	// 
	// 			$('.refreshform').click(function() {
	// 				$(".response").fadeOut(function() {
	// 					$("#broker-request").fadeIn(function() {
	// 						$(".response").remove();
	// 					});
	// 				});
	// 				return false;
	// 			});
	// 
	// 			console.log(data);
	// 		});
	// 		
	// 	}
	// 	
	// 
	// 	
	// 	return false;
	// });
	// 
	
	
});



/*
Count down until any date script-
By JavaScript Kit (www.javascriptkit.com)
Over 200+ free scripts here!
*/

//change the text below to reflect your own,
var before="<p id=\"countdown-descr\">Our first-quarter performance data will be released in:</p>"
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

function countdown(yr,m,d){
	theyear=yr;themonth=m;theday=d
	var today=new Date()
	var todayy=today.getYear()
	if (todayy < 1000)
		todayy+=1900
	var todaym=today.getMonth()
	var todayd=today.getDate()
	var todayh=today.getHours()
	var todaymin=today.getMinutes()
	var todaysec=today.getSeconds()
	var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
	futurestring=montharray[m-1]+" "+d+", "+yr
	dd=Date.parse(futurestring)-Date.parse(todaystring)
	dday=Math.floor(dd/(60*60*1000*24)*1)
	dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
	dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
	dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
	
	
	if(dday==0&&dhour==0&&dmin==0&&dsec==1){
		$('#date').html(current);
		return
	} else {

		if (dday < 10) {
			dday = "0"+dday;
		} else { dday = dday.toString(); }
		if (dhour < 10) {
			dhour = "0"+dhour;
		} else { dhour = dhour.toString(); }
		if (dmin < 10) {
			dmin = "0"+dmin;
		} else { dmin = dmin.toString(); }


		var dday_out = dhour_out = dmin_out = '';
		for (var i = 0; i < dday.length; i++) {
			dday_out += '<span class="digit">'+dday.charAt(i)+'</span>';
		}
		for (var i = 0; i < dhour.length; i++) {
			dhour_out += '<span class="digit">'+dhour.charAt(i)+'</span>';
		}
		for (var i = 0; i < dmin.length; i++) {
			dmin_out += '<span class="digit">'+dmin.charAt(i)+'</span>';
		}

		var out_d = '<span class="countdown dd rem_'+dday+'">'+dday_out+'<span class="label">DAYS</span></span>';
		var out_h = '<span class="countdown hh rem_'+dhour+'">'+dhour_out+'<span class="label">HOURS</span></span>';
		// var out_m = '<span class="countdown mm rem_'+dmin+'">'+dmin_out+'<span class="label">MINUTES</span></span>';

		$("#countdown-descr").remove();
		$('#date').before(before);
		$('#date').html(out_d+out_h);
		
	}
	setTimeout("countdown(theyear,themonth,theday)",60000)
}
//enter the count down date using the format year/month/day



function validEmail(e){
	 var regex =  /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+$/;
	 email = $(e).val();
	 if(email.match(regex)){
		 return true;
	 } else {
		 return false;
	 }
}

function jamURL(hash) {
	var d = $(hash.t).attr('href');
	$(hash.w).find('a[href*="jubakfund.com"]').attr('href',d);
}


function getVideo(u) {
	var url = u + ' #post-content';
	$('#video-window').load(url);
}


function validPlatform(platform, c) {
	switch(platform) {
		case 'vanguard':
			regex = /^\d{8,}$/;
			break;
			
		case 'schwab':
			regex = /^\d{3}$/;
			break;
			
		default:
			regex = -1;
			break;
	}
	
	if (regex != -1) {
		var code = $(c).val();
		if (code.match(regex)) {
			return true;
		} else {
			return false;
		}
	}
	
	return true;
	
}


function validTradeDate(platform, c) {
	switch(platform) {
		case 'schwab':
			regex = /^(0[1-9]|1[012])[\- \/.](0[1-9]|[12][0-9]|3[01])[\- \/.](19|20)\d\d$/;
			break;
			
		default:
			regex = -1;
			break;
	}
	
	if (regex != -1) {
		var code = $(c).val();
		if (code.match(regex)) {
			return true;
		} else {
			return false;
		}
	}
	
	return true;
}

