popup_url = new Array();
popup_url["stry"]			= "/biglobe/ttl/stry.php";
popup_url["stry_all_list"]		= "/biglobe/ttl/stry_all_list.php";
popup_url["stry_prev"]			= "/biglobe/ttl/stry_prev.php";
popup_url["staff_cast"]			= "staff_cast.php";
popup_url["chara"]			= "chara.php";
popup_url["mecha"]			= "mecha.php";
popup_url["feat_det"]			= "/biglobe/ttl/feat_det.php";
popup_url["feat_det_mbr"]		= "/biglobe/ttl/feat_det_mbr.php";
popup_url["series"]			= "series.php";
popup_url["chara_select"]		= "chara_select.php";
popup_url["story_select"]		= "feat_stry_select.php";
popup_url["myfeat_det"]			= "feat_det.php";
popup_url["top_feat_list"]		= "/biglobe/ttl/feat_det.php";
popup_url["review_list"]		= "/biglobe/ttl/ttl_review.php";
popup_url["ttl_review_det"]		= "/biglobe/ttl/ttl_review_det.php";
popup_url["aff_guideline"]		= "/biglobe/contents/affiliate/layer.html";
popup_url["newttl_schedule_biglobe"]	= "/top/biglobe/newttl_schedule_biglobe.html";
popup_url["review_info"]		= "review_info.php";
popup_url["mbr_profile"]		= "/biglobe/mypage/profile.php";
popup_url["mbr_emblem"]			= "/biglobe/mypage/mbr_emblem_list.php";
popup_url["mbr_comment"]		= "/biglobe/mypage/mbr_comment_list.php";
popup_url["ttl_difstry"]		= "/biglobe/ttl/ttl_commodity_difstry.php";
popup_url["top_lv_det"]			= "/biglobe/top/top_lv_det.php";
popup_url["ttl_emblem_mbr"]		= "/biglobe/ttl/ttl_mbr_emblem.php";

var b_scr;
var pop_up;
var scrolltop_now;
var scrollheight_now;
var page_width;
var select_c;

function get_elements() {
	if(document.getElementById("container")){
		with(document){
			b_scr = getElementById("b_scr");
			pop_up = getElementById("pop_up");
		}
		scrolltop_now = document.body.scrollTop;
		scrollheight_now = document.body.scrollHeight;
		page_width = document.getElementById("container").offsetWidth;
	}else if(top.document.getElementById("container")){
		with(top.document){
			b_scr = getElementById("b_scr");
			pop_up = getElementById("pop_up");
		}
		scrolltop_now = top.document.body.scrollTop;
		scrollheight_now = top.document.body.scrollHeight;
		page_width = top.document.getElementById("container").offsetWidth;
	}
}

