function WebValidation()
{
	/* properties */

	/* methods */
	this.validateEmail 					= Web_validateEmail;
	this.validateTextField				= Web_validateTextField;
	this.validateHiddenField			= Web_validateHiddenField;
	this.validateSelectField			= Web_validateSelectField;
	this.validateTextFieldWithLimit		= Web_validateTextFieldWithLimit;
	this.validateDateFormat				= Web_validateDateFormat;
    this.validateCreditCard             = Web_validateCreditCard;
    this.validateXOrSelect				= Web_validateXOrSelect;
	this.validateCheckbox				= Web_validateCheckbox;
	this.validateAgreement				= Web_validateAgreement;
	this.validateOptionalDateFormat		= Web_validateOptionalDateFormat;
	this.validateOrTextField			= Web_validateOrTextField;
	this.validateOptionalNumber			= Web_validateOptionalNumber;
	this.validateRadio					= Web_validateRadio;
}

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_validateHiddenField(field, fieldname)
{
	var str = field.value;
	if ((str == null) || (str == ""))
	{
		// alert the user of the error
		alert("Please enter a " + fieldname + ".");
		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_validateOptionalDateFormat(field, fieldname)
{
	var str = field.value;
	if(str == null || str == "") {
		return true;
	}
	else {
		return this.validateDateFormat(field, fieldname);	
	}
}

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_validateOrTextField(fieldOne, fieldTwo, fieldNameOne, fieldNameTwo)
{
	var strValueOne		= fieldOne.value;
	var strValueTwo		= fieldTwo.value;
	
	if ((strValueOne == null || strValueOne == "") && (strValueTwo == null || strValueTwo == "")) 
	{
		alert("Please enter either " + fieldNameOne + " or " + fieldNameTwo + " or both.");
		fieldOne.focus();
		return false;
	} else return true;
}
function Web_validateCheckbox(fieldOne, fieldNameOne)
{
	var count = fieldOne.length;
	var checked = false;
	for(var i = 0; i < count; i++) {
		if(fieldOne[i].checked) {
			checked = true;
			break;
		}
	}
	if(!checked) {
		alert("Please select a " + fieldNameOne + ".");
		//fieldOne.focus();
		return false;
	} else return true;
}
function Web_validateRadio(field, fieldName)
{
	var count = field.length;
	var checked = false;
	for(var i = 0; i < count; i++) {
		if(field[i].checked) {
			checked = true;
			break;
		}
	}
	if(!checked) {
		alert("Please select a " + fieldName + ".");
		//fieldOne.focus();
		return false;
	} else return true;
}
function Web_validateAgreement(fieldOne, message)
{
	if(!fieldOne.checked) {
		alert(message);
		//fieldOne.focus();
		return false;
	} else return true;
}
function Web_validateOptionalNumber(field, fieldname)
{
	var str = field.value;
	if ((str == null) || (str == ""))	{
		return true;
	}
	else {
		if(isNaN(str)) {
			// alert the user of the error
			alert("Please enter " + fieldname + " as a number.");
	
			// put focus on the form field
			field.focus();
			return false;
		}
		else {
			return true;
		}
	}
}