var wo_handle = null;
var not_close = false;

def_window_width = 0;
def_window_height = 0;
def_window_posx = 999999;
def_window_posy = 999999;

function WOPEN(url){
        window.open(url,"pop","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=700,height=640")
}

function setModeSubmit(set_mode, set_mode2){
	if ( document.getElementById("future_submit") ) {
		document.getElementById("future_submit").submit.disabled = set_mode;
		if ( document.getElementById("future_submit").common ) {
			document.getElementById("future_submit").common.disabled = set_mode2;
		}
		if ( document.getElementById("common_kichi_msg") ) {
			if (set_mode2 == false) {
				document.getElementById("common_kichi_msg").innerHTML = "他の人との共通吉方位を表示する.";
			} else {
				document.getElementById("common_kichi_msg").innerHTML = "<font color=\"gray\">他の人との共通吉方位を表示する.</font>";
			}
		}
	}
}

function selectRegistedData(parts) {
	var spmoji = parts.options[parts.selectedIndex].value.split(" ");
	if(spmoji.length > 1){
		if ( document.getElementById("birthday-input") ) {
			document.getElementById("birthday-input").family_number.value   = spmoji[0];
			document.getElementById("birthday-input").year.value  = spmoji[1];
			document.getElementById("birthday-input").month.value = spmoji[2];
			document.getElementById("birthday-input").day.value   = spmoji[3];
			document.getElementById("birthday-input").lat.value   = spmoji[4];
			document.getElementById("birthday-input").lon.value   = spmoji[5];
		}
		if ( document.getElementById("geo-search") ) {
			if (typeof spmoji[6] != "undefined") {
				document.getElementById("geo-search").address.value   = spmoji[6];
			} else {
				document.getElementById("geo-search").address.value   = "";
			}
		}
		if (spmoji[0] <= 0) {
if (spmoji[0] == 0) {
//	document.getElementById("birthday-input").year.value  = "";
//        document.getElementById("birthday-input").month.value = "";
//        document.getElementById("birthday-input").day.value   = "";
	document.getElementById("addres-set-msg").innerHTML = '<b>初期選択データの住所を使用します。</b>';
}
			setModeStep1Input(false);
			toggleAddressSetMsg('');
			setInputMsg(1);
		} else {
			setModeStep1Input(true);
			toggleAddressSetMsg('none');
			setInputMsg(0);
		}
	} else {
		if ( document.getElementById("birthday-input") ) {
			document.getElementById("birthday-input").year.value  = "";
			document.getElementById("birthday-input").month.value = "";
			document.getElementById("birthday-input").day.value   = "";
			document.getElementById("birthday-input").lat.value   = "";
			document.getElementById("birthday-input").lon.value   = "";
			document.getElementById("birthday-input").family_number.value   = "0";
		}
		if ( document.getElementById("geo-search") ) {
			document.getElementById("geo-search").address.value   = "";
			//2009.08.05
			if (spmoji[0] == 0) {
				setModeStep1Input(false);
				toggleAddressSetMsg('none');
				setInputMsg(0);
        			document.getElementById("birthday-set-msg").innerHTML = '<b>お誕生日を入力してください</b>';
				document.getElementById("geo-search").address.value   = '';
				document.getElementById("addres-set-msg").innerHTML = '<b>初期選択データの住所を使用します。</b>';
			        document.getElementById("geo-search").address.disabled = true;
			        document.getElementById("geo-search").submit.disabled = true;
			        document.getElementById("geo-search").submit.visible = false;
			}
			if (spmoji[0] < 0) {
				setModeStep1Input(false);
			        document.getElementById("geo-search").submit.disabled = false;
			        document.getElementById("geo-search").address.disabled = false;
			        document.getElementById("geo-search").submit.visible = true;
				toggleAddressSetMsg('');
				setInputMsg(1);
			}

		}
		//setModeStep1Input(false);
		//toggleAddressSetMsg('');
	}

}

function toggleAddressSetMsg(set_mode) {
	elem = document.getElementById("address-set");
	if (elem) {
		elem.style.display = set_mode;
	}
}

function setInputMsg(set_mode) {
	if (set_mode == 0) {
        	document.getElementById("birthday-set-msg").innerHTML = '<b>お誕生日</b>　　　　　　　　　';
        	document.getElementById("addres-set-msg").innerHTML = '<b>ご住所</b>';
	} else {
        	document.getElementById("birthday-set-msg").innerHTML = '<b>お誕生日を入力してください</b>';
        	document.getElementById("addres-set-msg").innerHTML = '<b>ご住所を設定してください</b>';
	}
}

function setModeStep1Input(set_mode){
        document.getElementById("geo-search").submit.disabled = set_mode;
        document.getElementById("geo-search").address.disabled = set_mode;
        document.getElementById("birthday-input").year.disabled = set_mode;
        document.getElementById("birthday-input").month.disabled = set_mode;
        document.getElementById("birthday-input").day.disabled = set_mode;
}

function swCommonKichi() {
	currentBoardSwitch();
}

function swClearDestin() {
        var clearDestin = document.getElementById("geo-search").clearDestin.checked;
	if (clearDestin == true) {
		document.getElementById("step2").clearDestin.value = "1";
	} else {
		document.getElementById("step2").clearDestin.value = "0";
	}
}

function oneClick(inside) {
  var copyText = eval("document."+inside);
  copyText.focus();
  copyText.select();
  //if (document.all) {
  //  txRange = copyText.createTextRange();
  //  txRange.execCommand('copy');
  //  setTimeout("window.status='クリップボードにコピーしました'", 500);
  //}
}


function openFuture(window_posx, window_posy, window_width, window_height) {
	if (def_window_width > 0) { window_width = def_window_width; }
	if (def_window_height > 0) { window_height = def_window_height; }
	if (def_window_posx != 999999) { window_posx = def_window_posx; }
	if (def_window_posy != 999999) { window_posy = def_window_posy; }

	boardNum = document.getElementById('future_submit').fee_menu.value;
	commonFlag = document.getElementById('future_submit').common.checked;
	nowDate = document.getElementById('future_submit').now_date.value;
	destLatLon = document.getElementById('future_submit').dest_lat_lon.value;
	selBirth = document.getElementById('future_submit').sel_birth.value;
	selLatLon = document.getElementById('future_submit').sel_lat_lon.value;
	fmno = document.getElementById('future_submit').fmno_fut.value;

	var isChrome = (navigator.userAgent.toLowerCase().indexOf('chrome')+1?1:0);

	if (boardNum >= 6 && boardNum <= 8) {
		url = "future.php?bn="+boardNum+"&cm=";
		if (commonFlag == true) {
			url += "1";
		} else {
			url += "0";
		}
		url += "&nt="+nowDate;
		url += "&dl="+destLatLon;
		url += "&sb="+selBirth;
		url += "&sl="+selLatLon;
		url += "&fn="+fmno;

		var dt = new Date();
		url += "&epc="+dt.getTime();

		if (window_posx == 999999) {
			posx = (screen.width - window_width - 20);
		} else {
			posx = window_posx;
		}
		if (window_posy == 999999) {
			posy = (screen.height - window_height - 120);
		} else {
			posy = window_posy;
		}
		wo_handle = window.open(url, "pop", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width="+window_width+",height="+window_height+",left="+posx+",top="+posy);
		if (isChrome == 0) {
			wo_handle.moveTo(posx, posy);
		}
		wo_handle.focus();
	}
}

function childWindowClose() {
	if (wo_handle != null) {
		if (!not_close) wo_handle.close();
	}
}

function setNotCloseMode(boo) {
	not_close = boo;
}


