var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;
$(function() {
  var options = {
    beforeSubmit:  showRequest,  // pre-submit callback
    success:       showResponse,  // post-submit callback
    clearForm: true,        // clear all form fields after successful submit
    resetForm: true        // reset the form after successful submit
  };

  // bind to the form's submit event
  $('#chcfl-opt-in').submit(function() {
    $(this).ajaxSubmit(options);
    return false;
  });


  // pre-submit callback
  function showRequest(formData, jqForm, options) {
    var queryString = $.param(formData);

    if (emailfilter.test($("#opt-in_email").val())==false){
      alert ("Please enter a vaild email address");
      $("#opt-in_email").focus();
      return false;
    }
    return true;
  }

  // post-submit callback
  function showResponse(responseText, statusText, xhr, $form)  {
    //alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + '\n\nThe output div should have already been updated with the responseText.');
		lbdialog({content: responseText});
		//alert();
  }
});
