function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 // Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}

var xmlHttp
var elementID=0;

function delleteAllCart(){
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request")
        return
    }

    var url="getcart.php"
    url=url+"?dellete=dellete"
    url=url+"&sid="+Math.random()    
    xmlHttp.onreadystatechange=stateCartDellete
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)            
}
function stateCartDellete()
{
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
     {                  
        try {
            eval(xmlHttp.responseText);
        } catch (e) {
            alert(xmlHttp.responseText);
        }                 
        document.getElementById("cartSum").innerHTML=prodd;
        document.getElementById("catrProduct").style.display = "none";
        document.getElementById("catrProductEmpty").style.display = "block";
     }
}

function changeCount(id,stock,note,delCount){
        
    if(delCount=='1'){
        var countID="count"+id;
        var countF= document.getElementById(countID);
        var count = countF.value; 

        count = count.replace(/,/g, ".");
    }else{
        count=delCount;
    }
    
    if(count>stock) {
        note=note+" "+stock;
        alert(note);
        countF.value=stock;
        count=stock;
    }
    
    if(elementID!=id) elementID=id;
    
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request")
        return
    }

    var url="getcart.php"
    url=url+"?id="+id
    url=url+"&count="+count
    url=url+"&change=change"
    url=url+"&sid="+Math.random()    
    xmlHttp.onreadystatechange=stateToCartChange
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)            

}
function stateToCartChange()
{
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
     {
     
        try {
            eval(xmlHttp.responseText);
        } catch (e) {
            alert(xmlHttp.responseText);
        }
        
        var countID="count"+elementID;
        var priceID="price"+elementID;
        var totalID="total"+elementID;

        var count = document.getElementById(countID).value;
        count = count.replace(/,/g, ".");
        
        var price = document.getElementById(priceID).innerHTML;

        var totalPrice=count*price;
        document.getElementById(totalID).innerHTML=totalPrice.toFixed(2);
        document.getElementById("allPrice").innerHTML=parseFloat(prodd).toFixed(2);
        document.getElementById("allShipment").innerHTML=prodWeight;             
        document.getElementById("allTotal").innerHTML=(parseFloat(prodd)+parseFloat(prodWeight)-parseFloat(discount)).toFixed(2);
        if(document.getElementById("allDiscount")) document.getElementById("allDiscount").innerHTML=(parseFloat(discount)).toFixed(2);
        document.getElementById("cartSum").innerHTML=(parseFloat(prodd)+parseFloat(prodWeight)-parseFloat(discount)).toFixed(2);
     }
}

function add_to_cart(id,count){
    
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request")
        return
    }

    var url="getcart.php"
    url=url+"?id="+id
    url=url+"&count="+count
    url=url+"&add='add'"
    url=url+"&sid="+Math.random()    
    xmlHttp.onreadystatechange=stateToCart
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)            
}

function stateToCart()
{
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
     {
        try {
            eval(xmlHttp.responseText);
        } catch (e) {
            alert(xmlHttp.responseText);
        }                                              
        document.getElementById("cartSum").innerHTML=(parseFloat(prodd)+parseFloat(prodWeight)-parseFloat(discount)).toFixed(2);
        if(add!='0') {
            document.location='/cart.html';
        }        
     }
}

