function validator(doSend, doPageItemID) {
hasFiles = 0;
var pageID = "page" + currentPage;
if (!$("#blanket").hasClass("custom")) {
$("#blanket").hide();
}
$("#mainAlert").hide();
$("#mainAlert").html("");
$("[id^='elemID']").removeClass("badField");
var alerts = "";
var cont = true;
var mandatoryResult = true;
var sendData = "";
var mandatoryFieldList = "";
$("[id^='elemIDerr']").html("");
if ($("#" + pageID).find("[mandatory=1]").length > 0) {
alerts = transFieldsWithRedAsteriskAreRequired;
$("#" + pageID).find("[mandatory=1]").each(function () {
mandatoryResult = AlertMandatoryField(this.id, $(this));
cont = cont && mandatoryResult;
if (!mandatoryResult) {
mandatoryFieldList = mandatoryFieldList + this.id + ", ";
}
});
}
//check validations
firstTime = "";
$("#" + pageID).find("[id^='txt']").each(function () {
if ($("#" + this.id).val() != "") {
if ($("#" + this.id).attr("validtype") != "0") {
if ($("#elemID" + this.id.replace("txt", "")).css("display") != "none") {
if ($("#" + this.id).attr("validtype") != undefined) {
if (!valid("#" + this.id, Math.abs($("#" + this.id).attr("validtype")), $("#" + this.id).attr("validationdata"))) {
mandatoryFieldList = mandatoryFieldList + this.id + ", ";
if (firstTime == "") {
alerts += "נא למלא שדות מסומנים";
}
cont = false;
$("#elemID" + this.id.replace("txt", "")).addClass("badField");
validName("#" + this.id, Math.abs($("#" + this.id).attr("validtype")), $("#" + this.id).attr("validationdata"));
}
}
else if ($("#" + this.id).attr("isautocomplete") != undefined && $("#" + this.id).attr("isautocomplete") == "1") {
var ctrlId = $(this).attr('id');
var autoCompletectrl = eval("autoComplete" + ctrlId.replace("txt", ""));
if (!autoCompletectrl.isSelected()) {
mandatoryFieldList = mandatoryFieldList + ctrlId + ", ";
var id = eval("elemID" + ctrlId.replace("txt", ""));
$(id).addClass("badField");
$("#elemIDerr" + ctrlId.replace("txt", "")).html("Please choose from the above values");
cont = false;
}
}
}
}
}
});
if (!cont) {
var $genFileds = $('#genFileds');
var $targetElement = $('.badField').first();
var targetOffset = 0;
if ($targetElement.offset().top && $genFileds.offset().top && $genFileds.scrollTop()) {
targetOffset = $targetElement.offset().top - $genFileds.offset().top + $genFileds.scrollTop();
}
else {
console.warn("Probably one of the mandatory fields is hidden !!!");
}
console.log("mandatoryFieldList:" + mandatoryFieldList);
$genFileds.animate({ scrollTop: targetOffset }, 'slow');
if (isFromBOT == "1") {
try {
window.parent.setFormFrameHeight("0", $(".upperView")[0].scrollHeight);
window.parent.scrollToTop("0", targetOffset);
} catch (e) { }
}
showBlanket("0");
return false;
}
sendData = "";
$(".mainDiv").find("[use=1]").each(function () {
var curID = this.id;
id = this.id.replace("timeStamp", "");
if (this.id.indexOf('timeStamp') != -1) {
sendData += "&timeStamp" + id + "=" + escape($(this).val());
}
id = this.id.replace("sig", "");
if (this.id.indexOf('sig') != -1) {
sendData += "&sig" + makeNumber(id) + "=" + eval(this.id).getImage();
}
id = this.id.replace("capa", "");
if (this.id.indexOf('capa') != -1) {
sendData += "&capa" + id + "=" + escape($(this).val());
}
id = this.id.replace("txt", "");
if (this.id.indexOf('txt') != -1) {
if ($(this).attr("isAutoComplete") == "1") {
if ($(this).attr("data-acvalue") != undefined) {
sendData += "&txt" + id + "=" + escape($(this).attr("data-acvalue"));
}
else {
sendData += "&txt" + id + "=" + escape($(this).val());
}
} else {
sendData += "&txt" + id + "=" + escape($(this).val());
}
}
id = this.id.replace("radio", "");
if (this.id.indexOf('radio') != -1) {
foundRadio = false;
if ($(this).is(':checked')) {
foundRadio = true;
data = "&radio" + id + "=" + escape($(this).val());
if (sendData.indexOf("&radio" + id + "=") > -1) {
sendData = sendData.replace("&radio" + id + "=", '');
}
}
if (!foundRadio) { data = "&radio" + id + "="; }
if (sendData.indexOf(data) == -1) sendData += data;
}
id = this.id.replace("chk", "");
if (this.id.indexOf('chk') != -1) {
if (sendData.indexOf("&chk" + id + "=") == -1) {
data = "";
if ($('input[name="' + this.id + '"]:checked').length > 0) {
sendData += "&chk" + id + "=";
$('input[name="' + this.id + '"]:checked').each(function () { sendData += escape($(this).val()) + "|"; });
} else { sendData += "&chk" + id + "="; };
}
// Trim last "|" from sendData
if (sendData.slice(-1) == "|") {
sendData = sendData.slice(0, -1)
}
}
id = id.replace("sel", "");
if (this.id.indexOf("sel") != -1) {
if (!isEmpty($(this).val())) {
sendData += "&sel" + id + "=" + escape($(this).val());
} else {
sendData += "&sel" + id + "=";
}
}
id = id.replace("DateComboBoxY", "");
id = id.replace("DateComboBoxM", "");
id = id.replace("DateComboBoxD", "");
if (this.id.indexOf("DateComboBoxY") != -1) {
if (!isEmpty($(this).val())) {
sendData += "&DateComboBox" + id + "=" + escape($("#DateComboBoxD" + id).val()) + "/" + escape($("#DateComboBoxM" + id).val()) + "/" + escape($("#DateComboBoxY" + id).val());
} else {
sendData += "&DateComboBox" + id + "=";
}
}
id = id.replace("TimeComboBoxH", "");
id = id.replace("TimeComboBoxM", "");
if (this.id.indexOf("TimeComboBoxH") != -1) {
if (!isEmpty($(this).val())) {
sendData += "&TimeComboBox" + id + "=" + escape($("#TimeComboBoxH" + id).val()) + ":" + escape($("#TimeComboBoxM" + id).val());
} else {
sendData += "&TimeComboBox" + id + "=";
}
}
id = id.replace("date", "");
if (this.id.indexOf("date") != -1) {
sendData += "&date" + id + "=" + escape($(this).val());
}
id = id.replace("longstamp", "");
if (this.id.indexOf("longstamp") != -1) {
sendData += "&longstamp" + id + "=" + escape($(this).val());
}
if ($(this).attr("block") == "1") {
id = id.replace("elemID", "");
var data = "";
$(this).find("input:checked").each(function () {
data += this.value + "##$$##";
});
sendData += "&radioBlock" + id + "=" + escape(data);
}
if ($(this).attr("block") == "2") {
id = id.replace("elemID", "");
var data = "";
$("#" + this.id + " select").each(function () {
data += this.value + "##$$##";
});
sendData += "&checkBlock" + id + "=" + escape(data);
}
});
if (doPageItemID != "") {
doNextPage(doPageItemID);
showBlanket("0");
return false;
}
// Trim last "|" from sendData
if (sendData.slice(0, 1) == "&") {
sendData = sendData.slice(1)
}
if (doSend == '1') {
if (showAlertForInvalidFileExtention()) {
return false;
}
if ("0" == "1" && pdfShownForPreview == "0" && (hasGeneratorRules == false || isLastStep == true)) {
getPDFforPreview(sendData);
return false;
}
$("[id^='fileToUpload']").each(function () {
if (!isEmpty($(this).val())) { hasFiles = 1 }
});
if (isFromBOT != "1") {
showBlanket('1', "שולח טופס...
");
}
if (hasOTP != "") { showOTP(sendData, false); } else {
FGFormSubmit(sendData, false);
}
}
else {
if (isFromBOT == "1") {
showBlanket('1', "
");
if (hasOTP != "") { showOTP(sendData, true); } else {
FGFormSubmit(sendData, true);
}
}
}
}