// Вывод случайного числа
function getRandomInt(min, max)
	{
	return Math.floor(Math.random() * (max - min + 1)) + min;
	}
// Вывод подсказки
function box(id) {
	var maskHeight = $(window).height();
	var maskWidth = $(window).width();
	var dialogTop =  (maskHeight/2) - ($('#box-infos'+id).height()/2);
	var dialogLeft = (maskWidth/2) - ($('#box-infos'+id).width()/2);
	$('#box-overlays'+id).css({height:maskHeight, width:maskWidth}).show();
	$('#box-infos'+id).css({top:dialogTop, left:dialogLeft}).show();
}
function boxs(id) {
	var maskHeight = $(window).height();
	var maskWidth = $(window).width();
	var dialogTop =  (maskHeight/2) - ($('#box-infos'+id).height()/2);
	var dialogLeft = (maskWidth/2) - ($('#box-infos'+id).width()/2);
	$('#box-overlays'+id).css({height:maskHeight, width:maskWidth}).show();
	$('#box-infos'+id).css({top:dialogTop, left:dialogLeft}).show();
}
// Обработка отзыва
function showUser(y, k, f, n, str, site)
	{
	document.getElementById("msg").innerHTML="<div style='color:green'>Загрузка...</div>";
		 if (window.XMLHttpRequest){xmlhttp=new XMLHttpRequest();}
		 else{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
		 xmlhttp.onreadystatechange=function()
		   {
		   if (xmlhttp.readyState==4 && xmlhttp.status==200)
		     {
		     if (xmlhttp.responseText == 1){document.getElementById("msg").innerHTML="<div style='color:red'>Пожалуйста, заполните все поля</div>";}
		     else
		     	{
			     if (xmlhttp.responseText == 2)
			     	{
			     	document.getElementById("msg").innerHTML="<div style='color:red'>Отзыв должен содержать более 10 символов</div>";
	        		}
        			else
        				{
        				document.getElementById("contact-form").innerHTML=xmlhttp.responseText;
        				}
        			}
		     	}
		   }
		 xmlhttp.open("GET",site+"/wp-content/themes/diplomers/inc-ajax/feedback.php?y="+encodeURIComponent(y)+"&k="+encodeURIComponent(k)+"&f="+encodeURIComponent(f)+"&n="+encodeURIComponent(n)+"&q="+encodeURIComponent(str)+"&rx="+Math.random(),true);
		 xmlhttp.send();
	}

function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
  {
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {    return unescape(y);
    }
  }
}

function setCookie (name, value, expires, path, domain, secure) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + expires);
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + exdate.toUTCString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "");
}

/*
function check_cart()
{
	var order=getCookie("order");
	document.getElementById("cartNotify").innerHTML='<a href="/forma-zakaza-raboti/"></a>';
	$('#cartNotify').show();
}
*/

