function validateArpa(theForm) {
	var reason = "";
	
	reason += validateEmpty(theForm.arpa);
	
	if (reason != "") {
		alert("Ilmoita arpalipukkeessasi oleva koodi.");
		theForm.arpa.focus();
		return false;
	}
	
	return true;
}
function validateVoittaja(theForm) {
	var reason = "";
	
	reason += validateEmpty(theForm.namn);
	reason += validateEmpty(theForm.foretag);
	reason += validateEmpty(theForm.telefon);
	reason += validateEmpty(theForm.email);
	
	if (reason != "") {
		alert("Täytä puuttuvat tiedot.");
		return false;
	}
	
	return true;
}
function validateTipsaChef(theForm) {
	var reason = "";

	reason += validateEmpty(theForm.t_namn);
	reason += validateEmpty(theForm.t_foretag);
	reason += validateEmpty(theForm.t_email);
    
	if (reason != "") {
		alert("Muista täyttää puuttuvat kentät.");
		theForm.t_email.focus();
		return false;
	}
	
	return true;
}
function validateSkickaTips(theForm) {
	var reason = "";

	reason += validateEmpty(theForm.t_foretag);
	reason += validateEmpty(theForm.t_person);
	reason += validateEmpty(theForm.t_adress);
	reason += validateEmpty(theForm.t_post);
    
	if (reason != "") {
		alert("Täytä puuttuvat tiedot.");
		return false;
	}
	
	return true;
}

function validateFeedback(theForm) {
	var reason = "";

	reason += validateEmpty(theForm.fb_feedback_subject);
    
	if (reason != "") {
		alert("Et ole kirjoittanut mitään.");
		theForm.fb_feedback_subject.focus();
		return false;
	}
	
	return true;
}

function validateCampaignForm(theForm) {
	
 	var noproduct = "";
	var reason = "";
	var pnr = "";
	var emailok = "";

 	noproduct = validateCampProduct();
 	pnr = validatePnr();
	emailok = validateEmail();
	
	reason += validateEmpty(theForm.vecka);
	reason += validateEmpty(theForm.f_foretag);
	reason += validateEmpty(theForm.f_namn);
	reason += validateEmpty(theForm.f_orgnr);
	reason += validateEmpty(theForm.f_adress);
	reason += validateEmpty(theForm.f_ort);
	reason += validateEmpty(theForm.telefon);
    
	if (noproduct != "") {
		alert("Et ole valinnut yhtään tuotetta.");
		return false;
	}
	if (reason != "") {
		alert("Täytä vielä puuttuvat pakolliset kentät.");
		return false;
	}
	if (pnr != "") {
		alert("Postinumerossa on virhe.");
		return false;
	}
	if (emailok != "") {
		alert("Sähköpostiosoitteessa on virhe.");
		return false;
	}
	
	return true;
}

function validateSeasonForm(theForm) {
	
	var reason = "";
	var pnr = "";
	var emailok = "";

 	pnr = validatePnr();
	emailok = validateEmail();
	
	reason += validateEmpty(theForm.f_foretag);
	reason += validateEmpty(theForm.f_namn);
	reason += validateEmpty(theForm.f_orgnr);
	reason += validateEmpty(theForm.f_adress);
	reason += validateEmpty(theForm.f_ort);
	reason += validateEmpty(theForm.telefon);
    
	if (reason != "") {
		alert("Täytä vielä puuttuvat pakolliset kentät.");
		return false;
	}
	if (pnr != "") {
		alert("Postinumerossa on virhe.");
		return false;
	}
	if (emailok != "") {
		alert("Sähköpostiosoitteessa on virhe.");
		return false;
	}
	
	return true;
}

