function check()
{
  if((document.getElementById('author').value=='')||(document.getElementById('author').value==null))
  {

   $("#dialog").html("Ваше ім'я?");
$( "#dialog"  ).dialog({
			autoOpen: false,
			show: "slide",
			hide: "slide",
            resizable: false,
            title:"Введіть ім'я",
            height: 70,
            minHeight: 70,
            modal:true
            })    
$( "#dialog"  ).dialog( "open" );
    document.getElementById('author').focus();
    return;
  }else
  {
  if((document.getElementById('mail').value=='')||(document.getElementById('mail').value==null))
  {
    $("#dialog").html('Не правильно вказаний Е-mail.');
$( "#dialog"  ).dialog({
			autoOpen: false,
			show: "slide",
			hide: "slide",
            resizable: false,
            title:'Помилка в E-mail',
            height: 70,
            minHeight: 70,
            modal:true
            })    
$( "#dialog"  ).dialog( "open" );
    document.getElementById('mail').focus();
    return true;
  }
  else
  {
  
  var email = document.getElementById('mail');
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(email.value)) {
 $("#dialog").html('Не правильно вказаний Е-mail.');
$( "#dialog"  ).dialog({
			autoOpen: false,
			show: "slide",
			hide: "slide",
            resizable: false,
            title:'Помилка в E-mail',
            height: 70,
            minHeight: 70,
            modal:true
            })    
$( "#dialog"  ).dialog( "open" );
email.focus;
return false; }

else
{
if((document.getElementById('text').value==''))
  {
    $("#dialog").html('Введіть повідомлення.');
$( "#dialog"  ).dialog({
			autoOpen: false,
			show: "slide",
			hide: "slide",
            resizable: false,
            title:'Введіть повідомлення',
            height: 70,
            minHeight: 70,
            modal:true
            })    
$( "#dialog"  ).dialog( "open" );
    document.getElementById('text').focus();
    return true;
  }
  else
  {
  //////////proverca CAPTCHA//////////////////////
  
 var cap=$("#checkcode").val();
 
if((cap=='')||(cap==null)){
 $("#dialog").html('Введіть перевірочний код.');
$( "#dialog"  ).dialog({
			autoOpen: false,
			show: "slide",
			hide: "slide",
            resizable: false,
            title:'Введіть перевірочний код',
            height: 70,
            minHeight: 70,
            modal:true
            })    
$( "#dialog"  ).dialog( "open" );
$("#checkcode").focus();}else
   {
    // Создать URL для подключения
  var url = "http://www.kpu.km.ua/pages/ajaxcheck/"+escape(cap);
  // Открыть соединение с сервером
  
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = updatePage;
  xmlHttp.send(null);
   }
  
  //////////proverca CAPTCHA//////////////////////
  }
}

  }
  
    //document.getElementById('myform').submit(); return false;
    
}
}

function updatePage() {
    
  if (xmlHttp.readyState == 4) {
    
    var response = xmlHttp.responseText;

   if(response=='0'){
    $("#res").html('Введіть правильний код');
	
   }
   if(response=='1'){//$("#myform").submit(); return false;
  $name=$('#author').val();
  $text=$('#text').val();
  $mail=$('#mail').val();
  $news_id=$('#news_id').val();
       $.ajax
	       ({
	         url:	"http://www.kpu.km.ua/pages/ajaxsendmail",
	         type:	'POST',
			 data: "name="+$name+"&mail="+$mail+"&text="+$text+"&news_id="+$news_id,
	         success:function(response, code)
			 { 
	               if ((code==200)||(code=='success'))
				   {
				    $("#author").val('');
				   $("#mail").val('');
				   $("#text").val('');
				   $("#checkcode").val('');
				   
	             $("#dialog").html(response);
$( "#dialog"  ).dialog({
			autoOpen: false,
			show: "slide",
			hide: "slide",
            resizable: false,
            title:'Інформація',
            height: 120,
            minHeight: 120,
            modal:true
            })    
$( "#dialog"  ).dialog( "open" );
$("#res").html("");
xajax_refresh_captcha();
	               }else
				   {
	                 alert('Сервер вернул ошибку: ' + code);
					 $("#res").html("");
	               }
	         }
           });
   
   
   
   }
  }
  
  else{
    
  $("#res").html("<img src='http://www.kpu.km.ua/img/ajax-loader.gif'>");
  
  }
}