function open_child(code, popup_type, page){
	get_elements();
	
	with(b_scr.style){
		position = "absolute";
		top = 0;
		left = 0;
		height = scrollheight_now;
		width = "100%";
		backgroundColor = "black";
		filter = 'alpha(opacity=70)';
		mozOpacity = 0.7;
		opacity = 0.7;
		zIndex = 40;
	}
	
	var func_ref = function(res){
		pop_up.innerHTML = res;
		with(pop_up.style){
			position = "absolute";
			top = scrolltop_now + 50;
			change_pos_child();	// ポップアップの左位置＝ページ幅（枠画像）の中心の座標からポップアップ幅の中心の表を引いた値
			//left = 200;
			zIndex = 50;
		}
		var b_scr_height;
		var popup_height = pop_up.offsetHeight;
		var client_height;
		if (document.all) { // IE用
			client_height = document.body.clientHeight;
		} else {
			client_height = innerHeight;
		}
		if((scrolltop_now + 50 + popup_height + 30) > scrollheight_now) {
			//b_scr_height = (scrolltop_now + 50 + popup_height) - scrollheight_now;
			if ((scrolltop_now + 50 + popup_height) < screen.height && scrollheight_now < client_height) {
				b_scr_height = "100%";
			} else {
				b_scr_height = (scrolltop_now + 50 + popup_height + 30);
			}
		} else {
			b_scr_height = scrollheight_now;
		}
		with(b_scr.style){
			height = b_scr_height;
		}
	};
	
	var date_param = get_date_param();
	
	var popup_param = "";
	var offset_su = "";
	code2 = new Array();
	switch (popup_type) {
	case "story_select":
	case "chara_select":
	case "series":
		offset_su = (page == null) ? "0" : page.toString();
		popup_param = "?ttl_c=" + code.toString() + "&offset_su=" + offset_su + "&" + date_param;
		break;
	case "stry":
	case "stry_all_list":
	case "stry_prev":
	case "chara":
	case "mecha":
	case "review_list":
		offset_su = (page == null) ? "0" : page.toString();
		code2 = code.split(":");
		popup_param = "?ttl_c=" + code2[0].toString() + "&stry_sq=" + code2[1].toString() + "&offset_su=" + offset_su + "&" + date_param;
		break;
	case "ttl_emblem_mbr":
		offset_su = (page == null) ? "0" : page.toString();
		code2 = code.split(":");
		popup_param = "?ttl_c=" + code2[0].toString() + "&emblem_sq=" + code2[1].toString() + "&offset_su=" + offset_su + "&" + date_param;
		break;
	case "staff_cast":
		code2 = code.split(":");
		popup_param = "?ttl_c=" + code2[0].toString() + "&stry_sq=" + code2[1].toString() + "&" + date_param;
		break;
	case "feat_det":
		popup_param = "?mbfeat_c=" + code.toString() + "&" + date_param;
		break;
	case "feat_det_mbr":
	case "top_feat_det_mbr":
		link_layer = (page == null) ? "0" : page.toString();
		popup_param = "?mb_c=" + code.toString() + "&link_layer=" + link_layer +"&" + date_param;
		break;
	case "mbr_profile":
		link_layer = (page == null) ? "0" : page.toString();
		popup_param = "?mb_c=" + code.toString() + "&link_layer=" + link_layer +"&" + date_param;
		break;
	case "mbr_comment":
		offset_su = (page == null) ? "" : page.toString();
		popup_param = "?mb_c=" + code.toString() + "&offset_su=" + offset_su + "&" + date_param;
		break;
	case "mbr_emblem":
		offset_su = (page == null) ? "" : page.toString();
		code2 = code.split(":");
		link_layer = (code2[1] == null) ? "" : code2[1].toString();
		link_layer_ttl_c = (code2[2] == null) ? "" : code2[2].toString();
		link_layer_emblem_sq = (code2[3] == null) ? "" : code2[3].toString();
		link_layer_offset_su = (code2[4] == null) ? "" : code2[4].toString();
		popup_param = "?mb_c=" + code2[0].toString() + "&link_layer=" + link_layer + "&link_layer_ttl_c=" + link_layer_ttl_c + "&link_layer_emblem_sq=" + link_layer_emblem_sq + "&link_layer_offset_su=" + link_layer_offset_su + "&offset_su=" + offset_su + "&" + date_param;
		break;
	case "top_lv_det":
		offset_su = (page == null) ? "" : page.toString();
		popup_param = "?lv=" + code.toString() + "&offset_su=" + offset_su + "&" + date_param;
		break;
	case "ttl_review_det":
		offset_su = (page == null) ? "" : page.toString();
		code2 = code.split(":");
		popup_param = "?mbttlrev_c=" + code2[0].toString() + "&link_layer=" + code2[1].toString() + "&offset_su=" + offset_su + "&" + date_param;
		break;
	case "top_feat_list":
	case "myfeat_det":
		code2 = code.split(":");
		popup_param = "?mbfeat_c=" + code2[0].toString() + "&mbfeat_dsp_f=" + code2[1].toString() + "&" + date_param;
		break;
	case "ttl_difstry":
		page = (page == null) ? "0" : page.toString();
		code2 = code.split(":");
		popup_param = "?ttl_c=" + code2[0].toString() + "&select_type=" + code2[1].toString() + "&page=" + page + "&" + date_param;
		break;
	case "newttl_schedule":
	case "aff_guideline":
	case "newttl_schedule_biglobe":
		popup_param = "";
	default:
		break;
	}
	
//	alert("テスト用アラートです\n" + popup_url[popup_type] + popup_param);
	
	httpRequest(popup_url[popup_type] + popup_param, func_ref);
}

function change_pos_child(){
	if(pop_up){
		if(pop_up.innerHTML != ""){
			pop_up.style.left = (page_width / 2) - (pop_up.offsetWidth / 2);
//			pop_up.style.left = (document.getElementById("container").offsetWidth / 2) - (pop_up.offsetWidth / 2);
//			(document.body.scrollWidth / 2) - (pop_up.offsetWidth / 2);
		}
	}
}		

