function ErrorCheck()
{
	
	this.isEmpty = function(object)
	{
	 
	  if($(object).val()=="")
	   {		
			
			
			//this.errMessage = this.errMessage+ "<li>"+"The "+userFldName+" is blank. Please make sure this field is filled in."+"</li>"
			return "Please, enter your "+$(object).attr("displayText")+".";
	   	
	   }
	   else 
	   {
			return "";
		
	   }
	} 
	// invalid phone number error
	this.checkPhone = function(value)
	{
			var filter = /\(?\d{3}\)?([-\/\.])\d{3}\1\d{4}/;
			var re = new RegExp(filter);
			if (re.test(value))
			{
				return "";
			}
			else{
				return "Invalid Phone# ex:(555-555-5555).";
			}
	
	}
    this.isEmail = function(value)
	{   
			var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			var re = new RegExp(filter);
			if (re.test(value.toString()))
			{	
				return "";
	
			}
			else{
				return "Invalid Email ex:(you@domain.com)";
			}
	}
	this.isInteger = function(value)
	{
		var filter = /^\d+$/;
		var re = new RegExp(filter);
		if (re.test(object.value)){
			object.style.backgroundColor = this.BGColor;
		}
		else{
			object.style.backgroundColor = this.errorBGColor;
			this.errMessage = this.errMessage+ "<li>The "+userFldName+" you entered is not a numeric value.</li>";
		    this.noErrors =  false;
		}
	}
	this.validVIN = function(value)
	{
	    var VIN = object.value.toString();
	    if(VIN.length==17)
		{
			object.style.backgroundColor = this.BGColor;
		}
		else
		{
			object.style.backgroundColor = this.errorBGColor;
			this.errMessage = this.errMessage+ "<li>Invalid VIN Number.</li>";
		    this.noErrors =  false;
		}
	}
	this.isMatch = function(object1,object2,userFldName)
	{
		
		if(object1.value==object2.value){
			object1.style.backgroundColor = this.BGColor;
			object2.style.backgroundColor = this.BGColor;
		}
		else{	
			object1.style.backgroundColor = this.errorBGColor;
			object2.style.backgroundColor = this.errorBGColor;
			this.errMessage = this.errMessage.toString()+ "<li>The two "+userFldName.toString()+" you entered have different values. Please check the fields and make sure they both match.</li>";
		    this.noErrors =  false;
		}
		
	
	}
	this.display = function(){
	
		if(this.errMessage!="" && this.noErrors==false)
		{
			this.div.innerHTML = "<ol style='list-style-type:none;'>"+this.errMessage.toString()+"</ol>";
			this.div.style.backgroundColor = this.BGColor.toString();
			this.div.style.borderStyle="dotted";
		}
	}
	this.isDate = function(value){
			  var RegExPattern = /^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/;
				var errorMessage = 'Please enter valid date as month, day, and four digit year.\nYou may use a slash, hyphen or period to separate the values.\nThe date must be a real date. 2-30-2000 would not be accepted.\nFormay mm/dd/yyyy.';
				if ((fld.value.match(RegExPattern)) && (fld.value!='')) {
					
				} else {
					 this.noErrors =  false;
					 this.errMessage = this.errMessage+ "<li>Invalid Date. Valid Dates <i>Example: (01/01/2008,03/28/2008)</li></i>";
				} 
	}
}// JavaScript Document

function formCheck(formLink,errorTag)
{
var theres_no_errors = true;
			$(formLink).each(function (){
					var error = new ErrorCheck();
					var test = error.isEmpty($(this).val());
					var errors = $(this).attr("error");
					if(errors!=undefined)
					{
							
							var errorsToCheck = errors.split( "," );
							for(var i = 0;i<errorsToCheck.length ;i++)
  							{								
							      var errorMessage = "";
								  var errorType = errorsToCheck[i];
								 switch(errorType)
								  {
								  case "empty":
								   		errorMessage =  error.isEmpty(this);
								 		break;
								   case "phone":
								   		errorMessage = error.checkPhone($(this).val())
								    	break;
								   case "email":
									    errorMessage = error.isEmail($(this).val())
									   break;
							       }
								   if(errorMessage!="")
								    break;
							 }

								  
								if(errorMessage!=""){
									if(errorTag=="span")
									{
									$(this).next().html("<strong style=color:#a10633>"+errorMessage+"</strong>");
									$(this).css("background-color","#B6B676");
									$(this).next().fadeIn();
									theres_no_errors = false;
									}
									else{
										$(this).val(errorMessage);
										$(this).css("background-color","#ff6600");
										theres_no_errors = false;
									   		
									}
								}
								
							
				    }
			});
		    return theres_no_errors;	
	
	
	
}