﻿var validateForm	=	function( form ){
	var formIsValid	=	true;
	// clear any previous validation classes
	$(".invalidFieldWarning").remove();
	$(".requiredField").each( function( i ){
		$this	=	$(this);
		$this.removeClass( "invalidField" ); // in case previously flagged
		var thisValue	=	$.trim( $this.val() );
		var thisClass	=	$this.attr( "class" );
		var fieldIsValid	=	true;
		// different types of validation
		if( thisClass.indexOf( "email" ) != -1 ){
			fieldIsValid	=	/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/i.test( thisValue );
		} else {
			fieldIsValid	=	( thisValue != "" );
		}
		if( !fieldIsValid ){
			$this.addClass( "invalidField" );
			var $warning	=	$( '<span />' )
				.addClass( "invalidFieldWarning" )
				.text( $this.attr( "title" ) );
			$this.after( $warning );
			formIsValid	=	false;
		}
	});
	if( !formIsValid ){
		$( "button" ).attr( "disabled",false );
		$( ".invalidField:first" ).focus();
	}
	return formIsValid;
}