// JavaScript Document++++++++++++++++++++++++++++

//Locationリンク
function lct(url){
	location.href = url;
}

//Confirm
function conf(name,url){
	res = confirm(name+"を本当に削除しますか？");
	if(res == true){
            lct(url);
	}else{
            return false;
	}
}

//フォーカス
function setfocus(){

	count = document.mainForm.length;
	for(i=0; i<count; i++){
		type = document.mainForm[i].type;
		if(type!="hidden"){
			document.mainForm[i].focus();
			break;
		}
	}
}

//フォーム非表示
function CExam_check(flg,formname){
	if(flg == "TRUE"){
		fname = formname.split(":");
		for(i=0; i<fname.length; i++){
			cform = document.mainForm.elements[fname[i]];
			cform.disabled=true;
		}
	}
}

//パスワード用フォームチェック
function check(){
	if(document.mainForm.old_password.value=="" || document.mainForm.new_password.value=="" || document.mainForm.chk_password.value==""){
		button=document.mainForm.key;
		button.disabled=true;
		setElementClassById("key", "disablepush");
		document.getElementById("message").innerHTML="";
	}else{
		button=document.mainForm.key;
		if(document.mainForm.new_password.value==document.mainForm.chk_password.value){
			button.disabled=false;
			setElementClassById("key", "pushbtn");
			document.getElementById("message").innerHTML="";
		}else{
			button.disabled=true;
			setElementClassById("key", "disablepush");
			document.getElementById("message").innerHTML="新パスワードと確認用パスワードが一致しません。<br>";
		}
	}
}

//非表示
function Button_check(formname){
		cform = document.subForm.elements[formname];
		cform.disabled=true;
}

//お気に入りに追加
function favorate(url,webname){
	window.external.addFavorite(url,webname);
}

//プリントアウトダイアログ
function printout(){
	window.print();
}

//サブウィンドウ表示
function subwin(URL,Name,Features,Size){
	window.open(URL,Name,Features,Size);
}

//サブウィンドウ表示
function chdate(type){
	//追加
	if(type==1){
		window.open('add_schedule.php','test','width=370,height=150');
	//削除
	}else{
	    window.open('del_schedule.php','test','width=370,height=150');
	}
}


//リロード
function reloads(){
	location.reload();
}


function Close(){
	window.close();
}

//フォームのカラーチェンジ関数
function Ch_color(elemName){
	ch_aera = document.mainForm.elements[elemName];
	ch_aera.style.backgroundColor='#F3F3F3'
}

//フォームのカラーチェンジ関数
function Ch_color2(elemName){
	ch_aera = document.mainForm.elements[elemName];
	ch_aera.style.backgroundColor='#FFFFFF'
}

//Submit
function ChangeSubmit(url) {
	document.mainForm.action = url;
	document.mainForm.target = "_self";
	document.mainForm.answer[0].value = "";
	document.mainForm.answer[1].value = "";
	document.mainForm.answer[2].value = "";
	document.mainForm.answer[3].value = "";
	document.mainForm.submit();
}

//回答チェック
function ChAnswer(){
	var check_flg = "";
	for(i=0; i<4; i++){
		flg = document.mainForm.answer[i].checked;
		if(flg){
			check_flg = "OK";
			break;
		}
	}
	if(check_flg==""){
		alert("解答を選択して下さい！");
		return false;
	}
}
// JavaScript Document++++++++++++++++++++++++++++

//Locationリンク
function lct(url){
	location.href = url;
}

//Confirm
function conf(name,url){
	res = confirm(name+"を本当に削除しますか？");
	if(res == true){
            lct(url);
	}else{
            return false;
	}
}

//フォーカス
function setfocus(){

	count = document.mainForm.length;
	for(i=0; i<count; i++){
		type = document.mainForm[i].type;
		if(type!="hidden"){
			document.mainForm[i].focus();
			break;
		}
	}
}

//フォーム非表示
function CExam_check(flg,formname){
	if(flg == "TRUE"){
		fname = formname.split(":");
		for(i=0; i<fname.length; i++){
			cform = document.mainForm.elements[fname[i]];
			cform.disabled=true;
		}
	}
}

//非表示
function Button_check(formname){
		cform = document.subForm.elements[formname];
		cform.disabled=true;
}

//お気に入りに追加
function favorate(url,webname){
	window.external.addFavorite(url,webname);
}

//プリントアウトダイアログ
function printout(){
	window.print();
}

//サブウィンドウ表示
function subwin(URL,Name,Features,Size){
	window.open(URL,Name,Features,Size);
}

//サブウィンドウ表示
function chdate(type){
	//追加
	if(type==1){
		window.open('add_schedule.php','test','width=370,height=150');
	//削除
	}else{
	    window.open('del_schedule.php','test','width=370,height=150');
	}
}
//検索サブウィンドウ表示
function search_sbwin(URL,Name,Features,Size){
	var length = document.mainForm.place_flg.length;
	for(i=0;i<length;i++){
		if(document.mainForm.place_flg[i].checked==true){
			URL=URL+"?type="+document.mainForm.place_flg[i].value;
			window.open(URL,Name,Features,Size);
		}
	}
}
//search_sbwin用ボタン表示チェック
function check_place_cd(){
	if(document.mainForm.place_flg[0].checked==true){
		button=document.mainForm.search_cd;
		button.disabled=true;
	}else{
		button=document.mainForm.search_cd;
		button.disabled=false;
	}
}
//ボタン表示チェック
function check_user_cd(){
	var length = document.mainForm.view_user.length;
	for(i=0;i<length;i++){
		if(document.mainForm.user_cd.value==document.mainForm.view_user[i].value){
			button=document.mainForm.submit_done;
			button.disabled=true;
		}
	}
}

