function formValid(theForm)
{
	company = theForm.company;
	street = theForm.street;
	town = theForm.town;
	zip = theForm.zip;
	state = theForm.state;
	country = theForm.country;
	email = theForm.email;
	
	errorelement = null;
	
	if (company.value == "")
	{
		errorelement = company;
	} else
	if (email.value == "" || email.value.indexOf('@') == -1 || email.value.length<6)
	{
		errorelement = email;
	} else
	if (street.value == "")
	{
		errorelement = street;
	} else
	if (town.value == "")
	{
		errorelement = town;
	} else
	if (zip.value == "")
	{
		errorelement = zip;
	} else
	if (state.value == "")
	{
		errorelement = state;
	} else
	if (country.selectedIndex==0)
	{
		errorelement = country;
	}

	if(errorelement)
	{
		showError(errorelement,true);
		return false;
	}
	return (true);
}

function showError(errorelement, state){
	$('div.formerror').each( function(element) {
		if(state)
		{
			$(this).show();
		}
		else
		{
			$(this).hide();
		}

	});
	$(errorelement).parents().find('tr').each(function(element){
		if(state)
		{
			$(this).addClass('error');
		}
		else
		{
			$(this).removeClass('error');
		}
	});
}

function initContactForm(){
	$( '.nojs' ).each(function( intIndex ){
		$(this).remove();
	});
	
	$('button[type=submit]').each( function(element) {
		$(this).click(function() { 
		
			for(i=0; i < document.contactForm.elements.length; i++){
				element = document.contactForm.elements[i];
				showError(element,false);
			}
			
			document.contactForm.woher.value = document.contactForm.country.options[document.contactForm.country.selectedIndex].text;
			
			return formValid(document.contactForm);
		})
	});
}

$(document).ready(function(){
	initContactForm();
});