"use strict";
window.addEventListener('load', function() { 
	$('#preloader').delay(400).fadeOut('slow');
	$('#preloader .clock').fadeOut();
 
	AOS.init({
		easing: 'ease-in-out-sine'
	});
});

document.addEventListener('DOMContentLoaded', function() {

$(".hiddenDetailText").css("display","none"),$(".show-more-text-libelle").each(function(e,t){$(t).text($(t).attr("data-text-libelle-more"))}),$(".hide-text-plus").each(function(e,t){$(t).attr("class","show-more-plus")}),$(document).on("click",".hide-text-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","show-more-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-more")),l.css("display","none")}),$(document).on("click",".show-more-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","hide-text-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-hide")),l.css("display","inline")});$(".hiddenDetailText").css("display","none"),$(".show-more-text-libelle").each(function(e,t){$(t).text($(t).attr("data-text-libelle-more"))}),$(".hide-text-plus").each(function(e,t){$(t).attr("class","show-more-plus")}),$(document).on("click",".hide-text-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","show-more-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-more")),l.css("display","none")}),$(document).on("click",".show-more-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","hide-text-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-hide")),l.css("display","inline")});$(".hiddenDetailText").css("display","none"),$(".show-more-text-libelle").each(function(e,t){$(t).text($(t).attr("data-text-libelle-more"))}),$(".hide-text-plus").each(function(e,t){$(t).attr("class","show-more-plus")}),$(document).on("click",".hide-text-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","show-more-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-more")),l.css("display","none")}),$(document).on("click",".show-more-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","hide-text-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-hide")),l.css("display","inline")});$(".hiddenDetailText").css("display","none"),$(".show-more-text-libelle").each(function(e,t){$(t).text($(t).attr("data-text-libelle-more"))}),$(".hide-text-plus").each(function(e,t){$(t).attr("class","show-more-plus")}),$(document).on("click",".hide-text-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","show-more-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-more")),l.css("display","none")}),$(document).on("click",".show-more-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","hide-text-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-hide")),l.css("display","inline")});$(".hiddenDetailText").css("display","none"),$(".show-more-text-libelle").each(function(e,t){$(t).text($(t).attr("data-text-libelle-more"))}),$(".hide-text-plus").each(function(e,t){$(t).attr("class","show-more-plus")}),$(document).on("click",".hide-text-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","show-more-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-more")),l.css("display","none")}),$(document).on("click",".show-more-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","hide-text-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-hide")),l.css("display","inline")});$(".hiddenDetailText").css("display","none"),$(".show-more-text-libelle").each(function(e,t){$(t).text($(t).attr("data-text-libelle-more"))}),$(".hide-text-plus").each(function(e,t){$(t).attr("class","show-more-plus")}),$(document).on("click",".hide-text-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","show-more-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-more")),l.css("display","none")}),$(document).on("click",".show-more-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","hide-text-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-hide")),l.css("display","inline")});$(".hiddenDetailText").css("display","none"),$(".show-more-text-libelle").each(function(e,t){$(t).text($(t).attr("data-text-libelle-more"))}),$(".hide-text-plus").each(function(e,t){$(t).attr("class","show-more-plus")}),$(document).on("click",".hide-text-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","show-more-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-more")),l.css("display","none")}),$(document).on("click",".show-more-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","hide-text-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-hide")),l.css("display","inline")});$(".hiddenDetailText").css("display","none"),$(".show-more-text-libelle").each(function(e,t){$(t).text($(t).attr("data-text-libelle-more"))}),$(".hide-text-plus").each(function(e,t){$(t).attr("class","show-more-plus")}),$(document).on("click",".hide-text-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","show-more-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-more")),l.css("display","none")}),$(document).on("click",".show-more-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","hide-text-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-hide")),l.css("display","inline")});$(".hiddenDetailText").css("display","none"),$(".show-more-text-libelle").each(function(e,t){$(t).text($(t).attr("data-text-libelle-more"))}),$(".hide-text-plus").each(function(e,t){$(t).attr("class","show-more-plus")}),$(document).on("click",".hide-text-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","show-more-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-more")),l.css("display","none")}),$(document).on("click",".show-more-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","hide-text-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-hide")),l.css("display","inline")});$(".hiddenDetailText").css("display","none"),$(".show-more-text-libelle").each(function(e,t){$(t).text($(t).attr("data-text-libelle-more"))}),$(".hide-text-plus").each(function(e,t){$(t).attr("class","show-more-plus")}),$(document).on("click",".hide-text-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","show-more-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-more")),l.css("display","none")}),$(document).on("click",".show-more-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","hide-text-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-hide")),l.css("display","inline")});$(".hiddenDetailText").css("display","none"),$(".show-more-text-libelle").each(function(e,t){$(t).text($(t).attr("data-text-libelle-more"))}),$(".hide-text-plus").each(function(e,t){$(t).attr("class","show-more-plus")}),$(document).on("click",".hide-text-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","show-more-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-more")),l.css("display","none")}),$(document).on("click",".show-more-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","hide-text-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-hide")),l.css("display","inline")});$(".hiddenDetailText").css("display","none"),$(".show-more-text-libelle").each(function(e,t){$(t).text($(t).attr("data-text-libelle-more"))}),$(".hide-text-plus").each(function(e,t){$(t).attr("class","show-more-plus")}),$(document).on("click",".hide-text-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","show-more-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-more")),l.css("display","none")}),$(document).on("click",".show-more-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","hide-text-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-hide")),l.css("display","inline")});$(".hiddenDetailText").css("display","none"),$(".show-more-text-libelle").each(function(e,t){$(t).text($(t).attr("data-text-libelle-more"))}),$(".hide-text-plus").each(function(e,t){$(t).attr("class","show-more-plus")}),$(document).on("click",".hide-text-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","show-more-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-more")),l.css("display","none")}),$(document).on("click",".show-more-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","hide-text-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-hide")),l.css("display","inline")});$(".hiddenDetailText").css("display","none"),$(".show-more-text-libelle").each(function(e,t){$(t).text($(t).attr("data-text-libelle-more"))}),$(".hide-text-plus").each(function(e,t){$(t).attr("class","show-more-plus")}),$(document).on("click",".hide-text-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","show-more-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-more")),l.css("display","none")}),$(document).on("click",".show-more-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","hide-text-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-hide")),l.css("display","inline")});$(".hiddenDetailText").css("display","none"),$(".show-more-text-libelle").each(function(e,t){$(t).text($(t).attr("data-text-libelle-more"))}),$(".hide-text-plus").each(function(e,t){$(t).attr("class","show-more-plus")}),$(document).on("click",".hide-text-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","show-more-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-more")),l.css("display","none")}),$(document).on("click",".show-more-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","hide-text-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-hide")),l.css("display","inline")});$(".hiddenDetailText").css("display","none"),$(".show-more-text-libelle").each(function(e,t){$(t).text($(t).attr("data-text-libelle-more"))}),$(".hide-text-plus").each(function(e,t){$(t).attr("class","show-more-plus")}),$(document).on("click",".hide-text-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","show-more-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-more")),l.css("display","none")}),$(document).on("click",".show-more-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","hide-text-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-hide")),l.css("display","inline")});$(".hiddenDetailText").css("display","none"),$(".show-more-text-libelle").each(function(e,t){$(t).text($(t).attr("data-text-libelle-more"))}),$(".hide-text-plus").each(function(e,t){$(t).attr("class","show-more-plus")}),$(document).on("click",".hide-text-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","show-more-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-more")),l.css("display","none")}),$(document).on("click",".show-more-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","hide-text-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-hide")),l.css("display","inline")});$(".hiddenDetailText").css("display","none"),$(".show-more-text-libelle").each(function(e,t){$(t).text($(t).attr("data-text-libelle-more"))}),$(".hide-text-plus").each(function(e,t){$(t).attr("class","show-more-plus")}),$(document).on("click",".hide-text-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","show-more-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-more")),l.css("display","none")}),$(document).on("click",".show-more-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","hide-text-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-hide")),l.css("display","inline")});$(".hiddenDetailText").css("display","none"),$(".show-more-text-libelle").each(function(e,t){$(t).text($(t).attr("data-text-libelle-more"))}),$(".hide-text-plus").each(function(e,t){$(t).attr("class","show-more-plus")}),$(document).on("click",".hide-text-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","show-more-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-more")),l.css("display","none")}),$(document).on("click",".show-more-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","hide-text-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-hide")),l.css("display","inline")});$(".hiddenDetailText").css("display","none"),$(".show-more-text-libelle").each(function(e,t){$(t).text($(t).attr("data-text-libelle-more"))}),$(".hide-text-plus").each(function(e,t){$(t).attr("class","show-more-plus")}),$(document).on("click",".hide-text-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","show-more-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-more")),l.css("display","none")}),$(document).on("click",".show-more-plus",function(e){e.preventDefault();var t=$(this),l=$(this).parent().find(".hiddenDetailText");t.attr("class","hide-text-plus"),$(this).parent().find(".show-more-text-libelle").text($(this).parent().find(".show-more-text-libelle").attr("data-text-libelle-hide")),l.css("display","inline")});




