flag_t="";

function isEmpty(str) 
{
   for (var i = 0; i < str.length; i++)
      if (" " != str.charAt(i))
          return false;
      return true;
}
function SendForm () 
{
  var i, j,flag;
  flag=true;
  var from=0;
  var to=0;
			
  if(isEmpty(document.ord.email.value) || !(/^[\w.-]+@([a-z0-9\-]+\.)+[a-z]{2,6}$/i.test(document.ord.email.value)))
  {
	flag=false;
	document.ord.email.focus();
	alert('Введите E-mail');
  }
  else
  {
	if(isEmpty(document.ord.fio.value))
	{
		flag=false;
	    document.ord.fio.focus();
		alert('Введите Ф.И.О.');
	}
	else
	{
		if(isEmpty(document.ord.phone.value))
		{
				flag=false;
				document.ord.phone.focus();
				alert('Введите телефон');
	    }
		else
		{
						if(document.ord.origs.selectedIndex<1)					
						{ 
								flag=false;
							document.ord.origs.focus();
							alert('Укажите язык оригинала');
						}
							else 
						{
								from=document.ord.origs.selectedIndex;
							if(document.ord.trans.selectedIndex<1)
							{ 
									flag=false;
								document.ord.trans.focus();
								alert('Укажите язык перевода');
							} 
								else
							{
									to=document.ord.trans.selectedIndex;
								if(from==to)
								{
										flag=false;
									document.ord.origs.focus();
									alert('Язык перевода совпадает с языком оригинала');
								}
									else
								{
									if(document.ord.oplata.selectedIndex<1)					
									{ 
											flag=false;
										document.ord.oplata.focus();
										alert('Укажите способ оплаты');
									}
									
								}
							}
						}
	   }
	}
  }
  if(flag)
  valid_fild("kode");			
}
function valid_fild(name)
{
	var url = "/ajax/check_user_mail_form.php";
	var par="";
           
 	var fild_value=$(name).value;	
	par={kode:fild_value};

	// notice the use of a proxy to circumvent the Same Origin Policy.
	new Ajax.Request(url,
	{
			//method:"post",
			parameters: par,
			onLoading:function(){$("mes").show();},
			onSuccess: function(transport){	
		    var data= transport.responseText.evalJSON(true);			
			if(data.text_error.empty() )
			{
               $("ord").submit(); 
			}	
			else
			{
			  $("mes").hide();
			  alert("Ошибочный контрольный код");		  
			}
		 },
		 onFailure: function(){ alert("Запрос не прошел. Повторите попытку…"); }
	});
}