function validateFormOnSubmit(theForm) {
	
 	var noproduct = "";
	var typ = "";
	var reason = "";
	var pnr = "";
	var emailok = "";

 	noproduct = validateProduct();
	typ = validateOrderType();
	pnr = validatePnr();
	emailok = validateEmail();
	
	reason += validateEmpty(theForm.vecka);
	reason += validateEmpty(theForm.f_foretag);
	reason += validateEmpty(theForm.f_namn);
	reason += validateEmpty(theForm.f_orgnr);
	reason += validateEmpty(theForm.f_adress);
	reason += validateEmpty(theForm.f_ort);
	reason += validateEmpty(theForm.telefon);
	
	if (noproduct != "") {
		alert("Et ole valinnut yhtään tuotetta.");
		return false;
	}
	if (typ != "") {
		alert("Valitse tilauksen tyyppi.");
		return false;
	} 
	if (reason != "") {
		alert("Täytä vielä puuttuvat pakolliset kentät.");
		return false;
	}
	if (pnr != "") {
		alert("Postinumerossa on virhe.");
		return false;
	}
	if (emailok != "") {
		alert("Sähköpostiosoitteessa on virhe.");
		return false;
	}
	
	return true;
}
function validateProduct(){
	fbselected = 0;
	error = "";

	if (document.tilaa.fb_140301_5.value.length > 0) { fbselected = 1; }
 	else if (document.tilaa.fb_140302_5.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140303_5.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140304_5.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140305_5.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140401_8.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140402_8.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140403_8.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140404_8.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140405_8.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140101_5.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140102_5.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140103_5.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140104_5.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140105_5.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140201_8.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140202_8.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140203_8.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140204_8.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140205_8.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140701_5.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140702_5.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140703_5.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140704_5.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140705_5.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140801_8.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140802_8.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140803_8.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140804_8.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140805_8.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_141301_6.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_141302_6.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_141303_6.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_141304_6.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_141305_6.value.length > 0) { fbselected = 1; }

	if (fbselected == 0) {
		error = "Pakollinen kenttä.";
		document.tilaa.fb_140301_5.focus();
		// change color of the fields...
	}
	return error;
}
function validateCampProduct(){
	fbselected = 0;
	error = "";

	if (document.tilaa.fb_140101_5.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140102_5.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140103_5.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140104_5.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140105_5.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140201_8.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140202_8.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140203_8.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140204_8.value.length > 0) { fbselected = 1; }
	else if (document.tilaa.fb_140205_8.value.length > 0) { fbselected = 1; }

	if (fbselected == 0) {
		error = "Pakollinen kenttä.";
		document.tilaa.fb_140101_5.focus();
		// change color of the fields...
	}
	return error;
}
function validateEmpty(field) {
    var error = "";
  
    if (field.value.length == 0) {
        field.style.background = "#D4FFA5";
        error = "Pakollinen kenttä.";
    } else {
        field.style.background = "";
    }
    return error;
}

function validatePnr() {
	var error = "";
	var x = document.tilaa.f_pnr.value;
 	var nummer_kontroll = x.match(/^\d{5,5}$/);

	if (nummer_kontroll && x > 0) {
		document.tilaa.f_pnr.style.background = "";
	} else {
		document.tilaa.f_pnr.style.background = "#D4FFA5";
		error = "Pakollinen kenttä.";
		document.tilaa.f_pnr.focus();
	}
	return error;
}

function validateOrderType() {
	var error = "";
	var x = document.getElementsByName("ordertyp");
	var selectedordertyp = -1;
	
	for (i = 0;i < x.length;i++){
		if (tilaa.ordertyp[i].checked) {
			selectedordertyp = i;
			typ = 1;
		}
	}
	
	if (selectedordertyp < 0) {
		alternativ.style.background = "#D4FFA5";
		error = "Tilauksen tyyppi puuttuu.";
	} else {
		alternativ.style.background = "#f0f0f0";
	}
	return error;
}
function validateEmail() {
	var error = "";
	var x = document.tilaa.email.value;
// 	var email_test = x.match(/^\w+(\.\w+)?\@\w+(\.\w+){1,3}$/);
	var email_test = x.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/);
	 
	if (email_test) { 
		document.tilaa.email.style.background = "";
	}
	else {
		document.tilaa.email.style.background = "#D4FFA5";
		error = "Pakollinen kenttä.";
		document.tilaa.email.focus();
	}
	return error;
}
function Enable(val) {
	if (val == 1) {
		tilaa.gava[0].disabled = true;
		tilaa.gava[1].disabled = true;
		// tilaa.gava[2].disabled = true;
		tilaa.gava[0].checked = false;
		tilaa.gava[1].checked = false;
		// tilaa.gava[2].checked = false;
	}
	if (val == 2) {
		tilaa.gava[0].disabled = false;
		tilaa.gava[1].disabled = false;
		// tilaa.gava[2].disabled = false;
	}
}

// function login_validera(){
// 	var x = document.login_form.email.value;
// 	var filter  = 
// 	/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
// 	if(!filter.test(x)){alert("Felaktigt angiven eMail adress!");return false;}
// 	else{return true;}
// }
