var contactForm = 
{
	frm: null,
	elms: {},
	maxMessageLength: 2048,
	errors:
	{
		prefix: 'Form contains following errors:',
		suffix: 'Please fix errors and try to submit form again.',
		firmEmpty: 'Firm required',
		nameEmpty: 'Name required',
		streetEmpty: 'Street required',
		zipEmpty: 'PLZ required',
		cityEmpty: 'City required',
		emailEmpty: 'Email required',
		emailInvalid: 'Email invalid',
		phoneEmpty: 'Phone required',
		messageTooLong: 'Message too long, max length is 2048 symbols!'
	},
	initialize: function(frm)
	{
		contactForm.frm = frm;
		var d = document;
		contactForm.elms.firm = d.getElementById('frm-contact-firmname');
		contactForm.elms.name = d.getElementById('frm-contact-name');
		contactForm.elms.street = d.getElementById('frm-contact-street');
		contactForm.elms.zip = d.getElementById('frm-contact-zip');
		contactForm.elms.city = d.getElementById('frm-contact-city');
		contactForm.elms.email = d.getElementById('frm-contact-email');
		contactForm.elms.phone = d.getElementById('frm-contact-phone');
		contactForm.elms.message = d.getElementById('frm-contact-message');
		frm.onsubmit = contactForm.onContactFormSubmit;
	},
	trim: function(str)
	{
		str = str.replace(/^\s+/);
		str = str.replace(/\s+$/);
		return str;
	},
	onContactFormSubmit: function()
	{
		errors = [];
		if(contactForm.trim(contactForm.elms.firm.value).length == 0)
		{
			errors[errors.length] = contactForm.errors.firmEmpty;
		}
		if(contactForm.trim(contactForm.elms.name.value).length == 0)
		{
			errors[errors.length] = contactForm.errors.nameEmpty;
		}
		if(contactForm.trim(contactForm.elms.street.value).length == 0)
		{
			errors[errors.length] = contactForm.errors.streetEmpty;
		}
		if(contactForm.trim(contactForm.elms.zip.value).length == 0)
		{
			errors[errors.length] = contactForm.errors.zipEmpty;
		}
		if(contactForm.trim(contactForm.elms.city.value).length == 0)
		{
			errors[errors.length] = contactForm.errors.cityEmpty;
		}
		if(contactForm.trim(contactForm.elms.email.value).length == 0)
		{
			errors[errors.length] = contactForm.errors.emailEmpty;
		}
		else if(contactForm.trim(contactForm.elms.email.value).search(/^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-\w]*[0-9a-zA-Z])*\.)+[a-zA-Z]{2,9})$/) == -1)
		{
			errors[errors.length] = contactForm.errors.emailInvalid;
		}
		if(contactForm.trim(contactForm.elms.phone.value).length == 0)
		{
			errors[errors.length] = contactForm.errors.phoneEmpty;
		}
		if(contactForm.trim(contactForm.elms.message.value).length > contactForm.maxMessageLength)
		{
			errors[errors.length] = contactForm.errors.messageTooLong;
		}
		if(errors.length > 0)
		{
			var msg = contactForm.errors.prefix + '\n\n';
			for(i = 0; i < errors.length; i++)
			{
				msg += '   - ' + errors[i] + ((i < errors.length - 1) ? (';\n') : ('.\n\n'));
			}
			msg += contactForm.errors.suffix;
			alert(msg);
			return false;
		}
		else
		{
			return true;
		}
	}
}