function usrListResp (req, xh_param) {
    var ulElem = xh_param[0];
    var sort = xh_param[2];
    var max_num = xh_param[3];
    var resp = req.responseText.split(DELIMITER);
    var inc_name=0, inc_pic_portf=0, i=0, sort=xh_param[2];
    var ul = document.getElementById(ulElem);
    var tbl = document.createElement('table');
    
    tbl.className = 'tfmtFixedBig';
    ul.appendChild(tbl);
    
    // alert(resp[0]+' '+resp[1]+' '+resp[2]+' '+resp[3]+' '+resp[4]);
    
    var row = tbl.insertRow(tbl.rows.length);
    var td = row.insertCell(i++);
    td.style.fontWeight='bold';
    if (ulElem == 'allMembers') {
        td.style.width = '160px';
    } else {
        td.style.width = '80px';
    }
    td.appendChild(document.createTextNode('Usr Id'));

    td = row.insertCell(i++);
    td.style.fontWeight='bold';
    td.appendChild(document.createTextNode('Member Since'));
    td.style.width = '88px';

    if (sort=='n') {
        td = row.insertCell(i++);
        td.style.width='100px';
        td.style.fontWeight='bold';
        td.appendChild(document.createTextNode('First Name'));

        td = row.insertCell(i++);
        td.style.width='100px';
        td.style.fontWeight='bold';
        td.appendChild(document.createTextNode('Last Name'));
        inc_name = 1;
    }

    if (max_num == 0) {
        td = row.insertCell(i++);
        td.style.fontWeight='bold';
        td.style.width = (sort=='n') ? '70px' : '120px';        

        td.appendChild(document.createTextNode('Portfolios'));
        td = row.insertCell(i++);
        td.style.fontWeight='bold';
        td.style.width = '70px';
        td.appendChild(document.createTextNode('Pictures '));
        inc_pic_portf = 1;
    }

    i=2;
    var inc_more=0, j=0;
    while (resp[i]) {
        if (++j == max_num) {
            inc_more = 1;
        }
        i += displayUsrs(tbl, resp, i, true, inc_name, inc_more, inc_pic_portf);
    }

    displayPages('usrlPages', 'usrl.php'+xh_param[1], resp[0], resp[1]);
}

function usrListReq (ulElem, page, sort, max_num) {
    var url = 'usrl_handler.php';
    var url_param = '?sort='+sort+'&num='+max_num+'&page='+page;
    var xh_param = new Array(ulElem, url_param, sort, max_num);
    
    xmlHttpReq(xmlHttpObj(), url+url_param, true, null, usrListResp, xh_param);
}

function displayUsrs (tbl, usrs, idx, inc_since, inc_name, inc_more, inc_pic_portf) {
    var i=0, td;
    var row = tbl.insertRow(tbl.rows.length);

    td = row.insertCell(i++);
    var a = document.createElement('a');
    var href_val = 'usr_profile.php?usrid=' + usrs[idx];
    var usr_id = usrs[idx];
    a.setAttribute('href', href_val);
    if (usr_id.length > 24) {
        usr_id = usr_id.substring(0,20) + '...';
    }
    a.appendChild(document.createTextNode(usr_id));
    td.appendChild(a);
    td.style.align = 'center';

    if (inc_since) {
        // member since
        td = row.insertCell(i++);
        td.style.width = '74px';
        td.appendChild(document.createTextNode(usrs[idx+1]));
    }

    if (inc_name) {
        td = row.insertCell(i++);
        td.appendChild(document.createTextNode(usrs[idx+2]));
        td = row.insertCell(i++);
        td.appendChild(document.createTextNode(usrs[idx+3]));
    }

    if (inc_pic_portf) {
        td = row.insertCell(i);
        var img;
        if (usrs[idx+i] & 2) {
            img = document.createElement('img');
            img.src = 'phpchat/data/public/themes/default/smileys/msn_thumbup.gif';
            a = document.createElement('a');
            href_val = 'usr_portf.php?usrid=' + usrs[idx];
            a.setAttribute('href', href_val);
            a.appendChild(img);
            td.appendChild(a);
        }
        td = row.insertCell(i+1);
        if (usrs[idx+i] & 1) {
            td.style.width = '50px';
            img = document.createElement('img');
            img.src = "phpchat/data/public/themes/default/smileys/msn_photo.gif";
            td.appendChild(img);
        } 

        i++;
    }

    if (inc_more) {
        var row = tbl.insertRow(tbl.rows.length);
        td = row.insertCell(0);
        td.colSpan = i;
        td.style.fontWeight = 'bold';
        td.appendChild(document.createTextNode('...'));
    }
    
    return(i);
}

function activeUsrListResp (req, xh_param) {
    var ulId = xh_param[0];
    var max_num = xh_param[1];
    var resp = req.responseText.split(DELIMITER);
    var i=0, j=0, inc_more = 0;
    var tbl = document.createElement('table');
    var ul = document.getElementById(ulId);
    tbl.className = 'tfmtNoB';
    ul.appendChild(tbl);
    
    // alert(resp[0]);
    while (resp[i]) {
        if (++j == max_num) {
            inc_more = 1;
        }
        i += displayUsrs(tbl, resp, i, 0, 0, inc_more, 0);
    }
}

function activeUsrListReq (ulId, max_num) {
    var url = 'active_usrl_handler.php';
    var url_param = '?sort=l&num='+max_num;
    var xh_param = new Array(ulId, max_num);
    xmlHttpReq(xmlHttpObj(), url+url_param, true, null, activeUsrListResp,
               xh_param);
}