var ads = "";


var min_three_ads_width = 1000;

function findParam(param, def)
{
    param += "=";
    var res = def;
    URL = self.location.href;
    var p = URL.indexOf(param);
    if (p == -1)
        {
	    return res;
        } else
        {
	    var temp = URL.substring(p + param.length);
	    pe = temp.indexOf("&");
	    if (pe == -1) pe = temp.length;
	    res = temp.substring(0, pe);
        }
    return Number(res);
}

function findWidth()
{
    var width = 1200;
    if (typeof(window.innerWidth) == 'number')
	width = window.innerWidth;
    else if (document.documentElement &&
	(document.documentElement.clientWidth)) 
	width = document.documentElement.clientWidth;
    else if (document.body && (document.body.clientWidth))
	width = document.body.clientWidth;
    return width;
}

function google_display_ad(google_ads, type, start, id) {
    //alert ("boto: " + type + "|" + start + "|" + id);
    ads = "";
    if (type == 1) {
        wstyle = " style='width:45%'";
	count = 2;
        if (google_afs_w == 3) {
            wstyle = " style='width:30%'";
        }
        if (google_ads.length > start) {
            ads += "<p id='googleAdsenseLink'><a href='https://www.google.com/adsense/support/bin/request.py?contact=afs_violation'>" + adsText + "</a></p>\n"
	    for(i = start; i < Math.min(google_ads.length, start+google_afs_w); i++) {
		ads += "<div class='googleAdsenseAd'" + wstyle + ">\n";
		ads += "<span><a href='" + google_ads[i].url + "'>" + google_ads[i].line1 + "</a></span>\n";
		ads += "<a href='" + google_ads[i].url + "'>" + "</a> " + google_ads[i].line2 + " " + google_ads[i].line3;
		ads += "\n<br><a href='" + google_ads[i].url + "'><span>" + google_ads[i].visible_url + "</span></a> " ;
		ads += "</div>\n";
	    }
 	    ads += "<div class='clear'></div>\n";
	    $(id).html(ads);
	    $(id).css("padding", "0 5px");
	}
    }
    else if (type == 2) {
        if (google_ads.length > start) {
            ads += "<p id='googleAdsenseLink'><a href='https://www.google.com/adsense/support/bin/request.py?contact=afs_violation'>" + adsText + "</a></p>\n"
	    for(i = start; i < Math.min(google_ads.length, start+3); i++) {
	        ads += "<div class='googleAdsenseAd' style='width:90%'>\n";
	        ads += "<span><a href='" + google_ads[i].url + "'>" + google_ads[i].line1 + "</a></span>\n";
	        ads += "<a href='" + google_ads[i].url + "'>" + "</a> " + google_ads[i].line2 + " " + google_ads[i].line3;
	        ads += "\n<br><a href='" + google_ads[i].url + "'><span>" + google_ads[i].visible_url + "</span></a> " ;
	        ads += "</div>\n";
	    }
 	    ads += "<div class='clear'></div>\n";
	    $(id).html(ads);
	    $().css("padding", "0 5px");
	}
    }
}

function google_afs_request_done(google_ads) {
    if ((ad_format >= 0) && (ad_format <= 2)) {
	google_display_ad(google_ads, 1, 0, "p#googleAdsense");
    }
    else if ((ad_format >= 3) && (ad_format <= 4)) {
	google_display_ad(google_ads, 2, 0, "p#googleAdsense");
    }
    else if ((ad_format >= 21)) {
	// Format to display in the first Google ad unit
	//  0 = none
	//  1 = horizontal
        //  2 = vertical
	afs_1 = [2, 2, 2, 2, 2, 1, 1, 2, 2, 2,
		 2, 2, 2, 1, 2, 1, 2, 1, 2, 1,
		 2, 2, 2, 2];
	// Format to display in the second Google ad unit
	afs_2 = [1, 2, 0, 0, 0, 1, 2, 0, 0, 0,
		 2, 2, 2, 0, 0, 0, 0, 0, 0, 0,
		 0, 2, 0, 0];
	google_display_ad(google_ads, afs_1[ad_format-21], 0, "p#googleAdsense");
	google_display_ad(google_ads, afs_2[ad_format-21], google_afs_w, "p#googleAdsense2");
    }
}

google_afs_adtest = 'off';
//google_afs_adtest = 'on';

//ad_format = 1;
google_afs_ad = 'n2'; // specify the number of ads you are requesting
google_afs_w = 2;
if ((ad_format == '3') || (ad_format == '4') || (findWidth() > min_three_ads_width)) {
    google_afs_w = 3;
    google_afs_ad = 'n3'; // specify the number of ads you are requesting
}
if (ad_format > '4') {
    google_afs_ad = 'n0'; // specify the number of ads you are requesting
}
if (ad_format > 20) {
    // Number of horizontal ad displays (eg 0-2 displays of perhaps 2-3 ads each)
    n_afs_h = [1, 0, 0, 0, 0, 2, 1, 0, 0, 0,
	       0, 0, 0, 1, 0, 1, 0, 1, 0, 1,
	       0, 0, 0, 0];
    // Number of vertical ad displays (eg 0-2 displays of perhaps 3 ads each)
    n_afs_v = [1, 2, 1, 1, 1, 0, 1, 1, 1, 1,
	       2, 2, 2, 0, 1, 0, 1, 0, 1, 0,
	       1, 2, 1, 1];
    var f = 2;
    if (findWidth() > min_three_ads_width) {
	google_afs_w = 3;
	f = 3;
    }
    google_afs_ad = 'n' + (n_afs_h[ad_format - 21]*f + n_afs_v[ad_format-21]*3); // specify the number of ads you are requesting
}
google_afs_client = 'pub-2751238045634895'; // substitute your client ID

google_afs_ie = 'utf8';;
google_afs_oe = 'utf8';

