var req;

function loadXMLDoc(url) {
    if (window.XMLHttpRequest) 
	{
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    } 
	else if (window.ActiveXObject) 
	{
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) 
		{
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}

function processReqChange() 
{   

    ab = window.setTimeout("req.abort();", 4000);
    
    if (req.readyState == 4) 
	{
        clearTimeout(ab);
        if (req.status == 200) 
		{
        document.getElementById("basket").innerHTML=req.responseText;
        } 
		else 
		{
        alert("Не удалось получить данные: " + req.statusText);
        }
    }  
}

function BasketAdd(id,count_cap)
{
var count;
count=document.getElementById("ct_"+id).value;
if (count==0)
{
alert("Пожалуйста, укажите число заказываемого товара.");		
}
else if (count<=count_cap)
		{
		document.getElementById("ct_"+id).value=0;	
		BasketExe("?id="+id+"&count="+count);
		alert("Товар в количетсве "+count+" ед. успешно добавлен в корзину.");
		window.setTimeout("BasketExe('');", 500);
		}
		else
		{
		alert("Введено неверное количество товара, пожалуйста, повторите ввод.");	
		document.getElementById("ct_"+id).value=0;
		}
}

function BasketRemove(id,count)
{
BasketOperation("?action=delete&id="+id+"&count="+count);	
}


function BasketOperation(params)
{
l=(screen.width-150)/2;
t=(screen.height-50)/2;
window.open('shop/goods_managment.php'+params,'','top='+t+', left='+l+', resizable=no, scrollbars=no, width=150, height=50');
}


function BasketExe(params)
{
loadXMLDoc('goods_managment.php'+params);
}

function z(name,w,h,title){l=(screen.width-w)/2; t=(screen.height-h)/2; q=w-2;g=h-2; obj=open("", "404", "top="+t+", left="+l+", width="+q+", height="+g+", status=no, toolbar=no, menubar=no"); obj.document.write("<title>"+title+"</title><body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0><img src="+name+" width="+w+" height="+h+ "></body>"); obj.document.close(); }
