+function($) {
	"use strict";

	var ncsaSection = $("#ncsaSection");
	var studentProfile = $("#studentProfile");
	var parentProfile = $("#parentProfile");
	var ncsaOptInToggle = $("#allowNCSAOptIn").val();
	var castudentProfile = $("#CAstudentProfile");
    var caparentProfile = $("#CAparentProfile");
    var caOptInToggleP = $("#allowCAOptInP").val();
    var caOptInToggleS = $("#allowCAOptInS").val();
	var angOptInToggle = $("#allowAngOptIn").val();
	var armyNGOptInToggle = $("#allowArmyNGOptIn").val();
	var collegeVineOptInToggle = $("#allowCollegeVineOptIn").val();
	var optIntelligenceToggle = $("#allowOptIntelligence").val();
	var showNCSAOptIn = ncsaOptInToggle;
	var showCAOptInP = caOptInToggleP;
	var showCAOptInS = caOptInToggleS;
	var showANGOptIn = angOptInToggle;
	var showArmyNGOptIn = armyNGOptInToggle;
	var showCollegeVineOptIn = collegeVineOptInToggle;
	var showOptIntelligence = optIntelligenceToggle;
	var myUserRole = '';

	function toggleProfileByUserRole() {
		// myUserRole = $("#myUserRole").val();
		myUserRole = $("input[name='userRole']:checked").val();

		if (myUserRole == "student") {
			showNCSAOptIn = 1;
			showCAOptInS=1;
			showANGOptIn = 1;
			showArmyNGOptIn = 1;
			showCollegeVineOptIn = 0;
			showOptIntelligence = 0;
			toggleProfileForStudent();
		}
		else if (myUserRole == "coach") {
			showANGOptIn = 0;
			showArmyNGOptIn = 0;
			showCollegeVineOptIn = 0;
			showOptIntelligence = 0;
			toggleProfileForCoach();
		}
		else if (myUserRole == "parent") {
			showNCSAOptIn = 1;
			showCAOptInP=1;
			showANGOptIn = 1;
			showArmyNGOptIn = 1;
			showCollegeVineOptIn = 1;
			showOptIntelligence = 1;
			toggleProfileForParent();
		}
		else if (myUserRole == "fan") {
			showNCSAOptIn = 1;
			showANGOptIn = 1;
			showArmyNGOptIn = 1;
			showCollegeVineOptIn = 1;
			showOptIntelligence = 0;
			toggleProfileForFan();
		}else{
			$("#ncsaOptInFormGroup").hide().find(":input").prop("disabled", true).prop("required", false);
			$("#caOptInFormGroup").hide().find(":input").prop("disabled", true).prop("required", false);
			$("#angOptInFormGroup").hide().find(":input").prop("disabled", true).prop("required", false);
			$("#armyNGOptInFormGroup").hide().find(":input").prop("disabled", true).prop("required", false);
			//$("#collegeVineOptInFormGroup").hide().find(":input").prop("disabled", true).prop("required", false);
			//$("#collegeVineSATOptInFormGroup").hide().find(":input").prop("disabled", true).prop("required", false);
			$("#mygraduationYear").prop("required", false);
		}

		$("#First-next").html("Next");
		$("#First-next").val("Next");
		$(".last-bubble").removeClass("hide");
		$("#bubble2").removeClass("hide");
		$("#progressbar #bubble1").removeClass("laststep");
	}

	function toggleProfileForStudent() {
		$('#grad_postal_div').css({'margin-top': '0px'});
		$('.stu-text').removeClass('d-none');
		$('.parent-text').addClass('d-none');

		$("#myGraduationYearFormGroup").show().find(":input").prop("disabled", false);
		$("#mySportIDFormGroup").show().find(":input").prop("disabled", false);
		$("#fanProfileColumn").removeClass("col-md-12").addClass("col-md-6");
		studentProfile.hide().find(":input").prop("disabled", true);
		$("#myRelationshipFormGroup").hide().find(":input").prop("disabled", true);
		parentProfile.show().find(":input").prop("disabled", false);
		$("#studentNCSAtext").show();
		$("#parentNCSAtext").hide();
		if(showNCSAOptIn == 1 && ncsaOptInToggle == 1){
			$("#ncsaOptInFormGroup").show().find(":input").prop("disabled", false).prop("required", true);
		}else{
			$("#ncsaOptInFormGroup").hide().find(":input").prop("disabled", true).prop("required", false);
		}


		castudentProfile.hide().find(":input").prop("disabled", true);
		caparentProfile.show().find(":input").prop("disabled", false);
		$("#studentCAtext").show();
		$("#parentCAtext").hide();
		if(showCAOptInS == 1 && caOptInToggleS == 1){
			$("#caOptInFormGroup").show().find(":input").prop("disabled", false).prop("required", true);
		}else{
			$("#caOptInFormGroup").hide().find(":input").prop("disabled", true).prop("required", false);
		}

		$("#studentANGtext").show();
		$("#parentANGtext").hide();
		if(showANGOptIn == 1 && angOptInToggle == 1){
			$("#angOptInFormGroup").show().find(":input").prop("disabled", false).prop("required", true);
		}else{
			$("#angOptInFormGroup").hide().find(":input").prop("disabled", true).prop("required", false);
		}

		$("#studentArmyNGtext").show();
		$("#parentArmyNGtext").hide();
		if(showArmyNGOptIn == 1 && armyNGOptInToggle == 1){
			$("#armyNGOptInFormGroup").show().find(":input").prop("disabled", false).prop("required", true);
		}else{
			$("#armyNGOptInFormGroup").hide().find(":input").prop("disabled", true).prop("required", false);
		}
		$("#studentCollegeVinetext").hide();
		$("#parentCollegeVinetext").hide();
		$("#studentCollegeVineSATtext").hide();
		$("#parentCollegeVineSATtext").hide();
		if(showCollegeVineOptIn == 1 && collegeVineOptInToggle == 1){
			$("#collegeVineOptInFormGroup").show().find(":input").prop("disabled", false).prop("required", true);
			$("#collegeVineSATOptInFormGroup").show().find(":input").prop("disabled", false).prop("required", true);
		}else{
			$("#collegeVineOptInFormGroup").hide().find(":input").prop("disabled", true).prop("required", false);
			$("#collegeVineSATOptInFormGroup").hide().find(":input").prop("disabled", true).prop("required", false);
		}
		$("#mygraduationYearSelection").show();
    $("#mygraduationYear").prop("required", false);
		$("#IsGraduationYearRequired").hide();
		$("#optIntelligenceFormGroup").hide();
	}

	function toggleProfileForCoach() {
		$("#myGraduationYearFormGroup").hide().find(":input").prop("disabled", true);
		$("#mySportIDFormGroup").hide().find(":input").prop("disabled", true);
		$("#fanProfileColumn").removeClass("col-md-6").addClass("col-md-12");
		studentProfile.hide().find(":input").prop("disabled", true);
		castudentProfile.hide().find(":input").prop("disabled", true);
		$("#myRelationshipFormGroup").hide().find(":input").prop("disabled", true);
		parentProfile.hide().find(":input").prop("disabled", true);
		caparentProfile.hide().find(":input").prop("disabled", true);
		$('#grad_postal_div').css({'margin-top': '70px'});
		$('.stu-text').addClass('d-none');
		$('.parent-text').addClass('d-none');

		$("#ncsaOptInFormGroup").hide().find(":input").prop("disabled", true).prop("required", false);
		$("#caOptInFormGroup").hide().find(":input").prop("disabled", true).prop("required", false);
		$("#angOptInFormGroup").hide().find(":input").prop("disabled", true).prop("required", false);
		$("#armyNGOptInFormGroup").hide().find(":input").prop("disabled", true).prop("required", false);
		$("#collegeVineOptInFormGroup").hide().find(":input").prop("disabled", true).prop("required", false);
		$("#collegeVineSATOptInFormGroup").hide().find(":input").prop("disabled", true).prop("required", false);
		$("#studentNCSAtext").hide();
		$("#parentNCSAtext").hide();
		$("#studentCAtext").hide();
		$("#parentCAtext").hide();
		$("#studentANGtext").hide();
		$("#parentANGtext").hide();
		$("#studentArmyNGtext").hide();
		$("#parentArmyNGtext").hide();
		$("#studentCollegeVinetext").hide();
		$("#parentCollegeVinetext").hide();
		$("#studentCollegeVineSATtext").hide();
		$("#parentCollegeVineSATtext").hide();
		$("#mygraduationYearSelection").hide();
        $("#IsGraduationYearRequired").hide();
		$("#optIntelligenceFormGroup").hide();
	}

	function toggleProfileForParent() {
		$("#myGraduationYearFormGroup").hide().find(":input").prop("disabled", true);
		$("#mySportIDFormGroup").hide().find(":input").prop("disabled", false);
		$("#fanProfileColumn").removeClass("col-md-12").addClass("col-md-6");
		studentProfile.show().find(":input").prop("disabled", false);
		$("#myRelationshipFormGroup").show().find(":input").prop("disabled", false);
		parentProfile.hide().find(":input").prop("disabled", true);
		$("#studentNCSAtext").hide();
		$("#parentNCSAtext").show();
		$('#grad_postal_div').css({'margin-top': '35px'});
		$('.stu-text').addClass('d-none');
		$('.parent-text').removeClass('d-none');

		if(showNCSAOptIn == 1 && ncsaOptInToggle == 1){
			$("#ncsaOptInFormGroup").show().find(":input").prop("disabled", false).prop("required", true);
		}else{
			$("#ncsaOptInFormGroup").hide().find(":input").prop("disabled", true).prop("required", false);
		}

        castudentProfile.show().find(":input").prop("disabled", false);
        caparentProfile.hide().find(":input").prop("disabled", true);
		$("#studentCAtext").hide();
		$("#parentCAtext").show();
		if(showCAOptInP == 1 && caOptInToggleP == 1){
			$("#caOptInFormGroup").show().find(":input").prop("disabled", false).prop("required", true);
		}else{
			$("#caOptInFormGroup").hide().find(":input").prop("disabled", true).prop("required", false);
		}


		$("#studentANGtext").hide();
		$("#parentANGtext").show();
		if(showANGOptIn == 1 && angOptInToggle == 1){
			$("#angOptInFormGroup").show().find(":input").prop("disabled", false).prop("required", true);
		}else{
			$("#angOptInFormGroup").hide().find(":input").prop("disabled", true).prop("required", false);
		}
		$("#studentArmyNGtext").hide();
		$("#parentArmyNGtext").show();
		if(showArmyNGOptIn == 1 && armyNGOptInToggle == 1){
			$("#armyNGOptInFormGroup").show().find(":input").prop("disabled", false).prop("required", true);
		}else{
			$("#armyNGOptInFormGroup").hide().find(":input").prop("disabled", true).prop("required", false);
		}
		$("#studentCollegeVinetext").hide();
		$("#parentCollegeVinetext").show();
		$("#studentCollegeVineSATtext").hide();
		$("#parentCollegeVineSATtext").show();
		if(showCollegeVineOptIn == 1 && collegeVineOptInToggle == 1){
			$("#collegeVineOptInFormGroup").show().find(":input").prop("disabled", false);
		//	$("#collegeVineSATOptInFormGroup").show().find(":input").prop("disabled", false).prop("required", true);
		}else{
			$("#collegeVineOptInFormGroup").hide().find(":input").prop("disabled", true);
		//	$("#collegeVineSATOptInFormGroup").hide().find(":input").prop("disabled", true).prop("required", false);
		}
		$("#mygraduationYearSelection").show();
       $("#mygraduationYear").prop("required", false);
		if(($("#collegeVineOptInYes").prop("checked")) || ($("#collegeVineSATOptInYes").prop("checked"))){
			$("#IsGraduationYearRequired").show();
		}
		if(!($("#collegeVineOptInYes").prop("checked")) && !($("#collegeVineSATOptInYes").prop("checked")) && !($("#collegeVineOptInNo").prop("checked"))){
			$("#collegeVineOptInNo").prop("required", true);
		}
		if(showOptIntelligence == 1 && optIntelligenceToggle == 1){
			// $("#optIntelligenceFormGroup").show();
		}
	}

	function toggleProfileForFan() {
		$("#myGraduationYearFormGroup").hide().find(":input").prop("disabled", true);
		$("#mySportIDFormGroup").hide().find(":input").prop("disabled", false);
		$("#fanProfileColumn").removeClass("col-md-12").addClass("col-md-6");
		studentProfile.show().find(":input").prop("disabled", false);
		$("#myRelationshipFormGroup").show().find(":input").prop("disabled", false);
		parentProfile.hide().find(":input").prop("disabled", true);

		$('#grad_postal_div').css({'margin-top': '100px'});
		$('.stu-text').addClass('d-none');
		$('.parent-text').addClass('d-none');


        castudentProfile.hide().find(":input").prop("disabled", true);
        caparentProfile.hide().find(":input").prop("disabled", true);
		$("#studentCAtext").hide();
		$("#parentCAtext").hide();
		$("#caOptInFormGroup").hide().find(":input").prop("disabled", true).prop("required", false);


		$("#studentNCSAtext").hide();
		$("#parentNCSAtext").show();
		if(showNCSAOptIn == 1 && ncsaOptInToggle == 1){
			$("#ncsaOptInFormGroup").show().find(":input").prop("disabled", false).prop("required", true);
		}else{
			$("#ncsaOptInFormGroup").hide().find(":input").prop("disabled", true).prop("required", false);
		}
		$("#studentANGtext").hide();
		$("#parentANGtext").show();
		if(showANGOptIn == 1 && angOptInToggle == 1){
			$("#angOptInFormGroup").show().find(":input").prop("disabled", false).prop("required", true);
		}else{
			$("#angOptInFormGroup").hide().find(":input").prop("disabled", true).prop("required", false);
		}
		$("#studentArmyNGtext").hide();
		$("#parentArmyNGtext").show();
		if(showArmyNGOptIn == 1 && armyNGOptInToggle == 1){
			$("#armyNGOptInFormGroup").show().find(":input").prop("disabled", false).prop("required", true);
		}else{
			$("#armyNGOptInFormGroup").hide().find(":input").prop("disabled", true).prop("required", false);
		}
		$("#studentCollegeVinetext").hide();
		$("#parentCollegeVinetext").show();
		$("#studentCollegeVineSATtext").hide();
		$("#parentCollegeVineSATtext").show();
		if(showCollegeVineOptIn == 1 && collegeVineOptInToggle == 1){
			$("#collegeVineOptInFormGroup").show().find(":input").prop("disabled", false);
		//	$("#collegeVineSATOptInFormGroup").show().find(":input").prop("disabled", false).prop("required", true);
		}else{
			$("#collegeVineOptInFormGroup").hide().find(":input").prop("disabled", true);
		//	$("#collegeVineSATOptInFormGroup").hide().find(":input").prop("disabled", true).prop("required", false);
		}
		$("#mygraduationYearSelection").hide();
    if(($("#collegeVineOptInYes").prop("checked")) || ($("#collegeVineSATOptInYes").prop("checked"))){
			$("#IsGraduationYearRequired").show();
		}
		if(!($("#collegeVineOptInYes").prop("checked")) && !($("#collegeVineSATOptInYes").prop("checked")) && !($("#collegeVineOptInNo").prop("checked"))){
			$("#collegeVineOptInNo").prop("required", true);
		}
		$("#optIntelligenceFormGroup").hide();
	}

	function toggleNewPasswordConstraints() {
		var currentPasswordElm = $("#currentPassword");
		var newPasswordElm = $("#newPassword");
		var confirmPasswordElm = $("#confirmPassword");
		if (!!currentPasswordElm.length && !!newPasswordElm.length && !!confirmPasswordElm.length) {
			if (currentPasswordElm.val().length > 0) {
				setDisabled(newPasswordElm, false);
				setRequired(newPasswordElm, true);
				setDisabled(confirmPasswordElm, false);
				setRequired(confirmPasswordElm, true);
			}
			else {
				newPasswordElm.val("");
				setDisabled(newPasswordElm, true);
				setRequired(newPasswordElm, false);

				confirmPasswordElm.val("");
				setDisabled(confirmPasswordElm, true);
				setRequired(confirmPasswordElm, false);
			}
		}
	}

	function setRequired(elm, isRequired) {
		var elm = $(elm);
		if (isRequired) {
			elm.prop("required", true);
			var hasRequiredElm = elm.parents(".form-group").find("label .text-required");
			if (hasRequiredElm.length === 0) {
				var requiredElm = $('<span class="text-required text-danger" title="required"> *</span>');
				elm.parents(".form-group").find("label").append(requiredElm);
			}
		}
		else {
			elm.prop("required", false);
			elm.parents(".form-group").find("label .text-required").remove();
		}
	}

	function setDisabled(elm, isDisabled) {
		var elm = $(elm);
		if (isDisabled) {
			elm.prop("disabled", true);
		}
		else {
			elm.prop("disabled", false);
		}
	}

	$(function() {

		$(document).on("change.oldFanPassword", "#currentPassword", function() {
			toggleNewPasswordConstraints();
		});
		toggleNewPasswordConstraints();


		$(document).on("change.userRole", "#myUserRole input[type='radio']", function() {
			toggleProfileByUserRole();
			removeAllErrors();
			updateFirstNextButton();
			var optins = [
					'armyNGOptInFormGroup',
					'angOptInFormGroup',
					'ncsaOptInFormGroup',
					'caOptInFormGroup',
					'collegeVineOptInFormGroup'
					// 'optIntelligenceFormGroup'
				];

				if(haveOptins(optins) == false)
				{
					// no optin then make first step as final step.
					$("#First-next").html("Create");
					$("#First-next").val("Create");
					$("#First-next").addClass("fisrtnext-create");
					$(".last-bubble").addClass("hide");
					$("#bubble2").addClass("hide");
					$("#progressbar #bubble1").addClass("laststep");
				}
				else{
					$("#First-next").html("Next");
					$("#First-next").val("Next");
					$(".last-bubble").removeClass("hide");
					$("#bubble2").removeClass("hide");
					$("#progressbar #bubble1").removeClass("laststep");
				}
		});

		$(document).on("change.postalCode", "#myPostalCode", function() {
			updateFirstNextButton();
		});

		$(document).on("keyup", "#newPassword", function() {
			if($("#passwordErrorMessage").css("display") != 'none'){
				var newPass = $('#newPassword').val();
				var passes = true;

				var upper = 0;
				var lower = 0;
				var number = 0;
				var special = 0;

				for (var i = 0; i < newPass.length; i++) {
					if (newPass[i] >= "A" && newPass[i] <= "Z") upper++;
					else if (newPass[i] >= "a" && newPass[i] <= "z") lower++;
					else if (newPass[i] >= "0" && newPass[i] <= "9") number++;
					else special++;
				}

				if (upper < 1 || lower < 1 || number < 1) {
					passes = false;
				}

				if(!passes){
					$("#passwordErrorMessage").show();
					$("#newPassword").focus();
				}else{
					$("#passwordErrorMessage").hide();
				}
			}
		});

		toggleProfileByUserRole();
	});

}(jQuery);
function removeAllErrors()
{
	if(document.getElementById("armyNGOptInValidationText"))
	   document.getElementById("armyNGOptInValidationText").style.display = "none";

	if(document.getElementById("angOptInValidationText")) 
	   document.getElementById("angOptInValidationText").style.display = "none";

	if(document.getElementById("ncsaOptInValidationText"))
	   document.getElementById("ncsaOptInValidationText").style.display = "none";

	if(document.getElementById("collegeadvisoroptinValidationText"))
	  document.getElementById("collegeadvisoroptinValidationText").style.display = "none";

	if(document.getElementById("collegeVineOptInValidationText"))
	  document.getElementById("collegeVineOptInValidationText").style.display = "none";
}

