/*
 * $Id: lineage.js 193 2006-07-22 05:30:37Z michi2 $
 */
function xmlhttpPost(strURL, id, img_id) {
    var xmlHttpReq = false;
    var self = this;
    
    var external=false;
    if (strURL.substring(0,3) == 'ext'){
        external=true;
    }
    if (document.getElementById(id).innerHTML != '') {
        updatepage('', id, img_id, external);
        return;
    }
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(self.xmlHttpReq.responseText, id, img_id, external);
        }
    }
    self.xmlHttpReq.send('');
}

function updatepage(str, id, img_id, external){
    var img = document.getElementById(img_id);
    if (document.getElementById(id).innerHTML == '') {
        document.getElementById(id).innerHTML = str;
        if (external){
            img.innerHTML = '<img title="Hide lineage of this alternative" src="img/up-red.gif" alt="--" />';
        }
        else{
            img.innerHTML = '<img title="Hide lineage of this alternative" src="img/up.gif" alt="--" />';
        }
    } else {
        document.getElementById(id).innerHTML = '';
        if (external){
            img.innerHTML = '<img title="Get lineage of this alternative" src="img/down-red.gif" alt="+" />';
        }
        else{
            img.innerHTML = '<img title="Hide lineage of this alternative" src="img/down.gif" alt="--" />';
        }
    }
}
