var isOtpValid = false;
$(document).ready(function() {
var isMobileDevices = (/android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(navigator.userAgent.toLowerCase()));
$("#searchPolicyForm").attr("autocomplete", "off");
$("#searchPolicyForm").attr('novalidate', 'novalidate');
$("#page_name").text("Online Portal");
var validate = function(key) {
$("#" + validators[key].label).next(".red").remove();
var glyphOk = "";
var glyphRemove = "";
var customErrorMessage = "", isFound = false, isInputValid = false;
if (validators[key]["id"]) {
var value = $('#' + validators[key].id).val();
if (validators[key].duplicate) {
var duplicateValidator = validators[key].duplicate;
var elemPos = duplicateValidator.findDuplicate(value);
var currPos = duplicateValidator.pos;
customErrorMessage = duplicateValidator.errorMessage;
if (validators[key].duplicate.edit) {
isFound = (elemPos == -1 || elemPos == currPos) ? false : true;
} else {
isFound = (elemPos == -1) ? false : true;
}
}
if (validators[key].required == false && validators[key].inputpattern) {
isInputValid = (value != "" && value != null) ? (validators[key].inputpattern.test(value) ? true : false) : true;
if (!isInputValid) {
$("#" + validators[key].id).css("border", "1px solid red");
$("#" + validators[key].label).after('
' + validators[key].errorMessage0 + '
');
$("#" + validators[key].label).closest('.elem').find(".glyrenpol").remove();
if (value != null && value != "") {
$("#" + validators[key].label).closest('.glyphdiv').before(glyphRemove);
}
return false;
} else {
$("#" + validators[key].id).css("border", "1px solid #55565A");
$("#" + validators[key].label).next(".red").remove();
$("#" + validators[key].label).closest('.elem').find(".glyrenpol").remove();
if (value != null && value != "") {
$("#" + validators[key].label).closest('.glyphdiv').before(glyphOk);
}
return true;
}
} else if (value.length == 0 || value.trim() == "" ||
(validators[key].pattern0 && !validators[key].pattern0.test(value)) || isFound) {
var errMsg = isFound ? duplicateValidator.errorMessage : validators[key].errorMessage0;
$("#" + validators[key].id).css("border", "1px solid red");
$("#" + validators[key].label).after('' + errMsg + '
');
$("#" + validators[key].label).closest('.elem').find(".glyrenpol").remove();
$("#" + validators[key].label).closest('.glyphdiv').before(glyphRemove);
return false;
} else if ((value != null && validators[key].patternFunc0 != null) && !validators[key].patternFunc0(value)) {
$("#" + validators[key].id).css("border", "1px solid red");
$("#" + validators[key].label).after('' + validators[key].errorMessage1 + '
');
$("#" + validators[key].label).closest('.elem').find(".glyrenpol").remove();
$("#" + validators[key].label).closest('.glyphdiv').before(glyphRemove);
}
else {
$("#" + validators[key].id).css("border", "1px solid #55565A");
$("#" + validators[key].label).next(".red").remove();
$("#" + validators[key].label).closest('.elem').find(".glyrenpol").remove();
$("#" + validators[key].label).closest('.glyphdiv').before(glyphOk);
return true;
}
} else {
var value = $("." + validators[key].class).val();
if (value == null) {
$("#" + validators[key].label).after('' + validators[key].errorMessage0 + '
');
return false;
}
else {
$("#" + validators[key].label).next(".red").remove();
return true;
}
}
};
var fields = {
"civil_id": [
{ "required": "required" },
{ "onpaste": "return true;" },
{ "ondrag": "return false;" },
{ "ondrop": "return false;" },
{ "type": "text" }
],
"mobile_number": [
{ "required": "required" },
{ "onpaste": "return true;" },
{ "ondrag": "return false;" },
{ "ondrop": "return false;" },
{ "type": "tel" }
],
"otp": [
{ "required": "required" },
{ "onpaste": "return true;" },
{ "ondrag": "return false;" },
{ "ondrop": "return false;" },
{ "type": "tel" }
]
};
for (var id in fields) {
for (var i = 0; i < fields[id].length; i++) {
var field = fields[id][i];
for (var attrName in field) {
$("#" + id).attr(attrName, field[attrName]);
}
}
}
var validators = {
"civil_id": {
id: "civil_id",
label: "civil_id-float",
errorMessage0: 'Please provide a valid Civil ID.',
pattern0: /^[0-9!@#$%^&*/]+$/,
},
"mobile_number": {
id: "mobile_number",
label: "mobileNumber-float",
errorMessage0: 'Please provide Mobile Number in numerical values with a minimum of eight digits.',
pattern0: /^\d{8,9}$/,
},
"otp": {
id: "otp",
label: "otp-float",
errorMessage0: 'Please provide the OTP sent to your Mobile Number.',
pattern0: /^[0-9!@#$%^&*/]+$/,
}
};
$("#civil_id").on("keyup blur", function() {
validate('civil_id');
});
$("#mobile_number").on("keyup blur", function() {
validate('mobile_number');
});
$("#otp").on("keyup blur", function() {
validate('otp');
});
var showPopup = function(button, element) {
setTimeout(function() {
var val = button.offset();
if (!isMobileDevices || $('.submenu-left').is(':visible')) {
$(element)
.css({
left: val.left + button.outerWidth() + 15,
top: val.top - $(element).height() / 2 - 5
});
} else {
document.body.style.overflowY = 'hidden';
$(element).css({ top: val.top - $(element).height() / 2 - 5 });
}
// $(element).height(window.innerHeight - 90);
$(element).css('display', 'block');
});
};
if (!isMobileDevices) {
$("#mobile-number").hover(function(obj) {
showPopup(
$(this),
'.mobileNumber'
);
}, function() {
$(".mobileNumber").css('display', 'none');
});
} else {
$("#mobile-number").click(function(obj) {
showPopup(
$(this),
'.mobileNumber'
);
});
}
$("#search_submit").click(function() {
if (isFormValid(policy_search).isFormValid) {
$(".loading-container").show();
$("body").addClass("show-loader");
var mobileNumber = $("#mobile_number").val();
var civilId = $("#civil_id").val();
var otp = $("#otp").val();
if (civilId != null && civilId.trim() != "" && mobileNumber != null && mobileNumber.trim() != "" && otp != null && otp.trim() != "") {
validateOtp();
if (isOtpValid) {
var fullUrl = window.location.href;
document.searchPolicyForm.action = contextPathUrl + "/searchPolicyDetails.do?civilId=" + civilId + "&mobNo=" + mobileNumber + "";
if (fullUrl.includes("Lang=A")) {
document.searchPolicyForm.action = contextPathUrl + "/searchPolicyDetails.do?civilId=" + civilId + "&mobNo=" + mobileNumber + "&Lang=A";
}
document.searchPolicyForm.submit();
} else {
$('#errorModal').find('.modal-body p').html("OTP validation failed, please click on Send OTP to validate again");
$('#errorModal').modal('show');
$('#errorModal').find('.modal-body p').css("text-align", "center");
$(".otpDiv").show();
$("#otp").val('');
$("#enterOtp").hide();
$("#searchSubmit").hide();
$(".loading-container").hide();
$("body").removeClass("show-loader");
return false;
}
} else {
$("#civil_id, #mobile_number, #otp").addClass('error');
return false;
}
}
else {
return false;
}
});
var policy_search = ["civil_id", "mobile_number", "otp"];
var otp_form_validate_fields = ["civil_id", "mobile_number"];
var updateMobNum_field = ["mobile_number"];
var isFormValid = function(elements) {
var validCount = 0;
for (var i = 0; i < elements.length; i++) {
if (validate(elements[i])) {
validCount++;
}
}
return { isFormValid: validCount == elements.length, invalidCount: elements.length - validCount };
};
$("#sendOtp").click(function() {
if (isFormValid(otp_form_validate_fields).isFormValid) {
$('#mobileNumber-float').next(".red").remove();
if ($("#mobile_number").val() == "" || $("#mobile_number").val().length == 0) {
$('#mobileNumber-float').after('Please Enter Mobile Number to send Otp.
');
return false;
}
else {
$(".otpDiv").hide();
sendOtpfunction();
$("#enterOtp").show();
$("#searchSubmit").show();
}
}
});
if (errMessage) {
$('#errorModal').find('.modal-body p').html(errMessage);
$('#errorModal').modal('show');
$('#errorModal').find('.modal-body p').css("text-align", "center");
}
$(".logOutCustPortal").click(function() {
var fullUrl = window.location.href;
var redirectUrl = contextPathUrl + "/customerPortal.do?logout=Y";
if (fullUrl.includes("Lang=A")) {
redirectUrl = redirectUrl + "&Lang=A";
}
window.location.href = redirectUrl;
});
$("#updateMobSubmit").click(function() {
if (isFormValid(updateMobNum_field).isFormValid) {
$("#loaderAnimation").show();
$("#updateMobSubmit").hide();
var policyId = document.getElementById('policyId').value;
var endtId = document.getElementById('endtId').value;
var mobNum = document.getElementById('mobile_number').value;
$.ajax({
type: "POST",
url: contextPathUrl + "/updateMobileNum.do?policyId=" + policyId + "&endtId=" + endtId + "&mobNo=" + mobNum,
dataType: "json",
success: function(data, status, xhr) {
console.log("Success" + data);
$("#updateMobNum").modal('hide');
$('#errorModal').find('.modal-body p').html("Mobile Number updated Successfully!");
$('#errorModal').modal('show');
$('#errorModal').find('.modal-body p').css("text-align", "center");
//window.location.replace(window.location.href + "&updatedMobile=Y");
},
error: function(status, errorThrown) {
console.log("Error");
console.log(JSON.stringify(status));
console.log(JSON.stringify(errorThrown));
}
});
} else {
return false;
}
});
});
$(document).on('show.bs.modal', '#updateMobNum', function(event) {
var policyId = $(event.relatedTarget).data('policyid');
var endtId = $(event.relatedTarget).data('endtid');
$(this).find("#policyId").val(policyId);
$(this).find("#endtId").val(endtId);
});
$(document).on('hidden.bs.modal', '#updateMobNum', function(event) {
$("#updateMobSubmit").show();
$("#loaderAnimation").hide();
$("#mobile_number").val("");
});
function sendOtpfunction() {
var mobileNo = $("#mobile_number").val();
console.log("Mobile Number:", mobileNo);
$(".loading-container").show();
$("body").addClass("show-loader");
$.ajax({
type: "POST",
url: contextPathUrl + "/sendOTP.do?mobileNumber=" + mobileNo,
timeout: 30000,
dataType: "json",
success: function(data, status) {
console.log("In Success");
$(".loading-container").hide();
$("body").removeClass("show-loader");
},
error: function(status, errorThrown) {
console.log("In error");
}
});
}
function validateOtp() {
var otp = $("#otp").val();
console.log("UI OTP:", otp);
$.ajax({
type: "POST",
url: contextPathUrl + "/validateOTP.do?otpCode=" + otp,
async: false,
timeout: 30000,
dataType: "json",
success: function(data, status) {
console.log("In Success");
console.log(data["Validated"].Response);
if (data["Validated"].Response == "true") {
isOtpValid = true;
}
else {
isOtpValid = false;
}
console.log("isOtpValid", isOtpValid);
$(".loading-container").hide();
$("body").removeClass("show-loader");
return isOtpValid;
},
error: function(status, errorThrown) {
console.log("In error");
}
});
}
function downloadOrangeCard(policyId, endtId) {
$(".loading-container").show();
$("body").addClass("show-loader");
$.ajax({
type: "POST",
url: contextPathUrl + "/getOrangeCard.do?policyId=" + policyId + "&endtId=" + endtId,
dataType: "json",
success: function(data, status, xhr) {
console.log("Success" + data);
if (data.Response.eInvoicePdf != 'null') {
var reportPDF = data.Response.eInvoicePdf;
var pdfData = base64ToArrayBuffer(reportPDF);
var file = new Blob([pdfData], {
type: 'application/pdf'
});
var fileURL = window.URL.createObjectURL(file);
const a = document.createElement('a');
a.href = fileURL;
a.download = data.Response.orangeCardNo;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
} else {
$('#errorModal').find('.modal-body p').html("Orange Card is not available for this policy.");
$('#errorModal').modal('show');
$('#errorModal').find('.modal-body p').css("text-align", "center");
}
$(".loading-container").hide();
$("body").removeClass("show-loader");
},
error: function(status, errorThrown) {
console.log("Error");
console.log(JSON.stringify(status));
console.log(JSON.stringify(errorThrown));
$(".loading-container").hide();
$("body").removeClass("show-loader");
}
});
}
function base64ToArrayBuffer(base64) {
var binary_string = window.atob(base64);
var len = binary_string.length;
var bytes = new Uint8Array(len);
for (var i = 0; i < len; i++) {
bytes[i] = binary_string.charCodeAt(i);
}
return bytes.buffer;
}
function printPolicyDocs(policyId, endtId, valStDate) {
$(".loading-container").show();
$("body").addClass("show-loader");
$.ajax({
type: "POST",
url: contextPathUrl + "/printPolicyDocs.do?policyId=" + policyId + "&endtId=" + endtId,
dataType: "json",
success: function(data, status, xhr) {
console.log("Success" + data);
var url = "/QuoteAndBuy/run?__format=pdf&__report=reporttemplates%5CPolicyReportsOmanNew.rptdesign&policyId=" + policyId + "&endorsementId=" + endtId + "&validityStartDate=" + valStDate + "&countryCode=1&BreakDownRecovery=False&PolicySchedule=True&language=E&location=30&draft=false&__parameterpage=false&vatEnabledFlag=" + data.Response.vatEnabledFlag;
if (endtId > 0) {
url = url + "&EndtSchedule=True";
}
var tempUrl = url;
if (data.Response.DebitNoteDt != 'null' && data.Response.DebitNoteNo != 'null') {
url = url + "&DebitNoteReport=True&debitNoteDate=" + data.Response.DebitNoteDt + "&debitNoteNo=" + data.Response.DebitNoteNo;
}
if (data.Response.isReceiptAvailable != 'null') {
url = url + "&Receipt=" + data.Response.isReceiptAvailable;
}
url = tempUrl + "&DebitNoteReport=False&Receipt=False";
window.open(url, "RSADirect", "width=800,height=450");
var save = document.createElement('a');
save.href = url;
save.download = "PolicyDocs";
document.body.appendChild(save);
save.click();
document.body.removeChild(save);
$(".loading-container").hide();
$("body").removeClass("show-loader");
},
error: function(status, errorThrown) {
console.log("Error");
console.log(JSON.stringify(status));
console.log(JSON.stringify(errorThrown));
$(".loading-container").hide();
$("body").removeClass("show-loader");
}
});
}
function fetchROPStatus(concPolicyNo, renewalCount) {
$(".loading-container").show();
$("body").addClass("show-loader");
if (renewalCount === null || renewalCount === '') {
renewalCount = 0;
}
$.ajax({
type: "POST",
url: contextPathUrl + "/fetchRopStatus.do?concPolicyNoWithRenewalCount=" + concPolicyNo + "/" + renewalCount,
dataType: "json",
success: function(data, status, xhr) {
console.log("Success" + data);
if (data.Response.RopStatus === "null" && data.Response.RopStatus != "SUCCESS") {
$('#errorModal').find('.modal-body p').html("Your policy is not uploaded to ROP.");
$('#errorModal').modal('show');
$('#errorModal').find('.modal-body p').css("text-align", "center");
} else {
$('#errorModal').find('.modal-body p').html("Your policy is successfully uploaded to ROP.");
$('#errorModal').modal('show');
$('#errorModal').find('.modal-body p').css("text-align", "center");
}
$(".loading-container").hide();
$("body").removeClass("show-loader");
},
error: function(status, errorThrown) {
console.log("Error");
console.log(JSON.stringify(status));
console.log(JSON.stringify(errorThrown));
$(".loading-container").hide();
$("body").removeClass("show-loader");
}
});
}
function ropReupload(concPolicyNo, renewalCount, policyId, endtId) {
$(".loading-container").show();
$("body").addClass("show-loader");
if (renewalCount === null || renewalCount === '') {
renewalCount = 0;
}
$.ajax({
type: "POST",
url: contextPathUrl + "/ropReupload.do?concPolicyNoWithRenewalCount=" + concPolicyNo + "/" + renewalCount + "&policyId=" + policyId + "&endtId=" + endtId,
dataType: "json",
success: function(data, status, xhr) {
console.log("Success" + data);
if (data.Response.UploadStatus === "null" && (data.Response.UploadStatus != "Y" || data.Response.UploadStatus != "N")) {
$('#errorModal').find('.modal-body p').html("Your Policy has been already uploaded to ROP");
} else if(data.Response.UploadStatus === "Y") {
$('#errorModal').find('.modal-body p').html("Your policy has been initiated for ROP Upload, please check after some time for ROP upload status.");
} else {
$('#errorModal').find('.modal-body p').html("An error occured while uploading to ROP, please try again.");
}
$('#errorModal').modal('show');
$('#errorModal').find('.modal-body p').css("text-align", "center");
$(".loading-container").hide();
$("body").removeClass("show-loader");
},
error: function(status, errorThrown) {
console.log("Error");
console.log(JSON.stringify(status));
console.log(JSON.stringify(errorThrown));
$(".loading-container").hide();
$("body").removeClass("show-loader");
}
});
}
function printRewardCard(policyId, endtId, valStDate) {
$(".loading-container").show();
$("body").addClass("show-loader");
$.ajax({
type: "POST",
url: contextPathUrl + "/printPolicyDocs.do?policyId=" + policyId + "&endtId=" + endtId,
dataType: "json",
success: function(data, status, xhr) {
console.log("Success" + data);
var url = "/QuoteAndBuy/run?__format=pdf&__report=reporttemplates%5CRewardCardOman.rptdesign&policyId=" + policyId;
var tempUrl = url;
url = tempUrl + "&location=30&language=E";
window.open(url, "RSADirect", "width=800,height=450");
var save = document.createElement('a');
save.href = url;
save.download = "RewardCard";
document.body.appendChild(save);
save.click();
document.body.removeChild(save);
$(".loading-container").hide();
$("body").removeClass("show-loader");
},
error: function(status, errorThrown) {
console.log("Error");
console.log(JSON.stringify(status));
console.log(JSON.stringify(errorThrown));
$(".loading-container").hide();
$("body").removeClass("show-loader");
}
});
}