$('#ncsaFanForm').submit(function(ev) {
	if(this.checkValidity()){
		if ($(myUserRole).val() == "student") {
			$("#parent1FirstName").val($("#ncsaFrm_parent1FirstName").val());
			$("#parent1LastName").val($("#ncsaFrm_parent1LastName").val());
			$("#parent1Email").val($("#ncsaFrm_parent1Email").val());
			$("#parent1Phone").val($("#ncsaFrm_parent1Phone").val());
			$("#studentFirstName").val($("#myFirstName").val());
			$("#studentLastName").val($("#myLastName").val());
			$("#studentEmailAddress").val($("#myEmailAddress").val());
			$("#studentGraduationYear").val($("#ncsaFrm_studentGraduationYear").val());
			$("#studentSportID").val($("#ncsaFrm_studentSportID").val());
			$("#birthdate").val($("#ncsaFrm_birthdate").val());

			$("#ca_parent1FirstName").val($("#college_adviser_parent_firstname").val());
			$("#ca_parent1LastName").val($("#college_adviser_parent_lastname").val());
			$("#ca_parent1Email").val($("#college_adviser_parent_email").val());
			$("#ca_parent1Phone").val($("#college_adviser_parent_phone").val());
			$("#ca_studentFirstName").val($("#myFirstName").val());
			$("#ca_studentLastName").val($("#myLastName").val());
			$("#ca_studentPhone").val($("#myMobilePhoneNumber").val());
			$("#ca_studentEmail").val($("#myEmailAddress").val());

			$("#ca_studentGraduationYear").val($("#college_adviser_student_grad_year").val());
			$("#ca_studentGPA").val($("#college_adviser_gpa").val());
			$("#ca_studentFinancial_aid").val($("#college_adviser_financial_aid").val());


			$('#ncsaDialog').modal('toggle');
		} else {
			$("#parent1FirstName").val($("#myFirstName").val());
			$("#parent1LastName").val($("#myLastName").val());
			$("#parent1Email").val($("#myEmailAddress").val());
			$("#parent1Phone").val($("#myMobilePhoneNumber").val());

			$("#studentFirstName").val($("#ncsaFrm_studentFirstName").val());
			$("#studentLastName").val($("#ncsaFrm_studentLastName").val());
			$("#studentEmailAddress").val($("#myEmailAddress").val());

			$("#studentGraduationYear").val($("#ncsaFrm_studentGraduationYear").val());
			$("#studentSportID").val($("#ncsaFrm_studentSportID").val());
			$("#birthdate").val($("#ncsaFrm_birthdate").val());

			$("#ca_parent1FirstName").val($("#myFirstName").val());
			$("#ca_parent1LastName").val($("#myLastName").val());
			$("#ca_parent1Email").val($("#myEmailAddress").val());
			$("#ca_parent1Phone").val($("#myMobilePhoneNumber").val());
			$("#ca_studentFirstName").val($("#college_adviser_student_firstname").val());
			$("#ca_studentLastName").val($("#college_adviser_student_lastname").val());
			$("#ca_studentPhone").val($("#college_adviser_student_phone").val());
			$("#ca_studentEmail").val($("#college_adviser_student_email").val());
			
			$("#ca_studentGraduationYear").val($("#college_adviser_student_grad_year").val());
			$("#ca_studentGPA").val($("#college_adviser_gpa").val());
			$("#ca_studentFinancial_aid").val($("#college_adviser_financial_aid").val());



			$('#ncsaDialog').modal('toggle');
		}
		if ($("#allowOptIntelligence").val() > 0 && $("#myUserRole").val() == 'parent') {
			var oiElements = $(".OI_RADIO");
			var hasAnOptIn = false;
			$.each(oiElements, function(item, val) {
				if (val.checked && val.value != "NO") {
					hasAnOptIn = true;
				}
			});
			if (hasAnOptIn) {
				if (oi.profile != undefined) {
					oi.profile.email = $("#myEmailAddress").val();
					oi.profile.firstname = $("#myFirstName").val();
					oi.profile.lastname = $("#myLastName").val();
					oi.profile.address1 = "";
					oi.profile.postalcode = $("#myPostalCode").val();
					oi.profile.gender = "";
					oi.profile.dateofbirth = "";
					oi.profile.homephone = $("#myMobilePhoneNumber").val();
					oi.profile.businessphone = "";
					oi.profile.mobilephone = $("#myMobilePhoneNumber").val();
					oi("#offers").optIn();
				}
			}
		}
		document.getElementById('newFanForm').submit();
	}else{
		ev.preventDefault();
	}
});

