<!-- scripts -->
{# {% set CDN_URL = app_CDN_url() %} #}
{% set CDN_URL = 'https://d2577j2dd5wuk.cloudfront.net' %}
{% set currentSite = currentSite is defined ? currentSite : app_current_site() %}
{% if skipDuplicateMainJs is defined and skipDuplicateMainJs %}
{# scripts.html.twig was already included and rendered on this page; drop what it
already printed so our own render below only adds the files unique to this file #}
{% do pimcore_head_script().getContainer().exchangeArray([]) %}
{% endif %}
{% if skipDuplicateMainJs is not defined or not skipDuplicateMainJs %}
{% do pimcore_head_script().appendFile(asset(CDN_URL~'/assets/JS/jquery.min.js')) %}
{% do pimcore_head_script().appendFile(asset(CDN_URL~'/assets/JS/popper.min.js')) %}
{% do pimcore_head_script().appendFile(asset(CDN_URL~'/assets/JS/bootstrap.min.js')) %}
{% do pimcore_head_script().appendFile(asset(CDN_URL~'/assets/JS/select2.min.js')) %}
{% do pimcore_head_script().appendFile(asset(CDN_URL~'/assets/JS/moment.min.js')) %}
{% do pimcore_head_script().appendFile(asset(CDN_URL~'/assets/JS/daterangepicker.min.js')) %}
{% do pimcore_head_script().appendFile(asset(CDN_URL~'/assets/JS/jquery.validate.min.js')) %}
{% do pimcore_head_script().appendFile(asset(CDN_URL~'/assets/JS/lighbox.js')) %}
{% do pimcore_head_script().appendFile(asset(CDN_URL~'/assets/JS/functions.js')) %}
{# {% do pimcore_head_script().appendFile(asset(CDN_URL~'/assets/JS/main.js')) %} #}
{% do pimcore_head_script().appendFile(asset('bundles/global/js/main.js')) %}
{% endif %}
{% do pimcore_head_script().appendFile(asset(CDN_URL~'/assets/JS/aos.js')) %}
{% do pimcore_head_script().appendFile(asset(CDN_URL~'/assets/JS/examwizard.js')) %}
{% do pimcore_head_script().appendFile(asset(CDN_URL~'/assets/JS/country/intlTelInput.js')) %}
{# {% do pimcore_head_script().appendFile(asset(CDN_URL~'/assets/JS/TweenMax.min.js')) %}
{% do pimcore_head_script().appendFile(asset(CDN_URL~'/assets/JS/wheel-indicator.js')) %}
{% do pimcore_head_script().appendFile(asset(CDN_URL~'/assets/JS/ScrollToPlugin.min.js')) %}
{% do pimcore_head_script().appendFile(asset(CDN_URL~'/assets/JS/script.js')) %} #}
{# output scripts added before #}
{% block headscripts deferred %}
{{ pimcore_head_script() }}
{% endblock %}
{% if 'salescampaign' in app.request.pathinfo %}
{% if isVerified == 0 %}
<script>
$(window).on('load', function() {
$('#leadForm').modal('show');
});
$('#leadForm').modal({
backdrop: 'static',
keyboard: false
});
</script>
{% endif %}
{% endif %}
{% if not is_granted('IS_AUTHENTICATED_REMEMBERED') and app.request.pathinfo == '/home' %}
<script type="text/javascript">
$(window).on('load', function() {
$('#login').modal('show');
});
</script>
{% endif %}
<script type="text/javascript">
$("#jquery-intl-phone").intlTelInput({});
$("#jquery-intl-phone-access").intlTelInput({});
$("#jquery-intl-phone-manufacture").intlTelInput({});
function pushGtmAuthEvent(eventName, payload) {
window.dataLayer = window.dataLayer || [];
var data = {
event: eventName,
method: 'onsite'
};
payload = payload || {};
for (var key in payload) {
if (Object.prototype.hasOwnProperty.call(payload, key) && payload[key] !== undefined && payload[key] !== null && payload[key] !== '') {
data[key] = payload[key];
}
}
window.dataLayer.push(data);
}
function getValidationErrorReason(errorData) {
if (!errorData) {
return 'Validation Error';
}
if (typeof errorData === 'string') {
return errorData;
}
var reasons = [];
for (var key in errorData) {
if (Object.prototype.hasOwnProperty.call(errorData, key) && errorData[key]) {
reasons.push(key + ': ' + errorData[key]);
}
}
return reasons.length ? reasons.join(', ') : 'Validation Error';
}
function getAuthUserId(data) {
return data && (data.userId || data.user_id || data['user-id']) ? (data.userId || data.user_id || data['user-id']) : '';
}
$(document).on('submit', 'form', function() {
if ($(this).find('#_username').length && $(this).find('#_password').length) {
pushGtmAuthEvent('user-login-submit');
}
});
{% set gtmLoginFailReason = app.session.get('gtm_login_fail_reason') %}
{% if app.request.get('errorFlag') == '1' or gtmLoginFailReason %}
pushGtmAuthEvent('user-login-fail', {
'validation-error': '{{ app.request.get('errorType')|default(gtmLoginFailReason|default('Login Failed'))|e('js') }}'
});
{% do app.session.remove('gtm_login_fail_reason') %}
{% endif %}
$('.country-dropdown-select2').each(function () {
console.log("Initializing select2 for country dropdown");
$(this).select2({
placeholder: 'Select Country *',
dropdownParent: $(this).parent(),
});
$(this).on('change', function() {
var selectedCountry = $(this).val();
console.log("Country changed to: " + selectedCountry);
});
});
// examwizard
var examWizard = $.fn.examWizard({
nextOption: {
callBack: function(){
$("#prev-screen").hide();
$("#back-to-prev-question").show();
if($("#current-question-number-label").text()=="5"){
if ($("#signupAgreeMf").is(":checked")) {
$("#finishExams").removeClass('disabled');
$("#finishExams").show();
}else{
$("#finishExams").show();
$("#finishExams").addClass('disabled');
}
$("#go-to-next-question").hide();
} else {
$("#finishExams").hide();
$("#go-to-next-question").show();
}
}
},
prevOption: {
callBack: function(){
$("#finishExams").hide();
$("#go-to-next-question").show();
if($("#current-question-number-label").text()=="1"){
$("#back-to-prev-question").hide();
$("#prev-screen").show();
} else {
$("#back-to-prev-question").show();
$("#prev-screen").hide();
}
}
}
});
$('#signupAgree').change(function(){
if(this.checked) {
$("#signupDone").removeClass('disabled');
}else{
$("#signupDone").addClass('disabled');
}
});
$('#signupAgreeMf').change(function(){
if(this.checked) {
$("#finishExams").removeClass('disabled');
}else{
$("#finishExams").addClass('disabled');
}
});
$('input[name=SignupType]').click(function(){
//alert('on click type');
var value = $(this).val();
$('#customer-selection').hide();
$('#signupCustTypes').prop('selectedIndex', 0).change();
$('#signupSupplierTypes').prop('selectedIndex', 0).change();
$('#signupSupplierTypesMf').prop('selectedIndex', 0).change();
if(value == 'distributor'){
$('#typeSignup').val('S');
$('#frmSignup').show();
$('#signupSupplierTypes + span').show();
$('#signupCustTypes + span').hide();
}else{
$('#typeSignup').val('C');
$('#frmSignup').show();
$('#signupCustTypes + span').show();
$('#signupSupplierTypes + span').hide();
}
});
$('#signupSupplierTypes').change(function(){
//alert('on click type');
var value = $(this).val();
//alert(value);
// if(value == 'M'){
// $('#manufacturer').show();
// $('#frmSignup').hide();
// $('#signupSupplierTypesMf').prop('selectedIndex', 2).change();
// }else{
$('#frmSignup').show();
$('#manufacturer').hide();
// }
});
$('#signupSupplierTypesMf').change(function(){
//alert('on click type');
var value = $(this).val();
//alert(value);
// if(value == 'M'){
// $('#manufacturer').show();
// $('#frmSignup').hide();
// }else{
$('#frmSignup').show();
$('#manufacturer').hide();
if(value == 'D'){
$('#signupSupplierTypes').prop('selectedIndex', 1).change();
}else if(value == 'S'){
//alert('select stylist');
$('#signupSupplierTypes').prop('selectedIndex', 3).change();
}else{
$('#signupSupplierTypes').prop('selectedIndex', 0).change();
}
// }
});
$('#signupPrevious').click(function(){
//alert('on click type');
$('#customer-selection').show();
$('#frmSignup').hide();
});
$('#prev-screen').click(function(){
//alert('on click type');
$('#customer-selection').show();
$('#manufacturer').hide();
});
jQuery.validator.addMethod("validateURL", function (value, element) {
var regExp = new RegExp(/^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/);
return this.optional(element) || regExp.test(value);
}, "Invalid URL");
window.history.replaceState(null, null, window.location.pathname);
var validationRules = {
// Specify validation rules
errorElement: 'span',
errorClass: 'error-msg',
rules: {
firstName: {
required: true,
// noSpace: true
},
lastName: {
required: true,
// noSpace: true
},
email: {
required: true,
ValidEmail: true,
email: true,
noSpace: true
},
jobRole: {
required: true,
//minlength : 3,
},
companyType: {
required: true,
//minlength : 3,
},
companySize: {
required: true,
//minlength : 3,
},
companyName: {
required: true,
noSpace: true
},
password:{
required: true,
noSpace: true,
},
ConfirmPassword:{
required: true,
noSpace: true,
equalTo: "#password"
},
},
// Specify validation error messages
messages: {
firstName: {
required: 'Required',
maxlength: "Max 50",
// noSpace: 'Required'
},
lastName: {
required: 'Required',
maxlength: "Max 50",
// noSpace: 'Required'
},
email: {
required: 'Required',
email: 'Not valid',
ValidEmail: 'Not valid`',
noSpace: 'Required'
},
jobRole: {
required: 'Required',
},
companyType: {
required: 'Required',
},
companySize: {
required: 'Required',
},
companyName: {
required: 'Required',
noSpace: 'Required'
},
password: {
required: 'Required',
noSpace: 'Required'
},
ConfirmPassword: {
required: 'Required',
noSpace: 'Required',
equalTo: "Password not Matched"
}
},
errorPlacement: function (error, element) {
error.insertAfter(element);
}
};
$('#pimcore_editable_landing_bookdemo').click(function (e) {
$('select').prop('selectedIndex', 0).change();
$("#email-error, #companySize-error, #lastName-error,#firstName-error,#companyType-error,#jobRole-error,#companyName-error").html("");
});
$('#close-btn').click(function (e) {
$("#frmBookDemo").get(0).reset();
$('select').prop('selectedIndex', 0).change();
$('#companyType').prop('selectedIndex', 0).change();
$("#bookAdemo_success").hide();
$("#bookAdemo_normal").show();
$('#frmBookDemo').validate(validationRules).reset();
$("#email-error, #companySize-error, #lastName-error,#firstName-error,#companyType-error,#jobRole-error,#companyName-error").html("");
});
$("#signupPrevious").click(function (e) {
$('select').prop('selectedIndex', 0).change();
$("#signupDone").addClass('disabled');
$("#finishExams").addClass('disabled');
$('#signupCustTypes').prop('selectedIndex', 0).change();
$('#signupSupplierTypes').prop('selectedIndex', 0).change();
$('#signupSupplierTypesMf').prop('selectedIndex', 0).change();
document.getElementById("customer-selection").reset();
document.getElementById("frmSignup").reset();
document.getElementById("examwizard-question").reset();
$("#frmSignup").hide();
$("#manufacturer").hide();
for (let el of document.querySelectorAll('span.error-msg')) el.style.display = 'none';
document.querySelector('.file-upload-label').textContent = "Please attach your portfolio";
$('.remove-file').removeClass('attached');
const fileInput = document.querySelector('#portfolio-upload');
fileInput.value="";
});
$("#prev-screen").click(function (e) {
$('select').prop('selectedIndex', 0).change();
$("#signupDone").addClass('disabled');
$("#finishExams").addClass('disabled');
$('#signupCustTypes').prop('selectedIndex', 0).change();
$('#signupSupplierTypes').prop('selectedIndex', 0).change();
$('#signupSupplierTypesMf').prop('selectedIndex', 0).change();
document.getElementById("customer-selection").reset();
document.getElementById("frmSignup").reset();
document.getElementById("examwizard-question").reset();
$("#frmSignup").hide();
$("#manufacturer").hide();
for (let el of document.querySelectorAll('span.error-msg')) el.style.display = 'none';
document.querySelector('.file-upload-label').textContent = "Please attach your portfolio";
$('.remove-file').removeClass('attached');
const fileInput = document.querySelector('#portfolio-upload');
fileInput.value="";
});
$('#close-btn-signup').click(function (e) {
$("#signup_success").hide();
$("#currentQuestionNumber").val(1);
$('select').prop('selectedIndex', 0).change();
$('#signupCustTypes').prop('selectedIndex', 0).change();
$('#signupSupplierTypes').prop('selectedIndex', 0).change();
$('#signupSupplierTypesMf').prop('selectedIndex', 0).change();
$("#current-question-number-label").text('1');
var count=0;
for (let el of document.querySelectorAll('div.question')){
el.classList.remove("hidden");
if(count != 0){
el.classList.add("hidden");
}
count++;
}
$("#go-to-next-question").removeClass('disabled');
$("#go-to-next-question").show();
$("#finishExams").hide();
$("#frmSignup").hide();
$("#manufacturer").hide();
$("#customer-selection").show();
document.getElementById("customer-selection").reset();
document.getElementById("frmSignup").reset();
document.getElementById("examwizard-question").reset();
$("#signupDone").addClass('disabled');
$("#finishExams").addClass('disabled');
for (let el of document.querySelectorAll('span.error-msg')) el.style.visibility = 'hidden';
$("#signup_form").show();
});
$('#close-btn-signup-form').click(function (e) {
$("#signup_success").hide();
// $("#currentQuestionNumber").val(1);
// $('select').prop('selectedIndex', 0).change();
// $('#signupCustTypes').prop('selectedIndex', 0).change();
// $('#signupSupplierTypes').prop('selectedIndex', 0).change();
// $('#signupSupplierTypesMf').prop('selectedIndex', 0).change();
// $("#current-question-number-label").text('1');
// var count=0;
// for (let el of document.querySelectorAll('div.question')){
// el.classList.remove("hidden");
// if(count != 0){
// el.classList.add("hidden");
// }
// count++;
// }
// $("#go-to-next-question").removeClass('disabled');
// $("#go-to-next-question").show();
// $("#finishExams").hide();
// $("#frmSignup").hide();
// $("#manufacturer").hide();
// $("#customer-selection").show();
// document.getElementById("customer-selection").reset();
document.getElementById("frmSignup").reset();
$("#frmSignup").show();
$(".modal-header").show();
// document.getElementById("examwizard-question").reset();
$("#signupDone").addClass('disabled');
// $("#finishExams").addClass('disabled');
// for (let el of document.querySelectorAll('span.error-msg')) el.style.visibility = 'hidden';
// $("#signup_form").show();
});
var validationRulesContact = {
// Specify validation rules
errorElement: 'span',
errorClass: 'error-msg',
rules: {
contactName: {
required: true,
noSpace: false
},
contactEmail: {
required: true,
ValidEmail: true,
email: true,
noSpace: true
}
},
// Specify validation error messages
messages: {
contactName: {
required: 'Required',
noSpace: 'Required',
maxlength: "Max 50",
},
contactEmail: {
required: 'Required',
email: "Not valid",
ValidEmail: 'Not valid'
}
},
errorPlacement: function (error, element) {
error.insertAfter(element);
}
};
var validationRulesSignup = {
// Specify validation rules
errorElement: 'span',
errorClass: 'error-msg',
rules: {
firstName: {
required: true,
// noSpace: true
},
companyName: {
required: true,
//noSpace: true
},
customerType: {
required: true,
},
email: {
required: true,
ValidEmail: true,
email: true,
noSpace: true
},
/*contactNumber:{
required: true,
noSpace: true
},*/
password:{
required: true,
noSpace: true,
},
ConfirmPassword:{
required: true,
noSpace: true,
equalTo: "#password"
},
countryName:{
required: true,
},
website:{
validateURL: true,
required: false,
}
},
// Specify validation error messages
messages: {
firstName: {
required: 'Required',
// noSpace: 'Required',
maxlength: "Max 50",
},
companyName: {
required: 'Required',
//noSpace: 'Required',
maxlength: "Max 50",
},
customerType: {
required: 'Required'
},
email: {
required: 'Required',
email: "Not valid",
ValidEmail: 'Not valid'
},
/*contactNumber: {
required: 'Required',
noSpace: 'Required'
},*/
password: {
required: 'Required',
noSpace: 'Required'
},
ConfirmPassword: {
required: 'Required',
noSpace: 'Required',
equalTo: "Password not Matched"
},
countryName:{
required: 'Required',
}
},
errorPlacement: function (error, element) {
error.insertAfter(element);
}
};
var validationRulesSignupMf = {
// Specify validation rules
errorElement: 'span',
errorClass: 'error-msg',
rules: {
signupFirstNameMf: {
required: true,
// noSpace: true
},
signupCompanyNameMf: {
required: true,
//noSpace: true
},
signupEmailMf: {
required: true,
ValidEmail: true,
email: true,
noSpace: true
},
contactNumbermanufacture: {
required: true,
noSpace: true
}
},
// Specify validation error messages
messages: {
signupFirstNameMf: {
required: 'Required',
// noSpace: 'Required'
},
signupCompanyNameMf: {
required: 'Required',
//noSpace: 'Required'
},
signupEmailMf: {
required: 'Required',
email: "Not valid",
ValidEmail: 'Not valid'
},
contactNumbermanufacture: {
required: 'Required',
noSpace: 'Required'
}
},
errorPlacement: function (error, element) {
error.insertAfter(element);
}
};
var validationRulesSC = {
// Specify validation rules
errorElement: 'span',
errorClass: 'error-msg',
rules: {
SCFirstName: {
required: true,
// noSpace: true
},
SCLastName: {
required: true,
// noSpace: true
},
SCphone: {
required: true,
noSpace: true
},
SCemail: {
required: true,
ValidEmail: true,
email: true,
noSpace: true
},
SCaccessCode: {
required: true,
noSpace: true
}
},
// Specify validation error messages
messages: {
SCFirstName: {
required: 'Required',
// noSpace: 'Required'
},
SCLastName: {
required: 'Required',
// noSpace: 'Required'
},
SCphone: {
required: 'Required',
noSpace: 'Required'
},
SCemail: {
required: 'Required',
email: "Not valid",
ValidEmail: 'Not valid'
},
SCaccessCode: {
required: 'Required',
noSpace: 'Required'
}
},
errorPlacement: function (error, element) {
error.insertAfter(element);
}
};
$(function () {
//alert('test');
jQuery.validator.addMethod("ValidEmail", function (value, element) {
var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
return regex.test(value);
});
jQuery.validator.addMethod("noSpace", function (value, element) {
return value.indexOf(" ") < 0 && value != "";
});
$('#frmBookDemo').validate(validationRules);
//alert('before submit');
$('#frmBookDemo').submit(function (event) {
//submit form with ajax - start
var firstName = $("#firstName").val();
var lastName = $("#lastName").val();
var email = $("#email").val();
var jobRole = $("#jobRole").val();
var companyType = $("#companyType").val();
var companySize = $("#companySize").val();
var companyName = $("#companyName").val();
// stop the form from submitting the normal way and refreshing the page
event.preventDefault();
if ($('#frmBookDemo').valid()) {
$.ajax({
type: "POST",
url: "/booking",
data: "firstName=" + firstName + "&lastName=" + lastName + "&email=" + email + "&jobRole=" + jobRole + "&companyType=" + companyType + "&companySize=" + companySize + "&companyName=" + companyName + "&submitAction=bookAdemo",
success: function (data) {
if (data == 'success') {
$("#bookAdemo_success").show();
$("#bookAdemo_normal").hide();
} else {
$("#bookAdemo_error").show();
}
}
});
//alert('ajax end');
}
});
$('#frmSignup').validate(validationRulesSignup);
$('#frmSignup').submit(function (event) {
event.preventDefault();
var firstName = $("#signupFirstName").val();
var email = $("#signupEmail").val();
var companyName = $("#signupCompanyName").val();
var lastName = $("#signupLastName").val();
var phoneCode = $("#jquery-intl-phone").val() ?? "";
var phone = $("#signupContactNumber").val() ?? "";
var password = $("#password").val();
//var signupSupplierTypes = $('input[name="signupSupplierTypes"]:selectedIndex').val();
var signupSupplierType = $('#signupSupplierTypes option:selected').val();
var signupCustType = $('#signupCustTypes').find(":selected").text();
//var type = $('input[name="type"]:checked').val();
// var type = $("#customerType").val();
var type = $('#customerType').val();
//var country = $('#signupCountry').val();
var website = $('#signupWebsite').val();
var country = $('#signupCountry').select2('val');
if(type == 'R'){
var actionurl = '/customerSignup';
}else{
var actionurl = '/supplierSignup';
}
signupSupplierType = type;
signupCustType = type;
// event.preventDefault();
if ($('#frmSignup').valid()) {
// reCAPTCHA is mandatory when it is configured on the page
var recaptchaToken = "";
if ($('#frmSignup').find('.g-recaptcha').length) {
recaptchaToken = $('#frmSignup').find('[name="g-recaptcha-response"]').val() || "";
if (recaptchaToken === "") {
$('#signupRecaptcha-error').text('Please confirm you are not a robot').show();
return false;
}
$('#signupRecaptcha-error').hide();
}
pushGtmAuthEvent('user-signup-submit');
$('#signupMismatchData-error').remove();
$.ajax({
type: "POST",
url: actionurl,
data: "firstName=" + firstName + "&lastName="+lastName+"&email=" + email + "&companyName=" + companyName + "&supplierType=" + signupSupplierType + "&custType=" + signupCustType + "&password=" + password + "&country=" + country + "&website=" + website + "&phoneCode=" + phoneCode + "&phone=" + phone + "&g-recaptcha-response=" + encodeURIComponent(recaptchaToken),
success: function (data) {
data = JSON.parse(data);
if (data.status == 'success') {
pushGtmAuthEvent('user-signup-success', {
'user-id': getAuthUserId(data)
});
$.ajax({
type: "POST",
url: '/signupEmails',
data: "firstName=" + firstName + "&lastName="+lastName+"&email=" + email + "&companyName=" + companyName + "&supplierType=" + signupSupplierType + "&custType=" + signupCustType + "&password=" + password + "&country=" + country + "&website=" + website + "&phoneCode=" + phoneCode + "&phone=" + phone,
success: function (data) {
data = JSON.parse(data);
if (data.status == 'success') {
// console.log("hii");
}
}
});
if(type != 'R'){
signupCustType = "Supplier";
actionurl = '/customerSignup';
$.ajax({
type: "POST",
url: actionurl,
data: "firstName=" + firstName + "&lastName="+lastName+"&email=" + email + "&companyName=" + companyName + "&supplierType=" + signupSupplierType + "&custType=" + signupCustType + "&password=" + password + "&country=" + country + "&website=" + website + "&phoneCode=" + phoneCode + "&phone=" + phone,
success: function (data) {
data = JSON.parse(data);
if (data.status == 'success') {
// console.log("hii");
}
}
});
}
$("#signupCountry").val("").trigger("change");
$("#frmSignup").hide();
$(".modal-header").hide();
$("#signup_success").show();
$('#signupMismatchData-error').remove();
} else {
var error = data.errorData;
pushGtmAuthEvent('user-signup-fail', {
'validation-error': getValidationErrorReason(error)
});
//alert(error.companyName);
//alert(error.email);
if(error.email){
$('<span id="signupEmail-error" class="error-msg">'+error.email+'</span>').insertAfter("#signupEmail");
}
if(error.companyName){
$('<span id="signupCompanyName-error" class="error-msg">'+error.companyName+'</span>').insertAfter("#signupCompanyName");
}
if(error.signupContactNumber){
$('<span id="signupContactNumber-error" class="error-msg">'+error.signupContactNumber+'</span>').insertAfter("#signupContactNumber");
}
if(error.mismatchData){
$('<span id="signupMismatchData-error" class="error-msg" style="right: 145px;">'+error.mismatchData+'</span>').insertAfter(".modal-header");
}
if(error.recaptcha){
$('#signupRecaptcha-error').text(error.recaptcha).show();
}
// a token is single use at Google, so the widget
// must be reset before the customer tries again
if (window.grecaptcha && $('#frmSignup').find('.g-recaptcha').length) {
try { window.grecaptcha.reset(); } catch (e) {}
}
$("#signup_form").show();
$("#signup_success").hide();
}
},
error: function () {
pushGtmAuthEvent('user-signup-fail', {
'validation-error': 'Network Error'
});
}
});
} else {
pushGtmAuthEvent('user-signup-fail', {
'validation-error': 'Validation Error'
});
}
});
$('#examwizard-question').validate(validationRulesSignupMf);
$('#go-to-next-question').on('click', function(event) {
var screen = $("#currentQuestionNumber").val();
//alert(screen);
if(screen == 1){
//alert('validate first screen');
event.preventDefault();
if ($('#examwizard-question').valid()) {
//return true;
//alert('validated');
var actionurl = '/supplierSignupCheck';
var firstName = $("#signupFirstNameMf").val();
var email = $("#signupEmailMf").val();
var companyName = $("#signupCompanyNameMf").val();
var clients = $("#signupClientsMf").val();
var lastName = $("#signupLastNameMf").val();
var fd = new FormData();
fd.append('firstName',firstName);
fd.append('lastName',lastName);
fd.append('email',email);
fd.append('companyName',companyName);
fd.append('clients',clients);
$.ajax({
type: "POST",
url: actionurl,
data: fd,
contentType: false,
processData: false,
success: function (data) {
data = JSON.parse(data);
//alert(data.status);
if (data.status == 'success') {
$("#current-question-number-label").text('2');
$("#currentQuestionNumber").val(2);
var count=0;
for (let el of document.querySelectorAll('div.question')){
el.classList.remove("hidden");
if(count != 1){
el.classList.add("hidden");
}
count++;
}
$("#back-to-prev-question").show();
$("#prev-screen").hide();
$("#back-to-prev-question").removeClass('disabled');
} else {
var error = data.errorData;
pushGtmAuthEvent('user-signup-fail', {
'validation-error': getValidationErrorReason(error)
});
//alert(error.companyName);
//alert(error.email);
$("#current-question-number-label").text('1');
$("#currentQuestionNumber").val(1);
if(error.email){
$('<span id="signupEmailMf-error" class="error-msg">'+error.email+'</span>').insertAfter("#signupEmailMf");
}
if(error.companyName){
$('<span id="signupCompanyNameMf-error" class="error-msg">'+error.companyName+'</span>').insertAfter("#signupCompanyNameMf");
}
}
},
error: function () {
pushGtmAuthEvent('user-signup-fail', {
'validation-error': 'Network Error'
});
}
});
$("#current-question-number-label").text('1');
$("#currentQuestionNumber").val(1);
return false;
}else{
pushGtmAuthEvent('user-signup-fail', {
'validation-error': 'Validation Error'
});
//alert('else validated');
$("#current-question-number-label").text('1');
$("#currentQuestionNumber").val(1);
return false;
}
}
});
$('#examwizard-question').submit(function (event) {
//alert("before submit");
// stop the form from submitting the normal way and refreshing the page
var firstName = $("#signupFirstNameMf").val();
var email = $("#signupEmailMf").val();
var companyName = $("#signupCompanyNameMf").val();
var lastName = $("#signupLastNameMf").val();
var signupFactorySizeMf = $("#signupFactorySizeMf").val();
var signupEmployeesMf = $("#signupEmployeesMf").val();
var signupMachinesMf = $("#signupMachinesMf").val();
var signupPortMf = $('#signupPortMf').find(":selected").val();
var signupFOBMf = $("#signupFOBMf").val();
var clients = $("#signupClientsMf").val();
var phoneCode = $("#jquery-intl-phone-manufacture").val();
var phone = $("#signupContactNumber-manufacture").val();
///alert(firstName);
var signupCountryMf = '';
$('input[name="signupCountryMf"]:checked').each(function() {
signupCountryMf = signupCountryMf + this.value+',';
});
var signupCategoryMf = '';
$('input[name="signupCategoryMf"]:checked').each(function() {
signupCategoryMf = signupCategoryMf + this.value+',';
});
var signupComplianceMf = '';
$('input[name="signupComplianceMf"]:checked').each(function() {
signupComplianceMf = signupComplianceMf + this.value+',';
});
var signupSupplierType = $('#signupSupplierTypesMf option:selected').val();
var fd = new FormData();
fd.append('firstName',firstName);
fd.append('lastName',lastName);
fd.append('email',email);
fd.append('companyName',companyName);
fd.append('signupFactorySizeMf',signupFactorySizeMf);
fd.append('signupEmployeesMf',signupEmployeesMf);
fd.append('signupMachinesMf',signupMachinesMf);
fd.append('signupPortMf',signupPortMf);
fd.append('signupFOBMf',signupFOBMf);
fd.append('signupCountryMf',signupCountryMf);
fd.append('signupCategoryMf',signupCategoryMf);
fd.append('signupComplianceMf',signupComplianceMf);
fd.append('supplierType',signupSupplierType);
fd.append('phoneCode',phoneCode);
fd.append('phone',phone);
fd.append('clients',clients);
var files = $('#portfolio-upload')[0].files;
// Check file selected or not
//alert(files.length);
if(files.length > 0 ){
fd.append('file',files[0]);
}
var actionurl = '/supplierSignup';
event.preventDefault();
//if ($('#frmSignup').valid()) {
//return true;
pushGtmAuthEvent('user-signup-submit');
$.ajax({
type: "POST",
url: actionurl,
data: fd,
contentType: false,
processData: false,
success: function (data) {
data = JSON.parse(data);
if (data.status == 'success') {
pushGtmAuthEvent('user-signup-success', {
'user-id': getAuthUserId(data)
});
$("#signup_success").show();
$("#signup_form").hide();
} else {
pushGtmAuthEvent('user-signup-fail', {
'validation-error': getValidationErrorReason(data.errorData)
});
$("#signup_form").show();
$("#signup_success").hide();
}
},
error: function () {
pushGtmAuthEvent('user-signup-fail', {
'validation-error': 'Network Error'
});
}
});
//}
});
$('#frmContactUs').validate(validationRulesContact);
//alert('before submit');
$('#frmContactUs').submit(function (event) {
//submit form with ajax - start
var contactName = $("#contactName").val();
var contactMessage = $("#contactMessage").val();
var contactEmail = $("#contactEmail").val();
var contactInquiryType = $("#contactInquiryType").val();
// stop the form from submitting the normal way and refreshing the page
event.preventDefault();
console.log('1111');
if ($('#frmContactUs').valid()) {
//alert('validated');
console.log('2222');
//return true;
//alert('ajax start');
//alert("name=" + contactName +"&message=" +contactMessage+"&email=" +contactEmail+"&inquiryType=" +contactInquiryType+"&submitAction=contactUs");
$.ajax({
type: "POST",
url: "/contact",
data: "name=" + contactName + "&message=" + contactMessage + "&email=" + contactEmail + "&inquiryType=" + contactInquiryType + "&submitAction=contactUs",
success: function (data) {
if (data == 'success') {
$("#frmContactUs").get(0).reset();
$('#contactInquiryType').prop('selectedIndex', 0).change();
// $("#contactusmodal").modal('hide');
// $("#success-message").html("Thanks! Our team will contact you shortly.");
// $("#contact_success").modal('show');
} else {
$("#contact_error").show();
}
}
});
$("#contactusmodal").modal('hide');
$("#success-message").html("Thanks! Our team will contact you shortly.");
$("#contact_success").modal('show');
//alert('ajax end');
}
});
$('#frmScAccessCode').validate(validationRulesSC);
//alert('before submit');
$('#frmScAccessCode').submit(function (event) {
//submit form with ajax - start
var firstName = $("#SCFirstName").val();
var lastName = $("#SCLastName").val();
var email = $("#SCemail").val();
var phone = $("#SCphone").val();
var accessCode = $("#SCaccessCode").val();
// stop the form from submitting the normal way and refreshing the page
event.preventDefault();
if ($('#frmScAccessCode').valid()) {
$.ajax({
type: "POST",
data: $('#frmScAccessCode').serialize(),
success: function (data) {
data = JSON.parse(data);
if (data.status == 'success') {
$('#leadForm').modal('hide');
}else{
var error = data.errorData;
if(error.accessCode){
$('<span id="SCaccessCode-error" class="error-msg">Invalid!!</span>').insertAfter("#SCaccessCode");
}
}
}
});
//alert('ajax end');
}
});
});
function sitemenuValueStore(id) {
$.post("/sitemenuValue", {"siteMenuId": id});
}
function validatePassword() {
$.validator.addMethod( "pattern", function( value, element, param ) {
if ( this.optional( element ) ) {
return true;
}
if ( typeof param === "string" ) {
param = new RegExp( "^(?:" + param + ")$" );
}
return param.test( value );
}, "Invalid format." );
var validator = $("#resetPassword").validate({
rules: {
newPassword: {
required: true,
minlength: 6,
maxlength: 20,
pattern: "((?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).{6,20})"
},
confirmPassword: {
equalTo: "#newPassword"
}
},
messages: {
newPassword: {
required: "Please enter your new password",
minlength: "Please enter at least 6 characters",
maxlength: "Please enter no more than 20 characters",
pattern: "Please enter a valid password. 1 number,1 Capital Alphabet "
},
confirmPassword: " Enter Confirm Password Same as Password"
}
});
if (validator.form()) {
$("#resetPassword").submit();
}
}
// $(".moveToDiv").on("click", function( e ) {
// e.preventDefault();
// document.getElementById("signupToExplore").focus()
// });
function salesCampaignPdfPreview(salesCampaignId){
$(".bs-loader-pdf").show();
var url = "/salesCampaignPreview/"+salesCampaignId;
$('#myModal-wish-catalog').hide();
$(".salesCampaign-catalog").html("");
$.get( url, function( data ) {
$(".salesCampaign-catalog").append(data);
$("#myModal-wish-catalog").modal('show');
$(".bs-loader-pdf").hide();
});
}
function genrateSalesCampaignXLS(salesCampaignId){
$.ajax({
type: "POST",
url:'/salesxls',
// dataType:'json',
data: ({salesCampaignId: salesCampaignId}),
beforeSend: function(){
$(".bs-loader").show();
},
success: function(response)
{
$(".bs-loader").hide();
data = JSON.parse(response);
// console.log(data.ExportLink);
window.open(data.ExportLink, '_blank')
}
});
}
function genrateSalesCampaignPDF(salesCampaignId){
$.ajax({
type: "POST",
url:'/salesCampaignPdf',
dataType:'json',
data: ({salesCampaignId: salesCampaignId}),
beforeSend: function(){
$(".bs-loader").show();
},
success: function(response)
{
//console.log(respose);
$(".bs-loader").hide();
window.open(response);
}
});
}
$(document).ready(function(){
var error = $("#_error").val();
if(error){
$("#login").modal('show');
}
$("#buyerbtn").addClass('active');
$("#buyer").show();
$("#supplier").hide();
$("#designer").hide();
//ON SIGNUP MODAL SHOW FORCE TO SHOW FORM
$("#signup").on("shown.bs.modal",function(){
$("#frmSignup").show();
$("body").addClass("singup-modal-body");
});
$("#signup").on("hidden.bs.modal",function(){
$("body").removeClass("singup-modal-body");
});
});
$(".benefit-btn").on("click", function( e ) {
var value = this.id;
$(this).addClass('active');
if(value == 'buyerbtn'){
$("#supplier").removeClass('active');
$("#designerbtn").removeClass('active');
$("#buyer").show();
$("#supplier").hide();
$("#designer").hide();
}else if(value == 'supplierbtn'){
$("#buyerbtn").removeClass('active');
$("#designerbtn").removeClass('active');
$("#buyer").hide();
$("#supplier").show();
$("#designer").hide();
}else if(value == "designerbtn"){
$("#supplierbtn").removeClass('active');
$("#buyerbtn").removeClass('active');
$("#buyer").hide();
$("#supplier").hide();
$("#designer").show();
}
$("video").each(function(){
$(this).get(0).pause();
});
$(".benefit").css("background-color", $(this).attr("data-color"));
});
</script>
{% if '/blog' in app.request.pathinfo %}
<script>
$(document).ready(function(){
var blogId = $("#blogId").val();
// alert("hii");
$.ajax({
type: "POST",
url: "/saveBlogPageView",
data: "blogId=" + blogId,
success: function (data) {
}
});
});
</script>
{% endif %}
{% if 'marketingreport' in app.request.pathinfo %}
<script type="text/javascript">
$(document).ready(function(){
var firstName = $('#signupFirstName');
var lastName = $('#signupLastName');
var email = $('#signupEmail');
var downloadButton = $('#downloadButton');
function checkInputs() {
var emailRegex = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
if(firstName.val() && lastName.val() && emailRegex.test(email.val())) {
downloadButton.prop('disabled', false); // Enable the button
} else {
downloadButton.prop('disabled', true); // Disable the button
}
}
firstName.on('input', checkInputs);
lastName.on('input', checkInputs);
email.on('input', checkInputs);
$("#download-report-form").on('submit', function(e){
e.preventDefault();
var formData = $(this).serialize();
$.ajax({
url: "/marketingreport/response",
type: "post",
data: formData,
success: function(response) {
data = JSON.parse(response);
if (data.status == 'success') {
$('#thankyou-popup').modal('show');
}
},
error: function(jqXHR, textStatus, errorThrown) {
// Handle the error here
}
});
});
});
</script>
{% endif %}
{% if 'salescampaign' in app.request.pathinfo %}
<script>
$(document).ready(function(){
$(".product-download-icon").click(function(e){
e.preventDefault();
var parameters = $(this).data('parameters');
$.ajax({
url: $(this).attr('href'),
type: 'get',
data: parameters,
success: function (response) {
data = JSON.parse(response);
// downloadImageThumbnailAction returns {"success": false, "message": ...}
// when the thumbnail cannot be generated. Without this guard the modal
// opens with an undefined imageUrl and a dead download link.
if (!data.success) {
alert(data.message || 'Unable to load the high resolution image. Please try again later.');
return;
}
var downloadFile = data.downloadFile;
var downloadFileName = data.downloadFileName;
// Clear the previous URL
$('.produt-big-image img').attr('src', '');
$('.download-popup-img').attr('href', '');
// Set the new URL
$('.produt-big-image img').attr('src', data.imageUrl);
$('#downLoadProductImg').modal('show');
$('.download-popup-img').on('click', function(e) {
e.preventDefault(); // prevent the default action
window.location = '/download-image-popup?downloadFile=' + encodeURIComponent(downloadFile) + '&downloadFileName=' + encodeURIComponent(downloadFileName);
});
}
});
});
});
</script>
{# common image download model popup #}
<div class="modal signup-modal download-product-image" id="downLoadProductImg">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header p-0">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<a href="#" class="download-popup-img">
<img src="https://d2fzew76uxzkhe.cloudfront.net/assets/images/download-arrow.svg">
</a>
</div>
<!-- Modal body -->
<div class="modal-body p-0">
<div class="row">
<div class="col-lg-12 text-center col-md-12 col-12">
<div class="produt-big-image">
<img src="" alt="product big image">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{# common image download popup end #}
{% endif %}
{% if currentSite == 'NuFind' %}
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-236265253-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-236265253-1');
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-236265253-1', 'auto');
ga('send', 'pageview');
</script>
{% endif %}
<script>
document.addEventListener('DOMContentLoaded', function() {
// ---------------------------------------------
// 1️⃣ Enable "READY, SET, GO!" only if email is filled and valid
// ---------------------------------------------
const emailInput = document.getElementById('_username');
const readyBtn = document.querySelector('.level-start .btn-sa-pink');
if (!emailInput || !readyBtn) {
return;
}
emailInput.addEventListener('input', function() {
if (/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/.test(emailInput.value.trim())) {
readyBtn.classList.remove('btn-disabled');
readyBtn.removeAttribute('disabled');
} else {
readyBtn.classList.add('btn-disabled');
readyBtn.setAttribute('disabled', 'disabled');
}
});
// ---------------------------------------------
// 2️⃣ Initial setup - show only start screen
// ---------------------------------------------
document.querySelectorAll('.level-screens-main').forEach(el => el.style.display = 'none');
document.querySelector('.level-start').style.display = 'block';
let totalLevels = 4;
let answers = {};
let userEmail = '';
let isSubmitting = false;
// ---------------------------------------------
// 3️⃣ Start Quiz
// ---------------------------------------------
readyBtn.addEventListener('click', function(e) {
e.preventDefault();
if (readyBtn.classList.contains('btn-disabled')) return;
userEmail = emailInput.value.trim();
document.querySelector('.level-start').style.display = 'none';
document.querySelector('.level-1').style.display = 'block';
});
// ---------------------------------------------
// 4️⃣ Levels 1 - 3 logic
// ---------------------------------------------
for (let i = 1; i <= totalLevels; i++) {
let levelDiv = document.querySelector(`.level-${i}`);
if (levelDiv) {
let radios = levelDiv.querySelectorAll('.radio-group');
let nextBtn = levelDiv.querySelector('.level-btn .btn-sa-pink');
nextBtn.classList.add('btn-disabled');
//nextBtn.setAttribute('disabled', 'disabled');
radios.forEach(function(group) {
group.addEventListener('change', function() {
let allAnswered = Array.from(radios).every(g => g.querySelector('input[type=radio]:checked'));
console.log(`Level ${i} allAnswered:`, allAnswered);
if (allAnswered) {
nextBtn.classList.remove('btn-disabled');
nextBtn.removeAttribute('disabled');
} else {
nextBtn.classList.add('btn-disabled');
//nextBtn.setAttribute('disabled', 'disabled');
}
});
});
nextBtn.addEventListener('click', function(e) {
e.preventDefault();
if (nextBtn.classList.contains('btn-disabled')) return;
radios.forEach(function(group, idx) {
let checked = group.querySelector('input[type=radio]:checked');
if (checked) {
answers[`level${i}_q${idx + 1}`] = parseInt(checked.labels[0].innerText);
}
});
levelDiv.style.display = 'none';
if (i < totalLevels) {
document.querySelector(`.level-${i + 1}`).style.display = 'block';
}
if (i === totalLevels) {
let total = Object.values(answers).reduce((a, b) => a + b, 0);
console.log('Sending data to backend:', { email: userEmail, score: total, answers: answers });
// Show circular loader
const loader = document.querySelector('.new-circle-loader-with-percentage');
const percentText = loader.querySelector('.percentage-text');
loader.style.display = 'flex';
percentText.textContent = '0%';
// Animate percentage (slower and smoother progress)
let percent = 0;
let interval = setInterval(() => {
percent += 2; // Smaller, consistent step for smoother effect
if (percent > 100) percent = 100;
percentText.textContent = percent + '%';
if (percent >= 100) clearInterval(interval);
}, 150); // Slower interval (150ms)
$.ajax({
url: '/sourcing-assessment',
type: 'POST',
dataType: 'json',
contentType: 'application/json',
data: JSON.stringify({ email: userEmail, score: total, answers: answers }),
success: function(resp) {
console.log('Backend response:', resp);
clearInterval(interval);
percentText.textContent = '100%';
setTimeout(function() {
loader.style.display = 'none';
document.querySelectorAll('.level-screens-main').forEach(el => el.style.display = 'none');
document.querySelector('.get-your-score').style.display = 'block';
// Show all score sections
document.querySelectorAll('.final-level-score .score-section').forEach(sec => sec.style.display = 'block');
// Hide all score badges
document.querySelectorAll('.final-level-score .score-badge').forEach(badge => badge.style.display = 'none');
let sec;
if (total >= 44) {
sec = document.querySelector('.final-level-score .score-section');
} else if (total >= 30) {
sec = document.querySelector('.final-level-score .score-section.yellow');
} else {
sec = document.querySelector('.final-level-score .score-section.red');
}
// Show only the correct score badge and set the score
if (sec) {
let badge = sec.querySelector('.score-badge');
if (badge) {
badge.style.display = 'flex';
badge.querySelector('span').innerText = total;
}
}
isSubmitting = false;
}, 1200); // delay for effect
},
error: function() {
clearInterval(interval);
loader.style.display = 'none';
getScoreBtn.classList.remove('btn-disabled');
getScoreBtn.removeAttribute('disabled');
isSubmitting = false;
alert('An error occurred while submitting your score. Please try again.');
}
});
}
});
}
}
// Handle modal show to ensure listeners are active
$('#SourcingAssessment').on('shown.bs.modal', function() {
console.log('Modal fully shown, re-checking final radios');
const getScoreBtn = document.querySelector('.level-final .get-score-btn');
if (getScoreBtn) {
const finalRadios = document.querySelectorAll('.level-final .radio-group');
let allAnswered = Array.from(finalRadios).every(g => g.querySelector('input[type=radio]:checked'));
if (allAnswered) {
getScoreBtn.classList.remove('btn-disabled');
getScoreBtn.removeAttribute('disabled');
}
}
});
$('#SourcingAssessment .close').on('click', function() {
// Hide the modal
$('#SourcingAssessment').modal('hide');
// Reset email input and button
$('#_username').val('');
$('.level-start .btn-sa-pink').addClass('btn-disabled').attr('disabled', 'disabled');
// Reset answers and state
answers = {};
userEmail = '';
isSubmitting = false;
// Uncheck all radios
$('#SourcingAssessment input[type=radio]').prop('checked', false);
// Hide all levels and loader
$('#SourcingAssessment .level-screens-main').hide();
$('#SourcingAssessment .new-circle-loader-with-percentage').hide();
// Show start screen
$('#SourcingAssessment .level-start').show();
// Reset all next/score buttons
$('#SourcingAssessment .btn-sa-pink').addClass('btn-disabled').attr('disabled', 'disabled');
});
});
// Sample Kit Registration Form Submissio
document.addEventListener('DOMContentLoaded', function() {
const form = document.getElementById('smapleKit3sForm');
const submitBtn = document.getElementById('smplekitDone');
const successPopup = $('#samplekit-success-popup');
if (!form) {
return;
}
function showError(input, message) {
let errorSpan = input.parentNode.querySelector('.error-msg');
if (!errorSpan) {
errorSpan = document.createElement('span');
errorSpan.className = 'error-msg';
errorSpan.style.display = 'none';
input.parentNode.appendChild(errorSpan);
}
errorSpan.innerText = message;
errorSpan.style.display = 'block';
errorSpan.style.opacity = 0;
errorSpan.style.transition = 'opacity 0.3s';
setTimeout(() => { errorSpan.style.opacity = 1; }, 10);
input.classList.add('input-error');
}
function clearError(input) {
let errorSpan = input.parentNode.querySelector('.error-msg');
if (errorSpan) {
errorSpan.style.opacity = 0;
setTimeout(() => { errorSpan.style.display = 'none'; }, 300);
}
input.classList.remove('input-error');
}
function validateForm() {
let valid = true;
const firstName = document.getElementById('smplekitFirstName');
const lastName = document.getElementById('smplekitLastName');
const companyName = document.getElementById('smplekitCompanyName');
const country = document.getElementById('sampleSignupCountry');
const email = document.getElementById('smplekitEmail');
const contactNumber = document.getElementById('smplekitContactNumber');
const phoneCode = document.getElementById('jquery-intl-phone');
const emailValid = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/.test(email.value.trim());
const nameValid = /^[A-Za-z\s]+$/;
[firstName, lastName, companyName, country, email, contactNumber, phoneCode].forEach(clearError);
if (!firstName.value.trim()) {
showError(firstName, '*');
valid = false;
} else if (!nameValid.test(firstName.value.trim())) {
showError(firstName, 'Only letters allowed');
valid = false;
}
if (!lastName.value.trim()) {
showError(lastName, '*');
valid = false;
} else if (!nameValid.test(lastName.value.trim())) {
showError(lastName, 'Only letters allowed');
valid = false;
}
if (!companyName.value.trim()) {
showError(companyName, '*');
valid = false;
}
if (!country.value.trim()) {
showError(country, '*');
valid = false;
}
if (!email.value.trim()) {
showError(email, '*');
valid = false;
} else if (!emailValid) {
showError(email, 'Invalid email');
valid = false;
}
if (!phoneCode.value.trim()) {
showError(phoneCode, '*');
valid = false;
}
if (!contactNumber.value.trim()) {
showError(contactNumber, '*');
valid = false;
}
return valid;
}
['smplekitFirstName','smplekitLastName','smplekitCompanyName','sampleSignupCountry','smplekitEmail','smplekitContactNumber','jquery-intl-phone'].forEach(id => {
const el = document.getElementById(id);
if (el) {
el.addEventListener('input', () => clearError(el));
el.addEventListener('change', () => clearError(el));
}
});
form.addEventListener('submit', function(e) {
e.preventDefault();
if (!validateForm()) {
return;
}
submitBtn.disabled = true;
submitBtn.innerText = 'Submitting...';
const data = {
firstName: document.getElementById('smplekitFirstName').value.trim(),
lastName: document.getElementById('smplekitLastName').value.trim(),
companyName: document.getElementById('smplekitCompanyName').value.trim(),
country: document.getElementById('sampleSignupCountry').value.trim(),
countryCode: document.getElementById('jquery-intl-phone').value.trim(),
contactNumber: document.getElementById('smplekitContactNumber').value.trim(),
notes: document.getElementById('commentProductsamplekit').value.trim(),
email: document.getElementById('smplekitEmail').value.trim()
};
fetch('/sample-kit-registration-form-submit', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(data)
})
.then(resp => resp.json())
.then(resp => {
if (resp.status === 'success') {
form.reset();
$('.input-error').removeClass('input-error');
$('.error-msg').remove();
successPopup.modal('show');
setTimeout(() => { successPopup.modal('hide'); }, 3000);
} else {
let formError = document.getElementById('samplekit-form-error');
if (!formError) {
formError = document.createElement('div');
formError.id = 'samplekit-form-error';
formError.className = 'form-global-error';
form.insertBefore(formError, form.firstChild);
}
formError.innerText = resp.message || 'Submission failed.';
formError.style.display = 'block';
formError.style.opacity = 0;
formError.style.transition = 'opacity 0.3s';
setTimeout(() => { formError.style.opacity = 1; }, 10);
}
})
.catch(() => {
let formError = document.getElementById('samplekit-form-error');
if (!formError) {
formError = document.createElement('div');
formError.id = 'samplekit-form-error';
formError.className = 'form-global-error';
form.insertBefore(formError, form.firstChild);
}
formError.innerText = 'Server error. Please try again.';
formError.style.display = 'block';
formError.style.opacity = 0;
formError.style.transition = 'opacity 0.3s';
setTimeout(() => { formError.style.opacity = 1; }, 10);
})
.finally(() => {
submitBtn.disabled = false;
submitBtn.innerText = 'Sign Up';
});
});
});
</script>