/*====================================================================================================
//////////////////////////////////////////////////////////////////////////////////////////////////////

 author : http://www.yomotsu.net
 created: 2008/04/05
 update : 
 
 Licensed under the GNU Lesser General Public License version 2.1
 
 リンク先のHTML文書など body 要素内のソースを現在のページ内にモーダルウインドウとして表示する

//////////////////////////////////////////////////////////////////////////////////////////////////////
====================================================================================================*/

var modalWindow = {
	cur_id:null,

	conf : {
		triggerClassName       : "show-detail", // クリックしたときウインドウを開く a 要素につける class 属性
		displayBasePositionTop : 0, // ( px )
		displayBaseMaxWidth    : 726, // ( px )
		displayBaseMaxHeight   : 525, // ( px )
		backgroundMaxOpacity   : 0.30 // [ 0.00 ~ 1.00 ]
	},
	
	start : function(){
		try {
			window.addEventListener('load', this.trigger, false);
		} catch (e) {
			window.attachEvent('onload', this.trigger);
		}
	},
	
	trigger : function(){
	 var a = document.links;
	 for(var i=0; i<a.length; i++){
	 	if(new RegExp("\\b" + modalWindow.conf.triggerClassName + "\\b").exec(a[i].className)){
			a[i].onclick = function(){
				if(this.href.match(/\..*html?|\.xml|\.php|\.asp/)){
					modalWindow.set(this.href);
					return false;
				}
			}
		}
	 }
	},

	set : function(URI){
		cur_id = URI;
		displayBase = document.getElementById(cur_id);
		displayBase.id = "display-base";
		displayBase.style.position = "absolute";
		displayBase.style.zIndex   = "100";
		
                /*
		tmp = displayBase;
		while(tmp = tmp.parentNode) {
			if (tmp.id == "left") {
				displayBase.style.left = 60 + "px";
				break;
			} else if (tmp.id == "right") {
				displayBase.style.right = 240 + "px";
				break;
			}
		}
                */
		//displayBase.style.left     = getPageSize().width / 2 - (modalWindow.conf.displayBaseMaxWidth / 2) -130 + "px";

		displayBase.style.top      = getPageOffset().yOffset + (getScreenSize().inH / 2 - (modalWindow.conf.displayBaseMaxHeight / 2)) + "px";
		displayBase.style.left     = (getScreenSize().inW / 2 - (modalWindow.conf.displayBaseMaxWidth / 2)) -25 + "px";
		
		var elems = document.getElementsByTagName("select");
		for (i = 0; i < elems.length; i++) {
		 elems[i].style.display = "none";
		}
		displayBase.style.display="";
		backScreen.set();
	},
	
	remove : function(){
		var displayBase = document.getElementById("display-base");
		var cur_id_n = document.getElementById(cur_id + "_n");
		
		if (cur_id_n) {
			var temptext = "";
			var ElementsList = displayBase.getElementsByTagName("input");
			for (i = 0; i < ElementsList.length; i++) {
				if (ElementsList[i].type == 'checkbox' && ElementsList[i].checked == true) {
					if (ElementsList[i].nextSibling.tagName == "LABEL") {
						curtext = ElementsList[i].nextSibling.innerHTML;
					} else {
						curtext = ElementsList[i].nextSibling.nodeValue;
					}
					if (temptext.length + curtext.length > 10) {
						temptext += "...";
						break;
					}
					else {
						if (temptext != "") {
							temptext += "、";
						}
						temptext += curtext;
					}
				}
			}
			if (temptext == "") {
				temptext = cur_id_n.parentNode.title;
			}
			cur_id_n.innerHTML = temptext;
		}
		if (displayBase) {
			displayBase.style.display = "none";
			displayBase.id = cur_id;
		}
		var elems = document.getElementsByTagName("select");
		for (i = 0; i < elems.length; i++) {
			elems[i].style.display = "";
		}
		backScreen.remove(cur_id);
	}
	
};


modalWindow.start();


//-----------------------------------------------------
//  get page size
//-----------------------------------------------------