function checkNCSA(){
	if($('input:radio[name="ncsaOptIn"]:checked').val() == 1){
		return true;
	}else{
		return false;
	}

}

function checkCA(){
	if($('input:radio[name="collegeadvisoroptin"]:checked').val() == 1){
		return true;
	}else{
		return false;
	}

}

function checkANG(){
	if($('input:radio[name="angOptIn"]:checked').val() == 1){
		return true;
	}else{
		return false;
	}

}

function checkArmyNG(){
	if($('input:radio[name="armyNGOptIn"]:checked').val() == 1){
		return true;
	}else{
		return false;
	}

}

function checkCollegeVine(){
	if($('input:radio[name="collegeVineOptIn"]:checked').val() == 1){
		return true;
	}else{
		return false;
	}

}

function checkCollegeVineSAT(){
	if($('input:radio[name="collegeVineSATOptIn"]:checked').val() == 1){
		return true;
	}else{
		return false;
	}

}

function validatePasswords() {
	var newPassword = $("#newPassword").val();
	var confirmPassword = $("#confirmPassword").val();
	var confirmPasswordInput = $("#confirmPassword");
	var isValid = false;
	

	if (newPassword != confirmPassword) {
		isValid = false;
		confirmPasswordInput.addClass("is-invalid");
		confirmPasswordInput.siblings(".invalid-feedback").text("Passwords do not match.");
	} else {
		isValid = true;
		confirmPasswordInput.removeClass("is-invalid");
		confirmPasswordInput.siblings(".invalid-feedback").text("");
	}

}

