/*
File:	ValidateFunctions.js
Author: Andrew Ma
Date:	August 10, 2004

The functions contained within this file uses
Regular Expression patterns to validate various
types of strings.

CheckEmail		- Validates if the string is a valid email address
CheckPostal		- Validates if the string is a valid Canadian Postal Code
CheckPhone		- Validates if the string is a valid phone number (XXX-XXX-XXXX)
CheckDate		- Validates if the string is a valid date (MM/DD/YY)
CheckTimeEnglish- Validates if the string is a valid time (12:00am)
CheckTimeFrench	- Validates if the string is a valid time (24:00)
*/

/*
Function: CheckEmail
Input:	String - Email address to validate
Output: Boolen - Result of the validation
Method:	Applies Regular Expression to validate
*/

function CheckEmail(strEmail)
{
	var strValidateEmail;
	strValidateEmail = strEmail;

	if (strValidateEmail.search(/^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$/) == -1) {
		return false;
	}
	else {
		return true;
	}
}

/*
Funciton: CheckPostal
Input:	String - Postal Code to validate
Output: Boolen - Result of the validation
Method:	Applies Regular Expression to validate
*/
function CheckPostal(strPostal)
{
	var strValidatePostal;
	strValidatePostal = strPostal;

	if (strValidatePostal.search(/[A-Za-z]\d[A-Za-z].\d[A-Za-z]\d|[A-Za-z]\d[A-Za-z]\d[A-Za-z]\d/) == -1) {
		return false;
	}
	else {
		return true;
	}
}

/*
Funciton: CheckPhone
Input:	String - Number to validate
Output: Boolen - Result of the validation
Method:	Applies Regular Expression to validate
*/
function CheckPhone(strDate)
{
	var strValidateDate;
	strValidateDate = strDate;

	if (strValidateDate.search(/^([0-1]([\s-./\\])?)?(\(?[2-9]\d{2}\)?|[2-9]\d{3})([\s-./\\])?(\d{3}([\s-./\\])?\d{4}|[a-zA-Z0-9]{7})$/) == -1) {
		return false;
	}
	else {
		return true;
	}
}

/*
Funciton: CheckDate
Input:	String - Date to validate
Output: Boolen - Result of the validation
Method:	Applies Regular Expression to validate
*/
function CheckDate(strDate)
{
	var strValidateDate;
	strValidateDate = strDate;

	if (strValidateDate.search(/^(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/) == -1) {
		return false;
	}
	else {
		return true;
	}
}

/*
Funciton: CheckTimeEnglish
Input:	String - Time to validate in 12:00 AM/PM format
Output: Boolen - Result of the validation
Method:	Applies Regular Expression to validate
*/
function CheckTimeEnglish(strTime)
{
	var strValidateTime;
	strValidateTime = strTime;

	if (strValidateDate.search(/^ *(1[0-2]|[1-9]):[0-5][0-9] *(a|p|A|P)(m|M) *$/) == -1) {
		return false;
	}
	else {
		return true;
	}
}

/*
Funciton: CheckTimeFrench
Input:	String - Time to validate in 24:00 format
Output: Boolen - Result of the validation
Method:	Applies Regular Expression to validate
*/
function CheckTimeFrench(strTime)
{
	var strValidateTime;
	strValidateTime = strTime;

	if (strValidateDate.search(/^([0-1]?[0-9]|[2][0-3]):([0-5][0-9])$/) == -1) {
		return false;
	}
	else {
		return true;
	}
}

