// include SPECIFIC PAGE LEVEL SCRIPTS 
document.write('<script src="assets/plugins/jquery-validation/dist/jquery.validate.min.js" type="text/javascript"></script>');

/////////////////////////////////////
jQuery(document).ready(function() {
	App.init();
	$('a[data-toggle="tab"]').on('shown', function(e) {
		e.target // activated tab
		e.relatedTarget // previous tab
	});

	$('#customer-form').validate({
		ignore: "",
		errorElement: 'label', //default input error message container
//            errorClass: 'help-block', // default input error message class
		focusInvalid: false, // do not focus the last invalid input
		rules: {
			customer_type: "required",
			customer_firstname: "required",
			customer_lastname: "required",
			customer_tel: "required",
			customer_email: {
				"required": true,
				"email": true
			}
		},
		messages: {
			customer_type: 		"Veuillez choisir un Type.",
			customer_firstname: "Veuillez entrer le Prénom du client.",
			customer_lastname: 	"Veuillez entrer le Nom du client.",
			customer_tel: 		"Veuillez entrer le N° Tel du client.",
			customer_email: {
								"required": "Veuillez entrer l'adresse email du client.",
								"email": "Veuillez entrer une adresse email valide."
							}
		},
		invalidHandler: function(event, validator) { //display error alert on form submit   
			// $('.alert-danger', $('#customer-form')).show();

		},
		highlight: function(element) { // hightlight error inputs
			$(element).closest('.form-group').addClass('has-error'); // set error class to the control group

			if ($(".tab-content").find("div.tab-pane.active:has(div.has-error)").length == 0)
			{
				$(".tab-content").find("div.tab-pane:hidden:has(div.has-error)").each(function() {
					var id = $(this).attr("id");
					console.log(id);
					$('.nav-tabs a[href="#' + id + '"]').tab('show');
				});
			}
		},
		success: function(label) {
			var a = label.closest('.form-group');
			label.closest('.form-group').removeClass('has-error');
			label.remove();
		},
		errorPlacement: function(error, element) {
			//error.insertAfter(element.closest('.input-icon'));
			error.appendTo(element.parent("div"));
		}
	});
});