function fieldFocus(obj)
{
	obj.style.background = '#99CC66';
}

function fieldBlur(obj)
{
	obj.style.background = '#FFFFFF';
}

function fieldError(obj)
{
	obj.style.background = '#CCCCCC';
}

function trim(str)
{
	while (str.substr(0,1) == ' ')
		str = str.substr(1);
	
	while (str.substr(str.length-1, 1) == ' ')
		str = str.substr(0, str.length-1);
	
	return str;
}


function checkArray(strArrayName)
{
	if (strArrayName == null)
		return false;
	aElems = document.getElementsByName(strArrayName);

	
	for (i = 0; i < aElems.length; i++)
	{
		if (aElems[i].checked)

			return true;
	}
	
	return false;
}


function checkPalaute()
{
	thisForm = document.forms['palauteForm'];
		
	var errorMsg = "";
	
	Nimi = trim(thisForm.Nimi.value);
	Viesti = trim(thisForm.Viesti.value);
	Otsikko = trim(thisForm.Otsikko.value);
	Email = trim(thisForm.Email.value);

	thisForm.Nimi.value = Nimi;
	thisForm.Viesti.value = Viesti;
	thisForm.Otsikko.value = Otsikko;
	thisForm.Email.value = Email;
	
	/*Lahiosoite = trim(thisForm.Lähiosoite.value);
	Postiosoite = trim(thisForm.Postiosoite.value);
	Puhelin = trim(thisForm.Puhelin.value);
	
	thisForm.Lähiosoite.value = Lahiosoite;
	thisForm.Postiosoite.value = Postiosoite;
	thisForm.Puhelin.value = Puhelin;*/
	
	
	if (Nimi.length <= 0) 
	{
		errorMsg += "\n - Nimi";
		fieldError(thisForm.Nimi);
	} else
	{
		fieldBlur(thisForm.Nimi);
	}
	
		if (Email.length <= 0) 
	{
		errorMsg += "\n - E-mail";
		fieldError(thisForm.Email);
	} else
	{
		fieldBlur(thisForm.Email);
	}
	
	if (Otsikko.length <= 0) 
	{
		errorMsg += "\n - Otsikko";
		fieldError(thisForm.Otsikko);
	} else
	{
		fieldBlur(thisForm.Otsikko);
	}
	
	if (Viesti.length <= 0) 
	{
		errorMsg += "\n - Viesti";
		fieldError(thisForm.Viesti);
	} else
	{
		fieldBlur(thisForm.Viesti);
	}
	

	
	
	
	
	
	
	/*
	if (Lahiosoite.length <= 0) 
	{
		errorMsg += "\n - Lähiosoite";
		fieldError(thisForm.Lähiosoite);
	} else
	{
		fieldBlur(thisForm.Lähiosoite);
	}
	
	if (Postiosoite.length <= 0) 
	{
		errorMsg += "\n - Postiosoite";
		fieldError(thisForm.Postiosoite);
	} else
	{
		fieldBlur(thisForm.Postiosoite);
	}
	
	if (Puhelin.length <= 0) 
	{
		errorMsg += "\n - Puhelin";
		fieldError(thisForm.Puhelin);
	} else
	{
		fieldBlur(thisForm.Puhelin);
	}*/
		
	if (errorMsg.length > 0)
	{
		alert("Täytäthän kaikki pakolliset kentät!\n\nPuuttuvat tiedot:\n" + errorMsg);
		return false;
	}

	
	return true;
}

function checkToihin()
{
	thisForm = document.forms['palauteForm'];
		
	var errorMsg = "";
	
	Nimi = trim(thisForm.Nimi.value);
	Ika = trim(thisForm.Ika.value);
	Viesti = trim(thisForm.Viesti.value);
	Otsikko = trim(thisForm.Otsikko.value);

	thisForm.Nimi.value = Nimi;
	thisForm.Ika.value = Ika;
	thisForm.Viesti.value = Viesti;
	thisForm.Otsikko.value = Otsikko;
	
	/*Lahiosoite = trim(thisForm.Lähiosoite.value);
	Postiosoite = trim(thisForm.Postiosoite.value);
	Puhelin = trim(thisForm.Puhelin.value);
	
	thisForm.Lähiosoite.value = Lahiosoite;
	thisForm.Postiosoite.value = Postiosoite;
	thisForm.Puhelin.value = Puhelin;*/
	
	
	if (Nimi.length <= 0) 
	{
		errorMsg += "\n - Nimesi";
		fieldError(thisForm.Nimi);
	} else
	{
		fieldBlur(thisForm.Nimi);
	}
	
	if (Ika.length <= 0) 
	{
		errorMsg += "\n - Ikä";
		fieldError(thisForm.Ika);
	} else
	{
		fieldBlur(thisForm.Ika);
	}
	
	if (Otsikko.length <= 0) 
	{
		errorMsg += "\n - Viestin otsikko";
		fieldError(thisForm.Otsikko);
	} else
	{
		fieldBlur(thisForm.Otsikko);
	}
	
	if (Viesti.length <= 0) 
	{
		errorMsg += "\n - Vapaa sana";
		fieldError(thisForm.Viesti);
	} else
	{
		fieldBlur(thisForm.Viesti);
	}
	

	
	
	
	
	
	
	/*
	if (Lahiosoite.length <= 0) 
	{
		errorMsg += "\n - Lähiosoite";
		fieldError(thisForm.Lähiosoite);
	} else
	{
		fieldBlur(thisForm.Lähiosoite);
	}
	
	if (Postiosoite.length <= 0) 
	{
		errorMsg += "\n - Postiosoite";
		fieldError(thisForm.Postiosoite);
	} else
	{
		fieldBlur(thisForm.Postiosoite);
	}
	
	if (Puhelin.length <= 0) 
	{
		errorMsg += "\n - Puhelin";
		fieldError(thisForm.Puhelin);
	} else
	{
		fieldBlur(thisForm.Puhelin);
	}*/
		
	if (errorMsg.length > 0)
	{
		alert("Täytäthän kaikki pakolliset kentät!\n\nPuuttuvat tiedot:\n" + errorMsg);
		return false;
	}

	
	return true;
}