function validatePasswordStrength() {
	var password = $("#newPassword").val();
	var strengthMessage = $("#passwordStrengthMessage");
	var isValid = false; length= false; uppercase= false; lowercase = false; numeric= false; special_character = false;

	// Check for at least 8 characters
	if (password.length >= 8) {
		length = true;
	}

	// Check for at least 1 uppercase letter
	if (/[A-Z]/.test(password)) {
		uppercase = true;
	}

	// Check for at least 1 lowercase letter
	if (/[a-z]/.test(password)) {
		lowercase = true;
	}

	// Check for at least 1 number
	if (/\d/.test(password)) {
		numeric = true;
	}

	// Check for special characters
	if (/[^A-Za-z\d]/.test(password)) {
    	special_character = true;
	}
	
	if(special_character && numeric && lowercase && uppercase && length){
		strengthMessage.text("Strength: Maximum Strong");
	}
	else if(numeric && lowercase && uppercase && length){
		strengthMessage.text("Strength: Strong");
	}
	else if(numeric && lowercase && length){
		strengthMessage.text("Strength: Moderate");
	}
	else{
		strengthMessage.text("Strength: Weak");
	}


	if(numeric && lowercase && uppercase && length)
	{
		isValid = true;
		$("#newPassword").removeClass("is-invalid");
		$("#newPassword").siblings(".invalid-feedback").text("");
	}
	else{
		$("#newPassword").addClass("is-invalid");
		$("#newPassword").siblings(".invalid-feedback").text("Password doesn't match the minimum password requirements.");
		isValid = false;
	}

	return isValid;
}

