function clsValidate()
{
	//Properties
	this.aryError = new Array();
	this.strValue="";
	
	//Methods
	this.trim = trim;
	this.CheckAlpha = CheckAlpha;
	this.CheckNumeric = CheckNumeric;
	this.CheckEmail = CheckEmail;
	this.CheckMax = CheckMax;
	this.CheckMin = CheckMin;
	this.CheckChars = CheckChars;

	this.GetError = GetError;
}


var aryError=new Array();

/*################################()###################################
Name: trim
Description: strips leading and trailing spaces from value (similar to Java trim method)
Input: string to be trimmed 
Output: trimmed string
#######################################################################*/
function trim(strValue) 
{

	/* Strip leading spaces from input */
	startposn = 0;
	
	while((strValue.charCodeAt(startposn) == 32) && (startposn < strValue.length)) 
		{startposn++;}

	if(startposn == strValue.length) 
		{value = '';} 
	else 
	{
		/* If anything left of string after stripping leading spaces strip trailing spaces as well */
		strValue = strValue.substring(startposn, strValue.length);
		endposn = (strValue.length) - 1;
		
		while(strValue.charCodeAt(endposn) == 32) 
			{endposn--;}
		
		strValue = strValue.substring(0, endposn + 1);
	}
	
	return(strValue);
}


/*################################()###################################
Name: CheckAlpha
Description: checks a string for alpha characters, 
			allows spaces in between chars
Input: 
			- strValue: string to be checked
			- strErrorMsg: message to display if an error occurs
#######################################################################*/
function CheckAlpha(strValue, strErrorMsg, blnAllowSpace)
{
	var intSrtPos = 0;
	var blnError = false;
	
	strValue = trim(strValue);
	
	if(strValue.length > 0)
	{
		if(strErrorMsg == null || strErrorMsg == '')
			{strErrorMsg = 'One of the form text fields contains non-alpha characters';}

		strValue = strValue.toLowerCase();
		
		if(blnAllowSpace == false)
		{
			while((strValue.charCodeAt(intSrtPos) > 96 && strValue.charCodeAt(intSrtPos) < 123) && (intSrtPos < strValue.length))
				{intSrtPos++;}
		}		
		else
		{
			while((strValue.charCodeAt(intSrtPos) > 96 && strValue.charCodeAt(intSrtPos) < 123 || strValue.charCodeAt(intSrtPos) == 32 || strValue.charCodeAt(intSrtPos) == 46) && (intSrtPos < strValue.length))
				{intSrtPos++;}
		}
		
		if(intSrtPos != strValue.length)
		{
			aryError[aryError.length + 1] = strErrorMsg;
			blnError = true;
		}
	}
	else
		{blnError = true;}
		
	return(blnError);
}



/*################################()###################################
Name: CheckNumeric
Description: checks a string for numeric characters

Input: 
			- strValue: string to be checked
			- strErrorMsg: message to display if an error occurs
#######################################################################*/
function CheckNumeric(strValue, strErrorMsg, blnAllowSpace)
{
	var intSrtPos = 0;
	var blnError = false;
	
	strValue = trim(strValue);
	
	if(strValue.length > 0)
	{
		if(strErrorMsg == null || strErrorMsg == '')
			{strErrorMsg = 'One of the form text fields contains non-numeric characters';}
		
		strValue = strValue.toLowerCase();
		
		if(blnAllowSpace == false)
		{
			while((strValue.charCodeAt(intSrtPos) > 47 && strValue.charCodeAt(intSrtPos) < 58) && (intSrtPos < strValue.length))
				{intSrtPos++;}
		}
		else
		{
			while((strValue.charCodeAt(intSrtPos) > 47 && strValue.charCodeAt(intSrtPos) < 58 || strValue.charCodeAt(intSrtPos) == 32 || strValue.charCodeAt(intSrtPos) == 46) && (intSrtPos < strValue.length))
				{intSrtPos++;}
		}
		
		if(intSrtPos != strValue.length)
		{
			aryError[aryError.length + 1] = strErrorMsg;
			blnError = true;
		}
	}
	else
		{blnError = true;}
		
	return(blnError);
}


/*################################()###################################
Name: CheckEmail
Description: checks a string if it is a valid email

Input: 
			- strValue: string to be checked
			- strErrorMsg: message to display if an error occurs
#######################################################################*/
function CheckEmail(strValue, strErrorMsg)
{
	var blnError = false;

	strValue = trim(strValue);
	
	if(strValue.length > 0)
	{
		if(strErrorMsg == null || strErrorMsg == '')
			{strErrorMsg = 'You have mistyped an email in one of the form fields';}
			
		if((strValue.indexOf('@', 1) == -1) || (strValue.indexOf('.', 2) == -1))
		{
			aryError[aryError.length + 1] = strErrorMsg;
			blnError = true;
		}
	}
	else
		{blnError = true;}
	
	return(blnError);
}


