function clearHelpers(whichFld){
	switch (whichFld.value) {
		case 'MM':
		case 'DD':
		case 'YYYY':
			whichFld.value="";
			break;
	}
	return true;
}

function autotab(original,destination){
	if (original.getAttribute && original.value.length==original.getAttribute("maxlength"))  destination.focus();
}

function validateBirthday(){
	//jsvalidator_form2_bdyr
	// ^\d{1,2}\/\d{1,2}\/\d{4}$
	var tmp, validBirthdate;
	var DateRegExp =  /^\d{1,2}\-\d{1,2}\-\d{4}$/;
	var rc=false;
	with (document.form2){
		if (bdyr.value != "YYYY" ) {
			theyear = parseInt(bdyr.value);
			if ((theyear < 1863) || (theyear > 2007)) {
			 	rc = showDateError(false);
				return false;
			}
			tmp = bdmon.value + '-' +  bdday.value + '-' +  bdyr.value;
			//alert(tmp)
			validBirthdate = true;
			if (!DateRegExp.test(tmp)) {
				validBirthdate = false;
			} else {
				birthdate.value = tmp;
			}
			
			rc = showDateError(validBirthdate);
		}
	}
	return rc;
}



function validateEmails(){
	var e1Flag = true;
	var e2Flag = true;
	var emailMatch = true;
	var rc=false;
	var EmailRegExp =  /^([a-zA-Z0-9_\.\-])+(\+[a-zA-Z0-9]+)*\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	with (document.form2){
		e1=email.value;
		e2=email2.value;
		e1Flag = EmailRegExp.test(e1);
		e2Flag = EmailRegExp.test(e2);
		showErrorMsg('email_error', e1Flag, '<br/> A valid email address is required.');
		showErrorMsg('email2_error', e2Flag, '<br/> A valid email address is required.');
		
		if (e1 != e2) emailMatch = false;

		if (e1Flag && e2Flag) showErrorMsg('email2_error', emailMatch, '<br>Both E-mail addresses must match');
		
		if (e1Flag && e2Flag && emailMatch ) rc=true;
	}
	return rc;
}

function showErrorMsg(efld, eFlag, eMsg){
	var ezone = $(efld);

	if (eFlag) {
		ezone.update(' ');
		ezone.hide();
		rc=true;	
	} else {
		ezone.update(eMsg);
		ezone.show();
		new Effect.Opacity(ezone, {to:1.0, duration: .5 });
		rc = false;
	}
	return rc;
}

function showDateError(eFlag){
	var bderror = $('jsvalidator_form2_bdyr');
	if (eFlag) {
		bderror.innerHTML = ' ';
		bderror.hide();
		rc=true;	
	} else {
		bderror.innerHTML = '<br>A valid birth date is required';
		bderror.show();
		new Effect.Opacity(bderror, {to:1.0, duration: .5 });
		rc = false;
	}
	return rc;
}

function getAge() {
	with (document.form2){
			
		var bday=parseInt(bdday.value);
		var bmo=(parseInt(bdmon.value)-1);
		var byr=parseInt(bdyr.value);
		var byr;
		var age;
		var now = new Date();
		
		tday=now.getDate();
		tmo=(now.getMonth());
		tyr=(now.getFullYear());
		
		if((tmo > bmo)||(tmo==bmo & tday>=bday)) {
			age=byr
		} else {
			age=byr+1
		}
		return (tyr-age);
	}
}

function countWords(whichFld, maxWords, msg){
	var numWords=0;
	numWords= whichFld.value.split(' ').length;
	if (numWords > maxWords) {
		whichFld.value = whichFld.value.substring(0, whichFld.value.length-1);
		alert(msg);
	}
}