function addToCart ( id, count ) {
	
	if ( count<1 ) return;
	
	var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            
            if ( req.responseJS.success == 1 ) {
            	showCartStat();
            	alert ('Товар добавлен в вашу корзину');
            } else if ( req.responseJS.alert.length > 0 ) {
            	alert ( req.responseJS.alert );
            } else {
            	alert ( 'Неизвестная ошибка.' );
            }
        }
    }
    req.open(null, '/ajax.php', true);
    req.send( { id: id, count: count, action: 'add_to_cart' } );
}

function showCartStat() {
	var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('cart_total').innerHTML = req.responseJS.total;
            document.getElementById('cart_price').innerHTML = req.responseJS.price;
        }
    }
    req.open(null, '/ajax.php', true);
    req.send( { action: 'show_cart_stat' } );
}
var popup;
function openIMG(URL,w,h)
{
	if (popup != null && !popup.closed) popup.close();  
	sw = screen.width-100;
	sh = screen.availHeight-100;
	if (w > sw || h > sh)
	{
		if (w > sw) {w1 = sw;} else {w1 = w+17;}
		if (h > sh) {h1 = sh;} else {h1 = h+17;}
		mtw1 = (screen.width-w1)/2;
		mth1 = (screen.availHeight-h1)/2;
		popup = window.open('','',"width="+w1+",height="+h1+",top="+mth1+",left="+mtw1+",status=no,toolbar=no,scrollbars=yes,resizable=no,menubar=no");
		popup.focus();
	}
	else
	{
		mtw = (screen.width-w)/2;
		mth = (screen.availHeight-h)/2;
    	popup = window.open('','',"width="+w+",height="+h+",top="+mth+",left="+mtw+",status=no,toolbar=no,scrollbars=no,resizable=no,menubar=no");
		popup.focus();
	}
  	popup.document.writeln('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>Изображение</title></head><body style="margin: 0px;"><a href="javascript:window.close();"><img src="'+URL+'" border=0 width="'+w+'" height="'+h+'" alt="Закрыть окно"></a></body></html>');
}
