/* Proviss.js
*/
/* Object prototype section
*/
function countProperties(obj) { // Can't do Object.prototype.length
return Object.keys(obj).length;
}
function SpacePad( Num, Len ) { return Num.SpacePad(Len); }
Number.prototype.SpacePad = function( Len ) {
var String=this.toString(),
Padder=' ';
return Padder.substr(1,Len-String.length)+String;
}
function ZeroFill( Num, Len ) { return Num.ZeroFill(Len); }
Number.prototype.ZeroFill = function( Len ) {
var String=this.toString(),
Padder='00000000000000000000';
return Padder.substr(1,Len-String.length)+String;
}
String.prototype.SpacePad = function( Len ) {
var String=this.toString(),
Padder=' ';
return String+Padder.substr(1,Len-String.length);
}
function Trim( Str ) { return Str.trim(); }
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g,"");
}
function LTrim( Str ) { return Str.ltrim(); }
String.prototype.ltrim = function() {
return this.replace(/^\s+/,"");
}
function RTrim( Str ) { return Str.rtrim(); }
String.prototype.rtrim = function() {
return this.replace(/\s+$/,"");
}
function Empty( Str ) { return Str.empty(); }
String.prototype.empty = function() {
return (this.length == 0);
}
Array.prototype.contains = function(e) {
return ($.inArray(e,this) >= 0);
}
function OptionAccess( Access, Option )
{
for( var i = 0 ; i < Access.length ; i++ )
{
if( Access[i] == Option ) return true;
if( Access[i] == "+" || Access[i] == "*" ) return true;
if( Access[i] == "-" || Access[i] == "/" ) return false;
}
return false;
}
function TableMap( Table, Index )
{
var Selector = "#"+Table+" > tbody > tr"
+ (Index > 0 ? ":gt("+(Index-1)+")" : "" );
var arr = $(Selector).map(function()
{
return $(this).children().map(function()
{ return $(this); });
});
return arr;
}
function FieldFocus( Field )
{
$(Field).focus().select();
}
function Transform( Field )
{
var Attr = $(Field).css('text-transform');
if( Attr == "uppercase" ) return $(Field).val().trim().toUpperCase();
if( Attr == "lowercase" ) return $(Field).val().trim().toLowerCase();
return $(Field).val().trim();
}
function isPrint( ch ) // UNIX style
{
return (ch == 13 || ch >=32 && ch <=126 );
}
function Q( String ) // Standard quotes
{
return '"' + String + '"';
}
function QF( String ) // Field quotes: has escaped doubles
{
return '"' + String.replace( '"', '""' ) + '"';
}
function ErrorInit( )
{
var ErrMsg = '
'
+ '
';
$('#HeadNav').append(ErrMsg);
$('#Error').hide();
$('.Field').keypress(function(event) { $('#Error').hide(); } );
}
function ErrorDisplay( ErrMsg )
{
$('#Error').text(ErrMsg).show();
}
function DisplayDateTime( )
{
return; //dave: disable
if( $('#DateTime').length == 0 ) return;
$.post( '/web/php/Date.php', function( Data, Status ) {
if( Data.length == 0 ) return;
/*dave: Extended time w/ day & tz
var f = Data.split( "|" ),
CurrDate = f[3]+' '+f[1]+'/'+f[2]+'/'+f[0],
CurrTime = f[8]+' '+f[4]+':'+f[5]+' '+f[7].toLowerCase(),
Delay = 60 - parseInt(f[6]) + 0;
*/
var f = Data.split( "|" ),
CurrDate = f[1]+'/'+f[2]+'/'+f[0],
CurrTime = f[4]+':'+f[5]+' '+f[7].toLowerCase(),
Delay = 60 - parseInt(f[6]) + 0;
$('#DateTime').css('color','black')
.html(CurrDate+'
'+CurrTime);
setTimeout( DisplayDateTime, Delay*1000 );
//console.log(f);
}).fail( function() {
$('#DateTime').css('color','red');
setTimeout( DisplayDateTime, 60*1000 );
});
/*dave: local time
var Now = new Date(),
YY = Now.getYear()%100,
MM = Now.getMonth()+1,
DD = Now.getDate(),
hh = Now.getHours(),
mm = Now.getMinutes(),
AP = (hh < 12) ? 'am' : 'pm',
hh = (hh-1)%12+1,
Delay = 60 - Now.getSeconds(),
CurrDate = ZeroFill(MM,2)+'/'+ZeroFill(DD,2)+'/'+ZeroFill(YY,2),
CurrTime = ZeroFill(hh,2)+':'+ZeroFill(mm,2)+AP;
$('#DateTime').html(CurrDate+'
'+CurrTime);
setTimeout( DisplayDateTime, (Delay)*1000 );
*/
}
function DateStr() {
var Now = new Date(),
YY = Now.getYear()+1900,
MM = Now.getMonth()+1,
DD = Now.getDate();
return ZeroFill(MM,2)+'/'+ZeroFill(DD,2)+'/'+ZeroFill(YY,4);
}
// List functions for tables with ID and Description
function Lister( Obj, ListSelect, Query )
{
$.post( '/web/php/ApplExec.php', { Query: Query }, function( Data, Status ) {
if( Data.length == 0 ) return;
//console.log("Data=\n"+Data);
var Record = Data.split( "\n" ); Record.pop();
if( Record.length == 0 ) return;
if( Record[0].substr(0,8) == "sqlcode=" )
{ alert("Error=\n"+Data); return; }
if( Record.length == 1 )
{ var Field = Record[0].split( "|" ); Field.pop();
//console.log("Field="+Field[0]);
ListSelect( Trim(Field[0]) ); return;
}
var Left=Obj.offsetLeft, Top=Obj.offsetTop+Obj.offsetHeight;
var Lister = "