var getPageSize = function(){
	var w1=w2=h1=h2=0, width, height;
			
	if (document.documentElement) {
		w1 = document.documentElement.scrollWidth;
		h1 = document.documentElement.scrollHeight;
	}
	
	if (document.body) {
		w2 = document.body.scrollWidth;
		h2 = document.body.scrollHeight;
	}
	
	var width  = Math.max(w1, w2);
	var height = Math.max(h1, h2);
	if (navigator.userAgent.indexOf("Opera") > -1) {
		width = Math.min(w1, w2);
		height = Math.min(h1, h2);
	}
		
	return {width: width, height: height};
};

//---------------------------

var getPageOffset = function(){
	var xOffset  = document.body.scrollLeft || document.documentElement.scrollLeft;
	var yOffset  = document.body.scrollTop  || document.documentElement.scrollTop;
	return {xOffset: xOffset, yOffset: yOffset};
};


var getScreenSize = function(){
	// ウィンドウ内側の横幅
	var inW = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
	// ウィンドウ内側の縦幅
	var inH = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;

	return {inW: inW, inH: inH};
};

//-----------------------------------------------------
//  backScreen
//-----------------------------------------------------


var backScreen = {
	alpha : 0,
	
	set : function(){
		var backScreen = document.createElement("div");
		
		backScreen.id = "back-screen";
		backScreen.style.position = "absolute";
		backScreen.style.left     = 0;
		backScreen.style.top      = 0;
		backScreen.style.zIndex   = 99;
		backScreen.style.width    = Math.max(getPageSize().width, modalWindow.conf.displayBaseMaxWidth) +"px";
		backScreen.style.height   = getPageSize().height +"px";
		backScreen.style.filter     = "alpha(opacity="+this.alpha*100+")";
		backScreen.style.MozOpacity = this.alpha;
		backScreen.style.opacity    = this.alpha;
		backScreen.style.backgroundColor = "#000000";
		
		document.getElementById('display-base').parentNode.appendChild(backScreen);
		
		this.alpha = 0;
		this.fadeIn();
	},
	
	fadeIn : function(){
		var backScreen = document.getElementById("back-screen");
		this.alpha += 0.50;
		if(backScreen.style.opacity)        	backScreen.style.opacity    = this.alpha;
		else if(backScreen.style.MozOpacity)	backScreen.style.MozOpacity = this.alpha;
		else if(backScreen.style.filter)	backScreen.style.filter     = "alpha(opacity="+this.alpha*100+")";
		if (this.alpha < modalWindow.conf.backgroundMaxOpacity ) {
			backScreen.onclick = function(){return};
			window.setTimeout("backScreen.fadeIn()", 25);
		}
		else {
			backScreen.onclick = modalWindow.remove;
		}
	},
	
	fadeOut : function(curid){
		var backScreen = document.getElementById("back-screen");
		backScreen.onclick = function(){return};
		this.alpha -= 0.50;
		if(backScreen.style.opacity)        	backScreen.style.opacity    = this.alpha;
		else if(backScreen.style.MozOpacity)	backScreen.style.MozOpacity = this.alpha;
		else if(backScreen.style.filter)	backScreen.style.filter     = "alpha(opacity="+this.alpha*100+")";
		if (this.alpha > 0.05) {
			window.setTimeout("backScreen.fadeOut('"+curid+"')", 20);
		}else{
			if (document.getElementById(curid)) {
				document.getElementById(curid).parentNode.removeChild(backScreen);
			}
			this.alpha = 0;
		}
	},
	
	remove : function(curid){
		var backScreen = document.getElementById("back-screen");
		if(backScreen)
			this.fadeOut(curid);
	},
	
	fix : function(){
		var backScreen = document.getElementById("back-screen");
		if(backScreen){
			backScreen.style.width  = getPageSize().width  +"px";
			backScreen.style.height = getPageSize().height +"px";
		}
	}
};

try {
	window.addEventListener('resize', backScreen.fix, false);
} catch (e) {
	window.attachEvent('onresize', backScreen.fix);
};


