
function arrayHasItem(array, item)
{
    var i;
    for (i = 0; i < array.length; i++) {
        if (array[i] == item)
            return true;
    }
    return false;
}


function printMultiSelectCheckboxes(name, selected, ids, descs)
{
    var i;
    for (i = 1; i < ids.length; i++) {
        var checked = "";
        if (arrayHasItem(selected, ids[i])) {
            checked = 'checked="checked"';
        }
        document.writeln('<nobr><input type="checkbox" class="checkbox" name="' + name + '" value="' + ids[i] + '" title="' + descs[i] + '" ' + checked + ' />' + descs[i] + '</nobr> ');
    }
}


function printArchiveRegionCtrl(limit, begin, months, nextBegin) 
{
    var cur = new Date();
    var i = cur.getFullYear() * 12 + cur.getMonth();
    var check = begin.getFullYear() * 12 + begin.getMonth();
    var end = limit.getFullYear() * 12 + limit.getMonth();
    while (i >= end) {
        var caption = Math.floor(i / 12) + '年' + (i % 12 + 1) + '月';
        var lastDayOfMonth = new Date();
        lastDayOfMonth.setTime(Date.parse(Math.floor((i + 1) / 12) +
            '/' + ((i + 1) % 12 + 1) + '/1') - 86400000);
        var val = lastDayOfMonth.getFullYear() + '/' +
            (lastDayOfMonth.getMonth() + 1) + '/' +
            lastDayOfMonth.getDate();
        var selected = '';
        if (i == check) {
            selected = 'selected="selected"';
        }
        document.writeln('<option value="' + val + '" ' + selected + '>' + caption + '</option>');
        i--;
    }
}

function helloWorld() {
    if (Math.random() < 0.8) {
        alert('ハイヤー！ハイヤー！');
    } else {
        if (confirm('ハイヤー？ハイヤー？')) {
            alert('ハイヤー！ハイヤーー！！');
        } else {
            alert('Have a nice day.');
            window.location.href = 'http://battlefieldbadcompany.jp/';
        }
    }
}
