var AdminUserFormValidation = function(){

	var i = function() {
            var e = $("#frmAdminUser"),
                r = $(".alert-danger", e),
                i = $(".alert-success", e);
            e.validate({
                errorElement: "span",
                errorClass: "help-block help-block-error",
                focusInvalid: true,
                debug: false,
                ignore: "",
                rules: {
                    firstName: {
						required: true,
                        minlength: 3,
                    },
					lastName: {
						required: true,
                        minlength: 3,
                    },
                    emailID: {
                        required: true,
						email: true
                    },
					mobileNumber:{
						required: true,
						digits: true,
						minlength: 10,
					},
					username: {
						required: true,
                        minlength: 6,
                    },
					password: {
						required: true,
                        minlength: 6,
                    },
					confirmPassword: {
						required: true,
                        minlength: 6,
						equalTo: '#password'
                    },
								
                }, 
                messages: {
					firstName:{
						required: "Please enter First Name",
						minlength: "First Name must consist of at least 3 characters"
					},
					lastName:{
						required: "Please enter Last Name",
						minlength: "Last Name must consist of at least 3 characters"
					},
			        emailID: "Please enter a valid email address",
					mobileNumber:{
						required: "Please provide mobile number.",
						digits:"Please enter a valid mobile number.",
						minlength: "Please enter 10 digit mobile number."
					},
					username:{
						required: "Please enter username",
						minlength:"Username must consist of at least 6 characters"
					},
					password:{
						required: "Please enter the password",
						minlength:"Password must consist of at least 6 characters"
					},
					confirmPassword:{
						required: "Please enter the password",
						minlength:"Password must consist of at least 6 characters",
						equalTo:  "Password & Confirm Password must be same."
					},
                   
                },
                invalidHandler: function(e, t) {
                    i.hide(), r.show();
					//App.scrollTo(r, -200);
                },
                errorPlacement: function(e, r) {
                    r.is(":checkbox") ? e.insertAfter(r.closest(".md-checkbox-list, .md-checkbox-inline, .checkbox-list, .checkbox-inline")) : r.is(":radio") ? e.insertAfter(r.closest(".md-radio-list, .md-radio-inline, .radio-list,.radio-inline")) : e.insertAfter(r)
                },
                highlight: function(e) {
                    $(e).closest(".form-md-line-input").addClass("has-error")
                },
                unhighlight: function(e) {
                    $(e).closest(".form-md-line-input").removeClass("has-error")
                },
                success: function(e) {
                    e.closest(".form-md-line-input").removeClass("has-error");

                },

                submitHandler: function(e) {
                    i.show(), r.hide();
					$.blockUI({css: { 
						border: 'none', 
						padding: '15px', 
						backgroundColor: '#000', 
						'-webkit-border-radius': '10px', 
						'-moz-border-radius': '10px', 
						opacity: .5, 
						color: '#fff' 
					},  boxed: true, message: 'Processing Form'});


					
					$.ajax({
							type        : 'POST', 
							url         : '../API/API_Admin_Users.php', 
							data        : new FormData(e),
							dataType    : 'json', 
							encode      : true,
							cache		: false,
							contentType : false,
							processData : false,
							async		: false,							
					})

					.done(function(data){
							
							window.setTimeout(function() {
								$.unblockUI();
							
								if (data.status) { 
									alert(data.message);
									location.reload();
								}

								else{
									alert(data.message);
								}

							}, 2000);

					})


					.fail(function(data){

						window.setTimeout(function() {
							$.unblockUI();
							alert("Form processing error!");
						}, 2000);

						
					});
								
			        return false;
	            }
            })
        };
    return {
        init: function() {
           i()
        }
    }
}();