$('.carousel-4item-dots-fluid').owlCarousel({
    loop: false,
    margin: 60,
    nav: false,
    autoplay: true,
    autoplayHoverPause: true,
    rewind: true,
    responsive: {
        0: {
            items: 1
        },
        600: {
            items: 3
        },
        1000: {
            items: 4
        },
        1600: {
            items: 5
        }
    }

});


var dynamicPhrases = ["What's your Website idea?", "e.g. An eco-friendly gardening service called EcoGarden", "e.g. An art workshop for children called Little Picasso", "e.g. An eco-friendly travel agency called EcoTravelers", "e.g. A cat caf&eacute; called Meow Caf&eacute;", ];
var inputElem = document.getElementById("startupIdeaInput");
var currentIndex = 0;

function updatePlaceholder() {
	inputElem.placeholder = dynamicPhrases[currentIndex];
	currentIndex = (currentIndex + 1) % dynamicPhrases.length;
}
updatePlaceholder();
setInterval(updatePlaceholder, 4000);


var nextBtn = document.getElementById("submitButton");
var firstForm = document.getElementById("contact-halfbg-form--0-form");
var secondForm = document.getElementById("contact-halfbg-form-form");
const inputField = document.getElementById('startupIdeaInput');

nextBtn.addEventListener("click", function(event) {
	event.preventDefault();

	if (inputField.value.trim() === '') {
		inputField.style.border = '2px solid #fa4800';
		setTimeout(() => {
			inputField.style.border = '';
			inputField.style.border = '';
		}, 6000);
	} else {
		firstForm.style.display = "none";
		secondForm.style.display = "block";
	}
});