function updateFirstNextButton() {
    var userRoleValue = $('#myUserRole input[type="radio"]:checked').val();
    var postalCodeValue = $('#myPostalCode').val();

    // Check if both user role and postal code have values
    if (userRoleValue && postalCodeValue) {
        $('#First-next').prop('disabled', false);
        $('#First-next').removeClass('disabled');
    } else {
        $('#First-next').prop('disabled', true);
        $('#First-next').addClass('disabled');
    }
}


function togglePass(span)
{
	var passwordInput = $(span).closest('div').find('input.password');
    var type = passwordInput.attr('type') === 'password' ? 'text' : 'password';
    passwordInput.attr('type', type);
    $(span).find('i').toggleClass('fa-eye fa-eye-slash');
}

function haveOptins(ids) {
    for (var i = 0; i < ids.length; i++) {
        var optinDiv = document.getElementById(ids[i]);
        if (optinDiv && optinDiv.style.display !== 'none') {
            return true; // Return true if have optins
        }
    }
    return false; // Return false if no optin
}

function createAccount_phase1(event){
    event.preventDefault();
	checkpassword = true;

	if(validatePasswordStrength() == false)
	{
		checkpassword = false;
	}

	if(validatePasswords() == false){
		checkpassword = false;
	}

    if (checkpassword == false || !event.target.checkValidity())  
    {
	
        event.target.classList.add('was-validated');
    }
    else
    {
		var formData = $("#newFanForm_phase1").serializeArray();
		$.ajax({
			type: "POST",
			url: '/auth/newaccount_phase1_checks',
			data: formData,
			success: function(response) {
				var res = JSON.parse(response);
				if(res.firstName){
					if(res.firstName.message.length > 0){
						fcAlert(res.firstName.message);
						return;
					}
				}

				if(res.lastName){
					if(res.lastName.message.length > 0){
						fcAlert(res.lastName.message);
						return;
					}
				}

				if(res.phone){
					if(res.phone.message.length > 0){
						fcAlert(res.phone.message);
						return;
					}
				}

				if(res.invalidEmail){
					if(res.invalidEmail.message.length > 0){
						fcAlert(res.invalidEmail.message);
						return;
					}
				}

				if(res.emailAddressInUse){
					if(res.emailAddressInUse.message.length > 0){
						fcAlert(res.emailAddressInUse.message);
						return;
					}
				}

				if(res.emailExists){
					if(res.emailExists.message.length > 0){
						fcAlert(res.emailExists.message);
						return;
					}
				}

				if(res.passwordStrength){
					if(res.passwordStrength.message.length > 0){
						fcAlert(res.passwordStrength.message);
						return;
					}
				}

				if(res.passwordMismatch){
					if(res.passwordMismatch.message.length > 0){
						fcAlert(res.passwordMismatch.message);
						return;
					}
				}

				if(res.invalidCaptcha){
					if(res.invalidCaptcha.message.length > 0){
						fcAlert(res.invalidCaptcha.message);
						return;
					}
				}

				if(res.success){
					if(res.success.message.length > 0){
						$(".su_phase_2").removeClass("d-none");
						$(".su_phase_1").addClass("d-none");
						$(".pw-col").addClass("d-none");
						$('.su_phase_1').addClass("m-auto");
						$('.su_phase_1').css({'margin-left': '0px'});
						var firstName = $("#myFirstName").val();
						$("#userRole_desc").text("What type of Fan are You,  " + firstName + " ? I'm a");
					}
				}
			},
			error: function(xhr, textStatus, errorThrown) {
			  fcAlert("Failed to submit");
			  console.error("AJAX Request Failed");
			}
		  });
    }
}

