// cpx_lib.js
// Rangel Reale	-	2004-11-15
//
// javascript functions to be used together with the CPX component library
//
// Some portions from:
//		FormCheck.js
// 18 Feb 97 created Eric Krock
//
// (c) 1997 Netscape Communications Corporation


// *******************
// VARIABLES
// *******************

// lang
var cpxvar_lang_default = 'en_US';
var cpxvar_lang_current = 'en_US';
var cpxvar_lang_defs = new Array();
var cpxvar_lang_str = new Array();

// char constants
var cpxvar_char_whitespace				= " \t\n\r";

// func
// message function: "function message(msg)"
var cpxvar_func_message				= null;

// constants
var cpxvar_const_defaultemptyok			= false;

var cpxvar_const_daysinmonth = new Array(12);
cpxvar_const_daysinmonth[1] = 31;
cpxvar_const_daysinmonth[2] = 29;   // must programmatically check this
cpxvar_const_daysinmonth[3] = 31;
cpxvar_const_daysinmonth[4] = 30;
cpxvar_const_daysinmonth[5] = 31;
cpxvar_const_daysinmonth[6] = 30;
cpxvar_const_daysinmonth[7] = 31;
cpxvar_const_daysinmonth[8] = 31;
cpxvar_const_daysinmonth[9] = 30;
cpxvar_const_daysinmonth[10] = 31;
cpxvar_const_daysinmonth[11] = 30;
cpxvar_const_daysinmonth[12] = 31;


// *******************
// FUNCTIONS
// *******************

// INIT function
function cpx_init()
{
	// loads the default language
	cpx_lang_default();
}

// AUX functions
function cpx_setmessagefunc(msgfunc)
{
	cpxvar_func_message = msgfunc;
}

// LANGUAGE functions
function cpx_lang_default()
{
	cpxvar_lang_defs[cpxvar_lang_default] = new Array();
	cpxvar_lang_defs[cpxvar_lang_default]['dec_separator'] = '.';
	cpxvar_lang_defs[cpxvar_lang_default]['thousands_separator'] = ',';
	cpxvar_lang_defs[cpxvar_lang_default]['date_separator'] = '/';
	cpxvar_lang_defs[cpxvar_lang_default]['date_format'] = 'm/d/y';
	cpxvar_lang_defs[cpxvar_lang_default]['time_format'] = 'h:m';

	cpxvar_lang_defs[cpxvar_lang_default]['lang_checks'] = new Array();

	cpxvar_lang_str[cpxvar_lang_default] = new Array();
	cpxvar_lang_str[cpxvar_lang_default]['field_required'] = 'The field "%%fld%%" cannot be blank.';
	cpxvar_lang_str[cpxvar_lang_default]['field_invalid'] = 'The value of field "%%fld%%" is invalid.';
	
	cpxvar_lang_current = cpxvar_lang_default;	
}


// ***********************
// INTERNAL FUNCTIONS
// ***********************
function cpxint_showmessage(message)
{
	if (cpxvar_func_message != null)
		eval(cpxvar_func_message+'("'+message+'")');
	else
		alert(message);
}


// Check whether string s is empty.
function cpxint_is_empty (s)
{
	return ((s == null) || (s.length == 0));
}

