var scrollLeft ;  // 水平スクロール量
var scrollTop  ;  // 垂直スクロール量
var tmp ;
var i ;
var j ;
var id ;
var timer ;
var flag=false ;

// レスをポップアップ
function popUp(i) {
	return popUp(i , null) ;
}

function popUp(i , e) {
	if(pop[i] != null) {
		tmp = "" ;
		clearTimeout(timer) ;
		flag = true ;
		
		scrollLeft = document.body.scrollLeft || document.documentElement.scrollLeft ;
		scrollTop  = document.body.scrollTop  || document.documentElement.scrollTop ;
		
		tmp = pop[i];
		tmp = tmp + "<div style=\"text-align:right;\"><a onClick=\"forseHidePopup();\" onMouseOver=\"this.style.cursor='pointer';\" onMouseOut=\"this.style.cursor='auto';\">[閉じる]</a></div>";
		
		POP.innerHTML = tmp ;
		if(document.all) {
			// IE用
			POP.style.left = window.event.clientX + scrollLeft + 15 ; 
			POP.style.top  = window.event.clientY + scrollTop  + 10 ; 
		} else {
			// FireFox用
			POP.style.left = e.clientX + scrollLeft + 15 ;
			POP.style.top  = e.clientY + scrollTop  + 10 ; 
		}
		//window.alert(i);
		
		POP.style.visibility = "visible" ;
	}
}

// 複数のレスをポップアップ
function popUps(i, j) {
	return popUps(i, j, null) ;
}

function popUps(i, j, e) {
	tmp = "" ;
	clearTimeout(timer) ;
	flag = true ;
	
	scrollLeft = document.body.scrollLeft || document.documentElement.scrollLeft ;
	scrollTop  = document.body.scrollTop  || document.documentElement.scrollTop ;
	for(;i<=j;i++) {
		if(pop[i] != null) {
			tmp = tmp + pop[i] ;
		}
	}
	
	if(tmp != "") {
		tmp = tmp + "<div style=\"text-align:right;\"><a onClick=\"forseHidePopup();\" onMouseOver=\"this.style.cursor='pointer';\" onMouseOut=\"this.style.cursor='auto';\">[閉じる]</a></div>";
		POP.innerHTML  = tmp ;
		
		if(document.all) {
			// IE用
			POP.style.left = window.event.clientX + scrollLeft + 15 ; 
			POP.style.top  = window.event.clientY + scrollTop  + 10 ; 
		} else {
			// FireFox用
			POP.style.left = e.clientX + scrollLeft + 15 ;
			POP.style.top  = e.clientY + scrollTop  + 10 ; 
		}
		
		POP.style.visibility = "visible" ;
	}
}

// 自分宛のレスをポップアップ
function refPopUp(i) {
	return refPopUp(i, null) ;
}

function refPopUp(i, e) {
	if(refNo[i] == null) {
		return ;
	}
	
	// 配列を変換
	ref = new Array() ;
	ref = refNo[i].split(",") ;
	
	// 一つ以上のレス番号が存在した場合
	if(ref.length > 0) {
		tmp = "" ;
		clearTimeout(timer) ;
		flag = true ;
		
		scrollLeft = document.body.scrollLeft || document.documentElement.scrollLeft ;
		scrollTop  = document.body.scrollTop  || document.documentElement.scrollTop ;
		
		for(i=0;i<ref.length;i++) {
			if(pop[ref[i]] != null) {
				tmp = tmp + pop[ref[i]] ;
			}
		}
		
		tmp = tmp + "<div style=\"text-align:right;\"><a onClick=\"forseHidePopup();\" onMouseOver=\"this.style.cursor='pointer';\" onMouseOut=\"this.style.cursor='auto';\">[閉じる]</a></div>";
		POP.innerHTML  = tmp ;
		
		if(document.all) {
			// IE用
			POP.style.left = window.event.clientX + scrollLeft + 15 ; 
			POP.style.top  = window.event.clientY + scrollTop  + 10 ; 
		} else {
			// FireFox用
			POP.style.left = e.clientX + scrollLeft + 15 ;
			POP.style.top  = e.clientY + scrollTop  + 10 ; 
		}
		
		POP.style.visibility = "visible" ;
	}
}

// IDのポップアップ
function idPopUp(id) {
	return idPopUp(id, null) ;
}

function idPopUp(id, e) {
	if(refId[id] == null) {
		return ;
	}
	
	// 配列を変換
	ref = new Array() ;
	ref = refId[id].split(",") ;
	
	// 一つ以上のレス番号が存在した場合
	if(ref.length > 0) {
		tmp = "" ;
		clearTimeout(timer) ;
		flag = true ;
		
		scrollLeft = document.body.scrollLeft || document.documentElement.scrollLeft ;
		scrollTop  = document.body.scrollTop  || document.documentElement.scrollTop ;
		for(i=0;i<ref.length;i++) {
			if(pop[ref[i]] != null) {
				tmp = tmp + pop[ref[i]] ;
			}
		}
		tmp = tmp + "<div style=\"text-align:right;\"><a onClick=\"forseHidePopup();\" onMouseOver=\"this.style.cursor='pointer';\" onMouseOut=\"this.style.cursor='auto';\">[閉じる]</a></div>";
		POP.innerHTML  = tmp ;
		
		if(document.all) {
			// IE用
			POP.style.left = window.event.clientX + scrollLeft - 400 ; 
			POP.style.top  = window.event.clientY + scrollTop  + 10 ; 
		} else {
			// FireFox用
			POP.style.left = e.clientX + scrollLeft - 250 ;
			POP.style.top  = e.clientY + scrollTop  + 10 ; 
		}
		
		POP.style.visibility = "visible" ;
	}
}

// ポップアップを閉じるかどうか判断
function hidePop() {
  timer = setTimeout("hidePopup()",500) ;
  flag  = false ;
}

// 実際にポップアップを閉じる
function hidePopup() {
  if(flag == false) {
    POP.style.visibility = "hidden" ;
    clearTimeout(timer) ;
  }
}

// ポップアップを強制的に閉じる
function forseHidePopup() {
  POP.style.visibility = "hidden" ;
  clearTimeout(timer) ;
}

// ポップアップにマウスが載った場合
function onPopup() {
  flag = true ;
}

// ポップアップからマウスが離れた場合
function outPopup() {
  flag = false ;
}