function createAccount_phase2(event){
    event.preventDefault();
    if (!event.target.checkValidity()) 
    {
        event.target.classList.add('was-validated');
		var armyNGOptInradio = document.forms["newFanForm"]["armyNGOptIn"].value;
		var angOptInradio = document.forms["newFanForm"]["angOptIn"].value;
		var ncsaOptInradio = document.forms["newFanForm"]["ncsaOptIn"].value;
		var collegeadvisorradio = document.forms["newFanForm"]["collegeadvisoroptin"].value;
		var collegeVineOptInradio = document.forms["newFanForm"]["collegeVineOptIn"].value;

		if (armyNGOptInradio == "")
		{
			document.getElementById("armyNGOptInValidationText").style.display = "block";
			document.getElementById("armyNGOptInValidationText").innerHTML = "This value is required.";
			}
		if(angOptInradio == "") 
		{
			document.getElementById("angOptInValidationText").style.display = "block";
			document.getElementById("angOptInValidationText").innerHTML = "This value is required.";
			}
		if(ncsaOptInradio == "")
		{
			document.getElementById("ncsaOptInValidationText").style.display = "block";
			document.getElementById("ncsaOptInValidationText").innerHTML = "This value is required.";
			} 
		if(collegeadvisorradio == "")
		{
			document.getElementById("collegeadvisoroptinValidationText").style.display = "block";
			document.getElementById("collegeadvisoroptinValidationText").innerHTML = "This value is required.";
			}
		if(collegeVineOptInradio == "")
			{
			document.getElementById("collegeVineOptInValidationText").style.display = "block";
			document.getElementById("collegeVineOptInValidationText").innerHTML = "This value is required.";
			}
    }
    else
    {
		if($("#progressbar #bubble2").hasClass("laststep"))
		{
			//create account was triggerred from step 2
			var formData = $("#newFanForm, #newFanForm_phase1").serializeArray();
			$.ajax({
				type: "POST", 
				url: "/auth/new", 
				data: formData,
				success: function(response) {
					try {
						res = JSON.parse(response);
						if (res.postalCode && res.postalCode.message.length > 0) {
							fcAlert(res.postalCode.message);
							return;
						}
					} catch (e) {
						// If parsing fails, it's not JSON
						console.error("Error parsing response as JSON:", e);
					}
					// Handle the success response from the server
					window.location = "/fans/favoritesform";
				},
				error: function(error) {
				  // Handle the error response from the server
					if(error.statusText)
					{
						fcAlert(error.statusText);
					}
					console.error("Form submission failed:", error);
				}
			});
		}
		else{
			//create account was triggerred from step 3
			if ($(myUserRole).val() == "student") {
				$("#parent1FirstName").val($("#ncsaFrm_parent1FirstName").val());
				$("#parent1LastName").val($("#ncsaFrm_parent1LastName").val());
				$("#parent1Email").val($("#ncsaFrm_parent1Email").val());
				$("#parent1Phone").val($("#ncsaFrm_parent1Phone").val());
				$("#studentFirstName").val($("#myFirstName").val());
				$("#studentLastName").val($("#myLastName").val());
				$("#studentEmailAddress").val($("#myEmailAddress").val());
				$("#studentGraduationYear").val($("#ncsaFrm_studentGraduationYear").val());
				$("#studentSportID").val($("#ncsaFrm_studentSportID").val());
				$("#birthdate").val($("#ncsaFrm_birthdate").val());
	
				$("#ca_parent1FirstName").val($("#college_adviser_parent_firstname").val());
				$("#ca_parent1LastName").val($("#college_adviser_parent_lastname").val());
				$("#ca_parent1Email").val($("#college_adviser_parent_email").val());
				$("#ca_parent1Phone").val($("#college_adviser_parent_phone").val());
				$("#ca_studentFirstName").val($("#myFirstName").val());
				$("#ca_studentLastName").val($("#myLastName").val());
				$("#ca_studentPhone").val($("#myMobilePhoneNumber").val());
				$("#ca_studentEmail").val($("#myEmailAddress").val());
	
				$("#ca_studentGraduationYear").val($("#college_adviser_student_grad_year").val());
				$("#ca_studentGPA").val($("#college_adviser_gpa").val());
				$("#ca_studentFinancial_aid").val($("#college_adviser_financial_aid").val());
			} 
			else {
				$("#parent1FirstName").val($("#myFirstName").val());
				$("#parent1LastName").val($("#myLastName").val());
				$("#parent1Email").val($("#myEmailAddress").val());
				$("#parent1Phone").val($("#myMobilePhoneNumber").val());
	
				$("#studentFirstName").val($("#ncsaFrm_studentFirstName").val());
				$("#studentLastName").val($("#ncsaFrm_studentLastName").val());
				$("#studentEmailAddress").val($("#myEmailAddress").val());
	
				$("#studentGraduationYear").val($("#ncsaFrm_studentGraduationYear").val());
				$("#studentSportID").val($("#ncsaFrm_studentSportID").val());
				$("#birthdate").val($("#ncsaFrm_birthdate").val());
	
				$("#ca_parent1FirstName").val($("#myFirstName").val());
				$("#ca_parent1LastName").val($("#myLastName").val());
				$("#ca_parent1Email").val($("#myEmailAddress").val());
				$("#ca_parent1Phone").val($("#myMobilePhoneNumber").val());
				$("#ca_studentFirstName").val($("#college_adviser_student_firstname").val());
				$("#ca_studentLastName").val($("#college_adviser_student_lastname").val());
				$("#ca_studentPhone").val($("#college_adviser_student_phone").val());
				$("#ca_studentEmail").val($("#college_adviser_student_email").val());
				
				$("#ca_studentGraduationYear").val($("#college_adviser_student_grad_year").val());
				$("#ca_studentGPA").val($("#college_adviser_gpa").val());
				$("#ca_studentFinancial_aid").val($("#college_adviser_financial_aid").val());
	
			}

			if ($("#allowOptIntelligence").val() > 0 && $("#myUserRole").val() == 'parent') {
				var oiElements = $(".OI_RADIO");
				var hasAnOptIn = false;
				$.each(oiElements, function(item, val) {
					if (val.checked && val.value != "NO") {
						hasAnOptIn = true;
					}
				});
				if (hasAnOptIn) {
					if (oi.profile != undefined) {
						oi.profile.email = $("#myEmailAddress").val();
						oi.profile.firstname = $("#myFirstName").val();
						oi.profile.lastname = $("#myLastName").val();
						oi.profile.address1 = "";
						oi.profile.postalcode = $("#myPostalCode").val();
						oi.profile.gender = "";
						oi.profile.dateofbirth = "";
						oi.profile.homephone = $("#myMobilePhoneNumber").val();
						oi.profile.businessphone = "";
						oi.profile.mobilephone = $("#myMobilePhoneNumber").val();
						oi("#offers").optIn();
					}
				}
			}

			var formData = $("#newFanForm, #newFanForm_phase1").serializeArray();
			$.ajax({
				type: "POST", 
				url: "/auth/new", 
				data: formData,
				success: function(response) {
				  // Handle the success response from the server
					try {
						res = JSON.parse(response);
						if (res.postalCode && res.postalCode.message.length > 0) {
							fcAlert(res.postalCode.message);
							return;
						}
					} catch (e) {
						// If parsing fails, it's not JSON
						console.error("Error parsing response as JSON:", e);
					}
				  console.log("Form submitted successfully:", response);
				  window.location = "/fans/favoritesform";
				},
				error: function(error) {
				  // Handle the error response from the server
					if(error.statusText)
					{
						fcAlert(error.statusText);
					}
					console.error("Form submission failed:", error);
				}
			});
		}
    }
}

