function getBulletin(tid,stid)
{
    path = '';
    if(tid != ''){
        path += '?tid=' + tid;
        if(stid != '' && stid != 0){
            path += '&stid=' + stid;
        }
    }
    url = 'http://' + host + '/api/get_bulletin.php' + path;
    
    var oJsr = new JSONscriptRequest(url);
    oJsr.buildScriptTag();
    oJsr.addScriptTag();
    //oJsr.removeScriptTag();
}

function bulletin_callback(data) {
    document.getElementById("bulletin_result").innerHTML = result_parse(data);
}

// JSONのデータを解析して表示
function result_parse(data)
{
    var resultText = '<ul class="bulletin">';
    
    for(var i=0; i<data.item.length; i++)
    {
        theme_name = data.item[i].theme;
        bid = data.item[i].id;
        tid = data.item[i].tid;
        stid = data.item[i].stid;
        canuser = data.item[i].can_user;
        title = data.item[i].title;
        if(bid == ''){
            resultText += '<li class="message">テーマ内に掲示板がありません</li>';
            break;
        }else{
            if(i == 0){
                resultText += '<li class="message">' + theme_name + '掲示板</li>';
            }
        }
        if(tid == 1){
            resultText += '<li class="delivery"><a href="http://' + host + '/bulletin/view/bid/' + bid + '">' + title + '</a></li>';
        }else if(canuser == 1){
            resultText += '<li><a href="http://' + host + '/bulletin/view/bid/' + bid + '">' + title + '</a></li>';
        }else{
            resultText += '<li class="can_user"><a href="http://' + host + '/bulletin/view/bid/' + bid + '">' + title + '</a></li>';
        }
        
    }
    number = 5 - data.item.length;
    if(number > 0){
        for(var i=0; i<number; i++)
        {
            resultText += '<li class="message">&nbsp;</li>';
        }
    }
    resultText += "</ul>";
    resultText += '<p class="more"><img src="/img/common/arrow_p.gif" alt="" width="5" height="7" border="0" class="m" />&nbsp;<a href="javascript:void(0);" onClick="goList(); return false;">もっと見る</a></p>';
    return resultText;
}

// init
function bulletinInit(tid,stid){
    getBulletin(tid,stid);
}