//--- Utility Script
//--- (C) Digital Scorpions, India
//--- http://www.digitalscorpions.in
//--- support@digitalscorpions.in
function isJson(str) {
try {
JSON.parse(str);
} catch (e) {
return false;
}
return true;
}
function FormFormatValidation(obj){
if(obj.attr("placeholder").indexOf("*") <= 0 && obj.val().trim()==""){return true;}
if(obj.attr("placeholder").indexOf("*") >= 0 && Trim(obj.val().trim())==""){
showError(obj.attr("placeholder").replace("*", "") + " not mentioned. Please check.");
obj.focus();
return false;
}
switch(obj.attr("ds-data-type")){
case "text":
if(!isNaN(obj.val())){
showError(obj.attr("placeholder").replace("*", "") + " must be Alphanumeric. Please check.");
obj.focus();
return false;
}
break;
case "number":
if(isNaN(obj.val())){
showError(obj.attr("placeholder").replace("*", "") + " must be Numeric. Please check.");
obj.focus();
return false;
}
break;
case "email":
if(!isEmail(obj.val())){
showError(obj.attr("placeholder").replace("*", "") + " is invalid. Please check.");
obj.focus();
return false;
}
break;
case "mobile":
if(obj.val() < 1000000000){
showError(obj.attr("placeholder").replace("*", "") + " is invalid. Please check.");
obj.focus();
return false;
}
break;
}
return true;
}
function openTab(label, mAction, id){
if(id==undefined)
id = "tabs-" + tabCounter;
if(id=='new-window'){
window.open(mAction, '_blank');
return
}
li = $( tabTemplate.replace( /#\{href\}/g, mAction)
.replace( /#\{label\}/g, label )
.replace( /#\{id\}/g, id ) );
if(tabs.find('a#' + id).size() <= 0){
tabs.find( ".ui-tabs-nav" ).append( li );
tabs.tabs( "refresh" );
tabCounter++;
tabs.tabs("option", "active", tabs.find("ul:first li").size() - 1);
} else
tabs.find("ul:first li").each(function(index, element) {
if($(this).find("a#" + id).size() > 0)
tabs.tabs("option", "active", index);
});
}
function InitTab(){
$("#LabLogo").hide().html("");
//--- Close all open tabs
tabs.find("li").each(function (){
panelId = $(this).remove().attr( "aria-controls" );
$("#" + panelId).remove();
});
tabs.tabs("refresh");
}
function showError(mErr){
$("#divError").text(mErr).show(1000);
setTimeout(function() {
$("#divError").hide(200);
}, 10000);
}
function hideError(ExtraDiv){
if(ExtraDiv)
ExtraDiv.html('');
$("#divError").text('').hide();
}
function showLoading(obj, msg) {
if(!msg) {msg = 'Loading...';}
obj.html(" " + msg).show();
}
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g, "");
};
String.prototype.replaceAll = function(stringToFind,stringToReplace){
var temp = this;
mHoldString = stringToReplace;
stringToReplace = "<£Ü>";
var index = temp.indexOf(stringToFind);
while(index != -1){
temp = temp.replace(stringToFind,stringToReplace);
index = temp.indexOf(stringToFind);
}
stringToFind = "<£Ü>";
stringToReplace = mHoldString;
var index = temp.indexOf(stringToFind);
while(index != -1){
temp = temp.replace(stringToFind,stringToReplace);
index = temp.indexOf(stringToFind);
}
return temp;
}
function URLEncode (clearString) {
var output = '';
var x = 0;
clearString = clearString.toString();
var regex = /(^[a-zA-Z0-9_.]*)/;
while (x < clearString.length) {
var match = regex.exec(clearString.substr(x));
if (match != null && match.length > 1 && match[1] != '') {
output += match[1];
x += match[1].length;
} else {
if (clearString[x] == ' ')
output += '+';
else {
var charCode = clearString.charCodeAt(x);
var hexVal = charCode.toString(16);
output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
}
x++;
}
}
return output;
}
function isDate(dateString) {
var regEx = /^\d{4}-\d{2}-\d{2}$/;
return dateString.match(regEx) != null;
}
function ChangeDateFormat(Dt, Fmt, RetFmt) {
switch(Fmt) {
case "dmy":
y=6; m=3; d=0; b1=2; b2=5;
break;
case "mdy":
y=6; m=0; d=3; b1=2; b2=5;
break;
case "myd":
y=3; m=0; d=8; b1=2; b2=7;
break;
case "dym":
y=3; m=8; d=0; b1=2; b2=7;
break;
case "ydm":
y=0; m=8; d=5; b1=4; b2=7;
break;
default:
//"ymd":
y=0; m=5; d=8; b1=4; b2=7;
break;
}
mRet = "";
switch(RetFmt) {
case "ymd":
mRet = Dt.substr(y,4) + '/' + Dt.substr(m,2) + '/' + Dt.substr(d,2);
break;
case "mdy":
mRet = Dt.substr(m,2) + '/' + Dt.substr(d,2) + '/' + Dt.substr(y,4);
break;
case "myd":
mRet = Dt.substr(m,2) + '/' + Dt.substr(y,4) + '/' + Dt.substr(d,2);
break;
case "dym":
mRet = Dt.substr(d,2) + '/' + Dt.substr(y,4) + '/' + Dt.substr(m,2);
break;
case "ydm":
mRet = Dt.substr(y,4) + '/' + Dt.substr(d,2) + '/' + Dt.substr(m,2);
break;
default:
//"dmy":
mRet = Dt.substr(d,2) + '/' + Dt.substr(m,2) + '/' + Dt.substr(y,4);
break;
}
return mRet;
}
//----------
function isTime(Tm, Fmt){
if(!Fmt){Fmt="hms";}
h=0; m=3; s=6; b1=2; b2=5; b3=8; ap=9;
if(isNaN(Tm.substr(h,2)-0)||(Tm.substr(h,2)-0<0) || (Tm.substr(h,2)-0>12))
return false;
if(Tm.substr(b1,1)!=":")
return false;
if(isNaN(Tm.substr(m,2)-0)||(Tm.substr(m,2)-0<0) || (Tm.substr(m,2)-0>59))
return false;
if(Tm.substr(b2,1)!=":")
return false;
if(isNaN(Tm.substr(s,2)-0)||(Tm.substr(s,2)-0<0) || (Tm.substr(s,2)-0>59))
return false;
if(Tm.substr(b3,1)!=" ")
return false;
if(Tm.substr(ap,2).toUpperCase()!="AM" && Tm.substr(ap,2).toUpperCase()!="PM")
return false;
return true;
}
//..............
function TimeStamp(mDt){
y=mDt.substr(6,4);
m=mDt.substr(3,2);
d=mDt.substr(0,2);
return y + m + d;
}
//..............
function isEmail(Ml){
if(!Ml){return true}
if(Ml.indexOf("@")<=0 || Ml.indexOf("@")==Ml.length-1 || Ml.indexOf(".")<=0 || Ml.indexOf(".")==Ml.length-1 || Ml.indexOf("..")!=-1 || Ml.indexOf("@@")!=-1 || Ml.indexOf("{")!=-1 || Ml.indexOf("}")!=-1 || Ml.indexOf("(")!=-1 || Ml.indexOf(")")!=-1 || Ml.indexOf("[")!=-1 || Ml.indexOf("]")!=-1 || Ml.indexOf("@.")!=-1 || Ml.indexOf(".@")!=-1)
return false;
else
return true;
}
//..............
function isInt(theNum)
{
if(Trim(theNum) == "")
return true;
else if(theNum.indexOf(".") != -1)
return false;
else if(!isNaN(theNum))
return true;
}
function isDecimal(str)
{
mystring = str;
if (mystring.match(/^\d+\.\d/ ))
return true;
else if(isInt(mystring))
return true;
else
return false;
}
function Trim(s){return LTrim(RTrim(' '+s));}
//..............
function LTrim (s){
if(!s){return '';}
while(s.charAt(0)==' ')
s = s.substring(1,s.length);
return s;
}
//..............
function RTrim (s){
if(!s || s==' '){return '';}
if (s.length > 1){
while(s.charAt(s.length-1)==' ')
s = s.substring(0,s.length-2);
return s;
}
}
function setNumRange(t) {
if(!t.value)
return
if(t.value - 0 < t.min - 0){
showError('Invalid out of range value.');
t.value = t.min;
}
if(t.value - 0 > t.max - 0){
showError('Invalid out of range value.');
t.value = t.max;
}
}
function addRow(mTable) {
var m = $(mTable).find("tr:last").clone();
m.find("input[type=text], [type=date], [type=number]").val('');
$(mTable).append(m);
}
//..............
function delRow(mTable, t) {
if($(mTable).find("tr").size() > 3)
t.parent().parent().remove();
else if($(mTable).find("tr").size() > 2)
t.closest('tr').find('input[type!=button]').val('');
}
var isSupported = function (t) {
var input = document.createElement('input');
var v = 'a';
input.setAttribute('type', t);
input.setAttribute('value', v);
return (input.value !== v);
};
$(function (){
if(!isSupported('date')){
$(document).on('focus', '[type=date]', (e) => {
$(e.target).datepicker( "destroy" ).datepicker({
constrainInput: true,
dateFormat: 'yy-mm-dd',
changeMonth: true,
changeYear: true,
minDate: $(e.target).attr('min'),
maxDate: $(e.target).attr('max')
}).datepicker("show");
});
}
if(!isSupported('month')){
$(document).on('focus', '[type=month]', (e) => {
var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
var yyyy = today.getFullYear();
if(!$(e.target).val())
$(e.target).val(yyyy + '-' + mm);
if(!$(e.target).attr('min'))
$(e.target).val($(e.target).sttr('min').substring(0,7));
$(e.target).datepicker( "destroy" ).datepicker({
defaultDate : new Date($(e.target).val() + "-15"),
constrainInput: true,
dateFormat: "yy-mm",
changeMonth: true,
changeYear: true,
showButtonPanel: true,
onClose: function() {
var iMonth = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var iYear = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('setDate', new Date(iYear, iMonth, 1));
}
}).datepicker("show");
$("#ui-datepicker-div table.ui-datepicker-calendar").css('display', 'none');
});
}
});
//JSON To Table
function JSONToTable(r, cls = ""){
let res = $.parseJSON(r);
let thead = "";
let tbody = "