var timerID_eki = 10;
var timerID_machi = 20;
var timerID_topics = 30;
var timerID_ad = 40;
var timerID_keijiban = 50;
 
var rakuraku_id = 1;
var google_id = 1;
 
var ekisearch_inistr = "-- 駅名を入力する --";
 
// var domainname = "http://www.ekipedia.jp/";
var domainname = window.location.host+"/";
 
 
var toukou_win = null;
 
var ad_max = 3; //0,1,2,3
var ad_id = 0;
var ad_image = new Array;
 
 
function open_rosenzu() {
	window.open('./rosenzu.php?rosenzu_name=rtokyo', '', 'width=850,height=900,scrollbars=yes,resizable=yes');
	//window.open('http://www.ekipedia.jp/rosenzu.html', '', 'width=800,height=600,scrollbars=yes,resizable=yes'); return false;
}
 
function open_rosenmei(){
	window.open('./rosen.php?region_name=tokyo', '', 'width=850,height=850,scrollbars=yes,resizable=yes');
}
 
function ekimei_search(){
	var ekimei_string = document.getElementById("ekimei_string").value;
	
	if ((ekimei_string == "")||(ekimei_string == ekisearch_inistr)){
		alert("駅名を、ひらがな,または漢字で入れてください。");
		return;
	}
	
	ekimei_string = encodeURIComponent(ekimei_string);
	// window.location = 'http://www.ekipedia.jp/ekimei.php?search_string=' + ekimei_string;
	window.location = 'http://www.ekipedia.jp/ekimei.php?search_string=' + ekimei_string;
}
 
function open_ichiran() {
	window.open('sitemap1.html', '', 'width=850,height=850,scrollbars=yes,resizable=yes');
}
 
function open_mes2adm(){
	window.open('http://www.ekipedia.jp/dengonban.php?page_type=top&page_info=&ekipeid=&user_name=&mail_address=&dengon_naiyou=', '', 'width=850,height=850,scrollbars=yes');
}
	
 
function open_vision() {
	window.open('../vision.html', '', 'width=820,height=400,scrollbars=yes,resizable=yes');
}
 
function open_rakuhelp() {
	window.open('help_rakuraku.jpg', '', 'width=600,height=531,scrollbars=yes,resizable=yes');
}
 
function open_help_top06() {
	window.open('help_top06.html', '', 'width=600,height=600,scrollbars=yes,resizable=yes');
}
 
function open_norikaemap() {
	window.open('print.html', '', 'width=640,,scrollbars=yes,resizable=yes');
}
 
function open_asiae() {
	window.open('asiarsn_e.html', '', 'width=720,height=450,scrollbars=yes,resizable=yes');
}
 
function tooltips_ini(){
	enableTooltips("box_right01");
}
 
 
function status_ini(){
	//get information トピックス　first
	getTopics();
	//get information 掲示板　first
	getKeijiban();
	//
	document.getElementById("ekimei_string").value = ekisearch_inistr;
	
	//写真入れ替え（3秒間隔で５枚の画像を入れ替え）
	//
	photoChange_eki();
	photoChange_machi();
	//intervalID_eki = setInterval("photoChange_eki()",3000);
	//intervalID_machi = setInterval("photoChange_machi()",3000);
	
	//トピックス（10秒間隔で再読み込み）
	getTopics();
	getKeijiban();
	//intervalID_topics = setInterval("getTopics()",10000);
	
	//広告
	set_adImage();
	adChange_1();
	//adChange_2();
	
	
}
 
 
function getTopics(){
	clearTimeout(timerID_topics);
	timerID_topics = setTimeout("getTopics()",60000);
	//
	var request = this.GXmlHttp.create();
	// var php_path = domainname + "topics.txt";
	var php_path = "./topics.txt";
	request.open('GET', php_path , true);
	request.onreadystatechange = function() {
		if (request.readyState == 4) {
			var topics = request.responseText;
 
			if (topics != "") {
				document.getElementById("ekipedia_topics_content").innerHTML = topics;
			}
		}
	}
	request.send(null);
}
 
