function formURL()
{
new Ajax.Request('/admin/ajaxURL',
  {
    method:'post',
	parameters: { text: $('title_h1').value.toLowerCase() },
    onSuccess: function(transport){
      var response = transport.responseText || "title_h1";
      $('url').value=response.toLowerCase();
    },
    onFailure: function(){ alert('Something went wrong with ajax...') }
  });
}

function check_contacts_form() {
	if(!check_is_empty(document.getElementById('txt')) || !check_email(document.getElementById('email')))
		{
			if(!check_email(document.getElementById('email')) || !check_is_empty(document.getElementById('txt')))
			return false;
		}
	else
		return true;	
}

function check_email(email)
{
	var reg = new RegExp("[0-9a-z_]+@[0-9a-z_^.]+\\.[a-z]", 'i');
	if (!reg.test(email.value)) {
		document.getElementById('email_error').style.display = 'block';
		return false;
	}
	else{
		document.getElementById('email_error').style.display = 'none';
		return true;
	}
}



function check_is_empty(field)
{
	if (field.value=='') {
		document.getElementById('text_error').style.display = 'block';
		return false;
	}
	else{
		document.getElementById('text_error').style.display = 'none';
		return true;
	}
}

function check_question_form() {
	if(!check_is_empty_question(document.getElementById('txt')) || !check_email_question(document.getElementById('email')) || !check_fio_question(document.getElementById('fio')))
		{
			if(!check_email_question(document.getElementById('email')) || !check_fio_question(document.getElementById('fio')) || !check_is_empty_question(document.getElementById('txt')))
			{
				if(!check_fio_question(document.getElementById('fio')) || !check_email_question(document.getElementById('email')) ||  !check_is_empty_question(document.getElementById('txt')))
				{
					if(!check_fio_question(document.getElementById('fio')) || !check_is_empty_question(document.getElementById('txt'))|| !check_email_question(document.getElementById('email')))
					return false;
				}
				else
					return false;
			}
			else
				return false;
		}
	else
		return true;	
}

function check_email_question(email)
{
	var reg = new RegExp("[0-9a-z_]+@[0-9a-z_^.]+\\.[a-z]", 'i');
	if (!reg.test(email.value)) {
		document.getElementById('email_error').style.display = 'block';
		return false;
	}
	else{
		document.getElementById('email_error').style.display = 'none';
		return true;
	}
}

function check_is_empty_question(field2)
{
	if (field2.value=='') {
		document.getElementById('text_error').style.display = 'block';
		return false;
	}
	else{
		document.getElementById('text_error').style.display = 'none';
		return true;
	}
}

function check_fio_question(field1)
{
	if (field1.value=='') {
		document.getElementById('fio_error').style.display = 'block';
		return false;
	}
	else{
		document.getElementById('fio_error').style.display = 'none';
		return true;
	}
}





function check_zakaz_form() {
	$('fio_error').style.display = 'block';
	if(!check_is_empty_zakaz($('fio'))){$('fio_error').style.display = 'block';}
	else {$('fio_error').style.display = 'none';}

	if(!check_is_empty_zakaz($('phone1'))){$('phone_error').style.display = 'block';}
	else {$('phone_error').style.display = 'none';}

	if(!check_captcha($('captcha'))){$('captcha_error').style.display = 'block';}
	else {$('captcha_error').style.display = 'none';}
	
	if(check_captcha($('captcha')) && check_is_empty_zakaz($('fio')) && check_is_empty_zakaz($('phone1')))
	{return false;}
	else
	{return false;}
}


function check_is_empty_zakaz(field)
{
	if (field.value=='') {
		return false;
	}
	else{
		return true;
	}
}

function check_captcha(field)
{
	var res=false;
	
new Ajax.Request('http://som.od.ua/home/captcha_req/', {
			method:'post',
			asynchronous: false,
			parameters: { captcha: field.value },
			onSuccess: function(transport){
			var response = transport.responseText || "no response text";
				if (response==0) {
					res = false;
				}
				else{
					res = true;
				}
			},
			onFailure: function(){ alert('Запрос не прошел. Повторите попытку...') } 
	});
	return res;
}