/*
	Validation Regular Expression Javascript Library
	from Java Web Developer program
	Created: Wed, July 24, 2002
	Last Modified: Thurs, Feb. 15, 2007

	Marlon A. Griffith
*/

// D.Goodman, 'The JavaScript Bible'
var undefined;

function isEmpty( str )
{
	try
	{
		if( str === null || str === undefined || str.length === 0 )
			return true;
		else
			return false;
	}
	catch(e)
	{
		alert("Error " + e.message + "\n" + str);
	}
}

function isBlank( blStr ){
	if( /[\s]/.test(blStr) ){
		return false;
	} else {
		return true;
	}
}

// has a blank character?
function hasBlank( s ){
	if( /[\s]/.test(s) ){
		return false;
	} else {
		return true;
	}
}

/* This method will report true representing a field without entry
 if the field holds a null or undefined value, has a string of zero
 length, or holds non visible characters such as white spaces or
 newline characters. It will also exit as soon as any of these
 criteria is not met.
 Marlon; Thurs., May 27, 2004.
 This function is incorrect. It really works like hasBlank().
*/
function noEntry( str ){
	try{
		if ( /[\s]/.test(str) ){
			return false;
		}
		return true;
	} catch(e) {
		alert("noEntry Error: " + e.message + "\n"+ str);
	}
}

//Testing that the field value is composed of Characters From 0 to 9
function isWhole( num ){
	var sNum = num.toString( );
	if( /[\D]/.test(sNum) ){
		return false;
	} else {
		return true;
	}
}

// is the field of alpha characters?
function isAlpha( letters ){
	var s = letters.toString( );
	if( /[^a-zA-Z]/.test(s) ){
		return false;
	} else {
		return true;
	}
}

// does the field contain only alphanumeric characters?
function isAlphaNumeric( alNum ){
	var sAlNum = alNum.toString( );
	if( /[\W]/.test( sAlNum ) ){
		return false;
	} else {
		return true;
	}
}

// does the field contain only numeric characters?
function isNumeric( digits ){
	var dig = digits.toString( );
	if( dig.search( /[\d]/ )==-1 ){
		return false;
	} else {
		return true;
	}
}

// ensure the return logic is true.
function hasEntry( str )
{
	if ( str === null || str === undefined || str.length === 0 )
		return false;
	else if ( /[\s]/.test(str) )
			return false;

	return true;
}

/* Are there any ASCII word characters? Non-word 
  characters - i.e. a new line or space etc. - doesn't count.
*/
function hasMyWords( str )
{
	// Make sure there is something in the paragraph area
	if( (str === null) || (str === undefined) || (str.length === 0) )
	{
		return false;
	}
	else
	{
		// words regular expression
		var words = /\w+/;
		// test for words
		var result = str.match(words);
		if( result === null )
		{
			return false;
		}
		else
		{
			return true;
		}
	}
}


// is the field of email characters?
function isEmail( emailRet )
{
	var sEmailRet = emailRet.toString( );
	if( /(\w+)@([\w])+.([\w])/.test(sEmailRet) )
		return true;
	else
		return false;
}

// is the field of telephone no. characters?
function isCanPhoneNo( telephone )
{
	var sTelephone = telephone.toString();
	if( sTelephone === null || sTelephone === undefined || sTelephone.length == 0 )
	{
		return false;
	}
	else
	{
		// Canadian telephone number pattern
		var pattern = /(([(][1-9][\d]{2}[)])|([1-9][\d]{2}[-.]))[\d]{3}[-.][\d]{4}( x[\d]{1,5})?/;
		if( pattern.test( sTelephone ) )
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}

// is the field of street address characters?
function isStreet( strAddr )
{
	var sStrAddr = strAddr.toString();
	if (sStrAddr === null || sStrAddr === undefined || sStrAddr.length == 0 )
	{
		return false;
	}
	else
	{
		if( /[^- .\'\w]/.test(sStrAddr) )
		{
			return false;
		}
		else
		{
			return true;
		}
	}
}

// is the field of city characters?
function isCity( cityFld )
{
	var sCityFld = cityFld.toString();
	if (sCityFld === null || sCityFld === undefined || sCityFld.length == 0 )
	{
		return false;
	}
	else
	{
		if( /[^- .\'a-zA-Z]/.test(sCityFld) )
		{
			return false;
		}
		else
		{
			return true;
		}
	}
}

// is the field of Canada's postal code characters?
function isCanPostCode( pstCdFld )
{
	var sPstCdFld = pstCdFld.toString();
	if (sPstCdFld === null || sPstCdFld === undefined || sPstCdFld.length == 0 )
	{
		return false;
	}
	else
	{
		if( /[\w][\d][\w] [\d][\w][\d]/.test( sPstCdFld ) )
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}

// is the field of British Date format?
function isBritDate( britDt ){
	var sbritDt = britDt.toString( );
	if (sbritDt == null || sbritDt === undefined ||
	        sbritDt.length == 0 ){
		return false;
	} else {
		if( /\d\d\/\w{3}\/\d{4}/.test(sbritDt) ){
			return true;
		} else {
			return false;
		}
	}
}
