// Honors Program

$(document).ready(function(){
	
		
			function customRsvErrorHandler(f, errorInfo){
			// f is the form node being submitted
			// errorInfo is an array of errors defined by RSV
			var errorNode = document.getElementById(this.errorTargetElementId);
			$(errorNode).html("<ol></ol>");
			for (var i=0; i< errorInfo.length; i++)
			{

				$(errorInfo[i][0]).addClass("rsvError");
				
				// appends error message to errorTargetElementId
				$("ol", errorNode).append("<li>" + errorInfo[i][1] + "</li>") ;

			}
			$(errorNode).show();
			// here I bold the labels of the inputs that need attention
			$("li:has(.rsvError) label").css("font-weight", "bold");

	
			$(".rsvError").change(function(){
				$(this).removeClass("rsvError");
			});

			// here we expand the parts of the form that have errors, if they are collapsed
			$(".collapsed:has(.rsvError) legend").trigger("click");
		
			// you could collapse all the parts that do not have errors

			$(".expanded:not(:has(.rsvError)) legend").trigger("click");
			
			//return true if there were no errors
			return (errorInfo.length == 0) ? true : false;
		}
		
			// Make it pretty
			$('#honors-program-apply').prettyForms({formStyle: 'admission', adjustLegends: true}); //
			// Provide validation
			$('#honors-program-apply').RSV(
			{
		customErrorHandler: customRsvErrorHandler,
			errorFieldClass: "error-field"
			,displayType: "display-html"
			,errorTargetElementId: "rsv-errors"
			,errorTextIntro: "<b>Please fix the following errors and re-submit.</b>"
			,rules:  [
					"required,fname,Please enter your first name.",
					"required,lname,Please enter your last name.",
					"required,email,Please enter your email address.",
					"required,address1,Please enter the address you live at.",
					"required,city,Please enter the city you live in.",
					"required,state,Please enter the state you live in.",
					"required,zipCode,Please enter your zipcode.",
					"required,personalEssay,You must provide your essay.",
					"valid_email,email,Please enter a valid email address."
				]
			
			});
	});
