$(document).ready(function () {
$("#retrieveQuoteForm").attr('novalidate', 'novalidate');
$("#retrieveQuoteForm").attr("autocomplete","off");
var isMobileDevices = (/android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(navigator.userAgent.toLowerCase()));
var fields = {
"retQuoteNo" : [
{"required" : "required"},
{"onpaste" : "return true;"},
{"ondrag" : "return false;"},
{"ondrop" : "return false;"},
{"type" : "number"}
],
"retQuoteEmailId" : [
{"required" : "required"},
{"onpaste" : "return true;"},
{"ondrag" : "return false;"},
{"ondrop" : "return false;"},
{"type" : "text"}
],
"retQuoteMobileNo" : [
{"required" : "required"},
{"onpaste" : "return true;"},
{"ondrag" : "return false;"},
{"ondrop" : "return false;"},
{"type" : "tel"}
]
};
setTimeout(function() {
$(".arabicButton").hide();
}, 100);
var validators = {
"retQuoteNo" : {
id: "retQuoteNo",
label: "retQuoteNo-float",
errorMessage0: 'Please provide a valid Quotation Number.',
pattern0: /^\d+$/
},
"retQuoteEmailId" : {
id: "retQuoteEmailId",
label: "retQuoteEmailId-float",
errorMessage0: 'Please provide a valid email address.',
inputpattern: /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/,
required: false
},
"retQuoteMobileNo" : {
id: "retQuoteMobileNo",
label: "retQuoteMobileNo-float",
errorMessage0: 'Please provide a Mobile Number',
pattern0: /^\d{8,9}$/
}
};
setTimeout(function() {
$(".retrieveQuoteButton").hide();
}, 100);
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 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(".gly").remove();
$("#" + validators[key].label).closest('.glyphdiv').before(glyphRemove);
return false;
}
else if(isInputValid && (key == "retQuoteEmailId" || key == "retQuoteMobileNo")) {
$("#" + validators[key].id).css("border", "1px solid #55565A");
$("#" + validators[key].label).next(".red").remove();
$("#" + validators["retQuoteEmailId"].id).css("border", "1px solid #55565A");
$("#" + validators["retQuoteEmailId"].label).next(".red").remove();
$("#" + validators["retQuoteMobileNo"].id).css("border", "1px solid #55565A");
$("#" + validators[key].label).closest('.elem').find(".gly").remove();
$("#" + validators[key].label).closest('.glyphdiv').before(glyphOk);
return true;
}
else {
$("#" + validators[key].id).css("border", "1px solid #55565A");
$("#" + validators[key].label).next(".red").remove();
$("#" + validators[key].label).closest('.elem').find(".gly").remove();
$("#" + 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(".gly").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(".gly").remove();
$("#" + 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(".gly").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 retrieve_quota = ["retQuoteNo", "retQuoteMobileNo"];
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};
};
$("#retQuoteNo").on("blur keyup",function() {
validate('retQuoteNo');
});
/* $("#retQuoteEmailId").blur(function() {
validate('retQuoteEmailId');
});*/
$("#retQuoteMobileNo").on("blur keyup",function() {
validate('retQuoteMobileNo');
});
var errMsg = "Please provide Mobile Number.";
//Kaizen ADM - Release 6.8 - 28.07.2020 - Request ID#14940 - Oman Digital Changes - Starts
$("#quotation_submit").click(function() {
if (isFormValid(retrieve_quota).isFormValid) {
retrieve();
console.log("is Valid");
}
else{
return false;
}
/*if (!$("#retQuoteEmailId").val().trim() && !$("#retQuoteMobileNo").val().trim()) {
console.log("inside empty email and phone");
//$("#" + validators["retQuoteEmailId"].id).css("border", "1px solid red");
// $("#" + validators["retQuoteEmailId"].label).after('' + errMsg + '
');
$("#" + validators["retQuoteMobileNo"].id).css("border", "1px solid red");
return false;
}*/
});
setTimeout(function() {
$(".quoteAndBuyButton").removeClass("trackChanges").addClass("untrackChanges");
$(".renewPolicyButton").removeClass("trackChanges").addClass("untrackChanges");
$(".pageLogo").removeClass("goTohomeSite").addClass("homeSite");
$(".pageHome").removeClass("goTohomeSite").addClass("homeSite");
}, 100);
/*$("body").on("click", ".modal-dialog", function(e) {
if ($(e.target).hasClass('modal-dialog')) {
var hidePopup = $(e.target.parentElement).attr('id');
console.log(hidePopup);
$('#' + hidePopup).modal('hide');
}
});*/
$("body").on("click", function(e) {
if (!$(e.target).hasClass("custom-tooltip")) {
$(".custom-tooltip").css("display", "none");
document.body.style.overflowY = '';
}
});
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'
);
});
}
$(".legal").click(function() {
$("#footerModal").modal("show");
$(".modal-backdrop").addClass("modal-bg-backdrop");
$(".modal-body").height(window.innerHeight/1.8);
});
});
//Kaizen ADM - Release 6.8 - 28.07.2020 - Request ID#14940 - Oman Digital Changes - Starts
function retrieve(){
var retQuoteNum = $("#retQuoteNo").val();
//var retQuoteEmail = $("#retQuoteEmailId").val();
var retQuoteMobileNo = $("#retQuoteMobileNo").val();
/*if(retQuoteEmail!=""){
document.retrieveQuoteForm.action=contextPathUrl+"/retrieveQuoteDetails.do?retQuoteNum="+retQuoteNum+"&retQuoteEmail="+retQuoteEmail+"";
}
else{
}*/
//Kaizen ADM - Release 8.5 - OMAN - RequestId:#91922 - OmanTel EMI Scheme changes - STARTS
var partnerName = $("#partnerId").val();
var isPartnerSite = $("#isPartner").val();
console.log('isPartnerSite',isPartnerSite);
if(isPartnerSite == 'true'){
document.retrieveQuoteForm.action=contextPathUrl+"/"+partnerName+"/retrieveQuoteDetails.do?retQuoteNum="+retQuoteNum+"&retQuoteMobileNo="+retQuoteMobileNo+"";
}
else{
document.retrieveQuoteForm.action=contextPathUrl+"/retrieveQuoteDetails.do?retQuoteNum="+retQuoteNum+"&retQuoteMobileNo="+retQuoteMobileNo+"";
}
//Kaizen ADM - Release 8.5 - OMAN - RequestId:#91922 - OmanTel EMI Scheme changes - ENDS
document.retrieveQuoteForm.submit();
$(".loading-container").show();
$("body").addClass("show-loader");
return true;
}
//Kaizen ADM - Release 6.8 - 28.07.2020 - Request ID#14940 - Oman Digital Changes - Ends