var NecessaryVersion = 8;
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;

if(plugin){
	var words = navigator.plugins["Shockwave Flash"].description.split(" ");
	for(var i = 0;i < words.length;++i){
		if(isNaN(parseInt(words[i]))) continue;
		var YourVersion = words[i];
	}
	var YouCanPlay = YourVersion >= NecessaryVersion;
}else if(navigator.userAgent && navigator.userAgent.indexOf("MSIE") >= 0 && (navigator.appVersion.indexOf("Win") != -1)){
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('YouCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & NecessaryVersion)))\n');
	document.write('</SCR' + 'IPT\>\n');
}


function MailWin(pc) {
var PGMCODE = pc;
		
	Width = 550;
	Height = 520;
	/* Url = "https://wwws.fujitv.co.jp/safe/red_mpl/response/res_form.cgi?bancode=" + PGMCODE + "&flash=" + (Fiash = YouCanPlay ? 1 : 0) + "&type=resprg"; */
	Url = "https://wwws.fujitv.co.jp/safe/red_mpl/response/res_form.cgi?bancode=" + PGMCODE + "&flash=" + (Fiash = YouCanPlay ? 1 : 0) + "&type=resprg";
	WName = "SendM";
	if(document.getElementById){
		ScreenW = "\,left=" + ((screen.width / 2) - (Width / 2));
		ScreenH = "\,top=" + ((screen.height / 2) - (Height / 2));
	}else{
		ScreenW = "";
		ScreenH = "";
	}
	OptionW = "location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no,fullscreen=no,directories=no,width=" + Width + ",height=" + Height + ScreenH + ScreenW;
	window.open(Url,WName,OptionW);
}

function MailWin_NoPGM(tc) {
var TYPE = tc;
		
	Width = 550;
	Height = 520;
	/* Url = "https://wwws.fujitv.co.jp/safe/red_mpl/response/res_form.cgi?type=" + TYPE + "&flash=" + (Fiash = YouCanPlay ? 1 : 0); */
	Url = "https://wwws.fujitv.co.jp/safe/red_mpl/response/res_form.cgi?type=" + TYPE + "&flash=" + (Fiash = YouCanPlay ? 1 : 0);
	WName = "SendM";
	if(document.getElementById){
		ScreenW = "\,left=" + ((screen.width / 2) - (Width / 2));
		ScreenH = "\,top=" + ((screen.height / 2) - (Height / 2));
	}else{
		ScreenW = "";
		ScreenH = "";
	}
	OptionW = "location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no,fullscreen=no,directories=no,width=" + Width + ",height=" + Height + ScreenH + ScreenW;
	URLOpener.open(Url,WName,OptionW);
}

var ScreenWWON,ScreenHWON,OptionWWON;

function NewwinWON(UrlWON){
	WidthWON = 500;
	HeightWON = 367;
	UrlWON = "https://wwws.fujitv.co.jp/safe/msvcplus/wan_load.html?" + arguments[0];
	if(document.getElementById){
		ScreenWWON = (screen.width / 2) - (WidthWON / 2);
		ScreenHWON = (screen.height / 2) - (HeightWON / 2);
	}else{
		ScreenWWON = 0;
		ScreenHWON = 0;
	}
	OptionWWON = "location=no,menubar=no,resizable=yes,scrollbars=no,status=yes,toolbar=no,fullscreen=no,directories=no,width=" + WidthWON + ",height=" + HeightWON + ",top=" + ScreenHWON + ",left=" + ScreenWWON;
	URLOpener.open(UrlWON,"WON",OptionWWON);
}


function URLOpener() {
}

URLOpener.open = function(url, target, options) {

	if ( location.href.indexOf("b_hp") !== -1 && target === "spot" ) {
		var _oainfo = ( location.href.indexOf("index.html") !== -1 ) ? location.href.replace("index.html", "oainfo.xml"): location.href + "oainfo.xml";
		//var _oainfo = location.href.replace("index.html", "oainfo.xml");
		$.ajax({
			type: "GET", url: _oainfo, dataType: "xml", cache: true, success: function(xml) {
				$(xml).find("flvs").each(function(i) {
					var _x = URLOpener.xml(this);
					fujiplayer.show(_x.mplus.split("=")[1], _x.movie, "spot");
				});
			}
		});

		return;
	}

	if (URLOpener.isSafari()) {
		URLOpener.clickEvent(url, target, options);
		return;
	}

	window.open(url, target, options);
};

URLOpener.clickEvent = function(url, target, options) {
	var div = document.createElement('div');
	div.onclick = function() {
		window.open(url, target, options);
	};

	var event = document.createEvent('MouseEvents');
	event.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
	div.dispatchEvent(event);
};

URLOpener.isSafari = function() {
	return (
		navigator.userAgent != null &&
		navigator.userAgent.indexOf("Safari") >= 0 &&
		navigator.userAgent.indexOf("Chrome") < 0
	);
};

URLOpener.xml = function(_this) {
	var _r = {
		"date": $(_this).find("date").text(),
		"title": $(_this).find("title").text(),
		"subtitle": $(_this).find("subtitle").text(),
		"overview": $(_this).find("overview").text(),
		"cast": $(_this).find("cast").text(),
		"mplus": $(_this).find("mplus").text(),
		"movie": $(_this).find("movie").text()
	}
	return _r;
}

