$(function() {
$("#form").submit(function() {
		// validate and process form
		// first hide any error messages		
	  var name = $("input#name").val();
	  if (name == "") {
      return false;
    }
	  var msg = $("textarea#msg").val();
	  if (msg == "") {
      return false;
    }
      var coname = $("input#coname").val();

function validateAddress(email) {
var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
return pattern.test(email);
}

var email = $("input#email").val();
if (email == "") {
return false;
}
if (!validateAddress(email)) {
return false;
}
	  var website = $("input#website").val();
	  var coname = $("input#coname").val();
      var dataString = 'name='+ name + '&email=' + email + '&coname=' + coname + '&website=' + website + '&msg=' + msg;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "bin/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h3>Contact Form Submitted!</h3>")
        .append("<p>Thank you for your valuable feedback. We will get back to you in less than 24 hours. </p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message');
        });
      }
     });
    return false;
	});
});
