function el(id)
{
var elem = document.getElementById(id);
return (elem);
}
function ExtraTermsInfo()
{
var ld_Window = open('termsandconditions.asp', 'moreinfo', 'width=800,height=500,alwaysRaised=yes,menubar=no,toolbar=no,resizable=yes,scrollbars=yes');
ld_Window.focus();
}
function Adjust_Entry(objNm)
{
var sTmpStr = "";
var sRemnChr = "";
var sFrstChr = "";
sTmpStr = objNm.value;
if (sTmpStr.length > 0)
{
sFrstChr = sTmpStr.substring(0, 1);
if (sTmpStr.length > 1)
{
sRemnChr = sTmpStr.substring(1, 99);
objNm.value = sFrstChr.toUpperCase() + sRemnChr.toLowerCase();
}
}
}
function gl_ChkField(objNm, chkType, sErrorMsg)
{
bValid = true;
sTmpStr = "";
if (sErrorMsg == "")
{
sErrorMsg = objNm.name;
}
//alert(chkType + ',' + objNm.value);
switch (chkType)
{
case 'STRING':
if (objNm.value == '')
{
alert(sErrorMsg + ' is empty');
objNm.select;
bValid = false;
}
break;
case 'SOLO_STRING':
if (objNm == '')
{
alert(sErrorMsg + ' is empty');
objNm.select;
bValid = false;
}
break;
case 'DATE':
if (!gl_chkDate(objNm, "DD-MM-YYYY"))
{
//alert(sErrorMsg + ' has an invalid date format');
objNm.select;
bValid = false;
}
break;
case 'PASSWORD':
sTmpStr = objNm.value;
if (sTmpStr == '' || sTmpStr.length < 6 || sTmpStr.length > 8)
{
alert(sErrorMsg + ' should be 6 to 8 characters, letters and numbers only');
objNm.select;
bValid = false;
}
else if (sTmpStr == '12345678' || sTmpStr == '1234567' || sTmpStr == '87654321')
{
alert(sErrorMsg + ' may not be number sequence');
objNm.select;
bValid = false;
}
break;
case 'INTEGER':
if (isNaN(objNm.value))
{
alert(sErrorMsg + ' has an invalid numeric format');
objNm.select;
bValid = false;
}
break;
case 'EMAIL':
sTmpStr = objNm.value;
bValid = is_valid_email_address(sTmpStr, sErrorMsg);
break;
case 'CHECKED':
if (objNm.checked == false)
{
//alert(sErrorMsg + ' must be checked');
alert(sErrorMsg);
objNm.select;
bValid = false;
}
break;
}
return (bValid);
}
// is valid email address
function is_valid_email_address(email, email_name)
{
var atPos, substr;
if (email.length < 6)
{
alert("Email Address is Invalid");
return (false);
}
atPos = email.indexOf("@");
if (atPos == -1 || atPos == 0 || atPos == email.length - 1)
{
alert("Email Address is Invalid");
return (false);
}
substr = email.substring(0, atPos);
if (!is_all_in_string(substr, "a-zA-Z0-9_.=[]\/-"))
{
alert("Email Address is Invalid");
return (false);
}
substr = email.substring(atPos + 1, email.length);
if (!is_all_in_string(substr, "a-zA-Z0-9_.-"))
{
alert("Email Address is Invalid");
return (false);
}
if (substr.indexOf(".") == -1)
{
alert("Email Address is Invalid");
return (false);
}
return (true);
}
// is all in string
function is_all_in_string(string, chars)
{
var range = new Array(0);
var search_chars = new String("");
for (var i = 0; i < chars.length; i++)
{
if (i < chars.length - 2)
{
if (chars.charAt(i + 1) == '-')
{
var elem = new Array(chars.charAt(i), chars.charAt(i + 2));
range[range.length] = elem;
i += 2;
continue;
}
}
search_chars = search_chars + chars.charAt(i);
}
for (var i = 0; i < string.length; i++)
{
var next = 0;
var c = string.charAt(i);
for (var j = 0; j < range.length; j++)
{
if (c >= range[j][0] && c <= range[j][1])
{
next++;
break;
}
}
if (next)
{
continue;
}
for (var j = 0; j < search_chars.length; j++)
{
if (c == search_chars.charAt(j))
{
next++;
break;
}
}
if (next)
{
continue;
}
return (false);
}
return (true);
}
// Remove all entries from a select list
function gl_pop_fs(objselect)
{
while (objselect.options(0))
{
objselect.options.remove(0);
}
}
// fname is the name if the database field (MS SQL SERVER ONLY)
function SQL_DateWhere(fname, dateformat)
{
if (!dateformat)
{
dateformat = "DD-MMM-YYYY";
}
var sep = " + '-' + ";
var dd = "CONVERT(varchar, DATEPART(dd, " + fname + ")) ";
var mmm = "SUBSTRING(CONVERT(varchar, DATENAME(month, " + fname + ")), 1, 3) ";
var yyyy = "CONVERT(varchar, DATEPART(yy, " + fname + ")) ";
if (dateformat == "DD-MMM-YYYY")
{
sql = " " + dd + sep + mmm + sep + yyyy + fname;
}
else if (dateformat == "MMM-DD-YYYY")
{
sql = " " + mmm + sep + dd + sep + yyyy + fname;
}
return (sql);
}
function SQL_DateTimeWhere(fname, dateformat)
{
if (!dateformat)
{
dateformat = "DD-MMM-YYYY";
}
var sep = " + ' ' + ";
var dd = "CONVERT(varchar, DATEPART(dd, " + fname + ")) ";
var mmm = "SUBSTRING(CONVERT(varchar, DATENAME(month, " + fname + ")), 1, 3) ";
var yyyy = "CONVERT(varchar, DATEPART(yy, " + fname + ")) ";
if (dateformat == "DD-MMM-YYYY")
{
sql = " " + dd + sep + mmm + sep + yyyy + sep;
}
else if (dateformat == "MMM-DD-YYYY")
{
sql = " " + mmm + sep + dd + sep + yyyy + sep;
}
sql += "CONVERT(varchar, DATEPART(hh, " + fname + ")) + ':' + ";
sql += "RIGHT('0' + CONVERT(varchar, DATEPART(mi, " + fname + ")), 2) + ':' + ";
sql += "RIGHT('0' + CONVERT(varchar, DATEPART(ss, " + fname + ")), 2) " + fname;
return (sql);
}
function SQL_SDateTm_Where(fname, dateformat)
{
if (!dateformat)
{
dateformat = "DD-MMM-YYYY";
}
var sep = " + '-' + ";
var dd = "CONVERT(varchar, DATEPART(dd, " + fname + ")) ";
var mmm = "SUBSTRING(CONVERT(varchar, DATENAME(month, " + fname + ")), 1, 3) ";
var yyyy = "CONVERT(varchar, DATEPART(yy, " + fname + ")) ";
if (dateformat=="DD-MMM-YYYY")
{
sql=" convert(varchar,datepart(dd,"+fname+"))+'-'";
sql+="+substring(convert(varchar,datename(month,"+fname+")),1,3)+'-'";
sql+="+convert(varchar,datepart(yy,"+fname+"))+' '";
}
if (dateformat=="MMM-DD-YYYY")
{
sql="substring(convert(varchar,datename(month,"+fname+")),1,3)+' '";
sql+="+convert(varchar,datepart(dd,"+fname+"))+', '";
sql+="+convert(varchar,datepart(yy,"+fname+"))+' '";
}
sql+="+convert(varchar,datepart(hh,"+fname+"))+':'";
sql+="+RIGHT('0'+convert(varchar,datepart(mi,"+fname+")),2)+':'";
sql+="+RIGHT('0'+convert(varchar,datepart(ss,"+fname+")),2) "+fname;
return (sql);
}
function SQL_TimeWhere(fname)
{
sql = "CONVERT(varchar, DATEPART(hh, " + fname + ")) + ':' + ";
sql += "RIGHT('0' + CONVERT(varchar, DATEPART(mi, " + fname + ")), 2) + ':' + ";
sql += "RIGHT('0' + CONVERT(varchar, DATEPART(ss, " + fname + ")), 2) " + fname;
return (sql);
}
// Returns the shortname of the supplied month number
function RetnMthXXX(monthno)
{
var m = new Array(12);
m[1] = "Jan"; m[2] = "Feb"; m[3] = "Mar"; m[4] = "Apr";
m[5] = "May"; m[6] = "Jun"; m[7] = "Jul"; m[8] = "Aug";
m[9] = "Sep"; m[10] = "Oct"; m[11] = "Nov"; m[12] = "Dec";
if (monthno >= 1 && monthno <= 12)
{
return (m[monthno]);
}
return (false);
}
// Returns the month number of the supplied month name. eg g_getmnthnum(January) returns 1
function RetnMthX(monthname)
{
var sm = monthname.substring(0, 3).toLowerCase();
for (x = 1; x <= 12; x++)
{
if (sm == g_getshtmnth(x).toLowerCase())
{
return (x);
}
}
return (false);
}
// Checks if the number of days is valid for the supplied month and year.
function ChkDaysMth(days, month, year)
{
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
{
if (days >= 1 && days <= 31)
{
return (true);
}
return (false);
}
if (month == 4 || month == 6 || month == 9 || month == 11)
{
if (days >= 1 && days <= 30)
{
return (true);
}
return (false);
}
if (month == 2)
{
if (days >= 1 && days <= 28)
{
return (true);
}
if (days == 29)
{
if (parseInt(year / 4) == (year / 4))
{
return (true);
}
}
return (false);
}
return (false);
}
// Examines a text field and tries to convert it onto a recognised date.
function gl_chkDate(fd_datefield, date_format, no_change)
{
if (!date_format)
{
date_format = "DD-MM-YYYY";
}
date_format = date_format.toUpperCase();
var datefield = fd_datefield.value;
//alert(datefield + '<' + g_trim(datefield) + '|');
if (g_trim(datefield) == '')
{
// If this has a value, don't fire the pagechanged event
if (!no_change)
{
if (typeof pagechanged == "function")
{
pagechanged();
}
}
return (true);
}
// convert slashes to dashes
while (datefield.indexOf("/") != -1)
{
// The end of the next line is not commented out. Only the editor thinks so!
datefield = datefield.replace(/\//g, "-");
}
while (datefield.indexOf(" ") != -1)
{
// The end of the next line is not commented out. Only the editor thinks so!
datefield = datefield.replace(/\ /g, "-");
}
while (datefield.indexOf(",") != -1)
{
// The end of the next line is not commented out. Only the editor thinks so!
datefield = datefield.replace(/\,/g, "");
}
var delim1 = datefield.indexOf("-"); // find the first dash
var delim2 = datefield.lastIndexOf("-"); // find the last dash
if (delim1 != -1 && delim1 == delim2)
{
// if both can't be found then give up
alert ('Date format not valid.');
fd_datefield.focus();
fd_datefield.select();
return (false);
}
if (delim1 != -1)
{
// There are delimiters
if (date_format == "MMM-DD-YYYY")
{
var mmstring = datefield.substring(0, delim1); // extract the month part
var dd = parseInt(datefield.substring(delim1 + 1, delim2), 10); // extract the day part
}
else
{
// Assume Euro Date
var dd = parseInt(datefield.substring(0, delim1), 10); // extract the day part
var mmstring = datefield.substring(delim1 + 1, delim2); // extract the month part
}
if (isNaN(mmstring))
{
// if the month isn't a number, check for a month name.
var mm = g_getmnthnum(mmstring); // convert the monthname to a number
if (isNaN(mm))
{
// if it couldn't be converted, then exit.
alert('Date format not valid. Month name not found');
fd_datefield.focus();
fd_datefield.select();
return (false);
}
}
else
{
// the month is a number, so keep it
var mm = parseInt(mmstring, 10);
}
var yyyy = parseInt(datefield.substring(delim2 + 1, datefield.length), 10); // get the year part
}
else
{
// there are no delimitors. Assume a date format of DDMMYY[YY] or MMDDYY[YY]
if (date_format == "MMM-DD-YYYY")
{
var mm = parseInt(datefield.substring(0, 2), 10); // get the month part
var dd = parseInt(datefield.substring(2, 4), 10); // get the day part
}
else
{
var dd = parseInt(datefield.substring(0, 2), 10); // get the day part
var mm = parseInt(datefield.substring(2, 4), 10); // get the month part
}
var yyyy = parseInt(datefield.substring(4, datefield.length), 10); // get the year part
}
//alert(dd + ',' + mm + ',' + yyyy);
if (isNaN(dd) || isNaN(mm) || isNaN(yyyy))
{
// All the fields need to be numeric
alert('Date format not valid - please enter numeric values');
fd_datefield.focus();
fd_datefield.select();
return (false);
}
if (mm < 1 || mm > 12)
{
// month as to be 1 to 12
alert('Date format not valid. Invalid month');
fd_datefield.focus();
fd_datefield.select();
return (false);
}
if (yyyy > 99 && yyyy < 1000)
{
alert('Date format not valid. Invalid year');
fd_datefield.focus();
fd_datefield.select();
return (false);
}
if (yyyy < 100)
{
// If the year had only 2 digits add to it. Pivot year is 1930
if (yyyy > 30)
{
yyyy += 1900;
}
else
{
yyyy += 2000;
}
}
if (!g_chkdaysmnth(dd, mm, yyyy))
{
// Check the number of days is valid for this month.
alert('Date format not valid. Invalid days');
fd_datefield.focus();
fd_datefield.select();
return (false);
}
if (date_format == "MMM-DD-YYYY")
{
// Format the return date as MMM-DD-YYYY
fd_datefield.value = "" + g_getshtmnth(mm) + " " + dd + ", " + yyyy;
}
else if (date_format == "DD-MM-YYYY")
{
if (mm < 10)
{
fd_datefield.value = "" + dd + "-0" + mm + "-" + yyyy; // Format the return date as DD-MMM-YYYY
}
else
{
fd_datefield.value = "" + dd + "-" + mm + "-" + yyyy; // Format the return date as DD-MMM-YYYY
}
}
else
{
fd_datefield.value = "" + dd + "-" + g_getshtmnth(mm) + "-" + yyyy; // Format the return date as DD-MMM-YYYY
}
if (!no_change)
{
// If this has a value, don't fire the pagechanged event
if (typeof pagechanged == "function")
{
pagechanged();
}
}
return (true);
}
// Checks if the number of days is valid for the supplied month and year.
function g_chkdaysmnth(days, month, year)
{
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
{
if (days >= 1 && days <= 31)
{
return (true);
}
return (false);
}
if (month == 4 || month == 6 || month == 9 || month == 11)
{
if (days >= 1 && days <= 30)
{
return (true);
}
return (false);
}
if (month == 2)
{
if (days >= 1 && days <= 28)
{
return (true);
}
if (days == 29)
{
if (parseInt(year / 4) == (year / 4))
{
return (true);
}
return (false);
}
return (false);
}
return (false);
}
// Returns the shortname of the supplied month number
function g_getshtmnth(monthno)
{
var m = new Array(12);
m[1] = "Jan"; m[2] = "Feb"; m[3] = "Mar"; m[4] = "Apr";
m[5] = "May"; m[6] = "Jun"; m[7] = "Jul"; m[8] = "Aug";
m[9] = "Sep"; m[10] = "Oct"; m[11] = "Nov"; m[12] = "Dec";
if (monthno >= 1 && monthno <= 12)
{
return (m[monthno]);
}
return (false);
}
// Returns the month number of the supplied month name. eg g_getmnthnum(January) returns 1
function g_getmnthnum(monthname)
{
var sm = monthname.substring(0, 3).toLowerCase();
for (x = 1; x <= 12; x++)
{
if (sm == g_getshtmnth(x).toLowerCase())
{
return (x);
}
}
return (false);
}
// Get the next id for the table
// Use new ADO D.Roughan
function g_getnextid(tbl)
{
return (query2("sp_gen_id '" + tbl + "'")("id").value);
}
// Create the WHERE query for the owners - should be called from pages
function g_whereowner(tbl)
{
s = tbl + ".owner1_id='" + parent.g_owner1_id + "' ";
if (parent.g_owner2_id)
{
s += "AND " + tbl + ".owner2_id='" + parent.g_owner2_id + "' ";
}
if (parent.g_owner3_id)
{
s += "AND " + tbl + ".owner3_id='" + parent.g_owner3_id + "' ";
}
return (s);
}
// Strip out single quotes from a field
function g_dbprep(v)
{
if (v)
{
n = v;
n = n.replace(/\'/g, "''");
return (g_trim(n));
}
n = "";
return (n);
}
// Prepare the field that was returned from the database
function g_prep(st)
{
if (st == null)
{
st = "";
}
if (typeof st == "string")
{
st = g_trim(st);
}
// Deal with NULL date DD-MMM-YYY
if (st == '--')
{
st = '';
}
// Deal with NULL date MMM DD, YYYY
if (st == ",")
{
st = '';
}
return (st);
}
// Opens a new Browse window with the URL provided
function g_open_url(url_location)
{
if (url_location)
{
open('http://' + url_location, '', "height=570,width=850,left=0,top=0,location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=yes,titlebar=yes,toolbar=yes");
}
}
// Opens the Australian White Pages in a new Browser
function g_whitepages()
{
var location = "http://www.whitepages.com.au/search.shtml";
open(location, '', "height=600,width=800,left=0,top=0,location=yes,menubar=no,resizable=yes,scrollbars=yes,status=no,titlebar=no,toolbar=yes");
}
function g_yellowpages()
{
var location = "http://www.yellowpages.com.au/search/search.html";
open(location, '', "height=600,width=800,left=0,top=0,location=yes,menubar=no,resizable=yes,scrollbars=yes,status=no,titlebar=no,toolbar=yes");
}
function g_postcodes()
{
var location = "http://www.whitepages.com.au/pcode.shtml";
open(location, '', "height=600,width=800,left=0,top=0,location=yes,menubar=no,resizable=yes,scrollbars=yes,status=no,titlebar=no,toolbar=yes");
}
// number formater
function g_format_numbers(expr, decplaces)
{
// raise incoming value by power of 10 times the number
// of decimal places; round to an integer; convert to string
var str = "" + Math.round(eval(expr) * Math.pow(10, decplaces));
// pad small value strings with zeros to the left of rounded number
while (str.length <= decplaces)
{
str = "0" + str;
}
// establish location of decimal point
var decpoint = str.length - decplaces;
// assemble final result from:
// (a) the string up to the position of the decimal point;
// (b) the decimal point; and
// (c) the balance of the string. Return finished product.
if (decplaces == 0)
{
return (str.substring(0, decpoint));
}
return (str.substring(0, decpoint) + '.' + str.substring(decpoint, str.length));
}
// puts number in dollar format
function g_dollarise(expr)
{
return (g_format_numbers(expr, 2));
}
// Trim any spaces from the RHS and LHS of the string
function g_trim(ts)
{
if (ts)
{
while (ts.charAt(ts.length - 1) == ' ')
{
ts = ts.substring(0, ts.length - 1);
}
while (ts.charCodeAt(ts.length - 1) == 0)
{
ts = ts.substring(0, ts.length - 1);
}
while (ts.charAt(0) == ' ')
{
ts = ts.substring(1, ts.length);
}
}
return (ts);
}
Hudson - Global Leader in Staffing, Outsourcing, and Human Capital Solutions