function checkquestion()
{
  if((document.getElementById('author').value=='')||(document.getElementById('author').value==null))
  {

   $("#dialog").html("Ваше ім'я?");
$( "#dialog"  ).dialog({
			autoOpen: false,
			show: "slide",
			hide: "slide",
            resizable: false,
            title:"Введіть ім'я",
            height: 70,
            minHeight: 70,
            modal:true
            })    
$( "#dialog"  ).dialog( "open" );
    document.getElementById('author').focus();
    return;
  }else
  {
  if((document.getElementById('mail').value=='')||(document.getElementById('mail').value==null))
  {
    $("#dialog").html('Не правильно вказаний Е-mail.');
$( "#dialog"  ).dialog({
			autoOpen: false,
			show: "slide",
			hide: "slide",
            resizable: false,
            title:'Помилка в E-mail',
            height: 70,
            minHeight: 70,
            modal:true
            })    
$( "#dialog"  ).dialog( "open" );
    document.getElementById('mail').focus();
    return true;
  }
  else
  {
  
  var email = document.getElementById('mail');
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(email.value)) {
 $("#dialog").html('Не правильно вказаний Е-mail.');
$( "#dialog"  ).dialog({
			autoOpen: false,
			show: "slide",
			hide: "slide",
            resizable: false,
            title:'Помилка в E-mail',
            height: 70,
            minHeight: 70,
            modal:true
            })    
$( "#dialog"  ).dialog( "open" );
email.focus;
return false; }

else
{
if((document.getElementById('text').value==''))
  {
    $("#dialog").html('Введіть повідомлення.');
$( "#dialog"  ).dialog({
			autoOpen: false,
			show: "slide",
			hide: "slide",
            resizable: false,
            title:'Введіть повідомлення',
            height: 70,
            minHeight: 70,
            modal:true
            })    
$( "#dialog"  ).dialog( "open" );
    document.getElementById('text').focus();
    return true;
  }
  else
  {
  //////////proverca CAPTCHA//////////////////////
  
 var cap=$("#checkcode").val();
 
if((cap=='')||(cap==null)){
 $("#dialog").html('Введіть перевірочний код.');
$( "#dialog"  ).dialog({
			autoOpen: false,
			show: "slide",
			hide: "slide",
            resizable: false,
            title:'Введіть перевірочний код',
            height: 70,
            minHeight: 70,
            modal:true
            })    
$( "#dialog"  ).dialog( "open" );
$("#checkcode").focus();}else
   {
    // Создать URL для подключения
  var url = "http://www.kpu.km.ua/pages/ajaxcheck/"+escape(cap);
  // Открыть соединение с сервером
  
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = updatePage1;
  xmlHttp.send(null);
   }
  
  //////////proverca CAPTCHA//////////////////////
  }
}

  }
  
    //document.getElementById('myform').submit(); return false;
    
}
}

function updatePage1() {
    
  if (xmlHttp.readyState == 4) {
    
    var response = xmlHttp.responseText;

   if(response=='0'){
    $("#res").html('Введіть правильний код');
	
   }
   if(response=='1'){//$("#myform").submit(); return false;
  $name=$('#author').val();
  $text=$('#text').val();
  $mail=$('#mail').val();
  $news_id=$('#news_id').val();
       $.ajax
	       ({
	         url:	"http://www.kpu.km.ua/pages/ajaxaddquestion",
	         type:	'POST',
			 data: "name="+$name+"&mail="+$mail+"&text="+$text,
	         success:function(response, code)
			 { 
	               if ((code==200)||(code=='success'))
				   {
				     $("#author").val('');
				   $("#mail").val('');
				   $("#text").val('');
				   $("#checkcode").val('');
	             $("#dialog").html(response);
$( "#dialog"  ).dialog({
			autoOpen: false,
			show: "slide",
			hide: "slide",
            resizable: false,
            title:'Інформація',
            height: 120,
            minHeight: 120,
            modal:true
            })    
$( "#dialog"  ).dialog( "open" );
$("#res").html("");
xajax_refresh_captcha();
	               }else
				   {
	                 alert('Сервер вернул ошибку: ' + code);
					 $("#res").html("");
	               }
	         }
           });
   
   
   
   }
  }
  
  else{
    
  $("#res").html("<img src='http://www.kpu.km.ua/img/ajax-loader.gif'>");
  
  }
}

