validation = {
	init : function(vrules, formId) {
		$(formId).RSV(
		{
			//displayType: "display-html",
			//errorTextIntro: "Please correct the following errors:",
			//errorFieldClass: "errorfield",			
			onCompleteHandler: validation.submitForm,
			customErrorHandler: validation.customErrorDisplay,
			rules : vrules
			  
		});
	},
	
	customErrorDisplay : function(f, errorInfo) 
	{
		$(".error").remove();
		// disable or remove all error stuff by default
		if(errorInfo.length > 0){
			$('#article-email').prepend('<div class="error"><p class="instruct-error">Please correct the following errors</p></div>');
		}
		
		for (var i=0; i<errorInfo.length; i++)
		{
			$(".error").append('<p class="instruct-error">'+errorInfo[i][1]+'</p>');	
		}
		
		if (errorInfo.length == 0) 
		{
			return true;
		}
		else
		{
			
			return false;
		}
	},
	
	submitForm : function() {
		$(formId).submit();
	}
}

$(document).ready(function() {

	var vrules = [
				"required,recipientemail,Enter an email address for the recipient",
				"valid_email,recipientemail,Enter a valid email address for the recipient",		
				"required,youremail,Enter an email address for the sender",
				"valid_email,youremail,Enter a valid email address for the sender",		
				"required,name,Enter your name",
				"length<1001,message,The message must be no longer than 1000 characters"
				];
	
	validation.init(vrules, "#article-email");

});
