function addToCart(id,price,count,info){
    document.getElementById('loading').style.display='inline';
    var xmlHttp;
    xmlHttp = getXmlHttpObject();
    var url = baseUrl + "/frontend/processing/ajax/shCartActions.php";
    //var url = "http://repkos.net/webshop-beta-demo/frontend/processing/ajax/shCartActions.php";

    var params = "action=add&variantId=" + encodeURIComponent(id)
                    + "&price=" + encodeURIComponent(price)
                    + "&count=" + encodeURIComponent(count)
                    + "&info=" + encodeURIComponent(info);
    // alert(url+'?'+params);

    xmlHttp.open("POST", url, true);

    //Send the proper header information along with the request
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");

    xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
                //alert(xmlHttp.responseText);
		var response = eval('(' + xmlHttp.responseText + ')');
                //alert(response);
                if (response == undefined){
                    alert('There was an error fetching data. Try F5 to check if you have your item in the cart.\r\n\r\n System error: response==undefined, probably json_encode failure');
                } else {
                    document.getElementById('totalCartItems').innerHTML = response.count;
                    document.getElementById('totalCartPrice').innerHTML = response.price;
                    //alert('Number of items: ' + response.count);
                    //alert('Unique items: ' + response.unique);
                    //alert('Total price: ' + response.price);
                    alert('Item was added to your cart.')
                }
                document.getElementById('loading').style.display='none';
        }
    }
    xmlHttp.send(params);
}

function changeCart(id,count){
    var really = true;
    if (count==0){
        really = confirm('Do you really want to delete this item?');
    }

    if (really){
        document.getElementById('loading').style.display='inline';
        var xmlHttp;
        xmlHttp = getXmlHttpObject();
        var url = baseUrl + "/frontend/processing/ajax/shCartActions.php";
        //var url = "http://repkos.net/webshop-beta-demo/frontend/processing/ajax/shCartActions.php";
        var params = "action=change&variantId=" + encodeURIComponent(id)
                    + "&count=" + encodeURIComponent(count);
        // alert(url+'?'+params);

        xmlHttp.open("POST", url, true);

        //Send the proper header information along with the request
        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.setRequestHeader("Content-length", params.length);
        xmlHttp.setRequestHeader("Connection", "close");

        xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
            if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
		var response = eval('(' + xmlHttp.responseText + ')');
                document.getElementById('totalCartItems').innerHTML = response.count;
                document.getElementById('totalCartPrice').innerHTML = response.price;
                //alert('Number of items: ' + response.count);
                //alert('Unique items: ' + response.unique);
                //alert('Total price: ' + response.price);
                callAndFill(xmlHttp, baseUrl + '/frontend/subpages/gui/shopping-cart-gui.php?from=ajax',document.getElementById('center_content'),'innerHTML');
                document.getElementById('loading').style.display='none';
                if (count==0){
                    alert('Item was deleted');
                } else {
                    alert('Item count was changed');
                }
            }
        }
        xmlHttp.send(params);
    }
    
    }

 function changeDeliveryMethod(id){
    document.getElementById('loading').style.display='inline';
    var xmlHttp;
    xmlHttp = getXmlHttpObject();
    var url = baseUrl + "/frontend/processing/ajax/shCartActions.php";
    
    var params = "action=changeDelivery&deliveryId=" + encodeURIComponent(id);
    //alert(url+'?'+params);

    xmlHttp.open("POST", url, true);

    //Send the proper header information along with the request
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");

    xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
                //alert(xmlHttp.responseText);
		//var response = eval('(' + xmlHttp.responseText + ')');
                //alert(response);
                //if (response == undefined){
                //    alert('There was an error fetching data. Try F5 to check if changes have been made.');
                //} else {
                    //alert(xmlHttp.responseText);
                    callAndFill(xmlHttp, baseUrl + '/frontend/subpages/gui/shopping-cart-gui.php?from=ajax',document.getElementById('center_content'),'innerHTML');
                //}
                document.getElementById('loading').style.display='none';
        }
    }
    xmlHttp.send(params);
 }

 function changeTaxPaying(iPayTax){
    document.getElementById('loading').style.display='inline';
    var xmlHttp;
    xmlHttp = getXmlHttpObject();
    var url = baseUrl + "/frontend/processing/ajax/shCartActions.php";

    var params = "action=changeTax&iPayTax=" + encodeURIComponent(iPayTax);
    //alert(url+'?'+params);

    xmlHttp.open("POST", url, true);

    //Send the proper header information along with the request
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");

    xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
                //alert(xmlHttp.responseText);
		//var response = eval('(' + xmlHttp.responseText + ')');
                //alert(response);
                //if (response == undefined){
                //    alert('There was an error fetching data. Try F5 to check if changes have been made.');
                //} else {
                    //alert(xmlHttp.responseText);
                    callAndFill(xmlHttp, baseUrl + '/frontend/subpages/gui/shopping-cart-gui.php?from=ajax',document.getElementById('center_content'),'innerHTML');
                //}
                document.getElementById('loading').style.display='none';
        }
    }
    xmlHttp.send(params);
 }

 /*
    for (i=0; i<100; i++){
        if (document.getElementById('deliveryPrice'+i)){
            document.getElementById('deliveryPrice'+i).style.display='none';
        }
    }
    if (document.getElementById('deliveryPrice'+id)){
        document.getElementById('deliveryPrice'+id).style.display='inline';
    }
    for (i=0; i<100; i++){
        if (document.getElementById('deliveryPriceTwo'+i)){
            document.getElementById('deliveryPriceTwo'+i).style.display='none';
        }
    }
    if (document.getElementById('deliveryPriceTwo'+id)){
        document.getElementById('deliveryPriceTwo'+id).style.display='inline';
    }
    */