var MemberProfileFormValidation = function(){

	var i = function() {
            var e = $("#frmEditProfile"),
                r = $(".alert-danger", e),
                i = $(".alert-success", e);
            e.validate({
                errorElement: "span",
                errorClass: "help-block help-block-error",
                focusInvalid: true,
                debug: false,
                ignore: "",
                rules: {
                    firstName: {
						required: true,
                        minlength: 3,
                    },
					lastName: {
						required: true,
                        minlength: 3,
                    },
					motherName: {
						required: true,
                        minlength: 3,
                    },
                    emailID: {
                        required: true,
						email: true
                    },
					mobileNumber:{
						required: true,
						digits: true,
						minlength: 10,
					},
					username: {
						required: true,
                        minlength: 6,
                    },
					dob:{
					  required: true,
					},
					addressLine1: {
					  required: true,
					},
					addressLine2: {
					  required: true,
					},
				    country: {
					  required: true,
					},
					zipCode: {
					  required: true,
					},
					state: {
					  required: true,
					},
					city: {
					  required: true,
					},
					newLoginPassword: {
					  required: true,
					  minlength: 6,
					},
					confirmLoginPassword: {
					  required: true,
					  minlength: 6,
        			  equalTo: '#newLoginPassword'
    				},
					txtPan: {
					  required: true,
					  regex: /^([A-Z]){5}([0-9]){4}([A-Z]){1}?$/,
					},
					addressProofInfo: {
					  required: true,
					  regex: /^([0-9]){12}?$/,
					}
			    },
				messages: {
					firstName:{
						required: "Please enter First Name",
						minlength: "First Name must consist of at least 3 characters"
					},
					lastName:{
						required: "Please enter Last Name",
						minlength: "Last Name must consist of at least 3 characters"
					},
					motherName:{
						required: "Please enter Last Name",
						minlength: "Mother Name must consist of at least 3 characters"
					},
			        emailID: "Please enter a valid email address",
					mobileNumber:{
						required: "Please provide mobile number.",
						digits:"Please enter a valid mobile number.",
						minlength: "Please enter 10 digit mobile number."
					},
					username:{
						required: "Please enter username",
						minlength:"Username must consist of at least 6 characters"
					},
					dob: "Please enter a date of birth.",
					addressLine1: {
					  required: "Please enter address line 1.",
					},
					addressLine2: {
					  required: "Please enter address line 2.",
					},
					country: {
					  required: "Please enter the country name.",
					},
					zipCode: {
					  required: "Please enter the zip code.",
					},
					state: {
					  required: "Please enter the state name.",
					},
				    city: {
					  required: "Please enter the city name.",
					},
				    newLoginPassword: {
					  required: "Please enter new password.",
  					  minlength: "Password must consist of at least 6 characters"
					},
					confirmLoginPassword: {
					  required: "Please enter the confirm password",
  					  minlength: "Password must consist of at least 6 characters",
    				  equalTo:  "Password & Confirm Password must be same."
					},
					txtPan: {
					  required: "Please enter the pan card info.",
					  regex: "Please enter a valid PAN Number."
					},
					addressProofInfo: {
					  required: "Please enter the address proof info.",
					  regex: "Please enter the valid aadhar number without using space."
					}
                   
                },
                invalidHandler: function(e, t) {
                    i.hide(), r.show();
					//App.scrollTo(r, -200);
                },
                errorPlacement: function(e, r) {
                    r.is(":checkbox") ? e.insertAfter(r.closest(".md-checkbox-list, .md-checkbox-inline, .checkbox-list, .checkbox-inline")) : r.is(":radio") ? e.insertAfter(r.closest(".md-radio-list, .md-radio-inline, .radio-list,.radio-inline")) : e.insertAfter(r)
                },
                highlight: function(e) {
                    $(e).closest(".form-md-line-input").addClass("has-error")
                },
                unhighlight: function(e) {
                    $(e).closest(".form-md-line-input").removeClass("has-error")
                },
                success: function(e) {
                    e.closest(".form-md-line-input").removeClass("has-error");

                },

                submitHandler: function(e) {
                    i.show(), r.hide();
					$.blockUI({css: { 
						border: 'none', 
						padding: '15px', 
						backgroundColor: '#000', 
						'-webkit-border-radius': '10px', 
						'-moz-border-radius': '10px', 
						opacity: .5, 
						color: '#fff' 
					},  boxed: true, message: 'Processing Form'});


					
					$.ajax({
							type        : 'POST', 
							url         : '../API/API_Admin_Users.php', 
							data        : new FormData(e),
							dataType    : 'json', 
							encode      : true,
							cache		: false,
							contentType : false,
							processData : false,
							async		: false,							
					})

					.done(function(data){
							
							window.setTimeout(function() {
								$.unblockUI();
							
								if (data.status) { 
									alert(data.message);
									location.reload();
								}

								else{
									alert(data.message);
								}

							}, 2000);

					})


					.fail(function(data){

						window.setTimeout(function() {
							$.unblockUI();
							alert("Form processing error!");
						}, 2000);

						
					});
								
			        return false;
	            }
            })
        };
    return {
        init: function() {
           i()
        }
    }
}();




