function form_validator( theForm, required ){

	errors = new Array();
	message = "";

	for( x = 0; x < required.length; x++ )
	{
		element = theForm.elements[required[x]];
		if( element != undefined )
		{
			switch( element.type )
			{
				case "text":
				case "Textarea":
					if( element.value == "" ){
						errors[errors.length] = required[x];
					}
					break;

				case "Checkbox":
				case "Radio":
					found = false;
					for( y = 0; y < element.length; y++ )
					{
						if( element[y].checked ){
							found = true;
							break;
						}
					}

					if( !found ){
						errors[errors.length] == required[x];
					}
					break;

				case "select-one":
					if( element.selectedIndex == 0 ){
						errors[errors.length] = required[x];
					}
					break;

				case "password":
					if( element.value == "" ){
						errors[errors.length] = required[x];
					}
					break;

			}
		}
	}


	if( errors.length > 0 )
	{
		message = "The form is incomplete. ";
		if( errors.length > 1 )
		{
			missing = errors.join( ", " ).replace(/_/g," ");
			message += missing + " are missing.";
		}
		else{
			message += errors[0] + " is missing.";
		}

	}

	if( theForm.password2 != undefined ){
		if( theForm.password.value != theForm.password2.value )
		{
			if( errors.length > 0 )
				message += "\nAdditionally, your";
			else
				message += "\nYour ";
			message += " passwords do not match.";
		}
	}


	return message;
}



function autoAdvance( me, event, limit, next_element )
{
	if( event.keyCode < 48 || event.keyCode > 59 )
		return;

	if( me.value.length == limit )
	{
		document.enrollform[next_element].focus();
		document.enrollform[next_element].select();
	}
}

function pad_zeroes (digits, n) {  // n is a string or number
	if(n.constructor == Number) n = n.toString();

	while(n.length < digits) n = "0" + n;

	return n;
}

function pad_spaces (digits, n) { // n is a string or number
	if(n.constructor == Number) n = n.toString();

	while(n.length < digits) n = " " + n;

	return n;
}

function strip_numbers( inString, whichEnd )
{
	stripped = inString;
	if( whichEnd == "end" || whichEnd =="both" )
	{
		lastChar = stripped.charCodeAt( stripped.length-1 );
		while(  lastChar > 47 && lastChar < 58 ){
			stripped = stripped.substring(0,stripped.length-1);
			lastChar = stripped.charCodeAt( stripped.length-1 );
		}
	}
	if( whichEnd == "start" || whichEnd =="both" )
	{
		lastChar = stripped.charCodeAt( 0 );
		while(  lastChar > 47 && lastChar < 58 ){
			stripped = stripped.substring(1);
			lastChar = stripped.charCodeAt(0);
		}
	}

	return stripped;
}

function remove_element( theElement, theObject ){
	newObject = new Object();
	for( key in theObject){
		debug( "   " + key );
		if( key != theElement ){
			newObject[key] = theObject[key];
		}
	}

	return newObject;
}

function dump_array( theArray ){
	for( key in theArray )
		debugWin.document.write( "<div style='padding-left:15px'>" + key + " --> " + theArray[key] + "</div>" );
}

function debug( string ){
	if( debugOn && debugWin && !debugWin.closed )
	{
		debugWin.document.write( "<pre style='margin:2px'>" + string + "</pre>\n" );
	}
}