function numeric (str) {return /^[0-9-\+\(\)\s]+z/.test(str + "z");}
function text (str) {return /[0-9_;:'!~?=+<|>]/g.test(str);}
function mail (str) {return /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/.test(str);}

function checkForm () {
var title; var elem; var dutyField = "Пожалуйста введите "; var wrongField = "Неверное значение поля "; var check = true;

function checkError (field, str) {document.getElementById("alert").innerHTML = str; check = false;}

document.getElementById("alert").innerHTML = "";

if (check) {title = "E-mail";
elem = document.preview.email.value;
if (elem.length == 0) checkError('email', dutyField + title);
else if (!mail(elem)) checkError('email', wrongField + title); }

if (check) {title = "Полное имя";
elem = document.preview.fname.value;
if (elem.length == 0) checkError('name', dutyField + title);
else if (text(elem)) checkError('name', wrongField + title); }

if (check) {title = "Телефон";
elem = document.preview.phone.value;
if (elem.length == 0) checkError('phone', dutyField + title);
else if (!numeric(elem)) checkError('phone', wrongField + title); }

// if (check) {elem = document.preview.country.value;
// if (elem.length == 0) checkError('country', "Введите страну"); }

// if (check) {elem = document.preview.adults.value;
// if (elem.length == 0) checkError('adults', "Сколько взрослых?"); }

// if (check) {elem = document.preview.children.value;
// if (elem.length == 0) checkError('children', "Сколько детей?"); }

 


if (check) {document.preview.submit(); }
return check; }