// dlgcommon-validation.js
// Copyright (c) 1998-2000 PaperThin, Inc.

var gvDialogError = 0;
var reWhitespace = /^\s+$/; // Matches any combination of spaces, tabs, etc.
var reEmail = /^.+\@.+\..+$/; // Matches an email address xxx@xxx.xx
var reInteger = /^\d+$/; // Matches integers
var reAlphaNumeric = /^[a-zA-Z0-9]+$/; // Matches strings with only letters or numbers.
var reAlphaNumericSpace = /^[a-zA-Z0-9 ]+$/; // Matches strings with only letters, numbers, and spaces.
var reSiteChars = /^[a-zA-Z0-9\-_]+$/; // Matches strings with only letters or numbers.

function trim(str)
{
	return str.replace(/^\s+|\s+$/g,"");
}

// Check whether string s is empty.
function isEmpty(s)
{
	return ((s == null) || (s.length == 0));
}

// Returns true if string s is empty or 
// whitespace characters only.
function isWhitespace (s)
{
	return (isEmpty(s) || reWhitespace.test(s));
}

// Returns true if string s only has letters a-z and or numbers 0-9
function isAlphaNumeric (s)
{
	return reAlphaNumeric.test(s);
}

// Returns true if string s only has letters a-z and or numbers 0-9, or spaces
function isAlphaNumericSpace (s)
{
	return reAlphaNumericSpace.test(s);
}

// Returns true if string s only has letters a-z, numbers 0-9, dashes, or underscores
function isSiteChars (s)
{
	return reSiteChars.test(s);
}

// Returns true if it is a valid email address.
// Optional 2nd parameter can allow empty strings.
function isEmail (s)
{
	if (isEmpty(s))
	{
		if (isEmail.arguments.length == 1)
			return false;
		else
			return (isEmail.arguments[1] == true);
    }
	else
	{
       return reEmail.test(s);
    }
}

// Returns true for an integer
function isInteger (s)
{
	if (isEmpty(s))
	{
		if (isInteger.arguments.length == 1)
			return false;
		else
			return (isInteger.arguments[1] == true);
	}
	else
	{
		return reInteger.test(s)
	}
}

// Checks the length a of string for a minimum and maximum length;
function isLengthInRange (s, minimum, maximum) {
	if (s.length < minimum || s.length > maximum) {
		return false;
	} else {
		return true;
	}
}

// function to determine if value is in acceptable range for this application
function inRange(inputStr, lo, hi) {
	var num = parseInt(inputStr);
		if (num < lo || num > hi) {
			return false;
		}
	return true;
}

// Match the value property of 2 fields
function isMatch(fielda, fieldb) {
	if (fielda.value != fieldb.value) {
		return false;
	} else {
		return true;
	}
}

// Checks for a checked radio button
function isRadioChecked(radiofield) {
	for (var i = 0; i < radiofield.length; i++) {
		if (radiofield[i].checked) {
			return true;
		}
	}
	return false;
}

// Checks for a selected option
function isOptionSelected(selectfield) {
	if (selectfield.options[selectfield.selectedIndex].value == "") {
		return false;
	} else {
		return true;
	}
}

// Returns the checked option's value, returns null if no value is checked.
function getRadioCheckedValue(radiofield) {
	for (var i = 0; i < radiofield.length; i++) {
		if (radiofield[i].checked) {
			return radiofield[i].value;
		}
	}
	return null;
}

