﻿function tarkista()
{
	username = document.register.username.value;
	
	password = document.register.password.value
	password2 = document.register.password2.value
	
	ytunnus = document.register.ytunnus.value;
	company =  document.register.company.value;
	forename =  document.register.forename.value;
	surname =  document.register.surname.value;
	email =  document.register.email.value;
	
	tel =  document.register.tel.value;
	gsm =  document.register.gsm.value;
		
	// laskutusosoite
	address =  document.register.address.value;
	zip =  document.register.zip.value;
	city =  document.register.city.value;
	country =  document.register.country.value;
		
	// toimitusosoite
	altAddress = document.register.altAddress.value;
	altZip =  document.register.altZip.value;
	altCity =  document.register.altCity.value;
	altCountry = document.register.altCountry.value;
	
	
	if(password != "" && password.length > 4 && password == password2)
	{
		ok = true;
	}
	else
	{
		alert("Salasanat ei täsmää");
		return false;
	}
	
	if(username.length < 3)
		ok = false;
	if(ytunnus.length < 3)
		ok = false;
	if(company.length < 3)
		ok = false;
	if(forename.length < 3)
		ok = false;
	if(surname == "" && surname.length < 3)
		ok = false;
	if(email == "" && email.length < 3)
	{	
		alert("Virheellinen sähköpostiosoite");
		return false;
	}
	else
	{
		var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if(!email.match(emailRegEx))
			{
				alert("Virheellinen sähköpostiosoite");
				return false;
			}
	}
	
	if(tel == "" && tel.length < 3)
		ok = false;
	if(gsm == "" && gsm.length < 3)
		ok = false;
	if(address == "" && address.length < 3)
		ok = false;
	if(zip == "" && zip.length < 3)
		ok = false;
	if(city == "" && city.length < 3)
		ok = false;
	if(country == "" && country.length < 3)
		ok = false;
	if(altAddress == "" && altAddress.length < 3)
		ok = false;
	if(altZip == "" && altZip.length < 3)
		ok = false;
	if(altCity == "" && altCity.length < 3)
		ok = false;
	if(altCountry == "" && altCountry.length < 3)
		ok = false;
			
	
	if(ok)
		return true;
	else
	{
		alert('Täytä kaikki kentät');
		return false;
	}
	
}

