var _translation_c = function()
{
	this.form_o = new Object();
	this.language_s = 'nl';

	this.translation_a = new Array();

	this.translation_a['nl'] = new Array();
	this.translation_a['en'] = new Array();
	this.translation_a['fr'] = new Array();
	this.translation_a['de'] = new Array();
	this.translation_a['es'] = new Array();

	this.translation_a['nl']['notice_prefix'] = 'De volgende fouten zijn aangetroffen:';
	this.translation_a['en']['notice_prefix'] = 'The following errors occurred:';
	this.translation_a['fr']['notice_prefix'] = 'Les erreurs suivantes se sont produites:';
	this.translation_a['de']['notice_prefix'] = 'Die folgenden St?rungen sind aufgetreten:';
	this.translation_a['es']['notice_prefix'] = 'The following errors occurred:';

	this.translation_a['nl']['notice_suffix'] = 'Corrigeer de fouten en probeer het a.u.b. opnieuw.';
	this.translation_a['en']['notice_suffix'] = 'Please, correct the errors and try again.';
	this.translation_a['fr']['notice_suffix'] = 'Svp, corrigez les erreurs et essayez encore.';
	this.translation_a['de']['notice_suffix'] = 'Bitte beheben Sie die St?rungen und versuchen Sie noch einmal.';
	this.translation_a['es']['notice_suffix'] = 'Please, correct the errors and try again.';

	this.translation_a['nl']['notice_required_element_prefix'] = 'Het veld \' ';
	this.translation_a['en']['notice_required_element_prefix'] = 'The field \' ';
	this.translation_a['fr']['notice_required_element_prefix'] = 'Le champ \' ';
	this.translation_a['de']['notice_required_element_prefix'] = 'Das Feld \' ';
	this.translation_a['es']['notice_required_element_prefix'] = 'The field \' ';

	this.translation_a['nl']['notice_required_element_suffix'] = ' \' is leeg.';
	this.translation_a['en']['notice_required_element_suffix'] = ' \' is empty.';
	this.translation_a['fr']['notice_required_element_suffix'] = ' \' est vide.';
	this.translation_a['de']['notice_required_element_suffix'] = ' \' ist leer.';
	this.translation_a['es']['notice_required_element_suffix'] = ' \' is empty.';

	this.translation_a['nl']['notice_required_email_prefix'] = 'Het veld \' ';
	this.translation_a['en']['notice_required_email_prefix'] = 'The field \' ';
	this.translation_a['fr']['notice_required_email_prefix'] = 'Le champ \' ';
	this.translation_a['de']['notice_required_email_prefix'] = 'Das Feld \' ';
	this.translation_a['es']['notice_required_email_prefix'] = 'The field \' ';

	this.translation_a['nl']['notice_required_email_suffix'] = ' \' bevat een onjuist email adres.';
	this.translation_a['en']['notice_required_email_suffix'] = ' \' contains an incorrect email address.';
	this.translation_a['fr']['notice_required_email_suffix'] = ' \' contient un email address incorrect.';
	this.translation_a['de']['notice_required_email_suffix'] = ' \' enth?lt ein falsches email address.';
	this.translation_a['es']['notice_required_email_suffix'] = ' \' contains an incorrect email address.';
};

	/**/

	_translation_c.prototype.setLanguage = function()
	{
		this.language_s = (typeof this.form_o['__language__'] != 'undefined') ? this.form_o.__language__.value : this.language_s;
	};

	_translation_c.prototype.setFormObject = function(form_o)
	{
		this.form_o = form_o;
	};

	_translation_c.prototype.getTranslation = function(item_s)
	{
		return (typeof this.translation_a[this.language_s] != 'undefined') ? this.translation_a[this.language_s][item_s] : '';
	};

/*
*/

