jQuery(document).ready(function () {

	var checkForInt = function(evt) {
	evt = ( evt ) ? evt : window.event;
	var charCode = ( evt.which ) ? evt.which : evt.keyCode;
	return (charCode==13 || charCode==8 || (charCode >= 48 && charCode <= 57));
	};
	var dashIndices = [3, 6];

	jQuery('#phoneNumberInput').attr('maxlength', 12); // 10 digits + 2 dashes

	jQuery('#phoneNumberInput').keypress(checkForInt);

	jQuery('#phoneNumberInput').keydown(function(evt) {
			
			evt = ( evt ) ? evt : window.event;
			var charCode = ( evt.which ) ? evt.which : evt.keyCode;
			
			if (charCode >= 48 && charCode <= 57 || (charCode >= 96 && charCode <= 105) ) {
				
				var number = this.value.split('-').join('');
				var size = number.length;
				
				if (size === dashIndices[0]) {
					var first = number.substring(0, dashIndices[0]);
					this.value = first + '-';
				}
				else if (size === dashIndices[1]) {
					var first = number.substring(0, dashIndices[0]);
					var second = number.substring(dashIndices[0], dashIndices[1]);
					this.value = first + '-' + second + '-';
				}
				else if (size === dashIndices[2]) {
					var first = number.substring(0, dashIndices[0]);
					var second = number.substring(dashIndices[0], dashIndices[1]);
					var third = number.substring(dashIndices[1], dashIndices[2]);
					this.value = first + '-' + second + '-' + third + '-';
				}
				
			}
			
		});




});