var fields = new Array("family", "name", "otchestvo", "postal_code", "address", "tel", "email", "info");
var fields_required = new Array("family", "name", "address", "email");
var required_show = new Array("Фамилию получателя", "Имя получателя", "Адрес", "E-mail");

function checkout(flag) {
	var x;
	for (x = 0; x < fields.length; x++) {
		if (fields[x].length == 0)
			continue;

	  var elm = document.getElementById(fields[x]);

		if(!elm)
			continue;

		if (!flag) {
			elm.disabled = false;
		} else {
			elm.disabled = true;
		}

	}

	var div_continue = document.getElementById("continue");
	var div_checkout = document.getElementById("checkout");

	if (!flag) {
			div_continue.style.display = "";
			div_checkout.style.display = "none";
	} else {
			div_continue.style.display = "none";
			div_checkout.style.display = "";
	}

	return false;
}

function checkEmail()
{
  var email = document.getElementById("email");

	if(email) {
	  if (! (/^\w+[-_\.]*\w+@\w+-?\w+\.[a-z]{2,4}$/.test(email.value)) ) {
    	alert("Введите правильный e-mail адрес");
    	email.focus();
    	return false;
  	}
  }

 	checkout(true);
}

function checkForm() {
	var x;

	for (x = 0; x < fields_required.length; x++) {

	if (fields_required[x].length == 0)
			continue;

  	var elm = document.getElementById(fields_required[x]);

		if(!elm)
			continue;

		if (elm.value == "" ) {
			alert('Пожалуйста, введите ' + required_show[x]);
			elm.focus();
			return false;
		}
	}
	checkEmail();
}

