$(document).ready(function() { 

	 $('#Send').click(function() {  

			var fname 			= $("#name").val();

			

			var emailReg 		= /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

			var emailaddressVal = $("#email").val();

			var phone			= $("#phone").val();

			var message			= $("#message").val();

			var thecode			= $("#code").val();

			$("#form1").unbind('submit');

			if(fname == '') {

				$('#error_div').text("You forgot to enter Your Name").show().fadeOut(4000);

				$("input#name").focus();

				return false

			}

			

			if(emailaddressVal == '') {

				$('#error_div').text("You forgot to enter Your Email Address").show().fadeOut(4000);

				$("input#email").focus();

				return false

			}

			if(!emailReg.test(emailaddressVal)) {

				$('#error_div').text("Your email address is wrong").show().fadeOut(4000);

				$("input#email").focus();

				return false

			 

			}

			if(phone == '') {

				$('#error_div').text("You forgot to enter your phone number").show().fadeOut(4000);

				$("input#phone").focus();

				return false

			}

			if(message == '') {

				$('#error_div').text("You forgot to enter your message").show().fadeOut(4000);

				$("input#message").focus();

				return false

			}if(thecode == '') {

				$('#error_div').text("You forgot to enter the code").show().fadeOut(4000);

				$("input#code").focus();

				return false

			}else{

				$.get("post.php?code="+thecode, function(data){

					//alert(data);

					if(data == 0 || data != 1){

						$('#error_div').text("You are entered invalid code").show().fadeOut(4000);

						$("input#code").focus();

						return false	

					}
					else 
					{ 
						$("#form1").submit();
					}

				})	

			}return false;


		});

	 // refresh captcha

	 $('img#refresh').click(function() {  

		change_captcha();

	 });

	 function change_captcha()

	 {

	 	document.getElementById('captcha').src="get_captcha.php?rnd=" + Math.random();

	 }

});
