/*@cc_on _d=document;eval('var document=_d')@*/

var mouse_info = false;
var xmlhttp;

function set_ad_image()
{
    if (mouse_info) return;

    xmlhttp_create();

    if (!xmlhttp) return;

    url = "read_new_ad.php";

    xmlhttp.open("POST", url);
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            var data = xmlhttp.responseText;
            d = data.split("\n");
            if (d.length == 1 && d[0] == "") {
                obj = document.getElementById("ad");
                obj.innerHTML = "<p align=\"center\">今日折込のチラシはありません</p>";
                return;
            }
            var html = "<div class=\"adbox\">";
            for (i=0; i<d.length; i++) {
                if (d[i] == "") continue;
                dd  = d[i].split("\t");
                if (i == 4) {
                    html = html + "</div><div class=\"adbox\" style=\"margin-top:5px;\">";
                    html = html + "<li style=\"clear:both; float:left;\"><a href=\"javascript:void(0)\" onClick=\"WindowOpenMain('" + dd[1] + "',1000,650,'_blank',{'resizable':'no'});ebook_accesslog(" + dd[2] + "," + dd[3] + ");\" onMouseOver=\"mon()\" onMouseOut=\"mout()\"><img src=\"" + dd[1] + "thumbnail.jpg\" width=\"126\" height=\"126\" /><br />" + dd[0] + "</a></li>";
                } else {
                    html = html + "<li><a href=\"javascript:void(0)\" onClick=\"WindowOpenMain('" + dd[1] + "',1000,650,'_blank',{'resizable':'no'});ebook_accesslog(" + dd[2] + "," + dd[3] + ");\" onMouseOver=\"mon()\" onMouseOut=\"mout()\"><img src=\"" + dd[1] + "thumbnail.jpg\" width=\"126\" height=\"126\" /><br />" + dd[0] + "</a></li>";
                }
            }
            html = html + "</div>";
            obj = document.getElementById("ad");
            obj.innerHTML = html;
            if (dd[4] == 1) {
                obj = document.getElementById("today-header");
                obj.src = "images/00-top/period/period-title.gif";
                obj = document.getElementById("today-header-a");
                obj.href = "day.php?day=period";
            }
        }
    }
    xmlhttp.setRequestHeader("Content-Type" , "application/x-www-form-urlencoded");
    xmlhttp.send(url);
}

function ebook_accesslog(id, ad)
{
    xmlhttp_create();
    if (!xmlhttp) return;
    url = "ebook_log.php?id=" + id + "&ad=" + ad;
    xmlhttp.open("POST", url);
    xmlhttp.setRequestHeader("Content-Type" , "application/x-www-form-urlencoded");
    xmlhttp.send("id=" + id + "&ad=" + ad);
}

function xmlhttp_create()
{
    if (typeof ActiveXObject != "undefined") {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {
            xmlhttp = null;
        }
    }
    if (!xmlhttp && typeof XMLHttpRequest != "undefined") {
        xmlhttp = new XMLHttpRequest();
    }
}

function mon()
{
    mouse_info = true;
}

function mout()
{
    mouse_info = false;
}
