/**
*
*/
$(document).ready(function($,W,D) {
var a, b, c,
submitContent,
captcha,
locked,
validSubmit = false,
timeoutHandle;
// Generating a simple sum (a + b) to make with a result (c)
function generateCaptcha(){
a = Math.ceil(Math.random() * 10);
b = Math.ceil(Math.random() * 10);
c = a + b;
submitContent = '' + a + ' + ' + b + '' +
' = ';
$('.submit__generated').html(submitContent);
init();
}
// Check the value 'c' and the input value.
function checkCaptcha(){
if(captcha === c){
// Pop the green valid icon
$('.submit__generated')
.removeClass('unvalid')
.addClass('valid');
$('.submit').removeClass('overlay');
$('.submit__overlay').fadeOut('fast');
$('#submitBtn').removeAttr('disabled');
$('.submit__error').addClass('hide');
$('.submit__error--empty').addClass('hide');
validSubmit = true;
}
else {
if(captcha === ''){
$('.submit__error').addClass('hide');
$('.submit__error--empty').removeClass('hide');
}
else {
$('.submit__error').removeClass('hide');
$('.submit__error--empty').addClass('hide');
}
// Pop the red unvalid icon
$('.submit__generated')
.removeClass('valid')
.addClass('unvalid');
$('.submit').addClass('overlay');
$('.submit__overlay').fadeIn('fast');
$('#submitBtn').attr('disabled', true);
validSubmit = false;
}
return validSubmit;
}
function unlock(){ locked = false; }
// Refresh button click - Reset the captcha
$('.submit__control i.fa-refresh').on('click', function(){
if (!locked) {
locked = true;
setTimeout(unlock, 500);
generateCaptcha();
setTimeout(checkCaptcha, 0);
}
});
// init the action handlers - mostly useful when 'c' is refreshed
function init(){
$('form').on('submit', function(e){
e.preventDefault();
if($('.submit__generated').hasClass('valid')){
// var formValues = [];
captcha = $('.submit__input').val();
if(captcha !== ''){
captcha = Number(captcha);
}
checkCaptcha();
if(validSubmit === true){
validSubmit = false;
// Temporary direct 'success' simulation
//submitted();
}
}
else {
return false;
}
});
// Captcha input result handler
$('.submit__input').on('propertychange change keyup input paste', function(){
// Prevent the execution on the first number of the string if it's a 'multiple number string'
// (i.e: execution on the '1' of '12')
window.clearTimeout(timeoutHandle);
timeoutHandle = window.setTimeout(function(){
captcha = $('.submit__input').val();
if(captcha !== ''){
captcha = Number(captcha);
}
checkCaptcha();
},150);
});
// Add the ':active' state CSS when 'enter' is pressed
$('body')
.on('keydown', function(e) {
if (e.which === 13) {
if($('.submit-form').hasClass('overlay')){
checkCaptcha();
} else {
$('.submit-form').addClass('enter-press');
}
}
})
.on('keyup', function(e){
if (e.which === 13) {
$('.submit-form').removeClass('enter-press');
}
});
// Refresh button click - Reset the captcha
$('.submit-control i.fa-refresh').on('click', function(){
if (!locked) {
locked = true;
setTimeout(unlock, 500);
generateCaptcha();
setTimeout(checkCaptcha, 0);
}
});
// Submit white overlay click
$('.submit-form-overlay').on('click', function(){
checkCaptcha();
});
}
generateCaptcha();
$("#addUserForm").validate(
{
rules: {
// simple rule, converted to {required:true}
noKP: "required",
},
messages:
{
noKP:
{
required : "Please enter your UTMID username"
}
},
submitHandler: function(form)
{
$(form).ajaxSubmit({
type: 'POST',
dataType: 'json',
url: '../emailTemplateUser.json',
data: $(form).serialize(),
data : {JSONdata : ""},
success: function(response,jqXHR,textStatus){
var censoredAltEmail = response.result;
censoredAltEmail = censoredAltEmail.split("___")[0];
censoredAltEmail = censoredAltEmail.replace(/OK---/gim, "");
var isUserExist = response.result;
isUserExist = isUserExist.split("___")[1];
//isUserExist = isUserExist.replace(/OK---/gim, "");
if (isUserExist == "userExist")
{
if (confirm("Change Password Link has been sent to (" + censoredAltEmail + ").\nCheck your Inbox or Spam Folder.\nClick on the Link and you'll be redirected to a Reset Password page.\nCONTACT US \nMobile Apps : DigitalCare@UTMSmart | Email : digitalcare@utm.my | Phone No : 07-5532136 (JB) / 03-26154440 (KL)"))
{
location.reload();
}
else{
location.reload();
}
}
else
{
if (confirm("User NOT Found. Please re-enter your UTMID username or CONTACT US Mobile Apps : DigitalCare@UTMSmart | Email : digitalcare@utm.my | Phone No : 07-5532136 (JB) / 03-26154440 (KL)."))
{
location.reload();
}
else{
location.reload();
}
}
//if (confirm("Change Password Link has been sent to (" + censoredAltEmail + ").\nCheck your Inbox or Spam Folder.\nClick on the Link and you'll be redirected to a Reset Password page.\nCONTACT US Mobile Apps : DigitalCare@UTMSmart | Email : digitalcare@utm.my | Phone No : 07-5532136 (JB) / 03-26154440 (KL)"))
// {location.reload();}
//else{location.reload();}
},
error: function(response,jqXHR,textStatus,errorThrown) {
if (confirm("Reset Password Fail: No E-Mail found. \nCONTACT US Mobile Apps : DigitalCare@UTMSmart | Email : digitalcare@utm.my | Phone No : 07-5532136 (JB) / 03-26154440 (KL)"))
{
location.reload();
}
else
{
location.reload();
}
},
});
//return false;
}
});
} );
//@ sourceURL=resetPassword.jsz