// whitespace characters
var whitespace = " \t\n\r";

// Check whether string s is empty.
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}
//--------------------------------------------------------------------------------------------
function ChkNumeric( FieldName ) {
	var ValueSent = FieldName.value;
	var Vlen = ValueSent.length;
	var FldName = FieldName.name;

	//--------- Added "." check 9/20/00 DB ---------------------------------------
		if ( ValueSent.length == 0 || ValueSent == "."){
			FieldName.value = "";
			return;
		}

	//DWEB000540 - Added if statement to check if auto year is in yyyy format. 6/15/2001 KR
	if (FldName == "AutoYear") 
	{
	  if(ValueSent.length < 4)
	  {  
	     alert ("Please ensure that a 4-digit year (including century) has been entered");
	     SetFocus(FieldName);
	     return false;
	  }
	}

	var  ch;
	for (var i = 0; i < Vlen; ++i) {
		ch = ValueSent.substring(i,i + 1);
		if (ch < "0" || "9" < ch) {
			alert ("Please enter a valid number, decimals and other punctuation are not allowed");
			SetFocus(FieldName);
			return false;
		}		
	}
	return true;
}

//--------------------------------------------------------------------------------------------
function SetFocus( _field ) {
	_field.focus();
	if (_field.type != "select-one") 
		_field.select();
}

//--------------------------------------------------------------------------------------------
function outputComma(number) {
	//** accounts for Negative values **
	//** Paul Rose
	
	var neg = "";
	 number = '' + number
	 if (number.charAt(0) == "-"){
		neg = "-";
		number = number.substring(1,number.length)
	 }
    if (number.length > 6) {
        var mod = number.length%3;
        var output = (mod > 0 ? (number.substring(0,mod)) : '');
        for (i=0 ; i < Math.floor(number.length/3) ; i++) {
            if (((mod ==0) && (i ==0)) || ( output.length > number.length-3 ))
                output+= number.substring(mod+3*i,mod+3*i+3);
            else 
                output+= ',' + number.substring(mod+3*i,mod+3*i+3);            
        }
        return (neg + output);
    }
    else return neg + number;
}
//--------------------------------------------------------------------------------------------
function formatCent(amount) {
	//** returns number value in the XX.99 format **
	
    amount -= 0;
    return (amount == Math.floor(amount)) ? amount + '.00' : (  (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
}
//--------------------------------------------------------------------------------------------
function stripCommas(ValueSent) {
	// ** Clean , and $ sign from number/string values **
	
	var Vlen = ValueSent.length;
	var ch;
	var nval = "";
 
	for (var i = 0; i < Vlen; ++i) {
		ch = ValueSent.substring(i,i + 1);
      if(ch != "," && ch != "$") 
			nval = nval + ch;
	}	
 
	return nval;
}
//--------------------------------------------------------------------------------------------
function stripSpaces(stg) {
	//** Trim leading and trailing spaces off string value **
	
    x = stg + "";
    while (x.substring(0,1) == ' ') x = x.substring(1);
    while (x.substring(x.length-1,x.length) == ' ') x = x.substring(0,x.length-1);
    return x;
}

// Returns true if string s is empty or 
// whitespace characters only.

function isWhitespace (s)
{   var i;

    // Is s empty?
    if (isEmpty(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 (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

function chkImg(Field, ImgName)
{
	var frm, img, len, i;
	img = Field.name;
	frm = Field.form.name;
	len = document.forms[frm].elements[img].length;
	for (i = 0; i < len; i++)
    {   
		if (document.forms[frm].elements[img][i].value != ImgName)
			document.forms[frm].elements[img][i].checked = false;
    }
}

/****************************************************************/
// Returns true if the string passed in is a valid number
//  (no alpha characters), else it return false

function ForceNumber(objField)
{
	var strField = new String(objField.value);
	
	if (isWhitespace(strField)){
		return false;	
	} 

	var i = 0;

	for (i = 0; i < strField.length; i++)
		if (strField.charAt(i) < '0' || strField.charAt(i) > '9') 
			return false;
   return true;
}
/****************************************************************/
// Returns true if the string passed in is a positive number,
// else it return false

function isPositiveNumber( num )
{
	for( var index = 0; index < num.length; index++ )
		if( (num.charAt(index) != ".") && ((num.charAt(index) < "0") || (num.charAt(index) > "9")) )
			return false;
	return true;
}
/****************************************************************/
// Returns true if the string passed in is a valid number
//  (no alpha characters, "." is allowed), else it return false

function ForcePointNumber(objField)
{
	var strField = new String(objField.value);
	
	if (isWhitespace(strField)){
		return false;	
	} 

	var i = 0;

	for (i = 0; i < strField.length; i++)
		if ((strField.charAt(i) < '0' || strField.charAt(i) > '9') && strField.charAt(i) != '.') 
			return false;
   return true;
}

/****************************************************************/


// isEmail (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

function isEmail (s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return false;
       else return (isEmail.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(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;
}


/****************************************************************/