function showPic(teacherID) {
	if (picwin) picwin.close()
	var picwin = open("/tpics/"+teacherID+".jpg","picwin","width=150,height=170");
	picwin.focus();
}




function setEdAtt() {
	if (tf.edat1.checked) 
		tf.Education_attending[0].value = 'Now Attending'
	else
		tf.Education_attending[0].value = '';
	if (tf.edat2.checked) 
		tf.Education_attending[1].value = 'Now Attending'
	else
		tf.Education_attending[1].value = '';
	if (tf.edat3.checked) 
		tf.Education_attending[2].value = 'Now Attending'
	else
		tf.Education_attending[2].value = '';
	if (tf.inMil.checked)
		tf.Teachers_inMilitary.value='in Military';
	else
		tf.Teachers_inMilitary.value='';
}

function confirmForm() {
	if (tf.edat1) 
		setEdAtt()
	var reqs=''
	with (document.regForm) {
		for (var i=0; i<elements.length;i++) {
			if ((elements[i].req) && (elements[i].value=='')) {
				reqs+= elements[i].req + "\n"
			}
		}
		if (reqs) {
			alert("You must enter the following fields:\n\n"+reqs)
			return (false)
		}
		submit()
	}
}

function clearData() {
	document.regForm.reset();
}

function loadData(langField) {
	var newListArray = new Array()
	var newListArrayD = new Array()
	
	if (top.prefecture) {
		updatePref(top.prefecture.document.all.prefList,langField);
		with (document.regForm) {
			newListArray = selectPlaceList.value.split(",")
			newListArrayD = _displayList.value.split(",")
			for (i=0; i<newListArray.length;i++) {
				_selectPlaceBox.options[i] = new Option(newListArrayD[i].replace(/:/g,", "),newListArray[i])	
			}
		}
	}
}

function makePref(langField,dlang) {
	var loadText = 'loading...';
	if (dlang) loadText ='ローディング中';
	var loadColor = '#e1d2b1';
	nowLoading(top.prefecture,loadText,loadColor,'right');
	top.prefecture.document.location.href= webdir+"/cgi-bin/preflist.cgi?dlang="+document.regForm._lang.value+"&langID="+langField
}

function updatePref(prefList,langField,dlang) {
	var pref = getSelection(prefList)
	var loadText = 'loading...';
	if (dlang) loadText ='ローディング中';
	var loadColor = '#e1d2b1';
	nowLoading(top.pref,loadText,loadColor,'right');
	top.city.document.location.href=webdir+"/cgi-bin/citylist.cgi?dlang="+document.regForm._lang.value+"&pref="+pref+"&langID="+langField
}

function nowLoading(loadWin,loadText,color,align) {
	loadWin.document.write("<html><body bgcolor='"+color+"'><div align='"+align+"'><b>"+loadText+"</b></div></body></html>");
	loadWin.document.close();
}

function updateCity(cityList,langField) {
	var city = getSelection(cityList)
	var pref = getSelection(top.prefList)
	alert('got city= '+city)
	alert('got pref= '+pref)
	alert('wclist= '+document.regForm._wcList.value)
	if (document.regForm._wcList.value.indexOf(city)==-1) {
		top.ward.document.write('<html><body bgcolor="#e0f9ff"></body></html>');
		return(false);
	}

	top.ward.document.write('<html><body bgcolor="#e0f9ff"><b>loading...</b></body></html>');
	top.ward.document.close();
	top.ward.document.location.href=webdir+"/cgi-bin/wardlist.cgi?dlang="+document.regForm._lang.value+"&city="+city+"&pref="+pref+"&langID="+langField
}

function getSelection(theList, lang) {
	var result = ""

	if(!theList) return('');
	for (var i= 0; i< theList.length; i++) {
		if (theList.options[i].selected) {
			if (lang)
				return(theList.options[i].text)
			return(theList.options[i].value)
		}
	}
	return result
}

