// JavaScript Document


function validate() {
	var why = "";
	
	if (document.orderform.name.value == "") {
		why += "Введите Фамилие Имя Отчество\n";
		document.orderform.name.style.backgroundColor='#cccccc';
	} else {
		document.orderform.name.style.backgroundColor='';
	}
	
	if (document.orderform.post.value == "") {
		why += "Введите Почтовый индекс\n";
		document.orderform.post.style.backgroundColor='#cccccc';
	} else {
		document.orderform.post.style.backgroundColor='';
	}
	
	if (document.orderform.city.value == "") {
		why += "Введите Город\n";
		document.orderform.city.style.backgroundColor='#cccccc';
	} else {
		document.orderform.city.style.backgroundColor='';
	}
	
	if (document.orderform.address1.value == "") {
		why += "Введите Адрес\n";
		document.orderform.address1.style.backgroundColor='#cccccc';
	} else {
		document.orderform.address1.style.backgroundColor='';
	}
	
	if (document.orderform.phone.value == "") {
		why += "Введите Телефон\n";
		document.orderform.phone.style.backgroundColor='#cccccc';
	} else {
		document.orderform.phone.style.backgroundColor='';
	}
	
	if (document.orderform.email.value == "") {
		why += "Введите Адрес эл. почты\n";
		document.orderform.email.style.backgroundColor='#cccccc';
	} else {
		document.orderform.email.style.backgroundColor='';
	}
	
	if (!isEmailAddress(document.orderform.email.value) && document.orderform.email.value!="") {
		why += "Введенный Адрес эл. почты неверен\n";
		document.orderform.email.style.backgroundColor='#cccccc';
	} else {
		document.orderform.email.style.backgroundColor='';
	}
	
	if (document.orderform.other.value == "" && document.orderform.source.value == "-1") {
		why += "Введите с какого вы форума\n";
		document.orderform.other.style.backgroundColor='#cccccc';
	} else {
		document.orderform.other.style.backgroundColor='';
	}

	if (document.orderform.nick.value == "") {
		why += "Введите Свое имя на форуме\n";
		document.orderform.nick.style.backgroundColor='#cccccc';
	} else {
		document.orderform.nick.style.backgroundColor='';
	}

	
	if (document.orderform.request.value == "") {
		why += "Введите Запрос\n";
		document.orderform.request.style.backgroundColor='#cccccc';
	} else {
		document.orderform.request.style.backgroundColor='';
	}
	
    if (why != "") {
       alert(why);
	   return true;
    } else
	{
		document.orderform.submit();
		return true
	}
}

function isEmailAddress (string)
{
	var addressPattern =  /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	return addressPattern.test(string);
}

function disableArea () 
{
	if ( document.orderform.source.value == "-1" ) {
		document.orderform.other.disabled = false;
		document.orderform.other.focus();
	} else {
		document.orderform.other.disabled = true;
		document.orderform.other.value = '';
		document.orderform.other.style.backgroundColor='';
	}
}