function checkLoytotavara()
{
	thisForm = document.forms['loytoForm'];
		
	var errorMsg = "";
	
	Nimi = trim(thisForm.Nimi.value);
	Mita = trim(thisForm.MitaKatosi.value);
	//Otsikko = trim(thisForm.Otsikko.value);
	Email = trim(thisForm.Email.value);
	Puhelin = trim(thisForm.Puhelin.value);
	
	thisForm.Nimi.value = Nimi;
	thisForm.MitaKatosi.value = Mita;
	//thisForm.Otsikko.value = Otsikko;
	thisForm.Email.value = Email;
	thisForm.Puhelin.value = Puhelin;
	
	/*Lahiosoite = trim(thisForm.Lähiosoite.value);
	Postiosoite = trim(thisForm.Postiosoite.value);
	
	
	thisForm.Lähiosoite.value = Lahiosoite;
	thisForm.Postiosoite.value = Postiosoite;
	*/
	
	
	if (Nimi.length <= 0) 
	{
		errorMsg += "\n - Nimi";
		fieldError(thisForm.Nimi);
	} else
	{
		fieldBlur(thisForm.Nimi);
	}
	
	if (Email.length <= 0) 
	{
		errorMsg += "\n - E-mail";
		fieldError(thisForm.Email);
	} else
	{
		fieldBlur(thisForm.Email);
	}
	
	if (Puhelin.length <= 0) 
	{
		errorMsg += "\n - Puhelin";
		fieldError(thisForm.Puhelin);
	} else
	{
		fieldBlur(thisForm.Puhelin);
	}
	
	if (Mita.length <= 0) 
	{
		errorMsg += "\n - Mitä katosi / milloin katosi";
		fieldError(thisForm.MitaKatosi);
	} else
	{
		fieldBlur(thisForm.MitaKatosi);
	}
	

	
	
	
	
	
	
	/*
	if (Lahiosoite.length <= 0) 
	{
		errorMsg += "\n - Lähiosoite";
		fieldError(thisForm.Lähiosoite);
	} else
	{
		fieldBlur(thisForm.Lähiosoite);
	}
	
	if (Postiosoite.length <= 0) 
	{
		errorMsg += "\n - Postiosoite";
		fieldError(thisForm.Postiosoite);
	} else
	{
		fieldBlur(thisForm.Postiosoite);
	}
	
	*/
		
	if (errorMsg.length > 0)
	{
		alert("Täytäthän kaikki pakolliset kentät!\n\nPuuttuvat tiedot:\n" + errorMsg);
		return false;
	}

	
	return true;
}

function checkOrderPrepaid()
{
	thisForm = document.forms['palauteForm'];
		
	var errorMsg = "";
	

	Nimi = trim(thisForm.Nimi.value);
	Katuosoite = trim(thisForm.Katuosoite.value);
	Postinumero = trim(thisForm.Postinumero.value);
	Postitmp = trim(thisForm.Postitmp.value);

	thisForm.Nimi.value = Nimi;
	thisForm.Katuosoite.value = Katuosoite;
	thisForm.Postinumero.value = Postinumero;
	thisForm.Postitmp.value = Postitmp;

	
	if (Nimi.length <= 0) 
	{
		errorMsg += "\n - Nimi";
		fieldError(thisForm.Nimi);
	} else
	{
		fieldBlur(thisForm.Nimi);
	}
	
	if (Katuosoite.length <= 0) 
	{
		errorMsg += "\n - Katuosoite";
		fieldError(thisForm.Katuosoite);
	} else
	{
		fieldBlur(thisForm.Katuosoite);
	}
	
	if (Postinumero.length <= 0) 
	{
		errorMsg += "\n - Postinumero";
		fieldError(thisForm.Postinumero);
	} else
	{
		fieldBlur(thisForm.Postinumero);
	}
	
	if (Postitmp.length <= 0) 
	{
		errorMsg += "\n - Postitoimipaikka";
		fieldError(thisForm.Postitmp);
	} else
	{
		fieldBlur(thisForm.Postitmp);
	}
		
	if (errorMsg.length > 0)
	{
		alert("Täytäthän kaikki pakolliset kentät!\n\nPuuttuvat tiedot:\n" + errorMsg);
		return false;
	}

	
	return true;
}


