var toggleTripAdminModules = function () {
    $('#editTripButton').click(function(e) {
        e.preventDefault();
        $('.staticInfo').toggle();
        $('.dynInfo').toggle();        
    });
};

var addTripFormValidation = function () {
	// validate the blogPostingForm when it is submitted
	
	// make whereTo field empty if there's a grayed out fillertext in it, so validation works
	$("#tripPlannerForm").submit(function(e){
		if ($("#whereTo").val() == $("#whereTo")[0].title) {
			$("#whereTo").val("");
		}
		if ($("#fromWhere").val() == $("#fromWhere")[0].title) {
			$("#fromWhere").val("");
		}
	});
	
	// add validation rules
	$("#tripPlannerForm").validate({
		rules: {
		    fromWhere: {
				required: true,
				minlength: 5,
				maxlength: 50
			},
			whereTo: {
				required: true,
				minlength: 5,
				maxlength: 50
			},
			tripDescription: {
				required: true,
				minlength: 20,
				maxlength: 35000
			},
			beginDate: {
				required: true,
				dateDE: true
			},
			endDate: {
				required: true,
				dateDE: true
			}
		},
		messages: {
		    fromWhere: {
				required: "Please enter trip start location",
				minlength: "Start location should be atleast 5 letters long ;)",
				maxlength: "Start location shouldn't be more than 50 letters long"
			},
			whereTo: {
				required: "Please enter trip destination",
				minlength: "Destination should be atleast 5 letters long ;)",
				maxlength: "Destination shouldn't be more than 50 letters long"
			},
			tripDescription: {
				required: "Please enter some summary about that trip",
				minlength: "Trip summary should be atleast 20 letters long",
				maxlength: "Writing some kind of novel? :) It's a bit too long"
			},
			beginDate: {
			    required: "Please enter trip begin date, in form 21.07.2008"
			},
			endDate: {
			    required: "Please enter trip end date, in form 14.08.2008"
			}			
		}
	});
};

$(document).ready(function(){
    toggleTripAdminModules();
	addTripFormValidation();
});