$(function(){
   $("#btn_order").validateForm();
   $(".feedback").validateForm();
});
// проверяются поля validate_item
// only_num - тольуо цифры
// email  -  только e-mail
jQuery.fn.validateForm = function() { 

    var obj = this;
    var marker;

	var show_error = function(obj_item) {
	
		 $(obj_item).addClass("validate_error");
		 $(".error[rel="+$(obj_item).attr("rel")+"]").fadeIn();
         marker = false;
	} 			
	
	var hide_error = function(obj_item) {
	
		$(obj_item).removeClass("validate_error");
	   	$(".error[rel="+$(obj_item).attr("rel")+"]").hide();
	} 			
	
	// validate item number
	this.find(".validate_item.only_num").bind("keypress",function(event) { 
		  
		  return (event.which >= 48 && event.which <= 57)? true: false;
				
	}); 
			
    var checked_form = function() {
  
 
			// validate oll item
			$(obj).find(".validate_item").each(function() { 
			
				  (this.value+"" == "") ? show_error(this) : hide_error(this);		  
			  
			}); 
 

		 	// validate item email
			$(obj).find(".validate_item.email").each(function(event) { 	      
			 	
				str = $(this).attr("value"); 
			   
				re = new RegExp("\\S+@\\S+\\.\\S+");
				result_mail = re.exec(str);

				(result_mail == null) ? show_error(this) : hide_error(this);	
      
			}); 
 
		 return marker;
		 
    };			
				 
    this.find("input[type=submit]").click(function(){
		marker = true;
		return checked_form();
		
	});
   
  
};
