function showProgress(progress_status)
{
	if(progress_status == 'show'){
		document.getElementById('progress').style.visibility = 'visible';
	}else{
		document.getElementById('progress').style.visibility = 'hidden';
	}
}

function updateBasketSum()
{
                                        JsHttpRequest.query
                                        (
                                                '/ajax_action.php',
                                                { q: 'basket_sum' },
                                                function (result, errors)
                                                {
                                                        document.getElementById('basket_sum').innerHTML = (result ? result.basket_sum : '0.00');
                                                },
                                                true // запрещает кэширование
                                        );
}


function AddToCompare(id)
{
	var req = new JsHttpRequest();
	var send_data = '';

	req.onreadystatechange = function() {
		if (req.readyState == 4){
			if (req.responseJS.success == 1){
                    document.getElementById('confirm_id').innerHTML = '<b>'+req.responseJS.count+'</b>';
					showProgress('hide');
				}
				else{
					alert(req.responseJS.error);
					showProgress('hide');
				}
	    }
	}

	showProgress('show');

	req.open(null, '/ajax_action.php', true);

	send_data = 'compare-' + id;

	req.send( { q: send_data } );
}

function RemoveFromBasket(id)
{
        showProgress('show');
        
        JsHttpRequest.query
        (
                '/ajax_action.php',
                { q: 'remove-' + id },
                
                function (result, errors)
                {
                        if (result.success)
                        {
                                document.getElementById('basket_sum').innerHTML = result.count;
                                var row = document.getElementById('basket-item-' + id);
                                row.parentNode.removeChild(row);
                        }
                        else alert(result.error);
                        
                        showProgress('hide');
                },
                
                true // отключает кэширование
        );
}


function AddToBasket(id)
{
	var req = new JsHttpRequest();
	var send_data = '';

	req.onreadystatechange = function() {
		if (req.readyState == 4){
			if (req.responseJS.success == 1){
					document.getElementById('basket_sum').innerHTML = req.responseJS.count;
					showProgress('hide');
				}
				else{
					alert(req.responseJS.error);
					showProgress('hide');
				}
	    }
	}

	showProgress('show');

	req.open(null, '/ajax_action.php', true);

	send_data = 'buy-' + id;

	req.send( { q: send_data } );
}

function BasketCount()
{
	var req = new JsHttpRequest();
	var send_data = '';

	req.onreadystatechange = function() {
		if (req.readyState == 4){
			if (req.responseJS.success == 1){
					document.getElementById('basket_id').innerHTML = '<b>'+req.responseJS.count+'</b>';
					showProgress('hide');
				}
				else{
					alert(req.responseJS.error);
					showProgress('hide');
				}
	    }
	}

	req.open(null, '/ajax_action.php', true);

	send_data = 'check_buy_count-';

	req.send( { q: send_data } );

}

function CompareCount()
{
	var req = new JsHttpRequest();
	var send_data = '';

	req.onreadystatechange = function() {
		if (req.readyState == 4){
			if (req.responseJS.success == 1){
					document.getElementById('confirm_id').innerHTML = '<b>'+req.responseJS.count+'</b>';
					showProgress('hide');
				}
				else{
					alert(req.responseJS.error);
					showProgress('hide');
				}
	    }
	}


	req.open(null, '/ajax_action.php', true);

	send_data = 'check_compare_count-';

	req.send( { q: send_data } );
}

function screenSize() {
    var w, h; // Объявляем переменные, w - длина, h - высота
    w = (window.innerWidth ? window.innerWidth : (document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.offsetWidth));
    h = (window.innerHeight ? window.innerHeight : (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.offsetHeight));
    return {w:w, h:h};
}
/*
// Пример:
document.write(
    "Длина = " + screenSize().w + "px<br>" +
    "Высота = " + screenSize().h + "px"
);
*/
