function addToCart(id, q, desc, changebuttton) {
       if(q==null) q=1;
       if(desc==null) desc='';
       if(changebuttton==null) changebuttton=true;       
	var atcreq = new JsHttpRequest();
	atcreq.onreadystatechange = function() {
		if (atcreq.readyState == 4) {
			atcreq.onreadystatechange = this.dummy;			
			if (atcreq.responseJS) {
				setCartInformHtml(atcreq.responseJS.html||'failed', id, atcreq.responseJS.price||null);
			}
			if(atcreq.responseText) {
				alert(atcreq.responseText);
			}
		}
	}
	atcreq.caching = false;
	atcreq.open('POST', '/_admin/modules/ishop/components/cartchecker/process/process_0.php', true);
	atcreq.send({cart_act:'add', item_id: id, item_qty: q, item_desc: desc});	

};

function delFromCart(id) {     
	var atcreq = new JsHttpRequest();
	atcreq.onreadystatechange = function() {
		if (atcreq.readyState == 4) {
			atcreq.onreadystatechange = this.dummy;			
			if (atcreq.responseJS) {
				setCartInformHtml(atcreq.responseJS.html||'failed', id, atcreq.responseJS.price||null, false, true, 'del');
			}
			if(atcreq.responseText) {
				alert(atcreq.responseText);
			}
		}
	}
	atcreq.caching = false;
	atcreq.open('POST', '/_admin/modules/ishop/components/cartchecker/process/process_0.php', true);
	atcreq.send({cart_act:'del', item_id: id});	

};

function addArrayToCart(id, q, desc, changebuttton) {  
       if(q==null) q=1;
       if(desc==null) desc='';
       if(changebuttton==null) changebuttton=true;       
	var atcreq = new JsHttpRequest();
	atcreq.onreadystatechange = function() {
		if (atcreq.readyState == 4) {
			atcreq.onreadystatechange = this.dummy;			
			if (atcreq.responseJS) {
				setCartInformHtml(atcreq.responseJS.html||'failed', id, atcreq.responseJS.price||null, true);
			}
			if(atcreq.responseText) {
				alert(atcreq.responseText);
			}
		}
	}
	atcreq.caching = false;
	atcreq.open('POST', '/_admin/modules/ishop/components/cartchecker/process/process_0.php', true);
	atcreq.send({cart_act:'add_array', item_id: id, item_qty: q, item_desc: desc});	

};

function setCartInformHtml(html, id, price, noshowwin, noshowalert, typealert) {
    if(noshowwin==null || !noshowwin) { 
        var pos = $("#addtocartbutton_"+id).offset();
	if (($('#addtoacartinform').length)) {
            $('#addtoacartinform').detach();
        }        
   		//$('<div id="addtoacartinform" style="width:150px;height:30px;left:'+(pos.left-126)+'px;top:'+(pos.top-23)+'px;position:absolute;display:none;border:1px solid #521902;background-color:#f2e5d4;color:#521902;z-index:100;padding:10px;text-align:center;"><b>Товар добавлен</b><br><a href="/cart" style="color: #ab0000;text-decoration: underline;">перейти в корзину</a></div>').appendTo("#content");            
   		$('<div id="addtoacartinform" style="width:150px;height:30px;left:'+(pos.left-63)+'px;top:'+(pos.top+24)+'px;position:absolute;display:none;border:1px solid #aac6c8;background-color:#e9f4f4;color:#004f56;z-index:100;padding:10px;text-align:center;"><b>Товар '+((typealert!=null && typealert=='del')?'удален':'добавлен')+'</b><br><a href="/cart" style="color: #f74400;text-decoration: underline;">перейти в корзину</a></div>').appendTo("body");
	//} else {
	//	$('#addtoacartinform').stop(true, true).css('top',pos.top+24).css('left',pos.left-126);
	//}
        $('#addtoacartinform').stop(true, true).fadeIn(400).delay(3000).fadeOut(600); 
    } else {
        if(noshowalert==null || !noshowalert) {
            alert('Товар добавлен в корзину!');
        }
    }
    if(html) {
            var el = document.getElementById('cartinform');
            if(el !=null && typeof(el) == "object") {
                    el.innerHTML = html;
                    if(price) {
                            //reculccartinformer('RUB', price);                        
                    }
            } else {
                    //alert("Can't find 'cartinform' object")
            }
    }
}
