/***************************************************	

	fValidate
	Copyright (c) 2000-2003
	by Peter Bailey
	www.peterbailey.net/fValidate/

	fValidate.special.js

	Included Validators
	-------------------
	custom

	This file is only part of a larger validation
	library	and will not function autonomously.

	Created at a tab-spacing of four (4)

****************************************************/

fValidate.prototype.custom = function( flags, reverseTest )
{
	if ( this.typeMismatch( 'text' ) ) return;
	flags     = ( flags ) ? flags.replace( /[^gim]/ig ) : "";
	var regex = new RegExp( this.elem.getAttribute( this.config.pattern ), flags );
	if ( !regex.test( this.elem.value ) )
	{
		this.throwError( [this.elem.fName] );
	}	
}

fValidate.prototype.alnum2 = function( minLen, tCase, alphas, numbers, spaces, puncs )
{
	if ( this.typeMismatch( 'text' ) ) return;

	tCase = this.setArg( tCase, "a" );
	
	//alert( [minLen,tCase,numbers,spaces,puncs] );

	numbers = ( numbers == "true" || numbers == "1" );
	spaces = ( spaces == "true" || spaces == "1" );
	//alphas added by George Papdan
	//wanted a text field that accepts numbers with spaces in between
	alphas = ( alphas == "true" || alphas == "1" );

	//alert( [minLen,tCase,numbers,spaces,puncs] );
		
	var okChars = "",
		arrE	= ['None','Any','No','No','No','Any'];

	if ( minLen != '*' )
	{
		minLen =  parseInt( minLen, 10 );
		arrE[0] = minLen;
	} else {
		minLen = 0;
	}

	//Added alphas condition
	if (alphas == true)
	{
		switch( tCase.toUpperCase() )
		{
			case 'U':
				okChars += 'A-Z';
				arrE[1] =  'UPPER';
				break;
			case 'L':
				okChars += 'a-z';
				arrE[1] =  'lower';
				break;
			case 'C':
				okChars += 'A-Z][a-z';
				arrE[1] =  'Intial capital';
				minLen--;
				break;
			default:
				okChars += 'a-zA-Z';
				break;		
		}
	}

	
	if ( numbers == true )
	{
		okChars += '0-9';
		arrE[2] =  'Yes';
	}
	if ( spaces == true )
	{
		okChars += ' ';
		arrE[3] =  'Yes';
	}
	if ( puncs == "any" )
	{
		arrE[4]  = "Any";
	}
	else if ( puncs == "none" )
	{
		arrE[4] = "None";
	}
	else 
	{
		puncs = puncs.replace( /pipe/g, "|" );
		okChars += puncs;
		arrE[4] =  puncs; //.toPattern().replace( /\\/g, "" );
	}
	var length = ( minLen != "*" )?
		"{" + minLen + ",}":
		"+";
	var regex = ( puncs == "any" ) ?
		new RegExp( "^([" + okChars + "]|[^a-zA-Z0-9\\s])" + length + "$" ):
		new RegExp( "^[" + okChars + "]" + length + "$" );
	
	if ( !regex.test( this.elem.value ) )
	{
		this.throwError( [this.elem.value, this.elem.fName, arrE[0], arrE[1], arrE[2], arrE[3], arrE[4]] );
	}
}

//cc2 validator
//developed by George Papdan
//This is a simpler Credit Card validator as we don't want to ask for the type of credit card used
//so we can't used the 'cc' validator
//This is based on the numeric validator
//With the difference is that it has minLength set to 13, maxLength to 16
//and it allows for spaces in between
fValidate.prototype.cc2 = function()
{
	checkValue = this.elem.value.replace(/\s/g,"");
	regex = /^(\d){13,16}$/;
	if ( !regex.test( checkValue ) )
	{
		this.throwError( [this.elem.fName] );
	}
}


//	EOF
