$(document).ready(function(){
	// Handle numeric fields
	$('.phone-input').addClass('numeric-input');
	$('.numeric-input').keypress( function(eventObject) {
		// var key = eventObject.charCode ? eventObject.charCode : eventObject.keyCode;
		var key = eventObject.which;
		if ($(this).hasClass('phone-input')) {
			// Check to see if the field is 0 length, or the carrot is at the start, and that the key is +
			if ( ($(this).val().length == 0 || eventObject.target.selectionStart == 0) && key == 43 ) {
				// Only allow one + per field
				return !$(eventObject.target).val().match(/^\+/);
			}
		}
		return ((key > 47 && key < 58) || key == 0 || key == 8 );
	});
	$('input:text.date').date_input();
});

$.extend(DateInput.DEFAULT_OPTS, {
	stringToDate: function(string) {
		var matches;
		if ( matches = string.match(/^(\d{4,4})-(\d{2,2})-(\d{2,2})$/) ) {
			return new Date(matches[1], matches[2] - 1, matches[3]);
		}
		else {
			return null;
		};
	},

	dateToString: function(date) {
		var month = (date.getMonth() + 1).toString();
		var dom   = date.getDate().toString();

		if ( month.length == 1 ) month = "0" + month;
		if ( dom.length == 1 )   dom   = "0" + dom;

		return date.getFullYear() + "-" + month + "-" + dom;
	}
});