//リロード
function reloads(){
	location.reload();
}

function Close(){
	window.close();
}

//フォームのカラーチェンジ関数
function Ch_color(elemName){
	ch_aera = document.mainForm.elements[elemName];
	ch_aera.style.backgroundColor='#F3F3F3'
}

//フォームのカラーチェンジ関数
function Ch_color2(elemName){
	ch_aera = document.mainForm.elements[elemName];
	ch_aera.style.backgroundColor='#FFFFFF'
}

function editChange() {
	document.mainForm.action = "edit.php";
	document.mainForm.target = "_self";
	document.mainForm.submit();
}

function editOpenerChange() {
	window.opener.document.mainForm.action = "edit.php";
	window.opener.document.mainForm.target = "_self";
	window.opener.document.mainForm.submit();
}

//教科・目標・大・中・小項目セレクト関数
function Output_Value(PCD,CD){
	//PCD = 親WindowのForm指定No
	switch(PCD){
		//領域
		case 1:
			window.opener.document.mainForm.ter_cd.options[CD].selected = true;
			window.close();
			break;
		//教科
		case 2:
			window.opener.document.mainForm.sub_cd.options[CD].selected = true;
			window.close();
			break;
		//目標
		case 3:
			window.opener.document.mainForm.tar_cd.options[CD].selected = true;
			window.close();
			break;
		//大項目
		case 4:
			window.opener.document.mainForm.l_cd.options[CD].selected = true;
			editOpenerChange();
			window.close();
			break;
		//中項目
		case 5:
			window.opener.document.mainForm.m_cd.options[CD].selected = true;
			editOpenerChange();
			window.close();
			break;
		//小項目
		case 6:
			window.opener.document.mainForm.s_cd.options[CD].selected = true;
			window.close();
			break;
	}
}

//受験校登録フォームコントロール

function radio_ctl(num){
	for(i=0; i<num; i++){
		if(num>1){
			rform = document.school.sch_cd[i];
		}else{
			rform = document.school.sch_cd;
		}
		tname = "number"+(i+1);
		tform = document.school.elements[tname];
		if(rform.checked){
			tform.disabled = false;
			tform.style.backgroundColor='#FFFFFF';
			tform.focus();
		}else{
			tform.disabled = true;
			tform.style.backgroundColor='#F3F3F3';
			tform.value="";
		}
	}
}
//受験校人数入力不可 num=検索件数
function txt_disable(num){
	for(i=0; i<num; i++){
		tname = "number"+(i+1);
		tform = document.school.elements[tname];
		tform.disabled = true;
		tform.style.backgroundColor='#F3F3F3';
	}
}

//地域から都道府県絞込
function ChangePref(){
		a = document.getElementById("area").selectedIndex;
		for (i = 0; i < 9; i++) {
			document.getElementById("select" + i).style.display = (i == a ? "block" : "none");
			document.getElementById("pref" + i).disabled = (i != a);
		}
}
//都道府県から地区絞込
function ChangeDistrict(){
		a = document.getElementById("pref").selectedIndex;
		for (i = 0; i <= 48; i++) {
			document.getElementById("select" + i).style.display = (i == a ? "block" : "none");
			document.getElementById("district" + i).disabled = (i != a);
		}
}

//学校種別1から種別2絞込
function ChangeDiv(){
		a = document.getElementById("division1").selectedIndex;
		for (i = 0; i < 7; i++) {
			document.getElementById("div_select" + i).style.display = (i == a ? "block" : "none");
			document.getElementById("div" + i).disabled = (i != a);
		}
}

//Submit
function ChangeSubmit(url) {
	document.mainForm.action = url;
	document.mainForm.target = "_self";
	document.mainForm.submit();
}

//検索からセレクトチェンジ
function ItemChange(values,formname,submit_flg,url) {
	//フォーム数取得
	name = "document.mainForm."+formname+".options.length";
	num = eval(name);
	//フォーム名形成
	name2 = "document.mainForm."+formname;
	forname = eval(name2);
	//フォームセレクト
	for (i=0; i<num; i++) {
		if (forname.options[i].value == values) {
			forname.options[i].selected=true;
		}
	}
	//そのままリダイレクトするか？
	if(submit_flg=='TRUE'){
		ChangeSubmit(url);
	}
}

//子から親ウィンドウのItemChangeメソッド起動
function OyaRelease(no,name,submit_flg,url){
	window.opener.ItemChange(no,name,submit_flg,url);
	window.close();
}
//子から親ウィンドウのフォームに値を代入
function update(value){
    window.document.mainForm.place_cd.value = value;
}
//子から親ウィンドウのサブミット
function fnsubmit(url){
	document.mainForm.action = url;
	document.mainForm.target = "_self";
	document.forms["mainForm"].elements["submit_flg"].value="on";
	document.forms["mainForm"].submit();

}
//子ウィンドウ
function notifyParent(value){
    window.opener.update(value);
		window.close();
}
function notifyParent2(value){
    window.opener.update(value);
		window.opener.fnsubmit('edit.php');
		window.close();
}
//入力チェック
function TEXTcheck(checkvalue){
	target = checkvalue;
	if(target!=''){
		if(target.match(/[あ-んア-ンｱ-ﾝ]/)){
		
		}else{
			alert("氏名はカタカナで入力下さい。");
		}
	}

}
//class要素の追加・変更
function setElementClassById(elem, value) {
   if(document.getElementById) {
         var obj = document.getElementById(elem);
         if(obj) {
            obj.className = value;
         }
   }
}