var captchaTicked = false;
function imNotARobot() {
captchaTicked = true
}
$(function () {
$("#saveButton").on("click", function (e) {
e.preventDefault();
if (!validateFields()) {
saveNewTrial();
}
});
function showError(msg) {
document.getElementById("errorMessage").innerHTML = msg;
if (msg != "") {
document.getElementById("errorText").style.display = "block";
document.getElementById("errorMessage").style.display = "block";
} else {
document.getElementById("errorText").style.display = "none";
document.getElementById("errorMessage").style.display = "none";
}
}
function showResponse(icon, title, msg) {
document.getElementById("iconResponse").innerHTML = icon;
document.getElementById("titleResponse").innerHTML = title;
document.getElementById("messageResponse").innerHTML = msg;
}
function validateFields() {
showError("");
$('#firstName').removeClass('highlighted-error-field');
$('#lastName').removeClass('highlighted-error-field');
$('#email').removeClass('highlighted-error-field');
var hasError = false;
var firstName = $('#firstName').val();
var lastName = $('#lastName').val();
var email = $('#email').val();
var pattern = new RegExp(/^([\w-\.]+@([\w-]+\.)+[\w-]{2,})?$/);
if (firstName == '') {
showError("Please enter the First Name.");
$('#firstName').addClass('highlighted-error-field').focus();
hasError = true;
}
if (!hasError && lastName == '') {
$('#lastName').addClass('highlighted-error-field').focus();
showError("Please enter the Last Name.");
hasError = true;
}
if (!hasError && email == '') {
$('#email').addClass('highlighted-error-field').focus();
showError("Please enter the Email address.");
hasError = true;
} else if (!hasError && !pattern.test(email)) {
$('#email').addClass('highlighted-error-field').focus();
showError("Please enter a valid Email address.");
hasError = true;
}
if (!hasError && !document.querySelector("#terms").checked) {
showError("You must accept coreplus's Terms of Use, Privacy Policy and Clickwrap Licence Agreement in order to start your Free Trial.");
hasError = true;
}
if (!hasError && captchaTicked == false) {
showError("Please click I'm not a robot.");
hasError = true;
}
return hasError;
}
function saveNewTrial() {
var iconClass = 'iconNewTrialClass';
var iconDatabase = "");
var iconClick = "");
var iconExclamation = "");
var iconMail = "");
var firstName = $('#firstName').val();
var lastName = $('#lastName').val();
var email = $('#email').val();
var promoCode = $('#promoCode').val();
document.getElementById("newTrialForm").style.display = "none";
document.getElementById("newTrialResponse").style.display = "block";
showResponse(iconClick, 'Processing', 'We are processing your request. Please wait while we prepare your coreplus instance.');
$.ajax({
url: 'newtrialhandler.php',
data: {
'firstName': firstName,
'lastName': lastName,
'email': email,
'promoCode': promoCode
},
success: function (data) {
if (data == '0' || data == '4') {
showResponse(iconExclamation, 'Unexpected Issue', 'We are unable to process your submission at this time. Please double check your submission and try again later. If issue persists, please contact our support team.');
} else if (data == '2') {
document.getElementById("newTrialForm").style.display = "block";
document.getElementById("newTrialResponse").style.display = "none";
showError("It looks like the email address you entered may not be valid. Please provide a valid email address to proceed.");
$('#email').addClass('highlighted-error-field').focus();
} else if (data == '3') {
showResponse(iconMail, 'Account Already Exists', 'You already have a trial account with coreplus. A password reset link has been sent to you.');
} else {
showResponse(iconDatabase, 'Done', 'Redirecting you to coreplus application.');
window.location.href = coreplusUrl.concat("coreplus/?r=") + data;
}
$('#inputContent').hide()
},
error: function (req, status, errorObj) {
alert("Failed to process. Please contact Coreplus support.\n" + errorObj)
showResponse(iconExclamation, 'Unexpected Issue', 'We are unable to process your submission at this time. Please double check your submission and try again later. If issue persists, please contact our support team.');
}
});
}
})