function ajaxCart(typ,ProdID,callbackFunction, async) {
var URL = 'http://chrumek.pl/cart/'+typ;

	if( !window.XMLHttpRequest ) XMLHttpRequestAlt = function(){
		try{ return new ActiveXObject("MSXML3.XMLHTTP") }catch(e){}
		try{ return new ActiveXObject("MSXML2.XMLHTTP.3.0") }catch(e){}
		try{ return new ActiveXObject("Msxml2.XMLHTTP") }catch(e){}
		try{ return new ActiveXObject("Microsoft.XMLHTTP") }catch(e){}
		throw new Error("Could not find an XMLHttpRequest alternative.")
	};	
	
        var request = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0");
        request.open("POST", URL, async);
        request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
        request.onreadystatechange = function(){
	try {
                if (request.readyState == 4 && request.status == 200) {
                        if (request.responseText) {
                                callbackFunction(request.responseText);
                        }
                }
		}catch(e){
			//alert('AJAX err: message: ' + e.message + '  name: ' + e.name);
		}
        };
	vars = 'ProdID='+ProdID;
	//alert('alert'+vars);
        request.send(vars);
}

function nothing(txt) {
	//alert('bb'+txt);
	cartLoadingOff();
	return txt;
}


//wymaga formularza z polem od ID='IDProdField' w formularzu ID='form_icon'
function cartAdd(ProdID) {
	cartLoadingOn();
    ajaxCart('add', ProdID, nothing, false);
    history.go(0);
//window.location.href=window.location.href;
//window.location.reload();
}

function cartDel(ProdID) {
	cartLoadingOn();
ajaxCart('del', ProdID, nothing, false);
history.go(0);
//window.location.reload();
//window.location.href=window.location.href;
}

function cartLoadingOn() {
	cartLoading(1);
}

function cartLoadingOff() {
	cartLoading(0);
}

//1 to on, 0 to off
function cartLoading(arg) {
	var cartID = document.getElementById("cartLoading");
	if (! cartID) {alert('nocart'); return };
	
	if (arg == 1) {
		cartID.style.display = "block";
		//cartID.visibility = "block";
	} else {
		cartID.style.display = "none";
		//cartID.visibility = "hidden";
	}
}
/*
 var ld=(document.all);
  var ns4=document.layers;
 var ns6=document.getElementById&&!document.all;
 var ie4=document.all;
  if (ns4)
 	ld=document.loading;
 else if (ns6)
 	ld=document.getElementById("loading").style;
 else if (ie4)
 	ld=document.all.loading.style;
 	
  function init()
 {
 if(ns4){ld.visibility="hidden";}
 else if (ns6||ie4) ld.display="none";
 }
 </script>
*/

