

	// Fire once the document is ready.
	$(document).ready(function() {
		var emailText	= "Your comments here...";

		$("#navigateHead > div").click(function(){
			navigate([this.id]);
		});

		// form values
		$("#emailBody").focus(function() {
			if ( $(this).val() == emailText ) {
				$(this).val("");
			}
		});
		$("#emailBody").blur(function() {
			if ( $(this).val() == "" ) {
				$(this).val(emailText);
			}
		});
		$("#emailBody").trigger("blur");

		// set click events to buttons
		$("#buttonSubmit").click(function(){
			$("input[@name=event]").val( "contact" );
			$("#formMain").submit();
			return true;
		});

		$("#formMain").submit(function(){
			var success		= true;
			if ( $("input[@name=event]").val() == "contact" )
			{
				// validate content
				var mesg	= "";
				if ( $("#emailBody").val() == emailText ) {
					mesg	+= "  - Please type a valid message\n";
				}
				if ( $("#email").val() == "" ) {
					mesg	+= "  - Please enter your email address\n";
				}
				if (mesg != "") {
					alert("I'm sorry, this form cannot be submitted without the following:\n"+mesg);
					success	= false;
				}
				$("input[@name=task]").val("CONTACT");
			}
			else if ( $("input[@name=event]").val() == "addGuess" )
			{
				// validate content
				var mesg	= "";
				if ( $("#selectGender").val() == "" ) {
					mesg	+= "  - Please select the babies' gender\n";
				}
				if ( $("#inputName").val() == "" ) {
					mesg	+= "  - Please enter your name\n";
				}
				if ( $("#selectLbs").val() == "" ) {
					mesg	+= "  - Please select the birth wieght in pounds\n";
				}
				if ( $("#selectOzs").val() == "" ) {
					mesg	+= "  - Please select the birth wieght in ounces\n";
				}
				if (mesg != "") {
					alert("I'm sorry, this form cannot be submitted without the following:\n"+mesg);
					success	= false;
				}
				else {
					success	= confirm("Are you sure you want to submit the following guess?"
						+ "\nGender: " + ($("#selectGender").val() == "F" ? "Female" : "Male")
						+ "\nBirthdate: " + $("#inputCalendar").val()
						+ "\nWeight: " + $("#selectLbs").val() + " lbs " + $("#selectOzs").val() + " oz"
						+ "\nYour Name: " + $("#inputName").val()
					);
				}
			}
			if ( ! success ) {
				$("input[@name=event]").val( "" );
			}
			return success;
		});
	});

