google_ad_client = 'ca-livedoor-cgm_js';
google_ad_channel = 'knowledge';
google_ad_output = 'js';
google_ad_type = 'text';
google_language = 'ja';
google_encoding = 'utf8';
google_safe = 'high';
google_ad_section = 's1 s2';
google_max_num_ads = '10';
//google_ad_test = 'on';

function check_referrer(){
	var ref = document.referrer;
	var FromSearchEngine = false;
	if (/^http:\/\/search\.livedoor\.com\/search/.test(ref)) FromSearchEngine = true;
	if (/^http:\/\/www\.google\.(co\.jp|com)\/search/.test(ref)) FromSearchEngine = true;
	if (/^http:\/\/images\.google\.(co\.jp|com)/.test(ref)) FromSearchEngine = true;
	if (/^http:\/\/search\.yahoo\.(co\.jp|com)\/search/.test(ref)) FromSearchEngine = true;
	if (/^http:\/\/search\.live\.com\/results\.aspx/.test(ref)) FromSearchEngine = true;
	if (/^http:\/\/search\.msn\.co\.jp/.test(ref)) FromSearchEngine = true;
	if (/^http:\/\/search\.jp\.aol\.com\/aol\/search/.test(ref)) FromSearchEngine = true;
	if (/^http:\/\/www\.baidu\.jp\/s/.test(ref)) FromSearchEngine = true;
	if (/^http:\/\/www\.excite\.co\.jp\/search\.gw/.test(ref)) FromSearchEngine = true;
	if (/^http:\/\/ask\.jp\/web\.asp/.test(ref)) FromSearchEngine = true;
	if (/^http:\/\/search\.goo\.ne\.jp\/web\.jsp/.test(ref)) FromSearchEngine = true;
	if (/^http:\/\/search\.nifty\.com\/websearch\/search/.test(ref)) FromSearchEngine = true;
	if (/^http:\/\/search\.www\.infoseek\.co\.jp\/Web/.test(ref)) FromSearchEngine = true;
	return FromSearchEngine;
}

function google_ad_request_done(google_ads) {
    var s = '';
    var i = 0;
    var num = check_referrer() ? 5 : 3;
    /*
     * Verify that there are actually ads to display.
     */
    if (google_ads.length === 0) {
      s += '';
      document.write(s);
      return;
    }
        s +='<div id="google_adsense">';
        s += '';
        if (google_ads.length == 1) {
            /*
             * Partners should adjust text sizes
             * so ads occupy the majority of ad space.
             */
                s += '<p class="google-ads ad-type1"><a href="' + google_ads[i].url + '" ' +
                                  'onmouseout="window.status=\'\'" ' +
                                  'onmouseover="window.status=\'go to ' +
                                  google_ads[i].visible_url + '\'" ' +
                                  ' target="_blank">' +
                                  '<span class="sitename">' +
                                  google_ads[i].line1 + '</span>' + 
                                  '<span  class="siteurl">' +
                                  google_ads[i].visible_url + '</span><br /><span class="sitetext">' +
                                  google_ads[i].line2 +
                                  google_ads[i].line3 + '</span></a></p>';
        } else if (google_ads.length > 1) {
            /*
             * For text ads, append each ad to the string.
             */
            
            for(i=0; i < num/*google_ads.length*/; ++i) {
                s += '<p class="google-ads ad-type2"><a href="' + google_ads[i].url + '" ' +
                                  'onmouseout="window.status=\'\'" ' +
                                  'onmouseover="window.status=\'go to ' +
                                  google_ads[i].visible_url + '\'" ' +
                                  ' target="_blank">' +
                                  '<span class="sitename">' +
                                  google_ads[i].line1 + '</span>' + 
                                  '<span  class="siteurl">' +
                                  google_ads[i].visible_url + '</span><br /><span class="sitetext">' +
                                  google_ads[i].line2 +
                                  google_ads[i].line3 + '</span></a></p>';
            }
        }
        s += '</div>';

    document.write(s);
    return;
}


function load_ld_google_ad(ad_start) {
    var s = '';
    var i;
    ad_start += check_referrer() ? 2 : 0;

    if (google_ads.length > ad_start) {
        s += '<div id="google_adsense_2nd">';
        for (i = ad_start; i < ad_start+4 && i < google_ads.length; i++) {
            s += '<p class="google-ads ad-type3"><a href="' + google_ads[i].url + '" ' +
                'onmouseout="window.status=\'\'" ' +
                'onmouseover="window.status=\'go to ' +
                google_ads[i].visible_url + '\'" ' +
                ' target="_blank">' +
                '<span class="sitename">' +
               google_ads[i].line1 + '</span>' + 
                '<span  class="siteurl">' +
                google_ads[i].visible_url + '</span><br /><span class="sitetext">' +
                google_ads[i].line2 +
                google_ads[i].line3 + '</span></a></p>';
        }
        s += '</div>';
        document.write(s);
        return;
    }
}
