var campimg = new Object();
campimg.protocol = document.location.protocol;
campimg.url = campimg.protocol + "//p.ca-mpr.jp/s";

campimg.clear = function() {
	campimg.option = new Object();
	campimg.i4a = "";
}

campimg.createParameter = function() {
	campimg.param = "";
	if ( campimg.i4a ) {
		campimg.param += "i4a=" + campimg.getUrlEncode(campimg.i4a);
	} else if ( campimg.option["cv"]) {
		campimg.param += "";
	} else {
		campimg.param += campimg.getQuery();
	}
	if ( campimg.param == "" ) {
		campimg.param += "rf=" + campimg.getUrlEncode(campimg.getReferrer());
	} else {
		campimg.param += "&rf=" + campimg.getUrlEncode(campimg.getReferrer());
	}
	campimg.param += "&lc=" + campimg.getUrlEncode(campimg.getUrl());
	for ( var val in campimg.option ) {
		if ( campimg.option[val] != "" ) {
			campimg.param += "&" + val + "=" + campimg.getUrlEncode(campimg.option[val]);
		}
	}
	campimg.param += "&ttl="  + campimg.getUrlEncode(campimg.getTitle());
	campimg.param += "&fl="  + campimg.getUrlEncode(campimg.getFlashVersion());
	campimg.param += "&jav=" + campimg.getJavaEnabled();
	campimg.param += "&cke=" + campimg.getCookieEnabled();
	campimg.param += "&col=" + campimg.getColorDepth();
	campimg.param += "&os=" + campimg.getOsName();
	campimg.param += "&brt=" + campimg.getBrowserType();
	campimg.param += "&brv=" + campimg.getBrowserVersion();
	campimg.param += "&scw=" + campimg.getScreenWidth();
	campimg.param += "&sch=" + campimg.getScreenHeight();
	campimg.param += "&wiw=" + campimg.getWindowWidth();
	campimg.param += "&wih=" + campimg.getWindowHeight();
	campimg.param += "&ms=" + campimg.getMilliseconds();
}

campimg.getMilliseconds = function(){
	return new Date().getMilliseconds();
}

campimg.createImgTag = function() {
	imgtag = new Image(1,1);
	imgtag.src = campimg.url + "/" + campimg.i4c + "/" + "?" + campimg.param;
	imgtag.onload = function() { return; }
}

campimg.createImgTagOld = function() {
	if ( document.body ) {
		document.write('<img src="' + campimg.url + "/" + campimg.i4c + "/" + "?" + campimg.param +'" width="1" height="1" >');
	} else {
		imgtag = new Image(1,1);
		imgtag.src = campimg.url + "/" + campimg.i4c + "/" + "?" + campimg.param;
	}
}

campimg.getUrlEncode = function(str) {
	if ( typeof(encodeURIComponent) == 'function' ) {
		return encodeURIComponent(str);
	} else {
		return escape(str);
	}
}

campimg.getQuery = function() {
	var url;

	try {
		if ( document.referrer == parent.location ) {
			url = top.document.location.search;
		} else {
			url = document.location.search;
		}
	} catch (e) {
		url = document.location.search;
	}

	var query = "";
	var urlPram = url.replace("?","");
	var params = urlPram.split("&");
	if (params[0].indexOf("=")>-1) {
		for ( i = 0; i < params.length; i++ ) {
			var key = params[i].split("=")[0];
			var value = params[i].split("=")[1];
			if ( key == "i4a" || key == "i4t" || key == "i4v" ) {
				if ( query == "" ) {
					query = campimg.getUrlEncode(key) + "=" + campimg.getUrlEncode(value);
				} else {
					query += "&" + campimg.getUrlEncode(key) + "=" + campimg.getUrlEncode(value);
				}
			}
		}
	}
	return query;
}

campimg.getReferrer = function() {
	return document.referrer;
}

campimg.getUrl = function() {
	return document.location.href;
}

campimg.getTitle = function() {
	return document.title;
}

campimg.getFlashVersion = function() {
	var ver = "";
	if ( navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] ) {
		var plugin = navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin;
		if (plugin) {
			ver = parseInt(plugin.description.match(/\d+\.\d+/));
		}
	} else if ( window.ActiveXObject ) {
		try {
			var axoFlash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash").GetVariable("$version").match(/([0-9]+)/);
			if (axoFlash) {
				ver = parseInt(axoFlash[0]);
			}
		} catch(e) {
		}
	}
	if ( ver == "" ) {
		ver = 0;
	}
	return ver;
}

campimg.getJavaEnabled = function() {
	return navigator.javaEnabled() ? 1 : 0;
}

campimg.getCookieEnabled = function() {
	return navigator.cookieEnabled ? 1 : 0;
}

campimg.getColorDepth = function() {
	return window.screen.colorDepth;
}