var prevBtn = document.querySelector(".prev-btn");
var activeForm = document.querySelector(".active-form");
var hiddenForm = document.getElementById("contact-halfbg-form-form");
prevBtn.addEventListener("click", function(event) {
	event.preventDefault();
	hiddenForm.style.display = "none";
	activeForm.style.display = "block";
});

document.querySelector('.back2').addEventListener('click', function(event) {
	event.preventDefault();
	document.getElementById('step1').style.display = 'block';
	document.getElementById('step2').style.display = 'none';
	currentForm = 0;
});

const selectField = document.querySelector('select[name="select_0"]');
const otherInput = document.querySelector('input[name="What\'s your startup idea?"]');
const nextButton = document.querySelector('.next-btn');

selectField.addEventListener('change', function() {
	if (this.value !== "") {
		otherInput.parentNode.style.display = 'block';
		nextButton.style.display = 'block';
	} else {
		otherInput.parentNode.style.display = 'none';
		nextButton.style.display = 'none';
	}
});


// Next button in the second form
document.querySelector('.next2').addEventListener('click', function(event) {
	event.preventDefault();

	const storeNameInput = document.getElementById('specific-input-id');
	const fullNameInput = document.getElementsByName('NAME')[0];
	if (storeNameInput.value.trim() === '' || fullNameInput.value.trim() === '') {

		if (storeNameInput.value.trim() === '') {
			storeNameInput.style.border = '2px solid #fa4800';
			// Reset styles after 3 seconds
			setTimeout(() => {
				storeNameInput.style.border = '';
				storeNameInput.style.border = '';
			}, 6000);
		}

		if (fullNameInput.value.trim() === '') {
			fullNameInput.style.border = '2px solid #fa4800';
			// Reset styles after 3 seconds
			setTimeout(() => {
				fullNameInput.style.border = '';
				fullNameInput.style.border = '';
			}, 6000);
		}
	} else {

		document.getElementById('step1').style.display = 'none';
		document.getElementById('step2').style.display = 'block';

		currentForm = 0;
		this.disabled = false;
	}
});

