aVF = {};
aV = {
	init: $(document).ready( function(){
		$('.autoValid').each( function(i,e){
			var id = $(this).attr('id');
			aVF[id] = {};
			$(this).find(':radio, :text, :password, :checkbox, select, textarea').each( function(it, ee){
					var n = $(this).attr('name');
					aVF[id][n] = $(this);
				});
		});
	}),
	/**
	 * 
	 * @param {Object} id
	 * @param {Object} p
	 */
	insertError: function(id,p){
		//This function inserts a single error into a specific container determined by the parent node
		//'container' arg must be a jQuery obj ( $('parentElement') ).

		if(p){
			var errPane = p.find('.errorHolder');
		}else{
			errPane = $('.errorHolder');
		}

		// If the value passed into this function contains anything besides a 
		// a digit, it assumes it's being passed an error string directly from the
		// backend
		if(/\D/.test(id)){
			errPane.append("<div class='errorPoint'>"+id+"</div>");
		}else{
			errPane.append("<div class='errorPoint'>"+mG.err[id]+"</div>");
		}

		errPane.show().find(".errorPoint").show();
		//location
	},
	/**
	 * 
	 * @param {Object} a
	 * 
	 * If you supplyan onject, vals will be removed, otherwise only error stated will be removed
	 */
	resetForm: function(a){
		if(a){
			$.each(a, function(i,e){
			$(this).val('').removeClass('ui-state-error');
		});
		}else{
			$('input, textarea').removeClass('ui-state-error');
		}
		$(".errorHolder").html("").hide();
	},
	checkLength: function(o,n,min,max,p){
		if(o.val().length > max || o.val().length < min){
			o.addClass('ui-state-error');
			aV.insertError('Length of '+n+' must be between '+min+' and '+max+'.',p);
			return false;
		}else{
			return true;
		}
	},
	checkRegex: function(o,regexp,n,p){
		if ( !( regexp.test( o.val() ) ) ) {
			o.addClass('ui-state-error');
			aV.insertError(n,p);
			return false;
		} else {
			return true;
		}
	}
}
