
function initAffImage() {
	var objImageArea = document.getElementById('affimage-cformat-0158');
	if (objImageArea) {
		var strAltText = '';
		var objLinks = objImageArea.getElementsByTagName('a');
		if (objLinks[0]) { strAltText = objLinks[0].innerHTML; }

		objImageArea.innerHTML = '';
		var objAffLink = document.createElement('a');
		objAffLink.target = '_blank';
		objAffLink.href = 'http://click.duga.jp/ppv/cformat-0158/1667-01';
		var objAffImage = document.createElement('img');
		objAffImage.src = 'http://pic.duga.jp/unsecure/cformat/0158/noauth/240x180.jpg';
		objAffImage.width = '240';
		objAffImage.height = '180';
		objAffImage.alt = strAltText;
		objAffLink.appendChild(objAffImage);
		objImageArea.appendChild(objAffLink);
	}

	// イベント送信
	google_analytics_send_event('1667', decodeURI('%E5%BA%83%E5%91%8A%E7%B4%A0%E6%9D%90'), decodeURI('%E3%83%AA%E3%82%AF%E3%82%A8%E3%82%B9%E3%83%88'), decodeURI('%E3%82%B5%E3%83%A0%E3%83%8D%E3%82%A4%E3%83%AB'), '1');
}
if (navigator.userAgent.indexOf('MSIE') != -1) {
	IEContentLoaded(window, initAffImage);
} else {
	document.addEventListener('DOMContentLoaded', initAffImage, false);
}

/**************************************************************
 *  Google Analytics
 **************************************************************/
var GA_MEASUREMENT_ID = 'UA-33035204-4';
// var GA_MEASUREMENT_ID = 'UA-134544554-1'; // 開発用

function loadScript(src, callback, charset) {
    var done = false;
    var head = document.getElementsByTagName('head')[0];
    var script = document.createElement('script');
	script.type = 'text/javascript';
	if (charset) { script.charset = charset; }
    script.src = src;
    head.appendChild(script);
    // Attach handlers for all browsers
    script.onload = script.onreadystatechange = function() {
        if ( !done && (!this.readyState ||
                this.readyState === 'loaded' || this.readyState === 'complete') ) {
            done = true;
            callback();
            // Handle memory leak in IE
            script.onload = script.onreadystatechange = null;
            if ( head && script.parentNode ) {
                head.removeChild( script );
            }
        }
    };
}

function google_analytics_send_event(uid, category, action, label, value) {
	loadScript('https://www.googletagmanager.com/gtag/js?id=' + GA_MEASUREMENT_ID, function () {
		window.dataLayer = window.dataLayer || [];
		function gtag(){ dataLayer.push(arguments); }
		gtag('js', new Date());
	
		gtag('config', GA_MEASUREMENT_ID, {
			'user_id': uid,
			'send_page_view': false
		});
		  
		gtag('event', action, {
			'event_category': category,
			'event_label': label,
			'value': value
		});
	}, 'UTF-8');
}

/*
 *
 * IEContentLoaded.js
 *
 * Author: Diego Perini (diego.perini at gmail.com) NWBOX S.r.l.
 * Summary: DOMContentLoaded emulation for IE browsers
 * Updated: 05/10/2007
 * License: GPL
 * Version: TBD
 *
 * Copyright (C) 2007 Diego Perini & NWBOX S.r.l.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see http://javascript.nwbox.com/IEContentLoaded/GNU_GPL.txt.
 *
 */

// @w	window reference
// @fn	function reference
function IEContentLoaded (w, fn) {
	var d = w.document, done = false,
	// only fire once
	init = function () {
		if (!done) {
			done = true;
			fn();
		}
	};
	// polling for no errors
	(function () {
		try {
			// throws errors until after ondocumentready
			d.documentElement.doScroll('left');
		} catch (e) {
			setTimeout(arguments.callee, 50);
			return;
		}
		// no errors, fire
		init();
	})();
	// trying to always fire before onload
	d.onreadystatechange = function() {
		if (d.readyState == 'complete') {
			d.onreadystatechange = null;
			init();
		}
	};
}
