// JavaScript Document
function checksubscrform(frm){
	if (check_email(frm.email.value))
		return true;
	else {
		alert ("Введен не корректный EMail, пожалуйста повторите ввод.");
		frm.email.focus();
		return false;
	}
}

function drop_spaces(str) {
    var newstr = trim(str);
    return newstr.replace(/(s)+/g, ""); 
}

function check_email(email) {
//    var template = /^[A-Za-z0-9](([_.-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([.-]?[a-zA-Z0-9]+)*).([A-Za-z])$/;
	var template = /[a-z0-9]+@[a-z0-9]+.[a-z0-9]+/i;
    email = drop_spaces(email);
    if (email.match(template)) {
        return true;
    }
    return false; 
}

function trim(str) {
    var newstr = str.replace(/^s*(.+?)s*$/, "$1");
    if (newstr == " ") {
        return "";
    }
    return newstr;
}

function checkofficeform(){
    if (document.office.organization.value == ""){
      message = "Пожалуйста заполните поле `Организация`\n";
	  alert (message);
	  document.office.organization.focus();
	  return false;
	}
    if (document.office.fname.value == ""){
      message = "Пожалуйста заполните поле `Фамилия`\n";
	  alert (message);
	  document.office.fname.focus();
	  return false;
	}
    if (document.office.name.value == ""){
      message = "Пожалуйста заполните поле `Имя`\n";
	  alert (message);
	  document.office.name.focus();
	  return false;
	}
    if (document.office.sname.value == ""){
      message = "Пожалуйста заполните поле `Отчество`\n";
	  alert (message);
	  document.office.sname.focus();
	  return false;
	}
    if (document.office.phone.value == ""){
      message = "Пожалуйста заполните поле `Контактный телефон`\n";
	  alert (message);
	  document.office.phone.focus();
	  return false;
	}
    if (document.office.question.value == ""){
      message = "Пожалуйста укажите примерную тему консультации\n";
	  alert (message);
	  document.office.question.focus();
	  return false;
	}
}