const emailInput = document.querySelector('input[name="EMAIL"]');
const passwordInput = document.querySelector('input[name="PASSWORD"]');
const generateButton = document.getElementById('generateButton');

emailInput.addEventListener('input', updateGenerateButtonState);
passwordInput.addEventListener('input', updateGenerateButtonState);

function updateGenerateButtonState() {
	const emailNotEmpty = emailInput.value.trim() !== '';
	const passwordNotEmpty = passwordInput.value.trim() !== '';
	if (emailNotEmpty && passwordNotEmpty) {
		generateButton.disabled = false;
	} else {
		generateButton.disabled = true;
	}
	emailInput.style.border = emailNotEmpty ? '' : '2px solid #fa4800';
	passwordInput.style.border = passwordNotEmpty ? '' : '2px solid #fa4800';
}



window.plan = 'P-8BL57270AS055602FMXCSDXQ';
window.planPrice = '22.5';
window.planPeriod = 'm';

function getCookie(cname) {
	let name = cname + "=";
	let ca = document.cookie.split(';');
	for (let i = 0; i < ca.length; i++) {
		let c = ca[i];
		while (c.charAt(0) == ' ') {
			c = c.substring(1);
		}
		if (c.indexOf(name) == 0) {
			return c.substring(name.length, c.length);
		}
	}
	return "";
}

var affiliated = getCookie('affiliated');

console.log('affiliated : ', affiliated);

