function formValidate( form) {
	var valid = true;
	var wasValid = true;
	$(".required", form).each( function() {
		$(this).removeClass( "invalid");
		$('label[for='+this.id+']').removeClass( "invalid");
		if (this.tagName == "SELECT" && this.value == 0) {
			$(this).addClass( "invalid");
			valid = false;
		} else if (this.tagName == "INPUT" && this.type == "password" && false == /^.{5,}$/.test( this.value)) {
			$(this).addClass( "invalid");
			valid = false;
		} else if (this.tagName == "INPUT" && this.type == "checkbox" && false == this.checked) {
			$('label[for='+this.id+']').addClass( "invalid");
			valid = false;
		} else if ($(this).attr( "class").indexOf( "email") >= 0 && false == /^[A-Za-z0-9._%-]+@[A-Za-z0-9._%-]+\.[A-Za-z0-9._%-]{2,4}$/.test( this.value)) {
			$(this).addClass( "invalid");
			valid = false;
		} else if (this.value == "") {
			$(this).addClass( "invalid");
			valid = false;
		}
		if (false == valid && wasValid) {
			this.focus();
			wasValid = valid;
		}
	});
	$(".date", form).each( function() {
		$(this).removeClass( "invalid");
		if (this.value != '' && false == /^\d{4}-\d{1,2}-\d{1,2}$/.test( this.value)) {
			$(this).addClass( "invalid");
			valid = false;
			if (wasValid) {
				this.focus();
				wasValid = valid;
			}
		}
	});
	return( valid);
}
function escapeVal( val) {
	return( val.replace( '"', '&quot;'));
}

function formatLoadingMsg( msg) {
	return( '<img src="/img/loading.gif" class="loading" alt="'+escapeVal( msg)+'" /> '+msg);
}

function viewValidate( form) {
	var result = formValidate( form);
	return( result);
}
$(document).ready( function() { 
	$('a.linkOut').each( function() { $(this).click( function() { window.open( this.href); return( false);}); }) 
});