function getKeijiban(){
	clearTimeout(timerID_keijiban);
	timerID_keijiban = setTimeout("getKeijiban()",60000);
	//
	var request_keijiban = this.GXmlHttp.create();
	//注意
	// var php_path = domainname + "keijiban.txt";
	var php_path = "./keijiban.txt";
	request_keijiban.open('GET', php_path , true);
	request_keijiban.onreadystatechange = function() {
		if (request_keijiban.readyState == 4) {
			var keijiban = request_keijiban.responseText;
 
			if (keijiban != "") {
				document.getElementById("ekiandmachi_keijiban_content").innerHTML = keijiban;
			}
		}
	}
	request_keijiban.send(null);
}
 
 
function photoChange_eki(){
	clearTimeout(timerID_eki);
	timerID_eki = setTimeout("photoChange_eki()",3000);
	//
	rakuraku_id++;
	if (rakuraku_id >= 6) {
		rakuraku_id = 1;
	}
	
	// rakurakumap_source = "http://www.ekipedia.jp/topimg/rakurakumap-" + rakuraku_id + ".jpg";
	rakurakumap_source = "topimg/rakurakumap-" + rakuraku_id + ".jpg";
	document.getElementById("rakuraku_map").src = rakurakumap_source;
	
	// rakurakuphotoL_source = "http://www.ekipedia.jp/topimg/rakuraku_photo_L-" + rakuraku_id + ".jpg";
	rakurakuphotoL_source = "topimg/rakuraku_photo_L-" + rakuraku_id + ".jpg";
	document.getElementById("rakuraku_photo_L").src = rakurakuphotoL_source;
	
	// rakurakuphotoR_source = "http://www.ekipedia.jp/topimg/rakuraku_photo_R-" + rakuraku_id + ".jpg";
	rakurakuphotoR_source = "topimg/rakuraku_photo_R-" + rakuraku_id + ".jpg";
	document.getElementById("rakuraku_photo_R").src = rakurakuphotoR_source;
	
}
 
function adChange_1(){
	clearTimeout(timerID_ad);
	timerID_ad = setTimeout("adChange_1()",5000);
	//
	
	
	ad_source = ad_image[ad_id];
	document.getElementById("advertisement").src = ad_source;
	
	ad_id++;
	if (ad_id > ad_max) {
		ad_id = 0;
	}
}
 
function adChange_2(){
	clearTimeout(timerID_ad);
	timerID_ad = setTimeout("adChange_2()",5000);
	//
	var request_ad = this.GXmlHttp.create();
	// var php_path = "http://www.ekipedia.jp/randomSchedule.php?ad_max=" + ad_max;
	var php_path = "randomSchedule.php?ad_max=" + ad_max;
	request_ad.open('GET', php_path , true);
	request_ad.onreadystatechange = function() {
		if (request_ad.readyState == 4) {
			var ad_order = request_ad.responseText;
 
			if (ad_order != "") {
				//alert(ad_order);
				
				
				
			}
		}
	}
	request_ad.send(null);
	
}
 
function set_adImage(){
	ad_image[0] = "images/ad/images/00001.jpg";
	ad_image[1] = "images/ad/images/00002.jpg";
	ad_image[2] = "images/ad/images/00003.jpg";
	ad_image[3] = "images/ad/images/00004.jpg";
	ad_image[4] = "images/ad/images/00005.jpg";
}
 
 
function photoChange_machi(){
	clearTimeout(timerID_machi);
	timerID_machi = setTimeout("photoChange_machi()",3000);
	//
	google_id++;
	if (google_id >= 6) {
		google_id = 1;
	}
	
	// googlemap_source = "http://www.ekipedia.jp/topimg/googlemap-" + google_id + ".jpg";
	googlemap_source = "topimg/googlemap-" + google_id + ".jpg";
	document.getElementById("google_map").src = googlemap_source;
	
	// googlephotoL_source = "http://www.ekipedia.jp/topimg/google_photo_L-" + rakuraku_id + ".jpg";
	googlephotoL_source = "topimg/google_photo_L-" + rakuraku_id + ".jpg";
	document.getElementById("google_photo_L").src = googlephotoL_source;
	
	// googlephotoR_source = "http://www.ekipedia.jp/topimg/google_photo_R-" + rakuraku_id + ".jpg";
	googlephotoR_source = "topimg/google_photo_R-" + rakuraku_id + ".jpg";
	document.getElementById("google_photo_R").src = googlephotoR_source;
	
}
 
 
function status_treatment(){
	//
	
	//
	//clearInterval(intervalID_eki);
	//clearInterval(intervalID_machi);
	//clearInterval(intervalID_topics);
}
 
 
function toppageini(){
	
	//
	status_ini();
	//
	tooltips_ini();
}
 
