$(function() {
$("#button").click(function() {

var recipients = $("#recipients").val();
var subject = $("#subject").val();
var required = $("#required").val();
var env_report = $("#env_report").val();

var realname = $("#realname").val();
var email = $("#email").val();
var topic = $("#topic").val();
var message = $("#message").val();

var dataString = 'drftghtyutyui=drftghtyutyui&recipients=' + recipients + '&subject=' + subject + '&required=' + required + '&realname=' + realname + '&email=' + email + '&topic=' + topic + '&message=' + message;

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

//alert (dataString);
//return false;

if(recipients=='' ) {
  $("p#TB-output").text("Please choose who to contact!");
  tb_show('Error','TB_inline?height=130&amp;width=300&amp;inlineId=TBcontent');
	hasError = true;
} else if(realname=='' ) {
  $("p#TB-output").text("Please supply your name!");
  tb_show('Error','TB_inline?height=130&amp;width=300&amp;inlineId=TBcontent');
	hasError = true;
} else if(!emailReg.test(email)) {
  $("p#TB-output").text("Enter a valid email address.");
  tb_show('Error','TB_inline?height=130&amp;width=300&amp;inlineId=TBcontent');
	hasError = true;
} else if(email=='' ) {
  $("p#TB-output").text("Enter your email address.");
  tb_show('Error','TB_inline?height=130&amp;width=300&amp;inlineId=TBcontent');
  hasError = true;
} else if(topic=='' ) {
  $("p#TB-output").text("Please choose what the email is about!");
  tb_show('Error','TB_inline?height=130&amp;width=300&amp;inlineId=TBcontent');
  hasError = true;
} else if(message=='' ) {
  $("p#TB-output").text("Please supply your message!");
  tb_show('Error','TB_inline?height=130&amp;width=300&amp;inlineId=TBcontent');
  hasError = true;
}
else
{
$.ajax({
type: "POST",
url: "includes/ajax/contact_mail.php",
data: dataString,
success: function(){
$("p#TB-output").text("We have received your message, we will be in touch soon.");
tb_show('Success','TB_inline?height=155&amp;width=300&amp;inlineId=TBcontent');
$('#realname').attr("value", "");
$('#email').attr("value", "");
$('#topic').attr("value", "");
$('#message').attr("value", "");
}

});

}

$('input#TBcancel').click(function(){
   tb_remove();
});

return false;
});
});