$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
$('.error').hide();

	var name = $("input#name").val();
	if (name == "") {
		$("label#name_error").show();
		$("input#name").focus();
		return false;
	}
  var phone = $("input#phone").val();
	if (phone == "") {
		$("label#phone_error").show();
		$("input#phone").focus();
		return false;
	}

var validemail = false
	var email = $("input#email").val();
	var filter = "/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/";
	
	var aindex = email.indexOf("@");
	var pindex = email.lastIndexOf(".");
	
	if (aindex>0){
		if ((pindex > aindex+1) && (email.length > pindex+1)){
			validemail = true;
		}
	}

	if (!validemail) {
		$("label#email_error").show();
		$("input#email").focus();
		return false;
	}

  

	


 var query = $("textarea#query").val();
	if (query == "") {
		$("label#query_error").show();
		$("textarea#query").focus();
		return false;
	}

	

		
			var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone +  '&query=' + query ;
		//alert (dataString);return false;
		
		$.ajax({
			type: "POST",
			url: "contact_post.php",
			data: dataString,
			
			/*
			success: function(msg) {	
				alert(msg);
				$('#message').html("Contact Form Submitted!")
				.hide()
				.fadeIn(1500);
			}
		*/
		success: function(msg) {
		
			$('#message').html(msg)
			.hide()
			.fadeIn(1500);	
			//$("textarea#curve").empty()
			document.getElementById("name").value = "";
			document.getElementById("email").value = "";
			
			document.getElementById("phone").value = "";
			document.getElementById("query").value = "";
			
		}



	     });

    return false;
	});
});

/*
	success: function(msg) {	
		$("#note").ajaxComplete(function(event, request, settings){  

			if(msg == 'OK') {
				result = '<div class="notification_ok">Your message has been sent. Thank you!</div>';
				//$("#fields").hide();
			}
			else{
				result = msg;
			}

			//$(this).html(result);
			$('#message').html(result)
			});
		} 
		*/
