function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
  {alert(alerttxt);return false;}
else {return true}
}
}

function validate_phone(field,alerttext)
{
with (field)
{
if (isNaN(value)||value.length<6)
    {alert(alerttext); return false;}
else {return true;}
}
}

function validate_email(field,alerttxt)
{
with (field)
{
apos=value.indexOf("@");
dotpos=value.lastIndexOf(".");
if (apos<1||dotpos-apos<2) 
  {alert(alerttxt);return false;}
else {return true;}
}
}

function piilota()
{
document.getElementById('remove').style.display='none';
return true;
}

function nayta()
{
document.getElementById('remove').style.display='';
return true;
}
function validate_form(thisform)
{
with (thisform)
{
if (validate_required(nimi,"Unohdit täyttää nimen/yrityksen!")==false)
  {nimi.focus();return false;}
if (validate_required(puhelin,"Unohdit täyttää puhelinnumeron!")==false)
  {puhelin.focus();return false;}
if (validate_phone(puhelin,"Puhelinnumero väärin täytetty! Vähimmäispituus 6 numeroa, sallitut numerot \"0123456789\"")==false)
  {puhelin.focus();return false;}
if (validate_required(sahkoposti,"Unohdit täyttää sähköpostiosoitteen!")==false)
  {sahkoposti.focus();return false;}
if (validate_email(sahkoposti,"Sähköpostiosoite on virheellinen!")==false)
  {sahkoposti.focus();return false;}
if (validate_required(tiedot,"Unohdit täyttää työn tiedot!")==false)
  {tiedot.focus();return false;}
}
}
