﻿function InitGAFS(afs_query, afs_ad, afs_client, afs_channel, afs_adpage) {
    google_afs_query = afs_query;
    google_afs_ad = afs_ad; // specify the number of ads you are requesting
    google_afs_client = afs_client; // substitute your client ID
    google_afs_channel = afs_channel; // enter your comma-separated channel IDs
    google_afs_hl = "zh-CN"; // enter your interface language if not English
    google_afs_gl = 'cn';
    //google_afs_ie = 'gb2312'; // select input encoding scheme
    //google_afs_oe = 'gb2312'; // select output encoding scheme
    google_afs_adsafe = 'medium'; // specify level for filtering non-family-safe ads
    google_afs_adtest = 'off'; // ** set parameter to off before launch to production
    google_afs_adpage = afs_adpage;
}
function OutputGAFS() {
    //document.write(unescape("%3Cscript type='text/javascript' language='JavaScript' src='http://www.google.com/afsonline/show_afs_ads.js'%3E%3C/script%3E"));
    document.write(unescape("%3Cscript type='text/javascript' language='JavaScript' src='http://www.google.cn/afsonline/show_afs_ads_cn.js'%3E%3C/script%3E"));
}

function InitGAFC(ad_client, ad_channel, max_num_ads, ad_type, image_size) {
    google_ad_client = ad_client; // 此处填上您的pub-id号码(pub-#)
    google_ad_channel = ad_channel;
    google_ad_output = 'js';
    google_max_num_ads = max_num_ads;
    google_ad_type = ad_type;
    google_image_size = image_size;
    google_feedback = 'on';
}
function OutputGAFC() {
    document.write(unescape("%3Cscript type='text/javascript' language='JavaScript' src='http://pagead2.googlesyndication.com/pagead/show_ads.js'%3E%3C/script%3E"));
}

