//All scripts and code are copyright (2002) by Harbinger Corporation
var re = new Array(26);							//reg exps - in pairs
	re[0] = /([\~\!\#\^\*\|\<\>\"])/;			//name
	re[1] = /^[a-zA-Z][a-zA-Z\-\ \'\.]*[a-zA-Z]?$/;

	re[2] = /([\~\!\^\*\|\<\>\"])/;				//address
	re[3] = /^[a-zA-Z0-9][a-zA-Z0-9\-\ \'\.#]*[a-zA-Z0-9]?$/;

	re[4] = /[^0-9\-]/;					//telephone
	re[5] = /^\d{3}\-\d{3}-\d{4}$/;

	re[6] = /(@.*@)|([@\.\-\_][@\.\-\_])/;			//email
	re[7] = /^[a-zA-Z0-9][a-zA-Z0-9\-\.\_]*\@[a-zA-Z0-9\-\.\_]+\.([a-zA-Z]{2,3})$/;

	re[8] = /[^a-zA-Z0-9]/;					//password
	re[9] = /^.{8,16}$/;

	re[10] = /[\~\!\#\^\*\|\<\>\"]/;			//hint
	re[11] = /./;

	re[12] = /[^0-9\-]/;					//zip code
	re[13] = /^\d{5}(\-\d{4})?$/;
	
	re[14] = /[\d]{3,9}/;					//month
	re[15] = /^[1-9]{1,1}$|^[1][0-2]$/;

	re[16] = /[\d]{3,9}/;					//day
	re[17] = /^[1-9]{1,1}$|^[1-3][\d]$/;

	re[18] = /[^\d]/;					//year
	re[19] = /19[\d]{2,2}$|20[\d]{2,2}$/;

	re[20] = /[^\d]/;					//any whole number (no commas or decimals)
	re[21] = /^[\d][\d]*/;

	re[22] = /[^\d\.]/;					//any whole number or decimal
	re[23] = /^[\.\d][\.\d]*/;

	re[24] = /^\s+$/;					//anything except just blank spaces
	re[25] = /./;

	re[26] = /\..*\.|[^\d\.]/;				//any decimal or whole number (no commas)
	re[27] = /\d+/;
	
	re[28] = /[^\d\-\/]/;					//date
	re[29] = /^\d{1,2}[\/\-]\d{1,2}[\/\-]\d{4}$/;
	
	re[30] = /[^0-9a-zA-Z/]/;					//digits and letters only
	re[31] = /./;
	
var	anything = /.+/;

function irec(field,reqd,reidx,msg) {
	this.field = field;	//value entered in form
	this.reqd  = reqd;	//0 not reqd or 1 reqd
	this.reidx = reidx;	//index of first of reg exp pair
	this.msg   = msg;	//message to place in alert box
}
function checkfields(start,stop,rec) {
	for (recnum=start; recnum<=stop; recnum=recnum+1) {
			if (validfield(rec[recnum])==false) {return false;}
		}
	return true;
}
function validfield(input) {
	with (input) {
		if (anything.test(field.value)) {
			if (!re[reidx].test(field.value) && re[reidx+1].test(field.value)) {
				return true;
			}
			else {
				alert(msg);
				field.focus();
				field.select();
				return false;
			}
		}
		else if (reqd==1) {
			alert('Please be sure that there is an entry in each field');
			field.focus();
			field.select();
			return false;
		}
		else {return true;}
	}
	return true;
}
var toomanycaps = /[A-Z]{3}/;
var anycaps = /[A-Z]/;
var capflag =0;
function proper(name) {
	if (name.length == 0) {return name}
	if (toomanycaps.test(name) || !anycaps.test(name)){
		capflag++;

		words = name.split(/\s+/g); // split the name into an array of words
		for (i = 0 ; i < words.length ; i ++ ) {
			firstLetter = words[i].substring(0, 1).toUpperCase();
			restOfWord = words[i].substring(1, words[i].length).toLowerCase();
			words[i] = firstLetter + restOfWord; // re-assign it back to the array and move on
		}
		name = words.join(' '); // join it back together
	}
    return name;
}