/*################################()###################################
Name: CheckMax
Description: checks the maximum amount of chars allowed

Input: 
			- strValue: string to be checked
			- strErrorMsg: message to display if an error occurs
			- intMaxNo: max length
#######################################################################*/
function CheckMax(strValue, strErrorMsg, intMaxNo)
{
	var blnError = false;
	
	strValue = trim(strValue);
	
	if(intMaxNo != '' || intMaxNo != null)
	{
		if(strErrorMsg == null || strErrorMsg == '')
			{strErrorMsg = 'You have exceeded the maximum character limit in one of the fields';}
			
		if(strValue.length > intMaxNo)
		{
			aryError[aryError.length + 1] = strErrorMsg;
			blnError = true;
		}
	
	}
	else
		{blnError = true;}
		
	return(blnError);
}


/*################################()###################################
Name: CheckMin
Description: checks the minimum amount of chars allowed

Input: 
			- strValue: string to be checked
			- strErrorMsg: message to display if an error occurs
			- intMinNo: min length
#######################################################################*/
function CheckMin(strValue, strErrorMsg, intMinNo)
{
	var blnError = false;
	
	strValue = trim(strValue);
	
	if(intMinNo != '' || intMinNo != null)
	{
		if(strErrorMsg == null || strErrorMsg == '')
			{strErrorMsg = 'One of the fields does not satisfy the minimum value required';}

		if(strValue.length < parseInt(intMinNo))
		{
			aryError[aryError.length + 1] = strErrorMsg;
			blnError = true;
		}
	
	}
	else
		{blnError = true;}
		
	return(blnError);
}



/*################################()###################################
Name: CheckChars
Description: checks a string for particular characters

Input: 
			- strValue: string to be checked
			- strErrorMsg: message to display if an error occurs
			- aryChars: an array of valid chars to look for
#######################################################################*/
function CheckChars(strValue, strErrorMsg, aryChars)
{
	var blnError = false;
	var intSrtPos = 0;
	var blnFound = false;
	var i = 0;
	
	strValue = trim(strValue);
	
	if(strValue.length > 0 || aryChars == '' || aryChars == null || typeof(aryChars) != 'object')
	{
		while((intSrtPos < strValue.length) && (blnError == false))
		{
			blnFound = false;
			i = 0;
			
			while((i < aryChars.length) && (blnFound == false))
			{
				if(strValue.charAt(intSrtPos) == aryChars[i])
					{blnFound = true;}
				else
					{blnFound = false;}

				i++;
			}
			
			if(blnFound == false)
			{
				aryError[aryError.length + 1] = strErrorMsg;
				blnError = true;
			}
			
			intSrtPos++;
		}	
	}
	else
		{blnError = true;}

	return(blnError);
}


/*################################()###################################
Name: GetError
Description: displays all the encountered errors
#######################################################################*/
function GetError()
{
	var blnReturn = false;
	
	if(aryError.length > 0)
	{
		var strErrorMsg = '===========================================================\n' +
						  '\t\tError Module Report\n' +
						  '===========================================================\n' +						  
						  '\nYour request has been declined due to the following errors:';
		var strErrors = '';

		for(var i = 1, z = 1; i < aryError.length; i+=2, z++)
			{strErrors = strErrors + '\n\t' + z + ') ' + aryError[i];}
		
		alert(strErrorMsg + '\n' + strErrors);
	}
	else
		{blnReturn = true;}

	aryError=new Array();	
	return(blnReturn);

}
/*################################()###################################
Name: CheckShortDate
Description: checks a string if it is a valid 'Short Date' eg. "12/12/1999"
			 the year can be either 2 or 4 characters.

Input: 
			- strValue: string to be checked
			- strErrorMsg: message to display if an error occurs
#######################################################################*/
function CheckShortDate(strValue)
{
	var blnError = false;

	strValue = trim(strValue);
	
	if(strValue.length > 0)
	{
		if((strValue.charAt(2) != '/') || (strValue.charAt(5) != '/'))
		{
		
			blnError = true;
		}
		if(strValue.length > 10)
		{
			
			blnError = true;
		}
	}
	else
		{
			blnError = true;
		}
	
	return(blnError);
}