var g_bGWShow = false;
var g_bGNShow = false;
function google_afs_request_done(google_ads) {
    /*
    * Verify that there are actually ads to display.
    */
    var google_num_ads = google_ads.length;
    //    if (google_num_ads <= 0)
    //        return;

    var wideAds = "";   //wide ad unit html text
    var wideAds2 = "";   //wide ad unit html text
    var narrowAds = "";   //narrow ad unit html text
    var narrowAds2 = ""; //wide2narrow ad unit html text

    var bWideClosed = false;
    var bWideClosed2 = false;
    for (i = 0; i < google_num_ads; i++) {
        if (google_ads[i].type == "text/wide") {
            //** render a wide ad
            if (i < 4) {
                if (i % 2 == 0) {
                    bWideClosed = false;
                    wideAds += '<div class="gaitem gaitemw">';
                    //wideAds += '<div class="chkitem"><input type="checkbox" disabled="true"/></div>';
                    //wideAds += '<div class="galimg"><a target="_blank" href="' + google_ads[i].url + '"><img src="http://img.zhigou.com/images/no-100_100.gif" alt="' + google_ads[i].line1 + '" /></a></div>';
                }
                wideAds += '<span class="gatitle"><a target="_blank" href="' + google_ads[i].url + '">' +
                google_ads[i].line1 + '</a></span>' +
                '<span class="gatext">' + google_ads[i].line2 +
                '<a target="_blank" href="' + google_ads[i].url + '">' + google_ads[i].visible_url + '</a></span>';
                if (i % 2 == 1) {
                    bWideClosed = true;
                    wideAds += '</div>';
                }

                //render a wide2narrow ad
                narrowAds2 += '<div class="gaitem">';
                narrowAds2 += '<span class="gatitle"><a target="_blank" href="' + google_ads[i].url + '">' +
                                        '<b>' + google_ads[i].line1 + '</b></a></span>' +
                                        '<span class="gatext">' + google_ads[i].line2 + '</span>' +
                                        '<span class="gasite"><a target="_blank" href="' + google_ads[i].url + '">' +
                                        google_ads[i].visible_url + '</a></span>';
                narrowAds2 += '</div>';
            }
            else {
                if (i % 2 == 0) {
                    bWideClosed2 = false;
                    wideAds2 += '<div class="gaitem gaitemw">';
                    //wideAds2 += '<div class="chkitem"><input type="checkbox" disabled="true"/></div>';
                    //wideAds2 += '<div class="galimg"><a target="_blank" href="' + google_ads[i].url + '"><img src="http://img.zhigou.com/images/no-100_100.gif" alt="' + google_ads[i].line1 + '" /></a></div>';
                }
                wideAds2 += '<span class="gatitle"><a target="_blank" href="' + google_ads[i].url + '">' +
                google_ads[i].line1 + '</a></span>' +
                '<span class="gatext">' + google_ads[i].line2 +
                '<a target="_blank" href="' + google_ads[i].url + '">' + google_ads[i].visible_url + '</a></span>';
                if (i % 2 == 1) {
                    bWideClosed2 = true;
                    wideAds2 += '</div>';
                }
            }
        }
        else {
            //render a narrow ad
            narrowAds += '<div class="gaitem">';
            narrowAds += '<span class="gatitle"><a target="_blank" href="' + google_ads[i].url + '">' +
            '<b>' + google_ads[i].line1 + '</b></a></span>' +
            '<span class="gatext">' + google_ads[i].line2 + ' ' + google_ads[i].line3 + '</span>' +
            '<span class="gasite"><a target="_blank" href="' + google_ads[i].url + '">' +
            google_ads[i].visible_url + '</a></span>';
            narrowAds += '</div>';
        }
    }
    if (narrowAds != "") {
        g_bGNShow = true;
        narrowAds = '<div class="gahead"><a href="https://www.google.com/adsense/support/bin/request.py?contact=afs_violation" target="_blank">Google提供的广告</a></div>' + narrowAds;
    }
    if (narrowAds2 != "") {
        g_bGNShow = true;
        narrowAds2 = '<div class="gahead"><a href="https://www.google.com/adsense/support/bin/request.py?contact=afs_violation" target="_blank">Google提供的广告</a></div>' + narrowAds2;
    }

    if (wideAds != "") {
        g_bGWShow = true;
        if (!bWideClosed) {
            bWideClosed = true;
            wideAds += '</div>';
        }
        wideAds = '<div class="gahead"><span class="text"><a href="https://www.google.com/adsense/support/bin/request.py?contact=afs_violation" target="_blank">Google提供的广告</a></span></div>' + wideAds; //<span class="link">欢迎到智购网选购' + g_queryWord + '</span>
    }

    if (wideAds2 != "") {
        g_bGWShow = true;
        if (!bWideClosed2) {
            bWideClosed2 = true;
            wideAds2 += '</div>';
        }
        wideAds2 = '<div class="gahead"><span class="text"><a href="https://www.google.com/adsense/support/bin/request.py?contact=afs_violation" target="_blank">Google提供的广告</a></span></div>' + wideAds2; //<span class="link">欢迎到智购网选购' + g_queryWord + '</span>
    }

    //** Write HTML for wide and narrow ads to the proper <div> elements
    if(wideAds!=""){
    $("#gwcon").html(wideAds);$("#gwcon").show();}
    if(wideAds2!=""){
    $("#gwcon2").html(wideAds2);$("#gwcon2").show();}
    if(narrowAds!=""){
    $("#gncon").html(narrowAds);$("#gncon").show();}
    else {
        if (narrowAds2 != "") {
            $("#gncon").html(narrowAds2); $("#gncon").show();
        }
        else {
            g_bShowGGNarrowADOnly = true;
            InitGAFC('pub-3388570396365381', '6513415927', '4', 'text', '728X90');
            OutputGAFC();
        }
    }
}

