//(function(){getAd()})();
function getAd()
{
    var footer = document.getElementById('footer');
    var footerTop = footer.offsetTop - 10;

    var data = '';

    var left = document.getElementById('leftSide');
    if (left != undefined) {
        var leftBottom = left.offsetTop + left.clientHeight;
        if (footerTop - leftBottom > 0) {
            data = data + "l_ad=" + (footerTop - leftBottom);
        }
    }
    var right = document.getElementById('rightSide');
    if (right != undefined) {
        var rightBottom = right.offsetTop + right.clientHeight;
        if (footerTop - rightBottom > 0) {
            data = data + "&r_ad=" + (footerTop - rightBottom);
        }
    }

    // 再描画用オブジェクトを取得する
    var jsHost;
    if ("https:" == document.location.protocol) {
        // SSL
        jsHost = "https://www.futsal-station.com";
        if (jsHost.indexOf(document.domain) == -1) {
            return true;
        }
        data = data + '&ssl=on';
    } else {
        jsHost = "";
        data = data + '&ssl=off';
    }
    sendRequest(onAdLoaded, data, 'POST', jsHost + '/ad.php', true, true);
}

// コールバック関数 (受信時に実行されます)
function onAdLoaded(res)
{
    var i, target, leftCount = 0, rightCount = 0;
    var xmlData = res.responseXML;
    var ad = xmlData.getElementsByTagName('Ad');
    for (i = 0; i < ad.length; i++) {
        var tag = ad[i].childNodes[0].firstChild.nodeValue;
        var pos = ad[i].childNodes[1].firstChild.nodeValue;
        target = document.getElementById(pos + '_ad');
        target.innerHTML += '<li>' + tag + '</li>';
        if (pos == 'left') {
            leftCount++;
        } else if (pos == 'right') {
            rightCount++;
        }
    }
    target = document.getElementById('left_ad');
    if (leftCount > 0) {
        document.getElementById('left_ad_area').style.display = '';
    }
    if (rightCount > 0) {
        document.getElementById('right_ad_area').style.display = '';
    }
}
