function makeRequest(url, evt, id) {
var http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml; charset=windows-1251');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Ошибка! Невозможно создать экземпляр класса XMLHTTP ');
return false;
}
http_request.onreadystatechange = function() { alertContents(http_request, evt, id); };
http_request.open('GET', url, true);
http_request.setRequestHeader("Accept-Language", "ru, en");
http_request.setRequestHeader("Accept-Charset", "windows-1251");
http_request.send(null);
}
function alertContents(http_request, evt, id) {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
if (evt == 1) {
               var stat_data = http_request.responseText;
               if (stat_data != "<b>er</b>") { document.getElementById('logauth').innerHTML = http_request.responseText;
               } else alert("Неверный логин или пароль.");
              }
if (evt == 2) { makeRequest('/data_shop/basket.php?ti='+Math.random(), 3) }
if (evt == 3) {document.getElementById('basket').innerHTML = http_request.responseText;}
if (evt == 4) {document.getElementById('c'+id).innerHTML = http_request.responseText;}
} else {
if (evt == 1) {alert("Произошла ошибка загрузки. Повторите попытку позже. error 1");}
if (evt == 2) {alert("Произошла ошибка загрузки. Повторите попытку позже. error 2");}
if (evt == 3) {alert("Произошла ошибка загрузки. Повторите попытку позже. error 3");}
}
}
}


// авторизация пользователя
function authl()
{
if(document.auth.login.value.length==0 ||document.auth.pass.value.length==0) { alert('Укажите Ваш логин и пароль.'); return; };
login = document.auth.login.value;
pass = document.auth.pass.value;
makeRequest('/data_shop/login.php?login='+login+'&pass='+pass+'&ti='+Math.random(), 1)
}


function shopimg(url)
{
document.getElementById('bigimg').style.display='block';
document.getElementById('bigimg').innerHTML = '<a href="javascript: hideimg();"><img src="'+url+'" alt=""></a><div style="z-index: 100; position: absolute; right: 0px; top: 0px;"><a href="javascript: hideimg();"><img src="/admin/image/tree/close_window.jpg" title="Закрыть изображение" align="right"></a></div>';
}
function hideimg()
{
document.getElementById('bigimg').style.display='none';
}
function addbasket(id, idd)
{
 document.getElementById('i'+id+'i'+idd).innerHTML = '<p>Добавлено в <a href="/basket/">корзину</a></p>';
 makeRequest('/data_shop/live_basket.php?id='+id+'&idd='+idd+'&tt='+Math.random(), 2)
}
function show_cat(id,maxid,cat)
{
 if (document.getElementById('c'+id).style.display == "block")
 {
   document.getElementById('c'+id).style.display = "none";
   eval("document.getElementById('icc'+id).src = '/images/plus.gif'");
 } else {
   document.getElementById('c'+id).style.display = "block";
   if(cat>0) { document.getElementById('c'+id).innerHTML = '<center><img src="/images/load.gif" alt=""> Загрузка...</center>';
   eval("document.getElementById('icc'+id).src = '/images/minus.gif'");
   makeRequest('/data_shop/catalog.php?id='+cat+'&l='+id+'&sl='+maxid, 4, id) }
 }
}
function show_menu(id)
{
   if (eval("document.getElementById('cc'+id).style.display") == "block")
 {
   eval("document.getElementById('cc'+id).style.visibility='hidden'");
   eval("document.getElementById('cc'+id).style.display = 'none'");
   eval("document.getElementById('icc'+id).src = '/images/plus.gif'");
 } else
 {
   eval("document.getElementById('cc'+id).style.visibility='visible'");
   eval("document.getElementById('cc'+id).style.display = 'block'");
   eval("document.getElementById('icc'+id).src = '/images/minus.gif'");
 }
}