campimg.getOsName = function() {
	var ua = navigator.userAgent.toLowerCase();
	var is = function(t){return ua.indexOf(t)>-1;};
	var osName =
		is('psp')?'PlayStation Portable':
		is('playstation')?'PlayStation':
		is('nintendo wii')?'NintendoWii':
		is('j2me')?'mobile':
		is('iphone;')?'iPhone':
		is('ipod;')?'ipod':
		is('mac')?'Macintosh ':
		is('darwin')?'Macintosh ':
		is('webtv')?'webtv':
		is('win')?'Windows':
		is('freebsd')?'freebsd':
		(is('x11')||is('linux'))?'linux':
		'undefined';
	if (navigator.platform.indexOf("Win") != -1) {
		if (ua.match(/win(dows )?nt 6\.1/)) {
			osName += "7";
		}
		else if (ua.match(/win(dows )?nt 6\.0/)) {
			osName += "Vista";
		}
		else if (ua.match(/win(dows )?nt 5\.2/)) {
			osName += "Server 2003";
		}
		else if (ua.match(/win(dows )?(nt 5\.1|xp)/)) {
			osName += "XP";
		}
		else if (ua.match(/win(dows)? (9x 4\.90|me)/)) {
			osName += "ME";
		}
		else if (ua.match(/win(dows )?(nt 5\.0|2000)/)) {
			osName += "2000";
		}
		else if (ua.match(/win(dows )?98/)) {
			osName += "98";
		}
		else if (ua.match(/win(dows )?nt( 4\.0)?/)) {
			osName += "NT";
		}
		else if (ua.match(/win(dows )?95/)) {
			osName += "95";
		}else{
			osName += "undefined";
		}
			return osName;
		}
	else {
		return osName;
	}
}

campimg.getBrowserType = function() {
	var ua = navigator.userAgent.toLowerCase();
	var ua_includes = function(t){return ua.indexOf(t)>-1;};

	if ( ua_includes('opera') ) {
		if ( /opera[\s\/]\d+\.\d+/.test(ua) ) return 'Opera';
	} else if ( ua_includes('msie') ) {
		if ( /msie\s\d+\.\d+/.test(ua) ) return 'InternetExplorer';
	} else if ( ua_includes('firefox/') ) {
		if ( /firefox\/[\d\.]+/.test(ua) ) return 'Firefox';
	} else if ( ua_includes('applewebkit/') && ua_includes('safari/') ) {
		if ( /chrome\/[\d\.]+/.test(ua) ) return 'google chrome';
		if ( /version\/[\d\.]+/.test(ua) ) return 'safari';
	}
	return 'none';
}

campimg.getBrowserVersion = function() {
	var ua = navigator.userAgent.toLowerCase();
	var ua_includes = function(t){return ua.indexOf(t)>-1;};
	
	if ( ua_includes('opera') ) {
		if ( /opera[\s\/](\d+\.\d+)/.test(ua) ) return RegExp.$1;
	} else if ( ua_includes('msie') ) {
		if ( /msie\s(\d+\.\d+)/.test(ua) ) return RegExp.$1;
	} else if ( ua_includes('firefox/') ) {
		if ( /firefox\/([\d\.]+)/.test(ua) ) return RegExp.$1;
	} else if ( ua_includes('applewebkit/') && ua_includes('safari/') ) {
		if ( /chrome\/([\d\.]+)/.test(ua) ) return RegExp.$1;
		if ( /version\/([\d\.]+)/.test(ua) ) return RegExp.$1;
	}
	return 'none';
}

campimg.getScreenWidth = function() {
	return window.screen.width;
} 

campimg.getScreenHeight = function() {
	return window.screen.height;
}

campimg.getWindowWidth = function() {
	if ( window.innerWidth ) {
		return window.innerWidth;
	}
	if ( document.documentElement.clientWidth ) {
		return document.documentElement.clientWidth;
	}
	return 0;
}

campimg.getWindowHeight = function() {
	if ( window.innerHeight ) {
		return window.innerHeight;
	}
	if ( document.documentElement.clientHeight ) {
		return document.documentElement.clientHeight;
	}
	return 0;
}

campimg.createTag = function() {
	campimg.createParameter();
	campimg.createImgTag();
	campimg.clear();
}

campimg.createTagOld = function() {
	campimg.createParameter();
	campimg.createImgTagOld();
	campimg.clear();
}

campimg.parseOption = function(option) {
	for (var key in option) {
		campimg.option[key] = option[key];
	}
}

campimg.clear();

function createTag(i4c) {
	campimg.i4c = i4c;
	campimg.createTagOld();
}

function createLpTag(i4c){
	campimg.i4c = i4c;
	campimg.createTag();
}
function createCvTag(i4c,cv){
	campimg.i4c = i4c;
	campimg.option["cv"] = cv;
	campimg.createTag();
}
function createFlashLpTag(i4c){
	campimg.i4c = i4c;
	campimg.createTag();
}
function createFixedIdLpTag(i4c,i4a){
	campimg.i4c = i4c;
	campimg.i4a = i4a;
	campimg.createTag();
}
function createFlashCvTag(i4c,cv){
	campimg.i4c = i4c;
	campimg.option["cv"] = cv;
	campimg.createTag();
}
function createFlashCvTagOption(i4c,cv,option){
	campimg.i4c = i4c;
	campimg.parseOption(option);
	campimg.option["cv"] = cv;
	campimg.createTag();	
}