//	fValidate.controls.js		
//-	Included Validators
//	select
//	selectm
//	selecti
//	checkbox
//	radio
//	file
fValidate.prototype.select = function()
{
	if ( this.typeMismatch( 's1' ) ) return;
	if ( this.elem.selectedIndex == 0 )
	{
		this.throwError( 'Please select a valid option for ' + this.elem.fName );
	}
}

fValidate.prototype.selectm = function( minS, maxS )
{
	if ( this.typeMismatch( 'sm' ) ) return;
	var count = 0;
	if ( maxS == 999 || maxS == '*' ) maxS = this.elem.length;
	for ( var opt, i = 0; ( opt = this.elem.options[i] ); i++ )
		if ( opt.selected ) count++;

	if ( count < minS || count > maxS )
	{
		this.throwError( 'Please select between ' + minS + ' and ' + maxS + ' options for ' + this.elem.fName + '.\nYou currently have ' + count + ' selected' );
	}
}

fValidate.prototype.selecti = function( indexes )
{
	if ( typeMismatch( 's1' ) ) return;

	indexes = indexes.split( "," );
	var selectOK = true;

	for ( var i = 0; i < indexes.length; i++ )
	{
		if ( this.elem.selectedIndex == indexes[i] )
		{
			selectOK = false;
			break;
		}
	}
	if ( !selectOK )
	{
		this.throwError( "Please select a valid options for " + this.elem.fName );
	}
}

fValidate.prototype.checkbox = function( minC, maxC )
{
	if ( this.typeMismatch( 'cb' ) ) return;
	if ( this.elem == this.form.elements[this.elem.name] && !this.elem.checked )
	{
		this.throwError( "Please check " + this.elem.fName + " before continuing" );
	}
	else
	{
		this.elem = this.form.elements[this.elem.name];
		var len   = this.elem.length;
		var count = 0;
		
		if ( maxC == 999 || maxC == '*' )
		{
			maxC == len;
		}
		var i = len;
		while( i-- > 0 )
		{
			if ( this.elem[i].checked )
			{
				count++;
			}
		}
		if ( count < minC || count > maxC )
		{
			this.throwError( 'Please select between ' + minC + ' and ' + maxC + ' options for ' + this.elem[0].fName + '.\nYou currently have ' + count + ' selected' );
		}			
	}
}

fValidate.prototype.radio = function()
{
	if ( this.typeMismatch( 'rg' ) ) return;
	this.elem = this.form.elements[this.elem.name];
	
	for ( var i = 0; i < this.elem.length; i++ )
	{
		if ( this.elem.item( i ).checked )
		{
			return;
		}
	}
	this.throwError( 'Please select an option for ' + this.elem[0].fName );
}

fValidate.prototype.file = function( extensions, cSens )
{
	if ( this.typeMismatch( 'file' ) ) return;
	cSens = ( cSens ) ? "" : "i";
	var regex = new RegExp( "^.+\\.(" + extensions.replace( /,/g, "|" ) + ")$", cSens );
	if ( ! regex.test( this.elem.value ) )
	{
		this.throwError( "The file must be one of the following types:\n" + extensions.replace( /,/g, "\n" ) + "\nNote: File extention may be case-sensitive" );
	}
}

//	EOF