function formselect(n)
{
  if (document.getElementById("TOODE"+n).checked) {
    document.getElementById("KOGUS"+n).style.display="inline";
    document.getElementById("KOGUS"+n).select();
    document.getElementById("KOGUS"+n).focus();
  } else if (!document.getElementById("TOODE"+n).checked) {
    document.getElementById("KOGUS"+n).style.display="none";
  }
  return false;
}

function trim(str)
{
  return str.replace(/^\s+|\s+$/g,'');
}

function isEmpty(formElement, message) {
  formElement.value = trim(formElement.value);
  
  _isEmpty = false;
  if (formElement.value == '') {
    _isEmpty = true;
    alert(message);
    formElement.focus();
  }
  
  return _isEmpty;
}

function echeck(str) {
  var at="@"
  var dot="."
  var lat=str.indexOf(at)
  var lstr=str.length
  var ldot=str.indexOf(dot)
  if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
     return false
  }
  if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
      return false
  }
   if (str.indexOf(at,(lat+1))!=-1){
      return false
   }
   if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
      return false
   }
   if (str.indexOf(dot,(lat+2))==-1){
      return false
   }
   if (str.indexOf(" ")!=-1){
      return false
   }

    return true          
}

function checkForm() {
  with (window.document.tellimisvorm) {
    if (isEmpty((NIMI), 'Palun sisestage nimi')) {
      NIMI.focus();
      return false;
    } else if (isEmpty((EPOST), 'Palun sisestage e-posti aadress')) {
      EPOST.focus();
      return false; 
    } else if (EPOST.value != '' && echeck(EPOST.value)==false) {
      alert('Palun sisestage korrektne e-posti aadress');
      EPOST.focus();
      return false; 
    } else {
//      cleardelay = setTimeout('clearForm()',1000);
      return true;
    }
  }
}

function clearForm() {
  window.document.tellimisvorm.NIMI.value = '';
  window.document.tellimisvorm.EPOST.value = '';
  window.document.tellimisvorm.KOMM.value = '';
}


