﻿function msObj(width, height, chartHeight, boolShowValueMax, boolShowValueMiddle){
	this.width = width;
	this.height = height;
	this.chartHeight = chartHeight;
	this.boolShowValueMax = boolShowValueMax;
	this.boolShowValueMiddle = boolShowValueMiddle;
}
//HTMLにflashタグの書き込み
msObj.prototype = {
	name : "externalgbms",
	width : 550,
	height : 365,
	chartHeight : 0,
	swfPath : "../chart/morningstar.swf",
	boolShowValueMax : true,
	boolShowValueMiddle : true,
	swf : {},
	
	draw : function(writeAreaID, code){
		this.code = code ? code : this.code;
		var so = new SWFObject(this.swfPath, this.name, this.width, this.height, "8", "#FFFFFF");

		// Flashオブジェクト内の変数にパラメータを付与
		so.addParam("menu", "false");
		so.addVariable("movieName", "msObj.gbms");
		so.addVariable("code", this.code);
		so.addVariable("INTERFACE_DIR_PATH", msObj.INTERFACE_DIR_PATH);

		so.addVariable("param_stage_width", this.width);
		so.addVariable("param_stage_height", this.height);
		so.addVariable("param_main_graph_height", this.chartHeight);
		so.addVariable("param_net_assets_graph_height", this.height - this.chartHeight - 10);
		so.addVariable("param_bool_showValueMax", this.boolShowValueMax);
		so.addVariable("param_bool_showValueMiddle", this.boolShowValueMiddle);
		
		so.write(writeAreaID);
		this.swf = document.getElementById(this.name);
		this.swf.onmouseout = function(){msObj.gbms.setter_MouseOuter();};
		var writeArea = document.getElementById(writeAreaID);

		// Flashのサイズおよびスタイル指定
		writeArea.style.width = this.width;
		writeArea.style.height = this.height;
		writeArea.style.borderColor = "#999999";
		writeArea.style.borderWidth = "1";
		writeArea.style.borderStyle = "solid";
	},
	//設定（期間やグラフの表示および対数など）変更メソッド
	setter_addObj : function(obj){
		this.swf.AddObj(obj);
	},
	//ファンド追加命令メソッド
	setter_addCode : function(codes){
		this.swf.AddCode(codes);
	},
	//ファンド削除命令メソッド
	setter_deletionCode : function(codes){
		this.swf.DeletionCode(codes);
	},
	//ファンド一意制約エラーメソッド
	setter_duplicate : function(codes){
		this.swf.DuplicateErr(codes);
	},
	setter_MouseOuter : function(){
		this.swf.MouseOuter();
	}
}

msObj.gbms = {};
msObj.codeArr = {};
msObj.INTERFACE_DIR_PATH = "../chart/normal/interface/";
//グラフ生成
msObj.createGraph = function (writeAreaID, width, height, param){
var chartHeight=280;
var boolShowValueMax=0;
var boolShowValueMiddle=1;

	msObj.gbms = new msObj(width, height, chartHeight, boolShowValueMax, boolShowValueMiddle);
	msObj.gbms.code = param;
	msObj.gbms.draw(writeAreaID, null);	
}

//flashへ設定（期間やグラフの表示および対数など）の受け渡し（オブジェクト「gbms」への中継）
msObj.addObj = function (obj){
	msObj.gbms.setter_addObj(obj);
}

//グラフの表示期間を変更
msObj.changePeriod = function (type){
	msObj.gbms.setter_addObj({type : 'scale', name : type});
}

//チャートの表示非表示を変更
msObj.setChartVisible = function (type, visible){
	msObj.gbms.setter_addObj({type : 'graph', name : type, checked : visible});
}

//flashへコードの受け渡し
//（オブジェクト「gbms」への中継および複数コードの配列化およびコードが重複した場合は削除）
msObj.addCode = function (code){
	var addarr = new Array();
	var delarr = new Array();
	var codes = code.split(",");
	for(var i = 0; i < codes.length; i++){
		//msObj.codeArr[codes[i]] = codes[i];
		addarr.push(codes[i]);
	}
	if(addarr.length > 0) {
		msObj.gbms.setter_addCode(addarr);
	}
}

msPeriodType = {
	P00 : '1ヶ月',
	P01 : '3ヶ月',
	P02 : '6ヶ月',
	P03 : '1年',
	P04 : '3年',
	P05 : '5年',
	P06 : '10年',
	P07 : '設定来'
}

msChartType = {
	C00 : "基準価格",
	C01 : "分配金込み（再投資）",
	C02 : "分配金込み（受取）",
	C03 : "純資産"
}

//エラーハンドラ
function onIrregular(event){
	switch(event.type){
		case "I00":
			//リクエストしたファンドが見つからない場合
			break;
		case "I01":
			//リクエストしたファンドがすでに表示されていた場合
			break;
		case "I02":
			//リクエストしたファンドを表示する際に、上限比較個数を越えた場合
			break;
		case "I03":
			//表示対象日別単位（日別、週別、月別）が存在しない場合
	}
	//メッセージ
	alert(event.message);
}


function graphsFund(params)
{
	var objBody = document.getElementById("MorningstarFundTitle");
	objBody.innerHTML = "";
	for(var i = 0; i < params.length; i++){
		param = params[i];
		objBody.innerHTML += '<form>';
		objBody.innerHTML += '<table>';
		objBody.innerHTML += '<tbody>';
		objBody.innerHTML += '<tr>';
		objBody.innerHTML += '<td>';
		objBody.innerHTML += '<span id="border'+param.num+'">┃</span>';
		objBody.innerHTML += '</td>';
		objBody.innerHTML += '<td>';
		objBody.innerHTML += '<span id="fund_name'+param.num+'">'+param.name+'</span>';
		objBody.innerHTML += '</td>';
		objBody.innerHTML += '</tr>';
		objBody.innerHTML += '</tbody>';
		objBody.innerHTML += '</table>';
		objBody.innerHTML += '</form>';
		var border = "border"+param.num;
		document.getElementById(border).style.color = param.color;
		document.getElementById(border).style.fontSize = '10pt';
		var fund_name = "fund_name"+param.num;
		document.getElementById(fund_name).style.fontSize = '10pt';
	}
}

function graphsColor(param){
	if(document.getElementById("markerPrice")) document.getElementById("markerPrice").style.color = param.markerPriceColor;
	if(document.getElementById("plowBack")) document.getElementById("plowBack").style.color = param.plowBackColor;
	if(document.getElementById("receipt")) document.getElementById("receipt").style.color = param.receiptColor;
	if(document.getElementById("netAssets")) document.getElementById("netAssets").style.color = param.netAssetsColor;
}

//別途SWFObjectを読み込んでいる場合は、以降のコードを削除した方が容量の削減になります。
//（SWFObject v2.0等上位バージョンを使用している場合には要検証）
/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;