var afc728A='';
var afc728B='';
var afc160A='';
var g_bShowGGNarrowADOnly = false;
var g_cShowGGNarrowADs = 3;
var g_cShowGGWideADsA = 3;
function google_ad_request_done(google_ads) {
    /*
    * 该函数是必须的，是用于展示来自JavaScript请求的
    * 广告。您可以修改本段代码以使其符合您网页的
    * 设计和布局的命令
    */
    afc728A = '';
    afc728B = '';
    afc160A='';
    var i;
    /*
    * 验证此处真的有广告展示。
    */
    if (google_ads.length == 0) {
        return;
    }
    /*
    * 如果返回的是一个图片或Flash广告，则展示该广告。
    * 否则，建立一个包含所有广告的字符串之后再使用
    * document.write 命令打印该字符串
    */
    if (google_ads[0].type == "text") {
        /*
        * 发布商可以修改文字大小。
        * 使文字占用广告单元的大部分空间。
        */
        if (!g_bShowGGNarrowADOnly) {
            for (i = 0; i < google_ads.length && i < g_cShowGGWideADsA; ++i) {
                afc728A += '<p class="adt"><a href="' +
                google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'去 ' +
                google_ads[i].visible_url + '\';return true">' +
                google_ads[i].line1 + '</a></p><p class="adc">' +
                google_ads[i].line2 + '  ' +
                google_ads[i].line3 + '</p><p class="adu"><a href="' +
                google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'去 ' +
                google_ads[i].visible_url + '\';return true">' +
                google_ads[i].visible_url + '</a></p>';
            }
            for (; i < google_ads.length && i < (g_cShowGGNarrowADs + g_cShowGGWideADsA); ++i) {
                afc160A += '<p class="adt"><a href="' +
                google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'去 ' +
                google_ads[i].visible_url + '\';return true">' +
                google_ads[i].line1 + '</a></p><p class="adc">' +
                google_ads[i].line2 + '  ' +
                google_ads[i].line3 + '</p><p class="adu"><a href="' +
                google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'去 ' +
                google_ads[i].visible_url + '\';return true">' +
                google_ads[i].visible_url + '</a></p>';
            }
            for (; i < google_ads.length; ++i) {
                afc728B += '<p class="adt"><a href="' +
                google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'去 ' +
                google_ads[i].visible_url + '\';return true">' +
                google_ads[i].line1 + '</a></p><p class="adc">' +
                google_ads[i].line2 + '  ' +
                google_ads[i].line3 + '</p><p class="adu"><a href="' +
                google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'去 ' +
                google_ads[i].visible_url + '\';return true">' +
                google_ads[i].visible_url + '</a></p>';
            }
        }
        else{
            for(i = 0; i < google_ads.length; ++i) {
                afc160A += '<p class="adt"><a href="' +
                google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'去 ' +
                google_ads[i].visible_url + '\';return true">' +
                google_ads[i].line1 + '</a></p><p class="adc">' +
                google_ads[i].line2 + '  ' + 
                google_ads[i].line3 + '</p><p class="adu"><a href="' +
                google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'去 ' +
                google_ads[i].visible_url + '\';return true">' +
                google_ads[i].visible_url + '</a></p>';
            }
        }
    }
    if (!g_bShowGGNarrowADOnly) {
        if (afc160A != "") {
            afc160A = '<p class="ggt"><a href=\"' + google_info.feedback_url + '\">Google提供的广告</a></p>' + afc160A;
            $("#ad160").html(afc160A); $("#ad160").show();
        }
        if (afc728A != "") {
            afc728A = '<p class="ggt"><a href=\"' + google_info.feedback_url + '\">Google提供的广告</a></p>' + afc728A;
            $("#ad728").html(afc728A); $("#ad728").show();
        }
        if (afc728B != "") {
            afc728B = '<p class="ggt"><a href=\"' + google_info.feedback_url + '\">Google提供的广告</a></p>' + afc728B;
            $("#ad728B").html(afc728B); $("#ad728B").show();
        }
    }
    else {
        if (afc160A != "") {
            afc160A = '<p class="ggt"><a href=\"' + google_info.feedback_url + '\">Google提供的广告</a></p>' + afc160A;
            $("#ad160").html(afc160A); $("#ad160").show();
        }
    }
}