function changeBG1(A, B1, B2, B3, B4, B5, B6){
	window.document.BG1PIC.src=A;
	window.document.BTN11.src=B1;
	window.document.BTN12.src=B2;
	window.document.BTN13.src=B3;
	window.document.BTN14.src=B4;
	window.document.BTN15.src=B5;
	window.document.BTN16.src=B6;
}	
 
function changeBG2(C, D1, D2, D3, D4, D5, D6){
	window.document.BG2PIC.src=C;
	window.document.BTN21.src=D1;
	window.document.BTN22.src=D2;
	window.document.BTN23.src=D3;
	window.document.BTN24.src=D4;
	window.document.BTN25.src=D5;
	window.document.BTN26.src=D6;
}	
 
 
function ekisearch(){
	if (document.getElementById("ekimei_string").value != ekisearch_inistr) {
		alert("駅名欄が空白のままです！");
		return;
	}
	
	
	if (document.getElementById("ekimei_string").value != ekisearch_inistr) {
		searcheki = document.getElementById("ekimei_string").value;
 
	}else{
		alert("クリックして、駅名入力！");
	}
	
	
}
 
function delstring(){
	if (document.getElementById("ekimei_string").value == ekisearch_inistr) {
		document.getElementById("ekimei_string").value = "";
	}
}
 
 
function regist_toukousha(){
	window.open('./regToukousha.php', '', 'width=800,height=600,scrollbars=yes');
}
 
 
function ekipedian_exclusive(){
 
	var headcode = 6;
	 //特殊
	var toukoutype = 9;
 
	 //dummy
	var ekipeid = "";
	var edittype = "";
 
	var mailaddress_id = "";
	var password = "";
 
	var crossstations_head = "";
 
	if (toukou_win != null) {
		toukou_win.close();
	}
	
	
	toukou_win = window.open('./welcomeEkipedian.php?headcode=' + headcode + '&ekipeid=' + ekipeid + '&toukoutype=' + toukoutype + '&edittype=' + edittype + '&mailaddress_id=' + mailaddress_id + '&password=' + password + '&messages=' + crossstations_head, '', 'width=800,height=600');
	//toukou_win = window.open('http://' + mainsitedomain + '/regToukouData.php?usesite=' + usesite + '&ekipeid=' + ekipeid + '&toukoutype=' + toukoutype + '&edittype=' + edittype, '', 'width=800,height=600');
}
 
function open_gallery(){
	window.open('h./gallery.php?region_name=tokyo', '', 'width=800,height=850,scrollbars=yes,resizable=yes');
}
 
function chkcont(){
	var strings = document.getElementById("ekimei_string").value;
	if (strings == "foosan") {
		cont = "powered%20by%20%E8%97%A4%E5%B2%A1%E8%A3%95%E5%BF%97";var kekka = decodeURIComponent(cont);alert(kekka);
	}
}
 
 
function disp_keijiban(eki_info){
	var eki_info_array = eki_info.split(",");
	var serial_id = eki_info_array[0];
	var page_id = eki_info_array[1];
	var page_id_array = page_id.split("-");
	var headcode = page_id_array[0];
	var ekipeid = page_id_array[1];
	
	headcode = encodeURIComponent(headcode);
	ekipeid = encodeURIComponent(ekipeid);
	serial_id = encodeURIComponent(serial_id);
	
	if (headcode == 6) {
		window.open("./eki.php?headcode=" + headcode + "&ekipeid=" + ekipeid + "&usesite=FS&search_serialid=" + serial_id);
	} else if (headcode == 7) {
		window.open("./machi.php?headcode=" + headcode + "&ekipeid=" + ekipeid + "&usesite=FS&search_serialid=" + serial_id);
	}
}
 
//-------------------------------------------------------------------------------------------------
function show_keijiban(){
	alert("BBSに移動");
 
}
 
function toukou(){
	alert("投稿");
}
 
function ketai_toukou(){
	alert("携帯投稿");
}
 
 
 
 