Form = function($who) {

	var $this = this;

	this.source = $who;

	this.onValidationError =
	this.onStart =
	this.onComplete = null;

	this.source.bind('submit', function(e) {

		var $continue = false;
		e.preventDefault();

		var $req = $(this).find('input[name="REQUIRED"]').val();
		var $email = $(this).find('input[name="EMAIL"]').val();

		if ($req == 'undefined' || $this.onValidationError == null)
			$continue = true;
		else {

			$req = String($req).split(',');
			$email = String($email).split(',');

			for (var i = 0; i < $req.length; i++) {

				var $el = $('*[name="VALUE_'+$req[i]+'"]');
				var $name = $('*[name="TITLE_'+$req[i]+'"]').val();

				if ($el.val() == '') {

					$this.onValidationError($name, $el, 'empty field');
					return false;

				}

				if ($.inArray($req[i],$email) >= 0) {

					var $pattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
					if (!$pattern.test($el.val())) {

						$this.onValidationError($name, $el, 'invalid email');
						return false;

					}

				}

			}

			$continue = true;

		}

		if ($continue) {

			if ($this.onStart != null)
				$this.onStart();

			$.ajax({
				url: $(this).attr('action'),
				type: 'POST',
				data: $(this).serialize(),
				success: function(xml) {

				if ($this.onComplete != null)
					$this.onComplete(xml);

				}

			});

		}

	});

}

Input = function($who) {

	var $val = ($('label[for="'+$($who).attr('id')+'"]').length > 0) ? $('label[for='+$($who).attr('id')+']').text() : ($($who).val() ? $($who).val() : '');
	if (!$($who).val()) {
	   $($who).val($val);
    }
    $('label[for="'+$($who).attr('id')+'"]').hide();

	$($who).focus(function() {

		if ($(this).val() == $val)
			$(this).val('');

	});

	$($who).blur(function() {

		if ($(this).val() == '')
			$(this).val($val);

	});

}