var DataForm = {
	initialize: function() {		
		$('#popupNieuwsbrief form').submit(function() {
			if (ProcessForm.validate($(this).parents('div').attr('id'))) {
				ProcessForm.send('/voice/voice_mail.asp',$(this).parents('div').attr('id'));
			}
			return false;
		});			
	}
};

var ProcessForm = {
	initialize: function() {	
	},

	validate: function(type) {
		
		if ($('#' + type + ' form input[type=text][value=]').length > 0) {
			$('#' + type + ' .error-email').hide();
			$('#' + type + ' .error-required').show();
			return false;
		}

		$('#' + type + ' .error-required').hide();

		var email = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
		var emailError = false;

		$('#' + type + ' form input.validate.email').each(function() {
			if (email.test($(this).val()) == false) {
				emailError = true;
			}
		});

		if (emailError) {
			$('#' + type + ' .error-email').show();
			return false;
		}
		
		$('#' + type + ' .error-email').hide();
		return true;
		
	},
	
	send: function(file, type) {
		
		var data = $('#' + type + ' form').serialize();
		
		var callback = function(result) {

			//var result = Math.floor(result);
			
			if (result == 0) {
				disablePopup();
			}

			if (result == 1) {
				
				$('#' + type + ' .msg-sent').show();
				
				$('#' + type + ' form').css('visibility', 'hidden');
				
				window.setTimeout(function() {
					//ProcessForm.close(type);
					disablePopup();
					
					window.setTimeout(function() {
						$('#' + type + ' .msg-sent').hide();
						$('#' + type + '  form').css('visibility', 'visible').get(0).reset();
					}, 1000);
				}, 2000);
			}
		}
		
		$.post(file, data, callback);
	}
};

$(function() { ProcessForm.initialize() });
$(function() { DataForm.initialize() });
//$(function() { MailForm.initialize() });