$(document).ready(function(){
	
	$('.datepicker').each(function (i) {
		var altField =  '#' + $(this).attr('name').replace('_selector','');
		$(this).datepicker({	dateFormat: 'dd/mm/yy', showOn: 'button', changeMonth: true, changeYear: true,
								altFormat: 'yy-mm-dd', altField: altField, yearRange: '1900:2050',
								buttonText: 'Press to choose date'});
	});
	
	$(".datepicker").keypress(function (e) {
		e.preventDefault();
	});
	
	$('.datepicker-v2').each(function (i) {
		var altField = '#' + $(this).attr('data-alt-field');
		$(this).datepicker({	dateFormat: 'dd/mm/yy', showOn: 'button', changeMonth: true, changeYear: true,
								altFormat: 'yy-mm-dd', altField: altField, yearRange: '1900:2050',
								buttonText: 'Press to choose date'});
	});

	$(".datepicker-v2").keypress(function (e) {
		e.preventDefault();
	});
	
	$("input:text:visible:first").focus();
	/*
	$('.datepicker_signup').datepicker({	dateFormat: 'dd/mm/yy', showOn: 'button', changeMonth: true, changeYear: true,
											altFormat: 'yy-mm-dd', yearRange: '1900:2050', constrainInput: true,
											buttonText: 'Press to choose date', altField: '#dob'});
	*/
	$('.numeric_only').keyup(function () { 
		this.value = this.value.replace(/[^0-9\.]/g,'');
	});
	
	$('.phone_prefix').keyup(function () {
		var max_size = $(this).attr('maxlength');
		if (this.value.length >= max_size) {
			$(this).next("input").focus();
		}
	});
	
	$('.toggle_enrolment_unit_trigger').click(function() {
		var state = ($(this).html() == 'Show Units') ? 'show' : 'hide';

		var enrolment_course_id = $(this).attr('id').replace('toggle_enrolment_course_','');
		var toggle_class = '.toggle_enrolment_course_unit_' + enrolment_course_id;
		
		if (state == 'show') {
			$(toggle_class).show();
			$(this).html('Hide Units');
		} else {
			$(toggle_class).hide();
			$(this).html('Show Units');
		}
	});
	
	/*
	$('li').each(function(index) {
		alert(index + ': ' + $(this).text());
	});
	*/
});