function moveNext(current_fs, next_fs) {
	//Add Class Active
	$("#progressbar li").eq($("fieldset").index(next_fs)).addClass("active");

	//show the next fieldset
	next_fs.show();
	//hide the current fieldset with style
	current_fs.animate({
		opacity: 0
	}, {
		step: function(now) {
			// for making fielset appear animation
			opacity = 1 - now;

			current_fs.css({
				'display': 'none',
				'position': 'relative'
			});
			next_fs.css({
				'opacity': opacity
			});
		},
		duration: 600
	});
}

function checkStep1Validations() {
	var val_error = false;
	$("#grad_postal_div").removeClass("was-validated");
	var user_gradYear = $('#mygraduationYear').val();
	var user_postalCode = $('#myPostalCode').val();

	if (user_postalCode == "") {
		$("#grad_postal_div").addClass("was-validated");
		val_error = true;
	}

	if($('[name="userRole"]:checked').val() == 'student' || $('[name="userRole"]:checked').val() == 'parent')
	{
		if (user_gradYear == "") {
			$(user_gradYear).attr("required");
			$("#grad_postal_div").addClass("was-validated");
			val_error = true;
		}
	}
	else{
		$(user_gradYear).removeAttr("required");
	}

	return val_error;
}

function checkOptinOffers() {
    var optinDivs = document.querySelectorAll('.optin_div');
    var allOptinGroupChecked = true;
    
    optinDivs.forEach(function(optinDiv) {
        if (optinDiv.style.display !== 'none') {
            var optinInputs = optinDiv.querySelectorAll('.optin_div input[type="checkbox"], .optin_div input[type="radio"]');
            var optinGroupChecked = false;
            
            optinInputs.forEach(function(optinInput) {
                if (optinInput.checked) {
                    optinGroupChecked = true;
                }
            });
            
            if (!optinGroupChecked) {
                allOptinGroupChecked = false;
            }
        }
    });

    return allOptinGroupChecked;
}