var AdminUserProfileFormValidation = function(){

	var i = function() {
            var e = $("#frmUserProfile"),
                r = $(".alert-danger", e),
                i = $(".alert-success", e);
            e.validate({
                errorElement: "span",
                errorClass: "help-block help-block-error",
                focusInvalid: true,
                debug: false,
                ignore: "",
                rules: {
                    firstName:{
						required: true,
                        minlength: 3,
                    },
					lastName:{
						required: true,
                        minlength: 3,
                    },
                    emailID:{
                        required: true,
						email: true
                    },
					phone:{
						required: true,
						digits: true,
						minlength: 10,
					},
					username:{
						required: true,
                        minlength: 6,
                    }
			    },
				messages: {
					firstName:{
						required: "Please enter First Name",
						minlength: "First Name must consist of at least 3 characters"
					},
					lastName:{
						required: "Please enter Last Name",
						minlength: "Last Name must consist of at least 3 characters"
					},
					emailID:{
                        required: "Please enter email address",
						email: "Please enter a valid email address."
                    },
					phone:{
						required: "Please provide mobile number.",
						digits:"Please enter a valid mobile number.",
						minlength: "Please enter 10 digit mobile number."
					},
					username:{
						required: "Please enter username",
						minlength:"Username must consist of at least 6 characters"
					}            
                },
                invalidHandler: function(e, t) {
                    i.hide(), r.show();
					//App.scrollTo(r, -200);
                },
                errorPlacement: function(e, r) {
                    r.is(":checkbox") ? e.insertAfter(r.closest(".md-checkbox-list, .md-checkbox-inline, .checkbox-list, .checkbox-inline")) : r.is(":radio") ? e.insertAfter(r.closest(".md-radio-list, .md-radio-inline, .radio-list,.radio-inline")) : e.insertAfter(r)
                },
                highlight: function(e) {
                    $(e).closest(".form-md-line-input").addClass("has-error")
                },
                unhighlight: function(e) {
                    $(e).closest(".form-md-line-input").removeClass("has-error")
                },
                success: function(e) {
                    e.closest(".form-md-line-input").removeClass("has-error");

                },

                submitHandler: function(e) {
                    i.show(), r.hide();
					$.blockUI({css: { 
						border: 'none', 
						padding: '15px', 
						backgroundColor: '#000', 
						'-webkit-border-radius': '10px', 
						'-moz-border-radius': '10px', 
						opacity: .5, 
						color: '#fff' 
					},  boxed: true, message: 'Processing Form'});


				
				    var	apiURL = '../API/API_EditAdminUserProfile.php';

					$.ajax({
						type        : 'POST', 
						url         : apiURL, 
						data        : new FormData(e),
						dataType    : 'json', 
						encode      : true,
						cache		: false,
						contentType : false,
						processData : false,
					})

					.done(function(data){

							window.setTimeout(function() {
								$.unblockUI();
							
								if (data.status) { 
									alert(data.message);
								}

								else{
									alert(data.message);
								}

							}, 1000);


					})


					.fail(function(data){

						window.setTimeout(function() {
							$.unblockUI();
							alert("Form processing error!");
						}, 2000);

						location.reload();
						
					});
								
			        return false;
	            }
            })
        };
    return {
        init: function() {
           i()
        }
    }
}();




var  AdminUserPasswordFormValidation = function(){

	var i = function() {
            var e = $("#frmUserPassword"),
                r = $(".alert-danger", e),
                i = $(".alert-success", e);
            e.validate({
                errorElement: "span",
                errorClass: "help-block help-block-error",
                focusInvalid: true,
                debug: false,
                ignore: "",
                rules: {
                    currentPassword:{
					  required: true,
					  minlength: 6,
					},
					newPassword:{
					  required: true,
					  minlength: 6,
    				},
					confirmPassword:{
					  required: true,
					  minlength: 6,
        			  equalTo: '#newPassword'
    				}
			    },
				messages: {
					currentPassword:{
					  required: "Please enter new password.",
  					  minlength: "Password must consist of at least 6 characters"
					},
					newPassword:{
					  required: "Please enter new password.",
  					  minlength: "Password must consist of at least 6 characters",
					},
					confirmPassword:{
					  required: "Please enter the confirm password",
  					  minlength: "Password must consist of at least 6 characters",
    				  equalTo:  "Password & Confirm Password must be same."
					}
                   
                },
                invalidHandler: function(e, t) {
                    i.hide(), r.show();
					//App.scrollTo(r, -200);
                },
                errorPlacement: function(e, r) {
                    r.is(":checkbox") ? e.insertAfter(r.closest(".md-checkbox-list, .md-checkbox-inline, .checkbox-list, .checkbox-inline")) : r.is(":radio") ? e.insertAfter(r.closest(".md-radio-list, .md-radio-inline, .radio-list,.radio-inline")) : e.insertAfter(r)
                },
                highlight: function(e) {
                    $(e).closest(".form-md-line-input").addClass("has-error")
                },
                unhighlight: function(e) {
                    $(e).closest(".form-md-line-input").removeClass("has-error")
                },
                success: function(e) {
                    e.closest(".form-md-line-input").removeClass("has-error");

                },

                submitHandler: function(e) {
                    i.show(), r.hide();
					$.blockUI({css: { 
						border: 'none', 
						padding: '15px', 
						backgroundColor: '#000', 
						'-webkit-border-radius': '10px', 
						'-moz-border-radius': '10px', 
						opacity: .5, 
						color: '#fff' 
					},  boxed: true, message: 'Processing Form'});


				
					var apiURL = '../API/API_ChangeAdminUserPassword.php';


					$.ajax({
						type        : 'POST', 
						url         : apiURL, 
						data        : new FormData(e),
						dataType    : 'json', 
						encode      : true,
						cache		: false,
						contentType : false,
						processData : false,
					})

					.done(function(data){
							
							window.setTimeout(function() {
								$.unblockUI();
							
								if (data.status) { 
									alert(data.message);
									location.reload();
								}

								else{
									alert(data.message);
								}

							}, 2000);

					})


					.fail(function(data){

						window.setTimeout(function() {
							$.unblockUI();
							alert("Form processing error!");
						}, 2000);

						
					});
								
			        return false;
	            }
            })
        };
    return {
        init: function() {
           i()
        }
    }
}();


