$(document).ready(function() {

	$(".noLda").attr('target','_blank');
	
	$('textarea[maxlength].textLimit').keyup(function(){
		var max = parseInt($(this).attr('maxlength'));
		if($(this).val().length > max){
			$(this).val($(this).val().substr(0, $(this).attr('maxlength')));
		}

		$(this).parent().find('.charsRemaining').html('You have ' + (max - $(this).val().length) + ' characters remaining');
	});
	
	/* Zero date field */
	
		$.fn.populate = function() {
		this.each(function(){
			this.value = $(this).prev('label').text();
		});	
		return this.focus(function() {
		
		if( this.value == $(this).prev('label').html() ) {
			this.value = "";
		}
		}).blur(function() {
			if( !this.value.length ) {
				this.value = $(this).prev('label').html();
		}
		});
	};
 
	$('.dateTimeInput input').populate();
	$('.dateTimeInput label.dateLabel').hide();
	
	/* Zero form data */
	
	$.fn.zero = function() {
		return this.focus(function() {
			if( this.value == this.defaultValue ) {
				this.value = "";
			}
		}).blur(function() {
			if( !this.value.length ) {
				this.value = this.defaultValue;
			}
		});
	};
	
	$(".formZero").zero();
	
	$('#discoveredExtraYes, #discoveredExtraNo').hide();
	
	$("#discoveredQuestion input[name=discovered]").change(function() {
		switch($(this).val()) {
			case 'Yes':
				$('#discoveredExtraYes').show();
				$('#discoveredExtraNo').hide();
				break;
			case 'No':
				$('#discoveredExtraNo').show();
				$('#discoveredExtraYes').hide();
				break;
			default:
				$('#discoveredExtraYes').show();
				break;
		}
	
	});
	
	/*$("form#registerForm input[name=contact_post]").change(function() {
		if ($(this).is(':checked')) { 
			$('#registerAddress').show();
		} else {
			$('#registerAddress').hide();
		}
	});
	
	$("form#registerForm input[name=contact_phone]").change(function() {
		if ($(this).is(':checked')) { 
			$('#registerPhone').show();
		} else {
			$('#registerPhone').hide();
		}
	});*/
		
});