var _notification_c = function()
{
	this.form_o = new Object();
	this.translation_o = new Object();

	this.notice_a = new Array();
};

	/**/

	_notification_c.prototype.getNoticeCount = function()
	{
		return this.notice_a.length;
	};

	_notification_c.prototype.getNoticeNameByElement = function(element_o)
	{
		return (typeof element_o.getAttribute != 'undefined') ? (element_o.getAttribute('alt') ? element_o.getAttribute('alt') : element_o.name) : element_o.name;
	};

	/**/

	_notification_c.prototype.setNoticeLine = function(message_s)
	{
		this.notice_a[this.notice_a.length] = message_s;
	};

	_notification_c.prototype.setNoticeByRequiredElement = function(element_o)
	{
		this.setNoticeLine(this.translation_o.getTranslation('notice_required_element_prefix') + this.getNoticeNameByElement(element_o) + this.translation_o.getTranslation('notice_required_element_suffix'));
	};

	_notification_c.prototype.setNoticeByRequiredEmail = function(element_o)
	{
		this.setNoticeLine(this.translation_o.getTranslation('notice_required_email_prefix') + this.getNoticeNameByElement(element_o) + this.translation_o.getTranslation('notice_required_email_suffix'));
	};

	/**/

	_notification_c.prototype.setAlert = function()
	{
		if (this.getNoticeCount())
		{
			var alert_s = '';

				alert_s += this.translation_o.getTranslation('notice_prefix') + '\n';
				alert_s += '_________________________________________\n';
				alert_s += '\n';
				alert_s += this.notice_a.join('\n');
				alert_s += '\n';
				alert_s += '_________________________________________\n';
				alert_s += '\n';
				alert_s += this.translation_o.getTranslation('notice_suffix');

			alert(alert_s);

			return false;
		}

		return true;
	};

	/**/

	_notification_c.prototype.setTranslationObject = function(translation_o)
	{
		this.translation_o = translation_o;
	};

	_notification_c.prototype.setFormObject = function(form_o)
	{
		this.form_o = form_o;
	};

/*
*/