//Member Purchase Form Validation
var  MemberPurchaseFormValidation = function(){

	var i = function() {
            var e = $("#frmPurchase"),
                r = $(".alert-danger", e),
                i = $(".alert-success", e);
            e.validate({
                errorElement: "span",
                errorClass: "help-block help-block-error",
                focusInvalid: true,
                debug: false,
                ignore: "",
                rules: {
                    memberID:{
					  required: true,
					  minlength: 9,
					},
					memberName:{
					  required: true,
                      minlength: 3,
    				}
			    },
				messages: {
					memberID:{
					  required: "Please enter Member ID.",
  					  minlength: "Member ID must consist of at least 9 characters"
					},
					memberName:{
					  required: "Please enter Member Name",
					  minlength: "Member Name must consist of at least 3 characters",
					}
                },
                invalidHandler: function(e, t) {
                    i.hide(), r.show();
					//App.scrollTo(r, -200);
                },
                errorPlacement: function(e, r) {
                    r.is(":checkbox") ? e.insertAfter(r.closest(".md-checkbox-list, .md-checkbox-inline, .checkbox-list, .checkbox-inline")) : r.is(":radio") ? e.insertAfter(r.closest(".md-radio-list, .md-radio-inline, .radio-list,.radio-inline")) : e.insertAfter(r)
                },
                highlight: function(e) {
                    $(e).closest(".form-md-line-input").addClass("has-error")
                },
                unhighlight: function(e) {
                    $(e).closest(".form-md-line-input").removeClass("has-error")
                },
                success: function(e) {
                    e.closest(".form-md-line-input").removeClass("has-error");

                },

                submitHandler: function(e) {
                    i.show(), r.hide();
					$.blockUI({css: { 
						border: 'none', 
						padding: '15px', 
						backgroundColor: '#000', 
						'-webkit-border-radius': '10px', 
						'-moz-border-radius': '10px', 
						opacity: .5, 
						color: '#fff' 
					},  boxed: true, message: 'Processing Form'});


				
					var apiURL = '../API/API_Package_Purchase.php';

					$.ajax({
						type        : 'POST', 
						url         : apiURL, 
						data        : new FormData(e),
						dataType    : 'json', 
						encode      : true,
						cache		: false,
						contentType : false,
						processData : false,
					})

					.done(function(data){
							
							window.setTimeout(function() {
								$.unblockUI();
							
								if (data.status) { 
									alert(data.message);
									location.reload();
								}

								else{
									alert(data.message);
								}

							}, 2000);

					})


					.fail(function(data){

						window.setTimeout(function() {
							$.unblockUI();
							alert("Form processing error!");
						}, 2000);

						
					});
								
			        return false;
	            }
            })
        };
    return {
        init: function() {
           i()
        }
    }
}();







jQuery(document).ready(function() {

	$("#btnSubmitAdminUser").click(function(){
		AdminUserFormValidation.init();
	});


	$("#btnEditProfile").click(function(){
		 //event.preventDefault();

			if($("#btnEditProfile").text() == "Edit")
			{
				$("#btnEditProfile").text("Save");
				$("#btnCancel").removeAttr("hidden");
				enableField();
			    return false;
			}


		   else
		   {

			  MemberProfileFormValidation.init();


		   }
	});


	$("#btnEditUserProfile").click(function(){

		 //event.preventDefault();

		if($("#btnEditUserProfile").text() == "Edit")
		{
			$("#btnEditUserProfile").text("Save");
			//$("#btnCancel").removeAttr("hidden");
			enableField();
			return false;
		}


	   else
	   {

		  AdminUserProfileFormValidation.init();


	   }
	});


	$("#btnChangeUserPassword").click(function(){
		  AdminUserPasswordFormValidation.init();
	});


	$("#btnPurchase").click(function(){
		 MemberPurchaseFormValidation.init();
	});



});


 