function validEmail(theEntry) {
  badEntry = false
  invalidChars = " /:,;"
  if (theEntry == "") { 
    badEntry = true
  }
  for (i=0; i < 5; i++)  {
    badChar = invalidChars.charAt(i)
    if (theEntry.indexOf(badChar,0) > -1) {
      badEntry = true
    }
  }  
  atsignLoc = theEntry.indexOf("@",1)
  if (atsignLoc == -1) {
    badEntry = true
  }     
  if (theEntry.indexOf("@",atsignLoc+1) > -1) {
    badEntry = true
  }
  dotLoc = theEntry.indexOf(".",atsignLoc)
  if (dotLoc == -1) {
    badEntry = true
  }
  if (dotLoc+3 > theEntry.length) {
    badEntry = true
  }
  return badEntry
}

function ValidateForm(oForm) {
  var oFocusItem = null;
  var bPassed = true; 
  var oItems = oForm.elements;
  for (var i = 0; i < oItems.length; i++) {
    if ( (oItems.item(i).className.indexOf('requiredfield') > -1) ) {
      if ( oItems.item(i).value.length < 1) { 
        oItems.item(i).className += ' invalidfield';
        if ( !oFocusItem ) oFocusItem = oItems.item(i);
        bPassed = false;
      } else if ( oItems.item(i).className.indexOf(' invalidfield') > -1) {
        oItems.item(i).className = 'requiredfield';
      }
    }
    if ( (oItems.item(i).className.indexOf('requireddigit') > -1) ) {
      re = /^\d{1,10}$/;
      if (!re.test(oItems.item(i).value)){
        oItems.item(i).className += ' invaliddigit';
        if ( !oFocusItem ) oFocusItem = oItems.item(i);
        bPassed = false;
        sMessage = 'You must fill in the required fields.';
      } else if ( oItems.item(i).className.indexOf(' invaliddigit') > -1) {
        oItems.item(i).className = 'requireddigit';
      }
    }
  }
  if (oForm.email && (oForm.email.className.indexOf('requiredfield') > -1) && validEmail(oForm.email.value)) {
    oForm.email.className += ' invalidfield';
    if ( !oFocusItem ) oFocusItem = oForm.email;
    bPassed = false;
  };
  if (oForm.to_email && (oForm.to_email.className.indexOf('requiredfield') > -1) && validEmail(oForm.to_email.value)) {
    oForm.to_email.className += ' invalidfield';
    if ( !oFocusItem ) oFocusItem = oForm.to_email;
    bPassed = false;
  };
  if ( !bPassed ) {
    if ( oFocusItem ) oFocusItem.focus();
  };
  return bPassed;
}

function SetVS(val){
  if (val == 0) {
    document.getElementById('edt1').style.display = 'none'; 
    document.getElementById('edt2').style.display = 'none'; 
    document.getElementById('txt1').style.display = 'none'; 
    document.getElementById('txt2').style.display = 'none'; 
  } else {
    document.getElementById('edt1').style.display = 'block';
    document.getElementById('edt2').style.display = 'block';
    document.getElementById('txt1').style.display = 'block';
    document.getElementById('txt2').style.display = 'block';
  }
}

function ValidateVoting(oForm){
  var res = false;
  if (oForm.vote && (oForm.vote.length > 0))
    for (var i=0; i<oForm.vote.length; i++)
      if (oForm.vote[i].checked){
        res = true;
        break;
      }
  if (!res) alert ("Пожалуйста, укажите Ваш вариант ответа.");
  return res;
}
