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);

	thisForm.Nimi.value = Nimi;
	thisForm.Viesti.value = Viesti;
	
	/*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 (Viesti.length <= 0) 
	{
		errorMsg += "\n - Viestisi";
		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 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;
}