var _validation_c = function()
{
	this.notification_o = new Object();
	this.form_o = new Object();
};

	/**/

	_validation_c.prototype.getValidEmailAddress = function(address_s)
	{
		var regex_o = new RegExp('^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$');

		return regex_o.test(address_s);
	};

	/**/

	_validation_c.prototype.setValidateRadioElement = function(element_o)
	{
		var checked_b = false;

		for (var i_i = 0; i_i < element_o.length; i_i++)
			if (element_o[i_i].checked)
				checked_b = true;

		if (!checked_b)
			this.notification_o.setNoticeByRequiredElement(element_o[0]);
	};

	_validation_c.prototype.setValidateTextElement = function(element_o)
	{
		if (!element_o.value)
			this.notification_o.setNoticeByRequiredElement(element_o);
	};

	_validation_c.prototype.setValidateCheckBoxElement = function(element_o)
	{
		if (!element_o.checked)
			this.notification_o.setNoticeByRequiredElement(element_o);
	};

	_validation_c.prototype.setValidateTextAreaElement = function(element_o)
	{
		if (!element_o.value)
			this.notification_o.setNoticeByRequiredElement(element_o);
	};

	_validation_c.prototype.setValidateArrayElement = function(element_o, name_s)
	{
		var cached_element_o = false;
		var filled_b = false;

		for (i_i = 0; i_i < this.form_o.elements.length; i_i++)
		{
			var current_element_o = this.form_o.elements[i_i];

			if (current_element_o.name.substr(0, name_s.length + 1) == name_s + '[')
			{
				if (current_element_o.name.charAt(current_element_o.name.length - 1) == ']')
				{
					cached_element_o = cached_element_o ? cached_element_o : current_element_o;

					if (current_element_o.type)
					{
						switch (current_element_o.type.toLowerCase())
						{
							case 'password':
							case 'text':

									if (current_element_o.value)
										filled_b = true;

								break;

							case 'checkbox':

									if (current_element_o.checked)
										filled_b = true;

								break;

							case 'radio':

									if (current_element_o.checked)
										filled_b = true;

								break;
						}
					}

					if (typeof current_element_o.nodeName != 'undefined')
						if (current_element_o.nodeName.toLowerCase() == 'textarea')
							if (current_element_o.value)
								filled_b = true;
				}
			}
		}

		if (!filled_b)
			if (cached_element_o)
				this.notification_o.setNoticeByRequiredElement(cached_element_o);
	};

	/**/

	_validation_c.prototype.setEmailValidation = function()
	{
		if (typeof this.form_o.__sender_email__ != 'undefined')
		{
			var email_o = this.form_o[this.form_o.__sender_email__.value];
			var valid_b = this.getValidEmailAddress(email_o.value);

			if (!valid_b)
				this.notification_o.setNoticeByRequiredEmail(email_o);
		}
	};

	_validation_c.prototype.setRequiredElementValidation = function()
	{
		if (typeof this.form_o.__required__ != 'undefined')
		{
			var element_name_a = this.form_o.__required__.value.split(',');

			for (var i_i = 0; i_i < element_name_a.length; i_i++)
			{
				var element_name_s = element_name_a[i_i].replace(/^[\s]+/g, '').replace(/[\s]+$/g, '');

				if (typeof this.form_o[element_name_s] != 'undefined')
				{
					var element_o = this.form_o[element_name_s];

					if (element_o.length)
						if (element_o[0].type)
							if (element_o[0].type.toLowerCase() == 'radio')
								this.setValidateRadioElement(element_o);

					if (element_o.type)
					{
						switch (element_o.type.toLowerCase())
						{
							case 'password':
							case 'text':

									this.setValidateTextElement(element_o);

								break;

							case 'checkbox':

									this.setValidateCheckBoxElement(element_o);

								break;
						}
					}

					if (typeof element_o.nodeName != 'undefined')
						if (element_o.nodeName.toLowerCase() == 'textarea')
							this.setValidateTextAreaElement(element_o);
				}
				else
				{
					this.setValidateArrayElement(element_o, element_name_s);
				}
			}
		}
	};

	/**/

	_validation_c.prototype.setNotificationObject = function(notification_o)
	{
		this.notification_o = notification_o;
	};

	_validation_c.prototype.setFormObject = function(form_o)
	{
		this.form_o = form_o;
	};

/*
*/

var _mutation_c = function()
{
	this.form_o = new Object();
};

	/**/

	_mutation_c.prototype.setReferrer = function()
	{
		if (typeof this.form_o['__referrer__'] == 'undefined')
		{
			var input_o = document.createElement('input');
				input_o.setAttribute('name', '__referrer__');
				input_o.setAttribute('type', 'hidden');
				input_o.setAttribute('value', document.location);

			this.form_o.appendChild(input_o);
		}
	};

	_mutation_c.prototype.setSpamCheck = function()
	{
		if (typeof this.form_o['__spam_check__'] != 'undefined')
		{
			if (this.form_o['__spam_check__'])
			{
				var input_o = document.createElement('input');
					input_o.setAttribute('name', '__spam_check_result__');
					input_o.setAttribute('type', 'hidden');
					input_o.setAttribute('value', 'valid');

				this.form_o.appendChild(input_o);
			}
		}
	};

	/**/

	_mutation_c.prototype.setFormObject = function(form_o)
	{
		this.form_o = form_o;
	};

/*
*/

var getValidation = function(form_o)
{
	var translation_o = new _translation_c();
		translation_o.setFormObject(form_o);
		translation_o.setLanguage();

	var notification_o = new _notification_c();
		notification_o.setTranslationObject(translation_o);
		notification_o.setFormObject(form_o);

	var validation_o = new _validation_c();
		validation_o.setNotificationObject(notification_o);
		validation_o.setFormObject(form_o);
		validation_o.setEmailValidation();
		validation_o.setRequiredElementValidation();

	var mutation_o = new _mutation_c();
		mutation_o.setFormObject(form_o);
		mutation_o.setReferrer();
		mutation_o.setSpamCheck();

	return notification_o.setAlert();
};
