var popWnd;
var req;
var reqTimeout;
 
function loadXMLDoc(url) 
{
    req = null;
    if (window.XMLHttpRequest) 
    {
        try 
        {
            req = new XMLHttpRequest();
        } 
        catch (e){}
    } 
    else if (window.ActiveXObject) 
    {
        try 
        {
            req = new ActiveXObject('Msxml2.XMLHTTP');
        } 
        catch (e)
        {
            try {
                req = new ActiveXObject('Microsoft.XMLHTTP');
            } catch (e){}
        }
    }
 
    if (req) {
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
        reqTimeout = setTimeout("req.abort();", 5000);
    } else {
        alert("Браузер не поддерживает AJAX");
    }
}
 
function processReqChange() 
{
    if (req.readyState == 4) 
    {
        clearTimeout(reqTimeout);
 
        if (req.status == 200)
        {
            //тут обновить кол-во 
            if (document.getElementById('basket_sum')) 
            {
               var sum = req.responseText;  
	       document.getElementById('basket_sum').innerHTML = sum;
//               if (document.getElementById('bedit_sum'))
//	          document.getElementById('bedit_sum').innerText = sum;
            }
            else    
	       document.title = 'Заказ товара. Сумма: '+req.responseText;
        } 
    }  
}

function requestdata(params)
{
  //вызов добавления в корзину
  loadXMLDoc('request.php'+params);
}



 function aover(p)
 {
   p.style.color = "#ff0000";
 }

 function aout(p)
 {
   p.style.color = "#440000";
 }

 function update(id,cat)
 {
   window.location.href = "?p=catalog&cat="+cat+"&id="+id+"&lv1="+lcl1+"&lv2="+lcl2+"&lv3="+lcl3+"&lv4="+lcl4+"&lv5="+lcl5+"&lv6="+lcl6;
 }
 
 function menuover(p)
 {
   p.style.color = "#440000";
   p.style.background = "#ffa800";
 }

 function menuout(p)
 {
   p.style.color = "#fffcd5";
   p.style.background = "#951F22";
 }

 function price(id, name)
 {
   var URL = "price.php?id="+id+"&name="+name;

   if (!popWnd || popWnd.closed)
   {
     popWnd = window.open(URL,'popWnd', "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resize=no,resizable=no,width=600,height=400,left=200,top=200,fullscreen=no");
   }
   else
   {
     popWnd.focus();
     popWnd.location = URL;
   }
 }

 function inbasket()
 { 
    var qty;
    var itemid;	
    var dim;	

    for (i=0;i<15000;i++)	
    {
      if (document.getElementById("qty"+i) && document.getElementById("qty"+i).value)
      {
        qty = document.getElementById("qty"+i).value;
        if (qty > 0) 
        {  
          itemid = document.getElementById("itemid"+i).value; 
          dim = document.getElementById("dim"+i).value; 
          if (itemid && qty)
          {
            requestdata("?add=1&id="+itemid+"&qty="+qty+"&dim="+dim);
            document.getElementById("qty"+i).value = "";
          }
        } else alert("Ошибка в формате числа или отрицательное количество");
      }
    }
 }

 function page_change(l3)
 {
   requestdata("?pc=1");
 }
