$( function() {
	
	// requires jquery + jquery masked input plugin
	$.mask.definitions['d'] = '[0123]';
	$.mask.definitions['m'] = '[01]';
	$.mask.definitions['y'] = '[12]';
	$.mask.definitions['z'] = '[90]';
	
	dobRemask = (function(){return function(){$(':input.dateOfBirth').not('.masked').addClass('masked').mask("d9/m9/yz99").blur( function() {
		if( $(this).val() == '') $(this).val( 'dd/mm/yyyy');
	//	console.log( $(this).val());
	}).css('width', '8em').each( function(i,n) {
		if( $(n).val() == '') $(n).val('dd/mm/yyyy');
	});}})();
	
	// on page load
	dobRemask();
	
	// try to attach to form?
	// oh yeah, forms might not have a class might they? durrrrrrr
	var classes = $(':input.dateOfBirth').eq(0).parents('form').attr('class');

	classes && $( classes.split(' ')).each( function(i,n) {
		if( typeof(n) == 'string' && $('form.'+n).length && $('form.'+n).find(':input.dateOfBirth').length ) {
			if( window[n] && window[n].add && typeof( window[n].add == 'function') && !window[n].add_orig) {
				window[n].add_orig = window[n].add;
				window[n].add = function() {
					this.add_orig.apply( this, arguments);
					dobRemask();
				}
			}
 		}
 	});
	
});
