function WebValidation()
{
	/* properties */

	/* methods */
	this.validateEmail 					= Web_validateEmail;
	this.validateTextField				= Web_validateTextField;
	this.validateSelectField			= Web_validateSelectField;
	this.validateFormTextField			= Web_validateFormTextField;
	this.validateDateFormat				= Web_validateDateFormat;
        this.validateCreditCard                         = Web_validateCreditCard;
        this.validateXOrSelect				= Web_validateXOrSelect;
		this.validateNonNullInt = Web_validateNonNullInt;
}

function Web_validateFormTextField( field, min, max, fieldname )
{
	var str = field.value;
	// replace all spaces with nothing and store in a temp value
	str = str.replace( /(\s+)$/g, "" );

	// verify that the length of the field is not greater than the max or less than the min length	
	if ((field.value.length < min) || (field.value.length > max))
	{
		// alert the user of the error
		alert(fieldname + " must be between " + min + " and " + max + " characters long.");

		// put focus on the form field
		field.focus();
		return false;
		
	}
	// verify that the field does not just contain spaces
	else if ((field.value.length != 0) && ( str == ""))
	{
		// alert the user of the problem
		alert( fieldname + " contains only spaces. Please fill in correctly."  );

		// put focus on the form field
		field.focus();
		return false;
	}
	// no problems. return success
	else return true;
}

function Web_validateTextField(field, fieldname)
{
	var str = field.value;
	if ((str == null) || (str == ""))
	{
		// alert the user of the error
		alert("Please enter a " + fieldname + ".");

		// put focus on the form field
		field.focus();
		return false;
		
	}
	// no problems. return success
	else return true;
}

function Web_validateSelectField(fieldOne, fieldNameOne)
{
	var strValueOne		= fieldOne.options[fieldOne.selectedIndex].value;
	
	if ((0 == strValueOne.length))
	{
		alert("Please select a " + fieldNameOne + ".");
		fieldOne.focus();
		return false;
	} else return true;
}

function Web_validateEmail(field)
{
  var fullEmail = field.value;
  if (fullEmail == "") {
    alert("\nPlease enter your Internet e-mail address.")
    field.focus();
    return false;
  }
  if (fullEmail.indexOf (" ",0) == -1) {}
  else {
    alert("\nYour e-mail address cannot contain spaces.\n\nPlease re-enter your e-mail address.")
    field.select();
    field.focus();
    return false;
  }
  if (fullEmail.indexOf ("@",0) == -1 || fullEmail.indexOf (".",0) == -1) {
    alert("\nYour e-mail address requires that a \"@\" and a \".\" be used.\n\nPlease re-enter your e-mail address.")
    field.select();
    field.focus();
    return false;
  }
  else
    if (fullEmail.length < 8 || fullEmail.substring((fullEmail.length - 1),(fullEmail.length)) == "." ||  fullEmail.substring(0,1) == "@")
    {
    alert("\nYour e-mail address is invalid.\n\nPlease re-enter your e-mail address.")
    field.select();
    field.focus();
    return false;
    }
  else
    {
    return true;
    }

}
function Web_validateDateFormat(field, fieldname)
{
	var str = field.value;
	var strDateNum = "1" + field.value + "";
	var strDateInt = parseInt(strDateNum,10) + "";
	
	str = str.replace( /\//g, "" );

	if(field.value.length != 10 || isNaN(strDateInt)) {
		// alert the user of the error
		alert("Please enter " + fieldname + " in MM/DD/YYYY format.");

		// put focus on the form field
		field.focus();
		return false;
	
	}

	// no problems. return success
	else return true;
}
function Web_validateCreditCard(field,fieldname)
{
	var str = field.value;
	if ((str == null) || (str == ""))
	{
		// alert the user of the error
		alert("Please enter a credit card number.");
		// put focus on the form field
		field.focus();
		return false;
	}
	else if(str.indexOf(" ",0) >= 0) {
    	alert("\nYour credit card cannot contain spaces.\n\nPlease re-enter your credit card number.")
    	field.select();
    	field.focus();
    	return false;	
	}	
	// If okay
	else return true;
}
function Web_validateXOrSelect(fieldOne, fieldTwo, fieldNameOne, fieldNameTwo)
{
	var strValueOne		= fieldOne.options[fieldOne.selectedIndex].value;
	var strValueTwo		= fieldTwo.options[fieldTwo.selectedIndex].value;
	
	if ((0 == strValueOne.length) && (0 == strValueTwo.length))
	{
		alert("You must select either " + fieldNameOne + " or " + fieldNameTwo + ".");
		fieldOne.focus();
		return false;
	} else if ((0 != strValueOne.length) && (0 != strValueTwo.length))
	{
		alert("You must select either " + fieldNameOne + " or " + fieldNameTwo + ", but not both.");
		fieldOne.focus();
		return false;
	} else return true;
}

function Web_validateNonNullInt(field, fieldname)
{
	//can't be blank
	if (field.value == "") {
		alert("Please enter a " + fieldname + ".");
		//	Put focus on the errant form field
		field.focus();
		return false;	
	}
	//	This else, checks to see if characters instead of numbers have been
	//	inputted into the field
	else if (isNaN(parseInt("1" + field.value)))
	{
		//	Alert the user that non-integer values will not be tolerated
		alert("Please do not enter non-number values in " + fieldname + ".");
		//	Put focus on the errant form field
		field.focus();
		return false;
	}

	//	Just because a NaN wasn't returned in the previous else if doesn't mean
	//	that the input is an integer - this else uses a hack method to ensure that
	//	the value inputted is an integer.  The main thing that is being tested
	//	against is if the user enters a value such as "12faf" which will cause
	//	a DB error but pass the previous tests, since parseInt will just return
	//	the beginning int value.  Also, this will guard against floating point
	//	values being entered.  So please leave the "" at the end of the parsedInput
	//	& actualInput variables, for they are essential.

	else
	{
		var actualInput = ("1" + field.value) + "";
		var parsedInput = parseInt("1" + field.value) + "";

		if(actualInput.length != parsedInput.length)
		{
			//	Alert the user that non-integer values will not be tolerated
			alert("Please do not enter non-number values in " + fieldname + ".");
			//	Put focus on the errant form field
			field.focus();
			return false;
		}
	//	If the number is an integer, and truly blessed, it will survive and be passed on
	return true;
	}
}