/* Javascript for:
Client ; ValuationsUK Form */

//1 Wait until the document is ready begin program
$(function(){

	//2 enable $.validation on the specified form
	//2.1 Check all fields are completed and
	//2.2 Check the data in the fields is valid
	$("#myform").validate({
	//3 Use AJAXsubmit to pass this data to the PHP file
		submitHandler: function(form) {
			$(form).ajaxSubmit({ 
        		target:        '.status',	// target element(s) to be updated with server response 
        		resetForm:		true,			//reset form when submit is sucessful
        		success: function() {$(".status").removeClass("fail").addClass("success");} //function to change status from red to green on success
			})
		},
		/*onfocusout: false,*/
		showErrors: function(errorMap, errorList) {
			$(".status").html("<p>" + this.numberOfInvalids() + "  fields are awaiting your details.</p>");
			this.defaultShowErrors();
		},
		success: function(label) {
     		label.parent('p').removeClass('error');
   		},
  		errorPlacement: function(error, element) {
  			$(".status").addClass("fail");
     		error.appendTo( element.parent("p") );
     		$(element).parent().addClass("error");
   		}
	});
});