(function(){
/* property */
var U="swf/hh.swf",
H="http://www.lifenet-seimei.co.jp/plan/",
ID="externalInterface",
fSize={w:835,h:615},
title="&#x3044;&#x304F;&#x3089;&#x5FC5;&#x8981;&#xFF1F;&#x79C1;&#x306E;&#x4FDD;&#x967A;&#x91D1;&#x5B;&#x30E9;&#x30A4;&#x30D5;&#x30CD;&#x30C3;&#x30C8;&#x751F;&#x547D;&#x4FDD;&#x967A;&#x682A;&#x5F0F;&#x4F1A;&#x793E;&#x5D;",
required="9".split(".");

var W=window,
D=document,
F="getElementsByTagName",
UA=navigator.userAgent,
Win=/Win/.test(UA),
Mac=/Mac/.test(UA),
IE=(D.all&&!W.opera),
IE6=(IE&&parseFloat(UA.match(/MSIE ([\d\.]+)/)[1])<7);

if(!D[F])return;

var scripts = D[F]("script");
scripts = scripts[scripts.length - 1];
var path = (scripts.src.match(/^(.+\/)js\//) || ["",""])[1];
var dir = path.replace(/^https?:\/\/[^\/]+/, "");
var domain = path.substr(0, path.indexOf(dir));
var q = scripts.src.split("?")[1];
var vars = {};
if (q) {
	var qs = q.split("&");
	for (var i = 0, n = qs.length; i < n; i++) {
		var name  = qs[i].substr(0, qs[i].indexOf("="));
		var value = qs[i].substr(qs[i].indexOf("=") + 1);
		vars[name] = encodeURI(value);
	}
}
vars["path"] = domain + dir;
if (!vars["btn"] && vars["type"]) {
	U = "swf/plan.swf";
}
U = (location.href.match(/^https?:/)) ? domain + dir + U : U;

var S=' style="'+[
'clear:both',
'float:none',
'display:block',
'background:transparent none no-repeat scroll 0 0',
'overflow:visible',
'visibility:visible',
'z-index:1000000000',
'position:static',
'margin:0',
'padding:0',
'border:0 none',
'width:auto',
'height:auto',
'min-width:auto',
'min-height:auto',
'max-width:auto',
'max-height:auto',
'text-decoration:none',
'text-align:left',
'vertical-align:baseline'
].join(";")+'"',
oS=S.replace("width:auto","width:"+fSize.w+"px").replace("height:auto","height:"+fSize.h+"px"),
cS=S.replace("position:static","position:absolute;bottom:15px;right:11px"),
fS=oS.replace("position:static","position:fixed"),
iS=fS.replace(/"$/,';top:0;left:0;filter:alpha(style=0,opacity=0)"'),
mS=fS.replace(/"$/,';top:0;left:0;filter:alpha(style=0,opacity=65)"'),
I=" !important;";
if (!IE) {
	var FF = (navigator.userAgent.indexOf("Firefox/") != -1);
	var FF3 = false;
	if (FF) {
		var rev = navigator.userAgent.match(/ Firefox\/([0-9.]+)/);
		if (rev) {
			if (parseFloat(rev[1]) >= 3) {
				FF3 = true;
			}
		}
	}
	if (FF3) {
		mS = mS.replace(
			'background:transparent none no-repeat scroll 0 0',
			'background:#ffffff none repeat scroll 0 0'
		);
	} else {
		mS = mS.replace(
			'background:transparent none no-repeat scroll 0 0',
			'background:transparent url(' + domain + dir + 'img/filter.png) repeat scroll 0 0'
		);
	}
}

/* utility */
function getVersion(){
	var _version = "0";
	var _plugin  = null;
	var _type    = "application/x-shockwave-flash";
	if (navigator.mimeTypes && navigator.mimeTypes[_type]) {
		_plugin = navigator.mimeTypes[_type].enabledPlugin;
		if (_plugin) {
			var _versionStrings = _plugin.description.match(/(\d+(\.\d+)*) +r(\d+)/);
			if (_versionStrings) {
				_version = _versionStrings[1] + "." + ((_versionStrings.length >= 4) ? _versionStrings[3] : 0);
			}
		}
	} else if (typeof(ActiveXObject) == "object" || typeof(ActiveXObject) == "function") {
		var _flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
		if (_flash) {
			var _versionStrings = _flash.GetVariable("$version").match(/(\d+(\,\d+)+)/);
			if (_versionStrings) {
				_version = _versionStrings[1].replace(/,/g, ".");
			}
		}
	}
	return _version;
}
function isEnabled(){
	var pluginVersion = (getVersion()).split(".");
	for (var i = 0, n = required.length; i < n; i++) {
		if (!required[i])      required[i] = 0;
		if (!pluginVersion[i]) pluginVersion[i] = 0;
		if (parseInt(pluginVersion[i]) > parseInt(required[i])) {
			return true;
		} else if (parseInt(pluginVersion[i]) < parseInt(required[i])) {
			return false;
		}
	}
	return true;
}
function param(name,value){return '<param name="'+name+'" value="'+value+'"></param>'}
function getWSize(){
	return {
		w:W.innerWidth||(Mac&&IE?D.body.scrollWidth:D.documentElement.offsetWidth),
		h:W.innerHeight||(Mac&&IE?D.body.scrollHeight:D.documentElement.offsetHeight)
	};
}
function fFixed(){
	return (flashContainer.style.position=="fixed");
}
function fOverSize(){
	var wSize=getWSize();
	return (wSize.w<flashContainer.offsetWidth||wSize.h<flashContainer.offsetHeight);
}
function fMoveTo(node, x,y){
	node.style.top=y+"px";
	node.style.left=x+"px";
}
function fMoveToCenter(x,y){
	var wSize=getWSize();
	var scroll={
		x:!fFixed()?(W.scrollX||D.documentElement.scrollLeft||D.body.scrollLeft||0):0,
		y:!fFixed()?(W.scrollY||D.documentElement.scrollTop||D.body.scrollTop||0):0
	}
	fMoveTo(
		flashContainer,
		Math.max(0,scroll.x+parseInt(wSize.w/2-fSize.w/2)),
		Math.max(0,scroll.y+parseInt(wSize.h/2-fSize.h/2))
	);
}
function fSetPosition(){
	if(fixed&&fFixed()&&fOverSize()){
		flashContainer.style.position="absolute";
	}else if(fixed){
		flashContainer.style.position="fixed";
	}else{
		flashContainer.style.position="absolute";
	}
	if (iframe) {
		if(fixed){
			iframe.style.position="fixed";
		} else {
			iframe.style.position=flashContainer.style.position;
		}
	}
	if (mask) {
		if(fixed){
			mask.style.position="fixed";
		} else {
			mask.style.position=flashContainer.style.position;
		}
	}
	if (flash.isShown == true) {
		var wSize=getWSize();
		var width = Math.max(wSize.w, D.body.offsetWidth, D.documentElement.offsetWidth);
		var height = Math.max(wSize.h, D.body.offsetHeight, D.documentElement.offsetHeight);
		if (iframe) {
			iframe.style.width=width + "px";
			iframe.style.height=height + "px";
			fMoveTo(iframe,0,0);
		}
		if (mask) {
			mask.style.width=width + "px";
			mask.style.height=height + "px";
			fMoveTo(mask,0,0);
		}
	}
}
function fShow(){
	flash.isShown=true;
	if (IE && typeof flash.setActive) {
		flash.setActive();
	}
	flashContainer.style.width=flash.style.width=fSize.w + "px";
	flashContainer.style.height=flash.style.height=fSize.h + "px";
	if (mask && IE) {
		mask.style.backgroundColor="#000000";
	}
	fSetPosition();
	fMoveToCenter();
}
function fHide(){
	flashContainer.style.width=flash.style.width="1px";
	flashContainer.style.height=flash.style.height="1px";
	if (iframe) {
		iframe.style.width=flashContainer.style.width;
		iframe.style.height=flashContainer.style.height;
	}
	if (mask) {
		mask.style.width=flashContainer.style.width;
		mask.style.height=flashContainer.style.height;
		if (IE) mask.style.backgroundColor="transparent";
	}
	flash.isShown=false;
}
function addEvent(node,type,func){
	if(node.addEventListener){
		var _removeListener=function(){
			node.removeEventListener(type,func,false);
			W.removeEventListener("unload",arguments.callee,false);
		}
		node.addEventListener(type,func,false);
		W.addEventListener("unload",_removeListener,false);
	}else if (node.attachEvent){
		var _removeListener=function(){
			node.detachEvent("on"+type,func);
			W.detachEvent("onunload",arguments.callee);
		}
		node.attachEvent("on"+type,func);
		W.attachEvent("onunload",_removeListener);
	}
}


/* main */
D.write('<div'+S+' id="'+ID+'"><a'+S+' href="'+H+'"><img'+S+' src="'+LN_CALCULATOR_IMAGE_URL+'" alt="'+title+'" /></a></div>');
if(!isEnabled()){
	return;
}

D.write('<s' + 'cript type="text/javas' + 'cript" src="' + domain + dir + 'js/compress.js"></s' + 'cript>');
W.LN_STRING_COMPRESSOR = function(str){
	return (new dataCompressor).compress(str)
}
W.LN_HIDE_PANELCONTENT = function(){
	fHide();
}
W.FLASH_TO_JS_FORM = function() {
	var params = {};
	var inputs = [];
	for (var i = 0, n = arguments.length; i < n; i++) {
		if (arguments[i]) {
			var name = arguments[i].substr(0, arguments[i].indexOf(":"));
			var value = arguments[i].substr(arguments[i].indexOf(":") + 1);
			params[name] = value;
		}
	}
	params["insurance"] = parseFloat(params["insurance"]) || 0;
	if (!params["insurance"] || params["insurance"] < 500) {
		params["insurance"] = 500;
	} else if (params["insurance"] > 10000) {
		params["insurance"] = 10000;
	}
	params["insurance"] = (Math.round(params["insurance"] / 100) * 100).toString();
	params["url-param"] = encodeURI(
		(new dataCompressor).compress(
			[
				params["year"]       || "",
				params["month"]      || "",
				params["date"]       || "",
				params["sex"]        || "",
				params["insurance"]  || "",
				params["term"]       || "",
				params["addmission"] || "",
				params["limit"]      || "",
				params["operation"]  || ""
			].join("|")
		)
	);
	location.href = "http://www.lifenet-seimei.co.jp/plan/continue.html?" + params["url-param"];
}
W.FLASH_TO_JS_PARAM = function(){
	var form = D.createElement("form");
	document.body.appendChild(form);
	form.setAttribute("action", "https://www.lifenet-seimei.co.jp/app/sp/wif/e/order");
	form.setAttribute("method", "POST");
	var params = {};
	var inputs = [];
	for (var i = 0, n = arguments.length; i < n; i++) {
		if (arguments[i]) {
			var name = arguments[i].substr(0, arguments[i].indexOf(":"));
			var value = arguments[i].substr(arguments[i].indexOf(":") + 1);
			params[name] = value;
		}
	}
	if (!parseInt(params["total-price"])) return;
	for (var i = 0, n = arguments.length; i < n; i++) {
		if (arguments[i]) {
			var name = arguments[i].substr(0, arguments[i].indexOf(":"));
			var value = arguments[i].substr(arguments[i].indexOf(":") + 1);
			if (params["life-activator"] != "TRUE" && (name == "life-activator" || name == "term" || name == "insurance" || name == "life-price")) {
				continue;
			}
			if (params["medical-activator"] != "TRUE" && (name == "medical-activator" || name == "operation" || name == "limit" || name == "admission" || name == "medical-price")) {
				continue;
			}
			if (name == "param1" || name == "param2" || name == "param3") {
				if (!params[name]) continue;
			}
			inputs.push('<input type="hidden" name="' + name + '" value="' + ((value && value != "undefined") ? encodeURI(value) : "") + '" />');
		}
	}
	form.innerHTML = inputs.join("");
	form.submit();
	document.body.removeChild(form);
}
W.FLASH_TO_JS_MAIL = function(){
	var form = D.createElement("form");
	document.body.appendChild(form);
	form.setAttribute("action", "https://www.lifenet-seimei.co.jp/app/sp/wif/e/mail");
	form.setAttribute("method", "POST");
	var params = {};
	var inputs = [];
	for (var i = 0, n = arguments.length; i < n; i++) {
		if (arguments[i]) {
			var name = arguments[i].substr(0, arguments[i].indexOf(":"));
			var value = arguments[i].substr(arguments[i].indexOf(":") + 1);
			params[name] = value;
		}
	}
	params["url-param"] = encodeURI(
		(new dataCompressor).compress(
			[
				params["year"]       || "",
				params["month"]      || "",
				params["date"]       || "",
				params["sex"]        || "",
				params["insurance"]  || "",
				params["term"]       || "",
				params["addmission"] || "",
				params["limit"]      || "",
				params["operation"]  || ""
			].join("|")
		)
	);
	for (var i = 0, n = arguments.length; i < n; i++) {
		if (arguments[i]) {
			var name = arguments[i].substr(0, arguments[i].indexOf(":"));
			if (name == "url-param") continue;
			var value = arguments[i].substr(arguments[i].indexOf(":") + 1);
			inputs.push('<input type="hidden" name="' + name + '" value="' + ((value && value != "undefined") ? encodeURI(value) : "") + '" />');
		}
	}
	inputs.push('<input type="hidden" name="url-param" value="' + params["url-param"] + '" />');
	form.innerHTML = inputs.join("");
	form.submit();
	document.body.removeChild(form);
}

var iframe, mask, flash, flashContainer;
var div=D.getElementById(ID),
button=div[F]("a")[0],
img=button[F]("img")[0];
if(window.LN_CALCULATOR_IMAGE_SIZE){
	div.style.width=button.style.width=img.style.width=LN_CALCULATOR_IMAGE_SIZE.width+"px";
	div.style.height=button.style.height=img.style.height=LN_CALCULATOR_IMAGE_SIZE.height+"px";
}else{
	addEvent(img,"load",function(){
		div.style.width=button.style.width=img.style.width=img.width+"px";
		div.style.height=button.style.height=img.style.height=img.height+"px";
	});
}
addEvent(button,"click",function(e){
	if(!e)e=W.event;
	if(e.preventDefault){
		e.preventDefault();
	}else{
		e.returnValue=false;
	}
	if(!flash)return;
	if(flash.isShown==false){
		fShow();
	}else{
		fHide();
	}
});

addEvent(W,"resize",function(e){
	if(!flash) return;
	fSetPosition()
	if(flash.isShown==true){
		fMoveToCenter();
	}
});
addEvent(W,"scroll",function(e){
	if(!flash) return;
	if(flash.isShown==true&&!fFixed()&&!fOverSize()){
		fMoveToCenter();
	}
});

addEvent(W,"load",function(e){
	if (!isEnabled()) return;

	if (IE) {
		var temp = document.createElement("div");
		temp.innerHTML = '<iframe src="about:blank"' + iS + '></iframe>';
		iframe = temp.getElementsByTagName("iframe")[0];
		iframe.style.zIndex = "1000000000";
		iframe.style.visibility = "hidden";
		document.body.appendChild(iframe);
	}

	var temp = document.createElement("div");
	temp.innerHTML = '<div' + mS + '></div>';
	mask = temp.getElementsByTagName("div")[0];
	mask.style.zIndex = "1000000001";
	mask.style.visibility = "hidden";
	document.body.appendChild(mask);
	addEvent(mask,"click",function(e){
		fHide();
	});

	var temp = document.createElement("div");
	temp.innerHTML = '<div'+fS+'><object'+oS+'id="flash'+ID+'"'+(!IE?' data="'+U+'"':'')+' type="application/x-shockwave-flash">'+(IE?param("movie",U):'')+param("quality","high")+param("scale","noscale")+param("salign","ct")+param("menu","false")+param("allowScriptAccess","always")+param("wmode","transparent")+param("FlashVars","path="+encodeURI(vars["path"])+"&amp;type="+(vars["type"]||"")+"&amp;btn="+(vars["btn"]||"")+"&amp;param1="+(vars["param1"]||"")+"&amp;param2="+(vars["param2"]||"")+"&amp;param3="+(vars["param3"]||""))+'</object></div>';
	flash=temp[F]("object")[0];
	flashContainer=temp[F]("div")[0];
	flashContainer.style.position=mask.style.position=(IE6||(flashContainer.currentStyle&&flashContainer.currentStyle.position=="static"))?"absolute":"fixed";
	if (iframe) {
		iframe.style.position=flashContainer.style.position;
	}
	fixed=(flashContainer.style.position=="fixed");
	flashContainer.style.overflow="hidden";
	flashContainer.style.top="0px";
	flashContainer.style.left="0px";
	flashContainer.style.zIndex="1000000002";
	document.body.appendChild(flashContainer);

	fHide();
	if (iframe) iframe.style.visibility = "visible";
	if (mask)   mask.style.visibility = "visible";
});

})();