$.fn.clearForm = function() {
  return this.each(function() {
	var type = this.type, tag = this.tagName.toLowerCase();
	if (tag == 'form')
	  return $(':input',this).clearForm();
	if (type == 'text' || type == 'password' || tag == 'textarea')
	  this.value = '';
	else if (type == 'checkbox' || type == 'radio')
	  this.checked = false;
	else if (tag == 'select')
	  this.selectedIndex = -1;
  });
};

$(document).ready(function(){
 
 var err_name="<span style='color:#FF0000'>Please enter your name</span>";
 var err_email="<span style='color:#FF0000'>Please enter your email</span>";
 var err_first_name="<span style='color:#FF0000'>Please enter your Message</span>";
	
	$("#send").click(function () {
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var email = document.getElementById('user_email');
		
		if (!filter.test(email.value)) 
		{
			$('.email-missing').html(err_email);
			$('.email-missing').show();
		} else {$('.email-missing').hide();}
		
		if (document.cform.user_nom .value == "")
		{$('.name-missing').html(err_name);
			$('.name-missing').show();
		} else {$('.name-missing').hide();}
		
		
		if (document.cform.message.value == "")
		{$('.mes-missing').html(err_first_name);
			$('.mes-missing').show();
		} else {$('.mes-missing').hide();}	

		if (document.cform.recaptcha_response_field.value == "")
		{
		$('.cap-missing').html("Please enter code in image ");
			$('.cap-missing').show();
		}
		 else {$('.cap-missing').hide();}	

		
		
		
		if ((document.cform.user_nom.value == "") || (!filter.test(email.value))||(document.cform.message.value == "")||(document.cform.recaptcha_response_field.value == "")){
			return false;
		}

			if ((document.cform.user_nom.value != "") && (filter.test(email.value)))
				{
	
					var param = $('#firstform :input').serialize();

		//alert(param);
			$.post("send.php", param, function(data)
			{
					//alert(data)
							if(data=="z")
							{
								$(".caps-missing").html("Please enter code in image");
							}else
							{
								$('.caps-missing').hide();
								$("#cap").html(data);
							}
				
			});				
		
					
				}
});
});
 
 

 
 
 

	


