$(document).ready(function(){


	$("input[value='range']").click(function(){
		if(!$("#newInputs").length) {
			var newInputs = '<div id="newInputs">&nbsp;&nbsp;to&nbsp;&nbsp;<input type="text" name="day2" class="day-input"/>'
							+ '<input type="text" name="month2" class="month-input"/>'
							+ '<input type="text" name="year2" class="year-input"/></div>';
			$("td#dates").append(newInputs);
		}
	});

	$("input[value='day']").click(function(){
		$("#newInputs").remove();
	});


	$("input.day-input, input.month-input, input.year-input")
	.focus(function(){
		if ($(this).val()=='Day' || $(this).val()=='Month' || $(this).val()=='Year')
		{
			$(this).val('');
		}
	})
	.blur(function(){
		if ($(this).val()=='')
		{
			var inputClass = $(this).attr('class');
			if (inputClass=='day-input')
			{
				$(this).val('Day');
			}
			if (inputClass=='month-input')
			{
				$(this).val('Month');
			}
			if (inputClass=='year-input')
			{
				$(this).val('Year');
			}
		}
	});

	$("form")
	.submit(function(event){
		var emptyFieldsExist = false;
		$("form input, form textarea").each(function(){
			if ($(this).val()=='')
			{
				emptyFieldsExist=true;
			}
		});
		if (emptyFieldsExist)
		{		 
			alert("You must completely fill in all form fields.");
			event.preventDefault();
		}
	});

});



