function WebValidation()
{
	/* properties */

	/* methods */
	this.validateEmail 					= Web_validateEmail;
	this.validateTextField				= Web_validateTextField;
	this.validateSelectField			= Web_validateSelectField;
	this.validateTextFieldWithLimit		= Web_validateTextFieldWithLimit;
	this.validateDateFormat				= Web_validateDateFormat;
    this.validateCreditCard             = Web_validateCreditCard;
    this.validateXOrSelect				= Web_validateXOrSelect;
    this.validateAgreement				= Web_validateAgreement;
}

function Web_validateTextFieldWithLimit(field, fieldname, limit )
{
	//return false;
	
	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;
		
	}
	else{
		//check size
		var str = field.value;
		var len =  field.value.length;
		if(!(len <= limit)) {
			alert(fieldname + " must be less than " + limit + " characters long.");
			field.focus();
			return false;
		}
		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_validateAgreement(fieldOne, message)
{
	if(!fieldOne.checked) {
		alert(message);
		//fieldOne.focus();
		return false;
	} else return true;
}