function placeExists(place) {

	for (i=0;i<document.regForm._selectPlaceBox.options.length;i++) {
		if (document.regForm._selectPlaceBox.options[i].value==place)
			return true
	}
	return false
}
function addPlace() {
	var newListArray= new Array()
	var newListArrayD= new Array()
	var newPlace,newPlaceD
	
	if (!(eval(top.prefecture.document.all.prefList) && eval(top.city.document.all.cityList) && eval(top.ward.document))) return
	with (document.regForm) {
		if (_selectPlaceBox.options.length < 10) {
			newPlace = getSelection(top.prefecture.document.all.prefList)+":"+getSelection(top.city.document.all.cityList)+":"+getSelection(top.ward.document.all.wardList)
			newPlaceD = getSelection(top.prefecture.document.all.prefList,1)+":"+getSelection(top.city.document.all.cityList,1)+":"+getSelection(top.ward.document.all.wardList,1)
			newPlace=newPlace.replace(/:$/,'')
			newPlaceD=newPlaceD.replace(/\(\w*\)/g,'')
			newPlaceD=newPlaceD.replace(/:$/,'')
			newPlaceD=newPlaceD.replace(/\(\w*\)/g,'')
			if (!placeExists(newPlace)) {
				if (selectPlaceList.value.length>0) comma=","
				else comma=""
				_selectPlaceBox.options.length=0
				selectPlaceList.value+= comma+newPlace
				_displayList.value+= comma+newPlaceD
				newListArray = selectPlaceList.value.split(",")
				newListArrayD = _displayList.value.split(",")
				for (i=0; i<newListArray.length;i++) {
					_selectPlaceBox.options[i] = new Option(newListArrayD[i].replace(/:/g,", "),newListArray[i])	
				}
			}
		} else {
			alert("Sorry.  You can only select up to 10 areas.")
		}
	}
}

function getPlace() {
	
	if (!(eval(top.prefecture.document.all.prefList) && eval(top.city.document.all.cityList) && eval(top.ward.document))) return
	with (document.regForm) {
		newPlace = getSelection(top.prefecture.document.all.prefList)+":"+getSelection(top.city.document.all.cityList)+":"+getSelection(top.ward.document.all.wardList)
		newPlace=newPlace.replace(/:$/,'')
		return(newPlace);
	}
}

function clearPlace() {
	var clearListArray = new Array()
	var placeListArray = new Array()
	var displayArray = new Array()
	var newListArray = new Array()
	var displayListArray = new Array()

	with (document.regForm) {
		clearList = getSelection(_selectPlaceBox)
		if (clearList!="") {
			clearListArray = clearList.split(",")
			placeListArray = selectPlaceList.value.split(",")
			displayArray = _displayList.value.split(",")
			for (i=0; i<placeListArray.length;i++) {
				for (j=0; j<clearListArray.length;j++) {
					if (clearListArray[j]==placeListArray[i])
						placeListArray[i] = ""
				}
			}
			_selectPlaceBox.options.length=0
			selectPlaceList.value=""
			_displayList.value=""
			for (i=0;i<placeListArray.length;i++) {
				if ((placeListArray[i]!="") && (placeListArray[i]!=null)) {
					selectPlaceList.value+=placeListArray[i]+","
					_displayList.value+=displayArray[i]+","
				}
			}
			if (i!=0) {
				selectPlaceList.value=selectPlaceList.value.substring(0,selectPlaceList.value.length-1)
				_displayList.value=_displayList.value.substring(0,_displayList.value.length-1)
				newListArray=selectPlaceList.value.split(",")
				displayListArray=_displayList.value.split(",")
				for (i=0; i<newListArray.length;i++) {
					_selectPlaceBox.options[i] = new Option(displayListArray[i].replace(/:/g,", "),newListArray[i])	
				}
			}
		}
	}
}

function setLangPlace() {
	tf.selectPlaceList.value = top.document.regForm.selectPlaceList.value; 
	tf.language.value = top.document.regForm.Languages_languageID.value;
}

function nada() {}