function close_child(){
	if(document.getElementById("container")){
		with(document){
			b_scr = getElementById("b_scr");
			pop_up = getElementById("pop_up");
		}
	}else if(top.document.getElementById("container")){
		with(top.document){
			b_scr = getElementById("b_scr");
			pop_up = getElementById("pop_up");
		}
	}

	with(pop_up){
		innerHTML = "";
//				with(style){
//					height = 0;
//					width = 0;
//				}
	}
	
	with(b_scr.style){
		height = 0;
		width = 0;
	}
}

var bVer = parseInt(navigator.appVersion);

function imgChange(imgName,imgNum) {
	if (bVer > 3) {
		document.images[imgName].src = eval(imgNum + ".src");
	}
}

function openWin(width, height) {
	newWin=window.open(
	"",
	"newWin",
	"toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=" + width + ",height=" + height);
	if(bVer >= 4){
		newWin.focus();
		newWin.moveTo(0,0);
	}
}

var httpObj;					//HTTP通信用オブジェクト
var timerId;					//タイマーID
var timeout_sec = 10;		//タイムアウトの秒数

//HTTPリクエスト開始
function httpRequest(target_url, funcRef){
	try{
		if(window.XMLHttpRequest){
			httpObj = new XMLHttpRequest();
		}else if(window.ActiveXObject){
			httpObj = new ActiveXObject("Microsoft.XMLHTTP")
		}else{
			httpObj = false;
		}
	}catch(e){
		httpObj = false;
	}
	if(! httpObj){
		httpObjGenerateFail();
	}

	//タイムアウト用タイマーオブジェクト等の初期化
	clearInterval(timerId);
	timeout_sec = 10;
	timerId = setInterval('timeoutCheck()', 1000);

	with(httpObj){
		open("GET", target_url, true);
		setRequestHeader("Content-Type" , "application/x-www-form-urlencoded");
		onreadystatechange = function(){
			if(readyState == 4){
				clearInterval(timerId);
				timeout_sec = 10;
				if(status == 200){
					funcRef(responseText);
//					var text = get_response_text(responseText);
//					funcRef(text);
				}else{
					alert(status + ':' + statusText);
					return false;
				}
			}
		}
		send('');
	}
}

function timeoutCheck(){
	timeout_sec--;
	if(timeout_sec <= 0){
		clearInterval(timerId);
		httpObj.abort();
		timeout_sec = 10;
		alert('タイムアウトです。');
		return false;
	}
}

function httpObjGenerateFail(){
	alert('ご利用のブラウザーでは、当サイトをご利用頂けません。');
	return false;
}

function select_chara(){
	var obj = document.getElementsByName("radiobutton");
	
	for(i = 0; i < obj.length; i++){
		if(obj[i].checked){
			with(document){
				getElementById("bchiconttl_c").value = getElementById("popup_ttl_c").value;
				getElementById("bchiconchara_txt").value = getElementById("popup_chara_txt_" + obj[i].value).value;
				getElementById("bchicon_txt").value = getElementById("popup_chara_thm_txt_" + obj[i].value).value;
				getElementById("select_ttl_txt").innerHTML = getElementById("popup_ttl_txt").value;
				getElementById("select_copyright_txt").innerHTML = getElementById("popup_copyright_txt").value;
				getElementById("slect_chara_txt").innerHTML = getElementById("popup_chara_txt_" + obj[i].value).value;
//				getElementById("select_img_txt").src = getElementById("img_chara_idx_" + obj[i].value).src;
				getElementById("select_img_txt").src
					= "http://image.b-ch.com/ttl2/"+ getElementById("popup_ttl_c").value
					+ "/" + getElementById("popup_chara_thm_txt_" + obj[i].value).value;
				window.scrollTo(0, 0);
				break;
			}
		}
	}
	
	close_child();
}

function get_date_param() {
	// 日付の取得
	var date = new Date();
	var year = date.getYear();
	var mon = date.getMonth() + 1;
	var day = date.getDate();
	
	// 西暦の処理とゼロパディング
	year = (year < 2000) ? year+1900 : year;
	if (mon < 10) { mon = "0" + mon; }
	if (day < 10) { day = "0" + day; }
	
	// 時間の取得
	var time = new Date();
	var hour = time.getHours();
	var min = time.getMinutes();
	var sec = time.getSeconds();

	// ゼロパディング
	if (hour < 10) { hour = "0" + hour; }
	if (min < 10) { min = "0" + min; }
	if (sec < 10) { sec = "0" + sec; }
	
	var date_param = "layer=" + year + mon + day + hour + min + sec;
	
	return date_param;
}


