function CalculateAge(birthdate) {
var birthday = new Date(birthdate);
var ageDifMs = Date.now() - birthday.getTime();
var ageDate = new Date(ageDifMs);
var age = Math.abs(ageDate.getUTCFullYear() - 1970);
console.log("age: " + age);
return age;
}
function calculateAgeLatest(birthday, dateToCalculate) {
var calculateYear = dateToCalculate.getFullYear();
var calculateMonth = dateToCalculate.getMonth();
var calculateDay = dateToCalculate.getDate();
var dateOfBirth = new Date(birthday);
var birthYear = dateOfBirth.getFullYear();
var birthMonth = dateOfBirth.getMonth();
var birthDay = dateOfBirth.getDate();
var age = calculateYear - birthYear;
var ageMonth = calculateMonth - birthMonth;
var ageDay = calculateDay - birthDay;
if (ageMonth < 0 || (ageMonth == 0 && ageDay < 0)) {
age = parseInt(age) - 1;
}
return age;
}
function CreateValidator(attribute, displayName) {
var newValidator = document.createElement('span');
var labelId = "#" + attribute + "_label";
var label = attribute + "_label";
newValidator.style.display = "none";
newValidator.id = attribute;
newValidator.controltovalidate = attribute;
newValidator.errormessage = "" + displayName + " is a required field.";
newValidator.validationGroup = "";
newValidator.initialvalue = "";
newValidator.evaluationfunction = function () {
var value = $("#" + attribute).val();
if (value == null || value == "") {
return false;
}
else {
return true;
}
};
Page_Validators.push(newValidator);
$("a[href='" + labelId + "']").on("click", function () {
scrollToAndFocus(label, attribute);
});
}
function removeValidator(fieldName) {
$.each(Page_Validators, function (index, validator) {
if (validator.id == fieldName) {
Page_Validators.splice(index, 1);
}
});
$("#" + fieldName + "_label").parent().removeClass("required");
}
var divActions = document.getElementsByClassName('actions');
var dataUsage = '' +
'
' +
'
To find out more about how CITB use your data please ' + '
' +'click here' +
'
' +
'
';
var notDisplayed = '' +
'' +
'
Your record is not currently being displayed on the Construction Training Register.
' +
'Having your record displayed on the Construction Training Register provides several benefits:
' +
'- It allows you to easily demonstrate to an employer or contractor that you hold required qualifications, achievements or training for a particular role
' +
'- It allows the training you have completed to more easily transfer between employers, leading to less time off- the - job repeating training you have already undertaken
' +
'- It can speed up the process of starting a new job, as employers can easily see the training you have completed
' +
'To display your record on the Construction Training Register please click ‘Display My Record” below' +
'
' +
'
';
var $closeAccount = $('Close my profile');
if ($('#citb_closeaccount_0').is(":checked")) //Account is not closed
{
//$closeAccount.appendTo(divActions);
$(".workflow-link.btn-default.btn").css('display', 'none');
$('table[data-name="SUMMARY_TAB_section_6"]').after(dataUsage);
}
else {
$("#UpdateButton").css('display', 'none');
$('table[data-name="SUMMARY_TAB_section_6"]').after(notDisplayed);
}
$(".workflow-link.btn-default.btn").addClass("btn btn-primary").removeClass('workflow-link btn-default');
$('#citb_closeaccount').parent().parent().css('display', 'none');
$('#citb_uniquelearnernumber').prop('disabled', true);
$('#citb_registrationnumber').prop('disabled', true);
$('#citb_nationalinsurancenumber').prop('disabled', true);
$('#citb_individualidentifier').prop('disabled', true);
$('#firstname').prop('disabled', true);
$('#lastname').prop('disabled', true);
$('#citb_dob').parent().find('*').attr('disabled', false);
var birthdate = $('#citb_dob').val();
//alert(calculateAgeLatest(birthdate,new Date()));
if (birthdate && calculateAgeLatest(birthdate, new Date()) < 18) {
$("label[for='citb_parentguardingname']").parent().attr('class', 'info required');
CreateValidator('citb_parentguardingname', 'Parent Guardian Name');
$("label[for='citb_relationshiptocarer']").parent().attr('class', 'info required');
CreateValidator('citb_relationshiptocarer', 'Relationship to Carer');
}
else {
$('#citb_parentguardingname').css('display', 'none');
$("label[for='citb_parentguardingname']").css('display', 'none');
$('#citb_relationshiptocarer').css('display', 'none');
$("label[for='citb_relationshiptocarer']").css('display', 'none');
}
// this is triggered once date of birth is changed
var dpcontrol = $('div.control')[5];
$(dpcontrol).on("dp.change", function (e) {
var birthdate = e.date;
var age = calculateAgeLatest(birthdate, new Date());
if (age < 18) {
$("label[for='citb_parentguardingname']").parent().attr('class', 'info required');
CreateValidator('citb_parentguardingname', 'Parent Guardian Name');
$("label[for='citb_relationshiptocarer']").parent().attr('class', 'info required');
CreateValidator('citb_relationshiptocarer', 'Relationship to Carer');
$('#citb_parentguardingname').css('display', '');
$("label[for='citb_parentguardingname']").css('display', '');
$('#citb_relationshiptocarer').css('display', '');
$("label[for='citb_relationshiptocarer']").css('display', '');
}
else {
removeValidator('citb_relationshiptocarer');
$('#citb_parentguardingname').css('display', 'none');
$("label[for='citb_parentguardingname']").css('display', 'none');
removeValidator('citb_parentguardingname');
$('#citb_relationshiptocarer').css('display', 'none');
$("label[for='citb_relationshiptocarer']").css('display', 'none');
}
});