// Добавить в корзину
function add(article, price, site)
{
document.getElementById("cart").innerHTML="Загрузка...";
var rand=getRandomInt('1', '1000');
var order=getCookie("order");
if (window.XMLHttpRequest){xmlhttp=new XMLHttpRequest();}
else{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
xmlhttp.onreadystatechange=function()
	 {
	 if (xmlhttp.readyState==4 && xmlhttp.status==200)
	   {
	   document.getElementById("cart").innerHTML=xmlhttp.responseText;
	   document.getElementById("cNotify").innerHTML="<div id='in-basket'>Выбранная работа добавлена в <a href='/forma-zakaza-raboti/' style='color:#fff;'>Вашу корзину</a>!</div>";
		 $('#cNotify').show(); 
		 $('#cNotify').delay(3000).fadeOut('normal');
	   }
	 }
xmlhttp.open("GET",site+"/wp-content/themes/diplomers/inc-ajax/handler-add.php?order="+order+"&article="+article+"&price="+price+"&"+rand+"="+rand+"&rx="+Math.random(),true);
xmlhttp.send();
return false;
}
// Удаление из корзины
function dele(id,site)
{
var sites=site;
var rand=getRandomInt('1', '1000');
var order=getCookie("order");
if (window.XMLHttpRequest){xmlhttp=new XMLHttpRequest();}
else{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
xmlhttp.onreadystatechange=function()
	 {
	 if (xmlhttp.readyState==4 && xmlhttp.status==200)
	   {
	   document.getElementById("carts").innerHTML=xmlhttp.responseText;
	   }
	 }
xmlhttp.open("GET",sites+"/wp-content/themes/diplomers/inc-ajax/handler-delete.php?order="+order+"&id="+id+"&"+rand+"="+rand+"&rx="+Math.random(),true);
xmlhttp.send();
return false;
}
// Оформление заказа
function handler_form(n,e,p,m,s,k,site)
{
    var sites=site;
	var order=getCookie("order");
	var rand=getRandomInt('1', '1000');
	if (window.XMLHttpRequest){xmlhttp=new XMLHttpRequest();}
	else{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
	    {
	    boxs('1');
        document.getElementById("info-order").innerHTML=xmlhttp.responseText;
        var maskHeight = $(window).height();
	    var maskWidth = $(window).width();
	    var dialogTop =  (maskHeight/2) - ($('#box-infos'+id).height()/2);
	    var dialogLeft = (maskWidth/2) - ($('#box-infos'+id).width()/2);
	    $('#box-overlays'+id).css({height:maskHeight, width:maskWidth}).show();
	    $('#box-infos'+id).css({top:dialogTop, left:dialogLeft}).show();
	    }
	  }
	xmlhttp.open("GET",sites+"/wp-content/themes/diplomers/inc-ajax/handler-shopping.php?n="+encodeURIComponent(n)+"&e="+encodeURIComponent(e)+"&p="+encodeURIComponent(p)+"&m="+encodeURIComponent(m)+"&s="+encodeURIComponent(s)+"&k="+encodeURIComponent(k)+"&order="+order+"&"+rand+"="+rand+"&rx="+Math.random(),true);
	xmlhttp.send();
	return false;
}
// Поиск
function searchajax(s,c,site)
{
	document.getElementById("list-cat").innerHTML="<div style='color:green'>Загрузка...</div>";
    var sites=site;
	var order=getCookie("order");
	var rand=getRandomInt('1', '1000');
	if (window.XMLHttpRequest){xmlhttp=new XMLHttpRequest();}
	else{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
	    {
	    document.getElementById("search-none").innerHTML="";  
        document.getElementById("list-cat").innerHTML=xmlhttp.responseText;
	    }
	  }
	xmlhttp.open("GET",sites+"/wp-content/themes/diplomers/inc-ajax/handler-search.php?s="+encodeURIComponent(s)+"&c="+encodeURIComponent(c)+"&"+rand+"="+rand+"&rx="+Math.random(),true);
	xmlhttp.send();
}
// FAQ

function faq(c,site)
{
	document.getElementById("text-l").innerHTML="<div style='color:green'>Загрузка...</div>";
    var sites=site;
	var rand=getRandomInt('1', '1000');
	if (window.XMLHttpRequest){xmlhttp=new XMLHttpRequest();}
	else{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
	    {
        document.getElementById("text-l").innerHTML=xmlhttp.responseText;
	    }
	  }
	xmlhttp.open("GET",sites+"/wp-content/themes/diplomers/inc-ajax/handler-faq.php?c="+c+"&"+rand+"="+rand+"&rx="+Math.random(),true);
	xmlhttp.send();
	return false;
}
// Онлайн заказ
function onlineorder(form,site)
{
    var sites=site;
	var rand=getRandomInt('1', '1000');
	if (window.XMLHttpRequest){xmlhttp=new XMLHttpRequest();}
	else{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
	    {
        document.getElementById("onlinemsg").innerHTML=xmlhttp.responseText;
	    }
	  }
	xmlhttp.open("GET",sites+"inc-ajax/handler-online-order.php?"+rand+"="+rand+"&rx="+Math.random(),true);
	xmlhttp.send();
	return false;
}
// Онлайн
function schets(s,site)
  {
	document.getElementById("schet").innerHTML="<div style='color:green'>Загрузка...</div>";
    var sites=site;
	var rand=getRandomInt('1', '1000');
	if (window.XMLHttpRequest){xmlhttp=new XMLHttpRequest();}
	else{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
	    {
        document.getElementById("schet").innerHTML=xmlhttp.responseText;
	    }
	  }
	xmlhttp.open("GET",sites+"/inc-ajax/handler-schet.php?s="+s+"&"+rand+"="+rand+"&rx="+Math.random(),true);
	xmlhttp.send();

}

// работа с формой "Вид работы"
function sss(t)
    {
    var arr = t.split(/[:]/);
    if(arr[0] == 'Реферат')
        {
        document.getElementById('n5').style.display='block';
        document.getElementById('txt').style.opacity=1;
        document.getElementById('txt').style.filter='alpha(opacity=100)';
        document.getElementById("txt").disabled=false;
        }
    else
        {
        document.getElementById('n5').style.display='none';
        if(arr[1] == 'true')
            {
            document.getElementById('txt').style.opacity=0.4;
            document.getElementById('txt').style.filter='alpha(opacity=40)';
            document.getElementById("txt").disabled=true;
            document.getElementById("txt").value="";
            }
        else
            {
            document.getElementById('txt').style.opacity=1;
            document.getElementById('txt').style.filter='alpha(opacity=100)';
            document.getElementById("txt").disabled=false;
            }
        document.getElementById('n4').value=arr[0];
        }
    }

// работа с формой "тип работы"
function ttt(t)
    {
    var arr = t.split(/[:]/);
    if(arr[1] == 'false')
        {
        document.getElementById('txt2').style.opacity=0.4;
        document.getElementById('txt2').style.filter='alpha(opacity=40)';
        document.getElementById("txt2").disabled=true;
        document.getElementById("txt2").value="";
        }
    else
        {
        document.getElementById('txt2').style.opacity=1;
        document.getElementById('txt2').style.filter='alpha(opacity=100)';
        document.getElementById("txt2").disabled=false;
        }
    document.getElementById('n4').value=arr[0];
    }

// Проверка на капчу на странице заказа
function cap(n1,n2,n3,n4,n5,type,site)
    {
    var sites=site;
    var rand=getRandomInt('1', '1000');
	if (window.XMLHttpRequest){xmlhttp=new XMLHttpRequest();}
	else{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
	    {
	    if(xmlhttp.responseText == 1){document.getElementById('form').submit();}
        else{document.getElementById("msg-form").innerHTML=xmlhttp.responseText;}
	    }
	  }
	xmlhttp.open("GET",sites+"/wp-content/themes/diplomers/inc-ajax/handler-capcha.php?n1="+n1+"&n2="+n2+"&n3="+n3+"&n4="+n4+"&n5="+n5+"&t="+encodeURIComponent(type)+"&"+rand+"="+rand+"&rx="+Math.random(),true);
	xmlhttp.send();
    }

// Проверка на капчу на странице авторам
function capavt(a1,a2,a3,a4,type,site)
    {
    var sites=site;
    var rand=getRandomInt('1', '1000');
	if (window.XMLHttpRequest){xmlhttp=new XMLHttpRequest();}
	else{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
	    {
	    if(xmlhttp.responseText == 1){document.getElementById('form').submit();}
        else{document.getElementById("msg-form").innerHTML=xmlhttp.responseText;}
	    }
	  }
	xmlhttp.open("GET",sites+"/wp-content/themes/diplomers/inc-ajax/handler-capcha-avt.php?a1="+a1+"&a2="+a2+"&a3="+a3+"&a4="+a4+"&t="+encodeURIComponent(type)+"&"+rand+"="+rand+"&rx="+Math.random(),true);
	xmlhttp.send();
    }

