function submitacymailingform(task,formName){
	var varform = eval('document.'+formName);
	if(!varform.elements) varform = varform[1];

	 if(task != 'optout'){
		 nameField = varform.elements['user[name]'];
		 if(nameField && (( typeof acymailing != 'undefined' && nameField.value == acymailing['NAMECAPTION'] ) || nameField.value.length < 2)){
			 if(typeof acymailing != 'undefined'){ alert(acymailing['NAME_MISSING']); }
			 nameField.className = nameField.className +' invalid';
			 return false;
		 }
	 }

	 var emailField = varform.elements['user[email]'];
	 if(emailField){
	 if(typeof acymailing == 'undefined' || emailField.value != acymailing['EMAILCAPTION']) emailField.value = emailField.value.replace(/ /g,"");
		var filter = /^([a-z0-9_'&\.\-\+])+\@(([a-z0-9\-])+\.)+([a-z0-9]{2,10})+$/i;
		if(!emailField || (typeof acymailing != 'undefined' && emailField.value == acymailing['EMAILCAPTION']) || !filter.test(emailField.value)){
			if(typeof acymailing != 'undefined'){ alert(acymailing['VALID_EMAIL']); }
			emailField.className = emailField.className +' invalid';
			return false;
		}
	 }

	if(varform.elements['hiddenlists'].value.length < 1){
		var listschecked = false;
		var alllists = varform.elements['subscription[]'];
		if(alllists && typeof alllists.value == 'undefined'){
			for(b=0;b<alllists.length;b++){
				if(alllists[b].checked) listschecked = true;
			}
			if(!listschecked){ alert(acymailing['NO_LIST_SELECTED']); return false;}
		}
	}


	 if(task != 'optout' && typeof acymailing != 'undefined' && typeof acymailing['reqFields'+formName] != 'undefined' && acymailing['reqFields'+formName].length > 0){

		for(var i =0;i<acymailing['reqFields'+formName].length;i++){
			elementName = 'user['+acymailing['reqFields'+formName][i]+']';
			elementToCheck = varform.elements[elementName];
			if(elementToCheck){
				var isValid = false;
				if(typeof elementToCheck.value != 'undefined'){
					if(elementToCheck.value==' ' && typeof varform[elementName+'[]'] != 'undefined'){
						if(varform[elementName+'[]'].checked){
							isValid = true;
						}else{
							for(var a=0; a < varform[elementName+'[]'].length; a++){
								if((varform[elementName+'[]'][a].checked || varform[elementName+'[]'][a].selected) && varform[elementName+'[]'][a].value.length>0) isValid = true;
							}
						}
					}else{
						if(elementToCheck.value.length>0){
							if(typeof acymailing['excludeValues'+formName] == 'undefined' || typeof acymailing['excludeValues'+formName][acymailing['reqFields'+formName][i]] == 'undefined' || acymailing['excludeValues'+formName][acymailing['reqFields'+formName][i]] != elementToCheck.value) isValid = true;
						}
					}
				}else{
					for(var a=0; a < elementToCheck.length; a++){
						 if(elementToCheck[a].checked && elementToCheck[a].value.length>0) isValid = true;
					}
				}
				if(!isValid){
					elementToCheck.className = elementToCheck.className +' invalid';
					alert(acymailing['validFields'+formName][i]);
					return false;
				}
			}else{
				if((varform.elements[elementName+'[day]'] && varform.elements[elementName+'[day]'].value<1) || (varform.elements[elementName+'[month]'] && varform.elements[elementName+'[month]'].value<1) || (varform.elements[elementName+'[year]'] && varform.elements[elementName+'[year]'].value<1902)){
					if(varform.elements[elementName+'[day]'] && varform.elements[elementName+'[day]'].value<1) varform.elements[elementName+'[day]'].className = varform.elements[elementName+'[day]'].className + ' invalid';
					if(varform.elements[elementName+'[month]'] && varform.elements[elementName+'[month]'].value<1) varform.elements[elementName+'[month]'].className = varform.elements[elementName+'[month]'].className + ' invalid';
					if(varform.elements[elementName+'[year]'] && varform.elements[elementName+'[year]'].value<1902) varform.elements[elementName+'[year]'].className = varform.elements[elementName+'[year]'].className + ' invalid';
					alert(acymailing['validFields'+formName][i]);
					return false;
				}
			}
		}
	}

	var captchaField = varform.elements['acycaptcha'];
	if(captchaField){
		if(captchaField.value.length<1){
			if(typeof acymailing != 'undefined'){ alert(acymailing['CAPTCHA_MISSING']); }
			captchaField.className = captchaField.className +' invalid';
					return false;
		}
	}

	if(task != 'optout'){
		var termsandconditions = varform.terms;
		if(termsandconditions && !termsandconditions.checked){
			if(typeof acymailing != 'undefined'){ alert(acymailing['ACCEPT_TERMS']); }
			termsandconditions.className = termsandconditions.className +' invalid';
			return false;
		}
	}

	taskField = varform.task;
	taskField.value = task;

	// No Ajax ?
	if(!varform.elements['ajax'] || !varform.elements['ajax'].value || varform.elements['ajax'].value == '0'){
		varform.submit();
		return false;
	}

	// Mootools < 1.2 ?
	if (typeof String.prototype.parseQueryString != 'function')
	{
		String.prototype.parseQueryString = function() {
			var vars = this.split(/[&;]/), res = {};
			if (vars.length) vars.each(function(val){
				var index = val.indexOf('='),
					keys = index < 0 ? [''] : [val.substr(0, index)],
					value = decodeURIComponent(val.substr(index + 1)),
					obj = res;
				keys.each(function(key, i){
					var current = obj[key];
					if(i < keys.length - 1)
						obj = obj[key] = current || {};
					else if($type(current) == 'array')
						current.push(value);
					else
						obj[key] = $defined(current) ? [current, value] : value;
				});
			});
			return res;
		}
	}

	// Get form values
	data = varform.toQueryString().parseQueryString();

	// Send the request
	if (typeof Ajax == 'function'){
		// Mootools < 1.2
		new Ajax(varform.action, {
			data: data,
			method: 'post',
			onRequest: function()
			{
				// Change the acyba form's opacity to show we are doing stuff
				varform.setAttribute('style', 'opacity: 0.5');
			},
			onSuccess: function(response)
			{
				// Write the response in it's DOM container
				response = Json.evaluate(response);
				acymailingDisplayAjaxResponse(unescape(response.message), response.type, varform);
			},
			onFailure: function(){
				// Write an error message
				acymailingDisplayAjaxResponse('Ajax Request Failure', 'error', varform);
			}
		}).request();
	}else{
		// Mootools >= 1.2
		new Request.JSON({
			url: varform.action,
			data: data,
			method: 'post',
			onRequest: function()
			{
				// Change the acyba form's opacity to show we are doing stuff
				varform.setStyle('opacity', 0.5);
			},
			onSuccess: function(response)
			{
				// Write the response in it's DOM container
				acymailingDisplayAjaxResponse(unescape(response.message), response.type, varform);
			},
			onFailure: function(){
				// Write an error message
				acymailingDisplayAjaxResponse('Ajax Request Failure', 'error', varform);
			}
		}).send();
	}

	return false;
}

function acymailingDisplayAjaxResponse(message, type, parentForm)
{
	// Retrieve the element we will display the response in
	var responseContainer = $$('#acymailing_module_'+parentForm.name+' .responseContainer')[0];
	if (typeof responseContainer == 'undefined'){
		responseContainer = new Element('div', {'class': 'responseContainer'});
		responseContainer.inject($('acymailing_module_'+parentForm.name), 'top');
	}

	// Get the form's dimensions
	var formSize = parentForm.getSize();

	// Mootools < 1.2 ?
	if (typeof Ajax == 'function')
	{
		switch (type)
		{
			case 'success':
				responseContainer.addClass('acymailing_module_success');
				responseContainer.innerHTML = '<div style="padding: 1em !important">'+message+'</div>';

				// Get the response's container dimensions
				responseContainer.setAttribute('style', '');
				var responseSize = responseContainer.getSize();

				// Set the style of the response's container
				responseContainer.setAttribute('style',
					'overflow: hidden;'+
					'position: absolute;'+
					'z-index: 10;'+
					'margin-bottom: 1em !important;'+
					'width: '+formSize.size.x+'px;'+
					'height: '+formSize.size.y+'px;'+
					'opacity: 0;'
				);

				// Display the response with a nice transition
				var myEffect = new Fx.Styles(parentForm, {duration: 500, transition: Fx.Transitions.linear});
				myEffect.start({
					'height': [formSize.size.y, responseSize.size.y],
					'opacity': [1, 0]
				});
				var myEffect2 = new Fx.Styles(responseContainer, {duration: 500, transition: Fx.Transitions.linear});
				myEffect2.start({
					'height': [formSize.size.y, responseSize.size.y],
					'opacity': [0, 1]
				});
				break;

			case 'error':
				// Restore the form's opacity
				parentForm.setAttribute('style', 'opacity: 1');

				// If no error message is displayed, we display the message with a slide transition
				if (responseContainer.innerHTML == '')
				{
					// Write the response in it's DOM container
					responseContainer.innerHTML = '<div class="acymailing_module_error" style="padding: 1em !important;" >'+message+'</div><br />';

					// Get the response's container dimensions
					responseContainer.setAttribute('style', '');
					var responseSize = responseContainer.getSize();

					// Set the style of the response's container
					responseContainer.setAttribute('style',
						'height: 0px;'+
						'overflow: hidden;'+
						'opacity: 0'
					);

					// Display the response with a nice transition
					var myEffect = new Fx.Styles(responseContainer, {duration: 500, transition: Fx.Transitions.linear});
					myEffect.start({
						'height': [0, responseSize.size.y],
						'opacity': [0, 1]
					});
				}
				else // We change the response container's content
				{
					responseContainer.innerHTML = '<div class="acymailing_module_error" style="padding: 1em !important;" >'+message+'</div><br />';
				}
				break;

			default:
				break;
		}
	}
	else // Mootools >= 1.2
	{
		switch (type)
		{
			case 'success':
				// Write the response in it's DOM container
				responseContainer.addClass('acymailing_module_success');
				responseContainer.innerHTML = '<div style="padding: 1em !important">'+message+'</div>';

				// Get the response's container dimensions
				responseContainer.setAttribute('style', '');
				var responseSize = responseContainer.getSize();

				// Set the style of the response's container
				responseContainer.setStyles({
					'overflow': 'hidden',
					'position': 'absolute',
					'z-index': 10,
					'margin-bottom': '1em !important',
					'width': formSize.x+'px',
					'height': formSize.y+'px',
					'opacity': 0
				});

				// Display the response with a nice transition
				parentForm.set('morph');
				parentForm.morph({
					'height': responseSize.y+'px',
					'opacity': 0
				});
				responseContainer.set('morph');
				responseContainer.morph({
					'height': responseSize.y+'px',
					'opacity': 1
				});
				break;

			case 'error':
				// Restore the form's opacity
				parentForm.setStyle('opacity', 1);

				// If no error message is displayed, we display the message with a slide transition
				if (responseContainer.innerHTML == ''){
					// Write the response in it's DOM container
					responseContainer.innerHTML = '<div class="acymailing_module_error" style="padding: 1em !important;" >'+message+'</div><br />';

					// Get the response's container dimensions
					responseContainer.setAttribute('style', '');
					var responseSize = responseContainer.getSize();
					responseContainer.setStyles({
						'height': '0px',
						'overflow': 'hidden',
						'opacity': 0
					});

					// Display the response with a nice transition
					responseContainer.set('morph');
					responseContainer.morph({
						'height': responseSize.y+'px',
						'opacity': 1
					});
				}
				else // We change the response container's content
				{
					responseContainer.innerHTML = '<div class="acymailing_module_error" style="padding: 1em !important;" >'+message+'</div><br />';
				}
				break;

			default:
				break;
		}
	}
}
