/*PDFダウンロードの調整要JQuery*/document.write("<script type=\"text/javascript\" src=\"_api/download/load_data.php?var_name=download_csvdata\"></script>");/*var download_csvdata = {	2010 : {		1 : {			"jp" : {				"kessantanshin" : [					"path" : "/ir/j/library/result/file/press_030523_1.pdf",					"misc" : ""				]			}		}	}};load_data.phpがCSVファイルを読んで上記のように整形*/$(document).ready(function(){		var PATH_API    = "_api/download/calc_zipsize.php";	var ELEM_WRAP   = $("div.download");	var ELEM_FORM   = $("form",ELEM_WRAP)	var ELEM_SELECT = $("select",ELEM_FORM);	var ELEM_CHECK  = $("input[type=checkbox]",ELEM_FORM);	var ELEM_BUTTON = $("input[type=image]",ELEM_FORM);		function Selector(obj,parent){		/**		* セレクト要素のクラス		*/				/* メインクラスの参照 */		this.parent = parent;				/* select要素 */		this.obj = obj;				/* 値を格納 */		this.value = null;				/* 順番格納用配列 */		this.stock = [];				/* 初期値格納配列 */		this.def = [];		this.Init();	}	Selector.prototype = {		Init : function(){			/**			* 初期化			*/			var S = this;						/* イベントリスナの設定 */			$(this.obj).bind("change",function(){				S.GetValue();				S.parent.Adjust();				S.parent.KindCheck();				S.parent.Post();			});						/* 順番と初期値を格納 */			for(var i=0,l=this.obj.options.length ; i<l ; i++)(function(index,item){				S.stock.push(index);				S.def.push(item.value);			})(i,this.obj.options[i]);						/* 値を格納 */			S.GetValue();					},		GetValue : function(){			/**			* 値を格納			*/			if(this.obj.options.length < 1) this.value = null;			else{				var v = this.obj.options[this.obj.selectedIndex].value;				this.value = (/\d/.test(v)) ? parseInt(v) : v ;			}		},		Enable : function(index){			/**			* 選択肢を有効化			* arg.0 : 初期の並び順			*/			var S = this;			if(arguments.length < 1) return;						/* 現在無効化されている場合のみ */			if(!!this.stock[index] && this.stock[index].nodeType == 1){								/* option要素 */				var opt = this.stock[index];								/* 現在入るべき並び順 */				var s = (function(index){					if(isNaN(S.stock[index+1])) return (S.stock[index+1] == undefined) ? null : arguments.callee(index+1) ;					else return S.stock[index+1];				})(index);								/* selectに追加 */				try{					/* 標準 */					if(s != null) this.obj.add(opt,this.obj.options[s]);					else this.obj.add(opt,null);				}				catch(e){					/* IE */					if(s != null) this.obj.add(opt,s);					else this.obj.add(opt);				}								/* 順番配列を調整 */				this.stock[index] = (s == null) ? this.obj.options.length - 1 : s ;				for(var i=index+1,l=this.stock.length ; i<l ; i++){					if(!isNaN(this.stock[i])) this.stock[i]++;				}			}						/* 値を格納 */			this.GetValue();		},		Disable : function(index){			/**			* 選択肢を無効化			* arg.0 : 初期の並び順			*/			if(arguments.length < 1) return;						/* 現在の並び順 */			var s = this.stock[index];						/* 順番配列に自信のコピーを格納 */			this.stock[index] = new Option(this.obj.options[s].text,this.obj.options[s].value);						/* selectから削除 */			this.obj.remove(s);						/* 順番配列を調整 */			for(var i=index+1,l=this.stock.length ; i<l ; i++){				if(!isNaN(this.stock[i])) this.stock[i]--;			}						/* 値を格納 */			this.GetValue();		}	};		function Check(obj,parent){		/**		* チェックボックスのクラス		*/				/* メインクラスの参照 */		this.parent = parent;				/* input[type=checkbox]要素 */		this.obj = obj;				/* チェックの有無 */		this.checked = false;				this.Init();	}	Check.prototype = {		Init : function(){			/**			* 初期化			*/			var C = this;						/* 値を格納 */			this.GetValue();						/* イベントリスナを設定 */			$(this.obj).bind("click",function(){				C.GetValue();				C.parent.KindCheck();				C.parent.Post();			});		},		GetValue : function(){			/**			* 値を格納			*/			this.checked = this.obj.checked;		}	};		function Button(obj,parent){		/**		* ボタンクラス		*/				/* メインクラスの参照 */		this.parent = parent;				/* input[type=image]要素 */		this.obj = obj;				/* 有効時の画像 */		this.f1 = document.createElement("img");				/* 無効時の画像 */		this.f2 = document.createElement("img");				this.Init();	}	Button.prototype = {		Init : function(){			/**			* 初期化			*/			this.f1.src = this.obj.src;			this.f2.src = this.obj.src.replace("_f1","_f2");		},		Enable : function(){			/**			* 有効化			*/			this.obj.disabled = false;			this.obj.src = this.f1.src;			$(this.obj).css({ cursor : "pointer" });		},		Disable : function(){			/**			* 無効化			*/			this.obj.disabled = true;			this.obj.src = this.f2.src;			$(this.obj).css({ cursor : "default" });		}	};		function Download(){		/**		* メインクラス		*/				/* csvファイルから読んだデータ */		this.data = download_csvdata;				/* form要素 */		this.form = ELEM_FORM;				/* APIのパス */		this.api = PATH_API;				/* ファイル数・サイズを表示する要素 */		this.size_display = $("p.file-size",this.form);				/* 開始 */		this.from = {			/* 年 */			year : new Selector(ELEM_SELECT[0],this),			/* 期 */			span : new Selector(ELEM_SELECT[1],this)		};				/* 終了 */		this.to = {			/* 年 */			year : new Selector(ELEM_SELECT[2],this),			/* 期 */			span : new Selector(ELEM_SELECT[3],this)		};				/* 種類 */		this.kind = new Selector(ELEM_SELECT[4],this);				/* 言語 */		this.lang = {			/* 日本語 */			jp : new Check(ELEM_CHECK[0],this),			/* 英語 */			en : new Check(ELEM_CHECK[1],this)		};				/* ボタン */		this.button = new Button(ELEM_BUTTON[0],this);				this.Init();	}	Download.prototype = {		Init : function(){			/**			* 初期化			*/			this.Adjust();			this.KindCheck();			this.Post();		},		Adjust : function(){			/**			* 期間選択のselectを調整			*/			var D = this;						/* その該当する年度にデータの無い四半期を無効（開始側） */			for(var s=0,l=this.from.span.def.length ; s<l ; s++)(function(index,quoter){				if(D.data[D.from.year.value][quoter] == undefined){					if(!isNaN(D.from.span.stock[index])) D.from.span.Disable(index);				}				else{					if(isNaN(D.from.span.stock[index])) D.from.span.Enable(index);				}			})(s,parseInt(this.from.span.def[s]));						/* 開始年度より古い終了年度を無効（終了側） */			for(var i=0,l=this.from.year.obj.options.length ; i<l ; i++)(function(index,item){				if(index > D.from.year.obj.selectedIndex){					if(!isNaN(D.to.year.stock[index])) D.to.year.Disable(index);				}				else{					if(isNaN(D.to.year.stock[index])) D.to.year.Enable(index);				}			})(i,this.from.year.obj.options[i]);						/* 同年度の場合開始四半期より古い終了四半期を無効（終了側） */			for(var s=0,l=this.to.span.def.length ; s<l ; s++)(function(index,quoter){				if(D.data[D.to.year.value][quoter] == undefined || ( D.from.year.value == D.to.year.value && (isNaN(D.from.span.stock[index]) || quoter < D.from.span.value))){					if(!isNaN(D.to.span.stock[index])) D.to.span.Disable(index);				}				else{					if(isNaN(D.to.span.stock[index])) D.to.span.Enable(index);				}			})(s,parseInt(this.to.span.def[s]));					},		KindCheck : function(){			/**			* 種類選択のselectを調整			*/			var D = this;						/* 現在選択されている期間・言語・種類に該当するデータがあれば、tmpに種類をキーとしてtrueを格納 */			var tmp = {};			for(var year=this.from.year.value; year<=this.to.year.value ; year++){				for(var span=1 ; span<=4 ; span++){					if(year == this.from.year.value && span < parseInt(this.from.span.value)) continue;					if(year == this.to.year.value   && span > parseInt(this.to.span.value))   continue;					if(!this.data[year][span]) continue;										if(this.lang.jp.checked) for(var i in this.data[year][span]["jp"]){						tmp[i] = true;					}					if(this.lang.en.checked) for(var i in this.data[year][span]["en"]){						tmp[i] = true;					}				}			}						/* tmpにない種類を無効 */			for(var i=0,l=this.kind.def.length ; i<l ; i++){				if(!tmp[this.kind.def[i]]){					if(!isNaN(this.kind.stock[i])) this.kind.Disable(i);				}				else{					if(isNaN(this.kind.stock[i])) this.kind.Enable(i);				}			}		},		Post : function(){			/**			* ファイル数・サイズの文字列を取得、書き換え			*/			var D = this;			$.post(this.api,this.form.serialize(),function(res,flag){				D.size_display.empty();				D.size_display.append(res);								if(res.charAt(0) == "0") D.button.Disable();				else D.button.Enable();			},"text");		}	};				var myDownload = new Download();			});
