function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();

function sndReq(action,ammount) {
    http.open('get', 'cartupdate.php?action='+action+'&ammount='+ammount);
    http.onreadystatechange = handleResponse;
    http.send(null);
}

function chExtra(gerecht_id,option_id) {
    http.open('get', 'getoptions.php?gid='+gerecht_id+'&oid='+option_id);
    http.onreadystatechange = showOptions;
    http.send(null);
}

function getCat(newcategory,current) {
    http.open('get', 'showmenu.php?category='+newcategory+'&current='+current);
    http.onreadystatechange = showCat;
    http.send(null);
}

function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();

        if(response.indexOf('|' != -1)) {
            update = response.split('|');
            document.getElementById('itog').value = update[1];
            document.getElementById(update[2]).innerHTML = update[3];
            document.getElementById(update[4]).value = update[5];  
            document.getElementById('bkostentext').innerHTML = update[6];
            document.getElementById('bkostenprijs').innerHTML = update[7];   
        }
    }
}

function showCat() {
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();
                
        if(response.indexOf('|' != -1)) {
           update = response.split('|');
           document.getElementById('menucontent').innerHTML = update[3];
           document.getElementById(update[1]).style.color="red";
           document.getElementById(update[2]).style.color="black";   
        }
    }
}

function showOptions() {
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();
                
        if(response.indexOf('|' != -1)) {
           update = response.split('|');
           document.getElementById(update[0]).innerHTML = update[1]; 
        }
    }
}
