
function setpt_cApplication_Lib_Util()
{
cApplication.prototype.GetCurrentConfigTxtArr = cApplication_GetCurrentConfigTxtArr;
cApplication.prototype.ProcessConfigStrArray = cApplication_ProcessConfigStrArray;
cApplication.prototype.GetCurrentTimezoneName = cApplication_GetCurrentTimezoneName;
cApplication.prototype.RTrim = cApplication_RTrim;
cApplication.prototype.ReplicateStr = cApplication_ReplicateStr;
cApplication.prototype.null2EmptyStr = cApplication_null2EmptyStr;
cApplication.prototype.null2NULLStr = cApplication_null2NULLStr;
cApplication.prototype.ODBCtimestamp = cApplication_ODBCtimestamp;
cApplication.prototype.Date2ODBCts = cApplication_Date2ODBCts;
cApplication.prototype.String2FileName = cApplication_String2FileName;
cApplication.prototype.GetInitials = cApplication_GetInitials;
cApplication.prototype.RemoveDelimTxts = cApplication_RemoveDelimTxts;
cApplication.prototype.ValidateText = cApplication_ValidateText;
cApplication.prototype.ValidateDateTime = cApplication_ValidateDateTime;
cApplication.prototype.ValidateNum = cApplication_ValidateNum;
}
function cApplication_GetCurrentConfigTxtArr(
pcfonly
)
{
var ca, v;
if (pcfonly == null)
pcfonly = false;
ca = new Array();
ca[0] = this.aPCF[0] +" v"+ this.aPCF[1];
ca[1] = "SN: "+ this.aPCF[2];
ca[2] = (this.RTrim(this.aPCF[3].toLowerCase()) == "unregistered"
? "This is an UNREGISTERED product, use for evaluation purposes only."
: "This product is licensed to "+ this.aPCF[3] +".");
ca[3] = (this.ParseDT(this.aPCF[4]) == null
? null
: "This is a time-limited product, expires on "+ this.aPCF[4] +".");
if (pcfonly)
return(ca);
ca[4] = this.sDBRegName + " [key: "+ this.sDBRegKey +"]" ;
v = this.oSystemConfig.Institute.Value;
if (v != null)
v = this.RTrim(v);
ca[5] = ((v != null) && v.length ? v : "-");
v = this.oSystemConfig.Owner.Value;
ca[6] = (v != null ? this.Id2DBField("Users", v, "Name") +" [ID: user"+ v +"]" : "-");
v = this.oSystemConfig.SystemGId.Value;
if (v != null)
v = this.RTrim(v);
ca[7] = ((v != null) && v.length ? v : "-");
v = this.oSession.nUserId;
ca[8] = this.Id2DBField("Users", v, "Name") +" [ID: user"+ v +"]";
return(ca);
}
function cApplication_ProcessConfigStrArray(
StrArray
)
{
var i, l, s, p;
l = StrArray.length;
for (i = 0; i < l; i++)
{
s = StrArray[i];
p = s.indexOf("=");
if (p > 0)
StrArray[ s.slice(0, p) ] = s.slice(p+1);
}
return( StrArray );
}
function cApplication_GetCurrentTimezoneName()
{
var m, n, s, h;
m = -(new Date(2004, 01, 01, 12)).getTimezoneOffset();
n = -(new Date(2004, 07, 01, 12)).getTimezoneOffset();
if (n < m)
m = n;
s = "GMT";
if (m != 0)
{
s += (m < 0 ? "-" : "+");
m = Math.abs(m);
h = Math.floor(m/60);
m %= 60;
s += (h < 10 ? "0" : "") + h + ":" + (m < 10 ? "0" : "") + m;
}
return( s );
}
function cApplication_RTrim(
str
)
{
var i;
if (str.length) {
i = str.length-1;
while (str.charAt(i) == " ") i--;
if (i < 0)
str = "";
else
str = str.slice(0, i+1);
}
return(str);
}
function cApplication_ReplicateStr(
sStr,
nTimes
)
{
var i, a;
a = new Array(nTimes);
for (i = 0; i < nTimes; i++)
a[i] = sStr;
return( a.join("") );
}
function cApplication_null2EmptyStr(v)
{
if (v == null)
return("");
else
return(v);
}
function cApplication_null2NULLStr(v)
{
if (v == null)
return("NULL");
else
return(v);
}
function cApplication_ODBCtimestamp(
y,
m,
d,
h,
min,
s,
ms
)
{
if (ms == null)
ms = 0;
m = m+"";
if (m.length < 2) m = "0"+m;
d = d+"";
if (d.length < 2) d = "0"+d;
h = h+"";
if (h.length < 2) h = "0"+h;
min = min+"";
if (min.length < 2) min = "0"+min;
s = s+"";
if (s.length < 2) s = "0"+s;
return("{ ts '"+y+"-"+m+"-"+d+" "+h+":"+min+":"+s+"."+ms+"'}");
}
function cApplication_Date2ODBCts(
date
)
{
if (date == null)
return("NULL");
return( this.ODBCtimestamp(date.getFullYear(),
date.getMonth()+1,
date.getDate(),
date.getHours(),
date.getMinutes(),
date.getSeconds(),
date.getMilliseconds()) );
}
function cApplication_String2FileName(
str
)
{
var re;
re = new RegExp("[\"/\\\\\\*\\?<>\\|:]", "g");
return( str.replace(re, "_") );
}
function cApplication_GetInitials(
txt,
maxlength
)
{
var ar, l, i, j, retval;
ar = txt.split(" ");
l = ar.length;
retval = "";
j = 0;
for (i = 0; (i < l) && ((maxlength == null) || (j < maxlength)); i++)
if (ar[i].length) {
retval += ar[i].charAt(0);
j++;
}
return( retval );
}
function cApplication_RemoveDelimTxts(
str,
odelim,
cdelim
)
{
var opos, cpos;
opos = str.indexOf(odelim);
cpos = str.indexOf(cdelim, opos+odelim.length);
while ((opos >= 0) && (cpos >= 0)) {
str = str.slice(0, opos) + str.slice(cpos+cdelim.length);
opos = str.indexOf(odelim, opos);
cpos = str.indexOf(cdelim, opos+odelim.length);
}
return(str);
}
function cApplication_ValidateText(
val,
maynull,
minlength,
maxlength,
valname
)
{
if (val == null)
if (maynull)
return(null);
else
return(valname +" is required.");
if (typeof(val) != "string")
return(valname+" is invalid.");
if ((minlength != null) && (val.length < minlength))
return(valname +" must contain at least "+ minlength +" characters.");
if ((maxlength != null) && (val.length > maxlength))
return(valname +" must not contain more than "+ maxlength +" characters.");
return(null);
}
function cApplication_ValidateDateTime(
val,
maynull,
valname
)
{
if (val == null)
if (maynull)
return(null);
else
return(valname+" is required!");
if (val.getFullYear == "undefined")
val = null;
else
val = val.getFullYear();
if ((val == null) || (val < 1753) || (val > 9999))
return(valname+" is invalid.");
return(null);
}
function cApplication_ValidateNum(
val,
maynull,
lobound,
hibound,
valname,
isint
)
{
if (val == null)
if (maynull)
return(null);
else
return(valname +" is required.");
if ((typeof(val) != "number") || isNaN(val))
return(valname+" is invalid.");
if (isint && (val != parseInt(val)))
return(valname+" must be an integer.");
if ((lobound != null) && (val < lobound))
return(valname+" must not be less than "+ lobound +".");
if ((hibound != null) && (val > hibound))
return(valname+" must not be greater than "+ hibound +".");
return(null);
}
setpt_cApplication_Lib_Util();
