jQuery(document).ready(function($) {
	var $aml = $('#add-mailing-list'),
      pattern = /^.+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,5})+$/;
  $aml.submit(function() {
		var msg = '';
		$(this).find(':text').each(function() {
		  var $input = $(this),
		      tmpMsg = 'Please enter a valid ' + $input.prev().text().slice(0,-1).toLowerCase() + '\n';
		  if ($input.is('.required') && !this.value) {
		    msg += tmpMsg;		    
		  } else if ($input.is('.email') && !pattern.test(this.value)) {
		    msg += tmpMsg; 
		  }
		});
		if (msg) {
		  alert(msg);
		  return false;
		}

    // Add form action to end of serialized data


    // var formAction = $(this).attr("action"),
    //         str = $aml.serialize(),
    //     serialdata = str + "&action=" + formAction;
    //     // return console.log(serialdata);
    // // Submit the form via ajax
    // $.ajax({
    //  url: '/global/cm_proxy',
    //  type: 'POST',
    //  data: serialdata,
    //  beforeSend: function() {
    //    $aml.css('position', 'relative').prepend('<div id="loading" style="position: absolute;"></div>')
    //      .find('#loading')
    //      .css({
    //        top: '0', 
    //        left: '0',
    //        width: '100%',
    //        height: '100%',
    //        backgroundColor: '#000',
    //        opacity: '.5',
    //        zIndex: '5'
    //      });
    //  },
    //  success: function(html) {
    //    
    //    var $thanks = $('<div><h3>Thank You!</h3><p>You have successfully subscribed to this list.</p></div>');
    //    $thanks.hide().insertAfter($aml).slideDown('slow');
    //    $aml.slideUp('slow');
    //  }
    // });
	});

});

