function send (type) {
  sd = document.senddata;
  sm = sd.Submit;

  if (checkform (type) == 1) {
    if (sm.length) {
      for (i=0; i<=(sm.length-1); i++) {
        sm[i].disabled = true;
      }
    }
    else {
      sm.disabled = true;
    }
    sd.submit();
  }
}

function checkform (type) {
	if (type == 'question') {
		if (!sd.name.value || sd.name.value.length < 2) {
      alert('Вы забыли ввести имя!');
      sd.name.focus();
      return 0;
    }
		else if (!check_email(sd.mail.value) || sd.mail.value == null || sd.mail.value.length < 6) {
      alert('Введите правильный email!');
      sd.mail.focus();
      return 0;
    }
    else if (!sd.text.value || sd.text.value.length < 10) {
      alert('Вы не ввели текст вопроса!');
      sd.text.focus();
      return 0;
    }
    else {return 1}
	}
	else if (type == 'needs') {
		if (!sd.text.value || sd.text.value.length < 3) {
      alert('Вы не ввели текст!');
      sd.text.focus();
      return 0;
    }
    else {return 1}
	}
}

function check_email(_email) {
  var letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_0123456789";
  var i = 0, j = 0;
  var match = false;
  if (_email.length == 0) return false;
  for (i = 0; i < _email.length; i++) {
    match = false;
    for (j = 0; j < letters.length; j++) {
      if (_email.charAt(i) == letters.charAt(j)) {
        match = true;
        break;
      }
    };
    if (!match) {
      if (_email.charAt(i) == '.')
        match = true;
    };
    if (!match) break;
  };
  if ( i >= _email.length )
    return false;
  if ( _email.charAt(i++) != '@' )
    return false;
  var dotpassed = false;
  while(i < _email.length) {
    var match = false;
    for (j = 0; j < letters.length; j++) {
      if (_email.charAt(i) == letters.charAt(j)) {
      	match = true;
      	break;
      }
    };
    if (!match) {
      if (_email.charAt(i) == '.') {
      	dotpassed = true;
      	match = true;
      };
    };
    if (!match) return false;
    i++;
  };
  if (dotpassed) return true;
  return false;
}
function cancel () {
	var newwin=window.open('cancel.shtml','cancel','menubar=no,location=no,resizable=no,scrollbars=no,status=no,width=500,height=400');
	newwin.focus();
	return false;
}