////////////////////////////////////////////////////

function sendungMerken(sendung_id) {
    //alert(sendung_id);
    
    var element_id = "merklink_"+sendung_id;
    var element_txt_id = "merklink_txt_"+sendung_id;
    var action = "merken"; 
    var query = "action="+action+"&sendung_id="+sendung_id;
        
    var xmlhttp = new ajaxRequest(
        server_root_path+"merkliste.php?action="+action+"&sendung_id="+sendung_id+"&timestamp=" + new Date().getTime(),
        function() {
            var r = xmlhttp.req;
            if (r.readyState==4) {
                //document.getElementById(element_id).src = r.responseText;
                //alert(document.getElementById(element_id).className);
                //alert(r.responseText);
                if(r.responseText == "saved") {
                    if(document.getElementById(element_id) !== null && document.getElementById(element_id).className == "merklink") {
                        document.getElementById(element_id).className = "merklink saved";
                    }
                    
                    if(document.getElementById(element_txt_id) !== null) {
                        var merklink = (document.getElementById("isvollbild") !== null) ? "vollbild/merkliste/" : "merkliste/";
                        document.getElementById(element_txt_id).innerHTML = 'Erfolgreich in der <a href="'+merklink+'">Merkliste</a> gespeichert!';
                    }
                }
                
            }
        },
        "GET",
        query,
        ["Content-Type","application/x-www-form-urlencoded"]
    );
    xmlhttp.doRequest();
}

////////////////////////////////////////////////////

function sendungLoeschen(sendung_id) {
    //alert(sendung_id);
    var element_id = "merkliste_eintrag_"+sendung_id;
    var action = "loeschen"; 
    var query = "action="+action+"&sendung_id="+sendung_id;
        
    var xmlhttp = new ajaxRequest(
        server_root_path+"merkliste.php?action="+action+"&sendung_id="+sendung_id+"&timestamp=" + new Date().getTime(),
        function() {
            var r = xmlhttp.req;
            if (r.readyState==4) {
                //document.getElementById(element_id).src = r.responseText;
                //alert(document.getElementById(element_id).className);
                //alert(r.responseText);
                if(r.responseText == "deleted") {
                    document.getElementById(element_id).style.display = "none";
                    if(document.getElementById("anzahl_sendungen") !== false) {
                        var anzahl = parseInt(document.getElementById("anzahl_sendungen").innerHTML)-1;
                        document.getElementById("anzahl_sendungen").innerHTML = anzahl;
                    }
                }
                
            }
        },
        "GET",
        query,
        ["Content-Type","application/x-www-form-urlencoded"]
    );
    xmlhttp.doRequest();
}


////////////////////////////////////////////////////

function merklisteLoeschen() {
    //alert(sendung_id);
    var action = "merkliste_loeschen"; 
    var query = "action="+action;
        
    var xmlhttp = new ajaxRequest(
        server_root_path+"merkliste.php?action="+action+"&timestamp=" + new Date().getTime(),
        function() {
            var r = xmlhttp.req;
            if (r.readyState==4) {
                //document.getElementById(element_id).src = r.responseText;
                //alert(document.getElementById(element_id).className);
                //alert(r.responseText);
                if(r.responseText == "deleted") {
                    document.getElementById(element_id).style.display = "none";
                    if(document.getElementById("anzahl_sendungen") !== false) {
                        var anzahl = parseInt(document.getElementById("anzahl_sendungen").innerHTML)-1;
                        document.getElementById("anzahl_sendungen").innerHTML = anzahl;
                    }
                }
                
            }
        },
        "GET",
        query,
        ["Content-Type","application/x-www-form-urlencoded"]
    );
    xmlhttp.doRequest();
}

////////////////////////////////////////////////////