// Returns true if string s is empty or 
// whitespace characters only.
function cpxint_is_whitespace (s)
{   
	var i;

    // Is s empty?
    if (cpxint_is_empty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (cpxvar_char_whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

// Removes all characters which appear in string chars from string s.
function cpxint_stripchars (s, chars)
{   
	var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is not in chars, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (chars.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}

// Removes all characters which do NOT appear in string chars 
// from string s.

function cpxint_stripcharsnot (s, chars)

{   
	var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is in chars, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (chars.indexOf(c) != -1) returnString += c;
    }

    return returnString;
}


// Removes all whitespace characters from s.
// Global variable whitespace (see above)
// defines which characters are considered whitespace.

function cpxint_strip_whitespace (s)
{   
	return cpxint_stripchars (s, cpxvar_char_whitespace);
}

// Removes initial (leading) whitespace characters from s.
// Global variable whitespace (see above)
// defines which characters are considered whitespace.
function cpxint_strip_initialwhitespace (s)
{   
	var i = 0;

    while ((i < s.length) && charInString (s.charAt(i), cpxvar_char_whitespace))
       i++;
    
    return s.substring (i, s.length);
}

// Returns true if character c is an English letter 
// (A .. Z, a..z).
//
// NOTE: Need i18n version to support European characters.
// This could be tricky due to different character
// sets and orderings for various languages and platforms.

function cpx_is_letter (c)
{   
	return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) );
}

// Returns true if character c is a digit 
// (0 .. 9).

function cpxint_is_digit (c)
{   
	return ((c >= "0") && (c <= "9"));
}

// Returns true if character c is a letter or digit.

function cpxint_is_letterordigit (c)
{   
	return (cpxint_is_letter(c) || cpxint_is_digit(c));
}


// cpxint_is_integer (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if all characters in string s are numbers.
//
// Accepts non-signed integers only. Does not accept floating 
// point, exponential notation, etc.
//
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.
//
// By default, returns cpxvar_const_defaultemptyok if s is empty.
// There is an optional second argument called emptyOK.
// emptyOK is used to override for a single function call
//      the default behavior which is specified globally by
//      cpxvar_const_defaultemptyok.
// If emptyOK is false (or any value other than true), 
//      the function will return false if s is empty.
// If emptyOK is true, the function will return true if s is empty.
//
// EXAMPLE FUNCTION CALL:     RESULT:
// cpxint_is_integer ("5")            true 
// cpxint_is_integer ("")             cpxvar_const_defaultemptyok
// cpxint_is_integer ("-5")           false
// cpxint_is_integer ("", true)       true
// cpxint_is_integer ("", false)      false
// cpxint_is_integer ("5", false)     true

function cpxint_is_integer (s)

{   var i;

    if (cpxint_is_empty(s)) 
       if (cpxint_is_integer.arguments.length == 1) return cpxvar_const_defaultemptyok;
       else return (cpxint_is_integer.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!cpxint_is_digit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

// cpxint_is_signedinteger (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if all characters are numbers; 
// first character is allowed to be + or - as well.
//
// Does not accept floating point, exponential notation, etc.
//
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
//
// EXAMPLE FUNCTION CALL:          RESULT:
// cpxint_is_signedinteger ("5")           true 
// cpxint_is_signedinteger ("")            cpxvar_const_defaultemptyok
// cpxint_is_signedinteger ("-5")          true
// cpxint_is_signedinteger ("+5")          true
// cpxint_is_signedinteger ("", false)     false
// cpxint_is_signedinteger ("", true)      true

function cpxint_is_signedinteger (s)

{   
	if (cpxint_is_empty(s)) 
       if (cpxint_is_signedinteger.arguments.length == 1) return cpxvar_const_defaultemptyok;
       else return (cpxint_is_signedinteger.arguments[1] == true);

    else {
        var startPos = 0;
        var secondArg = cpxvar_const_defaultemptyok;

        if (cpxint_is_signedinteger.arguments.length > 1)
            secondArg = cpxint_is_signedinteger.arguments[1];

        // skip leading + or -
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;    
        return (cpxint_is_integer(s.substring(startPos, s.length), secondArg))
    }
}

// cpxint_is_positiveinteger (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is an integer > 0.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function cpxint_is_positiveinteger (s)
{   
	var secondArg = cpxvar_const_defaultemptyok;

    if (cpxint_is_positiveinteger.arguments.length > 1)
        secondArg = cpxint_is_positiveinteger.arguments[1];

    // The next line is a bit byzantine.  What it means is:
    // a) s must be a signed integer, AND
    // b) one of the following must be true:
    //    i)  s is empty and we are supposed to return true for
    //        empty strings
    //    ii) this is a positive, not negative, number

    return (cpxint_is_signedinteger(s, secondArg)
         && ( (cpxint_is_empty(s) && secondArg)  || (parseInt (s) > 0) ) );
}


// cpxint_is_nonnegativeinteger (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is an integer >= 0.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function cpxint_is_nonnegativeinteger (s)
{   var secondArg = cpxvar_const_defaultemptyok;

    if (cpxint_is_nonnegativeinteger.arguments.length > 1)
        secondArg = cpxint_is_nonnegativeinteger.arguments[1];

    // The next line is a bit byzantine.  What it means is:
    // a) s must be a signed integer, AND
    // b) one of the following must be true:
    //    i)  s is empty and we are supposed to return true for
    //        empty strings
    //    ii) this is a number >= 0

    return (cpxint_is_signedinteger(s, secondArg)
         && ( (cpxint_is_empty(s) && secondArg)  || (parseInt (s) >= 0) ) );
}


// cpxint_is_negativeinteger (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is an integer < 0.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function cpxint_is_negativeinteger (s)
{   
	var secondArg = cpxvar_const_defaultemptyok;

    if (cpxint_is_negativeinteger.arguments.length > 1)
        secondArg = cpxint_is_negativeinteger.arguments[1];

    // The next line is a bit byzantine.  What it means is:
    // a) s must be a signed integer, AND
    // b) one of the following must be true:
    //    i)  s is empty and we are supposed to return true for
    //        empty strings
    //    ii) this is a negative, not positive, number

    return (cpxint_is_signedinteger(s, secondArg)
         && ( (cpxint_is_empty(s) && secondArg)  || (parseInt (s) < 0) ) );
}


// cpxint_is_nonpositiveinteger (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is an integer <= 0.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function cpxint_is_nonpositiveinteger (s)
{   
	var secondArg = cpxvar_const_defaultemptyok;

    if (cpxint_is_nonpositiveinteger.arguments.length > 1)
        secondArg = cpxint_is_nonpositiveinteger.arguments[1];

    // The next line is a bit byzantine.  What it means is:
    // a) s must be a signed integer, AND
    // b) one of the following must be true:
    //    i)  s is empty and we are supposed to return true for
    //        empty strings
    //    ii) this is a number <= 0

    return (cpxint_is_signedinteger(s, secondArg)
         && ( (cpxint_is_empty(s) && secondArg)  || (parseInt (s) <= 0) ) );
}


// cpxint_is_float (STRING s [, BOOLEAN emptyOK])
// 
// True if string s is an unsigned floating point (real) number. 
//
// Also returns true for unsigned integers. If you wish
// to distinguish between integers and floating point numbers,
// first call isInteger, then call isFloat.
//
// Does not accept exponential notation.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function cpxint_is_float (s)

{   
	var i;
    var seenDecimalPoint = false;

    if (cpxint_is_empty(s)) 
       if (cpxint_is_float.arguments.length == 1) return cpxvar_const_defaultemptyok;
       else return (cpxint_is_float.arguments[1] == true);

    if (s == cpxvar_lang_defs[cpxvar_lang_current]['dec_separator']) return false;

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if ((c == cpxvar_lang_defs[cpxvar_lang_current]['dec_separator']) && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!cpxint_is_digit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

// cpxint_is_signedfloat (STRING s [, BOOLEAN emptyOK])
// 
// True if string s is a signed or unsigned floating point 
// (real) number. First character is allowed to be + or -.
//
// Also returns true for unsigned integers. If you wish
// to distinguish between integers and floating point numbers,
// first call isSignedInteger, then call isSignedFloat.
//
// Does not accept exponential notation.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function cpxint_is_signedfloat (s)

{   
	if (cpxint_is_empty(s)) 
       if (cpxint_is_signedfloat.arguments.length == 1) return cpxvar_const_defaultemptyok;
       else return (cpxint_is_signedfloat.arguments[1] == true);

    else {
        var startPos = 0;
        var secondArg = cpxvar_const_defaultemptyok;

        if (cpxint_is_signedfloat.arguments.length > 1)
            secondArg = cpxint_is_signedfloat.arguments[1];

        // skip leading + or -
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;    
        return (cpxint_is_float(s.substring(startPos, s.length), secondArg))
    }
}


// cpxint_is_alphabetic (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is English letters 
// (A .. Z, a..z) only.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
//
// NOTE: Need i18n version to support European characters.
// This could be tricky due to different character
// sets and orderings for various languages and platforms.

function cpxint_is_alphabetic (s)

{   
	var i;

    if (cpxint_is_empty(s)) 
       if (cpxint_is_alphabetic.arguments.length == 1) return cpxvar_const_defaultemptyok;
       else return (cpxint_is_alphabetic.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-alphabetic character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is letter.
        var c = s.charAt(i);

        if (!cpxint_is_letter(c))
	        return false;
    }

    // All characters are letters.
    return true;
}


// cpxint_is_alphanumeric (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is English letters 
// (A .. Z, a..z) and numbers only.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
//
// NOTE: Need i18n version to support European characters.
// This could be tricky due to different character
// sets and orderings for various languages and platforms.

function cpxint_is_alphanumeric (s)

{   
	var i;

    if (cpxint_is_empty(s)) 
       if (cpxint_is_alphanumeric.arguments.length == 1) return cpxvar_const_defaultemptyok;
       else return (cpxint_is_alphanumeric.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-alphanumeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number or letter.
        var c = s.charAt(i);

        if (! cpxint_is_letterordigit(c) )
	        return false;
    }

    // All characters are numbers or letters.
    return true;
}


// cpxint_reformat (TARGETSTRING, STRING, INTEGER, STRING, INTEGER ... )       
//
// Handy function for arbitrarily inserting formatting characters
// or delimiters of various kinds within TARGETSTRING.
//
// reformat takes one named argument, a string s, and any number
// of other arguments.  The other arguments must be integers or
// strings.  These other arguments specify how string s is to be
// reformatted and how and where other strings are to be inserted
// into it.
//
// reformat processes the other arguments in order one by one.
// * If the argument is an integer, reformat appends that number 
//   of sequential characters from s to the resultString.
// * If the argument is a string, reformat appends the string
//   to the resultString.
//
// NOTE: The first argument after TARGETSTRING must be a string.
// (It can be empty.)  The second argument must be an integer.
// Thereafter, integers and strings must alternate.  This is to
// provide backward compatibility to Navigator 2.0.2 JavaScript
// by avoiding use of the typeof operator.
//
// It is the caller's responsibility to make sure that we do not
// try to copy more characters from s than s.length.
//
// EXAMPLES:
//
// * To reformat a 10-digit U.S. phone number from "1234567890"
//   to "(123) 456-7890" make this function call:
//   reformat("1234567890", "(", 3, ") ", 3, "-", 4)
//
// * To reformat a 9-digit U.S. Social Security number from
//   "123456789" to "123-45-6789" make this function call:
//   reformat("123456789", "", 3, "-", 2, "-", 4)
//
// HINT:
//
// If you have a string which is already delimited in one way
// (example: a phone number delimited with spaces as "123 456 7890")
// and you want to delimit it in another way using function reformat,
// call function stripCharsNotInBag to remove the unwanted 
// characters, THEN call function reformat to delimit as desired.
//
// EXAMPLE:
//
// cpxint_reformat (cpx_stripcharsnot ("123 456 7890", digits),
//           "(", 3, ") ", 3, "-", 4)

function cpxint_reformat (s)

{   
	var arg;
    var sPos = 0;
    var resultString = "";

    for (var i = 1; i < cpxint_reformat.arguments.length; i++) {
       arg = cpxint_reformat.arguments[i];
       if (i % 2 == 1) resultString += arg;
       else {
           resultString += s.substring(sPos, sPos + arg);
           sPos += arg;
       }
    }
    return resultString;
}


// cpxint_is_email (STRING s [, BOOLEAN emptyOK])
// 
// Email address must be of form a@b.c -- in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function cpxint_is_email (s)
{  
	if (cpxint_is_empty(s)) 
       if (cpxint_is_email.arguments.length == 1) return cpxvar_const_defaultemptyok;
       else return (cpxint_is_email.arguments[1] == true);
   
    // is s whitespace?
    if (cpxint_is_whitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

// cpxint_is_year (STRING s [, BOOLEAN emptyOK])
// 
// isYear returns true if string s is a valid 
// Year number.  Must be 2 or 4 digits only.
// 
// For Year 2000 compliance, you are advised
// to use 4-digit year numbers everywhere.
//
// And yes, this function is not Year 10000 compliant, but 
// because I am giving you 8003 years of advance notice,
// I don't feel very guilty about this ...
//
// For B.C. compliance, write your own function. ;->
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function cpxint_is_year (s)
{   if (cpxint_is_empty(s)) 
       if (cpxint_is_year.arguments.length == 1) return cpxvar_const_defaultemptyok;
       else return (cpxint_is_year.arguments[1] == true);
    if (!cpxint_is_nonnegativeinteger(s)) return false;
    return ((s.length == 2) || (s.length == 4));
}


// cpx_is_integerinrange (STRING s, INTEGER a, INTEGER b [, BOOLEAN emptyOK])
// 
// cpx_is_integerinrange returns true if string s is an integer 
// within the range of integer arguments a and b, inclusive.
// 
// For explanation of optional argument emptyOK,
// see comments of function isInteger.


function cpx_is_integerinrange (s, a, b)
{   
	if (cpxint_is_empty(s)) 
       if (cpx_is_integerinrange.arguments.length == 1) return cpxvar_const_defaultemptyok;
       else return (cpx_is_integerinrange.arguments[1] == true);

    // Catch non-integer strings to avoid creating a NaN below,
    // which isn't available on JavaScript 1.0 for Windows.
    if (!cpxint_is_integer(s, false)) return false;

    // Now, explicitly change the type to integer via parseInt
    // so that the comparison code below will work both on 
    // JavaScript 1.2 (which typechecks in equality comparisons)
    // and JavaScript 1.1 and before (which doesn't).
    var num = parseInt (s);
    return ((num >= a) && (num <= b));
}

// cpxint_is_month (STRING s [, BOOLEAN emptyOK])
// 
// cpxint_is_month returns true if string s is a valid 
// month number between 1 and 12.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function cpxint_is_month (s)
{   if (cpxint_is_empty(s)) 
       if (cpxint_is_month.arguments.length == 1) return cpxvar_const_defaultemptyok;
       else return (cpxint_is_month.arguments[1] == true);
    return cpxint_is_integerinrange (s, 1, 12);
}


// cpxint_is_day (STRING s [, BOOLEAN emptyOK])
// 
// cpxint_is_day returns true if string s is a valid 
// day number between 1 and 31.
// 
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function cpxint_is_day (s)
{   if (cpxint_is_empty(s)) 
       if (cpxint_is_day.arguments.length == 1) return cpxvar_const_defaultemptyok;
       else return (cpxint_is_day.arguments[1] == true);   
    return cpxint_is_integerinrange (s, 1, 31);
}

// cpxint_daysinfebruary (INTEGER year)
// 
// Given integer argument year,
// returns number of days in February of that year.

function cpxint_daysinfebruary (year)
{   // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}

// cpxint_is_date (STRING year, STRING month, STRING day)
//
// cpxint_is_date returns true if string arguments year, month, and day 
// form a valid date.
// 

function cpxint_is_date (year, month, day)
{   
	// catch invalid years (not 2- or 4-digit) and invalid months and days.
    if (! (cpxint_is_year(year, false) && cpxint_is_month(month, false) && cpxint_is_day(day, false))) return false;

    // Explicitly change type to integer to make code work in both
    // JavaScript 1.1 and JavaScript 1.2.
    var intYear = parseInt(year);
    var intMonth = parseInt(month);
    var intDay = parseInt(day);

    // catch invalid days, except for February
    if (intDay > cpxvar_const_daysinmonth[intMonth]) return false; 

    if ((intMonth == 2) && (intDay > cpxint_daysinfebruary(intYear))) return false;

    return true;
}


// Notify user that required field theField is empty.
// String s describes expected contents of theField.value.
// Put focus in theField and return false.

function cpxint_warnempty (theField, s)
{   
    if (theField != null) {
		try { theField.focus() } catch(e) {}
	}

    cpxint_showmessage(cpxvar_lang_str[cpxvar_lang_current]['field_required'].replace('%%fld%%', s));
    return false;
}



// Notify user that contents of field theField are invalid.
// String s describes expected contents of theField.value.
// Put select theField, pu focus in it, and return false.

function cpxint_warninvalid (theField, s)
{   
    if (theField != null) {
		try { theField.focus(); theField.select(); } catch(e) {}
	}
    cpxint_showmessage(cpxvar_lang_str[cpxvar_lang_current]['field_invalid'].replace('%%fld%%', s));
    return false;
}


/* FUNCTIONS TO INTERACTIVELY CHECK VARIOUS FIELDS. */

// cpxint_checkstring (TEXTFIELD theField, STRING s, [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is not all whitespace.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function cpxint_checkstring (theField, s, emptyOK)
{   
	// Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    if (cpxint_checkstring.arguments.length == 2) emptyOK = cpxvar_const_defaultemptyok;
    if ((emptyOK == true) && (cpxint_is_empty(theField.value))) return true;
    if (cpxint_is_whitespace(theField.value)) 
       return cpxint_warnempty (theField, s);
    else return true;
}


// cpxint_checknumber (TEXTFIELD theField, STRING s, [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid number.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function cpxint_checknumber (theField, s, emptyOK)
{   
	// Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    if (cpxint_checknumber.arguments.length == 2) emptyOK = cpxvar_const_defaultemptyok;
    if ((emptyOK == true) && (cpxint_is_empty(theField.value))) return true;
    if (! cpxint_is_signedinteger(theField.value) && ! cpxint_is_signedfloat(theField.value)) 
       return cpxint_warninvalid (theField, s);
    else return true;
}

// cpxint_checkemail (TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid Email.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function cpxint_checkemail (theField, s, emptyOK)
{   if (cpxint_checkemail.arguments.length == 2) emptyOK = cpxvar_const_defaultemptyok;
    if ((emptyOK == true) && (epxint_is_empty(theField.value))) return true;
    else if (!cpxint_is_email(theField.value, false)) 
       return cpxint_warninvalid (theField, s);
    else return true;
}


// Check that string theField.value is a valid Year.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function cpxint_checkyear (theField, s, emptyOK)
{   if (cpxint_checkyear.arguments.length == 2) emptyOK = cpxvar_const_defaultemptyok;
    if ((emptyOK == true) && (cpxint_is_empty(theField.value))) return true;
    if (!cpxint_is_year(theField.value, false)) 
       return cpxint_warninvalid (theField, s);
    else return true;
}


// Check that string theField.value is a valid Month.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function cpxint_checkmonth (theField, s, emptyOK)
{   if (cpxint_checkmonth.arguments.length == 2) emptyOK = cpxvar_const_defaultemptyok;
    if ((emptyOK == true) && (cpxint_is_empty(theField.value))) return true;
    if (!cpxint_is_month(theField.value, false)) 
       return cpxint_warninvalid (theField, s);
    else return true;
}


// Check that string theField.value is a valid Day.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function cpxint_checkday (theField, s, emptyOK)
{   if (cpxint_checkday.arguments.length == 2) emptyOK = cpxvar_const_defaultemptyok;
    if ((emptyOK == true) && (cpxint_is_empty(theField.value))) return true;
    if (!cpxint_is_day(theField.value, false)) 
       return cpxint_warninvalid (theField, s);
    else return true;
}


// cpxint_checkdate (yearField, monthField, dayField, STRING labelString [, OKtoOmitDay==false])
//
// Check that yearField.value, monthField.value, and dayField.value 
// form a valid date.
//
// If it is OK for the day field to be empty, set optional argument
// OKtoOmitDay to true.  It defaults to false.

function cpxint_checkdate (yearField, monthField, dayField, s, OKtoOmitDay)
{   
	// Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    if (cpxint_checkdate.arguments.length == 4) OKtoOmitDay = false;
    if (!cpxint_is_year(yearField.value)) return cpxint_warninvalid (yearField, s);
    if (!cpxint_is_month(monthField.value)) return cpxint_warninvalid (monthField, s);
    if ( (OKtoOmitDay == true) && cpxint_is_empty(dayField.value) ) return true;
    else if (!cpxint_is_day(dayField.value)) 
       return cpxint_warninvalid (dayField, s);
    if (cpxint_is_date (yearField.value, monthField.value, dayField.value))
       return true;
	cpxint_warninvalid(null, s);
    return false
}



// VALUE GET functions

// cpxint_getradiovalue(RADIOFIELD theField)
// Get checked value from radio button.

function cpxint_getradiovalue (theField)
{   
	for (var i = 0; i < theField.length; i++)
    {   
		if (theField[i].checked) { 
		    return theField[i].value;
		}
    }
	return '';
}

