

//////////////////////////////////////////////////////////////////////////////////////

// AJAX

/////////////


function createRequestObject() {
    var ro;
    if (window.XMLHttpRequest) {
        try {
            ro = new XMLHttpRequest();
        } catch(e) {
            ro = false;
        }
    } 
    else if (window.ActiveXObject) {
        try {
            ro = new ActiveXObject("Microsoft.XMLHTTP");
        } catch(e) {
            ro = false;
        }
    } 
    return ro;
}

// -------------------------------------------------------------------------------------

var http = createRequestObject();
var busy = false;
var elementsToUpdate = new Array();

// -------------------------------------------------------------------------------------

function ajax_addElementToUpdate( el_id ) {

elementsToUpdate[elementsToUpdate.length] = el_id;

}

// -------------------------------------------------------------------------------------

function ajax_updateGroup( prefix , action ) {

    for (var i=0; i<elementsToUpdate.length; i++) {
    
        if (elementsToUpdate[i].substr(0, prefix.length) == prefix) {
        
        ajax_updateElement(elementsToUpdate[i], action);
            
        }
        
    }
    
}

// -------------------------------------------------------------------------------------

function ajax_updateElement( el_id , page , action ) { 

    if (busy == false) {
    
    busy = true;
    http.open('get', page + '?rnd=' + Math.random()*4 + '&ajax_div=' + el_id + '&ajax_var=' + action);
    http.onreadystatechange = ajax_doUpdate;
    http.send(null);
   
    } else {
    
    window.setTimeout("ajax_updateElement('" + el_id + "', '" + action + "')", 10);
    
    }
    
}

// -------------------------------------------------------------------------------------

function ajax_doUpdate() {

    if (http.readyState == 4) {
    
    var response = http.responseText;
    var update = new Array();
        
        if (response.indexOf('|') != -1) {
        
        update = response.split('|'); 
        var el_id = update.shift();
        el_id = el_id.replace(/^\s+|\s+$/g, '');
        var text = update.join("|");
        document.getElementById(el_id).innerHTML = text;
        
        }
        
    busy = false;
    
    }

}

// -------------------------------------------------------------------------------------