$(document).ready(function() {

	$(".next").click(function() {
		button_id = this.id;
		if (button_id == 'First-next') {
			var firstName = $("#myFirstName").val();
			if ($('[name="userRole"]:checked').val() == 'student') {
				document.getElementById("su_acc_text").innerHTML =
					'<h3 class="su-h2 susui-head mt-2" style="color:#129846;">' + firstName +' </h3>' +
					'<h3 class="su-h2 susui-head mt-2" style="color:#129846;"> Student </h3>' +
					'<h3 class="su-h2 susui-head mt-2" > Fan Set Up </h3>';
			} else if ($('[name="userRole"]:checked').val() == 'parent')
			{
				document.getElementById("su_acc_text").innerHTML =
					'<h3 class="su-h2 susui-head mt-2" style="color:#129846;">' + firstName +' </h3>' +
					'<h3 class="su-h2 susui-head mt-2" style="color:#129846;"> Parent </h3>' +
					'<h3 class="su-h2 susui-head mt-2" > Fan Set Up</h3>';
			} else if ($('[name="userRole"]:checked').val() == 'coach') {
				document.getElementById("su_acc_text").innerHTML =
					'<h3 class="su-h2 susui-head mt-2" style="color:#129846;">' + firstName +' </h3>' +
					'<h3 class="su-h2 susui-head mt-2" style="color:#129846;"> Coach </h3>' +
					'<h3 class="su-h2 susui-head mt-2" > Account Set Up</h3>';
			} else if ($('[name="userRole"]:checked').val() == 'fan'){
				document.getElementById("su_acc_text").innerHTML =
					'<h3 class="su-h2 susui-head mt-2" style="color:#129846;">' + firstName +' </h3>' +
					'<h3 class="su-h2 susui-head mt-2" style="color:#129846;"> Fan </h3>' +
					'<h3 class="su-h2 susui-head mt-2" > Account Set Up </h3>';
			}
			$("#bubble2").addClass('active');

			var hasError = checkStep1Validations();
			if (!hasError) {
				var optins = [
					'armyNGOptInFormGroup',
					'angOptInFormGroup',
					'ncsaOptInFormGroup',
					'caOptInFormGroup',
					'collegeVineOptInFormGroup'
					// 'optIntelligenceFormGroup'
				];

				if(haveOptins(optins))
				{
					current_fs = $(this).closest('fieldset');
					next_fs = $(this).closest('fieldset').next();
					moveNext(current_fs, next_fs);
				}
				else
				{
					// no optin then make first step as final step. and do submission
					var formData = $("#newFanForm, #newFanForm_phase1").serializeArray();
					$.ajax({
						type: "POST", 
						url: "/auth/new", 
						data: formData,
						success: function(response) {
							try {
								res = JSON.parse(response);
								if (res.postalCode && res.postalCode.message.length > 0) {
									fcAlert(res.postalCode.message);
									return;
								}
							} catch (e) {
								// If parsing fails, it's not JSON
								console.error("Error parsing response as JSON:", e);
							}
							console.log("Form submitted successfully:", response);
							window.location = "/fans/favoritesform";
						},
						error: function(error) {
							if(error.statusText)
							{
								fcAlert(error.statusText);
							}
						  	console.error("Form submission failed:", error);
						}
					});
				}
			}
		}


		if (button_id == 'Second-next') {

			var isNCSA = checkNCSA();
			var isCA = checkCA();

			if (isNCSA && isCA ) {
				$('#parentProfile').prop('disabled', false);
				$('#studentProfile').prop('disabled', false);
				$('#CAparentProfile').prop('disabled', false);
				$('#CAstudentProfile').prop('disabled', false);
				$('#ncsa_div').css('display','block');
				$('#ca_div').css('display','block');

				$("#ca_div :input").each(function( index ) {
						$( this ).parsley().reset();
						});

				$("#ncsa_div :input").each(function( index ) {
						$( this ).parsley().reset();
				});

				$("#ncsa_div :input").each(function( index ) {
						$( this ).attr('required', true);
					});

				$("#ca_div :input").each(function( index ) {
						$( this ).attr('required', true);
					});

			}
			if (isCA && !(isNCSA)) {
				$('#parentProfile').prop('disabled', true);
				$('#studentProfile').prop('disabled', true);
				$('#CAparentProfile').prop('disabled', false);
				$('#CAstudentProfile').prop('disabled', false);
				$('#ca_div').css('display','block');
				$('#ncsa_div').css('display','none');

				$("#ca_div :input").each(function( index ) {
						$( this ).parsley().reset();
				});

				$("#ncsa_div :input").each(function( index ) {
						$( this ).attr('required', false);
				});

				$("#ca_div :input").each(function( index ) {
						$( this ).attr('required', true);
				});

			}
			if (!(isCA) && isNCSA ) {
				$('#parentProfile').prop('disabled', false);
				$('#studentProfile').prop('disabled', false);
				$('#CAparentProfile').prop('disabled', true);
				$('#CAstudentProfile').prop('disabled', true);
				$('#ncsa_div').css('display','block');
				$('#ca_div').css('display','none');

				$("#ncsa_div :input").each(function( index ) {
					$( this ).parsley().reset();
						});

				$("#ca_div :input").each(function( index ) {
						$( this ).attr('required', false);
				});

				$("#ncsa_div :input").each(function( index ) {
					$( this ).attr('required', true);
				});

			}
			if (!(isCA) && !(isNCSA)) {
				$('#parentProfile').prop('disabled', true);
				$('#studentProfile').prop('disabled', true);
				$('#CAparentProfile').prop('disabled', true);
				$('#CAstudentProfile').prop('disabled', true);
				$('#ncsaDialog').css('display','none');

				$("#ca_div :input").each(function( index ) {
					$( this ).parsley().reset();
				});

				$("#ncsa_div :input").each(function( index ) {
						$( this ).parsley().reset();
				});

				$("#ncsa_div :input").each(function( index ) {
						$( this ).attr('required', false);
				});

				$("#ca_div :input").each(function( index ) {
						$( this ).attr('required', false);
				});


			}

			if(isNCSA || isCA){
				current_fs = $(this).closest('fieldset');
				next_fs = $(this).closest('fieldset').next();
				moveNext(current_fs, next_fs);
				$("#bubble3").addClass('active');
			} else {
				if ($("#allowOptIntelligence").val() > 0 && $("#myUserRole").val() == 'parent') {
					var oiElements = $(".OI_RADIO");
					var hasAnOptIn = false;
					$.each(oiElements, function(item, val) {
						if (val.checked && val.value != "NO") {
							hasAnOptIn = true;
						}
					});
					if (hasAnOptIn) {
						if (oi.profile != undefined) {
							oi.profile.email = $("#myEmailAddress").val();
							oi.profile.firstname = $("#myFirstName").val();
							oi.profile.lastname = $("#myLastName").val();
							oi.profile.address1 = "";
							oi.profile.postalcode = $("#myPostalCode").val();
							oi.profile.gender = "";
							oi.profile.dateofbirth = "";
							oi.profile.homephone = $("#myMobilePhoneNumber").val();
							oi.profile.businessphone = "";
							oi.profile.mobilephone = $("#myMobilePhoneNumber").val();
							oi("#offers").optIn();
						}
					}
				}

				$("#su_phase2_create").click();
			}
		}
	});

	$(".previous").click(function() {

		button_id = this.id;
		if (button_id == 'First-back') {
			document.getElementById("su_acc_text").innerHTML = '<h2 class="susui-head mt-2"> Fan Account Setup </h2>';
			$("#progressbar #bubble2").removeClass("laststep");
			$(".last-bubble").removeClass("hide");
			$("#bubble2").removeClass('active');
		}
		else {
			$("#bubble3").removeClass('active');
		}


		current_fs = $(this).closest('fieldset');
		previous_fs = $(this).closest('fieldset').prev();

		//Remove class active
		$("#progressbar li").eq($("fieldset").index(current_fs)).removeClass("active");

		//show the previous fieldset
		previous_fs.show();

		//hide the current fieldset with style
		current_fs.animate({
			opacity: 0
		}, {
			step: function(now) {
				// for making fielset appear animation
				opacity = 1 - now;

				current_fs.css({
					'display': 'none',
					'position': 'relative'
				});
				previous_fs.css({
					'opacity': opacity
				});
			},
			duration: 600
		});
	});

	$(".cancel").click(function() {
		button_id = this.id;
		if (button_id == "First_cancel") {
			$(".su_phase_2").addClass("d-none");
			$(".su_phase_1").removeClass("d-none");
		}
	});

	var optinInputs = document.querySelectorAll('.optin_div input[type="checkbox"], .optin_div input[type="radio"]');
	optinInputs.forEach(function(optinInput) {
		optinInput.addEventListener('change', function() {
			var isNCSA = checkNCSA();
			var isCA = checkCA();
			var allOptinInputsChecked = checkOptinOffers();
			if(allOptinInputsChecked){
				$("#Second-next").html("Create");
				$("#Second-next").val("Create");
				$(".last-bubble").addClass("hide");
				$("#progressbar #bubble2").addClass("laststep");
				$('#Second-next').prop('disabled', false);
				$('#Second-next').removeClass('disabled');
			}
			else{
				$('#Second-next').prop('disabled', true);
				$('#Second-next').addClass('disabled');
			}

			if(isNCSA || isCA)
			{
				$('#Second-next').prop('disabled', false);
				$('#Second-next').removeClass('disabled');
				$("#Second-next").html("Next");
				$("#Second-next").val("Next");
				$(".last-bubble").removeClass("hide");
				$("#progressbar #bubble2").removeClass("laststep");
			}

		});
	});

	$("#confirmPassword").on("input", function() {
		validatePasswords();
	});

	$("#newPassword").on("input", function() {
		$(".pw-col").removeClass("d-none");
		$('.su_phase_1').removeClass("m-auto");
		$('.su_phase_1').css({'margin-left': '360px'});
		validatePasswordStrength();
	});

	let passwordInp = document.getElementById('newPassword');
	passwordInp.addEventListener('keyup', () => {

		let passwordChecklist = document.querySelectorAll('.list-item');
		let validationRegex = [
			{ regex: /.{8,}/ }, // min 8 letters,
			{ regex: /[0-9]/ }, // numbers from 0 - 9
			{ regex: /[a-z]/ }, // letters from a - z (lowercase)
			{ regex: /[A-Z]/}, // letters from A-Z (uppercase),
			{ regex: /[^A-Za-z0-9]/} // special characters
		];

		validationRegex.forEach((item, i) => {
			let isValid = item.regex.test(passwordInp.value);
			if(isValid) {
				passwordChecklist[i].classList.add('checked');
			} else{
				passwordChecklist[i].classList.remove('checked');
				$('#newPassword').attr('data-parsley-error-message', "Password must match the minimum password requirements");
			}

		})
	});


});