window.addEventListener('load', function() {

	var websiteInfoElem = $('#contact-halfbg-form-form, #contact-halfbg-form--0-form, #contact-halfbg-form--1-form');
	var paypalElem = $('#contact-halfbg-form--2-form');
	var curInfoId = null;
	var EmailTest = /^\w+([\.-]?\w+)@\w+([\.-]?\w+)(\.\w{2,6})+$/;

	function verif() {
		return EmailTest.test($('input[name="EMAIL"]', websiteInfoElem).val());
	}

	function validateStore() {
		console.log('validating input..');
		return /^[a-z0-9]\S+$/i.test($('input[name="STORE_NAME"]', websiteInfoElem).val());
	}

	paypalElem.addClass('hidden');
	$('#alert-email').addClass('hidden');
	$('#alert-store').addClass('hidden');

	$('input[name="EMAIL"]', websiteInfoElem).change(function() {
		if (verif()) {
			$('#alert-email', websiteInfoElem).addClass('hidden');
		} else {
			$('#alert-email', websiteInfoElem).removeClass('hidden');
		}
	});

	function debounce(func, timeout = 2000) {
		let timer;
		return (...args) => {
			clearTimeout(timer);
			timer = setTimeout(() => {
				func.apply(this, args);
			}, timeout);
		};
	}

	const checkStoreValidityEvent = debounce((ev) => {
		checkStoreValidity($('input[name="STORE_NAME"]', websiteInfoElem)[0]);
	});

	let loading = false,
		checkAfterComplete = false,
		lastStoreValidation = false;

	$('input[name="STORE_NAME"]', websiteInfoElem).on('input', checkStoreValidityEvent);

	function checkStoreValidity(_this) {
		if (!_this.value) return;
		$.ajax({
			url: Routing.generate('validate_store', {
				store: _this.value
			}),
			dataType: 'json',
			beforeSend: () => {
				$('input[name="STORE_NAME"]', websiteInfoElem).prop('disabled', true);
			},
			success(data) {
				setStoreMessage(lastStoreValidation = data.valid, data
					.message);
				console.log(lastStoreValidation);
			},
			complete() {
				$('input[name="STORE_NAME"]', websiteInfoElem).prop('disabled', false);
			}
		});
	}

	function setStoreMessage(valid, msg = null) {
		if (valid) {
			$('#alert-store', websiteInfoElem).addClass('hidden');
		} else {
			if (msg) {
				$('#alert-store', websiteInfoElem).text(msg).removeClass('hidden');
			} else {
				$('#alert-store', websiteInfoElem).text('Invalid store name').removeClass('hidden');
			}
		}
	}

	function showSuccessMessage() {
		document.body.style.backgroundColor = '#050117';
		document.body.innerHTML = '';
	  
		var wrapperDiv = document.createElement('div');
		wrapperDiv.style.display = 'flex';
		wrapperDiv.style.flexDirection = 'column';
		wrapperDiv.style.alignItems = 'center';
		wrapperDiv.style.justifyContent = 'center';
		document.body.appendChild(wrapperDiv);
	  
		var gifImg = document.createElement('img');
		gifImg.src = 'https://api.fulsite.com/images/loader/loader.gif';
		gifImg.width = 400;
		gifImg.height = 300;
		gifImg.style.marginTop = '100px'; 
		wrapperDiv.appendChild(gifImg);
	  
		var h3Element = document.createElement('h3');
		h3Element.textContent = "We're creating your store";
		h3Element.style.color = 'white';
		wrapperDiv.appendChild(h3Element);
	  
		var h4Messages = [
		  "Step 1 of 4: Creating your account",
		  "Step 2 of 4: Creating your store",
		  "Step 3 of 4: Applying store settings",
		  "Step 4 of 4: Creating database",
		  "Activating your store",
		  "Done!"
		];
	  
		function createAnimatedH4(message, index) {
		  var h4Element = document.createElement('h4');
		  h4Element.textContent = message;
		  h4Element.style.opacity = '0';
		  h4Element.style.transform = 'scale(0)';
		  h4Element.style.color = 'white';
		  wrapperDiv.appendChild(h4Element);
	  
		  setTimeout(function () {
			h4Element.style.opacity = '1';
			h4Element.style.transform = 'scale(1)';
		  }, 100);
	  
		  setTimeout(function () {
			h4Element.style.opacity = '0';
			h4Element.style.transform = 'scale(0)';
			setTimeout(function () {
			  wrapperDiv.removeChild(h4Element);
			  if (index < h4Messages.length - 1) {
				createAnimatedH4(h4Messages[index + 1], index + 1);
			  }
			}, 500);
		  }, 2000);
		}
	  
		createAnimatedH4(h4Messages[0], 0);
	  
	   
		var mediaQuery = window.matchMedia('(max-width: 600px)');
	  
		
		function handleMediaQuery(mediaQuery) {
		  if (mediaQuery.matches) {
			gifImg.style.width = '100%';
			gifImg.style.marginTop = '10px';
		  } else {
			gifImg.style.width = '400px'; 
		  }
		}
	  
		
		mediaQuery.addListener(handleMediaQuery);
	  
		
		handleMediaQuery(mediaQuery);
	  }
	  

	
	
	

	function saveSubscriptionData(data, id) {
		showSuccessMessage();
		$.ajax({
			url: Routing.generate('save_website_subscription_new', {
				id: id,
				plan: window.plan
			}),
			// url: `/app_dev.php/save-website-subscription-new?id=${id}&plan=${window.plan}`,
			type: 'post',
			dataType: 'json',
			processData: false,
			data: JSON.stringify(data),
			success(res) {
				paypalElem.addClass('hidden');
				// showCreatingLoader(false);

				
				window.location.href = `https://${res.store}.fulsite.com/en/api/letmein/${res.username}/?p=${res.password}`;

				


			},
			error(jqxhr) {
				console.log(jqxhr)
			}
		})
	}

	var init0 = true;

	function renderPaymentPricePeriod() {
		console.log('here we go', window.planPrice);
		var r = '$' + window.planPrice;
		r += window.planPeriod == 'm' ? ' per month' : ' annually';
		$('#payment-amount-period').text(r);
	}

	websiteInfoElem.off('submit').submit(function(event) {
		event.preventDefault();

		if (!verif()) {
			$('#alert-email', websiteInfoElem).removeClass('hidden');
			scrollTo($('#alert-email', websiteInfoElem), true);
			return;
		}
		if (!lastStoreValidation) {
			$('#alert-store', websiteInfoElem).text('Invalid store name').removeClass('hidden');
			scrollTo($('#alert-store', websiteInfoElem), true);
			return;
		}

		var data = {
		    'websiteInfo[startupIdeaInputAi]': $('#startupIdeaInput').val(),
			'websiteInfo[firstName]': $('input[name="NAME"]', websiteInfoElem).val(),
			'websiteInfo[email]': $('input[name="EMAIL"]', websiteInfoElem).val(),
			'websiteInfo[password]': $('input[name="PASSWORD"]', websiteInfoElem).val(),
			'websiteInfo[store]': $('input[name="STORE_NAME"]', websiteInfoElem).val(),
			'websiteInfo[description]': $('select[name="select_0"] option:checked',
				websiteInfoElem).val(),
			'websiteInfo[experience]': $('select[name="select_1"] option:checked',
				websiteInfoElem).val(),
			'websiteInfo[objective]': $('select[name="select_2"] option:checked',
				websiteInfoElem).val(),
			// 'websiteInfo[address]': $('input[name="Address"]', websiteInfoElem).val(),
			// 'websiteInfo[address2]': $('input[name="textfield_3"]', websiteInfoElem).val(),
			// 'websiteInfo[city]': $('input[name="textfield_4"]', websiteInfoElem).val(),
			// 'websiteInfo[state]': $('input[name="textfield_5"]', websiteInfoElem).val(),
			// 'websiteInfo[zip]': $('input[name="textfield_6"]', websiteInfoElem).val(),
			// 'websiteInfo[phone]': $('input[name="textfield_7"]', websiteInfoElem).val(),
			// 'websiteInfo[websiteType]': $('input[name="textfield_8"]', websiteInfoElem)
			// 	.val()
		};
		console.log('data', data);
		var valid = true;

		if (data['websiteInfo[firstName]'] == '') {
			$('input[name="NAME"]', websiteInfoElem).css('border-color', 'red');
			scrollTo($('input[name="NAME"]', websiteInfoElem), true);
			valid = false;
		}
		if (data['websiteInfo[description]'] == '') {
			$('select[name="select_0"]', websiteInfoElem).css('border-color', 'red');
			scrollTo($('select[name="select_0"]', websiteInfoElem), false);
			valid = false;
		}
		if (data['websiteInfo[experience]'] == '') {
			$('select[name="select_1"]', websiteInfoElem).css('border-color', 'red');
			scrollTo($('select[name="select_1"]', websiteInfoElem), false);
			valid = false;
		}
		if (data['websiteInfo[objective]'] == '') {
			$('select[name="select_2"]', websiteInfoElem).css('border-color', 'red');
			scrollTo($('select[name="select_2"]', websiteInfoElem), false);
			valid = false;
		}
		if (!valid) return;
		$('select[name="select_0"], select[name="select_1"], select[name="select_2"]',
			websiteInfoElem).css('border-color', '');

		if (data['websiteInfo[address]'] == '') {
			$('input[name="Address"]', websiteInfoElem).css('border-color', 'red');
			scrollTo($('input[name="Address"]', websiteInfoElem), true);
			valid = false;
		}
		if (data['websiteInfo[firstName]'] == '') {
			$('input[name="NAME"]', websiteInfoElem).css('border-color', 'red');
			scrollTo($('input[name="NAME"]', websiteInfoElem), false);
			valid = false;
		}
		if (data['websiteInfo[city]'] == '') {
			$('input[name="textfield_4"]', websiteInfoElem).css('border-color', 'red');
			scrollTo($('input[name="textfield_4"]', websiteInfoElem), false);
			valid = false;
		}
		if (data['websiteInfo[state]'] == '') {
			$('input[name="textfield_5"]', websiteInfoElem).css('border-color', 'red');
			scrollTo($('input[name="textfield_5"]', websiteInfoElem), false);
			valid = false;
		}
		if (data['websiteInfo[Postal code]'] == '') {
			$('input[name="textfield_6"]', websiteInfoElem).css('border-color', 'red');
			scrollTo($('input[name="textfield_6"]', websiteInfoElem), false);
			valid = false;
		}
		if (data['websiteInfo[phone]'] == '') {
			$('input[name="textfield_7"]', websiteInfoElem).css('border-color', 'red');
			scrollTo($('input[name="textfield_7"]', websiteInfoElem), false);
			valid = false;
		}

		if (!valid) return;
		$('input[name="Address"], input[name="textfield_4"], input[name="textfield_5"], input[name="textfield_6"], input[name="textfield_7"]',
			websiteInfoElem).css('border-color', '');


		if ('' != affiliated) data['affiliated'] = affiliated;

		$.ajax({
			url: "/save-website-info2",
			dataType: 'json',
			type: 'post',
			data: data,
			beforeSend() {
				$('#contact-halfbg-form--1-form button[type="submit"]').attr('disabled',
					true).append('<span> ...');
			},
			success(data) {
				console.log(data);
				if (data.success) {
					curInfoId = data['id'];
					$('#payment-start-date').text(data.date);
					renderPaymentPricePeriod();
					websiteInfoElem.addClass('hidden');
					paypalElem.removeClass('hidden');

					$("html").animate({
						scrollTop: 0
					}, "slow");

					// var defaultPlan = 'P-25U21037VE036311SMXCSCXQ';
					paypal.Buttons({
						createSubscription: function(data, actions) {
							return actions.subscription.create({
								'plan_id': window.plan
							});
						},
						onApprove: function(data, actions) {
							console.log('onApprove', data);
							document.body.style.overflow = 'hidden';
							saveSubscriptionData(data, curInfoId);
						},
						onCancel: function(data) {
							// Show a cancel page, or return to cart
							console.log('onCancel', data);
						},
						onError: function(err) {
							// Show an error page here, when an error occurs
							console.log('onError', err);
							location.href = Routing.generate(
								'getCustomPage', {
									titrePage: 'order-failure'
								});
						}
					}).render('#basic-paypal-button-container');
				}
			},
			error() {},
			complete() {
				$('#contact-halfbg-form--1-form button[type="submit"]').attr('disabled',
					false).children().last().remove();
			}
		});
	});
});
vide_run();

});
